@perkyzz/emvb 0.3.0 → 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 (121) 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 +1 -1
  10. package/src/admin/editor/Editor.tsx +106 -332
  11. package/src/admin/editor/EditorOverlay.tsx +3 -1
  12. package/src/admin/editor/PerfMeter.tsx +1 -1
  13. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  14. package/src/admin/editor/Timeline.tsx +16 -3
  15. package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
  16. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  17. package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
  18. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  19. package/src/admin/editor/canvas/drop-line.ts +24 -0
  20. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  21. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  22. package/src/admin/editor/collection-previews.ts +28 -5
  23. package/src/admin/editor/editor-chrome.tsx +346 -0
  24. package/src/admin/editor/editor-commands.ts +360 -0
  25. package/src/admin/editor/element-chrome.ts +89 -0
  26. package/src/admin/editor/feature-css.ts +15 -15
  27. package/src/admin/editor/host.ts +33 -0
  28. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  29. package/src/admin/editor/icons/library.ts +29 -19
  30. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  31. package/src/admin/editor/palette-items.ts +36 -5
  32. package/src/admin/editor/palette.ts +3 -2
  33. package/src/admin/editor/panels/AddPanel.tsx +2 -67
  34. package/src/admin/editor/panels/ColorControl.tsx +2 -10
  35. package/src/admin/editor/panels/ElementPanel.tsx +40 -99
  36. package/src/admin/editor/panels/LayersPanel.tsx +34 -62
  37. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  38. package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
  39. package/src/admin/editor/panels/VariableSection.tsx +1 -10
  40. package/src/admin/editor/panels/inline-error.tsx +11 -0
  41. package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
  42. package/src/admin/editor/panels/settings/AudienceEditor.tsx +73 -3
  43. package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
  44. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  45. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  46. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
  47. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  48. package/src/admin/editor/panels/settings/length-units.ts +15 -4
  49. package/src/admin/editor/panels/settings/style-sections.ts +5 -1
  50. package/src/admin/editor/panels/style-target.ts +105 -0
  51. package/src/admin/editor/section-templates.ts +43 -21
  52. package/src/admin/editor/shortcuts.ts +4 -0
  53. package/src/admin/editor/store.ts +10 -1
  54. package/src/admin/editor/useClipboardActions.ts +1 -1
  55. package/src/admin/editor/useEditorCommands.ts +61 -13
  56. package/src/admin/editor/useEditorData.ts +7 -1
  57. package/src/admin/editor/useEditorShortcuts.ts +23 -15
  58. package/src/admin/editor/useNodeActions.ts +6 -1
  59. package/src/admin/forms-api.ts +17 -6
  60. package/src/admin/icon-uploads-api.ts +18 -0
  61. package/src/admin/theme-api.ts +5 -18
  62. package/src/astro/content-port.ts +24 -0
  63. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  64. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  65. package/src/astro/forms/client.ts +1 -0
  66. package/src/astro/forms-definitions.ts +24 -11
  67. package/src/astro/index.ts +1 -0
  68. package/src/astro/render-session.ts +85 -0
  69. package/src/astro/request-data.ts +20 -8
  70. package/src/astro/resolve-theme.ts +166 -76
  71. package/src/astro/resolve.ts +57 -16
  72. package/src/astro/theme-posts.ts +16 -5
  73. package/src/astro/visitor.ts +67 -5
  74. package/src/constants.ts +1 -1
  75. package/src/core/arrange.ts +63 -38
  76. package/src/core/audience/rules.ts +22 -2
  77. package/src/core/canvas-styles.ts +24 -0
  78. package/src/core/clipboard.ts +11 -32
  79. package/src/core/css/generate.ts +9 -0
  80. package/src/core/css/print.ts +12 -0
  81. package/src/core/css/scope.ts +3 -3
  82. package/src/core/css-keywords.ts +83 -0
  83. package/src/core/data/bindings.ts +4 -6
  84. package/src/core/design/classes.ts +13 -15
  85. package/src/core/design/diff.ts +55 -0
  86. package/src/core/design/merge.ts +127 -0
  87. package/src/core/design/variables.ts +25 -21
  88. package/src/core/elements/dynamic-elements.ts +30 -0
  89. package/src/core/elements/form-elements.ts +1 -0
  90. package/src/core/elements/index.ts +183 -7
  91. package/src/core/forms/binding.ts +4 -13
  92. package/src/core/index.ts +10 -0
  93. package/src/core/local-style.ts +27 -0
  94. package/src/core/migrate/index.ts +9 -4
  95. package/src/core/nesting.ts +4 -23
  96. package/src/core/perf/scripts.ts +9 -6
  97. package/src/core/record.ts +3 -0
  98. package/src/core/render/context.ts +2 -0
  99. package/src/core/render/dynamic-post.ts +1 -2
  100. package/src/core/render/form.ts +133 -10
  101. package/src/core/render/index.ts +155 -13
  102. package/src/core/render/vnode.ts +12 -2
  103. package/src/core/sanitize/css.ts +90 -77
  104. package/src/core/sanitize/svg.ts +8 -3
  105. package/src/core/sanitize/url.ts +10 -1
  106. package/src/core/schema/design.ts +5 -7
  107. package/src/core/schema/layout.ts +153 -181
  108. package/src/core/schema/style.ts +53 -63
  109. package/src/core/share/link.ts +68 -28
  110. package/src/core/tabs/presence.ts +7 -17
  111. package/src/core/theme/dynamic.ts +200 -39
  112. package/src/core/theme/float.ts +1 -1
  113. package/src/core/tree-ops.ts +57 -0
  114. package/src/index.ts +14 -2
  115. package/src/server/design-routes.ts +4 -1
  116. package/src/server/icon-routes.ts +68 -16
  117. package/src/server/plugin.ts +8 -2
  118. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  119. package/src/admin/editor/icons/sets/lucide.json +0 -1
  120. package/src/admin/editor/icons/sets/remix.json +0 -1
  121. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -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,6 +18,7 @@ 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
 
