@joycostudio/studio 0.1.6 → 0.2.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 +28 -4
- package/dist/{chunk-6KZJEKOL.js → chunk-BBS4RC6N.js} +22 -48
- package/dist/chunk-BBS4RC6N.js.map +1 -0
- package/dist/{chunk-DEJYGBPJ.js → chunk-C6BT4KJA.js} +3 -3
- package/dist/chunk-C6BT4KJA.js.map +1 -0
- package/dist/chunk-SN5V6C26.js +28 -0
- package/dist/chunk-SN5V6C26.js.map +1 -0
- package/dist/cli.js +97 -42
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +15 -5
- package/dist/client.js +3 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/next.d.ts +3 -1
- package/dist/next.js +3 -2
- package/dist/next.js.map +1 -1
- package/dist/{protocol-DjrMADPm.d.ts → protocol-BviGBdSG.d.ts} +7 -5
- package/dist/react.d.ts +28 -5
- package/dist/react.js +37 -52
- package/dist/react.js.map +1 -1
- package/dist/runtime.d.ts +5 -2
- package/dist/runtime.js +42 -18
- package/dist/runtime.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/ui.d.ts +43 -0
- package/dist/ui.js +80 -0
- package/dist/ui.js.map +1 -0
- package/package.json +13 -4
- package/dist/chunk-6KZJEKOL.js.map +0 -1
- package/dist/chunk-DEJYGBPJ.js.map +0 -1
package/README.md
CHANGED
|
@@ -5,7 +5,8 @@ Plug project-specific tools into a `/studio` route, the app's floating debug pan
|
|
|
5
5
|
For contributor instructions on stable releases, betas, and commit previews, see the
|
|
6
6
|
[release workflow guide](../../.changeset/README.md).
|
|
7
7
|
|
|
8
|
-
A tool's controls are an [Xyz](https://hub.joyco.studio/toolbox/xyz) debug schema
|
|
8
|
+
A tool's controls are an [Xyz](https://hub.joyco.studio/toolbox/xyz) debug schema, drawn with Tweakpane or DialKit
|
|
9
|
+
(see [Choosing the controls UI](#choosing-the-controls-ui)). That same schema:
|
|
9
10
|
|
|
10
11
|
- renders the inspector in `/studio`,
|
|
11
12
|
- mounts in the app's floating pane (`?debug` / <kbd>Option</kbd>+<kbd>D</kbd>) through Xyz's `DebugManager`,
|
|
@@ -24,7 +25,8 @@ Open `/studio` and select Example. Move the Scale slider and Save to write the a
|
|
|
24
25
|
The initializer supports `app/` and `src/app/`, installs dependencies, wraps your dev command,
|
|
25
26
|
and adds generation to your typecheck script. It wraps the existing Next config with `withStudio`
|
|
26
27
|
so production builds also generate their registry on a clean checkout. The home page stays yours.
|
|
27
|
-
Use `studio init <directory>` to target another app,
|
|
28
|
+
Use `studio init <directory>` to target another app, `--ui dialkit` to draw controls with DialKit instead of
|
|
29
|
+
Tweakpane, or `--no-install` to prepare files without installing.
|
|
28
30
|
Reruns skip identical files; conflicting or edited files stop initialization before writes.
|
|
29
31
|
If generation fails, initialization restores existing files and removes newly created setup files.
|
|
30
32
|
Route checks include route groups and handlers. If Studio is already declared, install a version
|
|
@@ -131,9 +133,10 @@ in the application's TypeScript program. Scaffolded app files remain user-owned
|
|
|
131
133
|
```ts
|
|
132
134
|
// src/studio.ts (scaffolded once)
|
|
133
135
|
import { createStudio } from '@joycostudio/studio/next'
|
|
136
|
+
import { tweakpane } from '@joycostudio/studio/ui'
|
|
134
137
|
import { tools } from '../.studio/registry.generated'
|
|
135
138
|
|
|
136
|
-
export const studio = createStudio({ tools })
|
|
139
|
+
export const studio = createStudio({ tools, ui: tweakpane(() => import('tweakpane')) })
|
|
137
140
|
```
|
|
138
141
|
|
|
139
142
|
```ts
|
|
@@ -191,7 +194,7 @@ Explicit `defineTool({ id, file, initial, controls, preview })` definitions and
|
|
|
191
194
|
do not combine `tools` with `toolsDir`. To migrate, move the declarations into `studio.tool.ts`,
|
|
192
195
|
keep their IDs, replace `file`/`initial` with an optional `config` path, and default-export them.
|
|
193
196
|
Point the client at the generated registry and wrap Next config with `withStudio`.
|
|
194
|
-
For manual setups, install `@joycostudio/studio`, `@joycostudio/xyz`, and `tweakpane` in the app.
|
|
197
|
+
For manual setups, install `@joycostudio/studio`, `@joycostudio/xyz`, and `tweakpane` or `dialkit` in the app.
|
|
195
198
|
|
|
196
199
|
Live edits also work without `studio dev`, including in production. Studio shares configs between
|
|
197
200
|
same-origin previews and tabs in the same browser using `BroadcastChannel`. Peers match by tool ID,
|
|
@@ -214,6 +217,27 @@ Studio owns lazy pane creation, frame refresh, registration, and cleanup through
|
|
|
214
217
|
DebugManager. `?debug` and Option+D keep their existing behavior. The pane and command menu
|
|
215
218
|
are optional; neither is needed for `/studio`.
|
|
216
219
|
|
|
220
|
+
### Choosing the controls UI
|
|
221
|
+
|
|
222
|
+
The `/studio` inspector and the floating pane draw controls with the library the app passes as `ui`:
|
|
223
|
+
[Tweakpane](https://tweakpane.github.io/docs/) or [DialKit](https://github.com/joshpuckett/dialkit).
|
|
224
|
+
Install only the one you pick; it loads lazily from your app.
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
import { tweakpane } from '@joycostudio/studio/ui'
|
|
228
|
+
createStudio({ tools, ui: tweakpane(() => import('tweakpane')) })
|
|
229
|
+
|
|
230
|
+
// or
|
|
231
|
+
import 'dialkit/vanilla/styles.css'
|
|
232
|
+
import { dialkit } from '@joycostudio/studio/ui'
|
|
233
|
+
createStudio({ tools, ui: dialkit(() => import('dialkit/vanilla')) })
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Tool contracts don't change: the same schema validates and draws with either one.
|
|
237
|
+
`dialkit(load, options)` takes DialKit's root options (`position`, `theme`, …) for the floating pane; the inspector
|
|
238
|
+
always draws it inline, in Studio's palette. `<Studio>` and `<StudioDebug>` need `ui`; a studio that only reads
|
|
239
|
+
configs (`useToolConfig`, `studio.tool(...).config`) doesn't.
|
|
240
|
+
|
|
217
241
|
The Next.js adapter reads the endpoint passed by `studio dev`, including port overrides and
|
|
218
242
|
collision fallback. No `next.config` changes or hand-written environment variables are needed.
|
|
219
243
|
It defaults to browser-only mode without the CLI or in production. Restart the dev server when
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
diff,
|
|
3
|
+
writePath
|
|
4
|
+
} from "./chunk-SN5V6C26.js";
|
|
1
5
|
import {
|
|
2
6
|
error,
|
|
3
7
|
hasConfig,
|
|
4
8
|
validateConfig
|
|
5
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-C6BT4KJA.js";
|
|
6
10
|
|
|
7
11
|
// src/client/studio.ts
|
|
8
|
-
import {
|
|
9
|
-
button,
|
|
10
|
-
schemaValues
|
|
11
|
-
} from "@joycostudio/xyz/debug";
|
|
12
|
-
|
|
13
|
-
// src/core/diff.ts
|
|
14
|
-
function diff(before, after, path = []) {
|
|
15
|
-
const nested = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16
|
-
if (nested(before) && nested(after)) {
|
|
17
|
-
const keys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
18
|
-
return [...keys].flatMap((key) => diff(before[key], after[key], [...path, key]));
|
|
19
|
-
}
|
|
20
|
-
return JSON.stringify(before) === JSON.stringify(after) ? [] : [{ path, before, after }];
|
|
21
|
-
}
|
|
12
|
+
import { button } from "@joycostudio/xyz/debug";
|
|
22
13
|
|
|
23
14
|
// src/client/bridge.ts
|
|
24
15
|
function connectBridge(url, handlers) {
|
|
@@ -161,16 +152,6 @@ function createHistory() {
|
|
|
161
152
|
redo: () => step(future, past, "after")
|
|
162
153
|
};
|
|
163
154
|
}
|
|
164
|
-
function writePath(target, path, value) {
|
|
165
|
-
const key = path.at(-1);
|
|
166
|
-
let parent = target;
|
|
167
|
-
for (const segment of path.slice(0, -1)) {
|
|
168
|
-
const next = parent[segment];
|
|
169
|
-
parent = typeof next === "object" && next !== null ? next : parent[segment] = {};
|
|
170
|
-
}
|
|
171
|
-
if (value === void 0) delete parent[key];
|
|
172
|
-
else parent[key] = structuredClone(value);
|
|
173
|
-
}
|
|
174
155
|
|
|
175
156
|
// src/client/live.ts
|
|
176
157
|
function live(target, onWrite) {
|
|
@@ -267,23 +248,6 @@ function liveSchema(schema) {
|
|
|
267
248
|
})
|
|
268
249
|
);
|
|
269
250
|
}
|
|
270
|
-
function resetSlidersOnDoubleClick(handle) {
|
|
271
|
-
return (folder, { fields }) => {
|
|
272
|
-
const sliders = fields().filter(({ field }) => field.kind === "slider");
|
|
273
|
-
const onDoubleClick = (event) => {
|
|
274
|
-
if (handle.comparing || event.target.closest("input")) return;
|
|
275
|
-
const slider = sliders.find(({ blade }) => blade.element.contains(event.target));
|
|
276
|
-
if (slider?.field.kind !== "slider") return;
|
|
277
|
-
const saved = slider.path.reduce(
|
|
278
|
-
(values, key) => values?.[key],
|
|
279
|
-
schemaValues(handle.definition.controls(structuredClone(handle.saved)))
|
|
280
|
-
);
|
|
281
|
-
if (typeof saved === "number") slider.field.write(saved);
|
|
282
|
-
};
|
|
283
|
-
folder.element.addEventListener("dblclick", onDoubleClick);
|
|
284
|
-
return () => folder.element.removeEventListener("dblclick", onDoubleClick);
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
251
|
function everyFrame(refresh) {
|
|
288
252
|
let frame = requestAnimationFrame(function tick() {
|
|
289
253
|
refresh();
|
|
@@ -317,6 +281,11 @@ function createStudio(config, options = {}) {
|
|
|
317
281
|
const draft = () => stashed ?? raw;
|
|
318
282
|
let shared = readShared(definition.id);
|
|
319
283
|
let closed = false;
|
|
284
|
+
const warned = /* @__PURE__ */ new Set();
|
|
285
|
+
const warn = (message) => {
|
|
286
|
+
if (!warned.has(message)) console.warn(`[studio] ${definition.id}: ${message}`);
|
|
287
|
+
warned.add(message);
|
|
288
|
+
};
|
|
320
289
|
const changed = () => {
|
|
321
290
|
snapshot = structuredClone(raw);
|
|
322
291
|
handle.version++;
|
|
@@ -344,9 +313,11 @@ function createStudio(config, options = {}) {
|
|
|
344
313
|
scheduled = false;
|
|
345
314
|
const result = await bridge?.request("tool.update", { tool: definition.id, value: draft() });
|
|
346
315
|
if (!result) return;
|
|
347
|
-
if (result.ok)
|
|
348
|
-
|
|
349
|
-
|
|
316
|
+
if (result.ok) {
|
|
317
|
+
warned.clear();
|
|
318
|
+
adopt(result.data);
|
|
319
|
+
} else if (result.error !== "runtime_unavailable") {
|
|
320
|
+
warn(result.message ?? result.error);
|
|
350
321
|
await resync();
|
|
351
322
|
}
|
|
352
323
|
});
|
|
@@ -356,6 +327,9 @@ function createStudio(config, options = {}) {
|
|
|
356
327
|
if (runtimeOwnsDrafts()) push();
|
|
357
328
|
};
|
|
358
329
|
const receive = (state) => {
|
|
330
|
+
const fits = validateConfig(definition, state.draft.value);
|
|
331
|
+
if (!fits.ok) return warn(`the runtime's config doesn't fit this page's controls yet (${fits.message})`);
|
|
332
|
+
warned.clear();
|
|
359
333
|
adopt(state);
|
|
360
334
|
replace(state.draft.value);
|
|
361
335
|
browserSync?.publish(draft());
|
|
@@ -445,8 +419,7 @@ function createStudio(config, options = {}) {
|
|
|
445
419
|
};
|
|
446
420
|
return {
|
|
447
421
|
title: definition.title ?? definition.id,
|
|
448
|
-
schema: () => ({ ...liveSchema(handle.controls()), ...actions })
|
|
449
|
-
extend: resetSlidersOnDoubleClick(handle)
|
|
422
|
+
schema: () => ({ ...liveSchema(handle.controls()), ...actions })
|
|
450
423
|
};
|
|
451
424
|
},
|
|
452
425
|
async save({ force = false } = {}) {
|
|
@@ -516,6 +489,7 @@ function createStudio(config, options = {}) {
|
|
|
516
489
|
}
|
|
517
490
|
const studio = {
|
|
518
491
|
definitions: tools,
|
|
492
|
+
ui: config.ui,
|
|
519
493
|
tools: [...handles.values()],
|
|
520
494
|
tool(definition) {
|
|
521
495
|
const handle = handles.get(definition.id);
|
|
@@ -555,4 +529,4 @@ export {
|
|
|
555
529
|
everyFrame,
|
|
556
530
|
createStudio
|
|
557
531
|
};
|
|
558
|
-
//# sourceMappingURL=chunk-
|
|
532
|
+
//# sourceMappingURL=chunk-BBS4RC6N.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client/studio.ts","../src/client/bridge.ts","../src/client/browser-sync.ts","../src/client/history.ts","../src/client/live.ts","../src/client/share.ts"],"sourcesContent":["import { button, type DebugField, type DebugFolder, type DebugHost } from '@joycostudio/xyz/debug'\nimport { diff, writePath, type Change } from '../core/diff'\nimport type { ToolState } from '../core/protocol'\nimport { error, type Result } from '../core/result'\nimport { hasConfig, type StudioTool, type ToolControls, type ToolDefinition, type ToolReference } from '../core/tool'\nimport type { StudioUi } from '../ui'\nimport { validateConfig } from '../core/validate'\nimport { connectBridge, type BridgeClient, type Connection } from './bridge'\nimport { connectBrowserSync } from './browser-sync'\nimport { createHistory } from './history'\nimport { assignDeep, live } from './live'\nimport { afterLoad, clearShared, copyLink, readShared, shareUrl } from './share'\n\nexport type ToolHandle<TConfig extends object = any> = {\n readonly definition: ToolDefinition<TConfig>\n /** The live config. Writes sync to same-origin pages and, when connected, the runtime. */\n readonly config: TConfig\n /** Runtime-owned state; null while no runtime is connected or until it answers. */\n readonly state: ToolState<TConfig> | null\n /** Bumps on every config change. Handy as a React snapshot. */\n readonly version: number\n /** Called after every config change, local or remote. */\n subscribe(listener: (config: TConfig) => void): () => void\n /** The tool's Xyz schema bound to the live config. */\n controls(): ToolControls\n /** Xyz `Debuggable`: `debugManager.register(handle)` mounts this tool in the app's floating pane. */\n debug(): DebugFolder<DebugHost>\n /** The config on disk: the runtime's last reported saved value or, until one answers, the bundled `initial`. */\n readonly saved: TConfig\n /** Dotted paths where the draft differs from `saved`. Tracked locally, so it works without a runtime too. */\n readonly changes: string[]\n /** Each leaf where the draft differs from `saved`: `before` is the saved value, `after` the draft's. */\n readonly diff: Change[]\n /** The draft differs from `saved`. */\n readonly dirty: boolean\n /** True while `compare(true)` shows the saved config in place of the draft. */\n readonly comparing: boolean\n /**\n * Temporarily show `saved` (true) or go back to the draft (false). Local only: nothing\n * reaches the runtime, and edits made while comparing are dropped when it ends.\n */\n compare(showSaved: boolean): void\n /** True when `undo()` has an edit made on this page to step back through. */\n readonly canUndo: boolean\n readonly canRedo: boolean\n /**\n * Step back through edits made on this page (a slider drag counts as one), then sync the result like any\n * other edit. Only the leaves each edit changed are restored. Returns false with nothing to undo or while comparing.\n */\n undo(): boolean\n redo(): boolean\n /** Persist the draft. Needs a connected runtime. */\n save(options?: { force?: boolean }): Promise<Result<ToolState<TConfig>>>\n /**\n * Reset the draft to `saved`, with or without a runtime, then sync it like any other edit.\n * Undoable as its own step. Returns false when there is nothing to discard.\n */\n discard(): boolean\n /**\n * Reset one changed leaf (a dotted path from `changes`, or its keys, which also address keys containing dots) to its saved value, then sync it like any\n * other edit. Undoable as its own step. Returns false when that leaf is unchanged or while comparing.\n */\n revert(path: string | readonly string[]): boolean\n /**\n * A link to `base` (the current page by default) carrying the draft. Opening it on another machine applies\n * that draft as an unsaved, undoable edit; a draft that no longer fits the tool's controls is ignored.\n */\n shareUrl(base?: string | URL): string\n}\n\nexport type Studio = {\n /** Every registered tool in order, including preview-only ones. */\n readonly definitions: readonly StudioTool[]\n /** A handle per tool with a config. Preview-only tools have none. */\n readonly tools: readonly ToolHandle[]\n tool<TConfig extends object>(definition: ToolReference<TConfig>): ToolHandle<TConfig>\n readonly connection: Connection\n /** The debug UI library tools' controls are drawn with. `<Studio>` and `<StudioDebug>` need one. */\n readonly ui: StudioUi | undefined\n /** Bumps on connection or any tool state change. */\n readonly version: number\n subscribe(listener: () => void): () => void\n close(): void\n}\n\nexport type StudioOptions = {\n tools: readonly StudioTool[]\n /**\n * Runtime bridge URL (e.g. `ws://127.0.0.1:5179`). Omit or pass false for browser-only syncing, as in production.\n * Only browsers connect, so a module-scope `createStudio` is safe to evaluate during SSR.\n */\n runtime?: string | false\n /**\n * The debug UI library to draw controls with, from `@joycostudio/studio/ui`:\n * `tweakpane(() => import('tweakpane'))` or `dialkit(() => import('dialkit/vanilla'))`.\n * Required by `<Studio>` and `<StudioDebug>`; reading configs alone doesn't need one.\n */\n ui?: StudioUi\n}\n\nconst COMPARE_MESSAGE = 'joyco-studio:compare'\ntype CompareMessage = { type: typeof COMPARE_MESSAGE; tool: string; showSaved: boolean }\n\n/** Make the studio running in `target` (e.g. a preview iframe) compare `tool` as well. */\nexport function postCompare(target: Window | null | undefined, tool: string, showSaved: boolean) {\n const message: CompareMessage = { type: COMPARE_MESSAGE, tool, showSaved }\n target?.postMessage(message, location.origin)\n}\n\n/** Mark every value control live so a pane registered with `registerFrame` reflects remote edits. */\nfunction liveSchema(schema: ToolControls): ToolControls {\n return Object.fromEntries(\n Object.entries(schema).map(([key, field]): [string, DebugField<DebugHost>] => {\n if (field.kind === 'button') return [key, field]\n if (field.kind === 'folder')\n return [\n key,\n { ...field, definition: { ...field.definition, schema: () => liveSchema(field.definition.schema()) } },\n ]\n return [key, { ...field, live: true }]\n }),\n )\n}\n\n/** A `registerFrame` for Xyz's `DebugManager` / `bindDebugSchema`: refreshes live controls every animation frame. */\nexport function everyFrame(refresh: () => void) {\n let frame = requestAnimationFrame(function tick() {\n refresh()\n frame = requestAnimationFrame(tick)\n })\n return () => cancelAnimationFrame(frame)\n}\n\n/** One studio per runtime URL (or local tool set) per page; replace HMR instances without leaking transports. */\nconst instances: Map<string, Studio> = ((globalThis as { __joycoStudio?: Map<string, Studio> }).__joycoStudio ??=\n new Map())\n\nexport function createStudio(config: StudioOptions, options: Pick<StudioOptions, 'runtime'> = {}): Studio {\n const { tools } = config\n const runtime = options.runtime ?? config.runtime\n const instanceKey = runtime || JSON.stringify(tools.map(({ id, file }) => [id, file]).sort())\n let bridge: BridgeClient | null = null\n let connection: Connection = { phase: runtime ? 'connecting' : 'local' }\n let version = 0\n const studioListeners = new Set<() => void>()\n const touch = () => {\n version++\n for (const listener of studioListeners) listener()\n }\n\n /**\n * Who owns drafts: the runtime while connected, otherwise same-origin pages share them over BroadcastChannel.\n * The only place a draft change depends on the connection; reconnecting hands ownership back to the runtime.\n */\n const runtimeOwnsDrafts = () => connection.phase === 'connected'\n\n const createHandle = <TConfig extends object>(definition: ToolDefinition<TConfig>) => {\n const raw = structuredClone(definition.initial)\n const listeners = new Set<(config: TConfig) => void>()\n let pushing: Promise<unknown> = Promise.resolve()\n let scheduled = false\n /** The last saved config the runtime reported, kept while it is away; the bundled `initial` until one answers. */\n let saved: TConfig = definition.initial\n /** The draft to restore while comparing; null when showing the draft. */\n let stashed: TConfig | null = null\n const history = createHistory()\n /** A copy of `raw` as of the last change, so the next local edit can be diffed against it. */\n let snapshot = structuredClone(raw)\n /** The draft, even while `raw` shows the saved config for comparing. */\n const draft = () => stashed ?? raw\n /** A draft from this page's share link, applied once the runtime (if any) has had its say. */\n let shared = readShared(definition.id)\n let closed = false\n /** Warnings printed since the runtime last accepted a draft, so one that keeps rejecting edits logs each once. */\n const warned = new Set<string>()\n const warn = (message: string) => {\n if (!warned.has(message)) console.warn(`[studio] ${definition.id}: ${message}`)\n warned.add(message)\n }\n\n const changed = () => {\n snapshot = structuredClone(raw)\n handle.version++\n for (const listener of listeners) listener(handle.config)\n touch()\n }\n const adopt = (state: ToolState) => {\n handle.state = state as ToolState<TConfig>\n saved = state.saved.value as TConfig\n touch()\n }\n /** Replace the whole draft. While comparing, the shown saved config stays put; `changes` reads the new draft. */\n const replace = (value: TConfig) => {\n if (stashed) {\n stashed = structuredClone(value)\n touch()\n } else {\n assignDeep(raw as Record<string, unknown>, value as Record<string, unknown>)\n changed()\n }\n }\n const push = () => {\n if (scheduled || !bridge) return\n scheduled = true\n pushing = Promise.resolve().then(async () => {\n scheduled = false\n const result = await bridge?.request('tool.update', { tool: definition.id, value: draft() })\n if (!result) return\n if (result.ok) {\n warned.clear()\n adopt(result.data)\n } else if (result.error !== 'runtime_unavailable') {\n warn(result.message ?? result.error)\n await resync()\n }\n })\n }\n /**\n * Send a local draft change on: to the runtime while it owns drafts. Same-origin pages always get a copy,\n * so one opened after the runtime stops starts from it, but they only read it while no runtime is connected.\n */\n const sync = () => {\n browserSync?.publish(draft())\n if (runtimeOwnsDrafts()) push()\n }\n /**\n * The runtime's state, from a broadcast or a reply. While the runtime and this page disagree on the tool's\n * shape (one has reloaded the tool and the other hasn't yet), its draft would break these controls, so it\n * is skipped until the runtime sends one that fits.\n */\n const receive = (state: ToolState) => {\n const fits = validateConfig(definition, state.draft.value)\n if (!fits.ok) return warn(`the runtime's config doesn't fit this page's controls yet (${fits.message})`)\n warned.clear()\n adopt(state)\n replace(state.draft.value as TConfig)\n browserSync?.publish(draft())\n }\n const resync = async () => {\n const result = await bridge?.request('tool.get', { tool: definition.id })\n if (result?.ok) receive(result.data)\n }\n /** Every local change to the live config. */\n const edited = () => {\n // Edits made while comparing stay on this page and are dropped when it ends.\n if (stashed) return changed()\n history.record(snapshot, raw)\n changed()\n sync()\n }\n /** Apply the share link as a local edit, so it syncs and undoes like one. Runs once. */\n const hydrate = () => {\n if (!shared) return\n const { value } = shared\n shared = null\n afterLoad(() => {\n if (closed) return\n clearShared()\n const result = validateConfig(definition, value)\n if (!result.ok) return console.warn(`[studio] ${definition.id}: ignoring shared config: ${result.message}`)\n handle.compare(false)\n commit(() => assignDeep(raw as Record<string, unknown>, result.data as Record<string, unknown>))\n })\n }\n /** Apply a change to the draft as an undo step of its own, never merged with the edits around it. */\n const commit = (apply: () => void) => {\n const before = snapshot\n apply()\n changed()\n history.record(before, raw, { merge: false })\n sync()\n }\n const restore = (patch: ReturnType<typeof history.undo>) => {\n if (!patch) return false\n for (const { path, value } of patch) writePath(raw as Record<string, unknown>, path, value)\n changed()\n sync()\n return true\n }\n\n const handle = {\n definition,\n config: live(raw, edited),\n state: null as ToolState<TConfig> | null,\n version: 0,\n get saved(): TConfig {\n return saved\n },\n get diff() {\n return diff(saved, draft())\n },\n get changes() {\n return handle.diff.map(({ path }) => path.join('.'))\n },\n get dirty() {\n return handle.changes.length > 0\n },\n comparing: false,\n compare(showSaved: boolean) {\n if (showSaved === handle.comparing) return\n if (showSaved) stashed = structuredClone(raw)\n const next = showSaved ? saved : stashed!\n assignDeep(raw as Record<string, unknown>, next as Record<string, unknown>)\n if (!showSaved) stashed = null\n handle.comparing = showSaved\n changed()\n },\n get canUndo() {\n return history.canUndo\n },\n get canRedo() {\n return history.canRedo\n },\n undo: () => !stashed && restore(history.undo()),\n redo: () => !stashed && restore(history.redo()),\n subscribe(listener: (config: TConfig) => void) {\n listeners.add(listener)\n return () => void listeners.delete(listener)\n },\n controls: () => definition.controls(handle.config),\n debug(): DebugFolder<DebugHost> {\n const actions: ToolControls = {\n ...(runtime ? { save: button('Save', () => handle.save().then(fail), 'Saved ✓') } : {}),\n discard: button('Discard', () => void handle.discard(), 'Discarded'),\n share: button('Copy link', () => copyLink(handle.shareUrl()), 'Copied ✓'),\n }\n return {\n title: definition.title ?? definition.id,\n schema: () => ({ ...liveSchema(handle.controls()), ...actions }),\n }\n },\n async save({ force = false } = {}) {\n if (!bridge) return error('runtime_unavailable')\n await pushing\n const revision = handle.state?.draft.revision\n if (revision === undefined) return error('runtime_unavailable')\n const result = await bridge.request('tool.save', { tool: definition.id, revision, force })\n if (result.ok) adopt(result.data)\n return result as Result<ToolState<TConfig>>\n },\n discard() {\n if (!handle.dirty) return false\n const before = snapshot\n replace(saved)\n // Undoable, as a step of its own.\n if (!stashed) history.record(before, raw, { merge: false })\n sync()\n return true\n },\n revert(path: string | readonly string[]) {\n const change = handle.diff.find((change) =>\n typeof path === 'string'\n ? change.path.join('.') === path\n : change.path.length === path.length && change.path.every((key, i) => key === path[i]),\n )\n if (stashed || !change) return false\n commit(() => writePath(raw as Record<string, unknown>, change.path, change.before))\n return true\n },\n shareUrl: (base?: string | URL) => shareUrl(definition.id, draft(), base),\n /**\n * Connection changes: the runtime's draft wins on (re)connect; without one there is no runtime state.\n * A share link applies on top of the runtime's draft, or locally once the runtime proves unreachable.\n */\n connection() {\n if (runtimeOwnsDrafts()) return void resync().then(hydrate)\n handle.state = null\n if (connection.phase === 'offline') hydrate()\n },\n receive,\n close() {\n closed = true\n browserSync?.close()\n },\n }\n const browserSync = connectBrowserSync(definition, runtime, {\n enabled: () => !runtimeOwnsDrafts(),\n receive: replace,\n })\n if (!runtime) hydrate()\n return handle\n }\n\n const handles = new Map(tools.filter(hasConfig).map((definition) => [definition.id, createHandle(definition)]))\n\n // /studio asks its same-origin preview iframe to compare too (see `postCompare`).\n const onMessage = (event: MessageEvent) => {\n const message = event.data as CompareMessage | undefined\n if (event.origin !== location.origin || message?.type !== COMPARE_MESSAGE) return\n handles.get(message.tool)?.compare(message.showSaved)\n }\n if (typeof window !== 'undefined') window.addEventListener?.('message', onMessage)\n\n if (runtime && typeof window !== 'undefined') {\n bridge = connectBridge(runtime, {\n state: (state) => handles.get(state.tool)?.receive(state),\n connection(next) {\n connection = next\n for (const handle of handles.values()) handle.connection()\n touch()\n },\n })\n }\n\n const studio: Studio = {\n definitions: tools,\n ui: config.ui,\n tools: [...handles.values()],\n tool<TConfig extends object>(definition: ToolDefinition<TConfig>) {\n const handle = handles.get(definition.id)\n if (!handle) throw new Error(`[studio] tool \"${definition.id}\" was not passed to createStudio`)\n return handle as unknown as ToolHandle<TConfig>\n },\n get connection() {\n return connection\n },\n get version() {\n return version\n },\n subscribe(listener) {\n studioListeners.add(listener)\n return () => void studioListeners.delete(listener)\n },\n close() {\n bridge?.close()\n for (const handle of handles.values()) handle.close()\n studioListeners.clear()\n if (typeof window !== 'undefined') window.removeEventListener?.('message', onMessage)\n if (instances.get(instanceKey) === studio) instances.delete(instanceKey)\n },\n }\n if (typeof window !== 'undefined') {\n instances.get(instanceKey)?.close()\n instances.set(instanceKey, studio)\n }\n return studio\n}\n\nfunction fail(result: Result<unknown>) {\n if (!result.ok) throw new Error(result.message ?? result.error)\n}\n","import type { Op, Operations, ServerMessage, ToolState } from '../core/protocol'\nimport { error, type Result } from '../core/result'\n\nexport type Connection = { phase: 'local' } | { phase: 'connecting' } | { phase: 'connected' } | { phase: 'offline' }\n\ntype Pending = (result: Result<unknown>) => void\n\n/** A reconnecting WebSocket to the Studio runtime with request/response correlation. */\nexport function connectBridge(\n url: string,\n handlers: { state: (state: ToolState) => void; connection: (connection: Connection) => void },\n) {\n let socket: WebSocket | null = null\n let nextId = 0\n let retry = 0\n let timer: ReturnType<typeof setTimeout> | undefined\n let closed = false\n const pending = new Map<number, Pending>()\n\n const open = () => {\n handlers.connection({ phase: 'connecting' })\n const ws = new WebSocket(url)\n socket = ws\n ws.onopen = () => {\n retry = 0\n handlers.connection({ phase: 'connected' })\n }\n ws.onmessage = (event) => {\n const message = JSON.parse(String(event.data)) as ServerMessage\n if (message.type === 'state') return handlers.state(message.state)\n pending.get(message.id)?.(message.result)\n pending.delete(message.id)\n }\n ws.onclose = () => {\n socket = null\n for (const resolve of pending.values()) resolve(error('runtime_unavailable'))\n pending.clear()\n if (closed) return\n handlers.connection({ phase: 'offline' })\n timer = setTimeout(open, Math.min(500 * 2 ** retry++, 5000))\n }\n }\n open()\n\n return {\n request<TOp extends Op>(op: TOp, params: Operations[TOp]['params']): Promise<Result<Operations[TOp]['result']>> {\n if (socket?.readyState !== WebSocket.OPEN) return Promise.resolve(error('runtime_unavailable'))\n const id = nextId++\n socket.send(JSON.stringify({ id, op, params }))\n return new Promise((resolve) => pending.set(id, resolve as Pending))\n },\n close() {\n closed = true\n clearTimeout(timer)\n socket?.close()\n },\n }\n}\n\nexport type BridgeClient = ReturnType<typeof connectBridge>\n","import type { ToolDefinition } from '../core/tool'\nimport { validateConfig } from '../core/validate'\n\ntype Snapshot = { type: 'config'; clock: number; sender: string; value: unknown }\n\n/** Ephemeral config sharing between same-origin pages, including Studio's preview iframe. */\nexport function connectBrowserSync<T extends object>(\n definition: ToolDefinition<T>,\n runtime: string | false | undefined,\n handlers: { enabled(): boolean; receive(value: T): void },\n) {\n // Also exclude SSR and Node environments that expose their own BroadcastChannel implementation.\n if (typeof window === 'undefined' || !window.location?.origin || !window.BroadcastChannel) return null\n\n let channel: BroadcastChannel\n try {\n channel = new window.BroadcastChannel(\n JSON.stringify(['joyco-studio:config', runtime || null, definition.id, definition.file]),\n )\n } catch {\n return null\n }\n const sender = crypto.getRandomValues(new Uint32Array(4)).join('-')\n let clock = 0\n let latest: Snapshot | undefined\n let closed = false\n\n channel.onmessage = ({ data }) => {\n if (closed || !data || typeof data !== 'object') return\n if (data.type === 'request') {\n if (latest) channel.postMessage(latest)\n return\n }\n if (\n data.type !== 'config' ||\n !Number.isSafeInteger(data.clock) ||\n data.clock < 1 ||\n typeof data.sender !== 'string'\n )\n return\n clock = Math.max(clock, data.clock)\n if (!handlers.enabled()) return\n // A stable tie-break keeps simultaneous edits and multiple snapshot replies from diverging.\n if (latest && (data.clock < latest.clock || (data.clock === latest.clock && data.sender <= latest.sender))) return\n const result = validateConfig(definition, data.value)\n if (!result.ok) return\n latest = { type: 'config', clock: data.clock, sender: data.sender, value: result.data }\n handlers.receive(result.data)\n }\n // A newly mounted/reloaded preview asks existing peers for their current draft.\n channel.postMessage({ type: 'request' })\n\n return {\n publish(value: T) {\n if (closed) return\n // Wall time as a floor (peers share this browser's clock), so an edit made on a page that just opened,\n // such as an applied share link, outranks older drafts it hasn't heard about yet.\n clock = Math.max(clock + 1, Date.now())\n latest = { type: 'config', clock, sender, value: structuredClone(value) }\n channel.postMessage(latest)\n },\n close() {\n closed = true\n channel.onmessage = null\n channel.close()\n },\n }\n}\n","import { diff, type Change } from '../core/diff'\n\ntype Entry = { changes: Change[]; key: string; at: number }\n\nconst LIMIT = 100\n/** Edits to the same leaves this close together (a slider drag) undo as one step. */\nconst MERGE_MS = 500\n\n/**\n * Undo/redo for one page's edits. Entries hold only the leaves an edit changed, so stepping back\n * never reverts what another page, the runtime, or an agent changed in between.\n */\nexport function createHistory() {\n const past: Entry[] = []\n let future: Entry[] = []\n /** The newest entry while later edits to the same leaves may still extend it. */\n let open: Entry | null = null\n\n const step = (from: Entry[], to: Entry[], side: 'before' | 'after') => {\n const entry = from.pop()\n if (!entry) return null\n to.push(entry)\n open = null\n return entry.changes.map((change) => ({ path: change.path, value: change[side] }))\n }\n\n return {\n get canUndo() {\n return past.length > 0\n },\n get canRedo() {\n return future.length > 0\n },\n /** Record the edit between two snapshots. `merge: false` keeps it a step of its own (e.g. Discard). */\n record(before: unknown, after: unknown, { merge = true } = {}) {\n // Cloned so later in-place edits (e.g. to an array leaf) cannot rewrite history.\n const changes = structuredClone(diff(before, after))\n if (!changes.length) return\n future = []\n const key = JSON.stringify(changes.map(({ path }) => path))\n const now = Date.now()\n if (merge && open && open.key === key && now - open.at < MERGE_MS) {\n open.changes = open.changes.map((change, i) => ({ ...change, after: changes[i]!.after }))\n open.at = now\n // Dragged back to where it started: nothing left to undo.\n if (open.changes.every((change) => JSON.stringify(change.before) === JSON.stringify(change.after))) {\n past.pop()\n open = null\n }\n return\n }\n const entry = { changes, key, at: now }\n past.push(entry)\n if (past.length > LIMIT) past.shift()\n open = merge ? entry : null\n },\n /** The leaves to write back, or null when there is nothing to undo. */\n undo: () => step(past, future, 'before'),\n redo: () => step(future, past, 'after'),\n }\n}\n","/**\n * A deep proxy that reports every write, so plain `property(config, 'key')`\n * bindings from Xyz feed Studio without the tool author wiring callbacks.\n */\nexport function live<T extends object>(target: T, onWrite: () => void): T {\n const proxies = new WeakMap<object, object>()\n const wrap = <O extends object>(object: O): O => {\n let proxy = proxies.get(object)\n if (!proxy) {\n proxy = new Proxy(object, {\n get(target, key, receiver) {\n const value = Reflect.get(target, key, receiver)\n return typeof value === 'object' && value !== null ? wrap(value) : value\n },\n set(target, key, value, receiver) {\n const changed = Reflect.get(target, key, receiver) !== value\n const ok = Reflect.set(target, key, value, receiver)\n if (changed) onWrite()\n return ok\n },\n })\n proxies.set(object, proxy)\n }\n return proxy as O\n }\n return wrap(target)\n}\n\n/**\n * Make `target` equal `source` in place, keeping nested object identities (and every binding to them) intact.\n * Keys `source` lacks are removed.\n */\nexport function assignDeep(target: Record<string, unknown>, source: Record<string, unknown>) {\n for (const key of Object.keys(target)) if (!(key in source)) delete target[key]\n for (const [key, value] of Object.entries(source)) {\n const current = target[key]\n const nested = (v: unknown) => typeof v === 'object' && v !== null && !Array.isArray(v)\n if (nested(current) && nested(value))\n assignDeep(current as Record<string, unknown>, value as Record<string, unknown>)\n else target[key] = structuredClone(value)\n }\n}\n","/**\n * Share links carry one tool's draft in the URL: `?studio-share=<tool id>.<base64url JSON>`.\n * Opening one applies it as an unsaved edit, so teammates can review, save, or discard it.\n */\nconst PARAM = 'studio-share'\n\nconst toBase64Url = (text: string) => {\n // Byte by byte: spreading a large config into `String.fromCharCode` would exceed the argument limit.\n let binary = ''\n for (const byte of new TextEncoder().encode(text)) binary += String.fromCharCode(byte)\n return btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n}\n\nconst fromBase64Url = (data: string) =>\n new TextDecoder().decode(\n Uint8Array.from(atob(data.replace(/-/g, '+').replace(/_/g, '/')), (char) => char.charCodeAt(0)),\n )\n\n/** `base` (the current page by default) with `config` for tool `id` encoded into it. */\nexport function shareUrl(id: string, config: unknown, base: string | URL = location.href) {\n const url = new URL(base)\n url.searchParams.set(PARAM, `${id}.${toBase64Url(JSON.stringify(config))}`)\n return url.href\n}\n\n/** The config this page's URL shares for tool `id`, if any. Unvalidated. */\nexport function readShared(id: string): { value: unknown } | null {\n if (typeof window === 'undefined' || !window.location?.search) return null\n const param = new URLSearchParams(location.search).get(PARAM)\n if (!param?.startsWith(`${id}.`)) return null\n try {\n return { value: JSON.parse(fromBase64Url(param.slice(id.length + 1))) }\n } catch {\n console.warn(`[studio] ${id}: ignoring a malformed share link`)\n return null\n }\n}\n\n/** Drop the share from the address bar, so reloading after further edits doesn't reapply it. */\nexport function clearShared() {\n const url = new URL(location.href)\n if (!url.searchParams.has(PARAM)) return\n url.searchParams.delete(PARAM)\n history.replaceState(history.state, '', url)\n}\n\n/** Copy a share link. Plain-HTTP origins other than localhost have no clipboard API, so show it to copy by hand. */\nexport async function copyLink(url: string) {\n if (navigator.clipboard?.writeText) return navigator.clipboard.writeText(url)\n window.prompt('Copy this link', url)\n}\n\n/**\n * Run `apply` once the page has loaded. Routers such as Next.js rewrite the URL while hydrating,\n * which would restore a share parameter cleared any earlier.\n */\nexport function afterLoad(apply: () => void) {\n if (document.readyState === 'complete') setTimeout(apply)\n else addEventListener('load', () => setTimeout(apply), { once: true })\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,cAAiE;;;ACQnE,SAAS,cACd,KACA,UACA;AACA,MAAI,SAA2B;AAC/B,MAAI,SAAS;AACb,MAAI,QAAQ;AACZ,MAAI;AACJ,MAAI,SAAS;AACb,QAAM,UAAU,oBAAI,IAAqB;AAEzC,QAAM,OAAO,MAAM;AACjB,aAAS,WAAW,EAAE,OAAO,aAAa,CAAC;AAC3C,UAAM,KAAK,IAAI,UAAU,GAAG;AAC5B,aAAS;AACT,OAAG,SAAS,MAAM;AAChB,cAAQ;AACR,eAAS,WAAW,EAAE,OAAO,YAAY,CAAC;AAAA,IAC5C;AACA,OAAG,YAAY,CAAC,UAAU;AACxB,YAAM,UAAU,KAAK,MAAM,OAAO,MAAM,IAAI,CAAC;AAC7C,UAAI,QAAQ,SAAS,QAAS,QAAO,SAAS,MAAM,QAAQ,KAAK;AACjE,cAAQ,IAAI,QAAQ,EAAE,IAAI,QAAQ,MAAM;AACxC,cAAQ,OAAO,QAAQ,EAAE;AAAA,IAC3B;AACA,OAAG,UAAU,MAAM;AACjB,eAAS;AACT,iBAAW,WAAW,QAAQ,OAAO,EAAG,SAAQ,MAAM,qBAAqB,CAAC;AAC5E,cAAQ,MAAM;AACd,UAAI,OAAQ;AACZ,eAAS,WAAW,EAAE,OAAO,UAAU,CAAC;AACxC,cAAQ,WAAW,MAAM,KAAK,IAAI,MAAM,KAAK,SAAS,GAAI,CAAC;AAAA,IAC7D;AAAA,EACF;AACA,OAAK;AAEL,SAAO;AAAA,IACL,QAAwB,IAAS,QAA+E;AAC9G,UAAI,QAAQ,eAAe,UAAU,KAAM,QAAO,QAAQ,QAAQ,MAAM,qBAAqB,CAAC;AAC9F,YAAM,KAAK;AACX,aAAO,KAAK,KAAK,UAAU,EAAE,IAAI,IAAI,OAAO,CA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IACA,IAAI,aAAa;AACf,aAAO;AAAA,IACT;AAAA,IACA,IAAI,UAAU;AACZ,aAAO;AAAA,IACT;AAAA,IACA,UAAU,UAAU;AAClB,sBAAgB,IAAI,QAAQ;AAC5B,aAAO,MAAM,KAAK,gBAAgB,OAAO,QAAQ;AAAA,IACnD;AAAA,IACA,QAAQ;AACN,cAAQ,MAAM;AACd,iBAAW,UAAU,QAAQ,OAAO,EAAG,QAAO,MAAM;AACpD,sBAAgB,MAAM;AACtB,UAAI,OAAO,WAAW,YAAa,QAAO,sBAAsB,WAAW,SAAS;AACpF,UAAI,UAAU,IAAI,WAAW,MAAM,OAAQ,WAAU,OAAO,WAAW;AAAA,IACzE;AAAA,EACF;AACA,MAAI,OAAO,WAAW,aAAa;AACjC,cAAU,IAAI,WAAW,GAAG,MAAM;AAClC,cAAU,IAAI,aAAa,MAAM;AAAA,EACnC;AACA,SAAO;AACT;AAEA,SAAS,KAAK,QAAyB;AACrC,MAAI,CAAC,OAAO,GAAI,OAAM,IAAI,MAAM,OAAO,WAAW,OAAO,KAAK;AAChE;","names":["target","history","change"]}
|
|
@@ -51,9 +51,9 @@ function shapeMismatch(reference, value, path) {
|
|
|
51
51
|
if (expected === "object") {
|
|
52
52
|
const ref = reference;
|
|
53
53
|
const obj = value;
|
|
54
|
-
for (const key of Object.keys(obj)) if (!(key
|
|
54
|
+
for (const key of Object.keys(obj)) if (!Object.hasOwn(ref, key)) return `${path}.${key}: unknown key`;
|
|
55
55
|
for (const key of Object.keys(ref)) {
|
|
56
|
-
if (!(key
|
|
56
|
+
if (!Object.hasOwn(obj, key)) return `${path}.${key}: missing`;
|
|
57
57
|
const nested = shapeMismatch(ref[key], obj[key], `${path}.${key}`);
|
|
58
58
|
if (nested) return nested;
|
|
59
59
|
}
|
|
@@ -98,4 +98,4 @@ export {
|
|
|
98
98
|
error,
|
|
99
99
|
validateConfig
|
|
100
100
|
};
|
|
101
|
-
//# sourceMappingURL=chunk-
|
|
101
|
+
//# sourceMappingURL=chunk-C6BT4KJA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/tool.ts","../src/core/result.ts","../src/core/validate.ts"],"sourcesContent":["import type { DebugHost, DebugSchema } from '@joycostudio/xyz/debug'\n\n/** Controls as an Xyz schema. Drawn with whichever UI the app picks (`createStudio({ ui })`), so `extend` gets an unknown folder. */\nexport type ToolControls = DebugSchema<DebugHost>\n\n/**\n * An SVG icon as data: `[tag, attributes]` children of a 24×24 stroke icon.\n * Lucide's core package (`import { Palette } from 'lucide'`) exports exactly this shape.\n */\nexport type ToolIcon = readonly (readonly [tag: string, attrs: Record<string, string | number | undefined>])[]\n\ntype ToolBase = {\n /** Unique, URL-safe identifier. */\n id: string\n title?: string\n /** Shown next to the tool in /studio. Data, not a component, so contracts stay loadable in Node. */\n icon?: ToolIcon\n /** App route that renders this tool's result, shown next to the controls in /studio. */\n preview?: string\n /** Use a bare iframe for tools that already own their canvas layout and headers. */\n previewLayout?: 'canvas' | 'custom'\n}\n\n/**\n * A tool's contract. Isomorphic on purpose: the runtime loads it in Node to\n * validate and persist, the app loads it in the browser to apply and debug.\n *\n * `TConfig` is the one type that is read, edited, applied, and persisted.\n */\nexport type ToolDefinition<TConfig extends object = object> = ToolBase & {\n /** Repo-relative JSON file the config persists to. Import that same file as `initial`. */\n file: string\n /** Config used before the runtime answers (and in production). */\n initial: TConfig\n /**\n * What can be tweaked, as an Xyz schema bound to `config`.\n * Doubles as the runtime validator: every control's bounds are enforced on write.\n */\n controls: (config: TConfig) => ToolControls\n}\n\n/** A tool with nothing to tune: a sidebar entry for its preview, without an inspector or config file. */\nexport type PreviewToolDefinition = ToolBase & {\n preview: string\n file?: never\n initial?: never\n controls?: never\n}\n\n/** A tool with a config. */\nexport type AnyTool = ToolDefinition<any>\n\n/** Anything `defineTool` returns: the kind follows from whether it declares a config. */\nexport type StudioTool = AnyTool | PreviewToolDefinition\n\nexport const hasConfig = (tool: StudioTool): tool is AnyTool => tool.controls !== undefined\n\n/** Filled by .studio/types.generated.ts in each consuming project. */\nexport interface DiscoveredToolConfigs {}\n\n/** A discovered declaration is resolved into a full definition by the generated registry. */\nexport type DiscoveredToolDefinition<TConfig extends object = object> = ToolBase & {\n /** JSON source relative to this tool file, or a tsconfig path alias. Defaults to ./config.json. */\n config?: string\n controls: (config: TConfig) => ToolControls\n file?: never\n initial?: never\n}\nexport type ToolReference<TConfig extends object> = Pick<ToolDefinition<TConfig>, 'id' | 'controls'>\nexport type ConfigOf<TTool> = TTool extends ToolReference<infer TConfig> ? TConfig : never\n\nconst ID = /^[a-z0-9][a-z0-9-]*$/\n\n/** Discovered tools infer their config from the generated ID-to-JSON type map. */\nexport function defineTool<K extends keyof DiscoveredToolConfigs & string>(\n tool: Omit<DiscoveredToolDefinition<Extract<DiscoveredToolConfigs[K], object>>, 'id'> & { id: K },\n): DiscoveredToolDefinition<Extract<DiscoveredToolConfigs[K], object>>\n/** Existing explicitly registered tools remain supported. */\nexport function defineTool<TConfig extends object>(tool: ToolDefinition<TConfig>): ToolDefinition<TConfig>\nexport function defineTool(tool: PreviewToolDefinition): PreviewToolDefinition\n/** A discovered preview-only tool may infer its preview from the adjacent page. */\nexport function defineTool(\n tool: ToolBase & { controls?: never; config?: never; file?: never; initial?: never },\n): ToolBase\nexport function defineTool(tool: StudioTool | DiscoveredToolDefinition<any> | ToolBase) {\n if (!ID.test(tool.id)) throw new Error(`[studio] tool id \"${tool.id}\" must be kebab-case`)\n const value = tool as Partial<AnyTool>\n if (value.file !== undefined || value.initial !== undefined) {\n if (value.file === undefined || value.initial === undefined || value.controls === undefined)\n throw new Error(`[studio] tool \"${tool.id}\" needs all of file, initial, and controls, or none of them`)\n }\n return tool\n}\n\nexport type StudioConfig = {\n /** Explicit registry; omit to enable convention-based discovery. */\n tools?: readonly StudioTool[]\n /**\n * Directory to scan and watch for `studio.tool.ts` files, relative to\n * the project root.\n *\n * Defaults to the active Next.js app directory: `app/` or `src/app/`.\n * Set a narrower directory to reduce scanning and discovery triggers.\n * This does not change preview URLs.\n *\n * @example 'src/app/experiments'\n */\n toolsDir?: string\n /** Runtime WebSocket and HTTP MCP port. Defaults to 5179. */\n port?: number\n /** Browser origins allowed on the bridge and MCP endpoint. Defaults to localhost origins. */\n origins?: readonly string[]\n /** Running app URL (e.g. http://localhost:3000), used for MCP preview captures. */\n appUrl?: string\n}\n\nexport const DEFAULT_PORT = 5179\n\nexport function defineConfig<T extends StudioConfig>(config: T): T {\n return config\n}\n","export type Success<T> = { ok: true; data: T }\n\nexport type Failure = {\n ok: false\n /** snake_case wire code, e.g. `invalid_config`. */\n error: string\n message?: string\n}\n\nexport type Result<T> = Success<T> | Failure\n\nexport const success = <T>(data: T): Success<T> => ({ ok: true, data })\n\nexport const error = (code: string, message?: string): Failure => ({\n ok: false,\n error: code,\n ...(message === undefined ? {} : { message }),\n})\n","import { error, success, type Result } from './result'\nimport type { ToolControls, ToolDefinition } from './tool'\n\n/**\n * Accept `candidate` as a config for `tool` only if it has the exact shape of\n * `tool.initial` and every control in `tool.controls` accepts its value.\n * Returns a detached copy, never the input.\n */\nexport function validateConfig<TConfig extends object>(\n tool: ToolDefinition<TConfig>,\n candidate: unknown,\n): Result<TConfig> {\n const mismatch = shapeMismatch(tool.initial, candidate, 'config')\n if (mismatch) return error('invalid_config', mismatch)\n const config = structuredClone(candidate) as TConfig\n const invalid = invalidControl(tool.controls(config))\n return invalid ? error('invalid_config', invalid) : success(config)\n}\n\nfunction kind(value: unknown) {\n if (value === null) return 'null'\n if (Array.isArray(value)) return 'array'\n return typeof value\n}\n\nfunction shapeMismatch(reference: unknown, value: unknown, path: string): string | null {\n const expected = kind(reference)\n if (kind(value) !== expected) return `${path}: expected ${expected}, got ${kind(value)}`\n if (expected === 'number' && !Number.isFinite(value)) return `${path}: expected a finite number`\n if (expected === 'array') {\n const [first] = reference as unknown[]\n if (first === undefined) return null\n for (const [index, item] of (value as unknown[]).entries()) {\n const nested = shapeMismatch(first, item, `${path}[${index}]`)\n if (nested) return nested\n }\n }\n if (expected === 'object') {\n const ref = reference as Record<string, unknown>\n const obj = value as Record<string, unknown>\n for (const key of Object.keys(obj)) if (!Object.hasOwn(ref, key)) return `${path}.${key}: unknown key`\n for (const key of Object.keys(ref)) {\n if (!Object.hasOwn(obj, key)) return `${path}.${key}: missing`\n const nested = shapeMismatch(ref[key], obj[key], `${path}.${key}`)\n if (nested) return nested\n }\n }\n return null\n}\n\nconst isRgb = (value: unknown) =>\n typeof value === 'object' &&\n value !== null &&\n ['r', 'g', 'b'].every((channel) => Number.isFinite((value as Record<string, unknown>)[channel]))\n\nfunction invalidControl(schema: ToolControls, path = ''): string | null {\n for (const [key, field] of Object.entries(schema)) {\n if (field.kind === 'button') continue\n const name = `${path}${field.label ?? key}`\n if (field.kind === 'folder') {\n const nested = invalidControl(field.definition.schema(), `${name}/`)\n if (nested) return nested\n continue\n }\n const value: unknown = field.read()\n if (field.kind === 'slider') {\n if (typeof value !== 'number' || value < field.min || value > field.max)\n return `${name}: expected a number in [${field.min}, ${field.max}], got ${JSON.stringify(value)}`\n } else if (field.kind === 'bool') {\n if (typeof value !== 'boolean') return `${name}: expected a boolean`\n } else if (field.kind === 'select') {\n const options = Object.values(field.options)\n if (!options.includes(value as string | number))\n return `${name}: expected one of ${JSON.stringify(options)}, got ${JSON.stringify(value)}`\n } else if (field.kind === 'color-string') {\n if (typeof value !== 'string') return `${name}: expected a color string`\n } else if (field.kind === 'color') {\n if (!isRgb(value)) return `${name}: expected an { r, g, b } color`\n }\n }\n return null\n}\n"],"mappings":";AAuDO,IAAM,YAAY,CAAC,SAAsC,KAAK,aAAa;AAgBlF,IAAM,KAAK;AAaJ,SAAS,WAAW,MAA6D;AACtF,MAAI,CAAC,GAAG,KAAK,KAAK,EAAE,EAAG,OAAM,IAAI,MAAM,qBAAqB,KAAK,EAAE,sBAAsB;AACzF,QAAM,QAAQ;AACd,MAAI,MAAM,SAAS,UAAa,MAAM,YAAY,QAAW;AAC3D,QAAI,MAA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U,UAAW,QAAO,GAAG,IAAI;AAAA,IAChD,WAAW,MAAM,SAAS,UAAU;AAClC,YAAM,UAAU,OAAO,OAAO,MAAM,OAAO;AAC3C,UAAI,CAAC,QAAQ,SAAS,KAAwB;AAC5C,eAAO,GAAG,IAAI,qBAAqB,KAAK,UAAU,OAAO,CAAC,SAAS,KAAK,UAAU,KAAK,CAAC;AAAA,IAC5F,WAAW,MAAM,SAAS,gBAAgB;AACxC,UAAI,OAAO,UAAU,SAAU,QAAO,GAAG,IAAI;AAAA,IAC/C,WAAW,MAAM,SAAS,SAAS;AACjC,UAAI,CAAC,MAAM,KAAK,EAAG,QAAO,GAAG,IAAI;AAAA,IACnC;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/core/diff.ts
|
|
2
|
+
function diff(before, after, path = []) {
|
|
3
|
+
const nested = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
if (nested(before) && nested(after)) {
|
|
5
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)]);
|
|
6
|
+
return [...keys].flatMap((key) => diff(before[key], after[key], [...path, key]));
|
|
7
|
+
}
|
|
8
|
+
return JSON.stringify(before) === JSON.stringify(after) ? [] : [{ path, before, after }];
|
|
9
|
+
}
|
|
10
|
+
var define = (target, key, value) => Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });
|
|
11
|
+
function writePath(target, path, value) {
|
|
12
|
+
const key = path.at(-1);
|
|
13
|
+
let parent = target;
|
|
14
|
+
for (const segment of path.slice(0, -1)) {
|
|
15
|
+
const next = Object.hasOwn(parent, segment) ? parent[segment] : void 0;
|
|
16
|
+
if (typeof next !== "object" || next === null) define(parent, segment, {});
|
|
17
|
+
parent = parent[segment];
|
|
18
|
+
}
|
|
19
|
+
if (value === void 0) {
|
|
20
|
+
if (Object.hasOwn(parent, key)) delete parent[key];
|
|
21
|
+
} else define(parent, key, structuredClone(value));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
diff,
|
|
26
|
+
writePath
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=chunk-SN5V6C26.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/diff.ts"],"sourcesContent":["export type Change = { path: string[]; before: unknown; after: unknown }\n\n/** Every leaf that differs between two configs of the same shape. Arrays count as leaves. */\nexport function diff(before: unknown, after: unknown, path: string[] = []): Change[] {\n const nested = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n if (nested(before) && nested(after)) {\n const keys = new Set([...Object.keys(before), ...Object.keys(after)])\n return [...keys].flatMap((key) => diff(before[key], after[key], [...path, key]))\n }\n return JSON.stringify(before) === JSON.stringify(after) ? [] : [{ path, before, after }]\n}\n\n/** Set an own data property, never an inherited setter such as `__proto__`. */\nconst define = (target: Record<string, unknown>, key: string, value: unknown) =>\n Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true })\n\n/**\n * Write `value` at `path` in place; undefined removes the key (it did not exist before the edit).\n * Walks own properties only, so a path through `__proto__` can't reach `Object.prototype`.\n */\nexport function writePath(target: Record<string, unknown>, path: string[], value: unknown) {\n const key = path.at(-1)!\n let parent = target\n for (const segment of path.slice(0, -1)) {\n const next = Object.hasOwn(parent, segment) ? parent[segment] : undefined\n if (typeof next !== 'object' || next === null) define(parent, segment, {})\n parent = parent[segment] as Record<string, unknown>\n }\n if (value === undefined) {\n if (Object.hasOwn(parent, key)) delete parent[key]\n } else define(parent, key, structuredClone(value))\n}\n"],"mappings":";AAGO,SAAS,KAAK,QAAiB,OAAgB,OAAiB,CAAC,GAAa;AACnF,QAAM,SAAS,CAAC,UACd,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AACrE,MAAI,OAAO,MAAM,KAAK,OAAO,KAAK,GAAG;AACnC,UAAM,OAAO,oBAAI,IAAI,CAAC,GAAG,OAAO,KAAK,MAAM,GAAG,GAAG,OAAO,KAAK,KAAK,CAAC,CAAC;AACpE,WAAO,CAAC,GAAG,IAAI,EAAE,QAAQ,CAAC,QAAQ,KAAK,OAAO,GAAG,GAAG,MAAM,GAAG,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;AAAA,EACjF;AACA,SAAO,KAAK,UAAU,MAAM,MAAM,KAAK,UAAU,KAAK,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,QAAQ,MAAM,CAAC;AACzF;AAGA,IAAM,SAAS,CAAC,QAAiC,KAAa,UAC5D,OAAO,eAAe,QAAQ,KAAK,EAAE,OAAO,UAAU,MAAM,YAAY,MAAM,cAAc,KAAK,CAAC;AAM7F,SAAS,UAAU,QAAiC,MAAgB,OAAgB;AACzF,QAAM,MAAM,KAAK,GAAG,EAAE;AACtB,MAAI,SAAS;AACb,aAAW,WAAW,KAAK,MAAM,GAAG,EAAE,GAAG;AACvC,UAAM,OAAO,OAAO,OAAO,QAAQ,OAAO,IAAI,OAAO,OAAO,IAAI;AAChE,QAAI,OAAO,SAAS,YAAY,SAAS,KAAM,QAAO,QAAQ,SAAS,CAAC,CAAC;AACzE,aAAS,OAAO,OAAO;AAAA,EACzB;AACA,MAAI,UAAU,QAAW;AACvB,QAAI,OAAO,OAAO,QAAQ,GAAG,EAAG,QAAO,OAAO,GAAG;AAAA,EACnD,MAAO,QAAO,QAAQ,KAAK,gBAAgB,KAAK,CAAC;AACnD;","names":[]}
|