@alecsibilia/ui-kit 0.0.0-stage → 0.1.0-alpha.0
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/CHANGELOG.md +7 -0
- package/LICENSE +201 -0
- package/README.md +233 -2
- package/bin/ui-kit.js +12 -0
- package/dist/alchemy/app.d.ts +34 -0
- package/dist/alchemy/app.js +88 -0
- package/dist/alchemy/index.d.ts +11 -0
- package/dist/alchemy/index.js +11 -0
- package/dist/alchemy/live-rooms.d.ts +21 -0
- package/dist/alchemy/live-rooms.js +31 -0
- package/dist/alchemy/migrations.d.ts +28 -0
- package/dist/alchemy/migrations.js +56 -0
- package/dist/alchemy/stage.d.ts +20 -0
- package/dist/alchemy/stage.js +20 -0
- package/dist/alchemy/wrangler-config.d.ts +76 -0
- package/dist/alchemy/wrangler-config.js +82 -0
- package/dist/build/app-modules.d.ts +11 -0
- package/dist/build/app-modules.js +40 -0
- package/dist/build/check.d.ts +4 -0
- package/dist/build/check.js +170 -0
- package/dist/build/cli.d.ts +1 -0
- package/dist/build/cli.js +79 -0
- package/dist/build/feature.d.ts +8 -0
- package/dist/build/feature.js +24 -0
- package/dist/build/index.d.ts +13 -0
- package/dist/build/index.js +13 -0
- package/dist/build/measure-cpu.d.ts +2 -0
- package/dist/build/measure-cpu.js +196 -0
- package/dist/build/prerender.d.ts +5 -0
- package/dist/build/prerender.js +109 -0
- package/dist/build/preview.d.ts +7 -0
- package/dist/build/preview.js +41 -0
- package/dist/build/seo-files.d.ts +27 -0
- package/dist/build/seo-files.js +24 -0
- package/dist/client/head-swap.d.ts +45 -0
- package/dist/client/head-swap.js +183 -0
- package/dist/client/hydration-pass.d.ts +56 -0
- package/dist/client/hydration-pass.js +186 -0
- package/dist/client/hydration-reset.d.ts +82 -0
- package/dist/client/hydration-reset.js +154 -0
- package/dist/client/index.d.ts +37 -0
- package/dist/client/index.js +65 -0
- package/dist/client/nav-client.d.ts +35 -0
- package/dist/client/nav-client.js +371 -0
- package/dist/live/collab/doc-provider.d.ts +74 -0
- package/dist/live/collab/doc-provider.js +412 -0
- package/dist/live/collab/index.d.ts +51 -0
- package/dist/live/collab/index.jsx +142 -0
- package/dist/live/collab-status.d.ts +25 -0
- package/dist/live/collab-status.js +17 -0
- package/dist/live/cursors/cursor-engine.d.ts +57 -0
- package/dist/live/cursors/cursor-engine.js +243 -0
- package/dist/live/cursors/index.d.ts +46 -0
- package/dist/live/cursors/index.jsx +110 -0
- package/dist/live/declaration.d.ts +113 -0
- package/dist/live/declaration.js +94 -0
- package/dist/live/index.d.ts +8 -0
- package/dist/live/index.js +8 -0
- package/dist/live/protocol.d.ts +224 -0
- package/dist/live/protocol.js +272 -0
- package/dist/live/server/doc-store.d.ts +68 -0
- package/dist/live/server/doc-store.js +187 -0
- package/dist/live/server/index.d.ts +60 -0
- package/dist/live/server/index.js +77 -0
- package/dist/live/server/room-presence.d.ts +24 -0
- package/dist/live/server/room-presence.js +123 -0
- package/dist/live/server/room-sockets.d.ts +65 -0
- package/dist/live/server/room-sockets.js +97 -0
- package/dist/live/server/room.d.ts +20 -0
- package/dist/live/server/room.js +348 -0
- package/dist/live/server/route.d.ts +56 -0
- package/dist/live/server/route.js +159 -0
- package/dist/live/server/types.d.ts +163 -0
- package/dist/live/server/types.js +2 -0
- package/dist/logic/agent-actions.d.ts +133 -0
- package/dist/logic/agent-actions.js +150 -0
- package/dist/logic/command-types.d.ts +53 -0
- package/dist/logic/command-types.js +0 -0
- package/dist/logic/dev.d.ts +9 -0
- package/dist/logic/dev.js +10 -0
- package/dist/logic/draft-rebase.d.ts +59 -0
- package/dist/logic/draft-rebase.js +71 -0
- package/dist/logic/form-state.d.ts +105 -0
- package/dist/logic/form-state.js +93 -0
- package/dist/logic/head.d.ts +145 -0
- package/dist/logic/head.js +140 -0
- package/dist/logic/index.d.ts +27 -0
- package/dist/logic/index.js +25 -0
- package/dist/logic/island-def.d.ts +89 -0
- package/dist/logic/island-def.js +59 -0
- package/dist/logic/kit-commands.d.ts +104 -0
- package/dist/logic/kit-commands.js +72 -0
- package/dist/logic/kit-errors.d.ts +25 -0
- package/dist/logic/kit-errors.js +6 -0
- package/dist/logic/listen.d.ts +99 -0
- package/dist/logic/listen.js +92 -0
- package/dist/logic/mutation-def.d.ts +65 -0
- package/dist/logic/mutation-def.js +43 -0
- package/dist/logic/navigation-data.d.ts +50 -0
- package/dist/logic/navigation-data.js +55 -0
- package/dist/logic/navigation-policy.d.ts +74 -0
- package/dist/logic/navigation-policy.js +127 -0
- package/dist/logic/page-model-def.d.ts +108 -0
- package/dist/logic/page-model-def.js +31 -0
- package/dist/logic/path.d.ts +31 -0
- package/dist/logic/path.js +48 -0
- package/dist/logic/query-def.d.ts +56 -0
- package/dist/logic/query-def.js +37 -0
- package/dist/logic/query-key.d.ts +24 -0
- package/dist/logic/query-key.js +35 -0
- package/dist/logic/query-types.d.ts +28 -0
- package/dist/logic/query-types.js +2 -0
- package/dist/logic/resources.d.ts +163 -0
- package/dist/logic/resources.js +62 -0
- package/dist/logic/result.d.ts +30 -0
- package/dist/logic/result.js +23 -0
- package/dist/logic/route-model.d.ts +139 -0
- package/dist/logic/route-model.js +207 -0
- package/dist/logic/route-params.d.ts +80 -0
- package/dist/logic/route-params.js +114 -0
- package/dist/logic/route-table.d.ts +308 -0
- package/dist/logic/route-table.js +206 -0
- package/dist/logic/seo.d.ts +61 -0
- package/dist/logic/seo.js +101 -0
- package/dist/logic/site.d.ts +12 -0
- package/dist/logic/site.js +0 -0
- package/dist/logic/subscriptions.d.ts +177 -0
- package/dist/logic/subscriptions.js +152 -0
- package/dist/render/index.d.ts +32 -0
- package/dist/render/index.js +52 -0
- package/dist/runtime/island-wake.d.ts +38 -0
- package/dist/runtime/island-wake.js +147 -0
- package/dist/runtime/query-scope.d.ts +224 -0
- package/dist/runtime/query-scope.js +222 -0
- package/dist/runtime/room-hub.d.ts +107 -0
- package/dist/runtime/room-hub.js +307 -0
- package/dist/runtime/subscription-runner.d.ts +71 -0
- package/dist/runtime/subscription-runner.js +240 -0
- package/dist/server/bindings.d.ts +41 -0
- package/dist/server/bindings.js +74 -0
- package/dist/server/browser.d.ts +9 -0
- package/dist/server/browser.js +9 -0
- package/dist/server/edge-cache.d.ts +28 -0
- package/dist/server/edge-cache.js +35 -0
- package/dist/server/errors.d.ts +45 -0
- package/dist/server/errors.js +36 -0
- package/dist/server/form-actions-setup.d.ts +1 -0
- package/dist/server/form-actions-setup.js +15 -0
- package/dist/server/form-actions.d.ts +121 -0
- package/dist/server/form-actions.js +211 -0
- package/dist/server/index.d.ts +36 -0
- package/dist/server/index.js +35 -0
- package/dist/server/inputs.d.ts +45 -0
- package/dist/server/inputs.js +77 -0
- package/dist/server/rate-limit.d.ts +29 -0
- package/dist/server/rate-limit.js +32 -0
- package/dist/server/read-cache.d.ts +74 -0
- package/dist/server/read-cache.js +58 -0
- package/dist/server/request-info.d.ts +17 -0
- package/dist/server/request-info.js +11 -0
- package/dist/server/request.d.ts +52 -0
- package/dist/server/request.js +73 -0
- package/dist/server/response-cookies.d.ts +23 -0
- package/dist/server/response-cookies.js +24 -0
- package/dist/server/run-effect.d.ts +42 -0
- package/dist/server/run-effect.js +92 -0
- package/dist/server/run.d.ts +63 -0
- package/dist/server/run.js +66 -0
- package/dist/server/session.d.ts +125 -0
- package/dist/server/session.js +247 -0
- package/dist/test/fake-bindings.d.ts +32 -0
- package/dist/test/fake-bindings.js +108 -0
- package/dist/test/fake-room.d.ts +66 -0
- package/dist/test/fake-room.js +216 -0
- package/dist/test/index.d.ts +19 -0
- package/dist/test/index.js +44 -0
- package/dist/test/probe.d.ts +11 -0
- package/dist/test/probe.js +11 -0
- package/dist/test/solid-jsx.d.ts +23 -0
- package/dist/test/solid-jsx.js +28 -0
- package/dist/test/solid-preload.d.ts +1 -0
- package/dist/test/solid-preload.js +29 -0
- package/dist/ui/code-editor/index.d.ts +21 -0
- package/dist/ui/code-editor/index.jsx +286 -0
- package/dist/ui/collab-text/index.d.ts +29 -0
- package/dist/ui/collab-text/index.jsx +96 -0
- package/dist/ui/components/controls.d.ts +69 -0
- package/dist/ui/components/controls.jsx +81 -0
- package/dist/ui/components/feedback.d.ts +26 -0
- package/dist/ui/components/feedback.jsx +80 -0
- package/dist/ui/components/layout.d.ts +74 -0
- package/dist/ui/components/layout.jsx +146 -0
- package/dist/ui/components/lists.d.ts +69 -0
- package/dist/ui/components/lists.jsx +133 -0
- package/dist/ui/components/navigation.d.ts +73 -0
- package/dist/ui/components/navigation.jsx +112 -0
- package/dist/ui/components/text.d.ts +34 -0
- package/dist/ui/components/text.jsx +163 -0
- package/dist/ui/index.d.ts +7 -0
- package/dist/ui/index.js +7 -0
- package/dist/ui/jsx-runtime.d.ts +19 -0
- package/dist/ui/jsx-runtime.js +0 -0
- package/dist/ui/list-keys.d.ts +31 -0
- package/dist/ui/list-keys.js +45 -0
- package/dist/ui/styles/base.css +38 -0
- package/dist/ui/styles/components.css +608 -0
- package/dist/ui/styles/tokens.css +27 -0
- package/dist/ui/styles/transitions.css +23 -0
- package/dist/ui/styles/workbench.css +428 -0
- package/dist/ui/styles.css +9 -0
- package/dist/view/agent-actions-view.d.ts +30 -0
- package/dist/view/agent-actions-view.js +27 -0
- package/dist/view/agent-surface.d.ts +42 -0
- package/dist/view/agent-surface.js +123 -0
- package/dist/view/app-scope.d.ts +51 -0
- package/dist/view/app-scope.js +75 -0
- package/dist/view/boundary.d.ts +18 -0
- package/dist/view/boundary.jsx +26 -0
- package/dist/view/command-runner.d.ts +16 -0
- package/dist/view/command-runner.js +245 -0
- package/dist/view/form.d.ts +82 -0
- package/dist/view/form.jsx +109 -0
- package/dist/view/head-view.d.ts +31 -0
- package/dist/view/head-view.js +46 -0
- package/dist/view/index.d.ts +41 -0
- package/dist/view/index.js +40 -0
- package/dist/view/island-root.d.ts +30 -0
- package/dist/view/island-root.js +36 -0
- package/dist/view/island.d.ts +102 -0
- package/dist/view/island.jsx +154 -0
- package/dist/view/match.d.ts +41 -0
- package/dist/view/match.js +111 -0
- package/dist/view/model.d.ts +92 -0
- package/dist/view/model.js +162 -0
- package/dist/view/navigation-head.d.ts +29 -0
- package/dist/view/navigation-head.jsx +38 -0
- package/dist/view/page-model.d.ts +46 -0
- package/dist/view/page-model.js +146 -0
- package/dist/view/query-effects.d.ts +87 -0
- package/dist/view/query-effects.js +147 -0
- package/dist/view/query-ok.d.ts +45 -0
- package/dist/view/query-ok.js +96 -0
- package/dist/view/query.d.ts +115 -0
- package/dist/view/query.jsx +179 -0
- package/dist/view/result-view.d.ts +14 -0
- package/dist/view/result-view.jsx +15 -0
- package/dist/view/route-pages.d.ts +43 -0
- package/dist/view/route-pages.js +59 -0
- package/dist/view/router.d.ts +44 -0
- package/dist/view/router.js +123 -0
- package/dist/vite/dev-middleware.d.ts +12 -0
- package/dist/vite/dev-middleware.js +39 -0
- package/dist/vite/dev-objects.d.ts +25 -0
- package/dist/vite/dev-objects.js +127 -0
- package/dist/vite/dev-platform.d.ts +19 -0
- package/dist/vite/dev-platform.js +77 -0
- package/dist/vite/dev-seo-files.d.ts +11 -0
- package/dist/vite/dev-seo-files.js +40 -0
- package/dist/vite/index.d.ts +53 -0
- package/dist/vite/index.js +148 -0
- package/dist/vite/local-config.d.ts +34 -0
- package/dist/vite/local-config.js +72 -0
- package/dist/vite/worker-build.d.ts +24 -0
- package/dist/vite/worker-build.js +84 -0
- package/dist/worker/create-worker.d.ts +52 -0
- package/dist/worker/create-worker.js +90 -0
- package/dist/worker/index.d.ts +12 -0
- package/dist/worker/index.js +12 -0
- package/dist/worker/page-routes.d.ts +88 -0
- package/dist/worker/page-routes.js +100 -0
- package/dist/worker/page-status.d.ts +41 -0
- package/dist/worker/page-status.js +23 -0
- package/dist/worker/request-prelude.d.ts +69 -0
- package/dist/worker/request-prelude.js +107 -0
- package/dist/worker/security.d.ts +76 -0
- package/dist/worker/security.js +137 -0
- package/dist/worker/server-app.d.ts +54 -0
- package/dist/worker/server-app.js +76 -0
- package/guards/browser-only.js +5 -0
- package/guards/node-only.js +6 -0
- package/guards/server-only.js +5 -0
- package/migrations/0001-sessions.sql +22 -0
- package/package.json +233 -5
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model subscriptions (Elm / Foldkit `subscriptions`), as plain data.
|
|
3
|
+
* Import-free: a `.model.ts` builds them from its state; the kit starts,
|
|
4
|
+
* stops and diffs them (`subscription-runner.ts`).
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* subscriptions: (model) =>
|
|
8
|
+
* model.mode === "Live" ? [channel("/api/live-feed", decodeFeedFrame, (f) => ({ _tag: "FramePushed", f }))] : [],
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Identity: a subscription's `key`. Between two lists, same key = keep
|
|
12
|
+
* running (its message mappers are swapped for the newest ones); new key =
|
|
13
|
+
* start; missing key = stop.
|
|
14
|
+
*
|
|
15
|
+
* - Derived keys (no `key` option): kind + parameters (`every:1000`,
|
|
16
|
+
* `channel:/live/feed`). Several subscriptions with the same derived key
|
|
17
|
+
* all run: the runner numbers repeats by position among that key
|
|
18
|
+
* (`every:1000`, `every:1000#2`), like Elm, where two `Time.every 1000`
|
|
19
|
+
* with different Messages both fire. Their order in the list is their
|
|
20
|
+
* identity, so a model that inserts one in front shifts the mapper, not the
|
|
21
|
+
* timer.
|
|
22
|
+
* - Explicit keys (`{ key: "clock" }`) pin identity regardless of position.
|
|
23
|
+
* They still include the parameters (`every:1000:clock`,
|
|
24
|
+
* `channel:<url>:feed`), so a changed URL or interval restarts the
|
|
25
|
+
* subscription instead of silently keeping the old socket / timer. Two
|
|
26
|
+
* subscriptions with the same explicit key are a bug: the runner throws in
|
|
27
|
+
* development and logs (keeping the first) in production.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Presence of a live room as Messages, for any model (page model or
|
|
31
|
+
* island model). The page shares one socket per room with every other
|
|
32
|
+
* user of it (another `presence`, `<LiveCursors>`, the collab part).
|
|
33
|
+
* Cursor frames never reach `toMessage` (they are drawn by `<LiveCursors>`
|
|
34
|
+
* and stay out of the Message trace).
|
|
35
|
+
*
|
|
36
|
+
* @param room - A declared room (`roomRef(LIVE_ROOMS, type, key)`).
|
|
37
|
+
* @param toMessage - Presence -> Message. Keep it a plain wrapper; decide in `update`.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* subscriptions: (model) => [presence(model.room, (p) => ({ _tag: "PresenceChanged", presence: p }))]
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function presence(room, toMessage) {
|
|
45
|
+
return {
|
|
46
|
+
_tag: 'Room',
|
|
47
|
+
key: `room:${room.path}:presence`,
|
|
48
|
+
keySource: 'derived',
|
|
49
|
+
path: room.path,
|
|
50
|
+
receive: (event) => {
|
|
51
|
+
if (event._tag === 'Status') {
|
|
52
|
+
if (event.status === 'Connecting')
|
|
53
|
+
return toMessage({ _tag: 'Connecting' });
|
|
54
|
+
if (event.status === 'Closed')
|
|
55
|
+
return toMessage({ _tag: 'Offline' });
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const frame = event.frame;
|
|
59
|
+
if (frame.t !== 'presence')
|
|
60
|
+
return undefined;
|
|
61
|
+
return toMessage({
|
|
62
|
+
_tag: 'Here',
|
|
63
|
+
self: event.welcome?.self ?? '',
|
|
64
|
+
peers: frame.peers,
|
|
65
|
+
tabs: frame.tabs,
|
|
66
|
+
access: event.welcome?.access ?? 'Reader',
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The room's `saved` frames as Messages: a collaborative doc's persisted
|
|
73
|
+
* copy changed, so a model can `Refetch` the query that reads it (the
|
|
74
|
+
* doc's contents never become Messages). Shares the room's one socket.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* subscriptions: (model) => [roomSaved(planRoom(model.planId), (saved) => ({ _tag: "NotesSaved", doc: saved.doc }))]
|
|
79
|
+
* // update: NotesSaved -> [model, [refetch<typeof planCollabQueries>("planCollab")("notes")]]
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export function roomSaved(room, toMessage) {
|
|
83
|
+
return {
|
|
84
|
+
_tag: 'Room',
|
|
85
|
+
key: `room:${room.path}:saved`,
|
|
86
|
+
keySource: 'derived',
|
|
87
|
+
path: room.path,
|
|
88
|
+
receive: (event) => event._tag === 'Frame' && event.frame.t === 'saved'
|
|
89
|
+
? toMessage({ doc: event.frame.doc, at: event.frame.at })
|
|
90
|
+
: undefined,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Sends `toMessage(Date.now())` every `ms` ms while it is in the list.
|
|
95
|
+
* Two `every` with the same `ms` both run (see the identity rules above).
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* every(1000, (now) => ({ _tag: "ClockTicked", now }))
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export function every(ms, toMessage, options) {
|
|
103
|
+
const explicit = options?.key;
|
|
104
|
+
return explicit === undefined
|
|
105
|
+
? {
|
|
106
|
+
_tag: 'Every',
|
|
107
|
+
key: `every:${ms}`,
|
|
108
|
+
keySource: 'derived',
|
|
109
|
+
ms,
|
|
110
|
+
toMessage,
|
|
111
|
+
}
|
|
112
|
+
: {
|
|
113
|
+
_tag: 'Every',
|
|
114
|
+
key: `every:${ms}:${explicit}`,
|
|
115
|
+
keySource: 'explicit',
|
|
116
|
+
ms,
|
|
117
|
+
toMessage,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Listens to a WebSocket channel while it is in the list.
|
|
122
|
+
*
|
|
123
|
+
* @param url - `ws(s)://...` or a same-origin path.
|
|
124
|
+
* @param decode - Schema-ish decoder over the frame (parsed JSON, or the raw
|
|
125
|
+
* text with `frames: "text"`); `undefined` drops it.
|
|
126
|
+
* @param toMessage - Decoded frame -> Message.
|
|
127
|
+
* @param options - `onStatus` (connection state -> Message), `frames`, `key`
|
|
128
|
+
* (pins identity; the URL stays part of the key).
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* channel("/api/live-feed", decodeLiveFeedFrame, (frame) => ({ _tag: "FramePushed", frame }), {
|
|
133
|
+
* onStatus: (status) => ({ _tag: "ChannelStatusChanged", status }),
|
|
134
|
+
* })
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export function channel(url, decode, toMessage, options) {
|
|
138
|
+
return {
|
|
139
|
+
_tag: 'Channel',
|
|
140
|
+
key: options?.key === undefined
|
|
141
|
+
? `channel:${url}`
|
|
142
|
+
: `channel:${url}:${options.key}`,
|
|
143
|
+
keySource: options?.key === undefined ? 'derived' : 'explicit',
|
|
144
|
+
url,
|
|
145
|
+
frames: options?.frames ?? 'json',
|
|
146
|
+
receive: (raw) => {
|
|
147
|
+
const value = decode(raw);
|
|
148
|
+
return value === undefined ? undefined : toMessage(value);
|
|
149
|
+
},
|
|
150
|
+
onStatus: options?.onStatus,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Element as SolidElement } from 'solid-js';
|
|
2
|
+
/**
|
|
3
|
+
* Removes every executable `<script>` (Solid's hydration bootstrap and
|
|
4
|
+
* serialization scripts, the client entry) and every
|
|
5
|
+
* `<link rel="modulepreload">` from a whole page that rendered no island
|
|
6
|
+
* root, so the page ships no JS at all. Data blocks (`application/ld+json`,
|
|
7
|
+
* the agent manifest) stay. Kit-internal; exported for tests.
|
|
8
|
+
*/
|
|
9
|
+
export declare function withoutIslandScripts(html: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* The page renderer for the app's server entry (`src/entry-server.tsx`):
|
|
12
|
+
* `<Document><App /></Document>` through Solid's `renderToStream`, like
|
|
13
|
+
* the Solid plugin's generated entry, plus one step: a page rendered whole
|
|
14
|
+
* (`renderMode: "async"`, the default) that contains no island root gets
|
|
15
|
+
* no JS at all: no client entry, no hydration bootstrap or serialization
|
|
16
|
+
* scripts, no modulepreload links (`withoutIslandScripts`). A streamed
|
|
17
|
+
* page keeps them (its head leaves before the body is known).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* // src/entry-server.tsx
|
|
22
|
+
* import manifest from "virtual:solid-manifest";
|
|
23
|
+
* export const render = createPageRenderer({ manifest, Document, App });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function createPageRenderer(options: {
|
|
27
|
+
readonly manifest: unknown;
|
|
28
|
+
readonly Document: (props: {
|
|
29
|
+
readonly children: SolidElement;
|
|
30
|
+
}) => SolidElement;
|
|
31
|
+
readonly App: () => SolidElement;
|
|
32
|
+
}): (request?: Request, context?: unknown) => unknown;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getRequestEvent, renderToStream } from '@solidjs/web';
|
|
2
|
+
import { createComponent } from 'solid-js';
|
|
3
|
+
import { ISLAND_ATTR } from '../logic/island-def.js';
|
|
4
|
+
/** Script types that are data, not code (JSON-LD, the agent manifest): kept. */
|
|
5
|
+
const DATA_SCRIPT = /\stype="(?!module"|text\/javascript")[^"]+"/;
|
|
6
|
+
/**
|
|
7
|
+
* Removes every executable `<script>` (Solid's hydration bootstrap and
|
|
8
|
+
* serialization scripts, the client entry) and every
|
|
9
|
+
* `<link rel="modulepreload">` from a whole page that rendered no island
|
|
10
|
+
* root, so the page ships no JS at all. Data blocks (`application/ld+json`,
|
|
11
|
+
* the agent manifest) stay. Kit-internal; exported for tests.
|
|
12
|
+
*/
|
|
13
|
+
export function withoutIslandScripts(html) {
|
|
14
|
+
if (html.includes(`${ISLAND_ATTR.name}=`))
|
|
15
|
+
return html;
|
|
16
|
+
return html
|
|
17
|
+
.replace(/<script\b([^>]*)>[\s\S]*?<\/script>(?:<!--xs-->)?/g, (tag, attrs) => (DATA_SCRIPT.test(attrs) ? tag : ''))
|
|
18
|
+
.replace(/<link\b[^>]*\brel="modulepreload"[^>]*>/g, '');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The page renderer for the app's server entry (`src/entry-server.tsx`):
|
|
22
|
+
* `<Document><App /></Document>` through Solid's `renderToStream`, like
|
|
23
|
+
* the Solid plugin's generated entry, plus one step: a page rendered whole
|
|
24
|
+
* (`renderMode: "async"`, the default) that contains no island root gets
|
|
25
|
+
* no JS at all: no client entry, no hydration bootstrap or serialization
|
|
26
|
+
* scripts, no modulepreload links (`withoutIslandScripts`). A streamed
|
|
27
|
+
* page keeps them (its head leaves before the body is known).
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // src/entry-server.tsx
|
|
32
|
+
* import manifest from "virtual:solid-manifest";
|
|
33
|
+
* export const render = createPageRenderer({ manifest, Document, App });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function createPageRenderer(options) {
|
|
37
|
+
return () => {
|
|
38
|
+
const event = getRequestEvent();
|
|
39
|
+
const result = renderToStream(() => createComponent(options.Document, {
|
|
40
|
+
get children() {
|
|
41
|
+
return createComponent(options.App, {});
|
|
42
|
+
},
|
|
43
|
+
}), {
|
|
44
|
+
manifest: options.manifest,
|
|
45
|
+
nonce: event?.nonce,
|
|
46
|
+
signal: event?.request.signal,
|
|
47
|
+
});
|
|
48
|
+
if (event?.renderMode !== 'async')
|
|
49
|
+
return result;
|
|
50
|
+
return Promise.resolve(result).then((html) => withoutIslandScripts(html));
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-only helpers for client-only islands: the wake triggers and the
|
|
3
|
+
* replay of the interaction that woke them. No Solid; used by the nested
|
|
4
|
+
* `<Island load>` (inside a hydrated island) and by the island client entry
|
|
5
|
+
* for page-level lazy islands.
|
|
6
|
+
*/
|
|
7
|
+
/** When a client-only island renders: `load` at once, the rest on a trigger. */
|
|
8
|
+
export type WakeTrigger = 'load' | 'visible' | 'interaction' | 'idle';
|
|
9
|
+
/** The fallback element an early click / focus hit, by role-ish tag + label. */
|
|
10
|
+
export interface ReplayTarget {
|
|
11
|
+
readonly kind: 'click' | 'focus';
|
|
12
|
+
readonly tag: string;
|
|
13
|
+
readonly label: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Re-applies the last click / focus that reached the fallback before the
|
|
17
|
+
* island mounted, on the island element with the same tag and label (a
|
|
18
|
+
* fallback "Spells" button -> the island's "Spells" button). Enter / Space
|
|
19
|
+
* on a focused button fire `click`, so keyboard activation is covered too.
|
|
20
|
+
* Nothing happens when the island has no matching element: replaying at
|
|
21
|
+
* the old coordinates would hit whatever the new layout put there.
|
|
22
|
+
*/
|
|
23
|
+
export declare function replayInto(host: HTMLElement, wanted: ReplayTarget | undefined): void;
|
|
24
|
+
/**
|
|
25
|
+
* Records the last click / focus on `host` (the fallback) until `stop()`.
|
|
26
|
+
* Clicks win over focus.
|
|
27
|
+
*/
|
|
28
|
+
export declare function recordInteractions(host: HTMLElement): {
|
|
29
|
+
readonly last: () => ReplayTarget | undefined;
|
|
30
|
+
readonly stop: () => void;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Calls `wake()` once when `trigger` fires for `host`; returns a cancel
|
|
34
|
+
* function. `visible` uses an IntersectionObserver plus a scroll / resize
|
|
35
|
+
* check; `interaction` any pointer or focus on the host; `idle`
|
|
36
|
+
* `requestIdleCallback` (2 s timeout; a 200 ms timer without it).
|
|
37
|
+
*/
|
|
38
|
+
export declare function onWake(host: HTMLElement, trigger: WakeTrigger, wake: () => void): () => void;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-only helpers for client-only islands: the wake triggers and the
|
|
3
|
+
* replay of the interaction that woke them. No Solid; used by the nested
|
|
4
|
+
* `<Island load>` (inside a hydrated island) and by the island client entry
|
|
5
|
+
* for page-level lazy islands.
|
|
6
|
+
*/
|
|
7
|
+
/** Elements a user can click or focus (what a replayed event can land on). */
|
|
8
|
+
const INTERACTIVE = "button, a[href], input, select, textarea, summary, [role='button'], [tabindex]:not([tabindex='-1'])";
|
|
9
|
+
function labelOf(el) {
|
|
10
|
+
return (el.getAttribute('aria-label') ?? el.textContent ?? '').trim();
|
|
11
|
+
}
|
|
12
|
+
function describeTarget(host, target, kind) {
|
|
13
|
+
const el = target instanceof Element ? target.closest(INTERACTIVE) : null;
|
|
14
|
+
if (!el || !host.contains(el))
|
|
15
|
+
return undefined;
|
|
16
|
+
return { kind, tag: el.tagName, label: labelOf(el) };
|
|
17
|
+
}
|
|
18
|
+
function findReplayTarget(host, wanted) {
|
|
19
|
+
for (const el of host.querySelectorAll(INTERACTIVE)) {
|
|
20
|
+
if (el.tagName === wanted.tag && labelOf(el) === wanted.label)
|
|
21
|
+
return el;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Re-applies the last click / focus that reached the fallback before the
|
|
27
|
+
* island mounted, on the island element with the same tag and label (a
|
|
28
|
+
* fallback "Spells" button -> the island's "Spells" button). Enter / Space
|
|
29
|
+
* on a focused button fire `click`, so keyboard activation is covered too.
|
|
30
|
+
* Nothing happens when the island has no matching element: replaying at
|
|
31
|
+
* the old coordinates would hit whatever the new layout put there.
|
|
32
|
+
*/
|
|
33
|
+
export function replayInto(host, wanted) {
|
|
34
|
+
if (!wanted)
|
|
35
|
+
return;
|
|
36
|
+
const el = findReplayTarget(host, wanted);
|
|
37
|
+
if (!el)
|
|
38
|
+
return;
|
|
39
|
+
el.focus({ preventScroll: true });
|
|
40
|
+
if (wanted.kind === 'click')
|
|
41
|
+
el.click();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Records the last click / focus on `host` (the fallback) until `stop()`.
|
|
45
|
+
* Clicks win over focus.
|
|
46
|
+
*/
|
|
47
|
+
export function recordInteractions(host) {
|
|
48
|
+
let pending;
|
|
49
|
+
const recordClick = (event) => {
|
|
50
|
+
pending = describeTarget(host, event.target, 'click') ?? pending;
|
|
51
|
+
};
|
|
52
|
+
const recordFocus = (event) => {
|
|
53
|
+
const focus = describeTarget(host, event.target, 'focus');
|
|
54
|
+
if (focus && pending?.kind !== 'click')
|
|
55
|
+
pending = focus;
|
|
56
|
+
};
|
|
57
|
+
host.addEventListener('click', recordClick, true);
|
|
58
|
+
host.addEventListener('focusin', recordFocus, true);
|
|
59
|
+
return {
|
|
60
|
+
last: () => pending,
|
|
61
|
+
stop: () => {
|
|
62
|
+
host.removeEventListener('click', recordClick, true);
|
|
63
|
+
host.removeEventListener('focusin', recordFocus, true);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Calls `wake()` once when `trigger` fires for `host`; returns a cancel
|
|
69
|
+
* function. `visible` uses an IntersectionObserver plus a scroll / resize
|
|
70
|
+
* check; `interaction` any pointer or focus on the host; `idle`
|
|
71
|
+
* `requestIdleCallback` (2 s timeout; a 200 ms timer without it).
|
|
72
|
+
*/
|
|
73
|
+
export function onWake(host, trigger, wake) {
|
|
74
|
+
let fired = false;
|
|
75
|
+
const fire = () => {
|
|
76
|
+
if (fired)
|
|
77
|
+
return;
|
|
78
|
+
fired = true;
|
|
79
|
+
cancel();
|
|
80
|
+
wake();
|
|
81
|
+
};
|
|
82
|
+
const cleanups = [];
|
|
83
|
+
const cancel = () => {
|
|
84
|
+
for (const fn of cleanups.splice(0))
|
|
85
|
+
fn();
|
|
86
|
+
};
|
|
87
|
+
if (trigger === 'load') {
|
|
88
|
+
queueMicrotask(fire);
|
|
89
|
+
return () => {
|
|
90
|
+
fired = true;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (trigger === 'idle') {
|
|
94
|
+
if (typeof window.requestIdleCallback === 'function') {
|
|
95
|
+
const id = window.requestIdleCallback(fire, { timeout: 2000 });
|
|
96
|
+
cleanups.push(() => window.cancelIdleCallback(id));
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const timer = setTimeout(fire, 200);
|
|
100
|
+
cleanups.push(() => clearTimeout(timer));
|
|
101
|
+
}
|
|
102
|
+
return cancel;
|
|
103
|
+
}
|
|
104
|
+
if (trigger === 'interaction') {
|
|
105
|
+
const events = [
|
|
106
|
+
'pointerenter',
|
|
107
|
+
'pointerdown',
|
|
108
|
+
'focusin',
|
|
109
|
+
'click',
|
|
110
|
+
];
|
|
111
|
+
for (const evt of events) {
|
|
112
|
+
host.addEventListener(evt, fire, { once: true, passive: true });
|
|
113
|
+
cleanups.push(() => host.removeEventListener(evt, fire));
|
|
114
|
+
}
|
|
115
|
+
return cancel;
|
|
116
|
+
}
|
|
117
|
+
// visible
|
|
118
|
+
const isInViewport = () => {
|
|
119
|
+
const rect = host.getBoundingClientRect();
|
|
120
|
+
return (rect.height > 0 && rect.top < window.innerHeight && rect.bottom > 0);
|
|
121
|
+
};
|
|
122
|
+
if (isInViewport()) {
|
|
123
|
+
queueMicrotask(fire);
|
|
124
|
+
return () => {
|
|
125
|
+
fired = true;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (typeof IntersectionObserver !== 'undefined') {
|
|
129
|
+
const observer = new IntersectionObserver((entries) => {
|
|
130
|
+
if (entries.some((entry) => entry.isIntersecting))
|
|
131
|
+
fire();
|
|
132
|
+
}, { threshold: 0.1 });
|
|
133
|
+
observer.observe(host);
|
|
134
|
+
cleanups.push(() => observer.disconnect());
|
|
135
|
+
}
|
|
136
|
+
const check = () => {
|
|
137
|
+
if (isInViewport())
|
|
138
|
+
fire();
|
|
139
|
+
};
|
|
140
|
+
window.addEventListener('scroll', check, { passive: true });
|
|
141
|
+
window.addEventListener('resize', check, { passive: true });
|
|
142
|
+
cleanups.push(() => {
|
|
143
|
+
window.removeEventListener('scroll', check);
|
|
144
|
+
window.removeEventListener('resize', check);
|
|
145
|
+
});
|
|
146
|
+
return cancel;
|
|
147
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { type RoomHub } from './room-hub.ts';
|
|
2
|
+
import type { Tagged } from '../logic/result.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Plain, framework-free building blocks behind `<AppScope>`: the per-scope
|
|
5
|
+
* query dedupe cache ("Way 1" shared reads), the query outcome channel
|
|
6
|
+
* ("Way 2" outcomes -> Messages) and the invalidation table (`Refetch`,
|
|
7
|
+
* mutation `invalidates`). Zero Solid imports, so they are unit-testable
|
|
8
|
+
* in `bun test` and contain no module-level state: every `createKitScope()`
|
|
9
|
+
* call returns fresh instances (one per SSR request / browser page).
|
|
10
|
+
*/
|
|
11
|
+
/** How a registry query settled: a success value or a failure (typed or `Unexpected`). */
|
|
12
|
+
export type QueryOutcome = {
|
|
13
|
+
readonly _tag: 'Succeeded';
|
|
14
|
+
readonly value: unknown;
|
|
15
|
+
} | {
|
|
16
|
+
readonly _tag: 'Failed';
|
|
17
|
+
readonly error: Tagged;
|
|
18
|
+
};
|
|
19
|
+
/** One outcome published by a `<Query>` for one query + input. */
|
|
20
|
+
export interface QueryOutcomeEvent {
|
|
21
|
+
/** Query id `"<registry>/<name>"` (`createQueryRegistry`), e.g. `"planner/character"`. */
|
|
22
|
+
readonly queryId: string;
|
|
23
|
+
/** Serialized input (`inputKeyOf`); `""` for no input. */
|
|
24
|
+
readonly inputKey: string;
|
|
25
|
+
/** Dedupe key of the execution (query id + input + generation). */
|
|
26
|
+
readonly key: string;
|
|
27
|
+
readonly outcome: QueryOutcome;
|
|
28
|
+
}
|
|
29
|
+
export type QueryOutcomeListener = (event: QueryOutcomeEvent) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Kit-owned pub/sub for query outcomes, keyed by query id + input key.
|
|
32
|
+
*
|
|
33
|
+
* - `publish` skips an event identical (same key + same serialized outcome)
|
|
34
|
+
* to the latest one for that query + input, so two panels sharing one
|
|
35
|
+
* fetch, or the SSR value re-read by several boundaries after hydration,
|
|
36
|
+
* notify once.
|
|
37
|
+
* - `subscribe` replays the latest outcome of every query + input, oldest
|
|
38
|
+
* first (so the most recent outcome is heard last), to the new
|
|
39
|
+
* listener (late subscribers, e.g. a panel streamed in after the query
|
|
40
|
+
* settled, still learn the current state) and returns an unsubscribe
|
|
41
|
+
* function. Two inputs of one query keep two latest outcomes: neither
|
|
42
|
+
* overwrites the other.
|
|
43
|
+
*/
|
|
44
|
+
export interface QueryOutcomeChannel {
|
|
45
|
+
readonly publish: (event: QueryOutcomeEvent) => void;
|
|
46
|
+
readonly subscribe: (listener: QueryOutcomeListener) => () => void;
|
|
47
|
+
/** Latest published outcome for a query + input (for tests / debugging). */
|
|
48
|
+
readonly latest: (queryId: string, inputKey?: string) => QueryOutcomeEvent | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Forgets every latest outcome (listeners stay). A client navigation
|
|
51
|
+
* calls it: the old page's reads are not the new page's truth, and a
|
|
52
|
+
* persisted model's `listens` should hear the new page's outcomes, not a
|
|
53
|
+
* replay of the old ones.
|
|
54
|
+
*/
|
|
55
|
+
readonly forget: () => void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates an isolated outcome channel (see `QueryOutcomeChannel`).
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const channel = createQueryOutcomeChannel();
|
|
63
|
+
* const stop = channel.subscribe((e) => console.log(e.queryId, e.inputKey, e.outcome._tag));
|
|
64
|
+
* channel.publish({ queryId: "planner/character", inputKey: '"x"', key: 'planner/character:"x"#0',
|
|
65
|
+
* outcome: { _tag: "Succeeded", value: 1 } });
|
|
66
|
+
* stop();
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function createQueryOutcomeChannel(): QueryOutcomeChannel;
|
|
70
|
+
/**
|
|
71
|
+
* Refetch bookkeeping for one scope. `invalidate` bumps a generation; every
|
|
72
|
+
* `<Query>` of that query (optionally only that input) folds the generation
|
|
73
|
+
* into its dedupe key, so all of them move to one fresh execution together
|
|
74
|
+
* (two panels, still one call) while showing the old value in place.
|
|
75
|
+
*/
|
|
76
|
+
export interface QueryInvalidations {
|
|
77
|
+
/** Marks a query stale: every input, or only `inputKey`. */
|
|
78
|
+
readonly invalidate: (queryId: string, inputKey?: string) => void;
|
|
79
|
+
/** Current generation of a query + input (starts at 0). */
|
|
80
|
+
readonly generation: (queryId: string, inputKey: string) => number;
|
|
81
|
+
/** Called on every `invalidate` (`inputKey` undefined = every input). */
|
|
82
|
+
readonly subscribe: (listener: (queryId: string, inputKey: string | undefined) => void) => () => void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Creates an isolated invalidation table (see `QueryInvalidations`).
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const inv = createQueryInvalidations();
|
|
90
|
+
* inv.invalidate("planner/plan");
|
|
91
|
+
* inv.generation("planner/plan", '"voltar-main"'); // 1
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function createQueryInvalidations(): QueryInvalidations;
|
|
95
|
+
/** Handle returned by `QueryCache.acquire`; call `release()` exactly once. */
|
|
96
|
+
export interface QueryCacheLease<R> {
|
|
97
|
+
readonly value: R;
|
|
98
|
+
readonly release: () => void;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Ref-counted, in-flight + settled dedupe cache for query executions.
|
|
102
|
+
*
|
|
103
|
+
* - `acquire(key, run)` returns the existing entry's value when one is held
|
|
104
|
+
* for `key` (no second `run()`), otherwise calls `run()` once and stores it.
|
|
105
|
+
* - `release()` drops one reference; an entry with zero references is removed
|
|
106
|
+
* on the next microtask, so a `<Query>` that re-runs with the same key in
|
|
107
|
+
* the same tick (e.g. `<Errored>` reset) re-uses it instead of refetching.
|
|
108
|
+
* - `evict(key)` forgets the entry immediately (explicit retry).
|
|
109
|
+
*/
|
|
110
|
+
export interface QueryCache {
|
|
111
|
+
readonly acquire: <R>(key: string, run: () => R) => QueryCacheLease<R>;
|
|
112
|
+
readonly evict: (key: string) => void;
|
|
113
|
+
/** Number of live entries (for tests / debugging). */
|
|
114
|
+
readonly size: () => number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Creates an isolated dedupe cache (see `QueryCache`). Never module-global:
|
|
118
|
+
* `<AppScope>` creates one per SSR request and one per browser page.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const cache = createQueryCache();
|
|
123
|
+
* const a = cache.acquire("character:\"x\"@", () => fetchCharacter("x"));
|
|
124
|
+
* const b = cache.acquire("character:\"x\"@", () => fetchCharacter("x")); // no second fetch
|
|
125
|
+
* a.value === b.value; // true
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare function createQueryCache(): QueryCache;
|
|
129
|
+
/**
|
|
130
|
+
* The page's lifecycle as the kit's page models see it. Page models are
|
|
131
|
+
* created outside every island root, so Solid's `onSettled` (per owner)
|
|
132
|
+
* can't tell them when the page is interactive: the island client entry
|
|
133
|
+
* calls `markHydrated()` once every island root on the page has hydrated,
|
|
134
|
+
* and only then do page models start their init Commands, `listens`,
|
|
135
|
+
* `subscriptions` and `urlChanged`. On the server it is never called, so
|
|
136
|
+
* nothing starts there.
|
|
137
|
+
*/
|
|
138
|
+
export interface PageLifecycle {
|
|
139
|
+
/** Runs `start` once the page has hydrated (at once, on a microtask, if it already has). */
|
|
140
|
+
readonly afterHydration: (start: () => void) => void;
|
|
141
|
+
/** Called once by the island client entry after the one hydration pass. */
|
|
142
|
+
readonly markHydrated: () => void;
|
|
143
|
+
readonly isHydrated: () => boolean;
|
|
144
|
+
}
|
|
145
|
+
export declare function createPageLifecycle(): PageLifecycle;
|
|
146
|
+
/** How a page model instance lives in its scope (kit-internal, `usePageModel`). */
|
|
147
|
+
export interface PageModelLife {
|
|
148
|
+
/** Disposes the model's detached root: stops its subscriptions, listens, timers. */
|
|
149
|
+
readonly dispose: () => void;
|
|
150
|
+
/** Declared `persist: true`: survives client navigation. */
|
|
151
|
+
readonly persist: boolean;
|
|
152
|
+
/** The page it was created on (a later page hydrates its islands against `init`). */
|
|
153
|
+
readonly page: PageLifecycle;
|
|
154
|
+
/** The client-navigation section it was created in (`undefined`: a document route). A persisted model survives only within it. */
|
|
155
|
+
readonly section: string | undefined;
|
|
156
|
+
}
|
|
157
|
+
/** Everything `<AppScope>` provides to `<Query>` and `createModel`. */
|
|
158
|
+
export interface KitScope {
|
|
159
|
+
readonly queries: QueryCache;
|
|
160
|
+
readonly outcomes: QueryOutcomeChannel;
|
|
161
|
+
readonly invalidations: QueryInvalidations;
|
|
162
|
+
/**
|
|
163
|
+
* The page's models (`usePageModel`), one instance per definition per
|
|
164
|
+
* scope (per SSR request, per browser page). Keys are the module-level
|
|
165
|
+
* definitions; values are the created `[state, send]` pairs.
|
|
166
|
+
*/
|
|
167
|
+
readonly pageModels: Map<object, unknown>;
|
|
168
|
+
/** Lifecycle of each page model in `pageModels` (browser only; same keys). */
|
|
169
|
+
readonly pageModelLives: Map<object, PageModelLife>;
|
|
170
|
+
/** Persisted page models as a later page's islands see them during its pass (`usePageModel`). */
|
|
171
|
+
readonly pageModelMasks: WeakMap<PageLifecycle, Map<object, unknown>>;
|
|
172
|
+
/**
|
|
173
|
+
* The current page's lifecycle. One per document content: a client
|
|
174
|
+
* navigation (`nextPage`) starts a new one for the next page's pass.
|
|
175
|
+
*/
|
|
176
|
+
readonly page: PageLifecycle;
|
|
177
|
+
/**
|
|
178
|
+
* The document's client-navigation section (`undefined` on a document
|
|
179
|
+
* route, and on the server). Persisted page models and islands are
|
|
180
|
+
* scoped to it: crossing sections is a full load.
|
|
181
|
+
*/
|
|
182
|
+
readonly section: string | undefined;
|
|
183
|
+
/** Island roots rendered on this page so far (server: for unique ids). */
|
|
184
|
+
readonly islands: {
|
|
185
|
+
count: number;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* The page's live room hub: one shared socket per room (`presence`,
|
|
189
|
+
* `roomSaved`, `<LiveCursors>`, the collab part). Created on first use;
|
|
190
|
+
* browser only (the kit never calls it on the server).
|
|
191
|
+
*/
|
|
192
|
+
readonly rooms: () => RoomHub;
|
|
193
|
+
/**
|
|
194
|
+
* The viewer changed (a `changesAccess` mutation succeeded): reopen this
|
|
195
|
+
* page's room sockets and tell this origin's other tabs. No-op on the server.
|
|
196
|
+
*/
|
|
197
|
+
readonly viewerChanged: () => void;
|
|
198
|
+
/**
|
|
199
|
+
* Keeps every open room socket open (a room whose last user leaves is
|
|
200
|
+
* parked, not closed) until the returned release runs; then rooms nobody
|
|
201
|
+
* took back are closed. A client navigation holds the rooms across the
|
|
202
|
+
* swap, so the next page's islands pick up a shared room without a
|
|
203
|
+
* reconnect, and rooms only the old page used close. No-op without a hub.
|
|
204
|
+
*/
|
|
205
|
+
readonly holdRooms: () => () => void;
|
|
206
|
+
/**
|
|
207
|
+
* Client navigation only: the old page is gone, the next one is in
|
|
208
|
+
* `section`. Disposes every page model not declared `persist: true` and
|
|
209
|
+
* every model of another section (the runtime never swaps across
|
|
210
|
+
* sections; this keeps the rule in the scope too), forgets the old
|
|
211
|
+
* page's query outcomes, and starts a new page lifecycle for the next
|
|
212
|
+
* pass. The scope itself (query cache, invalidations, persisted models,
|
|
213
|
+
* room hub) lives as long as the document.
|
|
214
|
+
*/
|
|
215
|
+
readonly nextPage: (section: string | undefined) => void;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Creates a fresh `KitScope`: one per SSR request, and one per browser
|
|
219
|
+
* document (shared by every island root, and kept across client
|
|
220
|
+
* navigations; see `nextPage`).
|
|
221
|
+
*/
|
|
222
|
+
export declare function createKitScope(options?: {
|
|
223
|
+
readonly section?: string | undefined;
|
|
224
|
+
}): KitScope;
|