@perkyzz/emvb 0.6.0 → 0.7.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 (183) hide show
  1. package/package.json +1 -1
  2. package/src/admin/access/RequireEditor.tsx +7 -7
  3. package/src/admin/access/role.ts +5 -2
  4. package/src/admin/content-api.ts +10 -3
  5. package/src/admin/content-item.ts +1 -1
  6. package/src/admin/editor/A11yCopilot.tsx +104 -56
  7. package/src/admin/editor/CommandPalette.tsx +29 -13
  8. package/src/admin/editor/Editor.tsx +82 -20
  9. package/src/admin/editor/EditorToasts.tsx +26 -0
  10. package/src/admin/editor/PerfMeter.tsx +97 -72
  11. package/src/admin/editor/ShareLink.tsx +107 -72
  12. package/src/admin/editor/ShortcutsDialog.tsx +27 -16
  13. package/src/admin/editor/Timeline.tsx +255 -160
  14. package/src/admin/editor/TopBar.tsx +71 -14
  15. package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
  16. package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
  17. package/src/admin/editor/canvas/drop-line.ts +11 -3
  18. package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
  19. package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
  20. package/src/admin/editor/canvas/vnode-react.tsx +7 -0
  21. package/src/admin/editor/collection-previews.ts +10 -0
  22. package/src/admin/editor/dialogs.tsx +38 -14
  23. package/src/admin/editor/dnd/drop-target.ts +26 -1
  24. package/src/admin/editor/edited-noun.ts +15 -0
  25. package/src/admin/editor/editor-chrome.tsx +59 -7
  26. package/src/admin/editor/editor-commands.ts +2 -1
  27. package/src/admin/editor/editor-css.ts +72 -22
  28. package/src/admin/editor/element-chrome.ts +21 -11
  29. package/src/admin/editor/feature-css.ts +45 -13
  30. package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
  31. package/src/admin/editor/icons/library.ts +1 -1
  32. package/src/admin/editor/icons/use-icon-library.ts +5 -2
  33. package/src/admin/editor/ime.ts +29 -0
  34. package/src/admin/editor/palette-items.ts +10 -3
  35. package/src/admin/editor/panels/AddPanel.tsx +35 -10
  36. package/src/admin/editor/panels/ClassesSection.tsx +18 -7
  37. package/src/admin/editor/panels/ColorControl.tsx +130 -23
  38. package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
  39. package/src/admin/editor/panels/ElementPanel.tsx +134 -24
  40. package/src/admin/editor/panels/LayersPanel.tsx +55 -19
  41. package/src/admin/editor/panels/PageSettings.tsx +66 -35
  42. package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
  43. package/src/admin/editor/panels/TokenScales.tsx +76 -36
  44. package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
  45. package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
  46. package/src/admin/editor/panels/VariableSection.tsx +48 -18
  47. package/src/admin/editor/panels/color-space.ts +9 -3
  48. package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
  49. package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
  50. package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
  51. package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
  52. package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
  53. package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
  54. package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
  55. package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
  56. package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
  57. package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
  58. package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
  59. package/src/admin/editor/panels/settings/FieldControl.tsx +20 -8
  60. package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
  61. package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
  62. package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
  63. package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
  64. package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
  65. package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
  66. package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
  67. package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
  68. package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
  69. package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
  70. package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
  71. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
  72. package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
  73. package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
  74. package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
  75. package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
  76. package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
  77. package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
  78. package/src/admin/editor/panels/settings/query-style.ts +38 -9
  79. package/src/admin/editor/panels/settings/svg-images.ts +13 -0
  80. package/src/admin/editor/panels/site-list.tsx +20 -6
  81. package/src/admin/editor/panels/variable-values.ts +11 -4
  82. package/src/admin/editor/restore-deleted.ts +21 -2
  83. package/src/admin/editor/section-templates.ts +81 -12
  84. package/src/admin/editor/shortcuts.ts +17 -2
  85. package/src/admin/editor/store.ts +7 -0
  86. package/src/admin/editor/useEditorCommands.ts +61 -15
  87. package/src/admin/editor/useEditorData.ts +4 -2
  88. package/src/admin/editor/useEditorShortcuts.ts +17 -7
  89. package/src/admin/editor/useNodeActions.ts +61 -6
  90. package/src/admin/editor/useSave.ts +22 -7
  91. package/src/admin/forms-api.ts +2 -0
  92. package/src/admin/image-editor/CurvesPanel.tsx +2 -1
  93. package/src/admin/image-editor/ExportDialog.tsx +48 -18
  94. package/src/admin/image-editor/ImageEditorDialog.tsx +49 -7
  95. package/src/admin/image-editor/MetadataPanel.tsx +15 -4
  96. package/src/admin/image-editor/crop-geometry.ts +3 -2
  97. package/src/admin/image-editor/image-editor-css.ts +4 -2
  98. package/src/admin/image-editor/load.ts +9 -2
  99. package/src/admin/image-editor/parts.tsx +51 -2
  100. package/src/admin/image-editor/save.ts +23 -7
  101. package/src/admin/media-api.ts +2 -1
  102. package/src/admin/pages/AgentsPage.tsx +138 -27
  103. package/src/admin/pages/CreateDialog.tsx +97 -30
  104. package/src/admin/pages/NewPageDialog.tsx +21 -3
  105. package/src/admin/pages/NewThemePartDialog.tsx +11 -3
  106. package/src/admin/pages/PageList.tsx +14 -6
  107. package/src/admin/pages/SetupShell.tsx +28 -12
  108. package/src/admin/pages/ThemePartList.tsx +27 -7
  109. package/src/admin/pages/list-kit.tsx +106 -24
  110. package/src/admin/search.ts +15 -0
  111. package/src/admin/setup/useSetupStatus.ts +1 -1
  112. package/src/admin/theme-api.ts +13 -3
  113. package/src/admin/ui.ts +73 -22
  114. package/src/astro/floats/runtime.ts +21 -0
  115. package/src/astro/menu/runtime.ts +34 -1
  116. package/src/astro/popups/runtime.ts +33 -3
  117. package/src/astro/render.ts +3 -0
  118. package/src/astro/resolve-theme.ts +53 -11
  119. package/src/astro/resolve.ts +9 -1
  120. package/src/astro/tabs/runtime.ts +12 -0
  121. package/src/astro/theme-posts.ts +2 -2
  122. package/src/astro/visitor.ts +2 -0
  123. package/src/constants.ts +1 -1
  124. package/src/core/a11y/audit.ts +171 -24
  125. package/src/core/arrange.ts +27 -6
  126. package/src/core/audience/rules.ts +5 -1
  127. package/src/core/audience/variants.ts +29 -3
  128. package/src/core/clipboard.ts +7 -0
  129. package/src/core/css/generate.ts +31 -6
  130. package/src/core/data/bindings.ts +8 -1
  131. package/src/core/design/classes.ts +16 -7
  132. package/src/core/design/diff.ts +6 -0
  133. package/src/core/design/merge.ts +90 -2
  134. package/src/core/design/tokens.ts +16 -2
  135. package/src/core/design/transfer.ts +33 -6
  136. package/src/core/design/variables.ts +30 -9
  137. package/src/core/elements/dynamic-elements.ts +44 -5
  138. package/src/core/elements/form-elements.ts +55 -16
  139. package/src/core/elements/index.ts +83 -38
  140. package/src/core/elements/menu.ts +37 -19
  141. package/src/core/elements/select-prompt.ts +3 -0
  142. package/src/core/elements/svg-ids.ts +39 -0
  143. package/src/core/forms/binding.ts +57 -16
  144. package/src/core/forms/definition.ts +72 -0
  145. package/src/core/history/diff.ts +18 -1
  146. package/src/core/icons/catalog.ts +3 -2
  147. package/src/core/image-edit/schema.ts +11 -1
  148. package/src/core/image-edit/summary.ts +6 -3
  149. package/src/core/index.ts +15 -1
  150. package/src/core/limits.ts +12 -1
  151. package/src/core/perf/meter.ts +42 -7
  152. package/src/core/recipes/index.ts +5 -4
  153. package/src/core/render/context.ts +8 -0
  154. package/src/core/render/dynamic-post.ts +69 -12
  155. package/src/core/render/extras.ts +77 -4
  156. package/src/core/render/form.ts +140 -6
  157. package/src/core/render/index.ts +156 -20
  158. package/src/core/render/loop.ts +43 -7
  159. package/src/core/render/pagination.ts +18 -4
  160. package/src/core/render/section.ts +27 -0
  161. package/src/core/render/tabs.ts +12 -3
  162. package/src/core/render/vnode.ts +1 -1
  163. package/src/core/sanitize/css.ts +15 -2
  164. package/src/core/sanitize/embed-url.ts +42 -5
  165. package/src/core/sanitize/url.ts +2 -1
  166. package/src/core/schema/layout.ts +15 -6
  167. package/src/core/stats.ts +2 -1
  168. package/src/core/theme/conditions.ts +3 -1
  169. package/src/core/theme/dynamic.ts +36 -5
  170. package/src/core/theme/float.ts +9 -2
  171. package/src/core/theme/pagination.ts +31 -11
  172. package/src/core/theme/popup-markup.ts +23 -5
  173. package/src/core/theme/popup-rules.ts +1 -0
  174. package/src/core/theme/triggers.ts +3 -2
  175. package/src/core/tree-ops.ts +27 -0
  176. package/src/mcp/rate-limit.ts +2 -1
  177. package/src/mcp/read.ts +14 -2
  178. package/src/mcp/refs.ts +18 -0
  179. package/src/mcp/write.ts +174 -10
  180. package/src/server/agent-settings.ts +1 -1
  181. package/src/server/hooks.ts +5 -3
  182. package/src/server/icon-routes.ts +30 -9
  183. package/src/server/mcp-routes.ts +6 -1
