You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: NEWS.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,17 @@
1
+
## (Unreleased) Sverto 1.0.0
2
+
3
+
- Significant refactor of Sverto makes it easier to use and more compatible with Quarto's other features
4
+
- Use Sverto in a Quarto document by adding `sverto` to `filters` in the document frontmatter
5
+
- Add Svelte files to a document using the frontmatter key `sverto.use`
6
+
- No need for magic blocks anymore!
7
+
- When working in a website project, optionally use the `sverto` project type to cut down on duplicate Svelte compilation Quarto documents
8
+
- Works properly with Quarto includes
9
+
- Requires Quarto pre-release 1.5.25 or higher on Windows, but should work fine on Quarto 1.4 on macOS and Linux.
10
+
11
+
## Sverto 0.0.3
12
+
13
+
- Migrated from [`360-info/sverto`](https://github.comn/360-info/sverto) to [`jimjam-slam/sverto`](htps://github.com/jimjam-slam/sverto). Old GitHub links are maintained.
14
+
1
15
## Sverto 0.0.2
2
16
3
17
- Bump minimum Quarto version to 1.3.0.
@@ -7,6 +21,6 @@
7
21
1. avoid copying the `docs` folder in with the project template; and
Copy file name to clipboardExpand all lines: README.md
+7-9Lines changed: 7 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,21 +49,18 @@ title: "My document"
49
49
filters: ["sverto"]
50
50
sverto:
51
51
use:
52
-
example.svelte
52
+
- example.svelte
53
53
---
54
54
```
55
55
56
56
### Step 2: bring your Svelte component to life
57
57
58
-
Use an [Observable JS](https://quarto.org/docs/interactive/ojs/) chunk to _instantiate_ your Svelte component.
58
+
Use an [Observable JS](https://quarto.org/docs/interactive/ojs/) chunk to _construct_ your Svelte component.
59
59
60
60
````js
61
61
```{ojs}
62
62
myChart = new example.default({
63
63
target: document.querySelector("#chart")
64
-
props: {
65
-
chartData: {}
66
-
}
67
64
})
68
65
```
69
66
@@ -73,16 +70,17 @@ myChart = new example.default({
73
70
74
71
- the `target` is where it will appear. This needs to be an existing part of the document — you can put a [Pandoc div](https://quarto.org/docs/authoring/markdown-basics.html#divs-and-spans) right after this code, or put one anywhere else on the page
75
72
-`example` is the file name of your Svelte component, without the file extension
76
-
- if your Svelte component has any `props`, add default values here too. Don't put reactive OJS code in here; we'll update the props separately!
77
73
78
-
### Step 3: make your visual reactive
74
+
### Step 3: make your component reactive
79
75
80
-
If your visual has `props` that allow it to change or transition in response to other OJS code, you can update it by assigning the prop directly.
76
+
If your component has `props` that allow it to change or transition in response to other OJS code, you can update them by assigning the prop directly.
81
77
82
-
For example, if we have a dataset called `myData` in OJS, and a year slider called `selectedYear`, we can change a prop called `chartData` whenever the user selects a new year like:
78
+
For example, if we have a dataset called `myData` in OJS, and a year slider called `selectedYear`, we might change a prop called `chartData` whenever the user selects a new year like:
> **Note:**`quarto preview` won't "live reload" when you modify your Svelte component—but if you modify and save the Quarto doc that imports it, that will trigger a re-render. You may need to hard reload the page in your browser to see the updated Svelte component.
Here's an example of how to use the included example Svelte component, `Circles.svelte`. There are six steps:
11
+
Here's an example of how to use the included example Svelte component, `Circles.svelte`.
14
12
15
-
### 1. Install Sverto
16
-
17
-
```bash
18
-
quarto add jimjam-slam/sverto
19
-
```
20
-
21
-
### 2. Add Sverto to your document
22
-
23
-
In the document frontmatter:
24
-
25
-
```yaml
26
-
---
27
-
# filters:
28
-
# - sverto
29
-
---
30
-
```
31
-
32
-
#### (For projects only: use the sverto project type)
33
-
34
-
In `_quarto.yml`:
35
-
36
-
37
-
```yaml
38
-
project:
39
-
type: sverto
40
-
```
41
-
42
-
### 3. Create a place for your visual to live
43
-
44
-
We need to create an instance of our imported component, but---unlike a typical OJS block---Svelte components put the visual itself somewhere else in the document.
45
-
46
-
Create an empty div in your document and give it an #id with the hashtag. This will be the "target" in the next step, when we bring the component to life, or _instantiate_ it:
47
-
48
-
```markdown
49
-
:::{#mycircles}
50
-
:::
51
-
```
52
-
53
-
:::{#mycircles}
54
-
:::
55
-
56
-
:::{.callout-tip}
57
-
This block can go anywhere in your document! Feel free to put it well after the following steps, where you actually want your visualisation to appear.
58
-
:::
59
-
60
-
:::{.callout-tip}
61
-
If you know how how to use CSS, you can target `#mycircles` to position or size your visualisation as you'd like.
62
-
:::
63
-
64
-
### 4. Instantiate your component
65
-
66
-
Bring your component to life by creating an instance of it with `new [Component Name].default()`. This function takes an object as an argument with two properties:
67
-
68
-
- `target`is the place your visual will go. Use the `document.querySelector` to point it to the empty block we just made above, `#mycricles`.
69
-
- `props`: is an object where we pass props, or properties, to the component. This will vary depending on how the component is written: the one included as an example with this package, `Circles.svelte`, requires a prop called `data`.
70
-
71
-
Here's how we instantiate `Circles.svelte`:
13
+
Create one using `fileName.default()`, where `fileName` is the file name without `.svelte`:
72
14
73
15
```{ojs}
74
16
myCircles = new Circles.default({
75
-
target: document.querySelector("#mycircles"),
76
-
props: {
77
-
data: [5, 15, 25, 17, 8]
78
-
}
17
+
target: document.querySelector("#mycircles")
79
18
});
80
19
```
81
20
82
-
::: {.callout-important}
83
-
If you're creating a visual that will react in response to changing OJS (for example, some data that you've calculated in your document, or the value of an Observable Input), **do not put that data here.**
21
+
It will appear in a [div](https://quarto.org/docs/authoring/markdown-basics.html#divs-and-spans) called `#mycircles`, which I've added directly below:
84
22
85
-
If you put changing data here, the Svelte component will rebuild from scratch every time the data changes, and it will not animate.
86
-
87
-
Instead, we're going to take advantage of Svelte's own reactivity in the next step.
23
+
:::{#mycircles}
88
24
:::
89
25
90
-
### 5. Update your component
91
-
92
-
Now the fun part - updating our visual when our document changes. It's as simple as referring to the prop using `componentInstance.propName =`.
26
+
Now the fun part - updating our visual when our document changes. It's as simple as changing the prop using `componentName.propName =`.
93
27
94
-
For example, here are three datasets and an Observable Inputs dropdown menu that lets you select one of three datasets:
28
+
For example, here are three datasets and an [Observable Inputs](https://observablehq.com/documentation/inputs/overview) dropdown menu that lets you select one of three datasets:
95
29
96
30
```{ojs}
97
31
// here are some datasets...
@@ -113,22 +47,6 @@ Now we can update the prop `data` of the visual `myCircles` using:
113
47
myCircles.data = selectedDataset
114
48
```
115
49
116
-
You can't see anything here, but if we scroll back up to where we added the empty `#mycircles` block, you can see it transition whenever we select a new dataset!
117
-
118
-
:::{.callout-tip}
119
-
You can put `#mycircles` wherever you want in the document - it doesn't have to be in order!
120
-
:::
121
-
122
-
### 6. Render the project
123
-
124
-
Render your Quarto project as you normally would, with commands like `quarto run` and `quarto preview`.
125
-
126
-
:::{.callout-note}
127
-
You'll probably get the warning `OJS block count mismatch. Line number reporting is likely to be wrong` when rendering.
128
-
129
-
That's because of what we're doing under the hood to bring the Svelte files in. It won't stop your project from working, but be aware of it if you are referring to line numbers in code blocks!
130
-
:::
131
-
132
50
And there you go! 🚀
133
51
134
52
For more help writing Svelte components, check out the [Svelte tutorial](https://svelte.dev/tutorial/basics).
0 commit comments