@perkyzz/emvb 1.0.0 → 1.1.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 (80) hide show
  1. package/README.md +9 -0
  2. package/package.json +2 -2
  3. package/src/admin/bulk-api.ts +67 -0
  4. package/src/admin/content-api.ts +10 -6
  5. package/src/admin/copy-rich-text.ts +119 -0
  6. package/src/admin/dialog-tab-wrap.ts +78 -0
  7. package/src/admin/editor/A11yCopilot.tsx +2 -0
  8. package/src/admin/editor/Editor.tsx +18 -6
  9. package/src/admin/editor/Timeline.tsx +6 -2
  10. package/src/admin/editor/TopBar.tsx +27 -7
  11. package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
  12. package/src/admin/editor/canvas/DeviceBar.tsx +22 -9
  13. package/src/admin/editor/canvas/canvas-scale.ts +3 -3
  14. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  15. package/src/admin/editor/dnd/new-element.ts +22 -0
  16. package/src/admin/editor/editor-chrome.tsx +7 -5
  17. package/src/admin/editor/editor-commands.ts +10 -4
  18. package/src/admin/editor/editor-css.ts +2 -1
  19. package/src/admin/editor/panels/ElementPanel.tsx +29 -16
  20. package/src/admin/editor/panels/SettingsPanel.tsx +2 -2
  21. package/src/admin/editor/panels/settings/EffectsControls.tsx +79 -1
  22. package/src/admin/editor/panels/settings/IconControls.tsx +11 -0
  23. package/src/admin/editor/panels/settings/LengthRow.tsx +36 -3
  24. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +18 -0
  25. package/src/admin/editor/panels/settings/StyleRow.tsx +7 -0
  26. package/src/admin/editor/panels/settings/length-units.ts +15 -3
  27. package/src/admin/editor/panels/settings/style-sections.ts +1 -0
  28. package/src/admin/editor/panels/style-target.ts +17 -4
  29. package/src/admin/editor/section-templates.ts +26 -4
  30. package/src/admin/editor/store.ts +8 -2
  31. package/src/admin/editor/useEditorCommands.ts +7 -5
  32. package/src/admin/editor/useNodeActions.ts +4 -2
  33. package/src/admin/export-api.ts +221 -0
  34. package/src/admin/index.tsx +6 -1
  35. package/src/admin/pages/ExportDialog.tsx +395 -0
  36. package/src/admin/pages/PageList.tsx +67 -2
  37. package/src/admin/pages/ThemePartList.tsx +37 -1
  38. package/src/admin/pages/bulk.tsx +303 -0
  39. package/src/admin/search.ts +20 -0
  40. package/src/admin/theme-api.ts +4 -0
  41. package/src/admin/ui.ts +11 -2
  42. package/src/admin/widgets/CanvasField.tsx +8 -0
  43. package/src/admin/widgets/ConvertToRichText.tsx +136 -0
  44. package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
  45. package/src/admin/widgets/convert-body.ts +73 -2
  46. package/src/astro/render.ts +6 -6
  47. package/src/astro/resolve-theme.ts +11 -7
  48. package/src/astro/tabs/runtime.ts +16 -6
  49. package/src/constants.ts +1 -1
  50. package/src/core/a11y/audit.ts +2 -1
  51. package/src/core/contract.ts +22 -2
  52. package/src/core/css/generate.ts +83 -21
  53. package/src/core/css/scope.ts +10 -2
  54. package/src/core/css/trace.ts +33 -8
  55. package/src/core/design/classes.ts +25 -5
  56. package/src/core/design/devices.ts +78 -2
  57. package/src/core/design/variables.ts +14 -1
  58. package/src/core/export/runtimes.generated.ts +9 -0
  59. package/src/core/export/site.ts +562 -0
  60. package/src/core/export/zip.ts +95 -0
  61. package/src/core/history/diff.ts +25 -0
  62. package/src/core/import/elementor/atomic.ts +22 -9
  63. package/src/core/import/elementor/index.ts +22 -4
  64. package/src/core/import/elementor/style.ts +21 -1
  65. package/src/core/index.ts +14 -0
  66. package/src/core/json-schema.ts +8 -1
  67. package/src/core/perf/meter.ts +37 -19
  68. package/src/core/portable-text-export.ts +243 -0
  69. package/src/core/public-attributes.ts +30 -0
  70. package/src/core/render/index.ts +88 -9
  71. package/src/core/render/tabs.ts +18 -11
  72. package/src/core/sanitize/css.ts +26 -0
  73. package/src/core/schema/design.ts +2 -2
  74. package/src/core/schema/layout.ts +11 -3
  75. package/src/core/schema/style.ts +47 -0
  76. package/src/core/search-text.ts +70 -0
  77. package/src/core/theme/float.ts +1 -0
  78. package/src/core/theme/popup-rules.ts +16 -0
  79. package/src/mcp/read.ts +2 -3
  80. package/src/server/icon-routes.ts +52 -12
