@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,45 @@
|
|
|
1
|
+
import { type Accessor, type Element as SolidElement } from 'solid-js';
|
|
2
|
+
import type { Result as ResultValue, Tagged } from '../logic/result.ts';
|
|
3
|
+
/** Render-time metadata passed to `<Query ok={(value, meta) => ...} />`. */
|
|
4
|
+
export interface QueryMeta {
|
|
5
|
+
readonly isPending: Accessor<boolean>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Renders the success branch of a `<Query>`.
|
|
9
|
+
*
|
|
10
|
+
* Plain-object values (the normal case: a server function's record) are
|
|
11
|
+
* passed to `ok` as a live, read-only store view (`createProjection` over the
|
|
12
|
+
* result). `ok` runs ONCE per Ok mount; a refetch that lands a new value is
|
|
13
|
+
* reconciled into the view (arrays keyed by `id`), so only the bindings that
|
|
14
|
+
* read changed fields update. DOM identity, focus and local component state
|
|
15
|
+
* inside `ok` survive refetches. The view's handle is stable even when the
|
|
16
|
+
* root record's `id` changes (the projection swaps its root internally).
|
|
17
|
+
*
|
|
18
|
+
* Contract for `ok`, same as `<Match>` cases: read fields where they are
|
|
19
|
+
* used (`stats.queueDepth` in JSX), do not destructure. A model seeded from
|
|
20
|
+
* the value (`createModel({ init: initFrom(value) })`) gets a plain snapshot
|
|
21
|
+
* (`createModel` snapshots its init).
|
|
22
|
+
*
|
|
23
|
+
* Server (SSR): `ok` is built once the value has landed and receives the
|
|
24
|
+
* settled plain value, not the view (the server never refetches, and the
|
|
25
|
+
* view is still a pending proxy at that point, so every field read would
|
|
26
|
+
* throw and retry Solid's not-ready error). The view is still created, so
|
|
27
|
+
* owner ids match the client's for hydration.
|
|
28
|
+
*
|
|
29
|
+
* Other values (primitives, arrays, class instances) cannot be viewed in
|
|
30
|
+
* place, so `ok` re-runs with the new value when it changes (keyed).
|
|
31
|
+
*
|
|
32
|
+
* While the result is `Err` nothing renders here (the error branch does);
|
|
33
|
+
* going Err -> Ok mounts `ok` again.
|
|
34
|
+
*
|
|
35
|
+
* @param result - The `<Query>`'s async result accessor (read under `<Loading>`).
|
|
36
|
+
* @param ok - The app's success renderer.
|
|
37
|
+
* @param meta - Render metadata (`isPending`).
|
|
38
|
+
* @returns The success branch element.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* renderOkBranch(result, (value, meta) => props.ok(value, meta), meta);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function renderOkBranch<T>(result: Accessor<ResultValue<T, Tagged>>, ok: (value: T, meta: QueryMeta) => SolidElement, meta: QueryMeta): SolidElement;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { isServer } from '@solidjs/web';
|
|
2
|
+
import { createComponent, createMemo, createProjection, Show, untrack, } from 'solid-js';
|
|
3
|
+
const RenderShow = Show;
|
|
4
|
+
function isPlainObject(value) {
|
|
5
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const proto = Object.getPrototypeOf(value);
|
|
9
|
+
return proto === Object.prototype || proto === null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Renders the success branch of a `<Query>`.
|
|
13
|
+
*
|
|
14
|
+
* Plain-object values (the normal case: a server function's record) are
|
|
15
|
+
* passed to `ok` as a live, read-only store view (`createProjection` over the
|
|
16
|
+
* result). `ok` runs ONCE per Ok mount; a refetch that lands a new value is
|
|
17
|
+
* reconciled into the view (arrays keyed by `id`), so only the bindings that
|
|
18
|
+
* read changed fields update. DOM identity, focus and local component state
|
|
19
|
+
* inside `ok` survive refetches. The view's handle is stable even when the
|
|
20
|
+
* root record's `id` changes (the projection swaps its root internally).
|
|
21
|
+
*
|
|
22
|
+
* Contract for `ok`, same as `<Match>` cases: read fields where they are
|
|
23
|
+
* used (`stats.queueDepth` in JSX), do not destructure. A model seeded from
|
|
24
|
+
* the value (`createModel({ init: initFrom(value) })`) gets a plain snapshot
|
|
25
|
+
* (`createModel` snapshots its init).
|
|
26
|
+
*
|
|
27
|
+
* Server (SSR): `ok` is built once the value has landed and receives the
|
|
28
|
+
* settled plain value, not the view (the server never refetches, and the
|
|
29
|
+
* view is still a pending proxy at that point, so every field read would
|
|
30
|
+
* throw and retry Solid's not-ready error). The view is still created, so
|
|
31
|
+
* owner ids match the client's for hydration.
|
|
32
|
+
*
|
|
33
|
+
* Other values (primitives, arrays, class instances) cannot be viewed in
|
|
34
|
+
* place, so `ok` re-runs with the new value when it changes (keyed).
|
|
35
|
+
*
|
|
36
|
+
* While the result is `Err` nothing renders here (the error branch does);
|
|
37
|
+
* going Err -> Ok mounts `ok` again.
|
|
38
|
+
*
|
|
39
|
+
* @param result - The `<Query>`'s async result accessor (read under `<Loading>`).
|
|
40
|
+
* @param ok - The app's success renderer.
|
|
41
|
+
* @param meta - Render metadata (`isPending`).
|
|
42
|
+
* @returns The success branch element.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* renderOkBranch(result, (value, meta) => props.ok(value, meta), meta);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function renderOkBranch(result, ok, meta) {
|
|
50
|
+
const kind = createMemo(() => {
|
|
51
|
+
const current = result();
|
|
52
|
+
if (current._tag !== 'Ok')
|
|
53
|
+
return null;
|
|
54
|
+
return isPlainObject(current.value) ? 'view' : 'value';
|
|
55
|
+
});
|
|
56
|
+
// Typed loosely (`T` is unconstrained); only plain-object values reach it.
|
|
57
|
+
const view = createProjection(() => {
|
|
58
|
+
const current = result();
|
|
59
|
+
if (current._tag === 'Ok' && isPlainObject(current.value)) {
|
|
60
|
+
return current.value;
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}, {});
|
|
64
|
+
// The server renders once and never refetches, and its projection is
|
|
65
|
+
// still a pending proxy when this branch first runs (its compute settles
|
|
66
|
+
// after the async result does), so every field read in `ok` would throw
|
|
67
|
+
// and retry Solid's not-ready error. Hand the server the settled plain
|
|
68
|
+
// value instead. The projection is still created above on both builds,
|
|
69
|
+
// so owner (hydration) ids and its serialized value stay aligned.
|
|
70
|
+
const okValue = () => {
|
|
71
|
+
if (!isServer)
|
|
72
|
+
return view;
|
|
73
|
+
const current = result();
|
|
74
|
+
return current.value;
|
|
75
|
+
};
|
|
76
|
+
return [
|
|
77
|
+
createComponent(RenderShow, {
|
|
78
|
+
get when() {
|
|
79
|
+
return kind() === 'view';
|
|
80
|
+
},
|
|
81
|
+
get children() {
|
|
82
|
+
return untrack(() => ok(okValue(), meta));
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
createComponent(RenderShow, {
|
|
86
|
+
get when() {
|
|
87
|
+
const current = result();
|
|
88
|
+
return kind() === 'value' && current._tag === 'Ok'
|
|
89
|
+
? current
|
|
90
|
+
: null;
|
|
91
|
+
},
|
|
92
|
+
keyed: true,
|
|
93
|
+
children: (current) => untrack(() => ok(current.value, meta)),
|
|
94
|
+
}),
|
|
95
|
+
];
|
|
96
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/** @jsxImportSource @solidjs/web */
|
|
2
|
+
import { type Accessor, type Element as SolidElement } from 'solid-js';
|
|
3
|
+
import { type QueryMeta } from './query-ok.ts';
|
|
4
|
+
import type { QueryDef } from '../logic/query-def.ts';
|
|
5
|
+
import type { QueryError, QueryFailure } from '../logic/query-types.ts';
|
|
6
|
+
export { UNEXPECTED_QUERY_MESSAGE, type QueryError, type QueryFailure, type UnexpectedQueryError, } from '../logic/query-types.ts';
|
|
7
|
+
export type { QueryMeta } from './query-ok.ts';
|
|
8
|
+
/**
|
|
9
|
+
* Exhaustive error case object for `<Query error={...}>`: one render function
|
|
10
|
+
* per typed failure tag of `E` plus `Unexpected`, each narrowed to its
|
|
11
|
+
* variant like `<Match on={...}>{{ ... }}</Match>` (and rendered through
|
|
12
|
+
* `<Match>`, so a same-tag error with new fields updates in place). The
|
|
13
|
+
* second argument is the same `meta` the `ok` view gets: while a `Refetch`
|
|
14
|
+
* (retry) of the same input runs, the error stays on screen and
|
|
15
|
+
* `meta.isPending()` is true, so a case can show "Retrying..." or disable
|
|
16
|
+
* its button. `E` is inferred from `query`, never from the cases.
|
|
17
|
+
*/
|
|
18
|
+
export type QueryErrorCases<E extends QueryFailure> = {
|
|
19
|
+
readonly [K in NoInfer<QueryError<E>>['_tag']]: (error: NoInfer<Extract<QueryError<E>, {
|
|
20
|
+
readonly _tag: K;
|
|
21
|
+
}>>, meta: QueryMeta) => SolidElement;
|
|
22
|
+
};
|
|
23
|
+
type QueryInputProp<Input> = [Input] extends [void] ? {
|
|
24
|
+
readonly input?: void;
|
|
25
|
+
} : undefined extends Input ? {
|
|
26
|
+
readonly input?: Input;
|
|
27
|
+
} : {
|
|
28
|
+
readonly input: Input;
|
|
29
|
+
};
|
|
30
|
+
export type QueryProps<Input, T, E extends QueryFailure> = QueryInputProp<Input> & {
|
|
31
|
+
readonly query: QueryDef<Input, T, E>;
|
|
32
|
+
readonly pending: SolidElement;
|
|
33
|
+
/**
|
|
34
|
+
* Success view. Runs once per Ok mount: for record values it receives a
|
|
35
|
+
* live read-only view that refetches update in place (fine-grained, DOM
|
|
36
|
+
* kept), so read fields where used and never destructure. See
|
|
37
|
+
* `renderOkBranch`.
|
|
38
|
+
*/
|
|
39
|
+
readonly ok: (value: T, meta: QueryMeta) => SolidElement;
|
|
40
|
+
/**
|
|
41
|
+
* Optional exhaustive error cases `{ SomeTag: (e, meta) => ..., Unexpected: (e, meta) => ... }`.
|
|
42
|
+
* Omit it to get the kit's default danger `<Notice>` with a "Try again"
|
|
43
|
+
* button. App code never retries directly: to retry from a custom case,
|
|
44
|
+
* send a Message whose `update` returns a kit `Refetch` Command.
|
|
45
|
+
*/
|
|
46
|
+
readonly error?: QueryErrorCases<E>;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Default `<Query>` error view: a danger notice showing the error's safe
|
|
50
|
+
* `message` and a "Try again" button wired to the kit's internal retry.
|
|
51
|
+
* `Unauthorized` (the request has no session) is the one special case: a
|
|
52
|
+
* warning without "Try again" (retrying would fail the same way). Apps
|
|
53
|
+
* rarely show it: the kit's route model (`routerListens`) hears any read
|
|
54
|
+
* failing `Unauthorized` and sends the visitor on a protected route to
|
|
55
|
+
* sign-in (the client half of the Worker's auth redirect).
|
|
56
|
+
*/
|
|
57
|
+
export declare function QueryErrorNotice(props: {
|
|
58
|
+
readonly error: QueryError<QueryFailure>;
|
|
59
|
+
readonly retry: () => void;
|
|
60
|
+
}): SolidElement;
|
|
61
|
+
/**
|
|
62
|
+
* Framework-enforced async data-loading boundary.
|
|
63
|
+
*
|
|
64
|
+
* Accepts ONLY branded `QueryDef<Input, T, E>` entries produced by
|
|
65
|
+
* `createQueryRegistry({ ... })` — never raw functions or closures.
|
|
66
|
+
* Internally owns `createMemo`, `<Errored>`, `<Loading>` and `isPending`.
|
|
67
|
+
*
|
|
68
|
+
* Errors: typed failures (`Err<E>`) and anything thrown while loading
|
|
69
|
+
* (reported as `{ _tag: "Unexpected", message: "Something went wrong." }`)
|
|
70
|
+
* render through the optional exhaustive `error` case object (via `<Match>`,
|
|
71
|
+
* so a same-tag error with new fields updates in place). Omit it to get the
|
|
72
|
+
* kit's default `QueryErrorNotice` (whose "Try again" is kit-internal).
|
|
73
|
+
*
|
|
74
|
+
* Inside `<AppScope>`:
|
|
75
|
+
* - Shared reads: queries with the same id + serialized input + generation
|
|
76
|
+
* share one execution while any `<Query>` holds it (per SSR request on the
|
|
77
|
+
* server, per page on the client) — two panels, one server call.
|
|
78
|
+
* - Refetch: a `Refetch` Command, a mutation's `invalidates`, or the default
|
|
79
|
+
* notice's "Try again" bumps the query's generation in the scope; every
|
|
80
|
+
* `<Query>` of it moves to one fresh execution, keeping the old value on
|
|
81
|
+
* screen (`meta.isPending()`) until the new one lands.
|
|
82
|
+
* - A new `input` is different data: the `<Loading>` is keyed on it, so the
|
|
83
|
+
* `pending` fallback shows again until the new input's value lands.
|
|
84
|
+
* - Outcomes: every settled result is published by query id + input for
|
|
85
|
+
* `createModel({ listens })` (client only, after hydration).
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```tsx
|
|
89
|
+
* // Default error UI
|
|
90
|
+
* <Query query={plannerQueries.character} input="voltar-main"
|
|
91
|
+
* pending={<Spinner />} ok={(c) => <Text>{c.name}</Text>} />
|
|
92
|
+
*
|
|
93
|
+
* // Exhaustive in-place error views; retry = a Message whose update returns
|
|
94
|
+
* // plannerRefetch("simStats") (a kit Refetch Command)
|
|
95
|
+
* <Query query={plannerQueries.simStats} input={{}}
|
|
96
|
+
* pending={<Spinner />} ok={(s) => <Text>{s.runNumber}</Text>}
|
|
97
|
+
* error={{
|
|
98
|
+
* SimOverloaded: (o) => <Overloaded error={o} onRetry={() => send({ _tag: "RetryRequested" })} />,
|
|
99
|
+
* Unexpected: (u) => <Text>{u.message}</Text>,
|
|
100
|
+
* }} />
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function Query<Input, T, E extends QueryFailure>(props: QueryProps<Input, T, E>): SolidElement;
|
|
104
|
+
/**
|
|
105
|
+
* Computes a value once during SSR and serializes it into the hydration
|
|
106
|
+
* payload, so client hydration adopts the exact server value.
|
|
107
|
+
*
|
|
108
|
+
* Solid only serializes ASYNC memo answers (a synchronous memo is simply
|
|
109
|
+
* recomputed on the client), so the compute is wrapped in an async function.
|
|
110
|
+
* The answer is already resolved on the server, so it does not hold the
|
|
111
|
+
* shell; on the client the hydrated answer is adopted instead of the
|
|
112
|
+
* compute's own result. Client-only renders (no SSR payload) run `compute`
|
|
113
|
+
* in the browser.
|
|
114
|
+
*/
|
|
115
|
+
export declare function createServerValue<T>(compute: () => T): Accessor<T>;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/** @jsxImportSource @solidjs/web */
|
|
2
|
+
import { isServer } from '@solidjs/web';
|
|
3
|
+
import { createMemo, createSignal, Errored, isPending, Loading, onCleanup, Show, untrack, } from 'solid-js';
|
|
4
|
+
import { useKitScope } from './app-scope.js';
|
|
5
|
+
import { Match } from './match.js';
|
|
6
|
+
import { createOutcomePublisher, createSharedRead, createUnexpectedWatchers, UNEXPECTED, } from './query-effects.js';
|
|
7
|
+
import { renderOkBranch } from './query-ok.js';
|
|
8
|
+
import { Button, Notice } from '../ui/index.js';
|
|
9
|
+
export { UNEXPECTED_QUERY_MESSAGE, } from '../logic/query-types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Default `<Query>` error view: a danger notice showing the error's safe
|
|
12
|
+
* `message` and a "Try again" button wired to the kit's internal retry.
|
|
13
|
+
* `Unauthorized` (the request has no session) is the one special case: a
|
|
14
|
+
* warning without "Try again" (retrying would fail the same way). Apps
|
|
15
|
+
* rarely show it: the kit's route model (`routerListens`) hears any read
|
|
16
|
+
* failing `Unauthorized` and sends the visitor on a protected route to
|
|
17
|
+
* sign-in (the client half of the Worker's auth redirect).
|
|
18
|
+
*/
|
|
19
|
+
export function QueryErrorNotice(props) {
|
|
20
|
+
const unauthorized = () => props.error._tag === 'Unauthorized';
|
|
21
|
+
return (<Show when={unauthorized()} fallback={<Notice tone="danger" title="Couldn't load this section" description={props.error.message} action={<Button size="sm" variant="primary" onClick={() => props.retry()}>
|
|
22
|
+
Try again
|
|
23
|
+
</Button>}/>}>
|
|
24
|
+
<Notice tone="warning" title="Sign in to see this" description={props.error.message}/>
|
|
25
|
+
</Show>);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Render-nothing child that publishes this `<Query>`'s outcomes (Way 2). It
|
|
29
|
+
* sits inside `<Loading>` so its effect's pending read is owned by that
|
|
30
|
+
* boundary; see `createOutcomePublisher` for the hydration-id rule.
|
|
31
|
+
*/
|
|
32
|
+
function QueryOutcomePublisher(props) {
|
|
33
|
+
createOutcomePublisher(props.scope, props.queryId, props.inputKey, props.cacheKey, props.data);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Framework-enforced async data-loading boundary.
|
|
38
|
+
*
|
|
39
|
+
* Accepts ONLY branded `QueryDef<Input, T, E>` entries produced by
|
|
40
|
+
* `createQueryRegistry({ ... })` — never raw functions or closures.
|
|
41
|
+
* Internally owns `createMemo`, `<Errored>`, `<Loading>` and `isPending`.
|
|
42
|
+
*
|
|
43
|
+
* Errors: typed failures (`Err<E>`) and anything thrown while loading
|
|
44
|
+
* (reported as `{ _tag: "Unexpected", message: "Something went wrong." }`)
|
|
45
|
+
* render through the optional exhaustive `error` case object (via `<Match>`,
|
|
46
|
+
* so a same-tag error with new fields updates in place). Omit it to get the
|
|
47
|
+
* kit's default `QueryErrorNotice` (whose "Try again" is kit-internal).
|
|
48
|
+
*
|
|
49
|
+
* Inside `<AppScope>`:
|
|
50
|
+
* - Shared reads: queries with the same id + serialized input + generation
|
|
51
|
+
* share one execution while any `<Query>` holds it (per SSR request on the
|
|
52
|
+
* server, per page on the client) — two panels, one server call.
|
|
53
|
+
* - Refetch: a `Refetch` Command, a mutation's `invalidates`, or the default
|
|
54
|
+
* notice's "Try again" bumps the query's generation in the scope; every
|
|
55
|
+
* `<Query>` of it moves to one fresh execution, keeping the old value on
|
|
56
|
+
* screen (`meta.isPending()`) until the new one lands.
|
|
57
|
+
* - A new `input` is different data: the `<Loading>` is keyed on it, so the
|
|
58
|
+
* `pending` fallback shows again until the new input's value lands.
|
|
59
|
+
* - Outcomes: every settled result is published by query id + input for
|
|
60
|
+
* `createModel({ listens })` (client only, after hydration).
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* // Default error UI
|
|
65
|
+
* <Query query={plannerQueries.character} input="voltar-main"
|
|
66
|
+
* pending={<Spinner />} ok={(c) => <Text>{c.name}</Text>} />
|
|
67
|
+
*
|
|
68
|
+
* // Exhaustive in-place error views; retry = a Message whose update returns
|
|
69
|
+
* // plannerRefetch("simStats") (a kit Refetch Command)
|
|
70
|
+
* <Query query={plannerQueries.simStats} input={{}}
|
|
71
|
+
* pending={<Spinner />} ok={(s) => <Text>{s.runNumber}</Text>}
|
|
72
|
+
* error={{
|
|
73
|
+
* SimOverloaded: (o) => <Overloaded error={o} onRetry={() => send({ _tag: "RetryRequested" })} />,
|
|
74
|
+
* Unexpected: (u) => <Text>{u.message}</Text>,
|
|
75
|
+
* }} />
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export function Query(props) {
|
|
79
|
+
const scope = useKitScope();
|
|
80
|
+
const [attempt, setAttempt] = createSignal(0);
|
|
81
|
+
// Bumped when the scope invalidates this query; the generation itself is
|
|
82
|
+
// read from the scope so every <Query> of it computes the same key.
|
|
83
|
+
const [invalidated, setInvalidated] = createSignal(0);
|
|
84
|
+
const queryId = props.query.id;
|
|
85
|
+
const inputKey = () => props.query.inputKey(props.input);
|
|
86
|
+
const cacheKey = () => {
|
|
87
|
+
void invalidated();
|
|
88
|
+
const input = inputKey();
|
|
89
|
+
const generation = scope
|
|
90
|
+
? scope.invalidations.generation(queryId, input)
|
|
91
|
+
: 0;
|
|
92
|
+
return `${queryId}:${input}#${generation}`;
|
|
93
|
+
};
|
|
94
|
+
if (scope && !isServer) {
|
|
95
|
+
onCleanup(scope.invalidations.subscribe((id, input) => {
|
|
96
|
+
if (id !== queryId)
|
|
97
|
+
return;
|
|
98
|
+
if (input !== undefined && input !== untrack(inputKey))
|
|
99
|
+
return;
|
|
100
|
+
setInvalidated((n) => n + 1);
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
const data = createSharedRead(scope, cacheKey, attempt, () => props.query.execute(props.input));
|
|
104
|
+
const result = data;
|
|
105
|
+
const pending = () => isPending(() => data());
|
|
106
|
+
const meta = { isPending: pending };
|
|
107
|
+
const retry = () => {
|
|
108
|
+
if (scope) {
|
|
109
|
+
scope.invalidations.invalidate(queryId, untrack(inputKey));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
setAttempt((n) => n + 1);
|
|
113
|
+
};
|
|
114
|
+
const errorCases = () => props.error;
|
|
115
|
+
/** The app's cases as `<Match>` cases, each handed this `<Query>`'s `meta`. */
|
|
116
|
+
const withMeta = (cases) => {
|
|
117
|
+
const bound = {};
|
|
118
|
+
for (const tag of Object.keys(cases)) {
|
|
119
|
+
bound[tag] = (e) => cases[tag](e, meta);
|
|
120
|
+
}
|
|
121
|
+
return bound;
|
|
122
|
+
};
|
|
123
|
+
const renderTypedError = (error) => {
|
|
124
|
+
const cases = errorCases();
|
|
125
|
+
return cases ? (<Match on={error()}>{withMeta(cases)}</Match>) : (<QueryErrorNotice error={error()} retry={retry}/>);
|
|
126
|
+
};
|
|
127
|
+
// Thrown failures leave the read errored: there is no pending read to
|
|
128
|
+
// report until the watchers reset the boundary, so this meta answers
|
|
129
|
+
// false instead of rethrowing from inside the error view.
|
|
130
|
+
const unexpectedMeta = {
|
|
131
|
+
isPending: () => {
|
|
132
|
+
try {
|
|
133
|
+
return pending();
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
const renderUnexpected = (reset) => {
|
|
141
|
+
const failedKey = untrack(cacheKey);
|
|
142
|
+
createUnexpectedWatchers(scope, queryId, untrack(inputKey), cacheKey, failedKey, reset);
|
|
143
|
+
const cases = errorCases();
|
|
144
|
+
return cases ? (untrack(() => cases.Unexpected(UNEXPECTED, unexpectedMeta))) : (<QueryErrorNotice error={UNEXPECTED} retry={() => {
|
|
145
|
+
scope?.queries.evict(failedKey);
|
|
146
|
+
reset();
|
|
147
|
+
}}/>);
|
|
148
|
+
};
|
|
149
|
+
return (<Errored fallback={(thrown, reset) => {
|
|
150
|
+
console.error(`[Query:${queryId}] Unexpected load failure:`, thrown());
|
|
151
|
+
return renderUnexpected(reset);
|
|
152
|
+
}}>
|
|
153
|
+
{/* Keyed on the input: a NEW input is different data, so the pending
|
|
154
|
+
fallback shows again (and the model write that changed it commits at
|
|
155
|
+
once); a Refetch of the same input keeps the old value on screen
|
|
156
|
+
with meta.isPending(). */}
|
|
157
|
+
<Loading fallback={props.pending} on={inputKey()}>
|
|
158
|
+
{scope ? (<QueryOutcomePublisher scope={scope} queryId={queryId} inputKey={inputKey} cacheKey={cacheKey} data={data}/>) : null}
|
|
159
|
+
{renderOkBranch(result, (value, okMeta) => props.ok(value, okMeta), meta)}
|
|
160
|
+
<Show when={result()._tag === 'Err'}>
|
|
161
|
+
{renderTypedError(() => result().error)}
|
|
162
|
+
</Show>
|
|
163
|
+
</Loading>
|
|
164
|
+
</Errored>);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Computes a value once during SSR and serializes it into the hydration
|
|
168
|
+
* payload, so client hydration adopts the exact server value.
|
|
169
|
+
*
|
|
170
|
+
* Solid only serializes ASYNC memo answers (a synchronous memo is simply
|
|
171
|
+
* recomputed on the client), so the compute is wrapped in an async function.
|
|
172
|
+
* The answer is already resolved on the server, so it does not hold the
|
|
173
|
+
* shell; on the client the hydrated answer is adopted instead of the
|
|
174
|
+
* compute's own result. Client-only renders (no SSR payload) run `compute`
|
|
175
|
+
* in the browser.
|
|
176
|
+
*/
|
|
177
|
+
export function createServerValue(compute) {
|
|
178
|
+
return createMemo(async () => compute(), { ssrSource: 'server' });
|
|
179
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @jsxImportSource @solidjs/web */
|
|
2
|
+
import type { Element as SolidElement } from 'solid-js';
|
|
3
|
+
import type { Result as ResultValue, TagHandlers, Tagged } from '../logic/result.ts';
|
|
4
|
+
export interface ResultViewProps<T, E extends Tagged> {
|
|
5
|
+
readonly of: ResultValue<T, E>;
|
|
6
|
+
readonly ok: (value: T) => SolidElement;
|
|
7
|
+
readonly error: TagHandlers<E, SolidElement>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Renders a plain `Result<T, E>` with exhaustive per-tag error handlers.
|
|
11
|
+
* Uses keyed `<Show>` branches so Solid tracks `props.of` reactively without
|
|
12
|
+
* untracked top-level reads.
|
|
13
|
+
*/
|
|
14
|
+
export declare function Result<T, E extends Tagged>(props: ResultViewProps<T, E>): SolidElement;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @jsxImportSource @solidjs/web */
|
|
2
|
+
import { Show } from 'solid-js';
|
|
3
|
+
import { matchTag } from '../logic/result.js';
|
|
4
|
+
/**
|
|
5
|
+
* Renders a plain `Result<T, E>` with exhaustive per-tag error handlers.
|
|
6
|
+
* Uses keyed `<Show>` branches so Solid tracks `props.of` reactively without
|
|
7
|
+
* untracked top-level reads.
|
|
8
|
+
*/
|
|
9
|
+
export function Result(props) {
|
|
10
|
+
return (<Show when={props.of._tag === 'Ok' ? props.of : null} keyed fallback={<Show when={props.of._tag === 'Err' ? props.of.error : null} keyed>
|
|
11
|
+
{(e) => matchTag(e, props.error)}
|
|
12
|
+
</Show>}>
|
|
13
|
+
{(success) => props.ok(success.value)}
|
|
14
|
+
</Show>);
|
|
15
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type Element as SolidElement } from 'solid-js';
|
|
2
|
+
import type { RoutePaths, RouteTable } from '../logic/route-table.ts';
|
|
3
|
+
/**
|
|
4
|
+
* What every page component receives from the route table (all optional
|
|
5
|
+
* to use: a page that needs nothing declares no props).
|
|
6
|
+
*
|
|
7
|
+
* - `route`: this page's route as data, narrowed to its tag. Read params
|
|
8
|
+
* where used (`props.route.params.planId`, `props.route.search.tab`):
|
|
9
|
+
* a navigation to new params of the same route updates them in place
|
|
10
|
+
* (fine-grained, the page stays mounted).
|
|
11
|
+
* - `paths`: the table's matching data, for selectors that build links
|
|
12
|
+
* (`hrefFor(paths, route)`).
|
|
13
|
+
* - `sendNav`: the route model's `send`, so a page can navigate with a
|
|
14
|
+
* Message (`sendNav({ _tag: "Navigated", to })`).
|
|
15
|
+
*/
|
|
16
|
+
export interface PageProps<Route, Paths = RoutePaths, NavMsg = never> {
|
|
17
|
+
readonly route: Route;
|
|
18
|
+
readonly paths: Paths;
|
|
19
|
+
readonly sendNav: (msg: NavMsg) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Turns the route table into one lazy component per route (per-route code
|
|
23
|
+
* splitting: each page is its own chunk, loaded on first render) and
|
|
24
|
+
* returns `<RoutePage route={...} paths={...} sendNav={...} />`, which
|
|
25
|
+
* renders the current route's page and its head (the table's `head`, via
|
|
26
|
+
* Solid's `useHead`: in the SSR / prerendered `<head>`, replaced on client
|
|
27
|
+
* navigation) through `<Match>` (one mounted page per
|
|
28
|
+
* tag; switching tags swaps pages, new params of the same tag keep it and
|
|
29
|
+
* update `props.route` in place).
|
|
30
|
+
*
|
|
31
|
+
* SSR waits for the page module before flushing the shell; the browser
|
|
32
|
+
* preloads it for hydration (Solid's `lazy` + the Vite plugin's module
|
|
33
|
+
* manifest). Call it inside the root component (not at module scope).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* const RoutePage = createRoutePages(routes);
|
|
38
|
+
* <RoutePage route={nav().route} paths={nav().paths} sendNav={sendNav} />
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function createRoutePages<T extends RouteTable>(table: T): <Route extends {
|
|
42
|
+
readonly _tag: keyof T & string;
|
|
43
|
+
}, Paths, NavMsg>(props: PageProps<Route, Paths, NavMsg>) => SolidElement;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createComponent, lazy } from 'solid-js';
|
|
2
|
+
import { RouteHeadTags } from './head-view.js';
|
|
3
|
+
import { Match } from './match.js';
|
|
4
|
+
/**
|
|
5
|
+
* Turns the route table into one lazy component per route (per-route code
|
|
6
|
+
* splitting: each page is its own chunk, loaded on first render) and
|
|
7
|
+
* returns `<RoutePage route={...} paths={...} sendNav={...} />`, which
|
|
8
|
+
* renders the current route's page and its head (the table's `head`, via
|
|
9
|
+
* Solid's `useHead`: in the SSR / prerendered `<head>`, replaced on client
|
|
10
|
+
* navigation) through `<Match>` (one mounted page per
|
|
11
|
+
* tag; switching tags swaps pages, new params of the same tag keep it and
|
|
12
|
+
* update `props.route` in place).
|
|
13
|
+
*
|
|
14
|
+
* SSR waits for the page module before flushing the shell; the browser
|
|
15
|
+
* preloads it for hydration (Solid's `lazy` + the Vite plugin's module
|
|
16
|
+
* manifest). Call it inside the root component (not at module scope).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const RoutePage = createRoutePages(routes);
|
|
21
|
+
* <RoutePage route={nav().route} paths={nav().paths} sendNav={sendNav} />
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function createRoutePages(table) {
|
|
25
|
+
const pages = {};
|
|
26
|
+
for (const [tag, entry] of Object.entries(table)) {
|
|
27
|
+
pages[tag] = lazy(entry.page);
|
|
28
|
+
}
|
|
29
|
+
return (props) => {
|
|
30
|
+
const cases = {};
|
|
31
|
+
for (const tag of Object.keys(pages)) {
|
|
32
|
+
const Page = pages[tag];
|
|
33
|
+
const entry = table[tag];
|
|
34
|
+
cases[tag] = (route) => [
|
|
35
|
+
// The route's head (title, description, canonical, OG, JSON-LD).
|
|
36
|
+
createComponent(RouteHeadTags, {
|
|
37
|
+
path: entry.path,
|
|
38
|
+
head: entry.head,
|
|
39
|
+
route: route,
|
|
40
|
+
}),
|
|
41
|
+
createComponent(Page, {
|
|
42
|
+
route,
|
|
43
|
+
get paths() {
|
|
44
|
+
return props.paths;
|
|
45
|
+
},
|
|
46
|
+
get sendNav() {
|
|
47
|
+
return props.sendNav;
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
return createComponent(Match, {
|
|
53
|
+
get on() {
|
|
54
|
+
return props.route;
|
|
55
|
+
},
|
|
56
|
+
children: cases,
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export { normalizePathname, resolveRoute } from '../logic/path.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The path + query of the page being rendered: the request URL during SSR,
|
|
4
|
+
* `location` in the browser, `/` otherwise.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* currentUrl(); // "/plans/voltar-main?tab=stats"
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare function currentUrl(): string;
|
|
12
|
+
/** @deprecated Use `currentUrl()` (it keeps the query string for search params). */
|
|
13
|
+
export declare function currentPathname(): string;
|
|
14
|
+
/** Follows `href` by client navigation; `false` when it is not a client route (then a full load). */
|
|
15
|
+
type ClientNavigator = (href: string, replace: boolean) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Kit-internal: the client navigation runtime registers itself, so the
|
|
18
|
+
* `Navigate` Command takes the same path a link click does.
|
|
19
|
+
*/
|
|
20
|
+
export declare function setClientNavigator(navigator: ClientNavigator): void;
|
|
21
|
+
/**
|
|
22
|
+
* Runs the `Navigate` kit Command: a full document navigation
|
|
23
|
+
* (`location.assign`, or `location.replace` with `replace`). Pages are
|
|
24
|
+
* static server HTML plus islands, so a new page is a new document: the
|
|
25
|
+
* Worker renders (or the CDN serves) it, and its islands hydrate. There is
|
|
26
|
+
* no client-side page swap (see `docs/guides/ui-kit-architecture.md`, Navigation).
|
|
27
|
+
*
|
|
28
|
+
* The first `Navigate` of a page wins: once the document is leaving, later
|
|
29
|
+
* ones are dropped (a sign-out navigates home, then the refetch its
|
|
30
|
+
* invalidation started fails `Unauthorized` and the auth guard would send
|
|
31
|
+
* the visitor to sign-in instead). Same URL: no-op. No-op on the server.
|
|
32
|
+
*/
|
|
33
|
+
export declare function navigateTo(cmd: {
|
|
34
|
+
readonly href: string;
|
|
35
|
+
readonly replace?: boolean;
|
|
36
|
+
}): void;
|
|
37
|
+
/**
|
|
38
|
+
* Calls `onChange(url)` (path + query) on Back / Forward and after every
|
|
39
|
+
* `Navigate` Command. Kit-internal: used by `createModel({ urlChanged })`
|
|
40
|
+
* after hydration settles.
|
|
41
|
+
*
|
|
42
|
+
* @returns Unsubscribe function.
|
|
43
|
+
*/
|
|
44
|
+
export declare function subscribeUrlChanges(onChange: (url: string) => void): () => void;
|