@niscorp/loom 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/DESIGN.md +48 -10
  3. package/README.md +63 -11
  4. package/dist/{chunk-HHPSU7IA.js → chunk-3UI7CG24.js} +3 -4
  5. package/dist/chunk-3UI7CG24.js.map +1 -0
  6. package/dist/{chunk-LVDY6FUH.js → chunk-BYOKCNIJ.js} +3 -3
  7. package/dist/{chunk-LVDY6FUH.js.map → chunk-BYOKCNIJ.js.map} +1 -1
  8. package/dist/chunk-GXA57JFR.js +409 -0
  9. package/dist/chunk-GXA57JFR.js.map +1 -0
  10. package/dist/chunk-J5SYOIR2.js +100 -0
  11. package/dist/chunk-J5SYOIR2.js.map +1 -0
  12. package/dist/{chunk-VMOYMYMV.js → chunk-LAQIW27Q.js} +3 -3
  13. package/dist/chunk-LAQIW27Q.js.map +1 -0
  14. package/dist/{chunk-IQMWPPHW.js → chunk-OVTQEAV3.js} +290 -23
  15. package/dist/chunk-OVTQEAV3.js.map +1 -0
  16. package/dist/index.cjs +74 -32
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +9 -9
  19. package/dist/index.d.ts +9 -9
  20. package/dist/index.js +1 -4
  21. package/dist/loom-editor-DlNYrfT9.d.ts +15 -0
  22. package/dist/loom-editor-DtGAf8eH.d.cts +15 -0
  23. package/dist/plugins/nova/index.cjs +6 -3
  24. package/dist/plugins/nova/index.cjs.map +1 -1
  25. package/dist/plugins/nova/index.d.cts +1 -1
  26. package/dist/plugins/nova/index.d.ts +1 -1
  27. package/dist/plugins/nova/index.js +2 -3
  28. package/dist/plugins/nova/react/index.cjs +21 -7
  29. package/dist/plugins/nova/react/index.cjs.map +1 -1
  30. package/dist/plugins/nova/react/index.d.cts +2 -2
  31. package/dist/plugins/nova/react/index.d.ts +2 -2
  32. package/dist/plugins/nova/react/index.js +5 -5
  33. package/dist/plugins/nova/react/index.js.map +1 -1
  34. package/dist/plugins/prism/index.cjs +2 -0
  35. package/dist/plugins/prism/index.cjs.map +1 -1
  36. package/dist/plugins/prism/index.d.cts +1 -1
  37. package/dist/plugins/prism/index.d.ts +1 -1
  38. package/dist/plugins/prism/index.js +2 -2
  39. package/dist/plugins/prism/react/index.cjs +200 -189
  40. package/dist/plugins/prism/react/index.cjs.map +1 -1
  41. package/dist/plugins/prism/react/index.d.cts +3 -3
  42. package/dist/plugins/prism/react/index.d.ts +3 -3
  43. package/dist/plugins/prism/react/index.js +48 -108
  44. package/dist/plugins/prism/react/index.js.map +1 -1
  45. package/dist/plugins/vex/index.cjs +2 -0
  46. package/dist/plugins/vex/index.cjs.map +1 -1
  47. package/dist/plugins/vex/index.d.cts +1 -1
  48. package/dist/plugins/vex/index.d.ts +1 -1
  49. package/dist/plugins/vex/index.js +2 -2
  50. package/dist/plugins/vex/react/index.cjs +154 -96
  51. package/dist/plugins/vex/react/index.cjs.map +1 -1
  52. package/dist/plugins/vex/react/index.d.cts +3 -3
  53. package/dist/plugins/vex/react/index.d.ts +3 -3
  54. package/dist/plugins/vex/react/index.js +42 -29
  55. package/dist/plugins/vex/react/index.js.map +1 -1
  56. package/dist/react/index.cjs +153 -92
  57. package/dist/react/index.cjs.map +1 -1
  58. package/dist/react/index.d.cts +7 -3
  59. package/dist/react/index.d.ts +7 -3
  60. package/dist/react/index.js +3 -118
  61. package/dist/react/index.js.map +1 -1
  62. package/dist/{types-V5kJWZJn.d.ts → types-BWIIThEy.d.cts} +2 -0
  63. package/dist/{types-V5kJWZJn.d.cts → types-BWIIThEy.d.ts} +2 -0
  64. package/package.json +7 -7
  65. package/dist/chunk-27OMOR7I.js +0 -17
  66. package/dist/chunk-27OMOR7I.js.map +0 -1
  67. package/dist/chunk-67D727GH.js +0 -47
  68. package/dist/chunk-67D727GH.js.map +0 -1
  69. package/dist/chunk-BU5TULRP.js +0 -132
  70. package/dist/chunk-BU5TULRP.js.map +0 -1
  71. package/dist/chunk-DEZGKUTO.js +0 -170
  72. package/dist/chunk-DEZGKUTO.js.map +0 -1
  73. package/dist/chunk-HHPSU7IA.js.map +0 -1
  74. package/dist/chunk-IQMWPPHW.js.map +0 -1
  75. package/dist/chunk-OFKHIREC.js +0 -212
  76. package/dist/chunk-OFKHIREC.js.map +0 -1
  77. package/dist/chunk-VMOYMYMV.js.map +0 -1
  78. package/dist/loom-editor-BthwIGIZ.d.cts +0 -24
  79. package/dist/loom-editor-CHtjjiBp.d.ts +0 -24
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ZodType } from 'zod';
2
- import { F as Field, C as CompileOptions, L as LoomEditor, a as LoomEditorConfig } from './types-V5kJWZJn.js';
3
- export { D as Document, b as DocumentLayout, E as EmptyValue, c as EnumOption, d as FieldKind, e as FieldMeta, f as LoomArtifact, g as LoomEvent, h as LoomPlugin, O as ObjectField, P as Pattern, V as Variant, W as WidgetBinding } from './types-V5kJWZJn.js';
2
+ import { F as Field, C as CompileOptions, L as LoomEditor, a as LoomEditorConfig } from './types-BWIIThEy.js';
3
+ export { D as Document, b as DocumentLayout, E as EmptyValue, c as EnumOption, d as FieldKind, e as FieldMeta, f as LoomArtifact, g as LoomEvent, h as LoomPlugin, O as ObjectField, P as Pattern, V as Variant, W as WidgetBinding } from './types-BWIIThEy.js';
4
4
  import { ActionDefinition, LayoutNode, Shell } from '@niscorp/nova';
