@perkyzz/emvb 1.3.0 → 1.4.1

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 (161) hide show
  1. package/README.md +2 -2
  2. package/package.json +2 -2
  3. package/src/admin/bulk-api.ts +5 -1
  4. package/src/admin/content-item.ts +3 -0
  5. package/src/admin/copy-rich-text.ts +99 -9
  6. package/src/admin/editor/A11yCopilot.tsx +3 -1
  7. package/src/admin/editor/Editor.tsx +28 -3
  8. package/src/admin/editor/Timeline.tsx +1 -8
  9. package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
  10. package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
  11. package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
  12. package/src/admin/editor/canvas/vnode-react.tsx +2 -0
  13. package/src/admin/editor/co-design.ts +36 -1
  14. package/src/admin/editor/collection-previews.ts +7 -8
  15. package/src/admin/editor/dnd/dragged-source.ts +22 -0
  16. package/src/admin/editor/dnd/layer-drop.ts +141 -0
  17. package/src/admin/editor/dnd/new-element.ts +16 -0
  18. package/src/admin/editor/editor-css.ts +9 -1
  19. package/src/admin/editor/element-chrome.ts +6 -0
  20. package/src/admin/editor/extensions/ExtensionPanels.tsx +33 -1
  21. package/src/admin/editor/extensions-context.tsx +16 -1
  22. package/src/admin/editor/feature-css.ts +27 -0
  23. package/src/admin/editor/inert-links.ts +8 -0
  24. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  25. package/src/admin/editor/panels/ConditionsEditor.tsx +18 -0
  26. package/src/admin/editor/panels/ElementPanel.tsx +2 -2
  27. package/src/admin/editor/panels/FontFaces.tsx +342 -0
  28. package/src/admin/editor/panels/LayersPanel.tsx +56 -6
  29. package/src/admin/editor/panels/LeftPanel.tsx +153 -29
  30. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  31. package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
  32. package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
  33. package/src/admin/editor/panels/TokenScales.tsx +2 -0
  34. package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
  35. package/src/admin/editor/panels/VariableSection.tsx +111 -7
  36. package/src/admin/editor/panels/color-space.ts +71 -6
  37. package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
  38. package/src/admin/editor/panels/settings/FieldControl.tsx +33 -0
  39. package/src/admin/editor/panels/settings/FormBindControl.tsx +27 -31
  40. package/src/admin/editor/panels/settings/ImageFieldControl.tsx +106 -0
  41. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
  42. package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
  43. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
  44. package/src/admin/editor/panels/settings/loop-context.ts +34 -3
  45. package/src/admin/editor/panels/settings/style-sections.ts +19 -2
  46. package/src/admin/editor/panels/url-rules.ts +43 -0
  47. package/src/admin/editor/panels/use-layers-drop.ts +232 -0
  48. package/src/admin/editor/store.ts +4 -2
  49. package/src/admin/editor/useExtensions.ts +3 -1
  50. package/src/admin/editor/useNodeActions.ts +74 -1
  51. package/src/admin/editor/useSave.ts +116 -85
  52. package/src/admin/export-api.ts +27 -2
  53. package/src/admin/extension-outputs.ts +236 -0
  54. package/src/admin/font-files-api.ts +38 -0
  55. package/src/admin/import-forms.ts +133 -0
  56. package/src/admin/pages/ImportButton.tsx +15 -4
  57. package/src/admin/pages/ImportElementorDialog.tsx +53 -187
  58. package/src/admin/pages/ImportForms.tsx +71 -0
  59. package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
  60. package/src/admin/pages/ImportImageCopies.tsx +167 -0
  61. package/src/admin/pages/ImportReport.tsx +63 -0
  62. package/src/admin/pages/NewPageDialog.tsx +54 -32
  63. package/src/admin/pages/PageList.tsx +9 -0
  64. package/src/admin/pages/ThemePartList.tsx +9 -0
  65. package/src/admin/setup/plan.ts +2 -0
  66. package/src/admin/ui.ts +7 -0
  67. package/src/admin/widgets/ConvertToRichText.tsx +3 -2
  68. package/src/astro/EmVBPage.astro +5 -2
  69. package/src/astro/extension-styles.ts +35 -0
  70. package/src/astro/forms/EmVBFormsClient.astro +3 -0
  71. package/src/astro/forms/enhance.ts +107 -0
  72. package/src/astro/popups/runtime.ts +47 -2
  73. package/src/astro/render.ts +25 -4
  74. package/src/astro/resolve-theme.ts +11 -4
  75. package/src/astro/resolve.ts +2 -0
  76. package/src/astro/theme-posts.ts +17 -23
  77. package/src/astro/visitor.ts +14 -5
  78. package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
  79. package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
  80. package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
  81. package/src/astro/widgets/alerts.ts +16 -2
  82. package/src/astro/widgets/carousel.ts +65 -24
  83. package/src/astro/widgets/countdown.ts +18 -7
  84. package/src/astro/widgets/extension-runtimes.ts +27 -0
  85. package/src/astro/widgets/headline.ts +14 -5
  86. package/src/astro/widgets/sticky.ts +87 -0
  87. package/src/astro/widgets/theme.ts +52 -0
  88. package/src/constants.ts +1 -1
  89. package/src/core/a11y/audit.ts +150 -2
  90. package/src/core/arrange.ts +19 -1
  91. package/src/core/css/font-face.ts +72 -0
  92. package/src/core/css/generate.ts +41 -2
  93. package/src/core/css/trace.ts +8 -0
  94. package/src/core/data/bindings.ts +7 -4
  95. package/src/core/elements/dynamic-elements.ts +1 -1
  96. package/src/core/elements/element-nouns.ts +48 -0
  97. package/src/core/elements/form-elements.ts +119 -9
  98. package/src/core/elements/icon-svg.ts +14 -0
  99. package/src/core/elements/index.ts +24 -4
  100. package/src/core/elements/input-limits.ts +44 -0
  101. package/src/core/elements/menu.ts +109 -47
  102. package/src/core/elements/site.ts +108 -0
  103. package/src/core/elements/widgets.ts +13 -3
  104. package/src/core/export/runtimes.generated.ts +7 -5
  105. package/src/core/export/site.ts +53 -4
  106. package/src/core/extensions/classes.ts +114 -0
  107. package/src/core/extensions/index.ts +19 -2
  108. package/src/core/extensions/normalize.ts +13 -0
  109. package/src/core/extensions/placeholder.ts +7 -2
  110. package/src/core/extensions/registry.ts +134 -10
  111. package/src/core/extensions/render-ext.ts +115 -36
  112. package/src/core/extensions/safe-nodes.ts +67 -11
  113. package/src/core/extensions/types.ts +48 -1
  114. package/src/core/fonts/files.ts +74 -0
  115. package/src/core/fonts/google.ts +112 -0
  116. package/src/core/fonts/test-font.ts +9 -0
  117. package/src/core/import/elementor/context.ts +42 -4
  118. package/src/core/import/elementor/index.ts +55 -23
  119. package/src/core/import/elementor/widgets.ts +242 -20
  120. package/src/core/import/html/blocks.ts +602 -0
  121. package/src/core/import/html/index.ts +155 -0
  122. package/src/core/import/html/map.ts +958 -0
  123. package/src/core/import/html/parse.ts +430 -0
  124. package/src/core/index.ts +54 -0
  125. package/src/core/migrate/v18.ts +3 -0
  126. package/src/core/public-attributes.ts +17 -0
  127. package/src/core/render/extras.ts +31 -7
  128. package/src/core/render/form.ts +103 -10
  129. package/src/core/render/index.ts +165 -16
  130. package/src/core/render/section.ts +31 -1
  131. package/src/core/render/spacer-basis.ts +102 -0
  132. package/src/core/render/theme-boot.ts +16 -0
  133. package/src/core/render/vnode.ts +1 -1
  134. package/src/core/sanitize/css.ts +68 -3
  135. package/src/core/sanitize/motion.ts +12 -0
  136. package/src/core/schema/design.ts +40 -0
  137. package/src/core/schema/layout.ts +118 -6
  138. package/src/core/schema/style.ts +28 -0
  139. package/src/core/templates/index.ts +218 -0
  140. package/src/core/templates/pages.ts +29 -0
  141. package/src/core/templates/sections.ts +794 -0
  142. package/src/core/templates/types.ts +9 -0
  143. package/src/core/theme/dynamic.ts +9 -6
  144. package/src/core/theme/media-value.ts +88 -0
  145. package/src/core/theme/popup-markup.ts +21 -2
  146. package/src/core/theme/popup-rules.ts +36 -0
  147. package/src/core/theme/triggers.ts +64 -5
  148. package/src/core/translatable.ts +5 -2
  149. package/src/core/visitor-cookie.ts +91 -0
  150. package/src/extension-build.ts +331 -0
  151. package/src/index.ts +53 -4
  152. package/src/mcp/agent-defaults.ts +40 -0
  153. package/src/mcp/brief.ts +191 -0
  154. package/src/mcp/extensions.ts +138 -0
  155. package/src/mcp/prompts.ts +33 -0
  156. package/src/mcp/read.ts +84 -20
  157. package/src/mcp/tools.ts +42 -3
  158. package/src/mcp/write.ts +124 -9
  159. package/src/server/extension-routes.ts +110 -0
  160. package/src/server/font-routes.ts +301 -0
  161. package/src/server/plugin.ts +15 -0
