@perkyzz/emvb 0.2.1 → 0.4.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 (150) hide show
  1. package/README.md +4 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +3 -1
  4. package/src/admin/access/role.ts +9 -3
  5. package/src/admin/api.ts +17 -7
  6. package/src/admin/content-api.ts +7 -51
  7. package/src/admin/content-item.ts +22 -0
  8. package/src/admin/design-api.ts +30 -0
  9. package/src/admin/editor/A11yCopilot.tsx +126 -0
  10. package/src/admin/editor/CommandPalette.tsx +118 -0
  11. package/src/admin/editor/Editor.tsx +188 -152
  12. package/src/admin/editor/EditorOverlay.tsx +9 -1
  13. package/src/admin/editor/PerfMeter.tsx +121 -0
  14. package/src/admin/editor/ShareLink.tsx +164 -0
  15. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  16. package/src/admin/editor/Timeline.tsx +287 -0
  17. package/src/admin/editor/TopBar.tsx +4 -0
  18. package/src/admin/editor/canvas/CanvasFrame.tsx +62 -370
  19. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  20. package/src/admin/editor/canvas/SelectionOverlay.tsx +87 -47
  21. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  22. package/src/admin/editor/canvas/drop-line.ts +24 -0
  23. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  24. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  25. package/src/admin/editor/collection-previews.ts +114 -0
  26. package/src/admin/editor/editor-chrome.tsx +346 -0
  27. package/src/admin/editor/editor-commands.ts +360 -0
  28. package/src/admin/editor/editor-css.ts +5 -3
  29. package/src/admin/editor/element-chrome.ts +89 -0
  30. package/src/admin/editor/feature-css.ts +105 -0
  31. package/src/admin/editor/host.ts +35 -0
  32. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  33. package/src/admin/editor/icons/library.ts +29 -19
  34. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  35. package/src/admin/editor/live-data.tsx +71 -0
  36. package/src/admin/editor/palette-items.ts +136 -0
  37. package/src/admin/editor/palette.ts +68 -0
  38. package/src/admin/editor/panels/AddPanel.tsx +48 -68
  39. package/src/admin/editor/panels/ClassesSection.tsx +5 -1
  40. package/src/admin/editor/panels/ColorControl.tsx +2 -10
  41. package/src/admin/editor/panels/ElementPanel.tsx +74 -102
  42. package/src/admin/editor/panels/LayersPanel.tsx +72 -63
  43. package/src/admin/editor/panels/LeftPanel.tsx +4 -1
  44. package/src/admin/editor/panels/SettingsPanel.tsx +13 -0
  45. package/src/admin/editor/panels/SiteStylesDrawer.tsx +18 -10
  46. package/src/admin/editor/panels/TokenScales.tsx +168 -0
  47. package/src/admin/editor/panels/VariableSection.tsx +10 -14
  48. package/src/admin/editor/panels/inline-error.tsx +11 -0
  49. package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
  50. package/src/admin/editor/panels/settings/AudienceEditor.tsx +285 -0
  51. package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
  52. package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
  53. package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
  54. package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
  55. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  56. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  57. package/src/admin/editor/panels/settings/MotionControl.tsx +252 -0
  58. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  59. package/src/admin/editor/panels/settings/StyleRow.tsx +26 -2
  60. package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
  61. package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
  62. package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
  63. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  64. package/src/admin/editor/panels/settings/length-units.ts +16 -5
  65. package/src/admin/editor/panels/settings/style-sections.ts +7 -2
  66. package/src/admin/editor/panels/style-target.ts +105 -0
  67. package/src/admin/editor/section-templates.ts +43 -21
  68. package/src/admin/editor/shortcuts.ts +6 -1
  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 +30 -14
  74. package/src/admin/editor/useNodeActions.ts +44 -16
  75. package/src/admin/forms-api.ts +17 -6
  76. package/src/admin/icon-uploads-api.ts +18 -0
  77. package/src/admin/theme-api.ts +5 -18
  78. package/src/admin/ui.ts +4 -4
  79. package/src/astro/content-port.ts +24 -0
  80. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  81. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  82. package/src/astro/forms/client.ts +1 -0
  83. package/src/astro/forms-definitions.ts +24 -11
  84. package/src/astro/index.ts +1 -0
  85. package/src/astro/render-session.ts +85 -0
  86. package/src/astro/request-data.ts +109 -0
  87. package/src/astro/resolve-theme.ts +184 -64
  88. package/src/astro/resolve.ts +63 -16
  89. package/src/astro/theme-posts.ts +48 -5
  90. package/src/astro/visitor.ts +204 -0
  91. package/src/constants.ts +1 -1
  92. package/src/core/a11y/audit.ts +282 -0
  93. package/src/core/arrange.ts +150 -34
  94. package/src/core/audience/rules.ts +124 -0
  95. package/src/core/audience/variants.ts +51 -0
  96. package/src/core/canvas-styles.ts +24 -0
  97. package/src/core/clipboard.ts +11 -32
  98. package/src/core/css/generate.ts +29 -2
  99. package/src/core/css/print.ts +12 -0
  100. package/src/core/css/scope.ts +3 -3
  101. package/src/core/css/trace.ts +169 -0
  102. package/src/core/css-keywords.ts +83 -0
  103. package/src/core/data/bindings.ts +255 -0
  104. package/src/core/design/classes.ts +13 -15
  105. package/src/core/design/diff.ts +55 -0
  106. package/src/core/design/merge.ts +127 -0
  107. package/src/core/design/tokens.ts +127 -0
  108. package/src/core/design/variables.ts +25 -21
  109. package/src/core/elements/dynamic-elements.ts +117 -2
  110. package/src/core/elements/form-elements.ts +1 -0
  111. package/src/core/elements/index.ts +185 -7
  112. package/src/core/forms/binding.ts +4 -13
  113. package/src/core/history/diff.ts +152 -0
  114. package/src/core/index.ts +121 -0
  115. package/src/core/local-style.ts +27 -0
  116. package/src/core/migrate/index.ts +12 -4
  117. package/src/core/nesting.ts +4 -22
  118. package/src/core/perf/meter.ts +160 -0
  119. package/src/core/perf/scripts.ts +61 -0
  120. package/src/core/recipes/index.ts +433 -0
  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 +1 -2
  124. package/src/core/render/form.ts +133 -10
  125. package/src/core/render/index.ts +206 -17
  126. package/src/core/render/loop.ts +54 -7
  127. package/src/core/render/pagination.ts +9 -1
  128. package/src/core/render/vnode.ts +12 -2
  129. package/src/core/sanitize/css.ts +129 -80
  130. package/src/core/sanitize/motion.ts +129 -0
  131. package/src/core/sanitize/svg.ts +8 -3
  132. package/src/core/sanitize/url.ts +10 -1
  133. package/src/core/schema/design.ts +29 -8
  134. package/src/core/schema/layout.ts +291 -169
  135. package/src/core/schema/motion.ts +14 -0
  136. package/src/core/schema/style.ts +101 -66
  137. package/src/core/share/link.ts +187 -0
  138. package/src/core/tabs/presence.ts +7 -17
  139. package/src/core/theme/dynamic.ts +242 -32
  140. package/src/core/theme/float.ts +1 -1
  141. package/src/core/theme/pagination.ts +56 -0
  142. package/src/core/tree-ops.ts +57 -0
  143. package/src/index.ts +14 -2
  144. package/src/server/design-routes.ts +4 -1
  145. package/src/server/icon-routes.ts +68 -16
  146. package/src/server/plugin.ts +8 -2
  147. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  148. package/src/admin/editor/icons/sets/lucide.json +0 -1
  149. package/src/admin/editor/icons/sets/remix.json +0 -1
  150. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -0,0 +1,71 @@
