@perkyzz/emvb 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/package.json +4 -4
- package/src/admin/bulk-api.ts +5 -1
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +22 -2
- package/src/admin/editor/Timeline.tsx +1 -8
- package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
- package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
- package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
- package/src/admin/editor/canvas/vnode-react.tsx +5 -0
- package/src/admin/editor/co-design.ts +36 -1
- package/src/admin/editor/dnd/dragged-source.ts +22 -0
- package/src/admin/editor/dnd/layer-drop.ts +141 -0
- package/src/admin/editor/dnd/new-element.ts +76 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +34 -0
- package/src/admin/editor/feature-css.ts +22 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/FontFaces.tsx +342 -0
- package/src/admin/editor/panels/LayersPanel.tsx +56 -6
- package/src/admin/editor/panels/LeftPanel.tsx +153 -29
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
- package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
- package/src/admin/editor/panels/TokenScales.tsx +2 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
- package/src/admin/editor/panels/VariableSection.tsx +111 -7
- package/src/admin/editor/panels/color-space.ts +71 -6
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +18 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +33 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
- package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
- package/src/admin/editor/panels/settings/style-sections.ts +19 -2
- package/src/admin/editor/panels/url-rules.ts +43 -0
- package/src/admin/editor/panels/use-layers-drop.ts +232 -0
- package/src/admin/editor/store.ts +4 -2
- package/src/admin/editor/useExtensions.ts +3 -1
- package/src/admin/editor/useNodeActions.ts +74 -1
- package/src/admin/editor/useSave.ts +116 -85
- package/src/admin/export-api.ts +25 -2
- package/src/admin/extension-outputs.ts +179 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +22 -188
- package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
- package/src/admin/pages/ImportImageCopies.tsx +167 -0
- package/src/admin/pages/ImportReport.tsx +63 -0
- package/src/admin/pages/NewPageDialog.tsx +54 -32
- package/src/admin/pages/PageList.tsx +9 -0
- package/src/admin/pages/ThemePartList.tsx +9 -0
- package/src/astro/EmVBPage.astro +5 -2
- package/src/astro/extension-styles.ts +35 -0
- package/src/astro/forms/EmVBFormsClient.astro +3 -0
- package/src/astro/forms/enhance.ts +107 -0
- package/src/astro/popups/runtime.ts +47 -2
- package/src/astro/render.ts +19 -4
- package/src/astro/request-data.ts +6 -0
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/resolve.ts +9 -0
- package/src/astro/widgets/EmVBCountdownRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCounterRuntime.astro +8 -0
- package/src/astro/widgets/EmVBHeadlineRuntime.astro +9 -0
- package/src/astro/widgets/EmVBMapRuntime.astro +8 -0
- package/src/astro/widgets/EmVBShareRuntime.astro +9 -0
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +22 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +91 -0
- package/src/astro/widgets/counter.ts +98 -0
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +99 -0
- package/src/astro/widgets/map.ts +37 -0
- package/src/astro/widgets/share.ts +21 -0
- package/src/astro/widgets/sticky.ts +87 -0
- package/src/astro/widgets/theme.ts +52 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +177 -6
- package/src/core/arrange.ts +71 -1
- package/src/core/canvas-collections.ts +28 -0
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +35 -1
- package/src/core/elements/counter-format.ts +15 -0
- package/src/core/elements/form-elements.ts +119 -9
- package/src/core/elements/icon-svg.ts +14 -0
- package/src/core/elements/index.ts +54 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/marketing.ts +1490 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +40 -5
- package/src/core/export/runtimes.generated.ts +10 -3
- package/src/core/export/site.ts +55 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +17 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +66 -21
- package/src/core/extensions/safe-nodes.ts +67 -11
- package/src/core/extensions/types.ts +48 -1
- package/src/core/fonts/files.ts +74 -0
- package/src/core/fonts/google.ts +112 -0
- package/src/core/fonts/test-font.ts +9 -0
- package/src/core/import/elementor/context.ts +13 -4
- package/src/core/import/elementor/index.ts +32 -21
- package/src/core/import/elementor/widgets.ts +532 -293
- package/src/core/import/html/blocks.ts +602 -0
- package/src/core/import/html/index.ts +155 -0
- package/src/core/import/html/map.ts +958 -0
- package/src/core/import/html/parse.ts +430 -0
- package/src/core/index.ts +45 -0
- package/src/core/limits.ts +6 -0
- package/src/core/migrate/v18.ts +3 -0
- package/src/core/public-attributes.ts +17 -0
- package/src/core/render/extras.ts +31 -7
- package/src/core/render/form.ts +103 -10
- package/src/core/render/index.ts +172 -16
- package/src/core/render/section.ts +31 -1
- package/src/core/render/spacer-basis.ts +102 -0
- package/src/core/render/theme-boot.ts +16 -0
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +68 -3
- package/src/core/sanitize/motion.ts +12 -0
- package/src/core/schema/design.ts +40 -0
- package/src/core/schema/layout.ts +534 -22
- package/src/core/schema/style.ts +28 -0
- package/src/core/templates/index.ts +218 -0
- package/src/core/templates/pages.ts +29 -0
- package/src/core/templates/sections.ts +794 -0
- package/src/core/templates/types.ts +9 -0
- package/src/core/theme/dynamic.ts +11 -6
- package/src/core/theme/popup-markup.ts +21 -2
- package/src/core/theme/popup-rules.ts +36 -0
- package/src/core/theme/triggers.ts +64 -5
- package/src/core/translatable.ts +5 -2
- package/src/extension-build.ts +331 -0
- package/src/index.ts +25 -3
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +29 -1
- package/src/mcp/tools.ts +40 -1
- package/src/mcp/write.ts +41 -1
- package/src/server/extension-routes.ts +73 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +11 -1
|
@@ -4,12 +4,16 @@ import * as React from "react";
|
|
|
4
4
|
import {
|
|
5
5
|
defaultTriggers,
|
|
6
6
|
MAX_POPUP_TRIGGERS,
|
|
7
|
+
PANEL_SIZES,
|
|
7
8
|
type PopupOpenTrigger,
|
|
8
9
|
type TriggersDoc,
|
|
10
|
+
type UrlParamRule,
|
|
11
|
+
validateTriggers,
|
|
9
12
|
} from "../../../core/index.ts";
|
|
10
13
|
import { BUTTON, FIELD } from "../../ui.ts";
|
|
11
14
|
import { TriggerSettings } from "./TriggerSettings.tsx";
|
|
12
15
|
import { isCommitEnter } from "../ime.ts";
|
|
16
|
+
import { formatUrlRules, parseUrlRules } from "./url-rules.ts";
|
|
13
17
|
|
|
14
18
|
type Props = {
|
|
15
19
|
triggers: TriggersDoc | undefined;
|
|
@@ -27,6 +31,19 @@ const TRIGGER_TYPES = [
|
|
|
27
31
|
|
|
28
32
|
type TriggerType = (typeof TRIGGER_TYPES)[number]["value"];
|
|
29
33
|
|
|
34
|
+
/** W-1071: a centred popup, or an off-canvas panel at an edge. */
|
|
35
|
+
const SHAPES = [
|
|
36
|
+
{ value: "centre", label: "Popup in the middle" },
|
|
37
|
+
{ value: "left", label: "Panel from the left" },
|
|
38
|
+
{ value: "right", label: "Panel from the right" },
|
|
39
|
+
] as const;
|
|
40
|
+
|
|
41
|
+
const WIDTHS = [
|
|
42
|
+
{ value: "narrow", label: "Narrow (20rem)" },
|
|
43
|
+
{ value: "medium", label: "Medium (24rem)" },
|
|
44
|
+
{ value: "wide", label: "Wide (32rem)" },
|
|
45
|
+
] as const;
|
|
46
|
+
|
|
30
47
|
function blankTrigger(type: TriggerType): PopupOpenTrigger {
|
|
31
48
|
switch (type) {
|
|
32
49
|
case "page_load":
|
|
@@ -78,13 +95,122 @@ function ShowTimesField({
|
|
|
78
95
|
}
|
|
79
96
|
|
|
80
97
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
98
|
+
* W-1081: a show-from or show-until moment, typed as a Countdown's target; empty clears it. The
|
|
99
|
+
* pair is checked too: an end at or before the start would make the whole triggers save fail.
|
|
100
|
+
*/
|
|
101
|
+
function ShowDateField({
|
|
102
|
+
label,
|
|
103
|
+
value,
|
|
104
|
+
pair,
|
|
105
|
+
onCommit,
|
|
106
|
+
}: {
|
|
107
|
+
label: string;
|
|
108
|
+
value: string | null;
|
|
109
|
+
/** The other date's field and value, for the end-after-start check. */
|
|
110
|
+
pair: { from?: string | null; until?: string | null };
|
|
111
|
+
onCommit: (value: string | null) => void;
|
|
112
|
+
}) {
|
|
113
|
+
const [draft, setDraft] = React.useState(value ?? "");
|
|
114
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
115
|
+
const commit = () => {
|
|
116
|
+
const raw = draft.trim();
|
|
117
|
+
if (raw === "") {
|
|
118
|
+
setError(null);
|
|
119
|
+
if (value !== null) onCommit(null);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (
|
|
123
|
+
!validateTriggers({
|
|
124
|
+
schemaVersion: 1,
|
|
125
|
+
open: [{ type: "page_load" }],
|
|
126
|
+
advanced: { from: raw },
|
|
127
|
+
}).ok
|
|
128
|
+
) {
|
|
129
|
+
setError("Use a date, time and UTC offset such as 2026-12-01T09:00-05:00.");
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const dates = { from: raw, until: raw, ...pair };
|
|
133
|
+
if (dates.from && dates.until && Date.parse(dates.until) <= Date.parse(dates.from)) {
|
|
134
|
+
setError("The end must come after the start.");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
setError(null);
|
|
138
|
+
if (raw !== value) onCommit(raw);
|
|
139
|
+
};
|
|
140
|
+
return (
|
|
141
|
+
<Input
|
|
142
|
+
label={label}
|
|
143
|
+
className={FIELD}
|
|
144
|
+
placeholder="2026-12-01T09:00-05:00"
|
|
145
|
+
value={draft}
|
|
146
|
+
{...(error ? { error } : {})}
|
|
147
|
+
aria-invalid={error ? true : undefined}
|
|
148
|
+
onChange={(event) => setDraft(event.currentTarget.value)}
|
|
149
|
+
onBlur={commit}
|
|
150
|
+
onKeyDown={(event) => {
|
|
151
|
+
if (isCommitEnter(event)) commit();
|
|
152
|
+
}}
|
|
153
|
+
/>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** W-1081: the URL rules, one per line, committed on blur when every line reads. */
|
|
158
|
+
function UrlRulesField({
|
|
159
|
+
value,
|
|
160
|
+
onCommit,
|
|
161
|
+
}: {
|
|
162
|
+
value: UrlParamRule[] | null;
|
|
163
|
+
onCommit: (rules: UrlParamRule[] | null) => void;
|
|
164
|
+
}) {
|
|
165
|
+
const id = React.useId();
|
|
166
|
+
const [draft, setDraft] = React.useState(formatUrlRules(value));
|
|
167
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
168
|
+
const commit = () => {
|
|
169
|
+
const parsed = parseUrlRules(draft);
|
|
170
|
+
if (!parsed.ok) {
|
|
171
|
+
setError(parsed.message);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
setError(null);
|
|
175
|
+
const next = parsed.rules.length > 0 ? parsed.rules : null;
|
|
176
|
+
if (formatUrlRules(next) !== formatUrlRules(value)) onCommit(next);
|
|
177
|
+
};
|
|
178
|
+
return (
|
|
179
|
+
<div className="emvb-field-group" data-emvb-url-rules="">
|
|
180
|
+
<label className="emvb-field-label" htmlFor={id}>
|
|
181
|
+
Only when the page address has
|
|
182
|
+
</label>
|
|
183
|
+
<textarea
|
|
184
|
+
id={id}
|
|
185
|
+
className={`${FIELD} emvb-textarea`}
|
|
186
|
+
rows={3}
|
|
187
|
+
value={draft}
|
|
188
|
+
aria-invalid={error ? true : undefined}
|
|
189
|
+
aria-describedby={`${id}-hint${error ? ` ${id}-error` : ""}`}
|
|
190
|
+
onChange={(event) => setDraft(event.currentTarget.value)}
|
|
191
|
+
onBlur={commit}
|
|
192
|
+
/>
|
|
193
|
+
<p className="emvb-helper" id={`${id}-hint`}>
|
|
194
|
+
One rule per line: utm_source=newsletter (that value), coupon (any value), or !preview (not
|
|
195
|
+
there). Every rule must hold. Empty: every address.
|
|
196
|
+
</p>
|
|
197
|
+
{error && (
|
|
198
|
+
<p className="emvb-inline-error" role="alert" id={`${id}-error`}>
|
|
199
|
+
{error}
|
|
200
|
+
</p>
|
|
201
|
+
)}
|
|
202
|
+
</div>
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Popup open triggers + advanced rules (S7b / W-081): how often, devices, the page address and
|
|
208
|
+
* show dates (W-1081). Gap vs Elementor (deferred): A/B.
|
|
83
209
|
*/
|
|
84
210
|
export function TriggersEditor({ triggers, onChange }: Props) {
|
|
85
211
|
const doc = triggers ?? defaultTriggers();
|
|
86
212
|
const setOpen = (open: PopupOpenTrigger[]) =>
|
|
87
|
-
onChange({
|
|
213
|
+
onChange({ ...doc, open, advanced: doc.advanced ?? {} });
|
|
88
214
|
|
|
89
215
|
const updateAt = (index: number, next: PopupOpenTrigger) => {
|
|
90
216
|
setOpen(doc.open.map((t, i) => (i === index ? next : t)));
|
|
@@ -165,14 +291,64 @@ export function TriggersEditor({ triggers, onChange }: Props) {
|
|
|
165
291
|
</p>
|
|
166
292
|
)}
|
|
167
293
|
|
|
294
|
+
<h3 className="emvb-section-label">Show as</h3>
|
|
295
|
+
<Select
|
|
296
|
+
label="Shape"
|
|
297
|
+
className={FIELD}
|
|
298
|
+
value={doc.panel?.edge ?? "centre"}
|
|
299
|
+
onValueChange={(value) => {
|
|
300
|
+
const { panel: _old, ...rest } = doc;
|
|
301
|
+
if (value === "left" || value === "right")
|
|
302
|
+
onChange({ ...rest, panel: { ...doc.panel, edge: value } });
|
|
303
|
+
else onChange(rest);
|
|
304
|
+
}}
|
|
305
|
+
renderValue={(value: unknown) =>
|
|
306
|
+
SHAPES.find((o) => o.value === value)?.label ?? String(value)
|
|
307
|
+
}
|
|
308
|
+
>
|
|
309
|
+
{SHAPES.map((option) => (
|
|
310
|
+
<Select.Option key={option.value} value={option.value}>
|
|
311
|
+
{option.label}
|
|
312
|
+
</Select.Option>
|
|
313
|
+
))}
|
|
314
|
+
</Select>
|
|
315
|
+
{doc.panel && (
|
|
316
|
+
<Select
|
|
317
|
+
label="Panel width"
|
|
318
|
+
className={FIELD}
|
|
319
|
+
value={doc.panel.size ?? "medium"}
|
|
320
|
+
onValueChange={(value) => {
|
|
321
|
+
const edge = doc.panel?.edge ?? "left";
|
|
322
|
+
const size = PANEL_SIZES.find((s) => s === value);
|
|
323
|
+
onChange({
|
|
324
|
+
...doc,
|
|
325
|
+
panel: size && size !== "medium" ? { edge, size } : { edge },
|
|
326
|
+
});
|
|
327
|
+
}}
|
|
328
|
+
renderValue={(value: unknown) =>
|
|
329
|
+
WIDTHS.find((o) => o.value === value)?.label ?? String(value)
|
|
330
|
+
}
|
|
331
|
+
>
|
|
332
|
+
{WIDTHS.map((option) => (
|
|
333
|
+
<Select.Option key={option.value} value={option.value}>
|
|
334
|
+
{option.label}
|
|
335
|
+
</Select.Option>
|
|
336
|
+
))}
|
|
337
|
+
</Select>
|
|
338
|
+
)}
|
|
339
|
+
<p className="emvb-helper">
|
|
340
|
+
A panel slides in from the edge and fills the screen's height: use it for a mobile menu,
|
|
341
|
+
filters or a cart, opened by a click trigger on a button.
|
|
342
|
+
</p>
|
|
343
|
+
|
|
168
344
|
<h3 className="emvb-section-label">Advanced</h3>
|
|
169
|
-
<p className="emvb-helper">
|
|
345
|
+
<p className="emvb-helper">
|
|
346
|
+
Limit how often the popup shows, on which devices, on which addresses and when.
|
|
347
|
+
</p>
|
|
170
348
|
<ShowTimesField
|
|
171
349
|
key={String(advanced.showTimes ?? "")}
|
|
172
350
|
value={advanced.showTimes ?? null}
|
|
173
|
-
onCommit={(showTimes) =>
|
|
174
|
-
onChange({ schemaVersion: 1, open: doc.open, advanced: { ...advanced, showTimes } })
|
|
175
|
-
}
|
|
351
|
+
onCommit={(showTimes) => onChange({ ...doc, advanced: { ...advanced, showTimes } })}
|
|
176
352
|
/>
|
|
177
353
|
<fieldset className="emvb-device-fieldset">
|
|
178
354
|
<legend className="emvb-field-label">Devices</legend>
|
|
@@ -196,8 +372,7 @@ export function TriggersEditor({ triggers, onChange }: Props) {
|
|
|
196
372
|
? [...selected.filter((d) => d !== value), value]
|
|
197
373
|
: selected.filter((d) => d !== value);
|
|
198
374
|
onChange({
|
|
199
|
-
|
|
200
|
-
open: doc.open,
|
|
375
|
+
...doc,
|
|
201
376
|
advanced: {
|
|
202
377
|
...advanced,
|
|
203
378
|
devices: next.length ? next : null,
|
|
@@ -210,6 +385,25 @@ export function TriggersEditor({ triggers, onChange }: Props) {
|
|
|
210
385
|
);
|
|
211
386
|
})}
|
|
212
387
|
</fieldset>
|
|
388
|
+
<UrlRulesField
|
|
389
|
+
key={formatUrlRules(advanced.urlParams)}
|
|
390
|
+
value={advanced.urlParams ?? null}
|
|
391
|
+
onCommit={(urlParams) => onChange({ ...doc, advanced: { ...advanced, urlParams } })}
|
|
392
|
+
/>
|
|
393
|
+
<ShowDateField
|
|
394
|
+
key={`from:${advanced.from ?? ""}`}
|
|
395
|
+
label="Show from"
|
|
396
|
+
value={advanced.from ?? null}
|
|
397
|
+
pair={{ until: advanced.until ?? null }}
|
|
398
|
+
onCommit={(from) => onChange({ ...doc, advanced: { ...advanced, from } })}
|
|
399
|
+
/>
|
|
400
|
+
<ShowDateField
|
|
401
|
+
key={`until:${advanced.until ?? ""}`}
|
|
402
|
+
label="Show until"
|
|
403
|
+
value={advanced.until ?? null}
|
|
404
|
+
pair={{ from: advanced.from ?? null }}
|
|
405
|
+
onCommit={(until) => onChange({ ...doc, advanced: { ...advanced, until } })}
|
|
406
|
+
/>
|
|
213
407
|
</div>
|
|
214
408
|
);
|
|
215
409
|
}
|
|
@@ -47,6 +47,8 @@ import {
|
|
|
47
47
|
type Length,
|
|
48
48
|
} from "./variable-values.ts";
|
|
49
49
|
import { isCancelEscape, isCommitEnter } from "../ime.ts";
|
|
50
|
+
import type { Fetcher } from "../../api.ts";
|
|
51
|
+
import { FontFaces } from "./FontFaces.tsx";
|
|
50
52
|
|
|
51
53
|
const VAR_TOKEN: Record<VariableKind, (id: string) => string> = {
|
|
52
54
|
color: (id) => `--emvb-c-${id}`,
|
|
@@ -217,6 +219,59 @@ function ValueEditor({
|
|
|
217
219
|
);
|
|
218
220
|
}
|
|
219
221
|
|
|
222
|
+
/**
|
|
223
|
+
* W-1067: the colour in dark mode, under a colour variable's value. Empty: the same colour in
|
|
224
|
+
* both. Enter or blur saves a valid change once.
|
|
225
|
+
*/
|
|
226
|
+
function DarkValue({
|
|
227
|
+
value,
|
|
228
|
+
onCommit,
|
|
229
|
+
}: {
|
|
230
|
+
value: string | undefined;
|
|
231
|
+
onCommit: (dark: string | undefined) => void;
|
|
232
|
+
}) {
|
|
233
|
+
const [text, setText] = React.useState(value ?? "");
|
|
234
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
235
|
+
const commit = (raw: string) => {
|
|
236
|
+
const trimmed = raw.trim();
|
|
237
|
+
if (trimmed === (value ?? "")) return setError(null);
|
|
238
|
+
if (trimmed === "") {
|
|
239
|
+
setError(null);
|
|
240
|
+
onCommit(undefined);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const parsed = parseValue("color", trimmed);
|
|
244
|
+
if (!parsed.ok || typeof parsed.value !== "string") {
|
|
245
|
+
setError(parsed.ok ? "Use a hex color such as #1a2b3c." : parsed.error);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
setError(null);
|
|
249
|
+
onCommit(parsed.value);
|
|
250
|
+
};
|
|
251
|
+
return (
|
|
252
|
+
<div className="emvb-site-item-body" data-emvb-var-dark="">
|
|
253
|
+
<div className="emvb-site-value-row">
|
|
254
|
+
<Input
|
|
255
|
+
label="Dark mode"
|
|
256
|
+
className={`${FIELD} emvb-site-value-input`}
|
|
257
|
+
placeholder="Same as light"
|
|
258
|
+
value={text}
|
|
259
|
+
aria-invalid={error ? true : undefined}
|
|
260
|
+
onChange={(event) => setText(event.target.value)}
|
|
261
|
+
onBlur={(event) => commit(event.currentTarget.value)}
|
|
262
|
+
onKeyDown={(event) => {
|
|
263
|
+
if (isCommitEnter(event)) commit(event.currentTarget.value);
|
|
264
|
+
}}
|
|
265
|
+
/>
|
|
266
|
+
</div>
|
|
267
|
+
{error ? <InlineError>{error}</InlineError> : null}
|
|
268
|
+
<p className="emvb-helper">
|
|
269
|
+
Used when the visitor's device is set to dark, or a Theme toggle chose dark.
|
|
270
|
+
</p>
|
|
271
|
+
</div>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
220
275
|
/** "2 on page", and the classes that use it too: "2 on page · 1 class" (W-150). */
|
|
221
276
|
const usageText = (onPage: number, inClasses: number) =>
|
|
222
277
|
inClasses
|
|
@@ -230,6 +285,7 @@ export function VariableSection({
|
|
|
230
285
|
layout,
|
|
231
286
|
onSave,
|
|
232
287
|
onAskDelete,
|
|
288
|
+
fetcher,
|
|
233
289
|
}: {
|
|
234
290
|
title: string;
|
|
235
291
|
kind: VariableKind;
|
|
@@ -237,6 +293,8 @@ export function VariableSection({
|
|
|
237
293
|
layout: Layout | null;
|
|
238
294
|
onSave: (design: DesignSystem) => Promise<boolean | void>;
|
|
239
295
|
onAskDelete: (id: string, name: string) => void;
|
|
296
|
+
/** W-1072: with a fetcher, a font variable can get its own font files. */
|
|
297
|
+
fetcher?: Fetcher;
|
|
240
298
|
}) {
|
|
241
299
|
const noun = useEditedNoun();
|
|
242
300
|
const listKey = LIST_KEY[kind];
|
|
@@ -279,6 +337,30 @@ export function VariableSection({
|
|
|
279
337
|
},
|
|
280
338
|
});
|
|
281
339
|
|
|
340
|
+
// W-1067: a colour's dark-mode value; undefined removes it.
|
|
341
|
+
const saveDark = (id: string, dark: string | undefined) =>
|
|
342
|
+
void onSave({
|
|
343
|
+
...design,
|
|
344
|
+
variables: {
|
|
345
|
+
...design.variables,
|
|
346
|
+
colors: design.variables.colors.map((entry) => {
|
|
347
|
+
if (entry.id !== id) return entry;
|
|
348
|
+
const { dark: _old, ...light } = entry;
|
|
349
|
+
return dark === undefined ? light : { ...light, dark };
|
|
350
|
+
}),
|
|
351
|
+
},
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// W-1072: a font variable with its custom faces, family and source.
|
|
355
|
+
const saveFont = (next: NonNullable<DesignSystem["variables"]["fonts"]>[number]) =>
|
|
356
|
+
onSave({
|
|
357
|
+
...design,
|
|
358
|
+
variables: {
|
|
359
|
+
...design.variables,
|
|
360
|
+
fonts: (design.variables.fonts ?? []).map((entry) => (entry.id === next.id ? next : entry)),
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
|
|
282
364
|
const q = filter.trim().toLowerCase();
|
|
283
365
|
const visible = q
|
|
284
366
|
? items.filter((item) => matches(q, item.name, item.id, VAR_TOKEN[kind](item.id)))
|
|
@@ -501,13 +583,35 @@ export function VariableSection({
|
|
|
501
583
|
/>
|
|
502
584
|
</div>
|
|
503
585
|
{isOpen && (
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
586
|
+
<>
|
|
587
|
+
<ValueEditor
|
|
588
|
+
key={text}
|
|
589
|
+
kind={kind}
|
|
590
|
+
item={item}
|
|
591
|
+
token={token}
|
|
592
|
+
onCommit={(next) => saveValue(item.id, next)}
|
|
593
|
+
/>
|
|
594
|
+
{kind === "font" && fetcher && (
|
|
595
|
+
<FontFaces
|
|
596
|
+
font={
|
|
597
|
+
(design.variables.fonts ?? []).find((font) => font.id === item.id) ?? {
|
|
598
|
+
id: item.id,
|
|
599
|
+
name: item.name,
|
|
600
|
+
value: String(item.value),
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
fetcher={fetcher}
|
|
604
|
+
onSave={saveFont}
|
|
605
|
+
/>
|
|
606
|
+
)}
|
|
607
|
+
{kind === "color" && (
|
|
608
|
+
<DarkValue
|
|
609
|
+
key={`dark:${(item as { dark?: string }).dark ?? ""}`}
|
|
610
|
+
value={(item as { dark?: string }).dark}
|
|
611
|
+
onCommit={(dark) => saveDark(item.id, dark)}
|
|
612
|
+
/>
|
|
613
|
+
)}
|
|
614
|
+
</>
|
|
511
615
|
)}
|
|
512
616
|
</li>
|
|
513
617
|
);
|
|
@@ -113,15 +113,80 @@ function rgbaToOklch({ r, g, b, a }: Rgba): Oklch {
|
|
|
113
113
|
return { l: L * 100, c, h: c < 0.0001 ? 0 : h, a };
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
function oklchToRgba({ l, c, h, a }: Oklch): Rgba {
|
|
116
|
+
const linearOf = ({ l, c, h }: Oklch): [number, number, number] => {
|
|
118
117
|
const rad = (h * Math.PI) / 180;
|
|
119
|
-
|
|
118
|
+
return oklabToLinearSrgb(l / 100, c * Math.cos(rad), c * Math.sin(rad));
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const inGamut = (linear: readonly number[]) => linear.every((v) => v >= -1e-6 && v <= 1 + 1e-6);
|
|
122
|
+
|
|
123
|
+
/** Each linear channel clipped into sRGB, as an OKLCH colour again. */
|
|
124
|
+
function clip(colour: Oklch): Oklch {
|
|
125
|
+
const [r, g, b] = linearOf(colour).map((v) => Math.min(1, Math.max(0, v))) as [
|
|
126
|
+
number,
|
|
127
|
+
number,
|
|
128
|
+
number,
|
|
129
|
+
];
|
|
130
|
+
const [L, A, B] = linearSrgbToOklab(r, g, b);
|
|
131
|
+
return { l: L * 100, c: Math.hypot(A, B), h: (Math.atan2(B, A) * 180) / Math.PI, a: colour.a };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Distance in Oklab, with L on its 0–1 scale (deltaEOK). */
|
|
135
|
+
function deltaEOK(x: Oklch, y: Oklch): number {
|
|
136
|
+
const lab = ({ l, c, h }: Oklch) => {
|
|
137
|
+
const rad = (h * Math.PI) / 180;
|
|
138
|
+
return [l / 100, c * Math.cos(rad), c * Math.sin(rad)];
|
|
139
|
+
};
|
|
140
|
+
const [l1 = 0, a1 = 0, b1 = 0] = lab(x);
|
|
141
|
+
const [l2 = 0, a2 = 0, b2 = 0] = lab(y);
|
|
142
|
+
return Math.hypot(l1 - l2, a1 - a2, b1 - b2);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* W-1082: CSS Color 4's gamut mapping (binary search on chroma with a local MINDE). An OKLCH
|
|
147
|
+
* colour sRGB can't show keeps its lightness and hue and loses chroma until clipping it changes
|
|
148
|
+
* it by less than a just-noticeable difference, instead of clipping each channel, which shifted
|
|
149
|
+
* the hue.
|
|
150
|
+
*/
|
|
151
|
+
function mapIntoSrgb(origin: Oklch): Oklch {
|
|
152
|
+
if (origin.l >= 100) return { l: 100, c: 0, h: origin.h, a: origin.a };
|
|
153
|
+
if (origin.l <= 0) return { l: 0, c: 0, h: origin.h, a: origin.a };
|
|
154
|
+
if (inGamut(linearOf(origin))) return origin;
|
|
155
|
+
const JND = 0.02;
|
|
156
|
+
const EPSILON = 0.0001;
|
|
157
|
+
let clipped = clip(origin);
|
|
158
|
+
if (deltaEOK(clipped, origin) < JND) return clipped;
|
|
159
|
+
let min = 0;
|
|
160
|
+
let max = origin.c;
|
|
161
|
+
let minInGamut = true;
|
|
162
|
+
while (max - min > EPSILON) {
|
|
163
|
+
const chroma = (min + max) / 2;
|
|
164
|
+
const current = { ...origin, c: chroma };
|
|
165
|
+
if (minInGamut && inGamut(linearOf(current))) {
|
|
166
|
+
min = chroma;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
clipped = clip(current);
|
|
170
|
+
const e = deltaEOK(clipped, current);
|
|
171
|
+
if (e < JND) {
|
|
172
|
+
if (JND - e < EPSILON) return clipped;
|
|
173
|
+
minInGamut = false;
|
|
174
|
+
min = chroma;
|
|
175
|
+
} else {
|
|
176
|
+
max = chroma;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return clipped;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Out-of-gamut colours are mapped into sRGB by reducing chroma (W-1082). */
|
|
183
|
+
function oklchToRgba(colour: Oklch): Rgba {
|
|
184
|
+
const [lr, lg, lb] = linearOf(mapIntoSrgb(colour));
|
|
120
185
|
return {
|
|
121
186
|
r: channel(linearToSrgb(lr) * 255),
|
|
122
187
|
g: channel(linearToSrgb(lg) * 255),
|
|
123
188
|
b: channel(linearToSrgb(lb) * 255),
|
|
124
|
-
a,
|
|
189
|
+
a: colour.a,
|
|
125
190
|
};
|
|
126
191
|
}
|
|
127
192
|
|
|
@@ -154,8 +219,8 @@ export function parseOklch(text: string): Rgba | null {
|
|
|
154
219
|
}
|
|
155
220
|
|
|
156
221
|
/**
|
|
157
|
-
* Whether a typed OKLCH colour lies outside sRGB, so saving it as hex
|
|
158
|
-
* The slack is half an 8-bit step, so a value EmVB formatted itself never counts
|
|
222
|
+
* Whether a typed OKLCH colour lies outside sRGB, so saving it as hex mapped it in (W-183,
|
|
223
|
+
* W-1082). The slack is half an 8-bit step, so a value EmVB formatted itself never counts.
|
|
159
224
|
*/
|
|
160
225
|
export function oklchClipped(text: string): boolean {
|
|
161
226
|
const oklch = readOklch(text);
|
|
@@ -137,6 +137,7 @@ export function AudienceEditor({
|
|
|
137
137
|
<span className="emvb-bind-label">Countries (two-letter codes)</span>
|
|
138
138
|
<Input
|
|
139
139
|
className={FIELD}
|
|
140
|
+
aria-label="Countries (two-letter codes)"
|
|
140
141
|
value={countryText}
|
|
141
142
|
placeholder="CA, US"
|
|
142
143
|
data-emvb-audience-countries=""
|
|
@@ -188,6 +189,7 @@ export function AudienceEditor({
|
|
|
188
189
|
<span className="emvb-bind-label">Segments (from your site)</span>
|
|
189
190
|
<Input
|
|
190
191
|
className={FIELD}
|
|
192
|
+
aria-label="Segments (from your site)"
|
|
191
193
|
value={segmentText}
|
|
192
194
|
placeholder="member, plan:pro"
|
|
193
195
|
data-emvb-audience-segments=""
|
|
@@ -298,6 +300,7 @@ export function AudienceEditor({
|
|
|
298
300
|
<span className="emvb-bind-label">Time zone</span>
|
|
299
301
|
<Input
|
|
300
302
|
className={FIELD}
|
|
303
|
+
aria-label="Time zone"
|
|
301
304
|
value={zoneText}
|
|
302
305
|
placeholder="UTC"
|
|
303
306
|
data-emvb-audience-zone=""
|
|
@@ -79,6 +79,24 @@ export function FieldControl({
|
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
if (field.key === "panelPartId" && node.type === "menu-item" && fetcher) {
|
|
83
|
+
// W-1069: a mega menu item's panel is a Section theme part.
|
|
84
|
+
return (
|
|
85
|
+
<LoopItemBindControl
|
|
86
|
+
key={field.key}
|
|
87
|
+
value={typeof raw === "string" ? raw : ""}
|
|
88
|
+
fetcher={fetcher}
|
|
89
|
+
partType="section"
|
|
90
|
+
label="Mega panel"
|
|
91
|
+
emptyLabel="No mega panel"
|
|
92
|
+
marker="mega-panel"
|
|
93
|
+
partName="Section"
|
|
94
|
+
helper="Optional published Section theme part. Its layout fills this item's panel in place of the items under it."
|
|
95
|
+
onChange={(partId) => onChange(withProp(node, "panelPartId", partId || undefined))}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
82
100
|
if (field.key === "field" && fetcher) {
|
|
83
101
|
return (
|
|
84
102
|
<React.Fragment key={field.key}>
|
|
@@ -10,6 +10,9 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
MAX_CAROUSEL_SLIDES,
|
|
12
12
|
MAX_GALLERY_IMAGES,
|
|
13
|
+
MAX_HOTSPOTS,
|
|
14
|
+
MAX_PRICE_ITEMS,
|
|
15
|
+
MAX_SHARE_LINKS,
|
|
13
16
|
MAX_SOCIAL_LINKS,
|
|
14
17
|
MAX_TABS,
|
|
15
18
|
type FieldDescriptor,
|
|
@@ -20,6 +23,9 @@ import {
|
|
|
20
23
|
newAccordionItem,
|
|
21
24
|
newCarouselSlide,
|
|
22
25
|
newGalleryImage,
|
|
26
|
+
newHotspot,
|
|
27
|
+
newPriceListItem,
|
|
28
|
+
newShareLink,
|
|
23
29
|
newSocialLink,
|
|
24
30
|
newTabPanel,
|
|
25
31
|
} from "../../dnd/new-element.ts";
|
|
@@ -73,6 +79,33 @@ const KINDS: Record<string, Kind> = {
|
|
|
73
79
|
make: (n) => newCarouselSlide(n),
|
|
74
80
|
max: MAX_CAROUSEL_SLIDES,
|
|
75
81
|
},
|
|
82
|
+
// W-1043: each row edits the item's title; its price and the rest are in its own panel.
|
|
83
|
+
"price-list": {
|
|
84
|
+
noun: "item",
|
|
85
|
+
field: (n) => ({ key: "title", kind: "text", label: `Item ${n} title` }),
|
|
86
|
+
make: (n) => newPriceListItem(n),
|
|
87
|
+
max: MAX_PRICE_ITEMS,
|
|
88
|
+
},
|
|
89
|
+
// W-1047: each row names its link for screen readers; Edit picks the service in its panel.
|
|
90
|
+
"share-buttons": {
|
|
91
|
+
noun: "link",
|
|
92
|
+
field: (n) => ({
|
|
93
|
+
key: "label",
|
|
94
|
+
kind: "text",
|
|
95
|
+
label: `Link ${n} name`,
|
|
96
|
+
optional: true,
|
|
97
|
+
message: "Leave it empty for Share on and the service's name.",
|
|
98
|
+
}),
|
|
99
|
+
make: (n) => newShareLink(n),
|
|
100
|
+
max: MAX_SHARE_LINKS,
|
|
101
|
+
},
|
|
102
|
+
// W-1048: each row edits the marker's title; its place and note are in its own panel.
|
|
103
|
+
hotspots: {
|
|
104
|
+
noun: "marker",
|
|
105
|
+
field: (n) => ({ key: "title", kind: "text", label: `Marker ${n} title` }),
|
|
106
|
+
make: (n) => newHotspot(n),
|
|
107
|
+
max: MAX_HOTSPOTS,
|
|
108
|
+
},
|
|
76
109
|
};
|
|
77
110
|
|
|
78
111
|
/** True for the elements whose Content tab is a list of their items (W-130). */
|
|
@@ -21,6 +21,8 @@ export function LoopItemBindControl({
|
|
|
21
21
|
label = "Loop item",
|
|
22
22
|
emptyLabel = "Use nested elements",
|
|
23
23
|
marker = "loop-item",
|
|
24
|
+
helper,
|
|
25
|
+
partName = label,
|
|
24
26
|
}: {
|
|
25
27
|
value: string;
|
|
26
28
|
fetcher: Fetcher;
|
|
@@ -30,6 +32,10 @@ export function LoopItemBindControl({
|
|
|
30
32
|
emptyLabel?: string;
|
|
31
33
|
/** `data-emvb-${marker}-bind` keeps the loop-item tests stable. */
|
|
32
34
|
marker?: string;
|
|
35
|
+
/** Replaces the helper line under the list. */
|
|
36
|
+
helper?: string;
|
|
37
|
+
/** The part type as the empty and failed notes name it; unset is `label`. */
|
|
38
|
+
partName?: string;
|
|
33
39
|
}) {
|
|
34
40
|
const [parts, setParts] = React.useState<ThemePartSummary[] | null>(null);
|
|
35
41
|
const [failed, setFailed] = React.useState(false);
|
|
@@ -96,7 +102,7 @@ export function LoopItemBindControl({
|
|
|
96
102
|
onChange={(event) => onChange(event.target.value.trim())}
|
|
97
103
|
/>
|
|
98
104
|
<p className="emvb-helper">
|
|
99
|
-
Optional published {label} theme part. Leave blank to use nested elements
|
|
105
|
+
{helper ?? `Optional published ${label} theme part. Leave blank to use nested elements.`}
|
|
100
106
|
{adminLinks && <a href="/_emdash/admin/plugins/emvb/theme"> Open Theme Builder</a>}
|
|
101
107
|
</p>
|
|
102
108
|
{chosen && chosen.status !== "published" && (
|
|
@@ -118,8 +124,8 @@ export function LoopItemBindControl({
|
|
|
118
124
|
/>
|
|
119
125
|
<p className="emvb-helper">
|
|
120
126
|
{failed
|
|
121
|
-
? `Could not load ${
|
|
122
|
-
: `No ${
|
|
127
|
+
? `Could not load ${partName} parts. Paste a theme-part id${adminLinks ? ", or " : "."}`
|
|
128
|
+
: `No ${partName} theme parts yet. Paste an id${adminLinks ? ", or " : "."}`}
|
|
123
129
|
{adminLinks && (
|
|
124
130
|
<>
|
|
125
131
|
<a href="/_emdash/admin/plugins/emvb/theme">create one in Theme Builder</a>.
|