@perkyzz/emvb 1.3.0 → 1.4.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.
- package/README.md +2 -2
- package/package.json +2 -2
- package/src/admin/bulk-api.ts +5 -1
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +22 -2
- package/src/admin/editor/Timeline.tsx +1 -8
- package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
- package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
- package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
- package/src/admin/editor/canvas/vnode-react.tsx +2 -0
- package/src/admin/editor/co-design.ts +36 -1
- package/src/admin/editor/dnd/dragged-source.ts +22 -0
- package/src/admin/editor/dnd/layer-drop.ts +141 -0
- package/src/admin/editor/dnd/new-element.ts +16 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +6 -0
- package/src/admin/editor/feature-css.ts +22 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/FontFaces.tsx +342 -0
- package/src/admin/editor/panels/LayersPanel.tsx +56 -6
- package/src/admin/editor/panels/LeftPanel.tsx +153 -29
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
- package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
- package/src/admin/editor/panels/TokenScales.tsx +2 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
- package/src/admin/editor/panels/VariableSection.tsx +111 -7
- package/src/admin/editor/panels/color-space.ts +71 -6
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +18 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
- package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
- package/src/admin/editor/panels/settings/style-sections.ts +19 -2
- package/src/admin/editor/panels/url-rules.ts +43 -0
- package/src/admin/editor/panels/use-layers-drop.ts +232 -0
- package/src/admin/editor/store.ts +4 -2
- package/src/admin/editor/useExtensions.ts +3 -1
- package/src/admin/editor/useNodeActions.ts +74 -1
- package/src/admin/editor/useSave.ts +116 -85
- package/src/admin/export-api.ts +25 -2
- package/src/admin/extension-outputs.ts +179 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +22 -188
- package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
- package/src/admin/pages/ImportImageCopies.tsx +167 -0
- package/src/admin/pages/ImportReport.tsx +63 -0
- package/src/admin/pages/NewPageDialog.tsx +54 -32
- package/src/admin/pages/PageList.tsx +9 -0
- package/src/admin/pages/ThemePartList.tsx +9 -0
- package/src/astro/EmVBPage.astro +5 -2
- package/src/astro/extension-styles.ts +35 -0
- package/src/astro/forms/EmVBFormsClient.astro +3 -0
- package/src/astro/forms/enhance.ts +107 -0
- package/src/astro/popups/runtime.ts +47 -2
- package/src/astro/render.ts +19 -4
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +18 -7
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +14 -5
- package/src/astro/widgets/sticky.ts +87 -0
- package/src/astro/widgets/theme.ts +52 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +150 -2
- package/src/core/arrange.ts +19 -1
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +35 -1
- package/src/core/elements/form-elements.ts +119 -9
- package/src/core/elements/icon-svg.ts +14 -0
- package/src/core/elements/index.ts +24 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +13 -3
- package/src/core/export/runtimes.generated.ts +7 -5
- package/src/core/export/site.ts +50 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +17 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +66 -21
- package/src/core/extensions/safe-nodes.ts +67 -11
- package/src/core/extensions/types.ts +48 -1
- package/src/core/fonts/files.ts +74 -0
- package/src/core/fonts/google.ts +112 -0
- package/src/core/fonts/test-font.ts +9 -0
- package/src/core/import/elementor/context.ts +13 -4
- package/src/core/import/elementor/index.ts +32 -21
- package/src/core/import/elementor/widgets.ts +114 -12
- package/src/core/import/html/blocks.ts +602 -0
- package/src/core/import/html/index.ts +155 -0
- package/src/core/import/html/map.ts +958 -0
- package/src/core/import/html/parse.ts +430 -0
- package/src/core/index.ts +45 -0
- package/src/core/migrate/v18.ts +3 -0
- package/src/core/public-attributes.ts +17 -0
- package/src/core/render/extras.ts +31 -7
- package/src/core/render/form.ts +103 -10
- package/src/core/render/index.ts +151 -15
- package/src/core/render/section.ts +31 -1
- package/src/core/render/spacer-basis.ts +102 -0
- package/src/core/render/theme-boot.ts +16 -0
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +68 -3
- package/src/core/sanitize/motion.ts +12 -0
- package/src/core/schema/design.ts +40 -0
- package/src/core/schema/layout.ts +114 -5
- package/src/core/schema/style.ts +28 -0
- package/src/core/templates/index.ts +218 -0
- package/src/core/templates/pages.ts +29 -0
- package/src/core/templates/sections.ts +794 -0
- package/src/core/templates/types.ts +9 -0
- package/src/core/theme/dynamic.ts +9 -6
- package/src/core/theme/popup-markup.ts +21 -2
- package/src/core/theme/popup-rules.ts +36 -0
- package/src/core/theme/triggers.ts +64 -5
- package/src/core/translatable.ts +5 -2
- package/src/extension-build.ts +331 -0
- package/src/index.ts +25 -3
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +29 -1
- package/src/mcp/tools.ts +40 -1
- package/src/mcp/write.ts +41 -1
- package/src/server/extension-routes.ts +73 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +9 -0
|
@@ -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 {
|
|
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 (
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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}
|
package/src/astro/EmVBPage.astro
CHANGED
|
@@ -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={
|
|
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={
|
|
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
|
+
}
|
|
@@ -3,15 +3,18 @@
|
|
|
3
3
|
* `resolveThemeParts().needsPopupsRuntime` is true (R-031).
|
|
4
4
|
*
|
|
5
5
|
* Triggers: page_load, delay, scroll, click, exit_intent, inactivity (W-081).
|
|
6
|
-
* Advanced
|
|
7
|
-
*
|
|
6
|
+
* Advanced: showTimes (localStorage), devices (viewport width), URL query rules and show dates
|
|
7
|
+
* (W-1081). Gap vs Elementor (deferred): A/B.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
11
|
clampScrollPercent,
|
|
12
12
|
matchesPopupDevices,
|
|
13
|
+
matchesUrlParams,
|
|
13
14
|
type PopupDevice,
|
|
14
15
|
TRIGGER_LIMITS,
|
|
16
|
+
type UrlParamRule,
|
|
17
|
+
withinShowDates,
|
|
15
18
|
withinShowTimes,
|
|
16
19
|
} from "../../core/theme/popup-rules.ts";
|
|
17
20
|
|
|
@@ -26,6 +29,9 @@ type OpenTrigger =
|
|
|
26
29
|
type Advanced = {
|
|
27
30
|
showTimes?: number | null;
|
|
28
31
|
devices?: PopupDevice[] | null;
|
|
32
|
+
urlParams?: UrlParamRule[] | null;
|
|
33
|
+
from?: string | null;
|
|
34
|
+
until?: string | null;
|
|
29
35
|
};
|
|
30
36
|
|
|
31
37
|
type TriggersDoc = {
|
|
@@ -85,6 +91,9 @@ function isValidSelector(selector: string): boolean {
|
|
|
85
91
|
function canOpen(config: PopupConfig, byClick: boolean): boolean {
|
|
86
92
|
const advanced = config.triggers.advanced;
|
|
87
93
|
if (!matchesPopupDevices(advanced, window.innerWidth)) return false;
|
|
94
|
+
// W-1081: where and when the popup runs at all, so a click is held to them too.
|
|
95
|
+
if (!matchesUrlParams(advanced, window.location.search)) return false;
|
|
96
|
+
if (!withinShowDates(advanced, Date.now())) return false;
|
|
88
97
|
if (!byClick && !withinShowTimes(advanced, timesShown(config.id))) return false;
|
|
89
98
|
return true;
|
|
90
99
|
}
|
|
@@ -93,6 +102,8 @@ type Controller = {
|
|
|
93
102
|
root: HTMLElement;
|
|
94
103
|
dialog: HTMLElement;
|
|
95
104
|
lastFocus: HTMLElement | null;
|
|
105
|
+
/** Click trigger selectors: the controls they match say they open this dialog. */
|
|
106
|
+
openers: string[];
|
|
96
107
|
open: () => void;
|
|
97
108
|
close: () => void;
|
|
98
109
|
opened: boolean;
|
|
@@ -127,6 +138,32 @@ function unlockScroll(): void {
|
|
|
127
138
|
if (!anyPopupOpen()) document.documentElement.style.overflow = savedOverflow;
|
|
128
139
|
}
|
|
129
140
|
|
|
141
|
+
const CONTROL = 'a[href], button, summary, input, [role="button"]';
|
|
142
|
+
|
|
143
|
+
/** The controls a click trigger's selector names: the matches, or the controls inside a match. */
|
|
144
|
+
function openerControls(selector: string): HTMLElement[] {
|
|
145
|
+
const out = new Set<HTMLElement>();
|
|
146
|
+
for (const match of document.querySelectorAll<HTMLElement>(selector)) {
|
|
147
|
+
if (match.matches(CONTROL)) out.add(match);
|
|
148
|
+
else for (const inner of match.querySelectorAll<HTMLElement>(CONTROL)) out.add(inner);
|
|
149
|
+
}
|
|
150
|
+
return [...out];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* W-1071: a control that opens a popup or panel says so (aria-haspopup="dialog") and whether it
|
|
155
|
+
* is open (aria-expanded), kept in step as the dialog opens and closes.
|
|
156
|
+
*/
|
|
157
|
+
function markOpeners(ctrl: Controller): void {
|
|
158
|
+
const expanded = String(ctrl.opened);
|
|
159
|
+
for (const selector of ctrl.openers) {
|
|
160
|
+
for (const control of openerControls(selector)) {
|
|
161
|
+
control.setAttribute("aria-haspopup", "dialog");
|
|
162
|
+
control.setAttribute("aria-expanded", expanded);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
130
167
|
function createController(root: HTMLElement): Controller | null {
|
|
131
168
|
const dialog = root.querySelector<HTMLElement>(".emvb-popup__dialog");
|
|
132
169
|
if (!dialog) return null;
|
|
@@ -134,6 +171,7 @@ function createController(root: HTMLElement): Controller | null {
|
|
|
134
171
|
root,
|
|
135
172
|
dialog,
|
|
136
173
|
lastFocus: null,
|
|
174
|
+
openers: [],
|
|
137
175
|
opened: false,
|
|
138
176
|
open() {
|
|
139
177
|
ctrl.lastFocus = document.activeElement as HTMLElement | null;
|
|
@@ -141,12 +179,14 @@ function createController(root: HTMLElement): Controller | null {
|
|
|
141
179
|
lockScroll();
|
|
142
180
|
root.hidden = false;
|
|
143
181
|
ctrl.opened = true;
|
|
182
|
+
markOpeners(ctrl);
|
|
144
183
|
dialog.focus({ preventScroll: true });
|
|
145
184
|
},
|
|
146
185
|
close() {
|
|
147
186
|
if (!ctrl.opened) return;
|
|
148
187
|
root.hidden = true;
|
|
149
188
|
ctrl.opened = false;
|
|
189
|
+
markOpeners(ctrl);
|
|
150
190
|
unlockScroll();
|
|
151
191
|
const prev = ctrl.lastFocus;
|
|
152
192
|
if (prev && typeof prev.focus === "function") prev.focus({ preventScroll: true });
|
|
@@ -317,6 +357,11 @@ function registerTrigger(ctrl: Controller, config: PopupConfig, trigger: OpenTri
|
|
|
317
357
|
const arm = (ARM as Record<string, Arm<OpenTrigger["type"]> | undefined>)[trigger.type];
|
|
318
358
|
const byClick = trigger.type === "click";
|
|
319
359
|
arm?.(() => openOnce(ctrl, config, byClick), trigger as never);
|
|
360
|
+
const selector = byClick ? String(trigger.selector ?? "").trim() : "";
|
|
361
|
+
if (selector && isValidSelector(selector)) {
|
|
362
|
+
ctrl.openers.push(selector);
|
|
363
|
+
markOpeners(ctrl);
|
|
364
|
+
}
|
|
320
365
|
}
|
|
321
366
|
|
|
322
367
|
/**
|
package/src/astro/render.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type Layout,
|
|
10
10
|
type ThemeDynamicData,
|
|
11
11
|
} from "../core/index.ts";
|
|
12
|
-
import type {
|
|
12
|
+
import type { PageRuntime } from "../core/elements/widgets.ts";
|
|
13
13
|
import { PLUGIN_ID } from "../constants.ts";
|
|
14
14
|
|
|
15
15
|
export type RenderedPage = {
|
|
@@ -22,11 +22,16 @@ export type RenderedPage = {
|
|
|
22
22
|
* W-1025: the opt-in widget scripts this page needs (a dismissible Alert…). `EmVBPage` loads
|
|
23
23
|
* them itself; set only when there is one.
|
|
24
24
|
*/
|
|
25
|
-
runtimes?:
|
|
25
|
+
runtimes?: PageRuntime[];
|
|
26
26
|
/** The site's text direction when set, for the host's `<html dir>` (W-230). */
|
|
27
27
|
dir?: "ltr" | "rtl" | "auto";
|
|
28
28
|
/** W-971: the element types whose base rules `css` holds, for `sharedPartCss`. */
|
|
29
29
|
baseTypes?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* W-1086: the extensions whose elements rendered. Their stylesheets are not in `css`:
|
|
32
|
+
* `EmVBPage` and the theme parts' `css` write each once per response.
|
|
33
|
+
*/
|
|
34
|
+
extensions?: string[];
|
|
30
35
|
};
|
|
31
36
|
|
|
32
37
|
/** The design document through the in-process public route (no HTTP round trip, D-013). */
|
|
@@ -109,6 +114,7 @@ export function renderStored(
|
|
|
109
114
|
scope: pageId,
|
|
110
115
|
...(partIds ? { partIds } : {}),
|
|
111
116
|
...(lang ? { lang } : {}),
|
|
117
|
+
separateExtensionCss: true,
|
|
112
118
|
});
|
|
113
119
|
} catch (error) {
|
|
114
120
|
// S-02: a layout that can't render leaves the page empty instead of failing the request.
|
|
@@ -119,8 +125,16 @@ export function renderStored(
|
|
|
119
125
|
});
|
|
120
126
|
return empty;
|
|
121
127
|
}
|
|
122
|
-
const {
|
|
123
|
-
|
|
128
|
+
const {
|
|
129
|
+
html,
|
|
130
|
+
css,
|
|
131
|
+
needsFormsRuntime,
|
|
132
|
+
needsTabsRuntime,
|
|
133
|
+
needsMenuRuntime,
|
|
134
|
+
baseTypes,
|
|
135
|
+
runtimes,
|
|
136
|
+
extensions,
|
|
137
|
+
} = result;
|
|
124
138
|
for (const warning of result.warnings) {
|
|
125
139
|
if (warning.code !== "refused-markup") continue;
|
|
126
140
|
// oxlint-disable-next-line no-console
|
|
@@ -133,6 +147,7 @@ export function renderStored(
|
|
|
133
147
|
needsTabsRuntime,
|
|
134
148
|
needsMenuRuntime,
|
|
135
149
|
...(runtimes.length > 0 ? { runtimes } : {}),
|
|
150
|
+
...(extensions.length > 0 ? { extensions } : {}),
|
|
136
151
|
...(design.direction ? { dir: design.direction } : {}),
|
|
137
152
|
baseTypes,
|
|
138
153
|
};
|