diff --git a/site/content/tutorial/01-introduction/07-making-an-app/text.md b/site/content/tutorial/01-introduction/07-making-an-app/text.md index f6f32cd626..136c6b5f07 100644 --- a/site/content/tutorial/01-introduction/07-making-an-app/text.md +++ b/site/content/tutorial/01-introduction/07-making-an-app/text.md @@ -12,6 +12,8 @@ First, you'll need to integrate Svelte with a build tool. Popular choices are: Don't worry if you're relatively new to web development and haven't used these tools before. We've prepared a simple step-by-step guide, [Svelte for new developers](blog/svelte-for-new-developers), which walks you through the process. +You'll also want to configure your text editor to treat `.svelte` files the same as `.html` for the sake of syntax highlighting. [Read this guide to learn how](blog/setting-up-your-editor). + Then, once you've got your project set up, using Svelte components is easy. The compiler turns each component into a regular JavaScript class — just import it and instantiate with `new`: ```js @@ -26,4 +28,4 @@ const app = new App({ }); ``` -You can then interact with `app` using the [component API](docs/component-api) if you need to. \ No newline at end of file +You can then interact with `app` using the [component API](docs/component-api) if you need to. diff --git a/site/content/tutorial/03-logic/04-each-blocks/text.md b/site/content/tutorial/03-logic/04-each-blocks/text.md index 3fbe56398a..e5aa9b16db 100644 --- a/site/content/tutorial/03-logic/04-each-blocks/text.md +++ b/site/content/tutorial/03-logic/04-each-blocks/text.md @@ -14,4 +14,6 @@ If you need to loop over lists of data, use an `each` block: > The expression (`cats`, in this case) can be any array or array-like object (i.e. it has a `length` property). You can loop over generic iterables with `each [...iterable]`. -If you prefer, you can use destructuring — `each cats as { id, name }` — and replace `cat.id` and `cat.name` with `id` and `name`. \ No newline at end of file +If you prefer, you can use destructuring — `each cats as { id, name }` — and replace `cat.id` and `cat.name` with `id` and `name`. + +> In some cases, you will need to use *keyed each blocks*. We'll learn about those [later](tutorial/keyed-each-blocks). \ No newline at end of file diff --git a/site/content/tutorial/04-props/01-declaring-props/app-a/App.svelte b/site/content/tutorial/04-props/01-declaring-props/app-a/App.svelte new file mode 100644 index 0000000000..79d7e6b789 --- /dev/null +++ b/site/content/tutorial/04-props/01-declaring-props/app-a/App.svelte @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/04-props/01-declaring-props/app-a/Nested.svelte b/site/content/tutorial/04-props/01-declaring-props/app-a/Nested.svelte new file mode 100644 index 0000000000..da9270c7a2 --- /dev/null +++ b/site/content/tutorial/04-props/01-declaring-props/app-a/Nested.svelte @@ -0,0 +1,5 @@ + + +

The answer is {answer}

\ No newline at end of file diff --git a/site/content/tutorial/04-props/01-declaring-props/app-b/App.svelte b/site/content/tutorial/04-props/01-declaring-props/app-b/App.svelte new file mode 100644 index 0000000000..79d7e6b789 --- /dev/null +++ b/site/content/tutorial/04-props/01-declaring-props/app-b/App.svelte @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/04-props/01-declaring-props/app-b/Nested.svelte b/site/content/tutorial/04-props/01-declaring-props/app-b/Nested.svelte new file mode 100644 index 0000000000..ecd3cb6254 --- /dev/null +++ b/site/content/tutorial/04-props/01-declaring-props/app-b/Nested.svelte @@ -0,0 +1,5 @@ + + +

The answer is {answer}

