diff --git a/README.md b/README.md index 96190a8c66..b60b1ad653 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ npm run test -- -g transition ## svelte.dev -The source code for https://svelte.dev, including all the documentation, lives in the [site](site) directory. The site is built with [Sapper](https://sapper.svelte.technology). To develop locally: +The source code for https://svelte.dev, including all the documentation, lives in the [site](site) directory. The site is built with [Sapper](https://sapper.svelte.dev). To develop locally: ```bash cd site diff --git a/package-lock.json b/package-lock.json index 79b4a3d5fa..7c7363db2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.0.0-beta.25", + "version": "3.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 85836aaa14..5659f4215d 100644 --- a/package.json +++ b/package.json @@ -92,5 +92,6 @@ ], "sourceMap": true, "instrument": true - } + }, + "dependencies": {} } diff --git a/site/README.md b/site/README.md index 223830b3fa..c438bda5ca 100644 --- a/site/README.md +++ b/site/README.md @@ -17,16 +17,20 @@ By default, the REPL will fetch the most recent version of Svelte from https://u ## REPL GitHub integration -In order for the REPL's GitHub integration to work properly when running locally, you will need to create a GitHub OAuth app. Set its authorization callback URL to `http://localhost:3000/auth/callback`, and in this project, create `site/.env` containing: - -``` -GITHUB_CLIENT_ID=[your app's client id] -GITHUB_CLIENT_SECRET=[your app's client secret] -BASEURL=http://localhost:3000 -``` +In order for the REPL's GitHub integration to work properly when running locally, you will need to: +- [create a GitHub OAuth app](https://github.com/settings/developers): + - set `Authorization callback URL` to `http://localhost:3000/auth/callback`; + - set `Application name` as you like, and `Homepage URL` as `http://localhost:3000/`; + - create the app and take note of `Client ID` and `Client Secret` +- in this repo, create `site/.env` containing: + ``` + GITHUB_CLIENT_ID=[your app's Client ID] + GITHUB_CLIENT_SECRET=[your app's Client Secret] + BASEURL=http://localhost:3000 + ``` ## Translating the API docs Anchors are automatically generated using headings in the documentation and by default (for the english language) they are latinised to make sure the URL is always conforming to RFC3986. -If we need to translate the API documentation to a language using unicode chars, we can setup this app to export the correct anchors by setting up `SLUG_PRESERVE_UNICODE` to `true` and `SLUG_LANG` to the ISO 639-1 two-letter language code of your choice in `config.js`. +If we need to translate the API documentation to a language using unicode chars, we can setup this app to export the correct anchors by setting up `SLUG_PRESERVE_UNICODE` to `true` in `config.js`. diff --git a/site/config.js b/site/config.js index 25dfce0c22..097bd173a8 100644 --- a/site/config.js +++ b/site/config.js @@ -1,3 +1,2 @@ export const SLUG_PRESERVE_UNICODE = false; export const SLUG_SEPARATOR = '_'; -export const SLUG_LANG = 'en'; diff --git a/site/content/blog/2019-04-22-svelte-3-rethinking-reactivity.md b/site/content/blog/2019-04-22-svelte-3-rethinking-reactivity.md index dcb8c50fc0..0721c09692 100644 --- a/site/content/blog/2019-04-22-svelte-3-rethinking-reactivity.md +++ b/site/content/blog/2019-04-22-svelte-3-rethinking-reactivity.md @@ -92,6 +92,6 @@ We don't take this lightly: hopefully once you've experienced Svelte 3 you'll un ## Still to come -As grueling as this release has been, we're nowhere near finished. We have a ton of ideas for generating smarter, more compact code, and a long feature wish-list. [Sapper](https://sapper.svelte.technology), our Next.js-style app framework, is still in the middle of being updated to use Svelte 3. The [Svelte Native](https://svelte-native.technology/) community project, which allows you to write Android and iOS apps in Svelte, is making solid progress but deserves more complete support from core. We don't yet have the bounty of editor extensions, syntax highlighters, component kits, devtools and so on that other frameworks have, and we should fix that. We *really* want to add first-class TypeScript support. +As grueling as this release has been, we're nowhere near finished. We have a ton of ideas for generating smarter, more compact code, and a long feature wish-list. [Sapper](https://sapper.svelte.dev), our Next.js-style app framework, is still in the middle of being updated to use Svelte 3. The [Svelte Native](https://svelte-native.technology/) community project, which allows you to write Android and iOS apps in Svelte, is making solid progress but deserves more complete support from core. We don't yet have the bounty of editor extensions, syntax highlighters, component kits, devtools and so on that other frameworks have, and we should fix that. We *really* want to add first-class TypeScript support. But in the meantime we think Svelte 3 is the best way to build web apps yet. Take an hour to go through the [tutorial](tutorial) and we hope to convince you of the same. Either way, we'd love to see you in our [Discord chatroom](https://discord.gg/yy75DKs) and on [GitHub](https://github.com/sveltejs/svelte) — everyone is welcome, especially you. \ No newline at end of file diff --git a/site/content/docs/00-introduction.md b/site/content/docs/00-introduction.md index 4730a0c1d5..c218cdfb5f 100644 --- a/site/content/docs/00-introduction.md +++ b/site/content/docs/00-introduction.md @@ -2,7 +2,7 @@ title: Before we begin --- -> Temporary note: This document is a work-in-progress. Please forgive any missing or misleading parts, and don't be shy about asking for help in the [Discord chatroom](https://discord.gg/yy75DKs). The [tutorial](tutorial) is more complete; start there. +> Temporary note: This document is a work-in-progress. Please forgive any missing or misleading parts, and don't be shy about asking for help in the [Discord chatroom](https://discord.gg/yy75DKs). The [tutorial](tutorial) is more complete; start there. This page contains detailed API reference documentation. It's intended to be a resource for people who already have some familiarity with Svelte. diff --git a/site/content/docs/01-component-format.md b/site/content/docs/01-component-format.md index d116dd8ff4..93af09b283 100644 --- a/site/content/docs/01-component-format.md +++ b/site/content/docs/01-component-format.md @@ -56,6 +56,8 @@ To change component state and trigger a re-render, just assign to a locally decl Update expressions (`count += 1`) and property assignments (`obj.x = y`) have the same effect. +Because Svelte's reactivity is based on assignments, using array methods like `.push()` and `.splice()` won't automatically trigger updates. Options for getting around this can be found in the [tutorial](tutorial/updating-arrays-and-objects). + ```html + + +``` + +--- +Events dispatched from child components can be listened to in their parent. Any data provided when the event was dispatched is available on the `detail` property of the event object. + +```html + + + +``` ### `svelte/store` @@ -475,21 +506,81 @@ TODO * fade, fly, slide, scale, draw * crossfade... -### `svelte/animation` +### `svelte/animate` -TODO +The `svelte/animate` module exports one function for use with svelte [animations](docs#Animations). + +#### `flip` + +```sv +animate:flip={params} +``` + +The `flip` function calculates the start and end position of an element and animates between them, translating the `x` and `y` values. `flip` stands for [First, Last, Invert, Play](https://aerotwist.com/blog/flip-your-animations/). + +`flip` accepts the following parameters: + +* `delay` (`number`, default 0) — milliseconds before starting +* `duration` (`number` | `function`, default `d => Math.sqrt(d) * 120`) — see below +* `easing` (`function`, default [`cubicOut`](docs#cubicOut)) — an [easing function](docs#svelte_easing) + + +`duration` can be be provided as either: + +- a `number`, in milliseconds. +- a function, `distance: number => duration: number`, receiving the distance the element will travel in pixels and returning the duration in milliseconds. This allows you to assign a duration that is relative to the distance travelled by each element. + +--- + +You can see a full example on the [animations tutorial](tutorial/animate) + + +```html + + +{#each list as n (n)} +
+ {n} +
+{/each} +``` -* TODO this doesn't even exist yet -TODO ### `svelte/easing` * TODO could have nice little interactive widgets showing the different functions, maybe + ### `svelte/register` -TODO +To render Svelte components in Node.js without bundling, use `require('svelte/register')`. After that, you can use `require` to include any `.svelte` file. + +```js +require('svelte/register'); + +const App = require('./App.svelte').default; + +... + +const { html, css, head } = App.render({ answer: 42 }); +``` + +> The `.default` is necessary because we're converting from native JavaScript modules to the CommonJS modules recognised by Node. Note that if your component imports JavaScript modules, they will fail to load in Node and you will need to use a bundler instead. + +To set compile options, or to use a custom file extension, call the `register` hook as a function: + +```js +require('svelte/register')({ + extensions: ['.customextension'], // defaults to ['.html', '.svelte'] + preserveComments: true +}); +``` ### Client-side component API @@ -500,8 +591,6 @@ TODO const component = new Component(options) ``` ---- - A client-side component — that is, a component compiled with `generate: 'dom'` (or the `generate` option left unspecified) is a JavaScript class. ```js diff --git a/site/content/docs/04-compile-time.md b/site/content/docs/04-compile-time.md index 7dd1e371f6..9abeee37ef 100644 --- a/site/content/docs/04-compile-time.md +++ b/site/content/docs/04-compile-time.md @@ -153,6 +153,30 @@ compiled: { --> +### `svelte.parse` + +```js +ast: object = svelte.parse( + source: string, + options?: { + filename?: string, + customElement?: boolean + } +) +``` + +--- + +The `parse` function parses a component, returning only its abstract syntax tree. Unlike compiling with the `generate: false` option, this will not perform any validation or other analysis of the component beyond parsing it. + + +```js +const svelte = require('svelte/compiler'); + +const ast = svelte.parse(source, { filename: 'App.svelte' }); +``` + + ### `svelte.preprocess` ```js diff --git a/site/content/tutorial/01-introduction/01-basics/text.md b/site/content/tutorial/01-introduction/01-basics/text.md index 95375edb25..c0fa2f48a3 100644 --- a/site/content/tutorial/01-introduction/01-basics/text.md +++ b/site/content/tutorial/01-introduction/01-basics/text.md @@ -29,4 +29,4 @@ Each tutorial chapter will have a 'Show me' button that you can click if you get ## Understanding components -In Svelte, an application is composed from one or more *components*. A component is a reusable self-contained block of code that encapsulates HTML, CSS and JavaScript that belong together, written into a `.svelte` file. The 'hello world' example on the right is a simple component. \ No newline at end of file +In Svelte, an application is composed from one or more *components*. A component is a reusable self-contained block of code that encapsulates HTML, CSS and JavaScript that belong together, written into a `.svelte` file. The 'hello world' example in the code editor is a simple component. diff --git a/site/content/tutorial/01-introduction/06-html-tags/text.md b/site/content/tutorial/01-introduction/06-html-tags/text.md index fdc8a576ff..ff547247e2 100644 --- a/site/content/tutorial/01-introduction/06-html-tags/text.md +++ b/site/content/tutorial/01-introduction/06-html-tags/text.md @@ -12,4 +12,4 @@ In Svelte, you do this with the special `{@html ...}` tag:

{@html string}

``` -> Svelte doesn't perform any sanitization of the data before it gets inserted into the DOM. In other words, it's critical that you manually escape HTML that comes from sources you don't trust, otherwise you risk exposing your users to XSS attacks. \ No newline at end of file +> Svelte doesn't perform any sanitization of the expression inside `{@html ...}` before it gets inserted into the DOM. In other words, if you use this feature it's critical that you manually escape HTML that comes from sources you don't trust, otherwise you risk exposing your users to XSS attacks. diff --git a/site/content/tutorial/08-stores/02-auto-subscriptions/text.md b/site/content/tutorial/08-stores/02-auto-subscriptions/text.md index 87306f3354..af584261f4 100644 --- a/site/content/tutorial/08-stores/02-auto-subscriptions/text.md +++ b/site/content/tutorial/08-stores/02-auto-subscriptions/text.md @@ -39,6 +39,8 @@ It starts to get a bit boilerplatey though, especially if your component subscri

The count is {$count}

``` +> Auto-subscription only works with store variables that are declared (or imported) at the top-level scope of a component. + You're not limited to using `$count` inside the markup, either — you can use it anywhere in the ` - - - - - - - diff --git a/site/src/components/InlineSvg.svelte b/site/src/components/InlineSvg.svelte deleted file mode 100644 index e29810ae97..0000000000 --- a/site/src/components/InlineSvg.svelte +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/site/src/components/TopNav.svelte b/site/src/components/TopNav.svelte deleted file mode 100644 index 49a1be50d1..0000000000 --- a/site/src/components/TopNav.svelte +++ /dev/null @@ -1,277 +0,0 @@ - - - - - - -
- -
diff --git a/site/src/components/unused/Logo.svelte b/site/src/components/unused/Logo.svelte deleted file mode 100644 index 811e5b9442..0000000000 --- a/site/src/components/unused/Logo.svelte +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/site/src/components/unused/debug-css.html b/site/src/components/unused/debug-css.html deleted file mode 100644 index 745d7a11b1..0000000000 --- a/site/src/components/unused/debug-css.html +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - -{#if show} -
-
-
-
-
-{/if} - - \ No newline at end of file diff --git a/site/src/components/unused/isometry.html b/site/src/components/unused/isometry.html deleted file mode 100644 index 6c2260ae50..0000000000 --- a/site/src/components/unused/isometry.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/site/src/components/unused/theme-input.html b/site/src/components/unused/theme-input.html deleted file mode 100644 index 8465cd8890..0000000000 --- a/site/src/components/unused/theme-input.html +++ /dev/null @@ -1,81 +0,0 @@ - -{#if color} - {/if} - -{#if text} - -{/if} - - - - - \ No newline at end of file diff --git a/site/src/components/unused/toaster.html b/site/src/components/unused/toaster.html deleted file mode 100644 index 6145efc568..0000000000 --- a/site/src/components/unused/toaster.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - - diff --git a/site/src/routes/_components/Example.svelte b/site/src/routes/_components/Example.svelte new file mode 100644 index 0000000000..c07b4be0b5 --- /dev/null +++ b/site/src/routes/_components/Example.svelte @@ -0,0 +1,52 @@ + + + + +
+
+ + +
+ + {#if intersecting} + + + {/if} + +
+
+
\ No newline at end of file diff --git a/site/src/routes/_layout.svelte b/site/src/routes/_layout.svelte index 5482ea4d46..bc557fb4da 100644 --- a/site/src/routes/_layout.svelte +++ b/site/src/routes/_layout.svelte @@ -1,19 +1,37 @@ + + {#if $preloading} {/if} - {#if $page.path !== '/repl/embed'} -