Skip to content

Commit 44f238a

Browse files
committed
Update documentation
1 parent 5a996c1 commit 44f238a

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

Circles.svelte

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
<!-- <svelte:options accessors /> -->
2-
31
<script>
2+
// let's borrow svelte's fly transitions for the circles that need to be
3+
// created or destroyed
4+
// https://svelte.dev/tutorial/transition
45
import { fly } from "svelte/transition";
56
6-
// forget the webcomponent: let's take a dataset as a direct array!
7-
// it expects pairs
7+
// here we declare `data` as a prop that this component can expect
8+
// https://svelte.dev/tutorial/declaring-props
89
export let data;
10+
11+
// prefix a statement with $: to make it reactive (so it runs every time
12+
// data changes)
13+
// https://svelte.dev/tutorial/reactive-statements
914
$: console.log("Dataset prop:", data);
1015
1116
</script>
1217

13-
<!-- we use svelte's in/out transitions for entering and existing dom elements,
14-
and vanilla css transitions for retained elements that change -->
18+
<!-- we use svelte's in/out transitions for entering and leaving dom elements,
19+
and vanilla css transitions for retained elements that change. the
20+
#each block means we create an svg <circle> for each element of data -->
1521
<svg>
1622
{#each data as d, i (i)}
1723
<circle
@@ -21,4 +27,4 @@
2127
fill="black"
2228
/>
2329
{/each}
24-
</svg>
30+
</svg>

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ This will install everything you need for your Svelte components to work to the
2626

2727
## 🎉 Use
2828

29-
Here's the short version of adding Svelte components to your Quarto docs:
29+
Here's the short way to add Svelte component you've written to a Quarto doc:
3030

31-
1. Add a list of Svelte components (eg. `Circles.svelte`) you want to add to your document frontmatter under `svelte`
32-
2. Add a magic placeholder div to your document using the `.svelteimport` class and a [Quarto include](https://quarto.org/docs/authoring/includes.html) to the path to your Quarto doc, prefixed with `/.sverto/`. For example:
31+
1. Add a magic placeholder block to your document with a [Quarto include](https://quarto.org/docs/authoring/includes.html) to the path to your Quarto doc, prefixed with `/.sverto/`. For example:
3332

34-
````
35-
:::{.svelteimport}
33+
```
34+
:::{}
3635
{{< include /.sverto/example.qmd >}}
3736
:::
38-
````
37+
```
3938
39+
2. Import your Svelte component with `Component = import_svelte("Component.svelte")`
4040
3. Add a target block for your visual and give it an `#id`
4141
4. Instantiate the Svelte component with `myVisual = Component.default()` using some default props and your target block
4242
5. Update the instantiated component with `myVisual.propName`
@@ -49,7 +49,7 @@ Here's the short version of adding Svelte components to your Quarto docs:
4949
* [`example.qmd`](./example.qmd): an example Quarto doc that uses a Svelte component
5050
* [`Circles.svelte`](./Circles.svelte): an example Svelte visualisation
5151
* [`package.json`](./package.json): this is used to keep track of the dependencies of your Svelte components. You should add this to version control.
52-
* Once you've run `npm install`, there'll also be a `package-lock.json`. You should version control this too.
52+
* Once you've run `npm install`, there'll also be a `package-lock.json` and a `.luarc.json`. You should version control these too (although you oughtn't need to edit them manually).
5353
5454
See [`example.qmd`](./example.qmd) to learn how to add Svelte components to your documents and the [Svelte tutorial](https://svelte.dev/tutorial/basics) to learn how to create them.
5555
@@ -61,9 +61,11 @@ If you want to refer to other JavaScript libraries in your Svelte component (lik
6161
npm install d3-scale
6262
```
6363
64-
If you'd prefer to compile your own Svelte components instead of letting this extension do it, you can skip steps 1 and 2 and simply refer to the compiled bundle with, for example, `Circles = require("Circles.js")` in an OJS block.
64+
## Use pre-compiled Svelte components
6565
66-
You must compiled Svelte component to ES6 bundles, and you must enable accessors when compiling if you want to be able to update them from OJS.
66+
If you'd prefer to compile your own Svelte components instead of letting this extension do it, you can skip steps 1 and 2 and simply refer to the compiled bundle with, for example, `Component = import("Component.js")` in an OJS block.
67+
68+
> **Note:** you must compile the Svelte component to an ES6 bundle, and you must enable accessors when compiling if you want to be able to update them from OJS. Refer to `_extensions/sverto/rollup.config.js` for guidance on configuring Rollup to do this.
6769
6870
## ❓ Issues
6971

0 commit comments

Comments
 (0)