@perkyzz/emvb 0.9.0 → 1.0.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 (160) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -2
  3. package/src/admin/agents-api.ts +45 -0
  4. package/src/admin/editor/A11yCopilot.tsx +1 -1
  5. package/src/admin/editor/Editor.tsx +297 -248
  6. package/src/admin/editor/Timeline.tsx +2 -1
  7. package/src/admin/editor/TopBar.tsx +4 -2
  8. package/src/admin/editor/canvas/CanvasFrame.tsx +2 -2
  9. package/src/admin/editor/canvas/DeviceBar.tsx +17 -9
  10. package/src/admin/editor/canvas/canvas-scale.ts +2 -2
  11. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  12. package/src/admin/editor/co-design.ts +190 -0
  13. package/src/admin/editor/dnd/new-element.ts +26 -4
  14. package/src/admin/editor/editor-chrome.tsx +3 -3
  15. package/src/admin/editor/editor-commands.ts +8 -3
  16. package/src/admin/editor/element-chrome.ts +3 -1
  17. package/src/admin/editor/extension-manifests.ts +20 -0
  18. package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
  19. package/src/admin/editor/extensions-context.tsx +27 -0
  20. package/src/admin/editor/feature-css.ts +17 -0
  21. package/src/admin/editor/palette-items.ts +2 -2
  22. package/src/admin/editor/panels/AddPanel.tsx +31 -1
  23. package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
  24. package/src/admin/editor/panels/ClassesSection.tsx +9 -6
  25. package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
  26. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  27. package/src/admin/editor/panels/ElementPanel.tsx +49 -14
  28. package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
  29. package/src/admin/editor/panels/LayersPanel.tsx +10 -6
  30. package/src/admin/editor/panels/LeftPanel.tsx +33 -5
  31. package/src/admin/editor/panels/PageSettings.tsx +4 -0
  32. package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
  33. package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
  34. package/src/admin/editor/panels/settings/BackgroundControls.tsx +72 -15
  35. package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
  36. package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
  37. package/src/admin/editor/panels/settings/EffectsControls.tsx +104 -9
  38. package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
  39. package/src/admin/editor/panels/settings/IconControls.tsx +14 -11
  40. package/src/admin/editor/panels/settings/LengthRow.tsx +27 -16
  41. package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
  42. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  43. package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
  44. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
  45. package/src/admin/editor/panels/settings/StyleRow.tsx +113 -13
  46. package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
  47. package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
  48. package/src/admin/editor/panels/settings/background-mode.ts +14 -11
  49. package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
  50. package/src/admin/editor/panels/settings/box-sides.ts +22 -14
  51. package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
  52. package/src/admin/editor/panels/settings/length-units.ts +53 -1
  53. package/src/admin/editor/panels/settings/query-style.ts +3 -3
  54. package/src/admin/editor/panels/settings/style-sections.ts +51 -10
  55. package/src/admin/editor/panels/style-target.ts +9 -7
  56. package/src/admin/editor/presence.ts +60 -0
  57. package/src/admin/editor/store.ts +6 -2
  58. package/src/admin/editor/useCoDesign.ts +177 -0
  59. package/src/admin/editor/useEditorCommands.ts +4 -4
  60. package/src/admin/editor/useExtensions.ts +45 -0
  61. package/src/admin/editor/useNodeActions.ts +15 -6
  62. package/src/admin/editor/useProposals.ts +81 -0
  63. package/src/admin/languages-api.ts +61 -0
  64. package/src/admin/pages/AgentSetup.tsx +148 -0
  65. package/src/admin/pages/AgentsPage.tsx +9 -26
  66. package/src/admin/pages/CreateDialog.tsx +15 -0
  67. package/src/admin/pages/ImportButton.tsx +18 -0
  68. package/src/admin/pages/ImportElementorDialog.tsx +669 -0
  69. package/src/admin/pages/ImportPageLinks.tsx +86 -0
  70. package/src/admin/pages/PageList.tsx +15 -1
  71. package/src/admin/pages/ThemePartList.tsx +15 -1
  72. package/src/admin/pages/section-head.tsx +27 -0
  73. package/src/admin/proposals-api.ts +91 -0
  74. package/src/admin/ui.ts +39 -2
  75. package/src/astro/content-port.ts +14 -1
  76. package/src/astro/resolve-theme.ts +14 -1
  77. package/src/astro/resolve.ts +89 -2
  78. package/src/constants.ts +1 -1
  79. package/src/core/a11y/audit.ts +44 -14
  80. package/src/core/arrange.ts +5 -1
  81. package/src/core/bounded-array.ts +31 -0
  82. package/src/core/clipboard.ts +9 -0
  83. package/src/core/contract.ts +285 -0
  84. package/src/core/css/generate.ts +89 -20
  85. package/src/core/css/trace.ts +18 -9
  86. package/src/core/css-keywords.ts +51 -1
  87. package/src/core/design/cascade.ts +12 -9
  88. package/src/core/design/classes.ts +4 -5
  89. package/src/core/design/devices.ts +13 -13
  90. package/src/core/design/states.ts +5 -3
  91. package/src/core/design/transfer.ts +5 -0
  92. package/src/core/design/variables.ts +17 -4
  93. package/src/core/elements/dynamic-elements.ts +3 -3
  94. package/src/core/elements/index.ts +73 -9
  95. package/src/core/extensions/define.ts +13 -0
  96. package/src/core/extensions/index.ts +41 -0
  97. package/src/core/extensions/namespace.ts +82 -0
  98. package/src/core/extensions/normalize.ts +141 -0
  99. package/src/core/extensions/placeholder.ts +41 -0
  100. package/src/core/extensions/registry.ts +94 -0
  101. package/src/core/extensions/render-ext.ts +118 -0
  102. package/src/core/extensions/safe-nodes.ts +93 -0
  103. package/src/core/extensions/schema.ts +112 -0
  104. package/src/core/extensions/types.ts +159 -0
  105. package/src/core/forms/binding.ts +1 -1
  106. package/src/core/history/diff.ts +1 -1
  107. package/src/core/import/elementor/atomic.ts +1595 -0
  108. package/src/core/import/elementor/classes.ts +127 -0
  109. package/src/core/import/elementor/context.ts +429 -0
  110. package/src/core/import/elementor/counter-steps.ts +72 -0
  111. package/src/core/import/elementor/css.ts +445 -0
  112. package/src/core/import/elementor/html.ts +500 -0
  113. package/src/core/import/elementor/index.ts +949 -0
  114. package/src/core/import/elementor/inline-marks.ts +81 -0
  115. package/src/core/import/elementor/snapshots.ts +48 -0
  116. package/src/core/import/elementor/style.ts +409 -0
  117. package/src/core/import/elementor/values.ts +241 -0
  118. package/src/core/import/elementor/widgets.ts +1897 -0
  119. package/src/core/index.ts +82 -0
  120. package/src/core/json-schema.ts +107 -0
  121. package/src/core/limits.ts +19 -0
  122. package/src/core/migrate/index.ts +6 -1
  123. package/src/core/migrate/v18.ts +222 -0
  124. package/src/core/perf/meter.ts +5 -5
  125. package/src/core/proposals-safety.ts +102 -0
  126. package/src/core/proposals.ts +357 -0
  127. package/src/core/recipes/index.ts +2 -2
  128. package/src/core/render/extras.ts +3 -3
  129. package/src/core/render/index.ts +140 -20
  130. package/src/core/render/loop.ts +1 -1
  131. package/src/core/render/section.ts +4 -4
  132. package/src/core/render/vnode.ts +1 -1
  133. package/src/core/sanitize/css.ts +125 -10
  134. package/src/core/sanitize/motion.ts +116 -0
  135. package/src/core/saved-sections.ts +6 -0
  136. package/src/core/schema/descriptors.ts +3 -1
  137. package/src/core/schema/design.ts +2 -1
  138. package/src/core/schema/layout.ts +82 -14
  139. package/src/core/schema/style.ts +251 -114
  140. package/src/core/text-marks.ts +227 -0
  141. package/src/core/theme/dynamic.ts +9 -4
  142. package/src/core/theme/float.ts +1 -0
  143. package/src/core/theme/popup-rules.ts +17 -1
  144. package/src/core/translatable.ts +34 -0
  145. package/src/core/validate.ts +13 -1
  146. package/src/index.ts +24 -0
  147. package/src/mcp/errors.ts +3 -1
  148. package/src/mcp/ports.ts +67 -0
  149. package/src/mcp/prompts.ts +1 -11
  150. package/src/mcp/proposals.ts +281 -0
  151. package/src/mcp/read.ts +10 -9
  152. package/src/mcp/tools.ts +71 -3
  153. package/src/mcp/write.ts +66 -11
  154. package/src/server/agent-settings.ts +5 -1
  155. package/src/server/mcp-routes.ts +15 -0
  156. package/src/server/plugin.ts +35 -2
  157. package/src/server/presence.ts +78 -0
  158. package/src/server/proposals.ts +261 -0
  159. package/src/server/requests.ts +196 -0
  160. package/src/server/tools-served.ts +45 -0
