@perkyzz/emvb 0.3.0 → 0.5.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 (163) hide show
  1. package/README.md +22 -4
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +5 -2
  4. package/src/admin/access/role.ts +9 -3
  5. package/src/admin/agents-api.ts +39 -0
  6. package/src/admin/api.ts +17 -7
  7. package/src/admin/content-api.ts +7 -51
  8. package/src/admin/content-item.ts +22 -0
  9. package/src/admin/design-api.ts +30 -0
  10. package/src/admin/editor/A11yCopilot.tsx +1 -1
  11. package/src/admin/editor/CommandPalette.tsx +43 -2
  12. package/src/admin/editor/Editor.tsx +133 -332
  13. package/src/admin/editor/EditorOverlay.tsx +3 -1
  14. package/src/admin/editor/PerfMeter.tsx +1 -1
  15. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  16. package/src/admin/editor/Timeline.tsx +124 -9
  17. package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
  18. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  19. package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
  20. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  21. package/src/admin/editor/canvas/drop-line.ts +24 -0
  22. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  23. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  24. package/src/admin/editor/collection-previews.ts +28 -5
  25. package/src/admin/editor/editor-chrome.tsx +346 -0
  26. package/src/admin/editor/editor-commands.ts +360 -0
  27. package/src/admin/editor/editor-css.ts +4 -0
  28. package/src/admin/editor/element-chrome.ts +89 -0
  29. package/src/admin/editor/feature-css.ts +37 -18
  30. package/src/admin/editor/host.ts +33 -0
  31. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  32. package/src/admin/editor/icons/library.ts +29 -19
  33. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  34. package/src/admin/editor/palette-items.ts +36 -5
  35. package/src/admin/editor/palette.ts +9 -4
  36. package/src/admin/editor/panels/AddPanel.tsx +2 -67
  37. package/src/admin/editor/panels/ColorControl.tsx +21 -18
  38. package/src/admin/editor/panels/ElementPanel.tsx +40 -99
  39. package/src/admin/editor/panels/LayersPanel.tsx +34 -62
  40. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  41. package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
  42. package/src/admin/editor/panels/TokenScales.tsx +4 -2
  43. package/src/admin/editor/panels/VariableSection.tsx +1 -10
  44. package/src/admin/editor/panels/color-space.ts +12 -1
  45. package/src/admin/editor/panels/inline-error.tsx +11 -0
  46. package/src/admin/editor/panels/settings/AdvancedFields.tsx +143 -1
  47. package/src/admin/editor/panels/settings/AudienceEditor.tsx +115 -7
  48. package/src/admin/editor/panels/settings/DraftTextField.tsx +42 -9
  49. package/src/admin/editor/panels/settings/FieldControl.tsx +6 -0
  50. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  51. package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
  52. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
  53. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  54. package/src/admin/editor/panels/settings/MediaPicker.tsx +2 -3
  55. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
  56. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
  57. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  58. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  59. package/src/admin/editor/panels/settings/length-units.ts +15 -4
  60. package/src/admin/editor/panels/settings/link-rules.ts +19 -0
  61. package/src/admin/editor/panels/settings/number-input.ts +11 -0
  62. package/src/admin/editor/panels/settings/query-style.ts +65 -0
  63. package/src/admin/editor/panels/settings/style-sections.ts +5 -1
  64. package/src/admin/editor/panels/style-target.ts +105 -0
  65. package/src/admin/editor/panels/variable-values.ts +4 -2
  66. package/src/admin/editor/remote-change.ts +67 -0
  67. package/src/admin/editor/section-templates.ts +43 -21
  68. package/src/admin/editor/shortcuts.ts +4 -0
  69. package/src/admin/editor/store.ts +10 -1
  70. package/src/admin/editor/useClipboardActions.ts +1 -1
  71. package/src/admin/editor/useEditorCommands.ts +61 -13
  72. package/src/admin/editor/useEditorData.ts +7 -1
  73. package/src/admin/editor/useEditorShortcuts.ts +23 -15
  74. package/src/admin/editor/useNodeActions.ts +6 -1
  75. package/src/admin/forms-api.ts +17 -6
  76. package/src/admin/icon-uploads-api.ts +18 -0
  77. package/src/admin/index.tsx +3 -1
  78. package/src/admin/media-api.ts +20 -0
  79. package/src/admin/pages/AgentsPage.tsx +274 -0
  80. package/src/admin/theme-api.ts +5 -18
  81. package/src/admin/ui.ts +28 -0
  82. package/src/astro/content-port.ts +24 -0
  83. package/src/astro/floats/runtime.ts +10 -0
  84. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  85. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  86. package/src/astro/forms/client.ts +1 -0
  87. package/src/astro/forms-definitions.ts +24 -11
  88. package/src/astro/index.ts +1 -0
  89. package/src/astro/popups/runtime.ts +15 -0
  90. package/src/astro/render-session.ts +85 -0
  91. package/src/astro/request-data.ts +20 -8
  92. package/src/astro/resolve-theme.ts +166 -76
  93. package/src/astro/resolve.ts +57 -16
  94. package/src/astro/tabs/runtime.ts +60 -1
  95. package/src/astro/theme-posts.ts +16 -5
  96. package/src/astro/visitor.ts +67 -5
  97. package/src/constants.ts +1 -1
  98. package/src/core/a11y/audit.ts +202 -26
  99. package/src/core/arrange.ts +71 -38
  100. package/src/core/audience/rules.ts +22 -2
  101. package/src/core/canvas-styles.ts +24 -0
  102. package/src/core/clipboard.ts +11 -32
  103. package/src/core/css/generate.ts +18 -1
  104. package/src/core/css/print.ts +12 -0
  105. package/src/core/css/scope.ts +3 -3
  106. package/src/core/css-keywords.ts +83 -0
  107. package/src/core/data/bindings.ts +4 -6
  108. package/src/core/design/classes.ts +13 -15
  109. package/src/core/design/diff.ts +55 -0
  110. package/src/core/design/merge.ts +127 -0
  111. package/src/core/design/variables.ts +25 -21
  112. package/src/core/elements/dynamic-elements.ts +30 -0
  113. package/src/core/elements/form-elements.ts +20 -3
  114. package/src/core/elements/index.ts +211 -7
  115. package/src/core/forms/binding.ts +4 -13
  116. package/src/core/index.ts +10 -0
  117. package/src/core/local-style.ts +27 -0
  118. package/src/core/migrate/index.ts +9 -4
  119. package/src/core/nesting.ts +4 -23
  120. package/src/core/perf/scripts.ts +9 -6
  121. package/src/core/record.ts +3 -0
  122. package/src/core/render/context.ts +2 -0
  123. package/src/core/render/dynamic-post.ts +22 -7
  124. package/src/core/render/form.ts +145 -15
  125. package/src/core/render/index.ts +195 -14
  126. package/src/core/render/pagination.ts +21 -2
  127. package/src/core/render/vnode.ts +12 -2
  128. package/src/core/sanitize/css.ts +90 -77
  129. package/src/core/sanitize/embed-url.ts +7 -1
  130. package/src/core/sanitize/href.ts +13 -1
  131. package/src/core/sanitize/svg.ts +8 -3
  132. package/src/core/sanitize/url.ts +10 -1
  133. package/src/core/schema/descriptors.ts +4 -1
  134. package/src/core/schema/design.ts +5 -7
  135. package/src/core/schema/layout.ts +160 -181
  136. package/src/core/schema/style.ts +53 -63
  137. package/src/core/share/link.ts +72 -29
  138. package/src/core/tabs/presence.ts +7 -17
  139. package/src/core/theme/dynamic.ts +205 -39
  140. package/src/core/theme/float.ts +1 -1
  141. package/src/core/tree-ops.ts +57 -0
  142. package/src/index.ts +14 -2
  143. package/src/mcp/errors.ts +44 -0
  144. package/src/mcp/index.ts +4 -0
  145. package/src/mcp/ports.ts +78 -0
  146. package/src/mcp/prompts.ts +76 -0
  147. package/src/mcp/publish.ts +60 -0
  148. package/src/mcp/queue.ts +19 -0
  149. package/src/mcp/rate-limit.ts +80 -0
  150. package/src/mcp/read.ts +419 -0
  151. package/src/mcp/refs.ts +84 -0
  152. package/src/mcp/settings.ts +18 -0
  153. package/src/mcp/tools.ts +265 -0
  154. package/src/mcp/write.ts +582 -0
  155. package/src/server/agent-settings.ts +134 -0
  156. package/src/server/design-routes.ts +75 -18
  157. package/src/server/icon-routes.ts +72 -16
  158. package/src/server/mcp-routes.ts +265 -0
  159. package/src/server/plugin.ts +40 -4
  160. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  161. package/src/admin/editor/icons/sets/lucide.json +0 -1
  162. package/src/admin/editor/icons/sets/remix.json +0 -1
  163. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -0,0 +1,315 @@
