@perkyzz/emvb 1.0.0 → 1.2.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 +9 -0
- package/THIRD_PARTY_NOTICES.md +1 -0
- package/package.json +10 -9
- package/src/admin/agents-api.ts +5 -1
- package/src/admin/bulk-api.ts +67 -0
- package/src/admin/content-api.ts +39 -6
- package/src/admin/copy-rich-text.ts +119 -0
- package/src/admin/dialog-tab-wrap.ts +78 -0
- package/src/admin/editor/A11yCopilot.tsx +2 -0
- package/src/admin/editor/Editor.tsx +24 -7
- package/src/admin/editor/ScheduleDialog.tsx +167 -0
- package/src/admin/editor/Timeline.tsx +6 -2
- package/src/admin/editor/TopBar.tsx +60 -8
- package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +22 -9
- package/src/admin/editor/canvas/canvas-scale.ts +3 -3
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/dnd/new-element.ts +68 -0
- package/src/admin/editor/editor-chrome.tsx +16 -5
- package/src/admin/editor/editor-commands.ts +10 -4
- package/src/admin/editor/editor-css.ts +2 -1
- package/src/admin/editor/element-chrome.ts +22 -0
- package/src/admin/editor/panels/ElementPanel.tsx +34 -17
- package/src/admin/editor/panels/SettingsPanel.tsx +2 -2
- package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
- package/src/admin/editor/panels/settings/EffectsControls.tsx +79 -1
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
- package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
- package/src/admin/editor/panels/settings/IconControls.tsx +11 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +36 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +36 -3
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +18 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +7 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- package/src/admin/editor/panels/settings/length-units.ts +15 -3
- package/src/admin/editor/panels/settings/style-sections.ts +1 -0
- package/src/admin/editor/panels/style-target.ts +17 -4
- package/src/admin/editor/section-templates.ts +26 -4
- package/src/admin/editor/store.ts +15 -3
- package/src/admin/editor/useEditorCommands.ts +7 -5
- package/src/admin/editor/useEditorData.ts +4 -0
- package/src/admin/editor/useNodeActions.ts +4 -2
- package/src/admin/editor/useSave.ts +47 -3
- package/src/admin/export-api.ts +238 -0
- package/src/admin/index.tsx +6 -1
- package/src/admin/menus-api.ts +113 -0
- package/src/admin/pages/ExportDialog.tsx +395 -0
- package/src/admin/pages/ImportElementorDialog.tsx +25 -1
- package/src/admin/pages/PageList.tsx +67 -2
- package/src/admin/pages/ThemePartList.tsx +37 -1
- package/src/admin/pages/bulk.tsx +303 -0
- package/src/admin/search.ts +20 -0
- package/src/admin/theme-api.ts +4 -0
- package/src/admin/ui.ts +11 -2
- package/src/admin/widgets/CanvasField.tsx +8 -0
- package/src/admin/widgets/ConvertToRichText.tsx +136 -0
- package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
- package/src/admin/widgets/convert-body.ts +73 -2
- package/src/astro/EmVBPage.astro +3 -0
- package/src/astro/render.ts +47 -22
- package/src/astro/request-data.ts +3 -0
- package/src/astro/resolve-theme.ts +88 -51
- package/src/astro/tabs/runtime.ts +16 -6
- package/src/astro/visitor.ts +23 -4
- package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
- package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +19 -0
- package/src/astro/widgets/alerts.ts +37 -0
- package/src/astro/widgets/carousel.ts +167 -0
- package/src/astro/widgets/index.ts +1 -0
- package/src/astro/widgets/lightbox.ts +123 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +103 -3
- package/src/core/arrange.ts +57 -1
- package/src/core/bounded-array.ts +16 -13
- package/src/core/contract.ts +26 -3
- package/src/core/css/generate.ts +83 -21
- package/src/core/css/scope.ts +10 -2
- package/src/core/css/trace.ts +33 -8
- package/src/core/design/classes.ts +25 -5
- package/src/core/design/devices.ts +78 -2
- package/src/core/design/variables.ts +14 -1
- package/src/core/elements/icon-svg.ts +135 -0
- package/src/core/elements/index.ts +33 -127
- package/src/core/elements/widgets.ts +907 -0
- package/src/core/export/runtimes.generated.ts +12 -0
- package/src/core/export/site.ts +579 -0
- package/src/core/export/zip.ts +95 -0
- package/src/core/extensions/schema.ts +2 -1
- package/src/core/geo-trust.ts +18 -0
- package/src/core/history/diff.ts +25 -0
- package/src/core/icons/social.generated.ts +29 -0
- package/src/core/image-edit/schema.ts +2 -1
- package/src/core/import/elementor/atomic.ts +22 -9
- package/src/core/import/elementor/context.ts +18 -0
- package/src/core/import/elementor/index.ts +72 -11
- package/src/core/import/elementor/style.ts +21 -1
- package/src/core/import/elementor/widgets.ts +394 -133
- package/src/core/index.ts +14 -0
- package/src/core/issue-cap.ts +19 -0
- package/src/core/json-schema.ts +8 -1
- package/src/core/limits.ts +6 -0
- package/src/core/loop-collections.ts +33 -0
- package/src/core/perf/meter.ts +37 -19
- package/src/core/portable-text-export.ts +243 -0
- package/src/core/proposals.ts +8 -2
- package/src/core/public-attributes.ts +30 -0
- package/src/core/render/index.ts +115 -13
- package/src/core/render/tabs.ts +18 -11
- package/src/core/render/vnode.ts +44 -6
- package/src/core/sanitize/css.ts +26 -0
- package/src/core/sanitize/svg-upload.ts +276 -23
- package/src/core/sanitize/svg.ts +3 -3
- package/src/core/schema/descriptors.ts +4 -0
- package/src/core/schema/design.ts +8 -7
- package/src/core/schema/layout.ts +406 -18
- package/src/core/schema/style.ts +49 -1
- package/src/core/search-text.ts +70 -0
- package/src/core/shadowing-ids.ts +41 -0
- package/src/core/theme/conditions.ts +2 -1
- package/src/core/theme/float.ts +1 -0
- package/src/core/theme/parse-doc.ts +10 -5
- package/src/core/theme/popup-rules.ts +16 -0
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/validate.ts +3 -2
- package/src/index.ts +23 -2
- package/src/mcp/ports.ts +18 -7
- package/src/mcp/proposals.ts +36 -11
- package/src/mcp/read.ts +2 -3
- package/src/mcp/tools.ts +1 -1
- package/src/server/agent-settings.ts +12 -1
- package/src/server/hooks.ts +41 -6
- package/src/server/icon-routes.ts +52 -12
- package/src/server/mcp-routes.ts +11 -5
- package/src/server/plugin.ts +27 -2
- package/src/server/presence.ts +5 -1
- package/src/server/proposals.ts +16 -4
- package/src/server/requests.ts +60 -11
- package/src/server/site-origin.ts +13 -0
- package/src/server/targets.ts +26 -0
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
collectSectionPartIds,
|
|
3
|
+
portableTextToLayout,
|
|
4
|
+
validateLayout,
|
|
5
|
+
type Layout,
|
|
6
|
+
} from "../../core/index.ts";
|
|
7
|
+
import { layoutToPortableText, type PortableTextBlock } from "../../core/portable-text-export.ts";
|
|
8
|
+
import { THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
9
|
+
import { listAllItems, requestJson, type Fetcher } from "../api.ts";
|
|
10
|
+
import type { ContentItem } from "../content-item.ts";
|
|
3
11
|
import { readCollection } from "../setup/run.ts";
|
|
4
12
|
|
|
5
13
|
const SLUG = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
@@ -52,3 +60,66 @@ export async function convertEntryBody(
|
|
|
52
60
|
return { ok: false, message: "Nothing in the saved body could be converted." };
|
|
53
61
|
return { ok: true, ...result, field: field.slug };
|
|
54
62
|
}
|
|
63
|
+
|
|
64
|
+
export type RichTextPlan =
|
|
65
|
+
| {
|
|
66
|
+
ok: true;
|
|
67
|
+
field: string;
|
|
68
|
+
body: PortableTextBlock[];
|
|
69
|
+
converted: number;
|
|
70
|
+
skipped: Record<string, number>;
|
|
71
|
+
/** The field already holds content that this replaces. */
|
|
72
|
+
replaces: boolean;
|
|
73
|
+
}
|
|
74
|
+
| { ok: false; message: string };
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* W-963: the reverse of Convert to EmVB, planned but not written: the layout as rich text for the
|
|
78
|
+
* entry's first Portable Text field (`content` first), with synced sections resolved.
|
|
79
|
+
*/
|
|
80
|
+
export async function planRichText(
|
|
81
|
+
fetcher: Fetcher,
|
|
82
|
+
entry: { collection: string; id: string },
|
|
83
|
+
layout: Layout,
|
|
84
|
+
): Promise<RichTextPlan> {
|
|
85
|
+
const schema = await readCollection(fetcher, entry.collection);
|
|
86
|
+
const rich = (schema?.fields ?? []).filter((f) => f.type === "portableText");
|
|
87
|
+
const field = rich.find((f) => f.slug === "content") ?? rich[0];
|
|
88
|
+
if (!field)
|
|
89
|
+
return { ok: false, message: "This collection has no rich-text field to convert into." };
|
|
90
|
+
const [data, parts] = await Promise.all([
|
|
91
|
+
requestJson<{ item: { data?: Record<string, unknown> } }>(fetcher, entryPath(entry)),
|
|
92
|
+
collectSectionPartIds(layout).length > 0
|
|
93
|
+
? listAllItems<ContentItem>(fetcher, `/_emdash/api/content/${THEME_PARTS_COLLECTION}`)
|
|
94
|
+
: Promise.resolve([]),
|
|
95
|
+
]);
|
|
96
|
+
const sectionTemplates: Record<string, Layout> = {};
|
|
97
|
+
for (const part of parts) {
|
|
98
|
+
if (part.status !== "published" || part.data?.["part_type"] !== "section") continue;
|
|
99
|
+
const checked = validateLayout(part.data["layout"]);
|
|
100
|
+
if (checked.ok) sectionTemplates[part.id] = checked.layout;
|
|
101
|
+
}
|
|
102
|
+
const result = layoutToPortableText(layout, { sectionTemplates });
|
|
103
|
+
if (result.body.length === 0)
|
|
104
|
+
return { ok: false, message: "This layout has no words or images to convert." };
|
|
105
|
+
const current = data.item.data?.[field.slug];
|
|
106
|
+
const replaces =
|
|
107
|
+
(Array.isArray(current) && current.length > 0) ||
|
|
108
|
+
(typeof current === "string" && current.trim() !== "" && current.trim() !== "[]");
|
|
109
|
+
return { ok: true, field: field.slug, ...result, replaces };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Writes a planned body into the entry's rich-text field. Nothing else on the entry changes. */
|
|
113
|
+
export async function writeRichText(
|
|
114
|
+
fetcher: Fetcher,
|
|
115
|
+
entry: { collection: string; id: string },
|
|
116
|
+
plan: Extract<RichTextPlan, { ok: true }>,
|
|
117
|
+
): Promise<void> {
|
|
118
|
+
await requestJson(fetcher, entryPath(entry), {
|
|
119
|
+
method: "PUT",
|
|
120
|
+
body: { data: { [plan.field]: plan.body } },
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const entryPath = (entry: { collection: string; id: string }) =>
|
|
125
|
+
`/_emdash/api/content/${encodeURIComponent(entry.collection)}/${encodeURIComponent(entry.id)}`;
|
package/src/astro/EmVBPage.astro
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
import type { RenderedPage } from "./render.ts";
|
|
3
|
+
import EmVBWidgetRuntimes from "./widgets/EmVBWidgetRuntimes.astro";
|
|
3
4
|
|
|
4
5
|
/** The resolved meta of the page (EmDash's `getSeoMeta` result fits), for blank canvas mode. */
|
|
5
6
|
interface PageMeta {
|
|
@@ -59,6 +60,7 @@ const ogDescription = seo?.ogDescription ?? description;
|
|
|
59
60
|
</head>
|
|
60
61
|
<body>
|
|
61
62
|
<Fragment set:html={page.html} />
|
|
63
|
+
<EmVBWidgetRuntimes names={page.runtimes} />
|
|
62
64
|
<slot />
|
|
63
65
|
</body>
|
|
64
66
|
</html>
|
|
@@ -66,6 +68,7 @@ const ogDescription = seo?.ogDescription ?? description;
|
|
|
66
68
|
<>
|
|
67
69
|
<style is:inline set:html={page.css} />
|
|
68
70
|
<Fragment set:html={page.html} />
|
|
71
|
+
<EmVBWidgetRuntimes names={page.runtimes} />
|
|
69
72
|
<slot />
|
|
70
73
|
</>
|
|
71
74
|
)
|
package/src/astro/render.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type Layout,
|
|
10
10
|
type ThemeDynamicData,
|
|
11
11
|
} from "../core/index.ts";
|
|
12
|
+
import type { WidgetRuntime } from "../core/elements/widgets.ts";
|
|
12
13
|
import { PLUGIN_ID } from "../constants.ts";
|
|
13
14
|
|
|
14
15
|
export type RenderedPage = {
|
|
@@ -17,8 +18,15 @@ export type RenderedPage = {
|
|
|
17
18
|
needsFormsRuntime: boolean;
|
|
18
19
|
needsTabsRuntime: boolean;
|
|
19
20
|
needsMenuRuntime: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* W-1025: the opt-in widget scripts this page needs (a dismissible Alert…). `EmVBPage` loads
|
|
23
|
+
* them itself; set only when there is one.
|
|
24
|
+
*/
|
|
25
|
+
runtimes?: WidgetRuntime[];
|
|
20
26
|
/** The site's text direction when set, for the host's `<html dir>` (W-230). */
|
|
21
27
|
dir?: "ltr" | "rtl" | "auto";
|
|
28
|
+
/** W-971: the element types whose base rules `css` holds, for `sharedPartCss`. */
|
|
29
|
+
baseTypes?: string[];
|
|
22
30
|
};
|
|
23
31
|
|
|
24
32
|
/** The design document through the in-process public route (no HTTP round trip, D-013). */
|
|
@@ -75,40 +83,57 @@ export function renderStored(
|
|
|
75
83
|
/** The page's language, e.g. "fr-CA", for Post Dates (W-688). */
|
|
76
84
|
lang?: string,
|
|
77
85
|
): RenderedPage {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
const empty: RenderedPage = {
|
|
87
|
+
html: "",
|
|
88
|
+
css: "",
|
|
89
|
+
needsFormsRuntime: false,
|
|
90
|
+
needsTabsRuntime: false,
|
|
91
|
+
needsMenuRuntime: false,
|
|
92
|
+
...(design.direction ? { dir: design.direction } : {}),
|
|
93
|
+
};
|
|
94
|
+
let result: ReturnType<typeof renderPage>;
|
|
95
|
+
try {
|
|
96
|
+
const { layout, problem } = inspectLayout(raw);
|
|
97
|
+
if (!layout) {
|
|
98
|
+
if (raw !== null && raw !== undefined && raw !== "") {
|
|
99
|
+
// Public renders have no plugin logger. The page id and where the layout first fails
|
|
100
|
+
// (a structural path and an issue code), never layout content or issue messages (W-182).
|
|
101
|
+
// oxlint-disable-next-line no-console
|
|
102
|
+
console.error("emvb: stored layout is unreadable", { pageId, ...problem });
|
|
103
|
+
}
|
|
104
|
+
return empty;
|
|
85
105
|
}
|
|
86
|
-
|
|
87
|
-
html: "",
|
|
88
|
-
css: "",
|
|
89
|
-
needsFormsRuntime: false,
|
|
90
|
-
needsTabsRuntime: false,
|
|
91
|
-
needsMenuRuntime: false,
|
|
92
|
-
...(design.direction ? { dir: design.direction } : {}),
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
const { html, css, needsFormsRuntime, needsTabsRuntime, needsMenuRuntime } = renderPage(
|
|
96
|
-
layout,
|
|
97
|
-
design,
|
|
98
|
-
{
|
|
106
|
+
result = renderPage(layout, design, {
|
|
99
107
|
formDefinitions,
|
|
100
108
|
dynamic,
|
|
101
109
|
scope: pageId,
|
|
102
110
|
...(partIds ? { partIds } : {}),
|
|
103
111
|
...(lang ? { lang } : {}),
|
|
104
|
-
}
|
|
105
|
-
)
|
|
112
|
+
});
|
|
113
|
+
} catch (error) {
|
|
114
|
+
// S-02: a layout that can't render leaves the page empty instead of failing the request.
|
|
115
|
+
// oxlint-disable-next-line no-console
|
|
116
|
+
console.error("emvb: stored layout failed to render", {
|
|
117
|
+
pageId,
|
|
118
|
+
error: error instanceof Error ? error.name : "unknown",
|
|
119
|
+
});
|
|
120
|
+
return empty;
|
|
121
|
+
}
|
|
122
|
+
const { html, css, needsFormsRuntime, needsTabsRuntime, needsMenuRuntime, baseTypes, runtimes } =
|
|
123
|
+
result;
|
|
124
|
+
for (const warning of result.warnings) {
|
|
125
|
+
if (warning.code !== "refused-markup") continue;
|
|
126
|
+
// oxlint-disable-next-line no-console
|
|
127
|
+
console.error("emvb: an element could not render", { pageId, nodeId: warning.nodeId });
|
|
128
|
+
}
|
|
106
129
|
return {
|
|
107
130
|
html,
|
|
108
131
|
css,
|
|
109
132
|
needsFormsRuntime,
|
|
110
133
|
needsTabsRuntime,
|
|
111
134
|
needsMenuRuntime,
|
|
135
|
+
...(runtimes.length > 0 ? { runtimes } : {}),
|
|
112
136
|
...(design.direction ? { dir: design.direction } : {}),
|
|
137
|
+
baseTypes,
|
|
113
138
|
};
|
|
114
139
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { loopCollectionAllowed } from "../core/loop-collections.ts";
|
|
1
2
|
import { emdashContent, type ContentPort } from "./content-port.ts";
|
|
2
3
|
import { siteFor } from "./render-session.ts";
|
|
3
4
|
import {
|
|
@@ -31,6 +32,8 @@ const ORDER_BY: Record<CollectionLoop["order"], Record<string, "asc" | "desc">>
|
|
|
31
32
|
|
|
32
33
|
/** Published entries for one collection Loop (W-308); a failing query lists nothing. */
|
|
33
34
|
async function loopEntries(loop: CollectionLoop, content: ContentPort): Promise<ThemePostFields[]> {
|
|
35
|
+
// S-11 (W-1000): a site that lists its Loop collections shows nothing from the others.
|
|
36
|
+
if (!loopCollectionAllowed(loop.collection)) return [];
|
|
34
37
|
try {
|
|
35
38
|
const result = await content.getCollection(loop.collection, {
|
|
36
39
|
status: "published",
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
parseThemePartType,
|
|
15
15
|
pickThemePartWinner,
|
|
16
16
|
POPUP_CHROME_CSS,
|
|
17
|
+
sharedPartCss,
|
|
17
18
|
validateConditions,
|
|
18
19
|
validateFloatSettings,
|
|
19
20
|
validateTriggers,
|
|
@@ -36,6 +37,7 @@ import {
|
|
|
36
37
|
} from "../core/index.ts";
|
|
37
38
|
import { THEME_PARTS_COLLECTION } from "../constants.ts";
|
|
38
39
|
import { readLayout, renderStored, type RenderedPage } from "./render.ts";
|
|
40
|
+
import type { WidgetRuntime } from "../core/elements/widgets.ts";
|
|
39
41
|
import { designFor, formsFor, layoutFor, partsFor } from "./render-session.ts";
|
|
40
42
|
import type { HostVisitor, VisitorAstro } from "./visitor.ts";
|
|
41
43
|
import { bindingDataFor } from "./request-data.ts";
|
|
@@ -97,6 +99,11 @@ export type ResolvedThemeParts = {
|
|
|
97
99
|
needsMenuRuntime: boolean;
|
|
98
100
|
/** Hosts load `EmVBFormsRuntime` only when a winning part renders a form. */
|
|
99
101
|
needsFormsRuntime: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* W-1025: the opt-in widget scripts the winning parts need; set only when there is one. Mount
|
|
104
|
+
* `<EmVBWidgetRuntimes names={theme.runtimes} />` from `@perkyzz/emvb/astro/widgets`.
|
|
105
|
+
*/
|
|
106
|
+
runtimes?: WidgetRuntime[];
|
|
100
107
|
/**
|
|
101
108
|
* True for an archive page past the last one (`/posts/page/9` with no posts there). Hosts
|
|
102
109
|
* answer 404 (W-221). Page 1 with no posts is not a 404.
|
|
@@ -410,6 +417,12 @@ async function buildDynamicForContent(
|
|
|
410
417
|
return undefined;
|
|
411
418
|
}
|
|
412
419
|
|
|
420
|
+
/** W-1025: every widget runtime the rendered parts need, once each, or nothing. */
|
|
421
|
+
function partRuntimes(rendered: readonly RenderedPage[]): { runtimes?: WidgetRuntime[] } {
|
|
422
|
+
const names = [...new Set(rendered.flatMap((page) => page.runtimes ?? []))].toSorted();
|
|
423
|
+
return names.length > 0 ? { runtimes: names } : {};
|
|
424
|
+
}
|
|
425
|
+
|
|
413
426
|
/**
|
|
414
427
|
* Resolve winning published theme parts for this request (R-062 / S7b–S7d).
|
|
415
428
|
* Returns plain HTML/CSS; popup JS is optional and only when `needsPopupsRuntime`.
|
|
@@ -440,6 +453,20 @@ export async function resolveThemeParts(
|
|
|
440
453
|
return resolveThemePartsWith(emdashContent, astro, ctx, options);
|
|
441
454
|
}
|
|
442
455
|
|
|
456
|
+
/** S-02: a part that fails to render is left out, so the rest of the site still renders. */
|
|
457
|
+
async function orSkip<T>(id: string, render: () => Promise<T | null>): Promise<T | null> {
|
|
458
|
+
try {
|
|
459
|
+
return await render();
|
|
460
|
+
} catch (error) {
|
|
461
|
+
// oxlint-disable-next-line no-console
|
|
462
|
+
console.error("emvb: theme part failed to render", {
|
|
463
|
+
partId: id,
|
|
464
|
+
error: error instanceof Error ? error.name : "unknown",
|
|
465
|
+
});
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
443
470
|
/** Same as `resolveThemeParts`, with a content port so tests can pass a fake (W-359). */
|
|
444
471
|
export async function resolveThemePartsWith(
|
|
445
472
|
port: ContentPort,
|
|
@@ -528,6 +555,8 @@ export async function resolveThemePartsWith(
|
|
|
528
555
|
|
|
529
556
|
const byId = new Map(parts.map((part) => [part.id, part]));
|
|
530
557
|
const rendered: RenderedPage[] = [];
|
|
558
|
+
// W-971: each part's scoped sheet, to write the shared rules once in `css`.
|
|
559
|
+
const sheets = new Map<string, { css: string; scope: string; baseTypes: readonly string[] }>();
|
|
531
560
|
// W-307: bound fields in a part read site settings and URL parameters too.
|
|
532
561
|
// W-312/W-313: synced sections and Loop items the part uses count too.
|
|
533
562
|
const boundFor = (stored: StoredPart, referenced: ThemeDynamicData | undefined) =>
|
|
@@ -571,6 +600,8 @@ export async function resolveThemePartsWith(
|
|
|
571
600
|
options.lang ?? astro.currentLocale,
|
|
572
601
|
);
|
|
573
602
|
rendered.push(page);
|
|
603
|
+
if (page.css)
|
|
604
|
+
sheets.set(stored.id, { css: page.css, scope: stored.id, baseTypes: page.baseTypes ?? [] });
|
|
574
605
|
// W-216: a header or footer part is the page's banner or contentinfo landmark (hosts put it
|
|
575
606
|
// straight in <body> instead of their own <header>/<footer>).
|
|
576
607
|
// W-586: a part that already has its own header or footer box keeps that one as the landmark;
|
|
@@ -600,7 +631,9 @@ export async function resolveThemePartsWith(
|
|
|
600
631
|
|
|
601
632
|
let pastLastPage = false;
|
|
602
633
|
let archiveInfo: { title?: string; page: number; titleText?: string } | undefined;
|
|
603
|
-
const renderPart =
|
|
634
|
+
const renderPart = (winner: ThemePartCandidate | null): Promise<RenderedThemePart | null> =>
|
|
635
|
+
orSkip(winner?.id ?? "", () => renderPartOf(winner));
|
|
636
|
+
const renderPartOf = async (
|
|
604
637
|
winner: ThemePartCandidate | null,
|
|
605
638
|
): Promise<RenderedThemePart | null> => {
|
|
606
639
|
const stored = winner ? byId.get(winner.id) : undefined;
|
|
@@ -660,64 +693,67 @@ export async function resolveThemePartsWith(
|
|
|
660
693
|
|
|
661
694
|
const popups = (
|
|
662
695
|
await Promise.all(
|
|
663
|
-
popupMatches.map(
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
696
|
+
popupMatches.map((match) =>
|
|
697
|
+
orSkip(match.id, async () => {
|
|
698
|
+
const stored = byId.get(match.id);
|
|
699
|
+
if (!stored) return null;
|
|
700
|
+
const { html, css } = await renderOne(
|
|
701
|
+
stored,
|
|
702
|
+
extraTemplates.get(stored.id),
|
|
703
|
+
extraBound.get(stored.id) ?? {},
|
|
704
|
+
);
|
|
705
|
+
const popup: RenderedPopup = {
|
|
706
|
+
id: stored.id,
|
|
707
|
+
title: stored.title,
|
|
708
|
+
html: wrapPopupMarkup(stored.id, html, stored.triggers, options.labels),
|
|
709
|
+
css,
|
|
710
|
+
triggers: stored.triggers,
|
|
711
|
+
};
|
|
712
|
+
return popup;
|
|
713
|
+
}),
|
|
714
|
+
),
|
|
680
715
|
)
|
|
681
716
|
).filter((popup): popup is RenderedPopup => popup !== null);
|
|
682
717
|
|
|
683
718
|
const floats = (
|
|
684
719
|
await Promise.all(
|
|
685
|
-
floatMatches.map(
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
720
|
+
floatMatches.map((match) =>
|
|
721
|
+
orSkip(match.id, async () => {
|
|
722
|
+
const stored = byId.get(match.id);
|
|
723
|
+
if (!stored) return null;
|
|
724
|
+
const { html, css } = await renderOne(
|
|
725
|
+
stored,
|
|
726
|
+
extraTemplates.get(stored.id),
|
|
727
|
+
extraBound.get(stored.id) ?? {},
|
|
728
|
+
);
|
|
729
|
+
const layout = readLayout(stored.layout);
|
|
730
|
+
const surface = !layout || !floatHasOwnSurface(layout, design);
|
|
731
|
+
const item: RenderedFloat = {
|
|
732
|
+
id: stored.id,
|
|
733
|
+
title: stored.title,
|
|
734
|
+
html: wrapFloatMarkup(
|
|
735
|
+
stored.id,
|
|
736
|
+
stored.title,
|
|
737
|
+
html,
|
|
738
|
+
stored.float,
|
|
739
|
+
surface,
|
|
740
|
+
options.labels?.close,
|
|
741
|
+
),
|
|
742
|
+
css,
|
|
743
|
+
settings: stored.float,
|
|
744
|
+
};
|
|
745
|
+
return item;
|
|
746
|
+
}),
|
|
747
|
+
),
|
|
711
748
|
)
|
|
712
749
|
).filter((item): item is RenderedFloat => item !== null);
|
|
713
750
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
];
|
|
751
|
+
// W-971: the parts' shared rules (scope wrapper, element base rules, print) are written once.
|
|
752
|
+
const ordered = [header, content, footer, ...popups, ...floats].flatMap((part) => {
|
|
753
|
+
const sheet = part ? sheets.get(part.id) : undefined;
|
|
754
|
+
return sheet ? [sheet] : [];
|
|
755
|
+
});
|
|
756
|
+
const cssParts = [sharedPartCss(ordered)];
|
|
721
757
|
if (popups.length > 0) cssParts.push(POPUP_CHROME_CSS);
|
|
722
758
|
if (floats.length > 0) cssParts.push(FLOAT_CHROME_CSS);
|
|
723
759
|
const css = cssParts.filter(Boolean).join("\n");
|
|
@@ -733,6 +769,7 @@ export async function resolveThemePartsWith(
|
|
|
733
769
|
needsTabsRuntime: rendered.some((page) => page.needsTabsRuntime),
|
|
734
770
|
needsMenuRuntime: rendered.some((page) => page.needsMenuRuntime),
|
|
735
771
|
needsFormsRuntime: rendered.some((page) => page.needsFormsRuntime),
|
|
772
|
+
...partRuntimes(rendered),
|
|
736
773
|
notFound: pastLastPage,
|
|
737
774
|
...(design.direction ? { dir: design.direction } : {}),
|
|
738
775
|
...(archiveInfo?.title ? { archiveTitle: archiveInfo.title } : {}),
|
|
@@ -24,6 +24,13 @@ const KEY_TARGETS: Record<string, (current: number, count: number) => number> =
|
|
|
24
24
|
End: (_current, count) => count - 1,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* W-975: the element with the tab role: a span inside the label since 1.1; the label itself on
|
|
29
|
+
* pages rendered before.
|
|
30
|
+
*/
|
|
31
|
+
const tabOf = (label: HTMLElement): HTMLElement =>
|
|
32
|
+
label.querySelector<HTMLElement>(":scope > [role='tab']") ?? label;
|
|
33
|
+
|
|
27
34
|
/** Selects tab `index`; only keyboard navigation moves focus, never load or a radio change. */
|
|
28
35
|
function activate(root: HTMLElement, index: number, focus = false): void {
|
|
29
36
|
if (root.dataset["emvbTabsActivating"] === "1") return;
|
|
@@ -37,11 +44,13 @@ function activate(root: HTMLElement, index: number, focus = false): void {
|
|
|
37
44
|
if (!input.checked) input.checked = true;
|
|
38
45
|
for (const [i, label] of labels.entries()) {
|
|
39
46
|
const selected = i === next;
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
const tab = tabOf(label);
|
|
48
|
+
tab.setAttribute("aria-selected", String(selected));
|
|
49
|
+
tab.tabIndex = selected ? 0 : -1;
|
|
42
50
|
panels[i]?.setAttribute("aria-hidden", String(!selected));
|
|
43
51
|
}
|
|
44
|
-
const
|
|
52
|
+
const focusLabel = focus ? labels[next] : undefined;
|
|
53
|
+
const focusTarget = focusLabel ? tabOf(focusLabel) : undefined;
|
|
45
54
|
if (focusTarget && document.activeElement !== focusTarget) {
|
|
46
55
|
try {
|
|
47
56
|
focusTarget.focus({ preventScroll: true });
|
|
@@ -63,13 +72,14 @@ function selectedIndex(root: HTMLElement): number {
|
|
|
63
72
|
function linkTabs(root: HTMLElement, labels: HTMLElement[], panels: HTMLElement[]): void {
|
|
64
73
|
const prefix = root.id || "emvb-tabs";
|
|
65
74
|
for (const [i, label] of labels.entries()) {
|
|
75
|
+
const tab = tabOf(label);
|
|
66
76
|
const panel = panels[i];
|
|
67
77
|
const panelId = panel?.id || `${prefix}-panel-${i}`;
|
|
68
78
|
if (panel && !panel.id) panel.id = panelId;
|
|
69
|
-
|
|
79
|
+
tab.setAttribute("aria-controls", panelId);
|
|
70
80
|
if (panel) {
|
|
71
|
-
if (!
|
|
72
|
-
panel.setAttribute("aria-labelledby",
|
|
81
|
+
if (!tab.id) tab.id = `${prefix}-tab-${i}`;
|
|
82
|
+
panel.setAttribute("aria-labelledby", tab.id);
|
|
73
83
|
}
|
|
74
84
|
}
|
|
75
85
|
}
|
package/src/astro/visitor.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { geoTrust } from "../core/geo-trust.ts";
|
|
1
2
|
import {
|
|
2
3
|
AUDIENCE_SEGMENT,
|
|
3
4
|
abCookieName,
|
|
@@ -113,16 +114,34 @@ const COUNTRY = /^[A-Z]{2}$/;
|
|
|
113
114
|
/** XX is Cloudflare's "unknown" and T1 is Tor: neither is a country (W-514: host facts too). */
|
|
114
115
|
const isCountry = (code: string) => COUNTRY.test(code) && code !== "XX" && code !== "T1";
|
|
115
116
|
|
|
117
|
+
const onCloudflare = () => globalThis.navigator?.userAgent === "Cloudflare-Workers";
|
|
118
|
+
const onVercel = () =>
|
|
119
|
+
Boolean(
|
|
120
|
+
(globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env?.[
|
|
121
|
+
"VERCEL"
|
|
122
|
+
],
|
|
123
|
+
);
|
|
124
|
+
|
|
116
125
|
/**
|
|
117
|
-
* The visitor's country from the edge: Cloudflare's header or
|
|
126
|
+
* The visitor's country from the edge: `request.cf`, Cloudflare's header or Vercel's header.
|
|
118
127
|
* Not `Astro.locals.runtime.cf`: since Astro 6 the Cloudflare adapter throws when it is read.
|
|
128
|
+
* S-10 (W-999): a header counts only where that edge sets it (on Cloudflare Workers, on
|
|
129
|
+
* Vercel); elsewhere the visitor could send it. `emvb({ trustGeoHeaders: true })` trusts them
|
|
130
|
+
* behind a proxy that strips client copies; `false` trusts none.
|
|
119
131
|
*/
|
|
120
|
-
function countryOf(
|
|
132
|
+
export function countryOf(
|
|
133
|
+
astro: VisitorAstro,
|
|
134
|
+
trust: boolean | undefined = geoTrust(),
|
|
135
|
+
): string | undefined {
|
|
121
136
|
const headers = astro.request?.headers;
|
|
122
137
|
const cf = (astro.request as { cf?: { country?: unknown } } | undefined)?.cf;
|
|
123
138
|
const candidates = [
|
|
124
|
-
|
|
125
|
-
|
|
139
|
+
trust === true || (trust === undefined && onCloudflare())
|
|
140
|
+
? headers?.get("cf-ipcountry")
|
|
141
|
+
: undefined,
|
|
142
|
+
trust === true || (trust === undefined && onVercel())
|
|
143
|
+
? headers?.get("x-vercel-ip-country")
|
|
144
|
+
: undefined,
|
|
126
145
|
cf?.country,
|
|
127
146
|
];
|
|
128
147
|
for (const value of candidates) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* W-1025: the opt-in scripts of the 1.2 widgets, each mounted only when `names` asks for it.
|
|
4
|
+
* `EmVBPage` renders this for its page; for theme parts, pass `theme.runtimes`.
|
|
5
|
+
*/
|
|
6
|
+
import EmVBAlertsRuntime from "./EmVBAlertsRuntime.astro";
|
|
7
|
+
import EmVBCarouselRuntime from "./EmVBCarouselRuntime.astro";
|
|
8
|
+
import EmVBLightboxRuntime from "./EmVBLightboxRuntime.astro";
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
names?: readonly string[] | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const names = new Set(Astro.props.names ?? []);
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
{names.has("alerts") && <EmVBAlertsRuntime />}
|
|
18
|
+
{names.has("lightbox") && <EmVBLightboxRuntime />}
|
|
19
|
+
{names.has("carousel") && <EmVBCarouselRuntime />}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-1025: the opt-in Alert runtime. It shows each dismissible Alert's close button (hidden until
|
|
3
|
+
* this script runs, so a page without it never shows a button that does nothing) and hides the
|
|
4
|
+
* Alert when it is pressed, moving focus to the next thing a keyboard reaches.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const FOCUSABLE =
|
|
8
|
+
"a[href], button:not([disabled]), input:not([disabled]):not([type=hidden]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1']), summary, iframe";
|
|
9
|
+
|
|
10
|
+
/** The first focusable element after `from` in the document, else the last one before it. */
|
|
11
|
+
function neighbour(from: Element): HTMLElement | null {
|
|
12
|
+
const all = [...from.ownerDocument.querySelectorAll<HTMLElement>(FOCUSABLE)].filter(
|
|
13
|
+
(el) => !from.contains(el) && !el.closest("[hidden]"),
|
|
14
|
+
);
|
|
15
|
+
const after = all.find(
|
|
16
|
+
(el) => from.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING,
|
|
17
|
+
);
|
|
18
|
+
return (
|
|
19
|
+
after ??
|
|
20
|
+
all.findLast((el) => from.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_PRECEDING) ??
|
|
21
|
+
null
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function initAlerts(root: ParentNode = document): void {
|
|
26
|
+
for (const button of root.querySelectorAll<HTMLButtonElement>("[data-emvb-alert-dismiss]")) {
|
|
27
|
+
if (button.dataset["emvbReady"] !== undefined) continue;
|
|
28
|
+
button.dataset["emvbReady"] = "";
|
|
29
|
+
button.addEventListener("click", () => {
|
|
30
|
+
const alert = button.closest<HTMLElement>(".emvb-alert");
|
|
31
|
+
if (!alert) return;
|
|
32
|
+
const next = neighbour(alert);
|
|
33
|
+
alert.hidden = true;
|
|
34
|
+
next?.focus();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|