@weasel-js/forge 1.7.3 → 1.8.1
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 +78 -0
- package/dist/{FrameController-RdGggdGA.d.ts → FrameController-BH8xJHZ8.d.ts} +36 -1
- package/dist/{chunk-NYBMOSSR.js → chunk-5N4YP5HS.js} +166 -10
- package/dist/chunk-5N4YP5HS.js.map +1 -0
- package/dist/chunk-CJX3W5HY.js +151 -0
- package/dist/chunk-CJX3W5HY.js.map +1 -0
- package/dist/{chunk-SEK6EKHO.js → chunk-GHTVXHNJ.js} +72 -10
- package/dist/chunk-GHTVXHNJ.js.map +1 -0
- package/dist/{chunk-KIFCYY4F.js → chunk-JQD3MVUQ.js} +4 -4
- package/dist/{chunk-KIFCYY4F.js.map → chunk-JQD3MVUQ.js.map} +1 -1
- package/dist/chunk-KJGXJD3U.js +15 -0
- package/dist/chunk-KJGXJD3U.js.map +1 -0
- package/dist/chunk-L5XM5VKB.js +47 -0
- package/dist/chunk-L5XM5VKB.js.map +1 -0
- package/dist/{chunk-YKN3IAEX.js → chunk-MGQWCPYE.js} +4 -24
- package/dist/chunk-MGQWCPYE.js.map +1 -0
- package/dist/{chunk-JNJGIUYU.js → chunk-NI5FYQHW.js} +8 -5
- package/dist/chunk-NI5FYQHW.js.map +1 -0
- package/dist/{config-BJIgUhiI.d.ts → config-DoLWwEb2.d.ts} +5 -1
- package/dist/csf/preview-api.js +2 -1
- package/dist/csf/preview-api.js.map +1 -1
- package/dist/frame/index.css +1 -0
- package/dist/frame/index.css.map +1 -1
- package/dist/frame/index.d.ts +2 -2
- package/dist/frame/index.js +5 -4
- package/dist/frame/index.js.map +1 -1
- package/dist/index.d.ts +79 -4
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/shell/index.css +14 -0
- package/dist/shell/index.css.map +1 -1
- package/dist/shell/index.d.ts +2 -2
- package/dist/shell/index.js +225 -56
- package/dist/shell/index.js.map +1 -1
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.js +6 -5
- package/dist/test/index.js.map +1 -1
- package/dist/vite/index.js +160 -16
- package/dist/vite/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-JNJGIUYU.js.map +0 -1
- package/dist/chunk-NYBMOSSR.js.map +0 -1
- package/dist/chunk-SEK6EKHO.js.map +0 -1
- package/dist/chunk-Y3WZ2EWR.js +0 -15
- package/dist/chunk-Y3WZ2EWR.js.map +0 -1
- package/dist/chunk-YKN3IAEX.js.map +0 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { isPlainObject, stableStringify } from './chunk-KJGXJD3U.js';
|
|
2
|
+
import { valueAtPath, isConfigBranch } from '@weasel-js/labkit/config';
|
|
3
|
+
|
|
4
|
+
var PLAYHEAD_PARAM = "t";
|
|
5
|
+
var RESERVED_PARAMS = /* @__PURE__ */ new Set([PLAYHEAD_PARAM]);
|
|
6
|
+
var INTERNAL_PREFIX = "$";
|
|
7
|
+
function parseRoute(hash) {
|
|
8
|
+
const body = hash.startsWith("#") ? hash.slice(1) : hash;
|
|
9
|
+
if (!body.startsWith("/")) return { story: null, params: {} };
|
|
10
|
+
const at = body.indexOf("?");
|
|
11
|
+
const path = at === -1 ? body.slice(1) : body.slice(1, at);
|
|
12
|
+
let story;
|
|
13
|
+
try {
|
|
14
|
+
story = decodeURIComponent(path) || null;
|
|
15
|
+
} catch {
|
|
16
|
+
story = null;
|
|
17
|
+
}
|
|
18
|
+
const params = {};
|
|
19
|
+
if (at !== -1) for (const [key, value] of new URLSearchParams(body.slice(at + 1))) params[key] = value;
|
|
20
|
+
return { story, params };
|
|
21
|
+
}
|
|
22
|
+
function formatRoute(route) {
|
|
23
|
+
const query = new URLSearchParams(Object.entries(route.params)).toString();
|
|
24
|
+
return `#/${encodeURIComponent(route.story ?? "")}${query ? `?${query}` : ""}`;
|
|
25
|
+
}
|
|
26
|
+
function isKnobParam(name) {
|
|
27
|
+
return name !== "" && !RESERVED_PARAMS.has(name) && !name.startsWith(INTERNAL_PREFIX);
|
|
28
|
+
}
|
|
29
|
+
function knobParams(params) {
|
|
30
|
+
return Object.fromEntries(Object.entries(params).filter(([name]) => isKnobParam(name)));
|
|
31
|
+
}
|
|
32
|
+
function reservedParams(params) {
|
|
33
|
+
return Object.fromEntries(Object.entries(params).filter(([name]) => !isKnobParam(name)));
|
|
34
|
+
}
|
|
35
|
+
function codecOf(leaf) {
|
|
36
|
+
switch (leaf.kind) {
|
|
37
|
+
case "number":
|
|
38
|
+
case "boolean":
|
|
39
|
+
case "string":
|
|
40
|
+
case "enum":
|
|
41
|
+
return leaf.kind;
|
|
42
|
+
case "color":
|
|
43
|
+
return "string";
|
|
44
|
+
case "list":
|
|
45
|
+
case "json":
|
|
46
|
+
return "json";
|
|
47
|
+
}
|
|
48
|
+
const d = leaf.default;
|
|
49
|
+
if (typeof d === "number" || typeof d === "boolean" || typeof d === "string") return typeof d;
|
|
50
|
+
return Array.isArray(d) || isPlainObject(d) ? "json" : null;
|
|
51
|
+
}
|
|
52
|
+
function encodeKnob(value) {
|
|
53
|
+
switch (typeof value) {
|
|
54
|
+
case "string":
|
|
55
|
+
return value;
|
|
56
|
+
case "number":
|
|
57
|
+
case "boolean":
|
|
58
|
+
return String(value);
|
|
59
|
+
case "object":
|
|
60
|
+
return value !== null && (Array.isArray(value) || isPlainObject(value)) ? JSON.stringify(value) : void 0;
|
|
61
|
+
default:
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function fits(codec, value, leaf) {
|
|
66
|
+
if (codec !== "json") return true;
|
|
67
|
+
const d = leaf.default;
|
|
68
|
+
if (Array.isArray(d)) {
|
|
69
|
+
if (!Array.isArray(value)) return false;
|
|
70
|
+
return leaf.kind !== "list" || value.every((item) => typeof item === "string");
|
|
71
|
+
}
|
|
72
|
+
if (isPlainObject(d)) return isPlainObject(value);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
function decodeKnob(raw, leaf) {
|
|
76
|
+
const codec = codecOf(leaf);
|
|
77
|
+
switch (codec) {
|
|
78
|
+
case "number": {
|
|
79
|
+
const n = raw.trim() === "" ? Number.NaN : Number(raw);
|
|
80
|
+
return Number.isNaN(n) ? void 0 : { value: n };
|
|
81
|
+
}
|
|
82
|
+
case "boolean":
|
|
83
|
+
if (raw === "" || raw === "true" || raw === "1") return { value: true };
|
|
84
|
+
if (raw === "false" || raw === "0") return { value: false };
|
|
85
|
+
return void 0;
|
|
86
|
+
case "string":
|
|
87
|
+
return { value: raw };
|
|
88
|
+
case "enum": {
|
|
89
|
+
const options = leaf.annotations?.options;
|
|
90
|
+
return !options || options.some((o) => o.value === raw) ? { value: raw } : void 0;
|
|
91
|
+
}
|
|
92
|
+
case "json": {
|
|
93
|
+
try {
|
|
94
|
+
const value = JSON.parse(raw);
|
|
95
|
+
return fits(codec, value, leaf) ? { value } : void 0;
|
|
96
|
+
} catch {
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
default:
|
|
101
|
+
return void 0;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function knobPaths(schema) {
|
|
105
|
+
const out = [];
|
|
106
|
+
const walk = (shape, at) => {
|
|
107
|
+
for (const [key, entry] of Object.entries(shape)) {
|
|
108
|
+
if (key.startsWith(INTERNAL_PREFIX) || key.includes(".")) continue;
|
|
109
|
+
const path = at === "" ? key : `${at}.${key}`;
|
|
110
|
+
if (isConfigBranch(entry)) walk(entry.children, path);
|
|
111
|
+
else if (codecOf(entry) !== null) out.push({ path, leaf: entry });
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
walk(schema.nodes, "");
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
function sameKnob(a, b) {
|
|
118
|
+
return Object.is(a, b) || stableStringify(a) === stableStringify(b);
|
|
119
|
+
}
|
|
120
|
+
function knobsToParams(schema, config) {
|
|
121
|
+
const params = {};
|
|
122
|
+
for (const { path, leaf } of knobPaths(schema)) {
|
|
123
|
+
const value = valueAtPath(config, path);
|
|
124
|
+
if (value === void 0 || sameKnob(value, leaf.default)) continue;
|
|
125
|
+
const encoded = encodeKnob(value);
|
|
126
|
+
if (encoded !== void 0) params[path] = encoded;
|
|
127
|
+
}
|
|
128
|
+
return params;
|
|
129
|
+
}
|
|
130
|
+
function paramsToKnobs(schema, params) {
|
|
131
|
+
const knobs = {};
|
|
132
|
+
for (const { path, leaf } of knobPaths(schema)) {
|
|
133
|
+
const raw = params[path];
|
|
134
|
+
if (raw === void 0 || !isKnobParam(path)) continue;
|
|
135
|
+
const decoded = decodeKnob(raw, leaf);
|
|
136
|
+
if (decoded) knobs[path] = decoded.value;
|
|
137
|
+
}
|
|
138
|
+
return knobs;
|
|
139
|
+
}
|
|
140
|
+
function storyHref(story, knobs = {}, params = {}) {
|
|
141
|
+
const encoded = {};
|
|
142
|
+
for (const [path, value] of Object.entries(knobs)) {
|
|
143
|
+
const raw = encodeKnob(value);
|
|
144
|
+
if (raw !== void 0 && isKnobParam(path)) encoded[path] = raw;
|
|
145
|
+
}
|
|
146
|
+
return formatRoute({ story, params: { ...encoded, ...reservedParams(params) } });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export { PLAYHEAD_PARAM, RESERVED_PARAMS, decodeKnob, encodeKnob, formatRoute, knobParams, knobPaths, knobsToParams, paramsToKnobs, parseRoute, reservedParams, sameKnob, storyHref };
|
|
150
|
+
//# sourceMappingURL=chunk-CJX3W5HY.js.map
|
|
151
|
+
//# sourceMappingURL=chunk-CJX3W5HY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/route/url.ts"],"names":[],"mappings":";;;AAWO,IAAM,cAAA,GAAiB;AAGvB,IAAM,eAAA,mBAAuC,IAAI,GAAA,CAAI,CAAC,cAAc,CAAC;AAG5E,IAAM,eAAA,GAAkB,GAAA;AASjB,SAAS,WAAW,IAAA,EAA0B;AACnD,EAAA,M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I,CAAA;AACvB,IAAA,IAAI,GAAA,KAAQ,MAAA,IAAa,CAAC,WAAA,CAAY,IAAI,CAAA,EAAG;AAC7C,IAAA,MAAM,OAAA,GAAU,UAAA,CAAW,GAAA,EAAK,IAAI,CAAA;AACpC,IAAA,IAAI,OAAA,EAAS,KAAA,CAAM,IAAI,CAAA,GAAI,OAAA,CAAQ,KAAA;AAAA,EACrC;AACA,EAAA,OAAO,KAAA;AACT;AAMO,SAAS,UACd,KAAA,EACA,KAAA,GAA2C,EAAC,EAC5C,MAAA,GAA2C,EAAC,EACpC;AACR,EAAA,MAAM,UAAkC,EAAC;AACzC,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AACjD,IAAA,MAAM,GAAA,GAAM,WAAW,KAAK,CAAA;AAC5B,IAAA,IAAI,QAAQ,MAAA,IAAa,WAAA,CAAY,IAAI,CAAA,EAAG,OAAA,CAAQ,IAAI,CAAA,GAAI,GAAA;AAAA,EAC9D;AACA,EAAA,OAAO,WAAA,CAAY,EAAE,KAAA,EAAO,MAAA,EAAQ,EAAE,GAAG,OAAA,EAAS,GAAG,cAAA,CAAe,MAAM,CAAA,EAAE,EAAG,CAAA;AACjF","file":"chunk-CJX3W5HY.js","sourcesContent":["import { type ConfigSchema, type ConfigShape, isConfigBranch, valueAtPath } from '@weasel-js/labkit/config';\nimport { isPlainObject } from '../csf/isPlainObject';\nimport { stableStringify } from '../protocol/messages';\n\n/**\n * Forge's URL, as pure functions: `#/<story id>?<params>`. The story and its params share the hash, so the page's\n * own query string stays the host's. A param is a knob — a story arg, addressed by its dotted config path\n * (`look.px`) — unless its name is reserved for the workshop itself.\n */\n\n/** The param a paused playhead is held in, in seconds. */\nexport const PLAYHEAD_PARAM = 't';\n\n/** Param names that are never knobs. */\nexport const RESERVED_PARAMS: ReadonlySet<string> = new Set([PLAYHEAD_PARAM]);\n\n/** Config keys forge keeps for itself, such as the `$globals` pins, start with this and never reach the URL. */\nconst INTERNAL_PREFIX = '$';\n\n/** What a forge hash holds: the story it names, and every param after it, knobs and reserved alike, in order. */\nexport interface ForgeRoute {\n story: string | null;\n params: Readonly<Record<string, string>>;\n}\n\n/** Reads a hash (`location.hash`, with or without its `#`). Anything not in the `#/<id>` form names no story. */\nexport function parseRoute(hash: string): ForgeRoute {\n const body = hash.startsWith('#') ? hash.slice(1) : hash;\n if (!body.startsWith('/')) return { story: null, params: {} };\n const at = body.indexOf('?');\n const path = at === -1 ? body.slice(1) : body.slice(1, at);\n let story: string | null;\n try {\n story = decodeURIComponent(path) || null;\n } catch {\n story = null;\n }\n const params: Record<string, string> = {};\n if (at !== -1) for (const [key, value] of new URLSearchParams(body.slice(at + 1))) params[key] = value;\n return { story, params };\n}\n\n/** The hash for `route`, with its leading `#`. The inverse of `parseRoute`. */\nexport function formatRoute(route: ForgeRoute): string {\n const query = new URLSearchParams(Object.entries(route.params)).toString();\n return `#/${encodeURIComponent(route.story ?? '')}${query ? `?${query}` : ''}`;\n}\n\n/** Whether a param name can be a knob: not reserved and not one of forge's own config keys. */\nexport function isKnobParam(name: string): boolean {\n return name !== '' && !RESERVED_PARAMS.has(name) && !name.startsWith(INTERNAL_PREFIX);\n}\n\n/** The params that are knobs, with the reserved ones left out. */\nexport function knobParams(params: Readonly<Record<string, string>>): Record<string, string> {\n return Object.fromEntries(Object.entries(params).filter(([name]) => isKnobParam(name)));\n}\n\n/** The params that are not knobs. Kept as they are when the knobs are rewritten. */\nexport function reservedParams(params: Readonly<Record<string, string>>): Record<string, string> {\n return Object.fromEntries(Object.entries(params).filter(([name]) => !isKnobParam(name)));\n}\n\n/** What a knob's value is decoded against: its schema leaf's declared kind, its default, and its choices. */\nexport interface KnobLeaf {\n kind: string | null;\n default: unknown;\n annotations?: { options?: readonly { value: string }[] };\n}\n\ntype Codec = 'number' | 'boolean' | 'string' | 'enum' | 'json';\n\n/** How a leaf's value travels: by its declared kind first, then by the type of its default. */\nfunction codecOf(leaf: KnobLeaf): Codec | null {\n switch (leaf.kind) {\n case 'number':\n case 'boolean':\n case 'string':\n case 'enum':\n return leaf.kind;\n case 'color':\n return 'string';\n case 'list':\n case 'json':\n return 'json';\n }\n const d = leaf.default;\n if (typeof d === 'number' || typeof d === 'boolean' || typeof d === 'string') return typeof d as Codec;\n return Array.isArray(d) || isPlainObject(d) ? 'json' : null;\n}\n\n/** A value as one param. Undefined for a value no param can carry, such as a function. */\nexport function encodeKnob(value: unknown): string | undefined {\n switch (typeof value) {\n case 'string':\n return value;\n case 'number':\n case 'boolean':\n return String(value);\n case 'object':\n return value !== null && (Array.isArray(value) || isPlainObject(value)) ? JSON.stringify(value) : undefined;\n default:\n return undefined;\n }\n}\n\n/** Whether `value` is something a leaf of codec `codec` could hold, so a well-formed param of the wrong type is refused. */\nfunction fits(codec: Codec, value: unknown, leaf: KnobLeaf): boolean {\n if (codec !== 'json') return true;\n const d = leaf.default;\n if (Array.isArray(d)) {\n if (!Array.isArray(value)) return false;\n return leaf.kind !== 'list' || value.every((item) => typeof item === 'string');\n }\n if (isPlainObject(d)) return isPlainObject(value);\n return true;\n}\n\n/**\n * One param read as `leaf`'s type: `{ value }`, or undefined for a param that does not parse as one — a number that\n * is not a number, an option the enum does not list, malformed JSON. A bare boolean param (`?dark`) reads as true.\n */\nexport function decodeKnob(raw: string, leaf: KnobLeaf): { value: unknown } | undefined {\n const codec = codecOf(leaf);\n switch (codec) {\n case 'number': {\n const n = raw.trim() === '' ? Number.NaN : Number(raw);\n return Number.isNaN(n) ? undefined : { value: n };\n }\n case 'boolean':\n if (raw === '' || raw === 'true' || raw === '1') return { value: true };\n if (raw === 'false' || raw === '0') return { value: false };\n return undefined;\n case 'string':\n return { value: raw };\n case 'enum': {\n const options = leaf.annotations?.options;\n return !options || options.some((o) => o.value === raw) ? { value: raw } : undefined;\n }\n case 'json': {\n try {\n const value: unknown = JSON.parse(raw);\n return fits(codec, value, leaf) ? { value } : undefined;\n } catch {\n return undefined;\n }\n }\n default:\n return undefined;\n }\n}\n\n/** One leaf a URL can address: its dotted path, and what its value decodes against. */\nexport interface KnobPath {\n path: string;\n leaf: KnobLeaf;\n}\n\n/** Every leaf of `schema` a param can carry, in schema order, with branches flattened into dotted paths. */\nexport function knobPaths(schema: Pick<ConfigSchema<unknown>, 'nodes'>): KnobPath[] {\n const out: KnobPath[] = [];\n const walk = (shape: ConfigShape, at: string): void => {\n for (const [key, entry] of Object.entries(shape)) {\n if (key.startsWith(INTERNAL_PREFIX) || key.includes('.')) continue;\n const path = at === '' ? key : `${at}.${key}`;\n if (isConfigBranch(entry)) walk(entry.children, path);\n else if (codecOf(entry) !== null) out.push({ path, leaf: entry });\n }\n };\n walk(schema.nodes, '');\n return out;\n}\n\n/** Whether two knob values are the same value, compared as data. */\nexport function sameKnob(a: unknown, b: unknown): boolean {\n return Object.is(a, b) || stableStringify(a) === stableStringify(b);\n}\n\n/**\n * The knob params for `config`: one per leaf whose value differs from its default, keyed by dotted path, in schema\n * order. A leaf absent from `config` is at its default.\n */\nexport function knobsToParams(schema: Pick<ConfigSchema<unknown>, 'nodes'>, config: unknown): Record<string, string> {\n const params: Record<string, string> = {};\n for (const { path, leaf } of knobPaths(schema)) {\n const value = valueAtPath(config, path);\n if (value === undefined || sameKnob(value, leaf.default)) continue;\n const encoded = encodeKnob(value);\n if (encoded !== undefined) params[path] = encoded;\n }\n return params;\n}\n\n/**\n * The knob values `params` sets, by dotted path, each coerced to its leaf's type. A param naming no leaf, a reserved\n * param, and one that does not parse as its leaf's type are left out rather than failing the rest.\n */\nexport function paramsToKnobs(\n schema: Pick<ConfigSchema<unknown>, 'nodes'>,\n params: Readonly<Record<string, string>>,\n): Record<string, unknown> {\n const knobs: Record<string, unknown> = {};\n for (const { path, leaf } of knobPaths(schema)) {\n const raw = params[path];\n if (raw === undefined || !isKnobParam(path)) continue;\n const decoded = decodeKnob(raw, leaf);\n if (decoded) knobs[path] = decoded.value;\n }\n return knobs;\n}\n\n/**\n * A link to a story at a given state, for a host that has no schema to hand: each knob is a dotted path and a value,\n * encoded by its own type. `params` adds workshop params, such as `t`.\n */\nexport function storyHref(\n story: string,\n knobs: Readonly<Record<string, unknown>> = {},\n params: Readonly<Record<string, string>> = {},\n): string {\n const encoded: Record<string, string> = {};\n for (const [path, value] of Object.entries(knobs)) {\n const raw = encodeKnob(value);\n if (raw !== undefined && isKnobParam(path)) encoded[path] = raw;\n }\n return formatRoute({ story, params: { ...encoded, ...reservedParams(params) } });\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { GLOBALS_KEY, effectiveGlobals, storyConfig,
|
|
2
|
-
import { StoryHost, createOverrides, createGlobalsTarget, scanCssVars, runAxe, captureElement } from './chunk-
|
|
1
|
+
import { GLOBALS_KEY, effectiveGlobals, storyConfig, isForgePath, PLAYHEAD_KEY } from './chunk-NI5FYQHW.js';
|
|
2
|
+
import { StoryHost, createOverrides, createGlobalsTarget, useStoryClock, useClockLoop, scanCssVars, runAxe, captureElement } from './chunk-5N4YP5HS.js';
|
|
3
|
+
import { ClockContext } from './chunk-L5XM5VKB.js';
|
|
3
4
|
import { createContext, memo, useContext, useCallback, useSyncExternalStore, useMemo, useId, useState, useRef, useLayoutEffect, useEffect } from 'react';
|
|
4
5
|
import { useLatest } from '@weasel-js/core';
|
|
5
6
|
import { usePersistedState, TrialIdContext, LabBoundary } from '@weasel-js/labkit';
|
|
@@ -227,6 +228,55 @@ function TrialHost({ layout, setup, config, children, hostRef, onRendered }) {
|
|
|
227
228
|
}
|
|
228
229
|
);
|
|
229
230
|
}
|
|
231
|
+
function createTrialClocks() {
|
|
232
|
+
const clocks = /* @__PURE__ */ new Map();
|
|
233
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
234
|
+
const notify = () => {
|
|
235
|
+
for (const listener of [...listeners]) listener();
|
|
236
|
+
};
|
|
237
|
+
return {
|
|
238
|
+
publish(trialId, clock) {
|
|
239
|
+
clocks.set(trialId, clock);
|
|
240
|
+
notify();
|
|
241
|
+
return () => {
|
|
242
|
+
if (clocks.get(trialId) !== clock) return;
|
|
243
|
+
clocks.delete(trialId);
|
|
244
|
+
notify();
|
|
245
|
+
};
|
|
246
|
+
},
|
|
247
|
+
get: (trialId) => clocks.get(trialId) ?? null,
|
|
248
|
+
subscribe(listener) {
|
|
249
|
+
listeners.add(listener);
|
|
250
|
+
return () => listeners.delete(listener);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
var TrialClocksContext = createContext(null);
|
|
255
|
+
var NEVER = () => () => {
|
|
256
|
+
};
|
|
257
|
+
var NONE2 = () => null;
|
|
258
|
+
function useTrialClock(trialId) {
|
|
259
|
+
const clocks = useContext(TrialClocksContext);
|
|
260
|
+
return useSyncExternalStore(clocks?.subscribe ?? NEVER, clocks ? () => clocks.get(trialId) : NONE2);
|
|
261
|
+
}
|
|
262
|
+
function usePersistedPlayhead(clock, persisted, write) {
|
|
263
|
+
const written = useRef(persisted);
|
|
264
|
+
const latestWrite = useLatest(write);
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
if (!clock || persisted === written.current) return;
|
|
267
|
+
written.current = persisted;
|
|
268
|
+
clock.request(persisted);
|
|
269
|
+
}, [clock, persisted]);
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
if (!clock) return;
|
|
272
|
+
return clock.subscribe(() => {
|
|
273
|
+
const { playing, time } = clock.get();
|
|
274
|
+
if (playing || clock.pending() !== null || time === written.current) return;
|
|
275
|
+
written.current = time;
|
|
276
|
+
latestWrite.current(time);
|
|
277
|
+
});
|
|
278
|
+
}, [clock, latestWrite]);
|
|
279
|
+
}
|
|
230
280
|
var NO_DECORATORS = [];
|
|
231
281
|
var StoryBody = memo(function StoryBody2({ story, config, setConfig, state, setState, globals, decorators, resetKey, onError }) {
|
|
232
282
|
const storyCtx = { config, setConfig, state, setState, globals, title: story.title, name: story.name };
|
|
@@ -234,7 +284,9 @@ var StoryBody = memo(function StoryBody2({ story, config, setConfig, state, setS
|
|
|
234
284
|
});
|
|
235
285
|
function StoryTrial({ story, setup, ctx, hostRef, onRendered, onError }) {
|
|
236
286
|
const latest = useLatest(ctx);
|
|
237
|
-
const
|
|
287
|
+
const [heldConfig, setHeldConfig] = useState(() => storyConfig(ctx.config));
|
|
288
|
+
const config = storyConfig(ctx.config, heldConfig);
|
|
289
|
+
if (config !== heldConfig) setHeldConfig(config);
|
|
238
290
|
const seeded = useRef(false);
|
|
239
291
|
useEffect(() => {
|
|
240
292
|
if (seeded.current || ctx.state !== null || !story.initialState) return;
|
|
@@ -248,13 +300,23 @@ function StoryTrial({ story, setup, ctx, hostRef, onRendered, onError }) {
|
|
|
248
300
|
setInput({ config, state: ctx.state, key: resetKey });
|
|
249
301
|
}
|
|
250
302
|
const setConfig = useCallback((path, value) => {
|
|
251
|
-
if (!
|
|
303
|
+
if (!isForgePath(path)) latest.current.setConfig(path, value);
|
|
252
304
|
}, [latest]);
|
|
253
305
|
const setState = useCallback((next) => latest.current.setState(next), [latest]);
|
|
306
|
+
const trialId = useContext(TrialIdContext);
|
|
307
|
+
const clocks = useContext(TrialClocksContext);
|
|
308
|
+
const ownHost = useRef(null);
|
|
309
|
+
const host = hostRef ?? ownHost;
|
|
310
|
+
const kept = ctx.config?.[PLAYHEAD_KEY];
|
|
311
|
+
const persisted = typeof kept === "number" && Number.isFinite(kept) ? kept : null;
|
|
312
|
+
const clock = useStoryClock(story.timeline?.(config) ?? null, () => persisted);
|
|
313
|
+
useClockLoop(clock, host);
|
|
314
|
+
usePersistedPlayhead(clock, persisted, (time) => latest.current.setConfig(PLAYHEAD_KEY, time));
|
|
315
|
+
useEffect(() => clock && clocks && trialId ? clocks.publish(trialId, clock) : void 0, [clock, clocks, trialId]);
|
|
254
316
|
const decorators = setup.decorators ?? NO_DECORATORS;
|
|
255
317
|
const latestError = useLatest(onError);
|
|
256
318
|
const reportError = useCallback((error) => latestError.current?.(error), [latestError]);
|
|
257
|
-
const render = (globals) => /* @__PURE__ */ jsx(
|
|
319
|
+
const render = (globals) => /* @__PURE__ */ jsx(ClockContext.Provider, { value: clock, children: /* @__PURE__ */ jsx(
|
|
258
320
|
StoryBody,
|
|
259
321
|
{
|
|
260
322
|
story,
|
|
@@ -267,20 +329,20 @@ function StoryTrial({ story, setup, ctx, hostRef, onRendered, onError }) {
|
|
|
267
329
|
resetKey,
|
|
268
330
|
onError: reportError
|
|
269
331
|
}
|
|
270
|
-
);
|
|
332
|
+
) });
|
|
271
333
|
return /* @__PURE__ */ jsx(
|
|
272
334
|
TrialHost,
|
|
273
335
|
{
|
|
274
336
|
layout: story.layout,
|
|
275
337
|
setup,
|
|
276
338
|
config: ctx.config,
|
|
277
|
-
|
|
339
|
+
hostRef: host,
|
|
278
340
|
...onRendered ? { onRendered } : {},
|
|
279
341
|
children: render
|
|
280
342
|
}
|
|
281
343
|
);
|
|
282
344
|
}
|
|
283
345
|
|
|
284
|
-
export { StoryGlobalsContext, StoryTrial, TrialFramesContext, TrialHost, createTrialFrames, useCssOverrides, useTrialFrame };
|
|
285
|
-
//# sourceMappingURL=chunk-
|
|
286
|
-
//# sourceMappingURL=chunk-
|
|
346
|
+
export { StoryGlobalsContext, StoryTrial, TrialClocksContext, TrialFramesContext, TrialHost, createTrialClocks, createTrialFrames, useCssOverrides, useTrialClock, useTrialFrame };
|
|
347
|
+
//# sourceMappingURL=chunk-GHTVXHNJ.js.map
|
|
348
|
+
//# sourceMappingURL=chunk-GHTVXHNJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/shell/trialFrames.ts","../src/shell/StoryGlobalsContext.ts","../src/shell/cssVars/overrides.ts","../src/shell/TrialHost.tsx","../src/timeline/trialClocks.ts","../src/timeline/usePersistedPlayhead.ts","../src/shell/StoryTrial.tsx"],"names":["createContext","useContext","NONE","useSyncExternalStore","useRef","useLatest","useEffect","StoryBody","jsx","useState","useCallback","TrialIdContext"],"mappings":";;;;;;;;;AA8CA,IAAM,QAAA,GAAuB,EAAE,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Ac,IAAI,CAAC,CAAA;AAC7F,EAAAE,SAAAA,CAAU,MAAO,KAAA,IAAS,MAAA,IAAU,UAAU,MAAA,CAAO,OAAA,CAAQ,OAAA,EAAS,KAAK,IAAI,MAAA,EAAY,CAAC,KAAA,EAAO,MAAA,EAAQ,OAAO,CAAC,CAAA;AAEnH,EAAA,MAAM,UAAA,GAAa,MAAM,UAAA,IAAc,aAAA;AACvC,EAAA,MAAM,WAAA,GAAcD,UAAU,OAAO,CAAA;AACrC,EAAA,MAAM,WAAA,GAAcK,WAAAA,CAAY,CAAC,KAAA,KAAmB,WAAA,CAAY,UAAU,KAAK,CAAA,EAAG,CAAC,WAAW,CAAC,CAAA;AAC/F,EAAA,MAAM,MAAA,GAAS,CAAC,OAAA,qBACdF,GAAAA,CAAC,aAAa,QAAA,EAAb,EAAsB,KAAA,EAAO,KAAA,EAC5B,QAAA,kBAAAA,GAAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAAA,MACC,KAAA;AAAA,MACA,MAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAO,GAAA,CAAI,KAAA;AAAA,MACX,QAAA;AAAA,MACA,OAAA;AAAA,MACA,UAAA;AAAA,MACA,QAAA;AAAA,MACA,OAAA,EAAS;AAAA;AAAA,GACX,EACF,CAAA;AAGF,EAAA,uBACEA,GAAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAAA,MACC,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,KAAA;AAAA,MACA,QAAQ,GAAA,CAAI,MAAA;AAAA,MACZ,OAAA,EAAS,IAAA;AAAA,MACR,GAAI,UAAA,GAAa,EAAE,UAAA,KAAe,EAAC;AAAA,MAEnC,QAAA,EAAA;AAAA;AAAA,GACH;AAEJ","file":"chunk-GHTVXHNJ.js","sourcesContent":["import { createContext, type RefObject, useCallback, useContext, useSyncExternalStore } from 'react';\nimport type { A11yReport, CapturedPicture, CssVarReport, ToFrame, Viewport } from '../protocol/messages';\n\ntype Send = (msg: ToFrame) => void;\n\n/** What an axe run in the frame came back with. */\nexport type A11yOutcome = { ok: true; report: A11yReport } | { ok: false; message: string };\n\n/** The half of a trial's frame that answers a request: each call is one round trip over the frame's channel. */\nexport interface TrialFrameCalls {\n send: Send;\n audit: () => Promise<A11yOutcome>;\n /** Rejects when the frame could not draw itself, or went away before it did. */\n capture: () => Promise<CapturedPicture>;\n}\n\n/** What trial chrome can reach of the frame its trial shows. */\nexport interface TrialFrame {\n /** Null while no frame is connected. */\n send: Send | null;\n /** The frame's latest `vars` report. */\n vars: readonly CssVarReport[];\n /** Runs axe over the story and records the answer as `a11y`. Null while no frame is connected. */\n audit: (() => Promise<A11yOutcome>) | null;\n /** What the last audit found; null until one has run against the connected frame. */\n a11y: A11yOutcome | null;\n /** The story's own picture, for an export to draw over. Null while no frame is connected. */\n capture: (() => Promise<CapturedPicture>) | null;\n /** The story's content box, as the frame last measured it; null until it has. */\n size: Viewport | null;\n}\n\n/** Each trial's frame, keyed by trial id: `FrameView` connects and reports, trial chrome reads. */\nexport interface TrialFrames {\n /** Returns a disconnect that does nothing once a newer connection replaced this one. */\n connect(trialId: string, calls: TrialFrameCalls): () => void;\n report(trialId: string, vars: readonly CssVarReport[]): void;\n reportA11y(trialId: string, outcome: A11yOutcome): void;\n reportSize(trialId: string, size: Viewport): void;\n /** The element a trial's frame is mounted in — stable across the frame reloads that replace the link,\n * because an annotation target's ref has to outlive them. */\n hostRef(trialId: string): RefObject<HTMLElement | null>;\n get(trialId: string): TrialFrame;\n subscribe(listener: () => void): () => void;\n}\n\nconst NO_FRAME: TrialFrame = { send: null, vars: [], audit: null, a11y: null, capture: null, size: null };\n\nexport function createTrialFrames(): TrialFrames {\n const frames = new Map<string, TrialFrame>();\n const hosts = new Map<string, RefObject<HTMLElement | null>>();\n const listeners = new Set<() => void>();\n const changed = () => {\n for (const listener of [...listeners]) listener();\n };\n const patch = (trialId: string, next: Partial<TrialFrame>) => {\n const frame = frames.get(trialId);\n if (!frame) return;\n frames.set(trialId, { ...frame, ...next });\n changed();\n };\n return {\n connect(trialId, calls) {\n const held = frames.get(trialId);\n frames.set(trialId, {\n send: calls.send,\n vars: [],\n audit: calls.audit,\n a11y: null,\n capture: calls.capture,\n size: held?.size ?? null,\n });\n changed();\n return () => {\n if (frames.get(trialId)?.send !== calls.send) return;\n frames.delete(trialId);\n changed();\n };\n },\n report: (trialId, vars) => patch(trialId, { vars }),\n reportA11y: (trialId, a11y) => patch(trialId, { a11y }),\n reportSize(trialId, size) {\n const frame = frames.get(trialId) ?? NO_FRAME;\n if (frame.size?.width === size.width && frame.size?.height === size.height) return;\n frames.set(trialId, { ...frame, size });\n changed();\n },\n hostRef(trialId) {\n let ref = hosts.get(trialId);\n if (!ref) {\n ref = { current: null };\n hosts.set(trialId, ref);\n }\n return ref;\n },\n get: (trialId) => frames.get(trialId) ?? NO_FRAME,\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n}\n\n/** The workshop's `TrialFrames`; `null` outside a `Workshop`. */\nexport const TrialFramesContext = createContext<TrialFrames | null>(null);\n\n/** The frame of the trial `trialId` names, re-read when it connects or reports. */\nexport function useTrialFrame(trialId: string): TrialFrame {\n const frames = useContext(TrialFramesContext);\n const subscribe = useCallback((listener: () => void) => frames?.subscribe(listener) ?? (() => {}), [frames]);\n const read = () => frames?.get(trialId) ?? NO_FRAME;\n return useSyncExternalStore(subscribe, read, read);\n}\n","import { createContext } from 'react';\nimport type { Globals } from '../protocol/messages';\n\n/** The lab's global values, which a trial's pins override. A change reaches open frames without replacing instruments. */\nexport const StoryGlobalsContext = createContext<Globals>({});\n","import { usePersistedState } from '@weasel-js/labkit';\n\nexport type CssOverrides = Readonly<Record<string, string>>;\n\nconst NONE: CssOverrides = {};\n\n/** The CSS variable overrides of the trial this is rendered inside, persisted with it. */\nexport function useCssOverrides() {\n return usePersistedState<CssOverrides>('fg-css-overrides', NONE, { scope: 'trial' });\n}\n","import { useLatest } from '@weasel-js/core';\nimport { LabBoundary, TrialIdContext } from '@weasel-js/labkit';\nimport { OverlayPortalProvider } from '@weasel-js/ui';\nimport {\n type ReactNode,\n type RefObject,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { runAxe } from '../frame/a11y';\nimport { captureElement } from '../frame/capture';\nimport { createOverrides, type Overrides, scanCssVars } from '../frame/cssVars';\nimport type { FrameSetup } from '../frame/FrameController';\nimport { createGlobalsTarget } from '../frame/globalsTarget';\nimport type { CssVarReport, Globals, Layout, ToFrame } from '../protocol/messages';\nimport { useCssOverrides } from './cssVars/overrides';\nimport { effectiveGlobals, GLOBALS_KEY } from './globals';\nimport { StoryGlobalsContext } from './StoryGlobalsContext';\nimport { type A11yOutcome, TrialFramesContext } from './trialFrames';\n\n/** Props for `TrialHost`. */\nexport interface TrialHostProps {\n layout: Layout;\n setup: FrameSetup;\n /** The trial's config, read for its `$globals` pins. */\n config: unknown;\n /** Rendered once the host element exists, with the globals in force on it. */\n children: (globals: Globals) => ReactNode;\n /** Receives the host element, for a caller with no trial to reach it through. */\n hostRef?: RefObject<HTMLElement | null>;\n /** Called once the children's first commit has painted. */\n onRendered?: () => void;\n}\n\n/** How far past the viewport a story stays mounted, so a small scroll back does not remount it. */\nconst IN_VIEW_MARGIN = '50%';\nconst VARS_SETTLE_MS = 100;\n\n/** Whether `ref`'s element is near the viewport; true where the browser cannot say. */\nfunction useInView(ref: RefObject<Element | null>): boolean {\n const [inView, setInView] = useState(true);\n useEffect(() => {\n const el = ref.current;\n if (!el || typeof IntersectionObserver === 'undefined') return;\n const observer = new IntersectionObserver(\n (entries) => {\n const last = entries.at(-1);\n if (last) setInView(last.isIntersecting);\n },\n { rootMargin: IN_VIEW_MARGIN },\n );\n observer.observe(el);\n return () => observer.disconnect();\n }, [ref]);\n return inView;\n}\n\n/** A selector matching only the element carrying `id`. */\nconst scopeOf = (id: string) => `[data-fg-host=\"${id}\"]`;\n\n/**\n * One story's box in the workshop document: what a frame document was, as an element. It applies the globals to\n * itself, keeps its CSS variable overrides on itself, contains fixed-position descendants and portals, reports its\n * vars, size and audits to the trial's frame registry, and unmounts its content while out of view.\n */\nexport function TrialHost({ layout, setup, config, children, hostRef, onRendered }: TrialHostProps) {\n const trialId = useContext(TrialIdContext);\n const frames = useContext(TrialFramesContext);\n const labGlobals = useContext(StoryGlobalsContext);\n const pins = (config as Record<string, unknown> | null | undefined)?.[GLOBALS_KEY];\n const globals = useMemo(() => effectiveGlobals(labGlobals, pins), [labGlobals, pins]);\n const [persisted] = useCssOverrides();\n const reactId = useId();\n const hostId = trialId ?? reactId;\n const [host, setHost] = useState<HTMLDivElement | null>(null);\n const elementRef = useRef<HTMLDivElement | null>(null);\n const inView = useInView(elementRef);\n const [pending, setPending] = useState(true);\n const overridesRef = useRef<Overrides | null>(null);\n const latest = useLatest({ setup, onRendered });\n\n // Everything the host owns for its lifetime: the globals target, the overrides rule, the registry connection.\n useLayoutEffect(() => {\n if (!host) return;\n const doc = host.ownerDocument;\n const scope = scopeOf(hostId);\n const { cssVarsScope } = latest.current.setup;\n const overrides = createOverrides(doc, cssVarsScope ? `${scope}, ${scope} :is(${cssVarsScope})` : scope);\n overridesRef.current = overrides;\n let lastVars: CssVarReport[] | null = null;\n let reported: string | null = null;\n const publish = (vars: CssVarReport[]) => {\n lastVars = vars;\n const key = JSON.stringify(vars);\n if (key === reported) return;\n reported = key;\n if (trialId) frames?.report(trialId, vars);\n };\n const scan = () => publish(scanCssVars(doc, overrides.has, host));\n let settleTimer: ReturnType<typeof setTimeout> | undefined;\n const ownMutation = (record: MutationRecord) =>\n overrides.owns(record.target) ||\n (record.type === 'childList' &&\n [...record.addedNodes, ...record.removedNodes].length > 0 &&\n [...record.addedNodes, ...record.removedNodes].every(overrides.owns));\n const mutations =\n typeof MutationObserver === 'undefined'\n ? null\n : new MutationObserver((records) => {\n if (records.every(ownMutation)) return;\n clearTimeout(settleTimer);\n settleTimer = setTimeout(scan, VARS_SETTLE_MS);\n });\n mutations?.observe(host, { subtree: true, childList: true, characterData: true, attributes: true });\n\n const send = (msg: ToFrame) => {\n if (msg.type !== 'vars.set') return;\n overrides.set(msg.name, msg.value);\n const at = lastVars?.findIndex((v) => v.name === msg.name) ?? -1;\n if (!lastVars || at < 0) return;\n const vars = lastVars.slice();\n vars[at] = { ...vars[at]!, overridden: overrides.has(msg.name) };\n scan();\n };\n const audit = async (): Promise<A11yOutcome> => {\n let outcome: A11yOutcome;\n try {\n outcome = { ok: true, report: await runAxe(host, { page: false }) };\n } catch (error) {\n outcome = { ok: false, message: error instanceof Error ? error.message : String(error) };\n }\n if (trialId) frames?.reportA11y(trialId, outcome);\n return outcome;\n };\n const capture = async () => captureElement(host);\n const disconnect = frames && trialId ? frames.connect(trialId, { send, audit, capture }) : () => {};\n if (frames && trialId) frames.hostRef(trialId).current = host;\n\n const sizes =\n typeof ResizeObserver === 'undefined'\n ? null\n : new ResizeObserver(() => {\n const { width, height } = host.getBoundingClientRect();\n if (trialId) frames?.reportSize(trialId, { width: Math.ceil(width), height: Math.ceil(height) });\n });\n sizes?.observe(host);\n\n return () => {\n disconnect();\n sizes?.disconnect();\n mutations?.disconnect();\n clearTimeout(settleTimer);\n overrides.dispose();\n overridesRef.current = null;\n if (frames && trialId && frames.hostRef(trialId).current === host) frames.hostRef(trialId).current = null;\n };\n }, [host, hostId, trialId, frames, latest]);\n\n // The overrides the trial persisted, put back on every mount and kept in step with the panel's edits.\n const applied = useRef<Record<string, string>>({});\n useLayoutEffect(() => {\n const overrides = overridesRef.current;\n if (!overrides) return;\n for (const name of Object.keys(applied.current)) if (!(name in persisted)) overrides.set(name, null);\n for (const [name, value] of Object.entries(persisted)) overrides.set(name, value);\n applied.current = { ...persisted };\n }, [host, persisted]);\n\n useLayoutEffect(() => {\n if (!host) return;\n const target = createGlobalsTarget(host, scopeOf(hostId));\n latest.current.setup.applyGlobals?.(globals, target);\n return () => target.dispose();\n }, [host, hostId, globals, latest]);\n\n // The host is hidden until its first commit has painted with its fonts, so a new trial never shows a jump.\n const announced = useRef(false);\n useEffect(() => {\n if (!host || !inView || announced.current) return;\n announced.current = true;\n let canceled = false;\n const done = () => {\n if (canceled) return;\n setPending(false);\n latest.current.onRendered?.();\n };\n const { fonts } = host.ownerDocument;\n if (!fonts) {\n done();\n return;\n }\n const afterPaint = () => requestAnimationFrame(done);\n void fonts.ready.then(afterPaint, afterPaint);\n return () => {\n canceled = true;\n };\n }, [host, inView, latest]);\n\n return (\n <div\n ref={(el) => {\n elementRef.current = el;\n if (hostRef) hostRef.current = el;\n setHost(el);\n }}\n className=\"fg-story\"\n data-fg-host={hostId}\n data-fg-layout={layout}\n data-pending={pending || undefined}\n >\n {host && inView ? (\n // The workshop is itself a lab; below the boundary a story sees no lab, trial or theme above it, as in a\n // document of its own.\n <LabBoundary>\n <OverlayPortalProvider container={host}>{children(globals)}</OverlayPortalProvider>\n </LabBoundary>\n ) : null}\n </div>\n );\n}\n","import { createContext, useContext, useSyncExternalStore } from 'react';\nimport type { Clock } from './clock';\n\n/** Each trial's story clock, by trial id: the story's trial publishes it, and the trial's transport reads it. */\nexport interface TrialClocks {\n /** Publishes `clock` as `trialId`'s; the returned function withdraws it. */\n publish(trialId: string, clock: Clock): () => void;\n get(trialId: string): Clock | null;\n subscribe(listener: () => void): () => void;\n}\n\nexport function createTrialClocks(): TrialClocks {\n const clocks = new Map<string, Clock>();\n const listeners = new Set<() => void>();\n const notify = () => {\n for (const listener of [...listeners]) listener();\n };\n return {\n publish(trialId, clock) {\n clocks.set(trialId, clock);\n notify();\n return () => {\n if (clocks.get(trialId) !== clock) return;\n clocks.delete(trialId);\n notify();\n };\n },\n get: (trialId) => clocks.get(trialId) ?? null,\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n}\n\nexport const TrialClocksContext = createContext<TrialClocks | null>(null);\n\nconst NEVER = () => () => {};\nconst NONE = () => null;\n\n/** The clock trial `trialId`'s story published, or null. */\nexport function useTrialClock(trialId: string): Clock | null {\n const clocks = useContext(TrialClocksContext);\n return useSyncExternalStore(clocks?.subscribe ?? NEVER, clocks ? () => clocks.get(trialId) : NONE);\n}\n","import { useLatest } from '@weasel-js/core';\nimport { useEffect, useRef } from 'react';\nimport type { Clock } from './clock';\n\n/**\n * Keeps `clock`'s paused time in the trial, through `write`, so a reload or a snapshot brings the story back there.\n * It writes when the clock stops or moves while stopped, never on a playing frame. A `persisted` value arriving from\n * outside — a snapshot loaded, a Reset — is requested of the clock, so a span set later can still hold it; null\n * stands for the span's start. Nothing is written while a request waits on a span.\n */\nexport function usePersistedPlayhead(clock: Clock | null, persisted: number | null, write: (time: number) => void): void {\n const written = useRef(persisted);\n const latestWrite = useLatest(write);\n\n useEffect(() => {\n if (!clock || persisted === written.current) return;\n written.current = persisted;\n clock.request(persisted);\n }, [clock, persisted]);\n\n useEffect(() => {\n if (!clock) return;\n return clock.subscribe(() => {\n const { playing, time } = clock.get();\n if (playing || clock.pending() !== null || time === written.current) return;\n written.current = time;\n latestWrite.current(time);\n });\n }, [clock, latestWrite]);\n}\n","import { type RenderContext, TrialIdContext } from '@weasel-js/labkit';\nimport { useLatest } from '@weasel-js/core';\nimport { memo, type RefObject, useCallback, useContext, useEffect, useRef, useState } from 'react';\nimport type { FrameSetup } from '../frame/FrameController';\nimport { StoryHost } from '../frame/StoryHost';\nimport type { Globals } from '../protocol/messages';\nimport type { Decorator, LoadedStory, StoryContext } from '../story/types';\nimport { ClockContext } from '../timeline/context';\nimport { useStoryClock } from '../timeline/StoryClock';\nimport { TrialClocksContext } from '../timeline/trialClocks';\nimport { useClockLoop } from '../timeline/useClockLoop';\nimport { usePersistedPlayhead } from '../timeline/usePersistedPlayhead';\nimport { isForgePath, PLAYHEAD_KEY, storyConfig } from './globals';\nimport { TrialHost } from './TrialHost';\n\n/** Props for `StoryTrial`. */\nexport interface StoryTrialProps {\n story: LoadedStory;\n setup: FrameSetup;\n /** The trial's config and state; the story reads and writes them through its `StoryContext`. */\n ctx: Pick<RenderContext<unknown, unknown>, 'config' | 'state' | 'setConfig' | 'setState'>;\n hostRef?: RefObject<HTMLElement | null>;\n onRendered?: () => void;\n /** A render throw, after the boundary has shown it. */\n onError?: (error: unknown) => void;\n}\n\nconst NO_DECORATORS: readonly Decorator[] = [];\n\ninterface StoryBodyProps {\n story: LoadedStory;\n config: StoryContext['config'];\n setConfig: StoryContext['setConfig'];\n state: unknown;\n setState: StoryContext['setState'];\n globals: Globals;\n decorators: readonly Decorator[];\n resetKey: number;\n onError: (error: unknown) => void;\n}\n\n/** Calls `render` only when its inputs change, as Storybook does: the lab re-renders a trial for its own reasons, and a\n * story declaring a component inside `render` remounts it on every extra call. */\nconst StoryBody = memo(function StoryBody({ story, config, setConfig, state, setState, globals, decorators, resetKey, onError }: StoryBodyProps) {\n const storyCtx: StoryContext = { config, setConfig, state, setState, globals, title: story.title, name: story.name };\n return <StoryHost story={story} ctx={storyCtx} decorators={decorators} resetKey={resetKey} onError={onError} />;\n});\n\n/** A story rendered in the workshop document, inside a `TrialHost`, from the trial's own config and state. */\nexport function StoryTrial({ story, setup, ctx, hostRef, onRendered, onError }: StoryTrialProps) {\n const latest = useLatest(ctx);\n // Kept across a write to a key forge owns, so moving the playhead or a pin does not re-render the story.\n const [heldConfig, setHeldConfig] = useState(() => storyConfig(ctx.config));\n const config = storyConfig(ctx.config, heldConfig);\n if (config !== heldConfig) setHeldConfig(config);\n\n // A trial opened on the provisional instrument starts at `null`; the story's own initial state fills it once.\n const seeded = useRef(false);\n useEffect(() => {\n if (seeded.current || ctx.state !== null || !story.initialState) return;\n seeded.current = true;\n ctx.setState(story.initialState(config));\n }, [ctx, story, config]);\n\n // Each new input retries a render the boundary caught, as the frame did on each message.\n // State, not a ref: a render React throws away takes its bump with it.\n const [input, setInput] = useState({ config, state: ctx.state, key: 0 });\n let resetKey = input.key;\n if (input.config !== config || input.state !== ctx.state) {\n resetKey = input.key + 1;\n setInput({ config, state: ctx.state, key: resetKey });\n }\n\n // Stable, as the frame's were: a story may list them as effect dependencies.\n // The pins belong to the trial; a story cannot see them, so it cannot set them either.\n const setConfig = useCallback((path: string, value: unknown) => {\n if (!isForgePath(path)) latest.current.setConfig(path, value);\n }, [latest]);\n const setState = useCallback((next: unknown) => latest.current.setState(next), [latest]);\n\n // The story's clock lives with its trial: the trial's transport reads it from the registry, the story from context.\n const trialId = useContext(TrialIdContext);\n const clocks = useContext(TrialClocksContext);\n const ownHost = useRef<HTMLElement | null>(null);\n const host = hostRef ?? ownHost;\n const kept = (ctx.config as Record<string, unknown> | null)?.[PLAYHEAD_KEY];\n const persisted = typeof kept === 'number' && Number.isFinite(kept) ? kept : null;\n const clock = useStoryClock(story.timeline?.(config) ?? null, () => persisted);\n useClockLoop(clock, host);\n usePersistedPlayhead(clock, persisted, (time) => latest.current.setConfig(PLAYHEAD_KEY, time));\n useEffect(() => (clock && clocks && trialId ? clocks.publish(trialId, clock) : undefined), [clock, clocks, trialId]);\n\n const decorators = setup.decorators ?? NO_DECORATORS;\n const latestError = useLatest(onError);\n const reportError = useCallback((error: unknown) => latestError.current?.(error), [latestError]);\n const render = (globals: Globals) => (\n <ClockContext.Provider value={clock}>\n <StoryBody\n story={story}\n config={config}\n setConfig={setConfig}\n state={ctx.state}\n setState={setState}\n globals={globals}\n decorators={decorators}\n resetKey={resetKey}\n onError={reportError}\n />\n </ClockContext.Provider>\n );\n\n return (\n <TrialHost\n layout={story.layout}\n setup={setup}\n config={ctx.config}\n hostRef={host}\n {...(onRendered ? { onRendered } : {})}\n >\n {render}\n </TrialHost>\n );\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { StoryHost } from './chunk-
|
|
1
|
+
import { StoryHost } from './chunk-5N4YP5HS.js';
|
|
2
2
|
import { sanitize } from './chunk-HRGPFQBW.js';
|
|
3
|
-
import { PROTOCOL_VERSION, isPlainObject } from './chunk-
|
|
3
|
+
import { PROTOCOL_VERSION, isPlainObject } from './chunk-KJGXJD3U.js';
|
|
4
4
|
import { f, isConfigBranch, resolveConfigSchema, schemaNodeAtPath, titleCase } from '@weasel-js/labkit/config';
|
|
5
5
|
import { Badge } from '@weasel-js/ui/components/Badge';
|
|
6
6
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
@@ -401,5 +401,5 @@ function IndexPage({ env, render }) {
|
|
|
401
401
|
}
|
|
402
402
|
|
|
403
403
|
export { IndexPage, LibraryBadge, answerSchema, describeSchema, indexEntries, indexId, isIndexId, libraryOf, openChannel, schemaFromDescription };
|
|
404
|
-
//# sourceMappingURL=chunk-
|
|
405
|
-
//# sourceMappingURL=chunk-
|
|
404
|
+
//# sourceMappingURL=chunk-JQD3MVUQ.js.map
|
|
405
|
+
//# sourceMappingURL=chunk-JQD3MVUQ.js.map
|