1
+ import * as React from "react";
2
+ import { siteBindingValues } from "../../core/index.ts";
3
+ import { readEnvelope, type Fetcher } from "../api.ts";
4
+
5
+ /**
6
+ * Live values for bound fields on the canvas (W-307): the site's settings, read once, and the
7
+ * URL parameters the editor previews with (`?plan=pro`), which only exist in the editor.
8
+ */
9
+ type LiveData = {
10
+ site: Readonly<Record<string, string>>;
11
+ params: Readonly<Record<string, string>>;
12
+ /** The preview query as typed, e.g. `plan=pro&utm_source=mail`. */
13
+ query: string;
14
+ setQuery: (query: string) => void;
15
+ };
16
+
17
+ const EMPTY: LiveData = { site: {}, params: {}, query: "", setQuery: () => undefined };
18
+
19
+ export const LiveDataContext = React.createContext<LiveData>(EMPTY);
20
+
21
+ export const useLiveData = () => React.useContext(LiveDataContext);
22
+
23
+ /**
24
+ * The site's origin while editing (W-307): the EmDash admin runs on the site itself, so a
25
+ * URL-parameter link to this origin counts as same-site on the canvas too.
26
+ */
27
+ export const siteOrigin = (): string | undefined => globalThis.location?.origin || undefined;
28
+
29
+ /** `a=1&b=two` (a leading `?` is fine) as a record, first value per name. */
30
+ function previewParams(query: string): Record<string, string> {
31
+ const params: Record<string, string> = {};
32
+ const search = new URLSearchParams(query.trim().replace(/^\?/, ""));
33
+ for (const [name, value] of search) if (!Object.hasOwn(params, name)) params[name] = value;
34
+ return params;
35
+ }
36
+
37
+ /** The site's settings as binding values; empty when the role can't read them. */
38
+ function useSiteSettings(fetcher: Fetcher): Record<string, string> {
39
+ const [site, setSite] = React.useState<Record<string, string>>({});
40
+ React.useEffect(() => {
41
+ let cancelled = false;
42
+ fetcher("/_emdash/api/settings")
43
+ .then(async (response) => {
44
+ if (!response.ok) return;
45
+ const body = await readEnvelope<unknown>(response);
46
+ if (!cancelled) setSite(siteBindingValues(body.data));
47
+ })
48
+ .catch(() => undefined);
49
+ return () => {
50
+ cancelled = true;
51
+ };
52
+ }, [fetcher]);
53
+ return site;
54
+ }
55
+
56
+ /** Provides live data to the editor. */
57
+ export function LiveDataProvider({
58
+ fetcher,
59
+ children,
60
+ }: {
61
+ fetcher: Fetcher;
62
+ children: React.ReactNode;
63
+ }) {
64
+ const site = useSiteSettings(fetcher);
65
+ const [query, setQuery] = React.useState("");
66
+ const value = React.useMemo(
67
+ () => ({ site, params: previewParams(query), query, setQuery }),
68
+ [site, query],
69
+ );
70
+ return <LiveDataContext.Provider value={value}>{children}</LiveDataContext.Provider>;
71
+ }
@@ -0,0 +1,136 @@
1
+ import {
2
+ ELEMENT_DESCRIPTORS,
3
+ SECTION_RECIPES,
4
+ type DesignSystem,
5
+ type ElementType,
6
+ type Layout,
7
+ type LayoutNode,
8
+ } from "../../core/index.ts";
9
+ import { ELEMENT_NAMES } from "./element-chrome.ts";
10
+ import type { PaletteItem } from "./palette.ts";
11
+
12
+ export type PaletteActions = {
13
+ layout: Layout | null;
14
+ design: DesignSystem;
15
+ selected: LayoutNode | null;
16
+ formsAvailable: boolean;
17
+ insert: (type: ElementType) => void;
18
+ /** Adds a section recipe (W-320). */
19
+ insertRecipe?: (id: string) => void;
20
+ select: (id: string) => void;
21
+ applyClass: (nodeId: string, classId: string) => void;
22
+ actions: { id: string; label: string; hint?: string; keywords?: string; run: () => void }[];
23
+ };
24
+
25
+ const MAX_LAYERS = 400;
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). */
39
+ function textOf(node: LayoutNode): string {
40
+ const props = node.props as Record<string, unknown>;
41
+ const parts: string[] = [];
42
+ for (const key of TEXT_KEYS) {
43
+ const value = props[key];
44
+ if (typeof value === "string" && value.trim()) parts.push(value.trim());
45
+ }
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);
55
+ }
56
+
57
+ /** Every palette command for the editor's current state (W-314). */
58
+ export function paletteItems(ctx: PaletteActions): PaletteItem[] {
59
+ const items: PaletteItem[] = ctx.actions.map((action) => ({
60
+ id: `action:${action.id}`,
61
+ group: "Actions",
62
+ label: action.label,
63
+ ...(action.hint ? { hint: action.hint } : {}),
64
+ ...(action.keywords ? { keywords: action.keywords } : {}),
65
+ run: action.run,
66
+ }));
67
+ for (const descriptor of ELEMENT_DESCRIPTORS) {
68
+ if (descriptor.type === "form" && !ctx.formsAvailable) continue;
69
+ items.push({
70
+ id: `insert:${descriptor.type}`,
71
+ group: "Insert",
72
+ label: `Insert ${descriptor.name}`,
73
+ keywords: `${descriptor.type} ${descriptor.group}`,
74
+ run: () => ctx.insert(descriptor.type as ElementType),
75
+ });
76
+ }
77
+ const insertRecipe = ctx.insertRecipe;
78
+ if (insertRecipe && ctx.layout) {
79
+ for (const recipe of SECTION_RECIPES) {
80
+ items.push({
81
+ id: `recipe:${recipe.id}`,
82
+ group: "Insert",
83
+ label: `Insert ${recipe.name} section`,
84
+ hint: "Recipe",
85
+ keywords: `recipe section block template ${recipe.description}`,
86
+ run: () => insertRecipe(recipe.id),
87
+ });
88
+ }
89
+ }
90
+ if (ctx.layout) {
91
+ let count = 0;
92
+ const walk = (node: LayoutNode, depth: number): void => {
93
+ if (count >= MAX_LAYERS) return;
94
+ count += 1;
95
+ const name = node.label || ELEMENT_NAMES[node.type] || node.type;
96
+ const text = textOf(node);
97
+ items.push({
98
+ id: `layer:${node.id}`,
99
+ group: "Jump to",
100
+ label: depth === 0 ? "Page (root)" : name,
101
+ ...(text ? { hint: `“${text.slice(0, 40)}”` } : {}),
102
+ keywords: `${node.type} ${text}`,
103
+ run: () => ctx.select(node.id),
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
+ }
115
+ if ("children" in node && Array.isArray(node.children)) {
116
+ for (const child of node.children as LayoutNode[]) walk(child, depth + 1);
117
+ }
118
+ };
119
+ walk(ctx.layout.root, 0);
120
+ }
121
+ const selected = ctx.selected;
122
+ if (selected) {
123
+ for (const cls of ctx.design.classes ?? []) {
124
+ if (selected.classes?.includes(cls.id)) continue;
125
+ items.push({
126
+ id: `class:${cls.id}`,
127
+ group: "Apply class",
128
+ label: `Apply .${cls.name}`,
129
+ hint: `to ${selected.label || ELEMENT_NAMES[selected.type] || selected.type}`,
130
+ keywords: cls.id,
131
+ run: () => ctx.applyClass(selected.id, cls.id),
132
+ });
133
+ }
134
+ }
135
+ return items;
136
+ }
@@ -0,0 +1,68 @@
1
+ /** One command in the Ctrl/Cmd+K palette (W-314). */
2
+ export type PaletteItem = {
3
+ id: string;
4
+ group: PaletteGroup;
5
+ label: string;
6
+ /** Shown to the right: a shortcut, an element type, a text preview. */
7
+ hint?: string;
8
+ /** Extra words that should find this item. */
9
+ keywords?: string;
10
+ run: () => void;
11
+ };
12
+
13
+ const PALETTE_GROUPS = ["Actions", "Insert", "Jump to", "Find text", "Apply class"] as const;
14
+ export type PaletteGroup = (typeof PALETTE_GROUPS)[number];
15
+
16
+ /** Prefixes that narrow the palette to one group, like `>` for actions in code editors. */
17
+ const PREFIXES: Record<string, PaletteGroup> = {
18
+ ">": "Actions",
19
+ "+": "Insert",
20
+ "@": "Jump to",
21
+ "/": "Find text",
22
+ ".": "Apply class",
23
+ };
24
+
25
+ /**
26
+ * How well `query` matches `text` (W-314): null when its letters don't all appear in order.
27
+ * Higher is better: a prefix beats a word start, which beats a scattered match.
28
+ */
29
+ export function fuzzyScore(query: string, text: string): number | null {
30
+ const q = query.trim().toLowerCase();
31
+ const t = text.toLowerCase();
32
+ if (!q) return 0;
33
+ if (t.startsWith(q)) return 1000 - t.length;
34
+ const at = t.indexOf(q);
35
+ if (at >= 0) return (/[\s\-_/.]/.test(t[at - 1] ?? " ") ? 800 : 600) - at - t.length / 100;
36
+ let score = 0;
37
+ let from = 0;
38
+ let previous = -2;
39
+ for (const ch of q) {
40
+ if (ch === " ") continue;
41
+ const found = t.indexOf(ch, from);
42
+ if (found < 0) return null;
43
+ score += found === previous + 1 ? 6 : /[\s\-_/.]/.test(t[found - 1] ?? " ") ? 4 : 1;
44
+ previous = found;
45
+ from = found + 1;
46
+ }
47
+ return score - t.length / 100;
48
+ }
49
+
50
+ /**
51
+ * The items for a query, best first, at most `limit` (W-314). An empty query lists every group
52
+ * in order; a leading `>`, `+`, `@`, `/` or `.` narrows to Actions, Insert, Jump to, Find text or Apply class.
53
+ */
54
+ export function filterPalette(items: PaletteItem[], raw: string, limit = 60): PaletteItem[] {
55
+ const prefix = PREFIXES[raw.trimStart()[0] ?? ""];
56
+ const query = prefix ? raw.trimStart().slice(1) : raw;
57
+ const pool = prefix ? items.filter((item) => item.group === prefix) : items;
58
+ if (!query.trim()) return pool.slice(0, limit);
59
+ const scored: { item: PaletteItem; score: number }[] = [];
60
+ for (const item of pool) {
61
+ const label = fuzzyScore(query, item.label);
62
+ const extra = item.keywords ? fuzzyScore(query, item.keywords) : null;
63
+ const best = Math.max(label ?? -Infinity, extra === null ? -Infinity : extra - 50);
64
+ if (best > -Infinity) scored.push({ item, score: best });
65
+ }
66
+ scored.sort((a, b) => b.score - a.score);
67
+ return scored.slice(0, limit).map((s) => s.item);
68
+ }
@@ -1,75 +1,16 @@
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";
29
- import { ELEMENT_DESCRIPTORS, type ElementType } from "../../../core/index.ts";
3
+ import { elementIcon } from "../element-chrome.ts";
4
+ import {
5
+ ELEMENT_DESCRIPTORS,
6
+ SECTION_RECIPES,
7
+ typeMayAddScript,
8
+ type ElementType,
9
+ } from "../../../core/index.ts";
30
10
  import { NEW_ELEMENT_MIME } from "../dnd/drop-target.ts";
31
11
  import { FIELD } from "../../ui.ts";
32
12
  import { dragStash } from "../dnd/drag-stash.ts";
33
13
 
34
- const ICONS: Record<string, typeof TextHIcon> = {
35
- container: SquareIcon,
36
- "div-block": SquareIcon,
37
- "layout-section": RowsIcon,
38
- flexbox: SquaresFourIcon,
39
- spacer: RectangleIcon,
40
- divider: MinusIcon,
41
- heading: TextHIcon,
42
- text: TextAlignLeftIcon,
43
- label: TextTIcon,
44
- link: LinkSimpleIcon,
45
- button: CursorClickIcon,
46
- list: ListBulletsIcon,
47
- image: ImageIcon,
48
- icon: StarIcon,
49
- svg: GraphIcon,
50
- tabs: BrowserIcon,
51
- accordion: ListBulletsIcon,
52
- menu: CaretDownIcon,
53
- "menu-item": CaretDownIcon,
54
- video: YoutubeLogoIcon,
55
- form: ClipboardTextIcon,
56
- "text-input": TextboxIcon,
57
- textarea: NotePencilIcon,
58
- select: TextboxIcon,
59
- checkbox: CheckSquareIcon,
60
- radio: RadioButtonIcon,
61
- submit: PaperPlaneTiltIcon,
62
- "post-title": TextHIcon,
63
- "post-excerpt": TextAlignLeftIcon,
64
- "post-content": NotePencilIcon,
65
- "post-image": ImageIcon,
66
- "post-link": LinkSimpleIcon,
67
- "post-date": TextTIcon,
68
- "post-author": TextTIcon,
69
- loop: ListBulletsIcon,
70
- pagination: ArrowsLeftRightIcon,
71
- };
72
-
73
14
  const GROUPS = [
74
15
  { id: "layout", label: "Layout" },
75
16
  { id: "content", label: "Content" },
@@ -79,10 +20,13 @@ const GROUPS = [
79
20
 
80
21
  export function AddPanel({
81
22
  onAdd,
23
+ onRecipe,
82
24
  defaultQuery = "",
83
25
  formsAvailable = true,
84
26
  }: {
85
27
  onAdd: (type: ElementType) => void;
28
+ /** Adds a section recipe (W-320); without it, recipes are not offered. */
29
+ onRecipe?: (id: string) => void;
86
30
  /** Test-only initial search string. */
87
31
  defaultQuery?: string;
88
32
  /** Hide the Form group when the forms plugin is missing (W-036). */
@@ -96,6 +40,11 @@ export function AddPanel({
96
40
  (formsAvailable || d.group !== "form") &&
97
41
  (!q || d.name.toLowerCase().includes(q)),
98
42
  );
43
+ const recipes = onRecipe
44
+ ? SECTION_RECIPES.filter(
45
+ (r) => !q || `${r.name} ${r.description} recipe section`.toLowerCase().includes(q),
46
+ )
47
+ : [];
99
48
  return (
100
49
  <div className="emvb-panel-body" data-emvb-panel="add">
101
50
  <Input
@@ -105,7 +54,7 @@ export function AddPanel({
105
54
  onChange={(event) => setQuery(event.target.value)}
106
55
  placeholder="Search elements"
107
56
  />
108
- {matched.length === 0 ? (
57
+ {matched.length === 0 && recipes.length === 0 ? (
109
58
  <p className="emvb-helper">No elements match &quot;{query.trim()}&quot;.</p>
110
59
  ) : (
111
60
  GROUPS.map((group) => {
@@ -116,7 +65,7 @@ export function AddPanel({
116
65
  <h3 className="emvb-add-group-title">{group.label}</h3>
117
66
  <div className="emvb-add-tiles" aria-label={group.label}>
118
67
  {tiles.map((tile) => {
119
- const Icon = ICONS[tile.type] ?? SquareIcon;
68
+ const Icon = elementIcon(tile.type);
120
69
  return (
121
70
  <button
122
71
  key={tile.type}
@@ -133,6 +82,15 @@ export function AddPanel({
133
82
  >
134
83
  <Icon size={20} aria-hidden="true" />
135
84
  <span>{tile.name}</span>
85
+ {typeMayAddScript(tile.type) && (
86
+ <span
87
+ className="emvb-js-badge"
88
+ title="Adds a small script to the page; everything else is zero-JS"
89
+ aria-hidden="true"
90
+ >
91
+ JS
92
+ </span>
93
+ )}
136
94
  </button>
137
95
  );
138
96
  })}
@@ -141,6 +99,28 @@ export function AddPanel({
141
99
  );
142
100
  })
143
101
  )}
102
+ {onRecipe && recipes.length > 0 && (
103
+ <div className="emvb-add-group" data-emvb-recipes="">
104
+ <h3 className="emvb-add-group-title">Section recipes</h3>
105
+ <p className="emvb-helper">
106
+ Whole sections that use your Site styles colours, sizes and classes.
107
+ </p>
108
+ <div className="emvb-recipe-list" aria-label="Section recipes">
109
+ {recipes.map((recipe) => (
110
+ <button
111
+ key={recipe.id}
112
+ type="button"
113
+ className="emvb-recipe-tile"
114
+ data-emvb-recipe={recipe.id}
115
+ onClick={() => onRecipe(recipe.id)}
116
+ >
117
+ <span className="emvb-recipe-name">{recipe.name}</span>
118
+ <span className="emvb-recipe-desc">{recipe.description}</span>
119
+ </button>
120
+ ))}
121
+ </div>
122
+ </div>
123
+ )}
144
124
  </div>
145
125
  );
146
126
  }
@@ -70,7 +70,11 @@ function classKeys(
70
70
  state === "normal"
71
71
  ? withFit
72
72
  : withFit.filter(
73
- (key) => key !== "transition" && key !== "entrance" && key !== "iconAnimation",
73
+ (key) =>
74
+ key !== "transition" &&
75
+ key !== "entrance" &&
76
+ key !== "iconAnimation" &&
77
+ key !== "scrollMotion",
74
78
  )
75
79
  ) as StyleKey[];
76
80
  }
@@ -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,
@@ -20,6 +20,7 @@ import {
20
20
  parseRgb,
21
21
  toHex,
22
22
  } from "./color-space.ts";
23
+ import { InlineError } from "./inline-error.tsx";
23
24
  import { pickerHex } from "./variable-values.ts";
24
25
 
25
26
  const HEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
@@ -32,15 +33,6 @@ const BAD_HEX = "Enter a hex color such as #1a2b3c.";
32
33
  const errorText = (error: unknown) =>
33
34
  error instanceof Error ? error.message : "Couldn't save site styles. Try again.";
34
35
 
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
36
  function Swatch({ color }: { color: string }) {
45
37
  return <span className="emvb-swatch" style={{ background: color }} aria-hidden="true" />;
46
38
  }