@perkyzz/emvb 0.9.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 (187) hide show
  1. package/README.md +10 -1
  2. package/package.json +2 -2
  3. package/src/admin/agents-api.ts +45 -0
  4. package/src/admin/bulk-api.ts +67 -0
  5. package/src/admin/content-api.ts +10 -6
  6. package/src/admin/copy-rich-text.ts +119 -0
  7. package/src/admin/dialog-tab-wrap.ts +78 -0
  8. package/src/admin/editor/A11yCopilot.tsx +3 -1
  9. package/src/admin/editor/Editor.tsx +311 -250
  10. package/src/admin/editor/Timeline.tsx +8 -3
  11. package/src/admin/editor/TopBar.tsx +29 -7
  12. package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
  13. package/src/admin/editor/canvas/DeviceBar.tsx +31 -10
  14. package/src/admin/editor/canvas/canvas-scale.ts +3 -3
  15. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  16. package/src/admin/editor/co-design.ts +190 -0
  17. package/src/admin/editor/dnd/new-element.ts +48 -4
  18. package/src/admin/editor/editor-chrome.tsx +8 -6
  19. package/src/admin/editor/editor-commands.ts +15 -4
  20. package/src/admin/editor/editor-css.ts +2 -1
  21. package/src/admin/editor/element-chrome.ts +3 -1
  22. package/src/admin/editor/extension-manifests.ts +20 -0
  23. package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
  24. package/src/admin/editor/extensions-context.tsx +27 -0
  25. package/src/admin/editor/feature-css.ts +17 -0
  26. package/src/admin/editor/palette-items.ts +2 -2
  27. package/src/admin/editor/panels/AddPanel.tsx +31 -1
  28. package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
  29. package/src/admin/editor/panels/ClassesSection.tsx +9 -6
  30. package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
  31. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  32. package/src/admin/editor/panels/ElementPanel.tsx +68 -20
  33. package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
  34. package/src/admin/editor/panels/LayersPanel.tsx +10 -6
  35. package/src/admin/editor/panels/LeftPanel.tsx +33 -5
  36. package/src/admin/editor/panels/PageSettings.tsx +4 -0
  37. package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
  38. package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
  39. package/src/admin/editor/panels/settings/BackgroundControls.tsx +72 -15
  40. package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
  41. package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
  42. package/src/admin/editor/panels/settings/EffectsControls.tsx +183 -10
  43. package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
  44. package/src/admin/editor/panels/settings/IconControls.tsx +25 -11
  45. package/src/admin/editor/panels/settings/LengthRow.tsx +63 -19
  46. package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
  47. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +19 -1
  48. package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
  49. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
  50. package/src/admin/editor/panels/settings/StyleRow.tsx +120 -13
  51. package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
  52. package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
  53. package/src/admin/editor/panels/settings/background-mode.ts +14 -11
  54. package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
  55. package/src/admin/editor/panels/settings/box-sides.ts +22 -14
  56. package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
  57. package/src/admin/editor/panels/settings/length-units.ts +68 -4
  58. package/src/admin/editor/panels/settings/query-style.ts +3 -3
  59. package/src/admin/editor/panels/settings/style-sections.ts +52 -10
  60. package/src/admin/editor/panels/style-target.ts +22 -7
  61. package/src/admin/editor/presence.ts +60 -0
  62. package/src/admin/editor/section-templates.ts +26 -4
  63. package/src/admin/editor/store.ts +14 -4
  64. package/src/admin/editor/useCoDesign.ts +177 -0
  65. package/src/admin/editor/useEditorCommands.ts +7 -5
  66. package/src/admin/editor/useExtensions.ts +45 -0
  67. package/src/admin/editor/useNodeActions.ts +18 -7
  68. package/src/admin/editor/useProposals.ts +81 -0
  69. package/src/admin/export-api.ts +221 -0
  70. package/src/admin/index.tsx +6 -1
  71. package/src/admin/languages-api.ts +61 -0
  72. package/src/admin/pages/AgentSetup.tsx +148 -0
  73. package/src/admin/pages/AgentsPage.tsx +9 -26
  74. package/src/admin/pages/CreateDialog.tsx +15 -0
  75. package/src/admin/pages/ExportDialog.tsx +395 -0
  76. package/src/admin/pages/ImportButton.tsx +18 -0
  77. package/src/admin/pages/ImportElementorDialog.tsx +669 -0
  78. package/src/admin/pages/ImportPageLinks.tsx +86 -0
  79. package/src/admin/pages/PageList.tsx +82 -3
  80. package/src/admin/pages/ThemePartList.tsx +52 -2
  81. package/src/admin/pages/bulk.tsx +303 -0
  82. package/src/admin/pages/section-head.tsx +27 -0
  83. package/src/admin/proposals-api.ts +91 -0
  84. package/src/admin/search.ts +20 -0
  85. package/src/admin/theme-api.ts +4 -0
  86. package/src/admin/ui.ts +50 -4
  87. package/src/admin/widgets/CanvasField.tsx +8 -0
  88. package/src/admin/widgets/ConvertToRichText.tsx +136 -0
  89. package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
  90. package/src/admin/widgets/convert-body.ts +73 -2
  91. package/src/astro/content-port.ts +14 -1
  92. package/src/astro/render.ts +6 -6
  93. package/src/astro/resolve-theme.ts +25 -8
  94. package/src/astro/resolve.ts +89 -2
  95. package/src/astro/tabs/runtime.ts +16 -6
  96. package/src/constants.ts +1 -1
  97. package/src/core/a11y/audit.ts +45 -14
  98. package/src/core/arrange.ts +5 -1
  99. package/src/core/bounded-array.ts +31 -0
  100. package/src/core/clipboard.ts +9 -0
  101. package/src/core/contract.ts +305 -0
  102. package/src/core/css/generate.ts +151 -20
  103. package/src/core/css/scope.ts +10 -2
  104. package/src/core/css/trace.ts +47 -13
  105. package/src/core/css-keywords.ts +51 -1
  106. package/src/core/design/cascade.ts +12 -9
  107. package/src/core/design/classes.ts +28 -9
  108. package/src/core/design/devices.ts +89 -13
  109. package/src/core/design/states.ts +5 -3
  110. package/src/core/design/transfer.ts +5 -0
  111. package/src/core/design/variables.ts +31 -5
  112. package/src/core/elements/dynamic-elements.ts +3 -3
  113. package/src/core/elements/index.ts +73 -9
  114. package/src/core/export/runtimes.generated.ts +9 -0
  115. package/src/core/export/site.ts +562 -0
  116. package/src/core/export/zip.ts +95 -0
  117. package/src/core/extensions/define.ts +13 -0
  118. package/src/core/extensions/index.ts +41 -0
  119. package/src/core/extensions/namespace.ts +82 -0
  120. package/src/core/extensions/normalize.ts +141 -0
  121. package/src/core/extensions/placeholder.ts +41 -0
  122. package/src/core/extensions/registry.ts +94 -0
  123. package/src/core/extensions/render-ext.ts +118 -0
  124. package/src/core/extensions/safe-nodes.ts +93 -0
  125. package/src/core/extensions/schema.ts +112 -0
  126. package/src/core/extensions/types.ts +159 -0
  127. package/src/core/forms/binding.ts +1 -1
  128. package/src/core/history/diff.ts +26 -1
  129. package/src/core/import/elementor/atomic.ts +1608 -0
  130. package/src/core/import/elementor/classes.ts +127 -0
  131. package/src/core/import/elementor/context.ts +429 -0
  132. package/src/core/import/elementor/counter-steps.ts +72 -0
  133. package/src/core/import/elementor/css.ts +445 -0
  134. package/src/core/import/elementor/html.ts +500 -0
  135. package/src/core/import/elementor/index.ts +967 -0
  136. package/src/core/import/elementor/inline-marks.ts +81 -0
  137. package/src/core/import/elementor/snapshots.ts +48 -0
  138. package/src/core/import/elementor/style.ts +429 -0
  139. package/src/core/import/elementor/values.ts +241 -0
  140. package/src/core/import/elementor/widgets.ts +1897 -0
  141. package/src/core/index.ts +96 -0
  142. package/src/core/json-schema.ts +114 -0
  143. package/src/core/limits.ts +19 -0
  144. package/src/core/migrate/index.ts +6 -1
  145. package/src/core/migrate/v18.ts +222 -0
  146. package/src/core/perf/meter.ts +42 -24
  147. package/src/core/portable-text-export.ts +243 -0
  148. package/src/core/proposals-safety.ts +102 -0
  149. package/src/core/proposals.ts +357 -0
  150. package/src/core/public-attributes.ts +30 -0
  151. package/src/core/recipes/index.ts +2 -2
  152. package/src/core/render/extras.ts +3 -3
  153. package/src/core/render/index.ts +222 -23
  154. package/src/core/render/loop.ts +1 -1
  155. package/src/core/render/section.ts +4 -4
  156. package/src/core/render/tabs.ts +18 -11
  157. package/src/core/render/vnode.ts +1 -1
  158. package/src/core/sanitize/css.ts +151 -10
  159. package/src/core/sanitize/motion.ts +116 -0
  160. package/src/core/saved-sections.ts +6 -0
  161. package/src/core/schema/descriptors.ts +3 -1
  162. package/src/core/schema/design.ts +4 -3
  163. package/src/core/schema/layout.ts +92 -16
  164. package/src/core/schema/style.ts +296 -112
  165. package/src/core/search-text.ts +70 -0
  166. package/src/core/text-marks.ts +227 -0
  167. package/src/core/theme/dynamic.ts +9 -4
  168. package/src/core/theme/float.ts +2 -0
  169. package/src/core/theme/popup-rules.ts +33 -1
  170. package/src/core/translatable.ts +34 -0
  171. package/src/core/validate.ts +13 -1
  172. package/src/index.ts +24 -0
  173. package/src/mcp/errors.ts +3 -1
  174. package/src/mcp/ports.ts +67 -0
  175. package/src/mcp/prompts.ts +1 -11
  176. package/src/mcp/proposals.ts +281 -0
  177. package/src/mcp/read.ts +10 -10
  178. package/src/mcp/tools.ts +71 -3
  179. package/src/mcp/write.ts +66 -11
  180. package/src/server/agent-settings.ts +5 -1
  181. package/src/server/icon-routes.ts +52 -12
  182. package/src/server/mcp-routes.ts +15 -0
  183. package/src/server/plugin.ts +35 -2
  184. package/src/server/presence.ts +78 -0
  185. package/src/server/proposals.ts +261 -0
  186. package/src/server/requests.ts +196 -0
  187. package/src/server/tools-served.ts +45 -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)
