@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
@@ -0,0 +1,91 @@
1
+ import { PLUGIN_ID } from "../constants.ts";
2
+ import type { Proposal } from "../core/proposals.ts";
3
+ import { requestJson, type Fetcher } from "./api.ts";
4
+
5
+ /** W-930: an agent proposal waiting for review, as the plugin-local route returns it. */
6
+ export type PendingProposal = { id: string; createdAt: string; proposal: Proposal };
7
+
8
+ const BASE = `/_emdash/api/plugins/${PLUGIN_ID}/proposals`;
9
+
10
+ /** The page's proposals, newest first. Damaged records are left out by the server. */
11
+ export async function listProposals(
12
+ fetcher: Fetcher,
13
+ collection: string,
14
+ id: string,
15
+ ): Promise<PendingProposal[]> {
16
+ const data = await requestJson<{
17
+ items?: { id: string; record: { proposal: Proposal; createdAt: string } }[];
18
+ }>(fetcher, BASE, { method: "POST", body: { collection, id } });
19
+ return (data.items ?? []).map((item) => ({
20
+ id: item.id,
21
+ createdAt: item.record.createdAt,
22
+ proposal: item.record.proposal,
23
+ }));
24
+ }
25
+
26
+ /** Removes a proposal once every change in it was accepted or rejected (or on Reject all). */
27
+ export async function withdrawProposal(
28
+ fetcher: Fetcher,
29
+ id: string,
30
+ decision?: { accepted: number; rejected: number },
31
+ ): Promise<void> {
32
+ await requestJson(fetcher, `${BASE}/withdraw`, {
33
+ method: "POST",
34
+ body: decision ? { id, decision } : { id },
35
+ });
36
+ }
37
+
38
+ /** Labels the newest saved version "Via agent" in the timeline. */
39
+ export async function recordAccepted(
40
+ fetcher: Fetcher,
41
+ collection: string,
42
+ id: string,
43
+ accepted: number,
44
+ ): Promise<void> {
45
+ await requestJson(fetcher, `${BASE}/accepted`, {
46
+ method: "POST",
47
+ body: { target: { collection, id }, accepted },
48
+ });
49
+ }
50
+
51
+ /** W-931: a request the person wrote for their agent. */
52
+ export type AgentRequest = {
53
+ id: string;
54
+ prompt: string;
55
+ createdAt: string;
56
+ status: "open" | "answered";
57
+ proposalId?: string;
58
+ };
59
+
60
+ const REQUESTS = `/_emdash/api/plugins/${PLUGIN_ID}/requests`;
61
+
62
+ /** The page's requests, newest first, and when an agent last checked for requests. */
63
+ export async function listRequests(
64
+ fetcher: Fetcher,
65
+ collection: string,
66
+ id: string,
67
+ ): Promise<{ items: AgentRequest[]; agentSeenAt: string | null }> {
68
+ const data = await requestJson<{ items?: AgentRequest[]; agentSeenAt?: string | null }>(
69
+ fetcher,
70
+ REQUESTS,
71
+ { method: "POST", body: { collection, id } },
72
+ );
73
+ return { items: data.items ?? [], agentSeenAt: data.agentSeenAt ?? null };
74
+ }
75
+
76
+ export async function createRequest(
77
+ fetcher: Fetcher,
78
+ collection: string,
79
+ id: string,
80
+ prompt: string,
81
+ ): Promise<AgentRequest> {
82
+ const data = await requestJson<{ request: AgentRequest }>(fetcher, `${REQUESTS}/create`, {
83
+ method: "POST",
84
+ body: { target: { collection, id }, prompt },
85
+ });
86
+ return data.request;
87
+ }
88
+
89
+ export async function cancelRequest(fetcher: Fetcher, id: string): Promise<void> {
90
+ await requestJson(fetcher, `${REQUESTS}/cancel`, { method: "POST", body: { id } });
91
+ }
@@ -13,3 +13,23 @@ export function matchesSearch(query: string, ...fields: string[]): boolean {
13
13
  .filter(Boolean)
14
14
  .every((word) => haystack.includes(word));
15
15
  }
