@perkyzz/emvb 1.0.0 → 1.2.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 (142) hide show
  1. package/README.md +9 -0
  2. package/THIRD_PARTY_NOTICES.md +1 -0
  3. package/package.json +10 -9
  4. package/src/admin/agents-api.ts +5 -1
  5. package/src/admin/bulk-api.ts +67 -0
  6. package/src/admin/content-api.ts +39 -6
  7. package/src/admin/copy-rich-text.ts +119 -0
  8. package/src/admin/dialog-tab-wrap.ts +78 -0
  9. package/src/admin/editor/A11yCopilot.tsx +2 -0
  10. package/src/admin/editor/Editor.tsx +24 -7
  11. package/src/admin/editor/ScheduleDialog.tsx +167 -0
  12. package/src/admin/editor/Timeline.tsx +6 -2
  13. package/src/admin/editor/TopBar.tsx +60 -8
  14. package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
  15. package/src/admin/editor/canvas/DeviceBar.tsx +22 -9
  16. package/src/admin/editor/canvas/canvas-scale.ts +3 -3
  17. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  18. package/src/admin/editor/dnd/new-element.ts +68 -0
  19. package/src/admin/editor/editor-chrome.tsx +16 -5
  20. package/src/admin/editor/editor-commands.ts +10 -4
  21. package/src/admin/editor/editor-css.ts +2 -1
  22. package/src/admin/editor/element-chrome.ts +22 -0
  23. package/src/admin/editor/panels/ElementPanel.tsx +34 -17
  24. package/src/admin/editor/panels/SettingsPanel.tsx +2 -2
  25. package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
  26. package/src/admin/editor/panels/settings/EffectsControls.tsx +79 -1
  27. package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
  28. package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
  29. package/src/admin/editor/panels/settings/IconControls.tsx +11 -0
  30. package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
  31. package/src/admin/editor/panels/settings/ItemList.tsx +36 -2
  32. package/src/admin/editor/panels/settings/LengthRow.tsx +36 -3
  33. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +18 -0
  34. package/src/admin/editor/panels/settings/StyleRow.tsx +7 -0
  35. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  36. package/src/admin/editor/panels/settings/length-units.ts +15 -3
  37. package/src/admin/editor/panels/settings/style-sections.ts +1 -0
  38. package/src/admin/editor/panels/style-target.ts +17 -4
  39. package/src/admin/editor/section-templates.ts +26 -4
  40. package/src/admin/editor/store.ts +15 -3
  41. package/src/admin/editor/useEditorCommands.ts +7 -5
  42. package/src/admin/editor/useEditorData.ts +4 -0
  43. package/src/admin/editor/useNodeActions.ts +4 -2
  44. package/src/admin/editor/useSave.ts +47 -3
  45. package/src/admin/export-api.ts +238 -0
  46. package/src/admin/index.tsx +6 -1
  47. package/src/admin/menus-api.ts +113 -0
  48. package/src/admin/pages/ExportDialog.tsx +395 -0
  49. package/src/admin/pages/ImportElementorDialog.tsx +25 -1
  50. package/src/admin/pages/PageList.tsx +67 -2
  51. package/src/admin/pages/ThemePartList.tsx +37 -1
  52. package/src/admin/pages/bulk.tsx +303 -0
  53. package/src/admin/search.ts +20 -0
  54. package/src/admin/theme-api.ts +4 -0
  55. package/src/admin/ui.ts +11 -2
  56. package/src/admin/widgets/CanvasField.tsx +8 -0
  57. package/src/admin/widgets/ConvertToRichText.tsx +136 -0
  58. package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
  59. package/src/admin/widgets/convert-body.ts +73 -2
  60. package/src/astro/EmVBPage.astro +3 -0
  61. package/src/astro/render.ts +47 -22
  62. package/src/astro/request-data.ts +3 -0
  63. package/src/astro/resolve-theme.ts +88 -51
  64. package/src/astro/tabs/runtime.ts +16 -6
  65. package/src/astro/visitor.ts +23 -4
  66. package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
  67. package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
  68. package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
  69. package/src/astro/widgets/EmVBWidgetRuntimes.astro +19 -0
  70. package/src/astro/widgets/alerts.ts +37 -0
  71. package/src/astro/widgets/carousel.ts +167 -0
  72. package/src/astro/widgets/index.ts +1 -0
  73. package/src/astro/widgets/lightbox.ts +123 -0
  74. package/src/constants.ts +1 -1
  75. package/src/core/a11y/audit.ts +103 -3
  76. package/src/core/arrange.ts +57 -1
  77. package/src/core/bounded-array.ts +16 -13
  78. package/src/core/contract.ts +26 -3
  79. package/src/core/css/generate.ts +83 -21
  80. package/src/core/css/scope.ts +10 -2
  81. package/src/core/css/trace.ts +33 -8
  82. package/src/core/design/classes.ts +25 -5
  83. package/src/core/design/devices.ts +78 -2
  84. package/src/core/design/variables.ts +14 -1
  85. package/src/core/elements/icon-svg.ts +135 -0
  86. package/src/core/elements/index.ts +33 -127
  87. package/src/core/elements/widgets.ts +907 -0
  88. package/src/core/export/runtimes.generated.ts +12 -0
  89. package/src/core/export/site.ts +579 -0
  90. package/src/core/export/zip.ts +95 -0
  91. package/src/core/extensions/schema.ts +2 -1
  92. package/src/core/geo-trust.ts +18 -0
  93. package/src/core/history/diff.ts +25 -0
  94. package/src/core/icons/social.generated.ts +29 -0
  95. package/src/core/image-edit/schema.ts +2 -1
  96. package/src/core/import/elementor/atomic.ts +22 -9
  97. package/src/core/import/elementor/context.ts +18 -0
  98. package/src/core/import/elementor/index.ts +72 -11
  99. package/src/core/import/elementor/style.ts +21 -1
  100. package/src/core/import/elementor/widgets.ts +394 -133
  101. package/src/core/index.ts +14 -0
  102. package/src/core/issue-cap.ts +19 -0
  103. package/src/core/json-schema.ts +8 -1
  104. package/src/core/limits.ts +6 -0
  105. package/src/core/loop-collections.ts +33 -0
  106. package/src/core/perf/meter.ts +37 -19
  107. package/src/core/portable-text-export.ts +243 -0
  108. package/src/core/proposals.ts +8 -2
  109. package/src/core/public-attributes.ts +30 -0
  110. package/src/core/render/index.ts +115 -13
  111. package/src/core/render/tabs.ts +18 -11
  112. package/src/core/render/vnode.ts +44 -6
  113. package/src/core/sanitize/css.ts +26 -0
  114. package/src/core/sanitize/svg-upload.ts +276 -23
  115. package/src/core/sanitize/svg.ts +3 -3
  116. package/src/core/schema/descriptors.ts +4 -0
  117. package/src/core/schema/design.ts +8 -7
  118. package/src/core/schema/layout.ts +406 -18
  119. package/src/core/schema/style.ts +49 -1
  120. package/src/core/search-text.ts +70 -0
  121. package/src/core/shadowing-ids.ts +41 -0
  122. package/src/core/theme/conditions.ts +2 -1
  123. package/src/core/theme/float.ts +1 -0
  124. package/src/core/theme/parse-doc.ts +10 -5
  125. package/src/core/theme/popup-rules.ts +16 -0
  126. package/src/core/theme/triggers.ts +3 -2
  127. package/src/core/validate.ts +3 -2
  128. package/src/index.ts +23 -2
  129. package/src/mcp/ports.ts +18 -7
  130. package/src/mcp/proposals.ts +36 -11
  131. package/src/mcp/read.ts +2 -3
  132. package/src/mcp/tools.ts +1 -1
  133. package/src/server/agent-settings.ts +12 -1
  134. package/src/server/hooks.ts +41 -6
  135. package/src/server/icon-routes.ts +52 -12
  136. package/src/server/mcp-routes.ts +11 -5
  137. package/src/server/plugin.ts +27 -2
  138. package/src/server/presence.ts +5 -1
  139. package/src/server/proposals.ts +16 -4
  140. package/src/server/requests.ts +60 -11
  141. package/src/server/site-origin.ts +13 -0
  142. package/src/server/targets.ts +26 -0
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)
@@ -20,6 +20,7 @@ When an editor picks an icon, its SVG is stored with the page and shown inline o
20
20
  - Icons: Font Awesome Free by Fonticons, Inc., licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). Full text: [`licenses/fontawesome-free.LICENSE`](licenses/fontawesome-free.LICENSE).