@@ -7,8 +7,11 @@ import {
7
7
  type DesignSystem,
8
8
  type Layout,
9
9
  type PerfKind,
10
+ type ThemeDynamicData,
10
11
  } from "../../core/index.ts";
11
12
  import { ELEMENT_NAMES } from "./element-chrome.ts";
13
+ import { BUTTON } from "../ui.ts";
14
+ import { useEditedNoun } from "./edited-noun.ts";
12
15
 
13
16
  const KINDS: { kind: PerfKind; label: string }[] = [
14
17
  { kind: "html", label: "HTML" },
@@ -17,7 +20,15 @@ const KINDS: { kind: PerfKind; label: string }[] = [
17
20
  { kind: "images", label: "Images" },
18
21
  ];
19
22
 
20
- const kb = (bytes: number) => (bytes < 1000 ? `${bytes} B` : `${(bytes / 1000).toFixed(1)} KB`);
23
+ /** UX-083: "1.4 KB", "100 KB", "1.5 MB": one decimal only where it says something. */
24
+ export const kb = (bytes: number) => {
25
+ if (bytes < 1000) return `${bytes} B`;
26
+ // W-771: round before choosing the form, so 1999 B is "2 KB", not "2.0 KB", and 999.6 KB is "1 MB".
27
+ const inMb = Math.round(bytes / 1000) >= 1000;
28
+ const raw = inMb ? bytes / 1_000_000 : bytes / 1000;
29
+ const value = raw >= 100 ? Math.round(raw) : Math.round(raw * 10) / 10;
30
+ return `${value} ${inMb ? "MB" : "KB"}`;
31
+ };
21
32
 
22
33
  /**
23
34
  * The page's weight against its budget (W-310): one bar per kind, the scripts it loads (zero
@@ -28,93 +39,107 @@ export function PerfMeterDialog({
28
39
  onOpenChange,
29
40
  layout,
30
41
  design,
42
+ parts,
31
43
  onSelect,
32
44
  }: {
33
45
  open: boolean;
34
46
  onOpenChange: (open: boolean) => void;
35
47
  layout: Layout | null;
36
48
  design: DesignSystem;
49
+ /** W-671: the synced sections and Loop Item parts the canvas shows, weighed with the page. */
50
+ parts?: ThemeDynamicData;
37
51
  onSelect: (id: string) => void;
38
52
  }) {
53
+ const noun = useEditedNoun();
39
54
  const report = React.useMemo(
40
- () => (open && layout ? measurePage(layout, design) : null),
41
- [open, layout, design],
55
+ () => (open && layout ? measurePage(layout, design, parts) : null),
56
+ [open, layout, design, parts],
42
57
  );
43
58
  return (
44
59
  <Dialog.Root open={open} onOpenChange={onOpenChange}>
45
60
  <Dialog size="base" className="p-6 emvb-perf" data-emvb-perf="">
46
- <Dialog.Title>Page weight</Dialog.Title>
47
- {report && (
48
- <>
49
- <ul className="emvb-perf-bars">
50
- {KINDS.map(({ kind, label }) => {
51
- const share = Math.min(1, report.bytes[kind] / PERF_BUDGETS[kind]);
52
- const over = report.over.includes(kind);
53
- return (
54
- <li key={kind} data-emvb-perf-kind={kind} data-over={over ? "" : undefined}>
55
- <span className="emvb-perf-label">{label}</span>
56
- <span
57
- className="emvb-perf-bar"
58
- role="meter"
59
- aria-label={`${label} weight`}
60
- aria-valuemin={0}
61
- aria-valuemax={PERF_BUDGETS[kind]}
62
- aria-valuenow={Math.min(report.bytes[kind], PERF_BUDGETS[kind])}
63
- aria-valuetext={`${kb(report.bytes[kind])} of ${kb(PERF_BUDGETS[kind])}`}
64
- >
65
- <span style={{ width: `${Math.round(share * 100)}%` }} />
66
- </span>
67
- <span className="emvb-perf-value">
68
- {kb(report.bytes[kind])} / {kb(PERF_BUDGETS[kind])}
69
- </span>
70
- </li>
71
- );
72
- })}
73
- </ul>
74
- <p className="emvb-helper" data-emvb-perf-js="">
75
- {report.scripts.length === 0
76
- ? "Zero JavaScript: this page is plain HTML and CSS."
77
- : `Scripts: ${report.scripts.map((s) => SCRIPT_LABELS[s.script]).join(", ")}.`}
78
- </p>
79
- {report.warnings.length > 0 && (
80
- <ul className="emvb-perf-warnings" data-emvb-perf-warnings="">
81
- {report.warnings.map((warning) => (
82
- <li key={warning}>{warning}</li>
83
- ))}
84
- </ul>
85
- )}
86
- {report.sections.length > 0 && (
87
- <>
88
- <h3 className="emvb-perf-heading">Heaviest sections</h3>
89
- <ol className="emvb-perf-sections">
90
- {report.sections.slice(0, 5).map((section) => (
91
- <li key={section.id}>
92
- <button
93
- type="button"
94
- className="emvb-link-button"
95
- data-emvb-perf-section={section.id}
96
- onClick={() => {
97
- onSelect(section.id);
98
- onOpenChange(false);
99
- }}
61
+ <div className="emvb-dialog" data-emvb-dialog="perf">
62
+ <Dialog.Title>Page weight</Dialog.Title>
63
+ {report && (
64
+ <>
65
+ <ul className="emvb-perf-bars">
66
+ {KINDS.map(({ kind, label }) => {
67
+ const share = Math.min(1, report.bytes[kind] / PERF_BUDGETS[kind]);
68
+ const over = report.over.includes(kind);
69
+ return (
70
+ <li key={kind} data-emvb-perf-kind={kind} data-over={over ? "" : undefined}>
71
+ <span className="emvb-perf-label">{label}</span>
72
+ <span
73
+ className="emvb-perf-bar"
74
+ role="meter"
75
+ aria-label={`${label} weight`}
76
+ aria-valuemin={0}
77
+ aria-valuemax={PERF_BUDGETS[kind]}
78
+ aria-valuenow={Math.min(report.bytes[kind], PERF_BUDGETS[kind])}
79
+ aria-valuetext={`${kb(report.bytes[kind])} of ${kb(PERF_BUDGETS[kind])}`}
100
80
  >
101
- {section.label || ELEMENT_NAMES[section.type] || section.type}
102
- </button>{" "}
103
- {kb(section.bytes)}
104
- {section.images > 0
105
- ? ` · ${section.images} image${section.images === 1 ? "" : "s"}`
106
- : ""}
81
+ <span style={{ width: `${Math.round(share * 100)}%` }} />
82
+ </span>
83
+ <span className="emvb-perf-value">
84
+ {kb(report.bytes[kind])} / {kb(PERF_BUDGETS[kind])}
85
+ </span>
107
86
  </li>
87
+ );
88
+ })}
89
+ </ul>
90
+ <p className="emvb-helper" data-emvb-perf-js="">
91
+ {report.scripts.length === 0
92
+ ? `Zero JavaScript: this ${noun} is plain HTML and CSS.`
93
+ : `Scripts: ${report.scripts.map((s) => SCRIPT_LABELS[s.script]).join(", ")}.`}
94
+ </p>
95
+ {report.warnings.length > 0 && (
96
+ <ul className="emvb-perf-warnings" data-emvb-perf-warnings="">
97
+ {report.warnings.map((warning) => (
98
+ <li key={warning}>{warning}</li>
108
99
  ))}
109
- </ol>
110
- </>
111
- )}
112
- <p className="emvb-helper">
113
- HTML and CSS are gzipped estimates; image sizes come from their width and height.
114
- </p>
115
- </>
116
- )}
117
- <Dialog.Close render={(props) => <Button {...props}>Close</Button>} />
100
+ </ul>
101
+ )}
102
+ {report.sections.length > 0 && (
103
+ <>
104
+ <h3 className="emvb-perf-heading">Heaviest sections</h3>
105
+ <ol className="emvb-perf-sections">
106
+ {report.sections.slice(0, 5).map((section) => (
107
+ <li key={section.id}>
108
+ <button
109
+ type="button"
110
+ className="emvb-link-button"
111
+ data-emvb-perf-section={section.id}
112
+ onClick={() => {
113
+ onSelect(section.id);
114
+ onOpenChange(false);
115
+ }}
116
+ >
117
+ {section.label || ELEMENT_NAMES[section.type] || section.type}
118
+ </button>{" "}
119
+ {kb(section.bytes)}
120
+ {section.images > 0
121
+ ? ` · ${section.images} image${section.images === 1 ? "" : "s"}`
122
+ : ""}
123
+ </li>
124
+ ))}
125
+ </ol>
126
+ </>
127
+ )}
128
+ <p className="emvb-helper">
129
+ HTML and CSS are gzipped estimates; image sizes come from their width and height.
130
+ </p>
131
+ </>
132
+ )}
133
+ <div className="emvb-dialog-actions">
134
+ <Dialog.Close
135
+ render={(props) => (
136
+ <Button {...props} variant="secondary" className={BUTTON}>
137
+ Close
138
+ </Button>
139
+ )}
140
+ />
141
+ </div>
142
+ </div>
118
143
  </Dialog>
119
144
  </Dialog.Root>
120
145
  );
@@ -15,15 +15,40 @@ const siteOnly = (value: unknown) =>
15
15
  typeof value === "string" && value.trim() !== "" && !/^(https?:)?\/\//i.test(value.trim());
16
16
 
17
17
  /** Media on the page whose address only works on this site (W-321): a path, not a full URL. */
18
- export function siteOnlyMedia(layout: Layout): number {
18
+ export function siteOnlyMedia(layout: Layout, design?: DesignSystem): number {
19
19
  let count = 0;
20
+ type Owner = {
21
+ style?: unknown;
22
+ devices?: unknown;
23
+ states?: unknown;
24
+ query?: { style?: unknown };
25
+ };
26
+ const sheets = (owner: Owner): unknown[] => [
27
+ owner.style,
28
+ // Device and hover/focus/active styles can carry a background too (W-631), and so can a
29
+ // container-query override (W-644).
30
+ ...Object.values((owner.devices ?? {}) as Record<string, unknown>),
31
+ ...Object.values((owner.states ?? {}) as Record<string, unknown>),
32
+ owner.query?.style,
33
+ ];
34
+ // W-644: a background set by a class the page uses, when the link carries the site styles.
35
+ const classes = new Map((design?.classes ?? []).map((c) => [c.id, c]));
36
+ const counted = new Set<string>();
20
37
  const visit = (node: LayoutNode) => {
21
- const props = node.props as Record<string, unknown>;
22
- const style = (node.style ?? {}) as Record<string, unknown>;
23
- for (const key of MEDIA_KEYS) {
24
- const raw = props[key] ?? style[key];
25
- const url = typeof raw === "object" && raw !== null ? (raw as { url?: unknown }).url : raw;
26
- if (siteOnly(url)) count += 1;
38
+ const fromClasses = (node.classes ?? []).flatMap((id) => {
39
+ const cls = classes.get(id);
40
+ if (!cls || counted.has(id)) return [];
41
+ counted.add(id);
42
+ return sheets(cls as Owner);
43
+ });
44
+ const sources = [node.props, ...sheets(node as Owner), ...fromClasses];
45
+ for (const source of sources) {
46
+ if (typeof source !== "object" || source === null) continue;
47
+ for (const key of MEDIA_KEYS) {
48
+ const raw = (source as Record<string, unknown>)[key];
49
+ const url = typeof raw === "object" && raw !== null ? (raw as { url?: unknown }).url : raw;
50
+ if (siteOnly(url)) count += 1;
51
+ }
27
52
  }
28
53
  const kids = (node as { children?: LayoutNode[] }).children;
29
54
  if (Array.isArray(kids)) for (const child of kids) visit(child);
@@ -57,6 +82,7 @@ export function ShareLinkDialog({
57
82
  const [link, setLink] = React.useState<string | null>(null);
58
83
  const [error, setError] = React.useState<string | null>(null);
59
84
  const [copied, setCopied] = React.useState<"yes" | "no" | null>(null);
85
+ const copyAttempt = React.useRef(0);
60
86
 
61
87
  React.useEffect(() => {
62
88
  if (!open || !layout) return;
@@ -74,89 +100,98 @@ export function ShareLinkDialog({
74
100
  );
75
101
  return () => {
76
102
  cancelled = true;
103
+ copyAttempt.current += 1;
77
104
  };
78
105
  }, [open, layout, design, title, withStyles, base]);
79
106
 
80
107
  const copy = () => {
81
108
  if (!link) return;
109
+ const attempt = ++copyAttempt.current;
110
+ const reportCopy = (result: "yes" | "no") => {
111
+ if (attempt === copyAttempt.current) setCopied(result);
112
+ };
82
113
  if (!navigator.clipboard?.writeText) {
83
- setCopied("no");
114
+ reportCopy("no");
84
115
  return;
85
116
  }
86
117
  navigator.clipboard.writeText(link).then(
87
- () => setCopied("yes"),
88
- () => setCopied("no"),
118
+ () => reportCopy("yes"),
119
+ () => reportCopy("no"),
89
120
  );
90
121
  };
91
122
 
92
- const siteMedia = layout ? siteOnlyMedia(layout) : 0;
123
+ const siteMedia = layout ? siteOnlyMedia(layout, withStyles ? design : undefined) : 0;
93
124
  return (
94
125
  <Dialog.Root open={open} onOpenChange={onOpenChange}>
95
126
  <Dialog size="base" className="p-6 emvb-share" data-emvb-share="">
96
- <Dialog.Title>Share as a playground link</Dialog.Title>
97
- <Dialog.Description>
98
- Anyone with the link can open a copy of this page in the EmVB playground and edit it in
99
- their own browser. The page travels inside the link; nothing is uploaded.
100
- </Dialog.Description>
101
- <Switch
102
- label="Include Site styles (colours, fonts, sizes, classes)"
103
- checked={withStyles}
104
- onCheckedChange={(checked) => setWithStyles(checked === true)}
105
- />
106
- {error ? (
107
- <p className="emvb-helper" role="alert">
108
- Couldn't build the link: {error}
109
- </p>
110
- ) : (
111
- <Input
112
- label="Link"
113
- className={FIELD}
114
- readOnly
115
- value={link ?? "Building the link…"}
116
- data-emvb-share-link=""
117
- onFocus={(event) => event.currentTarget.select()}
127
+ <div className="emvb-dialog" data-emvb-dialog="share">
128
+ <Dialog.Title>Share as a playground link</Dialog.Title>
129
+ <Dialog.Description>
130
+ Anyone with the link can open a copy of this page in the EmVB playground and edit it in
131
+ their own browser. The page travels inside the link; nothing is uploaded.
132
+ </Dialog.Description>
133
+ <Switch
134
+ label="Include Site styles (colours, fonts, sizes, classes)"
135
+ checked={withStyles}
136
+ onCheckedChange={(checked) => setWithStyles(checked === true)}
118
137
  />
119
- )}
120
- {link && (
121
- <p className="emvb-helper" data-emvb-share-size="">
122
- {link.length.toLocaleString("en")} characters
123
- {link.length > LONG_LINK_CHARS
124
- ? ". That's long: some chat apps cut links this size, so paste it somewhere that keeps it whole."
125
- : "."}
126
- </p>
127
- )}
128
- {siteMedia > 0 && (
129
- <p className="emvb-helper" data-emvb-share-media="">
130
- {siteMedia === 1 ? "1 image or video uses" : `${siteMedia} images or videos use`} an
131
- address on this site only, so the playground shows {siteMedia === 1 ? "it" : "them"}{" "}
132
- empty.
133
- </p>
134
- )}
135
- <p className="emvb-helper">
136
- Unsaved changes are included. Posts, forms and uploads stay on this site.
137
- </p>
138
- <div className="emvb-dialog-actions">
139
- {copied && (
140
- <span role="status" className="emvb-helper">
141
- {copied === "yes" ? "Copied." : "Copy didn't work here: select the link and copy it."}
142
- </span>
138
+ {error ? (
139
+ <p className="emvb-helper" role="alert">
140
+ Couldn't build the link: {error}
141
+ </p>
142
+ ) : (
143
+ <Input
144
+ label="Link"
145
+ className={FIELD}
146
+ readOnly
147
+ value={link ?? "Building the link…"}
148
+ data-emvb-share-link=""
149
+ onFocus={(event) => event.currentTarget.select()}
150
+ />
143
151
  )}
144
- <Dialog.Close
145
- render={(props) => (
146
- <Button {...props} variant="secondary" className={BUTTON}>
147
- Close
148
- </Button>
152
+ {link && (
153
+ <p className="emvb-helper" data-emvb-share-size="">
154
+ {link.length.toLocaleString("en")} characters
155
+ {link.length > LONG_LINK_CHARS
156
+ ? ". That's long: some chat apps cut links this size, so paste it somewhere that keeps it whole."
157
+ : "."}
158
+ </p>
159
+ )}
160
+ {siteMedia > 0 && (
161
+ <p className="emvb-helper" data-emvb-share-media="">
162
+ {siteMedia === 1 ? "1 image or video uses" : `${siteMedia} images or videos use`} an
163
+ address on this site only, so the playground shows {siteMedia === 1 ? "it" : "them"}{" "}
164
+ empty.
165
+ </p>
166
+ )}
167
+ <p className="emvb-helper">
168
+ Unsaved changes are included. Posts, forms and uploads stay on this site.
169
+ </p>
170
+ <div className="emvb-dialog-actions">
171
+ {copied && (
172
+ <span role="status" className="emvb-helper">
173
+ {copied === "yes"
174
+ ? "Copied."
175
+ : "Copy didn't work here: select the link and copy it."}
176
+ </span>
149
177
  )}
150
- />
151
- <Button
152
- variant="primary"
153
- className={BUTTON}
154
- disabled={!link}
155
- onClick={copy}
156
- data-emvb-share-copy=""
157
- >
158
- Copy link
159
- </Button>
178
+ <Dialog.Close
179
+ render={(props) => (
180
+ <Button {...props} variant="secondary" className={BUTTON}>
181
+ Close
182
+ </Button>
183
+ )}
184
+ />
185
+ <Button
186
+ variant="primary"
187
+ className={BUTTON}
188
+ disabled={!link}
189
+ onClick={copy}
190
+ data-emvb-share-copy=""
191
+ >
192
+ Copy link
193
+ </Button>
194
+ </div>
160
195
  </div>
161
196
  </Dialog>
162
197
  </Dialog.Root>
@@ -1,5 +1,6 @@
1
1
  import { Button, Dialog } from "@cloudflare/kumo";
2
2
  import { SHORTCUTS } from "./shortcuts.ts";
3
+ import { BUTTON } from "../ui.ts";
3
4
 
4
5
  export function ShortcutsDialog({
5
6
  open,
@@ -11,22 +12,32 @@ export function ShortcutsDialog({
11
12
  return (
12
13
  <Dialog.Root open={open} onOpenChange={onOpenChange}>
13
14
  <Dialog size="base" className="p-6">
14
- <Dialog.Title>Keyboard shortcuts</Dialog.Title>
15
- <table className="emvb-shortcuts">
16
- <tbody>
17
- {SHORTCUTS.map(({ action, keys }) => (
18
- <tr key={action}>
19
- <td>{action}</td>
20
- <td>{keys}</td>
21
- </tr>
22
- ))}
23
- </tbody>
24
- </table>
25
- <p>
26
- Shortcuts don't fire while a text field has focus, except Ctrl/Cmd+S and Ctrl/Cmd+K. In a
27
- dialog, only Ctrl/Cmd+S fires.
28
- </p>
29
- <Dialog.Close render={(props) => <Button {...props}>Close</Button>} />
15
+ <div className="emvb-dialog" data-emvb-dialog="shortcuts">
16
+ <Dialog.Title>Keyboard shortcuts</Dialog.Title>
17
+ <table className="emvb-shortcuts">
18
+ <tbody>
19
+ {SHORTCUTS.map(({ action, keys }) => (
20
+ <tr key={action}>
21
+ <td>{action}</td>
22
+ <td>{keys}</td>
23
+ </tr>
24
+ ))}
25
+ </tbody>
26
+ </table>
27
+ <p className="emvb-helper">
28
+ Shortcuts don't fire while a text field has focus, except Ctrl/Cmd+S and Ctrl/Cmd+K. In
29
+ a dialog, only Ctrl/Cmd+S fires.
30
+ </p>
31
+ <div className="emvb-dialog-actions">
32
+ <Dialog.Close
33
+ render={(props) => (
34
+ <Button {...props} variant="secondary" className={BUTTON}>
35
+ Close
36
+ </Button>
37
+ )}
38
+ />
39
+ </div>
40
+ </div>
30
41
  </Dialog>
31
42
  </Dialog.Root>
32
43
  );