5
5
 
6
6
  declare const parse: (schema: ZodType) => Field;
@@ -12,13 +12,6 @@ type NovaEditor = {
12
12
  };
13
13
  declare const toNova: (ir: Field, options?: CompileOptions) => NovaEditor;
14
14
 
15
- type Doc = Record<string, unknown>;
16
- declare const attachValidation: (shell: Shell, instanceId: string, schema: ZodType, onDocument?: (document: Doc) => void) => (() => void);
17
-
18
- declare const mountView: (editor: LoomEditor, action: ActionDefinition, read: (editor: LoomEditor) => Record<string, unknown>) => void;
19
-
20
- declare const createLoomEditor: (config: LoomEditorConfig) => LoomEditor;
21
-
22
15
  declare const Roles: {
23
16
  readonly box: "loom:box";
24
17
  readonly group: "loom:group";
@@ -37,4 +30,11 @@ declare const Roles: {
37
30
  };
38
31
  type Role = (typeof Roles)[keyof typeof Roles];
39
32
 
33
+ type Doc = Record<string, unknown>;
34
+ declare const attachValidation: (shell: Shell, instanceId: string, schema: ZodType, onDocument?: (document: Doc) => void) => (() => void);
35
+
36
+ declare const mountView: (editor: LoomEditor, action: ActionDefinition, read: (editor: LoomEditor) => Record<string, unknown>) => void;
37
+
38
+ declare const createLoomEditor: (config: LoomEditorConfig) => LoomEditor;
39
+
40
40
  export { CompileOptions, ERROR_NAMESPACE, Field, LoomEditor, LoomEditorConfig, type NovaEditor, type Role, Roles, attachValidation, createLoomEditor, mountView, parse, toNova };
package/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- export { ERROR_NAMESPACE, attachValidation, createLoomEditor, toNova } from './chunk-IQMWPPHW.js';
2
- export { Roles } from './chunk-67D727GH.js';
3
- export { parse } from './chunk-DEZGKUTO.js';
4
- export { mountView } from './chunk-27OMOR7I.js';
1
+ export { ERROR_NAMESPACE, Roles, attachValidation, createLoomEditor, mountView, parse, toNova } from './chunk-OVTQEAV3.js';
5
2
  //# sourceMappingURL=index.js.map
6
3
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,15 @@
1
+ import { FC } from 'react';
2
+ import { NovaComponent } from '@niscorp/nova/adapters/react';
3
+ import { h as LoomPlugin, f as LoomArtifact } from './types-BWIIThEy.js';
4
+
5
+ type LoomEditorPlugin = LoomPlugin & {
6
+ components?: Record<string, NovaComponent>;
7
+ };
8
+ type LoomEditorProps = {
9
+ plugins: LoomEditorPlugin[];
10
+ artifact: LoomArtifact;
11
+ onChange?: (documents: Record<string, unknown>) => void;
12
+ };
13
+ declare const LoomEditor: FC<LoomEditorProps>;
14
+
15
+ export { type LoomEditorPlugin as L, LoomEditor as a, type LoomEditorProps as b };
@@ -0,0 +1,15 @@
1
+ import { FC } from 'react';
2
+ import { NovaComponent } from '@niscorp/nova/adapters/react';
3
+ import { h as LoomPlugin, f as LoomArtifact } from './types-BWIIThEy.cjs';
4
+
5
+ type LoomEditorPlugin = LoomPlugin & {
6
+ components?: Record<string, NovaComponent>;
7
+ };
8
+ type LoomEditorProps = {
9
+ plugins: LoomEditorPlugin[];
10
+ artifact: LoomArtifact;
11
+ onChange?: (documents: Record<string, unknown>) => void;
12
+ };
13
+ declare const LoomEditor: FC<LoomEditorProps>;
14
+
15
+ export { type LoomEditorPlugin as L, LoomEditor as a, type LoomEditorProps as b };
@@ -1,6 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var zod = require('zod');
4
+ require('@niscorp/nova');
5
+
6
+ // src/editor/editor.ts
7
+
8
+ // src/compile/parse.ts
9
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4
10
 
5
11
  // src/editor/view.ts
6
12
  var mountView = (editor, action, read) => {
@@ -28,9 +34,6 @@ var layoutSchema = (manifest) => {
28
34
  return layoutNode;
29
35
  };
30
36
 
31
- // src/compile/parse.ts
32
- var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
33
-
34
37
  // src/plugins/nova/data.layout.ts
35
38
  var fieldFor = (key, value) => ({
36
39
  component: "loom:field",
@@ -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":";;;;;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,CA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AM;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
+ {"version":3,"sources":["../../../src/compile/parse.ts","../../../src/editor/view.ts","../../../src/plugins/nova/schema.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":";;;;;;;;AA0QO,IAAM,QAAA,GAAW,CAAC,KAAA,KACvB,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA,IAAQ,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;;;ACxQ9D,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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\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\n// A schema whose own code throws on a missing value cannot accept one.\nconst acceptsAbsence = (schema: ZodType): boolean => {\n try {\n return schema.safeParse(undefined).success;\n } catch {\n return false;\n }\n};\n\nconst objectFields = (schema: ZodType, walk: Walk): ObjectField[] =>\n Object.entries(defOf(schema).shape ?? {}).map(([key, value]) => ({\n key,\n required: !acceptsAbsence(value),\n field: parseField(value, walk),\n }));\n\n// A branch is read as what it unwraps to: a `z.lazy` or an optional branch has\n// no shape of its own.\nconst shapeOf = (branch: ZodType): Record<string, ZodType> => defOf(unwrap(branch).core).shape ?? {};\nconst branchKeys = (branch: ZodType): string[] => Object.keys(shapeOf(branch));\n\nconst JSON_TYPES = new Set(['string', 'number', 'boolean', 'object', 'array', 'null']);\nconst jsonType = (branch: ZodType): string | undefined => {\n const type = defOf(unwrap(branch).core).type;\n return JSON_TYPES.has(type) ? type : undefined;\n};\n\n// A literal lists its values, an enum its entries. The first is the tag a new\n// document of the branch gets; a stored document may have any of them.\nconst tagPattern = (key: string, discriminator: ZodType | undefined): Pattern => {\n const def = discriminator === undefined ? undefined : defOf(discriminator);\n const values = def === undefined ? [] : def.values !== undefined ? [...def.values] : Object.values(def.entries ?? {});\n return values.length > 1 ? { kind: 'tag', key, value: values[0], values } : { kind: 'tag', key, value: values[0] };\n};\n\nconst distinguish = (branch: ZodType, siblings: readonly ZodType[], tag: string | undefined): Pattern | undefined => {\n const shape = shapeOf(branch);\n if (tag !== undefined) {\n return tagPattern(tag, shape[tag]);\n }\n const elsewhere = new Set(siblings.flatMap(branchKeys));\n const own = Object.keys(shape).filter((k) => !elsewhere.has(k));\n // A key the branch requires is in every value of it; an optional one may be absent.\n const key = own.find((k) => {\n const schema = shape[k];\n return schema !== undefined && !acceptsAbsence(schema);\n }) ?? own[0];\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 literal: (schema) => {\n const values = defOf(schema).values ?? [];\n return { kind: 'enum', options: values.map((value) => ({ value, label: String(value) })), default: values[0] };\n },\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; nullable?: true } => {\n let core = schema;\n let fallback: unknown;\n let nullable = false;\n let def = defOf(core);\n while (WRAPPERS.has(def.type) || def.type === 'lazy') {\n if (def.type === 'nullable') nullable = true;\n const inner = def.type === 'lazy' ? resolveLazy(core) : def.innerType;\n if (inner === undefined) break;\n // The outermost default is the one zod applies.\n if ('defaultValue' in def && fallback === undefined) fallback = def.defaultValue;\n core = inner;\n def = defOf(core);\n }\n return { core, ...(fallback !== undefined ? { default: fallback } : {}), ...(nullable ? { nullable: true } : {}) };\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, nullable } = 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 } : {}), ...(nullable === true ? { nullable } : {}) };\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, options) => {\n if (field.kind !== 'union') return {};\n const first = field.variants[0];\n return first === undefined ? {} : variantDefaults(first, options);\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, options: CompileOptions): unknown => {\n const defaults = buildDocument(variant.field, options);\n if (variant.pattern.kind !== 'tag') return defaults;\n return { [variant.pattern.key]: variant.pattern.value, ...(isRecord(defaults) ? defaults : {}) };\n};\n","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 { LayoutNode } from '@niscorp/nova';\nimport { isRecord } from '@compile';\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, type LoomPlugin } from '@editor';\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-V5kJWZJn.cjs';
1
+ import { h as LoomPlugin } from '../../types-BWIIThEy.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,4 +1,4 @@
1
- import { h as LoomPlugin } from '../../types-V5kJWZJn.js';
1
+ import { h as LoomPlugin } from '../../types-BWIIThEy.js';
2
2
  import { N as NovaComponentShape } from '../../schema--OhtatTX.js';
3
3
  export { l as layoutSchema } from '../../schema--OhtatTX.js';
4
4
  import 'zod';
@@ -1,5 +1,4 @@
1
- export { PREVIEW, layoutSchema, novaPlugin } from '../../chunk-HHPSU7IA.js';
2
- import '../../chunk-DEZGKUTO.js';
3
- import '../../chunk-27OMOR7I.js';
1
+ export { PREVIEW, layoutSchema, novaPlugin } from '../../chunk-3UI7CG24.js';
2
+ import '../../chunk-OVTQEAV3.js';
4
3
  //# sourceMappingURL=index.js.map
5
4
  //# sourceMappingURL=index.js.map
@@ -1,8 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  var zod = require('zod');
4
- var react = require('@niscorp/nova/adapters/react');
4
+ require('@niscorp/nova');
5
+ var react$1 = require('@niscorp/nova/adapters/react');
5
6
  var jsxRuntime = require('react/jsx-runtime');
7
+ var react = require('react');
8
+
9
+ // src/editor/editor.ts
10
+
11
+ // src/compile/parse.ts
12
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
6
13
 
7
14
  // src/editor/view.ts
8
15
  var mountView = (editor, action, read) => {
@@ -30,9 +37,6 @@ var layoutSchema = (manifest) => {
30
37
  return layoutNode;
31
38
  };
32
39
 
33
- // src/compile/parse.ts
34
- var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
35
-
36
40
  // src/plugins/nova/data.layout.ts
37
41
  var fieldFor = (key, value) => ({
38
42
  component: "loom:field",
@@ -71,19 +75,29 @@ var novaPlugin = (config) => ({
71
75
  },
72
76
  mount: (editor) => mountView(editor, previewAction, (e) => ({ documents: e.documents }))
73
77
  });
78
+
79
+ // src/react/kit/tokens.ts
80
+ var COLORS = {
81
+ stage: "var(--loom-stage, #0c0c18)",
82
+ stageGlow: "var(--loom-stage-glow, #1b1b3a)",
83
+ stageBorder: "var(--loom-stage-border, #2a2a4a)"
84
+ };
85
+ react.createContext(0);
86
+ react.createContext({ close: () => {
87
+ }, anchor: "right" });
74
88
  var frame = {
75
89
  padding: 24,
76
90
  borderRadius: 12,
77
91
  minHeight: 220,
78
- background: "radial-gradient(circle at 30% 15%, #1b1b3a, #0c0c18 70%)",
79
- border: "1px solid #2a2a4a"
92
+ background: `radial-gradient(circle at 30% 15%, ${COLORS.stageGlow}, ${COLORS.stage} 70%)`,
93
+ border: `1px solid ${COLORS.stageBorder}`
80
94
  };
81
95
  var makePreview = (components) => {
82
96
  const Preview = ({ documents }) => {
83
97
  const docs = isRecord(documents) ? documents : {};
84
98
  const layout = docs["layout"];
85
99
  const data = isRecord(docs["data"]) ? docs["data"] : {};
86
- return /* @__PURE__ */ jsxRuntime.jsx("div", { style: frame, children: isRecord(layout) ? /* @__PURE__ */ jsxRuntime.jsx(react.Nova.Layout, { layout, data, components, builtins: false }) : null });
100
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: frame, children: isRecord(layout) ? /* @__PURE__ */ jsxRuntime.jsx(react$1.Nova.Layout, { layout, data, components, builtins: false }) : null });
87
101
  };
88
102
  return Preview;
89
103
  };
@@ -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":";;;;;;;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,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A,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,EAAAC,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.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
+ {"version":3,"sources":["../../../../src/compile/parse.ts","../../../../src/editor/view.ts","../../../../src/plugins/nova/schema.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/react/kit/tokens.ts","../../../../src/react/kit/variant.tsx","../../../../src/react/kit/menu.tsx","../../../../src/plugins/nova/react/preview.tsx","../../../../src/plugins/nova/react/index.ts"],"names":["z","createContext","jsx","Nova","name"],"mappings":";;;;;;;;;;;AA0QO,IAAM,QAAA,GAAW,CAAC,KAAA,KACvB,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA,IAAQ,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;;;ACxQ9D,IAAM,SAAA,GAAY,CACvB,MAAA,EACA,MAAA,EACA,IAAA,KACS;AACT,EAAA,MAAM,EAAE,OAAM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AA8B,IAAA,EAAY,YAAwB,QAAA,EAAU,KAAA,EAAO,IAC9F,IAAA,EACN,CAAA;AAAA,EAEJ,CAAA;AACA,EAAA,OAAO,OAAA;AACT,CAAA;;;ACnBO,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,EAAAC,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.cjs","sourcesContent":["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\n// A schema whose own code throws on a missing value cannot accept one.\nconst acceptsAbsence = (schema: ZodType): boolean => {\n try {\n return schema.safeParse(undefined).success;\n } catch {\n return false;\n }\n};\n\nconst objectFields = (schema: ZodType, walk: Walk): ObjectField[] =>\n Object.entries(defOf(schema).shape ?? {}).map(([key, value]) => ({\n key,\n required: !acceptsAbsence(value),\n field: parseField(value, walk),\n }));\n\n// A branch is read as what it unwraps to: a `z.lazy` or an optional branch has\n// no shape of its own.\nconst shapeOf = (branch: ZodType): Record<string, ZodType> => defOf(unwrap(branch).core).shape ?? {};\nconst branchKeys = (branch: ZodType): string[] => Object.keys(shapeOf(branch));\n\nconst JSON_TYPES = new Set(['string', 'number', 'boolean', 'object', 'array', 'null']);\nconst jsonType = (branch: ZodType): string | undefined => {\n const type = defOf(unwrap(branch).core).type;\n return JSON_TYPES.has(type) ? type : undefined;\n};\n\n// A literal lists its values, an enum its entries. The first is the tag a new\n// document of the branch gets; a stored document may have any of them.\nconst tagPattern = (key: string, discriminator: ZodType | undefined): Pattern => {\n const def = discriminator === undefined ? undefined : defOf(discriminator);\n const values = def === undefined ? [] : def.values !== undefined ? [...def.values] : Object.values(def.entries ?? {});\n return values.length > 1 ? { kind: 'tag', key, value: values[0], values } : { kind: 'tag', key, value: values[0] };\n};\n\nconst distinguish = (branch: ZodType, siblings: readonly ZodType[], tag: string | undefined): Pattern | undefined => {\n const shape = shapeOf(branch);\n if (tag !== undefined) {\n return tagPattern(tag, shape[tag]);\n }\n const elsewhere = new Set(siblings.flatMap(branchKeys));\n const own = Object.keys(shape).filter((k) => !elsewhere.has(k));\n // A key the branch requires is in every value of it; an optional one may be absent.\n const key = own.find((k) => {\n const schema = shape[k];\n return schema !== undefined && !acceptsAbsence(schema);\n }) ?? own[0];\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 literal: (schema) => {\n const values = defOf(schema).values ?? [];\n return { kind: 'enum', options: values.map((value) => ({ value, label: String(value) })), default: values[0] };\n },\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; nullable?: true } => {\n let core = schema;\n let fallback: unknown;\n let nullable = false;\n let def = defOf(core);\n while (WRAPPERS.has(def.type) || def.type === 'lazy') {\n if (def.type === 'nullable') nullable = true;\n const inner = def.type === 'lazy' ? resolveLazy(core) : def.innerType;\n if (inner === undefined) break;\n // The outermost default is the one zod applies.\n if ('defaultValue' in def && fallback === undefined) fallback = def.defaultValue;\n core = inner;\n def = defOf(core);\n }\n return { core, ...(fallback !== undefined ? { default: fallback } : {}), ...(nullable ? { nullable: true } : {}) };\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, nullable } = 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 } : {}), ...(nullable === true ? { nullable } : {}) };\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, options) => {\n if (field.kind !== 'union') return {};\n const first = field.variants[0];\n return first === undefined ? {} : variantDefaults(first, options);\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, options: CompileOptions): unknown => {\n const defaults = buildDocument(variant.field, options);\n if (variant.pattern.kind !== 'tag') return defaults;\n return { [variant.pattern.key]: variant.pattern.value, ...(isRecord(defaults) ? defaults : {}) };\n};\n","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 { LayoutNode } from '@niscorp/nova';\nimport { isRecord } from '@compile';\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, type LoomPlugin } from '@editor';\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","export const COLORS = {\n border: 'var(--loom-border, #d1d5db)',\n borderSubtle: 'var(--loom-border-subtle, #e5e7eb)',\n borderFaint: 'var(--loom-border-faint, #f1f5f9)',\n surface: 'var(--loom-surface, #fff)',\n surfaceMuted: 'var(--loom-surface-muted, #f9fafb)',\n fill: 'var(--loom-fill, #f3f4f6)',\n text: 'var(--loom-text, #111827)',\n textBody: 'var(--loom-text-body, #1f2937)',\n label: 'var(--loom-label, #374151)',\n muted: 'var(--loom-muted, #6b7280)',\n faint: 'var(--loom-faint, #9ca3af)',\n accent: 'var(--loom-accent, #1d4ed8)',\n accentFill: 'var(--loom-accent-fill, #eff6ff)',\n danger: 'var(--loom-danger, #dc2626)',\n dangerText: 'var(--loom-danger-text, #991b1b)',\n dangerFill: 'var(--loom-danger-fill, #fef2f2)',\n dangerBorder: 'var(--loom-danger-border, #fecaca)',\n warningText: 'var(--loom-warning-text, #92400e)',\n warningFill: 'var(--loom-warning-fill, #fffbeb)',\n warningBorder: 'var(--loom-warning-border, #fde68a)',\n shadow: 'var(--loom-shadow, rgba(0,0,0,0.12))',\n shadowStrong: 'var(--loom-shadow-strong, rgba(0,0,0,0.14))',\n stage: 'var(--loom-stage, #0c0c18)',\n stageGlow: 'var(--loom-stage-glow, #1b1b3a)',\n stageBorder: 'var(--loom-stage-border, #2a2a4a)',\n} as const;\n","import { createContext, useContext, type CSSProperties } from 'react';\nimport type { NovaComponent } from '@niscorp/nova/adapters/react';\nimport { isRecord, type Pattern } from '@compile';\nimport { useModelWrite } from '../hooks/model.js';\nimport { decodeLiteral, inputStyle, matches } from './shared.js';\nimport { JsonEditor } from './json-editor.js';\n\nconst variantStyle: CSSProperties = { display: 'flex', flexDirection: 'column', gap: 12 };\n\ntype Branch = { label: string; pattern: Pattern; defaults: unknown; childrenKey?: string };\n\nconst ActiveBranch = createContext(0);\n\nexport const LoomBranch: NovaComponent<{ index?: number }> = ({ index, children }) =>\n useContext(ActiveBranch) === index ? <>{children}</> : null;\n\nexport const LoomVariant: NovaComponent<{ value?: unknown; branches?: unknown }> = ({\n value,\n branches,\n children,\n novaModel,\n}) => {\n const set = useModelWrite(novaModel);\n const options = decodeLiteral<Branch[]>(branches) ?? [];\n const matched = options.findIndex((branch) => matches(value, branch.pattern));\n const fallback = options.findIndex((branch) => branch.pattern.kind === 'fallback');\n // A value no branch recognises, with no fallback branch, is shown as it is.\n const active = matched >= 0 ? matched : fallback;\n const switchTo = (chosen: Branch): void => {\n const activeKey = options[active]?.childrenKey;\n const oldChildren = activeKey !== undefined && isRecord(value) ? value[activeKey] : undefined;\n if (chosen.childrenKey !== undefined && Array.isArray(oldChildren)) {\n set({ ...(isRecord(chosen.defaults) ? chosen.defaults : {}), [chosen.childrenKey]: oldChildren });\n return;\n }\n if (Array.isArray(oldChildren) && oldChildren.length > 0 && !window.confirm('This type has no children. Discard them?')) return;\n set(chosen.defaults);\n };\n return (\n <div style={variantStyle}>\n <select\n value={active < 0 ? '' : active}\n onChange={(event) => {\n const chosen = options[Number(event.target.value)];\n if (chosen !== undefined) switchTo(chosen);\n }}\n style={inputStyle}\n >\n {active < 0 ? (\n <option value=\"\" disabled>\n —\n </option>\n ) : null}\n {options.map((branch, index) => (\n <option key={index} value={index}>\n {branch.label}\n </option>\n ))}\n </select>\n {active < 0 ? <JsonEditor value={value} onChange={set} /> : <ActiveBranch.Provider value={active}>{children}</ActiveBranch.Provider>}\n </div>\n );\n};\n","import { createContext, useContext, useState, type CSSProperties, type FC, type ReactNode } from 'react';\nimport { COLORS } from './tokens.js';\n\nconst trigger: CSSProperties = { padding: '4px 8px', border: `1px solid ${COLORS.border}`, borderRadius: 6, background: COLORS.surface, cursor: 'pointer', fontSize: 13, lineHeight: 1 };\nconst base: CSSProperties = { position: 'absolute', zIndex: 30, minWidth: 170, display: 'flex', flexDirection: 'column', background: COLORS.surface, border: `1px solid ${COLORS.border}`, borderRadius: 6, boxShadow: `0 6px 16px ${COLORS.shadow}`, padding: 4 };\nconst menuRight: CSSProperties = { ...base, top: '100%', right: 0, marginTop: 4 };\nconst menuLeft: CSSProperties = { ...base, top: '100%', left: 0, marginTop: 4 };\n// Flush (`100%`), no gap: the pointer has to cross into the submenu without\n// leaving the row.\nconst flyLeft: CSSProperties = { ...base, top: 0, right: '100%', maxHeight: 280, overflowY: 'auto' };\nconst flyRight: CSSProperties = { ...base, top: 0, left: '100%', maxHeight: 280, overflowY: 'auto' };\nconst itemStyle: CSSProperties = { width: '100%', boxSizing: 'border-box', textAlign: 'left', padding: '6px 10px', cursor: 'pointer', fontSize: 13, borderRadius: 4, whiteSpace: 'nowrap', display: 'flex', justifyContent: 'space-between', gap: 12 };\nconst itemDisabled: CSSProperties = { ...itemStyle, color: COLORS.faint, cursor: 'default' };\nconst MENU_CSS = `.loom-menu-item{background:transparent;border:none;}.loom-menu-item:hover:not(:disabled){background:${COLORS.fill};}`;\n\ntype Anchor = 'left' | 'right';\nconst MenuContext = createContext<{ close: () => void; anchor: Anchor }>({ close: () => {}, anchor: 'right' });\n\nexport const ActionMenu: FC<{ label?: ReactNode; ariaLabel?: string; anchor?: Anchor; children: ReactNode }> = ({\n label = '⋯',\n ariaLabel = 'Actions',\n anchor = 'right',\n children,\n}) => {\n const [open, setOpen] = useState(false);\n return (\n <div style={{ position: 'relative' }}>\n <button type=\"button\" aria-label={ariaLabel} onClick={() => setOpen((was) => !was)} style={trigger}>\n {label}\n </button>\n {open ? (\n <>\n <div onMouseDown={() => setOpen(false)} style={{ position: 'fixed', inset: 0, zIndex: 29 }} />\n <div style={anchor === 'right' ? menuRight : menuLeft}>\n <style>{MENU_CSS}</style>\n <MenuContext.Provider value={{ close: () => setOpen(false), anchor }}>{children}</MenuContext.Provider>\n </div>\n </>\n ) : null}\n </div>\n );\n};\n\nexport const MenuItem: FC<{ label: ReactNode; onSelect: () => void; disabled?: boolean }> = ({ label, onSelect, disabled }) => {\n const { close } = useContext(MenuContext);\n return (\n <button\n type=\"button\"\n className=\"loom-menu-item\"\n disabled={disabled}\n onClick={() => {\n onSelect();\n close();\n }}\n style={disabled ? itemDisabled : itemStyle}\n >\n {typeof label === 'string' ? <span>{label}</span> : label}\n </button>\n );\n};\n\nexport const SubMenu: FC<{ label: ReactNode; children: ReactNode }> = ({ label, children }) => {\n const { anchor } = useContext(MenuContext);\n const [open, setOpen] = useState(false);\n return (\n <div style={{ position: 'relative' }} onMouseEnter={() => setOpen(true)} onMouseLeave={() => setOpen(false)}>\n <button type=\"button\" className=\"loom-menu-item\" onClick={() => setOpen((was) => !was)} style={itemStyle}>\n <span>{label}</span>\n <span>▸</span>\n </button>\n {open ? <div style={anchor === 'right' ? flyLeft : flyRight}>{children}</div> : null}\n </div>\n );\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';\nimport { COLORS } from '@react/kit';\n\nconst frame: CSSProperties = {\n padding: 24,\n borderRadius: 12,\n minHeight: 220,\n background: `radial-gradient(circle at 30% 15%, ${COLORS.stageGlow}, ${COLORS.stage} 70%)`,\n border: `1px solid ${COLORS.stageBorder}`,\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-BthwIGIZ.cjs';
2
+ import { L as LoomEditorPlugin } from '../../../loom-editor-DtGAf8eH.cjs';
3
3
  import { N as NovaComponentShape } from '../../../schema--OhtatTX.cjs';
4
4
  import 'react';
5
+ import '../../../types-BWIIThEy.cjs';
5
6
  import 'zod';
6
7
  import '@niscorp/nova';
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-CHtjjiBp.js';
2
+ import { L as LoomEditorPlugin } from '../../../loom-editor-DlNYrfT9.js';
3
3
  import { N as NovaComponentShape } from '../../../schema--OhtatTX.js';
4
4
  import 'react';
5
+ import '../../../types-BWIIThEy.js';
5
6
  import 'zod';
6
7
  import '@niscorp/nova';
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-HHPSU7IA.js';
2
- import { isRecord } from '../../../chunk-DEZGKUTO.js';
3
- import '../../../chunk-27OMOR7I.js';
1
+ import { novaPlugin, PREVIEW } from '../../../chunk-3UI7CG24.js';
2
+ import { COLORS } from '../../../chunk-GXA57JFR.js';
3
+ import { isRecord } from '../../../chunk-OVTQEAV3.js';
4
4
  import { Nova } from '@niscorp/nova/adapters/react';
5
5
  import { jsx } from 'react/jsx-runtime';
6
6
 
@@ -8,8 +8,8 @@ var frame = {
8
8
  padding: 24,
9
9
  borderRadius: 12,
10
10
  minHeight: 220,
11
- background: "radial-gradient(circle at 30% 15%, #1b1b3a, #0c0c18 70%)",
12
- border: "1px solid #2a2a4a"
11
+ background: `radial-gradient(circle at 30% 15%, ${COLORS.stageGlow}, ${COLORS.stage} 70%)`,
12
+ border: `1px solid ${COLORS.stageBorder}`
13
13
  };
14
14
  var makePreview = (components) => {
15
15
  const Preview = ({ documents }) => {
@@ -1 +1 @@
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,SAA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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
+ {"version":3,"sources":["../../../../src/plugins/nova/react/preview.tsx","../../../../src/plugins/nova/react/index.ts"],"names":["name"],"mappings":";;;;;;AAMA,IAAM,K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O,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';\nimport { COLORS } from '@react/kit';\n\nconst frame: CSSProperties = {\n padding: 24,\n borderRadius: 12,\n minHeight: 220,\n background: `radial-gradient(circle at 30% 15%, ${COLORS.stageGlow}, ${COLORS.stage} 70%)`,\n border: `1px solid ${COLORS.stageBorder}`,\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,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var prism = require('@niscorp/prism');
4
+ require('zod');
5
+ require('@niscorp/nova');
4
6
 
5
7
  // src/plugins/prism/index.ts
6
8
 
@@ -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":";;;;;;;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
+ {"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;;;ACCO,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, type LoomPlugin } from '@editor';\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,7 +1,7 @@
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-V5kJWZJn.cjs';
4
+ import { h as LoomPlugin } from '../../types-BWIIThEy.cjs';
5
5
  import '@niscorp/nova';
6
6
 
7
7
  declare const PREVIEW = "prism:preview";
@@ -1,7 +1,7 @@
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-V5kJWZJn.js';
4
+ import { h as LoomPlugin } from '../../types-BWIIThEy.js';
5
5
  import '@niscorp/nova';
6
6
 
7
7
  declare const PREVIEW = "prism:preview";
@@ -1,4 +1,4 @@
1
- export { NODE, PREVIEW, prismPlugin } from '../../chunk-LVDY6FUH.js';
2
- import '../../chunk-27OMOR7I.js';
1
+ export { NODE, PREVIEW, prismPlugin } from '../../chunk-BYOKCNIJ.js';
2
+ import '../../chunk-OVTQEAV3.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map