16
+
17
+ /**
18
+ * W-978: when `query` matches an item only through its content, a short piece of that content
19
+ * around the first word, so the list can say why the item is shown. Undefined otherwise.
20
+ */
21
+ export function contentSnippet(
22
+ query: string,
23
+ content: string | undefined,
24
+ ...fields: string[]
25
+ ): string | undefined {
26
+ if (!content || !query.trim() || matchesSearch(query, ...fields)) return undefined;
27
+ const words = fold(query).split(/\s+/).filter(Boolean);
28
+ const folded = fold(content);
29
+ const at = Math.min(...words.map((w) => folded.indexOf(w)).filter((i) => i >= 0));
30
+ if (!Number.isFinite(at)) return undefined;
31
+ // Folding can change lengths (ß → ss); close enough for a preview.
32
+ const start = Math.max(0, at - 30);
33
+ const end = Math.min(content.length, at + 60);
34
+ return `${start > 0 ? "…" : ""}${content.slice(start, end).trim()}${end < content.length ? "…" : ""}`;
35
+ }
@@ -6,6 +6,7 @@ import {
6
6
  parseThemePartType,
7
7
  starterLayout,
8
8
  THEME_PART_TYPE_LABELS,
9
+ layoutSearchText,
9
10
  validateLayout,
10
11
  type ConditionsDoc,
11
12
  type FloatSettings,
@@ -28,6 +29,8 @@ export type ThemePartSummary = {
28
29
  status: string;
29
30
  updatedAt: string;
30
31
  conditionsSummary: string;
32
+ /** W-978: the layout's words, for searching by content. */
33
+ text?: string;
31
34
  };
32
35
 
33
36
  export type ThemePartDraft = {
@@ -136,6 +139,7 @@ export async function listThemeParts(fetcher: Fetcher): Promise<ThemePartSummary
136
139
  // UX-061: reusable parts never match a location, so say where they're used instead.
137
140
  conditionsSummary:
138
141
  ITEM_PART_USE_SHORT[partTypeOf(item)] ?? summarizeConditions(item.data?.["conditions"]),
142
+ text: layoutSearchText(item.data?.["layout"]),
139
143
  }));
140
144
  }
141
145
 
package/src/admin/ui.ts CHANGED
@@ -82,6 +82,11 @@ export const UI_CSS = `
82
82
  .emvb-list-loading .skeleton-line { background: var(--color-kumo-tint); }
83
83
  .emvb-list-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
84
84
  .emvb-list-search { max-width: 320px; margin: 12px 0; }
85
+ .emvb-bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; }
86
+ .emvb-bulk-count { font-weight: 600; margin-inline-end: 4px; }
87
+ .emvb-bulk-bar [data-emvb-bulk-status] { flex-basis: 100%; margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
88
+ .emvb-surface-card[data-emvb-list] .emvb-row-select { width: 48px; padding-inline-end: 0; }
89
+ .emvb-row-found { margin-top: 2px; font-size: 12px; color: var(--text-color-kumo-subtle, inherit); overflow-wrap: anywhere; }
85
90
  .emvb-page-title { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 600; color: var(--text-color-kumo-default); }
86
91
  .emvb-row-title { color: var(--text-color-kumo-default); font-size: 14px; line-height: 20px; font-weight: 600; text-decoration: none; }
87
92
  .emvb-row-title:hover { text-decoration: underline; text-underline-offset: 2px; }
@@ -91,8 +96,9 @@ export const UI_CSS = `
91
96
  .emvb-row-title, .emvb-row-slug { overflow-wrap: anywhere; }
92
97
  /* UX-018: on narrow admin widths the short columns keep one line and the title keeps a readable
93
98
  width; the card scrolls sideways before anything breaks mid-word or mid-date. */