@@ -0,0 +1,86 @@
1
+ import { Input } from "@cloudflare/kumo";
2
+ import * as React from "react";
3
+ import { sanitizeHref } from "../../core/index.ts";
4
+ import type { PageSummary } from "../content-api.ts";
5
+ import { FIELD } from "../ui.ts";
6
+
7
+ /** Where WordPress page ids went in earlier imports, so a site imports page by page (W-958). */
8
+ const STORAGE_KEY = "emvb-elementor-page-links";
9
+
10
+ export type PageLinks = Readonly<Record<number, string>>;
11
+
12
+ export function readPageLinks(): PageLinks {
13
+ try {
14
+ const parsed = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "{}") as unknown;
15
+ if (typeof parsed !== "object" || parsed === null) return {};
16
+ const out: Record<number, string> = {};
17
+ for (const [key, value] of Object.entries(parsed)) {
18
+ const id = Number(key);
19
+ if (Number.isInteger(id) && id > 0 && typeof value === "string" && value.length <= 2000)
20
+ out[id] = value;
21
+ }
22
+ return out;
23
+ } catch {
24
+ return {};
25
+ }
26
+ }
27
+
28
+ export function writePageLinks(links: PageLinks): void {
29
+ try {
30
+ localStorage.setItem(STORAGE_KEY, JSON.stringify({ ...readPageLinks(), ...links }));
31
+ } catch {
32
+ // Storage is off or full: the next import asks again.
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Page links (W-958): an Elementor 4 export links to WordPress pages by id only. Each gets an
38
+ * address on this site (one of your pages, or typed); left empty, its links are left out.
39
+ */
40
+ export function ImportPageLinks({
41
+ ids,
42
+ links,
43
+ pages,
44
+ onChange,
45
+ }: {
46
+ ids: readonly number[];
47
+ links: PageLinks;
48
+ pages: readonly PageSummary[] | undefined;
49
+ onChange: (id: number, address: string) => void;
50
+ }) {
51
+ const listId = React.useId();
52
+ if (ids.length === 0) return null;
53
+ return (
54
+ <fieldset className="emvb-import-links" data-emvb-import-links="">
55
+ <legend className="emvb-import-label">Page links</legend>
56
+ <p className="emvb-helper">
57
+ This export links to WordPress pages by their number. Enter where each goes on this site,
58
+ such as /contact, or pick one of your pages. Leave one empty to leave its links out.
59
+ </p>
60
+ <datalist id={listId}>
61
+ {(pages ?? []).map((page) => (
62
+ <option key={page.id} value={`/${page.slug}`}>
63
+ {page.title}
64
+ </option>
65
+ ))}
66
+ </datalist>
67
+ {ids.map((id) => {
68
+ const value = links[id] ?? "";
69
+ const invalid = value.trim() !== "" && sanitizeHref(value.trim()) === undefined;
70
+ return (
71
+ <Input
72
+ key={id}
73
+ label={`WordPress page ${id}`}
74
+ className={`${FIELD} emvb-mono`}
75
+ list={listId}
76
+ placeholder="/address"
77
+ value={value}
78
+ aria-invalid={invalid || undefined}
79
+ error={invalid ? "Enter an address such as /contact." : undefined}
80
+ onChange={(event) => onChange(id, event.target.value)}
81
+ />
82
+ );
83
+ })}
84
+ </fieldset>
85
+ );
86
+ }
@@ -15,12 +15,15 @@ import {
15
15
  StatusBadge,
16
16
  useList,
17
17
  } from "./list-kit.tsx";
18
+ import { ImportElementorDialog } from "./ImportElementorDialog.tsx";
19
+ import { ImportButton } from "./ImportButton.tsx";
18
20
  import { NewPageDialog } from "./NewPageDialog.tsx";
19
21
 
20
22
  /** The Visual pages list (IA): title and slug, status, last edited; New page. */
21
23
  export function PageList({ fetcher }: { fetcher: Fetcher }) {
22
24
  const list = useList(fetcher, listPages);
23
25
  const [creating, setCreating] = React.useState(false);
26
+ const [importing, setImporting] = React.useState(false);
24
27
  const [query, setQuery] = React.useState("");
25
28
  const searchRef = React.useRef<HTMLInputElement>(null);
26
29
  const shown =
@@ -28,7 +31,12 @@ export function PageList({ fetcher }: { fetcher: Fetcher }) {
28
31
  ? list.items.filter((page) => matchesSearch(query, page.title, `/${page.slug}`))
29
32
  : [];
30
33
 
31
- const newPage = <NewButton label="New page" onClick={() => setCreating(true)} />;
34
+ const newPage = (
35
+ <div className="emvb-list-actions">
36
+ <ImportButton onClick={() => setImporting(true)} />
37
+ <NewButton label="New page" onClick={() => setCreating(true)} />
38
+ </div>
39
+ );
32
40
 
33
41
  return (
34
42
  <>
@@ -94,6 +102,12 @@ export function PageList({ fetcher }: { fetcher: Fetcher }) {
94
102
  </div>
95
103
  )}
96
104
  <NewPageDialog fetcher={fetcher} open={creating} onOpenChange={setCreating} />
105
+ <ImportElementorDialog
106
+ fetcher={fetcher}
107
+ open={importing}
108
+ onOpenChange={setImporting}
109
+ target="page"
110
+ />
97
111
  </>
98
112
  );
99
113
  }
@@ -17,6 +17,8 @@ import {
17
17
  StatusBadge,
18
18
  useList,
19
19
  } from "./list-kit.tsx";
20
+ import { ImportButton } from "./ImportButton.tsx";
21
+ import { ImportElementorDialog } from "./ImportElementorDialog.tsx";
20
22
  import { NewThemePartDialog } from "./NewThemePartDialog.tsx";
21
23
 
22
24
  type Filter = "all" | ThemePartType;
@@ -122,11 +124,17 @@ function FilterTabs({
122
124
  export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
123
125
  const list = useList(fetcher, listThemeParts);
124
126
  const [creating, setCreating] = React.useState(false);
127
+ const [importing, setImporting] = React.useState(false);
125
128
  const [filter, setFilter] = React.useState<Filter>("all");
126
129
  const [query, setQuery] = React.useState("");
127
130
  const searchRef = React.useRef<HTMLInputElement>(null);
128
131
 
129
- const newPart = <NewButton label="New theme part" onClick={() => setCreating(true)} />;
132
+ const newPart = (
133
+ <div className="emvb-list-actions">
134
+ <ImportButton onClick={() => setImporting(true)} />
135
+ <NewButton label="New theme part" onClick={() => setCreating(true)} />
136
+ </div>
137
+ );
130
138
 
131
139
  const visible =
132
140
  list.state === "ready"
@@ -232,6 +240,12 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
232
240
  )}
233
241
  </div>
234
242
  )}
