@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
@@ -0,0 +1,199 @@
1
+ import { Button } from "@cloudflare/kumo";
2
+ import * as React from "react";
3
+ import {
4
+ ArrowDownIcon,
5
+ ArrowUpIcon,
6
+ PencilSimpleIcon,
7
+ PlusIcon,
8
+ TrashIcon,
9
+ } from "@phosphor-icons/react";
10
+ import { MAX_TABS, type FieldDescriptor, type LayoutNode } from "../../../../core/index.ts";
11
+ import { BUTTON } from "../../../ui.ts";
12
+ import { newAccordionItem, newTabPanel } from "../../dnd/new-element.ts";
13
+ import { DraftTextField } from "./DraftTextField.tsx";
14
+
15
+ /** Layout operations the list runs through the editor, so limits, history and Restore apply. */
16
+ export type ItemActions = {
17
+ add: (parentId: string, node: LayoutNode) => void;
18
+ /** Deletes with the editor's usual confirm and Restore toast. */
19
+ remove: (id: string) => void;
20
+ move: (id: string, direction: "up" | "down") => void;
21
+ };
22
+
23
+ type Kind = {
24
+ noun: string;
25
+ field: (n: number) => FieldDescriptor;
26
+ make: (n: number) => LayoutNode;
27
+ max?: number;
28
+ };
29
+
30
+ const KINDS: Record<string, Kind> = {
31
+ accordion: {
32
+ noun: "item",
33
+ field: (n) => ({ key: "summary", kind: "text", label: `Item ${n} title` }),
34
+ make: (n) => newAccordionItem(n),
35
+ },
36
+ tabs: {
37
+ noun: "tab",
38
+ field: (n) => ({ key: "label", kind: "text", label: `Tab ${n} label` }),
39
+ make: (n) => newTabPanel(n),
40
+ max: MAX_TABS,
41
+ },
42
+ };
43
+
44
+ /** True for the elements whose Content tab is a list of their items (W-130). */
45
+ export const hasItemList = (type: string) => type in KINDS;
46
+
47
+ const childrenOf = (node: LayoutNode): LayoutNode[] =>
48
+ "children" in node && Array.isArray(node.children) ? (node.children as LayoutNode[]) : [];
49
+
50
+ /** Fallback when no editor actions are wired (isolated panels): plain edits of the parent. */
51
+ function localActions(node: LayoutNode, onChange: (node: LayoutNode) => void): ItemActions {
52
+ const kids = childrenOf(node);
53
+ const set = (children: LayoutNode[]) => onChange({ ...node, children } as LayoutNode);
54
+ return {
55
+ add: (_parentId, child) => set([...kids, child]),
56
+ remove: (id) => set(kids.filter((child) => child.id !== id)),
57
+ move: (id, direction) => {
58
+ const from = kids.findIndex((child) => child.id === id);
59
+ const to = direction === "up" ? from - 1 : from + 1;
60
+ if (from < 0 || to < 0 || to >= kids.length) return;
61
+ const next = [...kids];
62
+ const [moved] = next.splice(from, 1);
63
+ if (moved) next.splice(to, 0, moved);
64
+ set(next);
65
+ },
66
+ };
67
+ }
68
+
69
+ /**
70
+ * Accordion items or Tabs panels as a list: title, edit (select it), move, delete, and Add
71
+ * (W-130). Each item's content is its child elements, edited on the canvas.
72
+ */
73
+ export function ItemList({
74
+ node,
75
+ onChange,
76
+ onSelect,
77
+ actions,
78
+ }: {
79
+ node: LayoutNode;
80
+ onChange: (node: LayoutNode) => void;
81
+ onSelect: (id: string) => void;
82
+ actions?: ItemActions;
83
+ }) {
84
+ const kind = KINDS[node.type];
85
+ const kids = childrenOf(node);
86
+ // An added item's title field takes focus with its text selected, so typing names it (W-154).
87
+ const listRef = React.useRef<HTMLDivElement>(null);
88
+ const focusNew = React.useRef<string | null>(null);
89
+ const ids = kids.map((child) => child.id).join(" ");
90
+ React.useEffect(() => {
91
+ const id = focusNew.current;
92
+ if (!id || !ids.split(" ").includes(id)) return;
93
+ focusNew.current = null;
94
+ const field = listRef.current?.querySelector<HTMLInputElement>(
95
+ `[data-emvb-item="${id}"] input`,
96
+ );
97
+ field?.focus();
98
+ field?.select();
99
+ }, [ids]);
100
+ if (!kind) return null;
101
+ const run = actions ?? localActions(node, onChange);
102
+ const Noun = kind.noun === "tab" ? "Tab" : "Item";
103
+ const full = kind.max !== undefined && kids.length >= kind.max;
104
+ return (
105
+ <div className="emvb-item-list" data-emvb-item-list={node.type} ref={listRef}>
106
+ <h3 className="emvb-section-label">{kind.noun === "tab" ? "Tabs" : "Items"}</h3>
107
+ {kids.length === 0 ? (
108
+ <p className="emvb-helper" data-emvb-item-empty="">
109
+ {kind.noun === "tab"
110
+ ? "No tabs yet. Add a tab, then put elements in its panel on the canvas."
111
+ : "No items yet. Add an item, then put elements in its body on the canvas."}
112
+ </p>
113
+ ) : (
114
+ <ol className="emvb-trigger-list">
115
+ {kids.map((child, index) => {
116
+ const n = index + 1;
117
+ return (
118
+ <li key={child.id} className="emvb-item-row" data-emvb-item={child.id}>
119
+ <DraftTextField
120
+ field={kind.field(n)}
121
+ node={child}
122
+ onChange={(next) =>
123
+ onChange({
124
+ ...node,
125
+ children: kids.map((k) => (k.id === next.id ? next : k)),
126
+ } as LayoutNode)
127
+ }
128
+ />
129
+ <div className="emvb-item-actions">
130
+ <Button
131
+ type="button"
132
+ variant="ghost"
133
+ shape="square"
134
+ className={BUTTON}
135
+ aria-label={`Edit ${kind.noun} ${n}`}
136
+ title={`Select ${kind.noun} ${n} to edit its settings and content`}
137
+ icon={<PencilSimpleIcon aria-hidden="true" />}
138
+ onClick={() => onSelect(child.id)}
139
+ />
140
+ <Button
141
+ type="button"
142
+ variant="ghost"
143
+ shape="square"
144
+ className={BUTTON}
145
+ aria-label={`Move ${kind.noun} ${n} up`}
146
+ title={`Move ${kind.noun} ${n} up`}
147
+ disabled={index === 0}
148
+ icon={<ArrowUpIcon aria-hidden="true" />}
149
+ onClick={() => run.move(child.id, "up")}
150
+ />
151
+ <Button
152
+ type="button"
153
+ variant="ghost"
154
+ shape="square"
155
+ className={BUTTON}
156
+ aria-label={`Move ${kind.noun} ${n} down`}
157
+ title={`Move ${kind.noun} ${n} down`}
158
+ disabled={index === kids.length - 1}
159
+ icon={<ArrowDownIcon aria-hidden="true" />}
160
+ onClick={() => run.move(child.id, "down")}
161
+ />
162
+ <Button
163
+ type="button"
164
+ variant="ghost"
165
+ shape="square"
166
+ className={BUTTON}
167
+ aria-label={`Delete ${kind.noun} ${n}`}
168
+ title={`Delete ${kind.noun} ${n}`}
169
+ icon={<TrashIcon aria-hidden="true" />}
170
+ onClick={() => run.remove(child.id)}
171
+ />
172
+ </div>
173
+ </li>
174
+ );
175
+ })}
176
+ </ol>
177
+ )}
178
+ <Button
179
+ type="button"
180
+ variant="secondary"
181
+ className={BUTTON}
182
+ icon={<PlusIcon aria-hidden="true" />}
183
+ disabled={full}
184
+ onClick={() => {
185
+ const fresh = kind.make(kids.length + 1);
186
+ focusNew.current = fresh.id;
187
+ run.add(node.id, fresh);
188
+ }}
189
+ >
190
+ {`Add ${kind.noun}`}
191
+ </Button>
192
+ {full && (
193
+ <p className="emvb-helper">
194
+ {Noun}s can show up to {kind.max} {kind.noun}s.
195
+ </p>
196
+ )}
197
+ </div>
198
+ );
199
+ }
@@ -22,8 +22,10 @@ const isLiteral = (value: unknown): value is LengthLiteral =>
22
22
  const same = (a: unknown, b: unknown) =>
