@perkyzz/emvb 0.8.0 → 1.0.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 (179) hide show
  1. package/README.md +3 -3
  2. package/package.json +4 -4
  3. package/src/admin/agents-api.ts +45 -0
  4. package/src/admin/editor/A11yCopilot.tsx +1 -1
  5. package/src/admin/editor/Editor.tsx +325 -239
  6. package/src/admin/editor/FieldPreview.tsx +164 -0
  7. package/src/admin/editor/Timeline.tsx +2 -1
  8. package/src/admin/editor/TopBar.tsx +36 -3
  9. package/src/admin/editor/canvas/CanvasFrame.tsx +2 -2
  10. package/src/admin/editor/canvas/DeviceBar.tsx +17 -9
  11. package/src/admin/editor/canvas/canvas-scale.ts +2 -2
  12. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  13. package/src/admin/editor/co-design.ts +190 -0
  14. package/src/admin/editor/dnd/new-element.ts +26 -4
  15. package/src/admin/editor/editor-chrome.tsx +3 -3
  16. package/src/admin/editor/editor-commands.ts +8 -3
  17. package/src/admin/editor/editor-css.ts +3 -0
  18. package/src/admin/editor/element-chrome.ts +3 -1
  19. package/src/admin/editor/extension-manifests.ts +20 -0
  20. package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
  21. package/src/admin/editor/extensions-context.tsx +27 -0
  22. package/src/admin/editor/feature-css.ts +17 -0
  23. package/src/admin/editor/host.ts +6 -0
  24. package/src/admin/editor/palette-items.ts +2 -2
  25. package/src/admin/editor/panels/AddPanel.tsx +31 -1
  26. package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
  27. package/src/admin/editor/panels/ClassesSection.tsx +9 -6
  28. package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
  29. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  30. package/src/admin/editor/panels/ElementPanel.tsx +53 -15
  31. package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
  32. package/src/admin/editor/panels/LayersPanel.tsx +10 -6
  33. package/src/admin/editor/panels/LeftPanel.tsx +33 -5
  34. package/src/admin/editor/panels/PageSettings.tsx +4 -0
  35. package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
  36. package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
  37. package/src/admin/editor/panels/settings/BackgroundControls.tsx +76 -20
  38. package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
  39. package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
  40. package/src/admin/editor/panels/settings/EffectsControls.tsx +104 -9
  41. package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
  42. package/src/admin/editor/panels/settings/IconControls.tsx +14 -11
  43. package/src/admin/editor/panels/settings/LengthRow.tsx +27 -16
  44. package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
  45. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  46. package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
  47. package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
  48. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
  49. package/src/admin/editor/panels/settings/StyleRow.tsx +113 -13
  50. package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
  51. package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
  52. package/src/admin/editor/panels/settings/background-mode.ts +14 -11
  53. package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
  54. package/src/admin/editor/panels/settings/box-sides.ts +22 -14
  55. package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
  56. package/src/admin/editor/panels/settings/length-units.ts +55 -2
  57. package/src/admin/editor/panels/settings/query-style.ts +3 -3
  58. package/src/admin/editor/panels/settings/style-sections.ts +51 -10
  59. package/src/admin/editor/panels/style-target.ts +9 -7
  60. package/src/admin/editor/presence.ts +60 -0
  61. package/src/admin/editor/store.ts +6 -2
  62. package/src/admin/editor/useCoDesign.ts +177 -0
  63. package/src/admin/editor/useEditorCommands.ts +4 -4
  64. package/src/admin/editor/useExtensions.ts +45 -0
  65. package/src/admin/editor/useNodeActions.ts +15 -6
  66. package/src/admin/editor/useProposals.ts +81 -0
  67. package/src/admin/index.tsx +5 -1
  68. package/src/admin/languages-api.ts +61 -0
  69. package/src/admin/media-api.ts +27 -0
  70. package/src/admin/pages/AgentSetup.tsx +148 -0
  71. package/src/admin/pages/AgentsPage.tsx +11 -28
  72. package/src/admin/pages/CollectionsPage.tsx +215 -0
  73. package/src/admin/pages/CreateDialog.tsx +15 -0
  74. package/src/admin/pages/ImportButton.tsx +18 -0
  75. package/src/admin/pages/ImportElementorDialog.tsx +669 -0
  76. package/src/admin/pages/ImportPageLinks.tsx +86 -0
  77. package/src/admin/pages/PageList.tsx +15 -1
  78. package/src/admin/pages/ThemePartList.tsx +15 -1
  79. package/src/admin/pages/section-head.tsx +27 -0
  80. package/src/admin/proposals-api.ts +91 -0
  81. package/src/admin/setup/host-collections.ts +100 -0
  82. package/src/admin/ui.ts +39 -2
  83. package/src/admin/widgets/CanvasField.tsx +202 -0
  84. package/src/admin/widgets/convert-body.ts +54 -0
  85. package/src/admin/widgets/field-fetcher.ts +79 -0
  86. package/src/astro/content-port.ts +14 -1
  87. package/src/astro/index.ts +2 -0
  88. package/src/astro/page-count.ts +77 -0
  89. package/src/astro/resolve-theme.ts +58 -3
  90. package/src/astro/resolve.ts +128 -5
  91. package/src/astro/responsive-images.ts +99 -0
  92. package/src/constants.ts +1 -1
  93. package/src/core/a11y/audit.ts +44 -14
  94. package/src/core/arrange.ts +5 -1
  95. package/src/core/bounded-array.ts +31 -0
  96. package/src/core/canvas-collections.ts +20 -0
  97. package/src/core/clipboard.ts +9 -0
  98. package/src/core/contract.ts +285 -0
  99. package/src/core/css/generate.ts +89 -20
  100. package/src/core/css/trace.ts +18 -9
  101. package/src/core/css-keywords.ts +51 -1
  102. package/src/core/design/cascade.ts +12 -9
  103. package/src/core/design/classes.ts +4 -5
  104. package/src/core/design/devices.ts +13 -13
  105. package/src/core/design/states.ts +5 -3
  106. package/src/core/design/transfer.ts +5 -0
  107. package/src/core/design/variables.ts +17 -4
  108. package/src/core/elements/dynamic-elements.ts +19 -4
  109. package/src/core/elements/index.ts +73 -9
  110. package/src/core/extensions/define.ts +13 -0
  111. package/src/core/extensions/index.ts +41 -0
  112. package/src/core/extensions/namespace.ts +82 -0
  113. package/src/core/extensions/normalize.ts +141 -0
  114. package/src/core/extensions/placeholder.ts +41 -0
  115. package/src/core/extensions/registry.ts +94 -0
  116. package/src/core/extensions/render-ext.ts +118 -0
  117. package/src/core/extensions/safe-nodes.ts +93 -0
  118. package/src/core/extensions/schema.ts +112 -0
  119. package/src/core/extensions/types.ts +159 -0
  120. package/src/core/forms/binding.ts +1 -1
  121. package/src/core/history/diff.ts +1 -1
  122. package/src/core/import/elementor/atomic.ts +1595 -0
  123. package/src/core/import/elementor/classes.ts +127 -0
  124. package/src/core/import/elementor/context.ts +429 -0
  125. package/src/core/import/elementor/counter-steps.ts +72 -0
  126. package/src/core/import/elementor/css.ts +445 -0
  127. package/src/core/import/elementor/html.ts +500 -0
  128. package/src/core/import/elementor/index.ts +949 -0
  129. package/src/core/import/elementor/inline-marks.ts +81 -0
  130. package/src/core/import/elementor/snapshots.ts +48 -0
  131. package/src/core/import/elementor/style.ts +409 -0
  132. package/src/core/import/elementor/values.ts +241 -0
  133. package/src/core/import/elementor/widgets.ts +1897 -0
  134. package/src/core/index.ts +84 -0
  135. package/src/core/json-schema.ts +107 -0
  136. package/src/core/limits.ts +19 -0
  137. package/src/core/migrate/index.ts +6 -1
  138. package/src/core/migrate/v18.ts +222 -0
  139. package/src/core/perf/meter.ts +5 -5
  140. package/src/core/portable-text.ts +127 -0
  141. package/src/core/proposals-safety.ts +102 -0
  142. package/src/core/proposals.ts +357 -0
  143. package/src/core/recipes/index.ts +2 -2
  144. package/src/core/render/extras.ts +3 -3
  145. package/src/core/render/index.ts +140 -20
  146. package/src/core/render/loop.ts +1 -1
  147. package/src/core/render/pagination.ts +20 -1
  148. package/src/core/render/section.ts +4 -4
  149. package/src/core/render/vnode.ts +1 -1
  150. package/src/core/sanitize/css.ts +125 -10
  151. package/src/core/sanitize/motion.ts +116 -0
  152. package/src/core/saved-sections.ts +6 -0
  153. package/src/core/schema/descriptors.ts +3 -1
  154. package/src/core/schema/design.ts +2 -1
  155. package/src/core/schema/layout.ts +87 -14
  156. package/src/core/schema/style.ts +251 -114
  157. package/src/core/text-marks.ts +227 -0
  158. package/src/core/theme/dynamic.ts +9 -4
  159. package/src/core/theme/float.ts +1 -0
  160. package/src/core/theme/pagination.ts +9 -0
  161. package/src/core/theme/popup-rules.ts +17 -1
  162. package/src/core/translatable.ts +34 -0
  163. package/src/core/validate.ts +13 -1
  164. package/src/index.ts +35 -1
  165. package/src/mcp/errors.ts +3 -1
  166. package/src/mcp/ports.ts +67 -0
  167. package/src/mcp/prompts.ts +1 -11
  168. package/src/mcp/proposals.ts +281 -0
  169. package/src/mcp/read.ts +10 -9
  170. package/src/mcp/tools.ts +71 -3
  171. package/src/mcp/write.ts +66 -11
  172. package/src/server/agent-settings.ts +21 -2
  173. package/src/server/hooks.ts +81 -0
  174. package/src/server/mcp-routes.ts +15 -0
  175. package/src/server/plugin.ts +53 -5
  176. package/src/server/presence.ts +78 -0
  177. package/src/server/proposals.ts +261 -0
  178. package/src/server/requests.ts +196 -0
  179. package/src/server/tools-served.ts +45 -0
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Render one extension element node to a VNode (W-927, D-066).
3
+ * Missing extension, throwing render, or illegal output → placeholder.
4
+ */
5
+
6
+ import type { LayoutNode } from "../schema/layout.ts";
7
+ import type { VNode } from "../render/vnode.ts";
8
+ import { liveElement, liveExtension } from "./registry.ts";
9
+ import { validateExtensionProps } from "./schema.ts";
10
+ import { safeExtensionOutput } from "./safe-nodes.ts";
11
+ import { extensionPlaceholderVNode } from "./placeholder.ts";
12
+ import type { ExtensionRenderContext } from "./types.ts";
13
+ import { parseExtensionType } from "./namespace.ts";
14
+
15
+ export type ExtensionRenderMode = "public" | "editor";
16
+
17
+ function isThenable(value: unknown): value is Promise<unknown> {
18
+ return !!value && typeof (value as { then?: unknown }).then === "function";
19
+ }
20
+
21
+ function cleanSourceRecord(raw: Readonly<Record<string, string>>): Record<string, string> {
22
+ const out: Record<string, string> = {};
23
+ let n = 0;
24
+ for (const [key, value] of Object.entries(raw)) {
25
+ if (n >= 32) break;
26
+ if (typeof key !== "string" || !/^[a-zA-Z][a-zA-Z0-9_.-]{0,63}$/.test(key)) continue;
27
+ if (typeof value !== "string") continue;
28
+ let cleaned = "";
29
+ for (const char of value) {
30
+ const code = char.codePointAt(0) ?? 0;
31
+ if (code === 9) cleaned += " ";
32
+ else if (code === 10 || (code >= 32 && code !== 127 && !(code >= 0x80 && code <= 0x9f))) {
33
+ cleaned += char;
34
+ }
35
+ if (cleaned.length >= 2000) break;
36
+ }
37
+ out[key] = cleaned.trim();
38
+ n += 1;
39
+ }
40
+ return out;
41
+ }
42
+
43
+ /**
44
+ * Resolve source values for one package (sync resolvers only).
45
+ * Async sources are left empty here; hosts that need them can pre-resolve later.
46
+ */
47
+ export function syncSourceValues(pkg: string): Record<string, Record<string, string>> {
48
+ const ext = liveExtension(pkg);
49
+ if (!ext?.sources) return {};
50
+ const out: Record<string, Record<string, string>> = {};
51
+ for (const source of ext.sources) {
52
+ try {
53
+ const result = source.resolve();
54
+ if (result && typeof result === "object" && !Array.isArray(result) && !isThenable(result)) {
55
+ out[source.name] = cleanSourceRecord(result as Readonly<Record<string, string>>);
56
+ } else {
57
+ out[source.name] = {};
58
+ }
59
+ } catch {
60
+ out[source.name] = {};
61
+ }
62
+ }
63
+ return out;
64
+ }
65
+
66
+ export type VisitChildren = (nodes: LayoutNode[]) => VNode[];
67
+
68
+ /**
69
+ * Build the VNode for a stored extension element. Always returns a node (placeholder
70
+ * on failure) so siblings keep rendering.
71
+ */
72
+ export function renderExtensionNode(
73
+ node: LayoutNode,
74
+ mode: ExtensionRenderMode,
75
+ visitChildren: VisitChildren,
76
+ ): VNode {
77
+ const id = typeof node.id === "string" ? node.id : undefined;
78
+ const type = node.type;
79
+ const parsed = parseExtensionType(type);
80
+ if (!parsed) {
81
+ return extensionPlaceholderVNode(type, id, mode);
82
+ }
83
+
84
+ const found = liveElement(type);
85
+ if (!found) {
86
+ return extensionPlaceholderVNode(type, id, mode);
87
+ }
88
+
89
+ const storedProps =
90
+ node.props && typeof node.props === "object" && !Array.isArray(node.props)
91
+ ? (node.props as Record<string, unknown>)
92
+ : {};
93
+ const checked = validateExtensionProps(found.manifest.schema, storedProps);
94
+ const ctx: ExtensionRenderContext = { sources: syncSourceValues(parsed.pkg) };
95
+
96
+ let raw: unknown;
97
+ try {
98
+ raw = found.element.render(checked.props, ctx);
99
+ } catch {
100
+ return extensionPlaceholderVNode(type, id, mode);
101
+ }
102
+
103
+ const safe = safeExtensionOutput(raw);
104
+ if (safe.length === 0) {
105
+ return extensionPlaceholderVNode(type, id, mode);
106
+ }
107
+
108
+ const children = visitChildren(safe);
109
+ return {
110
+ tag: "div",
111
+ attrs: {
112
+ class: "emvb-ext",
113
+ "data-emvb-ext": type,
114
+ ...(id && mode === "editor" ? { "data-emvb-id": id } : {}),
115
+ },
116
+ children,
117
+ };
118
+ }
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Turn an extension render() result into built-in LayoutNodes EmVB will render (W-927).
3
+ * Rejects raw HTML strings, unknown types, nested extension types, and oversized trees.
4
+ * Surviving nodes are re-validated through EmVB's layout schema so props and styles
5
+ * pass the same sanitizer as editor-saved content.
6
+ */
7
+
8
+ import { LAYOUT_SCHEMA_VERSION, type LayoutNode } from "../schema/layout.ts";
9
+ import { KNOWN_ELEMENT_TYPES } from "../schema/layout.ts";
10
+ import { validateLayout } from "../validate.ts";
11
+ import { newNodeId } from "../tree-ops.ts";
12
+ import { isExtensionType } from "./namespace.ts";
13
+
14
+ const KNOWN = new Set<string>(KNOWN_ELEMENT_TYPES);
15
+ const MAX_NODES = 32;
16
+ const MAX_DEPTH = 8;
17
+
18
+ function coerce(
19
+ value: unknown,
20
+ depth: number,
21
+ budget: { left: number },
22
+ random: () => number,
23
+ ): Record<string, unknown> | undefined {
24
+ if (budget.left <= 0 || depth > MAX_DEPTH) return undefined;
25
+ if (typeof value === "string") return undefined; // raw HTML / text — refused
26
+ if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
27
+ const node = value as Record<string, unknown>;
28
+ if (typeof node.type !== "string" || !KNOWN.has(node.type) || isExtensionType(node.type)) {
29
+ return undefined;
30
+ }
31
+ if (
32
+ node.props !== undefined &&
33
+ (typeof node.props !== "object" || node.props === null || Array.isArray(node.props))
34
+ ) {
35
+ return undefined;
36
+ }
37
+ budget.left -= 1;
38
+ const id =
39
+ typeof node.id === "string" && /^[A-Za-z0-9_-]{4,24}$/.test(node.id)
40
+ ? node.id
41
+ : newNodeId(random);
42
+ let children: Record<string, unknown>[] | undefined;
43
+ if (Array.isArray(node.children)) {
44
+ children = [];
45
+ for (const child of node.children) {
46
+ const ok = coerce(child, depth + 1, budget, random);
47
+ if (ok) children.push(ok);
48
+ }
49
+ }
50
+ // Drop style/attributes from extension output: only props + children of built-ins.
51
+ // (Extensions style through the host element's own style on the wrapper.)
52
+ return {
53
+ id,
54
+ type: node.type,
55
+ props: { ...(node.props as Record<string, unknown>) },
56
+ ...(children ? { children } : {}),
57
+ };
58
+ }
59
+
60
+ /**
61
+ * Normalize a render() return value to validated built-in nodes.
62
+ * Illegal shapes, schema failures and empty output yield `[]` (caller shows the placeholder).
63
+ */
64
+ export function safeExtensionOutput(
65
+ raw: unknown,
66
+ random: () => number = Math.random,
67
+ ): LayoutNode[] {
68
+ const budget = { left: MAX_NODES };
69
+ const coerced: Record<string, unknown>[] = [];
70
+ if (Array.isArray(raw)) {
71
+ for (const item of raw) {
72
+ const node = coerce(item, 0, budget, random);
73
+ if (node) coerced.push(node);
74
+ }
75
+ } else {
76
+ const one = coerce(raw, 0, budget, random);
77
+ if (one) coerced.push(one);
78
+ }
79
+ if (coerced.length === 0) return [];
80
+
81
+ const page = {
82
+ schemaVersion: LAYOUT_SCHEMA_VERSION,
83
+ root: {
84
+ id: "root0001",
85
+ type: "container",
86
+ props: {},
87
+ children: coerced,
88
+ },
89
+ };
90
+ const result = validateLayout(page);
91
+ if (!result.ok) return [];
92
+ return result.layout.root.children.slice();
93
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Compile an extension's declarative prop schema into Zod, with EmVB limits on top
3
+ * (W-927). Extensions never pass us a Zod instance — only ExtensionPropSchema.
4
+ */
5
+
6
+ import { z } from "zod";
7
+ import { MAX_TEXT_LENGTH } from "../limits.ts";
8
+ import type { ExtensionPropSchema } from "./types.ts";
9
+
10
+ /** Hard caps on top of whatever the extension declares (limits may only loosen later). */
11
+ const EXT_MAX_STRING = MAX_TEXT_LENGTH;
12
+ const EXT_MAX_ARRAY = 32;
13
+ const EXT_MAX_OBJECT_KEYS = 32;
14
+ const EXT_MAX_DEPTH = 4;
15
+ const EXT_MAX_NUMBER = 1_000_000_000;
16
+
17
+ const FIELD_KINDS = new Set(["text", "textarea", "number", "int", "select", "boolean", "href"]);
18
+
19
+ export function isAllowedExtensionFieldKind(kind: string): boolean {
20
+ return FIELD_KINDS.has(kind);
21
+ }
22
+
23
+ function compileAt(schema: ExtensionPropSchema, depth: number): z.ZodType {
24
+ if (depth > EXT_MAX_DEPTH) {
25
+ return z.never();
26
+ }
27
+ switch (schema.type) {
28
+ case "string": {
29
+ const max = Math.min(schema.maxLength ?? EXT_MAX_STRING, EXT_MAX_STRING);
30
+ const min = Math.max(0, schema.minLength ?? 0);
31
+ let s = z.string().max(max);
32
+ if (min > 0) s = s.min(min);
33
+ return schema.default !== undefined ? s.default(schema.default) : s;
34
+ }
35
+ case "number": {
36
+ const min = schema.min ?? -EXT_MAX_NUMBER;
37
+ const max = Math.min(schema.max ?? EXT_MAX_NUMBER, EXT_MAX_NUMBER);
38
+ let n = z.number().min(min).max(max);
39
+ if (schema.integer) n = n.int();
40
+ return schema.default !== undefined ? n.default(schema.default) : n;
41
+ }
42
+ case "boolean": {
43
+ const b = z.boolean();
44
+ return schema.default !== undefined ? b.default(schema.default) : b;
45
+ }
46
+ case "enum": {
47
+ const values = schema.values
48
+ .filter((v) => typeof v === "string" && v.length <= 64)
49
+ .slice(0, 32);
50
+ if (values.length === 0) return z.never();
51
+ const e = z.enum(values as [string, ...string[]]);
52
+ return schema.default !== undefined && values.includes(schema.default)
53
+ ? e.default(schema.default)
54
+ : e;
55
+ }
56
+ case "array": {
57
+ const maxItems = Math.min(schema.maxItems ?? EXT_MAX_ARRAY, EXT_MAX_ARRAY);
58
+ const a = z.array(compileAt(schema.items, depth + 1)).max(maxItems);
59
+ return schema.default !== undefined ? a.default([...schema.default]) : a;
60
+ }
61
+ case "object": {
62
+ const keys = Object.keys(schema.properties).slice(0, EXT_MAX_OBJECT_KEYS);
63
+ const shape: Record<string, z.ZodType> = {};
64
+ const required = new Set(schema.required ?? []);
65
+ for (const key of keys) {
66
+ if (!/^[a-zA-Z][a-zA-Z0-9_]{0,31}$/.test(key)) continue;
67
+ const prop = schema.properties[key];
68
+ if (!prop) continue;
69
+ const compiled = compileAt(prop, depth + 1);
70
+ shape[key] = required.has(key) ? compiled : compiled.optional();
71
+ }
72
+ return z.object(shape).strict();
73
+ }
74
+ default:
75
+ return z.never();
76
+ }
77
+ }
78
+
79
+ /** Zod schema for one element's props. Unknown keys are stripped (strict object leaves). */
80
+ function compileExtensionProps(schema: ExtensionPropSchema): z.ZodType {
81
+ return compileAt(schema, 0);
82
+ }
83
+
84
+ /** Defaults implied by the schema (and any `defaults()` the extension supplies). */
85
+ export function schemaDefaults(schema: ExtensionPropSchema): Record<string, unknown> {
86
+ if (schema.type !== "object") return {};
87
+ const out: Record<string, unknown> = {};
88
+ for (const [key, prop] of Object.entries(schema.properties)) {
89
+ if ("default" in prop && prop.default !== undefined) out[key] = prop.default;
90
+ }
91
+ return out;
92
+ }
93
+
94
+ /**
95
+ * Validate untrusted stored props. On failure returns the schema defaults (so a
96
+ * bad value never reaches render) and `ok: false`.
97
+ */
98
+ export function validateExtensionProps(
99
+ schema: ExtensionPropSchema,
100
+ input: unknown,
101
+ ): { ok: true; props: Record<string, unknown> } | { ok: false; props: Record<string, unknown> } {
102
+ const compiled = compileExtensionProps(schema);
103
+ const result = compiled.safeParse(input ?? {});
104
+ if (result.success) {
105
+ const props =
106
+ result.data && typeof result.data === "object" && !Array.isArray(result.data)
107
+ ? (result.data as Record<string, unknown>)
108
+ : {};
109
+ return { ok: true, props };
110
+ }
111
+ return { ok: false, props: schemaDefaults(schema) };
112
+ }
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Extensions API v1 (W-927, D-066). Site owners register extensions through
3
+ * `emvb({ extensions: [...] })` at build time. Stored data is namespaced
4
+ * `ext:<pkg>/<name>`, validated, and render output goes through EmVB's sanitizer.
5
+ *
6
+ * Freeze rules match D-065: within extensionApi 1.x no key is removed, renamed or
7
+ * changed in meaning; additions are optional; breaking changes wait for 2.0.
8
+ */
9
+
10
+ import type { FieldDescriptor } from "../schema/descriptors.ts";
11
+ import type { LayoutNode } from "../schema/layout.ts";
12
+
13
+ /** Shipped API version. Same freeze rules as D-065 (see docs/EXTENSIONS.md). */
14
+ export const EXTENSION_API_VERSION = 1 as const;
15
+ export type ExtensionApiVersion = typeof EXTENSION_API_VERSION;
16
+
17
+ /**
18
+ * Declarative prop schema EmVB compiles to Zod. Extensions must not hand us a
19
+ * Zod instance (or any other code) as a "schema" — only this subset.
20
+ */
21
+ export type ExtensionPropSchema =
22
+ | {
23
+ type: "string";
24
+ maxLength?: number;
25
+ minLength?: number;
26
+ default?: string;
27
+ }
28
+ | {
29
+ type: "number";
30
+ min?: number;
31
+ max?: number;
32
+ integer?: boolean;
33
+ default?: number;
34
+ }
35
+ | {
36
+ type: "boolean";
37
+ default?: boolean;
38
+ }
39
+ | {
40
+ type: "enum";
41
+ values: readonly string[];
42
+ default?: string;
43
+ }
44
+ | {
45
+ type: "array";
46
+ items: ExtensionPropSchema;
47
+ maxItems?: number;
48
+ default?: readonly unknown[];
49
+ }
50
+ | {
51
+ type: "object";
52
+ properties: Readonly<Record<string, ExtensionPropSchema>>;
53
+ required?: readonly string[];
54
+ };
55
+
56
+ /** Inspector field: the same declarative kinds ElementDescriptor uses (W-021). */
57
+ export type ExtensionField = Pick<
58
+ FieldDescriptor,
59
+ "key" | "kind" | "label" | "options" | "message" | "optional" | "max" | "min"
60
+ >;
61
+
62
+ /** Context passed to an element render function (read-only source values). */
63
+ export type ExtensionRenderContext = {
64
+ /** Resolved values from this extension's sources, keyed by source name then field. */
65
+ sources: Readonly<Record<string, Readonly<Record<string, string>>>>;
66
+ };
67
+
68
+ /**
69
+ * A custom element. `name` becomes the stored type `ext:<extension.id>/<name>`.
70
+ * `render` returns EmVB layout nodes (built-in types only), never HTML strings.
71
+ */
72
+ export type ExtensionElement = {
73
+ name: string;
74
+ label: string;
75
+ /** Optional Add-panel group; defaults to "content". */
76
+ group?: "layout" | "content" | "form" | "dynamic";
77
+ schema: ExtensionPropSchema;
78
+ fields: readonly ExtensionField[];
79
+ defaults?: () => Record<string, unknown>;
80
+ render: (
81
+ props: Record<string, unknown>,
82
+ ctx: ExtensionRenderContext,
83
+ ) => LayoutNode | readonly LayoutNode[];
84
+ };
85
+
86
+ /**
87
+ * Declarative editor panel. EmVB renders it in a Kumo slot with EmVB tokens.
88
+ * Extensions may not inject global admin CSS (D-067).
89
+ */
90
+ export type ExtensionPanel = {
91
+ name: string;
92
+ label: string;
93
+ /** Short body shown in the slot (plain text; EmVB escapes it). */
94
+ description?: string;
95
+ /** Optional source name whose resolved fields are listed read-only in the panel. */
96
+ source?: string;
97
+ };
98
+
99
+ /** What a read-only data source may return (W-927). */
100
+ export type ExtensionSourceCapability = "text" | "url" | "image";
101
+
102
+ /**
103
+ * A read-only resolver. Results are treated as untrusted strings and run through
104
+ * the same cleaning path bindings use before anything renders them.
105
+ */
106
+ export type ExtensionSource = {
107
+ name: string;
108
+ label: string;
109
+ capabilities: readonly ExtensionSourceCapability[];
110
+ resolve: () => Readonly<Record<string, string>> | Promise<Readonly<Record<string, string>>>;
111
+ };
112
+
113
+ /** One extension package. `id` is the package name (unscoped), e.g. `emvb-ext-hello`. */
114
+ export type EmVBExtension = {
115
+ extensionApi: ExtensionApiVersion;
116
+ id: string;
117
+ label?: string;
118
+ elements?: readonly ExtensionElement[];
119
+ panels?: readonly ExtensionPanel[];
120
+ sources?: readonly ExtensionSource[];
121
+ };
122
+
123
+ /**
124
+ * Serializable manifest sent to the admin through `editor/config` (no functions).
125
+ * Live render/resolve functions stay in the process registry.
126
+ */
127
+ export type ExtensionElementManifest = {
128
+ type: string;
129
+ name: string;
130
+ label: string;
131
+ group: "layout" | "content" | "form" | "dynamic";
132
+ schema: ExtensionPropSchema;
133
+ fields: readonly ExtensionField[];
134
+ defaults: Record<string, unknown>;
135
+ };
136
+
137
+ export type ExtensionPanelManifest = {
138
+ id: string;
139
+ name: string;
140
+ label: string;
141
+ description?: string;
142
+ source?: string;
143
+ };
144
+
145
+ export type ExtensionSourceManifest = {
146
+ id: string;
147
+ name: string;
148
+ label: string;
149
+ capabilities: readonly ExtensionSourceCapability[];
150
+ };
151
+
152
+ export type ExtensionManifest = {
153
+ extensionApi: ExtensionApiVersion;
154
+ id: string;
155
+ label: string;
156
+ elements: readonly ExtensionElementManifest[];
157
+ panels: readonly ExtensionPanelManifest[];
158
+ sources: readonly ExtensionSourceManifest[];
159
+ };
@@ -91,7 +91,7 @@ export type RequiredFieldIssue =
91
91
  };
92
92
 
93
93
  const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "radio"]);
94
- const DEVICE_ORDER = ["desktop", "tablet", "mobile"];
94
+ const DEVICE_ORDER = ["desktop", "laptop", "tablet", "mobile"];
95
95
 
96
96
  /** Each bound field's controls, with the devices each is hidden on (itself or an ancestor). */
97
97
  type Control = { nodeId: string; hidden: Set<string>; who?: string; split?: string };
@@ -54,7 +54,7 @@ function editsBetween(before: LayoutNode, after: LayoutNode): number {
54
54
  const describe = (node: LayoutNode) => ({
55
55
  id: node.id,
56
56
  type: node.type,
57
- ...(node.label ? { label: node.label } : {}),
57
+ ...(node.editorLabel ? { label: node.editorLabel } : {}),
58
58
  });
59
59
 
60
60
  /**