@perkyzz/emvb 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +6 -4
  2. package/THIRD_PARTY_NOTICES.md +32 -0
  3. package/licenses/fontawesome-free.LICENSE +165 -0
  4. package/licenses/lucide-static.LICENSE +43 -0
  5. package/licenses/remixicon.LICENSE +201 -0
  6. package/licenses/tabler-icons.LICENSE +21 -0
  7. package/package.json +9 -5
  8. package/src/admin/api.ts +27 -0
  9. package/src/admin/content-api.ts +72 -9
  10. package/src/admin/editor/Editor.tsx +89 -14
  11. package/src/admin/editor/EditorOverlay.tsx +12 -0
  12. package/src/admin/editor/SmallScreenNotice.tsx +4 -3
  13. package/src/admin/editor/TopBar.tsx +76 -12
  14. package/src/admin/editor/canvas/CanvasFrame.tsx +224 -43
  15. package/src/admin/editor/canvas/DeviceBar.tsx +43 -2
  16. package/src/admin/editor/canvas/SelectionOverlay.tsx +60 -6
  17. package/src/admin/editor/canvas/canvas-events.ts +20 -7
  18. package/src/admin/editor/canvas/tab-reveal.ts +66 -0
  19. package/src/admin/editor/canvas/vnode-react.tsx +21 -1
  20. package/src/admin/editor/dialogs.tsx +39 -0
  21. package/src/admin/editor/dnd/drop-target.ts +63 -16
  22. package/src/admin/editor/dnd/new-element.ts +76 -1
  23. package/src/admin/editor/editor-css.ts +101 -15
  24. package/src/admin/editor/host.ts +30 -0
  25. package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
  26. package/src/admin/editor/icons/library.ts +243 -0
  27. package/src/admin/editor/icons/set-format.ts +29 -0
  28. package/src/admin/editor/icons/sets/fontawesome.json +1 -0
  29. package/src/admin/editor/icons/sets/lucide.json +1 -0
  30. package/src/admin/editor/icons/sets/remix.json +1 -0
  31. package/src/admin/editor/icons/sets/tabler.json +1 -0
  32. package/src/admin/editor/panels/AddPanel.tsx +7 -3
  33. package/src/admin/editor/panels/ClassesSection.tsx +44 -6
  34. package/src/admin/editor/panels/ColorControl.tsx +268 -21
  35. package/src/admin/editor/panels/ElementPanel.tsx +237 -93
  36. package/src/admin/editor/panels/LayersPanel.tsx +303 -66
  37. package/src/admin/editor/panels/LeftPanel.tsx +4 -0
  38. package/src/admin/editor/panels/PageSettings.tsx +134 -5
  39. package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
  40. package/src/admin/editor/panels/SiteStylesDrawer.tsx +158 -2
  41. package/src/admin/editor/panels/TriggersEditor.tsx +19 -2
  42. package/src/admin/editor/panels/VariableSection.tsx +47 -9
  43. package/src/admin/editor/panels/color-space.ts +195 -0
  44. package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
  45. package/src/admin/editor/panels/settings/BackgroundControls.tsx +153 -55
  46. package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
  47. package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
  48. package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
  49. package/src/admin/editor/panels/settings/ClassChipInput.tsx +104 -2
  50. package/src/admin/editor/panels/settings/DraftTextField.tsx +44 -3
  51. package/src/admin/editor/panels/settings/EffectsControls.tsx +25 -16
  52. package/src/admin/editor/panels/settings/FieldBindControl.tsx +53 -17
  53. package/src/admin/editor/panels/settings/FieldControl.tsx +129 -9
  54. package/src/admin/editor/panels/settings/FormBindControl.tsx +14 -5
  55. package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
  56. package/src/admin/editor/panels/settings/IconPicker.tsx +133 -72
  57. package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
  58. package/src/admin/editor/panels/settings/LengthRow.tsx +97 -61
  59. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +10 -4
  60. package/src/admin/editor/panels/settings/MediaPicker.tsx +4 -2
  61. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  62. package/src/admin/editor/panels/settings/StyleRow.tsx +158 -75
  63. package/src/admin/editor/panels/settings/VariableBinding.tsx +5 -1
  64. package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
  65. package/src/admin/editor/panels/settings/background-mode.ts +112 -0
  66. package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
  67. package/src/admin/editor/panels/settings/box-sides.ts +153 -0
  68. package/src/admin/editor/panels/settings/button-url.ts +27 -0
  69. package/src/admin/editor/panels/settings/class-suggest.ts +5 -3
  70. package/src/admin/editor/panels/settings/form-names.ts +38 -0
  71. package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
  72. package/src/admin/editor/panels/settings/image-alt.ts +25 -0
  73. package/src/admin/editor/panels/settings/length-units.ts +40 -7
  74. package/src/admin/editor/panels/settings/loop-context.ts +26 -0
  75. package/src/admin/editor/panels/settings/style-sections.ts +114 -11
  76. package/src/admin/editor/panels/settings/svg-images.ts +14 -0
  77. package/src/admin/editor/panels/site-list.tsx +3 -0
  78. package/src/admin/editor/restore-deleted.ts +80 -0
  79. package/src/admin/editor/shortcuts.ts +1 -1
  80. package/src/admin/editor/store.ts +35 -7
  81. package/src/admin/editor/useEditorCommands.ts +66 -5
  82. package/src/admin/editor/useEditorData.ts +29 -3
  83. package/src/admin/editor/useEditorShortcuts.ts +34 -2
  84. package/src/admin/editor/useNodeActions.ts +68 -6
  85. package/src/admin/editor/useSave.ts +60 -3
  86. package/src/admin/entry-status.ts +19 -0
  87. package/src/admin/icon-uploads-api.ts +44 -0
  88. package/src/admin/pages/PageList.tsx +22 -2
  89. package/src/admin/pages/ThemePartList.tsx +23 -4
  90. package/src/admin/pages/list-kit.tsx +52 -2
  91. package/src/admin/setup/spec.ts +7 -0
  92. package/src/admin/theme-api.ts +61 -14
  93. package/src/admin/ui.ts +17 -4
  94. package/src/astro/EmVBPage.astro +28 -2
  95. package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
  96. package/src/astro/floats/index.ts +1 -0
  97. package/src/astro/floats/runtime.ts +78 -0
  98. package/src/astro/forms-definitions.ts +22 -0
  99. package/src/astro/index.ts +1 -0
  100. package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
  101. package/src/astro/menu/index.ts +1 -0
  102. package/src/astro/menu/runtime.ts +37 -0
  103. package/src/astro/popups/runtime.ts +54 -4
  104. package/src/astro/render.ts +47 -13
  105. package/src/astro/resolve-theme.ts +168 -24
  106. package/src/astro/tabs/runtime.ts +6 -1
  107. package/src/astro/theme-context.ts +25 -5
  108. package/src/astro/theme-posts.ts +19 -1
  109. package/src/constants.ts +1 -1
  110. package/src/core/arrange.ts +98 -10
  111. package/src/core/clipboard.ts +91 -9
  112. package/src/core/css/generate.ts +21 -4
  113. package/src/core/design/classes.ts +95 -9
  114. package/src/core/design/transfer.ts +101 -2
  115. package/src/core/design/variables.ts +51 -11
  116. package/src/core/elements/dynamic-elements.ts +57 -5
  117. package/src/core/elements/field-id.ts +6 -0
  118. package/src/core/elements/form-elements.ts +23 -8
  119. package/src/core/elements/index.ts +267 -49
  120. package/src/core/elements/menu.ts +190 -0
  121. package/src/core/forms/definition.ts +11 -0
  122. package/src/core/index.ts +67 -3
  123. package/src/core/limits.ts +2 -0
  124. package/src/core/migrate/index.ts +51 -1
  125. package/src/core/nesting.ts +51 -0
  126. package/src/core/render/context.ts +7 -0
  127. package/src/core/render/dynamic-post.ts +39 -11
  128. package/src/core/render/extras.ts +22 -3
  129. package/src/core/render/form.ts +134 -36
  130. package/src/core/render/index.ts +123 -25
  131. package/src/core/render/loop.ts +10 -3
  132. package/src/core/render/pagination.ts +76 -0
  133. package/src/core/render/section.ts +5 -1
  134. package/src/core/render/tabs.ts +8 -4
  135. package/src/core/render/vnode.ts +1 -1
  136. package/src/core/sanitize/css.ts +197 -17
  137. package/src/core/sanitize/embed-url.ts +64 -7
  138. package/src/core/sanitize/svg-upload.ts +203 -0
  139. package/src/core/sanitize/svg.ts +102 -21
  140. package/src/core/schema/descriptors.ts +4 -0
  141. package/src/core/schema/design.ts +7 -2
  142. package/src/core/schema/layout.ts +210 -19
  143. package/src/core/schema/style.ts +87 -8
  144. package/src/core/tabs/presence.ts +9 -0
  145. package/src/core/theme/conditions.ts +4 -1
  146. package/src/core/theme/dynamic.ts +10 -0
  147. package/src/core/theme/float.ts +113 -0
  148. package/src/core/theme/pagination.ts +97 -0
  149. package/src/core/theme/part-types.ts +2 -0
  150. package/src/core/theme/popup-markup.ts +3 -1
  151. package/src/core/theme/popup-rules.ts +4 -3
  152. package/src/server/hooks.ts +20 -0
  153. package/src/server/icon-routes.ts +79 -0
  154. package/src/server/plugin.ts +5 -1