1
+ import * as React from "react";
2
+ import type { Fetcher } from "../../api.ts";
3
+ import {
4
+ deleteUploadedIcon,
5
+ listUploadedIcons,
6
+ renameUploadedIcon,
7
+ uploadIconFile,
8
+ } from "../../icon-uploads-api.ts";
9
+ import {
10
+ ALL_ICONS,
11
+ filterIcons,
12
+ ICON_CATEGORIES,
13
+ ICON_SETS,
14
+ loadIconSet,
15
+ locateIcon,
16
+ setsFor,
17
+ uploadedIcons,
18
+ UPLOADS,
19
+ UPLOADS_CATEGORY,
20
+ type IconCategory,
21
+ type IconSetId,
22
+ type LibraryIcon,
23
+ } from "./library.ts";
24
+
25
+ export const fmt = (count: number) => count.toLocaleString("en-US");
26
+
27
+ function initialCategory(currentId: string | undefined, uploads: boolean): string {
28
+ const at = currentId ? locateIcon(currentId) : undefined;
29
+ if (!at) return ALL_ICONS;
30
+ if (at.set === UPLOADS) return uploads ? UPLOADS : ALL_ICONS;
31
+ const style = ICON_CATEGORIES.find((category) => category.id === `${at.set}/${at.style}`);
32
+ return style?.id ?? at.set;
33
+ }
34
+
35
+ /** Category, search, uploads and the keyboard cursor for the icon library. */
36
+ export function useIconLibrary({
37
+ currentId,
38
+ fetcher,
39
+ }: {
40
+ currentId: string | undefined;
41
+ fetcher?: Fetcher;
42
+ }) {
43
+ const [categoryId, setCategoryId] = React.useState(() =>
44
+ initialCategory(currentId, fetcher !== undefined),
45
+ );
46
+ const categories = React.useMemo(
47
+ () => (fetcher ? [...ICON_CATEGORIES, UPLOADS_CATEGORY] : ICON_CATEGORIES),
48
+ [fetcher],
49
+ );
50
+ const [uploads, setUploads] = React.useState<LibraryIcon[]>();
51
+ const [uploadsFailed, setUploadsFailed] = React.useState<string>();
52
+ const [uploading, setUploading] = React.useState(false);
53
+ const [uploadNote, setUploadNote] = React.useState<{ error: boolean; text: string }>();
54
+ const fileRef = React.useRef<HTMLInputElement | null>(null);
55
+ const [query, setQuery] = React.useState("");
56
+ const [selectedId, setSelectedId] = React.useState(
57
+ () => (currentId ? locateIcon(currentId)?.id : undefined) ?? currentId,
58
+ );
59
+ const [sets, setSets] = React.useState<Partial<Record<IconSetId, LibraryIcon[]>>>({});
60
+ const [failed, setFailed] = React.useState<string>();
61
+ const [attempt, setAttempt] = React.useState(0);
62
+ const gridRef = React.useRef<HTMLDivElement | null>(null);
63
+ const searchId = React.useId();
64
+
65
+ const category: IconCategory =
66
+ categories.find((item) => item.id === categoryId) ?? (ICON_CATEGORIES[0] as IconCategory);
67
+ const inUploads = category.id === UPLOADS;
68
+ const needed = inUploads ? [] : setsFor(category);
69
+ const neededKey = needed.join(",");
70
+
71
+ // My uploads loads when first needed: its category, All icons (which lists them first, W-295),
72
+ // or a stored upload to show as picked.
73
+ const inAll = category.id === ALL_ICONS;
74
+ const wantUploads =
75
+ fetcher !== undefined && (inUploads || inAll || locateIcon(currentId ?? "")?.set === UPLOADS);
76
+ React.useEffect(() => {
77
+ if (!wantUploads || !fetcher || uploads) return undefined;
78
+ let live = true;
79
+ setUploadsFailed(undefined);
80
+ listUploadedIcons(fetcher).then(
81
+ (items) => {
82
+ if (live) setUploads(uploadedIcons(items));
83
+ },
84
+ (caught: unknown) => {
85
+ if (live)
86
+ setUploadsFailed(caught instanceof Error ? caught.message : "Couldn't load uploads.");
87
+ },
88
+ );
89
+ return () => {
90
+ live = false;
91
+ };
92
+ }, [wantUploads, fetcher, uploads, attempt]);
93
+
94
+ React.useEffect(() => {
95
+ let live = true;
96
+ setFailed(undefined);
97
+ for (const id of (neededKey ? neededKey.split(",") : []) as IconSetId[]) {
98
+ loadIconSet(id).then(
99
+ (icons) => {
100
+ if (live) setSets((prev) => (prev[id] ? prev : { ...prev, [id]: icons }));
101
+ },
102
+ () => {
103
+ if (live) setFailed(ICON_SETS.find((set) => set.id === id)?.label ?? id);
104
+ },
105
+ );
106
+ }
107
+ return () => {
108
+ live = false;
109
+ };
110
+ }, [neededKey, attempt]);
111
+
112
+ // All icons waits for the uploads list too, unless it failed (the sets still show, W-295).
113
+ const uploadsSettled = !fetcher || uploads !== undefined || uploadsFailed !== undefined;
114
+ const ready = inUploads
115
+ ? uploads !== undefined
116
+ : needed.every((id) => sets[id]) && (!inAll || uploadsSettled);
117
+ const filtered = React.useMemo(
118
+ () =>
119
+ ready
120
+ ? filterIcons(
121
+ inUploads
122
+ ? (uploads ?? [])
123
+ : [...(inAll ? (uploads ?? []) : []), ...needed.flatMap((id) => sets[id] ?? [])],
124
+ category,
125
+ query,
126
+ )
127
+ : [],
128
+ // `needed` follows `category`; `ready` follows `sets` and `uploads`.
129
+ [ready, sets, uploads, category, query, inAll],
130
+ );
131
+
132
+ // Matches per sidebar entry, for the sets loaded so far (a search shows where its hits are).
133
+ const counts = React.useMemo(() => {
134
+ const loaded = Object.values(sets).flat();
135
+ const tally = new Map<string, number>();
136
+ for (const icon of filterIcons(loaded, ICON_CATEGORIES[0] as IconCategory, query)) {
137
+ tally.set(icon.set, (tally.get(icon.set) ?? 0) + 1);
138
+ tally.set(`${icon.set}/${icon.style}`, (tally.get(`${icon.set}/${icon.style}`) ?? 0) + 1);
139
+ }
140
+ if (uploads) tally.set(UPLOADS, filterIcons(uploads, UPLOADS_CATEGORY, query).length);
141
+ const allLoaded = ICON_SETS.every((set) => sets[set.id]);
142
+ if (allLoaded)
143
+ tally.set(
144
+ ALL_ICONS,
145
+ [...ICON_SETS].reduce((n, s) => n + (tally.get(s.id) ?? 0), 0) + (tally.get(UPLOADS) ?? 0),
146
+ );
147
+ return tally;
148
+ }, [sets, uploads, query]);
149
+
150
+ // The keyboard cursor belongs to one list. A new list (search, category) starts from the picked
151
+ // icon if it is in it, else nowhere, in the same render: an index left over from the last list
152
+ // would scroll this one to a tile it doesn't have.
153
+ const [cursor, setCursor] = React.useState<{ list: readonly LibraryIcon[]; index: number }>({
154
+ list: [],
155
+ index: -1,
156
+ });
157
+ const active =
158
+ cursor.list === filtered ? cursor.index : filtered.findIndex((icon) => icon.id === selectedId);
159
+ const setActive = (index: number) => setCursor({ list: filtered, index });
160
+
161
+ const selected = React.useMemo(() => {
162
+ if (!selectedId) return undefined;
163
+ for (const icons of [...Object.values(sets), uploads]) {
164
+ const found = icons?.find((icon) => icon.id === selectedId);
165
+ if (found) return found;
166
+ }
167
+ return undefined;
168
+ }, [sets, uploads, selectedId]);
169
+
170
+ const onUpload = async (file: File | undefined) => {
171
+ if (!file || !fetcher) return;
172
+ setUploading(true);
173
+ setUploadNote(undefined);
174
+ try {
175
+ const result = await uploadIconFile(fetcher, file, (svg) => {
176
+ const [probe] = uploadedIcons([{ id: "new", name: "", svg, uploadedAt: "" }]);
177
+ return uploads?.find((other) => other.markup === probe?.markup)?.id;
178
+ });
179
+ setQuery("");
180
+ setCursor({ list: [], index: -1 });
181
+ if ("existingId" in result) {
182
+ const known = uploads?.find((other) => other.id === result.existingId);
183
+ setSelectedId(result.existingId);
184
+ setUploadNote({
185
+ error: false,
186
+ text: `You already uploaded this SVG as ${known?.label ?? "an icon"}, so it's selected. Insert adds it to the page.`,
187
+ });
188
+ return;
189
+ }
190
+ const { item, imagesLeftOut } = result;
191
+ const [icon] = uploadedIcons([item]);
192
+ if (!icon) throw new Error("The uploaded SVG couldn't be shown. Try another file.");
193
+ setUploads((prev) => [icon, ...(prev ?? []).filter((other) => other.id !== icon.id)]);
194
+ setSelectedId(icon.id);
195
+ setUploadNote({
196
+ error: false,
197
+ text: `Uploaded ${icon.label}. Insert adds it to the page.${
198
+ imagesLeftOut > 0
199
+ ? ` ${imagesLeftOut} outside image${imagesLeftOut === 1 ? " was" : "s were"} left out.`
200
+ : ""
201
+ }`,
202
+ });
203
+ } catch (caught) {
204
+ setUploadNote({
205
+ error: true,
206
+ text: caught instanceof Error ? caught.message : "The upload failed. Try again.",
207
+ });
208
+ } finally {
209
+ setUploading(false);
210
+ if (fileRef.current) fileRef.current.value = "";
211
+ }
212
+ };
213
+
214
+ const activate = (index: number) => {
215
+ setActive(index);
216
+ const icon = filtered[index];
217
+ if (icon) setSelectedId(icon.id);
218
+ };
219
+
220
+ const uploadId = selected?.id.startsWith("upload:")
221
+ ? selected.id.slice("upload:".length)
222
+ : undefined;
223
+ const renameUpload = () => {
224
+ if (!fetcher || !uploadId || !selected) return;
225
+ const name = window.prompt("Rename this upload", selected.label);
226
+ if (!name || !name.trim() || name.trim() === selected.label) return;
227
+ void renameUploadedIcon(fetcher, uploadId, name.trim())
228
+ .then((item) => {
229
+ const [icon] = uploadedIcons([item]);
230
+ if (!icon) return;
231
+ setUploads((current) => current?.map((entry) => (entry.id === icon.id ? icon : entry)));
232
+ setUploadNote({
233
+ error: false,
234
+ text: `Renamed to ${icon.label}. Pages that already use it are unchanged.`,
235
+ });
236
+ })
237
+ .catch((caught: unknown) => {
238
+ setUploadNote({
239
+ error: true,
240
+ text: caught instanceof Error ? caught.message : "Couldn't rename that upload.",
241
+ });
242
+ });
243
+ };
244
+ const deleteUpload = () => {
245
+ if (!fetcher || !uploadId || !selected) return;
246
+ if (
247
+ !window.confirm(
248
+ `Remove “${selected.label}” from My uploads? Icons already on a page stay as they are.`,
249
+ )
250
+ ) {
251
+ return;
252
+ }
253
+ void deleteUploadedIcon(fetcher, uploadId)
254
+ .then(() => {
255
+ setUploads((current) => current?.filter((entry) => entry.id !== selected.id));
256
+ setSelectedId(undefined);
257
+ setUploadNote({
258
+ error: false,
259
+ text: "Removed from My uploads. Icons already placed on a page still show.",
260
+ });
261
+ })
262
+ .catch((caught: unknown) => {
263
+ setUploadNote({
264
+ error: true,
265
+ text: caught instanceof Error ? caught.message : "Couldn't remove that upload.",
266
+ });
267
+ });
268
+ };
269
+
270
+ const status = failed
271
+ ? `${failed} didn't load.`
272
+ : inUploads && uploadsFailed
273
+ ? "Uploads didn't load."
274
+ : !ready
275
+ ? "Loading icons…"
276
+ : filtered.length === 0
277
+ ? query.trim()
278
+ ? `No icons match "${query.trim()}" in ${category.label}.`
279
+ : inUploads
280
+ ? "No uploads yet."
281
+ : "No icons here."
282
+ : `${fmt(filtered.length)} icon${filtered.length === 1 ? "" : "s"}`;
283
+
284
+ return {
285
+ categories,
286
+ categoryId,
287
+ setCategoryId,
288
+ query,
289
+ setQuery,
290
+ searchId,
291
+ category,
292
+ filtered,
293
+ active,
294
+ setActive,
295
+ gridRef,
296
+ inUploads,
297
+ uploading,
298
+ fileRef,
299
+ onUpload,
300
+ uploadNote,
301
+ uploadsFailed,
302
+ setUploadsFailed,
303
+ setAttempt,
304
+ failed,
305
+ ready,
306
+ status,
307
+ counts,
308
+ selectedId,
309
+ activate,
310
+ selected,
311
+ uploadId,
312
+ renameUpload,
313
+ deleteUpload,
314
+ };
315
+ }
@@ -6,7 +6,7 @@ import {
6
6
  type Layout,
7
7
  type LayoutNode,
8
8
  } from "../../core/index.ts";
