Skip to content

Commit 6dfc519

Browse files
committed
Merge branch 'dev'
2 parents 3ea3302 + baa7836 commit 6dfc519

34 files changed

+1640
-1720
lines changed

.github/workflows/check.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# workflow to test sverto
1+
# workflow to test quarto-svelte
22

33
on:
44
workflow_dispatch:
@@ -7,10 +7,10 @@ on:
77
pull_request:
88
branches: [main, dev]
99

10-
name: sverto-check
10+
name: quarto-svelte-check
1111

1212
jobs:
13-
sverto-check:
13+
quarto-svelte-check:
1414

1515
strategy:
1616
matrix:
@@ -34,19 +34,19 @@ jobs:
3434
with:
3535
node-version: 20
3636

37-
- name: Install Sverto docs npm dependencies
37+
- name: Install quarto-svelte docs npm dependencies
3838
run: npm install
3939
working-directory: ./docs
4040

4141
- name: Create docs _extensions folder
4242
run: mkdir docs/_extensions
4343
shell: bash
4444

45-
- name: Copy Sverto extension into docs
46-
run: cp -rf _extensions/sverto docs/_extensions/sverto
45+
- name: Copy quarto-svelte extension into docs
46+
run: cp -rf _extensions/quarto-svelte docs/_extensions/quarto-svelte
4747
shell: bash
4848

49-
- name: Render sverto docs
49+
- name: Render quarto-svelte docs
5050
uses: quarto-dev/quarto-actions/render@v2
5151
with:
5252
path: docs

.gitignore

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# quarto backend folder
22
/.quarto/
33

4-
# .sverto directory (except rollup.config.js)
5-
/.sverto/import
6-
/.sverto/.sverto-*
7-
!/.sverto/rollup.config.js
4+
# .quarto-svelte directory (except rollup.config.js)
5+
/.quarto-svelte/import
6+
/.quarto-svelte/.quarto-svelte-*
7+
!/.quarto-svelte/rollup.config.js
88

99
# installed npm packages
1010
/node_modules/
@@ -18,10 +18,11 @@
1818
# rendered documentation site
1919
/docs/_site/
2020
/docs/.quarto/
21-
/docs/.sverto/
21+
/docs/.quarto-svelte/
2222

23-
# sverto extension in docs site (we get it from project root on render)
24-
/docs/_extensions/sverto
25-
26-
# rendered single doc example files
23+
# quarto-svelte extension + files in docs site (we get it from project root on render)
24+
/docs/_extensions/quarto-svelte
25+
/docs/package.json
26+
/docs/package-lock.json
2727
/example_files/
28+

Circles.svelte

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<!-- this line is needed to add your svelte component to quarto! -->
2+
<svelte:options customElement={{
3+
tag: "my-circles",
4+
props: {
5+
data: { type: "Array" }
6+
}
7+
}} />
8+
19
<script>
210
// let's borrow svelte's fly transitions for the circles that need to be
311
// created or destroyed
@@ -6,16 +14,14 @@
614
715
// here we declare `data` as a prop that this component can expect. it has
816
// a default value in case we don't provide anything
9-
// https://svelte.dev/tutorial/declaring-props
10-
export let data = [5, 15, 10, 12, 14];
11-
12-
// prefix a statement with $: to make it reactive (so it runs every time
13-
// data changes)
14-
// https://svelte.dev/tutorial/reactive-statements
15-
$: console.log("Dataset prop:", data);
17+
18+
let { data = [5, 15, 10, 12, 14] } = $props();
1619
1720
</script>
1821

22+
<!-- use @debug to log changes in an object to the developer console -->
23+
{@debug data}
24+
1925
<!-- we use svelte's in/out transitions for entering and exiting dom elements,
2026
and vanilla css transitions for retained elements that change. the
2127
#each block means we create an svg <circle> for each element of data -->

