@perkyzz/emvb 0.6.0 → 0.7.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/package.json +1 -1
- 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/Editor.tsx +82 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +97 -72
- package/src/admin/editor/ShareLink.tsx +107 -72
- package/src/admin/editor/ShortcutsDialog.tsx +27 -16
- package/src/admin/editor/Timeline.tsx +255 -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 +38 -14
- 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 +59 -7
- package/src/admin/editor/editor-commands.ts +2 -1
- package/src/admin/editor/editor-css.ts +72 -22
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +45 -13
- package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
- 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 +10 -3
- package/src/admin/editor/panels/AddPanel.tsx +35 -10
- 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 +55 -19
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
- package/src/admin/editor/panels/TokenScales.tsx +76 -36
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
- package/src/admin/editor/panels/VariableSection.tsx +48 -18
- package/src/admin/editor/panels/color-space.ts +9 -3
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
- 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 +12 -8
- 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/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 +17 -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/forms-api.ts +2 -0
- 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 +49 -7
- 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 +4 -2
- package/src/admin/image-editor/load.ts +9 -2
- package/src/admin/image-editor/parts.tsx +51 -2
- package/src/admin/image-editor/save.ts +23 -7
- 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 +27 -7
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +13 -3
- package/src/admin/ui.ts +73 -22
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +33 -3
- 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 +171 -24
- package/src/core/arrange.ts +27 -6
- 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/data/bindings.ts +8 -1
- package/src/core/design/classes.ts +16 -7
- package/src/core/design/diff.ts +6 -0
- package/src/core/design/merge.ts +90 -2
- 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 +44 -5
- package/src/core/elements/form-elements.ts +55 -16
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -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/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 +15 -1
- package/src/core/limits.ts +12 -1
- 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 +43 -7
- 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 +15 -2
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/schema/layout.ts +15 -6
- 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 +9 -2
- package/src/core/theme/pagination.ts +31 -11
- 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/rate-limit.ts +2 -1
- package/src/mcp/read.ts +14 -2
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/write.ts +174 -10
- 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 +6 -1
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isFormNode,
|
|
3
|
+
LAYOUT_SCHEMA_VERSION,
|
|
4
|
+
type Layout,
|
|
5
|
+
type LayoutNode,
|
|
6
|
+
} from "../schema/layout.ts";
|
|
7
|
+
import { loneAbTests } from "../audience/variants.ts";
|
|
2
8
|
import { audienceSummary } from "../audience/rules.ts";
|
|
3
9
|
import { forEachNode, nodeChildren, someNode } from "../tree-ops.ts";
|
|
10
|
+
import { stableJson } from "../stable-json.ts";
|
|
4
11
|
import { fieldsOf, type FormDefinitions } from "./definition.ts";
|
|
5
12
|
|
|
6
13
|
export type MissingRequiredField = {
|
|
@@ -39,6 +46,8 @@ export function findMissingRequiredFields(
|
|
|
39
46
|
const definition = definitions.get(node.props.formId);
|
|
40
47
|
if (!definition) return;
|
|
41
48
|
const bound = boundFields(node);
|
|
49
|
+
// W-595: a hidden field is sent by the form itself, with no control.
|
|
50
|
+
for (const field of fieldsOf(definition)) if (field.type === "hidden") bound.add(field.name);
|
|
42
51
|
for (const field of fieldsOf(definition)) {
|
|
43
52
|
if (field.required && !bound.has(field.name)) {
|
|
44
53
|
missing.push({ formNodeId: node.id, formId: node.props.formId, field: field.name });
|
|
@@ -53,7 +62,7 @@ export function layoutHasForm(layout: Layout): boolean {
|
|
|
53
62
|
}
|
|
54
63
|
|
|
55
64
|
/** A field as the forms plugin defines it; only what the checks below read. */
|
|
56
|
-
export type RequiredFieldInfo = { name: string; label: string; required: boolean };
|
|
65
|
+
export type RequiredFieldInfo = { name: string; label: string; required: boolean; type?: string };
|
|
57
66
|
|
|
58
67
|
/**
|
|
59
68
|
* A required field visitors can't fill (W-511): `missing` has no control in the form; `hidden`
|
|
@@ -85,13 +94,30 @@ const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "ra
|
|
|
85
94
|
const DEVICE_ORDER = ["desktop", "tablet", "mobile"];
|
|
86
95
|
|
|
87
96
|
/** Each bound field's controls, with the devices each is hidden on (itself or an ancestor). */
|
|
88
|
-
type Control = { nodeId: string; hidden: Set<string>; who?: string };
|
|
97
|
+
type Control = { nodeId: string; hidden: Set<string>; who?: string; split?: string };
|
|
89
98
|
|
|
90
99
|
/**
|
|
91
100
|
* W-513: who an element is limited to, by a Visitors rule or as one arm of an A/B test, or
|
|
92
101
|
* undefined when everyone sees it.
|
|
93
102
|
*/
|
|
94
|
-
|
|
103
|
+
/**
|
|
104
|
+
* W-550: the exact visitors split a node makes, e.g. "ab:hero:a" or "aud:1:{rules}". Two
|
|
105
|
+
* controls cover everyone when they are the two halves of one split; labels alone can't tell
|
|
106
|
+
* (they cut long country lists and leave out the time zone).
|
|
107
|
+
*/
|
|
108
|
+
function splitKey(node: LayoutNode, lone: ReadonlySet<string>): string | undefined {
|
|
109
|
+
const audience = node.audience;
|
|
110
|
+
if (audience) {
|
|
111
|
+
const { hide, ...rules } = audience;
|
|
112
|
+
return `aud:${hide ? 1 : 0}:${stableJson(rules)}`;
|
|
113
|
+
}
|
|
114
|
+
if (node.variant && !lone.has(node.variant.test)) {
|
|
115
|
+
return `ab:${node.variant.test}:${node.variant.arm}`;
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function restriction(node: LayoutNode, lone: ReadonlySet<string>): string | undefined {
|
|
95
121
|
const audience = node.audience;
|
|
96
122
|
if (audience) {
|
|
97
123
|
const { hide, timeZone: _zone, ...rules } = audience;
|
|
@@ -99,27 +125,41 @@ function restriction(node: LayoutNode): string | undefined {
|
|
|
99
125
|
return audienceSummary(audience);
|
|
100
126
|
}
|
|
101
127
|
}
|
|
102
|
-
|
|
128
|
+
// W-628: a test missing an arm isn't run, so its remaining arm reaches everyone.
|
|
129
|
+
if (node.variant && !lone.has(node.variant.test)) {
|
|
103
130
|
return `Variant ${node.variant.arm.toUpperCase()} of A/B test ${node.variant.test}`;
|
|
104
131
|
}
|
|
105
132
|
return undefined;
|
|
106
133
|
}
|
|
107
134
|
|
|
108
135
|
function boundControls(form: LayoutNode): Map<string, Control[]> {
|
|
136
|
+
// A/B arms are siblings, so a test's arms inside a form are all inside it.
|
|
137
|
+
const lone = loneAbTests({ schemaVersion: LAYOUT_SCHEMA_VERSION, root: form } as Layout);
|
|
109
138
|
const found = new Map<string, Control[]>();
|
|
110
|
-
const walk = (
|
|
139
|
+
const walk = (
|
|
140
|
+
node: LayoutNode,
|
|
141
|
+
inherited: ReadonlySet<string>,
|
|
142
|
+
limited: { who: string; split?: string } | undefined,
|
|
143
|
+
) => {
|
|
111
144
|
const own = (node as { hiddenOn?: readonly string[] }).hiddenOn ?? [];
|
|
112
145
|
const hidden = own.length ? new Set([...inherited, ...own]) : inherited;
|
|
113
|
-
|
|
146
|
+
let scope = limited;
|
|
147
|
+
if (!scope) {
|
|
148
|
+
const who = restriction(node, lone);
|
|
149
|
+
if (who) scope = { who, split: splitKey(node, lone) };
|
|
150
|
+
}
|
|
114
151
|
if (FIELD_TYPES.has(node.type)) {
|
|
115
152
|
const field = (node.props as { field?: unknown }).field;
|
|
116
153
|
if (typeof field === "string" && field) {
|
|
117
154
|
const control: Control = { nodeId: node.id, hidden: new Set(hidden) };
|
|
118
|
-
if (
|
|
155
|
+
if (scope) {
|
|
156
|
+
control.who = scope.who;
|
|
157
|
+
if (scope.split) control.split = scope.split;
|
|
158
|
+
}
|
|
119
159
|
found.set(field, [...(found.get(field) ?? []), control]);
|
|
120
160
|
}
|
|
121
161
|
}
|
|
122
|
-
for (const child of nodeChildren(node)) walk(child, hidden,
|
|
162
|
+
for (const child of nodeChildren(node)) walk(child, hidden, scope);
|
|
123
163
|
};
|
|
124
164
|
// The form's own hiddenOn or audience hides the whole form, which loses no answers: not counted.
|
|
125
165
|
for (const child of nodeChildren(form)) walk(child, new Set(), undefined);
|
|
@@ -131,12 +171,12 @@ function boundControls(form: LayoutNode): Map<string, Control[]> {
|
|
|
131
171
|
* "Hidden for X") still reach everyone.
|
|
132
172
|
*/
|
|
133
173
|
function coversEveryone(controls: readonly Control[]): boolean {
|
|
134
|
-
const
|
|
135
|
-
for (const
|
|
136
|
-
if (!
|
|
137
|
-
const ab = /^
|
|
138
|
-
if (ab &&
|
|
139
|
-
if (
|
|
174
|
+
const splits = new Set(controls.map((control) => control.split));
|
|
175
|
+
for (const key of splits) {
|
|
176
|
+
if (!key) continue;
|
|
177
|
+
const ab = /^ab:(.*):([ab])$/.exec(key);
|
|
178
|
+
if (ab && splits.has(`ab:${ab[1]}:${ab[2] === "a" ? "b" : "a"}`)) return true;
|
|
179
|
+
if (key.startsWith("aud:0:") && splits.has(`aud:1:${key.slice(6)}`)) return true;
|
|
140
180
|
}
|
|
141
181
|
return false;
|
|
142
182
|
}
|
|
@@ -149,7 +189,8 @@ export function requiredFieldIssues(
|
|
|
149
189
|
const controls = boundControls(form);
|
|
150
190
|
const issues: RequiredFieldIssue[] = [];
|
|
151
191
|
for (const field of fields) {
|
|
152
|
-
|
|
192
|
+
// W-595: a hidden field is sent by the form itself, with no control.
|
|
193
|
+
if (!field.required || field.type === "hidden") continue;
|
|
153
194
|
const label = field.label.trim() || field.name;
|
|
154
195
|
const bound = controls.get(field.name);
|
|
155
196
|
if (!bound?.length) {
|
|
@@ -43,3 +43,75 @@ export function fieldByName(
|
|
|
43
43
|
if (!definition) return undefined;
|
|
44
44
|
return fieldsOf(definition).find((field) => field.name === name);
|
|
45
45
|
}
|
|
46
|
+
|
|
47
|
+
/** W-577: a field whose limits no answer can meet (min above max), so the form can't be sent. */
|
|
48
|
+
export type ImpossibleRangeField = {
|
|
49
|
+
name: string;
|
|
50
|
+
label: string;
|
|
51
|
+
kind: "length" | "value" | "both";
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const above = (lo: unknown, hi: unknown) =>
|
|
55
|
+
typeof lo === "number" && typeof hi === "number" && lo > hi;
|
|
56
|
+
|
|
57
|
+
export function impossibleRangeFields(
|
|
58
|
+
fields: ReadonlyArray<{ name: string; label: string; validation?: unknown }>,
|
|
59
|
+
): ImpossibleRangeField[] {
|
|
60
|
+
const found: ImpossibleRangeField[] = [];
|
|
61
|
+
for (const field of fields) {
|
|
62
|
+
const v = field.validation;
|
|
63
|
+
if (!v || typeof v !== "object") continue;
|
|
64
|
+
const { minLength, maxLength, min, max } = v as Record<string, unknown>;
|
|
65
|
+
const label = field.label.trim() || field.name;
|
|
66
|
+
const badLength = above(minLength, maxLength);
|
|
67
|
+
const badValue = above(min, max);
|
|
68
|
+
// W-589: report both problems together so fixing one doesn't reveal the other later.
|
|
69
|
+
if (badLength || badValue) {
|
|
70
|
+
const kind = badLength && badValue ? "both" : badLength ? "length" : "value";
|
|
71
|
+
found.push({ name: field.name, label, kind });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return found;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* W-579: a control that can't send any answer its field accepts. A field with a fixed list of
|
|
79
|
+
* options (select, radio, checkbox group) is refused by the forms plugin unless the value is one
|
|
80
|
+
* of them, so a Text input, Textarea or Checkbox bound to it makes the form unsendable.
|
|
81
|
+
*/
|
|
82
|
+
export type MismatchedControl = { nodeId: string; name: string; label: string; fieldType: string };
|
|
83
|
+
|
|
84
|
+
const OPTION_TYPES = new Set(["select", "radio", "checkbox-group"]);
|
|
85
|
+
const FREE_CONTROLS = new Set(["text-input", "textarea", "checkbox"]);
|
|
86
|
+
|
|
87
|
+
type ControlLike = { id: string; type: string; props: unknown; children?: readonly ControlLike[] };
|
|
88
|
+
|
|
89
|
+
export function mismatchedControls(
|
|
90
|
+
form: ControlLike,
|
|
91
|
+
fields: ReadonlyArray<{
|
|
92
|
+
name: string;
|
|
93
|
+
type: string;
|
|
94
|
+
label: string;
|
|
95
|
+
options?: readonly unknown[];
|
|
96
|
+
}>,
|
|
97
|
+
): MismatchedControl[] {
|
|
98
|
+
const byName = new Map(fields.map((field) => [field.name, field]));
|
|
99
|
+
const found: MismatchedControl[] = [];
|
|
100
|
+
const visit = (node: ControlLike) => {
|
|
101
|
+
if (FREE_CONTROLS.has(node.type)) {
|
|
102
|
+
const name = (node.props as { field?: unknown }).field;
|
|
103
|
+
const field = typeof name === "string" ? byName.get(name) : undefined;
|
|
104
|
+
if (field && OPTION_TYPES.has(field.type) && (field.options?.length ?? 0) > 0) {
|
|
105
|
+
found.push({
|
|
106
|
+
nodeId: node.id,
|
|
107
|
+
name: field.name,
|
|
108
|
+
label: field.label.trim() || field.name,
|
|
109
|
+
fieldType: field.type,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
for (const child of node.children ?? []) visit(child);
|
|
114
|
+
};
|
|
115
|
+
for (const child of form.children ?? []) visit(child);
|
|
116
|
+
return found;
|
|
117
|
+
}
|
package/src/core/history/diff.ts
CHANGED
|
@@ -129,6 +129,21 @@ const count = (node: LayoutNode): number =>
|
|
|
129
129
|
* current section with the same id, or, if it was removed, goes back near its old place. Ids
|
|
130
130
|
* already used elsewhere on the page are renewed, so the page stays valid.
|
|
131
131
|
*/
|
|
132
|
+
/** `node` with the A/B mark removed from every element whose id is in `live` (W-636). */
|
|
133
|
+
function withoutCopiedArms(node: LayoutNode, live: ReadonlySet<string>): LayoutNode {
|
|
134
|
+
let next = node;
|
|
135
|
+
if (node.variant && live.has(node.id)) {
|
|
136
|
+
next = { ...node };
|
|
137
|
+
delete next.variant;
|
|
138
|
+
}
|
|
139
|
+
const kids = nodeChildren(next);
|
|
140
|
+
if (kids.length === 0) return next;
|
|
141
|
+
return {
|
|
142
|
+
...next,
|
|
143
|
+
children: kids.map((child) => withoutCopiedArms(child, live)),
|
|
144
|
+
} as LayoutNode;
|
|
145
|
+
}
|
|
146
|
+
|
|
132
147
|
export function restoreSection(
|
|
133
148
|
current: Layout,
|
|
134
149
|
older: Layout,
|
|
@@ -143,7 +158,9 @@ export function restoreSection(
|
|
|
143
158
|
const clashes = [...index(section).keys()].some((id) => elsewhere.has(id));
|
|
144
159
|
// CSS ids another section took since then stay there: a repeat made the page fail to save (W-517).
|
|
145
160
|
const takenHtml = htmlIdsOf(current.root, replacing);
|
|
146
|
-
|
|
161
|
+
// An element still on the page elsewhere comes back as a copy, and a copy is never part of an
|
|
162
|
+
// A/B test (W-629/W-632): it would add a second copy of a live arm (W-636).
|
|
163
|
+
const fresh = clashes ? withFreshIds(current, withoutCopiedArms(section, elsewhere)) : section;
|
|
147
164
|
const incoming = withoutTakenHtmlIds(fresh, takenHtml);
|
|
148
165
|
const size = count(current.root) - (replacing ? count(replacing) : 0) + count(incoming);
|
|
149
166
|
if (size > MAX_NODES) return { ok: false, reason: "The page would have too many elements." };
|
|
@@ -62,8 +62,9 @@ export const BUNDLED_ICONS: readonly BundledIcon[] = [
|
|
|
62
62
|
label: "Circle Alert",
|
|
63
63
|
children: [
|
|
64
64
|
{ tag: "circle", attrs: { cx: "12", cy: "12", r: "10" } },
|
|
65
|
-
|
|
66
|
-
{ tag: "line", attrs: {} },
|
|
65
|
+
// W-699: the mark's two lines had no coordinates, so the icon drew an empty circle.
|
|
66
|
+
{ tag: "line", attrs: { x1: "12", x2: "12", y1: "8", y2: "12" } },
|
|
67
|
+
{ tag: "line", attrs: { x1: "12", x2: "12.01", y1: "16", y2: "16" } },
|
|
67
68
|
],
|
|
68
69
|
},
|
|
69
70
|
{
|
|
@@ -82,6 +82,15 @@ const Geometry = z
|
|
|
82
82
|
/** photocn filter labels are short names ("juno"); unknown ones are ignored by the renderer. */
|
|
83
83
|
const FilterLabel = z.string().regex(/^[A-Za-z0-9 _-]{1,32}$/, "Filter names are short words");
|
|
84
84
|
|
|
85
|
+
/** Backslashes and control characters, which URL parsing rewrites or drops. */
|
|
86
|
+
function hasUnsafeUrlChar(s: string): boolean {
|
|
87
|
+
for (const ch of s) {
|
|
88
|
+
const code = ch.charCodeAt(0);
|
|
89
|
+
if (ch === "\\" || code < 0x20 || code === 0x7f) return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
85
94
|
/**
|
|
86
95
|
* A blend image must be a same-site path or an https URL; `data:` blends (picked files) are
|
|
87
96
|
* refused because they would put a whole image into the layout.
|
|
@@ -90,7 +99,8 @@ const BlendSrc = z
|
|
|
90
99
|
.string()
|
|
91
100
|
.max(2000)
|
|
92
101
|
.refine(
|
|
93
|
-
|
|
102
|
+
// A backslash or control character can turn "/\\host" into another host (W-534).
|
|
103
|
+
(s) => !hasUnsafeUrlChar(s) && (/^\/(?!\/)/.test(s) || /^https:\/\//i.test(s)),
|
|
94
104
|
"Blend images must be a site path or an https URL",
|
|
95
105
|
);
|
|
96
106
|
|
|
@@ -28,7 +28,7 @@ const title = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
|
28
28
|
*/
|
|
29
29
|
export function summarizeImageEdit(recipe: ImageEditRecipe, max = 5): string {
|
|
30
30
|
const parts: string[] = [];
|
|
31
|
-
if (recipe.filters) {
|
|
31
|
+
if (recipe.filters && recipe.filters.strength !== 0) {
|
|
32
32
|
const s = recipe.filters.strength;
|
|
33
33
|
parts.push(
|
|
34
34
|
s === undefined || s >= 1
|
|
@@ -45,12 +45,15 @@ export function summarizeImageEdit(recipe: ImageEditRecipe, max = 5): string {
|
|
|
45
45
|
}
|
|
46
46
|
for (const section of [recipe.lights, recipe.colors, recipe.effects]) {
|
|
47
47
|
for (const [key, value] of Object.entries(section ?? {})) {
|
|
48
|
-
|
|
48
|
+
// Shown as a whole percent: a nudge that rounds to 0 is no change (W-551).
|
|
49
|
+
if (typeof value === "number" && Math.round(value * 100) !== 0)
|
|
49
50
|
parts.push(`${LABELS[key] ?? key} ${signed(value)}`);
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
if (recipe.curves?.some((c) => c !== null)) parts.push("Curves");
|
|
53
|
-
|
|
54
|
+
// The centre alone blurs nothing (W-551).
|
|
55
|
+
const blur = recipe.blur;
|
|
56
|
+
if (blur && (blur.bokehstrength || blur.gaussianstrength)) parts.push("Blur");
|
|
54
57
|
if (recipe.blend) parts.push("Blend");
|
|
55
58
|
if (parts.length === 0) return "No changes";
|
|
56
59
|
if (parts.length <= max) return parts.join(" · ");
|
package/src/core/index.ts
CHANGED
|
@@ -159,6 +159,10 @@ export {
|
|
|
159
159
|
export {
|
|
160
160
|
fieldsOf,
|
|
161
161
|
fieldByName,
|
|
162
|
+
impossibleRangeFields,
|
|
163
|
+
mismatchedControls,
|
|
164
|
+
type ImpossibleRangeField,
|
|
165
|
+
type MismatchedControl,
|
|
162
166
|
type PublicFormDefinition,
|
|
163
167
|
type PublicFormField,
|
|
164
168
|
type FormDefinitions,
|
|
@@ -167,6 +171,7 @@ export { FORMS_SUBMIT_PATH } from "./render/index.ts";
|
|
|
167
171
|
|
|
168
172
|
export {
|
|
169
173
|
cleanClassName,
|
|
174
|
+
nameKey,
|
|
170
175
|
MAX_CLASSES,
|
|
171
176
|
moveClassId,
|
|
172
177
|
addClassId,
|
|
@@ -255,6 +260,7 @@ export {
|
|
|
255
260
|
nodeIdAtPath,
|
|
256
261
|
newNodeId,
|
|
257
262
|
starterLayout,
|
|
263
|
+
pageSlug,
|
|
258
264
|
slugify,
|
|
259
265
|
type Removed,
|
|
260
266
|
} from "./tree-ops.ts";
|
|
@@ -361,7 +367,12 @@ export {
|
|
|
361
367
|
type PopupDevice,
|
|
362
368
|
} from "./theme/popup-rules.ts";
|
|
363
369
|
|
|
364
|
-
export {
|
|
370
|
+
export {
|
|
371
|
+
POPUP_CHROME_CSS,
|
|
372
|
+
wrapPopupMarkup,
|
|
373
|
+
type ChromeLabels,
|
|
374
|
+
type PopupPublicConfig,
|
|
375
|
+
} from "./theme/popup-markup.ts";
|
|
365
376
|
|
|
366
377
|
export {
|
|
367
378
|
FLOAT_EDGES,
|
|
@@ -394,6 +405,7 @@ export {
|
|
|
394
405
|
archivePageTitle,
|
|
395
406
|
DEFAULT_PER_PAGE,
|
|
396
407
|
loopPerPage,
|
|
408
|
+
paginationArchiveTitle,
|
|
397
409
|
paginationTitleText,
|
|
398
410
|
MAX_ARCHIVE_PAGE,
|
|
399
411
|
paginationItems,
|
|
@@ -445,6 +457,7 @@ export {
|
|
|
445
457
|
export {
|
|
446
458
|
abCookieName,
|
|
447
459
|
collectAbTests,
|
|
460
|
+
loneAbTests,
|
|
448
461
|
pickArm,
|
|
449
462
|
variantShows,
|
|
450
463
|
type AbArm,
|
|
@@ -513,3 +526,4 @@ export {
|
|
|
513
526
|
ImageEditRecipe,
|
|
514
527
|
} from "./image-edit/schema.ts";
|
|
515
528
|
export { summarizeImageEdit } from "./image-edit/summary.ts";
|
|
529
|
+
export { boxLinkHeldBack } from "./render/extras.ts";
|
package/src/core/limits.ts
CHANGED
|
@@ -10,10 +10,21 @@ export const MAX_TABS = 12;
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* W-509: `text` cut to at most `max` UTF-16 units, as schema limits count, without leaving half
|
|
13
|
-
* of an emoji (a lone surrogate) at the end.
|
|
13
|
+
* of an emoji (a lone surrogate), an accent's base letter or half a flag at the end.
|
|
14
14
|
*/
|
|
15
15
|
export function clipText(text: string, max: number): string {
|
|
16
16
|
if (text.length <= max) return text;
|
|
17
|
+
// W-543: whole characters as people see them, so an accent or half a flag isn't left behind.
|
|
18
|
+
if (typeof Intl !== "undefined" && "Segmenter" in Intl) {
|
|
19
|
+
let end = 0;
|
|
20
|
+
for (const { segment } of new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(
|
|
21
|
+
text.slice(0, max + 32),
|
|
22
|
+
)) {
|
|
23
|
+
if (end + segment.length > max) break;
|
|
24
|
+
end += segment.length;
|
|
25
|
+
}
|
|
26
|
+
return text.slice(0, end);
|
|
27
|
+
}
|
|
17
28
|
const code = text.charCodeAt(max - 1);
|
|
18
29
|
return text.slice(0, code >= 0xd800 && code <= 0xdbff ? max - 1 : max);
|
|
19
30
|
}
|
package/src/core/perf/meter.ts
CHANGED
|
@@ -51,25 +51,55 @@ function imageBytes(node: LayoutNode): number {
|
|
|
51
51
|
return w > 0 && h > 0 ? Math.max(5_000, Math.round(w * h * 0.25)) : IMAGE_GUESS;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
type Sheets = { style?: unknown; devices?: Record<string, unknown>; query?: { style?: unknown } };
|
|
55
|
+
const sheetsHaveBackground = (owner: Sheets): boolean => {
|
|
56
|
+
// W-645: a container-query override (W-346) can set the background too.
|
|
57
|
+
const sheets = [owner.style, ...Object.values(owner.devices ?? {}), owner.query?.style];
|
|
56
58
|
return sheets.some((style) => {
|
|
57
59
|
const value = (style as { backgroundImage?: unknown } | undefined)?.backgroundImage;
|
|
58
60
|
return typeof value === "string" ? value.length > 0 : Boolean(value);
|
|
59
61
|
});
|
|
60
62
|
};
|
|
61
63
|
|
|
64
|
+
/** Ids of global classes that set a background image (W-635). */
|
|
65
|
+
const backgroundClasses = (design: DesignSystem): Set<string> =>
|
|
66
|
+
new Set((design.classes ?? []).filter((c) => sheetsHaveBackground(c)).map((c) => c.id));
|
|
67
|
+
|
|
68
|
+
/** Its own style or one of its classes sets a background image (W-635). */
|
|
69
|
+
const hasBackgroundImage = (node: LayoutNode, bgClasses: Set<string>): boolean =>
|
|
70
|
+
sheetsHaveBackground(node as Sheets) || (node.classes ?? []).some((id) => bgClasses.has(id));
|
|
71
|
+
|
|
62
72
|
const isPlayerEmbed = (node: LayoutNode): boolean => {
|
|
63
73
|
const url = (node.props as { url?: unknown }).url;
|
|
64
74
|
return typeof url === "string" && resolveEmbedUrl(url)?.kind === "iframe";
|
|
65
75
|
};
|
|
66
76
|
|
|
67
77
|
/** Images and embeds under a node, with their estimated weight. */
|
|
68
|
-
function media(
|
|
78
|
+
function media(
|
|
79
|
+
node: LayoutNode,
|
|
80
|
+
bgClasses: Set<string>,
|
|
81
|
+
dynamic?: ThemeDynamicData,
|
|
82
|
+
): { images: number; bytes: number; embeds: number } {
|
|
69
83
|
let images = 0;
|
|
70
84
|
let bytes = 0;
|
|
71
85
|
let embeds = 0;
|
|
86
|
+
const seen = new Set<Layout>();
|
|
87
|
+
/** W-671: a synced section or Loop Item part the canvas loaded is weighed with the page. */
|
|
88
|
+
const part = (n: LayoutNode): Layout | undefined => {
|
|
89
|
+
const props = n.props as { partId?: unknown; itemPartId?: unknown };
|
|
90
|
+
const found =
|
|
91
|
+
n.type === "section" && typeof props.partId === "string"
|
|
92
|
+
? dynamic?.sectionTemplates?.[props.partId.trim()]
|
|
93
|
+
: n.type === "loop" && typeof props.itemPartId === "string"
|
|
94
|
+
? dynamic?.loopTemplates?.[props.itemPartId.trim()]
|
|
95
|
+
: undefined;
|
|
96
|
+
if (!found || seen.has(found)) return undefined;
|
|
97
|
+
seen.add(found);
|
|
98
|
+
return found;
|
|
99
|
+
};
|
|
72
100
|
const walk = (n: LayoutNode): void => {
|
|
101
|
+
const template = part(n);
|
|
102
|
+
if (template) walk(template.root);
|
|
73
103
|
if (n.type === "image" || n.type === "post-image") {
|
|
74
104
|
const src = (n.props as { src?: unknown }).src;
|
|
75
105
|
if (n.type === "post-image" || (typeof src === "string" && src.trim())) {
|
|
@@ -77,7 +107,7 @@ function media(node: LayoutNode): { images: number; bytes: number; embeds: numbe
|
|
|
77
107
|
bytes += imageBytes(n);
|
|
78
108
|
}
|
|
79
109
|
}
|
|
80
|
-
if (hasBackgroundImage(n)) {
|
|
110
|
+
if (hasBackgroundImage(n, bgClasses)) {
|
|
81
111
|
images += 1;
|
|
82
112
|
bytes += IMAGE_GUESS;
|
|
83
113
|
}
|
|
@@ -110,7 +140,8 @@ export function measurePage(
|
|
|
110
140
|
bytes: SCRIPT_BYTES[script],
|
|
111
141
|
nodeIds,
|
|
112
142
|
}));
|
|
113
|
-
const
|
|
143
|
+
const bgClasses = backgroundClasses(design);
|
|
144
|
+
const all = media(layout.root, bgClasses, dynamic);
|
|
114
145
|
const bytes: Record<PerfKind, number> = {
|
|
115
146
|
html: Math.round(utf8(rendered.html) * GZIP),
|
|
116
147
|
css: Math.round(utf8(rendered.css) * GZIP),
|
|
@@ -126,7 +157,7 @@ export function measurePage(
|
|
|
126
157
|
root: Object.assign({}, layout.root, { children: [child] }),
|
|
127
158
|
};
|
|
128
159
|
const one = renderPage(alone, design, opts);
|
|
129
|
-
const m = media(child);
|
|
160
|
+
const m = media(child, bgClasses, dynamic);
|
|
130
161
|
sections.push({
|
|
131
162
|
id: child.id,
|
|
132
163
|
type: child.type,
|
|
@@ -157,8 +188,12 @@ export function measurePage(
|
|
|
157
188
|
return { bytes, over, scripts, imageCount: all.images, embeds: all.embeds, sections, warnings };
|
|
158
189
|
}
|
|
159
190
|
|
|
191
|
+
/** W-574: the first image that renders; an Image with no picture yet shows nothing to load. */
|
|
160
192
|
function findFirstImage(node: LayoutNode): LayoutNode | undefined {
|
|
161
|
-
if (node.type === "image")
|
|
193
|
+
if (node.type === "image") {
|
|
194
|
+
const src = (node.props as { src?: unknown }).src;
|
|
195
|
+
if (typeof src === "string" && src.trim()) return node;
|
|
196
|
+
}
|
|
162
197
|
if (!isParentNode(node)) return undefined;
|
|
163
198
|
for (const child of node.children) {
|
|
164
199
|
const found = findFirstImage(child);
|
|
@@ -103,12 +103,13 @@ export function siteTokens(design: DesignSystem): RecipeTokens {
|
|
|
103
103
|
if (surface) tokens.surface = surface;
|
|
104
104
|
const onAccent = color(pick(others, /on[- ]?(primary|brand|accent)|inverse|white/));
|
|
105
105
|
if (onAccent) tokens.onAccent = onAccent;
|
|
106
|
-
else if (accentVar && /^#[0-9a-f]{6}$/i.test(accentVar.value)) {
|
|
106
|
+
else if (accentVar && /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(accentVar.value)) {
|
|
107
107
|
// No "on accent" colour: white or near-black, whichever reads better on the accent.
|
|
108
|
+
// W-642: a short (#fd0) or alpha (#ffdd00cc) accent is judged as its six-digit colour.
|
|
109
|
+
const h = accentVar.value.slice(1);
|
|
110
|
+
const hex = `#${(h.length <= 4 ? [...h].map((c) => c + c).join("") : h).slice(0, 6)}`;
|
|
108
111
|
tokens.onAccent =
|
|
109
|
-
contrastRatio(
|
|
110
|
-
? "#ffffff"
|
|
111
|
-
: "#111111";
|
|
112
|
+
contrastRatio(hex, "#ffffff") >= contrastRatio(hex, "#111111") ? "#ffffff" : "#111111";
|
|
112
113
|
}
|
|
113
114
|
const buttonCls = pick(design.classes, /\b(button|btn)\b/, /cta/);
|
|
114
115
|
if (buttonCls) {
|
|
@@ -18,6 +18,14 @@ export type RenderContext = {
|
|
|
18
18
|
* stay with their own copy.
|
|
19
19
|
*/
|
|
20
20
|
uniqueId: (base: string) => string;
|
|
21
|
+
/**
|
|
22
|
+
* W-653: claims `nodes` elements from this render's synced-section budget; false once spent.
|
|
23
|
+
* Sections nested in sections multiply, so a few small parts could expand to millions of
|
|
24
|
+
* elements and stall the page.
|
|
25
|
+
*/
|
|
26
|
+
takeSectionBudget?: (nodes: number) => boolean;
|
|
27
|
+
/** The page's language, e.g. "fr-CA", for dates (W-688). */
|
|
28
|
+
lang?: string;
|
|
21
29
|
/** The form whose children are rendering, so each field reads that form's definition. */
|
|
22
30
|
formId?: string;
|
|
23
31
|
};
|