foldkit 0.158.2 → 0.159.0-canary.63fa8e97d24a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/calendar/calendarDate.js +1 -1
- package/dist/command/index.d.ts +10 -8
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +8 -6
- package/dist/customElement/index.d.ts +15 -8
- package/dist/customElement/index.d.ts.map +1 -1
- package/dist/customElement/index.js +28 -5
- package/dist/customElement/public.d.ts +1 -1
- package/dist/customElement/public.d.ts.map +1 -1
- package/dist/dom/dom.d.ts +7 -4
- package/dist/dom/dom.d.ts.map +1 -1
- package/dist/dom/dom.js +8 -5
- package/dist/experimental/server/fetch.d.ts +42 -0
- package/dist/experimental/server/fetch.d.ts.map +1 -0
- package/dist/experimental/server/fetch.js +75 -0
- package/dist/experimental/server/index.d.ts +1 -0
- package/dist/experimental/server/index.d.ts.map +1 -1
- package/dist/experimental/server/index.js +1 -0
- package/dist/experimental/server/public.d.ts +2 -2
- package/dist/experimental/server/public.d.ts.map +1 -1
- package/dist/experimental/server/public.js +1 -1
- package/dist/experimental/server/server.d.ts +3 -2
- package/dist/experimental/server/server.d.ts.map +1 -1
- package/dist/experimental/server/template.js +4 -4
- package/dist/html/index.d.ts +42 -3
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/index.js +147 -10
- package/dist/hydrationMarker.d.ts +2 -2
- package/dist/hydrationMarker.d.ts.map +1 -1
- package/dist/hydrationMarker.js +2 -2
- package/dist/runtime/devToolsConfig.d.ts +3 -3
- package/dist/runtime/devToolsConfig.d.ts.map +1 -1
- package/dist/runtime/devToolsConfig.js +3 -3
- package/dist/runtime/hydrationHandoff.d.ts +5 -4
- package/dist/runtime/hydrationHandoff.d.ts.map +1 -1
- package/dist/runtime/hydrationHandoff.js +14 -13
- package/dist/runtime/{hmrProtocol.d.ts → modelPreservation.d.ts} +3 -3
- package/dist/runtime/modelPreservation.d.ts.map +1 -0
- package/dist/runtime/{hmrProtocol.js → modelPreservation.js} +2 -2
- package/dist/runtime/modelPreservationBridge.d.ts +4 -0
- package/dist/runtime/modelPreservationBridge.d.ts.map +1 -0
- package/dist/runtime/{hmrModelBridge.js → modelPreservationBridge.js} +7 -7
- package/dist/runtime/modelPreservationPublic.d.ts +2 -0
- package/dist/runtime/modelPreservationPublic.d.ts.map +1 -0
- package/dist/runtime/{hmrProtocolPublic.js → modelPreservationPublic.js} +1 -1
- package/dist/runtime/preserveScheduler.d.ts +1 -1
- package/dist/runtime/runtime.d.ts +8 -7
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +16 -16
- package/dist/runtime/{hmrScroll.d.ts → scrollPreservation.d.ts} +1 -1
- package/dist/runtime/scrollPreservation.d.ts.map +1 -0
- package/dist/runtime/{hmrScroll.js → scrollPreservation.js} +3 -3
- package/dist/runtime/slowPhase.d.ts +2 -1
- package/dist/runtime/slowPhase.d.ts.map +1 -1
- package/dist/runtime/start.d.ts +10 -7
- package/dist/runtime/start.d.ts.map +1 -1
- package/dist/runtime/start.js +21 -9
- package/dist/runtime/visibility.d.ts +2 -2
- package/dist/runtime/visibility.d.ts.map +1 -1
- package/dist/runtime/visibility.js +2 -2
- package/dist/schema/index.d.ts +42 -12
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +33 -26
- package/dist/test/apps/contentEditableEditor.d.ts +32 -0
- package/dist/test/apps/contentEditableEditor.d.ts.map +1 -0
- package/dist/test/apps/contentEditableEditor.js +39 -0
- package/dist/test/apps/fileUpload.d.ts.map +1 -1
- package/dist/test/apps/fileUpload.js +2 -1
- package/dist/test/apps/formChild.js +1 -1
- package/dist/test/apps/keypressSelf.d.ts +26 -0
- package/dist/test/apps/keypressSelf.d.ts.map +1 -0
- package/dist/test/apps/keypressSelf.js +30 -0
- package/dist/test/apps/pointer.d.ts.map +1 -1
- package/dist/test/apps/pointer.js +10 -11
- package/dist/test/scene.d.ts +28 -6
- package/dist/test/scene.d.ts.map +1 -1
- package/dist/test/scene.js +38 -13
- package/dist/test/vitest.d.ts +2 -2
- package/dist/test/vitest.d.ts.map +1 -1
- package/dist/test/vitest.js +1 -1
- package/dist/url/index.js +1 -1
- package/dist/vdom.js +5 -5
- package/package.json +9 -9
- package/dist/runtime/hmrModelBridge.d.ts +0 -4
- package/dist/runtime/hmrModelBridge.d.ts.map +0 -1
- package/dist/runtime/hmrProtocol.d.ts.map +0 -1
- package/dist/runtime/hmrProtocolPublic.d.ts +0 -2
- package/dist/runtime/hmrProtocolPublic.d.ts.map +0 -1
- package/dist/runtime/hmrScroll.d.ts.map +0 -1
package/dist/runtime/runtime.js
CHANGED
|
@@ -6,16 +6,16 @@ import { addNavigationEventListeners, } from './browserListeners.js';
|
|
|
6
6
|
import { deepFreeze } from './deepFreeze.js';
|
|
7
7
|
import { makeDevToolsIntegration } from './devToolsIntegration.js';
|
|
8
8
|
import { createDuplicateIdScanner } from './duplicateIdScanner.js';
|
|
9
|
-
import { preserveModel } from './hmrModelBridge.js';
|
|
10
|
-
import { preserveScrollPosition, restorePreservedScrollPosition, } from './hmrScroll.js';
|
|
11
9
|
import { makePortChannels, validatePorts, } from './hostConnector.js';
|
|
12
10
|
import { resolveHydrationHandoff, } from './hydrationHandoff.js';
|
|
13
11
|
import { forkManagedResourceFibers } from './managedResourceFibers.js';
|
|
14
12
|
import { makeMessageQueue } from './messageQueue.js';
|
|
13
|
+
import { preserveModel } from './modelPreservationBridge.js';
|
|
15
14
|
import { makePreserveScheduler } from './preserveScheduler.js';
|
|
16
15
|
import { makeRenderer } from './renderer.js';
|
|
17
16
|
import { makeResourceProvider } from './resourceProvider.js';
|
|
18
17
|
import { makeRuntimeStatus } from './runtimeStatus.js';
|
|
18
|
+
import { preserveScrollPosition, restorePreservedScrollPosition, } from './scrollPreservation.js';
|
|
19
19
|
import { __resolveSlowConfig, measureSlowPhase, reportSlowPhase, } from './slowPhase.js';
|
|
20
20
|
import { forkSubscriptionFibers } from './subscriptionFibers.js';
|
|
21
21
|
import { __resolveStartViewTransition, } from './viewTransition.js';
|
|
@@ -50,7 +50,7 @@ export const makeRuntime = ({ ports, kind, Model, Flags: FlagsCodec, configuredF
|
|
|
50
50
|
const runtimeId = hydration !== undefined && hydration.runtimeId !== ''
|
|
51
51
|
? hydration.runtimeId
|
|
52
52
|
: (container?.id ?? '');
|
|
53
|
-
const startWith = (maybeConnector,
|
|
53
|
+
const startWith = (maybeConnector, preservedModel, bootMode = 'Fresh', bootFlags, buildId) => {
|
|
54
54
|
// NOTE: one notifier per runtime, provided across the whole runtime
|
|
55
55
|
// Effect so Commands, Subscriptions, and Mount-forked Effects all resolve
|
|
56
56
|
// the same signal. A commit in one embedded application must never wake a
|
|
@@ -58,7 +58,7 @@ export const makeRuntime = ({ ports, kind, Model, Flags: FlagsCodec, configuredF
|
|
|
58
58
|
const commitNotifier = createCommitNotifier();
|
|
59
59
|
return Effect.scoped(Effect.gen(function* () {
|
|
60
60
|
if (runtimeId === '') {
|
|
61
|
-
return yield* Effect.die(new Error('[foldkit] Runtime container must have an `id` for
|
|
61
|
+
return yield* Effect.die(new Error('[foldkit] Runtime container must have an `id` for Model preservation across reloads. ' +
|
|
62
62
|
'Set `container.id = "app"` (or any unique string) before passing it to makeApplication or makeElement. ' +
|
|
63
63
|
'On a server-rendered page the id comes from the `data-foldkit-app` root stamp instead.'));
|
|
64
64
|
}
|
|
@@ -89,7 +89,7 @@ export const makeRuntime = ({ ports, kind, Model, Flags: FlagsCodec, configuredF
|
|
|
89
89
|
configuredFlags,
|
|
90
90
|
isFlagsRequired,
|
|
91
91
|
FlagsCodec,
|
|
92
|
-
|
|
92
|
+
preservedModel,
|
|
93
93
|
container,
|
|
94
94
|
buildId,
|
|
95
95
|
provideResources,
|
|
@@ -97,33 +97,33 @@ export const makeRuntime = ({ ports, kind, Model, Flags: FlagsCodec, configuredF
|
|
|
97
97
|
const ModelJsonCodec = Schema.toCodecJson(
|
|
98
98
|
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */
|
|
99
99
|
Model);
|
|
100
|
-
const
|
|
101
|
-
const
|
|
100
|
+
const decodePreservedModel = Schema.decodeUnknownExit(ModelJsonCodec);
|
|
101
|
+
const encodePreservedModel = Schema.encodeUnknownSync(ModelJsonCodec);
|
|
102
102
|
const currentUrl = Option.fromNullishOr(routingConfig).pipe(Option.flatMap(() => urlFromString(window.location.href)));
|
|
103
103
|
// NOTE: a restored Model skips `init`, so resolving Flags on that
|
|
104
104
|
// path would build the `resources` Layer only to discard what it
|
|
105
105
|
// produced. Gating the resolution on the restore decision is what
|
|
106
106
|
// stops a reload from reconnecting whatever the Layer holds. It has
|
|
107
|
-
// to stay ahead of the preserve-scheduler and
|
|
107
|
+
// to stay ahead of the preserve-scheduler and preservation finalizers: a
|
|
108
108
|
// Flags Effect that fails after those are registered tears down more
|
|
109
109
|
// than it used to, and their release defects would bury its cause.
|
|
110
110
|
const runInit = Effect.map(resolveFlags, flags => init(flags, Option.getOrUndefined(currentUrl)));
|
|
111
|
-
const init_ = yield*
|
|
112
|
-
? Exit.match(
|
|
111
|
+
const init_ = yield* preservedModel !== undefined
|
|
112
|
+
? Exit.match(decodePreservedModel(preservedModel), {
|
|
113
113
|
onFailure: () => runInit,
|
|
114
114
|
onSuccess: restoredModel => Effect.succeed({ model: restoredModel }),
|
|
115
115
|
})
|
|
116
116
|
: runInit;
|
|
117
117
|
const initModelRaw = init_.model;
|
|
118
118
|
const initCommands = init_.commands ?? [];
|
|
119
|
-
// NOTE: keep `
|
|
119
|
+
// NOTE: keep `encodePreservedModel` off the dispatch hot path. It walks
|
|
120
120
|
// the entire Model graph (O(modelSize) per call) and blocks input
|
|
121
121
|
// on large Models. The scheduler defers encoding to a quiet window
|
|
122
|
-
// and the `vite:beforeFullReload` flush covers the
|
|
122
|
+
// and the `vite:beforeFullReload` flush covers the reload boundary.
|
|
123
123
|
const PRESERVE_DEBOUNCE = Duration.millis(200);
|
|
124
124
|
const preserveScheduler = yield* makePreserveScheduler({
|
|
125
|
-
onDebounce: model => Effect.sync(() => preserveModel(runtimeId,
|
|
126
|
-
onFlush: model => Effect.sync(() => preserveModel(runtimeId,
|
|
125
|
+
onDebounce: model => Effect.sync(() => preserveModel(runtimeId, encodePreservedModel(model), false)),
|
|
126
|
+
onFlush: model => Effect.sync(() => preserveModel(runtimeId, encodePreservedModel(model), true)),
|
|
127
127
|
}, PRESERVE_DEBOUNCE);
|
|
128
128
|
const hot = import.meta.hot;
|
|
129
129
|
if (hot) {
|
|
@@ -342,14 +342,14 @@ export const makeRuntime = ({ ports, kind, Model, Flags: FlagsCodec, configuredF
|
|
|
342
342
|
yield* Effect.never;
|
|
343
343
|
})).pipe(Effect.provideService(RenderCommit, commitNotifier.service));
|
|
344
344
|
};
|
|
345
|
-
const start = (
|
|
345
|
+
const start = (preservedModel) => startWith(Option.none(), preservedModel, 'Fresh');
|
|
346
346
|
const program = {
|
|
347
347
|
runtimeId,
|
|
348
348
|
start,
|
|
349
349
|
ports,
|
|
350
350
|
};
|
|
351
351
|
runtimeInternals.set(program, {
|
|
352
|
-
startWith: (maybeConnector,
|
|
352
|
+
startWith: (maybeConnector, preservedModel, bootMode, flags, buildId) => startWith(maybeConnector, preservedModel, bootMode, flags, buildId),
|
|
353
353
|
kind,
|
|
354
354
|
isEmbedActive: false,
|
|
355
355
|
maybeActiveFiber: Option.none(),
|
|
@@ -18,4 +18,4 @@ export declare const takePreservedScrollPosition: (runtimeId: string) => Option.
|
|
|
18
18
|
* defeating any CSS `scroll-behavior: smooth`. A no-op when nothing was
|
|
19
19
|
* preserved. Consumes the stored offset, so a second call restores nothing. */
|
|
20
20
|
export declare const restorePreservedScrollPosition: (runtimeId: string) => Effect.Effect<void>;
|
|
21
|
-
//# sourceMappingURL=
|
|
21
|
+
//# sourceMappingURL=scrollPreservation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrollPreservation.d.ts","sourceRoot":"","sources":["../../src/runtime/scrollPreservation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAiB/C;+EAC+E;AAC/E,eAAO,MAAM,yBAAyB,cAAe,MAAM,KAAG,MAC/B,CAAA;AAE/B;;oCAEoC;AACpC,eAAO,MAAM,sBAAsB,cAAe,MAAM,KAAG,IAW1D,CAAA;AAED;;;0BAG0B;AAC1B,eAAO,MAAM,2BAA2B,cAC3B,MAAM,KAChB,MAAM,CAAC,MAAM,CAAC;IAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAS1D,CAAA;AAED;;gFAEgF;AAChF,eAAO,MAAM,8BAA8B,cAC9B,MAAM,KAChB,MAAM,CAAC,MAAM,CAAC,IAAI,CAOjB,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect, Option, Schema } from 'effect';
|
|
2
2
|
/**
|
|
3
|
-
* Window scroll offset persisted across a Vite
|
|
3
|
+
* Window scroll offset persisted across a Vite dev full reload. Held in
|
|
4
4
|
* `sessionStorage` as a JSON string so it survives the reload and can be
|
|
5
5
|
* reapplied synchronously at the next init render, before the browser paints.
|
|
6
6
|
*/
|
|
@@ -9,7 +9,7 @@ const encodePreservedScrollPosition = Schema.encodeUnknownSync(PreservedScrollPo
|
|
|
9
9
|
const decodePreservedScrollPosition = Schema.decodeUnknownOption(PreservedScrollPosition);
|
|
10
10
|
/** The `sessionStorage` key a runtime uses for its preserved scroll offset,
|
|
11
11
|
* scoped by runtime id so multiple runtimes never read each other's value. */
|
|
12
|
-
export const preservedScrollStorageKey = (runtimeId) => `foldkit:
|
|
12
|
+
export const preservedScrollStorageKey = (runtimeId) => `foldkit:scroll:${runtimeId}`;
|
|
13
13
|
/** Captures the current window scroll offset under the runtime's key. Called
|
|
14
14
|
* from the `vite:beforeFullReload` handler so the offset is stored just
|
|
15
15
|
* before Vite reloads the page. */
|
|
@@ -20,7 +20,7 @@ export const preserveScrollPosition = (runtimeId) => {
|
|
|
20
20
|
catch {
|
|
21
21
|
// NOTE: sessionStorage throws when storage is disabled or blocked by a
|
|
22
22
|
// privacy mode. Scroll restoration is a dev-only convenience, so a failure
|
|
23
|
-
// here must never break the
|
|
23
|
+
// here must never break the dev reload this runs inside.
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
/** Reads and clears the preserved scroll offset for a runtime. Returns
|
|
@@ -63,7 +63,8 @@ type ResolvedSlowConfig<Model, Message> = Readonly<{
|
|
|
63
63
|
* thresholds. Pass `false` to disable warnings entirely. Pass an object to
|
|
64
64
|
* refine those defaults.
|
|
65
65
|
*
|
|
66
|
-
* - `show`: `'Development'` (default) enables warnings only
|
|
66
|
+
* - `show`: `'Development'` (default) enables warnings only under Vite's dev
|
|
67
|
+
* server. `'Always'` enables them in every environment.
|
|
67
68
|
* - `measuredPhases`: Phases to measure. Defaults to every slow warning phase.
|
|
68
69
|
* - `thresholdOverrides`: Per-phase budget overrides. Omitted fields keep defaults; overrides for unmeasured phases are ignored.
|
|
69
70
|
* - `onSlow`: Callback for every measured phase that exceeds its budget. Replaces Foldkit's default `console.warn`; Foldkit will not also warn for tags your callback ignores.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slowPhase.d.ts","sourceRoot":"","sources":["../../src/runtime/slowPhase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAqB,MAAM,EAAQ,MAAM,QAAQ,CAAA;AAE9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,kFAAkF;AAClF,MAAM,MAAM,eAAe,CAAC,KAAK,EAAE,OAAO,IAAI,QAAQ,CAAC;IACrD,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,KAAK,CAAA;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC/B,UAAU,EAAE,MAA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,CAAC,EAAE,sBAAsB,CAAA;IAC3C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;CACxD,CAAC,CAAA;AA4BN,eAAO,MAAM,mBAAmB,GAAI,KAAK,EAAE,OAAO,QAC1C,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,SAAS,iBAC7B,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,KAC3C,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,CA8ClD,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,OAAO,EAAE,MAAM,eACjC,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC,OACvD,MAAM,MAAM,KAChB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CASzC,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,OAAO,eACxB,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC,mBAC3C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,eACzB,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,KAChE,IAYF,CAAA;AAsBD,eAAO,MAAM,mBAAmB,YACrB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,KACrC,IAgCF,CAAA"}
|
package/dist/runtime/start.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect } from 'effect';
|
|
1
|
+
import { Cause, Effect } from 'effect';
|
|
2
2
|
import type { Ports } from '../port/index.js';
|
|
3
3
|
import { type EmbedHandle } from './hostConnector.js';
|
|
4
4
|
import type { BootMode } from './hydrationHandoff.js';
|
|
@@ -12,17 +12,20 @@ export type RunOptions<Flags, Resources = never> = Readonly<{
|
|
|
12
12
|
}>;
|
|
13
13
|
type RuntimeProgram = Readonly<{
|
|
14
14
|
runtimeId: string;
|
|
15
|
-
start: (
|
|
15
|
+
start: (preservedModel?: unknown) => Effect.Effect<void>;
|
|
16
16
|
ports: Ports | undefined;
|
|
17
17
|
}>;
|
|
18
18
|
/** Starts a program Effect with explicit boot inputs for runtime tests.
|
|
19
19
|
* @internal */
|
|
20
|
-
export declare const __startProgram: (program: RuntimeProgram,
|
|
20
|
+
export declare const __startProgram: (program: RuntimeProgram, preservedModel: unknown, bootMode: BootMode, flags?: Effect.Effect<unknown, never, any>, buildId?: string) => Effect.Effect<void>;
|
|
21
|
+
/** Reports unhandled non-interrupt Causes using Effect's runtime policy.
|
|
22
|
+
* @internal */
|
|
23
|
+
export declare const __reportUnhandledCause: <E>(cause: Cause.Cause<E>) => Effect.Effect<void>;
|
|
21
24
|
/** Starts a Foldkit runtime that owns the page for the page's whole lifetime,
|
|
22
|
-
* with
|
|
23
|
-
* the container, replacing whatever is there. On a
|
|
24
|
-
* `hydrate` instead, which adopts the existing DOM.
|
|
25
|
-
* host-controlled lifecycle, use `embed`. */
|
|
25
|
+
* with state-preserving live reload for development. The first render builds
|
|
26
|
+
* the DOM fresh in the container, replacing whatever is there. On a
|
|
27
|
+
* server-rendered page use `hydrate` instead, which adopts the existing DOM.
|
|
28
|
+
* To start a runtime under a host-controlled lifecycle, use `embed`. */
|
|
26
29
|
export declare function run<P extends Ports | undefined, Resources, Kind extends 'Application' | 'Element'>(program: MakeRuntimeReturn<P, void, Resources, Kind>): void;
|
|
27
30
|
export declare function run<P extends Ports | undefined, Flags, Resources, Kind extends 'Application' | 'Element'>(program: MakeRuntimeReturn<P, Flags, Resources, Kind>, options: RunOptions<Flags, Resources>): void;
|
|
28
31
|
/** Options for {@link hydrate}. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/runtime/start.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EAOP,MAAM,QAAQ,CAAA;AAEf,OAAO,KAA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AiB,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EACrD,OAAO,EAAE,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,GACpC,WAAW,CAAC,CAAC,CAAC,CAAA"}
|
package/dist/runtime/start.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Effect, Fiber, Function, Option, Predicate, Runtime, pipe, } from 'effect';
|
|
1
|
+
import { Cause, Effect, Fiber, Function, Option, Predicate, Runtime, pipe, } from 'effect';
|
|
2
2
|
import { provideBrowserScheduler } from './browserScheduler.js';
|
|
3
|
-
import { resolveHmrModel } from './hmrModelBridge.js';
|
|
4
3
|
import { buildPortHandles, makeHostConnector, } from './hostConnector.js';
|
|
4
|
+
import { resolvePreservedModel } from './modelPreservationBridge.js';
|
|
5
5
|
import { runtimeInternals } from './runtime.js';
|
|
6
6
|
/** Starts a program Effect with explicit boot inputs for runtime tests.
|
|
7
7
|
* @internal */
|
|
8
|
-
export const __startProgram = (program,
|
|
8
|
+
export const __startProgram = (program, preservedModel, bootMode, flags, buildId) => {
|
|
9
9
|
const internals = runtimeInternals.get(program);
|
|
10
10
|
if (Predicate.isUndefined(internals)) {
|
|
11
11
|
return Effect.die(new Error('[foldkit] Runtime boot expects a program created by ' +
|
|
@@ -15,7 +15,7 @@ export const __startProgram = (program, hmrModel, bootMode, flags, buildId) => {
|
|
|
15
15
|
return Effect.die(new Error('[foldkit] Runtime.hydrate expects a program created by ' +
|
|
16
16
|
'makeApplication.'));
|
|
17
17
|
}
|
|
18
|
-
return internals.startWith(Option.none(),
|
|
18
|
+
return internals.startWith(Option.none(), preservedModel, bootMode, flags, buildId);
|
|
19
19
|
};
|
|
20
20
|
// NOTE: deliberately not `BrowserRuntime.runMain`, which interrupts the
|
|
21
21
|
// runtime on `beforeunload`. `beforeunload` is a question, not a commitment:
|
|
@@ -25,11 +25,23 @@ export const __startProgram = (program, hmrModel, bootMode, flags, buildId) => {
|
|
|
25
25
|
// put the container element back empty, so the page is left alive with no app
|
|
26
26
|
// in it. A page-owning runtime gains nothing from tearing itself down while
|
|
27
27
|
// the document is on its way out, so it starts with no page-lifecycle
|
|
28
|
-
// interrupt at all and lets the document take the runtime with it.
|
|
29
|
-
//
|
|
28
|
+
// interrupt at all and lets the document take the runtime with it. The
|
|
29
|
+
// keep-alive interval still comes from `makeRunMain`; Foldkit owns the shared
|
|
30
|
+
// error-reporting policy used by page-owning and embedded runtimes below.
|
|
30
31
|
const runMainWithoutUnloadInterrupt = Runtime.makeRunMain(Function.constVoid);
|
|
32
|
+
/** Reports unhandled non-interrupt Causes using Effect's runtime policy.
|
|
33
|
+
* @internal */
|
|
34
|
+
export const __reportUnhandledCause = (cause) => {
|
|
35
|
+
if (Cause.hasInterruptsOnly(cause)) {
|
|
36
|
+
return Effect.void;
|
|
37
|
+
}
|
|
38
|
+
return Runtime.getErrorReported(Cause.squash(cause))
|
|
39
|
+
? Effect.logError(cause)
|
|
40
|
+
: Effect.void;
|
|
41
|
+
};
|
|
42
|
+
const withUnhandledCauseReporting = (effect) => Effect.tapCause(effect, __reportUnhandledCause);
|
|
31
43
|
const startProgram = (program, bootMode, flags, buildId) => {
|
|
32
|
-
runMainWithoutUnloadInterrupt(provideBrowserScheduler(Effect.flatMap(
|
|
44
|
+
runMainWithoutUnloadInterrupt(withUnhandledCauseReporting(provideBrowserScheduler(Effect.flatMap(resolvePreservedModel(program.runtimeId), preservedModel => __startProgram(program, preservedModel, bootMode, flags, buildId)))), { disableErrorReporting: true });
|
|
33
45
|
};
|
|
34
46
|
export function run(program, options) {
|
|
35
47
|
startProgram(program, 'Fresh', options?.flags);
|
|
@@ -81,8 +93,8 @@ export function embed(program, options) {
|
|
|
81
93
|
const startEffect = pipe(Option.match(internals.maybeActiveFiber, {
|
|
82
94
|
onNone: () => Effect.void,
|
|
83
95
|
onSome: previousFiber => Effect.asVoid(Fiber.await(previousFiber)),
|
|
84
|
-
}), Effect.andThen(
|
|
85
|
-
const fiber = Effect.runFork(provideBrowserScheduler(startEffect));
|
|
96
|
+
}), Effect.andThen(resolvePreservedModel(program.runtimeId)), Effect.flatMap(preservedModel => internals.startWith(Option.some(connector), preservedModel, 'Fresh', options?.flags)));
|
|
97
|
+
const fiber = Effect.runFork(withUnhandledCauseReporting(provideBrowserScheduler(startEffect)));
|
|
86
98
|
internals.maybeActiveFiber = Option.some(fiber);
|
|
87
99
|
let isHandleDisposed = false;
|
|
88
100
|
const dispose = () => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export type Visibility = 'Development' | 'Always';
|
|
3
3
|
/** Whether a feature configured with `show` is enabled. `'Always'` enables it
|
|
4
4
|
* everywhere. `'Development'` enables it only when `isDevelopment` is true.
|
|
5
|
-
* Callers pass whether Vite
|
|
6
|
-
* top-level window. */
|
|
5
|
+
* Callers pass whether Vite's dev server is active, and DevTools also requires
|
|
6
|
+
* a top-level window. */
|
|
7
7
|
export declare const isVisible: (show: Visibility, isDevelopment: boolean) => boolean;
|
|
8
8
|
//# sourceMappingURL=visibility.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visibility.d.ts","sourceRoot":"","sources":["../../src/runtime/visibility.ts"],"names":[],"mappings":"AAEA,wCAAwC;AACxC,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,QAAQ,CAAA;AAEjD;;;
|
|
1
|
+
{"version":3,"file":"visibility.d.ts","sourceRoot":"","sources":["../../src/runtime/visibility.ts"],"names":[],"mappings":"AAEA,wCAAwC;AACxC,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,QAAQ,CAAA;AAEjD;;;0BAG0B;AAC1B,eAAO,MAAM,SAAS,SAAU,UAAU,iBAAiB,OAAO,KAAG,OAKlE,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Match } from 'effect';
|
|
2
2
|
/** Whether a feature configured with `show` is enabled. `'Always'` enables it
|
|
3
3
|
* everywhere. `'Development'` enables it only when `isDevelopment` is true.
|
|
4
|
-
* Callers pass whether Vite
|
|
5
|
-
* top-level window. */
|
|
4
|
+
* Callers pass whether Vite's dev server is active, and DevTools also requires
|
|
5
|
+
* a top-level window. */
|
|
6
6
|
export const isVisible = (show, isDevelopment) => Match.value(show).pipe(Match.when('Always', () => true), Match.when('Development', () => isDevelopment), Match.exhaustive);
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -20,10 +20,35 @@ type TaggedUnionMatchCases<CasesByTag extends Record<string, Schema.Struct.Field
|
|
|
20
20
|
readonly _tag: Tag;
|
|
21
21
|
}>) => Output;
|
|
22
22
|
};
|
|
23
|
+
type TaggedUnionMatchOrElseCases<CasesByTag extends Record<string, Schema.Struct.Fields>, Input extends TaggedUnionType<CasesByTag>, Output> = {
|
|
24
|
+
readonly [Tag in keyof CasesByTag & string]?: (value: Extract<Input, {
|
|
25
|
+
readonly _tag: Tag;
|
|
26
|
+
}>) => Output;
|
|
27
|
+
};
|
|
28
|
+
type TaggedUnionMatchOrElseCaseReturns<Cases> = {
|
|
29
|
+
[Tag in keyof Cases]-?: NonNullable<Cases[Tag]> extends (...args: never) => infer Output ? Output : never;
|
|
30
|
+
}[keyof Cases];
|
|
31
|
+
type TaggedUnionMatchOrElseOutput<Cases, OrElse> = TaggedUnionMatchOrElseCaseReturns<Cases> | (OrElse extends (...args: never) => infer Output ? Output : never);
|
|
32
|
+
type TaggedUnionMatchOrElseHandledTags<CasesByTag extends Record<string, Schema.Struct.Fields>, Cases> = Extract<{
|
|
33
|
+
[Tag in keyof Cases]-?: {} extends Pick<Cases, Tag> ? never : Tag;
|
|
34
|
+
}[keyof Cases], keyof CasesByTag & string>;
|
|
35
|
+
type ValidateMatchOrElseCases<CasesByTag extends Record<string, Schema.Struct.Fields>, Cases> = {
|
|
36
|
+
readonly [Tag in Exclude<keyof Cases, keyof CasesByTag & string>]: never;
|
|
37
|
+
};
|
|
23
38
|
type TaggedUnionMatch<CasesByTag extends Record<string, Schema.Struct.Fields>> = {
|
|
24
39
|
<Output, Input extends TaggedUnionType<CasesByTag> = TaggedUnionType<CasesByTag>>(cases: TaggedUnionMatchCases<CasesByTag, Input, Output>): (value: Input) => Output;
|
|
25
40
|
<Output, Input extends TaggedUnionType<CasesByTag> = TaggedUnionType<CasesByTag>>(value: Input, cases: TaggedUnionMatchCases<CasesByTag, Input, Output>): Output;
|
|
26
41
|
};
|
|
42
|
+
type TaggedUnionMatchOrElse<CasesByTag extends Record<string, Schema.Struct.Fields>> = {
|
|
43
|
+
<Input extends TaggedUnionType<CasesByTag>, const Cases extends TaggedUnionMatchOrElseCases<CasesByTag, Input, unknown>, OrElse extends (value: Exclude<Input, {
|
|
44
|
+
readonly _tag: TaggedUnionMatchOrElseHandledTags<CasesByTag, Cases>;
|
|
45
|
+
}>) => unknown>(value: Input, cases: Cases & ValidateMatchOrElseCases<CasesByTag, Cases>, orElse: OrElse): TaggedUnionMatchOrElseOutput<Cases, OrElse>;
|
|
46
|
+
<const Cases extends TaggedUnionMatchOrElseCases<CasesByTag, TaggedUnionType<CasesByTag>, unknown>, OrElse extends (value: Exclude<TaggedUnionType<CasesByTag>, {
|
|
47
|
+
readonly _tag: TaggedUnionMatchOrElseHandledTags<CasesByTag, Cases>;
|
|
48
|
+
}>) => unknown>(cases: Cases & ValidateMatchOrElseCases<CasesByTag, Cases>, orElse: OrElse): (value: TaggedUnionType<CasesByTag>) => TaggedUnionMatchOrElseOutput<Cases, OrElse>;
|
|
49
|
+
<Output, Input extends TaggedUnionType<CasesByTag> = TaggedUnionType<CasesByTag>>(cases: TaggedUnionMatchOrElseCases<CasesByTag, Input, Output>, orElse: (value: Input) => Output): (value: Input) => Output;
|
|
50
|
+
<Output, Input extends TaggedUnionType<CasesByTag> = TaggedUnionType<CasesByTag>>(value: Input, cases: TaggedUnionMatchOrElseCases<CasesByTag, Input, Output>, orElse: (value: Input) => Output): Output;
|
|
51
|
+
};
|
|
27
52
|
interface UnionSchema<CasesByTag extends Record<string, Schema.Struct.Fields>> extends Schema.BottomLazy<BaseTaggedUnion<CasesByTag>['ast'], UnionSchema<CasesByTag>> {
|
|
28
53
|
readonly Type: BaseTaggedUnion<CasesByTag>['Type'];
|
|
29
54
|
readonly Encoded: BaseTaggedUnion<CasesByTag>['Encoded'];
|
|
@@ -44,13 +69,16 @@ type TaggedUnionSubsetMembers<CasesByTag extends Record<string, Schema.Struct.Fi
|
|
|
44
69
|
interface RichUnionSchema<CasesByTag extends Record<string, Schema.Struct.Fields>> extends UnionSchema<CasesByTag> {
|
|
45
70
|
readonly guards: BaseTaggedUnion<CasesByTag>['guards'];
|
|
46
71
|
readonly isAnyOf: BaseTaggedUnion<CasesByTag>['isAnyOf'];
|
|
72
|
+
readonly matchOrElse: TaggedUnionMatchOrElse<CasesByTag>;
|
|
47
73
|
readonly members: ReadonlyArray<TaggedUnionMember<CasesByTag>>;
|
|
48
74
|
/** Returns a Schema that accepts only the named variants. */
|
|
49
75
|
readonly subset: <const Tags extends ReadonlyArray<keyof CasesByTag & string>>(tags: Tags) => Schema.Union<TaggedUnionSubsetMembers<CasesByTag, Tags>>;
|
|
50
76
|
}
|
|
51
77
|
/** The Schema returned by `defineTaggedUnion`. It includes callable variant
|
|
52
|
-
* constructors, exhaustive `match`,
|
|
53
|
-
* `members`.
|
|
78
|
+
* constructors, exhaustive `match`, partial `matchOrElse`, `guards`,
|
|
79
|
+
* `isAnyOf`, `subset`, and `members`. Pass a structurally refined union as a
|
|
80
|
+
* matcher's optional second type argument to preserve narrower payload fields
|
|
81
|
+
* in each handler. */
|
|
54
82
|
export type TaggedUnion<CasesByTag extends Record<string, Schema.Struct.Fields>> = RichUnionSchema<CasesByTag> & {
|
|
55
83
|
readonly [Tag in keyof CasesByTag & string]: CallableTaggedStruct<Tag, CasesByTag[Tag]>;
|
|
56
84
|
};
|
|
@@ -83,8 +111,8 @@ export type RouteUnion<CasesByTag extends Record<string, Schema.Struct.Fields>>
|
|
|
83
111
|
* fields.
|
|
84
112
|
*
|
|
85
113
|
* A tag cannot use a name already owned by the union, such as `make`, `match`,
|
|
86
|
-
* `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
87
|
-
* untyped calls throw an error.
|
|
114
|
+
* `matchOrElse`, `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
115
|
+
* these names, and untyped calls throw an error.
|
|
88
116
|
*
|
|
89
117
|
* @example
|
|
90
118
|
* ```typescript
|
|
@@ -108,6 +136,7 @@ export declare function defineMessageUnion<const CasesByTag extends Record<strin
|
|
|
108
136
|
*
|
|
109
137
|
* - One callable Schema constructor per variant.
|
|
110
138
|
* - `match` for exhaustive handling.
|
|
139
|
+
* - `matchOrElse` for selected variants with a fallback for the rest.
|
|
111
140
|
* - `guards` and `isAnyOf` for variant checks.
|
|
112
141
|
* - `subset` for a Schema that accepts only the named variants.
|
|
113
142
|
* - `members` for APIs such as `Machine.define` that enumerate the union.
|
|
@@ -116,8 +145,8 @@ export declare function defineMessageUnion<const CasesByTag extends Record<strin
|
|
|
116
145
|
* unions and standalone tagged structs are the common cases.
|
|
117
146
|
*
|
|
118
147
|
* A tag cannot use a name already owned by the union, such as `make`, `match`,
|
|
119
|
-
* `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
120
|
-
* untyped calls throw an error.
|
|
148
|
+
* `matchOrElse`, `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
149
|
+
* these names, and untyped calls throw an error.
|
|
121
150
|
*
|
|
122
151
|
* @example
|
|
123
152
|
* ```typescript
|
|
@@ -143,17 +172,18 @@ export declare function defineTaggedUnion<const CasesByTag extends Record<string
|
|
|
143
172
|
* `parseUrlWithFallback`, while `AppRoute.Person({ personId: 42 })` constructs
|
|
144
173
|
* a value.
|
|
145
174
|
*
|
|
146
|
-
* Use `match` to handle every Route, `
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* not change an
|
|
175
|
+
* Use `match` to handle every Route, `matchOrElse` to handle selected Routes
|
|
176
|
+
* with a fallback, `guards` or `isAnyOf` to check selected tags, and `subset`
|
|
177
|
+
* when another Schema accepts only some Routes. A subset includes only the
|
|
178
|
+
* tags named in the call. Adding a Route to `AppRoute` does not change an
|
|
179
|
+
* existing subset.
|
|
150
180
|
*
|
|
151
181
|
* Routers remain separate. A Route is the parsed value; a Router describes the
|
|
152
182
|
* URL that produces it.
|
|
153
183
|
*
|
|
154
184
|
* A tag cannot use a name already owned by the union, such as `make`, `match`,
|
|
155
|
-
* `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
156
|
-
* untyped calls throw an error.
|
|
185
|
+
* `matchOrElse`, `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
186
|
+
* these names, and untyped calls throw an error.
|
|
157
187
|
*
|
|
158
188
|
* @example
|
|
159
189
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,MAAM,EAAa,KAAK,EAAE,MAAM,QAAQ,CAAA;AAEtE,qIAAqI;AACrI,MAAM,MAAM,oBAAoB,CAC9B,GAAG,SAAS,MAAM,EAClB,MAAM,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,IACjC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,GAClC,CAAC,MAAM,MAAM,SAAS,KAAK,GACvB,CACE,KAAK,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,KACnE,KAAK,CAAC,QAAQ,CACjB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;CAAE,GAAG,MAAM,CAAC,CAChE,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAE7D,UAAU,EAAE,UAAU,GAAG,oBAAoB,CAAC,UAAU,CAAC,GACxD,UAAU,CAAC,UAAU,CAAC,CAExB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,GAAG,SAAS,MAAM,EAC7C,GAAG,EAAE,GAAG,GACP,oBAAoB,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;AAChC,wBAAgB,YAAY,CAC1B,GAAG,SAAS,MAAM,EAClB,MAAM,SAAS,MAAM,CAAC,MAAM,CAAC,MAAM,EACnC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA"}
|
package/dist/schema/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Array, Match, Schema, SchemaAST } from 'effect';
|
|
1
|
+
import { Array, Cause, Match, Schema, SchemaAST } from 'effect';
|
|
2
2
|
const assignPlainProperty = (output, name, value) => {
|
|
3
3
|
if (name === '__proto__') {
|
|
4
4
|
Object.defineProperty(output, name, {
|
|
@@ -12,11 +12,20 @@ const assignPlainProperty = (output, name, value) => {
|
|
|
12
12
|
output[name] = value;
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
+
const runConstructorOperation = (operation) => {
|
|
16
|
+
try {
|
|
17
|
+
return operation();
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new Error('Constructor adapter can only throw schema issues', {
|
|
21
|
+
cause: Cause.die(error),
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
15
25
|
const isDirectlyCopyable = (ast) => {
|
|
16
26
|
if (ast.checks !== undefined ||
|
|
17
27
|
ast.encoding !== undefined ||
|
|
18
|
-
ast.context !== undefined
|
|
19
|
-
ast.annotations?.['parseOptions'] !== undefined) {
|
|
28
|
+
ast.context !== undefined) {
|
|
20
29
|
return false;
|
|
21
30
|
}
|
|
22
31
|
return Match.value(ast).pipe(Match.withReturnType(), Match.tagsExhaustive({
|
|
@@ -39,7 +48,7 @@ const isDirectlyCopyable = (ast) => {
|
|
|
39
48
|
TemplateLiteral: ({ parts }) => parts.every(isDirectlyCopyable),
|
|
40
49
|
Arrays: () => false,
|
|
41
50
|
Objects: () => false,
|
|
42
|
-
Union: ({
|
|
51
|
+
Union: ({ options, types }) => options?.mode !== 'oneOf' && types.every(isDirectlyCopyable),
|
|
43
52
|
Suspend: () => false,
|
|
44
53
|
}));
|
|
45
54
|
};
|
|
@@ -70,24 +79,20 @@ const makeCallable = (tag, fields) => {
|
|
|
70
79
|
}
|
|
71
80
|
const output = {};
|
|
72
81
|
for (const name of propertyNames) {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return
|
|
78
|
-
}
|
|
79
|
-
if (descriptor !== undefined && !('value' in descriptor)) {
|
|
80
|
-
return make(value);
|
|
81
|
-
}
|
|
82
|
-
const inputValue = descriptor === undefined ? undefined : input[name];
|
|
82
|
+
const inputValue = runConstructorOperation(() => {
|
|
83
|
+
const hasProperty = name === '__proto__'
|
|
84
|
+
? Object.hasOwn(input, name)
|
|
85
|
+
: Reflect.has(input, name);
|
|
86
|
+
return hasProperty ? input[name] : undefined;
|
|
87
|
+
});
|
|
83
88
|
if (name === '_tag') {
|
|
84
89
|
if (inputValue !== undefined && inputValue !== tag) {
|
|
85
90
|
return make(value);
|
|
86
91
|
}
|
|
87
|
-
assignPlainProperty(output, name, tag);
|
|
92
|
+
runConstructorOperation(() => assignPlainProperty(output, name, tag));
|
|
88
93
|
}
|
|
89
94
|
else {
|
|
90
|
-
assignPlainProperty(output, name, inputValue);
|
|
95
|
+
runConstructorOperation(() => assignPlainProperty(output, name, inputValue));
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
98
|
return output;
|
|
@@ -176,8 +181,8 @@ const defineUnion = (variantLabel, casesByTag) => {
|
|
|
176
181
|
* fields.
|
|
177
182
|
*
|
|
178
183
|
* A tag cannot use a name already owned by the union, such as `make`, `match`,
|
|
179
|
-
* `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
180
|
-
* untyped calls throw an error.
|
|
184
|
+
* `matchOrElse`, `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
185
|
+
* these names, and untyped calls throw an error.
|
|
181
186
|
*
|
|
182
187
|
* @example
|
|
183
188
|
* ```typescript
|
|
@@ -203,6 +208,7 @@ export function defineMessageUnion(casesByTag) {
|
|
|
203
208
|
*
|
|
204
209
|
* - One callable Schema constructor per variant.
|
|
205
210
|
* - `match` for exhaustive handling.
|
|
211
|
+
* - `matchOrElse` for selected variants with a fallback for the rest.
|
|
206
212
|
* - `guards` and `isAnyOf` for variant checks.
|
|
207
213
|
* - `subset` for a Schema that accepts only the named variants.
|
|
208
214
|
* - `members` for APIs such as `Machine.define` that enumerate the union.
|
|
@@ -211,8 +217,8 @@ export function defineMessageUnion(casesByTag) {
|
|
|
211
217
|
* unions and standalone tagged structs are the common cases.
|
|
212
218
|
*
|
|
213
219
|
* A tag cannot use a name already owned by the union, such as `make`, `match`,
|
|
214
|
-
* `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
215
|
-
* untyped calls throw an error.
|
|
220
|
+
* `matchOrElse`, `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
221
|
+
* these names, and untyped calls throw an error.
|
|
216
222
|
*
|
|
217
223
|
* @example
|
|
218
224
|
* ```typescript
|
|
@@ -240,17 +246,18 @@ export function defineTaggedUnion(casesByTag) {
|
|
|
240
246
|
* `parseUrlWithFallback`, while `AppRoute.Person({ personId: 42 })` constructs
|
|
241
247
|
* a value.
|
|
242
248
|
*
|
|
243
|
-
* Use `match` to handle every Route, `
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
* not change an
|
|
249
|
+
* Use `match` to handle every Route, `matchOrElse` to handle selected Routes
|
|
250
|
+
* with a fallback, `guards` or `isAnyOf` to check selected tags, and `subset`
|
|
251
|
+
* when another Schema accepts only some Routes. A subset includes only the
|
|
252
|
+
* tags named in the call. Adding a Route to `AppRoute` does not change an
|
|
253
|
+
* existing subset.
|
|
247
254
|
*
|
|
248
255
|
* Routers remain separate. A Route is the parsed value; a Router describes the
|
|
249
256
|
* URL that produces it.
|
|
250
257
|
*
|
|
251
258
|
* A tag cannot use a name already owned by the union, such as `make`, `match`,
|
|
252
|
-
* `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
253
|
-
* untyped calls throw an error.
|
|
259
|
+
* `matchOrElse`, `cases`, `ast`, `members`, or `subset`. TypeScript rejects
|
|
260
|
+
* these names, and untyped calls throw an error.
|
|
254
261
|
*
|
|
255
262
|
* @example
|
|
256
263
|
* ```typescript
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
import type { Html, HtmlBuilder } from '../../html/index.js';
|
|
3
|
+
import type * as Update from '../../update/index.js';
|
|
4
|
+
export declare const Model: Schema.Struct<{
|
|
5
|
+
readonly body: Schema.String;
|
|
6
|
+
}>;
|
|
7
|
+
export type Model = typeof Model.Type;
|
|
8
|
+
export declare const Message: import("../../schema/index.js").MessageUnion<{
|
|
9
|
+
readonly UpdatedBody: {
|
|
10
|
+
value: Schema.String;
|
|
11
|
+
};
|
|
12
|
+
readonly InsertedText: {
|
|
13
|
+
value: Schema.String;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
export type Message = typeof Message.Type;
|
|
17
|
+
export declare const initialModel: Model;
|
|
18
|
+
export declare const update: (model: Model, message: Message) => Readonly<{
|
|
19
|
+
model: {
|
|
20
|
+
readonly body: string;
|
|
21
|
+
};
|
|
22
|
+
commands?: Update.Commands<{
|
|
23
|
+
readonly _tag: "InsertedText";
|
|
24
|
+
readonly value: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly _tag: "UpdatedBody";
|
|
27
|
+
readonly value: string;
|
|
28
|
+
}, never>;
|
|
29
|
+
outMessage?: never;
|
|
30
|
+
}>;
|
|
31
|
+
export declare const view: (model: Model, h: HtmlBuilder<Message>) => Html;
|
|
32
|
+
//# sourceMappingURL=contentEditableEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentEditableEditor.d.ts","sourceRoot":"","sources":["../../../src/test/apps/contentEditableEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEvC,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAG5D,OAAO,KAAK,KAAK,MAAM,MAAM,uBAAuB,CAAA;AAIpD,eAAO,MAAM,KAAK;;EAEhB,CAAA;AAEF,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,CAAA;AAIrC,eAAO,MAAM,OAAO;;QACH,KAAK;;;QACJ,KAAK;;EACrB,CAAA;AAEF,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;AAIzC,eAAO,MAAM,YAAY,EAAE,KAE1B,CAAA;AAID,eAAO,MAAM,MAAM,UAAW,KAAK,WAAW,OAAO;;;;;;;;;;;;EAQjD,CAAA;AAIJ,eAAO,MAAM,IAAI,UAAW,KAAK,KAAK,WAAW,CAAC,OAAO,CAAC,KAAG,IAoB5D,CAAA"}
|