@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,37 @@
|
|
|
1
|
+
import { type AnyIslandTable } from './hydration-pass.ts';
|
|
2
|
+
import type { SiteSettings } from '../view/app-scope.ts';
|
|
3
|
+
export { createHydrationPass, runIslandsPass, type AnyIslandTable, type IslandRoot, type IslandsPass, } from './hydration-pass.ts';
|
|
4
|
+
/**
|
|
5
|
+
* The island client entry (`src/entry-client.tsx`): the only JS a page
|
|
6
|
+
* runs. Never renders the app root, the route pages or the shell.
|
|
7
|
+
*
|
|
8
|
+
* 0. A page prerendered on hover (speculation rules, `speculate:
|
|
9
|
+
* "prerender"`) waits until it is shown: no hydration, page model or
|
|
10
|
+
* socket runs in a hidden tab.
|
|
11
|
+
* 1. Finds the page's island roots (`[data-kit-island]`).
|
|
12
|
+
* 2. Hydrated roots (`wake: "load"`): loads every island module (in
|
|
13
|
+
* parallel), then hydrates every root in one synchronous loop: one pass,
|
|
14
|
+
* one task (a root hydrated later would silently replace its server
|
|
15
|
+
* DOM, solidjs/solid#3845). A module that fails to load leaves its
|
|
16
|
+
* root's server HTML in place (`data-island-state="failed"`).
|
|
17
|
+
* 3. Once every root has hydrated, starts the page models (their init
|
|
18
|
+
* Commands, `listens`, `subscriptions`; see `usePageModel`).
|
|
19
|
+
* 4. Lazy roots: client-only renders when their wake trigger fires, never
|
|
20
|
+
* before the hydration pass has ended (an early `idle` wake waits).
|
|
21
|
+
* 5. On a page in a client-navigation section (the head's client
|
|
22
|
+
* navigation data block, `<PageNavigation>`), loads the kit's navigation
|
|
23
|
+
* runtime (its own chunk; other pages never fetch it) and hands it the
|
|
24
|
+
* page and its section.
|
|
25
|
+
*
|
|
26
|
+
* One `KitScope` per document, shared by every island root: one query
|
|
27
|
+
* dedupe cache, one outcome channel (`listen` across islands), one
|
|
28
|
+
* invalidation table (a mutation in one island refetches a query in
|
|
29
|
+
* another), one set of page models, one room hub.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* // src/entry-client.tsx
|
|
34
|
+
* startIslands(islands, siteSettings);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function startIslands(table: AnyIslandTable, site: SiteSettings | null): Promise<void>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { runIslandsPass } from './hydration-pass.js';
|
|
2
|
+
import { CLIENT_NAV_DATA_TYPE, parseClientNavigationData, } from '../logic/navigation-data.js';
|
|
3
|
+
import { createKitScope } from '../runtime/query-scope.js';
|
|
4
|
+
export { createHydrationPass, runIslandsPass, } from './hydration-pass.js';
|
|
5
|
+
/** Resolves when the page is shown (at once unless it is being prerendered by speculation rules). */
|
|
6
|
+
function whenShown() {
|
|
7
|
+
const doc = document;
|
|
8
|
+
if (!doc.prerendering)
|
|
9
|
+
return Promise.resolve();
|
|
10
|
+
return new Promise((resolve) => document.addEventListener('prerenderingchange', () => resolve(), {
|
|
11
|
+
once: true,
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The island client entry (`src/entry-client.tsx`): the only JS a page
|
|
16
|
+
* runs. Never renders the app root, the route pages or the shell.
|
|
17
|
+
*
|
|
18
|
+
* 0. A page prerendered on hover (speculation rules, `speculate:
|
|
19
|
+
* "prerender"`) waits until it is shown: no hydration, page model or
|
|
20
|
+
* socket runs in a hidden tab.
|
|
21
|
+
* 1. Finds the page's island roots (`[data-kit-island]`).
|
|
22
|
+
* 2. Hydrated roots (`wake: "load"`): loads every island module (in
|
|
23
|
+
* parallel), then hydrates every root in one synchronous loop: one pass,
|
|
24
|
+
* one task (a root hydrated later would silently replace its server
|
|
25
|
+
* DOM, solidjs/solid#3845). A module that fails to load leaves its
|
|
26
|
+
* root's server HTML in place (`data-island-state="failed"`).
|
|
27
|
+
* 3. Once every root has hydrated, starts the page models (their init
|
|
28
|
+
* Commands, `listens`, `subscriptions`; see `usePageModel`).
|
|
29
|
+
* 4. Lazy roots: client-only renders when their wake trigger fires, never
|
|
30
|
+
* before the hydration pass has ended (an early `idle` wake waits).
|
|
31
|
+
* 5. On a page in a client-navigation section (the head's client
|
|
32
|
+
* navigation data block, `<PageNavigation>`), loads the kit's navigation
|
|
33
|
+
* runtime (its own chunk; other pages never fetch it) and hands it the
|
|
34
|
+
* page and its section.
|
|
35
|
+
*
|
|
36
|
+
* One `KitScope` per document, shared by every island root: one query
|
|
37
|
+
* dedupe cache, one outcome channel (`listen` across islands), one
|
|
38
|
+
* invalidation table (a mutation in one island refetches a query in
|
|
39
|
+
* another), one set of page models, one room hub.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* // src/entry-client.tsx
|
|
44
|
+
* startIslands(islands, siteSettings);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export async function startIslands(table, site) {
|
|
48
|
+
await whenShown();
|
|
49
|
+
const data = parseClientNavigationData(document.querySelector(`script[type="${CLIENT_NAV_DATA_TYPE}"]`)
|
|
50
|
+
?.textContent);
|
|
51
|
+
// The document's section scopes persisted page models (`nextPage`).
|
|
52
|
+
const scope = createKitScope({ section: data?.section });
|
|
53
|
+
const first = runIslandsPass(table, site, scope);
|
|
54
|
+
if (data) {
|
|
55
|
+
try {
|
|
56
|
+
const nav = await import('./nav-client.js');
|
|
57
|
+
nav.installClientNavigation({ table, site, scope, first, data });
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
// Links stay plain links: full page loads.
|
|
61
|
+
console.error('[nav] client navigation failed to load; links do full page loads:', error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
await first.ready;
|
|
65
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AnyIslandTable, IslandsPass } from './hydration-pass.ts';
|
|
2
|
+
import { type ClientNavigationData } from '../logic/navigation-data.ts';
|
|
3
|
+
import type { KitScope } from '../runtime/query-scope.ts';
|
|
4
|
+
import type { SiteSettings } from '../view/app-scope.ts';
|
|
5
|
+
export { scriptsAllowedBy } from './head-swap.ts';
|
|
6
|
+
/** One navigation's timings (detail of the `kit:page-load` event on `window`). */
|
|
7
|
+
export interface NavTiming {
|
|
8
|
+
readonly url: string;
|
|
9
|
+
readonly mode: NavMode;
|
|
10
|
+
/** Click to response parsed and checked. */
|
|
11
|
+
readonly fetchMs: number;
|
|
12
|
+
/** Styles + island modules loaded, head + body swapped, scripts re-run. */
|
|
13
|
+
readonly swapMs: number;
|
|
14
|
+
/** The new islands' hydration pass, until page models started. */
|
|
15
|
+
readonly hydrateMs: number;
|
|
16
|
+
/** Click to interactive. */
|
|
17
|
+
readonly totalMs: number;
|
|
18
|
+
readonly persisted: number;
|
|
19
|
+
readonly islands: number;
|
|
20
|
+
/** `_$HY.r` entries deleted for roots that are gone. */
|
|
21
|
+
readonly forgotten: number;
|
|
22
|
+
}
|
|
23
|
+
type NavMode = 'push' | 'replace' | 'traverse';
|
|
24
|
+
export interface ClientNavigationStart {
|
|
25
|
+
readonly table: AnyIslandTable;
|
|
26
|
+
readonly site: SiteSettings | null;
|
|
27
|
+
readonly scope: KitScope;
|
|
28
|
+
readonly first: IslandsPass;
|
|
29
|
+
readonly data: ClientNavigationData;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Installs client navigation on this document (kit-internal; called by
|
|
33
|
+
* `startIslands` on pages in a client-navigation section).
|
|
34
|
+
*/
|
|
35
|
+
export declare function installClientNavigation(start: ClientNavigationStart): void;
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { createAnnouncer, documentNonce, entryOf, focusAndAnnounce, loadStyles, preloadIslands, round, runScripts, scriptsAllowedBy, scrollAfterSwap, settled, swapHead, viewTransitionsWanted, } from './head-swap.js';
|
|
2
|
+
import { runIslandsPass } from './hydration-pass.js';
|
|
3
|
+
import { forgetHydrationData, hydrationReopenable, namespaceIslandIds, reopenHydration, } from './hydration-reset.js';
|
|
4
|
+
import { ISLAND_ATTR } from '../logic/island-def.js';
|
|
5
|
+
import { CLIENT_NAV_DATA_TYPE, navigationDecision, parseClientNavigationData, } from '../logic/navigation-data.js';
|
|
6
|
+
import { CLIENT_NAV_ACTIVE_ATTR } from '../logic/navigation-policy.js';
|
|
7
|
+
import { normalizePathname } from '../logic/path.js';
|
|
8
|
+
import { matchPattern } from '../logic/route-table.js';
|
|
9
|
+
import { setClientNavigator } from '../view/router.js';
|
|
10
|
+
export { scriptsAllowedBy } from './head-swap.js';
|
|
11
|
+
/**
|
|
12
|
+
* Client navigation (layer 2 of `docs/guides/ui-kit-page-transitions.md`): between
|
|
13
|
+
* routes of the same named section (`navigation: { client: "app" }`), a
|
|
14
|
+
* link click (or the `Navigate` Command) fetches the next page's server
|
|
15
|
+
* HTML and swaps it in, instead of a new document. A link into another
|
|
16
|
+
* section, or into a `document` route, is never intercepted: the browser
|
|
17
|
+
* does a full load, which resets persisted islands, page models and room
|
|
18
|
+
* sockets. Loaded by the island client entry only on pages whose head has
|
|
19
|
+
* the client navigation data block (`<PageNavigation>`), as its own chunk.
|
|
20
|
+
* The data block lists only this section's routes.
|
|
21
|
+
*
|
|
22
|
+
* One navigation:
|
|
23
|
+
* 1. fetch the page (`X-Kit-Nav: 1`; an in-flight navigation is aborted
|
|
24
|
+
* by a newer one); full load instead on a network error, a non-OK
|
|
25
|
+
* status, a non-HTML or cross-origin answer, a redirect out of the
|
|
26
|
+
* section, a page without client navigation or of another section, a
|
|
27
|
+
* new client build, or a response whose CSP has no nonce;
|
|
28
|
+
* 2. pick the inline scripts the **fetched response's own CSP** allows
|
|
29
|
+
* (its nonce or a listed `sha256`): anything else is what the parser
|
|
30
|
+
* would have blocked on a direct load (an injected `<script>`), so it
|
|
31
|
+
* never runs here either;
|
|
32
|
+
* 3. give its island roots a fresh hydration-id namespace, load its
|
|
33
|
+
* stylesheets and island modules (so the swap and the pass run in one task);
|
|
34
|
+
* 4. swap (inside a same-document view transition unless reduced motion):
|
|
35
|
+
* move `persist` islands into the new body, dispose every other island
|
|
36
|
+
* root and every page model not declared `persist`, replace the managed
|
|
37
|
+
* head tags and the body, push the URL, re-run the allowed scripts with
|
|
38
|
+
* this document's nonce, re-open Solid's hydration (`reopenHydration`, the
|
|
39
|
+
* kit's one contact with Solid's private flag) and hydrate the new
|
|
40
|
+
* islands in one pass;
|
|
41
|
+
* 5. room sockets are held across the swap: a room the next page uses
|
|
42
|
+
* again is never reconnected; the others close once its islands started;
|
|
43
|
+
* 6. scroll (top, `#hash`, or the saved position on Back / Forward), focus
|
|
44
|
+
* the new page's heading and announce its title to screen readers.
|
|
45
|
+
* Any error after the swap began: a full load of the target.
|
|
46
|
+
*/
|
|
47
|
+
const matches = (pattern, path) => matchPattern(pattern, path) !== undefined;
|
|
48
|
+
/** Kit-wide opt-out on a link: always a full load. */
|
|
49
|
+
const RELOAD_ATTR = 'data-kit-reload';
|
|
50
|
+
/** How long a hover prefetch is kept for the click that follows it. */
|
|
51
|
+
const PREFETCH_TTL_MS = 10_000;
|
|
52
|
+
/** Hover time before a prefetch (Chrome's `moderate` speculation uses 200 ms). */
|
|
53
|
+
const PREFETCH_HOVER_MS = 80;
|
|
54
|
+
/** How long rooms the old page used stay parked after the new page's islands started. */
|
|
55
|
+
const ROOM_HANDOFF_MS = 500;
|
|
56
|
+
/** How long a navigation waits for the previous page's pass before swapping anyway. */
|
|
57
|
+
const PREVIOUS_PASS_WAIT_MS = 2_000;
|
|
58
|
+
const isHistoryState = (value) => typeof value === 'object' &&
|
|
59
|
+
value !== null &&
|
|
60
|
+
value.kitNav === true;
|
|
61
|
+
/**
|
|
62
|
+
* Installs client navigation on this document (kit-internal; called by
|
|
63
|
+
* `startIslands` on pages in a client-navigation section).
|
|
64
|
+
*/
|
|
65
|
+
export function installClientNavigation(start) {
|
|
66
|
+
const { table, site, scope } = start;
|
|
67
|
+
/** This document's section; it never changes (crossing sections is a new document). */
|
|
68
|
+
const here = start.data;
|
|
69
|
+
const entry = entryOf(document);
|
|
70
|
+
const nonce = documentNonce();
|
|
71
|
+
/** Every pass with live island roots (each pass's `roots` fills in as its roots hydrate). */
|
|
72
|
+
let passes = [start.first];
|
|
73
|
+
let lastPass = start.first;
|
|
74
|
+
const liveCount = () => passes.reduce((n, p) => n + p.roots.size, 0);
|
|
75
|
+
let seq = 0;
|
|
76
|
+
let inFlight;
|
|
77
|
+
/** The in-flight navigation's history mode (until it commits). */
|
|
78
|
+
let inFlightMode;
|
|
79
|
+
let prefetched;
|
|
80
|
+
const announcer = createAnnouncer();
|
|
81
|
+
// The head's speculation rules stop prefetching this section's routes: this runtime fetches them.
|
|
82
|
+
document.documentElement.setAttribute(CLIENT_NAV_ACTIVE_ATTR, here.section);
|
|
83
|
+
history.scrollRestoration = 'manual';
|
|
84
|
+
if (!isHistoryState(history.state))
|
|
85
|
+
history.replaceState({ kitNav: true, scroll: scrollY }, '');
|
|
86
|
+
const inSection = (url) => {
|
|
87
|
+
if (url.origin !== location.origin)
|
|
88
|
+
return false;
|
|
89
|
+
const path = normalizePathname(url.pathname);
|
|
90
|
+
return here.client.some((pattern) => matchPattern(pattern, path) !== undefined);
|
|
91
|
+
};
|
|
92
|
+
const followable = (a) => {
|
|
93
|
+
if (!a ||
|
|
94
|
+
!a.href ||
|
|
95
|
+
a.hasAttribute('download') ||
|
|
96
|
+
a.hasAttribute(RELOAD_ATTR))
|
|
97
|
+
return undefined;
|
|
98
|
+
if (a.target !== '' && a.target !== '_self')
|
|
99
|
+
return undefined;
|
|
100
|
+
if ((a.getAttribute('rel') ?? '').split(/\s+/).includes('external'))
|
|
101
|
+
return undefined;
|
|
102
|
+
const url = new URL(a.href, location.href);
|
|
103
|
+
return inSection(url) ? url : undefined;
|
|
104
|
+
};
|
|
105
|
+
const fetchPage = (href, signal) => {
|
|
106
|
+
const hit = prefetched;
|
|
107
|
+
prefetched = undefined;
|
|
108
|
+
if (hit &&
|
|
109
|
+
hit.href === href &&
|
|
110
|
+
performance.now() - hit.at < PREFETCH_TTL_MS)
|
|
111
|
+
return hit.res;
|
|
112
|
+
return fetch(href, {
|
|
113
|
+
headers: { Accept: 'text/html', 'X-Kit-Nav': '1' },
|
|
114
|
+
credentials: 'same-origin',
|
|
115
|
+
signal,
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
const fullLoad = (href, why) => {
|
|
119
|
+
console.info(`[nav] full page load (${why}): ${href}`);
|
|
120
|
+
if (inFlight)
|
|
121
|
+
inFlight.abort();
|
|
122
|
+
location.assign(href);
|
|
123
|
+
};
|
|
124
|
+
async function go(href, mode, restoreScroll) {
|
|
125
|
+
const mine = ++seq;
|
|
126
|
+
// A replace that supersedes a push still in flight keeps the push:
|
|
127
|
+
// that push never committed, so its history entry is still owed (a
|
|
128
|
+
// route guard's redirect racing a sign-in's Navigate must not eat
|
|
129
|
+
// the page the visitor came from).
|
|
130
|
+
if (mode === 'replace' && inFlight && inFlightMode === 'push')
|
|
131
|
+
mode = 'push';
|
|
132
|
+
inFlight?.abort();
|
|
133
|
+
const controller = new AbortController();
|
|
134
|
+
inFlight = controller;
|
|
135
|
+
inFlightMode = mode;
|
|
136
|
+
const t0 = performance.now();
|
|
137
|
+
const target = new URL(href, location.href);
|
|
138
|
+
if (!hydrationReopenable())
|
|
139
|
+
return fullLoad(target.href, "Solid's hydration globals look different");
|
|
140
|
+
let res;
|
|
141
|
+
try {
|
|
142
|
+
res = await fetchPage(target.href, controller.signal);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
if (controller.signal.aborted)
|
|
146
|
+
return;
|
|
147
|
+
return fullLoad(target.href, 'network error');
|
|
148
|
+
}
|
|
149
|
+
if (mine !== seq)
|
|
150
|
+
return;
|
|
151
|
+
const finalUrl = new URL(res.url || target.href, location.href);
|
|
152
|
+
finalUrl.hash = target.hash;
|
|
153
|
+
if (!res.ok)
|
|
154
|
+
return fullLoad(finalUrl.href, `status ${res.status}`);
|
|
155
|
+
if (!(res.headers.get('content-type') ?? '').includes('text/html'))
|
|
156
|
+
return fullLoad(finalUrl.href, 'not HTML');
|
|
157
|
+
if (!inSection(finalUrl))
|
|
158
|
+
return fullLoad(finalUrl.href, 'outside the section');
|
|
159
|
+
let html;
|
|
160
|
+
try {
|
|
161
|
+
html = await res.text();
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
if (controller.signal.aborted)
|
|
165
|
+
return;
|
|
166
|
+
return fullLoad(finalUrl.href, 'network error');
|
|
167
|
+
}
|
|
168
|
+
if (mine !== seq)
|
|
169
|
+
return;
|
|
170
|
+
const next = new DOMParser().parseFromString(html, 'text/html');
|
|
171
|
+
const nextData = parseClientNavigationData(next.querySelector(`script[type="${CLIENT_NAV_DATA_TYPE}"]`)
|
|
172
|
+
?.textContent);
|
|
173
|
+
const decision = navigationDecision(here, normalizePathname(finalUrl.pathname), nextData, matches);
|
|
174
|
+
if (!decision.swap || !nextData)
|
|
175
|
+
return fullLoad(finalUrl.href, decision.swap ? 'no data' : decision.reason);
|
|
176
|
+
const nextEntry = entryOf(next);
|
|
177
|
+
if (nextEntry !== null && entry !== null && nextEntry !== entry)
|
|
178
|
+
return fullLoad(finalUrl.href, 'a new client build');
|
|
179
|
+
const allowed = await scriptsAllowedBy(res.headers.get('content-security-policy'), next, nonce !== '');
|
|
180
|
+
if (!allowed)
|
|
181
|
+
return fullLoad(finalUrl.href, "the page's CSP has no nonce");
|
|
182
|
+
if (mine !== seq)
|
|
183
|
+
return;
|
|
184
|
+
const tFetched = performance.now();
|
|
185
|
+
// Fresh hydration ids for this page's roots (Solid keeps per-id state).
|
|
186
|
+
namespaceIslandIds(next, `n${mine}`);
|
|
187
|
+
// Everything the swap needs is loaded before it, so the swap and the
|
|
188
|
+
// hydration pass run in one task.
|
|
189
|
+
try {
|
|
190
|
+
await Promise.all([loadStyles(next), preloadIslands(next, table)]);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (mine !== seq)
|
|
194
|
+
return;
|
|
195
|
+
console.error("[nav] loading the page's assets failed:", error);
|
|
196
|
+
return fullLoad(finalUrl.href, 'assets failed to load');
|
|
197
|
+
}
|
|
198
|
+
await settled(lastPass.ready, PREVIOUS_PASS_WAIT_MS);
|
|
199
|
+
if (mine !== seq)
|
|
200
|
+
return;
|
|
201
|
+
if (mode !== 'traverse') {
|
|
202
|
+
history.replaceState({
|
|
203
|
+
...history.state,
|
|
204
|
+
kitNav: true,
|
|
205
|
+
scroll: scrollY,
|
|
206
|
+
}, '');
|
|
207
|
+
}
|
|
208
|
+
let tSwapped = 0;
|
|
209
|
+
let persisted = 0;
|
|
210
|
+
let forgotten = 0;
|
|
211
|
+
let pass;
|
|
212
|
+
const releaseRooms = scope.holdRooms();
|
|
213
|
+
const swap = () => {
|
|
214
|
+
// 1. Persisted islands: the live element replaces the new server copy.
|
|
215
|
+
const keep = new Set();
|
|
216
|
+
const replacedIds = [];
|
|
217
|
+
for (const el of next.body.querySelectorAll(`[${ISLAND_ATTR.persist}]`)) {
|
|
218
|
+
const key = el.getAttribute(ISLAND_ATTR.persist) ?? '';
|
|
219
|
+
const current = document.body.querySelector(`[${ISLAND_ATTR.persist}="${CSS.escape(key)}"]`);
|
|
220
|
+
if (!current || keep.has(current))
|
|
221
|
+
continue;
|
|
222
|
+
const replacedId = el.getAttribute(ISLAND_ATTR.id);
|
|
223
|
+
if (replacedId)
|
|
224
|
+
replacedIds.push(replacedId);
|
|
225
|
+
el.replaceWith(current);
|
|
226
|
+
keep.add(current);
|
|
227
|
+
}
|
|
228
|
+
persisted = keep.size;
|
|
229
|
+
// 2. Every other island root of the old page goes, with its data.
|
|
230
|
+
const goneIds = [...replacedIds];
|
|
231
|
+
for (const old of passes) {
|
|
232
|
+
for (const [el, dispose] of [...old.roots]) {
|
|
233
|
+
if ([...keep].some((k) => k === el || k.contains(el)))
|
|
234
|
+
continue;
|
|
235
|
+
old.roots.delete(el);
|
|
236
|
+
const id = el.getAttribute(ISLAND_ATTR.id);
|
|
237
|
+
if (id)
|
|
238
|
+
goneIds.push(id);
|
|
239
|
+
try {
|
|
240
|
+
dispose();
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
console.error('[nav] disposing an island failed:', error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
passes = passes.filter((old) => old.roots.size > 0);
|
|
248
|
+
// 3. Page models that aren't `persist` (or not of this section), old outcomes, a new page lifecycle.
|
|
249
|
+
scope.nextPage(nextData.section);
|
|
250
|
+
// 4. Head, body, URL.
|
|
251
|
+
swapHead(next);
|
|
252
|
+
const body = document.adoptNode(next.body);
|
|
253
|
+
body.append(announcer);
|
|
254
|
+
document.documentElement.replaceChild(body, document.body);
|
|
255
|
+
if (mode === 'push')
|
|
256
|
+
history.pushState({ kitNav: true, scroll: 0 }, '', finalUrl.href);
|
|
257
|
+
else if (mode === 'replace')
|
|
258
|
+
history.replaceState({ kitNav: true, scroll: 0 }, '', finalUrl.href);
|
|
259
|
+
// The history entry is written: nothing is owed any more.
|
|
260
|
+
if (inFlight === controller)
|
|
261
|
+
inFlightMode = undefined;
|
|
262
|
+
// 5. The new page's serialization scripts, then one fresh pass.
|
|
263
|
+
runScripts(next, allowed, nonce);
|
|
264
|
+
forgotten = forgetHydrationData(goneIds);
|
|
265
|
+
reopenHydration();
|
|
266
|
+
tSwapped = performance.now();
|
|
267
|
+
pass = runIslandsPass(table, site, scope, {
|
|
268
|
+
root: document.body,
|
|
269
|
+
skip: keep,
|
|
270
|
+
});
|
|
271
|
+
lastPass = pass;
|
|
272
|
+
passes.push(pass);
|
|
273
|
+
scrollAfterSwap(finalUrl, restoreScroll);
|
|
274
|
+
};
|
|
275
|
+
const run = async () => {
|
|
276
|
+
swap();
|
|
277
|
+
await pass?.ready;
|
|
278
|
+
};
|
|
279
|
+
try {
|
|
280
|
+
const transition = viewTransitionsWanted()
|
|
281
|
+
? document.startViewTransition(run)
|
|
282
|
+
: undefined;
|
|
283
|
+
if (transition) {
|
|
284
|
+
await transition.updateCallbackDone;
|
|
285
|
+
void transition.finished.catch(() => { });
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
await run();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
console.error('[nav] the page swap failed:', error);
|
|
293
|
+
releaseRooms();
|
|
294
|
+
location.assign(finalUrl.href);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const tReady = performance.now();
|
|
298
|
+
setTimeout(releaseRooms, ROOM_HANDOFF_MS);
|
|
299
|
+
focusAndAnnounce(announcer);
|
|
300
|
+
if (inFlight === controller) {
|
|
301
|
+
inFlight = undefined;
|
|
302
|
+
inFlightMode = undefined;
|
|
303
|
+
}
|
|
304
|
+
const timing = {
|
|
305
|
+
url: finalUrl.pathname + finalUrl.search,
|
|
306
|
+
mode,
|
|
307
|
+
fetchMs: round(tFetched - t0),
|
|
308
|
+
swapMs: round(tSwapped - tFetched),
|
|
309
|
+
hydrateMs: round(tReady - tSwapped),
|
|
310
|
+
totalMs: round(tReady - t0),
|
|
311
|
+
persisted,
|
|
312
|
+
islands: liveCount(),
|
|
313
|
+
forgotten,
|
|
314
|
+
};
|
|
315
|
+
window.dispatchEvent(new CustomEvent('kit:page-load', { detail: timing }));
|
|
316
|
+
}
|
|
317
|
+
document.addEventListener('click', (event) => {
|
|
318
|
+
if (event.defaultPrevented || event.button !== 0)
|
|
319
|
+
return;
|
|
320
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
|
|
321
|
+
return;
|
|
322
|
+
const a = event.target?.closest?.('a') ?? null;
|
|
323
|
+
const url = followable(a);
|
|
324
|
+
if (!url)
|
|
325
|
+
return;
|
|
326
|
+
// An in-page anchor: the browser scrolls, no fetch.
|
|
327
|
+
if (url.pathname === location.pathname &&
|
|
328
|
+
url.search === location.search &&
|
|
329
|
+
url.hash !== '')
|
|
330
|
+
return;
|
|
331
|
+
event.preventDefault();
|
|
332
|
+
const same = url.pathname === location.pathname && url.search === location.search;
|
|
333
|
+
void go(url.href, same ? 'replace' : 'push');
|
|
334
|
+
});
|
|
335
|
+
let hoverTimer;
|
|
336
|
+
document.addEventListener('pointerover', (event) => {
|
|
337
|
+
clearTimeout(hoverTimer);
|
|
338
|
+
const a = event.target?.closest?.('a') ?? null;
|
|
339
|
+
const url = followable(a);
|
|
340
|
+
if (!url || prefetched?.href === url.href)
|
|
341
|
+
return;
|
|
342
|
+
hoverTimer = setTimeout(() => {
|
|
343
|
+
prefetched = {
|
|
344
|
+
href: url.href,
|
|
345
|
+
at: performance.now(),
|
|
346
|
+
res: fetch(url.href, {
|
|
347
|
+
headers: { Accept: 'text/html', 'X-Kit-Nav': '1' },
|
|
348
|
+
credentials: 'same-origin',
|
|
349
|
+
}),
|
|
350
|
+
};
|
|
351
|
+
prefetched.res.catch(() => { });
|
|
352
|
+
}, PREFETCH_HOVER_MS);
|
|
353
|
+
});
|
|
354
|
+
window.addEventListener('popstate', (event) => {
|
|
355
|
+
if (!isHistoryState(event.state))
|
|
356
|
+
return;
|
|
357
|
+
void go(location.href, 'traverse', event.state.scroll);
|
|
358
|
+
});
|
|
359
|
+
// Back to this document from the back/forward cache: nothing in flight.
|
|
360
|
+
window.addEventListener('pageshow', (event) => {
|
|
361
|
+
if (event.persisted)
|
|
362
|
+
inFlight?.abort();
|
|
363
|
+
});
|
|
364
|
+
setClientNavigator((href, replace) => {
|
|
365
|
+
const url = new URL(href, location.href);
|
|
366
|
+
if (!inSection(url))
|
|
367
|
+
return false;
|
|
368
|
+
void go(url.href, replace ? 'replace' : 'push');
|
|
369
|
+
return true;
|
|
370
|
+
});
|
|
371
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as awarenessProtocol from 'y-protocols/awareness';
|
|
2
|
+
import type * as Y from 'yjs';
|
|
3
|
+
/** How long a `ping` may go unanswered before the socket counts as dead. */
|
|
4
|
+
export declare const PONG_TIMEOUT_MS = 10000;
|
|
5
|
+
/** The doc socket's state as the provider sees it. */
|
|
6
|
+
export type DocConnection = 'Connecting' | 'Synced' | 'Offline';
|
|
7
|
+
/** The slice of `WebSocket` the provider uses. */
|
|
8
|
+
export interface DocSocketLike {
|
|
9
|
+
binaryType: string;
|
|
10
|
+
readonly readyState: number;
|
|
11
|
+
onopen: ((event: unknown) => void) | null;
|
|
12
|
+
onmessage: ((event: {
|
|
13
|
+
readonly data: unknown;
|
|
14
|
+
}) => void) | null;
|
|
15
|
+
onclose: ((event: unknown) => void) | null;
|
|
16
|
+
onerror: ((event: unknown) => void) | null;
|
|
17
|
+
send(data: string | Uint8Array): void;
|
|
18
|
+
close(): void;
|
|
19
|
+
}
|
|
20
|
+
export interface DocProviderDeps {
|
|
21
|
+
readonly openSocket: (path: string) => DocSocketLike;
|
|
22
|
+
readonly setTimeout: (fn: () => void, ms: number) => unknown;
|
|
23
|
+
readonly clearTimeout: (handle: unknown) => void;
|
|
24
|
+
readonly now: () => number;
|
|
25
|
+
readonly random: () => number;
|
|
26
|
+
/** Whether the tab is hidden now. */
|
|
27
|
+
readonly isHidden: () => boolean;
|
|
28
|
+
/** Visibility changes; returns an unsubscribe. */
|
|
29
|
+
readonly onVisibility: (fn: () => void) => () => void;
|
|
30
|
+
/** Network came back (`online`); returns an unsubscribe. */
|
|
31
|
+
readonly onOnline: (fn: () => void) => () => void;
|
|
32
|
+
}
|
|
33
|
+
export interface DocProviderOptions {
|
|
34
|
+
/** The doc socket path (`DocRef.path`). */
|
|
35
|
+
readonly path: string;
|
|
36
|
+
readonly doc: Y.Doc;
|
|
37
|
+
readonly awareness: awarenessProtocol.Awareness;
|
|
38
|
+
/** Whether the viewer may write (Editor access, not refused). Read on every send. */
|
|
39
|
+
readonly canWrite: () => boolean;
|
|
40
|
+
/** Connection changes (deduped). */
|
|
41
|
+
readonly onConnection: (connection: DocConnection) => void;
|
|
42
|
+
/** The room refused a write (`read-only`, `doc-full`). */
|
|
43
|
+
readonly onDenied?: (reason: string) => void;
|
|
44
|
+
}
|
|
45
|
+
export interface DocProvider {
|
|
46
|
+
/** Reconnect now (the viewer changed: a new identity at the room). */
|
|
47
|
+
readonly reconnect: () => void;
|
|
48
|
+
/** The local awareness state to announce while visible (`null`: none). */
|
|
49
|
+
readonly setLocalState: (state: Record<string, unknown> | null) => void;
|
|
50
|
+
readonly destroy: () => void;
|
|
51
|
+
/** Kit-internal counters (tests). */
|
|
52
|
+
readonly stats: () => {
|
|
53
|
+
readonly opened: number;
|
|
54
|
+
readonly sentFrames: number;
|
|
55
|
+
readonly pings: number;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Connects `doc` (and its `awareness`) to a room doc socket. Starts at
|
|
60
|
+
* once (call it after hydration settles); `destroy()` ends it.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const doc = new Y.Doc();
|
|
65
|
+
* const awareness = new Awareness(doc);
|
|
66
|
+
* const provider = createDocProvider({
|
|
67
|
+
* path: notes.path, doc, awareness,
|
|
68
|
+
* canWrite: () => access === "Editor",
|
|
69
|
+
* onConnection: (c) => console.log(c),
|
|
70
|
+
* });
|
|
71
|
+
* provider.setLocalState({ user: { name: "Alice", color: "#f80" } });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function createDocProvider(options: DocProviderOptions, deps?: DocProviderDeps): DocProvider;
|