\ No newline at end of file diff --git a/site/content/tutorial/04-props/01-declaring-props/text.md b/site/content/tutorial/04-props/01-declaring-props/text.md new file mode 100644 index 0000000000..26e6762106 --- /dev/null +++ b/site/content/tutorial/04-props/01-declaring-props/text.md @@ -0,0 +1,15 @@ +--- +title: Declaring props +--- + +So far, we've dealt exclusively with internal state — that is to say, the values are only accessible within a given component. + +In any real application, you'll need to pass data from one component down to its children. To do that, we need to declare *properties*, generally shortened to 'props'. In Svelte, we do that with the `export` keyword. Edit the `Nested.svelte` component: + +```html + +``` + +> Just like `$:`, this may feel a little weird at first. That's not how `export` normally works in JavaScript modules! Just roll with it for now — it'll soon become second nature. \ No newline at end of file diff --git a/site/content/tutorial/04-props/02-default-values/app-a/App.svelte b/site/content/tutorial/04-props/02-default-values/app-a/App.svelte new file mode 100644 index 0000000000..79d7e6b789 --- /dev/null +++ b/site/content/tutorial/04-props/02-default-values/app-a/App.svelte @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/04-props/02-default-values/app-a/Nested.svelte b/site/content/tutorial/04-props/02-default-values/app-a/Nested.svelte new file mode 100644 index 0000000000..ecd3cb6254 --- /dev/null +++ b/site/content/tutorial/04-props/02-default-values/app-a/Nested.svelte @@ -0,0 +1,5 @@ + + +

The answer is {answer}

\ No newline at end of file diff --git a/site/content/tutorial/04-props/02-default-values/app-b/App.svelte b/site/content/tutorial/04-props/02-default-values/app-b/App.svelte new file mode 100644 index 0000000000..f9d63b30d6 --- /dev/null +++ b/site/content/tutorial/04-props/02-default-values/app-b/App.svelte @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/site/content/tutorial/04-props/02-default-values/app-b/Nested.svelte b/site/content/tutorial/04-props/02-default-values/app-b/Nested.svelte new file mode 100644 index 0000000000..35ee5c9f88 --- /dev/null +++ b/site/content/tutorial/04-props/02-default-values/app-b/Nested.svelte @@ -0,0 +1,5 @@ + + +

The answer is {answer}