243
+ <ImportElementorDialog
244
+ fetcher={fetcher}
245
+ open={importing}
246
+ onOpenChange={setImporting}
247
+ target="part"
248
+ />
235
249
  <NewThemePartDialog
236
250
  fetcher={fetcher}
237
251
  open={creating}
@@ -0,0 +1,27 @@
1
+ import type { Icon } from "@phosphor-icons/react";
2
+ import type { ReactNode } from "react";
3
+
4
+ /** A card's heading row: an icon tile, the title and one line on what the card is for (W-477). */
5
+ export function SectionHead({
6
+ id,
7
+ icon: SectionIcon,
8
+ title,
9
+ children,
10
+ }: {
11
+ id: string;
12
+ icon: Icon;
13
+ title: string;
14
+ children: ReactNode;
15
+ }) {
16
+ return (
17
+ <div className="emvb-agents-head">
18
+ <span className="emvb-agents-icon" aria-hidden="true">
19
+ <SectionIcon size={18} />
20
+ </span>
21
+ <div>
22
+ <h2 id={id}>{title}</h2>
23
+ <p>{children}</p>
24
+ </div>
25
+ </div>
26
+ );
27
+ }
@@ -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
+ }
package/src/admin/ui.ts CHANGED
@@ -123,6 +123,12 @@ export const UI_CSS = `
123
123
  .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
124
  .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
125
  .emvb-agents-section p { margin: 0; font-size: 14px; line-height: 20px; color: var(--text-color-kumo-subtle); }
126
+ /* W-932: setup checklist */
127
+ .emvb-agents-steps { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
128
+ .emvb-agents-steps li { display: flex; align-items: flex-start; gap: 10px; }
129
+ .emvb-agents-step-icon { display: inline-flex; flex: none; margin-block-start: 1px; color: var(--text-color-kumo-subtle); }
130
+ .emvb-agents-steps li[data-state="done"] .emvb-agents-step-icon { color: var(--text-color-kumo-success, var(--color-kumo-brand)); }
131
+ .emvb-agents-steps li[data-state="todo"] .emvb-agents-step-icon { color: var(--text-color-kumo-warning, var(--text-color-kumo-default)); }
126
132
  .emvb-agents-section code { padding: 1px 5px; border-radius: 4px; background: var(--color-kumo-tint); font-family: var(--font-mono); font-size: 12px; }
127
133
  .emvb-agents-option { display: grid; gap: 4px; padding-top: 16px; border-top: 1px solid var(--color-kumo-line); }
128
134
  .emvb-agents-option > p { padding-inline-start: 44px; font-size: 13px; }
@@ -224,12 +230,43 @@ export const UI_CSS = `
224
230
  }
