From 145d67a48905b9f668bd7b3074f49c7d84dc925b Mon Sep 17 00:00:00 2001
From: Ben McCann <322311+benmccann@users.noreply.github.com>
Date: Tue, 9 Jul 2024 16:30:36 -0700
Subject: [PATCH] docs: copy Svelte 5 docs from omnisite (#12317)
---
.../docs/01-getting-started/meta.json | 3 -
.../docs/01-introduction/01-overview.md | 30 +
.../02-getting-started.md} | 19 +-
.../03-reactivity-fundamentals.md | 88 ++
documentation/docs/01-introduction/index.md | 3 +
.../01-component-fundamentals.md | 184 ++++
.../01-svelte-components.md | 350 -------
.../02-template-syntax/02-basic-markup.md | 94 +-
...{03-logic-blocks.md => 03-control-flow.md} | 109 +--
.../docs/02-template-syntax/04-snippets.md | 253 +++++
.../02-template-syntax/04-special-tags.md | 88 --
.../05-element-directives.md | 863 ------------------
.../05-styles-and-classes.md | 214 +++++
.../06-component-directives.md | 129 ---
.../06-transitions-and-animations.md | 432 +++++++++
.../07-actions.md} | 35 +-
.../docs/02-template-syntax/08-bindings.md | 305 +++++++
...ial-elements.md => 09-special-elements.md} | 166 +---
.../02-template-syntax/10-data-fetching.md | 85 ++
.../docs/02-template-syntax/index.md | 3 +
.../docs/02-template-syntax/meta.json | 3 -
documentation/docs/03-runes/01-state.md | 234 +++++
.../docs/03-runes/02-side-effects.md | 360 ++++++++
documentation/docs/03-runes/index.md | 3 +
documentation/docs/03-runtime/01-svelte.md | 230 -----
.../docs/03-runtime/03-svelte-motion.md | 169 ----
.../docs/03-runtime/04-svelte-transition.md | 300 ------
.../docs/03-runtime/05-svelte-animate.md | 48 -
.../docs/03-runtime/06-svelte-easing.md | 31 -
documentation/docs/03-runtime/meta.json | 3 -
.../04-compiler-and-api/01-svelte-compiler.md | 302 ------
.../02-client-side-component-api.md | 253 -----
.../03-server-side-component-api.md | 50 -
.../docs/04-compiler-and-api/meta.json | 3 -
.../01-stores.md} | 77 +-
documentation/docs/04-runtime/02-context.md | 131 +++
.../docs/04-runtime/03-lifecycle-hooks.md | 172 ++++
.../04-runtime/04-imperative-component-api.md | 76 ++
documentation/docs/04-runtime/index.md | 3 +
documentation/docs/05-misc/01-debugging.md | 94 ++
documentation/docs/05-misc/01-faq.md | 126 ---
.../docs/05-misc/02-accessibility-warnings.md | 360 --------
documentation/docs/05-misc/02-testing.md | 8 +
documentation/docs/05-misc/03-typescript.md | 217 +++--
.../04-custom-elements.md} | 21 +-
.../docs/05-misc/04-v4-migration-guide.md | 245 -----
.../docs/05-misc/05-reactivity-indepth.md | 6 +
.../05-misc/06-svelte-5-migration-guide.md | 5 +
documentation/docs/05-misc/index.md | 3 +
documentation/docs/05-misc/meta.json | 3 -
.../docs/06-legacy/01-svelte-register.md | 30 -
documentation/docs/06-legacy/meta.json | 3 -
documentation/docs/98-reference/01-state.md | 9 +
documentation/docs/98-reference/20-svelte.md | 5 +
.../docs/98-reference/21-svelte-action.md | 5 +
.../docs/98-reference/21-svelte-animate.md | 5 +
.../docs/98-reference/21-svelte-compiler.md | 5 +
.../docs/98-reference/21-svelte-easing.md | 5 +
.../docs/98-reference/21-svelte-events.md | 5 +
.../docs/98-reference/21-svelte-legacy.md | 5 +
.../docs/98-reference/21-svelte-motion.md | 5 +
.../docs/98-reference/21-svelte-reactivity.md | 5 +
.../docs/98-reference/21-svelte-server.md | 5 +
.../docs/98-reference/21-svelte-store.md | 5 +
.../docs/98-reference/21-svelte-transition.md | 5 +
documentation/docs/98-reference/index.md | 3 +
documentation/docs/index.md | 3 +
67 files changed, 3097 insertions(+), 4000 deletions(-)
delete mode 100644 documentation/docs/01-getting-started/meta.json
create mode 100644 documentation/docs/01-introduction/01-overview.md
rename documentation/docs/{01-getting-started/01-introduction.md => 01-introduction/02-getting-started.md} (52%)
create mode 100644 documentation/docs/01-introduction/03-reactivity-fundamentals.md
create mode 100644 documentation/docs/01-introduction/index.md
create mode 100644 documentation/docs/02-template-syntax/01-component-fundamentals.md
delete mode 100644 documentation/docs/02-template-syntax/01-svelte-components.md
rename documentation/docs/02-template-syntax/{03-logic-blocks.md => 03-control-flow.md} (52%)
create mode 100644 documentation/docs/02-template-syntax/04-snippets.md
delete mode 100644 documentation/docs/02-template-syntax/04-special-tags.md
delete mode 100644 documentation/docs/02-template-syntax/05-element-directives.md
create mode 100644 documentation/docs/02-template-syntax/05-styles-and-classes.md
delete mode 100644 documentation/docs/02-template-syntax/06-component-directives.md
create mode 100644 documentation/docs/02-template-syntax/06-transitions-and-animations.md
rename documentation/docs/{03-runtime/07-svelte-action.md => 02-template-syntax/07-actions.md} (77%)
create mode 100644 documentation/docs/02-template-syntax/08-bindings.md
rename documentation/docs/02-template-syntax/{07-special-elements.md => 09-special-elements.md} (57%)
create mode 100644 documentation/docs/02-template-syntax/10-data-fetching.md
create mode 100644 documentation/docs/02-template-syntax/index.md
delete mode 100644 documentation/docs/02-template-syntax/meta.json
create mode 100644 documentation/docs/03-runes/01-state.md
create mode 100644 documentation/docs/03-runes/02-side-effects.md
create mode 100644 documentation/docs/03-runes/index.md
delete mode 100644 documentation/docs/03-runtime/01-svelte.md
delete mode 100644 documentation/docs/03-runtime/03-svelte-motion.md
delete mode 100644 documentation/docs/03-runtime/04-svelte-transition.md
delete mode 100644 documentation/docs/03-runtime/05-svelte-animate.md
delete mode 100644 documentation/docs/03-runtime/06-svelte-easing.md
delete mode 100644 documentation/docs/03-runtime/meta.json
delete mode 100644 documentation/docs/04-compiler-and-api/01-svelte-compiler.md
delete mode 100644 documentation/docs/04-compiler-and-api/02-client-side-component-api.md
delete mode 100644 documentation/docs/04-compiler-and-api/03-server-side-component-api.md
delete mode 100644 documentation/docs/04-compiler-and-api/meta.json
rename documentation/docs/{03-runtime/02-svelte-store.md => 04-runtime/01-stores.md} (61%)
create mode 100644 documentation/docs/04-runtime/02-context.md
create mode 100644 documentation/docs/04-runtime/03-lifecycle-hooks.md
create mode 100644 documentation/docs/04-runtime/04-imperative-component-api.md
create mode 100644 documentation/docs/04-runtime/index.md
create mode 100644 documentation/docs/05-misc/01-debugging.md
delete mode 100644 documentation/docs/05-misc/01-faq.md
delete mode 100644 documentation/docs/05-misc/02-accessibility-warnings.md
create mode 100644 documentation/docs/05-misc/02-testing.md
rename documentation/docs/{04-compiler-and-api/04-custom-elements-api.md => 05-misc/04-custom-elements.md} (90%)
delete mode 100644 documentation/docs/05-misc/04-v4-migration-guide.md
create mode 100644 documentation/docs/05-misc/05-reactivity-indepth.md
create mode 100644 documentation/docs/05-misc/06-svelte-5-migration-guide.md
create mode 100644 documentation/docs/05-misc/index.md
delete mode 100644 documentation/docs/05-misc/meta.json
delete mode 100644 documentation/docs/06-legacy/01-svelte-register.md
delete mode 100644 documentation/docs/06-legacy/meta.json
create mode 100644 documentation/docs/98-reference/01-state.md
create mode 100644 documentation/docs/98-reference/20-svelte.md
create mode 100644 documentation/docs/98-reference/21-svelte-action.md
create mode 100644 documentation/docs/98-reference/21-svelte-animate.md
create mode 100644 documentation/docs/98-reference/21-svelte-compiler.md
create mode 100644 documentation/docs/98-reference/21-svelte-easing.md
create mode 100644 documentation/docs/98-reference/21-svelte-events.md
create mode 100644 documentation/docs/98-reference/21-svelte-legacy.md
create mode 100644 documentation/docs/98-reference/21-svelte-motion.md
create mode 100644 documentation/docs/98-reference/21-svelte-reactivity.md
create mode 100644 documentation/docs/98-reference/21-svelte-server.md
create mode 100644 documentation/docs/98-reference/21-svelte-store.md
create mode 100644 documentation/docs/98-reference/21-svelte-transition.md
create mode 100644 documentation/docs/98-reference/index.md
create mode 100644 documentation/docs/index.md
diff --git a/documentation/docs/01-getting-started/meta.json b/documentation/docs/01-getting-started/meta.json
deleted file mode 100644
index 345e69a3c2..0000000000
--- a/documentation/docs/01-getting-started/meta.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "title": "Getting Started"
-}
diff --git a/documentation/docs/01-introduction/01-overview.md b/documentation/docs/01-introduction/01-overview.md
new file mode 100644
index 0000000000..a0901b9518
--- /dev/null
+++ b/documentation/docs/01-introduction/01-overview.md
@@ -0,0 +1,30 @@
+---
+title: Overview
+---
+
+- Short intro to what Svelte is and why it's the best ever
+- A few code examples to have a very rough understanding of how Svelte code looks like
+- Jump off points to tutorial, SvelteKit etc
+
+Svelte is a web UI framework that uses a compiler to turn declarative component code like this...
+
+```svelte
+
+
+
+
+```
+
+...into tightly optimized JavaScript that updates the document when state like count changes. Because the compiler can 'see' where count is referenced, the generated code is highly efficient, and because we're hijacking syntax like `$state(...)` and `=` instead of using cumbersome APIs, you can write less code.
+
+Besides being fun to work with, Svelte offers a lot of features built-in, such as animations and transitions. Once you've written your first components you can reach for our batteries included metaframework [SvelteKit](/docs/kit) which provides you with an opinionated router, data loading and more.
+
+If you're new to Svelte, visit the [interactive tutorial](/tutorial) before consulting this documentation. You can try Svelte online using the [REPL](/repl). Alternatively, if you'd like a more fully-featured environment, you can try Svelte on [StackBlitz](https://sveltekit.new).
diff --git a/documentation/docs/01-getting-started/01-introduction.md b/documentation/docs/01-introduction/02-getting-started.md
similarity index 52%
rename from documentation/docs/01-getting-started/01-introduction.md
rename to documentation/docs/01-introduction/02-getting-started.md
index 8d3c41ce1a..0f896abe18 100644
--- a/documentation/docs/01-getting-started/01-introduction.md
+++ b/documentation/docs/01-introduction/02-getting-started.md
@@ -1,10 +1,11 @@
---
-title: Introduction
+title: Getting started
---
-Welcome to the Svelte reference documentation! This is intended as a resource for people who already have some familiarity with Svelte and want to learn more about using it.
-
-If that's not you (yet), you may prefer to visit the [interactive tutorial](https://learn.svelte.dev) or the [examples](/examples) before consulting this reference. You can try Svelte online using the [REPL](/repl). Alternatively, if you'd like a more fully-featured environment, you can try Svelte on [StackBlitz](https://sveltekit.new).
+- `npm create svelte@latest`, describe that it scaffolds SvelteKit project
+- `npm create vite@latest`, describe that it scaffolds Svelte SPA powered by Vite
+- mention `svelte-add`
+- Jump off points to tutorial, SvelteKit etc
## Start a new project
@@ -19,15 +20,19 @@ npm run dev
SvelteKit will handle calling [the Svelte compiler](https://www.npmjs.com/package/svelte) to convert your `.svelte` files into `.js` files that create the DOM and `.css` files that style it. It also provides all the other pieces you need to build a web application such as a development server, routing, deployment, and SSR support. [SvelteKit](https://kit.svelte.dev/) uses [Vite](https://vitejs.dev/) to build your code.
+Don't worry if you don't know Svelte yet! You can ignore all the nice features SvelteKit brings on top for now and dive into it later.
+
### Alternatives to SvelteKit
-If you don't want to use SvelteKit for some reason, you can also use Svelte with Vite (but without SvelteKit) by running `npm create vite@latest` and selecting the `svelte` option. With this, `npm run build` will generate HTML, JS and CSS files inside the `dist` directory. In most cases, you will probably need to [choose a routing library](/faq#is-there-a-router) as well.
+If you don't want to use SvelteKit for some reason, you can also use Svelte with Vite (but without SvelteKit) by running `npm create vite@latest` and selecting the `svelte` option. With this, `npm run build` will generate HTML, JS and CSS files inside the `dist` directory thanks using [vite-plugin-svelte](https://github.com/sveltejs/vite-plugin-svelte). In most cases, you will probably need to [choose a routing library](faq#is-there-a-router) as well.
-Alternatively, there are [plugins for all the major web bundlers](https://sveltesociety.dev/tools#bundling) to handle Svelte compilation — which will output `.js` and `.css` that you can insert into your HTML — but most others won't handle SSR.
+Alternatively, there are plugins for [Rollup](https://github.com/sveltejs/rollup-plugin-svelte), [Webpack](https://github.com/sveltejs/svelte-loader) [and a few others](https://sveltesociety.dev/packages?category=build-plugins) to handle Svelte compilation — which will output `.js` and `.css` that you can insert into your HTML — but setting up SSR with them requires more manual work.
## Editor tooling
-The Svelte team maintains a [VS Code extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) and there are integrations with various other [editors](https://sveltesociety.dev/tools#editor-support) and tools as well.
+The Svelte team maintains a [VS Code extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) and there are integrations with various other [editors](https://sveltesociety.dev/resources#editor-support) and tools as well.
+
+You can also check your code from the command line using [svelte-check](https://www.npmjs.com/package/svelte-check) (using the Svelte or Vite CLI setup will install this for you).
## Getting help
diff --git a/documentation/docs/01-introduction/03-reactivity-fundamentals.md b/documentation/docs/01-introduction/03-reactivity-fundamentals.md
new file mode 100644
index 0000000000..0f1c8e0799
--- /dev/null
+++ b/documentation/docs/01-introduction/03-reactivity-fundamentals.md
@@ -0,0 +1,88 @@
+---
+title: Reactivity fundamentals
+---
+
+Reactivity is at the heart of interactive UIs. When you click a button, you expect some kind of response. It's your job as a developer to make this happen. It's Svelte's job to make your job as intuitive as possible, by providing a good API to express reactive systems.
+
+## Runes
+
+Svelte 5 uses _runes_, a powerful set of primitives for controlling reactivity inside your Svelte components and inside `.svelte.js` and `.svelte.ts` modules.
+
+Runes are function-like symbols that provide instructions to the Svelte compiler. You don't need to import them from anywhere — when you use Svelte, they're part of the language.
+
+The following sections introduce the most important runes for declare state, derived state and side effects at a high level. For more details refer to the later sections on [state](/docs/svelte/runes/state) and [side effects](/docs/svelte/runes/side-effects).
+
+## `$state`
+
+Reactive state is declared with the `$state` rune:
+
+```svelte
+
+
+
+```
+
+You can also use `$state` in class fields (whether public or private):
+
+```js
+// @errors: 7006 2554
+class Todo {
+ done = $state(false);
+ text = $state();
+
+ constructor(text) {
+ this.text = text;
+ }
+}
+```
+
+## `$derived`
+
+Derived state is declared with the `$derived` rune:
+
+```svelte
+
+
+
+
+
{count} doubled is {doubled}
+```
+
+The expression inside `$derived(...)` should be free of side-effects. Svelte will disallow state changes (e.g. `count++`) inside derived expressions.
+
+As with `$state`, you can mark class fields as `$derived`.
+
+## `$effect`
+
+To run _side-effects_ when the component is mounted to the DOM, and when values change, we can use the `$effect` rune ([demo](/#H4sIAAAAAAAAE31T24rbMBD9lUG7kAQ2sbdlX7xOYNk_aB_rQhRpbAsU2UiTW0P-vbrYubSlYGzmzMzROTPymdVKo2PFjzMzfIusYB99z14YnfoQuD1qQh-7bmdFQEonrOppVZmKNBI49QthCc-OOOH0LZ-9jxnR6c7eUpOnuv6KeT5JFdcqbvbcBcgDz1jXKGg6ncFyBedYR6IzLrAZwiN5vtSxaJA-EzadfJEjKw11C6GR22-BLH8B_wxdByWpvUYtqqal2XB6RVkG1CoHB6U1WJzbnYFDiwb3aGEdDa3Bm1oH12sQLTcNPp7r56m_00mHocSG97_zd7ICUXonA5fwKbPbkE2ZtMJGGVkEdctzQi4QzSwr9prnFYNk5hpmqVuqPQjNnfOJoMF22lUsrq_UfIN6lfSVyvQ7grB3X2mjMZYO3XO9w-U5iLx42qg29md3BP_ni5P4gy9ikTBlHxjLzAtPDlyYZmRdjAbGq7HprEQ7p64v4LU_guu0kvAkhBim3nMplWl8FreQD-CW20aZR0wq12t-KqDWeBywhvexKC3memmDwlHAv9q4Vo2ZK8KtK0CgX7u9J8wXbzdKv-nRnfF_2baTqlYoWUF2h5efl9-n0O6koAMAAA==)):
+
+```svelte
+
+
+
+```
+
+The function passed to `$effect` will run when the component mounts, and will re-run after any changes to the values it reads that were declared with `$state` or `$derived` (including those passed in with `$props`). Re-runs are batched (i.e. changing `color` and `size` in the same moment won't cause two separate runs), and happen after any DOM updates have been applied.
diff --git a/documentation/docs/01-introduction/index.md b/documentation/docs/01-introduction/index.md
new file mode 100644
index 0000000000..8f14f7a7c9
--- /dev/null
+++ b/documentation/docs/01-introduction/index.md
@@ -0,0 +1,3 @@
+---
+title: Introduction
+---
diff --git a/documentation/docs/02-template-syntax/01-component-fundamentals.md b/documentation/docs/02-template-syntax/01-component-fundamentals.md
new file mode 100644
index 0000000000..5e4d78e59a
--- /dev/null
+++ b/documentation/docs/02-template-syntax/01-component-fundamentals.md
@@ -0,0 +1,184 @@
+---
+title: Component fundamentals
+---
+
+- script (module) / template / style (rough overview)
+- `$props` / `$state` (in the context of components)
+
+Components are the building blocks of Svelte applications. They are written into `.svelte` files, using a superset of HTML.
+
+All three sections — script, styles and markup — are optional.
+
+```svelte
+
+
+
+
+
+```
+
+## <script>
+
+A `
+```
+
+You can specify a fallback value for a prop. It will be used if the component's consumer doesn't specify the prop on the component when instantiating the component, or if the passed value is `undefined` at some point.
+
+```svelte
+
+```
+
+To get all properties, use rest syntax:
+
+```svelte
+
+```
+
+You can use reserved words as prop names.
+
+```svelte
+
+```
+
+If you're using TypeScript, you can declare the prop types:
+
+```svelte
+
+```
+
+If you export a `const`, `class` or `function`, it is readonly from outside the component.
+
+```svelte
+
+```
+
+Readonly props can be accessed as properties on the element, tied to the component using [`bind:this` syntax](/docs/component-directives#bind-this).
+
+### Reactive variables
+
+To change component state and trigger a re-render, just assign to a locally declared variable that was declared using the `$state` rune.
+
+Update expressions (`count += 1`) and property assignments (`obj.x = y`) have the same effect.
+
+```svelte
+
+```
+
+Svelte's `
+```
+
+If you'd like to react to changes to a prop, use the `$derived` or `$effect` runes instead.
+
+```svelte
+
+```
+
+For more information on reactivity, read the documentation around runes.
+
+## <script context="module">
+
+A `
+
+
+```
+
+## <style>
+
+CSS inside a `
+```
+
+For more information regarding styling, read the documentation around [styles and classes](styles-and-classes).
diff --git a/documentation/docs/02-template-syntax/01-svelte-components.md b/documentation/docs/02-template-syntax/01-svelte-components.md
deleted file mode 100644
index e05a90a4c4..0000000000
--- a/documentation/docs/02-template-syntax/01-svelte-components.md
+++ /dev/null
@@ -1,350 +0,0 @@
----
-title: Svelte components
----
-
-Components are the building blocks of Svelte applications. They are written into `.svelte` files, using a superset of HTML.
-
-All three sections — script, styles and markup — are optional.
-
-```svelte
-
-
-
-
-
-```
-
-## <script>
-
-A `
-```
-
-You can specify a default initial value for a prop. It will be used if the component's consumer doesn't specify the prop on the component (or if its initial value is `undefined`) when instantiating the component. Note that if the values of props are subsequently updated, then any prop whose value is not specified will be set to `undefined` (rather than its initial value).
-
-In development mode (see the [compiler options](/docs/svelte-compiler#compile)), a warning will be printed if no default initial value is provided and the consumer does not specify a value. To squelch this warning, ensure that a default initial value is specified, even if it is `undefined`.
-
-```svelte
-
-```
-
-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
-
-
-```
-
-Readonly props can be accessed as properties on the element, tied to the component using [`bind:this` syntax](/docs/component-directives#bind-this).
-
-You can use reserved words as prop names.
-
-```svelte
-
-
-```
-
-### 2. Assignments are 'reactive'
-
-To change component state and trigger a re-render, just assign to a locally declared variable.
-
-Update expressions (`count += 1`) and property assignments (`obj.x = y`) have the same effect.
-
-```svelte
-
-```
-
-Because Svelte's reactivity is based on assignments, using array methods like `.push()` and `.splice()` won't automatically trigger updates. A subsequent assignment is required to trigger the update. This and more details can also be found in the [tutorial](https://learn.svelte.dev/tutorial/updating-arrays-and-objects).
-
-```svelte
-
-```
-
-Svelte's `
-```
-
-### 3. `$:` marks a statement as reactive
-
-Any top-level statement (i.e. not inside a block or a function) can be made reactive by prefixing it with the `$:` [JS label syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label). Reactive statements run after other script code and before the component markup is rendered, whenever the values that they depend on have changed.
-
-```svelte
-
-```
-
-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
-
-
-
-Total: {total}
-
-
-
-```
-
-It is important to note that the reactive blocks are ordered via simple static analysis at compile time, and all the compiler looks at are the variables that are assigned to and used within the block itself, not in any functions called by them. This means that `yDependent` will not be updated when `x` is updated in the following example:
-
-```svelte
-
-```
-
-Moving the line `$: yDependent = y` below `$: setY(x)` will cause `yDependent` to be updated when `x` is updated.
-
-If a statement consists entirely of an assignment to an undeclared variable, Svelte will inject a `let` declaration on your behalf.
-
-```svelte
-
-
-```
-
-### 4. Prefix stores with `$` to access their values
-
-A _store_ is an object that allows reactive access to a value via a simple _store contract_. The [`svelte/store` module](/docs/svelte-store) contains minimal store implementations which fulfil this contract.
-
-Any time you have a reference to a store, you can access its value inside a component by prefixing it with the `$` character. This causes Svelte to declare the prefixed variable, subscribe to the store at component initialisation and unsubscribe when appropriate.
-
-Assignments to `$`-prefixed variables require that the variable be a writable store, and will result in a call to the store's `.set` method.
-
-Note that the store must be declared at the top level of the component — not inside an `if` block or a function, for example.
-
-Local variables (that do not represent store values) must _not_ have a `$` prefix.
-
-```svelte
-
-```
-
-#### Store contract
-
-```ts
-// @noErrors
-store = { subscribe: (subscription: (value: any) => void) => (() => void), set?: (value: any) => void }
-```
-
-You can create your own stores without relying on [`svelte/store`](/docs/svelte-store), by implementing the _store contract_:
-
-1. A store must contain a `.subscribe` method, which must accept as its argument a subscription function. This subscription function must be immediately and synchronously called with the store's current value upon calling `.subscribe`. All of a store's active subscription functions must later be synchronously called whenever the store's value changes.
-2. The `.subscribe` method must return an unsubscribe function. Calling an unsubscribe function must stop its subscription, and its corresponding subscription function must not be called again by the store.
-3. A store may _optionally_ contain a `.set` method, which must accept as its argument a new value for the store, and which synchronously calls all of the store's active subscription functions. Such a store is called a _writable store_.
-
-For interoperability with RxJS Observables, the `.subscribe` method is also allowed to return an object with an `.unsubscribe` method, rather than return the unsubscription function directly. Note however that unless `.subscribe` synchronously calls the subscription (which is not required by the Observable spec), Svelte will see the value of the store as `undefined` until it does.
-
-## <script context="module">
-
-A `
-
-
-```
-
-## <style>
-
-CSS inside a `
-```
-
-To apply styles to a selector globally, use the `:global(...)` modifier.
-
-```svelte
-
-```
-
-If you want to make @keyframes that are accessible globally, you need to prepend your keyframe names with `-global-`.
-
-The `-global-` part will be removed when compiled, and the keyframe will then be referenced using just `my-animation-name` elsewhere in your code.
-
-```svelte
-
-```
-
-There should only be 1 top-level `
-
-```
diff --git a/documentation/docs/02-template-syntax/02-basic-markup.md b/documentation/docs/02-template-syntax/02-basic-markup.md
index e6192230d4..9a002bf5a7 100644
--- a/documentation/docs/02-template-syntax/02-basic-markup.md
+++ b/documentation/docs/02-template-syntax/02-basic-markup.md
@@ -2,6 +2,8 @@
title: Basic markup
---
+- [basically what we have in the Svelte docs today](https://svelte.dev/docs/basic-markup)
+
## Tags
A lowercase tag, like `
`, denotes a regular HTML element. A capitalised tag, such as `` or ``, indicates a _component_.
@@ -54,7 +56,7 @@ All other attributes are included unless their value is [nullish](https://develo
This div has no title attribute
```
-An expression might include characters that would cause syntax highlighting to fail in regular HTML, so quoting the value is permitted. The quotes do not affect how the value is parsed:
+Quoting a singular expression does not affect how the value is parsed yet, but in Svelte 6 it will:
```svelte
@@ -86,23 +88,62 @@ An element or component can have multiple spread attributes, interspersed with r
```
-`$$props` references all props that are passed to a component, including ones that are not declared with `export`. Using `$$props` will not perform as well as references to a specific prop because changes to any prop will cause Svelte to recheck all usages of `$$props`. But it can be useful in some cases – for example, when you don't know at compile time what props might be passed to a component.
+> The `value` attribute of an `input` element or its children `option` elements must not be set with spread attributes when using `bind:group` or `bind:checked`. Svelte needs to be able to see the element's `value` directly in the markup in these cases so that it can link it to the bound variable.
-```svelte
-
-```
+> Sometimes, the attribute order matters as Svelte sets attributes sequentially in JavaScript. For example, ``, Svelte will attempt to set the value to `1` (rounding up from 0.5 as the step by default is 1), and then set the step to `0.1`. To fix this, change it to ``.
+
+> Another example is ``. Svelte will set the img `src` before making the img element `loading="lazy"`, which is probably too late. Change this to `` to make the image lazily loaded.
-`$$restProps` contains only the props which are _not_ declared with `export`. It can be used to pass down other unknown attributes to an element in a component. It shares the same performance characteristics compared to specific property access as `$$props`.
+## Events
+
+Listening to DOM events is possible by adding attributes to the element that start with `on`. For example, to listen to the `click` event, add the `onclick` attribute to a button:
```svelte
-
+
```
-> The `value` attribute of an `input` element or its children `option` elements must not be set with spread attributes when using `bind:group` or `bind:checked`. Svelte needs to be able to see the element's `value` directly in the markup in these cases so that it can link it to the bound variable.
+Event attributes are case sensitive. `onclick` listens to the `click` event, `onClick` listens to the `Click` event, which is different. This ensures you can listen to custom events that have uppercase characters in them.
-> Sometimes, the attribute order matters as Svelte sets attributes sequentially in JavaScript. For example, ``, Svelte will attempt to set the value to `1` (rounding up from 0.5 as the step by default is 1), and then set the step to `0.1`. To fix this, change it to ``.
+Because events are just attributes, the same rules as for attributes apply:
-> Another example is ``. Svelte will set the img `src` before making the img element `loading="lazy"`, which is probably too late. Change this to `` to make the image lazily loaded.
+- you can use the shorthand form: ``
+- you can spread them: ``
+- component events are just (callback) properties and don't need a separate concept
+
+### Event delegation
+
+To reduce the memory footprint and increase performance, Svelte uses a technique called event delegation. This means that certain events are only listened to once at the application root, invoking a handler that then traverses the event call path and invokes listeners along the way.
+
+There are a few gotchas you need to be aware of when it comes to event delegation:
+
+- when you dispatch events manually, make sure to set the `{ bubbles: true }` option
+- when listening to events programmatically (i.e. not through `
` is not valid HTML. It also will _not_ compile Svelte code.
-
-> Svelte does not sanitize expressions before injecting HTML. If the data comes from an untrusted source, you must sanitize it, or you are exposing your users to an XSS vulnerability.
-
-```svelte
-
-
{post.title}
- {@html post.content}
-
-```
-
-## {@debug ...}
-
-```svelte
-
-{@debug}
-```
-
-```svelte
-
-{@debug var1, var2, ..., varN}
-```
-
-The `{@debug ...}` tag offers an alternative to `console.log(...)`. It logs the values of specific variables whenever they change, and pauses code execution if you have devtools open.
-
-```svelte
-
-
-{@debug user}
-
-
Hello {user.firstname}!
-```
-
-`{@debug ...}` accepts a comma-separated list of variable names (not arbitrary expressions).
-
-```svelte
-
-{@debug user}
-{@debug user1, user2, user3}
-
-
-{@debug user.firstname}
-{@debug myArray[0]}
-{@debug !isReady}
-{@debug typeof user === 'object'}
-```
-
-The `{@debug}` tag without any arguments will insert a `debugger` statement that gets triggered when _any_ state changes, as opposed to the specified variables.
-
-## {@const ...}
-
-```svelte
-
-{@const assignment}
-```
-
-The `{@const ...}` tag defines a local constant.
-
-```svelte
-
-
-{#each boxes as box}
- {@const area = box.width * box.height}
- {box.width} * {box.height} = {area}
-{/each}
-```
-
-`{@const}` is only allowed as direct child of `{#if}`, `{:else if}`, `{:else}`, `{#each}`, `{:then}`, `{:catch}`, `` or ``.
diff --git a/documentation/docs/02-template-syntax/05-element-directives.md b/documentation/docs/02-template-syntax/05-element-directives.md
deleted file mode 100644
index f9ff1821c8..0000000000
--- a/documentation/docs/02-template-syntax/05-element-directives.md
+++ /dev/null
@@ -1,863 +0,0 @@
----
-title: Element directives
----
-
-As well as attributes, elements can have _directives_, which control the element's behaviour in some way.
-
-## on:_eventname_
-
-```svelte
-
-on:eventname={handler}
-```
-
-```svelte
-
-on:eventname|modifiers={handler}
-```
-
-Use the `on:` directive to listen to DOM events.
-
-```svelte
-
-
-
-
- count: {count}
-
-```
-
-Handlers can be declared inline with no performance penalty. As with attributes, directive values may be quoted for the sake of syntax highlighters.
-
-```svelte
- (count += 1)}>
- count: {count}
-
-```
-
-Add _modifiers_ to DOM events with the `|` character.
-
-```svelte
-
-```
-
-The following modifiers are available:
-
-- `preventDefault` — calls `event.preventDefault()` before running the handler
-- `stopPropagation` — calls `event.stopPropagation()`, preventing the event reaching the next element
-- `stopImmediatePropagation` - calls `event.stopImmediatePropagation()`, preventing other listeners of the same event from being fired.
-- `passive` — improves scrolling performance on touch/wheel events (Svelte will add it automatically where it's safe to do so)
-- `nonpassive` — explicitly set `passive: false`
-- `capture` — fires the handler during the _capture_ phase instead of the _bubbling_ phase
-- `once` — remove the handler after the first time it runs
-- `self` — only trigger handler if `event.target` is the element itself
-- `trusted` — only trigger handler if `event.isTrusted` is `true`. I.e. if the event is triggered by a user action.
-
-Modifiers can be chained together, e.g. `on:click|once|capture={...}`.
-
-If the `on:` directive is used without a value, the component will _forward_ the event, meaning that a consumer of the component can listen for it.
-
-```svelte
- The component itself will emit the click event
-```
-
-It's possible to have multiple event listeners for the same event:
-
-```svelte
-
-
-Click me!
-```
-
-## bind:_property_
-
-```svelte
-
-bind:property={variable}
-```
-
-Data ordinarily flows down, from parent to child. The `bind:` directive allows data to flow the other way, from child to parent. Most bindings are specific to particular elements.
-
-The simplest bindings reflect the value of a property, such as `input.value`.
-
-```svelte
-
-
-
-
-```
-
-If the name matches the value, you can use a shorthand.
-
-```svelte
-
-
-```
-
-Numeric input values are coerced; even though `input.value` is a string as far as the DOM is concerned, Svelte will treat it as a number. If the input is empty or invalid (in the case of `type="number"`), the value is `undefined`.
-
-```svelte
-
-
-```
-
-On `` elements with `type="file"`, you can use `bind:files` to get the [`FileList` of selected files](https://developer.mozilla.org/en-US/docs/Web/API/FileList). It is readonly.
-
-```svelte
-
-
-```
-
-If you're using `bind:` directives together with `on:` directives, the order that they're defined in affects the value of the bound variable when the event handler is called.
-
-```svelte
-
-
- console.log('Old value:', value)}
- bind:value
- on:input={() => console.log('New value:', value)}
-/>
-```
-
-Here we were binding to the value of a text input, which uses the `input` event. Bindings on other elements may use different events such as `change`.
-
-## Binding `