94
- .emvb-surface-card[data-emvb-list] :is(th, td):not(:first-child) { white-space: nowrap; }
95
- .emvb-surface-card[data-emvb-list] td:first-child { min-width: 180px; }
99
+ /* W-978: the title column wraps and keeps a minimum width; it follows the tick-box column. */
100
+ .emvb-surface-card[data-emvb-list] :is(th, td):not(:first-child):not(:has(> .emvb-row-title)) { white-space: nowrap; }
101
+ .emvb-surface-card[data-emvb-list] td:has(> .emvb-row-title) { min-width: 180px; }
96
102
  .emvb-tabular { font-variant-numeric: tabular-nums; color: var(--text-color-kumo-subtle); font-size: 13px; }
97
103
 
98
104
  /* Elevated EmVB-owned card chrome (lists, empty/setup shells) — not host sidebar/header */
@@ -123,6 +129,12 @@ export const UI_CSS = `
123
129
  .emvb-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
124
130
  .emvb-agents-section h3 { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; line-height: 20px; font-weight: 600; color: var(--text-color-kumo-default); }
125
131
  .emvb-agents-section p { margin: 0; font-size: 14px; line-height: 20px; color: var(--text-color-kumo-subtle); }
132
+ /* W-932: setup checklist */
133
+ .emvb-agents-steps { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
134
+ .emvb-agents-steps li { display: flex; align-items: flex-start; gap: 10px; }
135
+ .emvb-agents-step-icon { display: inline-flex; flex: none; margin-block-start: 1px; color: var(--text-color-kumo-subtle); }
136
+ .emvb-agents-steps li[data-state="done"] .emvb-agents-step-icon { color: var(--text-color-kumo-success, var(--color-kumo-brand)); }
137
+ .emvb-agents-steps li[data-state="todo"] .emvb-agents-step-icon { color: var(--text-color-kumo-warning, var(--text-color-kumo-default)); }
126
138
  .emvb-agents-section code { padding: 1px 5px; border-radius: 4px; background: var(--color-kumo-tint); font-family: var(--font-mono); font-size: 12px; }
127
139
  .emvb-agents-option { display: grid; gap: 4px; padding-top: 16px; border-top: 1px solid var(--color-kumo-line); }
128
140
  .emvb-agents-option > p { padding-inline-start: 44px; font-size: 13px; }
@@ -147,6 +159,8 @@ export const UI_CSS = `
147
159
  .emvb-surface-card[data-emvb-list] tbody tr:hover { background: var(--color-kumo-tint); }
148
160
  .emvb-surface-card[data-emvb-list] tbody tr:hover .emvb-row-title { text-decoration: underline; text-underline-offset: 2px; }
149
161
  .emvb-surface-card[data-emvb-list] .emvb-row-title::after { content: ""; position: absolute; inset: 0; }
162
+ /* W-978: the row's tick box sits above the stretched title link, so it can be clicked. */
163
+ .emvb-surface-card[data-emvb-list] .emvb-row-select > * { position: relative; z-index: 1; }
150
164
  .emvb-surface-card .emvb-empty-shell,