9
- import { ELEMENT_NAMES } from "./panels/ElementPanel.tsx";
9
+ import { ELEMENT_NAMES } from "./element-chrome.ts";
10
10
  import type { PaletteItem } from "./palette.ts";
11
11
 
12
12
  export type PaletteActions = {
@@ -24,13 +24,34 @@ export type PaletteActions = {
24
24
 
25
25
  const MAX_LAYERS = 400;
26
26
 
27
+ const TEXT_KEYS = [
28
+ "text",
29
+ "label",
30
+ "title",
31
+ "alt",
32
+ "name",
33
+ "summary",
34
+ "caption",
35
+ "placeholder",
36
+ ] as const;
37
+
38
+ /** Visible copy on a node, including accordion and tab labels, for Find text (W-339). */
27
39
  function textOf(node: LayoutNode): string {
28
40
  const props = node.props as Record<string, unknown>;
29
- for (const key of ["text", "label", "title", "alt", "name"]) {
41
+ const parts: string[] = [];
42
+ for (const key of TEXT_KEYS) {
30
43
  const value = props[key];
31
- if (typeof value === "string" && value.trim()) return value.trim().slice(0, 40);
44
+ if (typeof value === "string" && value.trim()) parts.push(value.trim());
32
45
  }
33
- return "";
46
+ const items = props["items"];
47
+ if (Array.isArray(items)) {
48
+ for (const item of items) {
49
+ if (item && typeof item === "object" && "text" in item && typeof item.text === "string") {
50
+ parts.push(item.text.trim());
51
+ }
52
+ }
53
+ }
54
+ return parts.join(" ").replace(/\s+/g, " ").slice(0, 240);
34
55
  }
35
56
 
36
57
  /** Every palette command for the editor's current state (W-314). */
@@ -77,10 +98,20 @@ export function paletteItems(ctx: PaletteActions): PaletteItem[] {
77
98
  id: `layer:${node.id}`,
78
99
  group: "Jump to",
79
100
  label: depth === 0 ? "Page (root)" : name,
80
- ...(text ? { hint: `“${text}”` } : {}),
101
+ ...(text ? { hint: `“${text.slice(0, 40)}”` } : {}),
81
102
  keywords: `${node.type} ${text}`,
82
103
  run: () => ctx.select(node.id),
83
104
  });
105
+ if (text && depth > 0) {
106
+ items.push({
107
+ id: `find:${node.id}`,
108
+ group: "Find text",
109
+ label: text.length > 80 ? `${text.slice(0, 77)}…` : text,
110
+ hint: name,
111
+ keywords: text,
112
+ run: () => ctx.select(node.id),
113
+ });
114
+ }
84
115
  if ("children" in node && Array.isArray(node.children)) {
85
116
  for (const child of node.children as LayoutNode[]) walk(child, depth + 1);
86
117
  }
@@ -10,7 +10,7 @@ export type PaletteItem = {
10
10
  run: () => void;
11
11
  };
12
12
 
13
- const PALETTE_GROUPS = ["Actions", "Insert", "Jump to", "Apply class"] as const;
13
+ const PALETTE_GROUPS = ["Actions", "Insert", "Jump to", "Find text", "Apply class"] as const;
14
14
  export type PaletteGroup = (typeof PALETTE_GROUPS)[number];
15
15
 
16
16
  /** Prefixes that narrow the palette to one group, like `>` for actions in code editors. */
@@ -18,16 +18,21 @@ const PREFIXES: Record<string, PaletteGroup> = {
18
18
  ">": "Actions",
19
19
  "+": "Insert",
20
20
  "@": "Jump to",
21
+ "/": "Find text",
21
22
  ".": "Apply class",
22
23
  };
23
24
 
25
+ /** W-420: accents and case don't matter, so "cafe" finds "Café" and "strasse" finds "Straße". */
26
+ const fold = (value: string) =>
27
+ value.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/ß/g, "ss");
28
+
24
29
  /**
25
30
  * How well `query` matches `text` (W-314): null when its letters don't all appear in order.
26
31
  * Higher is better: a prefix beats a word start, which beats a scattered match.
27
32
  */
28
33
  export function fuzzyScore(query: string, text: string): number | null {
29
- const q = query.trim().toLowerCase();
30
- const t = text.toLowerCase();
34
+ const q = fold(query.trim());
35
+ const t = fold(text);
31
36
  if (!q) return 0;
32
37
  if (t.startsWith(q)) return 1000 - t.length;
33
38
  const at = t.indexOf(q);
@@ -48,7 +53,7 @@ export function fuzzyScore(query: string, text: string): number | null {
48
53
 
49
54
  /**
50
55
  * The items for a query, best first, at most `limit` (W-314). An empty query lists every group
51
- * in order; a leading `>`, `+`, `@` or `.` narrows to Actions, Insert, Jump to or Apply class.
56
+ * in order; a leading `>`, `+`, `@`, `/` or `.` narrows to Actions, Insert, Jump to, Find text or Apply class.
52
57
  */
53
58
  export function filterPalette(items: PaletteItem[], raw: string, limit = 60): PaletteItem[] {
54
59
  const prefix = PREFIXES[raw.trimStart()[0] ?? ""];
@@ -1,31 +1,6 @@
1
1
  import { Input } from "@cloudflare/kumo";
2
- import {
3
- ArrowsLeftRightIcon,
4
- LinkSimpleIcon,
5
- MinusIcon,
6
- RectangleIcon,
7
- SquareIcon,
8
- SquaresFourIcon,
9
- TextAlignLeftIcon,
10
- TextHIcon,
11
- TextTIcon,
12
- ListBulletsIcon,
13
- CaretDownIcon,
14
- CursorClickIcon,
15
- ImageIcon,
16
- GraphIcon,
17
- BrowserIcon,
18
- StarIcon,
19
- YoutubeLogoIcon,
20
- TextboxIcon,
21
- CheckSquareIcon,
22
- RadioButtonIcon,
23
- PaperPlaneTiltIcon,
24
- ClipboardTextIcon,
25
- NotePencilIcon,
26
- RowsIcon,
27
- } from "@phosphor-icons/react";
28
2
  import * as React from "react";
3
+ import { elementIcon } from "../element-chrome.ts";
29
4
  import {
30
5
  ELEMENT_DESCRIPTORS,
31
6
  SECTION_RECIPES,
@@ -36,46 +11,6 @@ import { NEW_ELEMENT_MIME } from "../dnd/drop-target.ts";
36
11
  import { FIELD } from "../../ui.ts";
37
12
  import { dragStash } from "../dnd/drag-stash.ts";
38
13
 
39
- const ICONS: Record<string, typeof TextHIcon> = {
40
- container: SquareIcon,
41
- "div-block": SquareIcon,
42
- "layout-section": RowsIcon,
43
- flexbox: SquaresFourIcon,
44
- spacer: RectangleIcon,
45
- divider: MinusIcon,
46
- heading: TextHIcon,
47
- text: TextAlignLeftIcon,
48
- label: TextTIcon,
49
- link: LinkSimpleIcon,
50
- button: CursorClickIcon,
51
- list: ListBulletsIcon,
52
- image: ImageIcon,
53
- icon: StarIcon,
54
- svg: GraphIcon,
55
- tabs: BrowserIcon,
56
- accordion: ListBulletsIcon,
57
- menu: CaretDownIcon,
58
- "menu-item": CaretDownIcon,
59
- video: YoutubeLogoIcon,
60
- form: ClipboardTextIcon,
61
- "text-input": TextboxIcon,
62
- textarea: NotePencilIcon,
63
- select: TextboxIcon,
64
- checkbox: CheckSquareIcon,
65
- radio: RadioButtonIcon,
66
- submit: PaperPlaneTiltIcon,
67
- "post-title": TextHIcon,
68
- "post-excerpt": TextAlignLeftIcon,
69
- "post-content": NotePencilIcon,
70
- "post-image": ImageIcon,
71
- "post-link": LinkSimpleIcon,
72
- "post-date": TextTIcon,
73
- "post-author": TextTIcon,
74
- loop: ListBulletsIcon,
75
- "loop-empty": SquareIcon,
76
- pagination: ArrowsLeftRightIcon,
77
- };
78
-
79
14
  const GROUPS = [
80
15
  { id: "layout", label: "Layout" },
81
16
  { id: "content", label: "Content" },
@@ -130,7 +65,7 @@ export function AddPanel({
130
65
  <h3 className="emvb-add-group-title">{group.label}</h3>
131
66
  <div className="emvb-add-tiles" aria-label={group.label}>
132
67
  {tiles.map((tile) => {
133
- const Icon = ICONS[tile.type] ?? SquareIcon;
68
+ const Icon = elementIcon(tile.type);
134
69
  return (
135
70
  <button
136
71
  key={tile.type}
@@ -1,5 +1,5 @@
1
1
  import { Button, Input, Select } from "@cloudflare/kumo";
2
- import { PlusIcon, WarningCircleIcon } from "@phosphor-icons/react";
2
+ import { PlusIcon } from "@phosphor-icons/react";
3
3
  import * as React from "react";
4
4
  import {
5
5
  cleanClassName,
@@ -15,11 +15,13 @@ import {
15
15
  formatOklch,
16
16
  formatRgb,
17
17
  oklchClipped,
18
+ hexInput,
18
19
  parseHex,
19
20
  parseOklch,
20
21
  parseRgb,
21
22
  toHex,
22
23
  } from "./color-space.ts";
24
+ import { InlineError } from "./inline-error.tsx";
23
25
  import { pickerHex } from "./variable-values.ts";
24
26
 
25
27
  const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
@@ -32,15 +34,6 @@ const BAD_HEX = "Enter a hex color such as #1a2b3c.";
32
34
  const errorText = (error: unknown) =>
33
35
  error instanceof Error ? error.message : "Couldn't save site styles. Try again.";
34
36
 
35
- function InlineError({ children }: { children: string }) {
36
- return (
37
- <p className="emvb-inline-error" role="alert">
38
- <WarningCircleIcon size={16} aria-hidden="true" />
39
- {children}
40
- </p>
41
- );
42
- }
43
-
44
37
  function Swatch({ color }: { color: string }) {
45
38
  return <span className="emvb-swatch" style={{ background: color }} aria-hidden="true" />;
46
39
  }
@@ -233,15 +226,22 @@ function CustomColor({
233
226
  const [error, setError] = React.useState<{ field: Notation; message: string } | null>(null);
234
227
  const picker = React.useRef<HTMLInputElement | null>(null);
235
228
  const commit = (next: string) => {
236
- const hex = next.trim();
237
- if (hex === value || hex === "") {
229
+ const typed = next.trim();
230
+ if (typed === value || typed === "") {
238
231
  setError(null);
239
232
  return;
240
233
  }
241
- if (!HEX.test(hex)) {
234
+ const hex = hexInput(typed);
235
+ if (!hex) {
242
236
  setError({ field: "hex", message: BAD_HEX });
243
237
  return;
244
238
  }
239
+ if (hex === value) {
240
+ setError(null);
241
+ setDraft(hex);
242
+ return;
243
+ }
244
+ setDraft(hex);
245
245
  setError(null);
246
246
  onCommit(hex);
247
247
  };
@@ -387,14 +387,16 @@ function VariableValue({
387
387
  const [draft, setDraft] = React.useState(value);
388
388
  const [error, setError] = React.useState<string | null>(null);
389
389
  const commit = async () => {
390
- if (draft === value) return;
391
- if (!HEX.test(draft)) {
390
+ const hex = hexInput(draft);
391
+ if (hex === value) return;
392
+ if (!hex) {
392
393
  setError(BAD_HEX);
393
394
  return;
394
395
  }
395
396
  setError(null);
397
+ setDraft(hex);
396
398
  try {
397
- await onCommit(draft);
399
+ await onCommit(hex);
398
400
  } catch (failure) {
399
401
  setError(errorText(failure));
400
402
  }
@@ -434,11 +436,12 @@ function NewVariable({
434
436
  const [busy, setBusy] = React.useState(false);
435
437
  const create = async () => {
436
438
  if (!name.trim()) return setError("Enter a name for the variable.");
437
- if (!HEX.test(hex)) return setError(BAD_HEX);
439
+ const typed = hexInput(hex);
440
+ if (!typed) return setError(BAD_HEX);
438
441
  setError(null);
439
442
  setBusy(true);
440
443
  try {
441
- await onCreate(name.trim(), hex);
444
+ await onCreate(name.trim(), typed);
442
445
  } catch (failure) {
443
446
  setError(errorText(failure));
444
447
  setBusy(false);