\ No newline at end of file diff --git a/site/content/tutorial/04-props/02-default-values/text.md b/site/content/tutorial/04-props/02-default-values/text.md new file mode 100644 index 0000000000..dda6a370fe --- /dev/null +++ b/site/content/tutorial/04-props/02-default-values/text.md @@ -0,0 +1,18 @@ +--- +title: Default values +--- + +We can easily specify default values for props: + +```html + +``` + +If we now instantiate the component without an `answer` prop, it will fall back to the default: + +```html + + +``` \ No newline at end of file diff --git a/site/content/tutorial/04-props/meta.json b/site/content/tutorial/04-props/meta.json new file mode 100644 index 0000000000..7b9e0a2783 --- /dev/null +++ b/site/content/tutorial/04-props/meta.json @@ -0,0 +1,3 @@ +{ + "title": "Props" +} \ No newline at end of file diff --git a/site/content/tutorial/05-events/01-dom-events/app-a/App.svelte b/site/content/tutorial/05-events/01-dom-events/app-a/App.svelte new file mode 100644 index 0000000000..dce67f6368 --- /dev/null +++ b/site/content/tutorial/05-events/01-dom-events/app-a/App.svelte @@ -0,0 +1,16 @@ + + + + +
+ The mouse position is {m.x} x {m.y} +
\ No newline at end of file diff --git a/site/content/tutorial/05-events/01-dom-events/app-b/App.svelte b/site/content/tutorial/05-events/01-dom-events/app-b/App.svelte new file mode 100644 index 0000000000..f26112f06c --- /dev/null +++ b/site/content/tutorial/05-events/01-dom-events/app-b/App.svelte @@ -0,0 +1,16 @@ + + + + +
+ The mouse position is {m.x} x {m.y} +
\ No newline at end of file diff --git a/site/content/tutorial/05-events/01-dom-events/text.md b/site/content/tutorial/05-events/01-dom-events/text.md new file mode 100644 index 0000000000..b8a4cf0332 --- /dev/null +++ b/site/content/tutorial/05-events/01-dom-events/text.md @@ -0,0 +1,11 @@ +--- +title: DOM events +--- + +As we briefly saw in an [earlier chapter](tutorial/reactive-assignments), you can listen to any event on an element with the `on:` directive: + +```html +
+ The mouse position is {m.x} x {m.y} +
+``` \ No newline at end of file diff --git a/site/content/tutorial/05-events/02-inline-handlers/app-a/App.svelte b/site/content/tutorial/05-events/02-inline-handlers/app-a/App.svelte new file mode 100644 index 0000000000..f26112f06c --- /dev/null +++ b/site/content/tutorial/05-events/02-inline-handlers/app-a/App.svelte @@ -0,0 +1,16 @@ + + + + +
+ The mouse position is {m.x} x {m.y} +
\ No newline at end of file diff --git a/site/content/tutorial/05-events/02-inline-handlers/app-b/App.svelte b/site/content/tutorial/05-events/02-inline-handlers/app-b/App.svelte new file mode 100644 index 0000000000..f0fd6ff17a --- /dev/null +++ b/site/content/tutorial/05-events/02-inline-handlers/app-b/App.svelte @@ -0,0 +1,11 @@ + + + + +
+ The mouse position is {m.x} x {m.y} +
\ No newline at end of file diff --git a/site/content/tutorial/05-events/02-inline-handlers/text.md b/site/content/tutorial/05-events/02-inline-handlers/text.md new file mode 100644 index 0000000000..0ec177cb44 --- /dev/null +++ b/site/content/tutorial/05-events/02-inline-handlers/text.md @@ -0,0 +1,15 @@ +--- +title: Inline handlers +--- + +You can also declare event handlers inline: + +```html +
+ The mouse position is {m.x} x {m.y} +
+``` + +The quote marks are optional, but they're helpful for syntax highlighting in some environments. + +> In some frameworks you may see recommendations to avoid inline event handlers for performance reasons, particularly inside loops. That advice doesn't apply to Svelte — the compiler will always do the right thing, whichever form you choose. \ No newline at end of file diff --git a/site/content/tutorial/05-events/03-event-modifiers/app-a/App.svelte b/site/content/tutorial/05-events/03-event-modifiers/app-a/App.svelte new file mode 100644 index 0000000000..e49115d4f1 --- /dev/null +++ b/site/content/tutorial/05-events/03-event-modifiers/app-a/App.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/03-event-modifiers/app-b/App.svelte b/site/content/tutorial/05-events/03-event-modifiers/app-b/App.svelte new file mode 100644 index 0000000000..94df49cb2d --- /dev/null +++ b/site/content/tutorial/05-events/03-event-modifiers/app-b/App.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/03-event-modifiers/text.md b/site/content/tutorial/05-events/03-event-modifiers/text.md new file mode 100644 index 0000000000..c9ac851408 --- /dev/null +++ b/site/content/tutorial/05-events/03-event-modifiers/text.md @@ -0,0 +1,27 @@ +--- +title: Event modifiers +--- + +DOM event handlers can have *modifiers* that alter their behaviour. For example, a handler with a `once` modifier will only run a single time: + +```html + + + +``` + +The full list of modifiers: + +* `preventDefault` — calls `event.preventDefault()` before running the handler. Useful for e.g. client-side form handling +* `stopPropagation` — calls `event.stopPropagation()`, preventing the event reaching the next element +* `passive` — improves scrolling performance on touch/wheel events (Svelte will add it automatically where it's safe to do so) +* `capture` — fires the handler during the *capture* phase instead of the *bubbling* phase +* `once` + +You can chain modifiers together, e.g. `on:click|once|capture={...}`. \ No newline at end of file diff --git a/site/content/tutorial/05-events/04-component-events/app-a/App.svelte b/site/content/tutorial/05-events/04-component-events/app-a/App.svelte new file mode 100644 index 0000000000..a8d14a368a --- /dev/null +++ b/site/content/tutorial/05-events/04-component-events/app-a/App.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/04-component-events/app-a/Inner.svelte b/site/content/tutorial/05-events/04-component-events/app-a/Inner.svelte new file mode 100644 index 0000000000..0a7980c45c --- /dev/null +++ b/site/content/tutorial/05-events/04-component-events/app-a/Inner.svelte @@ -0,0 +1,11 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/04-component-events/app-b/App.svelte b/site/content/tutorial/05-events/04-component-events/app-b/App.svelte new file mode 100644 index 0000000000..a8d14a368a --- /dev/null +++ b/site/content/tutorial/05-events/04-component-events/app-b/App.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/04-component-events/app-b/Inner.svelte b/site/content/tutorial/05-events/04-component-events/app-b/Inner.svelte new file mode 100644 index 0000000000..6ac8301f24 --- /dev/null +++ b/site/content/tutorial/05-events/04-component-events/app-b/Inner.svelte @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/04-component-events/text.md b/site/content/tutorial/05-events/04-component-events/text.md new file mode 100644 index 0000000000..222a292b5f --- /dev/null +++ b/site/content/tutorial/05-events/04-component-events/text.md @@ -0,0 +1,21 @@ +--- +title: Component events +--- + +Components can also dispatch events. To do so, they must create an event dispatcher. Update `Inner.svelte`: + +```html + +``` + +> `createEventDispatcher` must be called when the component is first instantiated — you can't do it later inside e.g. a `setTimeout` callback. This links `dispatch` to the component instance. \ No newline at end of file diff --git a/site/content/tutorial/05-events/05-event-forwarding/app-a/App.svelte b/site/content/tutorial/05-events/05-event-forwarding/app-a/App.svelte new file mode 100644 index 0000000000..973df50f0a --- /dev/null +++ b/site/content/tutorial/05-events/05-event-forwarding/app-a/App.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/05-event-forwarding/app-a/Inner.svelte b/site/content/tutorial/05-events/05-event-forwarding/app-a/Inner.svelte new file mode 100644 index 0000000000..6ac8301f24 --- /dev/null +++ b/site/content/tutorial/05-events/05-event-forwarding/app-a/Inner.svelte @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/05-event-forwarding/app-a/Outer.svelte b/site/content/tutorial/05-events/05-event-forwarding/app-a/Outer.svelte new file mode 100644 index 0000000000..6c13070e79 --- /dev/null +++ b/site/content/tutorial/05-events/05-event-forwarding/app-a/Outer.svelte @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/05-event-forwarding/app-b/App.svelte b/site/content/tutorial/05-events/05-event-forwarding/app-b/App.svelte new file mode 100644 index 0000000000..973df50f0a --- /dev/null +++ b/site/content/tutorial/05-events/05-event-forwarding/app-b/App.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/05-event-forwarding/app-b/Inner.svelte b/site/content/tutorial/05-events/05-event-forwarding/app-b/Inner.svelte new file mode 100644 index 0000000000..6ac8301f24 --- /dev/null +++ b/site/content/tutorial/05-events/05-event-forwarding/app-b/Inner.svelte @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/05-event-forwarding/app-b/Outer.svelte b/site/content/tutorial/05-events/05-event-forwarding/app-b/Outer.svelte new file mode 100644 index 0000000000..10c28f298a --- /dev/null +++ b/site/content/tutorial/05-events/05-event-forwarding/app-b/Outer.svelte @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/05-event-forwarding/text.md b/site/content/tutorial/05-events/05-event-forwarding/text.md new file mode 100644 index 0000000000..b65a028f27 --- /dev/null +++ b/site/content/tutorial/05-events/05-event-forwarding/text.md @@ -0,0 +1,34 @@ +--- +title: Event forwarding +--- + +Unlike DOM events, component events don't *bubble*. If you want to listen to an event on some deeply nested component, the intermediate components must *forward* the event. + +In this case, we have the same `App.svelte` and `Inner.svelte` as in the [previous chapter](tutorial/component-events), but there's now an `Outer.svelte` component that contains ``. + +One way we could solve the problem is adding `createEventDispatcher` to `Outer.svelte`, listening for the `message` event, and creating a handler for it: + +```html + + + +``` + +But that's a lot of code to write, so Svelte gives us an equivalent shorthand — an `on:message` event directive without a value means 'forward all `message` events'. + +```html + + + +``` \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/App.svelte b/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/App.svelte new file mode 100644 index 0000000000..1429cae207 --- /dev/null +++ b/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/App.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/FancyButton.svelte b/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/FancyButton.svelte new file mode 100644 index 0000000000..9c3ae75809 --- /dev/null +++ b/site/content/tutorial/05-events/06-dom-event-forwarding/app-a/FancyButton.svelte @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/App.svelte b/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/App.svelte new file mode 100644 index 0000000000..1429cae207 --- /dev/null +++ b/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/App.svelte @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/FancyButton.svelte b/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/FancyButton.svelte new file mode 100644 index 0000000000..75630ea99c --- /dev/null +++ b/site/content/tutorial/05-events/06-dom-event-forwarding/app-b/FancyButton.svelte @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/site/content/tutorial/05-events/06-dom-event-forwarding/text.md b/site/content/tutorial/05-events/06-dom-event-forwarding/text.md new file mode 100644 index 0000000000..0959e1d98b --- /dev/null +++ b/site/content/tutorial/05-events/06-dom-event-forwarding/text.md @@ -0,0 +1,13 @@ +--- +title: DOM event forwarding +--- + +Event forwarding works for DOM events too. + +We want to get notified of clicks on our `` — to do that, we just need to forward `click` events on the ` +``` \ No newline at end of file diff --git a/site/content/tutorial/05-events/meta.json b/site/content/tutorial/05-events/meta.json new file mode 100644 index 0000000000..c5f088e208 --- /dev/null +++ b/site/content/tutorial/05-events/meta.json @@ -0,0 +1,3 @@ +{ + "title": "Events" +} \ No newline at end of file diff --git a/site/content/tutorial/99-todo/99-todo/text.md b/site/content/tutorial/99-todo/99-todo/text.md index fe8583e145..d2b8d10f40 100644 --- a/site/content/tutorial/99-todo/99-todo/text.md +++ b/site/content/tutorial/99-todo/99-todo/text.md @@ -27,6 +27,8 @@ Outline (subject to change): Side-quest: create a 'Svelte for new developers' blog post that assumes no knowledge beyond HTML, CSS and JS (i.e. CLI, Node and npm, degit, build tools) +Another one should cover how to set up an editor for syntax highlighting. + ## Reactivity @@ -39,23 +41,28 @@ Side-quest: create a 'Svelte for new developers' blog post that assumes no knowl * [x] If blocks * [x] Else/elseif blocks -* [ ] Each blocks -* [ ] Keyed each blocks (maybe? kind of need to cover transitions before we can make this obvious) +* [x] Each blocks * [ ] Await blocks +* [ ] Keyed each blocks (maybe? kind of need to cover transitions before we can make this obvious) + + ## Props -* [ ] `export let foo` -* [ ] `export let foo = 1` +* [x] `export let foo` +* [x] `export let foo = 1` + + * [ ] `export function foo(){...}` ## Events -* [ ] `createEventDispatcher` and `dispatch` -* [ ] `on:blah` -* [ ] DOM event modifiers +* [x] `on:blah` +* [x] DOM event modifiers +* [x] `createEventDispatcher` and `dispatch` +* [x] shorthand events ## Bindings @@ -96,6 +103,7 @@ Side-quest: create a 'Svelte for new developers' blog post that assumes no knowl * [ ] Custom JS transitions * [ ] `in` * [ ] `out` +* [ ] `on:introstart` etc ## Animations @@ -132,4 +140,13 @@ Side-quest: create a 'Svelte for new developers' blog post that assumes no knowl ## Miscellaneous * Keyed each blocks -* Debug tags \ No newline at end of file +* Debug tags +* `context="module"` + + +--- + +## Bugs etc + +* 'Show me' should be greyed out if current state is identical to target state +* Clicking 'Show me' shouldn't change the file you're looking at \ No newline at end of file diff --git a/site/src/components/Repl/Output/Viewer.svelte b/site/src/components/Repl/Output/Viewer.svelte index f146b9d6fc..7602a56152 100644 --- a/site/src/components/Repl/Output/Viewer.svelte +++ b/site/src/components/Repl/Output/Viewer.svelte @@ -284,7 +284,7 @@
-