@@ -0,0 +1,167 @@
1
+ import { Button } from "@cloudflare/kumo";
2
+ import * as React from "react";
3
+ import type { Fetcher } from "../api.ts";
4
+ import { uploadImage } from "../media-api.ts";
5
+ import { BUTTON } from "../ui.ts";
6
+
7
+ /** An old-site image's copy in the media library. */
8
+ export type Copy = { url: string; id: string };
9
+
10
+ /** A URL's file name, decoded and lower-cased, to match a chosen file to the export's address (W-951, W-958). */
11
+ export function fileNameOf(url: string): string {
12
+ const last = url.split(/[?#]/)[0]?.split("/").pop() ?? "";
13
+ try {
14
+ return decodeURIComponent(last).toLowerCase();
15
+ } catch {
16
+ return last.toLowerCase();
17
+ }
18
+ }
19
+
20
+ /** W-958: an image copied into the media library is at most this large. */
21
+ const MAX_IMAGE_FILE = 20 * 1024 * 1024;
22
+
23
+ /** Fetches an old-site image without cookies; undefined when refused (CORS), not an image or too big. */
24
+ async function fetchImage(url: string): Promise<File | undefined> {
25
+ try {
26
+ const response = await fetch(url, {
27
+ credentials: "omit",
28
+ redirect: "follow",
29
+ signal: AbortSignal.timeout(20_000),
30
+ });
31
+ if (!response.ok) return undefined;
32
+ const blob = await response.blob();
33
+ if (!blob.type.startsWith("image/") || blob.size > MAX_IMAGE_FILE) return undefined;
34
+ return new File([blob], fileNameOf(url) || "image", { type: blob.type });
35
+ } catch {
36
+ return undefined;
37
+ }
38
+ }
39
+
40
+ /** Runs `run` on every item, at most `limit` at a time. */
41
+ async function eachLimited<T>(
42
+ items: readonly T[],
43
+ limit: number,
44
+ run: (item: T) => Promise<void>,
45
+ ): Promise<void> {
46
+ let next = 0;
47
+ const worker = async (): Promise<void> => {
48
+ const index = next++;
49
+ if (index >= items.length) return;
50
+ await run(items[index] as T);
51
+ return worker();
52
+ };
53
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
54
+ }
55
+
56
+ /**
57
+ * W-958 (shared with W-1074): the import dialogs' **Copy images** row. The browser fetches each
58
+ * old-site image (without cookies) and uploads it to the media library; images the old site
59
+ * won't let it read can be added as files, matched by file name. Nothing is fetched by the server.
60
+ */
61
+ export function ImportImageCopies({
62
+ fetcher,
63
+ images,
64
+ onCopied,
65
+ dataAttribute,
66
+ }: {
67
+ fetcher: Fetcher;
68
+ /** Old-site image addresses not copied yet. */
69
+ images: readonly string[];
70
+ onCopied: (done: [string, Copy][]) => void;
71
+ /** Marks the hidden file input for tests (`data-emvb-elementor-images`, …). */
72
+ dataAttribute: string;
73
+ }) {
74
+ const [status, setStatus] = React.useState<string>();
75
+ const [copying, setCopying] = React.useState(false);
76
+ const inputRef = React.useRef<HTMLInputElement>(null);
77
+
78
+ const upload = async (url: string, file: File, done: [string, Copy][]) => {
79
+ try {
80
+ const item = await uploadImage(fetcher, file);
81
+ done.push([url, { url: item.url, id: item.id }]);
82
+ } catch {
83
+ // Counted as not copied below.
84
+ }
85
+ };
86
+
87
+ const copyImages = async () => {
88
+ setCopying(true);
89
+ const done: [string, Copy][] = [];
90
+ const urls = [...images];
91
+ await eachLimited(urls, 4, async (url) => {
92
+ const file = await fetchImage(url);
93
+ if (file) await upload(url, file, done);
94
+ });
95
+ onCopied(done);
96
+ const failed = urls.length - done.length;
97
+ setStatus(
98
+ failed === 0
99
+ ? `Copied ${done.length} ${done.length === 1 ? "image" : "images"} to the media library.`
100
+ : `Copied ${done.length} of ${urls.length}. The rest couldn't be read from your old site from here: download them from its media library and add them with Add image files.`,
101
+ );
102
+ setCopying(false);
103
+ };
104
+
105
+ const addImages = async (files: readonly File[]) => {
106
+ setCopying(true);
107
+ const wanted = new Map(images.map((url) => [fileNameOf(url), url]));
108
+ const usable = (file: File) =>
109
+ file.size <= MAX_IMAGE_FILE &&
110
+ file.type.startsWith("image/") &&
111
+ wanted.has(file.name.toLowerCase());
112
+ const unused = files.filter((file) => !usable(file)).map((file) => file.name);
113
+ const done: [string, Copy][] = [];
114
+ await eachLimited(files.filter(usable), 4, (file) =>
115
+ upload(wanted.get(file.name.toLowerCase()) ?? "", file, done),
116
+ );
117
+ onCopied(done);
118
+ setStatus(
119
+ `Copied ${done.length} ${done.length === 1 ? "image" : "images"} to the media library.` +
120
+ (unused.length > 0
121
+ ? ` Not used (not in this export, not an image, or over 20 MB): ${unused.join(", ")}.`
122
+ : ""),
123
+ );
124
+ setCopying(false);
125
+ };
126
+
127
+ if (images.length === 0 && !status) return null;
128
+ return (
129
+ <div className="emvb-import-row" data-emvb-import-images="">
130
+ <Button
131
+ type="button"
132
+ variant="secondary"
133
+ className={BUTTON}
134
+ disabled={copying || images.length === 0}
135
+ onClick={() => void copyImages()}
136
+ >
137
+ {copying ? "Copying…" : "Copy images"}
138
+ </Button>
139
+ <Button
140
+ type="button"
141
+ variant="secondary"
142
+ className={BUTTON}
143
+ disabled={copying || images.length === 0}
144
+ onClick={() => inputRef.current?.click()}
145
+ >
146
+ Add image files
147
+ </Button>
148
+ <span className="emvb-helper" role="status">
149
+ {status ??
150
+ `${images.length} ${images.length === 1 ? "image loads" : "images load"} from your old site. Copy them to your media library (copies stay there even if you don't import), or add the files.`}
151
+ </span>
152
+ <input
153
+ ref={inputRef}
154
+ type="file"
155
+ accept="image/*"
156
+ multiple
157
+ hidden
158
+ {...{ [dataAttribute]: "" }}
159
+ onChange={(event) => {
160
+ const files = [...(event.target.files ?? [])];
161
+ event.target.value = "";
162
+ if (files.length > 0) void addImages(files);
163
+ }}
164
+ />
165
+ </div>
166
+ );
167
+ }
@@ -0,0 +1,63 @@
1
+ import type * as React from "react";
2
+ import type { ImportNote } from "../../core/index.ts";
3
+
4
+ const GROUPS: { kind: ImportNote["kind"]; title: string }[] = [
5
+ { kind: "unmapped", title: "Not recognised" },
6
+ { kind: "skipped", title: "Left out" },
7
+ { kind: "approximated", title: "Changed to fit EmVB" },
8
+ ];
9
+
10
+ /**
11
+ * What an import will do, before anything is created (W-945, shared with W-1074): the error, or
12
+ * the summary line and the notes grouped as not recognised, left out and changed.
13
+ */
14
+ export function ImportReport({
15
+ result,
16
+ summary,
17
+ children,
18
+ }: {
19
+ result: { ok: true; notes: ImportNote[] } | { ok: false; error: string } | undefined;
20
+ summary: string;
21
+ /** Extra lines under the summary (the fonts a page uses, …). */
22
+ children?: React.ReactNode;
23
+ }) {
24
+ if (!result) return null;
25
+ if (!result.ok) {
26
+ return (
27
+ <p className="emvb-inline-error" role="alert" data-emvb-import-error="">
28
+ {result.error}
29
+ </p>
30
+ );
31
+ }
32
+ return (
33
+ <section
34
+ className="emvb-import-report"
35
+ aria-label="Import report"
36
+ // The report can be long; it scrolls on its own and must be reachable by keyboard.
37
+ tabIndex={0}
38
+ data-emvb-import-report=""
39
+ >
40
+ <p className="emvb-import-summary" role="status">
41
+ {summary}
42
+ </p>
43
+ {children}
44
+ {GROUPS.map(({ kind, title }) => {
45
+ const notes = result.notes.filter((note) => note.kind === kind);
46
+ if (notes.length === 0) return null;
47
+ return (
48
+ <details key={kind} open={kind !== "approximated"} data-emvb-import-group={kind}>
49
+ <summary>{`${title} (${notes.length})`}</summary>
50
+ <ul>
51
+ {notes.map((note) => (
52
+ <li key={`${note.element}:${note.message}`}>
53
+ <strong>{note.element}:</strong> {note.message}
54
+ {note.count > 1 ? ` (${note.count}×)` : ""}
55
+ </li>
56
+ ))}
57
+ </ul>
58
+ </details>
59
+ );
60
+ })}
61
+ </section>
62
+ );
63
+ }
@@ -1,14 +1,24 @@
1
1
  import { Select } from "@cloudflare/kumo";
2
2
  import * as React from "react";
3
- import { layoutFromPageTemplate, starterLayout } from "../../core/index.ts";
3
+ import {
4
+ emptyDesign,
5
+ layoutFromPageTemplate,
6
+ PAGE_TEMPLATES,
7
+ starterLayout,
8
+ templatePageLayout,
9
+ } from "../../core/index.ts";
4
10
  import { ApiError, type Fetcher } from "../api.ts";
5
11
  import { createPage } from "../content-api.ts";
6
12
  import { editorUrl } from "../editor/exit.ts";
13
+ import { loadDesign } from "../editor/useEditorData.ts";
7
14
  import { listThemeParts, themePartLayout, type ThemePartSummary } from "../theme-api.ts";
8
15
  import { FIELD } from "../ui.ts";
9
16
  import { CreateDialog } from "./CreateDialog.tsx";
10
17
 
11
18
  const NONE = "__none__";
19
+ /** W-1068: starter page templates shipped with EmVB are chosen as `starter:<id>`. */
20
+ const STARTER = "starter:";
21
+ const starterName = (name: string) => `${name} (starter)`;
12
22
 
13
23
  /** New page (IA): title, auto-filled editable slug, then straight into the editor. */
14
24
  export function NewPageDialog({
@@ -37,8 +47,10 @@ export function NewPageDialog({
37
47
  cancelled = true;
38
48
  };
39
49
  }, [open, fetcher]);
50
+ const starterId = templateId.startsWith(STARTER) ? templateId.slice(STARTER.length) : null;
51
+ const starter = starterId ? PAGE_TEMPLATES.find((page) => page.id === starterId) : undefined;
40
52
  const hasUnlistedTemplate =
41
- templateId !== "" && !templates.some((part) => part.id === templateId);
53
+ templateId !== "" && !starter && !templates.some((part) => part.id === templateId);
42
54
 
43
55
  return (
44
56
  <CreateDialog
@@ -52,7 +64,14 @@ export function NewPageDialog({
52
64
  onOpenChange={onOpenChange}
53
65
  create={async (title, slug) => {
54
66
  let layout = starterLayout(title);
55
- if (templateId) {
67
+ if (starter) {
68
+ // The starter takes the site's Site styles; without them it uses neutral fallbacks.
69
+ const design = await loadDesign(fetcher).then(
70
+ (loaded) => loaded.design,
71
+ () => emptyDesign(),
72
+ );
73
+ layout = templatePageLayout(starter.id, design) ?? layout;
74
+ } else if (templateId) {
56
75
  const source = await themePartLayout(fetcher, templateId, "page_template");
57
76
  if (!source) {
58
77
  throw new ApiError(
@@ -66,36 +85,39 @@ export function NewPageDialog({
66
85
  return editorUrl(await createPage(fetcher, { title, slug, layout }));
67
86
  }}
68
87
  >
69
- {templates.length > 0 || hasUnlistedTemplate ? (
70
- <Select
71
- label="Page template"
72
- className={FIELD}
73
- value={templateId || NONE}
74
- renderValue={(value: unknown) =>
75
- !value || value === NONE
76
- ? "Blank page"
77
- : (templates.find((part) => part.id === value)?.title ??
78
- "Previously selected template")
88
+ <Select
89
+ label="Page template"
90
+ className={FIELD}
91
+ value={templateId || NONE}
92
+ renderValue={(value: unknown) =>
93
+ !value || value === NONE
94
+ ? "Blank page"
95
+ : (templates.find((part) => part.id === value)?.title ??
96
+ (starter ? starterName(starter.name) : "Previously selected template"))
97
+ }
98
+ onValueChange={(next) => {
99
+ if (!next || next === NONE) {
100
+ setTemplateId("");
101
+ return;
79
102
  }
80
- onValueChange={(next) => {
81
- if (!next || next === NONE) {
82
- setTemplateId("");
83
- return;
84
- }
85
- setTemplateId(next);
86
- }}
87
- >
88
- <Select.Option value={NONE}>Blank page</Select.Option>
89
- {hasUnlistedTemplate && (
90
- <Select.Option value={templateId}>Previously selected template</Select.Option>
91
- )}
92
- {templates.map((part) => (
93
- <Select.Option key={part.id} value={part.id}>
94
- {part.title}
95
- </Select.Option>
96
- ))}
97
- </Select>
98
- ) : null}
103
+ setTemplateId(next);
104
+ }}
105
+ >
106
+ <Select.Option value={NONE}>Blank page</Select.Option>
107
+ {PAGE_TEMPLATES.map((page) => (
108
+ <Select.Option key={page.id} value={`${STARTER}${page.id}`}>
109
+ {starterName(page.name)}
110
+ </Select.Option>
111
+ ))}
112
+ {hasUnlistedTemplate && (
113
+ <Select.Option value={templateId}>Previously selected template</Select.Option>
114
+ )}
115
+ {templates.map((part) => (
116
+ <Select.Option key={part.id} value={part.id}>
117
+ {part.title}
118
+ </Select.Option>
119
+ ))}
120
+ </Select>
99
121
  </CreateDialog>
100
122
  );
101
123
  }
@@ -18,6 +18,7 @@ import {
18
18
  useList,
19
19
  } from "./list-kit.tsx";
20
20
  import { ImportElementorDialog } from "./ImportElementorDialog.tsx";
21
+ import { ImportHtmlDialog } from "./ImportHtmlDialog.tsx";
21
22
  import { ImportButton } from "./ImportButton.tsx";
22
23
  import { ExportButton, ExportDialog } from "./ExportDialog.tsx";
23
24
  import { NewPageDialog } from "./NewPageDialog.tsx";
@@ -45,6 +46,7 @@ export function PageList({ fetcher }: { fetcher: Fetcher }) {
45
46
  const list = useList(fetcher, listPages);
46
47
  const [creating, setCreating] = React.useState(false);
47
48
  const [importing, setImporting] = React.useState(false);
49
+ const [importingHtml, setImportingHtml] = React.useState(false);
48
50
  const [exporting, setExporting] = React.useState(false);
49
51
  const [query, setQuery] = React.useState("");
50
52
  const searchRef = React.useRef<HTMLInputElement>(null);
@@ -64,6 +66,7 @@ export function PageList({ fetcher }: { fetcher: Fetcher }) {
64
66
  {list.state === "ready" && list.items.length > 0 && (
65
67
  <ExportButton onClick={() => setExporting(true)} />
66
68
  )}
69
+ <ImportButton source="html" onClick={() => setImportingHtml(true)} />
67
70
  <ImportButton onClick={() => setImporting(true)} />
68
71
  <NewButton label="New page" onClick={() => setCreating(true)} />
69
72
  </div>
@@ -167,6 +170,12 @@ export function PageList({ fetcher }: { fetcher: Fetcher }) {
167
170
  pages={list.state === "ready" ? list.items : []}
168
171
  selectedIds={exportIds}
169
172
  />
173
+ <ImportHtmlDialog
174
+ fetcher={fetcher}
175
+ open={importingHtml}
176
+ onOpenChange={setImportingHtml}
177
+ target="page"
178
+ />
170
179
  <ImportElementorDialog
171
180
  fetcher={fetcher}
172
181
  open={importing}
@@ -22,6 +22,7 @@ import {
22
22
  } from "./list-kit.tsx";
23
23
  import { ImportButton } from "./ImportButton.tsx";
24
24
  import { ImportElementorDialog } from "./ImportElementorDialog.tsx";
25
+ import { ImportHtmlDialog } from "./ImportHtmlDialog.tsx";
25
26
  import { NewThemePartDialog } from "./NewThemePartDialog.tsx";
26
27
 
27
28
  type Filter = "all" | ThemePartType;
@@ -128,12 +129,14 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
128
129
  const list = useList(fetcher, listThemeParts);
129
130
  const [creating, setCreating] = React.useState(false);
130
131
  const [importing, setImporting] = React.useState(false);
132
+ const [importingHtml, setImportingHtml] = React.useState(false);
131
133
  const [filter, setFilter] = React.useState<Filter>("all");
132
134
  const [query, setQuery] = React.useState("");
133
135
  const searchRef = React.useRef<HTMLInputElement>(null);
134
136
 
135
137
  const newPart = (
136
138
  <div className="emvb-list-actions">
139
+ <ImportButton source="html" onClick={() => setImportingHtml(true)} />
137
140
  <ImportButton onClick={() => setImporting(true)} />
138
141
  <NewButton label="New theme part" onClick={() => setCreating(true)} />
139
142
  </div>
@@ -276,6 +279,12 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
276
279
  )}
277
280
  </div>
278
281
  )}
282
+ <ImportHtmlDialog
283
+ fetcher={fetcher}
284
+ open={importingHtml}
285
+ onOpenChange={setImportingHtml}
286
+ target="part"
287
+ />
279
288
  <ImportElementorDialog
280
289
  fetcher={fetcher}
281
290
  open={importing}
@@ -13,6 +13,8 @@ export type FieldState = {
13
13
  required?: boolean;
14
14
  validation?: { options?: string[] } | null;
15
15
  defaultValue?: unknown;
16
+ /** EmDash i18n: false when the field is shared by every language of an entry. */
17
+ translatable?: boolean;
16
18
  };
17
19
 
18
20
  export type CollectionState = {
package/src/admin/ui.ts CHANGED
@@ -275,6 +275,13 @@ export const UI_CSS = `
275
275
  .emvb-import-report ul { margin: 4px 0 0; padding-inline-start: 18px; display: flex; flex-direction: column; gap: 2px; }
276
276
  .emvb-import-report li { overflow-wrap: anywhere; }
277
277
  .emvb-import-summary { font-weight: 600; }
278
+ .emvb-import-forms {
279
+ display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; border-radius: 6px;
280
+ border-inline-start: 3px solid var(--color-kumo-warning, #b7791f); box-shadow: var(--emvb-elevation-s);
281
+ font-size: 13px; line-height: 1.35; color: var(--text-color-kumo-default);
282
+ }
283
+ .emvb-import-forms ul { margin: 0; padding-inline-start: 18px; display: flex; flex-direction: column; gap: 2px; }
284
+ .emvb-import-forms li { overflow-wrap: anywhere; }
278
285
  .emvb-list-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
279
286
  /* UX-090: 16 px so the title stands above the 14 px field labels under it. */
280
287
  .emvb-dialog :is(h2, [data-slot="title"]) {
@@ -2,6 +2,7 @@ import { Button, Dialog, Loader } from "@cloudflare/kumo";
2
2
  import { TextAlignLeftIcon } from "@phosphor-icons/react";
3
3
  import * as React from "react";
4
4
  import type { Layout } from "../../core/index.ts";
5
+ import { elementCount } from "../../core/elements/element-nouns.ts";
5
6
  import type { Fetcher } from "../api.ts";
6
7
  import { DialogCloseButton } from "../editor/DialogCloseButton.tsx";
7
8
  import { BUTTON, SOLID_DESTRUCTIVE, UI_CSS } from "../ui.ts";
@@ -11,10 +12,10 @@ type Plan = Extract<RichTextPlan, { ok: true }>;
11
12
 
12
13
  const plural = (n: number, one: string) => `${n} ${n === 1 ? one : `${one}s`}`;
13
14
 
14
- /** "form, 2 icons", for what a conversion leaves out. */
15
+ /** "form, 12 icon boxes", for what a conversion leaves out (W-1091: names, real plurals). */
15
16
  export function leftOutText(skipped: Record<string, number>): string {
16
17
  return Object.entries(skipped)
17
- .map(([type, n]) => (n === 1 ? type : `${n} ${type}s`))
18
+ .map(([type, n]) => elementCount(type, n))
18
19
  .join(", ");
19
20
  }
20
21
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  import type { RenderedPage } from "./render.ts";
3
3
  import EmVBWidgetRuntimes from "./widgets/EmVBWidgetRuntimes.astro";
4
+ import { extensionStylesToWrite } from "./extension-styles.ts";
4
5
 
5
6
  /** The resolved meta of the page (EmDash's `getSeoMeta` result fits), for blank canvas mode. */
6
7
  interface PageMeta {
@@ -36,6 +37,8 @@ const { page, standalone = false, title = "", description, seo, lang } = Astro.p
36
37
  const docLang = [lang, Astro.currentLocale].find((tag) => tag && LANG_TAG.test(tag)) ?? "en";
37
38
  const ogTitle = seo?.ogTitle || title;
38
39
  const ogDescription = seo?.ogDescription ?? description;
40
+ // W-1086: extension stylesheets the theme parts or an earlier page of this response didn't write.
41
+ const css = page.css + extensionStylesToWrite(Astro.request, page.extensions);
39
42
  ---
40
43
 
41
44
  {
@@ -56,7 +59,7 @@ const ogDescription = seo?.ogDescription ?? description;
56
59
  {seo && (
57
60
  <meta name="twitter:card" content={seo.ogImage ? "summary_large_image" : "summary"} />
58
61
  )}
59
- <style is:inline set:html={page.css} />
62
+ <style is:inline set:html={css} />
60
63
  </head>
61
64
  <body>
62
65
  <Fragment set:html={page.html} />
@@ -66,7 +69,7 @@ const ogDescription = seo?.ogDescription ?? description;
66
69
  </html>
67
70
  ) : (
68
71
  <>
69
- <style is:inline set:html={page.css} />
72
+ <style is:inline set:html={css} />
70
73
  <Fragment set:html={page.html} />
71
74
  <EmVBWidgetRuntimes names={page.runtimes} />
72
75
  <slot />
@@ -0,0 +1,35 @@
1
+ import { extensionStylesheets } from "../core/extensions/index.ts";
2
+
3
+ /** Extension stylesheets already in one response (theme parts, then pages), per request. */
4
+ const written = new WeakMap<object, Set<string>>();
5
+
6
+ function writtenFor(request: object | undefined): Set<string> {
7
+ if (!request) return new Set();
8
+ const done = written.get(request) ?? new Set<string>();
9
+ written.set(request, done);
10
+ return done;
11
+ }
12
+
13
+ /**
14
+ * W-1086: the theme parts' sheet holds the stylesheets of `ids` (it always holds all of them, so
15
+ * it stays whole however often a host resolves the parts); pages in the same response skip them.
16
+ */
17
+ export function noteExtensionStyles(request: object | undefined, ids: readonly string[]): void {
18
+ const done = writtenFor(request);
19
+ for (const id of ids) done.add(id);
20
+ }
21
+
22
+ /**
23
+ * W-1086: the stylesheets of `ids` this response hasn't written yet, each once: a page whose
24
+ * header, footer and body all hold an extension's element ships its stylesheet once.
25
+ */
26
+ export function extensionStylesToWrite(
27
+ request: object | undefined,
28
+ ids: readonly string[] | undefined,
29
+ ): string {
30
+ if (!ids || ids.length === 0) return "";
31
+ const done = writtenFor(request);
32
+ const fresh = ids.filter((id) => !done.has(id));
33
+ for (const id of fresh) done.add(id);
34
+ return extensionStylesheets(fresh);
35
+ }
@@ -2,10 +2,13 @@
2
2
  // The forms plugin's client script (D-015). Rendered only by hosts that import
3
3
  // `@perkyzz/emvb/astro/forms/client` and have `@emdash-cms/plugin-forms` installed.
4
4
  // It loads on pages that contain a form (R-031); other pages never render this component.
5
+ // W-1065: EmVB's inline-message and step-focus layer runs after it (./enhance.ts).
5
6
  ---
6
7
 
7
8
  <script>
8
9
  import { initForms } from "@emdash-cms/plugin-forms/client";
10
+ import { enhanceForms } from "./enhance.ts";
9
11
 
10
12
  initForms();
13
+ enhanceForms();
11
14
  </script>
@@ -0,0 +1,107 @@
1
+ /**
2
+ * W-1065: inline validation messages and steps that screen reader and keyboard users can follow,
3
+ * on top of the forms plugin's own script (`initForms`), which checks the fields, writes each
4
+ * message into the field's `[data-error-for]` slot and pages through `[data-page]` steps. This
5
+ * adds what that script leaves out, on EmVB forms only:
6
+ *
7
+ * - a field whose slot holds a message is `aria-invalid="true"` until the message goes (the
8
+ * control already names the slot in `aria-describedby`, W-780);
9
+ * - Submit or Next with a field to fix moves focus to the first one, as the browser does on its
10
+ * own when no script runs; a server answer with field errors does the same;
11
+ * - a step that opens takes focus, so its legend is read out and Tab starts from it.
12
+ *
13
+ * Loaded with `initForms` by the forms runtime, which renders only on pages with a form.
14
+ */
15
+ const FORM = "form.emvb-form[data-ec-form]";
16
+ const SLOT = ".ec-form-error[data-error-for]";
17
+
18
+ /** The controls a message slot speaks for: the field's inputs with the slot's name. */
19
+ function controlsOf(slot: Element): HTMLElement[] {
20
+ const name = slot.getAttribute("data-error-for") ?? "";
21
+ const field = slot.closest(".emvb-form-field") ?? slot.parentElement;
22
+ if (!field || !name) return [];
23
+ return [...field.querySelectorAll<HTMLElement>("input, select, textarea")].filter(
24
+ (control) => control.getAttribute("name") === name,
25
+ );
26
+ }
27
+
28
+ /** Marks each field with a message invalid, and unmarks the rest. */
29
+ export function syncInvalid(form: Element): void {
30
+ for (const slot of form.querySelectorAll(SLOT)) {
31
+ const invalid = (slot.textContent ?? "").trim() !== "";
32
+ for (const control of controlsOf(slot)) {
33
+ if (invalid) control.setAttribute("aria-invalid", "true");
34
+ else control.removeAttribute("aria-invalid");
35
+ }
36
+ }
37
+ }
38
+
39
+ /** Shown: not inside a step the forms script hid, nor a field a condition hid. */
40
+ const shown = (el: Element) => !el.closest("[hidden]") && !(el as HTMLInputElement).disabled;
41
+
42
+ /** Focuses the first field with a message; true when there was one. */
43
+ export function focusFirstInvalid(form: Element): boolean {
44
+ const first = [...form.querySelectorAll<HTMLElement>('[aria-invalid="true"]')].find(shown);
45
+ if (!first) return false;
46
+ first.focus();
47
+ return true;
48
+ }
49
+
50
+ /** The step the visitor is on, in a form with steps. */
51
+ const openStep = (form: Element) =>
52
+ [...form.querySelectorAll<HTMLElement>("[data-page]")].find((step) => !step.hidden);
53
+
54
+ /** Waiting for the server's answer to a send that passed the checks here. */
55
+ const sending = new WeakSet<Element>();
56
+ const watched = new WeakSet<Element>();
57
+ const listening = new WeakSet<Document>();
58
+
59
+ function watch(form: Element): void {
60
+ if (watched.has(form)) return;
61
+ watched.add(form);
62
+ syncInvalid(form);
63
+ const view = form.ownerDocument.defaultView;
64
+ if (!view?.MutationObserver) return;
65
+ new view.MutationObserver(() => {
66
+ syncInvalid(form);
67
+ if (!sending.has(form)) return;
68
+ // The server's field errors arrive after the send; focus goes to the first, as it would have
69
+ // for a check that failed here. A status message (sent, or a network error) ends the wait.
70
+ if (focusFirstInvalid(form)) sending.delete(form);
71
+ else if (form.querySelector("[data-form-status]")?.textContent?.trim()) sending.delete(form);
72
+ }).observe(form, { subtree: true, childList: true, characterData: true });
73
+ }
74
+
75
+ function onSubmit(event: Event): void {
76
+ const form = (event.target as Element | null)?.closest?.(FORM);
77
+ if (!form) return;
78
+ watch(form);
79
+ syncInvalid(form);
80
+ if (focusFirstInvalid(form)) sending.delete(form);
81
+ else sending.add(form);
82
+ }
83
+
84
+ function onClick(event: Event): void {
85
+ const target = event.target as Element | null;
86
+ const button = target?.closest?.("[data-ec-next], [data-ec-prev]");
87
+ const form = button?.closest(FORM);
88
+ if (!form) return;
89
+ watch(form);
90
+ syncInvalid(form);
91
+ // The forms script has already run: a step with a field to fix stayed open with its message.
92
+ if (focusFirstInvalid(form)) return;
93
+ openStep(form)?.focus();
94
+ }
95
+
96
+ /** Wires every EmVB form on the page. Call after `initForms`, so these listeners run after its. */
97
+ export function enhanceForms(doc: Document = document): void {
98
+ for (const form of doc.querySelectorAll(FORM)) watch(form);
99
+ if (listening.has(doc)) return;
100
+ listening.add(doc);
101
+ doc.addEventListener("submit", onSubmit);
102
+ doc.addEventListener("click", onClick);
103
+ // Astro's ClientRouter swaps the page without a load; the forms script starts again there too.
104
+ doc.addEventListener("astro:page-load", () => {
105
+ for (const form of doc.querySelectorAll(FORM)) watch(form);
106
+ });
107
+ }