@perkyzz/emvb 0.6.0 → 0.8.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/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +7 -7
- package/src/admin/access/RequireEditor.tsx +7 -7
- package/src/admin/access/role.ts +5 -2
- package/src/admin/content-api.ts +10 -3
- package/src/admin/content-item.ts +1 -1
- package/src/admin/editor/A11yCopilot.tsx +104 -56
- package/src/admin/editor/CommandPalette.tsx +29 -13
- package/src/admin/editor/DialogCloseButton.tsx +16 -0
- package/src/admin/editor/Editor.tsx +115 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +92 -73
- package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
- package/src/admin/editor/ShareLink.tsx +102 -72
- package/src/admin/editor/ShortcutsDialog.tsx +37 -18
- package/src/admin/editor/Timeline.tsx +250 -160
- package/src/admin/editor/TopBar.tsx +71 -14
- package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
- package/src/admin/editor/canvas/drop-line.ts +11 -3
- package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
- package/src/admin/editor/canvas/vnode-react.tsx +7 -0
- package/src/admin/editor/collection-previews.ts +10 -0
- package/src/admin/editor/dialogs.tsx +41 -28
- package/src/admin/editor/dnd/drop-target.ts +26 -1
- package/src/admin/editor/edited-noun.ts +15 -0
- package/src/admin/editor/editor-chrome.tsx +43 -7
- package/src/admin/editor/editor-commands.ts +17 -2
- package/src/admin/editor/editor-css.ts +75 -24
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +56 -14
- package/src/admin/editor/focus-when-lost.ts +23 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +54 -18
- package/src/admin/editor/icons/library.ts +1 -1
- package/src/admin/editor/icons/use-icon-library.ts +5 -2
- package/src/admin/editor/ime.ts +29 -0
- package/src/admin/editor/palette-items.ts +27 -3
- package/src/admin/editor/panels/AddPanel.tsx +44 -11
- package/src/admin/editor/panels/ClassesSection.tsx +18 -7
- package/src/admin/editor/panels/ColorControl.tsx +130 -23
- package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
- package/src/admin/editor/panels/ElementPanel.tsx +134 -24
- package/src/admin/editor/panels/LayersPanel.tsx +61 -20
- package/src/admin/editor/panels/LeftPanel.tsx +9 -1
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +224 -42
- package/src/admin/editor/panels/TokenScales.tsx +88 -48
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +3 -2
- package/src/admin/editor/panels/VariableSection.tsx +48 -18
- package/src/admin/editor/panels/color-space.ts +23 -29
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +87 -74
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
- package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
- package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
- package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
- package/src/admin/editor/panels/settings/FieldControl.tsx +20 -8
- package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
- package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +33 -13
- package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
- package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
- package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
- package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
- package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
- package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
- package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
- package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
- package/src/admin/editor/panels/settings/query-style.ts +38 -9
- package/src/admin/editor/panels/settings/svg-images.ts +13 -0
- package/src/admin/editor/panels/site-list.tsx +20 -6
- package/src/admin/editor/panels/variable-values.ts +11 -4
- package/src/admin/editor/restore-deleted.ts +21 -2
- package/src/admin/editor/section-templates.ts +81 -12
- package/src/admin/editor/shortcuts.ts +31 -2
- package/src/admin/editor/store.ts +7 -0
- package/src/admin/editor/useEditorCommands.ts +61 -15
- package/src/admin/editor/useEditorData.ts +4 -2
- package/src/admin/editor/useEditorShortcuts.ts +17 -7
- package/src/admin/editor/useNodeActions.ts +61 -6
- package/src/admin/editor/useSave.ts +22 -7
- package/src/admin/editor/useSavedSections.ts +197 -0
- package/src/admin/forms-api.ts +2 -0
- package/src/admin/image-editor/Canvas.tsx +61 -17
- package/src/admin/image-editor/CurvesPanel.tsx +2 -1
- package/src/admin/image-editor/ExportDialog.tsx +48 -18
- package/src/admin/image-editor/ImageEditorDialog.tsx +179 -8
- package/src/admin/image-editor/MetadataPanel.tsx +15 -4
- package/src/admin/image-editor/crop-geometry.ts +3 -2
- package/src/admin/image-editor/image-editor-css.ts +15 -10
- package/src/admin/image-editor/load.ts +9 -2
- package/src/admin/image-editor/parts.tsx +69 -19
- package/src/admin/image-editor/save.ts +54 -8
- package/src/admin/media-api.ts +2 -1
- package/src/admin/pages/AgentsPage.tsx +138 -27
- package/src/admin/pages/CreateDialog.tsx +97 -30
- package/src/admin/pages/NewPageDialog.tsx +21 -3
- package/src/admin/pages/NewThemePartDialog.tsx +11 -3
- package/src/admin/pages/PageList.tsx +14 -6
- package/src/admin/pages/SetupShell.tsx +28 -12
- package/src/admin/pages/ThemePartList.tsx +59 -11
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/saved-sections-api.ts +51 -0
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +16 -5
- package/src/admin/ui.ts +82 -22
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +41 -9
- package/src/astro/render.ts +3 -0
- package/src/astro/resolve-theme.ts +53 -11
- package/src/astro/resolve.ts +9 -1
- package/src/astro/tabs/runtime.ts +12 -0
- package/src/astro/theme-posts.ts +2 -2
- package/src/astro/visitor.ts +2 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +196 -24
- package/src/core/arrange.ts +48 -12
- package/src/core/audience/rules.ts +5 -1
- package/src/core/audience/variants.ts +29 -3
- package/src/core/clipboard.ts +7 -0
- package/src/core/css/generate.ts +31 -6
- package/src/core/css/print.ts +5 -0
- package/src/core/data/bindings.ts +8 -1
- package/src/core/design/classes.ts +39 -16
- package/src/core/design/devices.ts +7 -13
- package/src/core/design/diff.ts +6 -0
- package/src/core/design/merge.ts +90 -2
- package/src/core/design/states.ts +7 -13
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +33 -6
- package/src/core/design/variables.ts +30 -9
- package/src/core/elements/dynamic-elements.ts +53 -14
- package/src/core/elements/form-elements.ts +55 -16
- package/src/core/elements/index.ts +84 -39
- package/src/core/elements/menu.ts +40 -19
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +57 -16
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +18 -1
- package/src/core/icons/animation-runs.ts +11 -0
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +11 -1
- package/src/core/image-edit/summary.ts +6 -3
- package/src/core/index.ts +35 -1
- package/src/core/limits.ts +12 -1
- package/src/core/migrate/index.ts +3 -0
- package/src/core/perf/meter.ts +42 -7
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +69 -12
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +140 -6
- package/src/core/render/index.ts +156 -20
- package/src/core/render/loop.ts +44 -8
- package/src/core/render/pagination.ts +18 -4
- package/src/core/render/section.ts +27 -0
- package/src/core/render/tabs.ts +12 -3
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +29 -8
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/saved-sections.ts +318 -0
- package/src/core/schema/design.ts +1 -1
- package/src/core/schema/layout.ts +16 -7
- package/src/core/schema/style.ts +4 -2
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +36 -5
- package/src/core/theme/float.ts +12 -2
- package/src/core/theme/pagination.ts +50 -29
- package/src/core/theme/part-types.ts +4 -4
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +1 -0
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/ports.ts +22 -1
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +15 -3
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/sections.ts +183 -0
- package/src/mcp/tools.ts +44 -0
- package/src/mcp/write.ts +178 -14
- package/src/server/agent-settings.ts +1 -1
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +30 -9
- package/src/server/mcp-routes.ts +8 -1
- package/src/server/plugin.ts +14 -0
- package/src/server/saved-sections.ts +163 -0
|
@@ -13,6 +13,8 @@ const YT_HOSTS = new Set([
|
|
|
13
13
|
"youtube.com",
|
|
14
14
|
"www.youtube.com",
|
|
15
15
|
"m.youtube.com",
|
|
16
|
+
// W-546: YouTube Music links play the same video ids.
|
|
17
|
+
"music.youtube.com",
|
|
16
18
|
"youtu.be",
|
|
17
19
|
"www.youtu.be",
|
|
18
20
|
"youtube-nocookie.com",
|
|
@@ -27,9 +29,26 @@ const YT_ID = /^[\w-]{6,}$/;
|
|
|
27
29
|
const VIMEO_ID = /^\d{6,}$/;
|
|
28
30
|
const firstSegment = (path: string) => path.split("/").find(Boolean);
|
|
29
31
|
|
|
32
|
+
/** A YouTube playlist id (PL…, UU…, OLAK5uy_…). */
|
|
33
|
+
const YT_LIST = /^[\w-]{10,64}$/;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* W-691: a playlist (`/embed/videoseries?list=…`, `/playlist?list=…`) embeds as
|
|
37
|
+
* `videoseries?list=…`. "videoseries" was taken for a video id and the list dropped, so the
|
|
38
|
+
* player showed "Video unavailable".
|
|
39
|
+
*/
|
|
40
|
+
function youtubePlaylist(parsed: URL): string | undefined | null {
|
|
41
|
+
const path = parsed.pathname.replace(/\/+$/, "");
|
|
42
|
+
if (path !== "/embed/videoseries" && path !== "/playlist") return null;
|
|
43
|
+
const list = matching(parsed.searchParams.get("list") ?? undefined, YT_LIST);
|
|
44
|
+
return list ? `videoseries?list=${list}` : undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
30
47
|
function youtubeId(parsed: URL): string | undefined {
|
|
31
48
|
const host = parsed.hostname.toLowerCase();
|
|
32
49
|
const path = parsed.pathname;
|
|
50
|
+
const playlist = youtubePlaylist(parsed);
|
|
51
|
+
if (playlist !== null) return playlist;
|
|
33
52
|
if (host === "youtu.be" || host === "www.youtu.be") return matching(firstSegment(path), YT_ID);
|
|
34
53
|
// W-215: /live/ links (a stream or its replay) too.
|
|
35
54
|
for (const prefix of ["/embed/", "/shorts/", "/live/"]) {
|
|
@@ -56,7 +75,9 @@ function vimeoId(parsed: URL): string | undefined {
|
|
|
56
75
|
: 0
|
|
57
76
|
: parts[0] === "channels"
|
|
58
77
|
? 2
|
|
59
|
-
: parts[0] === "groups" && parts[2] === "videos"
|
|
78
|
+
: (parts[0] === "groups" && parts[2] === "videos") ||
|
|
79
|
+
// W-546: a video opened from a showcase.
|
|
80
|
+
(parts[0] === "showcase" && parts[2] === "video")
|
|
60
81
|
? 3
|
|
61
82
|
: 0;
|
|
62
83
|
const id = matching(parts[at], VIMEO_ID);
|
|
@@ -93,7 +114,7 @@ const withStart = (provider: "youtube" | "vimeo", src: string, start: number | u
|
|
|
93
114
|
start === undefined
|
|
94
115
|
? src
|
|
95
116
|
: provider === "youtube"
|
|
96
|
-
? `${src}?start=${start}`
|
|
117
|
+
? `${src}${src.includes("?") ? "&" : "?"}start=${start}`
|
|
97
118
|
: `${src}#t=${start}s`;
|
|
98
119
|
|
|
99
120
|
/**
|
|
@@ -116,16 +137,32 @@ const PROVIDERS = [
|
|
|
116
137
|
*/
|
|
117
138
|
// W-448: "youtube.com/watch?v=…" typed without https:// was taken for a video file path on this
|
|
118
139
|
// site, so the page showed a broken player. Known video hosts get their scheme.
|
|
119
|
-
|
|
120
|
-
|
|
140
|
+
// W-659: every host the providers accept, not a hand-kept subset (youtube-nocookie.com and
|
|
141
|
+
// www.youtu.be still became a broken file player).
|
|
142
|
+
function bareVideoHost(typed: string): boolean {
|
|
143
|
+
const slash = typed.indexOf("/");
|
|
144
|
+
if (slash <= 0) return false;
|
|
145
|
+
const host = typed.slice(0, slash).toLowerCase();
|
|
146
|
+
return YT_HOSTS.has(host) || VIMEO_HOSTS.has(host);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** A site path (not `//host`) to a .mp4/.webm/.ogg file, or the media file route. */
|
|
150
|
+
function isVideoFilePath(value: string): boolean {
|
|
151
|
+
if (value.startsWith("//")) return false;
|
|
152
|
+
const path = value.split(/[?#]/)[0] ?? "";
|
|
153
|
+
return /\.(mp4|webm|ogg)$/i.test(path) || path.startsWith("/_emdash/api/media/file/");
|
|
154
|
+
}
|
|
121
155
|
|
|
122
156
|
export function resolveEmbedUrl(value: string): EmbedTarget | undefined {
|
|
123
157
|
const typed = value.trim();
|
|
124
|
-
const trimmed =
|
|
158
|
+
const trimmed = bareVideoHost(typed) ? `https://${typed}` : typed;
|
|
125
159
|
if (trimmed.length === 0 || trimmed.length > 2000) return undefined;
|
|
126
160
|
|
|
127
161
|
const hasScheme = /^[a-z][a-z0-9+.-]*:/i.test(trimmed);
|
|
128
162
|
if (!hasScheme) {
|
|
163
|
+
// W-795: a bare word such as "nonsense" became a page-relative <video> (a black player).
|
|
164
|
+
// A relative value must name a video file or the media route, as absolute ones must.
|
|
165
|
+
if (!isVideoFilePath(trimmed)) return undefined;
|
|
129
166
|
const media = sanitizeMediaUrl(trimmed);
|
|
130
167
|
if (!media) return undefined;
|
|
131
168
|
return { kind: "video", src: media };
|
package/src/core/sanitize/url.ts
CHANGED
|
@@ -20,7 +20,8 @@ export function sanitizeUrl(value: string, schemes: ReadonlySet<string>): string
|
|
|
20
20
|
// second address hides in the same string.
|
|
21
21
|
if (/[^\S ]|\\/.test(trimmed)) return undefined;
|
|
22
22
|
// Relative: /path, ./path, ../path, ?query, #hash, or bare path segment
|
|
23
|
-
|
|
23
|
+
// W-683: or one that starts in another script ("über-uns", "контакты"), like page slugs (W-554).
|
|
24
|
+
if (/^(?:[/?#.]|[\p{L}\p{N}._~-])/u.test(trimmed)) return trimmed;
|
|
24
25
|
return undefined;
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { addSectionNear, REASONS, withFreshIds, type Added, type Refusal } from "./arrange.ts";
|
|
2
|
+
import { prepareElement, prepareStyle, type Dropped } from "./clipboard.ts";
|
|
3
|
+
import { cleanClassName, MAX_CLASSES, nameKey } from "./design/classes.ts";
|
|
4
|
+
import { clipText, MAX_LAYOUT_BYTES } from "./limits.ts";
|
|
5
|
+
import { isRecord } from "./record.ts";
|
|
6
|
+
import { DESIGN_SCHEMA_VERSION, type DesignSystem } from "./schema/design.ts";
|
|
7
|
+
import { LAYOUT_SCHEMA_VERSION, type Layout, type LayoutNode } from "./schema/layout.ts";
|
|
8
|
+
import { findNode, newNodeId, nodeChildren, slugify } from "./tree-ops.ts";
|
|
9
|
+
import { byteLength, summarizeIssues, validateDesign, validateLayout } from "./validate.ts";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Saved sections (W-874, D-060): a named copy of an element and its children, kept per site so it
|
|
13
|
+
* can be inserted on any page. Each save carries a snapshot of the classes it uses, so it keeps
|
|
14
|
+
* its look on insert. Old saves are upgraded when read, through the same layout and design
|
|
15
|
+
* migrations as pages and site styles.
|
|
16
|
+
*/
|
|
17
|
+
const SAVED_SECTION_VERSION = 1;
|
|
18
|
+
export const SAVED_SECTION_NAME_MAX = 60;
|
|
19
|
+
export const MAX_SAVED_SECTIONS = 200;
|
|
20
|
+
|
|
21
|
+
type StyleClass = NonNullable<DesignSystem["classes"]>[number];
|
|
22
|
+
|
|
23
|
+
/** What storage holds for one saved section. */
|
|
24
|
+
export type SavedSectionRecord = {
|
|
25
|
+
version: typeof SAVED_SECTION_VERSION;
|
|
26
|
+
name: string;
|
|
27
|
+
layout: Layout;
|
|
28
|
+
designSchemaVersion: number;
|
|
29
|
+
classes: StyleClass[];
|
|
30
|
+
createdAt: string;
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** One saved section in a list (W-875). `damaged` rows can only be deleted. */
|
|
35
|
+
export type SavedSectionSummary = {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
updatedAt: string;
|
|
39
|
+
classCount: number;
|
|
40
|
+
damaged?: true;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** A saved section after it has been read, checked and upgraded. */
|
|
44
|
+
export type SavedSection = {
|
|
45
|
+
name: string;
|
|
46
|
+
node: LayoutNode;
|
|
47
|
+
classes: StyleClass[];
|
|
48
|
+
createdAt: string;
|
|
49
|
+
updatedAt: string;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const SAVED_SECTION_REASONS = {
|
|
53
|
+
name: "Give the section a name.",
|
|
54
|
+
root: "Choose an element inside the page; the page itself can't be saved as a section.",
|
|
55
|
+
missing: REASONS.missing,
|
|
56
|
+
tooBig: "This section is too big to save.",
|
|
57
|
+
damaged: "This saved section can't be read.",
|
|
58
|
+
tooManyClasses: `Inserting this section would go over ${MAX_CLASSES} classes on this site.`,
|
|
59
|
+
} as const;
|
|
60
|
+
|
|
61
|
+
const refuse = (reason: string): Refusal => ({ ok: false, reason });
|
|
62
|
+
const WRAPPER_ID = "savedsection";
|
|
63
|
+
|
|
64
|
+
/** The name as stored: cleaned like a class name, at most 60 characters; "" when blank. */
|
|
65
|
+
export const savedSectionName = (raw: string): string =>
|
|
66
|
+
clipText(cleanClassName(raw), SAVED_SECTION_NAME_MAX).trim();
|
|
67
|
+
|
|
68
|
+
/** A copy without A/B test arms: a saved copy is never part of the original's test (as W-629). */
|
|
69
|
+
function withoutVariants(node: LayoutNode): LayoutNode {
|
|
70
|
+
const { variant: _variant, ...rest } = node as LayoutNode & { variant?: unknown };
|
|
71
|
+
const kids = nodeChildren(node);
|
|
72
|
+
if (kids.length === 0) return rest as LayoutNode;
|
|
73
|
+
return { ...rest, children: kids.map(withoutVariants) } as LayoutNode;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function classIdsIn(node: LayoutNode, into = new Set<string>()): Set<string> {
|
|
77
|
+
for (const id of node.classes ?? []) into.add(id);
|
|
78
|
+
for (const child of nodeChildren(node)) classIdsIn(child, into);
|
|
79
|
+
return into;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const wrap = (node: LayoutNode): Layout => ({
|
|
83
|
+
schemaVersion: LAYOUT_SCHEMA_VERSION,
|
|
84
|
+
root: { id: WRAPPER_ID, type: "container", props: {}, children: [node] },
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
/** The record storage holds for a section that has been read (an old save comes back upgraded). */
|
|
88
|
+
export const savedSectionRecord = (section: SavedSection): SavedSectionRecord => ({
|
|
89
|
+
version: SAVED_SECTION_VERSION,
|
|
90
|
+
name: section.name,
|
|
91
|
+
layout: wrap(section.node),
|
|
92
|
+
designSchemaVersion: DESIGN_SCHEMA_VERSION,
|
|
93
|
+
classes: section.classes,
|
|
94
|
+
createdAt: section.createdAt,
|
|
95
|
+
updatedAt: section.updatedAt,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/** A record for `nodeId` with the classes it uses, or why it can't be saved. */
|
|
99
|
+
export function snapshotSection(
|
|
100
|
+
layout: Layout,
|
|
101
|
+
nodeId: string,
|
|
102
|
+
design: DesignSystem,
|
|
103
|
+
rawName: string,
|
|
104
|
+
now: string,
|
|
105
|
+
): { ok: true; record: SavedSectionRecord } | Refusal {
|
|
106
|
+
const name = savedSectionName(rawName);
|
|
107
|
+
if (!name) return refuse(SAVED_SECTION_REASONS.name);
|
|
108
|
+
if (nodeId === layout.root.id) return refuse(SAVED_SECTION_REASONS.root);
|
|
109
|
+
const found = findNode(layout, nodeId);
|
|
110
|
+
if (!found) return refuse(SAVED_SECTION_REASONS.missing);
|
|
111
|
+
const node = withoutVariants(structuredClone(found));
|
|
112
|
+
const used = classIdsIn(node);
|
|
113
|
+
const classes = (design.classes ?? [])
|
|
114
|
+
.filter((c) => used.has(c.id))
|
|
115
|
+
.map((c) => structuredClone(c));
|
|
116
|
+
const record: SavedSectionRecord = {
|
|
117
|
+
version: SAVED_SECTION_VERSION,
|
|
118
|
+
name,
|
|
119
|
+
layout: wrap(node),
|
|
120
|
+
designSchemaVersion: DESIGN_SCHEMA_VERSION,
|
|
121
|
+
classes,
|
|
122
|
+
createdAt: now,
|
|
123
|
+
updatedAt: now,
|
|
124
|
+
};
|
|
125
|
+
if (byteLength(record) > MAX_LAYOUT_BYTES) return refuse(SAVED_SECTION_REASONS.tooBig);
|
|
126
|
+
const checked = validateLayout(record.layout);
|
|
127
|
+
if (!checked.ok) return refuse(summarizeIssues(checked.issues));
|
|
128
|
+
return { ok: true, record };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A stored record, checked and upgraded: the layout through the layout migrations, the classes
|
|
133
|
+
* through the design migrations. Anything that doesn't pass is refused, never half-used.
|
|
134
|
+
*/
|
|
135
|
+
export function readSavedSection(raw: unknown): { ok: true; section: SavedSection } | Refusal {
|
|
136
|
+
if (!isRecord(raw) || raw["version"] !== SAVED_SECTION_VERSION) {
|
|
137
|
+
return refuse(SAVED_SECTION_REASONS.damaged);
|
|
138
|
+
}
|
|
139
|
+
const name = typeof raw["name"] === "string" ? savedSectionName(raw["name"]) : "";
|
|
140
|
+
const createdAt = typeof raw["createdAt"] === "string" ? raw["createdAt"] : "";
|
|
141
|
+
const updatedAt = typeof raw["updatedAt"] === "string" ? raw["updatedAt"] : createdAt;
|
|
142
|
+
if (!name || !createdAt) return refuse(SAVED_SECTION_REASONS.damaged);
|
|
143
|
+
const layout = validateLayout(raw["layout"]);
|
|
144
|
+
if (!layout.ok) return refuse(SAVED_SECTION_REASONS.damaged);
|
|
145
|
+
const node = layout.layout.root.children[0];
|
|
146
|
+
if (!node || layout.layout.root.children.length !== 1) {
|
|
147
|
+
return refuse(SAVED_SECTION_REASONS.damaged);
|
|
148
|
+
}
|
|
149
|
+
const version = raw["designSchemaVersion"];
|
|
150
|
+
const design = validateDesign({
|
|
151
|
+
schemaVersion: typeof version === "number" ? version : DESIGN_SCHEMA_VERSION,
|
|
152
|
+
variables: { colors: [] },
|
|
153
|
+
classes: Array.isArray(raw["classes"]) ? raw["classes"] : [],
|
|
154
|
+
});
|
|
155
|
+
if (!design.ok) return refuse(SAVED_SECTION_REASONS.damaged);
|
|
156
|
+
return {
|
|
157
|
+
ok: true,
|
|
158
|
+
section: { name, node, classes: design.design.classes ?? [], createdAt, updatedAt },
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** A class's look, in one comparable form (key order doesn't matter). */
|
|
163
|
+
function lookOf(cls: StyleClass): string {
|
|
164
|
+
const sorted = (value: unknown): unknown =>
|
|
165
|
+
Array.isArray(value)
|
|
166
|
+
? value.map(sorted)
|
|
167
|
+
: isRecord(value)
|
|
168
|
+
? Object.fromEntries(
|
|
169
|
+
Object.keys(value)
|
|
170
|
+
.toSorted()
|
|
171
|
+
.map((key) => [key, sorted(value[key])]),
|
|
172
|
+
)
|
|
173
|
+
: value;
|
|
174
|
+
const { id: _id, name: _name, ...look } = cls;
|
|
175
|
+
return JSON.stringify(sorted(look));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type ClassMerge = {
|
|
179
|
+
design: DesignSystem;
|
|
180
|
+
/** Saved class id → the id it has on this site. */
|
|
181
|
+
ids: Map<string, string>;
|
|
182
|
+
added: string[];
|
|
183
|
+
reused: string[];
|
|
184
|
+
renamed: { from: string; to: string }[];
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Brings a saved section's classes onto this site (D-060). Never changes a class that is already
|
|
189
|
+
* here: a class with the same id or name and the same look is reused; one whose look differs is
|
|
190
|
+
* added as a copy with a numbered name ("Card 2") and a new id; a missing one is added.
|
|
191
|
+
*/
|
|
192
|
+
export function mergeSectionClasses(
|
|
193
|
+
design: DesignSystem,
|
|
194
|
+
incoming: readonly StyleClass[],
|
|
195
|
+
): ClassMerge | Refusal {
|
|
196
|
+
const classes = [...(design.classes ?? [])];
|
|
197
|
+
const merge: ClassMerge = { design, ids: new Map(), added: [], reused: [], renamed: [] };
|
|
198
|
+
for (const raw of incoming) {
|
|
199
|
+
// A ref to a colour or size this site doesn't have is dropped, like on paste.
|
|
200
|
+
const { style } = prepareStyle(raw, design);
|
|
201
|
+
const cls: StyleClass = { id: raw.id, name: raw.name, style: style.style ?? {} };
|
|
202
|
+
if (style.states) cls.states = style.states;
|
|
203
|
+
if (style.devices) cls.devices = style.devices;
|
|
204
|
+
if (style.hiddenOn) cls.hiddenOn = style.hiddenOn;
|
|
205
|
+
const look = lookOf(cls);
|
|
206
|
+
const same = classes.find(
|
|
207
|
+
(c) => (c.id === cls.id || nameKey(c.name) === nameKey(cls.name)) && lookOf(c) === look,
|
|
208
|
+
);
|
|
209
|
+
if (same) {
|
|
210
|
+
merge.ids.set(raw.id, same.id);
|
|
211
|
+
merge.reused.push(same.name);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (classes.length >= MAX_CLASSES) return refuse(SAVED_SECTION_REASONS.tooManyClasses);
|
|
215
|
+
const names = new Set(classes.map((c) => nameKey(c.name)));
|
|
216
|
+
let name = cls.name;
|
|
217
|
+
for (let n = 2; names.has(nameKey(name)); n++) {
|
|
218
|
+
name = `${clipText(cls.name, 54).trim()} ${n}`;
|
|
219
|
+
}
|
|
220
|
+
const ids = new Set(classes.map((c) => c.id));
|
|
221
|
+
const base = ids.has(cls.id)
|
|
222
|
+
? slugify(name).slice(0, 34).replace(/-+$/, "") || "class"
|
|
223
|
+
: cls.id;
|
|
224
|
+
let id = base;
|
|
225
|
+
for (let n = 2; ids.has(id); n++) id = `${base}-${n}`.slice(0, 40);
|
|
226
|
+
classes.push({ ...cls, id, name });
|
|
227
|
+
merge.ids.set(raw.id, id);
|
|
228
|
+
if (name === cls.name) merge.added.push(name);
|
|
229
|
+
else merge.renamed.push({ from: cls.name, to: name });
|
|
230
|
+
}
|
|
231
|
+
merge.design = { ...design, classes };
|
|
232
|
+
return merge;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function withClassIds(node: LayoutNode, ids: ReadonlyMap<string, string>): LayoutNode {
|
|
236
|
+
const kids = nodeChildren(node);
|
|
237
|
+
const next = { ...node } as LayoutNode;
|
|
238
|
+
if (node.classes) next.classes = node.classes.map((id) => ids.get(id) ?? id);
|
|
239
|
+
if (kids.length > 0) {
|
|
240
|
+
(next as { children: LayoutNode[] }).children = kids.map((kid) => withClassIds(kid, ids));
|
|
241
|
+
}
|
|
242
|
+
return next;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export type PreparedSection = {
|
|
246
|
+
node: LayoutNode;
|
|
247
|
+
design: DesignSystem;
|
|
248
|
+
merge: ClassMerge;
|
|
249
|
+
dropped: Dropped;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* The node to insert for a saved section on `layout`, and the site styles with its classes:
|
|
254
|
+
* classes merged as above, then the same checks as a paste (new ids, CSS ids already on the page
|
|
255
|
+
* dropped, links, images and SVGs sanitized).
|
|
256
|
+
*/
|
|
257
|
+
export function prepareSavedSection(
|
|
258
|
+
section: SavedSection,
|
|
259
|
+
layout: Layout,
|
|
260
|
+
design: DesignSystem,
|
|
261
|
+
random: () => number = Math.random,
|
|
262
|
+
/** A merge already applied to `design` (its classes are saved): reused, not merged again. */
|
|
263
|
+
merged?: ClassMerge,
|
|
264
|
+
): ({ ok: true } & PreparedSection) | Refusal {
|
|
265
|
+
const merge = merged ?? mergeSectionClasses(design, section.classes);
|
|
266
|
+
if ("ok" in merge) return merge;
|
|
267
|
+
const remapped = withClassIds(section.node, merge.ids);
|
|
268
|
+
const { node, dropped } = prepareElement(remapped, layout, merge.design, random);
|
|
269
|
+
return { ok: true, node, design: merge.design, merge, dropped };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** Prepares and adds a saved section near the selection, like a section recipe (W-320). */
|
|
273
|
+
export function insertSavedSection(
|
|
274
|
+
section: SavedSection,
|
|
275
|
+
layout: Layout,
|
|
276
|
+
design: DesignSystem,
|
|
277
|
+
selectedId: string | null,
|
|
278
|
+
random: () => number = Math.random,
|
|
279
|
+
): ({ design: DesignSystem; merge: ClassMerge; dropped: Dropped } & Added) | Refusal {
|
|
280
|
+
const prepared = prepareSavedSection(section, layout, design, random);
|
|
281
|
+
if (!prepared.ok) return prepared;
|
|
282
|
+
const added = addSectionNear(layout, prepared.node, selectedId);
|
|
283
|
+
if (!added.ok) return added;
|
|
284
|
+
return { ...added, design: prepared.design, merge: prepared.merge, dropped: prepared.dropped };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** "Classes: 1 added, 1 renamed (Card → Card 2)" for the notice, or null when nothing changed. */
|
|
288
|
+
export function classMergeNotice(merge: ClassMerge): string | null {
|
|
289
|
+
const parts: string[] = [];
|
|
290
|
+
if (merge.added.length > 0) parts.push(`${merge.added.length} added`);
|
|
291
|
+
if (merge.renamed.length > 0) {
|
|
292
|
+
const list = merge.renamed.map(({ from, to }) => `${from} → ${to}`).join(", ");
|
|
293
|
+
parts.push(`${merge.renamed.length} added as a copy (${list})`);
|
|
294
|
+
}
|
|
295
|
+
return parts.length > 0 ? `Classes: ${parts.join("; ")}.` : null;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The layout of a new Section theme part for a synced section (W-876, W-098): a copy of the
|
|
300
|
+
* element with fresh ids and no A/B arms. Null for the page itself or an unknown id.
|
|
301
|
+
*/
|
|
302
|
+
export function syncedPartLayout(
|
|
303
|
+
layout: Layout,
|
|
304
|
+
nodeId: string,
|
|
305
|
+
random: () => number = Math.random,
|
|
306
|
+
): Layout | null {
|
|
307
|
+
const found = nodeId === layout.root.id ? undefined : findNode(layout, nodeId);
|
|
308
|
+
if (!found) return null;
|
|
309
|
+
return {
|
|
310
|
+
schemaVersion: LAYOUT_SCHEMA_VERSION,
|
|
311
|
+
root: {
|
|
312
|
+
id: newNodeId(random),
|
|
313
|
+
type: "container",
|
|
314
|
+
props: {},
|
|
315
|
+
children: [withFreshIds(layout, withoutVariants(found), random)],
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
}
|
|
@@ -8,7 +8,7 @@ import { DeviceStyles, HiddenOn, StyleProps, StyleStates } from "./style.ts";
|
|
|
8
8
|
* 13 since W-307, in step with layouts (the W-307 batch only adds optional fields).
|
|
9
9
|
* 12 since W-160: class gradients use the same stops as layouts. v11 `{ angle, from, to }` upgrades on read.
|
|
10
10
|
*/
|
|
11
|
-
export const DESIGN_SCHEMA_VERSION =
|
|
11
|
+
export const DESIGN_SCHEMA_VERSION = 16;
|
|
12
12
|
|
|
13
13
|
/** Tags a site can give a starting style. Classes and local styles still win. */
|
|
14
14
|
export const DEFAULT_STYLE_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "a", "button"] as const;
|
|
@@ -17,7 +17,7 @@ import { DeviceStyles, HiddenOn, Length, StyleProps, StyleStates } from "./style
|
|
|
17
17
|
* (`{ angle, from, to }`) become a linear gradient on read.
|
|
18
18
|
* 11 since W-156 and W-157 (D-045): the layout Section element and an editor-only node label.
|
|
19
19
|
*/
|
|
20
|
-
export const LAYOUT_SCHEMA_VERSION =
|
|
20
|
+
export const LAYOUT_SCHEMA_VERSION = 17;
|
|
21
21
|
|
|
22
22
|
export const NodeId = z
|
|
23
23
|
.string()
|
|
@@ -107,7 +107,7 @@ export const AUDIENCE_DEVICES = ["mobile", "tablet", "desktop"] as const;
|
|
|
107
107
|
/** A visitor segment name the host passes and a Visitors rule matches (W-329). */
|
|
108
108
|
/** A host segment name: letters, digits, and `:` `_` `-`, up to 64 characters (`plan:pro`). */
|
|
109
109
|
export const AUDIENCE_SEGMENT = /^[a-z0-9][a-z0-9:_-]{0,63}$/;
|
|
110
|
-
const SEGMENT_HINT = "Segments are lowercase letters, digits, :, - or _,
|
|
110
|
+
const SEGMENT_HINT = "Segments are lowercase letters, digits, :, - or _, such as plan:pro";
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
113
|
* Who sees an element (W-313): visitors from these countries, on these devices, new or
|
|
@@ -117,7 +117,7 @@ const SEGMENT_HINT = "Segments are lowercase letters, digits, :, - or _, e.g. pl
|
|
|
117
117
|
*/
|
|
118
118
|
export const Audience = z.strictObject({
|
|
119
119
|
countries: z
|
|
120
|
-
.array(z.string().regex(/^[A-Z]{2}$/, "Two-letter country codes,
|
|
120
|
+
.array(z.string().regex(/^[A-Z]{2}$/, "Two-letter country codes, such as CA"))
|
|
121
121
|
.min(1)
|
|
122
122
|
.max(50)
|
|
123
123
|
.optional(),
|
|
@@ -567,7 +567,7 @@ export const PostLinkNode = leafNode(
|
|
|
567
567
|
export const LOOP_DISPLAYS = ["list", "grid", "cards"] as const;
|
|
568
568
|
/** A collection field's slug, e.g. `photo` (W-330). */
|
|
569
569
|
const FIELD_SLUG = /^[a-z][a-z0-9_]{0,63}$/;
|
|
570
|
-
const FIELD_SLUG_HINT = "Use the field's slug,
|
|
570
|
+
const FIELD_SLUG_HINT = "Use the field's slug, such as photo";
|
|
571
571
|
/** A site path with `{slug}` or `{id}`, and no other placeholders (W-330). */
|
|
572
572
|
export const LOOP_PERMALINK =
|
|
573
573
|
/^(?=.*\{(?:slug|id)\})\/(?!\/)(?:[A-Za-z0-9._~/-]|\{slug\}|\{id\})*$/;
|
|
@@ -593,7 +593,7 @@ export const LoopNode = parentNode(
|
|
|
593
593
|
*/
|
|
594
594
|
collection: z
|
|
595
595
|
.string()
|
|
596
|
-
.regex(/^[a-z][a-z0-9_]{0,63}$/, "Use the collection's slug,
|
|
596
|
+
.regex(/^[a-z][a-z0-9_]{0,63}$/, "Use the collection's slug, such as team")
|
|
597
597
|
.optional(),
|
|
598
598
|
/** How many entries a collection Loop shows, 1–50. Unset = 6. */
|
|
599
599
|
limit: z.number().int().min(1).max(50).optional(),
|
|
@@ -608,7 +608,7 @@ export const LoopNode = parentNode(
|
|
|
608
608
|
permalink: z
|
|
609
609
|
.string()
|
|
610
610
|
.max(200)
|
|
611
|
-
.regex(LOOP_PERMALINK, "A site path with {slug} or {id},
|
|
611
|
+
.regex(LOOP_PERMALINK, "A site path with {slug} or {id}, such as /team/{slug}")
|
|
612
612
|
.optional(),
|
|
613
613
|
/** The entry field holding the image Post Image shows (W-330). Unset = featured_image. */
|
|
614
614
|
imageField: z.string().regex(FIELD_SLUG, FIELD_SLUG_HINT).optional(),
|
|
@@ -650,6 +650,14 @@ export const PaginationNode = leafNode(
|
|
|
650
650
|
* Unset = "{title} – page {page}". Hosts read it with `archivePageTitle`.
|
|
651
651
|
*/
|
|
652
652
|
titleText: z.string().max(60).optional(),
|
|
653
|
+
archiveTitle: z.string().max(60).optional(),
|
|
654
|
+
/** W-689: screen reader names in the site's language. Unset = "Pagination". */
|
|
655
|
+
navLabel: z.string().max(60).optional(),
|
|
656
|
+
/** Each number's name; `{page}` is filled in. Unset = "Page {page}". */
|
|
657
|
+
pageLabel: z.string().max(60).optional(),
|
|
658
|
+
/** Previous / Next names when their text is only an arrow. Unset = "Previous page" / "Next page". */
|
|
659
|
+
prevLabel: z.string().max(60).optional(),
|
|
660
|
+
nextLabel: z.string().max(60).optional(),
|
|
653
661
|
}),
|
|
654
662
|
);
|
|
655
663
|
|
|
@@ -910,7 +918,8 @@ export type TabPanelNode = NodeEnvelope & {
|
|
|
910
918
|
|
|
911
919
|
export type TabsNode = NodeEnvelope & {
|
|
912
920
|
type: "tabs";
|
|
913
|
-
|
|
921
|
+
/** W-790: read from TabsNodeSchema, so the type can't drift from what the schema accepts. */
|
|
922
|
+
props: z.infer<typeof TabsNodeSchema>["props"];
|
|
914
923
|
children: LayoutNode[];
|
|
915
924
|
};
|
|
916
925
|
|
package/src/core/schema/style.ts
CHANGED
|
@@ -266,14 +266,16 @@ export const StyleProps = z.strictObject({
|
|
|
266
266
|
})
|
|
267
267
|
.optional(),
|
|
268
268
|
/**
|
|
269
|
-
* A
|
|
270
|
-
* (W-
|
|
269
|
+
* A spin or pulse; off for visitors who prefer reduced motion. It stops after about 5 s
|
|
270
|
+
* (W-848) unless `loop` is true (W-853, D-059). `{ type: "none" }` (W-248) stops an animation a
|
|
271
|
+
* device would otherwise inherit from a wider one.
|
|
271
272
|
*/
|
|
272
273
|
iconAnimation: z
|
|
273
274
|
.union([
|
|
274
275
|
z.strictObject({
|
|
275
276
|
type: z.enum(["spin", "pulse"]),
|
|
276
277
|
duration: z.number().int().min(200).max(10_000),
|
|
278
|
+
loop: z.literal(true).optional(),
|
|
277
279
|
}),
|
|
278
280
|
z.strictObject({ type: z.literal("none") }),
|
|
279
281
|
])
|
package/src/core/stats.ts
CHANGED
|
@@ -12,7 +12,8 @@ export function summarizeLayout(input: unknown): LayoutSummary | undefined {
|
|
|
12
12
|
if (typeof node !== "object" || node === null) continue;
|
|
13
13
|
nodes++;
|
|
14
14
|
const children = (node as { children?: unknown }).children;
|
|
15
|
-
|
|
15
|
+
// No spread: a huge children list would overflow the call stack (W-646).
|
|
16
|
+
if (Array.isArray(children)) for (const child of children) stack.push(child);
|
|
16
17
|
}
|
|
17
18
|
return { nodes, schemaVersion };
|
|
18
19
|
}
|
|
@@ -142,8 +142,10 @@ export function conditionSpecificity(rule: ConditionRule): number {
|
|
|
142
142
|
if (
|
|
143
143
|
rule.group === "archive" &&
|
|
144
144
|
rule.name === "taxonomy" &&
|
|
145
|
-
typeof rule.args["slug"] === "string"
|
|
145
|
+
typeof rule.args["slug"] === "string" &&
|
|
146
|
+
rule.args["slug"] !== ""
|
|
146
147
|
) {
|
|
148
|
+
// A blank slug matches every term (taxonomyMatches), so it is not more specific (W-584).
|
|
147
149
|
score += 5;
|
|
148
150
|
}
|
|
149
151
|
return score;
|
|
@@ -41,6 +41,8 @@ export type ThemeDynamicData = {
|
|
|
41
41
|
sectionTemplates?: Record<string, Layout>;
|
|
42
42
|
/** Section part ids already being expanded, so a section cannot include itself. */
|
|
43
43
|
sectionStack?: readonly string[];
|
|
44
|
+
/** Loop item parts being rendered, outermost first, so a part that lists itself stops (W-654). */
|
|
45
|
+
loopStack?: readonly string[];
|
|
44
46
|
/**
|
|
45
47
|
* Where the nodes being rendered come from (W-250): unset for the page itself, else the synced
|
|
46
48
|
* section and loop item parts they were expanded from. Another layout can reuse an id.
|
|
@@ -170,8 +172,14 @@ const hasText = (nodes: readonly (VNode | string)[]): boolean =>
|
|
|
170
172
|
*/
|
|
171
173
|
export function portableTextToVNodes(value: unknown): VNode[] {
|
|
172
174
|
if (typeof value === "string") {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
+
// W-662: plain-text content kept its blank lines and line breaks as raw newlines, which
|
|
176
|
+
// the page collapses, so every paragraph ran together into one.
|
|
177
|
+
return value
|
|
178
|
+
.replaceAll("\r\n", "\n")
|
|
179
|
+
.split(/\n[ \t]*\n/)
|
|
180
|
+
.map((para) => para.trim())
|
|
181
|
+
.filter(Boolean)
|
|
182
|
+
.map((para) => ({ tag: "p", attrs: {}, children: withBreaks(para) }));
|
|
175
183
|
}
|
|
176
184
|
if (!Array.isArray(value)) return [];
|
|
177
185
|
const out: VNode[] = [];
|
|
@@ -214,9 +222,32 @@ export function portableTextToVNodes(value: unknown): VNode[] {
|
|
|
214
222
|
const tag = style === "normal" ? "p" : style;
|
|
215
223
|
out.push({ tag, attrs: {}, children: inline });
|
|
216
224
|
}
|
|
217
|
-
return out
|
|
218
|
-
|
|
219
|
-
|
|
225
|
+
return pruneEmptyLists(out);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Lists with no items dropped at every depth (W-585): a blank nested item used to leave an empty
|
|
230
|
+
* `<ul>` inside its parent item, or an `<li>` holding only that empty list.
|
|
231
|
+
*/
|
|
232
|
+
const isList = (n: VNode): boolean => n.tag === "ul" || n.tag === "ol";
|
|
233
|
+
|
|
234
|
+
function pruneEmptyLists(nodes: VNode[]): VNode[] {
|
|
235
|
+
const keep: VNode[] = [];
|
|
236
|
+
for (const node of nodes) {
|
|
237
|
+
if (isList(node)) {
|
|
238
|
+
const items: VNode[] = [];
|
|
239
|
+
for (const li of node.children) {
|
|
240
|
+
if (typeof li === "string") continue;
|
|
241
|
+
li.children = li.children.flatMap((c) =>
|
|
242
|
+
typeof c !== "string" && isList(c) ? pruneEmptyLists([c]) : [c],
|
|
243
|
+
);
|
|
244
|
+
if (li.children.length > 0) items.push(li);
|
|
245
|
+
}
|
|
246
|
+
node.children = items;
|
|
247
|
+
if (items.length > 0) keep.push(node);
|
|
248
|
+
} else keep.push(node);
|
|
249
|
+
}
|
|
250
|
+
return keep;
|
|
220
251
|
}
|
|
221
252
|
|
|
222
253
|
/** Collect `loop.itemPartId` values so hosts can load Loop Item templates. */
|
package/src/core/theme/float.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { chromeLabel } from "./popup-markup.ts";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { escapeAttr } from "../sanitize/escape.ts";
|
|
3
4
|
import type { DesignSystem } from "../schema/design.ts";
|
|
@@ -43,7 +44,11 @@ export function validateFloatSettings(raw: unknown): FloatValidation {
|
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* Chrome for pinned bars and corner floats. Loaded only when a float matches.
|
|
47
|
+
* W-759: a corner float keeps its 1rem gap on both sides and never grows past the screen; a long
|
|
48
|
+
* one scrolls inside (on a phone it ran off the top, taking its close button and heading with it).
|
|
46
49
|
* Bars reserve their height through the two custom properties the runtime sets.
|
|
50
|
+
* W-844 (D-053): a top or bottom bar is capped at half the screen and its body scrolls, so a
|
|
51
|
+
* tall bar can't cover a phone.
|
|
47
52
|
*/
|
|
48
53
|
export const FLOAT_CHROME_CSS = `
|
|
49
54
|
.emvb-float{position:fixed;z-index:9000;box-sizing:border-box;max-width:100%;display:flex;align-items:flex-start;gap:.35rem}.emvb-float:hover,.emvb-float:focus-within{z-index:9001}
|
|
@@ -57,9 +62,12 @@ export const FLOAT_CHROME_CSS = `
|
|
|
57
62
|
:where(.emvb-float--surface){background:#fff;color:#0f172a;box-shadow:0 4px 16px -4px rgba(15,23,42,.25);padding:.5rem 1rem}
|
|
58
63
|
:where(.emvb-float--surface:is(.emvb-float--start-top,.emvb-float--end-top,.emvb-float--start-bottom,.emvb-float--end-bottom)){border-radius:.75rem;padding:.75rem 1rem}
|
|
59
64
|
.emvb-float__body{min-width:0;flex:1}
|
|
65
|
+
.emvb-float:is(.emvb-float--start-top,.emvb-float--end-top,.emvb-float--start-bottom,.emvb-float--end-bottom){max-width:calc(100% - 2rem)}
|
|
66
|
+
.emvb-float:is(.emvb-float--start-top,.emvb-float--end-top,.emvb-float--start-bottom,.emvb-float--end-bottom) .emvb-float__body{max-height:calc(100vh - 3.5rem);max-height:calc(100dvh - 3.5rem);overflow:auto}
|
|
67
|
+
.emvb-float:is(.emvb-float--top,.emvb-float--bottom) .emvb-float__body{max-height:50vh;max-height:50dvh;overflow:auto}
|
|
60
68
|
.emvb-float__close{flex:none;width:2rem;height:2rem;border:0;border-radius:999px;background:transparent;color:inherit;font-size:1.5rem;line-height:1;cursor:pointer}
|
|
61
69
|
.emvb-float__close:focus-visible{outline:2px solid #2563eb;outline-offset:2px}
|
|
62
|
-
html{--emvb-float-top:0px;--emvb-float-bottom:0px}
|
|
70
|
+
html{--emvb-float-top:0px;--emvb-float-bottom:0px;scroll-padding-top:var(--emvb-float-top);scroll-padding-bottom:var(--emvb-float-bottom)}
|
|
63
71
|
body{padding-top:var(--emvb-float-top);padding-bottom:var(--emvb-float-bottom)}
|
|
64
72
|
`
|
|
65
73
|
.replace(/\n+/g, "")
|
|
@@ -97,12 +105,14 @@ export function wrapFloatMarkup(
|
|
|
97
105
|
bodyHtml: string,
|
|
98
106
|
settings: FloatSettings,
|
|
99
107
|
surface = true,
|
|
108
|
+
/** W-690: the close button's name in the site's language. Unset is "Close". */
|
|
109
|
+
closeLabel?: string,
|
|
100
110
|
): string {
|
|
101
111
|
const safeId = escapeAttr(id);
|
|
102
112
|
const label = escapeAttr(title.trim() || "Notice");
|
|
103
113
|
const edge = escapeAttr(settings.edge);
|
|
104
114
|
const close = settings.dismiss
|
|
105
|
-
? `<button type="button" class="emvb-float__close" data-emvb-float-dismiss aria-label="Close"><span aria-hidden="true">×</span></button>`
|
|
115
|
+
? `<button type="button" class="emvb-float__close" data-emvb-float-dismiss aria-label="${chromeLabel(closeLabel, "Close")}"><span aria-hidden="true">×</span></button>`
|
|
106
116
|
: "";
|
|
107
117
|
return [
|
|
108
118
|
`<aside class="emvb-float emvb-float--${edge}${surface ? " emvb-float--surface" : ""}" id="emvb-float-${safeId}" data-emvb-float="${safeId}" data-emvb-float-edge="${edge}" role="region" aria-label="${label}">`,
|