@@ -16,7 +25,7 @@ Library pictures can be cropped, adjusted, filtered and saved as a new media ite
16
25
  npm i @perkyzz/emvb
17
26
  ```
18
27
 
19
- Peers, which an EmDash 1.x site already has: `emdash` ^1.0.0, `astro` ^7, `react` and `react-dom` ^19, `@cloudflare/kumo` 2.6.0 and `@phosphor-icons/react` ^2.1.10. `@emdash-cms/plugin-forms` ^0.2.9 is optional and enables forms. EmVB currently supports Astro 7 up to 7.3.5: Astro 7.3.6 and later depend on zod ^4.6.5, while EmDash pins zod to exactly 4.5.4, and the second copy of zod breaks type checking of EmDash plugin routes. Keep your site on `astro` 7.3.5 for now; this will be widened once EmDash moves its zod pin.
28
+ Peers, which an EmDash 1.x site already has: `emdash` ^1.0.0, `astro` ^7, `react` and `react-dom` ^19, `@cloudflare/kumo` 2.6.0 and `@phosphor-icons/react` ^2.1.10. `@emdash-cms/plugin-forms` ^0.2.9 is optional and enables forms. Use the Astro version your EmDash site already has: EmVB is verified on a stock `create-emdash` 1.4.0 site, which installs Astro 7.4.7.
20
29
 
21
30
  Dependencies installed with it: `zod` and [`@perkyzz/emvb-icons`](https://www.npmjs.com/package/@perkyzz/emvb-icons), the icon sets for the editor's Icon library. Only the editor loads them; a placed icon is saved into the page as SVG.
22
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perkyzz/emvb",
3
- "version": "0.9.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": "0.9.0",
52
+ "@perkyzz/emvb-icons": "1.1.0",
53
53
  "photocn": "0.1.2",
54
54
  "zod": "~4.5.4"
55
55
  },
@@ -19,6 +19,8 @@ export type AgentsState = {
19
19
  revision: string | null;
20
20
  endpoint: string;
21
21
  activity: AgentActivity[];
22
+ /** W-932: an agent has used this EmVB version's tools through EmDash's endpoint. */
23
+ toolsServed?: boolean;
22
24
  };
23
25
 
24
26
  const base = `/_emdash/api/plugins/${PLUGIN_ID}`;
@@ -37,3 +39,46 @@ export async function saveAgentSettings(
37
39
  });
38
40
  return body.revision;
39
41
  }
42
+
43
+ /** W-932: what stands between this site and a working agent connection. */
44
+ export type AgentSetup = {
45
+ /** EmDash's MCP endpoint: off when `emdash({ mcp: true })` isn't set (the route 404s). */
46
+ endpoint: "on" | "off" | "unknown";
47
+ /**
48
+ * EmVB's tools: used through EmDash's endpoint since this version ("served"); approved on the
49
+ * Plugins screen but not used since ("approved": EmDash hides them after an update changes the
50
+ * list, until an admin approves again); not approved ("off"); or unknown.
51
+ */
52
+ tools: "served" | "approved" | "off" | "unknown";
53
+ };
54
+
55
+ /**
56
+ * W-932: checks EmDash's MCP route exists (it answers a signed-in browser 401, a missing route
57
+ * 404) and whether EmVB's tools are approved. Sends no token and never reads or shows one.
58
+ */
59
+ export async function checkAgentSetup(fetcher: Fetcher, served: boolean): Promise<AgentSetup> {
60
+ let endpoint: AgentSetup["endpoint"] = "unknown";
61
+ try {
62
+ const response = await fetcher("/_emdash/api/mcp", {
63
+ method: "POST",
64
+ headers: {
65
+ "content-type": "application/json",
66
+ accept: "application/json, text/event-stream",
67
+ },
68
+ body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "ping" }),
69
+ });
70
+ endpoint = response.status === 404 ? "off" : response.status < 500 ? "on" : "unknown";
71
+ } catch {
72
+ /* unknown */
73
+ }
74
+ if (endpoint === "off") return { endpoint, tools: "off" };
75
+ if (served) return { endpoint, tools: "served" };
76
+ const approved = await requestJson<{ item?: { mcpToolsEnabled?: boolean } }>(
77
+ fetcher,
78
+ `/_emdash/api/admin/plugins/${PLUGIN_ID}`,
79
+ ).then(
80
+ (data) => data.item?.mcpToolsEnabled,
81
+ () => undefined,
82
+ );
83
+ return { endpoint, tools: approved === undefined ? "unknown" : approved ? "approved" : "off" };
84
+ }
@@ -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,11 +75,13 @@ 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";
81
83
  if (layout && node.id === layout.root.id) return "Page";
82
- return node.label || ELEMENT_NAMES[node.type] || node.type;
84
+ return node.editorLabel || ELEMENT_NAMES[node.type] || node.type;
83
85
  };
84
86
  return (
85
87
  <Dialog.Root open={open} onOpenChange={onOpenChange}>