151
165
  .emvb-empty-shell {
152
166
  display: flex;
@@ -224,12 +238,44 @@ export const UI_CSS = `
224
238
  }
225
239
 
226
240
  /* EmVB-owned dialog body (Kumo Dialog keeps host radius/shadow) */
227
- .emvb-dialog { display: flex; flex-direction: column; gap: 10px; }
228
- .emvb-dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
241
+ /* A long dialog (Import from Elementor with its report and options) scrolls inside the screen,
242
+ with its actions kept in view at the bottom. */
243
+ .emvb-dialog { display: flex; flex-direction: column; gap: 10px; max-height: calc(100dvh - 96px); overflow-y: auto; overscroll-behavior: contain; margin: -4px; padding: 4px; }
244
+ .emvb-dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; padding-top: 8px; background: var(--color-kumo-base); }
229
245
  /* UX-023: selects in EmVB dialogs line up with the full-width fields under them. */
230
246
  .emvb-dialog .emvb-field { width: 100%; }
231
247
  .emvb-create-fields { display: flex; flex-direction: column; gap: 10px; min-width: 0; margin: 0; padding: 0; border: 0; }
232
248
  .emvb-create-status { min-height: 18px; }
249
+ /* W-945: Import from Elementor. The JSON box keeps its rows; the report scrolls on its own. */
250
+ .emvb-export-fields { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
251
+ .emvb-import-source { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
252
+ .emvb-import-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
253
+ .emvb-import-label { font-size: 14px; font-weight: 500; color: var(--text-color-kumo-default); }
254
+ .emvb-marks { display: grid; gap: 6px; min-width: 0; }
255
+ .emvb-marks-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
256
+ .emvb-marks-color { display: inline-flex; align-items: center; gap: 6px; }
257
+ .emvb-marks-color input { inline-size: 32px; block-size: 32px; padding: 0; border: 1px solid var(--color-kumo-line); border-radius: 6px; background: transparent; }
258
+ .emvb-marks-link { display: grid; gap: 6px; }
259
+ .emvb-marks-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
260
+ .emvb-marks-list li { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
261
+ .emvb-import-links { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 0; border: 0; }
262
+ .emvb-import-links > legend { padding: 0; margin-bottom: 4px; }
263
+ .emvb-dialog .emvb-field.emvb-import-json {
264
+ height: auto; min-height: 84px; padding: 8px; resize: vertical;
265
+ font-family: var(--font-mono); font-size: 12px; line-height: 1.4;
266
+ }
267
+ .emvb-import-report {
268
+ max-height: 220px; overflow: auto; overscroll-behavior: contain;
269
+ display: flex; flex-direction: column; gap: 6px;
270
+ padding: 8px 10px; border-radius: 6px; box-shadow: var(--emvb-elevation-s);
271
+ font-size: 13px; line-height: 1.35; color: var(--text-color-kumo-default);
272
+ }
273
+ .emvb-import-report:focus-visible { outline: 2px solid var(--color-kumo-brand, currentColor); outline-offset: 2px; }
274
+ .emvb-import-report summary { cursor: pointer; font-weight: 600; }
275
+ .emvb-import-report ul { margin: 4px 0 0; padding-inline-start: 18px; display: flex; flex-direction: column; gap: 2px; }
276
+ .emvb-import-report li { overflow-wrap: anywhere; }
277
+ .emvb-import-summary { font-weight: 600; }
278
+ .emvb-list-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
233
279
  /* UX-090: 16 px so the title stands above the 14 px field labels under it. */
234
280
  .emvb-dialog :is(h2, [data-slot="title"]) {
235
281
  margin: 0;
@@ -11,6 +11,8 @@ import { EditorHostContext, type EditorHost } from "../editor/host.ts";
11
11
  import { layerPreview } from "../editor/panels/LayersPanel.tsx";
12
12
  import { BUTTON, SOLID_PRIMARY } from "../ui.ts";
13
13
  import { convertEntryBody, hostEntryFromLocation } from "./convert-body.ts";
14
+ import { ConvertToRichText } from "./ConvertToRichText.tsx";
15
+ import { ExportEntryHtml } from "./ExportEntryHtml.tsx";
14
16
  import { createFieldFetcher, FIELD_ENTRY_ID, readFieldLayout } from "./field-fetcher.ts";
15
17
  import type { FieldWidgetProps } from "./LayoutField.tsx";
16
18
 
@@ -178,6 +180,12 @@ export function CanvasField({
178
180
  Convert to EmVB
179
181
  </Button>
180
182
  )}
183
+ {entry && layout && !unreadable && (layout.root.children ?? []).length > 0 && (
184
+ <ConvertToRichText fetcher={fetcher} entry={entry} layout={layout} />
185
+ )}
186
+ {entry && layout && !unreadable && (layout.root.children ?? []).length > 0 && (
187
+ <ExportEntryHtml fetcher={fetcher} entry={entry} />
188
+ )}
181
189
  </div>
182
190
  )}
183
191
  {(convert.state === "done" || convert.state === "error") && (
@@ -0,0 +1,136 @@
1
+ import { Button, Dialog, Loader } from "@cloudflare/kumo";
2
+ import { TextAlignLeftIcon } from "@phosphor-icons/react";
3
+ import * as React from "react";
4
+ import type { Layout } from "../../core/index.ts";
5
+ import type { Fetcher } from "../api.ts";
6
+ import { DialogCloseButton } from "../editor/DialogCloseButton.tsx";
7
+ import { BUTTON, SOLID_DESTRUCTIVE, UI_CSS } from "../ui.ts";
8
+ import { planRichText, writeRichText, type RichTextPlan } from "./convert-body.ts";
9
+
10
+ type Plan = Extract<RichTextPlan, { ok: true }>;
11
+
12
+ const plural = (n: number, one: string) => `${n} ${n === 1 ? one : `${one}s`}`;
13
+
14
+ /** "form, 2 icons", for what a conversion leaves out. */
15
+ export function leftOutText(skipped: Record<string, number>): string {
16
+ return Object.entries(skipped)
17
+ .map(([type, n]) => (n === 1 ? type : `${n} ${type}s`))
18
+ .join(", ");
19
+ }
20
+
21
+ /**
22
+ * W-963: Convert to rich text, the way out of a canvas field. The layout's words, headings, lists,
23
+ * links and images replace the entry's rich-text field, after a confirm that says what is kept and
24
+ * what is left out. The layout itself is untouched; the entry reloads so its form shows the result.
25
+ */
26
+ export function ConvertToRichText({
27
+ fetcher,
28
+ entry,
29
+ layout,
30
+ reload = () => window.location.reload(),
31
+ }: {
32
+ fetcher: Fetcher;
33
+ entry: { collection: string; id: string };
34
+ layout: Layout;
35
+ reload?: () => void;
36
+ }) {
37
+ const [state, setState] = React.useState<
38
+ | { kind: "idle" }
39
+ | { kind: "planning" }
40
+ | { kind: "confirm" | "writing"; plan: Plan }
41
+ | { kind: "error"; message: string }
42
+ >({ kind: "idle" });
43
+
44
+ const start = async () => {
45
+ setState({ kind: "planning" });
46
+ try {
47
+ const plan = await planRichText(fetcher, entry, layout);
48
+ setState(plan.ok ? { kind: "confirm", plan } : { kind: "error", message: plan.message });
49
+ } catch {
50
+ setState({ kind: "error", message: "The entry couldn't be read. Try again." });
51
+ }
52
+ };
53
+ const write = async (plan: Plan) => {
54
+ setState({ kind: "writing", plan });
55
+ try {
56
+ await writeRichText(fetcher, entry, plan);
57
+ reload();
58
+ } catch (error) {
59
+ setState({
60
+ kind: "error",
61
+ message: `The ${plan.field} field wasn't changed: ${error instanceof Error ? error.message : String(error)}`,
62
+ });
63
+ }
64
+ };
65
+ const plan = state.kind === "confirm" || state.kind === "writing" ? state.plan : null;
66
+ const writing = state.kind === "writing";
67
+ const leftOut = plan ? leftOutText(plan.skipped) : "";
68
+
69
+ return (
70
+ <>
71
+ <Button
72
+ variant="secondary"
73
+ className={BUTTON}
74
+ icon={
75
+ state.kind === "planning" ? (
76
+ <Loader size={14} />
77
+ ) : (
78
+ <TextAlignLeftIcon aria-hidden="true" />
79
+ )
80
+ }
81
+ disabled={state.kind === "planning"}
82
+ onClick={() => void start()}
83
+ data-emvb-convert-rich-text=""
84
+ >
85
+ Convert to rich text
86
+ </Button>
87
+ {state.kind === "error" && (
88
+ <p className="emvb-canvas-convert-note" role="alert" data-emvb-convert="error">
89
+ {state.message}
90
+ </p>
91
+ )}
92
+ <Dialog.Root
93
+ open={plan !== null}
94
+ onOpenChange={(open) => {
95
+ if (!open && !writing) setState({ kind: "idle" });
96
+ }}
97
+ >
98
+ <Dialog size="base" className="p-6">
99
+ <style>{UI_CSS}</style>
100
+ <div data-emvb-dialog="convert-rich-text" className="emvb-dialog">
101
+ <Dialog.Title>Copy this layout into {plan?.field}?</Dialog.Title>
102
+ <Dialog.Description>
103
+ {plan &&
104
+ `${plural(plan.body.length, "block")} of words, headings, lists, links and images go into the entry's ${plan.field} field${plan.replaces ? ", replacing what it holds now" : ""}. The design (colours, columns, spacing) doesn't come across.`}
105
+ </Dialog.Description>
106
+ {plan && leftOut && (
107
+ <p className="emvb-helper" data-emvb-left-out="">
108
+ Left out: {leftOut}.
109
+ </p>
110
+ )}
111
+ <p className="emvb-helper">
112
+ The layout stays as it is. Save your other changes to this entry first: it reloads
113
+ afterwards. To show the rich text on your site, clear the layout and save the entry.
114
+ </p>
115
+ <div className="emvb-dialog-actions">
116
+ <DialogCloseButton>Cancel</DialogCloseButton>
117
+ <Button
118
+ variant={plan?.replaces ? "destructive" : "primary"}
119
+ className={BUTTON}
120
+ {...(plan?.replaces ? { style: SOLID_DESTRUCTIVE } : {})}
121
+ icon={writing ? <Loader size={14} /> : undefined}
122
+ aria-disabled={writing}
123
+ aria-busy={writing}
124
+ onClick={() => {
125
+ if (plan && !writing) void write(plan);
126
+ }}
127
+ >
128
+ {plan?.replaces ? `Replace ${plan.field}` : `Copy into ${plan?.field ?? "field"}`}
129
+ </Button>
130
+ </div>
131
+ </div>
132
+ </Dialog>
133
+ </Dialog.Root>
134
+ </>
135
+ );
136
+ }
@@ -0,0 +1,92 @@
1
+ import { Button, Loader } from "@cloudflare/kumo";
2
+ import { DownloadSimpleIcon } from "@phosphor-icons/react";
3
+ import * as React from "react";
4
+ import type { Fetcher } from "../api.ts";
5
+ import { canvasSources, exportSite } from "../export-api.ts";
6
+ import { downloadBlob } from "../image-editor/flatten.ts";
7
+ import { BUTTON } from "../ui.ts";
8
+
9
+ /**
10
+ * W-977: Export HTML on an entry's Canvas card. Downloads the entry's published layout as a zip
11
+ * of HTML and CSS, with the header, footer, popups and floats it shows, the same as Export pages
12
+ * does for EmVB pages.
13
+ */
14
+ export function ExportEntryHtml({
15
+ fetcher,
16
+ entry,
17
+ origin = window.location.origin,
18
+ }: {
19
+ fetcher: Fetcher;
20
+ entry: { collection: string; id: string };
21
+ origin?: string;
22
+ }) {
23
+ const [state, setState] = React.useState<
24
+ { kind: "idle" } | { kind: "busy" } | { kind: "done" | "error"; message: string }
25
+ >({ kind: "idle" });
26
+ const run = async () => {
27
+ setState({ kind: "busy" });
28
+ try {
29
+ const source = (await canvasSources(fetcher)).find((s) => s.collection === entry.collection);
30
+ if (!source) {
31
+ setState({ kind: "error", message: "This collection has no EmVB layout field to export." });
32
+ return;
33
+ }
34
+ const date = new Date().toISOString().slice(0, 10);
35
+ const result = await exportSite(fetcher, {
36
+ source,
37
+ onlyPageId: entry.id,
38
+ copyMedia: true,
39
+ origin,
40
+ date,
41
+ });
42
+ const page = result.site.report.pages[0];
43
+ if (!page) {
44
+ setState({
45
+ kind: "error",
46
+ message:
47
+ "Only the published version is exported, and this entry has no published layout yet. Publish it first.",
48
+ });
49
+ return;
50
+ }
51
+ downloadBlob(
52
+ new Blob([result.zip as Uint8Array<ArrayBuffer>], { type: "application/zip" }),
53
+ `emvb-export-${page.path.replace(/\/$/, "")}-${date}.zip`,
54
+ );
55
+ setState({
56
+ kind: "done",
57
+ message:
58
+ "Downloaded the published layout as HTML and CSS. EXPORT-REPORT.md in the zip lists what only works on the live site.",
59
+ });
60
+ } catch (error) {
61
+ setState({
62
+ kind: "error",
63
+ message: `The export didn't finish: ${error instanceof Error ? error.message : String(error)}. Try again.`,
64
+ });
65
+ }
66
+ };
67
+ return (
68
+ <>
69
+ <Button
70
+ variant="secondary"
71
+ className={BUTTON}
72
+ icon={
73
+ state.kind === "busy" ? <Loader size={14} /> : <DownloadSimpleIcon aria-hidden="true" />
74
+ }
75
+ disabled={state.kind === "busy"}
76
+ onClick={() => void run()}
77
+ data-emvb-export-entry=""
78
+ >
79
+ Export HTML
80
+ </Button>
81
+ {(state.kind === "done" || state.kind === "error") && (
82
+ <p
83
+ className="emvb-canvas-convert-note"
84
+ role={state.kind === "error" ? "alert" : "status"}
85
+ data-emvb-export-entry-status={state.kind}
86
+ >
87
+ {state.message}
88
+ </p>
89
+ )}
90
+ </>
91
+ );
92
+ }
@@ -1,5 +1,13 @@
1
- import { portableTextToLayout, type Layout } from "../../core/index.ts";
2
- import { requestJson, type Fetcher } from "../api.ts";
1
+ import {
2
+ collectSectionPartIds,
3
+ portableTextToLayout,
4
+ validateLayout,
5
+ type Layout,
6
+ } from "../../core/index.ts";
7
+ import { layoutToPortableText, type PortableTextBlock } from "../../core/portable-text-export.ts";
8
+ import { THEME_PARTS_COLLECTION } from "../../constants.ts";
9
+ import { listAllItems, requestJson, type Fetcher } from "../api.ts";
10
+ import type { ContentItem } from "../content-item.ts";
3
11
  import { readCollection } from "../setup/run.ts";