package/README.md CHANGED
@@ -1,3 +1,12 @@
1
+ <p align="center">
2
+ <a href="https://emvb.dev">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/PerkyZZ999/EmVB/main/docs/brand/logo-dark.svg">
5
+ <img src="https://raw.githubusercontent.com/PerkyZZ999/EmVB/main/docs/brand/logo-light.svg" alt="EmVB" width="320">
6
+ </picture>
7
+ </a>
8
+ </p>
9
+
1
10
  # @perkyzz/emvb
2
11
 
3
12
  [![Website](https://img.shields.io/badge/website-emvb.dev-1f6feb)](https://emvb.dev) [![npm](https://img.shields.io/npm/v/@perkyzz/emvb)](https://www.npmjs.com/package/@perkyzz/emvb)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perkyzz/emvb",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Visual page builder plugin for EmDash CMS",
5
5
  "keywords": [
6
6
  "astro",
@@ -49,7 +49,7 @@
49
49
  "test:astro": "bun --bun vitest run"
50
50
  },
51
51
  "dependencies": {
52
- "@perkyzz/emvb-icons": "1.0.0",
52
+ "@perkyzz/emvb-icons": "1.1.0",
53
53
  "photocn": "0.1.2",
54
54
  "zod": "~4.5.4"
55
55
  },
@@ -0,0 +1,67 @@
1
+ import { ApiError, listAllItems, requestJson, type Fetcher } from "./api.ts";
2
+ import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../constants.ts";
3
+ import { titleOf, type ContentItem } from "./content-item.ts";
4
+ import { publishEntry } from "./content-api.ts";
5
+
6
+ /** What a bulk action did: the ids it changed and, for the rest, why not. */
7
+ export type BulkResult = { done: string[]; failed: { id: string; message: string }[] };
8
+
9
+ const message = (error: unknown) =>
10
+ error instanceof ApiError || error instanceof Error ? error.message : String(error);
11
+
12
+ /** Runs `act` on each id in turn (one request at a time); a failure doesn't stop the rest. */
13
+ async function each(ids: readonly string[], act: (id: string) => Promise<unknown>) {
14
+ const result: BulkResult = { done: [], failed: [] };
15
+ for (const id of ids) {
16
+ try {
17
+ // oxlint-disable-next-line no-await-in-loop -- one at a time keeps the site's load low
18
+ await act(id);
19
+ result.done.push(id);
20
+ } catch (error) {
21
+ result.failed.push({ id, message: message(error) });
22
+ }
23
+ }
24
+ return result;
25
+ }
26
+
27
+ const path = (collection: string, id: string, action = "") =>
28
+ `/_emdash/api/content/${encodeURIComponent(collection)}/${encodeURIComponent(id)}${action}`;
29
+
30
+ /** W-978: publishes each entry's latest saved version. */
31
+ export const publishMany = (fetcher: Fetcher, collection: string, ids: readonly string[]) =>
32
+ each(ids, (id) =>
33
+ publishEntry(fetcher, `/_emdash/api/content/${encodeURIComponent(collection)}`, id, null),
34
+ );
35
+
36
+ /** W-978: moves each entry to EmDash's trash, from where `restoreMany` brings it back. */
37
+ export const trashMany = (fetcher: Fetcher, collection: string, ids: readonly string[]) =>
38
+ each(ids, (id) => requestJson(fetcher, path(collection, id), { method: "DELETE" }));
39
+
40
+ /** W-978: brings entries back from the trash. */
41
+ export const restoreMany = (fetcher: Fetcher, collection: string, ids: readonly string[]) =>
42
+ each(ids, (id) => requestJson(fetcher, path(collection, id, "/restore"), { method: "POST" }));
43
+
44
+ /**
45
+ * W-980: which of `ids` (theme parts) published pages and parts still use, as synced sections or
46
+ * loop items, with the titles of where. Deleting one leaves nothing in its place there.
47
+ */
48
+ export async function partsInUse(
49
+ fetcher: Fetcher,
50
+ ids: readonly string[],
51
+ ): Promise<Map<string, string[]>> {
52
+ const [pages, parts] = await Promise.all([
53
+ listAllItems<ContentItem>(fetcher, `/_emdash/api/content/${PAGES_COLLECTION}`),
54
+ listAllItems<ContentItem>(fetcher, `/_emdash/api/content/${THEME_PARTS_COLLECTION}`),
55
+ ]);
56
+ const used = new Map<string, string[]>();
57
+ for (const item of [...pages, ...parts]) {
58
+ if (ids.includes(item.id)) continue;
59
+ const layout = item.data?.["layout"];
60
+ const text = typeof layout === "string" ? layout : JSON.stringify(layout ?? null);
61
+ for (const id of ids) {
62
+ if (!text.includes(`"partId":${JSON.stringify(id)}`)) continue;
63
+ used.set(id, [...(used.get(id) ?? []), titleOf(item, "Untitled")]);
64
+ }
65
+ }
66
+ return used;
67
+ }
@@ -1,9 +1,10 @@
1
- import type {
2
- ConditionsDoc,
3
- FloatSettings,
4
- Layout,
5
- ThemePartType,
6
- TriggersDoc,
1
+ import {
2
+ layoutSearchText,
3
+ type ConditionsDoc,
4
+ type FloatSettings,
5
+ type Layout,
6
+ type ThemePartType,
7
+ type TriggersDoc,
7
8
  } from "../core/index.ts";
8
9
  import { PAGES_COLLECTION } from "../constants.ts";
9
10
  import { listAllItems, requestJson, type Fetcher } from "./api.ts";
@@ -20,6 +21,8 @@ export type PageSummary = {
20
21
  slug: string;
21
22
  status: string;
22
23
  updatedAt: string;
24
+ /** W-978: the layout's words, for searching by content. */
25
+ text?: string;
23
26
  };
24
27
 
25
28
  export async function listPages(fetcher: Fetcher): Promise<PageSummary[]> {
@@ -30,6 +33,7 @@ export async function listPages(fetcher: Fetcher): Promise<PageSummary[]> {
30
33
  slug: item.slug ?? "",
31
34
  status: entryStatus(item),
32
35
  updatedAt: item.updatedAt ?? "",
36
+ text: layoutSearchText(item.data?.["layout"]),
33
37
  }));
34
38
  }
35
39
 
@@ -0,0 +1,119 @@
1
+ import { validateLayout, type Layout } from "../core/index.ts";
2
+ import { layoutToPortableText } from "../core/portable-text-export.ts";
3
+ import { THEME_PARTS_COLLECTION } from "../constants.ts";
4
+ import { ApiError, listAllItems, requestJson, type Fetcher } from "./api.ts";
5
+ import type { ContentItem } from "./content-item.ts";
6
+ import { loadExportData } from "./export-api.ts";
7
+ import { readCollection } from "./setup/run.ts";
8
+
9
+ export type RichTextTarget = {
10
+ slug: string;
11
+ label: string;
12
+ /** The Portable Text field the words go into (`content` first). */
13
+ field: string;
14
+ /** The collection has a `title` field for the page title. */
15
+ hasTitle: boolean;
16
+ };
17
+
18
+ /** Visible collections with a rich-text field: where EmVB pages can be copied as rich text. */
19
+ export async function richTextTargets(fetcher: Fetcher): Promise<RichTextTarget[]> {
20
+ const list = await requestJson<{ items: { slug: string; label?: string; hidden?: boolean }[] }>(
21
+ fetcher,
22
+ "/_emdash/api/schema/collections",
23
+ );
24
+ const rows = await Promise.all(
25
+ list.items
26
+ .filter((c) => !c.hidden)
27
+ .map(async (c) => {
28
+ const fields = (await readCollection(fetcher, c.slug))?.fields ?? [];
29
+ const rich = fields.filter((f) => f.type === "portableText");
30
+ const field = rich.find((f) => f.slug === "content") ?? rich[0];
31
+ if (!field) return null;
32
+ const target: RichTextTarget = {
33
+ slug: c.slug,
34
+ label: c.label?.trim() || c.slug,
35
+ field: field.slug,
36
+ hasTitle: fields.some((f) => f.slug === "title"),
37
+ };
38
+ return target;
39
+ }),
40
+ );
41
+ return rows.filter((row): row is RichTextTarget => row !== null);
42
+ }
43
+
44
+ export type CopyResult = {
45
+ created: { title: string; id: string }[];
46
+ failed: { title: string; message: string }[];
47
+ /** Elements left out across all pages, by type. */
48
+ skipped: Record<string, number>;
49
+ };
50
+
51
+ /**
52
+ * W-963: published EmVB pages (all or one) become draft entries in another collection, their
53
+ * words, headings, lists, links and images as rich text. EmVB pages are only read; nothing is
54
+ * published. A page whose entry can't be created (a slug in use) is reported and the rest go on.
55
+ */
56
+ export async function copyPagesAsRichText(
57
+ fetcher: Fetcher,
58
+ target: RichTextTarget,
59
+ onlyPageId?: string | readonly string[],
60
+ ): Promise<CopyResult> {
61
+ const [{ pages }, partItems] = await Promise.all([
62
+ loadExportData(fetcher, onlyPageId),
63
+ listAllItems<ContentItem>(fetcher, `/_emdash/api/content/${THEME_PARTS_COLLECTION}`),
64
+ ]);
65
+ const sectionTemplates: Record<string, Layout> = {};
66
+ for (const part of partItems) {
67
+ if (part.status !== "published" || part.data?.["part_type"] !== "section") continue;
68
+ const checked = validateLayout(part.data["layout"]);
69
+ if (checked.ok) sectionTemplates[part.id] = checked.layout;
70
+ }
71
+ const result: CopyResult = { created: [], failed: [], skipped: {} };
72
+ for (const page of pages) {
73
+ let raw = page.layout;
74
+ if (typeof raw === "string") {
75
+ try {
76
+ raw = JSON.parse(raw) as unknown;
77
+ } catch {
78
+ raw = null;
79
+ }
80
+ }
81
+ const checked = validateLayout(raw);
82
+ if (!checked.ok) {
83
+ result.failed.push({ title: page.title, message: "its layout couldn't be read" });
84
+ continue;
85
+ }
86
+ const converted = layoutToPortableText(checked.layout, { sectionTemplates });
87
+ for (const [type, n] of Object.entries(converted.skipped))
88
+ result.skipped[type] = (result.skipped[type] ?? 0) + n;
89
+ try {
90
+ // oxlint-disable-next-line no-await-in-loop -- one entry at a time; failures are per page
91
+ const body = await requestJson<{ item: { id: string } }>(
92
+ fetcher,
93
+ `/_emdash/api/content/${encodeURIComponent(target.slug)}`,
94
+ {
95
+ method: "POST",
96
+ body: {
97
+ data: {
98
+ ...(target.hasTitle ? { title: page.title } : {}),
99
+ [target.field]: converted.body,
100
+ },
101
+ ...(page.slug ? { slug: page.slug } : {}),
102
+ },
103
+ },
104
+ );
105
+ result.created.push({ title: page.title, id: body.item.id });
106
+ } catch (error) {
107
+ result.failed.push({
108
+ title: page.title,
109
+ message:
110
+ error instanceof ApiError && error.status === 409
111
+ ? "its address is already used there"
112
+ : error instanceof Error
113
+ ? error.message
114
+ : String(error),
115
+ });
116
+ }
117
+ }
118
+ return result;
119
+ }
@@ -0,0 +1,78 @@
1
+ /** What Tab can land on inside the editor. */
2
+ const TABBABLE = [
3
+ "a[href]",
4
+ "button",
5
+ "input",
6
+ "select",
7
+ "textarea",
8
+ "[tabindex]",
9
+ "[contenteditable='true']",
10
+ ].join(",");
11
+
12
+ /** Visible, enabled, in the tab order, and not one of Base UI's focus guards. */
13
+ export function tabbablesIn(root: HTMLElement): HTMLElement[] {
14
+ return [...root.querySelectorAll<HTMLElement>(TABBABLE)].filter((el) => {
15
+ if (el.hasAttribute("data-base-ui-focus-guard")) return false;
16
+ if (el.tabIndex < 0) return false;
17
+ if ((el as HTMLButtonElement).disabled) return false;
18
+ if (el instanceof HTMLInputElement && el.type === "hidden") return false;
19
+ if (el.closest("[inert],[hidden]")) return false;
20
+ return el.getClientRects().length > 0;
21
+ });
22
+ }
23
+
24
+ /**
25
+ * W-984: Tab past the last control goes to the first, Shift+Tab before the first goes to the
26
+ * last. The dialog's own trap uses focus guards that, in the production build, sometimes let
27
+ * focus fall to the page behind; wrapping here means Tab never reaches them. Returns whether it
28
+ * moved focus (and stopped the key).
29
+ */
30
+ export function wrapTab(event: KeyboardEvent, root: HTMLElement): boolean {
31
+ if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey) return false;
32
+ const items = tabbablesIn(root);
33
+ const first = items[0];
34
+ const last = items.at(-1);
35
+ if (!first || !last) return false;
36
+ const active = root.ownerDocument.activeElement;
37
+ const target = event.shiftKey
38
+ ? active === first || !root.contains(active)
39
+ ? last
40
+ : null
41
+ : active === last || !root.contains(active)
42
+ ? first
43
+ : null;
44
+ if (!target) return false;
45
+ event.preventDefault();
46
+ target.focus();
47
+ return true;
48
+ }
49
+
50
+ /** An open EmVB dialog (Kumo/Base UI popup with EmVB content) around `el`, if any. */
51
+ export function emvbDialogOf(el: Element | null): HTMLElement | null {
52
+ const dialog = el?.closest<HTMLElement>('[role="dialog"],[role="alertdialog"]') ?? null;
53
+ if (!dialog) return null;
54
+ const ours =
55
+ dialog.matches("[data-emvb-image-editor-popup]") ||
56
+ dialog.querySelector('[data-emvb-dialog],.emvb-dialog,[class*="emvb-"]') !== null;
57
+ return ours ? dialog : null;
58
+ }
59
+
60
+ let installed = false;
61
+
62
+ /**
63
+ * W-984: one Tab handler for every EmVB dialog, installed once with the admin. EmDash's own
64
+ * dialogs are left alone.
65
+ */
66
+ export function installDialogTabWrap(doc: Document): void {
67
+ if (installed) return;
68
+ installed = true;
69
+ doc.addEventListener(
70
+ "keydown",
71
+ (event) => {
72
+ if (event.key !== "Tab" || event.defaultPrevented) return;
73
+ const dialog = emvbDialogOf(doc.activeElement);
74
+ if (dialog) wrapTab(event, dialog);
75
+ },
76
+ true,
77
+ );
78
+ }
@@ -75,6 +75,8 @@ export function A11yDialog({
75
75
  refocusAfterFix.current = true;
76
76
  onApply(next, note);
77
77
  };
78
+ // W-979: the issue list of a large page was built on every edit while the dialog was closed.
79
+ if (!open) return null;
78
80
  const name = (id: string) => {
79
81
  const node = layout ? findNode(layout, id) : undefined;
80
82
  if (!node) return "Element";
@@ -19,6 +19,9 @@ import {
19
19
  type Layout,
20
20
  type LayoutNode,
21
21
  type Device,
22
+ type EditorDevice,
23
+ hiddenOnDevice,
24
+ wideHideIsOwn,
22
25
  } from "../../core/index.ts";
23
26
  import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
24
27
  import { EditedNounContext, editedNounOf, useEditedNoun } from "./edited-noun.ts";
@@ -58,7 +61,7 @@ import {
58
61
  type LoadedDesign,
59
62
  } from "./useEditorData.ts";
60
63
  import { EDITOR_MIN_WIDTH_QUERY, useMediaQuery } from "./useMediaQuery.ts";
61
- import { usePartTemplates } from "./section-templates.ts";
64
+ import { partDraftLabel, usePartTemplates } from "./section-templates.ts";
62
65
  import { useCollectionPreviews, withPartLayouts } from "./collection-previews.ts";
63
66
  import { useEditorPresence } from "./presence.ts";
64
67
  import { useCoDesign } from "./useCoDesign.ts";
@@ -168,7 +171,7 @@ function EditorApp({
168
171
  const noun = useEditedNoun();
169
172
  const toasts = React.useMemo(() => createKumoToastManager(), []);
170
173
  const chrome = useChromeFlags();
171
- const [device, setDevice] = React.useState<Device>("desktop");
174
+ const [device, setDevice] = React.useState<EditorDevice>("desktop");
172
175
  const [zoom, setZoom] = React.useState<CanvasZoom>("fit");
173
176
  const [scale, setScale] = React.useState(1);
174
177
  const [statePreview, setStatePreview] = React.useState<StatePreview | null>(null);
@@ -264,7 +267,10 @@ function EditorApp({
264
267
  if (chrome.leaving) exit();
265
268
  }, [chrome.leaving, exit]);
266
269
 
267
- const { sectionTemplates, loopTemplates } = usePartTemplates(state.page.layout, fetcher);
270
+ const { sectionTemplates, loopTemplates, partStatus } = usePartTemplates(
271
+ state.page.layout,
272
+ fetcher,
273
+ );
268
274
  const partDynamic = React.useMemo(
269
275
  () => ({ sectionTemplates, loopTemplates }),
270
276
  [sectionTemplates, loopTemplates],
@@ -371,7 +377,12 @@ function EditorApp({
371
377
  selectedId: selectedNode ? state.selectedId : null,
372
378
  labelFor: (id) => {
373
379
  const node = layoutIndex?.byId.get(id);
374
- return node ? (node.editorLabel ?? ELEMENT_NAMES[node.type] ?? node.type) : "Element";
380
+ if (!node) return "Element";
381
+ const name = node.editorLabel ?? ELEMENT_NAMES[node.type] ?? node.type;
382
+ // W-970: a synced section or Loop item drawn from unpublished changes says so on the canvas.
383
+ const partId = (node.props as { partId?: unknown } | undefined)?.partId;
384
+ const status = typeof partId === "string" ? partStatus?.[partId] : undefined;
385
+ return status && status !== "published" ? `${name} · ${partDraftLabel(status)}` : name;
375
386
  },
376
387
  canDelete,
377
388
  canMove,
@@ -576,7 +587,8 @@ function EditorApp({
576
587
  <main className="emvb-canvas">
577
588
  <DeviceBar
578
589
  device={device}
579
- hidden={!!selectedNode?.hiddenOn?.includes(device)}
590
+ hidden={!!selectedNode && hiddenOnDevice(selectedNode, device)}
591
+ inherited={device === "wide" && !!selectedNode && !wideHideIsOwn(selectedNode)}
580
592
  canHide={!!hideOnDevice && !hideOnDevice.disabled}
581
593
  hideLabel={hideOnDevice?.label ?? `Hide on ${device}`}
582
594
  onDevice={setDevice}
@@ -693,7 +705,7 @@ function EditorApp({
693
705
  <FieldPreview
694
706
  open={fieldPreview}
695
707
  onOpenChange={setFieldPreview}
696
- device={device === "laptop" ? "desktop" : device}
708
+ device={device === "laptop" || device === "wide" ? "desktop" : device}
697
709
  render={renderFieldPreview}
698
710
  />
699
711
  )}
@@ -418,6 +418,7 @@ export function TimelineDialog({
418
418
  <span className="emvb-timeline-kind">{KIND_LABELS[change.kind]}</span>{" "}
419
419
  {change.label || ELEMENT_NAMES[change.type] || change.type}
420
420
  {change.kind === "changed" &&
421
+ !change.page &&
421
422
  ` · ${change.edits} element${change.edits === 1 ? "" : "s"}`}
422
423
  {(change.kind === "changed" || change.kind === "removed") && (
423
424
  <button
@@ -433,10 +434,13 @@ export function TimelineDialog({
433
434
  }
434
435
  setError(null);
435
436
  refocusAfterRestore.current = true;
436
- onApply(result.layout, "Section restored");
437
+ onApply(
438
+ result.layout,
439
+ change.page ? "Page styles restored" : "Section restored",
440
+ );
437
441
  }}
438
442
  >
439
- Restore this section
443
+ {change.page ? "Restore page styles" : "Restore this section"}
440
444
  </button>
441
445
  )}
442
446
  </li>
@@ -11,6 +11,7 @@ import {
11
11
  FloppyDiskIcon,
12
12
  KeyboardIcon,
13
13
  LaptopIcon,
14
+ MonitorIcon,
14
15
  PaintBrushIcon,
15
16
  SignOutIcon,
16
17
  UploadSimpleIcon,
@@ -19,11 +20,12 @@ import {
19
20
  import { BUTTON, SOLID_PRIMARY } from "../ui.ts";
20
21
  import { statusLabel } from "../entry-status.ts";
21
22
  import type { SaveStatus } from "./useSave.ts";
22
- import type { Device } from "../../core/index.ts";
23
+ import { WIDE_MIN_PX, type EditorDevice } from "../../core/index.ts";
23
24
  import { useMediaQuery } from "./useMediaQuery.ts";
24
25
 
25
26
  /** Preview sizes (W-158): the canvas device widths, in a window of that size. */
26
27
  const PREVIEW_SIZES = [
28
+ { device: "wide", label: "Wide screen (2560 px)", icon: MonitorIcon },
27
29
  { device: "desktop", label: "Desktop", icon: DesktopIcon },
28
30
  { device: "laptop", label: "Laptop (1200 px)", icon: LaptopIcon },
29
31
  { device: "tablet", label: "Tablet (768 px)", icon: DeviceTabletIcon },
@@ -32,6 +34,9 @@ const PREVIEW_SIZES = [
32
34
 
33
35
  export type TopBarPage = { title: string; status: string };
34
36
 
37
+ const wideScreenFits = () =>
38
+ typeof window !== "undefined" && (window.screen?.availWidth ?? 0) >= WIDE_MIN_PX;
39
+
35
40
  function SaveStatusText({
36
41
  status,
37
42
  dirty,
@@ -93,7 +98,7 @@ export function TopBar({
93
98
  onShortcuts: () => void;
94
99
  onSiteStyles?: () => void;
95
100
  /** Opens the preview; with no device, at the device shown on the canvas (W-158). */
96
- onPreview: (device?: Device) => void;
101
+ onPreview: (device?: EditorDevice) => void;
97
102
  onSave: () => void;
98
103
  onPublish: () => void;
99
104
  /** Site styles have unpublished changes (W-153): the Publish button carries a dot. */
@@ -253,11 +258,26 @@ export function TopBar({
253
258
  />
254
259
  </DropdownMenu.Trigger>
255
260
  <DropdownMenu.Content data-emvb-preview-sizes="">
256
- {PREVIEW_SIZES.map(({ device, label, icon }) => (
257
- <DropdownMenu.Item key={device} icon={icon} onClick={() => onPreview(device)}>
258
- {label}
259
- </DropdownMenu.Item>
260
- ))}
261
+ {PREVIEW_SIZES.map(({ device, label, icon }) => {
262
+ // W-959: a window can't be wider than the screen, so Wide screen's media
263
+ // queries only apply on a screen at least 2400 px wide.
264
+ const tooNarrow = device === "wide" && !wideScreenFits();
265
+ return (
266
+ <DropdownMenu.Item
267
+ key={device}
268
+ icon={icon}
269
+ disabled={tooNarrow}
270
+ title={
271
+ tooNarrow
272
+ ? `Needs a screen at least ${WIDE_MIN_PX} px wide; the canvas shows Wide screen at any size`
273
+ : undefined
274
+ }
275
+ onClick={() => onPreview(device)}
276
+ >
277
+ {label}
278
+ </DropdownMenu.Item>
279
+ );
280
+ })}
261
281
  </DropdownMenu.Content>
262
282
  </DropdownMenu>
263
283
  </div>
@@ -1,5 +1,10 @@
1
1
  import { createPortal } from "react-dom";
2
- import { isMultilineText, type Layout, type Device, type VNode } from "../../../core/index.ts";
2
+ import {
3
+ isMultilineText,
4
+ type Layout,
5
+ type EditorDevice,
6
+ type VNode,
7
+ } from "../../../core/index.ts";
3
8
  import type { PasteRefusal } from "../useClipboardActions.ts";
4
9
  import { CanvasTextEdit } from "./CanvasTextEdit.tsx";
5
10
  import { useFrameFocusRing } from "./frame-focus-ring.ts";
@@ -112,7 +117,7 @@ export function CanvasFrame({
112
117
  /** The style state chosen in the Style tab, shown on the selected element (W-089). */
113
118
  statePreview?: StatePreview | null;
114
119
  /** The previewed device (W-096): its page width, scaled to the stage (W-158, D-046). */
115
- device?: Device;
120
+ device?: EditorDevice;
116
121
  /** Fit to the stage or show at 100% (W-158). */
117
122
  zoom?: CanvasZoom;
118
123
  /** Told the on-screen scale whenever it changes, for the zoom readout (W-158). */
@@ -5,18 +5,21 @@ import {
5
5
  DeviceTabletIcon,
6
6
  type Icon,
7
7
  LaptopIcon,
8
+ MonitorIcon,
8
9
  } from "@phosphor-icons/react";
9
10
  import * as React from "react";
10
- import { DEVICES, type Device } from "../../../core/index.ts";
11
+ import { EDITOR_DEVICES, type EditorDevice } from "../../../core/index.ts";
11
12
 
12
- const LABELS: Record<Device, string> = {
13
+ const LABELS: Record<EditorDevice, string> = {
14
+ wide: "Wide screen",
13
15
  desktop: "Desktop",
14
16
  laptop: "Laptop",
15
17
  tablet: "Tablet",
16
18
  mobile: "Mobile",
17
19
  };
18
20
 
19
- const ICONS: Record<Device, Icon> = {
21
+ const ICONS: Record<EditorDevice, Icon> = {
22
+ wide: MonitorIcon,
20
23
  desktop: DesktopIcon,
21
24
  laptop: LaptopIcon,
22
25
  tablet: DeviceTabletIcon,
@@ -24,7 +27,7 @@ const ICONS: Record<Device, Icon> = {
24
27
  };
25
28
 
26
29
  /** The device's icon (decorative) and its name, which stays the tab's accessible name (W-127). */
27
- function DeviceLabel({ device }: { device: Device }) {
30
+ function DeviceLabel({ device }: { device: EditorDevice }) {
28
31
  const DeviceIcon = ICONS[device];
29
32
  return (
30
33
  <span className="emvb-device-label">
@@ -34,25 +37,28 @@ function DeviceLabel({ device }: { device: Device }) {
34
37
  );
35
38
  }
36
39
 
37
- /** Desktop, tablet or mobile. Desktop edits `style`; the others edit overrides (W-096). */
40
+ /** Wide screen (W-959), desktop, laptop, tablet or mobile. Desktop edits `style`; the others edit overrides (W-096). */
38
41
  export function DeviceBar({
39
42
  device,
40
43
  hidden,
41
44
  canHide,
42
45
  hideLabel,
46
+ inherited = false,
43
47
  onDevice,
44
48
  onToggleHidden,
45
49
  zoom = "fit",
46
50
  scale = 1,
47
51
  onZoom,
48
52
  }: {
49
- device: Device;
53
+ device: EditorDevice;
50
54
  /** Whether the selected element is hidden on `device`. */
51
55
  hidden: boolean;
52
56
  canHide: boolean;
53
57
  /** From the hide-on-device command, so the checkbox wording has one source. */
54
58
  hideLabel: string;
55
- onDevice: (device: Device) => void;
59
+ /** W-959: Wide screen's hide still follows Desktop (no choice of its own yet). */
60
+ inherited?: boolean;
61
+ onDevice: (device: EditorDevice) => void;
56
62
  onToggleHidden: () => void;
57
63
  /** Fit or 100% (W-158), with the current on-screen scale for the readout. */
58
64
  zoom?: "fit" | "actual";
@@ -70,19 +76,26 @@ export function DeviceBar({
70
76
  variant="segmented"
71
77
  size="sm"
72
78
  className="emvb-device-tabs"
73
- tabs={DEVICES.map((item) => ({
79
+ tabs={EDITOR_DEVICES.map((item) => ({
74
80
  value: item,
75
81
  label: <DeviceLabel device={item} />,
76
82
  }))}
77
83
  value={device}
78
84
  onValueChange={(next) => {
79
- if ((DEVICES as readonly string[]).includes(next)) onDevice(next as Device);
85
+ if ((EDITOR_DEVICES as readonly string[]).includes(next))
86
+ onDevice(next as EditorDevice);
80
87
  }}
81
88
  />
82
89
  </div>
83
90
  <label className="emvb-device-hide">
84
91
  <input type="checkbox" checked={hidden} disabled={!canHide} onChange={onToggleHidden} />
85
92
  {hideLabel}
93
+ {inherited && (
94
+ <span className="emvb-helper" data-emvb-hide-inherited="">
95
+ {" "}
96
+ (follows Desktop)
97
+ </span>
98
+ )}
86
99
  </label>
87
100
  {onZoom && (
88
101
  <Button
@@ -1,4 +1,4 @@
1
- import { DEVICE_PREVIEW_PX, type Device } from "../../../core/index.ts";
1
+ import { DEVICE_PREVIEW_PX, WIDE_PREVIEW_PX, type EditorDevice } from "../../../core/index.ts";
2
2
 
3
3
  /** Fit scales the canvas down to the stage; Actual shows it at 100% and scrolls (W-158). */
4
4
  export type CanvasZoom = "fit" | "actual";
@@ -9,11 +9,11 @@ export type CanvasZoom = "fit" | "actual";
9
9
  * the stage width, never up; Actual keeps 100% and the stage scrolls sideways.
10
10
  */
11
11
  export function canvasScale(
12
- device: Device,
12
+ device: EditorDevice,
13
13
  stageWidth: number,
14
14
  zoom: CanvasZoom,
15
15
  ): { width: number; scale: number } {
16
- const base = DEVICE_PREVIEW_PX[device];
16
+ const base = device === "wide" ? WIDE_PREVIEW_PX : DEVICE_PREVIEW_PX[device];
17
17
  const width = device === "desktop" ? Math.max(base, Math.floor(stageWidth)) : base;
18
18
  if (zoom === "actual" || stageWidth <= 0) return { width, scale: 1 };
19
19
  return { width, scale: Math.min(1, stageWidth / width) };
@@ -4,7 +4,7 @@ import {
4
4
  isPlainTextNode,
5
5
  plainTextOf,
6
6
  type Layout,
7
- type Device,
7
+ type EditorDevice,
8
8
  type VNode,
9
9
  } from "../../../core/index.ts";
10
10
  import type { PasteRefusal, ClipboardActions } from "../useClipboardActions.ts";
@@ -65,7 +65,7 @@ export function useCanvasSession({
65
65
  layout: Layout | null;
66
66
  selection: CanvasSelection;
67
67
  statePreview: StatePreview | null;
68
- device: Device;
68
+ device: EditorDevice;
69
69
  zoom: CanvasZoom;
70
70
  onScale?: (scale: number) => void;
71
71
  refusal: PasteRefusal | null;