21
21
  - Changes: the attribution comment in each SVG file is removed by EmVB's sanitizer, so this notice carries the attribution. Each path's `fill="currentColor"` moves to the root `<svg>`.
22
22
  - Brand icons are trademarks of their owners. Use them only to represent the company, product or service they refer to.
23
+ - The Social icons element (W-1024) ships 22 of these icons in the plugin itself (`src/core/icons/social.generated.ts`, built by `scripts/build-social-icons.ts` from the icon library's set), so public pages draw them without the library: 19 brand icons and the solid envelope, RSS and globe icons. Same license and changes as above.
23
24
 
24
25
  ## Tabler Icons
25
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perkyzz/emvb",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Visual page builder plugin for EmDash CMS",
5
5
  "keywords": [
6
6
  "astro",
@@ -40,6 +40,7 @@
40
40
  "./astro/floats": "./src/astro/floats/index.ts",
41
41
  "./astro/tabs": "./src/astro/tabs/index.ts",
42
42
  "./astro/menu": "./src/astro/menu/index.ts",
43
+ "./astro/widgets": "./src/astro/widgets/index.ts",
43
44
  "./mcp": "./src/mcp/index.ts"
44
45
  },
45
46
  "publishConfig": {
@@ -49,28 +50,28 @@
49
50
  "test:astro": "bun --bun vitest run"
50
51
  },
51
52
  "dependencies": {
52
- "@perkyzz/emvb-icons": "1.0.0",
53
+ "@perkyzz/emvb-icons": "1.2.0",
53
54
  "photocn": "0.1.2",
54
- "zod": "~4.5.4"
55
+ "zod": ">=4.5.4 <5"
55
56
  },
56
57
  "devDependencies": {
57
- "@cloudflare/kumo": "2.6.0",
58
- "@emdash-cms/plugin-forms": "0.2.12",
58
+ "@cloudflare/kumo": "2.15.0",
59
+ "@emdash-cms/plugin-forms": "0.2.13",
59
60
  "@phosphor-icons/react": "2.1.10",
60
61
  "@types/react": "19.3.0",
61
62
  "@types/react-dom": "19.3.0",
62
- "astro": "7.3.5",
63
- "emdash": "1.4.0",
63
+ "astro": "7.4.11",
64
+ "emdash": "1.5.0",
64
65
  "react": "19.3.1",
65
66
  "react-dom": "19.3.1",
66
67
  "vitest": "5.0.5"
67
68
  },
68
69
  "peerDependencies": {
69
- "@cloudflare/kumo": "2.6.0",
70
+ "@cloudflare/kumo": "2.6.0 || 2.15.0",
70
71
  "@emdash-cms/plugin-forms": "^0.2.9",
71
72
  "@phosphor-icons/react": "^2.1.10",
72
73
  "astro": "^7.0.0",
73
- "emdash": "^1.0.0",
74
+ "emdash": ">=1.4.0 <2",
74
75
  "react": "^19.0.0",
75
76
  "react-dom": "^19.0.0"
76
77
  },
@@ -25,7 +25,11 @@ export type AgentsState = {
25
25
 
26
26
  const base = `/_emdash/api/plugins/${PLUGIN_ID}`;
27
27
 
28
- export const loadAgents = (fetcher: Fetcher) => requestJson<AgentsState>(fetcher, `${base}/agents`);
28
+ /** S-05 (W-995): the server may send the endpoint's path alone; it is resolved against this page. */
29
+ export async function loadAgents(fetcher: Fetcher): Promise<AgentsState> {
30
+ const state = await requestJson<AgentsState>(fetcher, `${base}/agents`);
31
+ return { ...state, endpoint: new URL(state.endpoint, globalThis.location?.href).toString() };
32
+ }
29
33
 
30
34
  /** Saves the agent settings; the returned revision is the one the next save must send. */
31
35
  export async function saveAgentSettings(
@@ -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
 
@@ -143,6 +147,35 @@ export async function publishEntry(
143
147
  return { rev: body["_rev"], slug: body.item.slug ?? "" };
144
148
  }
145
149
 
150
+ /**
151
+ * W-1027: has EmDash publish the saved draft of entry `id` by itself at `at` (sent as ISO with
152
+ * its offset), or with `at` null cancels that. `rev` makes a stale draft fail with 409.
153
+ */
154
+ export async function scheduleEntry(
155
+ fetcher: Fetcher,
156
+ contentPath: string,
157
+ id: string,
158
+ at: Date | null,
159
+ rev: string | null,
160
+ ): Promise<{ rev: string; status: string; scheduledAt: string | null }> {
161
+ const path = `${contentPath}/${encodeURIComponent(id)}/schedule`;
162
+ const body = await requestJson<{
163
+ _rev: string;
164
+ item: { status?: string; scheduledAt?: string | null; draftRevisionId?: string | null };
165
+ }>(
166
+ fetcher,
167
+ path,
168
+ at
169
+ ? { method: "POST", body: { scheduledAt: at.toISOString(), ...(rev ? { _rev: rev } : {}) } }
170
+ : { method: "DELETE" },
171
+ );
172
+ return {
173
+ rev: body["_rev"],
174
+ status: entryStatus(body.item),
175
+ scheduledAt: body.item.scheduledAt ?? null,
176
+ };
177
+ }
178
+
146
179
  /**
147
180
  * Drops the saved draft of entry `id` so it is back to its published version (W-193). EmDash's
148
181
  * `discard-draft` checks `rev`, so a draft saved elsewhere meanwhile fails with 409.
@@ -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,
@@ -471,7 +482,11 @@ function EditorApp({
471
482
  {wideEnough ? (
472
483
  <>
473
484
  <TopBar
474
- page={{ title: state.page.title, status: state.status }}
485
+ page={{
486
+ title: state.page.title,
487
+ status: state.status,
488
+ scheduledAt: state.scheduledAt ?? null,
489
+ }}
475
490
  dirty={dirty}
476
491
  status={saver.status}
477
492
  busy={busy}
@@ -484,6 +499,7 @@ function EditorApp({
484
499
  stylesUnpublished={state.designUnpublished === true}
485
500
  canRevert={canRevert}
486
501
  onRevert={() => chrome.open("revert")}
502
+ {...(host.field ? {} : { onSchedule: () => chrome.open("schedule") })}
487
503
  {...(host.field ? { onApply: () => host.field?.apply(state.page.layout) } : {})}
488
504
  tools={
489
505
  <>
@@ -576,7 +592,8 @@ function EditorApp({
576
592
  <main className="emvb-canvas">
577
593
  <DeviceBar
578
594
  device={device}
579
- hidden={!!selectedNode?.hiddenOn?.includes(device)}
595
+ hidden={!!selectedNode && hiddenOnDevice(selectedNode, device)}
596
+ inherited={device === "wide" && !!selectedNode && !wideHideIsOwn(selectedNode)}
580
597
  canHide={!!hideOnDevice && !hideOnDevice.disabled}
581
598
  hideLabel={hideOnDevice?.label ?? `Hide on ${device}`}
582
599
  onDevice={setDevice}
@@ -693,7 +710,7 @@ function EditorApp({
693
710
  <FieldPreview
694
711
  open={fieldPreview}
695
712
  onOpenChange={setFieldPreview}
696
- device={device === "laptop" ? "desktop" : device}
713
+ device={device === "laptop" || device === "wide" ? "desktop" : device}
697
714
  render={renderFieldPreview}
698
715
  />
699
716
  )}