225
231
 
226
232
  /* 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; }
233
+ /* A long dialog (Import from Elementor with its report and options) scrolls inside the screen,
234
+ with its actions kept in view at the bottom. */
235
+ .emvb-dialog { display: flex; flex-direction: column; gap: 10px; max-height: calc(100dvh - 96px); overflow-y: auto; overscroll-behavior: contain; margin: -4px; padding: 4px; }
236
+ .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
237
  /* UX-023: selects in EmVB dialogs line up with the full-width fields under them. */
230
238
  .emvb-dialog .emvb-field { width: 100%; }
231
239
  .emvb-create-fields { display: flex; flex-direction: column; gap: 10px; min-width: 0; margin: 0; padding: 0; border: 0; }
232
240
  .emvb-create-status { min-height: 18px; }
241
+ /* W-945: Import from Elementor. The JSON box keeps its rows; the report scrolls on its own. */
242
+ .emvb-import-source { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
243
+ .emvb-import-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
244
+ .emvb-import-label { font-size: 14px; font-weight: 500; color: var(--text-color-kumo-default); }
245
+ .emvb-marks { display: grid; gap: 6px; min-width: 0; }
246
+ .emvb-marks-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
247
+ .emvb-marks-color { display: inline-flex; align-items: center; gap: 6px; }
248
+ .emvb-marks-color input { inline-size: 32px; block-size: 32px; padding: 0; border: 1px solid var(--color-kumo-line); border-radius: 6px; background: transparent; }
249
+ .emvb-marks-link { display: grid; gap: 6px; }
250
+ .emvb-marks-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
251
+ .emvb-marks-list li { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
252
+ .emvb-import-links { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 0; border: 0; }
253
+ .emvb-import-links > legend { padding: 0; margin-bottom: 4px; }
254
+ .emvb-dialog .emvb-field.emvb-import-json {
255
+ height: auto; min-height: 84px; padding: 8px; resize: vertical;
256
+ font-family: var(--font-mono); font-size: 12px; line-height: 1.4;
257
+ }
258
+ .emvb-import-report {
259
+ max-height: 220px; overflow: auto; overscroll-behavior: contain;
260
+ display: flex; flex-direction: column; gap: 6px;
261
+ padding: 8px 10px; border-radius: 6px; box-shadow: var(--emvb-elevation-s);
262
+ font-size: 13px; line-height: 1.35; color: var(--text-color-kumo-default);
263
+ }
264
+ .emvb-import-report:focus-visible { outline: 2px solid var(--color-kumo-brand, currentColor); outline-offset: 2px; }
265
+ .emvb-import-report summary { cursor: pointer; font-weight: 600; }
266
+ .emvb-import-report ul { margin: 4px 0 0; padding-inline-start: 18px; display: flex; flex-direction: column; gap: 2px; }
267
+ .emvb-import-report li { overflow-wrap: anywhere; }
268
+ .emvb-import-summary { font-weight: 600; }
269
+ .emvb-list-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
233
270
  /* UX-090: 16 px so the title stands above the 14 px field labels under it. */
234
271
  .emvb-dialog :is(h2, [data-slot="title"]) {
235
272
  margin: 0;
@@ -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
  };
@@ -430,6 +430,11 @@ export async function resolveThemeParts(
430
430
  * uses EmVB's own one-row probe queries, or pass a counter (e.g. an EmDash count API).
431
431
  */
432
432
  pageCount?: boolean | PostCounter;
433
+ /**
434
+ * W-937: the page's languages, for a Language switcher in a header or footer. Pass
435
+ * `resolveEmVBPage(...)?.translations` (or your own list of published translations).
436
+ */
437
+ translations?: readonly { locale: string; href: string; current: boolean }[];
433
438
  } = {},
434
439
  ): Promise<ResolvedThemeParts> {
435
440
  return resolveThemePartsWith(emdashContent, astro, ctx, options);
@@ -451,6 +456,11 @@ export async function resolveThemePartsWith(
451
456
  * uses EmVB's own one-row probe queries, or pass a counter (e.g. an EmDash count API).
452
457
  */
453
458
  pageCount?: boolean | PostCounter;
459
+ /**
460
+ * W-937: the page's languages, for a Language switcher in a header or footer. Pass
461
+ * `resolveEmVBPage(...)?.translations` (or your own list of published translations).
462
+ */
463
+ translations?: readonly { locale: string; href: string; current: boolean }[];
454
464
  } = {},
455
465
  ): Promise<ResolvedThemeParts> {
456
466
  const counter =
@@ -537,7 +547,10 @@ export async function resolveThemePartsWith(
537
547
  partDynamic: ThemeDynamicData | undefined,
538
548
  bound: Awaited<ReturnType<typeof bindingDataFor>>,
539
549
  ) => {
540
- const dynamic = Object.keys(bound).length > 0 ? { ...partDynamic, ...bound } : partDynamic;
550
+ const withBound = Object.keys(bound).length > 0 ? { ...partDynamic, ...bound } : partDynamic;
551
+ const dynamic = options.translations
552
+ ? { ...withBound, translations: options.translations }
553
+ : withBound;
541
554
  const formDefinitions = await formsFor(
542
555
  astro,
543
556
  handler,
@@ -1,4 +1,6 @@
1
1
  import { PAGES_COLLECTION } from "../constants.ts";
2
+ import { forEachNode } from "../core/tree-ops.ts";
3
+ import type { Layout, LayoutNode } from "../core/schema/layout.ts";
2
4
  import { emdashContent, type ContentPort } from "./content-port.ts";
3
5
  import { formIdsInLayouts } from "./forms-definitions.ts";
4
6
  import { readLayout, renderStored, type RenderedPage } from "./render.ts";
@@ -19,6 +21,18 @@ export type ResolvedEmVBPage = RenderedPage & {
19
21
  canvasMode: "site-layout" | "blank";
20
22
  /** A valid `_preview` token is serving the draft: don't cache the response. */
21
23
  isPreview: boolean;
24
+ /** W-935 (D-068): the locale asked for (option or Astro's), when the site has one. */
25
+ locale?: string;
26
+ /**
27
+ * W-935: set when that locale has no translation of the page and EmDash served this one from
28
+ * its fallback chain instead. Hosts can say so, or link to the requested language's home.
29
+ */
30
+ fallbackLocale?: string;
31
+ /**
32
+ * W-937: this page in each published language (the shown one marked current), when the site
33
+ * has languages. Pass it to `resolveThemeParts` for a Language switcher in the header.
34
+ */
35
+ translations?: { locale: string; href: string; current: boolean }[];
22
36
  };
23
37
 
24
38
  type AstroLike = VisitorAstro & {
@@ -55,6 +69,16 @@ export async function resolveEmVBPage(
55
69
  * from the host's image service (authorise the site origin in `image.remotePatterns`).
56
70
  */
57
71
  getImage?: ResponsiveGetImage;
72
+ /**
73
+ * W-935: which translation to read (EmDash's row-per-locale model, D-068). Defaults to
74
+ * Astro's `currentLocale`; EmDash falls back along its chain when there is none.
75
+ */
76
+ locale?: string;
77
+ /**
78
+ * W-937: where a translation of this page lives, for the Language switcher. Defaults to
79
+ * `/<slug>` for the default locale and `/<locale>/<slug>` for the others.
80
+ */
81
+ translationHref?: (translation: { locale: string; slug: string }) => string;
58
82
  } = {},
59
83
  ): Promise<ResolvedEmVBPage | null> {
60
84
  return resolveEmVBPageWith(emdashContent, astro, options);
@@ -82,13 +106,25 @@ export async function resolveEmVBPageWith(
82
106
  * from the host's image service (authorise the site origin in `image.remotePatterns`).
83
107
  */
84
108
  getImage?: ResponsiveGetImage;
109
+ /** W-935: which translation to read; defaults to Astro's `currentLocale`. */
110
+ locale?: string;
111
+ /**
112
+ * W-937: where a translation of this page lives, for the Language switcher. Defaults to
113
+ * `/<slug>` for the default locale and `/<locale>/<slug>` for the others.
114
+ */
115
+ translationHref?: (translation: { locale: string; slug: string }) => string;
85
116
  } = {},
86
117
  ): Promise<ResolvedEmVBPage | null> {
87
118
  const slug = options.slug ?? content.decodeSlug(astro.params[options.param ?? "slug"]);
88
119
  if (!slug) return null;
120
+ const locale = options.locale ?? astro.currentLocale;
89
121
  let found: Awaited<ReturnType<ContentPort["getEntry"]>>;
90
122
  try {
91
- found = await content.getEntry(options.collection ?? PAGES_COLLECTION, slug);
123
+ found = await content.getEntry(
124
+ options.collection ?? PAGES_COLLECTION,
125
+ slug,
126
+ locale ? { locale } : undefined,
127
+ );
92
128
  } catch {
93
129
  // No emvb_pages collection yet (EmVB not set up): not an EmVB page.
94
130
  return null;
@@ -119,7 +155,18 @@ export async function resolveEmVBPageWith(
119
155
  ]),
120
156
  )
121
157
  : undefined;
158
+ const translations =
159
+ content.getI18nConfig?.() ||
160
+ (layout &&
161
+ [layout, ...Object.values(sectionTemplates)].some((l) => hasType(l, "language-switcher")))
162
+ ? await translationLinks(content, {
163
+ collection: options.collection ?? PAGES_COLLECTION,
164
+ entryId: String(data["id"] ?? entry.id),
165
+ ...(options.translationHref ? { hrefOf: options.translationHref } : {}),
166
+ })
167
+ : undefined;
122
168
  const dynamic = {
169
+ ...(translations ? { translations } : {}),
123
170
  ...(Object.keys(sectionTemplates).length > 0 ? { sectionTemplates } : {}),
124
171
  ...(Object.keys(loopTemplates).length > 0 ? { loopTemplates } : {}),
125
172
  ...(await bindingDataFor(
@@ -145,12 +192,52 @@ export async function resolveEmVBPageWith(
145
192
  formDefinitions,
146
193
  Object.keys(dynamic).length > 0 ? dynamic : undefined,
147
194
  false,
148
- options.lang ?? astro.currentLocale,
195
+ options.lang ?? found.fallbackLocale ?? locale,
149
196
  ),
150
197
  entry,
151
198
  collection: hosted ? (options.collection as string) : PAGES_COLLECTION,
152
199
  title: typeof data["title"] === "string" ? data["title"] : "",
153
200
  canvasMode: !hosted && data["canvas_mode"] === "blank" ? "blank" : "site-layout",
154
201
  isPreview: Boolean(found.isPreview),
202
+ ...(locale ? { locale } : {}),
203
+ ...(found.fallbackLocale ? { fallbackLocale: found.fallbackLocale } : {}),
204
+ ...(translations ? { translations } : {}),
155
205
  };
156
206
  }
207
+
208
+ function hasType(layout: Layout, type: string): boolean {
209
+ let found = false;
210
+ forEachNode(layout.root as LayoutNode, (node) => {
211
+ if (node.type === type) found = true;
212
+ });
213
+ return found;
214
+ }
215
+
216
+ /**
217
+ * W-937: the page's languages for its Language switcher. Only published translations are
218
+ * linked (a draft never is); the page being shown is always listed and marked current.
219
+ */
220
+ async function translationLinks(
221
+ content: ContentPort,
222
+ input: {
223
+ collection: string;
224
+ entryId: string;
225
+ hrefOf?: (translation: { locale: string; slug: string }) => string;
226
+ },
227
+ ): Promise<{ locale: string; href: string; current: boolean }[] | undefined> {
228
+ if (!content.getTranslations) return undefined;
229
+ const found = await content.getTranslations(input.collection, input.entryId).catch(() => null);
230
+ if (!found || found.error) return undefined;
231
+ const defaultLocale = content.getI18nConfig?.()?.defaultLocale;
232
+ const hrefOf =
233
+ input.hrefOf ??
234
+ ((t: { locale: string; slug: string }) =>
235
+ t.locale === defaultLocale ? `/${t.slug}` : `/${t.locale}/${t.slug}`);
236
+ return found.translations
237
+ .filter((t) => t.slug && (t.status === "published" || t.id === input.entryId))
238
+ .map((t) => ({
239
+ locale: t.locale,
240
+ href: hrefOf({ locale: t.locale, slug: t.slug as string }),
241
+ current: t.id === input.entryId,
242
+ }));
243
+ }
package/src/constants.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PLUGIN_ID = "emvb";
2
- export const PLUGIN_VERSION = "0.9.0";
2
+ export const PLUGIN_VERSION = "1.0.0";
3
3
  export const PACKAGE_NAME = "@perkyzz/emvb";
4
4
  export const ADMIN_ENTRY = `${PACKAGE_NAME}/admin`;
5
5
  export const PAGES_COLLECTION = "emvb_pages";