@@ -48,7 +49,7 @@ export function fuzzyScore(query: string, text: string): number | null {
48
49
 
49
50
  /**
50
51
  * 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.
52
+ * in order; a leading `>`, `+`, `@`, `/` or `.` narrows to Actions, Insert, Jump to, Find text or Apply class.
52
53
  */
53
54
  export function filterPalette(items: PaletteItem[], raw: string, limit = 60): PaletteItem[] {
54
55
  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,
@@ -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
  }
@@ -3,23 +3,13 @@ import type { Fetcher } from "../../api.ts";
3
3
  import {
4
4
  CaretDownIcon,
5
5
  CaretRightIcon,
6
- CheckSquareIcon,
7
- ClipboardTextIcon,
8
- ImageIcon,
9
- NotePencilIcon,
10
6
  PaintBrushIcon,
11
- PaperPlaneTiltIcon,
12
7
  PencilSimpleIcon,
13
- RadioButtonIcon,
14
- RowsIcon,
15
- SquaresFourIcon,
16
- StarIcon,
17
- TextHIcon,
18
- TextboxIcon,
19
8
  WarningCircleIcon,
20
- YoutubeLogoIcon,
21
9
  } from "@phosphor-icons/react";
22
10
  import * as React from "react";
11
+ import { ELEMENT_NAMES, elementIcon } from "../element-chrome.ts";
12
+ import { indexLayout } from "../../../core/tree-ops.ts";
23
13
  import type { ThemePartType } from "../../../core/theme/part-types.ts";
24
14
  import { sharedPartH1 } from "./settings/heading-warning.ts";
25
15
  import { UNNAMED_BOX_LINK_NOTE, unnamedBoxLink } from "./settings/box-link-name.ts";
@@ -31,24 +21,16 @@ import { duplicateFieldName } from "./settings/form-names.ts";
31
21
  import { hasItemList, ItemList, type ItemActions } from "./settings/ItemList.tsx";
32
22
  import {
33
23
  ELEMENT_DESCRIPTORS,
34
- findNode,
35
24
  hasLocalStyles,
36
25
  localStylesToClass,
37
26
  localToClassRefusal,
38
27
  isFormNode,
39
- parentOf,
40
28
  type DesignSystem,
41
29
  type ElementDescriptor,
42
30
  type Layout,
43
31
  type Arranged,
44
32
  inheritedStyle,
45
33
  type LayoutNode,
46
- patchClassDevices,
47
- patchClassState,
48
- patchClassStyle,
49
- patchDeviceStyle,
50
- patchStates,
51
- type DeviceStyles,
52
34
  type PopupDevice,
53
35
  type ResponsiveDevice,
54
36
  classStylesInListOrder,
@@ -60,6 +42,7 @@ import {
60
42
  type StyleProps,
61
43
  type StyleStates,
62
44
  } from "../../../core/index.ts";
45
+ import { applyStylePatch } from "./style-target.ts";
63
46
  import { FieldControl } from "./settings/FieldControl.tsx";
64
47
  import { BindingsEditor } from "./settings/BindingsEditor.tsx";
65
48
  import { VariantEditor } from "./settings/VariantEditor.tsx";
@@ -69,7 +52,12 @@ import { BoxControl } from "./settings/BoxControl.tsx";
69
52
  import { boxGroupOf } from "./settings/box-sides.ts";
70
53
  import { IconShapeRow, IconSingleColorRow } from "./settings/IconControls.tsx";
71
54
  import { StyleRow } from "./settings/StyleRow.tsx";
72
- import { AttributesEditor, HtmlIdField } from "./settings/AdvancedFields.tsx";
55
+ import {
56
+ AttributesEditor,
57
+ ContainerQueryFields,
58
+ DirectionField,
59
+ HtmlIdField,
60
+ } from "./settings/AdvancedFields.tsx";
73
61
  import { ClassChipInput } from "./settings/ClassChipInput.tsx";
74
62
  import { StateDot, StateSwitcher, type StyleStateChoice } from "./settings/StateSwitcher.tsx";
75
63
  import {
@@ -83,60 +71,17 @@ import {
83
71
  type StyleSectionId,
84
72
  } from "./settings/style-sections.ts";
85
73
 
86
- export const ELEMENT_NAMES: Record<string, string> = Object.fromEntries(
87
- ELEMENT_DESCRIPTORS.map((d) => [d.type, d.name]),
88
- );
89
-
90
74
  const enclosingFormId = (layout: Layout, nodeId: string): string | undefined => {
91
- let current = parentOf(layout, nodeId);
75
+ const index = indexLayout(layout);
76
+ let current = index.parentOf.get(nodeId);
92
77
  while (current) {
93
- const node = findNode(layout, current);
78
+ const node = index.byId.get(current);
94
79
  if (node && isFormNode(node)) return node.props.formId || undefined;
95
- current = parentOf(layout, current);
80
+ current = index.parentOf.get(current);
96
81
  }
97
82
  return undefined;
98
83
  };
99
84
 
100
- const ICONS: Record<string, typeof TextHIcon> = {
101
- heading: TextHIcon,
102
- container: SquaresFourIcon,
103
- "div-block": SquaresFourIcon,
104
- "layout-section": RowsIcon,
105
- flexbox: SquaresFourIcon,
106
- image: ImageIcon,
107
- icon: StarIcon,
108
- svg: StarIcon,
109
- tabs: SquaresFourIcon,
110
- "tab-panel": SquaresFourIcon,
111
- video: YoutubeLogoIcon,
112
- form: ClipboardTextIcon,
113
- "text-input": TextboxIcon,
114
- textarea: NotePencilIcon,
115
- select: TextboxIcon,
116
- checkbox: CheckSquareIcon,
117
- radio: RadioButtonIcon,
118
- submit: PaperPlaneTiltIcon,
119
- };
120
-
121
- const withStyle = (node: LayoutNode, patch: Partial<StyleProps>): LayoutNode => {
122
- const style: Record<string, unknown> = { ...node.style, ...patch };
123
- for (const key of Object.keys(style)) if (style[key] === undefined) delete style[key];
124
- return {
125
- ...node,
126
- style: Object.keys(style).length > 0 ? (style as StyleProps) : undefined,
127
- };
128
- };
129
-
130
- const withDevices = (node: LayoutNode, devices: DeviceStyles | undefined): LayoutNode => {
131
- const { devices: _old, ...rest } = node;
132
- return (devices ? { ...rest, devices } : rest) as LayoutNode;
133
- };
134
-
135
- const withStates = (node: LayoutNode, states: StyleStates | undefined): LayoutNode => {
136
- const { states: _old, ...rest } = node;
137
- return (states ? { ...rest, states } : rest) as LayoutNode;
138
- };
139
-
140
85
  const sectionKey = (type: string) => `emvb-style-sections:${type}`;
141
86
 
142
87
  /**
@@ -417,13 +362,20 @@ function KnownElementPanel({
417
362
  const position = positionInEffect(node, design, cls);
418
363
  const iconSvg =
419
364
  node.type === "icon" && typeof node.props.iconSvg === "string" ? node.props.iconSvg : undefined;
420
- const strokeAdjustable = node.type === "icon" && !cls ? iconHasAdjustableStroke(iconSvg) : true;
365
+ const strokeAdjustable = React.useMemo(
366
+ () => (node.type === "icon" && !cls ? iconHasAdjustableStroke(iconSvg) : true),
367
+ [node.type, cls, iconSvg],
368
+ );
369
+ const ownColors = React.useMemo(
370
+ () => node.type === "icon" && iconHasOwnColors(iconSvg),
371
+ [node.type, iconSvg],
372
+ );
421
373
  const singleColorOffered =
422
374
  node.type === "icon" &&
423
375
  !cls &&
424
376
  !responsive &&
425
377
  styleState === "normal" &&
426
- (node.props.singleColor === true || iconHasOwnColors(iconSvg));
378
+ (node.props.singleColor === true || ownColors);
427
379
  // W-296: elsewhere (Hover, Focus, a device) Colour does nothing on such an SVG until Force single
428
380
  // colour is on, and that switch only lives in Normal on Desktop, so say so there.
429
381
  const colorIgnoredHere =
@@ -431,36 +383,22 @@ function KnownElementPanel({
431
383
  !cls &&
432
384
  !singleColorOffered &&
433
385
  node.props.singleColor !== true &&
434
- iconHasOwnColors(iconSvg);
386
+ ownColors;
435
387
  const patchStyle = (patch: Partial<StyleProps>) => {
436
- if (responsive) {
437
- if (!cls) {
438
- onChange(withDevices(node, patchDeviceStyle(node.devices, responsive, patch)));
439
- return;
440
- }
441
- setDesignError(null);
442
- onDesignChange(patchClassDevices(design, cls.id, responsive, patch)).catch((error: unknown) =>
443
- setDesignError(
444
- error instanceof Error ? error.message : "Couldn't save the class. Try again.",
445
- ),
446
- );
447
- return;
448
- }
449
- const state = styleState;
450
- if (!cls) {
451
- onChange(
452
- state === "normal"
453
- ? withStyle(node, patch)
454
- : withStates(node, patchStates(node.states, state, patch)),
455
- );
388
+ const written = applyStylePatch({
389
+ node,
390
+ design,
391
+ classId: cls ? cls.id : null,
392
+ device,
393
+ state: styleState,
394
+ patch,
395
+ });
396
+ if (written.kind === "node") {
397
+ onChange(written.node);
456
398
  return;
457
399
  }
458
400
  setDesignError(null);
459
- const next =
460
- state === "normal"
461
- ? patchClassStyle(design, cls.id, patch)
462
- : patchClassState(design, cls.id, state, patch);
463
- onDesignChange(next).catch((error: unknown) =>
401
+ onDesignChange(written.design).catch((error: unknown) =>
464
402
  setDesignError(
465
403
  error instanceof Error ? error.message : "Couldn't save the class. Try again.",
466
404
  ),
@@ -472,7 +410,7 @@ function KnownElementPanel({
472
410
  const bodyRef = React.useRef<HTMLDivElement>(null);
473
411
  useTabScroll(bodyRef, tab, node.id);
474
412
 
475
- const Icon = ICONS[node.type] ?? SquaresFourIcon;
413
+ const Icon = elementIcon(node.type);
476
414
  const crumbs = breadcrumb(layout, node.id);
477
415
  const section = (
478
416
  id: StyleSectionId,
@@ -647,6 +585,8 @@ function KnownElementPanel({
647
585
  (node.htmlId ? 1 : 0) + (node.attributes?.length ?? 0),
648
586
  <>
649
587
  <HtmlIdField node={node} layout={layout} onChange={onChange} />
588
+ <DirectionField node={node} onChange={onChange} />
589
+ {"children" in node && <ContainerQueryFields node={node} onChange={onChange} />}
650
590
  <AttributesEditor
651
591
  attributes={node.attributes}
652
592
  onChange={(attributes) => onChange({ ...node, attributes })}
@@ -789,16 +729,17 @@ function breadcrumb(
789
729
  id: string,
790
730
  ): Array<{ id: string | null; label: string }> {
791
731
  if (!layout) return [];
732
+ const index = indexLayout(layout);
792
733
  const chain: Array<{ id: string; label: string }> = [];
793
734
  let current: string | undefined = id;
794
735
  while (current) {
795
- const node = findNode(layout, current);
736
+ const node = index.byId.get(current);
796
737
  if (!node) break;
797
738
  chain.unshift({
798
739
  id: node.id,
799
740
  label: ELEMENT_NAMES[node.type] ?? node.type,
800
741
  });
801
- current = parentOf(layout, current);
742
+ current = index.parentOf.get(current);
802
743
  }
803
744
  return [{ id: null, label: "Page" }, ...chain];
804
745
  }
@@ -1,10 +1,4 @@
1
- import {
2
- CaretDownIcon,
3
- CaretRightIcon,
4
- RowsIcon,
5
- SquaresFourIcon,
6
- TextHIcon,
7
- } from "@phosphor-icons/react";
1
+ import { CaretDownIcon, CaretRightIcon } from "@phosphor-icons/react";
8
2
  import * as React from "react";
9
3
  import {
10
4
  firstChild,
@@ -20,23 +14,14 @@ import {
20
14
  SCRIPT_LABELS,
21
15
  type PageScript,
22
16
  } from "../../../core/index.ts";
17
+ import { indexLayout } from "../../../core/tree-ops.ts";
23
18
  import { EXISTING_ELEMENT_MIME } from "../dnd/drop-target.ts";
24
- import { ELEMENT_NAMES } from "./ElementPanel.tsx";
19
+ import { ELEMENT_NAMES, elementIcon } from "../element-chrome.ts";
20
+ import { editorCommands } from "../editor-commands.ts";
25
21
  import { dragStash } from "../dnd/drag-stash.ts";
26
22
  import { StateDot } from "./settings/StateSwitcher.tsx";
27
23
  import type { ClipboardActions } from "../useClipboardActions.ts";
28
24
 
29
- const ICONS: Record<string, typeof TextHIcon> = {
30
- heading: TextHIcon,
31
- container: SquaresFourIcon,
32
- svg: SquaresFourIcon,
33
- tabs: SquaresFourIcon,
34
- "tab-panel": SquaresFourIcon,
35
- "div-block": SquaresFourIcon,
36
- "layout-section": RowsIcon,
37
- flexbox: SquaresFourIcon,
38
- };
39
-
40
25
  const rows = (
41
26
  node: LayoutNode,
42
27
  depth: number,
@@ -92,47 +77,33 @@ function menuItems(
92
77
  clip: ClipboardActions | undefined,
93
78
  rename: () => void,
94
79
  ): MenuItem[] {
95
- const naming: MenuItem[] = actions.onRename ? [{ label: "Rename", run: rename }] : [];
96
- const parent = isParentNode(node);
97
- const clipboard: MenuItem[] = clip
98
- ? [
99
- { label: "Copy", run: clip.copy },
100
- ...(isRoot
101
- ? []
102
- : [
103
- {
104
- label: "Paste",
105
- run: (id: string) => clip.paste(id),
106
- disabled: !!clip.pasteBlocked,
107
- },
108
- ]),
109
- ...(parent
110
- ? [
111
- {
112
- label: "Paste inside",
113
- run: (id: string) => clip.paste(id, "inside"),
114
- disabled: !!clip.pasteBlocked,
115
- },
116
- ]
117
- : []),
118
- ]
119
- : [];
120
- const style: MenuItem[] = clip
121
- ? [
122
- { label: "Copy style", run: clip.copyStyle },
123
- { label: "Paste style", run: clip.pasteStyle, disabled: !!clip.pasteStyleBlocked },
124
- ]
125
- : [];
126
- if (isRoot) return [...naming, ...clipboard, ...style];
127
- return [
128
- ...naming,
129
- ...clipboard,
130
- { label: "Duplicate", run: actions.onDuplicate },
131
- ...style,
132
- { label: "Move up", run: actions.onMoveUp },
133
- { label: "Move down", run: actions.onMoveDown },
134
- { label: "Delete", run: actions.onDelete, className: "emvb-danger-text" },
135
- ];
80
+ return editorCommands({
81
+ surface: "layers",
82
+ targetId: node.id,
83
+ isRoot,
84
+ isParent: isParentNode(node),
85
+ device: "desktop",
86
+ canDuplicate: !isRoot,
87
+ canDelete: !isRoot,
88
+ runners: {
89
+ rename: actions.onRename ? rename : undefined,
90
+ duplicate: actions.onDuplicate,
91
+ remove: actions.onDelete,
92
+ moveUp: actions.onMoveUp,
93
+ moveDown: actions.onMoveDown,
94
+ copy: clip?.copy,
95
+ paste: clip?.paste,
96
+ copyStyle: clip?.copyStyle,
97
+ pasteStyle: clip?.pasteStyle,
98
+ pasteBlocked: clip?.pasteBlocked,
99
+ pasteStyleBlocked: clip?.pasteStyleBlocked,
100
+ },
101
+ }).map((command) => ({
102
+ label: command.label,
103
+ run: () => command.run(),
104
+ disabled: command.disabled,
105
+ className: command.danger ? "emvb-danger-text" : undefined,
106
+ }));
136
107
  }
137
108
 
138
109
  /** What a key does in the tree: select another row, toggle the selected one, or nothing. */
@@ -242,10 +213,11 @@ export function LayersPanel({
242
213
  if (!layout || !selectedId) return;
243
214
  setCollapsed((current) => {
244
215
  const next = new Set(current);
216
+ const parents = indexLayout(layout).parentOf;
245
217
  let id: string | undefined = selectedId;
246
218
  while (id) {
247
219
  next.delete(id);
248
- id = parentOf(layout, id);
220
+ id = parents.get(id);
249
221
  }
250
222
  return next;
251
223
  });
@@ -345,7 +317,7 @@ const LayerRow = React.memo(function LayerRow({
345
317
  }) {
346
318
  const onToggle = () => toggleRow(node.id);
347
319
  const onMenu = (open: boolean) => menuRow(node.id, open);
348
- const Icon = ICONS[node.type] ?? SquaresFourIcon;
320
+ const Icon = elementIcon(node.type);
349
321
  const preview = layerPreview(node);
350
322
  const typeName = ELEMENT_NAMES[node.type] ?? node.type;
351
323
  // A label names the row in place of the type (W-157); the type stays in the tooltip.
@@ -66,6 +66,7 @@ export function SettingsPanel({
66
66
  layout={state.page.layout}
67
67
  onDesignChange={onDesignChange}
68
68
  unpublished={state.designUnpublished === true}
69
+ published={state.publishedDesign}
69
70
  onPublishStyles={onPublishStyles}
70
71
  {...(onDesignItemDeleted ? { onDeleted: onDesignItemDeleted } : {})}
71
72
  onLayoutChange={(layout) =>
@@ -1,10 +1,12 @@
1
1
  import { Button, Select, Tabs } from "@cloudflare/kumo";
2
2
  import { deletionOf, type Deletion } from "../restore-deleted.ts";
3
- import { WarningCircleIcon, XIcon } from "@phosphor-icons/react";
3
+ import { XIcon } from "@phosphor-icons/react";
4
4
  import * as React from "react";
5
5
  import {
6
6
  clearClassRefs,
7
7
  deleteVariable,
8
+ designChangeLabel,
9
+ designChanges,
8
10
  designFromJson,
9
11
  designToJson,
10
12
  findClassUsages,
@@ -27,6 +29,7 @@ import { stopEditorShortcuts } from "./settings/ClassChip.tsx";
27
29
  import { StyleRow } from "./settings/StyleRow.tsx";
28
30
  import { FIELD } from "../../ui.ts";
29
31
  import { TokenScales } from "./TokenScales.tsx";
32
+ import { InlineError } from "./inline-error.tsx";
30
33
  import { VariableSection } from "./VariableSection.tsx";
31
34
 
32
35
  const STYLE_NOTE = "Style changes stay unpublished until you publish styles.";
@@ -36,6 +39,8 @@ type Props = {
36
39
  layout: Layout | null;
37
40
  onDesignChange: (design: DesignSystem) => Promise<void>;
38
41
  unpublished?: boolean;
42
+ /** Published design. With `unpublished`, the drawer lists what Publish styles will change. */
43
+ published?: DesignSystem;
39
44
  onPublishStyles?: () => Promise<void>;
40
45
  onLayoutChange: (layout: Layout) => void;
41
46
  /** W-252: called with what a delete removes, before the page loses its uses. */
@@ -43,15 +48,6 @@ type Props = {
43
48
  onClose: () => void;
44
49
  };
45
50
 
46
- function InlineError({ children }: { children: string }) {
47
- return (
48
- <p className="emvb-inline-error" role="alert">
49
- <WarningCircleIcon size={16} aria-hidden="true" />
50
- {children}
51
- </p>
52
- );
53
- }
54
-
55
51
  function exportDesign(design: DesignSystem) {
56
52
  const blob = new Blob([designToJson(design)], { type: "application/json" });
57
53
  const url = URL.createObjectURL(blob);
@@ -71,6 +67,7 @@ export function SiteStylesDrawer({
71
67
  layout,
72
68
  onDesignChange,
73
69
  unpublished = false,
70
+ published,
74
71
  onPublishStyles,
75
72
  onLayoutChange,
76
73
  onDeleted,
@@ -160,6 +157,15 @@ export function SiteStylesDrawer({
160
157
  aria-label="Site styles actions"
161
158
  data-emvb-site-styles-actions=""
162
159
  >
160
+ {unpublished && published && (
161
+ <ul className="emvb-helper" data-emvb-style-diff="">
162
+ {designChanges(published, design).map((change) => (
163
+ <li key={`${change.kind}:${change.what}:${change.name}`}>
164
+ {designChangeLabel(change)}
165
+ </li>
166
+ ))}
167
+ </ul>
168
+ )}
163
169
  {unpublished && (
164
170
  <Button type="button" variant="primary" size="sm" onClick={() => void publish()}>
165
171
  Publish styles