@niscorp/loom 0.3.0 → 0.3.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/CHANGELOG.md +12 -0
- package/DESIGN.md +33 -6
- package/README.md +24 -3
- package/dist/{chunk-D743DI5J.js → chunk-27OMOR7I.js} +2 -2
- package/dist/chunk-27OMOR7I.js.map +1 -0
- package/dist/{chunk-PTXRAWJX.js → chunk-67D727GH.js} +2 -13
- package/dist/chunk-67D727GH.js.map +1 -0
- package/dist/{chunk-MIRMQPUE.js → chunk-BU5TULRP.js} +3 -3
- package/dist/chunk-BU5TULRP.js.map +1 -0
- package/dist/{chunk-TV4U22MY.js → chunk-DEZGKUTO.js} +4 -10
- package/dist/chunk-DEZGKUTO.js.map +1 -0
- package/dist/{chunk-DWQWPBBV.js → chunk-HHPSU7IA.js} +4 -8
- package/dist/chunk-HHPSU7IA.js.map +1 -0
- package/dist/{chunk-TCCN6LKV.js → chunk-IQMWPPHW.js} +4 -14
- package/dist/chunk-IQMWPPHW.js.map +1 -0
- package/dist/{chunk-A3UOFGL4.js → chunk-LVDY6FUH.js} +3 -3
- package/dist/chunk-LVDY6FUH.js.map +1 -0
- package/dist/{chunk-IZ5B6IMX.js → chunk-OFKHIREC.js} +5 -5
- package/dist/chunk-OFKHIREC.js.map +1 -0
- package/dist/{chunk-XTY7XO5C.js → chunk-VMOYMYMV.js} +3 -8
- package/dist/chunk-VMOYMYMV.js.map +1 -0
- package/dist/index.cjs +2 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/{loom-editor-Clohg49u.d.ts → loom-editor-BthwIGIZ.d.cts} +1 -4
- package/dist/{loom-editor-MACwUjLC.d.cts → loom-editor-CHtjjiBp.d.ts} +1 -4
- package/dist/plugins/nova/index.cjs +0 -4
- package/dist/plugins/nova/index.cjs.map +1 -1
- package/dist/plugins/nova/index.d.cts +1 -1
- package/dist/plugins/nova/index.d.ts +1 -1
- package/dist/plugins/nova/index.js +3 -3
- package/dist/plugins/nova/react/index.cjs +0 -4
- package/dist/plugins/nova/react/index.cjs.map +1 -1
- package/dist/plugins/nova/react/index.d.cts +2 -2
- package/dist/plugins/nova/react/index.d.ts +2 -2
- package/dist/plugins/nova/react/index.js +3 -3
- package/dist/plugins/nova/react/index.js.map +1 -1
- package/dist/plugins/prism/index.cjs.map +1 -1
- package/dist/plugins/prism/index.d.cts +1 -3
- package/dist/plugins/prism/index.d.ts +1 -3
- package/dist/plugins/prism/index.js +2 -2
- package/dist/plugins/prism/react/index.cjs +6 -16
- package/dist/plugins/prism/react/index.cjs.map +1 -1
- package/dist/plugins/prism/react/index.d.cts +2 -2
- package/dist/plugins/prism/react/index.d.ts +2 -2
- package/dist/plugins/prism/react/index.js +8 -12
- package/dist/plugins/prism/react/index.js.map +1 -1
- package/dist/plugins/vex/index.cjs +0 -5
- package/dist/plugins/vex/index.cjs.map +1 -1
- package/dist/plugins/vex/index.d.cts +1 -5
- package/dist/plugins/vex/index.d.ts +1 -5
- package/dist/plugins/vex/index.js +2 -2
- package/dist/plugins/vex/react/index.cjs +0 -5
- package/dist/plugins/vex/react/index.cjs.map +1 -1
- package/dist/plugins/vex/react/index.d.cts +2 -2
- package/dist/plugins/vex/react/index.d.ts +2 -2
- package/dist/plugins/vex/react/index.js +6 -6
- package/dist/plugins/vex/react/index.js.map +1 -1
- package/dist/react/index.cjs +2 -29
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +7 -7
- package/dist/react/index.js.map +1 -1
- package/dist/{types-l8sDxrMR.d.cts → types-V5kJWZJn.d.cts} +2 -27
- package/dist/{types-l8sDxrMR.d.ts → types-V5kJWZJn.d.ts} +2 -27
- package/package.json +7 -7
- package/dist/chunk-A3UOFGL4.js.map +0 -1
- package/dist/chunk-D743DI5J.js.map +0 -1
- package/dist/chunk-DWQWPBBV.js.map +0 -1
- package/dist/chunk-IZ5B6IMX.js.map +0 -1
- package/dist/chunk-MIRMQPUE.js.map +0 -1
- package/dist/chunk-PTXRAWJX.js.map +0 -1
- package/dist/chunk-TCCN6LKV.js.map +0 -1
- package/dist/chunk-TV4U22MY.js.map +0 -1
- package/dist/chunk-XTY7XO5C.js.map +0 -1
|
@@ -2,7 +2,7 @@ import { FC } from 'react';
|
|
|
2
2
|
import { ZodType } from 'zod';
|
|
3
3
|
import { LayoutNode } from '@niscorp/nova';
|
|
4
4
|
import { NovaComponent } from '@niscorp/nova/adapters/react';
|
|
5
|
-
import { i as FieldContext, L as LoomEditor$1, f as LoomArtifact } from './types-
|
|
5
|
+
import { i as FieldContext, L as LoomEditor$1, f as LoomArtifact } from './types-V5kJWZJn.js';
|
|
6
6
|
|
|
7
7
|
type LoomEditorPlugin = {
|
|
8
8
|
name: string;
|
|
@@ -15,11 +15,8 @@ type LoomEditorPlugin = {
|
|
|
15
15
|
mount?: (editor: LoomEditor$1) => void;
|
|
16
16
|
};
|
|
17
17
|
type LoomEditorProps = {
|
|
18
|
-
/** The loaded plugins (capabilities). Read once on mount. */
|
|
19
18
|
plugins: LoomEditorPlugin[];
|
|
20
|
-
/** The artifact to open. Read once on mount; give a new `key` to switch. */
|
|
21
19
|
artifact: LoomArtifact;
|
|
22
|
-
/** Called with the live documents whenever they change. */
|
|
23
20
|
onChange?: (documents: Record<string, unknown>) => void;
|
|
24
21
|
};
|
|
25
22
|
declare const LoomEditor: FC<LoomEditorProps>;
|
|
@@ -65,12 +65,8 @@ var novaPlugin = (config) => ({
|
|
|
65
65
|
name: "nova",
|
|
66
66
|
documents: {
|
|
67
67
|
layout: layoutSchema(config.manifest),
|
|
68
|
-
// `data` is freeform (its shape follows the layout's bindings), so it has no
|
|
69
|
-
// schema. The plugin builds its editing layout from the data's keys instead.
|
|
70
68
|
data: dataLayout
|
|
71
69
|
},
|
|
72
|
-
// The preview is a Nova concept, not a Loom one, so the plugin contributes it:
|
|
73
|
-
// a view canvas rendering the preview component bound to the live documents.
|
|
74
70
|
mount: (editor) => mountView(editor, previewAction, (e) => ({ documents: e.documents }))
|
|
75
71
|
});
|
|
76
72
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/view.ts","../../../src/plugins/nova/schema.ts","../../../src/compile/parse.ts","../../../src/plugins/nova/data.layout.ts","../../../src/plugins/nova/preview.layout.ts","../../../src/plugins/nova/preview.action.ts","../../../src/plugins/nova/index.ts"],"names":["z"],"mappings":";;;;;AAQO,IAAM,SAAA,GAAY,CACvB,MAAA,EACA,MAAA,EACA,IAAA,KACS;AACT,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,KAAA,CAAM,eAAe,MAAM,CAAA;AAC3B,EAAA,KAAA,CAAM,SAAA,CAAU,EAAE,EAAA,EAAI,MAAA,CAAO,IAAI,OAAA,EAAS,MAAA,CAAO,IAAI,CAAA;AACrD,EAAA,MAAM,WAAW,KAAA,CAAM,cAAA,CAAe,MAAA,CAAO,EAAE,EAAE,MAAA,EAAQ,EAAA;AACzD,EAAA,IAAI,aAAa,MAAA,EAAW;AAC5B,EAAA,MAAM,OAAO,MAAY;AACvB,IAAA,KAAA,CAAM,WAAW,QAAQ,CAAA,EAAG,OAAA,CAAQ,IAAA,CAAK,MAAM,CAAC,CAAA;AAAA,EAClD,CAAA;AACA,EAAA,MAAA,CAAO,EAAA,CAAG,UAAU,IAAI,CAAA;AACxB,EAAA,IAAA,EAAK;AACP,CAAA;ACZO,IAAM,YAAA,GAAe,CAAC,QAAA,KAAqD;AAChF,EAAA,MAAM,CAAC,KAAA,EAAO,GAAG,IAAI,CAAA,GAAI,QAAA;AACzB,EAAA,IAAI,KAAA,KAAU,MAAA,EAAW,MAAM,IAAI,MAAM,oCAAoC,CAAA;AAE7E,EAAA,MAAM,KAAA,GAAiBA,KAAA,CAAE,IAAA,CAAK,MAAM,UAAU,CAAA;AAC9C,EAAA,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IAAI,CAAA,CAAE,GAAA,CAAI,CAAC,GAAA,KAAQ,QAAA,CAAS,GAAA,EAAK,IAAA,CAAK,GAAG,CAAC,CAAC;AAAA,GACnE;AACF,CAAA;;;ACfO,IAAM,OAAA,GAAU;AAIhB,IAAM,aAAA,GAA4B;AAAA,EACvC,SAAA,EAAW,OAAA;AAAA,EACX,KAAA,EAAO,EAAE,SAAA,EAAW,aAAA;AACtB,CAAA;;;ACPO,IAAM,aAAA,GAAkC;AAAA,EAC7C,EAAA,EAAI,OAAA;AAAA,EACJ,MAAA,EAAQ,aAAA;AAAA,EACR,IAAA,EAAM,EAAE,SAAA,EAAW,EAAC;AACtB,CAAA;;;ACSO,IAAM,UAAA,GAAa,CAAC,MAAA,MAA0C;AAAA,EACnE,IAAA,EAAM,MAAA;AAAA,EACN,SAAA,EAAW;AAAA,IACT,MAAA,EAAQ,YAAA,CAAa,MAAA,CAAO,QAAQ,CAAA;AAAA;AAAA;AAAA,IAGpC,IAAA,EAAM;AAAA,GACR;AAAA;AAAA;AAAA,EAGA,KAAA,EAAO,CAAC,MAAA,KAAW,SAAA,CAAU,MAAA,EAAQ,aAAA,EAAe,CAAC,CAAA,MAAO,EAAE,SAAA,EAAW,CAAA,CAAE,SAAA,EAAU,CAAE;AACzF,CAAA","file":"index.cjs","sourcesContent":["import type { ActionDefinition } from '@niscorp/nova';\nimport type { LoomEditor } from './types.js';\n\n// Mount a view canvas: register `action`, add a canvas that renders it, and keep\n// its data in sync with the editor's live state — `read(editor)` is pushed onto\n// the canvas on every `change`. The canvas id is the action id. Used by the\n// default plugins (jsonviewer, validation) and any domain preview; the contributor\n// owns the canvas, so a later plugin can `shell.removeCanvas(action.id)` to drop it.\nexport const mountView = (\n editor: LoomEditor,\n action: ActionDefinition,\n read: (editor: LoomEditor) => Record<string, unknown>,\n): void => {\n const { shell } = editor;\n shell.registerAction(action);\n shell.addCanvas({ id: action.id, initial: action.id });\n const instance = shell.getCanvasState(action.id).active?.id;\n if (instance === undefined) return;\n const sync = (): void => {\n shell.getRuntime(instance)?.setData(read(editor));\n };\n editor.on('change', sync);\n sync();\n};\n","import { z, type ZodType } from 'zod';\n\n// The framework-free shape of one component in the manifest: its name, the schema\n// for its props, and whether it nests children. The render function (React, Vue,\n// …) lives in the per-framework surface, not here.\nexport type NovaComponentShape = { name: string; props: ZodType; container?: boolean };\n\n// Build the layout document's schema. Each component becomes a branch\n// discriminated by its `component` literal, carrying its prop schema; containers\n// recurse through `children`. This is the shape of a Nova ComponentNode, so the\n// edited `layout` document is itself a layout.\nexport const layoutSchema = (manifest: readonly NovaComponentShape[]): ZodType => {\n const [first, ...rest] = manifest;\n if (first === undefined) throw new Error('nova plugin: the manifest is empty');\n\n const recur: ZodType = z.lazy(() => layoutNode);\n const branch = (component: NovaComponentShape) =>\n z.object({\n component: z.literal(component.name),\n props: component.props,\n ...(component.container === true ? { children: z.array(recur) } : {}),\n });\n\n const layoutNode = z.discriminatedUnion('component', [branch(first), ...rest.map(branch)]);\n return layoutNode;\n};\n","import type { ZodType } from 'zod';\nimport type {\n CompileOptions,\n EmptyValue,\n EnumOption,\n Field,\n FieldKind,\n FieldMeta,\n ObjectField,\n Pattern,\n Variant,\n} from './types.js';\n\n// parse — turn a Zod schema into Loom's field model (IR). The only Zod-aware\n// code in the package, and pure data in / pure data out: no Nova. `parseByType`\n// is keyed by Zod's own `def.type` tag, so the type vocabulary lives as table\n// keys, not scattered checks.\n//\n// A recursive schema (`z.lazy`, or an object whose getter returns itself) would\n// expand forever. The walk carries the set of schemas it is currently inside;\n// re-entering one is a back-edge, emitted as a `self` marker and recorded so\n// the object it points back to can be tagged `recursive`. Expansion stops at\n// the cycle — the document, not the schema, decides how deep an editor goes.\n\n// The slice of a Zod schema's internal definition that parsing reads.\ntype ZodDef = {\n type: string;\n innerType?: ZodType;\n element?: ZodType;\n shape?: Record<string, ZodType>;\n entries?: Record<string, unknown>;\n defaultValue?: unknown;\n format?: string;\n checks?: ReadonlyArray<{ def?: { format?: string } }>;\n discriminator?: string;\n options?: readonly ZodType[];\n items?: readonly ZodType[];\n values?: readonly unknown[];\n getter?: () => ZodType;\n};\n\n// Zod types every schema's `.def` as the base `$ZodTypeDef` (just the `type`\n// discriminant); the per-type fields we read live on the concrete defs. This\n// views `.def` through the structural slice above — the single place the\n// parser depends on Zod's internal shape.\nconst defOf = (schema: ZodType): ZodDef => schema.def as ZodDef;\n\n// While walking, the schemas currently on the stack (cycle detection) and the\n// schemas a `self` pointed back to (so the matching object is tagged recursive).\n// Keyed by def, not instance: `.describe()`/`.meta()` clone the wrapper but\n// share the def, so a described alias of a recursive schema must read as the\n// schema itself — or every back-edge re-expands the whole thing one more level.\ntype Walk = { stack: Set<ZodDef>; targets: Set<ZodDef> };\n\n// ─── Reading Zod ─────────────────────────────────────────────\n\n// `safeint` is Zod's format tag for an integer-constrained number — the one\n// Zod-vocabulary token this file matches on.\nconst INTEGER_FORMAT = 'safeint';\n\nconst stringFormat = (schema: ZodType): string | undefined => {\n const def = defOf(schema);\n if (def.format !== undefined) return def.format;\n for (const check of def.checks ?? []) {\n if (check.def?.format !== undefined) return check.def.format;\n }\n return undefined;\n};\n\nconst isInteger = (schema: ZodType): boolean => {\n const def = defOf(schema);\n if (def.format === INTEGER_FORMAT) return true;\n return (def.checks ?? []).some((check) => check.def?.format === INTEGER_FORMAT);\n};\n\nconst enumOptions = (schema: ZodType): EnumOption[] =>\n Object.values(defOf(schema).entries ?? {}).map((value) => ({ value, label: String(value) }));\n\nconst objectFields = (schema: ZodType, walk: Walk): ObjectField[] =>\n Object.entries(defOf(schema).shape ?? {}).map(([key, value]) => ({\n key,\n // A property is optional when the schema accepts `undefined` for it\n // (covers `.optional()` and `.default()`) — asked of Zod, not inferred.\n required: !value.safeParse(undefined).success,\n field: parseField(value, walk),\n }));\n\n// ─── Union discrimination ────────────────────────────────────\n// For each branch, the cheapest fact that tells it apart from its siblings: the\n// declared tag's value, else a key only it carries, else a JS type only it is.\n// One function covers tagged, structural, and mixed unions; a branch that none\n// of these distinguish makes the whole union fall back to the raw editor.\n\nconst branchKeys = (branch: ZodType): string[] => Object.keys(defOf(branch).shape ?? {});\n\n// The branch's JS type, when it's one the runtime matcher checks (Zod names\n// these the same as `typeof`/`Array.isArray` do); otherwise undefined.\nconst JSON_TYPES = new Set(['string', 'number', 'boolean', 'object', 'array', 'null']);\nconst jsonType = (branch: ZodType): string | undefined => {\n const type = defOf(branch).type;\n return JSON_TYPES.has(type) ? type : undefined;\n};\n\nconst distinguish = (branch: ZodType, siblings: readonly ZodType[], tag: string | undefined): Pattern | undefined => {\n if (tag !== undefined) {\n const literal = (defOf(branch).shape ?? {})[tag];\n return { kind: 'tag', key: tag, value: literal !== undefined ? defOf(literal).values?.[0] : undefined };\n }\n const elsewhere = new Set(siblings.flatMap(branchKeys));\n const key = branchKeys(branch).find((k) => !elsewhere.has(k));\n if (key !== undefined) return { kind: 'key', key };\n const type = jsonType(branch);\n if (type !== undefined && siblings.every((s) => jsonType(s) !== type)) return { kind: 'type', type };\n return undefined;\n};\n\nconst patternLabel = (pattern: Pattern): string =>\n pattern.kind === 'tag'\n ? String(pattern.value)\n : pattern.kind === 'key'\n ? pattern.key\n : pattern.kind === 'type'\n ? pattern.type\n : 'other';\n\n// A union may nest unions (`z.union([...primitives, ...ops])` where the\n// primitives are themselves a `z.union`). The branches of a nested union are\n// siblings of the outer ones for discrimination, so inline them. Each branch is\n// unwrapped first (a described/optional sub-union still flattens); a non-union\n// branch passes through untouched. Unwrapping resolves lazies, so `seen` guards\n// a union that nests back into itself: once a union core is being flattened,\n// re-encountering it keeps the branch as a leaf rather than recursing forever.\nconst flattenBranches = (branches: readonly ZodType[], seen: Set<ZodDef> = new Set()): ZodType[] =>\n branches.flatMap((branch) => {\n const { core } = unwrap(branch);\n const def = defOf(core);\n if (def.type !== 'union' || seen.has(def)) return [branch];\n return flattenBranches(def.options ?? [], new Set(seen).add(def));\n });\n\n// A branch's editor. A tagged union owns its discriminant in the chooser, so it\n// is dropped from the fields; every other branch is edited whole — including a\n// `string` or `array` branch, which is just its own field, not a group.\nconst branchField = (branch: ZodType, walk: Walk, tag: string | undefined): Field =>\n tag === undefined\n ? parseField(branch, walk)\n : { kind: 'object', fields: objectFields(branch, walk).filter((f) => f.key !== tag) };\n\nconst parseByType: Record<string, (schema: ZodType, walk: Walk) => Field> = {\n string: (schema) => {\n const format = stringFormat(schema);\n return format !== undefined ? { kind: 'string', format } : { kind: 'string' };\n },\n number: (schema) => (isInteger(schema) ? { kind: 'number', integer: true } : { kind: 'number' }),\n boolean: () => ({ kind: 'boolean' }),\n enum: (schema) => ({ kind: 'enum', options: enumOptions(schema) }),\n object: (schema, walk) => {\n // On the stack while its fields parse, so a self-reference re-entering it\n // is caught as a cycle. If one was, the object is a recursion anchor.\n const def = defOf(schema);\n walk.stack.add(def);\n const fields = objectFields(schema, walk);\n walk.stack.delete(def);\n return walk.targets.has(def) ? { kind: 'object', fields, recursive: true } : { kind: 'object', fields };\n },\n array: (schema, walk) => {\n const element = defOf(schema).element;\n return { kind: 'array', item: element !== undefined ? parseField(element, walk) : { kind: 'unknown' } };\n },\n tuple: (schema, walk) => ({ kind: 'tuple', items: (defOf(schema).items ?? []).map((item) => parseField(item, walk)) }),\n union: (schema, walk) => {\n // Flatten nested unions into sibling branches, then dedup by identity — a\n // self-referential union resolves the same cached member instances twice, so\n // the same schema can appear more than once.\n const branches = [...new Set(flattenBranches(defOf(schema).options ?? []))];\n const tag = defOf(schema).discriminator;\n // Patterns don't need the stack — compute them first.\n const patterns = branches.map((b) => distinguish(b, branches.filter((x) => x !== b), tag));\n // A branch nothing distinguishes is the catch-all: allow exactly one, as the\n // fallback the widget picks when no other pattern matches. Two such branches\n // are ambiguous (which catches a plain value?), so the union still falls back\n // to the raw editor whole.\n const open = patterns.reduce<number[]>((acc, p, i) => (p === undefined ? [...acc, i] : acc), []);\n if (branches.length === 0 || open.length > 1) return { kind: 'unknown' };\n if (open.length === 1) patterns[open[0]!] = { kind: 'fallback' };\n // Parse the branch fields with the union on the stack, so a child that\n // re-enters it (a `children: LayoutNode[]`) is caught as a cycle.\n const def = defOf(schema);\n walk.stack.add(def);\n const variants: Variant[] = branches.map((branch, i) => ({\n label: readMeta(branch).title ?? patternLabel(patterns[i]!),\n field: branchField(branch, walk, tag),\n pattern: patterns[i]!,\n }));\n walk.stack.delete(def);\n return walk.targets.has(def) ? { kind: 'union', variants, recursive: true } : { kind: 'union', variants };\n },\n};\n\nconst unknownField = (): Field => ({ kind: 'unknown' });\n\n// Modifier wrappers that don't change the editing shape — peeled to reach the\n// core type, capturing any default along the way. `lazy` is peeled too: it is\n// the deferral that makes a schema recursive, resolved here to the schema it\n// guards (whose identity the cycle check then recognizes).\nconst WRAPPERS = new Set(['optional', 'nullable', 'default', 'readonly']);\n\n// A `lazy` is a deferred reference to one schema, but its getter may *build* a\n// fresh instance on every call (`z.lazy(() => z.union([...]))`) rather than\n// close over a stable const. Cycle detection needs the same resolution each\n// time, so resolve each lazy once and reuse it. Keyed by the lazy's def — the\n// def owns the getter, and a `.describe()` alias of the lazy shares it, so the\n// alias resolves to the same instance instead of a second copy of the tree.\nconst lazyResolved = new WeakMap<ZodDef, ZodType>();\nconst resolveLazy = (lazy: ZodType): ZodType | undefined => {\n const def = defOf(lazy);\n const cached = lazyResolved.get(def);\n if (cached !== undefined) return cached;\n const resolved = def.getter?.();\n if (resolved !== undefined) lazyResolved.set(def, resolved);\n return resolved;\n};\n\nconst unwrap = (schema: ZodType): { core: ZodType; default?: unknown } => {\n let core = schema;\n let fallback: unknown;\n let def = defOf(core);\n while (WRAPPERS.has(def.type) || def.type === 'lazy') {\n // `lazy` reaches its schema through a memoized getter; the other wrappers\n // through `innerType`. Either may be absent on a malformed def — stop if so.\n const inner = def.type === 'lazy' ? resolveLazy(core) : def.innerType;\n if (inner === undefined) break;\n if ('defaultValue' in def) fallback = def.defaultValue;\n core = inner;\n def = defOf(core);\n }\n return fallback !== undefined ? { core, default: fallback } : { core };\n};\n\nconst readMeta = (schema: ZodType): FieldMeta => {\n const meta: FieldMeta = {};\n const title = (schema.meta() as { title?: unknown } | undefined)?.title;\n if (typeof title === 'string') meta.title = title;\n if (schema.description !== undefined) meta.description = schema.description;\n return meta;\n};\n\nconst parseField = (schema: ZodType, walk: Walk): Field => {\n const { core, default: fallback } = unwrap(schema);\n // A schema already on the stack is a recursion back-edge: stop and record\n // it, so the object it cycles to is tagged when its parse unwinds.\n if (walk.stack.has(defOf(core))) {\n walk.targets.add(defOf(core));\n return { kind: 'self' };\n }\n const body = (parseByType[defOf(core).type] ?? unknownField)(core, walk);\n // Read metadata from both the core and the original, so a `.describe()` on\n // either the type or a wrapper is picked up; the outer one wins.\n const meta = { ...readMeta(core), ...readMeta(schema) };\n return { ...body, ...meta, ...(fallback !== undefined ? { default: fallback } : {}) };\n};\n\nexport const parse = (schema: ZodType): Field =>\n parseField(schema, { stack: new Set(), targets: new Set() });\n\n// ─── buildDocument: IR → default document ────────────────────\n// The default value of a field, by kind. Pure JSON — a model concern, not a\n// rendering one. Recursion bottoms out naturally: a recursive object's array\n// of itself defaults to empty, so no `self` is ever expanded into a default.\n\n// Each entry takes the whole field; the scalar kinds ignore it, and the two that\n// read their own shape (`object`, `union`) narrow with a guard rather than a\n// cast — the guard never fires (dispatch keys on `kind`), but it keeps the\n// types honest without a type assertion.\nconst EMPTY: Record<FieldKind, EmptyValue> = {\n string: () => '',\n number: () => 0,\n boolean: () => false,\n // No neutral in-domain value: \"no selection\" is absence (undefined), which\n // an optional enum accepts and a required one flags — unlike null, which a\n // Zod enum rejects outright. Defaults drop undefined, so no stray key.\n enum: () => undefined,\n array: () => [],\n // Each slot built from its own field; a fixed-length list, so no growth.\n tuple: (field, options) => (field.kind === 'tuple' ? field.items.map((item) => buildDocument(item, options)) : []),\n // A recursion point has no value of its own; the array holding it defaults to [].\n self: () => undefined,\n unknown: () => null,\n object: (field, options) => {\n if (field.kind !== 'object') return {};\n const includeOptional = options.includeOptional ?? true;\n const document: Record<string, unknown> = {};\n for (const child of field.fields) {\n if (!child.required && !includeOptional) continue;\n const value = buildDocument(child.field, options);\n if (value !== undefined) document[child.key] = value; // no stray undefined keys\n }\n return document;\n },\n // An empty union defaults to its first variant (tag + branch defaults).\n union: (field) => {\n if (field.kind !== 'union') return {};\n const first = field.variants[0];\n return first === undefined ? {} : variantDefaults(first);\n },\n};\n\nexport const buildDocument = (field: Field, options: CompileOptions): unknown => {\n if (field.default !== undefined) return field.default;\n return (options.empty?.[field.kind] ?? EMPTY[field.kind])(field, options);\n};\n\n// A plain object — not an array or null. Guards the spread of a built default\n// document, whose static type is `unknown` (so we check rather than assert).\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n// A branch's default value: whatever its field builds — an object, but also a\n// bare `''` or `[]` for a scalar/array branch. A tagged union additionally sets\n// its discriminant alongside. Used as an empty union's value and to reshape the\n// document when the chooser switches branches.\nexport const variantDefaults = (variant: Variant): unknown => {\n const defaults = buildDocument(variant.field, {});\n if (variant.pattern.kind !== 'tag') return defaults;\n return { [variant.pattern.key]: variant.pattern.value, ...(isRecord(defaults) ? defaults : {}) };\n};\n","import type { LayoutNode } from '@niscorp/nova';\nimport { isRecord } from '@compile/parse';\n\n// The data document's editing layout — the nova plugin builds it from the data's\n// own keys (the freeform key→value map the layout binds to). One field per key,\n// each control bound to `$.<key>`, a writable path (the bare root `$` is not). A\n// string value edits as a text input; anything else as a JSON editor.\nconst fieldFor = (key: string, value: unknown): LayoutNode => ({\n component: 'loom:field',\n props: { label: key },\n children: [{ component: typeof value === 'string' ? 'loom:text' : 'loom:raw', model: `$.${key}` }],\n});\n\nexport const dataLayout = (value: unknown): LayoutNode => {\n const data = isRecord(value) ? value : {};\n return {\n component: 'Stack',\n props: { direction: 'column', gap: 12 },\n children: Object.keys(data).map((key) => fieldFor(key, data[key])),\n };\n};\n","import type { LayoutNode } from '@niscorp/nova';\n\n// The preview view's id — one string for one view: the name its component\n// registers under, the id of its action, and the id of its canvas. The framework\n// surface registers the component under it; the core's mount references it.\nexport const PREVIEW = 'nova:preview';\n\n// The preview layout: one component bound to the editor's live documents (the\n// layout + its data). The component renders the layout against the data with Nova.\nexport const previewLayout: LayoutNode = {\n component: PREVIEW,\n props: { documents: '$.documents' },\n};\n","import type { ActionDefinition } from '@niscorp/nova';\nimport { previewLayout, PREVIEW } from './preview.layout.js';\n\n// The preview action: the preview layout over a `documents` data slot the mount\n// keeps in sync. Canvas id equals the action id (PREVIEW).\nexport const previewAction: ActionDefinition = {\n id: PREVIEW,\n layout: previewLayout,\n data: { documents: {} },\n};\n","import { mountView } from '@editor/view';\nimport type { LoomPlugin } from '@editor/types';\nimport { layoutSchema, type NovaComponentShape } from './schema.js';\nimport { dataLayout } from './data.layout.js';\nimport { previewAction } from './preview.action.js';\n\n// @niscorp/loom/plugins/nova — the Nova plugin (framework-free).\n//\n// A Nova layout has two documents: the `layout` (a component tree, its schema\n// derived from the component manifest) and the `data` its bindings (`$.x`)\n// resolve against. The plugin declares both and contributes the preview canvas;\n// the per-framework surface (./react) supplies the preview component.\n\nexport { PREVIEW } from './preview.layout.js';\nexport { layoutSchema, type NovaComponentShape } from './schema.js';\n\nexport type NovaPluginConfig = { manifest: readonly NovaComponentShape[] };\n\nexport const novaPlugin = (config: NovaPluginConfig): LoomPlugin => ({\n name: 'nova',\n documents: {\n layout: layoutSchema(config.manifest),\n // `data` is freeform (its shape follows the layout's bindings), so it has no\n // schema. The plugin builds its editing layout from the data's keys instead.\n data: dataLayout,\n },\n // The preview is a Nova concept, not a Loom one, so the plugin contributes it:\n // a view canvas rendering the preview component bound to the live documents.\n mount: (editor) => mountView(editor, previewAction, (e) => ({ documents: e.documents })),\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/view.ts","../../../src/plugins/nova/schema.ts","../../../src/compile/parse.ts","../../../src/plugins/nova/data.layout.ts","../../../src/plugins/nova/preview.layout.ts","../../../src/plugins/nova/preview.action.ts","../../../src/plugins/nova/index.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AAA;AAAA,EACJ,MAAA,EAAQ,aAAA;AAAA,EACR,IAAA,EAAM,EAAE,SAAA,EAAW,EAAC;AACtB,CAAA;;;ACIO,IAAM,UAAA,GAAa,CAAC,MAAA,MAA0C;AAAA,EACnE,IAAA,EAAM,MAAA;AAAA,EACN,SAAA,EAAW;AAAA,IACT,MAAA,EAAQ,YAAA,CAAa,MAAA,CAAO,QAAQ,CAAA;AAAA,IACpC,IAAA,EAAM;AAAA,GACR;AAAA,EACA,KAAA,EAAO,CAAC,MAAA,KAAW,SAAA,CAAU,MAAA,EAAQ,aAAA,EAAe,CAAC,CAAA,MAAO,EAAE,SAAA,EAAW,CAAA,CAAE,SAAA,EAAU,CAAE;AACzF,CAAA","file":"index.cjs","sourcesContent":["import type { ActionDefinition } from '@niscorp/nova';\nimport type { LoomEditor } from './types.js';\n\nexport const mountView = (\n editor: LoomEditor,\n action: ActionDefinition,\n read: (editor: LoomEditor) => Record<string, unknown>,\n): void => {\n const { shell } = editor;\n shell.registerAction(action);\n shell.addCanvas({ id: action.id, initial: action.id });\n const instance = shell.getCanvasState(action.id).active?.id;\n if (instance === undefined) return;\n const sync = (): void => {\n shell.getRuntime(instance)?.setData(read(editor));\n };\n editor.on('change', sync);\n sync();\n};\n","import { z, type ZodType } from 'zod';\n\nexport type NovaComponentShape = { name: string; props: ZodType; container?: boolean };\n\nexport const layoutSchema = (manifest: readonly NovaComponentShape[]): ZodType => {\n const [first, ...rest] = manifest;\n if (first === undefined) throw new Error('nova plugin: the manifest is empty');\n\n const recur: ZodType = z.lazy(() => layoutNode);\n const branch = (component: NovaComponentShape) =>\n z.object({\n component: z.literal(component.name),\n props: component.props,\n ...(component.container === true ? { children: z.array(recur) } : {}),\n });\n\n const layoutNode = z.discriminatedUnion('component', [branch(first), ...rest.map(branch)]);\n return layoutNode;\n};\n","import type { ZodType } from 'zod';\nimport type {\n CompileOptions,\n EmptyValue,\n EnumOption,\n Field,\n FieldKind,\n FieldMeta,\n ObjectField,\n Pattern,\n Variant,\n} from './types.js';\n\ntype ZodDef = {\n type: string;\n innerType?: ZodType;\n element?: ZodType;\n shape?: Record<string, ZodType>;\n entries?: Record<string, unknown>;\n defaultValue?: unknown;\n format?: string;\n checks?: ReadonlyArray<{ def?: { format?: string } }>;\n discriminator?: string;\n options?: readonly ZodType[];\n items?: readonly ZodType[];\n values?: readonly unknown[];\n getter?: () => ZodType;\n};\n\nconst defOf = (schema: ZodType): ZodDef => schema.def as ZodDef;\n\n// Keyed by def, not by instance: `.describe()` and `.meta()` clone the wrapper\n// but share the def, and an alias of a recursive schema has to be recognized as\n// the schema itself.\ntype Walk = { stack: Set<ZodDef>; targets: Set<ZodDef> };\n\nconst INTEGER_FORMAT = 'safeint';\n\nconst stringFormat = (schema: ZodType): string | undefined => {\n const def = defOf(schema);\n if (def.format !== undefined) return def.format;\n for (const check of def.checks ?? []) {\n if (check.def?.format !== undefined) return check.def.format;\n }\n return undefined;\n};\n\nconst isInteger = (schema: ZodType): boolean => {\n const def = defOf(schema);\n if (def.format === INTEGER_FORMAT) return true;\n return (def.checks ?? []).some((check) => check.def?.format === INTEGER_FORMAT);\n};\n\nconst enumOptions = (schema: ZodType): EnumOption[] =>\n Object.values(defOf(schema).entries ?? {}).map((value) => ({ value, label: String(value) }));\n\nconst objectFields = (schema: ZodType, walk: Walk): ObjectField[] =>\n Object.entries(defOf(schema).shape ?? {}).map(([key, value]) => ({\n key,\n required: !value.safeParse(undefined).success,\n field: parseField(value, walk),\n }));\n\nconst branchKeys = (branch: ZodType): string[] => Object.keys(defOf(branch).shape ?? {});\n\nconst JSON_TYPES = new Set(['string', 'number', 'boolean', 'object', 'array', 'null']);\nconst jsonType = (branch: ZodType): string | undefined => {\n const type = defOf(branch).type;\n return JSON_TYPES.has(type) ? type : undefined;\n};\n\nconst distinguish = (branch: ZodType, siblings: readonly ZodType[], tag: string | undefined): Pattern | undefined => {\n if (tag !== undefined) {\n const literal = (defOf(branch).shape ?? {})[tag];\n return { kind: 'tag', key: tag, value: literal !== undefined ? defOf(literal).values?.[0] : undefined };\n }\n const elsewhere = new Set(siblings.flatMap(branchKeys));\n const key = branchKeys(branch).find((k) => !elsewhere.has(k));\n if (key !== undefined) return { kind: 'key', key };\n const type = jsonType(branch);\n if (type !== undefined && siblings.every((s) => jsonType(s) !== type)) return { kind: 'type', type };\n return undefined;\n};\n\nconst patternLabel = (pattern: Pattern): string =>\n pattern.kind === 'tag'\n ? String(pattern.value)\n : pattern.kind === 'key'\n ? pattern.key\n : pattern.kind === 'type'\n ? pattern.type\n : 'other';\n\nconst flattenBranches = (branches: readonly ZodType[], seen: Set<ZodDef> = new Set()): ZodType[] =>\n branches.flatMap((branch) => {\n const { core } = unwrap(branch);\n const def = defOf(core);\n if (def.type !== 'union' || seen.has(def)) return [branch];\n return flattenBranches(def.options ?? [], new Set(seen).add(def));\n });\n\nconst branchField = (branch: ZodType, walk: Walk, tag: string | undefined): Field =>\n tag === undefined\n ? parseField(branch, walk)\n : { kind: 'object', fields: objectFields(branch, walk).filter((f) => f.key !== tag) };\n\nconst parseByType: Record<string, (schema: ZodType, walk: Walk) => Field> = {\n string: (schema) => {\n const format = stringFormat(schema);\n return format !== undefined ? { kind: 'string', format } : { kind: 'string' };\n },\n number: (schema) => (isInteger(schema) ? { kind: 'number', integer: true } : { kind: 'number' }),\n boolean: () => ({ kind: 'boolean' }),\n enum: (schema) => ({ kind: 'enum', options: enumOptions(schema) }),\n object: (schema, walk) => {\n const def = defOf(schema);\n walk.stack.add(def);\n const fields = objectFields(schema, walk);\n walk.stack.delete(def);\n return walk.targets.has(def) ? { kind: 'object', fields, recursive: true } : { kind: 'object', fields };\n },\n array: (schema, walk) => {\n const element = defOf(schema).element;\n return { kind: 'array', item: element !== undefined ? parseField(element, walk) : { kind: 'unknown' } };\n },\n tuple: (schema, walk) => ({ kind: 'tuple', items: (defOf(schema).items ?? []).map((item) => parseField(item, walk)) }),\n union: (schema, walk) => {\n // Deduplicated by identity: a union that nests back into itself yields the\n // same member instances twice.\n const branches = [...new Set(flattenBranches(defOf(schema).options ?? []))];\n const tag = defOf(schema).discriminator;\n const patterns = branches.map((b) => distinguish(b, branches.filter((x) => x !== b), tag));\n const open = patterns.reduce<number[]>((acc, p, i) => (p === undefined ? [...acc, i] : acc), []);\n if (branches.length === 0 || open.length > 1) return { kind: 'unknown' };\n if (open.length === 1) patterns[open[0]!] = { kind: 'fallback' };\n const def = defOf(schema);\n walk.stack.add(def);\n const variants: Variant[] = branches.map((branch, i) => ({\n label: readMeta(branch).title ?? patternLabel(patterns[i]!),\n field: branchField(branch, walk, tag),\n pattern: patterns[i]!,\n }));\n walk.stack.delete(def);\n return walk.targets.has(def) ? { kind: 'union', variants, recursive: true } : { kind: 'union', variants };\n },\n};\n\nconst unknownField = (): Field => ({ kind: 'unknown' });\n\nconst WRAPPERS = new Set(['optional', 'nullable', 'default', 'readonly']);\n\n// A lazy's getter may build a fresh instance on every call\n// (`z.lazy(() => z.union([...]))`). Cycle detection needs the same instance each\n// time, so each lazy is resolved once.\nconst lazyResolved = new WeakMap<ZodDef, ZodType>();\nconst resolveLazy = (lazy: ZodType): ZodType | undefined => {\n const def = defOf(lazy);\n const cached = lazyResolved.get(def);\n if (cached !== undefined) return cached;\n const resolved = def.getter?.();\n if (resolved !== undefined) lazyResolved.set(def, resolved);\n return resolved;\n};\n\nconst unwrap = (schema: ZodType): { core: ZodType; default?: unknown } => {\n let core = schema;\n let fallback: unknown;\n let def = defOf(core);\n while (WRAPPERS.has(def.type) || def.type === 'lazy') {\n const inner = def.type === 'lazy' ? resolveLazy(core) : def.innerType;\n if (inner === undefined) break;\n if ('defaultValue' in def) fallback = def.defaultValue;\n core = inner;\n def = defOf(core);\n }\n return fallback !== undefined ? { core, default: fallback } : { core };\n};\n\nconst readMeta = (schema: ZodType): FieldMeta => {\n const meta: FieldMeta = {};\n const title = (schema.meta() as { title?: unknown } | undefined)?.title;\n if (typeof title === 'string') meta.title = title;\n if (schema.description !== undefined) meta.description = schema.description;\n return meta;\n};\n\nconst parseField = (schema: ZodType, walk: Walk): Field => {\n const { core, default: fallback } = unwrap(schema);\n if (walk.stack.has(defOf(core))) {\n walk.targets.add(defOf(core));\n return { kind: 'self' };\n }\n const body = (parseByType[defOf(core).type] ?? unknownField)(core, walk);\n const meta = { ...readMeta(core), ...readMeta(schema) };\n return { ...body, ...meta, ...(fallback !== undefined ? { default: fallback } : {}) };\n};\n\nexport const parse = (schema: ZodType): Field =>\n parseField(schema, { stack: new Set(), targets: new Set() });\n\nconst EMPTY: Record<FieldKind, EmptyValue> = {\n string: () => '',\n number: () => 0,\n boolean: () => false,\n // `undefined`, not `null`: an optional enum accepts absence and a required one\n // reports it, while a Zod enum rejects `null` outright.\n enum: () => undefined,\n array: () => [],\n tuple: (field, options) => (field.kind === 'tuple' ? field.items.map((item) => buildDocument(item, options)) : []),\n self: () => undefined,\n unknown: () => null,\n object: (field, options) => {\n if (field.kind !== 'object') return {};\n const includeOptional = options.includeOptional ?? true;\n const document: Record<string, unknown> = {};\n for (const child of field.fields) {\n if (!child.required && !includeOptional) continue;\n const value = buildDocument(child.field, options);\n if (value !== undefined) document[child.key] = value;\n }\n return document;\n },\n union: (field) => {\n if (field.kind !== 'union') return {};\n const first = field.variants[0];\n return first === undefined ? {} : variantDefaults(first);\n },\n};\n\nexport const buildDocument = (field: Field, options: CompileOptions): unknown => {\n if (field.default !== undefined) return field.default;\n return (options.empty?.[field.kind] ?? EMPTY[field.kind])(field, options);\n};\n\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nexport const variantDefaults = (variant: Variant): unknown => {\n const defaults = buildDocument(variant.field, {});\n if (variant.pattern.kind !== 'tag') return defaults;\n return { [variant.pattern.key]: variant.pattern.value, ...(isRecord(defaults) ? defaults : {}) };\n};\n","import type { LayoutNode } from '@niscorp/nova';\nimport { isRecord } from '@compile/parse';\n\nconst fieldFor = (key: string, value: unknown): LayoutNode => ({\n component: 'loom:field',\n props: { label: key },\n children: [{ component: typeof value === 'string' ? 'loom:text' : 'loom:raw', model: `$.${key}` }],\n});\n\nexport const dataLayout = (value: unknown): LayoutNode => {\n const data = isRecord(value) ? value : {};\n return {\n component: 'Stack',\n props: { direction: 'column', gap: 12 },\n children: Object.keys(data).map((key) => fieldFor(key, data[key])),\n };\n};\n","import type { LayoutNode } from '@niscorp/nova';\n\nexport const PREVIEW = 'nova:preview';\n\nexport const previewLayout: LayoutNode = {\n component: PREVIEW,\n props: { documents: '$.documents' },\n};\n","import type { ActionDefinition } from '@niscorp/nova';\nimport { previewLayout, PREVIEW } from './preview.layout.js';\n\nexport const previewAction: ActionDefinition = {\n id: PREVIEW,\n layout: previewLayout,\n data: { documents: {} },\n};\n","import { mountView } from '@editor/view';\nimport type { LoomPlugin } from '@editor/types';\nimport { layoutSchema, type NovaComponentShape } from './schema.js';\nimport { dataLayout } from './data.layout.js';\nimport { previewAction } from './preview.action.js';\n\nexport { PREVIEW } from './preview.layout.js';\nexport { layoutSchema, type NovaComponentShape } from './schema.js';\n\nexport type NovaPluginConfig = { manifest: readonly NovaComponentShape[] };\n\nexport const novaPlugin = (config: NovaPluginConfig): LoomPlugin => ({\n name: 'nova',\n documents: {\n layout: layoutSchema(config.manifest),\n data: dataLayout,\n },\n mount: (editor) => mountView(editor, previewAction, (e) => ({ documents: e.documents })),\n});\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as LoomPlugin } from '../../types-
|
|
1
|
+
import { h as LoomPlugin } from '../../types-V5kJWZJn.cjs';
|
|
2
2
|
import { N as NovaComponentShape } from '../../schema--OhtatTX.cjs';
|
|
3
3
|
export { l as layoutSchema } from '../../schema--OhtatTX.cjs';
|
|
4
4
|
import 'zod';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { PREVIEW, layoutSchema, novaPlugin } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
3
|
-
import '../../chunk-
|
|
1
|
+
export { PREVIEW, layoutSchema, novaPlugin } from '../../chunk-HHPSU7IA.js';
|
|
2
|
+
import '../../chunk-DEZGKUTO.js';
|
|
3
|
+
import '../../chunk-27OMOR7I.js';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -67,12 +67,8 @@ var novaPlugin = (config) => ({
|
|
|
67
67
|
name: "nova",
|
|
68
68
|
documents: {
|
|
69
69
|
layout: layoutSchema(config.manifest),
|
|
70
|
-
// `data` is freeform (its shape follows the layout's bindings), so it has no
|
|
71
|
-
// schema. The plugin builds its editing layout from the data's keys instead.
|
|
72
70
|
data: dataLayout
|
|
73
71
|
},
|
|
74
|
-
// The preview is a Nova concept, not a Loom one, so the plugin contributes it:
|
|
75
|
-
// a view canvas rendering the preview component bound to the live documents.
|
|
76
72
|
mount: (editor) => mountView(editor, previewAction, (e) => ({ documents: e.documents }))
|
|
77
73
|
});
|
|
78
74
|
var frame = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/editor/view.ts","../../../../src/plugins/nova/schema.ts","../../../../src/compile/parse.ts","../../../../src/plugins/nova/data.layout.ts","../../../../src/plugins/nova/preview.layout.ts","../../../../src/plugins/nova/preview.action.ts","../../../../src/plugins/nova/index.ts","../../../../src/plugins/nova/react/preview.tsx","../../../../src/plugins/nova/react/index.ts"],"names":["z","jsx","Nova","name"],"mappings":";;;;;;;AAQO,IAAM,SAAA,GAAY,CACvB,MAAA,EACA,MAAA,EACA,IAAA,KACS;AACT,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,KAAA,CAAM,eAAe,MAAM,CAAA;AAC3B,EAAA,KAAA,CAAM,SAAA,CAAU,EAAE,EAAA,EAAI,MAAA,CAAO,IAAI,OAAA,EAAS,MAAA,CAAO,IAAI,CAAA;AACrD,EAAA,MAAM,WAAW,KAAA,CAAM,cAAA,CAAe,MAAA,CAAO,EAAE,EAAE,MAAA,EAAQ,EAAA;AACzD,EAAA,IAAI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AO,SAAA,QAAiB,EAAE,IAAA,EAAAA,KAAAA,EAAM,KAAA,EAAO,WAAU,CAAE,CAAA;AACpH,EAAA,MAAM,EAAE,MAAM,SAAA,EAAW,KAAA,KAAU,UAAA,CAAW,EAAE,QAAA,EAAU,KAAA,EAAO,CAAA;AACjE,EAAA,OAAO,EAAE,IAAA,EAAM,SAAA,EAAW,KAAA,EAAO,UAAA,EAAY,EAAE,CAAC,OAAO,GAAG,WAAA,CAAY,UAAU,CAAA,EAAE,EAAE;AACtF","file":"index.cjs","sourcesContent":["import type { ActionDefinition } from '@niscorp/nova';\nimport type { LoomEditor } from './types.js';\n\n// Mount a view canvas: register `action`, add a canvas that renders it, and keep\n// its data in sync with the editor's live state — `read(editor)` is pushed onto\n// the canvas on every `change`. The canvas id is the action id. Used by the\n// default plugins (jsonviewer, validation) and any domain preview; the contributor\n// owns the canvas, so a later plugin can `shell.removeCanvas(action.id)` to drop it.\nexport const mountView = (\n editor: LoomEditor,\n action: ActionDefinition,\n read: (editor: LoomEditor) => Record<string, unknown>,\n): void => {\n const { shell } = editor;\n shell.registerAction(action);\n shell.addCanvas({ id: action.id, initial: action.id });\n const instance = shell.getCanvasState(action.id).active?.id;\n if (instance === undefined) return;\n const sync = (): void => {\n shell.getRuntime(instance)?.setData(read(editor));\n };\n editor.on('change', sync);\n sync();\n};\n","import { z, type ZodType } from 'zod';\n\n// The framework-free shape of one component in the manifest: its name, the schema\n// for its props, and whether it nests children. The render function (React, Vue,\n// …) lives in the per-framework surface, not here.\nexport type NovaComponentShape = { name: string; props: ZodType; container?: boolean };\n\n// Build the layout document's schema. Each component becomes a branch\n// discriminated by its `component` literal, carrying its prop schema; containers\n// recurse through `children`. This is the shape of a Nova ComponentNode, so the\n// edited `layout` document is itself a layout.\nexport const layoutSchema = (manifest: readonly NovaComponentShape[]): ZodType => {\n const [first, ...rest] = manifest;\n if (first === undefined) throw new Error('nova plugin: the manifest is empty');\n\n const recur: ZodType = z.lazy(() => layoutNode);\n const branch = (component: NovaComponentShape) =>\n z.object({\n component: z.literal(component.name),\n props: component.props,\n ...(component.container === true ? { children: z.array(recur) } : {}),\n });\n\n const layoutNode = z.discriminatedUnion('component', [branch(first), ...rest.map(branch)]);\n return layoutNode;\n};\n","import type { ZodType } from 'zod';\nimport type {\n CompileOptions,\n EmptyValue,\n EnumOption,\n Field,\n FieldKind,\n FieldMeta,\n ObjectField,\n Pattern,\n Variant,\n} from './types.js';\n\n// parse — turn a Zod schema into Loom's field model (IR). The only Zod-aware\n// code in the package, and pure data in / pure data out: no Nova. `parseByType`\n// is keyed by Zod's own `def.type` tag, so the type vocabulary lives as table\n// keys, not scattered checks.\n//\n// A recursive schema (`z.lazy`, or an object whose getter returns itself) would\n// expand forever. The walk carries the set of schemas it is currently inside;\n// re-entering one is a back-edge, emitted as a `self` marker and recorded so\n// the object it points back to can be tagged `recursive`. Expansion stops at\n// the cycle — the document, not the schema, decides how deep an editor goes.\n\n// The slice of a Zod schema's internal definition that parsing reads.\ntype ZodDef = {\n type: string;\n innerType?: ZodType;\n element?: ZodType;\n shape?: Record<string, ZodType>;\n entries?: Record<string, unknown>;\n defaultValue?: unknown;\n format?: string;\n checks?: ReadonlyArray<{ def?: { format?: string } }>;\n discriminator?: string;\n options?: readonly ZodType[];\n items?: readonly ZodType[];\n values?: readonly unknown[];\n getter?: () => ZodType;\n};\n\n// Zod types every schema's `.def` as the base `$ZodTypeDef` (just the `type`\n// discriminant); the per-type fields we read live on the concrete defs. This\n// views `.def` through the structural slice above — the single place the\n// parser depends on Zod's internal shape.\nconst defOf = (schema: ZodType): ZodDef => schema.def as ZodDef;\n\n// While walking, the schemas currently on the stack (cycle detection) and the\n// schemas a `self` pointed back to (so the matching object is tagged recursive).\n// Keyed by def, not instance: `.describe()`/`.meta()` clone the wrapper but\n// share the def, so a described alias of a recursive schema must read as the\n// schema itself — or every back-edge re-expands the whole thing one more level.\ntype Walk = { stack: Set<ZodDef>; targets: Set<ZodDef> };\n\n// ─── Reading Zod ─────────────────────────────────────────────\n\n// `safeint` is Zod's format tag for an integer-constrained number — the one\n// Zod-vocabulary token this file matches on.\nconst INTEGER_FORMAT = 'safeint';\n\nconst stringFormat = (schema: ZodType): string | undefined => {\n const def = defOf(schema);\n if (def.format !== undefined) return def.format;\n for (const check of def.checks ?? []) {\n if (check.def?.format !== undefined) return check.def.format;\n }\n return undefined;\n};\n\nconst isInteger = (schema: ZodType): boolean => {\n const def = defOf(schema);\n if (def.format === INTEGER_FORMAT) return true;\n return (def.checks ?? []).some((check) => check.def?.format === INTEGER_FORMAT);\n};\n\nconst enumOptions = (schema: ZodType): EnumOption[] =>\n Object.values(defOf(schema).entries ?? {}).map((value) => ({ value, label: String(value) }));\n\nconst objectFields = (schema: ZodType, walk: Walk): ObjectField[] =>\n Object.entries(defOf(schema).shape ?? {}).map(([key, value]) => ({\n key,\n // A property is optional when the schema accepts `undefined` for it\n // (covers `.optional()` and `.default()`) — asked of Zod, not inferred.\n required: !value.safeParse(undefined).success,\n field: parseField(value, walk),\n }));\n\n// ─── Union discrimination ────────────────────────────────────\n// For each branch, the cheapest fact that tells it apart from its siblings: the\n// declared tag's value, else a key only it carries, else a JS type only it is.\n// One function covers tagged, structural, and mixed unions; a branch that none\n// of these distinguish makes the whole union fall back to the raw editor.\n\nconst branchKeys = (branch: ZodType): string[] => Object.keys(defOf(branch).shape ?? {});\n\n// The branch's JS type, when it's one the runtime matcher checks (Zod names\n// these the same as `typeof`/`Array.isArray` do); otherwise undefined.\nconst JSON_TYPES = new Set(['string', 'number', 'boolean', 'object', 'array', 'null']);\nconst jsonType = (branch: ZodType): string | undefined => {\n const type = defOf(branch).type;\n return JSON_TYPES.has(type) ? type : undefined;\n};\n\nconst distinguish = (branch: ZodType, siblings: readonly ZodType[], tag: string | undefined): Pattern | undefined => {\n if (tag !== undefined) {\n const literal = (defOf(branch).shape ?? {})[tag];\n return { kind: 'tag', key: tag, value: literal !== undefined ? defOf(literal).values?.[0] : undefined };\n }\n const elsewhere = new Set(siblings.flatMap(branchKeys));\n const key = branchKeys(branch).find((k) => !elsewhere.has(k));\n if (key !== undefined) return { kind: 'key', key };\n const type = jsonType(branch);\n if (type !== undefined && siblings.every((s) => jsonType(s) !== type)) return { kind: 'type', type };\n return undefined;\n};\n\nconst patternLabel = (pattern: Pattern): string =>\n pattern.kind === 'tag'\n ? String(pattern.value)\n : pattern.kind === 'key'\n ? pattern.key\n : pattern.kind === 'type'\n ? pattern.type\n : 'other';\n\n// A union may nest unions (`z.union([...primitives, ...ops])` where the\n// primitives are themselves a `z.union`). The branches of a nested union are\n// siblings of the outer ones for discrimination, so inline them. Each branch is\n// unwrapped first (a described/optional sub-union still flattens); a non-union\n// branch passes through untouched. Unwrapping resolves lazies, so `seen` guards\n// a union that nests back into itself: once a union core is being flattened,\n// re-encountering it keeps the branch as a leaf rather than recursing forever.\nconst flattenBranches = (branches: readonly ZodType[], seen: Set<ZodDef> = new Set()): ZodType[] =>\n branches.flatMap((branch) => {\n const { core } = unwrap(branch);\n const def = defOf(core);\n if (def.type !== 'union' || seen.has(def)) return [branch];\n return flattenBranches(def.options ?? [], new Set(seen).add(def));\n });\n\n// A branch's editor. A tagged union owns its discriminant in the chooser, so it\n// is dropped from the fields; every other branch is edited whole — including a\n// `string` or `array` branch, which is just its own field, not a group.\nconst branchField = (branch: ZodType, walk: Walk, tag: string | undefined): Field =>\n tag === undefined\n ? parseField(branch, walk)\n : { kind: 'object', fields: objectFields(branch, walk).filter((f) => f.key !== tag) };\n\nconst parseByType: Record<string, (schema: ZodType, walk: Walk) => Field> = {\n string: (schema) => {\n const format = stringFormat(schema);\n return format !== undefined ? { kind: 'string', format } : { kind: 'string' };\n },\n number: (schema) => (isInteger(schema) ? { kind: 'number', integer: true } : { kind: 'number' }),\n boolean: () => ({ kind: 'boolean' }),\n enum: (schema) => ({ kind: 'enum', options: enumOptions(schema) }),\n object: (schema, walk) => {\n // On the stack while its fields parse, so a self-reference re-entering it\n // is caught as a cycle. If one was, the object is a recursion anchor.\n const def = defOf(schema);\n walk.stack.add(def);\n const fields = objectFields(schema, walk);\n walk.stack.delete(def);\n return walk.targets.has(def) ? { kind: 'object', fields, recursive: true } : { kind: 'object', fields };\n },\n array: (schema, walk) => {\n const element = defOf(schema).element;\n return { kind: 'array', item: element !== undefined ? parseField(element, walk) : { kind: 'unknown' } };\n },\n tuple: (schema, walk) => ({ kind: 'tuple', items: (defOf(schema).items ?? []).map((item) => parseField(item, walk)) }),\n union: (schema, walk) => {\n // Flatten nested unions into sibling branches, then dedup by identity — a\n // self-referential union resolves the same cached member instances twice, so\n // the same schema can appear more than once.\n const branches = [...new Set(flattenBranches(defOf(schema).options ?? []))];\n const tag = defOf(schema).discriminator;\n // Patterns don't need the stack — compute them first.\n const patterns = branches.map((b) => distinguish(b, branches.filter((x) => x !== b), tag));\n // A branch nothing distinguishes is the catch-all: allow exactly one, as the\n // fallback the widget picks when no other pattern matches. Two such branches\n // are ambiguous (which catches a plain value?), so the union still falls back\n // to the raw editor whole.\n const open = patterns.reduce<number[]>((acc, p, i) => (p === undefined ? [...acc, i] : acc), []);\n if (branches.length === 0 || open.length > 1) return { kind: 'unknown' };\n if (open.length === 1) patterns[open[0]!] = { kind: 'fallback' };\n // Parse the branch fields with the union on the stack, so a child that\n // re-enters it (a `children: LayoutNode[]`) is caught as a cycle.\n const def = defOf(schema);\n walk.stack.add(def);\n const variants: Variant[] = branches.map((branch, i) => ({\n label: readMeta(branch).title ?? patternLabel(patterns[i]!),\n field: branchField(branch, walk, tag),\n pattern: patterns[i]!,\n }));\n walk.stack.delete(def);\n return walk.targets.has(def) ? { kind: 'union', variants, recursive: true } : { kind: 'union', variants };\n },\n};\n\nconst unknownField = (): Field => ({ kind: 'unknown' });\n\n// Modifier wrappers that don't change the editing shape — peeled to reach the\n// core type, capturing any default along the way. `lazy` is peeled too: it is\n// the deferral that makes a schema recursive, resolved here to the schema it\n// guards (whose identity the cycle check then recognizes).\nconst WRAPPERS = new Set(['optional', 'nullable', 'default', 'readonly']);\n\n// A `lazy` is a deferred reference to one schema, but its getter may *build* a\n// fresh instance on every call (`z.lazy(() => z.union([...]))`) rather than\n// close over a stable const. Cycle detection needs the same resolution each\n// time, so resolve each lazy once and reuse it. Keyed by the lazy's def — the\n// def owns the getter, and a `.describe()` alias of the lazy shares it, so the\n// alias resolves to the same instance instead of a second copy of the tree.\nconst lazyResolved = new WeakMap<ZodDef, ZodType>();\nconst resolveLazy = (lazy: ZodType): ZodType | undefined => {\n const def = defOf(lazy);\n const cached = lazyResolved.get(def);\n if (cached !== undefined) return cached;\n const resolved = def.getter?.();\n if (resolved !== undefined) lazyResolved.set(def, resolved);\n return resolved;\n};\n\nconst unwrap = (schema: ZodType): { core: ZodType; default?: unknown } => {\n let core = schema;\n let fallback: unknown;\n let def = defOf(core);\n while (WRAPPERS.has(def.type) || def.type === 'lazy') {\n // `lazy` reaches its schema through a memoized getter; the other wrappers\n // through `innerType`. Either may be absent on a malformed def — stop if so.\n const inner = def.type === 'lazy' ? resolveLazy(core) : def.innerType;\n if (inner === undefined) break;\n if ('defaultValue' in def) fallback = def.defaultValue;\n core = inner;\n def = defOf(core);\n }\n return fallback !== undefined ? { core, default: fallback } : { core };\n};\n\nconst readMeta = (schema: ZodType): FieldMeta => {\n const meta: FieldMeta = {};\n const title = (schema.meta() as { title?: unknown } | undefined)?.title;\n if (typeof title === 'string') meta.title = title;\n if (schema.description !== undefined) meta.description = schema.description;\n return meta;\n};\n\nconst parseField = (schema: ZodType, walk: Walk): Field => {\n const { core, default: fallback } = unwrap(schema);\n // A schema already on the stack is a recursion back-edge: stop and record\n // it, so the object it cycles to is tagged when its parse unwinds.\n if (walk.stack.has(defOf(core))) {\n walk.targets.add(defOf(core));\n return { kind: 'self' };\n }\n const body = (parseByType[defOf(core).type] ?? unknownField)(core, walk);\n // Read metadata from both the core and the original, so a `.describe()` on\n // either the type or a wrapper is picked up; the outer one wins.\n const meta = { ...readMeta(core), ...readMeta(schema) };\n return { ...body, ...meta, ...(fallback !== undefined ? { default: fallback } : {}) };\n};\n\nexport const parse = (schema: ZodType): Field =>\n parseField(schema, { stack: new Set(), targets: new Set() });\n\n// ─── buildDocument: IR → default document ────────────────────\n// The default value of a field, by kind. Pure JSON — a model concern, not a\n// rendering one. Recursion bottoms out naturally: a recursive object's array\n// of itself defaults to empty, so no `self` is ever expanded into a default.\n\n// Each entry takes the whole field; the scalar kinds ignore it, and the two that\n// read their own shape (`object`, `union`) narrow with a guard rather than a\n// cast — the guard never fires (dispatch keys on `kind`), but it keeps the\n// types honest without a type assertion.\nconst EMPTY: Record<FieldKind, EmptyValue> = {\n string: () => '',\n number: () => 0,\n boolean: () => false,\n // No neutral in-domain value: \"no selection\" is absence (undefined), which\n // an optional enum accepts and a required one flags — unlike null, which a\n // Zod enum rejects outright. Defaults drop undefined, so no stray key.\n enum: () => undefined,\n array: () => [],\n // Each slot built from its own field; a fixed-length list, so no growth.\n tuple: (field, options) => (field.kind === 'tuple' ? field.items.map((item) => buildDocument(item, options)) : []),\n // A recursion point has no value of its own; the array holding it defaults to [].\n self: () => undefined,\n unknown: () => null,\n object: (field, options) => {\n if (field.kind !== 'object') return {};\n const includeOptional = options.includeOptional ?? true;\n const document: Record<string, unknown> = {};\n for (const child of field.fields) {\n if (!child.required && !includeOptional) continue;\n const value = buildDocument(child.field, options);\n if (value !== undefined) document[child.key] = value; // no stray undefined keys\n }\n return document;\n },\n // An empty union defaults to its first variant (tag + branch defaults).\n union: (field) => {\n if (field.kind !== 'union') return {};\n const first = field.variants[0];\n return first === undefined ? {} : variantDefaults(first);\n },\n};\n\nexport const buildDocument = (field: Field, options: CompileOptions): unknown => {\n if (field.default !== undefined) return field.default;\n return (options.empty?.[field.kind] ?? EMPTY[field.kind])(field, options);\n};\n\n// A plain object — not an array or null. Guards the spread of a built default\n// document, whose static type is `unknown` (so we check rather than assert).\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n// A branch's default value: whatever its field builds — an object, but also a\n// bare `''` or `[]` for a scalar/array branch. A tagged union additionally sets\n// its discriminant alongside. Used as an empty union's value and to reshape the\n// document when the chooser switches branches.\nexport const variantDefaults = (variant: Variant): unknown => {\n const defaults = buildDocument(variant.field, {});\n if (variant.pattern.kind !== 'tag') return defaults;\n return { [variant.pattern.key]: variant.pattern.value, ...(isRecord(defaults) ? defaults : {}) };\n};\n","import type { LayoutNode } from '@niscorp/nova';\nimport { isRecord } from '@compile/parse';\n\n// The data document's editing layout — the nova plugin builds it from the data's\n// own keys (the freeform key→value map the layout binds to). One field per key,\n// each control bound to `$.<key>`, a writable path (the bare root `$` is not). A\n// string value edits as a text input; anything else as a JSON editor.\nconst fieldFor = (key: string, value: unknown): LayoutNode => ({\n component: 'loom:field',\n props: { label: key },\n children: [{ component: typeof value === 'string' ? 'loom:text' : 'loom:raw', model: `$.${key}` }],\n});\n\nexport const dataLayout = (value: unknown): LayoutNode => {\n const data = isRecord(value) ? value : {};\n return {\n component: 'Stack',\n props: { direction: 'column', gap: 12 },\n children: Object.keys(data).map((key) => fieldFor(key, data[key])),\n };\n};\n","import type { LayoutNode } from '@niscorp/nova';\n\n// The preview view's id — one string for one view: the name its component\n// registers under, the id of its action, and the id of its canvas. The framework\n// surface registers the component under it; the core's mount references it.\nexport const PREVIEW = 'nova:preview';\n\n// The preview layout: one component bound to the editor's live documents (the\n// layout + its data). The component renders the layout against the data with Nova.\nexport const previewLayout: LayoutNode = {\n component: PREVIEW,\n props: { documents: '$.documents' },\n};\n","import type { ActionDefinition } from '@niscorp/nova';\nimport { previewLayout, PREVIEW } from './preview.layout.js';\n\n// The preview action: the preview layout over a `documents` data slot the mount\n// keeps in sync. Canvas id equals the action id (PREVIEW).\nexport const previewAction: ActionDefinition = {\n id: PREVIEW,\n layout: previewLayout,\n data: { documents: {} },\n};\n","import { mountView } from '@editor/view';\nimport type { LoomPlugin } from '@editor/types';\nimport { layoutSchema, type NovaComponentShape } from './schema.js';\nimport { dataLayout } from './data.layout.js';\nimport { previewAction } from './preview.action.js';\n\n// @niscorp/loom/plugins/nova — the Nova plugin (framework-free).\n//\n// A Nova layout has two documents: the `layout` (a component tree, its schema\n// derived from the component manifest) and the `data` its bindings (`$.x`)\n// resolve against. The plugin declares both and contributes the preview canvas;\n// the per-framework surface (./react) supplies the preview component.\n\nexport { PREVIEW } from './preview.layout.js';\nexport { layoutSchema, type NovaComponentShape } from './schema.js';\n\nexport type NovaPluginConfig = { manifest: readonly NovaComponentShape[] };\n\nexport const novaPlugin = (config: NovaPluginConfig): LoomPlugin => ({\n name: 'nova',\n documents: {\n layout: layoutSchema(config.manifest),\n // `data` is freeform (its shape follows the layout's bindings), so it has no\n // schema. The plugin builds its editing layout from the data's keys instead.\n data: dataLayout,\n },\n // The preview is a Nova concept, not a Loom one, so the plugin contributes it:\n // a view canvas rendering the preview component bound to the live documents.\n mount: (editor) => mountView(editor, previewAction, (e) => ({ documents: e.documents })),\n});\n","import type { CSSProperties, FC } from 'react';\nimport type { LayoutNode } from '@niscorp/nova';\nimport { Nova, type NovaComponent } from '@niscorp/nova/adapters/react';\nimport { isRecord } from '@compile/parse';\n\n// The preview component: receives the live documents and renders `layout` against\n// `data` with Nova, using the manifest's render functions. Registered under\n// PREVIEW by the surface; the plugin's mount binds the documents to it.\n\nconst frame: CSSProperties = {\n padding: 24,\n borderRadius: 12,\n minHeight: 220,\n background: 'radial-gradient(circle at 30% 15%, #1b1b3a, #0c0c18 70%)',\n border: '1px solid #2a2a4a',\n};\n\nexport const makePreview = (components: Record<string, NovaComponent>): NovaComponent<{ documents?: unknown }> => {\n const Preview: FC<{ documents?: unknown }> = ({ documents }) => {\n const docs = isRecord(documents) ? documents : {};\n const layout = docs['layout'];\n const data = isRecord(docs['data']) ? (docs['data'] as Record<string, unknown>) : {};\n return (\n <div style={frame}>\n {isRecord(layout) ? (\n <Nova.Layout layout={layout as LayoutNode} data={data} components={components} builtins={false} />\n ) : null}\n </div>\n );\n };\n return Preview;\n};\n","import type { NovaComponent } from '@niscorp/nova/adapters/react';\nimport type { LoomEditorPlugin } from '@react';\nimport { novaPlugin, PREVIEW, type NovaComponentShape } from '../index.js';\nimport { makePreview } from './preview.js';\n\n// @niscorp/loom/plugins/nova/react — the React surface for the Nova plugin.\n//\n// The manifest entry the app provides: the framework-free shape (drives the\n// schema) plus the React render. `nova(config)` assembles the plugin with its\n// preview component into the object <LoomEditor> consumes.\n\nexport type NovaManifestEntry = NovaComponentShape & { render: NovaComponent };\n\nexport type NovaConfig = { manifest: readonly NovaManifestEntry[] };\n\nexport const nova = (config: NovaConfig): LoomEditorPlugin => {\n const components: Record<string, NovaComponent> = Object.fromEntries(\n config.manifest.map((entry) => [entry.name, entry.render]),\n );\n const shape: NovaComponentShape[] = config.manifest.map(({ name, props, container }) => ({ name, props, container }));\n const { name, documents, mount } = novaPlugin({ manifest: shape });\n return { name, documents, mount, components: { [PREVIEW]: makePreview(components) } };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/editor/view.ts","../../../../src/plugins/nova/schema.ts","../../../../src/compile/parse.ts","../../../../src/plugins/nova/data.layout.ts","../../../../src/plugins/nova/preview.layout.ts","../../../../src/plugins/nova/preview.action.ts","../../../../src/plugins/nova/index.ts","../../../../src/plugins/nova/react/preview.tsx","../../../../src/plugins/nova/react/index.ts"],"names":["z","jsx","Nova","name"],"mappings":";;;;;;;AAGO,IAAM,SAAA,GAAY,CACvB,MAAA,EACA,MAAA,EACA,IAAA,KACS;AACT,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,KAAA,CAAM,eAAe,MAAM,CAAA;AAC3B,EAAA,KAAA,CAAM,SAAA,CAAU,EAAE,EAAA,EAAI,MAAA,CAAO,IAAI,OAAA,EAAS,MAAA,CAAO,IAAI,CAAA;AACrD,EAAA,MAAM,WAAW,KAAA,CAAM,cAAA,CAAe,MAAA,CAAO,EAAE,EAAE,MAAA,EAAQ,EAAA;AACzD,EAAA,IAAI,aAAa,MAAA,EAAW;AAC5B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A,EAAO,WAAU,CAAE,CAAA;AACpH,EAAA,MAAM,EAAE,MAAM,SAAA,EAAW,KAAA,KAAU,UAAA,CAAW,EAAE,QAAA,EAAU,KAAA,EAAO,CAAA;AACjE,EAAA,OAAO,EAAE,IAAA,EAAM,SAAA,EAAW,KAAA,EAAO,UAAA,EAAY,EAAE,CAAC,OAAO,GAAG,WAAA,CAAY,UAAU,CAAA,EAAE,EAAE;AACtF","file":"index.cjs","sourcesContent":["import type { ActionDefinition } from '@niscorp/nova';\nimport type { LoomEditor } from './types.js';\n\nexport const mountView = (\n editor: LoomEditor,\n action: ActionDefinition,\n read: (editor: LoomEditor) => Record<string, unknown>,\n): void => {\n const { shell } = editor;\n shell.registerAction(action);\n shell.addCanvas({ id: action.id, initial: action.id });\n const instance = shell.getCanvasState(action.id).active?.id;\n if (instance === undefined) return;\n const sync = (): void => {\n shell.getRuntime(instance)?.setData(read(editor));\n };\n editor.on('change', sync);\n sync();\n};\n","import { z, type ZodType } from 'zod';\n\nexport type NovaComponentShape = { name: string; props: ZodType; container?: boolean };\n\nexport const layoutSchema = (manifest: readonly NovaComponentShape[]): ZodType => {\n const [first, ...rest] = manifest;\n if (first === undefined) throw new Error('nova plugin: the manifest is empty');\n\n const recur: ZodType = z.lazy(() => layoutNode);\n const branch = (component: NovaComponentShape) =>\n z.object({\n component: z.literal(component.name),\n props: component.props,\n ...(component.container === true ? { children: z.array(recur) } : {}),\n });\n\n const layoutNode = z.discriminatedUnion('component', [branch(first), ...rest.map(branch)]);\n return layoutNode;\n};\n","import type { ZodType } from 'zod';\nimport type {\n CompileOptions,\n EmptyValue,\n EnumOption,\n Field,\n FieldKind,\n FieldMeta,\n ObjectField,\n Pattern,\n Variant,\n} from './types.js';\n\ntype ZodDef = {\n type: string;\n innerType?: ZodType;\n element?: ZodType;\n shape?: Record<string, ZodType>;\n entries?: Record<string, unknown>;\n defaultValue?: unknown;\n format?: string;\n checks?: ReadonlyArray<{ def?: { format?: string } }>;\n discriminator?: string;\n options?: readonly ZodType[];\n items?: readonly ZodType[];\n values?: readonly unknown[];\n getter?: () => ZodType;\n};\n\nconst defOf = (schema: ZodType): ZodDef => schema.def as ZodDef;\n\n// Keyed by def, not by instance: `.describe()` and `.meta()` clone the wrapper\n// but share the def, and an alias of a recursive schema has to be recognized as\n// the schema itself.\ntype Walk = { stack: Set<ZodDef>; targets: Set<ZodDef> };\n\nconst INTEGER_FORMAT = 'safeint';\n\nconst stringFormat = (schema: ZodType): string | undefined => {\n const def = defOf(schema);\n if (def.format !== undefined) return def.format;\n for (const check of def.checks ?? []) {\n if (check.def?.format !== undefined) return check.def.format;\n }\n return undefined;\n};\n\nconst isInteger = (schema: ZodType): boolean => {\n const def = defOf(schema);\n if (def.format === INTEGER_FORMAT) return true;\n return (def.checks ?? []).some((check) => check.def?.format === INTEGER_FORMAT);\n};\n\nconst enumOptions = (schema: ZodType): EnumOption[] =>\n Object.values(defOf(schema).entries ?? {}).map((value) => ({ value, label: String(value) }));\n\nconst objectFields = (schema: ZodType, walk: Walk): ObjectField[] =>\n Object.entries(defOf(schema).shape ?? {}).map(([key, value]) => ({\n key,\n required: !value.safeParse(undefined).success,\n field: parseField(value, walk),\n }));\n\nconst branchKeys = (branch: ZodType): string[] => Object.keys(defOf(branch).shape ?? {});\n\nconst JSON_TYPES = new Set(['string', 'number', 'boolean', 'object', 'array', 'null']);\nconst jsonType = (branch: ZodType): string | undefined => {\n const type = defOf(branch).type;\n return JSON_TYPES.has(type) ? type : undefined;\n};\n\nconst distinguish = (branch: ZodType, siblings: readonly ZodType[], tag: string | undefined): Pattern | undefined => {\n if (tag !== undefined) {\n const literal = (defOf(branch).shape ?? {})[tag];\n return { kind: 'tag', key: tag, value: literal !== undefined ? defOf(literal).values?.[0] : undefined };\n }\n const elsewhere = new Set(siblings.flatMap(branchKeys));\n const key = branchKeys(branch).find((k) => !elsewhere.has(k));\n if (key !== undefined) return { kind: 'key', key };\n const type = jsonType(branch);\n if (type !== undefined && siblings.every((s) => jsonType(s) !== type)) return { kind: 'type', type };\n return undefined;\n};\n\nconst patternLabel = (pattern: Pattern): string =>\n pattern.kind === 'tag'\n ? String(pattern.value)\n : pattern.kind === 'key'\n ? pattern.key\n : pattern.kind === 'type'\n ? pattern.type\n : 'other';\n\nconst flattenBranches = (branches: readonly ZodType[], seen: Set<ZodDef> = new Set()): ZodType[] =>\n branches.flatMap((branch) => {\n const { core } = unwrap(branch);\n const def = defOf(core);\n if (def.type !== 'union' || seen.has(def)) return [branch];\n return flattenBranches(def.options ?? [], new Set(seen).add(def));\n });\n\nconst branchField = (branch: ZodType, walk: Walk, tag: string | undefined): Field =>\n tag === undefined\n ? parseField(branch, walk)\n : { kind: 'object', fields: objectFields(branch, walk).filter((f) => f.key !== tag) };\n\nconst parseByType: Record<string, (schema: ZodType, walk: Walk) => Field> = {\n string: (schema) => {\n const format = stringFormat(schema);\n return format !== undefined ? { kind: 'string', format } : { kind: 'string' };\n },\n number: (schema) => (isInteger(schema) ? { kind: 'number', integer: true } : { kind: 'number' }),\n boolean: () => ({ kind: 'boolean' }),\n enum: (schema) => ({ kind: 'enum', options: enumOptions(schema) }),\n object: (schema, walk) => {\n const def = defOf(schema);\n walk.stack.add(def);\n const fields = objectFields(schema, walk);\n walk.stack.delete(def);\n return walk.targets.has(def) ? { kind: 'object', fields, recursive: true } : { kind: 'object', fields };\n },\n array: (schema, walk) => {\n const element = defOf(schema).element;\n return { kind: 'array', item: element !== undefined ? parseField(element, walk) : { kind: 'unknown' } };\n },\n tuple: (schema, walk) => ({ kind: 'tuple', items: (defOf(schema).items ?? []).map((item) => parseField(item, walk)) }),\n union: (schema, walk) => {\n // Deduplicated by identity: a union that nests back into itself yields the\n // same member instances twice.\n const branches = [...new Set(flattenBranches(defOf(schema).options ?? []))];\n const tag = defOf(schema).discriminator;\n const patterns = branches.map((b) => distinguish(b, branches.filter((x) => x !== b), tag));\n const open = patterns.reduce<number[]>((acc, p, i) => (p === undefined ? [...acc, i] : acc), []);\n if (branches.length === 0 || open.length > 1) return { kind: 'unknown' };\n if (open.length === 1) patterns[open[0]!] = { kind: 'fallback' };\n const def = defOf(schema);\n walk.stack.add(def);\n const variants: Variant[] = branches.map((branch, i) => ({\n label: readMeta(branch).title ?? patternLabel(patterns[i]!),\n field: branchField(branch, walk, tag),\n pattern: patterns[i]!,\n }));\n walk.stack.delete(def);\n return walk.targets.has(def) ? { kind: 'union', variants, recursive: true } : { kind: 'union', variants };\n },\n};\n\nconst unknownField = (): Field => ({ kind: 'unknown' });\n\nconst WRAPPERS = new Set(['optional', 'nullable', 'default', 'readonly']);\n\n// A lazy's getter may build a fresh instance on every call\n// (`z.lazy(() => z.union([...]))`). Cycle detection needs the same instance each\n// time, so each lazy is resolved once.\nconst lazyResolved = new WeakMap<ZodDef, ZodType>();\nconst resolveLazy = (lazy: ZodType): ZodType | undefined => {\n const def = defOf(lazy);\n const cached = lazyResolved.get(def);\n if (cached !== undefined) return cached;\n const resolved = def.getter?.();\n if (resolved !== undefined) lazyResolved.set(def, resolved);\n return resolved;\n};\n\nconst unwrap = (schema: ZodType): { core: ZodType; default?: unknown } => {\n let core = schema;\n let fallback: unknown;\n let def = defOf(core);\n while (WRAPPERS.has(def.type) || def.type === 'lazy') {\n const inner = def.type === 'lazy' ? resolveLazy(core) : def.innerType;\n if (inner === undefined) break;\n if ('defaultValue' in def) fallback = def.defaultValue;\n core = inner;\n def = defOf(core);\n }\n return fallback !== undefined ? { core, default: fallback } : { core };\n};\n\nconst readMeta = (schema: ZodType): FieldMeta => {\n const meta: FieldMeta = {};\n const title = (schema.meta() as { title?: unknown } | undefined)?.title;\n if (typeof title === 'string') meta.title = title;\n if (schema.description !== undefined) meta.description = schema.description;\n return meta;\n};\n\nconst parseField = (schema: ZodType, walk: Walk): Field => {\n const { core, default: fallback } = unwrap(schema);\n if (walk.stack.has(defOf(core))) {\n walk.targets.add(defOf(core));\n return { kind: 'self' };\n }\n const body = (parseByType[defOf(core).type] ?? unknownField)(core, walk);\n const meta = { ...readMeta(core), ...readMeta(schema) };\n return { ...body, ...meta, ...(fallback !== undefined ? { default: fallback } : {}) };\n};\n\nexport const parse = (schema: ZodType): Field =>\n parseField(schema, { stack: new Set(), targets: new Set() });\n\nconst EMPTY: Record<FieldKind, EmptyValue> = {\n string: () => '',\n number: () => 0,\n boolean: () => false,\n // `undefined`, not `null`: an optional enum accepts absence and a required one\n // reports it, while a Zod enum rejects `null` outright.\n enum: () => undefined,\n array: () => [],\n tuple: (field, options) => (field.kind === 'tuple' ? field.items.map((item) => buildDocument(item, options)) : []),\n self: () => undefined,\n unknown: () => null,\n object: (field, options) => {\n if (field.kind !== 'object') return {};\n const includeOptional = options.includeOptional ?? true;\n const document: Record<string, unknown> = {};\n for (const child of field.fields) {\n if (!child.required && !includeOptional) continue;\n const value = buildDocument(child.field, options);\n if (value !== undefined) document[child.key] = value;\n }\n return document;\n },\n union: (field) => {\n if (field.kind !== 'union') return {};\n const first = field.variants[0];\n return first === undefined ? {} : variantDefaults(first);\n },\n};\n\nexport const buildDocument = (field: Field, options: CompileOptions): unknown => {\n if (field.default !== undefined) return field.default;\n return (options.empty?.[field.kind] ?? EMPTY[field.kind])(field, options);\n};\n\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nexport const variantDefaults = (variant: Variant): unknown => {\n const defaults = buildDocument(variant.field, {});\n if (variant.pattern.kind !== 'tag') return defaults;\n return { [variant.pattern.key]: variant.pattern.value, ...(isRecord(defaults) ? defaults : {}) };\n};\n","import type { LayoutNode } from '@niscorp/nova';\nimport { isRecord } from '@compile/parse';\n\nconst fieldFor = (key: string, value: unknown): LayoutNode => ({\n component: 'loom:field',\n props: { label: key },\n children: [{ component: typeof value === 'string' ? 'loom:text' : 'loom:raw', model: `$.${key}` }],\n});\n\nexport const dataLayout = (value: unknown): LayoutNode => {\n const data = isRecord(value) ? value : {};\n return {\n component: 'Stack',\n props: { direction: 'column', gap: 12 },\n children: Object.keys(data).map((key) => fieldFor(key, data[key])),\n };\n};\n","import type { LayoutNode } from '@niscorp/nova';\n\nexport const PREVIEW = 'nova:preview';\n\nexport const previewLayout: LayoutNode = {\n component: PREVIEW,\n props: { documents: '$.documents' },\n};\n","import type { ActionDefinition } from '@niscorp/nova';\nimport { previewLayout, PREVIEW } from './preview.layout.js';\n\nexport const previewAction: ActionDefinition = {\n id: PREVIEW,\n layout: previewLayout,\n data: { documents: {} },\n};\n","import { mountView } from '@editor/view';\nimport type { LoomPlugin } from '@editor/types';\nimport { layoutSchema, type NovaComponentShape } from './schema.js';\nimport { dataLayout } from './data.layout.js';\nimport { previewAction } from './preview.action.js';\n\nexport { PREVIEW } from './preview.layout.js';\nexport { layoutSchema, type NovaComponentShape } from './schema.js';\n\nexport type NovaPluginConfig = { manifest: readonly NovaComponentShape[] };\n\nexport const novaPlugin = (config: NovaPluginConfig): LoomPlugin => ({\n name: 'nova',\n documents: {\n layout: layoutSchema(config.manifest),\n data: dataLayout,\n },\n mount: (editor) => mountView(editor, previewAction, (e) => ({ documents: e.documents })),\n});\n","import type { CSSProperties, FC } from 'react';\nimport type { LayoutNode } from '@niscorp/nova';\nimport { Nova, type NovaComponent } from '@niscorp/nova/adapters/react';\nimport { isRecord } from '@compile/parse';\n\nconst frame: CSSProperties = {\n padding: 24,\n borderRadius: 12,\n minHeight: 220,\n background: 'radial-gradient(circle at 30% 15%, #1b1b3a, #0c0c18 70%)',\n border: '1px solid #2a2a4a',\n};\n\nexport const makePreview = (components: Record<string, NovaComponent>): NovaComponent<{ documents?: unknown }> => {\n const Preview: FC<{ documents?: unknown }> = ({ documents }) => {\n const docs = isRecord(documents) ? documents : {};\n const layout = docs['layout'];\n const data = isRecord(docs['data']) ? (docs['data'] as Record<string, unknown>) : {};\n return (\n <div style={frame}>\n {isRecord(layout) ? (\n <Nova.Layout layout={layout as LayoutNode} data={data} components={components} builtins={false} />\n ) : null}\n </div>\n );\n };\n return Preview;\n};\n","import type { NovaComponent } from '@niscorp/nova/adapters/react';\nimport type { LoomEditorPlugin } from '@react';\nimport { novaPlugin, PREVIEW, type NovaComponentShape } from '../index.js';\nimport { makePreview } from './preview.js';\n\nexport type NovaManifestEntry = NovaComponentShape & { render: NovaComponent };\n\nexport type NovaConfig = { manifest: readonly NovaManifestEntry[] };\n\nexport const nova = (config: NovaConfig): LoomEditorPlugin => {\n const components: Record<string, NovaComponent> = Object.fromEntries(\n config.manifest.map((entry) => [entry.name, entry.render]),\n );\n const shape: NovaComponentShape[] = config.manifest.map(({ name, props, container }) => ({ name, props, container }));\n const { name, documents, mount } = novaPlugin({ manifest: shape });\n return { name, documents, mount, components: { [PREVIEW]: makePreview(components) } };\n};\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { NovaComponent } from '@niscorp/nova/adapters/react';
|
|
2
|
-
import { L as LoomEditorPlugin } from '../../../loom-editor-
|
|
2
|
+
import { L as LoomEditorPlugin } from '../../../loom-editor-BthwIGIZ.cjs';
|
|
3
3
|
import { N as NovaComponentShape } from '../../../schema--OhtatTX.cjs';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import '@niscorp/nova';
|
|
7
|
-
import '../../../types-
|
|
7
|
+
import '../../../types-V5kJWZJn.cjs';
|
|
8
8
|
|
|
9
9
|
type NovaManifestEntry = NovaComponentShape & {
|
|
10
10
|
render: NovaComponent;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { NovaComponent } from '@niscorp/nova/adapters/react';
|
|
2
|
-
import { L as LoomEditorPlugin } from '../../../loom-editor-
|
|
2
|
+
import { L as LoomEditorPlugin } from '../../../loom-editor-CHtjjiBp.js';
|
|
3
3
|
import { N as NovaComponentShape } from '../../../schema--OhtatTX.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import '@niscorp/nova';
|
|
7
|
-
import '../../../types-
|
|
7
|
+
import '../../../types-V5kJWZJn.js';
|
|
8
8
|
|
|
9
9
|
type NovaManifestEntry = NovaComponentShape & {
|
|
10
10
|
render: NovaComponent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { novaPlugin, PREVIEW } from '../../../chunk-
|
|
2
|
-
import { isRecord } from '../../../chunk-
|
|
3
|
-
import '../../../chunk-
|
|
1
|
+
import { novaPlugin, PREVIEW } from '../../../chunk-HHPSU7IA.js';
|
|
2
|
+
import { isRecord } from '../../../chunk-DEZGKUTO.js';
|
|
3
|
+
import '../../../chunk-27OMOR7I.js';
|
|
4
4
|
import { Nova } from '@niscorp/nova/adapters/react';
|
|
5
5
|
import { jsx } from 'react/jsx-runtime';
|
|
6
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/nova/react/preview.tsx","../../../../src/plugins/nova/react/index.ts"],"names":["name"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/nova/react/preview.tsx","../../../../src/plugins/nova/react/index.ts"],"names":["name"],"mappings":";;;;;;AAKA,IAAM,KAAA,GAAuB;AAAA,EAC3B,OAAA,EAAS,EAAA;AAAA,EACT,YAAA,EAAc,EAAA;AAAA,EACd,SAAA,EAAW,GAAA;AAAA,EACX,UAAA,EAAY,0DAAA;AAAA,EACZ,MAAA,EAAQ;AACV,CAAA;AAEO,IAAM,WAAA,GAAc,CAAC,UAAA,KAAsF;AAChH,EAAA,MAAM,OAAA,GAAuC,CAAC,EAAE,SAAA,EAAU,KAAM;AAC9D,IAAA,MAAM,IAAA,GAAO,QAAA,CAAS,SAAS,CAAA,GAAI,YAAY,EAAC;AAChD,IAAA,MAAM,MAAA,GAAS,KAAK,QAAQ,CAAA;AAC5B,IAAA,MAAM,IAAA,GAAO,SAAS,IAAA,CAAK,MAAM,CAAC,CAAA,GAAK,IAAA,CAAK,MAAM,CAAA,GAAgC,EAAC;AACnF,IAAA,2BACG,KAAA,EAAA,EAAI,KAAA,EAAO,KAAA,EACT,QAAA,EAAA,QAAA,CAAS,MAAM,CAAA,mBACd,GAAA,CAAC,IAAA,CAAK,MAAA,EAAL,EAAY,MAAA,EAA8B,IAAA,EAAY,YAAwB,QAAA,EAAU,KAAA,EAAO,IAC9F,IAAA,EACN,CAAA;AAAA,EAEJ,CAAA;AACA,EAAA,OAAO,OAAA;AACT,CAAA;;;AClBO,IAAM,IAAA,GAAO,CAAC,MAAA,KAAyC;AAC5D,EAAA,MAAM,aAA4C,MAAA,CAAO,WAAA;AAAA,IACvD,MAAA,CAAO,QAAA,CAAS,GAAA,CAAI,CAAC,KAAA,KAAU,CAAC,KAAA,CAAM,IAAA,EAAM,KAAA,CAAM,MAAM,CAAC;AAAA,GAC3D;AACA,EAAA,MAAM,QAA8B,MAAA,CAAO,QAAA,CAAS,GAAA,CAAI,CAAC,EAAE,IAAA,EAAAA,KAAAA,EAAM,KAAA,EAAO,SAAA,QAAiB,EAAE,IAAA,EAAAA,KAAAA,EAAM,KAAA,EAAO,WAAU,CAAE,CAAA;AACpH,EAAA,MAAM,EAAE,MAAM,SAAA,EAAW,KAAA,KAAU,UAAA,CAAW,EAAE,QAAA,EAAU,KAAA,EAAO,CAAA;AACjE,EAAA,OAAO,EAAE,IAAA,EAAM,SAAA,EAAW,KAAA,EAAO,UAAA,EAAY,EAAE,CAAC,OAAO,GAAG,WAAA,CAAY,UAAU,CAAA,EAAE,EAAE;AACtF","file":"index.js","sourcesContent":["import type { CSSProperties, FC } from 'react';\nimport type { LayoutNode } from '@niscorp/nova';\nimport { Nova, type NovaComponent } from '@niscorp/nova/adapters/react';\nimport { isRecord } from '@compile/parse';\n\nconst frame: CSSProperties = {\n padding: 24,\n borderRadius: 12,\n minHeight: 220,\n background: 'radial-gradient(circle at 30% 15%, #1b1b3a, #0c0c18 70%)',\n border: '1px solid #2a2a4a',\n};\n\nexport const makePreview = (components: Record<string, NovaComponent>): NovaComponent<{ documents?: unknown }> => {\n const Preview: FC<{ documents?: unknown }> = ({ documents }) => {\n const docs = isRecord(documents) ? documents : {};\n const layout = docs['layout'];\n const data = isRecord(docs['data']) ? (docs['data'] as Record<string, unknown>) : {};\n return (\n <div style={frame}>\n {isRecord(layout) ? (\n <Nova.Layout layout={layout as LayoutNode} data={data} components={components} builtins={false} />\n ) : null}\n </div>\n );\n };\n return Preview;\n};\n","import type { NovaComponent } from '@niscorp/nova/adapters/react';\nimport type { LoomEditorPlugin } from '@react';\nimport { novaPlugin, PREVIEW, type NovaComponentShape } from '../index.js';\nimport { makePreview } from './preview.js';\n\nexport type NovaManifestEntry = NovaComponentShape & { render: NovaComponent };\n\nexport type NovaConfig = { manifest: readonly NovaManifestEntry[] };\n\nexport const nova = (config: NovaConfig): LoomEditorPlugin => {\n const components: Record<string, NovaComponent> = Object.fromEntries(\n config.manifest.map((entry) => [entry.name, entry.render]),\n );\n const shape: NovaComponentShape[] = config.manifest.map(({ name, props, container }) => ({ name, props, container }));\n const { name, documents, mount } = novaPlugin({ manifest: shape });\n return { name, documents, mount, components: { [PREVIEW]: makePreview(components) } };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/view.ts","../../../src/plugins/prism/preview.layout.ts","../../../src/plugins/prism/preview.action.ts","../../../src/plugins/prism/index.ts"],"names":["NodeSchema"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/view.ts","../../../src/plugins/prism/preview.layout.ts","../../../src/plugins/prism/preview.action.ts","../../../src/plugins/prism/index.ts"],"names":["NodeSchema"],"mappings":";;;;;;;AAGO,IAAM,SAAA,GAAY,CACvB,MAAA,EACA,MAAA,EACA,IAAA,KACS;AACT,EAAA,MAAM,EAAE,OAAM,GAAI,MAAA;AAClB,EAAA,KAAA,CAAM,eAAe,MAAM,CAAA;AAC3B,EAAA,KAAA,CAAM,SAAA,CAAU,EAAE,EAAA,EAAI,MAAA,CAAO,IAAI,OAAA,EAAS,MAAA,CAAO,IAAI,CAAA;AACrD,EAAA,MAAM,WAAW,KAAA,CAAM,cAAA,CAAe,MAAA,CAAO,EAAE,EAAE,MAAA,EAAQ,EAAA;AACzD,EAAA,IAAI,aAAa,MAAA,EAAW;AAC5B,EAAA,MAAM,OAAO,MAAY;AACvB,IAAA,KAAA,CAAM,WAAW,QAAQ,CAAA,EAAG,OAAA,CAAQ,IAAA,CAAK,MAAM,CAAC,CAAA;AAAA,EAClD,CAAA;AACA,EAAA,MAAA,CAAO,EAAA,CAAG,UAAU,IAAI,CAAA;AACxB,EAAA,IAAA,EAAK;AACP,CAAA;;;AChBO,IAAM,OAAA,GAAU;AAEhB,IAAM,aAAA,GAA4B;AAAA,EACvC,SAAA,EAAW,OAAA;AAAA,EACX,KAAA,EAAO,EAAE,MAAA,EAAQ,UAAA;AACnB,CAAA;;;ACJO,IAAM,aAAA,GAAkC;AAAA,EAC7C,EAAA,EAAI,OAAA;AAAA,EACJ,MAAA,EAAQ,aAAA;AAAA,EACR,IAAA,EAAM,EAAE,MAAA,EAAQ,IAAA;AAClB,CAAA;;;ACEO,IAAM,IAAA,GAAO;AAOb,IAAM,WAAA,GAAc,CAAC,OAAA,MAA6C;AAAA,EACvE,IAAA,EAAM,OAAA;AAAA,EACN,SAAA,EAAW,EAAE,MAAA,EAAQ,OAAA,CAAQ,UAAWA,gBAAA,EAAuB;AAAA,EAC/D,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,MAAM,KAAA,EAAO,CAAC,KAAA,KAAU,KAAA,CAAM,IAAA,KAAS,OAAA,IAAW,KAAA,CAAM,IAAA,KAAS,IAAI,CAAA;AAAA,EACvF,KAAA,EAAO,CAAC,MAAA,KACN,SAAA,CAAU,QAAQ,aAAA,EAAe,CAAC,CAAA,MAAO,EAAE,MAAA,EAAS,CAAA,CAAE,SAAA,CAAsC,QAAQ,GAAE,CAAE;AAC5G,CAAA","file":"index.cjs","sourcesContent":["import type { ActionDefinition } from '@niscorp/nova';\nimport type { LoomEditor } from './types.js';\n\nexport const mountView = (\n editor: LoomEditor,\n action: ActionDefinition,\n read: (editor: LoomEditor) => Record<string, unknown>,\n): void => {\n const { shell } = editor;\n shell.registerAction(action);\n shell.addCanvas({ id: action.id, initial: action.id });\n const instance = shell.getCanvasState(action.id).active?.id;\n if (instance === undefined) return;\n const sync = (): void => {\n shell.getRuntime(instance)?.setData(read(editor));\n };\n editor.on('change', sync);\n sync();\n};\n","import type { LayoutNode } from '@niscorp/nova';\n\nexport const PREVIEW = 'prism:preview';\n\nexport const previewLayout: LayoutNode = {\n component: PREVIEW,\n props: { config: '$.config' },\n};\n","import type { ActionDefinition } from '@niscorp/nova';\nimport { previewLayout, PREVIEW } from './preview.layout.js';\n\nexport const previewAction: ActionDefinition = {\n id: PREVIEW,\n layout: previewLayout,\n data: { config: null },\n};\n","import type { ZodType } from 'zod';\nimport { NodeSchema, type Config, type JsonObject, type JsonValue } from '@niscorp/prism';\nimport { mountView } from '@editor/view';\nimport type { LoomPlugin } from '@editor/types';\nimport { previewAction } from './preview.action.js';\n\nexport { PREVIEW } from './preview.layout.js';\nexport type { Config, JsonObject, JsonValue };\n\nexport const NODE = 'prism:node';\n\nexport type PrismPluginOptions = {\n input: JsonObject;\n schema?: ZodType;\n};\n\nexport const prismPlugin = (options: PrismPluginOptions): LoomPlugin => ({\n name: 'prism',\n documents: { config: options.schema ?? (NodeSchema as ZodType) },\n widgets: [{ role: NODE, match: (field) => field.kind === 'union' && field.path === '' }],\n mount: (editor) =>\n mountView(editor, previewAction, (e) => ({ config: (e.documents as Record<string, unknown>)['config'] })),\n});\n"]}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { ZodType } from 'zod';
|
|
2
2
|
import { JsonObject } from '@niscorp/prism';
|
|
3
3
|
export { Config, JsonObject, JsonValue } from '@niscorp/prism';
|
|
4
|
-
import { h as LoomPlugin } from '../../types-
|
|
4
|
+
import { h as LoomPlugin } from '../../types-V5kJWZJn.cjs';
|
|
5
5
|
import '@niscorp/nova';
|
|
6
6
|
|
|
7
7
|
declare const PREVIEW = "prism:preview";
|
|
8
8
|
|
|
9
9
|
declare const NODE = "prism:node";
|
|
10
10
|
type PrismPluginOptions = {
|
|
11
|
-
/** Sample source data the edited config is applied to in the preview. */
|
|
12
11
|
input: JsonObject;
|
|
13
|
-
/** Override the edited schema; defaults to Prism's `NodeSchema`. */
|
|
14
12
|
schema?: ZodType;
|
|
15
13
|
};
|
|
16
14
|
declare const prismPlugin: (options: PrismPluginOptions) => LoomPlugin;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { ZodType } from 'zod';
|
|
2
2
|
import { JsonObject } from '@niscorp/prism';
|
|
3
3
|
export { Config, JsonObject, JsonValue } from '@niscorp/prism';
|
|
4
|
-
import { h as LoomPlugin } from '../../types-
|
|
4
|
+
import { h as LoomPlugin } from '../../types-V5kJWZJn.js';
|
|
5
5
|
import '@niscorp/nova';
|
|
6
6
|
|
|
7
7
|
declare const PREVIEW = "prism:preview";
|
|
8
8
|
|
|
9
9
|
declare const NODE = "prism:node";
|
|
10
10
|
type PrismPluginOptions = {
|
|
11
|
-
/** Sample source data the edited config is applied to in the preview. */
|
|
12
11
|
input: JsonObject;
|
|
13
|
-
/** Override the edited schema; defaults to Prism's `NodeSchema`. */
|
|
14
12
|
schema?: ZodType;
|
|
15
13
|
};
|
|
16
14
|
declare const prismPlugin: (options: PrismPluginOptions) => LoomPlugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { NODE, PREVIEW, prismPlugin } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
1
|
+
export { NODE, PREVIEW, prismPlugin } from '../../chunk-LVDY6FUH.js';
|
|
2
|
+
import '../../chunk-27OMOR7I.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -97,8 +97,6 @@ var isInteger = (schema) => {
|
|
|
97
97
|
var enumOptions = (schema) => Object.values(defOf(schema).entries ?? {}).map((value) => ({ value, label: String(value) }));
|
|
98
98
|
var objectFields = (schema, walk) => Object.entries(defOf(schema).shape ?? {}).map(([key, value]) => ({
|
|
99
99
|
key,
|
|
100
|
-
// A property is optional when the schema accepts `undefined` for it
|
|
101
|
-
// (covers `.optional()` and `.default()`) — asked of Zod, not inferred.
|
|
102
100
|
required: !value.safeParse(void 0).success,
|
|
103
101
|
field: parseField(value, walk)
|
|
104
102
|
}));
|
|
@@ -212,14 +210,11 @@ var EMPTY = {
|
|
|
212
210
|
string: () => "",
|
|
213
211
|
number: () => 0,
|
|
214
212
|
boolean: () => false,
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
// Zod enum rejects outright. Defaults drop undefined, so no stray key.
|
|
213
|
+
// `undefined`, not `null`: an optional enum accepts absence and a required one
|
|
214
|
+
// reports it, while a Zod enum rejects `null` outright.
|
|
218
215
|
enum: () => void 0,
|
|
219
216
|
array: () => [],
|
|
220
|
-
// Each slot built from its own field; a fixed-length list, so no growth.
|
|
221
217
|
tuple: (field, options) => field.kind === "tuple" ? field.items.map((item) => buildDocument(item, options)) : [],
|
|
222
|
-
// A recursion point has no value of its own; the array holding it defaults to [].
|
|
223
218
|
self: () => void 0,
|
|
224
219
|
unknown: () => null,
|
|
225
220
|
object: (field, options) => {
|
|
@@ -233,7 +228,6 @@ var EMPTY = {
|
|
|
233
228
|
}
|
|
234
229
|
return document;
|
|
235
230
|
},
|
|
236
|
-
// An empty union defaults to its first variant (tag + branch defaults).
|
|
237
231
|
union: (field) => {
|
|
238
232
|
if (field.kind !== "union") return {};
|
|
239
233
|
const first = field.variants[0];
|
|
@@ -647,14 +641,10 @@ var ListEditor = ({ itemField, value, onChange }) => {
|
|
|
647
641
|
const removeAt = (index) => onChange(list.filter((_, i) => i !== index));
|
|
648
642
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: block, children: [
|
|
649
643
|
list.map(
|
|
650
|
-
(item, index) => (
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { flex: 1, minWidth: 0 }, children: /* @__PURE__ */ jsxRuntime.jsx(ArgEditor, { field: itemField, value: item, onChange: (next) => setAt(index, next) }) }),
|
|
655
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: iconBtn, onClick: () => removeAt(index), children: "\u2715" })
|
|
656
|
-
] }, index)
|
|
657
|
-
)
|
|
644
|
+
(item, index) => itemField.kind === "self" ? /* @__PURE__ */ jsxRuntime.jsx(NodeEditor, { value: item, onChange: (next) => setAt(index, next), onRemove: () => removeAt(index) }, index) : /* @__PURE__ */ jsxRuntime.jsxs("div", { style: rowStyle, children: [
|
|
645
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { flex: 1, minWidth: 0 }, children: /* @__PURE__ */ jsxRuntime.jsx(ArgEditor, { field: itemField, value: item, onChange: (next) => setAt(index, next) }) }),
|
|
646
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: iconBtn, onClick: () => removeAt(index), children: "\u2715" })
|
|
647
|
+
] }, index)
|
|
658
648
|
),
|
|
659
649
|
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: addBtn, onClick: () => onChange([...list, defaultItem(itemField)]), children: "Add" })
|
|
660
650
|
] });
|