@atom.io/spa 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +202 -138
- package/README.mdx +62 -26
- package/dist/astro-application.d.ts +1 -1
- package/dist/astro-client.d.ts +3 -2
- package/dist/astro-client.d.ts.map +1 -1
- package/dist/astro-client.js +11 -10
- package/dist/astro-client.js.map +1 -1
- package/dist/astro-resumability-client.d.ts +10 -0
- package/dist/astro-resumability-client.d.ts.map +1 -0
- package/dist/astro-resumability-client.js +29 -0
- package/dist/astro-resumability-client.js.map +1 -0
- package/dist/astro-resumability-server.d.ts +3 -0
- package/dist/astro-resumability-server.d.ts.map +1 -0
- package/dist/astro-resumability-server.js +7 -0
- package/dist/astro-resumability-server.js.map +1 -0
- package/dist/astro-server.d.ts +3 -2
- package/dist/astro-server.d.ts.map +1 -1
- package/dist/astro-server.js +28 -9
- package/dist/astro-server.js.map +1 -1
- package/dist/{astro-shared-BT45auwR.js → astro-shared-83hxw7-M.js} +4 -2
- package/dist/astro-shared-83hxw7-M.js.map +1 -0
- package/dist/{astro-shared-BkWvVZWZ.d.ts → astro-shared-DHIpjNIG.d.ts} +2 -2
- package/dist/{astro-shared-BkWvVZWZ.d.ts.map → astro-shared-DHIpjNIG.d.ts.map} +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +5 -7
- package/dist/astro.js.map +1 -1
- package/dist/{capabilities-CFP-HIuY.d.ts → capabilities-BCtBG-ni.d.ts} +19 -14
- package/dist/capabilities-BCtBG-ni.d.ts.map +1 -0
- package/dist/client.min.js +1 -1
- package/dist/{core-DCmqLZQP.js → core-DjFJ0aIJ.js} +31 -23
- package/dist/core-DjFJ0aIJ.js.map +1 -0
- package/dist/development/astro-client.js +11 -10
- package/dist/development/astro-client.js.map +1 -1
- package/dist/development/astro-resumability-client.js +29 -0
- package/dist/development/astro-resumability-client.js.map +1 -0
- package/dist/development/astro-resumability-server.js +7 -0
- package/dist/development/astro-resumability-server.js.map +1 -0
- package/dist/development/astro-server.js +28 -9
- package/dist/development/astro-server.js.map +1 -1
- package/dist/development/{astro-shared-BT45auwR.js → astro-shared-83hxw7-M.js} +4 -2
- package/dist/development/astro-shared-83hxw7-M.js.map +1 -0
- package/dist/development/astro.js +5 -7
- package/dist/development/astro.js.map +1 -1
- package/dist/development/{core-p9vciX9C.js → core-DxPiKryn.js} +31 -23
- package/dist/development/core-DxPiKryn.js.map +1 -0
- package/dist/development/{dom-Ci1XvbVJ.js → dom-BytVV6Rp.js} +44 -12
- package/dist/development/dom-BytVV6Rp.js.map +1 -0
- package/dist/development/index.js +4 -4
- package/dist/development/jsx-runtime.js.map +1 -1
- package/dist/development/konva.js +1 -1
- package/dist/development/konva.js.map +1 -1
- package/dist/development/motion.js +1 -1
- package/dist/development/renderer.js +1 -1
- package/dist/development/renderer.js.map +1 -1
- package/dist/development/server-renderer-CUQXh9oF.js +90 -0
- package/dist/development/server-renderer-CUQXh9oF.js.map +1 -0
- package/dist/development/server.js +2 -83
- package/dist/development/server.js.map +1 -1
- package/dist/{src-DCQa6qxs.js → development/src-WSHJxR9b.js} +4 -4
- package/dist/development/src-WSHJxR9b.js.map +1 -0
- package/dist/development/three.js +1 -1
- package/dist/development/three.js.map +1 -1
- package/dist/{dom-dHQM0O7Q.js → dom-B5OxgHkr.js} +44 -12
- package/dist/dom-B5OxgHkr.js.map +1 -0
- package/dist/{index-CJJXcKaw.d.ts → index-DufwkB6W.d.ts} +5 -5
- package/dist/{index-CJJXcKaw.d.ts.map → index-DufwkB6W.d.ts.map} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/{jsx-runtime-CREZYKDC.d.ts → jsx-runtime-DMDVr7A5.d.ts} +7 -7
- package/dist/{jsx-runtime-CREZYKDC.d.ts.map → jsx-runtime-DMDVr7A5.d.ts.map} +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/konva.d.ts +16 -16
- package/dist/konva.js +1 -1
- package/dist/konva.js.map +1 -1
- package/dist/motion.d.ts +1 -1
- package/dist/motion.js +1 -1
- package/dist/renderer.d.ts +4 -4
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +1 -1
- package/dist/renderer.js.map +1 -1
- package/dist/server-renderer-DcU55e6s.js +90 -0
- package/dist/server-renderer-DcU55e6s.js.map +1 -0
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +2 -83
- package/dist/server.js.map +1 -1
- package/dist/size.json +16 -16
- package/dist/{development/src-DG0xjuS5.js → src-DWIqXCiz.js} +4 -4
- package/dist/src-DWIqXCiz.js.map +1 -0
- package/dist/three.d.ts +17 -17
- package/dist/three.js +1 -1
- package/dist/three.js.map +1 -1
- package/package.json +27 -11
- package/src/astro-client.ts +20 -7
- package/src/astro-resumability-client.ts +40 -0
- package/src/astro-resumability-server.ts +7 -0
- package/src/astro-server.ts +58 -19
- package/src/astro-shared.ts +5 -2
- package/src/astro.ts +11 -3
- package/src/core.ts +54 -49
- package/src/dom.ts +73 -39
- package/src/index.ts +4 -4
- package/src/jsx-runtime.ts +7 -6
- package/src/jsx-types.d.ts +2 -2
- package/src/konva.ts +3 -3
- package/src/renderer.ts +24 -18
- package/src/server-renderer.ts +162 -0
- package/src/server.ts +4 -153
- package/src/three.ts +4 -4
- package/src/use-loadable.ts +3 -3
- package/dist/astro-shared-BT45auwR.js.map +0 -1
- package/dist/capabilities-CFP-HIuY.d.ts.map +0 -1
- package/dist/core-DCmqLZQP.js.map +0 -1
- package/dist/development/astro-shared-BT45auwR.js.map +0 -1
- package/dist/development/core-p9vciX9C.js.map +0 -1
- package/dist/development/dom-Ci1XvbVJ.js.map +0 -1
- package/dist/development/src-DG0xjuS5.js.map +0 -1
- package/dist/dom-dHQM0O7Q.js.map +0 -1
- package/dist/src-DCQa6qxs.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,35 +6,41 @@ An experimental JSX framework whose state engine is atom.io. Components run once
|
|
|
6
6
|
|
|
7
7
|
The npm package is named @atom.io/spa. Its browser runtime, Vite compiler, server renderer, and Astro integration are implemented here. It has no independent state primitive, effect API, React hook dispatcher, or compatibility layer.
|
|
8
8
|
|
|
9
|
+
## Start with the Astro template
|
|
10
|
+
|
|
11
|
+
Use the [SPA + Astro SSR template](https://github.com/jeremybanka/atom.io/tree/main/templates/spa-astro-ssr) for a ready-to-run application with Astro islands, resumable initial data, SQLite, and tRPC:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm create atom.io@latest my-spa -- --templateName=spa-astro-ssr --packageManager=npm
|
|
15
|
+
cd my-spa
|
|
16
|
+
npm run dev
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
For manual setup, see the [Astro](https://atom.io.fyi/docs/spa/astro) and [Vite](https://atom.io.fyi/docs/spa/vite) integration guides on atom.io.fyi.
|
|
21
|
+
|
|
9
22
|
## A point, not two signals
|
|
10
23
|
|
|
11
24
|
```tsx
|
|
12
|
-
import type {
|
|
13
|
-
import {
|
|
25
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
26
|
+
import { useGetter, useSetter } from "@atom.io/spa"
|
|
14
27
|
import { atom } from "atom.io"
|
|
15
28
|
|
|
16
29
|
const pointAtom = atom<{ x: number; y: number }>({
|
|
17
30
|
key: `point`,
|
|
18
31
|
default: { x: 20, y: 20 },
|
|
19
32
|
})
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
default: null,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
export function PointEditor(): VNode {
|
|
26
|
-
const point = useValue(pointAtom)
|
|
33
|
+
export function PointEditor(): SpaElement {
|
|
34
|
+
const getPoint = useGetter(pointAtom)
|
|
27
35
|
const setPoint = useSetter(pointAtom)
|
|
28
|
-
const circle = useRef(circleAtom)
|
|
29
|
-
const id = useId()
|
|
30
36
|
return (
|
|
31
|
-
<section
|
|
32
|
-
<h2
|
|
37
|
+
<section>
|
|
38
|
+
<h2>Point</h2>
|
|
33
39
|
<svg viewBox="0 0 100 100">
|
|
34
|
-
<circle
|
|
40
|
+
<circle cx={getPoint().x} cy={getPoint().y} r="3" />
|
|
35
41
|
</svg>
|
|
36
42
|
<output>
|
|
37
|
-
{
|
|
43
|
+
{getPoint().x}, {getPoint().y}
|
|
38
44
|
</output>
|
|
39
45
|
<button
|
|
40
46
|
onClick={() => {
|
|
@@ -49,7 +55,59 @@ export function PointEditor(): VNode {
|
|
|
49
55
|
|
|
50
56
|
```
|
|
51
57
|
|
|
52
|
-
The
|
|
58
|
+
Name the getter and setter after the atom: pointAtom uses getPoint and setPoint. The getPoint getter returns the current object. Each JSX attribute reads its coordinate when evaluated. Both bindings depend on the point atom, and unchanged primitive results skip DOM writes. Reads during setup are snapshots; reads in event handlers are current and untracked. Shared derived state belongs in atom.io selectors.
|
|
59
|
+
|
|
60
|
+
## Astro
|
|
61
|
+
|
|
62
|
+
Register the Astro integration, which compiles .tsx and .jsx components by default:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import spa from "@atom.io/spa/astro"
|
|
66
|
+
import { defineConfig } from "astro/config"
|
|
67
|
+
|
|
68
|
+
export default defineConfig({ integrations: [spa()] })
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Create a counter component:
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
76
|
+
import { useGetter, useSetter } from "@atom.io/spa"
|
|
77
|
+
import { atom } from "atom.io"
|
|
78
|
+
|
|
79
|
+
const countAtom = atom<number>({ key: `count`, default: 0 })
|
|
80
|
+
|
|
81
|
+
export default function Counter(): SpaElement {
|
|
82
|
+
const getCount = useGetter(countAtom)
|
|
83
|
+
const setCount = useSetter(countAtom)
|
|
84
|
+
return (
|
|
85
|
+
<button
|
|
86
|
+
onClick={() => {
|
|
87
|
+
setCount((count) => count + 1)
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
Count: {getCount()}
|
|
91
|
+
</button>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Import it into an Astro page and use client:load to make it interactive. Astro handles server rendering and browser hydration:
|
|
98
|
+
|
|
99
|
+
```astro
|
|
100
|
+
---
|
|
101
|
+
import Counter from "./Counter.tsx"
|
|
102
|
+
---
|
|
103
|
+
<html lang="en">
|
|
104
|
+
<head><title>SPA counter</title></head>
|
|
105
|
+
<body>
|
|
106
|
+
<Counter client:load />
|
|
107
|
+
</body>
|
|
108
|
+
</html>
|
|
109
|
+
|
|
110
|
+
```
|
|
53
111
|
|
|
54
112
|
## Vite
|
|
55
113
|
|
|
@@ -77,27 +135,39 @@ export default defineConfig({ plugins: [spa()] })
|
|
|
77
135
|
|
|
78
136
|
```
|
|
79
137
|
|
|
138
|
+
Add a host element in index.html, then mount the same counter from main.tsx:
|
|
139
|
+
|
|
140
|
+
```html
|
|
141
|
+
<!doctype html>
|
|
142
|
+
<html lang="en">
|
|
143
|
+
<head><title>SPA counter</title></head>
|
|
144
|
+
<body>
|
|
145
|
+
<div id="app"></div>
|
|
146
|
+
<script type="module" src="/main.tsx"></script>
|
|
147
|
+
</body>
|
|
148
|
+
</html>
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
|
|
80
152
|
```tsx
|
|
81
153
|
import { render } from "@atom.io/spa"
|
|
82
154
|
|
|
83
|
-
import
|
|
155
|
+
import Counter from "./Counter.tsx"
|
|
84
156
|
|
|
85
|
-
|
|
86
|
-
// Call root.dispose() when the application shell removes this root.
|
|
87
|
-
import.meta.hot?.dispose(root.dispose)
|
|
157
|
+
render(() => <Counter />, document.getElementById(`app`)!)
|
|
88
158
|
|
|
89
159
|
```
|
|
90
160
|
|
|
91
161
|
The development plugin keeps SPA and atom.io outside dependency prebundling so renderer entrypoints, component hooks, and stores share one runtime, including Astro adapter environments. It uses full page reloads. Components and render computations are synchronous. Modern browsers with ES2022 and DOM Range support are the target.
|
|
92
162
|
|
|
93
|
-
##
|
|
163
|
+
## Hooks
|
|
94
164
|
|
|
95
165
|
| API | Contract |
|
|
96
166
|
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
97
167
|
| useLoadable(token, fallback?) | Return a tracked accessor for loading, last-observed values, and handled errors. |
|
|
98
|
-
|
|
|
168
|
+
| useGetter(token) | Return a live accessor for an atom or selector, bound to this instance's store. |
|
|
99
169
|
| useSetter(token) | Return a stable atom.io writer. |
|
|
100
|
-
| useTimeline(token) | Return
|
|
170
|
+
| useTimeline(token) | Return a stable object with getCursor/getLength readers, undo/redo/clear commands, and transaction-group controls. |
|
|
101
171
|
| useTransaction(token) | Bind an atom.io transaction, preserving its arguments and result. |
|
|
102
172
|
| useRef(token) | Return an attachment callback for a nullable element atom. Clear it only while this attachment still owns the reference. |
|
|
103
173
|
| useId() | Allocate an instance-stable ID using the root's prefix. |
|
|
@@ -107,6 +177,55 @@ The development plugin keeps SPA and atom.io outside dependency prebundling so r
|
|
|
107
177
|
|
|
108
178
|
Call setup helpers synchronously during component setup or owned mount callbacks. Capture their results for event handlers. Tokens are fixed for an instance; use an application key in a reactive child expression to replace a component when its token changes. Component props stay live when read through the props object; destructuring during setup takes a snapshot.
|
|
109
179
|
|
|
180
|
+
useTimeline returns a TimelineControls object whose methods can be destructured during setup. getCursor and getLength read the current cursor position and recorded checkpoint count; calls inside JSX subscribe the computation, while calls during setup or in event handlers are untracked. undo, redo, and clear are stable commands. history.getTransaction() is a tracked reader that returns an object with optional undo and redo callbacks for the adjacent transaction groups. At a cursor between transactions, both callbacks may be present and target different groups. A missing callback means no transaction group is available in that direction; the reader returns an empty object when neither is available. Calling a returned callback travels its captured group across participating timelines where it remains at the relevant history head, leaving diverged timelines unchanged. Use history.getTransaction().undo?.() or history.getTransaction().redo?.() to retrieve and invoke the current action together.
|
|
181
|
+
|
|
182
|
+
```tsx
|
|
183
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
184
|
+
import { useGetter, useTimeline, useTransaction } from "@atom.io/spa"
|
|
185
|
+
import { atom, timeline, transaction } from "atom.io"
|
|
186
|
+
|
|
187
|
+
const countAtom = atom<number>({ key: `count`, default: 0 })
|
|
188
|
+
const historyTimeline = timeline({ key: `history`, scope: [countAtom] })
|
|
189
|
+
const incrementTransaction = transaction<() => void>({
|
|
190
|
+
key: `increment`,
|
|
191
|
+
do: ({ get, set }) => {
|
|
192
|
+
set(countAtom, get(countAtom) + 1)
|
|
193
|
+
},
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
export function TimelineExample(): SpaElement {
|
|
197
|
+
const getCount = useGetter(countAtom)
|
|
198
|
+
const increment = useTransaction(incrementTransaction)
|
|
199
|
+
const history = useTimeline(historyTimeline)
|
|
200
|
+
return (
|
|
201
|
+
<section>
|
|
202
|
+
<output>
|
|
203
|
+
Count: {getCount()} (history: {history.getCursor()}/{history.getLength()}
|
|
204
|
+
)
|
|
205
|
+
</output>
|
|
206
|
+
<button onClick={increment}>Increment</button>
|
|
207
|
+
<button
|
|
208
|
+
disabled={history.getTransaction().undo === undefined}
|
|
209
|
+
onClick={() => {
|
|
210
|
+
history.getTransaction().undo?.()
|
|
211
|
+
}}
|
|
212
|
+
>
|
|
213
|
+
Undo transaction
|
|
214
|
+
</button>
|
|
215
|
+
<button
|
|
216
|
+
disabled={history.getTransaction().redo === undefined}
|
|
217
|
+
onClick={() => {
|
|
218
|
+
history.getTransaction().redo?.()
|
|
219
|
+
}}
|
|
220
|
+
>
|
|
221
|
+
Redo transaction
|
|
222
|
+
</button>
|
|
223
|
+
</section>
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
```
|
|
228
|
+
|
|
110
229
|
Arrays support keyed components and elements. Reordering preserves instances and nodes; removed ranges release subscriptions, events, refs, and cleanup callbacks. Application keys must be unique among siblings. Explicit keys are compared as strings; unkeyed positions occupy a separate namespace. Unkeyed arrays use positions. A key identifies a row in a reactive child collection; it is not an independent reactive binding.
|
|
111
230
|
|
|
112
231
|
HTML and SVG use native DOM properties and attributes, plus className/htmlFor aliases. Events use onClick/onInput-style names, with Capture suffixes and onDoubleClick support. Styles are CSS strings. Mutable atom values still invalidate their consumers; project primitive fields for precise DOM writes. Refs attach once per element instance.
|
|
@@ -118,14 +237,14 @@ HTML and SVG tags have element-specific attribute, event, and ref types. Event h
|
|
|
118
237
|
useStore returns the current root's atom.io RootStore directly. It is the same object supplied to render or hydrate, the selected Astro island store, or the implicit atom.io store when no store was supplied. Server rendering exposes the store selected for that render.
|
|
119
238
|
|
|
120
239
|
```tsx
|
|
121
|
-
import type {
|
|
240
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
122
241
|
import { useStore } from "@atom.io/spa"
|
|
123
242
|
import { atom } from "atom.io"
|
|
124
243
|
import { getFromStore } from "atom.io/internal"
|
|
125
244
|
|
|
126
245
|
const countAtom = atom<number>({ key: `count`, default: 0 })
|
|
127
246
|
|
|
128
|
-
export function InspectCount():
|
|
247
|
+
export function InspectCount(): SpaElement {
|
|
129
248
|
const store = useStore()
|
|
130
249
|
return (
|
|
131
250
|
<button
|
|
@@ -140,15 +259,15 @@ export function InspectCount(): VNode {
|
|
|
140
259
|
|
|
141
260
|
```
|
|
142
261
|
|
|
143
|
-
Capture the store during component setup or an owned onMount callback, then pass it to store-aware atom.io operations or integrations. Getting the store creates no subscription. Direct reads such as getFromStore do not participate in SPA's dependency tracking;
|
|
262
|
+
Capture the store during component setup or an owned onMount callback, then pass it to store-aware atom.io operations or integrations. Getting the store creates no subscription. Direct reads such as getFromStore do not participate in SPA's dependency tracking; useGetter and useLoadable provide tracked reads. The returned object is a store, not a Silo or a new wrapper.
|
|
144
263
|
|
|
145
264
|
## Families
|
|
146
265
|
|
|
147
|
-
|
|
266
|
+
useGetter, useSetter, useRef, and useTimeline accept a family token followed by its key. useLoadable accepts a family, key, and optional fallback. Keys retain their declared types, including tuples, numbers, booleans, and null. Members resolve in the component's store, so isolated roots can use the same family tokens independently.
|
|
148
267
|
|
|
149
268
|
```tsx
|
|
150
|
-
import type {
|
|
151
|
-
import { useRef, useSetter, useTimeline
|
|
269
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
270
|
+
import { useGetter, useRef, useSetter, useTimeline } from "@atom.io/spa"
|
|
152
271
|
import { atomFamily, scopeFamily, timelineFamily } from "atom.io"
|
|
153
272
|
|
|
154
273
|
const countAtoms = atomFamily<number, string>({ key: `count`, default: 0 })
|
|
@@ -161,8 +280,8 @@ const historyTimelines = timelineFamily<string>({
|
|
|
161
280
|
scope: [scopeFamily(countAtoms, { timelineKey: (id) => id })],
|
|
162
281
|
})
|
|
163
282
|
|
|
164
|
-
export function FamilyCounter(props: { id: string }):
|
|
165
|
-
const
|
|
283
|
+
export function FamilyCounter(props: { id: string }): SpaElement {
|
|
284
|
+
const getCount = useGetter(countAtoms, props.id)
|
|
166
285
|
const setCount = useSetter(countAtoms, props.id)
|
|
167
286
|
const ref = useRef(buttonAtoms, props.id)
|
|
168
287
|
const history = useTimeline(historyTimelines, props.id)
|
|
@@ -174,14 +293,9 @@ export function FamilyCounter(props: { id: string }): VNode {
|
|
|
174
293
|
setCount((value) => value + 1)
|
|
175
294
|
}}
|
|
176
295
|
>
|
|
177
|
-
{
|
|
296
|
+
{getCount()}
|
|
178
297
|
</button>
|
|
179
|
-
<button
|
|
180
|
-
disabled={history().at === 0}
|
|
181
|
-
onClick={() => {
|
|
182
|
-
history().undo()
|
|
183
|
-
}}
|
|
184
|
-
>
|
|
298
|
+
<button disabled={history.getCursor() === 0} onClick={history.undo}>
|
|
185
299
|
Undo
|
|
186
300
|
</button>
|
|
187
301
|
</section>
|
|
@@ -195,7 +309,7 @@ The family and key are captured during setup and stay fixed for that component i
|
|
|
195
309
|
## Async state
|
|
196
310
|
|
|
197
311
|
```tsx
|
|
198
|
-
import type {
|
|
312
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
199
313
|
import { useLoadable, useSetter } from "@atom.io/spa"
|
|
200
314
|
import type { Loadable } from "atom.io"
|
|
201
315
|
import { atom } from "atom.io"
|
|
@@ -206,7 +320,7 @@ const greetingAtom = atom<Loadable<string>, Error>({
|
|
|
206
320
|
catch: [Error],
|
|
207
321
|
})
|
|
208
322
|
|
|
209
|
-
export function Greeting():
|
|
323
|
+
export function Greeting(): SpaElement {
|
|
210
324
|
const greeting = useLoadable(greetingAtom, `Loading…`)
|
|
211
325
|
const setGreeting = useSetter(greetingAtom)
|
|
212
326
|
return (
|
|
@@ -236,36 +350,32 @@ Atom.io owns promise settlement and subscriptions. SPA adds no fetching, retries
|
|
|
236
350
|
|
|
237
351
|
The client exports render and hydrate. Both accept a setup callback, a host Element, and optional store, idPrefix, and onError options, and return dispose and flush methods. Updates coalesce in a microtask; flush drains them synchronously. Dispose is idempotent and removes only owned nodes. Cleanup continues after individual cleanup failures and aggregates errors. A failed computation disposes its root; asynchronous update failures reach onError, while explicit flush failures throw.
|
|
238
352
|
|
|
239
|
-
The separate server entrypoint exports renderToString with the same setup callback and store/ID options. Supply a request-specific store for SSR. Server rendering retains no subscriptions and runs owner cleanup. Hydration reuses matching server nodes and IDs, attaches events, and recreates subscriptions.
|
|
353
|
+
The separate server entrypoint exports renderToString with the same setup callback and store/ID options. Supply a request-specific store for SSR. Server rendering retains no subscriptions and runs owner cleanup. Hydration reuses matching server nodes and IDs, attaches events, and recreates subscriptions. Match initial state, component structure, and valid HTML on both sides. A hydration mismatch produces one human-readable console warning per root in development and production, identifying the host and expected/found nodes. SPA repairs mismatched nodes, inserts missing nodes, and removes unexpected leftovers during the same hydration pass. Component setup and mount hooks run once, subscriptions remain active, and matching nodes are reused. Replaced nodes can lose focus, selection, or unsaved browser input; unaffected roots continue running. An explicit client idPrefix takes precedence when repairing mismatched root markers. Use explicit tbody elements in tables. Controlled form properties are applied during hydration.
|
|
240
354
|
|
|
241
|
-
The production build omits development diagnostics and invalid-input checks; the development export condition enables them. Pure render computations must not write state. Promise children, async components, portals, suspense, error boundaries, style objects, and automatic token-as-child bindings are outside this first implementation. Applications handle asynchronous data through atom.io state and synchronous conditional JSX.
|
|
355
|
+
The production build omits development-only diagnostics and invalid-input checks; the development export condition enables them. Hydration recovery warnings remain available in all builds. Pure render computations must not write state. Promise children, async components, portals, suspense, error boundaries, style objects, and automatic token-as-child bindings are outside this first implementation. Applications handle asynchronous data through atom.io state and synchronous conditional JSX.
|
|
242
356
|
|
|
243
|
-
## Astro
|
|
244
|
-
|
|
245
|
-
The integration transforms .spa.tsx and .spa.jsx files by default, so another JSX renderer can coexist. Configure include to change this filter. Top-level functions containing JSX are branded by the compiler for renderer detection.
|
|
357
|
+
## Astro state and data
|
|
246
358
|
|
|
247
|
-
|
|
248
|
-
import spa from "@atom.io/spa/astro"
|
|
249
|
-
import { defineConfig } from "astro/config"
|
|
359
|
+
The integration compiles .tsx and .jsx files by default. Use the include option to limit compilation to SPA component directories when another JSX renderer is present. Top-level functions containing JSX are branded by the compiler for renderer detection.
|
|
250
360
|
|
|
251
|
-
|
|
361
|
+
Default islands share the normal implicit atom.io store in the browser. Module-scoped tokens, SPA hooks, and ordinary getState/setState calls all address the same graph. SSR shares a separate store within each request; concurrent requests never share values. Definitions imported after an earlier island started are installed into that request's store before the next island prepares. Server reads and writes must use the selected store (through SPA hooks or store-aware atom.io operations); free getState/setState calls still target the process-global implicit store.
|
|
252
362
|
|
|
253
|
-
|
|
363
|
+
The integration starts observing browser state before island preparation. Untouched initial islands hydrate their matching server DOM. Once application state changes or a shared client:only island starts, delayed islands mount fresh against the live graph. Astro ClientRouter navigation also makes newly introduced islands mount fresh, preserving existing browser values instead of replaying the incoming server snapshot. Mounted and persisted roots keep their subscriptions and DOM. This decision is conservative across the application: even an unrelated state change disables hydration for later roots. Ordinary defaults should still produce matching initial values. DOM mismatch recovery keeps a view interactive; it does not reconstruct missing server data or resolve nondeterministic application logic.
|
|
254
364
|
|
|
255
|
-
|
|
365
|
+
With resumability/astro installed alongside SPA, resumability owns Astro's request collection, page sidecars, and browser scope. SPA awaits async state used by JSX and uses the host's renderer adapter to attach seeds to islands. Ordinary atom defaults use the host without changing the store's evaluator; private stores bind a separate scope so lazy work ends with the island. Define resumable defaults at module scope and render ordinary Astro islands. Components need no Resumption wrapper, prepareStore callback, or preload list. The same host supports plain Astro constants without atom.io. See the [resumability guide](https://atom.io.fyi/docs/spa/astro#resumability) and the inventory starter for a complete example. Resumability is an optional peer, loaded only by this adapter.
|
|
256
366
|
|
|
257
|
-
|
|
367
|
+
Server-rendered views record the state tokens they read so the browser can check readiness before hydration. If an ordinary async default is still pending without a synchronous seed, SPA mounts a fresh view with its loading state; seeded values continue to hydrate existing DOM. This also handles cached server reads and mixed ordinary/resumable state. Private server preparation and rendering are cancelled with their request, releasing cleanup resources even when a producer ignores its abort signal.
|
|
258
368
|
|
|
259
369
|
Set a component's isolate property to true to opt into a private store copied from registered definitions. An optional createStore(props, context) factory supplies a custom RootStore or promise and retains a private preparation lifetime. Custom factories that return the same store are responsible for coordinating their hydration and cleanup. Keep atom definitions at module scope in either mode.
|
|
260
370
|
|
|
261
|
-
An optional prepareStore(store, props, context) callback initializes the selected store and may return a promise. SPA awaits it before component setup on the server and browser. Existing one-argument synchronous factories still work.
|
|
371
|
+
An optional prepareStore(store, props, context) callback initializes the selected store and may return a promise. SPA awaits it before component setup on the server and browser. Existing one-argument synchronous factories still work. Shared preparation must be safe to call for multiple islands; use context.application.get(key, initialize) to create an application resource once.
|
|
262
372
|
|
|
263
373
|
The context provides element (the browser astro-island host, undefined on the server), signal, and onCleanup for the individual island. Its application provides get, signal, onCleanup, and canResume for the shared lifetime. Browser application resources survive island removal and ClientRouter navigation; they end on a full page exit, with back/forward-cache suspension preserved. SSR application resources end after the response stream finishes or is cancelled. Private islands' application resources end with the island. Use application cleanup and cancellation for shared fetches or resumption scopes; use the outer context for resources owned by one island.
|
|
264
374
|
|
|
265
375
|
Register cleanup as resources are acquired, before awaiting work that might fail. Cleanup callbacks run in reverse order and all run even if one throws; callbacks registered after cancellation run immediately. Cancelling an island stops its wait and prevents a stale mount without cancelling shared application work. Producers must honor their owner's signal to stop I/O. The example below explicitly isolates its per-island data preparation:
|
|
266
376
|
|
|
267
377
|
```tsx
|
|
268
|
-
import type {
|
|
378
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
269
379
|
import { useLoadable } from "@atom.io/spa"
|
|
270
380
|
import type { AstroStorePreparation } from "@atom.io/spa/astro"
|
|
271
381
|
import type { Loadable } from "atom.io"
|
|
@@ -277,7 +387,7 @@ const greetingAtom = atom<Loadable<string>>({
|
|
|
277
387
|
default: ``,
|
|
278
388
|
})
|
|
279
389
|
|
|
280
|
-
export default function Greeting():
|
|
390
|
+
export default function Greeting(): SpaElement {
|
|
281
391
|
const greeting = useLoadable(greetingAtom, ``)
|
|
282
392
|
return <p>{greeting().value}</p>
|
|
283
393
|
}
|
|
@@ -302,52 +412,6 @@ Greeting.prepareStore = prepare
|
|
|
302
412
|
|
|
303
413
|
AstroApplicationContext, AstroStoreContext, AstroStoreFactory, AstroStorePreparation, and Island types are exported from @atom.io/spa/astro. Preparation runs before component setup, so use the context's cleanup registrar there; use SPA's onCleanup inside components. Preparation failures reject the Astro render or hydration operation, retaining cleanup errors alongside the original failure. The factory and preparation callback are awaited per render; component setup and the standalone renderToString API remain synchronous.
|
|
304
414
|
|
|
305
|
-
```tsx
|
|
306
|
-
import type { Child, VNode } from "@atom.io/spa"
|
|
307
|
-
import { onCleanup, useId, useSetter, useValue } from "@atom.io/spa"
|
|
308
|
-
import { atom, Silo } from "atom.io"
|
|
309
|
-
import { IMPLICIT } from "atom.io/internal"
|
|
310
|
-
|
|
311
|
-
const countAtom = atom<number>({ key: `count`, default: 0 })
|
|
312
|
-
export default function Counter(props: {
|
|
313
|
-
initial: number
|
|
314
|
-
children?: Child
|
|
315
|
-
slots?: Record<string, Child>
|
|
316
|
-
}): VNode {
|
|
317
|
-
const count = useValue(countAtom)
|
|
318
|
-
const setCount = useSetter(countAtom)
|
|
319
|
-
const id = useId()
|
|
320
|
-
onCleanup(() => {
|
|
321
|
-
/* Release imperative resources owned by this instance here. */
|
|
322
|
-
})
|
|
323
|
-
return (
|
|
324
|
-
<section aria-labelledby={id}>
|
|
325
|
-
<h2 id={id}>Counter</h2>
|
|
326
|
-
{props.slots?.[`heading`]}
|
|
327
|
-
{props.children}
|
|
328
|
-
<button
|
|
329
|
-
onClick={() => {
|
|
330
|
-
setCount((value) => value + 1)
|
|
331
|
-
}}
|
|
332
|
-
>
|
|
333
|
-
{count()}
|
|
334
|
-
</button>
|
|
335
|
-
</section>
|
|
336
|
-
)
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// Astro calls this on the server and in the browser with the same serialized props.
|
|
340
|
-
Counter.createStore = (props: { initial: number }) => {
|
|
341
|
-
const silo = new Silo(
|
|
342
|
-
{ name: `counter-island`, lifespan: `ephemeral`, isProduction: true },
|
|
343
|
-
IMPLICIT.STORE,
|
|
344
|
-
)
|
|
345
|
-
silo.setState(countAtom, props.initial)
|
|
346
|
-
return silo.store
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
```
|
|
350
|
-
|
|
351
415
|
Astro client:load, client:idle, client:visible, client:media, and client:only use Astro's scheduling. The integration hydrates eligible initial server markup or renders fresh content and releases the root on astro:unmount. Default slot content arrives as children and named content through slots. Reserved astro-slot wrappers contain Astro's already-rendered HTML; never use their innerHTML escape hatch for untrusted strings.
|
|
352
416
|
|
|
353
417
|
Persisted islands receive live prop and slot updates without rerunning component setup or recreating their store. Repeated hydration calls during preparation share one factory and preparation invocation. New client mounts use the latest props and slots; hydration attaches to the original server tree first, then applies any changes received while preparing. The factory receives the initial props and runs only when an island is first mounted; put changing values in props rather than relying on the factory to run again.
|
|
@@ -358,7 +422,7 @@ The checked Astro fixture demonstrates default/named slots and custom independen
|
|
|
358
422
|
|
|
359
423
|
The build audits every browser export, including the JSX runtime, from the built JavaScript. Atom.io is an external peer in the incremental measurement. Compiler, server, and integration code have separate entrypoints. The report also includes the complete client plus atom.io, the Astro client entrypoint, and the installed Preact version under the same bundling/minification settings. These are full exported surfaces, not equivalent application benchmarks.
|
|
360
424
|
|
|
361
|
-
The hard budget is under 4,
|
|
425
|
+
The hard budget is under 4,300 bytes of ordinary level-9 gzip for the complete client export surface, including hydration recovery and its production diagnostics. Tsdown builds the package JavaScript and declarations, with separate production and development outputs that each share their runtime across entrypoints. The size audit then bundles the built exports with esbuild, minifies with Oxc, and measures compression using Node's gzip and Brotli implementations. The complete client export surface measures approximately 4.2 kB with gzip; dist/size.json records the exact build measurements. Actual application bundles add atom.io and compiler-generated application code.
|
|
362
426
|
|
|
363
427
|
Build output includes the minified audit entrypoint and machine-readable dist/size.json. These audit files are a bundled measurement; use the package exports in applications so the bundler preserves one runtime instance across entrypoints. Source tests exercise development behavior; the production test executes the audited minified artifact. Chromium checks exercise the actual Astro build, island isolation, hydration, keyed identity, focus/selection, SVG namespaces, and teardown. A fresh-cache Astro development check also covers mount hooks, shared state, and ClientRouter navigation.
|
|
364
428
|
|
|
@@ -380,7 +444,7 @@ pnpm --filter @atom.io/spa readme:check
|
|
|
380
444
|
|
|
381
445
|
Breakage exercises the packed package in isolated, locked peer environments, including the coordinated atom.io workspace candidate. Until the first published release, Breakage reports a first-release baseline; these checks establish compatibility with the declared peers rather than a previous spa release. Coverage gates require 100% of statements, branches, functions, and lines across the package source.
|
|
382
446
|
|
|
383
|
-
Tonnage measures combined browser bundles containing SPA and atom.io, with shared modules counted once and unused exports removed. The synchronous recipes include atom creation,
|
|
447
|
+
Tonnage measures combined browser bundles containing SPA and atom.io, with shared modules counted once and unused exports removed. The synchronous recipes include atom creation, useGetter, useSetter, and JSX; the client recipe adds render, the hydration recipe adds hydrate, and the Astro recipe adds the browser island adapter. The async recipe uses useLoadable with render and useSetter. The family recipe includes keyed state, refs, and timeline controls, plus atomFamily, timelineFamily, and scopeFamily. SPA declares atom.io as a peer dependency; these consumer-app measurements include it in every total. Application components, Astro scheduling code, CSS, declarations, and source maps are excluded. The full-client gzip budget above remains a separate, SPA-only audit.
|
|
384
448
|
|
|
385
449
|
## Browser serving sizes including atom.io
|
|
386
450
|
|
|
@@ -390,11 +454,11 @@ Sizes are exact minified and level-9 gzip JavaScript byte counts. Declarations,
|
|
|
390
454
|
|
|
391
455
|
| Recipe | Entry | Minified JS | Gzip JS |
|
|
392
456
|
| -------------------------------- | --------------------------------- | ----------: | -------: |
|
|
393
|
-
| Family app with refs and history | `tonnage-recipes/family-app.ts` |
|
|
394
|
-
| Async interactive client app | `tonnage-recipes/async-app.ts` | 42,
|
|
395
|
-
| Interactive client app | `tonnage-recipes/client-app.ts` |
|
|
396
|
-
| Hydrated interactive app | `tonnage-recipes/hydrated-app.ts` |
|
|
397
|
-
| Interactive Astro island | `tonnage-recipes/astro-island.ts` | 48,
|
|
457
|
+
| Family app with refs and history | `tonnage-recipes/family-app.ts` | 64,020 B | 19,088 B |
|
|
458
|
+
| Async interactive client app | `tonnage-recipes/async-app.ts` | 42,445 B | 13,332 B |
|
|
459
|
+
| Interactive client app | `tonnage-recipes/client-app.ts` | 42,108 B | 13,178 B |
|
|
460
|
+
| Hydrated interactive app | `tonnage-recipes/hydrated-app.ts` | 42,109 B | 13,176 B |
|
|
461
|
+
| Interactive Astro island | `tonnage-recipes/astro-island.ts` | 48,624 B | 15,226 B |
|
|
398
462
|
|
|
399
463
|
Report maintained with [tonnage](https://github.com/jeremybanka/tonnage).
|
|
400
464
|
|
|
@@ -411,8 +475,8 @@ SPA includes Konva, Three.js, and Motion integrations behind separate entrypoint
|
|
|
411
475
|
Import Stage, Layer, Group, Rect, Circle, Ellipse, Line, Text, Image, Path, Star, and Transformer from @atom.io/spa/konva. Stage renders a DOM container and creates its native stage after browser mounting. Compiled atom reads update native attributes; keyed children preserve node identity. Native configuration attributes and onClick, onPointerDown, onDragMove, and onDragEnd handlers are supported. Refs receive native nodes and null on cleanup. Removal destroys owned nodes and listeners.
|
|
412
476
|
|
|
413
477
|
```tsx
|
|
414
|
-
import type {
|
|
415
|
-
import {
|
|
478
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
479
|
+
import { useGetter, useSetter } from "@atom.io/spa"
|
|
416
480
|
import { Circle, Layer, Stage } from "@atom.io/spa/konva"
|
|
417
481
|
import { atom } from "atom.io"
|
|
418
482
|
|
|
@@ -420,15 +484,15 @@ const pointAtom = atom<{ x: number; y: number }>({
|
|
|
420
484
|
key: `point`,
|
|
421
485
|
default: { x: 100, y: 100 },
|
|
422
486
|
})
|
|
423
|
-
export function Editor():
|
|
424
|
-
const
|
|
487
|
+
export function Editor(): SpaElement {
|
|
488
|
+
const getPoint = useGetter(pointAtom)
|
|
425
489
|
const setPoint = useSetter(pointAtom)
|
|
426
490
|
return (
|
|
427
491
|
<Stage width={800} height={600}>
|
|
428
492
|
<Layer>
|
|
429
493
|
<Circle
|
|
430
|
-
x={
|
|
431
|
-
y={
|
|
494
|
+
x={getPoint().x}
|
|
495
|
+
y={getPoint().y}
|
|
432
496
|
radius={25}
|
|
433
497
|
fill="coral"
|
|
434
498
|
draggable
|
|
@@ -450,8 +514,8 @@ Konva owns hit testing, dragging, and draw batching. Write drag results back int
|
|
|
450
514
|
Import Canvas, Group, Mesh, PerspectiveCamera, AmbientLight, DirectionalLight, BoxGeometry, SphereGeometry, PlaneGeometry, MeshStandardMaterial, MeshBasicMaterial, and MeshNormalMaterial from @atom.io/spa/three. Canvas creates a WebGL renderer after browser mounting. Geometry and material children attach to their Mesh, with one of each supported. Position and rotation accept three-number tuples; scale also accepts a scalar.
|
|
451
515
|
|
|
452
516
|
```tsx
|
|
453
|
-
import type {
|
|
454
|
-
import {
|
|
517
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
518
|
+
import { useGetter } from "@atom.io/spa"
|
|
455
519
|
import {
|
|
456
520
|
AmbientLight,
|
|
457
521
|
BoxGeometry,
|
|
@@ -463,15 +527,15 @@ import {
|
|
|
463
527
|
import { atom } from "atom.io"
|
|
464
528
|
|
|
465
529
|
const colorAtom = atom<string>({ key: `color`, default: `coral` })
|
|
466
|
-
export function Scene():
|
|
467
|
-
const
|
|
530
|
+
export function Scene(): SpaElement {
|
|
531
|
+
const getColor = useGetter(colorAtom)
|
|
468
532
|
return (
|
|
469
533
|
<Canvas width={800} height={600}>
|
|
470
534
|
<AmbientLight intensity={0.5} />
|
|
471
535
|
<DirectionalLight position={[3, 3, 3]} />
|
|
472
536
|
<Mesh rotation={[0.3, 0.5, 0]}>
|
|
473
537
|
<BoxGeometry args={[1, 1, 1]} />
|
|
474
|
-
<MeshStandardMaterial color={
|
|
538
|
+
<MeshStandardMaterial color={getColor()} />
|
|
475
539
|
</Mesh>
|
|
476
540
|
</Canvas>
|
|
477
541
|
)
|
|
@@ -501,7 +565,7 @@ Import motionCapability from @atom.io/spa/motion and register it explicitly in r
|
|
|
501
565
|
import { render } from "@atom.io/spa"
|
|
502
566
|
import { motionCapability } from "@atom.io/spa/motion"
|
|
503
567
|
|
|
504
|
-
import { MotionPanel } from "./motion.
|
|
568
|
+
import { MotionPanel } from "./motion.tsx"
|
|
505
569
|
|
|
506
570
|
render(() => <MotionPanel />, document.getElementById(`app`)!, {
|
|
507
571
|
capabilities: [motionCapability()],
|
|
@@ -512,19 +576,19 @@ render(() => <MotionPanel />, document.getElementById(`app`)!, {
|
|
|
512
576
|
Use motion:initial, motion:animate, motion:exit, motion:transition, motion:whileHover, and motion:whileTap directly on native elements or custom tags. These are framework properties, separate from native attributes: they never become HTML attributes. An unregistered namespace or unsupported motion property produces an error. Standard XML, XMLNS, and XLink attribute namespaces retain their normal behavior.
|
|
513
577
|
|
|
514
578
|
```tsx
|
|
515
|
-
import type {
|
|
516
|
-
import {
|
|
579
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
580
|
+
import { useGetter, useSetter } from "@atom.io/spa"
|
|
517
581
|
import { atom } from "atom.io"
|
|
518
582
|
|
|
519
583
|
const targetXAtom = atom<number>({ key: `targetX`, default: 0 })
|
|
520
|
-
export function MotionPanel():
|
|
521
|
-
const
|
|
522
|
-
const
|
|
584
|
+
export function MotionPanel(): SpaElement {
|
|
585
|
+
const getTargetX = useGetter(targetXAtom)
|
|
586
|
+
const setTargetX = useSetter(targetXAtom)
|
|
523
587
|
return (
|
|
524
588
|
<section>
|
|
525
589
|
<button
|
|
526
590
|
onClick={() => {
|
|
527
|
-
|
|
591
|
+
setTargetX((value) => (value === 0 ? 200 : 0))
|
|
528
592
|
}}
|
|
529
593
|
>
|
|
530
594
|
Move
|
|
@@ -532,7 +596,7 @@ export function MotionPanel(): VNode {
|
|
|
532
596
|
<sliding-panel
|
|
533
597
|
style="display: block; width: 120px; padding: 16px; background: coral"
|
|
534
598
|
motion:initial={{ opacity: 0, x: -100 }}
|
|
535
|
-
motion:animate={{ opacity: 1, x:
|
|
599
|
+
motion:animate={{ opacity: 1, x: getTargetX() }}
|
|
536
600
|
motion:transition={{ type: `spring`, stiffness: 180, damping: 22 }}
|
|
537
601
|
motion:whileHover={{ scale: 1.05 }}
|
|
538
602
|
motion:whileTap={{ scale: 0.95 }}
|
|
@@ -552,8 +616,8 @@ Motion respects the user's reduced-motion preference by default, including chang
|
|
|
552
616
|
The same attributes animate numeric Konva properties and colors, or Three.js position, rotation, scale, light/material color, opacity, and intensity. Three.js rotation uses Euler components, not quaternion interpolation. DOM hover and tap use Motion's gesture handling; Konva gestures use native pointer events. Three.js gestures use the same raycast event layer as ordinary scene pointer handlers.
|
|
553
617
|
|
|
554
618
|
```tsx
|
|
555
|
-
import type {
|
|
556
|
-
import {
|
|
619
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
620
|
+
import { useGetter } from "@atom.io/spa"
|
|
557
621
|
import {
|
|
558
622
|
BoxGeometry,
|
|
559
623
|
Canvas,
|
|
@@ -567,13 +631,13 @@ const targetXAtom = atom<number>({
|
|
|
567
631
|
default: 1,
|
|
568
632
|
})
|
|
569
633
|
// Mount under a root with capabilities: [motionCapability()].
|
|
570
|
-
export function SpringCube():
|
|
571
|
-
const
|
|
634
|
+
export function SpringCube(): SpaElement {
|
|
635
|
+
const getTargetX = useGetter(targetXAtom)
|
|
572
636
|
return (
|
|
573
637
|
<Canvas>
|
|
574
638
|
<Mesh
|
|
575
639
|
motion:initial={{ position: [-1, 0, 0], scale: 0 }}
|
|
576
|
-
motion:animate={{ position: [
|
|
640
|
+
motion:animate={{ position: [getTargetX(), 0, 0], scale: 1 }}
|
|
577
641
|
motion:transition={{ type: `spring`, stiffness: 180, damping: 22 }}
|
|
578
642
|
motion:whileHover={{ scale: 1.2 }}
|
|
579
643
|
motion:whileTap={{ scale: 0.8 }}
|
|
@@ -590,20 +654,20 @@ export function SpringCube(): VNode {
|
|
|
590
654
|
|
|
591
655
|
```
|
|
592
656
|
|
|
593
|
-
When the motion capability is installed, Canvas draws in Motion's render phase after animated scene values update. Without it, Canvas uses requestAnimationFrame. Both drawing subscriptions and animations end with their owners. The base runtime imports no motion engine or retention coordinator. Presence hooks add approximately 300 bytes of gzip to the released 3.7 kB client surface; the optional Motion entrypoint owns the retention machinery. The full client budget is 4,
|
|
657
|
+
When the motion capability is installed, Canvas draws in Motion's render phase after animated scene values update. Without it, Canvas uses requestAnimationFrame. Both drawing subscriptions and animations end with their owners. The base runtime imports no motion engine or retention coordinator. Presence hooks add approximately 300 bytes of gzip to the released 3.7 kB client surface; the optional Motion entrypoint owns the retention machinery. The full client budget is 4,300 bytes.
|
|
594
658
|
|
|
595
659
|
### Exit animations and re-entry
|
|
596
660
|
|
|
597
661
|
Declare motion:exit on an element, custom tag, Konva node, or Three.js scene node. Conditional or keyed removal starts that target from its current Motion values. No presence wrapper is required. Register motionCapability as above.
|
|
598
662
|
|
|
599
663
|
```tsx
|
|
600
|
-
import type {
|
|
601
|
-
import {
|
|
664
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
665
|
+
import { useGetter, useSetter } from "@atom.io/spa"
|
|
602
666
|
import { atom } from "atom.io"
|
|
603
667
|
|
|
604
668
|
const visibleAtom = atom<boolean>({ key: `visible`, default: true })
|
|
605
|
-
export function DismissiblePanel():
|
|
606
|
-
const
|
|
669
|
+
export function DismissiblePanel(): SpaElement {
|
|
670
|
+
const getVisible = useGetter(visibleAtom)
|
|
607
671
|
const setVisible = useSetter(visibleAtom)
|
|
608
672
|
return (
|
|
609
673
|
<section>
|
|
@@ -614,7 +678,7 @@ export function DismissiblePanel(): VNode {
|
|
|
614
678
|
>
|
|
615
679
|
Toggle panel
|
|
616
680
|
</button>
|
|
617
|
-
{
|
|
681
|
+
{getVisible() && (
|
|
618
682
|
<sliding-panel
|
|
619
683
|
key="panel"
|
|
620
684
|
motion:initial={{ opacity: 0, y: 12 }}
|