23
23
  a === b || (isLiteral(a) && isLiteral(b) && a.value === b.value && a.unit === b.unit);
24
24
 
25
- const firstNumeric = (units: readonly UnitChoice[]): LengthUnit =>
26
- (units.find((u) => u !== "auto") as LengthUnit | undefined) ?? "px";
25
+ type NumericUnit = LengthUnit | "x";
26
+
27
+ const firstNumeric = (units: readonly UnitChoice[]): NumericUnit =>
28
+ (units.find((u) => u !== "auto") as NumericUnit | undefined) ?? "px";
27
29
 
28
30
  /** A length property: number input, unit menu inside its right edge, variable button (W-088). */
29
31
  export function LengthRow({
@@ -33,6 +35,7 @@ export function LengthRow({
33
35
  design,
34
36
  set,
35
37
  placeholder,
38
+ slider = false,
36
39
  onPatch,
37
40
  reset,
38
41
  }: {
@@ -43,15 +46,22 @@ export function LengthRow({
43
46
  set: boolean;
44
47
  /** The Normal value, shown while a state is edited (W-089). */
45
48
  placeholder?: string;
49
+ /** Gap: a slider for the common range. The number field still accepts the full length. */
50
+ slider?: boolean;
46
51
  onPatch: (patch: Partial<StyleProps>) => void;
47
52
  reset: React.ReactNode;
48
53
  }) {
49
54
  const units = unitsFor(styleKey);
50
- const literal = isLiteral(value) ? value : undefined;
55
+ // W-213: a plain number is a unitless line height, shown with the `x` unit.
56
+ const literal: { value: number; unit: NumericUnit } | undefined = isLiteral(value)
57
+ ? value
58
+ : typeof value === "number"
59
+ ? { value, unit: "x" }
60
+ : undefined;
51
61
  const numericUnit = literal?.unit ?? firstNumeric(units);
52
62
  const [draft, setDraft] = React.useState(literal ? String(literal.value) : "");
53
63
  const [unit, setUnit] = React.useState<UnitChoice>(value === "auto" ? "auto" : numericUnit);
54
- const lastNumeric = React.useRef<LengthUnit>(numericUnit);
64
+ const lastNumeric = React.useRef<NumericUnit>(numericUnit);
55
65
  const [error, setError] = React.useState<string | null>(null);
56
66
  React.useEffect(() => {
57
67
  setDraft(literal ? String(literal.value) : "");
@@ -60,7 +70,7 @@ export function LengthRow({
60
70
  setError(null);
61
71
  }, [value, literal]);
62
72
 
63
- const send = (next: LengthLiteral | "auto" | undefined) => {
73
+ const send = (next: LengthLiteral | "auto" | number | undefined) => {
64
74
  if (!same(next, value)) onPatch({ [styleKey]: next });
65
75
  };
66
76
 
@@ -86,7 +96,11 @@ export function LengthRow({
86
96
  lastNumeric.current = next;
87
97
  const parsed = parseLengthDraft(draft, styleKey, next);
88
98
  if (parsed.ok && parsed.value !== undefined && parsed.value !== "auto") {
89
- send({ value: parsed.value.value, unit: next });
99
+ const n = typeof parsed.value === "number" ? parsed.value : parsed.value.value;
100
+ if (next === "x") {
101
+ if (n <= 100) send(n);
102
+ else setError("Line height without a unit can be from 0 to 100.");
103
+ } else send({ value: n, unit: next });
90
104
  }
91
105
  };
92
106
 
@@ -110,61 +124,83 @@ export function LengthRow({
110
124
  onDetach={(kept) => onPatch({ [styleKey]: typeof kept === "object" ? kept : undefined })}
111
125
  />
112
126
  ) : (
113
- <InputGroup
114
- label={label}
115
- className={`${FIELD} emvb-length`}
116
- error={error ? { message: error, match: true } : undefined}
117
- >
118
- <InputGroup.Input
119
- className="emvb-mono"
120
- aria-label={label}
121
- inputMode="decimal"
122
- value={draft}
123
- placeholder={unit === "auto" ? "auto" : placeholder}
124
- aria-invalid={error ? true : undefined}
125
- onChange={(event) => {
126
- if (unit === "auto") setUnit(lastNumeric.current);
127
- setDraft(event.target.value);
128
- }}
129
- onBlur={commit}
130
- onKeyDown={(event) => {
131
- if (event.key === "Enter") commit();
132
- }}
133
- />
134
- <InputGroup.Addon align="end" className="emvb-unit-addon">
135
- <DropdownMenu>
136
- <DropdownMenu.Trigger>
137
- <button
138
- type="button"
139
- className="emvb-unit-btn"
140
- aria-label={`${label} unit (${unit})`}
141
- data-emvb-unit={unit}
142
- >
143
- {unit}
144
- <CaretDownIcon size={12} aria-hidden="true" />
145
- </button>
146
- </DropdownMenu.Trigger>
147
- <DropdownMenu.Content data-emvb-unit-menu={styleKey}>
148
- <DropdownMenu.RadioGroup
149
- value={unit}
150
- onValueChange={(next: UnitChoice) => pickUnit(next)}
151
- >
152
- {units.map((choice) => (
153
- <DropdownMenu.RadioItem
154
- key={choice}
155
- value={choice}
156
- closeOnClick
157
- data-emvb-unit-option={choice}
158
- >
159
- <span className="emvb-mono">{choice}</span>
160
- <DropdownMenu.RadioItemIndicator />
161
- </DropdownMenu.RadioItem>
162
- ))}
163
- </DropdownMenu.RadioGroup>
164
- </DropdownMenu.Content>
165
- </DropdownMenu>
166
- </InputGroup.Addon>
167
- </InputGroup>
127
+ <div className={slider ? "emvb-length-stack" : undefined}>
128
+ <InputGroup
129
+ label={label}
130
+ className={`${FIELD} emvb-length`}
131
+ error={error ? { message: error, match: true } : undefined}
132
+ >
133
+ <InputGroup.Input
134
+ className="emvb-mono"
135
+ aria-label={label}
136
+ inputMode="decimal"
137
+ value={draft}
138
+ placeholder={unit === "auto" ? "auto" : placeholder}
139
+ title={`A number in ${unit === "auto" ? lastNumeric.current : unit}, or with its own unit (2rem, 50%)${
140
+ units.includes("auto") ? ", or auto" : ""
141
+ }`}
142
+ aria-invalid={error ? true : undefined}
143
+ onChange={(event) => {
144
+ if (unit === "auto") setUnit(lastNumeric.current);
145
+ setDraft(event.target.value);
146
+ }}
147
+ onBlur={commit}
148
+ onKeyDown={(event) => {
149
+ if (event.key === "Enter") commit();
150
+ }}
151
+ />
152
+ <InputGroup.Addon align="end" className="emvb-unit-addon">
153
+ <DropdownMenu>
154
+ <DropdownMenu.Trigger>
155
+ <button
156
+ type="button"
157
+ className="emvb-unit-btn"
158
+ aria-label={`${label} unit (${unit})`}
159
+ data-emvb-unit={unit}
160
+ >
161
+ {unit === "x" ? "×" : unit}
162
+ <CaretDownIcon size={12} aria-hidden="true" />
163
+ </button>
164
+ </DropdownMenu.Trigger>
165
+ <DropdownMenu.Content data-emvb-unit-menu={styleKey}>
166
+ <DropdownMenu.RadioGroup
167
+ aria-label={`${label} unit`}
168
+ value={unit}
169
+ onValueChange={(next: UnitChoice) => pickUnit(next)}
170
+ >
171
+ {units.map((choice) => (
172
+ <DropdownMenu.RadioItem
173
+ key={choice}
174
+ value={choice}
175
+ closeOnClick
176
+ data-emvb-unit-option={choice}
177
+ >
178
+ <span className="emvb-mono">{choice === "x" ? "× (no unit)" : choice}</span>
179
+ <DropdownMenu.RadioItemIndicator />
180
+ </DropdownMenu.RadioItem>
181
+ ))}
182
+ </DropdownMenu.RadioGroup>
183
+ </DropdownMenu.Content>
184
+ </DropdownMenu>
185
+ </InputGroup.Addon>
186
+ </InputGroup>
187
+ {slider && unit !== "auto" && (
188
+ <input
189
+ className="emvb-gap-slider"
190
+ type="range"
191
+ min={0}
192
+ max={200}
193
+ step={1}
194
+ aria-label={`${label} slider`}
195
+ value={Math.min(200, literal?.value ?? 0)}
196
+ onChange={(event) => {
197
+ const next = Number(event.target.value);
198
+ setDraft(String(next));
199
+ send(unit === "x" ? next : { value: next, unit });
200
+ }}
201
+ />
202
+ )}
203
+ </div>
168
204
  )}
169
205
  {kind && (
170
206
  <VariableButton
@@ -4,6 +4,7 @@ import type { ThemePartType } from "../../../../core/index.ts";
4
4
  import type { Fetcher } from "../../../api.ts";
5
5
  import { listThemeParts, type ThemePartSummary } from "../../../theme-api.ts";
6
6
  import { FIELD } from "../../../ui.ts";
7
+ import { useAdminLinks } from "../../host.ts";
7
8
 
8
9
  const MANUAL = "__manual__";
9
10
  const NONE = "__none__";
@@ -32,6 +33,7 @@ export function LoopItemBindControl({
32
33
  }) {
33
34
  const [parts, setParts] = React.useState<ThemePartSummary[] | null>(null);
34
35
  const [failed, setFailed] = React.useState(false);
36
+ const adminLinks = useAdminLinks();
35
37
 
36
38
  React.useEffect(() => {
37
39
  let cancelled = false;
@@ -94,7 +96,7 @@ export function LoopItemBindControl({
94
96
  />
95
97
  <p className="emvb-helper">
96
98
  Optional published {label} theme part. Leave blank to use nested elements.
97
- <a href="/_emdash/admin/plugins/emvb/theme"> Open Theme Builder</a>
99
+ {adminLinks && <a href="/_emdash/admin/plugins/emvb/theme"> Open Theme Builder</a>}
98
100
  </p>
99
101
  </div>
100
102
  );
@@ -110,9 +112,13 @@ export function LoopItemBindControl({
110
112
  />
111
113
  <p className="emvb-helper">
112
114
  {failed
113
- ? `Could not load ${label} parts. Paste a theme-part id, or `
114
- : `No ${label} theme parts yet. Paste an id, or `}
115
- <a href="/_emdash/admin/plugins/emvb/theme">create one in Theme Builder</a>.
115
+ ? `Could not load ${label} parts. Paste a theme-part id${adminLinks ? ", or " : "."}`
116
+ : `No ${label} theme parts yet. Paste an id${adminLinks ? ", or " : "."}`}
117
+ {adminLinks && (
118
+ <>
119
+ <a href="/_emdash/admin/plugins/emvb/theme">create one in Theme Builder</a>.
120
+ </>
121
+ )}
116
122
  </p>
117
123
  </div>
118
124
  );
@@ -20,13 +20,15 @@ type Props = {
20
20
  node: LayoutNode;
21
21
  fetcher: Fetcher;
22
22
  onChange: (node: LayoutNode) => void;
23
+ /** Field label; Page settings uses "Social image" (W-287). */
24
+ label?: string;
23
25
  };
24
26
 
25
27
  /**
26
28
  * Image source control (W-024 / R-007): pick from EmDash media library, upload a file,
27
29
  * or paste a URL. Upload uses the same POST /_emdash/api/media path on both demos.
28
30
  */
29
- export function MediaPicker({ node, fetcher, onChange }: Props) {
31
+ export function MediaPicker({ node, fetcher, onChange, label = "Image" }: Props) {
30
32
  const props = propsOf(node);
31
33
  const src = typeof props.src === "string" ? props.src : "";
32
34
  const [open, setOpen] = React.useState(false);
@@ -108,7 +110,7 @@ export function MediaPicker({ node, fetcher, onChange }: Props) {
108
110
 
109
111
  return (
110
112
  <div className="emvb-field-group" data-emvb-field="src" data-emvb-media-picker="">
111
- <label className="emvb-field-label">Image</label>
113
+ <label className="emvb-field-label">{label}</label>
112
114
  {src ? (
113
115
  <div className="emvb-media-preview">
114
116
  <img src={src} alt="" className="emvb-media-thumb" />
@@ -18,7 +18,7 @@ const isChoice = (value: string): value is StyleStateChoice =>
18
18
  (CHOICES as string[]).includes(value);
19
19
 
20
20
  /**
21
- * The dot shown where state styles exist (DESIGN.md § State styles). Decorative on the state tabs,
21
+ * The dot shown where state styles exist. Decorative on the state tabs,
22
22
  * so their names stay "Hover", "Focus" and "Active".
23
23
  */
24
24
  export function StateDot({ decorative = false }: { decorative?: boolean }) {