@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,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App-facing kit surface. Deliberately NOT re-exported: `Show` and
|
|
3
|
+
* `Errored` (branching is `<Match>` only; page errors go through
|
|
4
|
+
* `<PageBoundary>`), raw signals/stores/effects. `For` must be keyed by a
|
|
5
|
+
* stable id (`keyed={(row) => row.id}`), enforced by
|
|
6
|
+
* the lint plugin (`ui-kit/no-logic-in-jsx`, `ui-kit/no-destructure-props`).
|
|
7
|
+
*/
|
|
8
|
+
export { For, type Element as View } from 'solid-js';
|
|
9
|
+
export { PageBoundary } from './boundary.tsx';
|
|
10
|
+
export { matchTag, ok, err, isOk, isErr, type Tagged, type TagHandlers, type Ok, type Err, type Result as ResultValue, } from '../logic/result.ts';
|
|
11
|
+
export { Result, type ResultViewProps } from './result-view.tsx';
|
|
12
|
+
export { createQueryRegistry, type AnyQueryFn, type AnyQueryRegistry, type QueryDef, type QueryRegistry, type RegistryIdOf, type RegistryInputOf, } from '../logic/query-def.ts';
|
|
13
|
+
export { createMutationRegistry, type MutationDef, type MutationRegistry, type MutationSpec, } from '../logic/mutation-def.ts';
|
|
14
|
+
export { refetch, navigate, readStorage, writeStorage, scrollToTop, KIT_COMMAND_TAGS, type KitCommand, type NavigateCommand, type RefetchCommand, type ScrollToTopCommand, type StorageReadCommand, type StorageWriteCommand, } from '../logic/kit-commands.ts';
|
|
15
|
+
export { every, channel, presence, roomSaved, type RoomDocSaved, type RoomEvent, type RoomPresence, type RoomSubscription, type ChannelStatus, type ChannelSubscription, type EverySubscription, type Subscription, type SubscriptionKeySource, } from '../logic/subscriptions.ts';
|
|
16
|
+
export { createSubscriptionRunner, jitteredDelay, RECONNECT_MAX_MS, RECONNECT_MIN_MS, STABLE_OPEN_MS, type SocketLike, type SubscriptionRunner, type SubscriptionRunnerDeps, } from '../runtime/subscription-runner.ts';
|
|
17
|
+
export { inputKeyOf, queryIdOf } from '../logic/query-key.ts';
|
|
18
|
+
export { Query, createServerValue, type QueryProps, QueryErrorNotice, UNEXPECTED_QUERY_MESSAGE, type QueryMeta, type QueryFailure, type QueryError, type QueryErrorCases, type UnexpectedQueryError, } from './query.tsx';
|
|
19
|
+
export { Match, type MatchCases, type MatchProps } from './match.ts';
|
|
20
|
+
export { Form, FormField, FormSubmit, type FormProps } from './form.tsx';
|
|
21
|
+
export { fieldErrorOf, formFieldsOf, formIdle, FORM_UNEXPECTED_MESSAGE, formMessageOf, formStatusOf, formSubmitting, isFormPending, type FieldError, type FormFailure, type FormFields, type FormFlash, type FormStatus, } from '../logic/form-state.ts';
|
|
22
|
+
export { AppScope, type AgentSurfaceFlag, type SiteSettings, } from './app-scope.ts';
|
|
23
|
+
export { Head } from './head-view.ts';
|
|
24
|
+
export { AgentActions, type PageAgentRegistry } from './agent-actions-view.ts';
|
|
25
|
+
export { absoluteUrl, headTagsFor, pageTitle, type HeadAlternate, type HeadSpec, type JsonLd, type RobotsDirective, type RouteHead, type SiteHead, } from '../logic/head.ts';
|
|
26
|
+
export { agentActions, agentField, type AgentActions as AgentActionMap, type AgentEffect, } from '../logic/agent-actions.ts';
|
|
27
|
+
export { listen, messageForOutcome, type ListenSpec, type Listens, type QueryListener, } from '../logic/listen.ts';
|
|
28
|
+
export { createKitScope, createQueryCache, createQueryOutcomeChannel, createQueryInvalidations, type KitScope, type QueryInvalidations, type QueryCache, type QueryCacheLease, type QueryOutcome, type QueryOutcomeChannel, type QueryOutcomeEvent, type QueryOutcomeListener, } from '../runtime/query-scope.ts';
|
|
29
|
+
export { createModel, type CommandContext, type CommandHandlers, type InitResult, type TraceEntry, } from './model.ts';
|
|
30
|
+
export { Island, IslandScripts, type IslandComponentProps, type IslandProps, type IslandWake, type NestedIslandProps, type PageIslandProps, } from './island.tsx';
|
|
31
|
+
export { PageNavigation } from './navigation-head.tsx';
|
|
32
|
+
export { defineIslands, type IslandDef, type IslandModule, type IslandSpec, type IslandTable, type Json, type LazyIslandWake, type PageIslandWake, } from '../logic/island-def.ts';
|
|
33
|
+
export { pageModelIn, usePageModel } from './page-model.ts';
|
|
34
|
+
export { caughtUpWith, rebaseDraft, type Rebased, type SaveConflictError, } from '../logic/draft-rebase.ts';
|
|
35
|
+
export { definePageModel, type PageModelDef, type PageModelPeers, type PageModelSpec, } from '../logic/page-model-def.ts';
|
|
36
|
+
export { currentUrl, currentPathname } from './router.ts';
|
|
37
|
+
export { normalizePathname, resolveRoute } from '../logic/path.ts';
|
|
38
|
+
export { routePathsOf, routeEntryFor, prerenderedPathsOf, DEFAULT_SSR_MODE, matchRoute, hrefFor, lazyPage, effectiveSpeculation, routePresence, sameRoute, decodeSearch, searchParam, type IntParam, type OneOfParam, type PageModule, type ParamNames, type ParamsOf, type PathRouteOf, type PathTagOf, type NavigationMode, type NavigationSpec, type SectionOf, routeSection, type RenderMode, type RouteAuth, type RouteEntry, type Speculation, type RouteMatch, type RouteOf, type RoutePathSpec, type RoutePaths, type RouteTable, type SsrMode, type SearchOf, type SearchParamSpec, type SearchParamValue, type SearchSpec, type TextParam, } from '../logic/route-table.ts';
|
|
39
|
+
export { createRoutePages, type PageProps } from './route-pages.ts';
|
|
40
|
+
export { afterSignIn, initRouter, routerListens, routerUrlChanged, signInRouteFor, updateRouter, Who, type RouterAuth, type RouterModel, type RouterMsg, } from '../logic/route-model.ts';
|
|
41
|
+
export type { CollabStatus, CollabStatusChanged, } from '../live/collab-status.ts';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App-facing kit surface. Deliberately NOT re-exported: `Show` and
|
|
3
|
+
* `Errored` (branching is `<Match>` only; page errors go through
|
|
4
|
+
* `<PageBoundary>`), raw signals/stores/effects. `For` must be keyed by a
|
|
5
|
+
* stable id (`keyed={(row) => row.id}`), enforced by
|
|
6
|
+
* the lint plugin (`ui-kit/no-logic-in-jsx`, `ui-kit/no-destructure-props`).
|
|
7
|
+
*/
|
|
8
|
+
export { For } from 'solid-js';
|
|
9
|
+
export { PageBoundary } from './boundary.jsx';
|
|
10
|
+
export { matchTag, ok, err, isOk, isErr, } from '../logic/result.js';
|
|
11
|
+
export { Result } from './result-view.jsx';
|
|
12
|
+
export { createQueryRegistry, } from '../logic/query-def.js';
|
|
13
|
+
export { createMutationRegistry, } from '../logic/mutation-def.js';
|
|
14
|
+
export { refetch, navigate, readStorage, writeStorage, scrollToTop, KIT_COMMAND_TAGS, } from '../logic/kit-commands.js';
|
|
15
|
+
export { every, channel, presence, roomSaved, } from '../logic/subscriptions.js';
|
|
16
|
+
export { createSubscriptionRunner, jitteredDelay, RECONNECT_MAX_MS, RECONNECT_MIN_MS, STABLE_OPEN_MS, } from '../runtime/subscription-runner.js';
|
|
17
|
+
export { inputKeyOf, queryIdOf } from '../logic/query-key.js';
|
|
18
|
+
export { Query, createServerValue, QueryErrorNotice, UNEXPECTED_QUERY_MESSAGE, } from './query.jsx';
|
|
19
|
+
export { Match } from './match.js';
|
|
20
|
+
export { Form, FormField, FormSubmit } from './form.jsx';
|
|
21
|
+
export { fieldErrorOf, formFieldsOf, formIdle, FORM_UNEXPECTED_MESSAGE, formMessageOf, formStatusOf, formSubmitting, isFormPending, } from '../logic/form-state.js';
|
|
22
|
+
export { AppScope, } from './app-scope.js';
|
|
23
|
+
export { Head } from './head-view.js';
|
|
24
|
+
export { AgentActions } from './agent-actions-view.js';
|
|
25
|
+
export { absoluteUrl, headTagsFor, pageTitle, } from '../logic/head.js';
|
|
26
|
+
export { agentActions, agentField, } from '../logic/agent-actions.js';
|
|
27
|
+
export { listen, messageForOutcome, } from '../logic/listen.js';
|
|
28
|
+
export { createKitScope, createQueryCache, createQueryOutcomeChannel, createQueryInvalidations, } from '../runtime/query-scope.js';
|
|
29
|
+
export { createModel, } from './model.js';
|
|
30
|
+
export { Island, IslandScripts, } from './island.jsx';
|
|
31
|
+
export { PageNavigation } from './navigation-head.jsx';
|
|
32
|
+
export { defineIslands, } from '../logic/island-def.js';
|
|
33
|
+
export { pageModelIn, usePageModel } from './page-model.js';
|
|
34
|
+
export { caughtUpWith, rebaseDraft, } from '../logic/draft-rebase.js';
|
|
35
|
+
export { definePageModel, } from '../logic/page-model-def.js';
|
|
36
|
+
export { currentUrl, currentPathname } from './router.js';
|
|
37
|
+
export { normalizePathname, resolveRoute } from '../logic/path.js';
|
|
38
|
+
export { routePathsOf, routeEntryFor, prerenderedPathsOf, DEFAULT_SSR_MODE, matchRoute, hrefFor, lazyPage, effectiveSpeculation, routePresence, sameRoute, decodeSearch, searchParam, routeSection, } from '../logic/route-table.js';
|
|
39
|
+
export { createRoutePages } from './route-pages.js';
|
|
40
|
+
export { afterSignIn, initRouter, routerListens, routerUrlChanged, signInRouteFor, updateRouter, Who, } from '../logic/route-model.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Component, type Element as SolidElement } from 'solid-js';
|
|
2
|
+
import { type SiteSettings } from './app-scope.ts';
|
|
3
|
+
import type { IslandModule } from '../logic/island-def.ts';
|
|
4
|
+
import type { KitScope } from '../runtime/query-scope.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Kit-internal: what an island root renders, the same on both sides so the
|
|
7
|
+
* hydration ids match. The server renders it inside `<Hydration id>`; the
|
|
8
|
+
* browser hydrates it with `hydrate(() => <IslandBody/>, el, { renderId: id })`
|
|
9
|
+
* (`startIslands`).
|
|
10
|
+
*
|
|
11
|
+
* `component` is a Solid `lazy` of the island module on both sides (one
|
|
12
|
+
* owner each side): on the server it registers the chunk for the page
|
|
13
|
+
* (modulepreload); in the browser the client entry has already resolved it
|
|
14
|
+
* (`preload()`), so it renders synchronously during the hydration pass.
|
|
15
|
+
*
|
|
16
|
+
* `onSettled` runs on both sides (it allocates an id); in the browser it
|
|
17
|
+
* reports that this root has hydrated (`onHydrated`), which is how the
|
|
18
|
+
* client entry knows when every island is live and page models may start.
|
|
19
|
+
*/
|
|
20
|
+
export declare function IslandBody(props: {
|
|
21
|
+
readonly scope: KitScope;
|
|
22
|
+
readonly site: SiteSettings | null;
|
|
23
|
+
readonly component: Component<object>;
|
|
24
|
+
readonly props: unknown;
|
|
25
|
+
readonly onHydrated?: () => void;
|
|
26
|
+
}): SolidElement;
|
|
27
|
+
/** Kit-internal: the island module as a Solid `lazy` component (see `IslandBody`). */
|
|
28
|
+
export declare function lazyIsland(load: () => Promise<IslandModule<unknown>>): Component<object> & {
|
|
29
|
+
readonly preload: () => Promise<unknown>;
|
|
30
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isServer } from '@solidjs/web';
|
|
2
|
+
import { createComponent, lazy, onSettled, } from 'solid-js';
|
|
3
|
+
import { ScopeProviders } from './app-scope.js';
|
|
4
|
+
/**
|
|
5
|
+
* Kit-internal: what an island root renders, the same on both sides so the
|
|
6
|
+
* hydration ids match. The server renders it inside `<Hydration id>`; the
|
|
7
|
+
* browser hydrates it with `hydrate(() => <IslandBody/>, el, { renderId: id })`
|
|
8
|
+
* (`startIslands`).
|
|
9
|
+
*
|
|
10
|
+
* `component` is a Solid `lazy` of the island module on both sides (one
|
|
11
|
+
* owner each side): on the server it registers the chunk for the page
|
|
12
|
+
* (modulepreload); in the browser the client entry has already resolved it
|
|
13
|
+
* (`preload()`), so it renders synchronously during the hydration pass.
|
|
14
|
+
*
|
|
15
|
+
* `onSettled` runs on both sides (it allocates an id); in the browser it
|
|
16
|
+
* reports that this root has hydrated (`onHydrated`), which is how the
|
|
17
|
+
* client entry knows when every island is live and page models may start.
|
|
18
|
+
*/
|
|
19
|
+
export function IslandBody(props) {
|
|
20
|
+
return createComponent(ScopeProviders, {
|
|
21
|
+
scope: props.scope,
|
|
22
|
+
site: props.site,
|
|
23
|
+
get children() {
|
|
24
|
+
onSettled(() => {
|
|
25
|
+
if (isServer)
|
|
26
|
+
return;
|
|
27
|
+
props.onHydrated?.();
|
|
28
|
+
});
|
|
29
|
+
return createComponent(props.component, props.props);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** Kit-internal: the island module as a Solid `lazy` component (see `IslandBody`). */
|
|
34
|
+
export function lazyIsland(load) {
|
|
35
|
+
return lazy(load);
|
|
36
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/** @jsxImportSource @solidjs/web */
|
|
2
|
+
import { type Component, type Element as SolidElement } from 'solid-js';
|
|
3
|
+
import { type IslandDef, type Json, type LazyIslandWake } from '../logic/island-def.ts';
|
|
4
|
+
export type { Json } from '../logic/island-def.ts';
|
|
5
|
+
/** When a nested client-only island (`<Island load>` inside a hydrated island) renders. */
|
|
6
|
+
export type IslandWake = 'visible' | 'interaction' | 'idle' | 'load';
|
|
7
|
+
/** Props the nested island component receives: its JSON props plus `send` to the host. */
|
|
8
|
+
export type IslandComponentProps<P, Msg> = P & {
|
|
9
|
+
/** Sends a JSON Message to the host island's model (a no-op without a host `send`). */
|
|
10
|
+
readonly send: (msg: Msg) => void;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A client-only widget inside a hydrated island (the host island's model
|
|
14
|
+
* gets its Messages through `send`). Rendered fresh on the client when its
|
|
15
|
+
* wake trigger fires, over the server's `fallback`; never hydrated.
|
|
16
|
+
*/
|
|
17
|
+
export interface NestedIslandProps<P extends object, Msg = never> {
|
|
18
|
+
readonly wake: IslandWake;
|
|
19
|
+
readonly load: () => Promise<{
|
|
20
|
+
readonly default: Component<IslandComponentProps<P, Msg>>;
|
|
21
|
+
}>;
|
|
22
|
+
/** JSON-only props (reactive: the island sees new values in place). No functions. */
|
|
23
|
+
readonly props: Json<P>;
|
|
24
|
+
/**
|
|
25
|
+
* The host model's `send`. The island talks back only with Messages: the
|
|
26
|
+
* kit gives the island component a `send` that forwards to this one.
|
|
27
|
+
*/
|
|
28
|
+
readonly send?: (msg: Msg) => void;
|
|
29
|
+
readonly fallback: SolidElement;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A page-level island: an entry of the app's island table
|
|
33
|
+
* (`defineIslands`), rendered in a page's static HTML.
|
|
34
|
+
* - `wake: "load"` entries: no `fallback` (the server renders the island
|
|
35
|
+
* itself, and the browser hydrates it at load).
|
|
36
|
+
* - lazy entries: a required `fallback` (real, semantic server HTML the
|
|
37
|
+
* island replaces when it wakes).
|
|
38
|
+
*/
|
|
39
|
+
export type PageIslandProps<P, W> = {
|
|
40
|
+
readonly of: IslandDef<P, W & ('load' | LazyIslandWake)>;
|
|
41
|
+
/** JSON-only props, serialized into the root element (`data-kit-props`). */
|
|
42
|
+
readonly props: Json<P>;
|
|
43
|
+
/**
|
|
44
|
+
* Keep this island alive across client navigation within its section
|
|
45
|
+
* (`navigation: { client: "<section>" }` routes): when the next page renders the same island with the
|
|
46
|
+
* same props, the live element (DOM, root, model, sockets) moves into
|
|
47
|
+
* the next page instead of the new server HTML being hydrated. Astro's
|
|
48
|
+
* `transition:persist`, keyed by island name + props. No effect on full
|
|
49
|
+
* page loads.
|
|
50
|
+
*/
|
|
51
|
+
readonly persist?: boolean;
|
|
52
|
+
} & ([W] extends ['load'] ? {
|
|
53
|
+
readonly fallback?: never;
|
|
54
|
+
} : {
|
|
55
|
+
readonly fallback: SolidElement;
|
|
56
|
+
});
|
|
57
|
+
/** Back-compat name for the nested island's props. */
|
|
58
|
+
export type IslandProps<P extends object, Msg = never> = NestedIslandProps<P, Msg>;
|
|
59
|
+
/**
|
|
60
|
+
* An island: the only part of a page that ships JS.
|
|
61
|
+
*
|
|
62
|
+
* **Page level** (`of`): an entry of the app's island table, in a page's
|
|
63
|
+
* static HTML (everything under `<AppScope>` is static server HTML).
|
|
64
|
+
* - `wake: "load"` entries hydrate at page load, all in one pass. The
|
|
65
|
+
* server renders the island component itself, so its HTML is complete
|
|
66
|
+
* with JS off.
|
|
67
|
+
* - lazy entries (`visible` / `interaction` / `idle`) take a `fallback`
|
|
68
|
+
* (real HTML); the browser renders the island over it when it wakes
|
|
69
|
+
* (client-only render; the click that woke it is replayed on the island's
|
|
70
|
+
* control with the same label).
|
|
71
|
+
* - Props are JSON (`Json<P>`), serialized into the root element. Islands
|
|
72
|
+
* share state through page models (`usePageModel`), not props.
|
|
73
|
+
*
|
|
74
|
+
* **Nested** (`load`, inside a hydrated island only): a client-only widget
|
|
75
|
+
* such as an editor, talking to the host island's model through `send`.
|
|
76
|
+
* The server renders its `fallback`.
|
|
77
|
+
*
|
|
78
|
+
* Late hydration of server HTML (solidjs/solid#3845) has no spelling here:
|
|
79
|
+
* hydrated islands always hydrate in the first pass, and every lazy one is a
|
|
80
|
+
* client-only render.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* <Island of={islands.planner} props={{ planId: "voltar-main" }} />
|
|
85
|
+
* <Island of={islands.dpsChart} props={{ rows }} fallback={<DpsTable rows={rows} />} />
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare const Island: {
|
|
89
|
+
<P, W>(props: PageIslandProps<P, W>): SolidElement;
|
|
90
|
+
<P extends object, Msg = never>(props: NestedIslandProps<P, Msg>): SolidElement;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The document's island scripts: Solid's hydration bootstrap and the
|
|
94
|
+
* island client entry (`src/entry-client.tsx`). Put it in the document
|
|
95
|
+
* `<head>`. The kit's page renderer (`createPageRenderer`) removes both
|
|
96
|
+
* from a whole (non-streamed) page that rendered no island, so such a page
|
|
97
|
+
* ships no JS.
|
|
98
|
+
*/
|
|
99
|
+
export declare function IslandScripts(props: {
|
|
100
|
+
/** The client entry's source path; the Solid plugin swaps in the built URL. */
|
|
101
|
+
readonly entry: string;
|
|
102
|
+
}): SolidElement;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/** @jsxImportSource @solidjs/web */
|
|
2
|
+
import { getRequestEvent, HydrationScript, isServer } from '@solidjs/web';
|
|
3
|
+
import { createComponent, createSignal, flush, Hydration, isHydratable, onSettled, Show, } from 'solid-js';
|
|
4
|
+
import { useKitScope, useSite } from './app-scope.js';
|
|
5
|
+
import { IslandBody, lazyIsland } from './island-root.js';
|
|
6
|
+
import { ISLAND_CLASS, } from '../logic/island-def.js';
|
|
7
|
+
import { onWake, recordInteractions, replayInto, } from '../runtime/island-wake.js';
|
|
8
|
+
/**
|
|
9
|
+
* Nested client-only island (inside a hydrated island).
|
|
10
|
+
*
|
|
11
|
+
* - On SSR and initial hydration: renders semantic HTML `fallback` with
|
|
12
|
+
* `data-island-state="fallback"` (zero island JS loaded).
|
|
13
|
+
* - On the client, after hydration settles (`onSettled`): attaches the chosen
|
|
14
|
+
* wake trigger (`visible` | `interaction` | `idle` | `load`), dynamically
|
|
15
|
+
* imports the lazy chunk via `load()`, and swaps in the interactive client
|
|
16
|
+
* component with `data-island-state="active"`.
|
|
17
|
+
* - Talking back: an island never takes function props. Its props are JSON;
|
|
18
|
+
* the host passes its model's `send`, and the island component receives
|
|
19
|
+
* a `send` prop that forwards JSON Messages to it (typed by the host's
|
|
20
|
+
* Message union). Like an Astro island with a typed event channel.
|
|
21
|
+
* - The interaction that wakes it is not lost: the last click or focus on an
|
|
22
|
+
* interactive fallback element before the island mounts is replayed on the
|
|
23
|
+
* island element with the same tag and label (see `replayInto`). A
|
|
24
|
+
* fallback that wants its first click to act renders the same controls
|
|
25
|
+
* (same labels) as the island.
|
|
26
|
+
* - If the chunk fails to load (offline, a deploy replaced the chunk), the
|
|
27
|
+
* error is logged, the semantic fallback stays, and the host gets
|
|
28
|
+
* `data-island-state="failed"`.
|
|
29
|
+
*/
|
|
30
|
+
function NestedIsland(props) {
|
|
31
|
+
if (isServer && !isHydratable()) {
|
|
32
|
+
throw new Error('<Island load> is a client-only widget inside a hydrated island. On a static page, add the island to the island table (defineIslands) and render <Island of={islands.name}>.');
|
|
33
|
+
}
|
|
34
|
+
const [loaded, setLoaded] = createSignal(null);
|
|
35
|
+
const sendToHost = (msg) => {
|
|
36
|
+
props.send?.(msg);
|
|
37
|
+
};
|
|
38
|
+
const [failed, setFailed] = createSignal(false);
|
|
39
|
+
let hostEl;
|
|
40
|
+
onSettled(() => {
|
|
41
|
+
const el = hostEl;
|
|
42
|
+
if (!el || typeof window === 'undefined')
|
|
43
|
+
return;
|
|
44
|
+
let disposed = false;
|
|
45
|
+
const recorder = recordInteractions(el);
|
|
46
|
+
const cancelWake = onWake(el, props.wake, () => {
|
|
47
|
+
props.load().then((mod) => {
|
|
48
|
+
if (disposed)
|
|
49
|
+
return;
|
|
50
|
+
recorder.stop();
|
|
51
|
+
setLoaded(() => mod.default);
|
|
52
|
+
flush();
|
|
53
|
+
replayInto(el, recorder.last());
|
|
54
|
+
}, (error) => {
|
|
55
|
+
console.error('[Island] Failed to load the island chunk; keeping its fallback:', error);
|
|
56
|
+
recorder.stop();
|
|
57
|
+
if (!disposed)
|
|
58
|
+
setFailed(true);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return () => {
|
|
62
|
+
disposed = true;
|
|
63
|
+
recorder.stop();
|
|
64
|
+
cancelWake();
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
return (<div data-island="" data-island-wake={props.wake} data-island-state={loaded() ? 'active' : failed() ? 'failed' : 'fallback'} ref={(el) => {
|
|
68
|
+
hostEl = el;
|
|
69
|
+
}}>
|
|
70
|
+
<Show when={loaded()} keyed fallback={props.fallback}>
|
|
71
|
+
{(Comp) => <Comp {...props.props} send={sendToHost}/>}
|
|
72
|
+
</Show>
|
|
73
|
+
</div>);
|
|
74
|
+
}
|
|
75
|
+
/** Plain JSON copy (what the browser will parse back from `data-kit-props`). */
|
|
76
|
+
function jsonCopy(value) {
|
|
77
|
+
const text = JSON.stringify(value ?? {});
|
|
78
|
+
return { text, value: JSON.parse(text) };
|
|
79
|
+
}
|
|
80
|
+
function PageIsland(props) {
|
|
81
|
+
if (!isServer || isHydratable()) {
|
|
82
|
+
throw new Error(`<Island of={islands.${props.of.name}}> belongs in a page's static HTML, not inside another island. Inside an island, use a component, or <Island load> for a client-only widget.`);
|
|
83
|
+
}
|
|
84
|
+
const scope = useKitScope();
|
|
85
|
+
if (!scope)
|
|
86
|
+
throw new Error('<Island of> needs <AppScope> (the page root).');
|
|
87
|
+
const site = useSite();
|
|
88
|
+
const def = props.of;
|
|
89
|
+
const json = jsonCopy(props.props);
|
|
90
|
+
const persistKey = props.persist === true ? `${def.name}:${json.text}` : undefined;
|
|
91
|
+
if (def.wake !== 'load') {
|
|
92
|
+
// Client-only: the fallback is the server HTML; the client entry
|
|
93
|
+
// renders the island over it when `wake` fires.
|
|
94
|
+
return (<div data-kit-island={def.name} data-kit-wake={def.wake} data-kit-props={json.text} data-island-state="fallback" data-kit-persist={persistKey}>
|
|
95
|
+
{props.fallback}
|
|
96
|
+
</div>);
|
|
97
|
+
}
|
|
98
|
+
const id = `i${scope.islands.count++}_`;
|
|
99
|
+
return (<div class={ISLAND_CLASS} data-kit-island={def.name} data-kit-island-id={id} data-kit-props={json.text} data-kit-persist={persistKey}>
|
|
100
|
+
<Hydration id={id}>
|
|
101
|
+
{createComponent(IslandBody, {
|
|
102
|
+
scope,
|
|
103
|
+
site,
|
|
104
|
+
component: lazyIsland(def.load),
|
|
105
|
+
props: json.value,
|
|
106
|
+
})}
|
|
107
|
+
</Hydration>
|
|
108
|
+
</div>);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* An island: the only part of a page that ships JS.
|
|
112
|
+
*
|
|
113
|
+
* **Page level** (`of`): an entry of the app's island table, in a page's
|
|
114
|
+
* static HTML (everything under `<AppScope>` is static server HTML).
|
|
115
|
+
* - `wake: "load"` entries hydrate at page load, all in one pass. The
|
|
116
|
+
* server renders the island component itself, so its HTML is complete
|
|
117
|
+
* with JS off.
|
|
118
|
+
* - lazy entries (`visible` / `interaction` / `idle`) take a `fallback`
|
|
119
|
+
* (real HTML); the browser renders the island over it when it wakes
|
|
120
|
+
* (client-only render; the click that woke it is replayed on the island's
|
|
121
|
+
* control with the same label).
|
|
122
|
+
* - Props are JSON (`Json<P>`), serialized into the root element. Islands
|
|
123
|
+
* share state through page models (`usePageModel`), not props.
|
|
124
|
+
*
|
|
125
|
+
* **Nested** (`load`, inside a hydrated island only): a client-only widget
|
|
126
|
+
* such as an editor, talking to the host island's model through `send`.
|
|
127
|
+
* The server renders its `fallback`.
|
|
128
|
+
*
|
|
129
|
+
* Late hydration of server HTML (solidjs/solid#3845) has no spelling here:
|
|
130
|
+
* hydrated islands always hydrate in the first pass, and every lazy one is a
|
|
131
|
+
* client-only render.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```tsx
|
|
135
|
+
* <Island of={islands.planner} props={{ planId: "voltar-main" }} />
|
|
136
|
+
* <Island of={islands.dpsChart} props={{ rows }} fallback={<DpsTable rows={rows} />} />
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export const Island = (props) => 'of' in props
|
|
140
|
+
? createComponent(PageIsland, props)
|
|
141
|
+
: createComponent(NestedIsland, props);
|
|
142
|
+
/**
|
|
143
|
+
* The document's island scripts: Solid's hydration bootstrap and the
|
|
144
|
+
* island client entry (`src/entry-client.tsx`). Put it in the document
|
|
145
|
+
* `<head>`. The kit's page renderer (`createPageRenderer`) removes both
|
|
146
|
+
* from a whole (non-streamed) page that rendered no island, so such a page
|
|
147
|
+
* ships no JS.
|
|
148
|
+
*/
|
|
149
|
+
export function IslandScripts(props) {
|
|
150
|
+
return (<>
|
|
151
|
+
<HydrationScript />
|
|
152
|
+
<script type="module" src={props.entry} async nonce={getRequestEvent()?.nonce}/>
|
|
153
|
+
</>);
|
|
154
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Element as SolidElement } from 'solid-js';
|
|
2
|
+
import type { Tagged } from '../logic/result.ts';
|
|
3
|
+
/**
|
|
4
|
+
* One render function per `_tag` of `T`. Exhaustive: a missing tag is a
|
|
5
|
+
* TypeScript error, and each handler's parameter is narrowed to its variant.
|
|
6
|
+
*/
|
|
7
|
+
export type MatchCases<T extends Tagged> = {
|
|
8
|
+
readonly [K in T['_tag']]: (value: Extract<T, {
|
|
9
|
+
readonly _tag: K;
|
|
10
|
+
}>) => SolidElement;
|
|
11
|
+
};
|
|
12
|
+
export interface MatchProps<T extends Tagged> {
|
|
13
|
+
/** The tagged value to switch on (a model field, store node, error, ...). */
|
|
14
|
+
readonly on: T;
|
|
15
|
+
/** Exhaustive case object: `{ Tag: (v) => <View v={v} />, ... }`. */
|
|
16
|
+
readonly children: MatchCases<T>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Exhaustive, fine-grained `_tag` switch for views.
|
|
20
|
+
*
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <Match on={plan().availability}>{{
|
|
23
|
+
* Available: () => <PlannerEditor ... />,
|
|
24
|
+
* Blocked: (b) => <BlockedPanel blocked={b} />,
|
|
25
|
+
* }}</Match>
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Performance contract (built on `createMemo` + keyed `<Show>`):
|
|
29
|
+
* - a case function runs only when `on._tag` changes (the tag is a memo, so
|
|
30
|
+
* equal tags never re-trigger);
|
|
31
|
+
* - when other fields change within the same tag, the case is NOT re-run and
|
|
32
|
+
* its DOM is kept: the handler receives a live view whose property reads
|
|
33
|
+
* are reactive, so only the bindings that read the changed fields update.
|
|
34
|
+
* Destructuring the parameter (`({ detail }) => ...`, or `const { detail }
|
|
35
|
+
* = v` in a case body) reads once and loses those updates; pass the value
|
|
36
|
+
* through and read `v.detail`. App code is held to this by the
|
|
37
|
+
* no-destructure rule in the lint plugin (`ui-kit/no-logic-in-jsx`, `ui-kit/no-destructure-props`).
|
|
38
|
+
*
|
|
39
|
+
* Works identically on the server (SSR renders the matching case once).
|
|
40
|
+
*/
|
|
41
|
+
export declare function Match<T extends Tagged>(props: MatchProps<T>): SolidElement;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createComponent, createMemo, Show, untrack, } from 'solid-js';
|
|
2
|
+
/**
|
|
3
|
+
* Builds a live, read-only view of `current()` narrowed to `tag`: every
|
|
4
|
+
* property read goes through `current()`, so bindings inside the rendered
|
|
5
|
+
* case update fine-grained when fields change, without re-running the case.
|
|
6
|
+
*
|
|
7
|
+
* While the value has `tag`, each read also records the property's value in
|
|
8
|
+
* a per-key cache (top-level keys, seeded at creation). After the value moves
|
|
9
|
+
* to another tag (the old case is being torn down, or a handler / async
|
|
10
|
+
* callback of the old case runs late) reads answer from that cache, so stale
|
|
11
|
+
* readers never observe another variant's shape. This matters for store
|
|
12
|
+
* sources: `reconcile` updates a tagged object in place, so the "previous"
|
|
13
|
+
* object is the same proxy and now carries the new variant's fields.
|
|
14
|
+
* Nested objects are not snapshotted: a nested store node stays live.
|
|
15
|
+
*/
|
|
16
|
+
function createTagView(current, tag) {
|
|
17
|
+
const cache = new Map();
|
|
18
|
+
let keys = [];
|
|
19
|
+
const remember = (value) => {
|
|
20
|
+
keys = Reflect.ownKeys(value);
|
|
21
|
+
for (const key of keys)
|
|
22
|
+
cache.set(key, Reflect.get(value, key));
|
|
23
|
+
};
|
|
24
|
+
untrack(() => remember(current()));
|
|
25
|
+
const live = () => {
|
|
26
|
+
const value = current();
|
|
27
|
+
return value._tag === tag ? value : undefined;
|
|
28
|
+
};
|
|
29
|
+
return new Proxy({}, {
|
|
30
|
+
get: (_target, key) => {
|
|
31
|
+
const value = live();
|
|
32
|
+
if (!value)
|
|
33
|
+
return cache.get(key);
|
|
34
|
+
const result = Reflect.get(value, key);
|
|
35
|
+
cache.set(key, result);
|
|
36
|
+
return result;
|
|
37
|
+
},
|
|
38
|
+
has: (_target, key) => {
|
|
39
|
+
const value = live();
|
|
40
|
+
return value ? key in value : cache.has(key);
|
|
41
|
+
},
|
|
42
|
+
ownKeys: () => {
|
|
43
|
+
const value = live();
|
|
44
|
+
if (value)
|
|
45
|
+
keys = Reflect.ownKeys(value);
|
|
46
|
+
return [...keys];
|
|
47
|
+
},
|
|
48
|
+
getOwnPropertyDescriptor: (_target, key) => {
|
|
49
|
+
const value = live();
|
|
50
|
+
if (value) {
|
|
51
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(value, key);
|
|
52
|
+
if (descriptor)
|
|
53
|
+
cache.set(key, Reflect.get(value, key));
|
|
54
|
+
return descriptor
|
|
55
|
+
? { ...descriptor, configurable: true }
|
|
56
|
+
: undefined;
|
|
57
|
+
}
|
|
58
|
+
return cache.has(key)
|
|
59
|
+
? {
|
|
60
|
+
value: cache.get(key),
|
|
61
|
+
writable: false,
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
}
|
|
65
|
+
: undefined;
|
|
66
|
+
},
|
|
67
|
+
set: () => false,
|
|
68
|
+
deleteProperty: () => false,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Exhaustive, fine-grained `_tag` switch for views.
|
|
73
|
+
*
|
|
74
|
+
* ```tsx
|
|
75
|
+
* <Match on={plan().availability}>{{
|
|
76
|
+
* Available: () => <PlannerEditor ... />,
|
|
77
|
+
* Blocked: (b) => <BlockedPanel blocked={b} />,
|
|
78
|
+
* }}</Match>
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* Performance contract (built on `createMemo` + keyed `<Show>`):
|
|
82
|
+
* - a case function runs only when `on._tag` changes (the tag is a memo, so
|
|
83
|
+
* equal tags never re-trigger);
|
|
84
|
+
* - when other fields change within the same tag, the case is NOT re-run and
|
|
85
|
+
* its DOM is kept: the handler receives a live view whose property reads
|
|
86
|
+
* are reactive, so only the bindings that read the changed fields update.
|
|
87
|
+
* Destructuring the parameter (`({ detail }) => ...`, or `const { detail }
|
|
88
|
+
* = v` in a case body) reads once and loses those updates; pass the value
|
|
89
|
+
* through and read `v.detail`. App code is held to this by the
|
|
90
|
+
* no-destructure rule in the lint plugin (`ui-kit/no-logic-in-jsx`, `ui-kit/no-destructure-props`).
|
|
91
|
+
*
|
|
92
|
+
* Works identically on the server (SSR renders the matching case once).
|
|
93
|
+
*/
|
|
94
|
+
export function Match(props) {
|
|
95
|
+
const current = createMemo(() => props.on);
|
|
96
|
+
const tag = createMemo(() => current()._tag);
|
|
97
|
+
return createComponent(Show, {
|
|
98
|
+
get when() {
|
|
99
|
+
return tag();
|
|
100
|
+
},
|
|
101
|
+
keyed: true,
|
|
102
|
+
children: (activeTag) => untrack(() => {
|
|
103
|
+
const cases = props.children;
|
|
104
|
+
const render = cases[activeTag];
|
|
105
|
+
if (!render) {
|
|
106
|
+
throw new Error(`<Match> has no case for tag "${activeTag}"`);
|
|
107
|
+
}
|
|
108
|
+
return render(createTagView(current, activeTag));
|
|
109
|
+
}),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { type Accessor } from 'solid-js';
|
|
2
|
+
import { type CommandHandlers, type TraceEntry } from './command-runner.ts';
|
|
3
|
+
import { type KitCommand } from '../logic/kit-commands.ts';
|
|
4
|
+
import { type Listens } from '../logic/listen.ts';
|
|
5
|
+
import { type Tagged } from '../logic/result.ts';
|
|
6
|
+
import type { Subscription } from '../logic/subscriptions.ts';
|
|
7
|
+
import type { KitScope } from '../runtime/query-scope.ts';
|
|
8
|
+
export type { CommandContext, CommandHandlers, TraceEntry, } from './command-runner.ts';
|
|
9
|
+
/**
|
|
10
|
+
* When a model's client-only work starts (listens, `urlChanged`,
|
|
11
|
+
* subscriptions, init Commands). `work` may return a cleanup.
|
|
12
|
+
*
|
|
13
|
+
* - Component models (`createModel` in a component): after the owner's
|
|
14
|
+
* hydration settles (`onSettled`). `onSettled` is called on both sides,
|
|
15
|
+
* since it allocates a hydration id; the work itself is client-only.
|
|
16
|
+
* - Page models (`usePageModel`): after every island root on the page has
|
|
17
|
+
* hydrated (`KitScope.page`), never on the server. They live outside
|
|
18
|
+
* every island root, so no owner's `onSettled` can say that.
|
|
19
|
+
*/
|
|
20
|
+
export type ModelStarter = (work: () => (() => void) | void) => void;
|
|
21
|
+
/** Kit-internal: the component starter (see `ModelStarter`). */
|
|
22
|
+
export declare const componentStarter: ModelStarter;
|
|
23
|
+
/**
|
|
24
|
+
* Kit-internal: the page-model starter (see `ModelStarter`). With `life`,
|
|
25
|
+
* the cleanup `work` returns is kept (`life.stops`) so disposing the page
|
|
26
|
+
* model (a client navigation) stops its listens and subscriptions, and
|
|
27
|
+
* work for a model disposed before its page hydrated never starts.
|
|
28
|
+
*/
|
|
29
|
+
export declare function pageStarter(scope: KitScope, life?: {
|
|
30
|
+
readonly stops: Array<() => void>;
|
|
31
|
+
readonly alive: () => boolean;
|
|
32
|
+
}): ModelStarter;
|
|
33
|
+
/** An initial model, optionally with Commands to run at start (Elm `init`). */
|
|
34
|
+
export type { InitResult } from '../logic/command-types.ts';
|
|
35
|
+
import type { InitResult } from '../logic/command-types.ts';
|
|
36
|
+
interface CommonOptions<Model, Msg> {
|
|
37
|
+
/** Query outcomes -> Messages, declared with `listen(...)` in the `.model.ts`. */
|
|
38
|
+
readonly listens?: Listens<Msg> | readonly Listens<Msg>[];
|
|
39
|
+
/**
|
|
40
|
+
* URL changes -> a Message (route models): Back / Forward and every
|
|
41
|
+
* `Navigate` kit Command, with the new path + query. Client only.
|
|
42
|
+
*/
|
|
43
|
+
readonly urlChanged?: (url: string) => Msg;
|
|
44
|
+
/**
|
|
45
|
+
* Timers / channels the model wants right now, as data from its state
|
|
46
|
+
* (`every`, `channel`). Started after hydration (client only), re-diffed
|
|
47
|
+
* after every Message by key, stopped on disposal. Pausing = returning
|
|
48
|
+
* a list without it.
|
|
49
|
+
*/
|
|
50
|
+
readonly subscriptions?: (model: Model) => readonly Subscription<Msg>[];
|
|
51
|
+
}
|
|
52
|
+
/** App Command handlers; optional when every Command is a kit Command (`Refetch`). */
|
|
53
|
+
type CommandsOption<Cmd extends Tagged, Msg> = [
|
|
54
|
+
Exclude<Cmd, KitCommand>
|
|
55
|
+
] extends [never] ? {
|
|
56
|
+
readonly commands?: CommandHandlers<Cmd, Msg>;
|
|
57
|
+
} : {
|
|
58
|
+
readonly commands: CommandHandlers<Cmd, Msg>;
|
|
59
|
+
};
|
|
60
|
+
/** Command-less model (e.g. enums, modals, toggles). */
|
|
61
|
+
export declare function createModel<Model, Msg>(options: CommonOptions<Model, Msg> & {
|
|
62
|
+
/** Initial model, or a thunk read once untracked (seed it from props / a `<Query>` view). */
|
|
63
|
+
readonly init: Model | (() => Model);
|
|
64
|
+
readonly update: (model: Model, msg: Msg) => Model;
|
|
65
|
+
readonly onTrace?: (entry: TraceEntry<Msg, never>) => void;
|
|
66
|
+
}): readonly [state: Accessor<Model>, send: (msg: Msg) => void];
|
|
67
|
+
/** Command-returning model (Elm / Foldkit state machine). */
|
|
68
|
+
export declare function createModel<Model, Msg, Cmd extends Tagged>(options: CommonOptions<Model, Msg> & CommandsOption<Cmd, Msg> & {
|
|
69
|
+
/**
|
|
70
|
+
* Initial model, `[model, commands]`, or a thunk returning either (read
|
|
71
|
+
* once, untracked). Init Commands (Elm / Foldkit `init`) run once in
|
|
72
|
+
* the browser after hydration settles, never on the server: the SSR
|
|
73
|
+
* HTML and the hydration pass always see the plain initial model, and
|
|
74
|
+
* whatever the Commands produce arrives as Messages afterwards.
|
|
75
|
+
*/
|
|
76
|
+
readonly init: InitResult<Model, Cmd> | (() => InitResult<Model, Cmd>);
|
|
77
|
+
readonly update: (model: Model, msg: Msg) => readonly [Model, readonly Cmd[]];
|
|
78
|
+
readonly onTrace?: (entry: TraceEntry<Msg, Cmd>) => void;
|
|
79
|
+
}): readonly [state: Accessor<Model>, send: (msg: Msg) => void];
|
|
80
|
+
/** The untyped options bag every model shape shares (kit-internal). */
|
|
81
|
+
export type AnyModelOptions<Model, Msg, Cmd extends Tagged> = CommonOptions<Model, Msg> & {
|
|
82
|
+
readonly init: InitResult<Model, Cmd> | (() => InitResult<Model, Cmd>);
|
|
83
|
+
readonly update: (model: Model, msg: Msg) => Model | readonly [Model, readonly Cmd[]];
|
|
84
|
+
readonly commands?: CommandHandlers<Cmd, Msg>;
|
|
85
|
+
readonly onTrace?: (entry: any) => void;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Kit-internal: `createModel` with an explicit scope and starter. Page
|
|
89
|
+
* models (`usePageModel`) are created in a detached root (no context), so
|
|
90
|
+
* they pass the page's scope and the page starter.
|
|
91
|
+
*/
|
|
92
|
+
export declare function createModelIn<Model, Msg, Cmd extends Tagged = Tagged>(options: AnyModelOptions<Model, Msg, Cmd>, scope: KitScope | null, start: ModelStarter): readonly [state: Accessor<Model>, send: (msg: Msg) => void];
|