Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6b603f2
Commit
PuruVJ Apr 5, 2023
78fb9cd
Merge branch 'sites' into feat/ts-in-docs
PuruVJ Apr 6, 2023
145b1e3
Push working type generation code
PuruVJ Apr 6, 2023
59bfa30
Fix type gen script invocation
PuruVJ Apr 6, 2023
1168b53
Delete type-info.js
PuruVJ Apr 6, 2023
60c05c8
Change build script
PuruVJ Apr 6, 2023
2d92a29
Recreate package lock
PuruVJ Apr 6, 2023
362cdfb
mkdir generated
PuruVJ Apr 6, 2023
7131650
Add type references to some pages
PuruVJ Apr 6, 2023
9ce5d96
Add TS-able snippets to docs examples
PuruVJ Apr 6, 2023
a42a769
Fix some stuff
PuruVJ Apr 9, 2023
218849c
Add types to individual functions
PuruVJ Apr 11, 2023
9f99679
Add to store page
PuruVJ Apr 11, 2023
6b95c24
Merge branch 'sites' into feat/ts-in-docs
PuruVJ Apr 12, 2023
ea0cfaf
Refactor compile-types.js
PuruVJ Apr 12, 2023
33a8614
Move ts sourcefile stuff to compile-types
PuruVJ Apr 12, 2023
e4a8417
Remove commented code
PuruVJ Apr 12, 2023
8e22b83
Half attempt at export aliases
PuruVJ Apr 12, 2023
a842562
Add
PuruVJ Apr 12, 2023
21fe5e9
Fix, add disclaimer for svelte/internal
PuruVJ Apr 12, 2023
2df994e
Merge branch 'sites' into feat/ts-in-docs
PuruVJ Apr 12, 2023
d654a8a
Disable /docs prerendering
PuruVJ Apr 12, 2023
a100a23
Remove internals page
PuruVJ Apr 12, 2023
9db28d6
Remove redundant stuff
PuruVJ Apr 12, 2023
c482362
Make search work with it
PuruVJ Apr 12, 2023
de803e1
Fix compile types logic
PuruVJ Apr 13, 2023
9b43939
Add file: comment,
PuruVJ Apr 13, 2023
4a288a5
Add two-slash to docs pages
PuruVJ Apr 14, 2023
6899df2
Get type links working
PuruVJ Apr 14, 2023
9abbc8c
Remove console.log
PuruVJ Apr 14, 2023
c331551
Add action module
PuruVJ Apr 14, 2023
8fa8c25
Fix actions logic
PuruVJ Apr 14, 2023
7a8d620
Make compile-types logic more robust
PuruVJ Apr 14, 2023
02933af
Bump site-kit
PuruVJ Apr 14, 2023
6b6da71
Fix gitignore
PuruVJ Apr 14, 2023
5d8a381
Use moduleResolution bundler
PuruVJ Apr 14, 2023
db87d06
Don't apply shiki-twoslash to auto generated code snippets from render
PuruVJ Apr 15, 2023
5a36085
Merge branch 'sites' into feat/ts-in-docs
PuruVJ Apr 17, 2023
01d666b
Merge branch 'sites' into feat/ts-in-docs
PuruVJ Apr 30, 2023
337dc4e
Recreate package lock
PuruVJ Apr 30, 2023
2cfcdc7
Make TSbpage undraft
PuruVJ Apr 30, 2023
181b541
Fix svelte component types
PuruVJ Apr 30, 2023
a962392
Remove console.log
PuruVJ Apr 30, 2023
73af4e4
No more sveltekit
PuruVJ Apr 30, 2023
fc29593
Make regex smarter
PuruVJ Apr 30, 2023
7a9dbea
Merge remote-tracking branch 'origin/sites' into feat/ts-in-docs
PuruVJ May 9, 2023
710aa50
Update sites/svelte.dev/scripts/type-gen/compile-types.js
PuruVJ May 9, 2023
07a1d8e
Merge branch 'sites' into feat/ts-in-docs
PuruVJ May 9, 2023
1817cb3
Rebuild package lock
PuruVJ May 10, 2023
a71aaca
Remove commented out code
PuruVJ May 10, 2023
835cd6e
Merge branch 'sites' into feat/ts-in-docs
PuruVJ May 11, 2023
e0bf346
Update deps
PuruVJ May 11, 2023
8f89aa6
Remove $$_attributes
PuruVJ May 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions site/content/docs/02-template-syntax/01-svelte-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ In development mode (see the [compiler options](/docs/svelte-compiler#svelte-com
If you export a `const`, `class` or `function`, it is readonly from outside the component. Functions are valid prop values, however, as shown below.

```svelte
<!--- file: App.svelte --->
<script>
// these are readonly
export const thisIs = 'readonly';

/** @param {string} name */
export function greet(name) {
alert(`hello ${name}!`);
}
Expand All @@ -70,7 +72,9 @@ Readonly props can be accessed as properties on the element, tied to the compone
You can use reserved words as prop names.

```svelte
<!--- file: App.svelte --->
<script>
/** @type {string} */
let className;

// creates a `class` property, even
Expand Down Expand Up @@ -155,10 +159,12 @@ Any top-level statement (i.e. not inside a block or a function) can be made reac
Only values which directly appear within the `$:` block will become dependencies of the reactive statement. For example, in the code below `total` will only update when `x` changes, but not `y`.

```svelte
<!--- file: App.svelte --->
<script>
let x = 0;
let y = 0;

/** @param {number} value */
function yPlusAValue(value) {
return value + y;
}
Expand All @@ -179,9 +185,10 @@ It is important to note that the reactive blocks are ordered via simple static a
let x = 0;
let y = 0;

const setY = (value) => {
/** @param {number} value */
function setY(value) {
y = value;
};
}

$: yDependent = y;
$: setY(x);
Expand All @@ -193,7 +200,9 @@ Moving the line `$: yDependent = y` below `$: setY(x)` will cause `yDependent` t
If a statement consists entirely of an assignment to an undeclared variable, Svelte will inject a `let` declaration on your behalf.

```svelte
<!--- file: App.svelte --->
<script>
/** @type {number} */
export let num;

// we don't need to declare `squared` and `cubed`
Expand Down Expand Up @@ -232,7 +241,8 @@ Local variables (that do not represent store values) must _not_ have a `$` prefi

#### Store contract

```js
```ts
// @noErrors
store = { subscribe: (subscription: (value: any) => void) => (() => void), set?: (value: any) => void }
```

Expand Down
38 changes: 37 additions & 1 deletion site/content/docs/02-template-syntax/05-element-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ on:eventname|modifiers={handler}
Use the `on:` directive to listen to DOM events.

```svelte
<!--- file: App.svelte --->
<script>
let count = 0;

/** @param {MouseEvent} event */
function handleClick(event) {
count += 1;
}
Expand Down Expand Up @@ -70,12 +72,14 @@ If the `on:` directive is used without a value, the component will _forward_ the
It's possible to have multiple event listeners for the same event:

```svelte
<!--- file: App.svelte --->
<script>
let counter = 0;
function increment() {
counter = counter + 1;
}

/** @param {MouseEvent} event */
function track(event) {
trackEvent(event);
}
Expand Down Expand Up @@ -274,8 +278,11 @@ bind:group={variable}
Inputs that work together can use `bind:group`.

```svelte
<!--- file: App.svelte --->
<script>
let tortilla = 'Plain';

/** @type {Array<string>} */
let fillings = [];
</script>

Expand All @@ -302,9 +309,11 @@ bind:this={dom_node}
To get a reference to a DOM node, use `bind:this`.

```svelte
<!--- file: App.svelte --->
<script>
import { onMount } from 'svelte';

/** @type {HTMLCanvasElement} */
let canvasElement;

onMount(() => {
Expand Down Expand Up @@ -390,7 +399,8 @@ use:action
use:action={parameters}
```

```js
```ts
// @noErrors
action = (node: HTMLElement, parameters: any) => {
update?: (parameters: any) => void,
destroy?: () => void
Expand All @@ -400,7 +410,9 @@ action = (node: HTMLElement, parameters: any) => {
Actions are functions that are called when an element is created. They can return an object with a `destroy` method that is called after the element is unmounted:

```svelte
<!--- file: App.svelte --->
<script>
/** @type {import('svelte/action').Action} */
function foo(node) {
// the node has been mounted in the DOM

Expand All @@ -420,9 +432,11 @@ An action can have a parameter. If the returned value has an `update` method, it
> Don't worry about the fact that we're redeclaring the `foo` function for every component instance — Svelte will hoist any functions that don't depend on local state out of the component definition.

```svelte
<!--- file: App.svelte --->
<script>
export let bar;

/** @type {import('svelte/action').Action} */
function foo(node, bar) {
// the node has been mounted in the DOM

Expand Down Expand Up @@ -460,6 +474,7 @@ transition:fn|local={params}
```

```js
// @noErrors
transition = (node: HTMLElement, params: any, options: { direction: 'in' | 'out' | 'both' }) => {
delay?: number,
duration?: number,
Expand Down Expand Up @@ -504,9 +519,11 @@ The `t` argument passed to `css` is a value between `0` and `1` after the `easin
The function is called repeatedly _before_ the transition begins, with different `t` and `u` arguments.

```svelte
<!--- file: App.svelte --->
<script>
import { elasticOut } from 'svelte/easing';

/** @type {boolean} */
export let visible;

function whoosh(node, params) {
Expand Down Expand Up @@ -657,6 +674,7 @@ animate:name={params}
```

```js
// @noErrors
animation = (node: HTMLElement, { from: DOMRect, to: DOMRect } , params: any) => {
delay?: number,
duration?: number,
Expand All @@ -667,6 +685,7 @@ animation = (node: HTMLElement, { from: DOMRect, to: DOMRect } , params: any) =>
```

```ts
// @noErrors
DOMRect {
bottom: number,
height: number,
Expand Down Expand Up @@ -712,10 +731,20 @@ The `t` argument passed to `css` is a value that goes from `0` and `1` after the

The function is called repeatedly _before_ the animation begins, with different `t` and `u` arguments.

<!-- TODO: Types -->

```svelte
<!--- file: App.svelte --->
<script>
import { cubicOut } from 'svelte/easing';

/**
* @param {HTMLElement} node
* @param {Object} states
* @param {DOMRect} states.from
* @param {DOMRect} states.to
* @param {any} params
*/
function whizz(node, { from, to }, params) {
const dx = from.left - to.left;
const dy = from.top - to.top;
Expand Down Expand Up @@ -744,6 +773,13 @@ A custom animation function can also return a `tick` function, which is called _
<script>
import { cubicOut } from 'svelte/easing';

/**
* @param {HTMLElement} node
* @param {Object} states
* @param {DOMRect} states.from
* @param {DOMRect} states.to
* @param {any} params
*/
function whizz(node, { from, to }, params) {
const dx = from.left - to.left;
const dy = from.top - to.top;
Expand Down
4 changes: 4 additions & 0 deletions site/content/docs/02-template-syntax/07-special-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ It cannot appear at the top level of your markup; it must be inside an if or eac

```svelte
<script>
/** @type {number} */
export let count;
</script>

Expand Down Expand Up @@ -198,6 +199,8 @@ If `this` is the name of a [void element](https://developer.mozilla.org/en-US/do
```svelte
<script>
let tag = 'div';

/** @type {(e: MouseEvent) => void} */
export let handler;
</script>

Expand All @@ -220,6 +223,7 @@ Unlike `<svelte:self>`, this element may only appear at the top level of your co

```svelte
<script>
/** @param {KeyboardEvent} event */
function handleKeydown(event) {
alert(`pressed the ${event.key} key`);
}
Expand Down
48 changes: 14 additions & 34 deletions site/content/docs/03-runtime/01-svelte.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ The `svelte` package exposes [lifecycle functions](/tutorial/onmount) and the [c

## `onMount`

```js
onMount(callback: () => void)
```

```js
onMount(callback: () => () => void)
```
> EXPORT_SNIPPET: svelte#onMount

The `onMount` function schedules a callback to run as soon as the component has been mounted to the DOM. It must be called during the component's initialisation (but doesn't need to live _inside_ the component; it can be called from an external module).

Expand Down Expand Up @@ -48,9 +42,7 @@ If a function is returned from `onMount`, it will be called when the component i

## `beforeUpdate`

```js
beforeUpdate(callback: () => void)
```
> EXPORT_SNIPPET: svelte#beforeUpdate

Schedules a callback to run immediately before the component is updated after any state change.

Expand All @@ -68,9 +60,7 @@ Schedules a callback to run immediately before the component is updated after an

## `afterUpdate`

```js
afterUpdate(callback: () => void)
```
> EXPORT_SNIPPET: svelte#afterUpdate

Schedules a callback to run immediately after the component has been updated.

Expand All @@ -88,9 +78,7 @@ Schedules a callback to run immediately after the component has been updated.

## `onDestroy`

```js
onDestroy(callback: () => void)
```
> EXPORT_SNIPPET: svelte#onDestroy

Schedules a callback to run immediately before the component is unmounted.

Expand All @@ -108,9 +96,7 @@ Out of `onMount`, `beforeUpdate`, `afterUpdate` and `onDestroy`, this is the onl

## `tick`

```js
promise: Promise = tick();
```
> EXPORT_SNIPPET: svelte#tick

Returns a promise that resolves once any pending state changes have been applied, or in the next microtask if there are none.

Expand All @@ -128,9 +114,7 @@ Returns a promise that resolves once any pending state changes have been applied

## `setContext`

```js
setContext(key: any, context: any)
```
> EXPORT_SNIPPET: svelte#setContext

Associates an arbitrary `context` object with the current component and the specified `key` and returns that object. The context is then available to children of the component (including slotted content) with `getContext`.

Expand All @@ -148,9 +132,7 @@ Like lifecycle functions, this must be called during component initialisation.

## `getContext`

```js
context: any = getContext(key: any)
```
> EXPORT_SNIPPET: svelte#getContext

Retrieves the context that belongs to the closest parent component with the specified `key`. Must be called during component initialisation.

Expand All @@ -164,9 +146,7 @@ Retrieves the context that belongs to the closest parent component with the spec

## `hasContext`

```js
hasContext: boolean = hasContext(key: any)
```
> EXPORT_SNIPPET: svelte#hasContext

Checks whether a given `key` has been set in the context of a parent component. Must be called during component initialisation.

Expand All @@ -182,9 +162,7 @@ Checks whether a given `key` has been set in the context of a parent component.

## `getAllContexts`

```js
contexts: Map<any, any> = getAllContexts()
```
> EXPORT_SNIPPET: svelte#getAllContexts

Retrieves the whole context map that belongs to the closest parent component. Must be called during component initialisation. Useful, for example, if you programmatically create a component and want to pass the existing context to it.

Expand All @@ -198,9 +176,7 @@ Retrieves the whole context map that belongs to the closest parent component. Mu

## `createEventDispatcher`

```js
dispatch: ((name: string, detail?: any, options?: DispatchOptions) => boolean) = createEventDispatcher();
```
> EXPORT_SNIPPET: svelte#createEventDispatcher

Creates an event dispatcher that can be used to dispatch [component events](/docs/component-directives#on-eventname). Event dispatchers are functions that can take two arguments: `name` and `detail`.

Expand Down Expand Up @@ -246,3 +222,7 @@ Events can be cancelable by passing a third parameter to the dispatch function.
}
</script>
```

## Types

> TYPES: svelte
Loading