@@ -33,3 +33,69 @@ export function tabPanelIdForLabel(target: EventTarget | null): string | null {
33
33
  const { labels, panels } = own(tabs);
34
34
  return panels[labels.indexOf(label)]?.getAttribute("data-emvb-id") ?? null;
35
35
  }
36
+
37
+ const AUTO_OPEN = "data-emvb-auto-open";
38
+
39
+ /**
40
+ * Opens the closed accordion items that hold element `id` on the canvas, so it can be seen and
41
+ * edited, and closes the ones it opened before once the selection leaves them. Canvas only: the
42
+ * saved Open setting is untouched (W-130).
43
+ */
44
+ export function revealInAccordions(
45
+ doc: Document,
46
+ id: string | null,
47
+ savedOpen: (itemId: string) => boolean = () => false,
48
+ ): void {
49
+ const element = id ? doc.querySelector(`[data-emvb-id="${CSS.escape(id)}"]`) : null;
50
+ const holders = new Set<HTMLDetailsElement>();
51
+ for (
52
+ let item = element?.closest<HTMLDetailsElement>("details.emvb-accordion-item");
53
+ item;
54
+ item = item.parentElement?.closest<HTMLDetailsElement>("details.emvb-accordion-item")
55
+ ) {
56
+ holders.add(item);
57
+ }
58
+ for (const item of doc.querySelectorAll<HTMLDetailsElement>(`details[${AUTO_OPEN}]`)) {
59
+ if (holders.has(item)) continue;
60
+ item.removeAttribute(AUTO_OPEN);
61
+ // Open was switched on while we held it open: leave it open.
62
+ if (!savedOpen(item.getAttribute("data-emvb-id") ?? "")) item.open = false;
63
+ }
64
+ for (const item of holders) {
65
+ if (item.open) continue;
66
+ item.setAttribute(AUTO_OPEN, "");
67
+ item.open = true;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Opens the menu disclosures that hold element `id` on the canvas, and closes the ones it
73
+ * opened before once the selection leaves them. The public page stays closed until the visitor
74
+ * opens it.
75
+ */
76
+ export function revealInMenus(doc: Document, id: string | null): void {
77
+ const element = id ? doc.querySelector(`[data-emvb-id="${CSS.escape(id)}"]`) : null;
78
+ const holders = new Set<HTMLDetailsElement>();
79
+ for (
80
+ let item = element?.closest("li.emvb-menu-item");
81
+ item;
82
+ item = item.parentElement?.closest("li.emvb-menu-item")
83
+ ) {
84
+ const details = item.querySelector<HTMLDetailsElement>(
85
+ ":scope > .emvb-menu-item__bar > details",
86
+ );
87
+ if (details) holders.add(details);
88
+ }
89
+ for (const details of doc.querySelectorAll<HTMLDetailsElement>(
90
+ `details.emvb-menu-item__disclosure[${AUTO_OPEN}]`,
91
+ )) {
92
+ if (holders.has(details)) continue;
93
+ details.removeAttribute(AUTO_OPEN);
94
+ details.open = false;
95
+ }
96
+ for (const details of holders) {
97
+ if (details.open) continue;
98
+ details.setAttribute(AUTO_OPEN, "");
99
+ details.open = true;
100
+ }
101
+ }
@@ -9,10 +9,30 @@ const REACT_ATTR: Record<string, string> = {
9
9
  autocomplete: "autoComplete",
10
10
  allowfullscreen: "allowFullScreen",
11
11
  referrerpolicy: "referrerPolicy",
12
+ // W-297: form field limits from the bound form definition.
13
+ minlength: "minLength",
14
+ maxlength: "maxLength",
15
+ novalidate: "noValidate",
12
16
  // The canvas never updates a radio from props, so a tab chosen there stays chosen (QA-5).
13
17
  checked: "defaultChecked",
14
18
  };
15
19
 
20
+ /**
21
+ * Presence attributes the core writes as `""`. React reads `""` as false for these, so a saved-open
22
+ * accordion item rendered closed on the canvas (W-130); presence means on.
23
+ */
24
+ const BOOLEAN_ATTRS = new Set([
25
+ "open",
26
+ "controls",
27
+ "allowfullscreen",
28
+ "muted",
29
+ "loop",
30
+ "playsinline",
31
+ "autoplay",
32
+ "required",
33
+ "novalidate",
34
+ ]);
35
+
16
36
  /** SVG tags the core keeps lowercase; the SVG namespace only knows their camelCase names. */
17
37
  const REACT_TAG: Record<string, string> = {
18
38
  lineargradient: "linearGradient",
@@ -39,7 +59,7 @@ export function vnodeToReact(node: VNode | string, key?: React.Key): React.React
39
59
  const props: Record<string, unknown> = { key };
40
60
  for (const [name, value] of Object.entries(node.attrs)) {
41
61
  if (!isAllowedAttr(name)) continue;
42
- props[reactAttr(name)] = name === "checked" ? true : value;
62
+ props[reactAttr(name)] = name === "checked" || BOOLEAN_ATTRS.has(name) ? true : value;
43
63
  }
44
64
  return React.createElement(
45
65
  REACT_TAG[node.tag] ?? node.tag,
@@ -39,6 +39,45 @@ export function ConflictDialog({
39
39
  );
40
40
  }
41
41
 
42
+ /** Revert to published (W-193): drops the saved draft and any unsaved edits, after a confirm. */
43
+ export function RevertDialog({
44
+ open,
45
+ onOpenChange,
46
+ onRevert,
47
+ }: OpenProps & { onRevert: () => void }) {
48
+ return (
49
+ <Dialog.Root open={open} onOpenChange={onOpenChange}>
50
+ <Dialog size="base" className="p-6">
51
+ <style>{UI_CSS}</style>
52
+ <div data-emvb-dialog="revert" className="emvb-dialog">
53
+ <Dialog.Title>Revert to the published version?</Dialog.Title>
54
+ <Dialog.Description>
55
+ Your saved draft and any unsaved changes are discarded, and the editor shows what is
56
+ live now. This can't be undone.
57
+ </Dialog.Description>
58
+ <div className="emvb-dialog-actions">
59
+ <Dialog.Close
60
+ render={(props) => (
61
+ <Button {...props} variant="secondary" className={BUTTON}>
62
+ Cancel
63
+ </Button>
64
+ )}
65
+ />
66
+ <Button
67
+ variant="destructive"
68
+ className={BUTTON}
69
+ style={SOLID_DESTRUCTIVE}
70
+ onClick={onRevert}
71
+ >
72
+ Revert
73
+ </Button>
74
+ </div>
75
+ </div>
76
+ </Dialog>
77
+ </Dialog.Root>
78
+ );
79
+ }
80
+
42
81
  /** Exit with unsaved changes (IA "Leaving the editor"). */
43
82
  export function LeaveDialog({
44
83
  open,
@@ -1,5 +1,5 @@
1
1
  import type { Layout, LayoutNode, StyleProps } from "../../../core/index.ts";
2
- import { findNode, parentOf } from "../../../core/index.ts";
2
+ import { findNode, isParentNode, parentOf } from "../../../core/index.ts";
3
3
 
4
4
  export type Rect = { top: number; left: number; width: number; height: number };
5
5
  export type Point = { x: number; y: number };
@@ -83,19 +83,66 @@ export function dropIndex(direction: Direction, children: Rect[], point: Point):
83
83
  return before ?? (group.at(-1) as number) + 1;
84
84
  }
85
85
 
86
- /** The container a drop over `hoveredId` goes into: the element itself if it's a container, else its parent. */
87
- export function dropContainer(layout: Layout, hoveredId: string | null): LayoutNode {
88
- const hovered = hoveredId ? findNode(layout, hoveredId) : undefined;
89
- if (!hovered) return layout.root;
90
- if (
91
- hovered.type === "container" ||
92
- hovered.type === "div-block" ||
93
- hovered.type === "flexbox" ||
94
- hovered.type === "loop" ||
95
- hovered.type === "tabs" ||
96
- hovered.type === "tab-panel"
97
- )
98
- return hovered;
99
- const parentId = parentOf(layout, hovered.id);
100
- return (parentId && findNode(layout, parentId)) || layout.root;
86
+ /** Whether `parent` takes the element being dragged (usually `canDrop` for the known source). */
87
+ export type Accepts = (parent: LayoutNode) => boolean;
88
+
89
+ const anyParent: Accepts = (parent) => isParentNode(parent);
90
+
91
+ /**
92
+ * The element a drop over `hoveredId` goes into (W-128): the nearest element at or above it that
93
+ * takes the dragged element. A non-panel dropped on Tabs goes into its active panel
94
+ * (`activePanel`, else the first panel). Falls back to the page's root.
95
+ */
96
+ export function dropContainer(
97
+ layout: Layout,
98
+ hoveredId: string | null,
99
+ accepts: Accepts = anyParent,
100
+ activePanel?: (tabsId: string) => string | undefined,
101
+ ): LayoutNode {
102
+ let current: LayoutNode | undefined = hoveredId ? findNode(layout, hoveredId) : undefined;
103
+ while (current) {
104
+ if (isParentNode(current)) {
105
+ if (accepts(current)) return current;
106
+ if (current.type === "tabs") {
107
+ const wanted = activePanel?.(current.id);
108
+ const panel = current.children.find((child) => child.id === wanted) ?? current.children[0];
109
+ if (panel && accepts(panel)) return panel;
110
+ }
111
+ }
112
+ const parentId = parentOf(layout, current.id);
113
+ current = parentId ? findNode(layout, parentId) : undefined;
114
+ }
115
+ return layout.root;
116
+ }
117
+
118
+ /** How close to a container's edge, along its parent's main axis, a drop goes beside it. */
119
+ const EDGE_ZONE = 10;
120
+
121
+ /**
122
+ * Before/after edge zones (W-128): a pointer within `EDGE_ZONE` px (at most a quarter of its size)
123
+ * of `container`'s start or end edge, along its parent's main axis, drops beside it in the
124
+ * parent instead of inside it. Null when the pointer is in the middle, for the root, or when the
125
+ * parent doesn't take the element.
126
+ */
127
+ export function edgeDrop(
128
+ layout: Layout,
129
+ container: LayoutNode,
130
+ rect: Rect,
131
+ point: Point,
132
+ accepts: Accepts = anyParent,
133
+ ): { parentId: string; index: number } | null {
134
+ const parentId = parentOf(layout, container.id);
135
+ const parent = parentId ? findNode(layout, parentId) : undefined;
136
+ if (!parent || !isParentNode(parent) || !accepts(parent)) return null;
137
+ const direction = parent.style?.flexDirection ?? "column";
138
+ const row = direction.startsWith("row");
139
+ const span = along(rect, row);
140
+ const zone = Math.min(EDGE_ZONE, (span.end - span.start) / 4);
141
+ const pointer = row ? point.x : point.y;
142
+ const index = parent.children.findIndex((child) => child.id === container.id);
143
+ const reverse = direction.endsWith("reverse");
144
+ if (pointer < span.start + zone)
145
+ return { parentId: parent.id, index: reverse ? index + 1 : index };
146
+ if (pointer > span.end - zone) return { parentId: parent.id, index: reverse ? index : index + 1 };
147
+ return null;
101
148
  }
@@ -3,10 +3,58 @@ import {
3
3
  ELEMENTS,
4
4
  newNodeId,
5
5
  type ElementType,
6
+ type Layout,
6
7
  type LayoutNode,
7
8
  } from "../../../core/index.ts";
8
9
 
9
- /** Default node for an Add-tile drag. */
10
+ const hasH1 = (node: LayoutNode): boolean =>
11
+ ((node.type === "heading" || node.type === "post-title") &&
12
+ (node.props as { level?: number }).level === 1) ||
13
+ ("children" in node && Array.isArray(node.children) && node.children.some(hasH1));
14
+
15
+ /**
16
+ * A new Heading is the page's H1 when the page has none yet, otherwise the default H2 (W-147).
17
+ * Other nodes, and headings whose level was already chosen, are returned as they are.
18
+ */
19
+ export function withPageHeadingLevel(node: LayoutNode, layout: Layout): LayoutNode {
20
+ if (node.type !== "heading" || node.props.level !== 2 || hasH1(layout.root)) return node;
21
+ return { ...node, props: { ...node.props, level: 1 } };
22
+ }
23
+
24
+ const textNode = (text: string, random?: () => number): LayoutNode => ({
25
+ ...defaultElement("text", newNodeId(random)),
26
+ props: { text },
27
+ });
28
+
29
+ /**
30
+ * An accordion item titled "Question n" holding a Text, for a new Accordion or its Add item
31
+ * (W-130, W-154).
32
+ */
33
+ export function newAccordionItem(n: number, random?: () => number, open = false): LayoutNode {
34
+ return {
35
+ id: newNodeId(random),
36
+ type: "accordion-item",
37
+ props: open ? { summary: `Question ${n}`, open: true } : { summary: `Question ${n}` },
38
+ children: [
39
+ textNode(`Answer to question ${n}. Replace this text or add elements here.`, random),
40
+ ],
41
+ };
42
+ }
43
+
44
+ /** A tab panel labelled "Tab n" holding a Text, for Tabs' Add tab (W-130). */
45
+ export function newTabPanel(n: number, random?: () => number): LayoutNode {
46
+ return {
47
+ id: newNodeId(random),
48
+ type: "tab-panel",
49
+ props: { label: `Tab ${n}` },
50
+ children: [textNode(`Content for tab ${n}.`, random)],
51
+ };
52
+ }
53
+
54
+ /**
55
+ * Default node for a new element from the Add panel. Only new inserts get starter children;
56
+ * saved Accordions and Tabs with no items keep working as they are (W-130).
57
+ */
10
58
  export function newElement(type: string, random?: () => number): LayoutNode | null {
11
59
  if (!(type in ELEMENTS)) return null;
12
60
  if (type === "tabs") {
@@ -28,5 +76,32 @@ export function newElement(type: string, random?: () => number): LayoutNode | nu
28
76
  children: [panel("Tab 1", "First tab"), panel("Tab 2", "Second tab")],
29
77
  };
30
78
  }
79
+ if (type === "menu") {
80
+ const menuNode = defaultElement("menu", newNodeId(random));
81
+ const item = (text: string, href: string, children: LayoutNode[] = []): LayoutNode => ({
82
+ id: newNodeId(random),
83
+ type: "menu-item",
84
+ props: { text, href },
85
+ children,
86
+ });
87
+ return {
88
+ ...menuNode,
89
+ children: [
90
+ item("Home", "/"),
91
+ item("Work", "/work", [
92
+ item("Projects", "/work/projects"),
93
+ item("Archive", "/work/archive"),
94
+ ]),
95
+ item("About", "/about"),
96
+ ],
97
+ };
98
+ }
99
+ if (type === "accordion") {
100
+ const accordion = defaultElement("accordion", newNodeId(random));
101
+ return {
102
+ ...accordion,
103
+ children: [1, 2, 3].map((n) => newAccordionItem(n, random, n === 1)),
104
+ };
105
+ }
31
106
  return defaultElement(type as ElementType, newNodeId(random));
32
107
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Editor chrome styles (DESIGN.md). The admin's Tailwind build is precompiled, so EmVB ships its
2
+ * Editor chrome styles. The admin's Tailwind build is precompiled, so EmVB ships its
3
3
  * own rules, scoped to the editor root and built only from Kumo variables. Panels keep their
4
4
  * 1 px borders inside their width, so the canvas gets exactly the space between them (D-025).
5
5
  * Density is compact (28 px controls, 44 px top bar, 256/288 panels) with near-opaque
@@ -62,7 +62,8 @@ export const EDITOR_CSS = `${UI_CSS}
62
62
  .emvb-save-status { display: flex; align-items: center; gap: 4px; font-size: 12px; line-height: 16px; color: var(--text-color-kumo-subtle); white-space: nowrap; }
63
63
  .emvb-danger-icon { color: var(--color-kumo-danger); }
64
64
  .emvb-link-button { border: 0; padding: 0; background: none; color: var(--text-color-kumo-default); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }
65
- .emvb-save-button { position: relative; }
65
+ .emvb-save-button, .emvb-publish-button { position: relative; }
66
+ .emvb-styles-dot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 9999px; background: currentColor; }
66
67
  .emvb-unsaved-dot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 9999px; background: var(--text-color-kumo-default); }
67
68
  .emvb-danger-text.emvb-danger-text { color: var(--text-color-kumo-danger); }
68
69
  .emvb-frame { display: grid; grid-template-columns: var(--emvb-panel-left) minmax(0, 1fr) var(--emvb-panel-right); min-height: 0; }
@@ -126,6 +127,21 @@ export const EDITOR_CSS = `${UI_CSS}
126
127
  .emvb-state-dot { display: inline-block; flex: none; width: 6px; height: 6px; margin-left: 6px; border-radius: 999px; background: var(--color-kumo-brand); vertical-align: middle; }
127
128
  .emvb-style-row[data-inherited] [role="combobox"] { color: var(--text-color-kumo-subtle); }
128
129
  .emvb-swatch { display: inline-block; width: 12px; height: 12px; margin-right: 6px; border-radius: 2px; box-shadow: inset 0 0 0 1px var(--color-kumo-line); vertical-align: -1px; }
130
+ .emvb-swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
131
+ .emvb-swatch-button { display: inline-flex; width: 24px; height: 24px; padding: 3px; border: 0; border-radius: 4px; background: transparent; box-shadow: inset 0 0 0 1px var(--color-kumo-line); cursor: pointer; }
132
+ .emvb-swatch-button .emvb-swatch { width: 100%; height: 100%; margin: 0; }
133
+ .emvb-swatch-button[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--color-kumo-brand); }
134
+ .emvb-swatch-button:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 1px; }
135
+ .emvb-custom-color { display: flex; flex-direction: column; gap: 4px; }
136
+ .emvb-custom-color-row { display: flex; align-items: flex-end; gap: 8px; }
137
+ .emvb-custom-color-row > :first-child { flex: 1; min-width: 0; }
138
+ .emvb-color-picker { width: 28px; height: 28px; padding: 2px; border: 0; border-radius: 6px; background: var(--color-kumo-control); box-shadow: inset 0 0 0 1px var(--color-kumo-line); cursor: pointer; }
139
+ .emvb-fill-types { display: flex; flex-wrap: wrap; gap: 4px; }
140
+ .emvb-fill-types button { min-height: 28px; padding: 0 10px; border: 0; border-radius: 6px; background: var(--color-kumo-control); color: var(--text-color-kumo-default); box-shadow: inset 0 0 0 1px var(--color-kumo-line); cursor: pointer; }
141
+ .emvb-fill-types button[aria-checked="true"] { background: var(--color-kumo-brand); color: #fff; box-shadow: none; }
142
+ .emvb-angle { display: flex; flex-direction: column; gap: 4px; }
143
+ .emvb-angle-slider { width: 100%; accent-color: var(--color-kumo-brand); }
144
+ .emvb-gradient-stop { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; box-shadow: inset 0 1px 0 var(--color-kumo-line); }
129
145
  .emvb-row-actions { display: flex; justify-content: flex-end; gap: 8px; }
130
146
  .emvb-layers { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 1px; }
131
147
  .emvb-layer-row { display: flex; align-items: center; gap: 6px; width: 100%; height: var(--emvb-control); padding-right: 4px; border-radius: 6px; color: var(--text-color-kumo-default); font-size: 13px; }
@@ -135,14 +151,27 @@ export const EDITOR_CSS = `${UI_CSS}
135
151
  .emvb-layer-select[aria-current="true"] { background: var(--color-kumo-brand); color: #fff; }
136
152
  .emvb-layer-select:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: -2px; }
137
153
  .emvb-layer-select[aria-current="true"]:focus-visible { outline-color: #fff; }
138
- .emvb-layer-preview { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-color-kumo-subtle); }
154
+ .emvb-layer-rename { flex: 1 1 auto; min-width: 0; height: var(--emvb-control); padding: 0 6px; border: 1px solid var(--color-kumo-brand); border-radius: 6px; background: transparent; color: inherit; font: inherit; font-size: 13px; }
155
+ .emvb-layer-select > svg { flex: none; }
156
+ .emvb-layer-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
157
+ .emvb-layer-preview { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-color-kumo-subtle); }
139
158
  .emvb-layer-select[aria-current="true"] .emvb-layer-preview { color: inherit; }
140
159
  .emvb-canvas { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--color-kumo-canvas); }
141
160
  .emvb-device-bar { display: flex; flex: none; align-items: center; justify-content: center; gap: 12px; height: 36px; border-bottom: 1px solid var(--color-kumo-line); background: var(--color-kumo-surface); }
142
- .emvb-device-tabs { width: 240px; }
161
+ /* W-127: the segmented control hugs its three options; a fixed width left a gap on the right. */
162
+ .emvb-device-tabs { width: max-content; }
163
+ /* W-244: an unselected segmented option (Desktop | Tablet | Mobile, Normal | Hover | Focus | Active) takes the
164
+ default text colour: Kumo's subtle grey on the segmented track is 4.0:1. The raised white pill marks the selected one. */
165
+ .emvb-device-tabs [role="tab"][aria-selected="false"], .emvb-state-tabs [role="tab"][aria-selected="false"] { color: var(--text-color-kumo-default); }
166
+ .emvb-device-label { display: inline-flex; align-items: center; gap: 6px; }
143
167
  .emvb-device-hide { display: inline-flex; align-items: center; gap: 6px; color: var(--text-color-kumo-default); font-size: 13px; }
144
- .emvb-stage { position: relative; display: flex; flex: 1 1 auto; justify-content: center; min-height: 0; width: 100%; overflow: hidden; }
145
- .emvb-stage-frame { position: relative; width: 100%; height: 100%; }
168
+ .emvb-stage { position: relative; display: flex; flex: 1 1 auto; justify-content: safe center; min-height: 0; width: 100%; overflow: hidden; }
169
+ /* W-158: at 100% a page wider than the stage scrolls sideways. */
170
+ .emvb-stage[data-emvb-zoom="actual"] { overflow-x: auto; }
171
+ .emvb-stage-frame { position: relative; flex: none; height: 100%; overflow: hidden; }
172
+ .emvb-stage-scaler { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
173
+ .emvb-zoom { min-width: 64px; font-variant-numeric: tabular-nums; }
174
+ .emvb-preview-split { display: inline-flex; gap: 2px; }
146
175
  .emvb-canvas iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }
147
176
  .emvb-canvas-text {
148
177
  position: absolute;
@@ -223,7 +252,10 @@ export const EDITOR_CSS = `${UI_CSS}
223
252
  }
224
253
  .emvb-element-tile:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 2px; }
225
254
  .emvb-element-tile:active { cursor: grabbing; }
226
- .emvb-drop-line { position: absolute; background: var(--color-kumo-brand); pointer-events: none; z-index: 2; }
255
+ .emvb-drop-line { position: absolute; background: var(--color-kumo-brand); pointer-events: none; z-index: 2; height: auto; min-height: 3px; min-width: 3px; box-shadow: 0 0 0 1px var(--color-kumo-base, #fff); border-radius: 2px; }
256
+ /* W-128: the container a drop goes into is tinted and named. */
257
+ .emvb-drop-target { position: absolute; pointer-events: none; z-index: 1; border: 2px dashed var(--color-kumo-brand); background: color-mix(in srgb, var(--color-kumo-brand) 6%, transparent); border-radius: 4px; box-sizing: border-box; }
258
+ .emvb-drop-target-label { position: absolute; pointer-events: none; z-index: 2; height: 22px; padding: 2px 8px; border-radius: 4px; background: var(--color-kumo-brand); color: #fff; font-size: 12px; line-height: 18px; white-space: nowrap; box-sizing: border-box; }
227
259
 
228
260
  .emvb-left-panel { gap: 12px; }
229
261
  .emvb-add-group { display: flex; flex-direction: column; gap: 8px; }
@@ -270,6 +302,27 @@ export const EDITOR_CSS = `${UI_CSS}
270
302
  .emvb-breadcrumb-part:hover { color: var(--text-color-kumo-default); text-decoration: underline; text-underline-offset: 2px; }
271
303
  .emvb-breadcrumb-part:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 2px; }
272
304
  .emvb-style-row { display: flex; align-items: flex-start; gap: 4px; }
305
+ .emvb-choice { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
306
+ .emvb-choice-label { font-size: 13px; line-height: 20px; color: var(--text-color-kumo-default); }
307
+ .emvb-style-row[data-set="true"] .emvb-choice-label { font-weight: 600; }
308
+ .emvb-choice-group { display: flex; flex-wrap: wrap; gap: 4px; }
309
+ .emvb-choice-group button {
310
+ display: inline-flex; align-items: center; justify-content: center;
311
+ width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px; cursor: pointer;
312
+ background: var(--color-kumo-control); color: var(--text-color-kumo-default);
313
+ box-shadow: inset 0 0 0 1px var(--color-kumo-line);
314
+ }
315
+ .emvb-choice-group button[aria-checked="true"],
316
+ .emvb-choice-group button[aria-pressed="true"] {
317
+ background: var(--color-kumo-tint); color: var(--color-kumo-brand);
318
+ box-shadow: inset 0 0 0 1px var(--color-kumo-brand);
319
+ }
320
+ .emvb-choice-group button:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 2px; }
321
+ .emvb-shape-swatch { display: block; width: 14px; height: 14px; background: currentColor; opacity: 0.85; }
322
+ .emvb-shape-swatch[data-shape="circle"] { border-radius: 50%; }
323
+ .emvb-shape-swatch[data-shape="rounded"] { border-radius: 4px; }
324
+ .emvb-length-stack { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
325
+ .emvb-gap-slider { width: 100%; margin: 0; accent-color: var(--color-kumo-brand); }
273
326
  .emvb-shadow-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
274
327
  .emvb-add-shadow { align-self: flex-start; }
275
328
  .emvb-style-row[data-emvb-style="boxShadow"] > .emvb-reset-btn { margin-top: -4px; }
@@ -286,12 +339,39 @@ export const EDITOR_CSS = `${UI_CSS}
286
339
  }
287
340
  .emvb-unit-btn:hover, .emvb-unit-btn[data-popup-open] { background: var(--color-kumo-tint); color: var(--text-color-kumo-default); }
288
341
  .emvb-unit-btn:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: -2px; }
289
- /* Variable button and bound-variable chip (W-087, DESIGN.md "variable chip") */
342
+ /* Variable button and bound-variable chip (W-087) */
290
343
  .emvb-var-btn {
291
344
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
292
345
  width: 28px; height: 28px; margin-top: 28px; padding: 0; border: 0; border-radius: 6px;
293
346
  background: transparent; color: var(--text-color-kumo-subtle); cursor: pointer;
294
347
  }
348
+ /* Linked four-box control (W-138, D-044): padding, margin, border width, radius. */
349
+ .emvb-box > .emvb-box-body { display: flex; flex-direction: column; gap: 4px; }
350
+ .emvb-box > .emvb-reset-btn { margin-top: 0; }
351
+ .emvb-box-head { display: flex; align-items: center; gap: 2px; min-height: 28px; }
352
+ .emvb-box-label { flex: 1 1 auto; min-width: 0; font-size: 14px; line-height: 20px; font-weight: 500; color: var(--text-color-kumo-default); }
353
+ .emvb-box-head .emvb-var-btn { margin-top: 0; }
354
+ .emvb-link-btn {
355
+ display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
356
+ width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px;
357
+ background: transparent; color: var(--text-color-kumo-subtle); cursor: pointer;
358
+ }
359
+ .emvb-link-btn:hover { background: var(--color-kumo-tint); color: var(--text-color-kumo-default); }
360
+ .emvb-link-btn[aria-pressed="true"] { color: var(--color-kumo-brand); background: var(--color-kumo-tint); }
361
+ .emvb-link-btn:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 1px; }
362
+ .emvb-box-sides { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
363
+ .emvb-box-side { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
364
+ .emvb-box-input {
365
+ width: 100%; height: 28px; padding: 0 4px; border: 0; border-radius: 6px; text-align: center;
366
+ background: var(--color-kumo-control); color: var(--text-color-kumo-default); font-size: 13px;
367
+ box-shadow: inset 0 0 0 1px var(--color-kumo-line);
368
+ }
369
+ .emvb-box-input::placeholder { color: var(--text-color-kumo-subtle); }
370
+ .emvb-box-input:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: -1px; }
371
+ .emvb-box-input[aria-invalid="true"] { box-shadow: inset 0 0 0 1px var(--text-color-kumo-danger); }
372
+ .emvb-box-input[data-bound="true"] { color: var(--color-kumo-brand); }
373
+ .emvb-box-name { font-size: 11px; line-height: 14px; color: var(--text-color-kumo-subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
374
+ .emvb-box-error { margin: 0; font-size: 12px; line-height: 16px; color: var(--text-color-kumo-danger); }
295
375
  .emvb-var-btn:hover, .emvb-var-btn[data-popup-open] { background: var(--color-kumo-tint); color: var(--text-color-kumo-default); }
296
376
  .emvb-var-btn[data-active="true"] { color: var(--color-kumo-brand); }
297
377
  .emvb-var-btn:focus-visible, .emvb-var-chip-x:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 1px; }
@@ -343,13 +423,15 @@ export const EDITOR_CSS = `${UI_CSS}
343
423
  .emvb-media-card img { display: block; width: 100%; height: 64px; object-fit: cover; border-radius: 4px; background: var(--color-kumo-canvas); }
344
424
  .emvb-media-card span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
345
425
 
346
- .emvb-icon-grid { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; max-height: 256px; overflow: auto; }
347
- .emvb-icon-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; padding: 8px 4px; border: 1px solid var(--color-kumo-hairline); border-radius: 6px; background: var(--emvb-glass-strong); color: var(--text-color-kumo-default); font: inherit; font-size: 11px; line-height: 14px; cursor: pointer; }
348
- .emvb-icon-tile:hover { background: var(--color-kumo-tint); }
349
- .emvb-icon-tile[data-selected="true"] { border-color: var(--color-kumo-brand); background: var(--color-kumo-tint); }
350
- .emvb-icon-tile span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
426
+ .emvb-icon-current { display: flex; align-items: center; gap: 8px; min-width: 0; }
427
+ .emvb-icon-current-preview { flex: none; display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; padding: 0; border: 1px solid var(--color-kumo-hairline); border-radius: 8px; background: var(--emvb-glass-strong); color: var(--text-color-kumo-default); cursor: pointer; }
428
+ .emvb-icon-current-preview:hover { border-color: var(--color-kumo-brand); }
429
+ .emvb-icon-current-preview span { display: flex; }
430
+ .emvb-icon-current-text { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 12px; line-height: 16px; }
431
+ .emvb-icon-current-text strong { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
432
+ .emvb-icon-current-text span { color: var(--text-color-kumo-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
351
433
 
352
- /* Class chip input (W-087, DESIGN.md): one 28 px box holding the chips and the text input */
434
+ /* Class chip input (W-087): one 28 px box holding the chips and the text input */
353
435
  .emvb-class-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
354
436
  .emvb-chip-anchor { position: relative; }
355
437
  .emvb-chip-box {
@@ -389,6 +471,9 @@ export const EDITOR_CSS = `${UI_CSS}
389
471
  flex: 1 0 72px; min-width: 72px; height: 20px; padding: 0 4px; border: 0; outline: 0;
390
472
  background: transparent; color: var(--text-color-kumo-default); font: inherit; font-size: 13px;
391
473
  }
474
+ .emvb-save-local { align-self: flex-start; font-size: 13px; }
475
+ .emvb-save-local-row { display: flex; flex-direction: column; gap: 8px; }
476
+ .emvb-save-local-actions { display: flex; gap: 8px; }
392
477
  .emvb-chip-text::placeholder { color: var(--text-color-kumo-placeholder, var(--text-color-kumo-subtle)); }
393
478
  .emvb-chip-listbox {
394
479
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0;
@@ -437,6 +522,7 @@ export const EDITOR_CSS = `${UI_CSS}
437
522
  .emvb-site-class-section:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: -2px; }
438
523
  .emvb-site-token { margin: 0; font-size: 11px; color: var(--text-color-kumo-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
439
524
  .emvb-site-cascade { margin: 0 0 4px; padding: 8px; border-radius: 6px; background: var(--color-kumo-tint); border: 1px solid var(--color-kumo-hairline); }
525
+ .emvb-unit-note { margin-left: 8px; font-size: 11px; color: var(--text-color-kumo-subtle); }
440
526
  .emvb-site-usage { flex: 0 0 auto; white-space: nowrap; font-size: 11px; line-height: 16px; color: var(--text-color-kumo-subtle); font-variant-numeric: tabular-nums; }
441
527
  /* Compact manager rows (W-087): one 32 px line per class or variable, details on demand */
442
528
  .emvb-site-items {
@@ -524,7 +610,7 @@ export const EDITOR_CSS = `${UI_CSS}
524
610
  .emvb-layer-menu-list,
525
611
  .emvb-media-dialog,
526
612
  .emvb-media-card,
527
- .emvb-icon-tile,
613
+ .emvb-icon-current-preview,
528
614
  .emvb-site-confirm,
529
615
  .emvb-invalid-label {
530
616
  background: var(--color-kumo-base);
@@ -0,0 +1,30 @@
1
+ import * as React from "react";
2
+ import { exitTarget, PAGES_URL } from "./exit.ts";
3
+
4
+ /**
5
+ * Where the editor sends someone who leaves it. The EmDash admin is the default; a host that
6
+ * embeds the editor somewhere else (the emvb.dev playground) provides its own.
7
+ */
8
+ export type EditorHost = {
9
+ /** Exit, and Discard or Save and leave in the Leave dialog. */
10
+ exit: () => void;
11
+ /** The way back when the editor can't open here (small screen, missing page). */
12
+ back: { label: string; go: () => void };
13
+ /**
14
+ * Whether panels link to other EmDash admin screens (Forms, Theme Builder). A host without the
15
+ * admin (the playground) sets false, so those links don't lead nowhere (W-289). Default true.
16
+ */
17
+ adminLinks?: boolean;
18
+ };
19
+
20
+ const defaultEditorHost: EditorHost = {
21
+ exit: () => window.location.assign(exitTarget(document.referrer, window.location.origin)),
22
+ back: { label: "Visual pages", go: () => window.location.assign(PAGES_URL) },
23
+ };
24
+
25
+ export const EditorHostContext = React.createContext<EditorHost>(defaultEditorHost);
26
+
27
+ export const useEditorHost = (): EditorHost => React.useContext(EditorHostContext);
28
+
29
+ /** False when the editor runs outside the EmDash admin, where admin links would lead nowhere. */
30
+ export const useAdminLinks = (): boolean => useEditorHost().adminLinks !== false;