4
12
 
5
13
  const SLUG = /^[a-z][a-z0-9_-]{0,63}$/;
@@ -52,3 +60,66 @@ export async function convertEntryBody(
52
60
  return { ok: false, message: "Nothing in the saved body could be converted." };
53
61
  return { ok: true, ...result, field: field.slug };
54
62
  }
63
+
64
+ export type RichTextPlan =
65
+ | {
66
+ ok: true;
67
+ field: string;
68
+ body: PortableTextBlock[];
69
+ converted: number;
70
+ skipped: Record<string, number>;
71
+ /** The field already holds content that this replaces. */
72
+ replaces: boolean;
73
+ }
74
+ | { ok: false; message: string };
75
+
76
+ /**
77
+ * W-963: the reverse of Convert to EmVB, planned but not written: the layout as rich text for the
78
+ * entry's first Portable Text field (`content` first), with synced sections resolved.
79
+ */
80
+ export async function planRichText(
81
+ fetcher: Fetcher,
82
+ entry: { collection: string; id: string },
83
+ layout: Layout,
84
+ ): Promise<RichTextPlan> {
85
+ const schema = await readCollection(fetcher, entry.collection);
86
+ const rich = (schema?.fields ?? []).filter((f) => f.type === "portableText");
87
+ const field = rich.find((f) => f.slug === "content") ?? rich[0];
88
+ if (!field)
89
+ return { ok: false, message: "This collection has no rich-text field to convert into." };
90
+ const [data, parts] = await Promise.all([
91
+ requestJson<{ item: { data?: Record<string, unknown> } }>(fetcher, entryPath(entry)),
92
+ collectSectionPartIds(layout).length > 0
93
+ ? listAllItems<ContentItem>(fetcher, `/_emdash/api/content/${THEME_PARTS_COLLECTION}`)
94
+ : Promise.resolve([]),
95
+ ]);
96
+ const sectionTemplates: Record<string, Layout> = {};
97
+ for (const part of parts) {
98
+ if (part.status !== "published" || part.data?.["part_type"] !== "section") continue;
99
+ const checked = validateLayout(part.data["layout"]);
100
+ if (checked.ok) sectionTemplates[part.id] = checked.layout;
101
+ }
102
+ const result = layoutToPortableText(layout, { sectionTemplates });
103
+ if (result.body.length === 0)
104
+ return { ok: false, message: "This layout has no words or images to convert." };
105
+ const current = data.item.data?.[field.slug];
106
+ const replaces =
107
+ (Array.isArray(current) && current.length > 0) ||
108
+ (typeof current === "string" && current.trim() !== "" && current.trim() !== "[]");
109
+ return { ok: true, field: field.slug, ...result, replaces };
110
+ }
111
+
112
+ /** Writes a planned body into the entry's rich-text field. Nothing else on the entry changes. */
113
+ export async function writeRichText(
114
+ fetcher: Fetcher,
115
+ entry: { collection: string; id: string },
116
+ plan: Extract<RichTextPlan, { ok: true }>,
117
+ ): Promise<void> {
118
+ await requestJson(fetcher, entryPath(entry), {
119
+ method: "PUT",
120
+ body: { data: { [plan.field]: plan.body } },
121
+ });
122
+ }
123
+
124
+ const entryPath = (entry: { collection: string; id: string }) =>
125
+ `/_emdash/api/content/${encodeURIComponent(entry.collection)}/${encodeURIComponent(entry.id)}`;
@@ -1,4 +1,12 @@
1
- import { decodeSlug, getEmDashCollection, getEmDashEntry, getSiteSettings, getTerm } from "emdash";
1
+ import {
2
+ decodeSlug,
3
+ getEmDashCollection,
4
+ getEmDashEntry,
5
+ getI18nConfig,
6
+ getSiteSettings,
7
+ getTerm,
8
+ getTranslations,
9
+ } from "emdash";
2
10
  import { getPublicPluginApiRouteHandler } from "emdash/plugin-utils";
