@atom.io/spa 0.0.4 → 0.0.6
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 +224 -105
- package/README.mdx +87 -20
- 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 +9 -8
- package/dist/astro-client.js.map +1 -1
- package/dist/astro-request-DRKvDjsO.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-CYSRrRr8.d.ts → astro-shared-B9wvGIkk.d.ts} +2 -2
- package/dist/{astro-shared-CYSRrRr8.d.ts.map → astro-shared-B9wvGIkk.d.ts.map} +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +6 -8
- package/dist/astro.js.map +1 -1
- package/dist/{capabilities-D3HObAIy.d.ts → capabilities-_zOwNJ-2.d.ts} +12 -7
- package/dist/capabilities-_zOwNJ-2.d.ts.map +1 -0
- package/dist/{capabilities-BkQ2i0vV.js → capabilities-nOIitQ-_.js} +6 -4
- package/dist/capabilities-nOIitQ-_.js.map +1 -0
- package/dist/client.min.js +1 -1
- package/dist/{core-Bl1Ec1hY.js → core-DjFJ0aIJ.js} +4 -2
- package/dist/core-DjFJ0aIJ.js.map +1 -0
- package/dist/development/astro-client.js +9 -8
- package/dist/development/astro-client.js.map +1 -1
- package/dist/development/astro-request-DRKvDjsO.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 +6 -8
- package/dist/development/astro.js.map +1 -1
- package/dist/development/{capabilities-BkQ2i0vV.js → capabilities-nOIitQ-_.js} +6 -4
- package/dist/development/capabilities-nOIitQ-_.js.map +1 -0
- package/dist/development/{core-DZFaOyTO.js → core-DxPiKryn.js} +4 -2
- package/dist/development/core-DxPiKryn.js.map +1 -0
- package/dist/development/{dom-Dwa2SFTn.js → dom-BWy4dDss.js} +53 -20
- package/dist/development/dom-BWy4dDss.js.map +1 -0
- package/dist/development/floating.js +148 -0
- package/dist/development/floating.js.map +1 -0
- package/dist/development/index.js +3 -3
- package/dist/development/jsx-runtime.js +2 -2
- package/dist/development/jsx-runtime.js.map +1 -1
- package/dist/development/konva.js +2 -2
- package/dist/development/konva.js.map +1 -1
- package/dist/development/motion.js +7 -2
- package/dist/development/motion.js.map +1 -1
- package/dist/development/renderer.js +2 -2
- package/dist/development/renderer.js.map +1 -1
- package/dist/development/server-renderer-C7lGVhpo.js +90 -0
- package/dist/development/server-renderer-C7lGVhpo.js.map +1 -0
- package/dist/development/server.js +2 -83
- package/dist/development/server.js.map +1 -1
- package/dist/development/{src-BUtG4BgX.js → src-WSHJxR9b.js} +2 -2
- package/dist/development/{src-BUtG4BgX.js.map → src-WSHJxR9b.js.map} +1 -1
- package/dist/development/three.js +12 -9
- package/dist/development/three.js.map +1 -1
- package/dist/{vite-CSHoxzXU.js → development/vite-Bmyb6P5w.js} +32 -7
- package/dist/development/vite-Bmyb6P5w.js.map +1 -0
- package/dist/development/vite.js +1 -1
- package/dist/{dom-Cfj3GtQK.js → dom-BrPrxO97.js} +53 -20
- package/dist/dom-BrPrxO97.js.map +1 -0
- package/dist/floating.d.ts +16 -0
- package/dist/floating.d.ts.map +1 -0
- package/dist/floating.js +148 -0
- package/dist/floating.js.map +1 -0
- package/dist/{index-YRZ79lN5.d.ts → index-BFIjI7gF.d.ts} +5 -5
- package/dist/{index-YRZ79lN5.d.ts.map → index-BFIjI7gF.d.ts.map} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/{jsx-runtime-Q-UBV97Y.d.ts → jsx-runtime-BhiCZOYZ.d.ts} +7 -7
- package/dist/{jsx-runtime-Q-UBV97Y.d.ts.map → jsx-runtime-BhiCZOYZ.d.ts.map} +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +2 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/konva.d.ts +16 -16
- package/dist/konva.js +2 -2
- package/dist/konva.js.map +1 -1
- package/dist/motion.d.ts +1 -1
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +7 -2
- package/dist/motion.js.map +1 -1
- package/dist/renderer.d.ts +4 -4
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +2 -2
- package/dist/renderer.js.map +1 -1
- package/dist/server-renderer-D-uRg04V.js +90 -0
- package/dist/server-renderer-D-uRg04V.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/{src-DvkUMuNW.js → src-DWIqXCiz.js} +2 -2
- package/dist/{src-DvkUMuNW.js.map → src-DWIqXCiz.js.map} +1 -1
- package/dist/three.d.ts +17 -17
- package/dist/three.js +12 -9
- package/dist/three.js.map +1 -1
- package/dist/{development/vite-CSHoxzXU.js → vite-Bmyb6P5w.js} +32 -7
- package/dist/vite-Bmyb6P5w.js.map +1 -0
- package/dist/vite.js +1 -1
- package/package.json +39 -11
- package/src/astro-client.ts +17 -4
- package/src/astro-request.ts +1 -1
- 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/capabilities.ts +9 -4
- package/src/compiler.ts +28 -9
- package/src/core.ts +15 -10
- package/src/dom.ts +85 -50
- package/src/floating.ts +234 -0
- package/src/index.ts +2 -2
- package/src/jsx-runtime.ts +11 -7
- package/src/jsx-types.d.ts +2 -2
- package/src/konva.ts +3 -3
- package/src/motion.ts +11 -1
- package/src/presence.ts +1 -1
- package/src/renderer.ts +24 -18
- package/src/server-renderer.ts +162 -0
- package/src/server.ts +4 -153
- package/src/three-events.ts +14 -10
- package/src/three.ts +4 -4
- package/dist/astro-shared-BT45auwR.js.map +0 -1
- package/dist/capabilities-BkQ2i0vV.js.map +0 -1
- package/dist/capabilities-D3HObAIy.d.ts.map +0 -1
- package/dist/core-Bl1Ec1hY.js.map +0 -1
- package/dist/development/astro-shared-BT45auwR.js.map +0 -1
- package/dist/development/capabilities-BkQ2i0vV.js.map +0 -1
- package/dist/development/core-DZFaOyTO.js.map +0 -1
- package/dist/development/dom-Dwa2SFTn.js.map +0 -1
- package/dist/development/vite-CSHoxzXU.js.map +0 -1
- package/dist/dom-Cfj3GtQK.js.map +0 -1
- package/dist/vite-CSHoxzXU.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,32 +6,38 @@ 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 { useGetter,
|
|
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
|
-
key: `circle`,
|
|
22
|
-
default: null,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
export function PointEditor(): VNode {
|
|
33
|
+
export function PointEditor(): SpaElement {
|
|
26
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}
|
|
@@ -51,6 +57,60 @@ export function PointEditor(): VNode {
|
|
|
51
57
|
|
|
52
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.
|
|
53
59
|
|
|
60
|
+
Component children follow the same getter contract as named props. A component declaring string children reads a string for both literal text and expression children, including an explicit children attribute. Read props.children inside compiled JSX or a tracked binding for reactive updates; setup reads capture a snapshot. Deliberately function-valued children remain functions, including render callbacks.
|
|
61
|
+
|
|
62
|
+
## Astro
|
|
63
|
+
|
|
64
|
+
Register the Astro integration, which compiles .tsx and .jsx components by default:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import spa from "@atom.io/spa/astro"
|
|
68
|
+
import { defineConfig } from "astro/config"
|
|
69
|
+
|
|
70
|
+
export default defineConfig({ integrations: [spa()] })
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Create a counter component:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
78
|
+
import { useGetter, useSetter } from "@atom.io/spa"
|
|
79
|
+
import { atom } from "atom.io"
|
|
80
|
+
|
|
81
|
+
const countAtom = atom<number>({ key: `count`, default: 0 })
|
|
82
|
+
|
|
83
|
+
export default function Counter(): SpaElement {
|
|
84
|
+
const getCount = useGetter(countAtom)
|
|
85
|
+
const setCount = useSetter(countAtom)
|
|
86
|
+
return (
|
|
87
|
+
<button
|
|
88
|
+
onClick={() => {
|
|
89
|
+
setCount((count) => count + 1)
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
Count: {getCount()}
|
|
93
|
+
</button>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Import it into an Astro page and use client:load to make it interactive. Astro handles server rendering and browser hydration:
|
|
100
|
+
|
|
101
|
+
```astro
|
|
102
|
+
---
|
|
103
|
+
import Counter from "./Counter.tsx"
|
|
104
|
+
---
|
|
105
|
+
<html lang="en">
|
|
106
|
+
<head><title>SPA counter</title></head>
|
|
107
|
+
<body>
|
|
108
|
+
<Counter client:load />
|
|
109
|
+
</body>
|
|
110
|
+
</html>
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
|
|
54
114
|
## Vite
|
|
55
115
|
|
|
56
116
|
Add @atom.io/spa and atom.io to the application's dependencies. The spa plugin is required: the ordinary TypeScript JSX transform cannot preserve live expressions. It compiles expressions into lazy child computations and property getters; it also preserves spread precedence and live component props.
|
|
@@ -77,20 +137,32 @@ export default defineConfig({ plugins: [spa()] })
|
|
|
77
137
|
|
|
78
138
|
```
|
|
79
139
|
|
|
140
|
+
Add a host element in index.html, then mount the same counter from main.tsx:
|
|
141
|
+
|
|
142
|
+
```html
|
|
143
|
+
<!doctype html>
|
|
144
|
+
<html lang="en">
|
|
145
|
+
<head><title>SPA counter</title></head>
|
|
146
|
+
<body>
|
|
147
|
+
<div id="app"></div>
|
|
148
|
+
<script type="module" src="/main.tsx"></script>
|
|
149
|
+
</body>
|
|
150
|
+
</html>
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
|
|
80
154
|
```tsx
|
|
81
155
|
import { render } from "@atom.io/spa"
|
|
82
156
|
|
|
83
|
-
import
|
|
157
|
+
import Counter from "./Counter.tsx"
|
|
84
158
|
|
|
85
|
-
|
|
86
|
-
// Call root.dispose() when the application shell removes this root.
|
|
87
|
-
import.meta.hot?.dispose(root.dispose)
|
|
159
|
+
render(() => <Counter />, document.getElementById(`app`)!)
|
|
88
160
|
|
|
89
161
|
```
|
|
90
162
|
|
|
91
163
|
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
164
|
|
|
93
|
-
##
|
|
165
|
+
## Hooks
|
|
94
166
|
|
|
95
167
|
| API | Contract |
|
|
96
168
|
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
@@ -110,7 +182,7 @@ Call setup helpers synchronously during component setup or owned mount callbacks
|
|
|
110
182
|
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.
|
|
111
183
|
|
|
112
184
|
```tsx
|
|
113
|
-
import type {
|
|
185
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
114
186
|
import { useGetter, useTimeline, useTransaction } from "@atom.io/spa"
|
|
115
187
|
import { atom, timeline, transaction } from "atom.io"
|
|
116
188
|
|
|
@@ -123,7 +195,7 @@ const incrementTransaction = transaction<() => void>({
|
|
|
123
195
|
},
|
|
124
196
|
})
|
|
125
197
|
|
|
126
|
-
export function TimelineExample():
|
|
198
|
+
export function TimelineExample(): SpaElement {
|
|
127
199
|
const getCount = useGetter(countAtom)
|
|
128
200
|
const increment = useTransaction(incrementTransaction)
|
|
129
201
|
const history = useTimeline(historyTimeline)
|
|
@@ -167,14 +239,14 @@ HTML and SVG tags have element-specific attribute, event, and ref types. Event h
|
|
|
167
239
|
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.
|
|
168
240
|
|
|
169
241
|
```tsx
|
|
170
|
-
import type {
|
|
242
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
171
243
|
import { useStore } from "@atom.io/spa"
|
|
172
244
|
import { atom } from "atom.io"
|
|
173
245
|
import { getFromStore } from "atom.io/internal"
|
|
174
246
|
|
|
175
247
|
const countAtom = atom<number>({ key: `count`, default: 0 })
|
|
176
248
|
|
|
177
|
-
export function InspectCount():
|
|
249
|
+
export function InspectCount(): SpaElement {
|
|
178
250
|
const store = useStore()
|
|
179
251
|
return (
|
|
180
252
|
<button
|
|
@@ -196,7 +268,7 @@ Capture the store during component setup or an owned onMount callback, then pass
|
|
|
196
268
|
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.
|
|
197
269
|
|
|
198
270
|
```tsx
|
|
199
|
-
import type {
|
|
271
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
200
272
|
import { useGetter, useRef, useSetter, useTimeline } from "@atom.io/spa"
|
|
201
273
|
import { atomFamily, scopeFamily, timelineFamily } from "atom.io"
|
|
202
274
|
|
|
@@ -210,7 +282,7 @@ const historyTimelines = timelineFamily<string>({
|
|
|
210
282
|
scope: [scopeFamily(countAtoms, { timelineKey: (id) => id })],
|
|
211
283
|
})
|
|
212
284
|
|
|
213
|
-
export function FamilyCounter(props: { id: string }):
|
|
285
|
+
export function FamilyCounter(props: { id: string }): SpaElement {
|
|
214
286
|
const getCount = useGetter(countAtoms, props.id)
|
|
215
287
|
const setCount = useSetter(countAtoms, props.id)
|
|
216
288
|
const ref = useRef(buttonAtoms, props.id)
|
|
@@ -239,7 +311,7 @@ The family and key are captured during setup and stay fixed for that component i
|
|
|
239
311
|
## Async state
|
|
240
312
|
|
|
241
313
|
```tsx
|
|
242
|
-
import type {
|
|
314
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
243
315
|
import { useLoadable, useSetter } from "@atom.io/spa"
|
|
244
316
|
import type { Loadable } from "atom.io"
|
|
245
317
|
import { atom } from "atom.io"
|
|
@@ -250,7 +322,7 @@ const greetingAtom = atom<Loadable<string>, Error>({
|
|
|
250
322
|
catch: [Error],
|
|
251
323
|
})
|
|
252
324
|
|
|
253
|
-
export function Greeting():
|
|
325
|
+
export function Greeting(): SpaElement {
|
|
254
326
|
const greeting = useLoadable(greetingAtom, `Loading…`)
|
|
255
327
|
const setGreeting = useSetter(greetingAtom)
|
|
256
328
|
return (
|
|
@@ -280,36 +352,32 @@ Atom.io owns promise settlement and subscriptions. SPA adds no fetching, retries
|
|
|
280
352
|
|
|
281
353
|
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.
|
|
282
354
|
|
|
283
|
-
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.
|
|
355
|
+
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.
|
|
284
356
|
|
|
285
|
-
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.
|
|
357
|
+
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.
|
|
286
358
|
|
|
287
|
-
## Astro
|
|
359
|
+
## Astro state and data
|
|
288
360
|
|
|
289
|
-
The integration
|
|
361
|
+
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.
|
|
290
362
|
|
|
291
|
-
|
|
292
|
-
import spa from "@atom.io/spa/astro"
|
|
293
|
-
import { defineConfig } from "astro/config"
|
|
363
|
+
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.
|
|
294
364
|
|
|
295
|
-
|
|
365
|
+
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.
|
|
296
366
|
|
|
297
|
-
|
|
367
|
+
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.
|
|
298
368
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
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 must still produce matching initial values; SPA does not serialize stores or repair nondeterministic renders.
|
|
369
|
+
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.
|
|
302
370
|
|
|
303
371
|
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.
|
|
304
372
|
|
|
305
|
-
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.
|
|
373
|
+
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.
|
|
306
374
|
|
|
307
375
|
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.
|
|
308
376
|
|
|
309
377
|
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:
|
|
310
378
|
|
|
311
379
|
```tsx
|
|
312
|
-
import type {
|
|
380
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
313
381
|
import { useLoadable } from "@atom.io/spa"
|
|
314
382
|
import type { AstroStorePreparation } from "@atom.io/spa/astro"
|
|
315
383
|
import type { Loadable } from "atom.io"
|
|
@@ -321,7 +389,7 @@ const greetingAtom = atom<Loadable<string>>({
|
|
|
321
389
|
default: ``,
|
|
322
390
|
})
|
|
323
391
|
|
|
324
|
-
export default function Greeting():
|
|
392
|
+
export default function Greeting(): SpaElement {
|
|
325
393
|
const greeting = useLoadable(greetingAtom, ``)
|
|
326
394
|
return <p>{greeting().value}</p>
|
|
327
395
|
}
|
|
@@ -346,52 +414,6 @@ Greeting.prepareStore = prepare
|
|
|
346
414
|
|
|
347
415
|
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.
|
|
348
416
|
|
|
349
|
-
```tsx
|
|
350
|
-
import type { Child, VNode } from "@atom.io/spa"
|
|
351
|
-
import { onCleanup, useGetter, useId, useSetter } from "@atom.io/spa"
|
|
352
|
-
import { atom, Silo } from "atom.io"
|
|
353
|
-
import { IMPLICIT } from "atom.io/internal"
|
|
354
|
-
|
|
355
|
-
const countAtom = atom<number>({ key: `count`, default: 0 })
|
|
356
|
-
export default function Counter(props: {
|
|
357
|
-
initial: number
|
|
358
|
-
children?: Child
|
|
359
|
-
slots?: Record<string, Child>
|
|
360
|
-
}): VNode {
|
|
361
|
-
const getCount = useGetter(countAtom)
|
|
362
|
-
const setCount = useSetter(countAtom)
|
|
363
|
-
const id = useId()
|
|
364
|
-
onCleanup(() => {
|
|
365
|
-
/* Release imperative resources owned by this instance here. */
|
|
366
|
-
})
|
|
367
|
-
return (
|
|
368
|
-
<section aria-labelledby={id}>
|
|
369
|
-
<h2 id={id}>Counter</h2>
|
|
370
|
-
{props.slots?.[`heading`]}
|
|
371
|
-
{props.children}
|
|
372
|
-
<button
|
|
373
|
-
onClick={() => {
|
|
374
|
-
setCount((value) => value + 1)
|
|
375
|
-
}}
|
|
376
|
-
>
|
|
377
|
-
{getCount()}
|
|
378
|
-
</button>
|
|
379
|
-
</section>
|
|
380
|
-
)
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
// Astro calls this on the server and in the browser with the same serialized props.
|
|
384
|
-
Counter.createStore = (props: { initial: number }) => {
|
|
385
|
-
const silo = new Silo(
|
|
386
|
-
{ name: `counter-island`, lifespan: `ephemeral`, isProduction: true },
|
|
387
|
-
IMPLICIT.STORE,
|
|
388
|
-
)
|
|
389
|
-
silo.setState(countAtom, props.initial)
|
|
390
|
-
return silo.store
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
```
|
|
394
|
-
|
|
395
417
|
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.
|
|
396
418
|
|
|
397
419
|
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.
|
|
@@ -402,7 +424,7 @@ The checked Astro fixture demonstrates default/named slots and custom independen
|
|
|
402
424
|
|
|
403
425
|
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.
|
|
404
426
|
|
|
405
|
-
The hard budget is under 4,
|
|
427
|
+
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.
|
|
406
428
|
|
|
407
429
|
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.
|
|
408
430
|
|
|
@@ -434,11 +456,11 @@ Sizes are exact minified and level-9 gzip JavaScript byte counts. Declarations,
|
|
|
434
456
|
|
|
435
457
|
| Recipe | Entry | Minified JS | Gzip JS |
|
|
436
458
|
| -------------------------------- | --------------------------------- | ----------: | -------: |
|
|
437
|
-
| Family app with refs and history | `tonnage-recipes/family-app.ts` |
|
|
438
|
-
| Async interactive client app | `tonnage-recipes/async-app.ts` | 42,
|
|
439
|
-
| Interactive client app | `tonnage-recipes/client-app.ts` |
|
|
440
|
-
| Hydrated interactive app | `tonnage-recipes/hydrated-app.ts` |
|
|
441
|
-
| Interactive Astro island | `tonnage-recipes/astro-island.ts` | 48,
|
|
459
|
+
| Family app with refs and history | `tonnage-recipes/family-app.ts` | 64,161 B | 19,153 B |
|
|
460
|
+
| Async interactive client app | `tonnage-recipes/async-app.ts` | 42,586 B | 13,386 B |
|
|
461
|
+
| Interactive client app | `tonnage-recipes/client-app.ts` | 42,249 B | 13,236 B |
|
|
462
|
+
| Hydrated interactive app | `tonnage-recipes/hydrated-app.ts` | 42,250 B | 13,234 B |
|
|
463
|
+
| Interactive Astro island | `tonnage-recipes/astro-island.ts` | 48,765 B | 15,286 B |
|
|
442
464
|
|
|
443
465
|
Report maintained with [tonnage](https://github.com/jeremybanka/tonnage).
|
|
444
466
|
|
|
@@ -455,7 +477,7 @@ SPA includes Konva, Three.js, and Motion integrations behind separate entrypoint
|
|
|
455
477
|
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.
|
|
456
478
|
|
|
457
479
|
```tsx
|
|
458
|
-
import type {
|
|
480
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
459
481
|
import { useGetter, useSetter } from "@atom.io/spa"
|
|
460
482
|
import { Circle, Layer, Stage } from "@atom.io/spa/konva"
|
|
461
483
|
import { atom } from "atom.io"
|
|
@@ -464,7 +486,7 @@ const pointAtom = atom<{ x: number; y: number }>({
|
|
|
464
486
|
key: `point`,
|
|
465
487
|
default: { x: 100, y: 100 },
|
|
466
488
|
})
|
|
467
|
-
export function Editor():
|
|
489
|
+
export function Editor(): SpaElement {
|
|
468
490
|
const getPoint = useGetter(pointAtom)
|
|
469
491
|
const setPoint = useSetter(pointAtom)
|
|
470
492
|
return (
|
|
@@ -494,7 +516,7 @@ Konva owns hit testing, dragging, and draw batching. Write drag results back int
|
|
|
494
516
|
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.
|
|
495
517
|
|
|
496
518
|
```tsx
|
|
497
|
-
import type {
|
|
519
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
498
520
|
import { useGetter } from "@atom.io/spa"
|
|
499
521
|
import {
|
|
500
522
|
AmbientLight,
|
|
@@ -507,7 +529,7 @@ import {
|
|
|
507
529
|
import { atom } from "atom.io"
|
|
508
530
|
|
|
509
531
|
const colorAtom = atom<string>({ key: `color`, default: `coral` })
|
|
510
|
-
export function Scene():
|
|
532
|
+
export function Scene(): SpaElement {
|
|
511
533
|
const getColor = useGetter(colorAtom)
|
|
512
534
|
return (
|
|
513
535
|
<Canvas width={800} height={600}>
|
|
@@ -545,7 +567,7 @@ Import motionCapability from @atom.io/spa/motion and register it explicitly in r
|
|
|
545
567
|
import { render } from "@atom.io/spa"
|
|
546
568
|
import { motionCapability } from "@atom.io/spa/motion"
|
|
547
569
|
|
|
548
|
-
import { MotionPanel } from "./motion.
|
|
570
|
+
import { MotionPanel } from "./motion.tsx"
|
|
549
571
|
|
|
550
572
|
render(() => <MotionPanel />, document.getElementById(`app`)!, {
|
|
551
573
|
capabilities: [motionCapability()],
|
|
@@ -556,12 +578,12 @@ render(() => <MotionPanel />, document.getElementById(`app`)!, {
|
|
|
556
578
|
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.
|
|
557
579
|
|
|
558
580
|
```tsx
|
|
559
|
-
import type {
|
|
581
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
560
582
|
import { useGetter, useSetter } from "@atom.io/spa"
|
|
561
583
|
import { atom } from "atom.io"
|
|
562
584
|
|
|
563
585
|
const targetXAtom = atom<number>({ key: `targetX`, default: 0 })
|
|
564
|
-
export function MotionPanel():
|
|
586
|
+
export function MotionPanel(): SpaElement {
|
|
565
587
|
const getTargetX = useGetter(targetXAtom)
|
|
566
588
|
const setTargetX = useSetter(targetXAtom)
|
|
567
589
|
return (
|
|
@@ -596,7 +618,7 @@ Motion respects the user's reduced-motion preference by default, including chang
|
|
|
596
618
|
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.
|
|
597
619
|
|
|
598
620
|
```tsx
|
|
599
|
-
import type {
|
|
621
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
600
622
|
import { useGetter } from "@atom.io/spa"
|
|
601
623
|
import {
|
|
602
624
|
BoxGeometry,
|
|
@@ -611,7 +633,7 @@ const targetXAtom = atom<number>({
|
|
|
611
633
|
default: 1,
|
|
612
634
|
})
|
|
613
635
|
// Mount under a root with capabilities: [motionCapability()].
|
|
614
|
-
export function SpringCube():
|
|
636
|
+
export function SpringCube(): SpaElement {
|
|
615
637
|
const getTargetX = useGetter(targetXAtom)
|
|
616
638
|
return (
|
|
617
639
|
<Canvas>
|
|
@@ -634,19 +656,19 @@ export function SpringCube(): VNode {
|
|
|
634
656
|
|
|
635
657
|
```
|
|
636
658
|
|
|
637
|
-
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,
|
|
659
|
+
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.
|
|
638
660
|
|
|
639
661
|
### Exit animations and re-entry
|
|
640
662
|
|
|
641
663
|
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.
|
|
642
664
|
|
|
643
665
|
```tsx
|
|
644
|
-
import type {
|
|
666
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
645
667
|
import { useGetter, useSetter } from "@atom.io/spa"
|
|
646
668
|
import { atom } from "atom.io"
|
|
647
669
|
|
|
648
670
|
const visibleAtom = atom<boolean>({ key: `visible`, default: true })
|
|
649
|
-
export function DismissiblePanel():
|
|
671
|
+
export function DismissiblePanel(): SpaElement {
|
|
650
672
|
const getVisible = useGetter(visibleAtom)
|
|
651
673
|
const setVisible = useSetter(visibleAtom)
|
|
652
674
|
return (
|
|
@@ -689,6 +711,103 @@ Exit props and transition settings are read at logical removal; later state chan
|
|
|
689
711
|
|
|
690
712
|
Root disposal and fatal errors bypass exits, stop active work, and release resources immediately. Stale animation completions cannot dispose a revived instance. This API covers exit retention and cancellation; layout/pop-layout animation, variants, presence wrappers, and automatic reparenting remain outside its scope.
|
|
691
713
|
|
|
714
|
+
### Floating overlays with Motion
|
|
715
|
+
|
|
716
|
+
The optional @atom.io/spa/floating entrypoint adapts @floating-ui/dom. Install Floating UI and Motion for this example, then register both capabilities on the root:
|
|
717
|
+
|
|
718
|
+
```sh
|
|
719
|
+
pnpm add @floating-ui/dom motion
|
|
720
|
+
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
```tsx
|
|
724
|
+
import { render } from "@atom.io/spa"
|
|
725
|
+
import { floatingCapability } from "@atom.io/spa/floating"
|
|
726
|
+
import { motionCapability } from "@atom.io/spa/motion"
|
|
727
|
+
|
|
728
|
+
import { FloatingDetails } from "./floating.tsx"
|
|
729
|
+
|
|
730
|
+
render(() => <FloatingDetails id="details" />, document.getElementById(`app`)!, {
|
|
731
|
+
capabilities: [floatingCapability(), motionCapability()],
|
|
732
|
+
})
|
|
733
|
+
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
Floating positions an HTML overlay using CSS translate. Motion can animate x, y, scale, rotation, and opacity on that same element through its separate transform property:
|
|
737
|
+
|
|
738
|
+
```tsx
|
|
739
|
+
import type { SpaElement } from "@atom.io/spa"
|
|
740
|
+
import { useGetter, useId, useRef, useSetter } from "@atom.io/spa"
|
|
741
|
+
import { flip, offset, shift } from "@floating-ui/dom"
|
|
742
|
+
import { atomFamily } from "atom.io"
|
|
743
|
+
|
|
744
|
+
const floatingOpenAtoms = atomFamily<boolean, string>({
|
|
745
|
+
key: `floatingOpen`,
|
|
746
|
+
default: false,
|
|
747
|
+
})
|
|
748
|
+
const floatingTriggerAtoms = atomFamily<HTMLButtonElement | null, string>({
|
|
749
|
+
key: `floatingTrigger`,
|
|
750
|
+
default: null,
|
|
751
|
+
})
|
|
752
|
+
const middleware = [offset(8), flip(), shift({ padding: 8 })]
|
|
753
|
+
|
|
754
|
+
export function FloatingDetails(props: { id: string }): SpaElement {
|
|
755
|
+
const getOpen = useGetter(floatingOpenAtoms, props.id)
|
|
756
|
+
const setOpen = useSetter(floatingOpenAtoms, props.id)
|
|
757
|
+
const getTrigger = useGetter(floatingTriggerAtoms, props.id)
|
|
758
|
+
const attachTrigger = useRef(floatingTriggerAtoms, props.id)
|
|
759
|
+
const panelId = useId()
|
|
760
|
+
return (
|
|
761
|
+
<>
|
|
762
|
+
<button
|
|
763
|
+
ref={attachTrigger}
|
|
764
|
+
aria-expanded={getOpen()}
|
|
765
|
+
aria-controls={panelId}
|
|
766
|
+
onClick={() => {
|
|
767
|
+
setOpen((value) => !value)
|
|
768
|
+
}}
|
|
769
|
+
>
|
|
770
|
+
Details
|
|
771
|
+
</button>
|
|
772
|
+
{getOpen() && (
|
|
773
|
+
<section
|
|
774
|
+
key="details"
|
|
775
|
+
id={panelId}
|
|
776
|
+
aria-label="Details"
|
|
777
|
+
style="width: 240px; margin: 0"
|
|
778
|
+
floating:reference={getTrigger()}
|
|
779
|
+
floating:placement="bottom-start"
|
|
780
|
+
floating:middleware={middleware}
|
|
781
|
+
motion:initial={{ opacity: 0, y: -4, scale: 0.98 }}
|
|
782
|
+
motion:animate={{ opacity: 1, y: 0, scale: 1 }}
|
|
783
|
+
motion:exit={{ opacity: 0, y: -4, scale: 0.98 }}
|
|
784
|
+
>
|
|
785
|
+
More information about this item.
|
|
786
|
+
</section>
|
|
787
|
+
)}
|
|
788
|
+
</>
|
|
789
|
+
)
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
```
|
|
793
|
+
|
|
794
|
+
| Attribute | Behavior |
|
|
795
|
+
| ------------------- | --------------------------------------------------------------------------------------------------- |
|
|
796
|
+
| floating:reference | A DOM or virtual reference; null releases positioning. |
|
|
797
|
+
| floating:placement | Floating UI placement, defaulting to bottom. |
|
|
798
|
+
| floating:strategy | absolute or fixed, defaulting to absolute. |
|
|
799
|
+
| floating:middleware | Standard Floating UI middleware such as offset, flip, and shift. |
|
|
800
|
+
| floating:enabled | Defaults to true; set false when a mounted overlay is closed. |
|
|
801
|
+
| floating:autoUpdate | Defaults to true; accepts observer options, or false for positioning only on SPA attribute updates. |
|
|
802
|
+
|
|
803
|
+
The capability waits for mount and ref publication before measuring, hides the overlay until its first position is available, and reconnects observers when its reference or observer options change. Updates from obsolete calculations are ignored. Server rendering omits floating attributes and starts no observers. Virtual references can supply getBoundingClientRect and an optional contextElement, as documented by Floating UI.
|
|
804
|
+
|
|
805
|
+
Give the overlay a fixed width or width: max-content and avoid margins so measurement remains stable. Floating owns position, left, top, and translate while enabled, and temporarily owns visibility until the first measurement. Do not animate translate through Motion or assign those positioning properties through another style writer on the same element. Floating restores original inline values and priorities when disabled, removed, or disposed. Keyboard behavior, focus management, dismissal, and top-layer mounting remain application responsibilities.
|
|
806
|
+
|
|
807
|
+
Reactive inline style changes preserve the current anchor position and Motion values while new measurements are pending. Temporary hiding uses !important until the first position is available, then restores the original inline visibility value and priority.
|
|
808
|
+
|
|
809
|
+
Position updates continue during Motion's retained exits, until physical disposal. If the reference itself moves through transforms, enable animationFrame in floating:autoUpdate. Run the package's example:floating script for a scrollable experiment with same-element scaling and rotation, moving anchors, viewport collisions, positioning strategies, and interrupted exits. Its test:browser:floating script checks actual Chromium geometry in both capability registration orders.
|
|
810
|
+
|
|
692
811
|
### Renderer extensions
|
|
693
812
|
|
|
694
813
|
The renderer entrypoint exposes createSceneRenderer, sceneComponent, bindScene, and onSceneFrame for imperative scene adapters. A host supplies creation, property updates, ordered child attachment, and destruction. Its children callback receives the parent, all owned children including retained exits, and the active children in that collection. Single resource slots can use active children for replacement while retaining ownership of outgoing resources. Children of an exiting parent keep their attachments until disposal. An optional target adapter exposes native property access and events to capabilities. The shared renderer supplies reactive bindings, keyed identity, refs, and cleanup. Use mount inside an owned component or mount callback to inherit its store, capabilities, and lifetime, or render with an explicit parent and optional root options to create a standalone scene root. Scene targets must be dedicated to their renderer's children. Scene subtrees do not support text nodes or hydration; their DOM boundaries defer graphics creation until browser mount. Server rendering validates and omits capability attributes without starting animations.
|