NEWS.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
## (Unreleased) Sverto 1.0.0
1+
## quarto-svelte 2.0.0
2+
3+
- Rename Sverto to quarto-svelte
4+
- **Breaking:** `filters: ["sverto"]` is now `filters: ["quarto-svelte"]`
5+
- **Breaking:** `sverto.use` is now `quarto-svelte.use`
6+
- Repo name is now `jimjam-slam/quarto-svelte`, but `jimjam-slam/sverto` will continue to work
7+
- Upgrade from Svelte 3 to Svelte 5
8+
- For notes on rewriting existing Svelte components for Svelte 5, see the [Svelte 5 Migration Guide](https://svelte.dev/docs/svelte/v5-migration-guide)
9+
- Now uses web components
10+
- **Breaking:** in addition to general Svelte 5 migration, components for quarto-svelte need to have a [custom element option](https://svelte.dev/docs/svelte/custom-elements)
11+
- **Breaking:** old instantiation syntax no longer works in Svelte 5. Instead, use an HTML template or JavaScript to create an element with the custom element name
12+
13+
## Sverto 1.0.0
214

315
- Significant refactor of Sverto makes it easier to use and more compatible with Quarto's other features
416
- Use Sverto in a Quarto document by adding `sverto` to `filters` in the document frontmatter

README.md

Lines changed: 62 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,99 @@
1-
# Sverto
1+
# quarto-svelte <img src="_extensions/quarto-svelte/quarto-svelte-logo.svg" align="right" width="180px" style="padding-left: 1rem;" />
22

3-
**Sverto** is an extension for [Quarto](https://quarto.org) that lets you seamlessly write and include [Svelte](https://svelte.dev) components, like charts and other visuals, in your Quarto website.
3+
**quarto-svelte** is an extension for [Quarto](https://quarto.org) that lets you seamlessly write and include [Svelte](https://svelte.dev) components, like charts and other visuals, in your Quarto website.
44

5-
Your Svelte components can seamlessly react to your ObservableJS code, making it quick and easy to build visuals that animate in response to [user inputs](https://observablehq.com/@observablehq/inputs?collection=@observablehq/inputs) or other changing data in your document.
5+
Your Svelte components can seamlessly react to your [Observable JavaScript](https://quarto.org/docs/interactive/ojs/) code, making it quick and easy to build bespoke visuals that animate in response to [user inputs](https://observablehq.com/documentation/inputs/overview) or other changing data in your Quarto document.
66

7-
## 📋 Prerequisites
7+
Get going in four easy steps:
88

9-
You'll need to install two things to run Sverto:
9+
**Step 1: create a Svelte component**
1010

11-
- [Quarto](https://quarto.org)
12-
- [Node and the Node Package Manager (npm)](https://nodejs.org)
13-
14-
## ⚙️ Installation
15-
16-
Install the project extension using:
17-
18-
```
19-
quarto use template jimjam-slam/sverto
20-
```
11+
If you've never written Svelte before, don't worry! You can start learning quickly with the comprehensive [Svelte tutorial](https://svelte.dev/tutorial/svelte/welcome-to-svelte).
2112

22-
Then run:
13+
quarto-svelte now uses a technique called [custom components](https://svelte.dev/docs/svelte/custom-elements) to bring Svelte into Quarto. So your Svelte component will need to start with a line like:
2314

24-
```
25-
npm install
15+
```html
16+
<svelte:options customElement="my-circles" />
2617
```
2718

28-
This will add the extension itself (which includes some project scripts) to the `_extension` folder, as well as a few other files.
19+
This name, `my-circles`, is what we'll use to place the component in our Quarto document. [It must be lowercase, and it must have at least one hyphen.](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#registering_a_custom_element)
2920

30-
### 📦 What's in the box?
21+
**Step 2: Add the Svelte file to your doc**
3122

32-
When you use the Sverto template in a project, it creates some files for you:
33-
34-
* [`example.qmd`](./example.qmd): an example Quarto doc that uses a Svelte component
35-
* [`Circles.svelte`](./Circles.svelte): an example Svelte visualisation
36-
* [`package.json`](./package.json): this is used to keep track of the dependencies of your Svelte components. **You should add this to version control.**
37-
* `package-lock.json` is created once you run `npm install`. You should add this to version control.
38-
* `node_modules/`: This folder is created once you rum `npm install`. Don't add it to version control.
39-
40-
## 🎉 Use
41-
42-
### Step 1: add Svelte to your document
43-
44-
In the document frontmatter, add `sverto` to `filters`, and add one or more `.svelte` files to `sverto.use`:
23+
You can import your shiny new Svelte component into Quarto by adding the `quarto-svelte` filter and then including it (and any other Svelte files you want) as a list under `quarto-svelte.use`:
4524

4625
```yaml
4726
---
48-
title: "My document"
49-
filters: ["sverto"]
50-
sverto:
27+
filters:
28+
- quarto-svelte
29+
quarto-svelte:
5130
use:
52-
- example.svelte
31+
- Circles.svelte
5332
---
5433
```
5534

56-
### Step 2: bring your Svelte component to life
35+
**Step 3: Place the Svelte component in your document**
5736

58-
Use an [Observable JS](https://quarto.org/docs/interactive/ojs/) chunk to _construct_ your Svelte component.
37+
Remember the name at the top of your Svelte file? To place your Svelte component, you're going to use that name as if it were an HTML tag:
5938

6039
````js
6140
```{ojs}
62-
myChart = new example.default({
63-
target: document.querySelector("#chart")
64-
})
41+
myCircles = html`<my-circles></my-circles>`
6542
```
66-
67-
:::{#chart}
68-
:::
6943
````
7044

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
72-
- `example` is the file name of your Svelte component, without the file extension
73-
74-
### Step 3: make your component reactive
45+
**Step 4: To update your Svelte component, use accessors to give it new props**
7546

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.
77-
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:
47+
If your Svelte component has [props](https://svelte.dev/tutorial/svelte/declaring-props) and you've assigned it to a variable in OJS, you can update the props on the fly! Let's update the data for our circles above:
7948

8049
````js
8150
```{ojs}
82-
myChart.chartData = myData.filter(d => d.year == selectedYear)
51+
myCircles.data = newData
8352
```
8453
````
8554

86-
> ![NOTE]
87-
> `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.
88-
>
89-
> If you want to quickly iterate on the Svelte component, you might find the [Svelte Preview](https://marketplace.visualstudio.com/items?itemName=RafaelMartinez.svelte-preview) extension for VSCode handy.
55+
## ⚙️ Installation
56+
57+
You'll need to install two things to run quarto-svelte:
58+
59+
- [Quarto](https://quarto.org)
60+
- [Node and the Node Package Manager (npm)](https://nodejs.org)
61+
9062

91-
## 📦 What's in the box?
63+
Install the extension and required files using:
9264

93-
When you use the Sverto template in a project, it creates some files for you:
65+
```
66+
quarto use template jimjam-slam/quarto-svelte
67+
```
68+
69+
> [!NOTE]
70+
> If you're running quarto-svelte in a Quarto project, be sure to install it from the root, or top-level, project folder.
71+
>
72+
> Do not use `quarto add`: quarto-svelte includes a `package.json` file that must sit in your project or document folder. `quarto use template` will copy this file for you.
73+
74+
Then run:
75+
76+
```
77+
npm install
78+
```
79+
80+
This will add the extension itself (which includes some project scripts) to the `_extension` folder, as well as a few other files.
81+
82+
### 📦 What's in the box?
83+
84+
When you use the quarto-svelte template in a project, it creates some files for you:
9485

9586
* [`example.qmd`](./example.qmd): an example Quarto doc that uses a Svelte component
9687
* [`Circles.svelte`](./Circles.svelte): an example Svelte visualisation
97-
* [`package.json`](./package.json): this is used to keep track of the dependencies of your Svelte components. You should add this to version control.
98-
* 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). You don't need to touch the `node_modules` folder, either.
88+
* [`package.json`](./package.json): this is used to keep track of the dependencies of your Svelte components. **You should add this to version control.**
89+
* `package-lock.json` is created once you run `npm install`. You should add this to version control.
90+
* `node_modules/`: This folder is created once you rum `npm install`. Don't add it to version control.
9991

100-
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.
92+
> [!NOTE]
93+
> `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.
94+
>
95+
> If you want to quickly iterate on the Svelte component, you might find the [Svelte Preview](https://marketplace.visualstudio.com/items?itemName=RafaelMartinez.svelte-preview) extension for VSCode handy.
10196
102-
As well as the project format, Sverto ships with document formats (the default is `sverto-html`). If you need to change document options that would normally go under `format: html`, use `format: sverto-html` or `format-sverto-revealjs` instead.
10397

10498
## 🛍 Use other libraries in your Svelte component
10599

@@ -109,21 +103,21 @@ If you want to refer to other JavaScript libraries in your Svelte component (lik
109103
npm install d3
110104
```
111105

112-
# 💭 Why Sverto?
106+
# 💭 Why quarto-svelte?
113107

114108
[Quarto](https://quarto.org) helps data scientists and analysts build beautiful documents regardless of their language of choice, and it encourages data analysts and scientists to explore web visualisation by making JavaScript accessible and easy to use.
115109

116110
Quarto makes interactive charts intuitive to write, but animated ones are still a challenge that require either dipping into a high-level JavaScript library or learning a lower-level one like [d3](https://d3js.org).
117111

118112
[Svelte](https://svelte.dev) is a framework for building charts, web visualisations and even apps in HTML, CSS and JavaScript. Svelte goes out of its way to make writing self-contained components, like charts, comfortable and intuitive.
119113

120-
Svelte has a great [playground environment](https://svelte.dev/repl/hello-world?version=3.55.1) for developing and testing components, but like many web frameworks, the experience is much more complex when you start developing locally.
114+
Svelte has a great [playground environment](https://svelte.dev/repl) for developing and testing components, but like many web frameworks, the experience is much more complex when you start developing locally.
121115

122-
_Sverto aims to make it as easy to build and use animated Svelte charts in Quarto documents as it is to work on them in the Svelte playground: just write a `.svelte` file, add it to a Quarto document, and Sverto takes care of the rest._
116+
_quarto-svelte aims to make it as easy to build and use animated Svelte charts in Quarto documents as it is to work on them in the Svelte playground: just write a `.svelte` file, add it to a Quarto document, and quarto-svelte takes care of the rest._
123117

124118
## ❓ Issues
125119

126-
If you have any problems with the extension, please feel free to [create an issue](https://github.com/jimjam-slam/sverto)!
120+
If you have any problems with the extension, please feel free to [create an issue](https://github.com/jimjam-slam/quarto-svelte)!
127121

128-
Special thanks to [Carlos Scheidegger](https://github.com/cscheid) from [Posit](https://posit.co) for his time and guidance getting Sverto working!
122+
Special thanks to [Carlos Scheidegger](https://github.com/cscheid) from [Posit](https://posit.co) for his time and guidance getting quarto-svelte working!
129123

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
title: quarto-svelte
2+
author: James Goldie
3+
version: 2.0.0
4+
quarto-version: ">=1.5.46"
5+
contributes:
6+
filters:
7+
- quarto-svelte.lua
8+
metadata:
9+
project:
10+
pre-render: quarto-svelte-prerender.lua

0 commit comments

Comments
 (0)