3
11
 
4
12
  /**
@@ -12,6 +20,9 @@ export type ContentPort = {
12
20
  getTerm: typeof getTerm;
13
21
  getSiteSettings: typeof getSiteSettings;
14
22
  pluginHandler: typeof getPublicPluginApiRouteHandler;
23
+ /** W-937: an entry's languages, for the Language switcher. Optional for older fakes. */
24
+ getTranslations?: typeof getTranslations;
25
+ getI18nConfig?: typeof getI18nConfig;
15
26
  };
16
27
 
17
28
  export const emdashContent: ContentPort = {
@@ -21,4 +32,6 @@ export const emdashContent: ContentPort = {
21
32
  getTerm,
22
33
  getSiteSettings,
23
34
  pluginHandler: getPublicPluginApiRouteHandler,
35
+ getTranslations,
36
+ getI18nConfig,
24
37
  };
@@ -19,6 +19,8 @@ export type RenderedPage = {
19
19
  needsMenuRuntime: boolean;
20
20
  /** The site's text direction when set, for the host's `<html dir>` (W-230). */
21
21
  dir?: "ltr" | "rtl" | "auto";
22
+ /** W-971: the element types whose base rules `css` holds, for `sharedPartCss`. */
23
+ baseTypes?: string[];
22
24
  };
23
25
 
24
26
  /** The design document through the in-process public route (no HTTP round trip, D-013). */
@@ -92,17 +94,14 @@ export function renderStored(
92
94
  ...(design.direction ? { dir: design.direction } : {}),
93
95
  };
94
96
  }
95
- const { html, css, needsFormsRuntime, needsTabsRuntime, needsMenuRuntime } = renderPage(
96
- layout,
97
- design,
98
- {
97
+ const { html, css, needsFormsRuntime, needsTabsRuntime, needsMenuRuntime, baseTypes } =
98
+ renderPage(layout, design, {
99
99
  formDefinitions,
100
100
  dynamic,
101
101
  scope: pageId,
102
102
  ...(partIds ? { partIds } : {}),
103
103
  ...(lang ? { lang } : {}),
104
- },
105
- );
104
+ });
106
105
  return {
107
106
  html,
108
107
  css,
@@ -110,5 +109,6 @@ export function renderStored(
110
109
  needsTabsRuntime,
111
110
  needsMenuRuntime,
112
111
  ...(design.direction ? { dir: design.direction } : {}),
112
+ baseTypes,
113
113
  };
114
114
  }