@perkyzz/emvb 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +57 -2
- package/package.json +72 -4
- package/src/admin/access/RequireEditor.tsx +39 -0
- package/src/admin/access/role.ts +36 -0
- package/src/admin/access/sidebar-shim.ts +108 -0
- package/src/admin/api.ts +48 -0
- package/src/admin/content-api.ts +147 -0
- package/src/admin/editor/Editor.tsx +457 -0
- package/src/admin/editor/EditorOverlay.tsx +54 -0
- package/src/admin/editor/ShortcutsDialog.tsx +30 -0
- package/src/admin/editor/SmallScreenNotice.tsx +20 -0
- package/src/admin/editor/TopBar.tsx +179 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +355 -0
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
- package/src/admin/editor/canvas/DeviceBar.tsx +50 -0
- package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
- package/src/admin/editor/canvas/SelectionOverlay.tsx +185 -0
- package/src/admin/editor/canvas/canvas-events.ts +232 -0
- package/src/admin/editor/canvas/state-preview.ts +19 -0
- package/src/admin/editor/canvas/tab-reveal.ts +35 -0
- package/src/admin/editor/canvas/vnode-react.tsx +49 -0
- package/src/admin/editor/clipboard-store.ts +44 -0
- package/src/admin/editor/dialogs.tsx +125 -0
- package/src/admin/editor/dnd/drag-stash.ts +27 -0
- package/src/admin/editor/dnd/drop-target.ts +101 -0
- package/src/admin/editor/dnd/new-element.ts +32 -0
- package/src/admin/editor/editor-css.ts +539 -0
- package/src/admin/editor/exit.ts +27 -0
- package/src/admin/editor/panels/AddPanel.tsx +142 -0
- package/src/admin/editor/panels/ClassesSection.tsx +334 -0
- package/src/admin/editor/panels/ColorControl.tsx +230 -0
- package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
- package/src/admin/editor/panels/ElementPanel.tsx +629 -0
- package/src/admin/editor/panels/LayersPanel.tsx +336 -0
- package/src/admin/editor/panels/LeftPanel.tsx +77 -0
- package/src/admin/editor/panels/PageSettings.tsx +126 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +101 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +392 -0
- package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +197 -0
- package/src/admin/editor/panels/VariableSection.tsx +492 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +320 -0
- package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +349 -0
- package/src/admin/editor/panels/settings/DraftTextField.tsx +201 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +347 -0
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +83 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +150 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +97 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +109 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +181 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +124 -0
- package/src/admin/editor/panels/settings/MediaPicker.tsx +218 -0
- package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +480 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +167 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +51 -0
- package/src/admin/editor/panels/settings/length-units.ts +83 -0
- package/src/admin/editor/panels/settings/node-props.ts +11 -0
- package/src/admin/editor/panels/settings/style-sections.ts +291 -0
- package/src/admin/editor/panels/site-list.tsx +206 -0
- package/src/admin/editor/panels/variable-values.ts +73 -0
- package/src/admin/editor/section-templates.ts +50 -0
- package/src/admin/editor/shortcuts.ts +20 -0
- package/src/admin/editor/store.ts +212 -0
- package/src/admin/editor/useClipboardActions.ts +136 -0
- package/src/admin/editor/useEditorCommands.ts +142 -0
- package/src/admin/editor/useEditorData.ts +167 -0
- package/src/admin/editor/useEditorShortcuts.ts +148 -0
- package/src/admin/editor/useMediaQuery.ts +20 -0
- package/src/admin/editor/useNodeActions.ts +122 -0
- package/src/admin/editor/useSave.ts +185 -0
- package/src/admin/forms-api.ts +73 -0
- package/src/admin/index.tsx +20 -0
- package/src/admin/media-api.ts +68 -0
- package/src/admin/pages/CreateDialog.tsx +150 -0
- package/src/admin/pages/EditorPage.tsx +57 -0
- package/src/admin/pages/NewPageDialog.tsx +83 -0
- package/src/admin/pages/NewThemePartDialog.tsx +61 -0
- package/src/admin/pages/PageList.tsx +71 -0
- package/src/admin/pages/PagesPage.tsx +25 -0
- package/src/admin/pages/SetupShell.tsx +90 -0
- package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
- package/src/admin/pages/ThemePartList.tsx +202 -0
- package/src/admin/pages/list-kit.tsx +75 -0
- package/src/admin/setup/plan.ts +150 -0
- package/src/admin/setup/run.ts +61 -0
- package/src/admin/setup/spec.ts +100 -0
- package/src/admin/setup/useSetupStatus.ts +62 -0
- package/src/admin/theme-api.ts +186 -0
- package/src/admin/ui.ts +231 -0
- package/src/admin/widgets/LayoutField.tsx +67 -0
- package/src/astro/EmVBPage.astro +37 -0
- package/src/astro/env.d.ts +5 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
- package/src/astro/forms/index.ts +1 -0
- package/src/astro/forms-definitions.ts +104 -0
- package/src/astro/index.ts +15 -0
- package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
- package/src/astro/popups/index.ts +1 -0
- package/src/astro/popups/runtime.ts +246 -0
- package/src/astro/render.ts +74 -0
- package/src/astro/resolve-theme.ts +371 -0
- package/src/astro/resolve.ts +65 -0
- package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
- package/src/astro/tabs/index.ts +1 -0
- package/src/astro/tabs/runtime.ts +111 -0
- package/src/astro/theme-context.ts +81 -0
- package/src/astro/theme-posts.ts +84 -0
- package/src/constants.ts +12 -0
- package/src/core/arrange.ts +360 -0
- package/src/core/clipboard.ts +422 -0
- package/src/core/css/generate.ts +219 -0
- package/src/core/css/scope.ts +88 -0
- package/src/core/design/cascade.ts +28 -0
- package/src/core/design/classes.ts +138 -0
- package/src/core/design/devices.ts +56 -0
- package/src/core/design/states.ts +49 -0
- package/src/core/design/transfer.ts +33 -0
- package/src/core/design/variables.ts +319 -0
- package/src/core/elements/definition.ts +12 -0
- package/src/core/elements/dynamic-elements.ts +173 -0
- package/src/core/elements/form-elements.ts +204 -0
- package/src/core/elements/index.ts +742 -0
- package/src/core/elements/plain-text.ts +32 -0
- package/src/core/forms/binding.ts +61 -0
- package/src/core/forms/definition.ts +34 -0
- package/src/core/forms/success-layout.ts +63 -0
- package/src/core/icons/catalog.ts +273 -0
- package/src/core/index.ts +316 -0
- package/src/core/limits.ts +7 -0
- package/src/core/migrate/index.ts +76 -0
- package/src/core/render/context.ts +14 -0
- package/src/core/render/dynamic-post.ts +147 -0
- package/src/core/render/extras.ts +79 -0
- package/src/core/render/form.ts +137 -0
- package/src/core/render/index.ts +274 -0
- package/src/core/render/loop.ts +36 -0
- package/src/core/render/section.ts +33 -0
- package/src/core/render/tabs.ts +72 -0
- package/src/core/render/vnode.ts +87 -0
- package/src/core/sanitize/css.ts +591 -0
- package/src/core/sanitize/embed-url.ts +103 -0
- package/src/core/sanitize/escape.ts +10 -0
- package/src/core/sanitize/href.ts +6 -0
- package/src/core/sanitize/media-url.ts +7 -0
- package/src/core/sanitize/svg.ts +293 -0
- package/src/core/sanitize/url.ts +31 -0
- package/src/core/schema/descriptors.ts +33 -0
- package/src/core/schema/design.ts +88 -0
- package/src/core/schema/layout.ts +817 -0
- package/src/core/schema/state-names.ts +4 -0
- package/src/core/schema/style.ts +257 -0
- package/src/core/stats.ts +18 -0
- package/src/core/tabs/presence.ts +16 -0
- package/src/core/theme/conditions.ts +321 -0
- package/src/core/theme/dynamic.ts +133 -0
- package/src/core/theme/parse-doc.ts +36 -0
- package/src/core/theme/part-types.ts +79 -0
- package/src/core/theme/popup-markup.ts +39 -0
- package/src/core/theme/popup-rules.ts +61 -0
- package/src/core/theme/triggers.ts +104 -0
- package/src/core/tree-ops.ts +139 -0
- package/src/core/validate.ts +185 -0
- package/src/index.ts +18 -0
- package/src/server/design-routes.ts +125 -0
- package/src/server/hooks.ts +98 -0
- package/src/server/plugin.ts +39 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { Button, Select, Tabs } from "@cloudflare/kumo";
|
|
2
|
+
import { WarningCircleIcon, XIcon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import {
|
|
5
|
+
clearClassRefs,
|
|
6
|
+
deleteVariable,
|
|
7
|
+
designFromJson,
|
|
8
|
+
designToJson,
|
|
9
|
+
findClassUsages,
|
|
10
|
+
findVariableUsages,
|
|
11
|
+
findVariableUsagesInDesign,
|
|
12
|
+
removeVariable,
|
|
13
|
+
DEFAULT_STYLE_TAGS,
|
|
14
|
+
type DefaultStyleTag,
|
|
15
|
+
type DesignSystem,
|
|
16
|
+
type Layout,
|
|
17
|
+
type StyleProps,
|
|
18
|
+
type VariableKind,
|
|
19
|
+
} from "../../../core/index.ts";
|
|
20
|
+
import { BUTTON, SOLID_DESTRUCTIVE } from "../../ui.ts";
|
|
21
|
+
import { ClassesSection } from "./ClassesSection.tsx";
|
|
22
|
+
import { stopEditorShortcuts } from "./settings/ClassChip.tsx";
|
|
23
|
+
import { StyleRow } from "./settings/StyleRow.tsx";
|
|
24
|
+
import { FIELD } from "../../ui.ts";
|
|
25
|
+
import { VariableSection } from "./VariableSection.tsx";
|
|
26
|
+
|
|
27
|
+
const STYLE_NOTE = "Style changes stay unpublished until you publish styles.";
|
|
28
|
+
|
|
29
|
+
type Props = {
|
|
30
|
+
design: DesignSystem;
|
|
31
|
+
layout: Layout | null;
|
|
32
|
+
onDesignChange: (design: DesignSystem) => Promise<void>;
|
|
33
|
+
unpublished?: boolean;
|
|
34
|
+
onPublishStyles?: () => Promise<void>;
|
|
35
|
+
onLayoutChange: (layout: Layout) => void;
|
|
36
|
+
onClose: () => void;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function InlineError({ children }: { children: string }) {
|
|
40
|
+
return (
|
|
41
|
+
<p className="emvb-inline-error" role="alert">
|
|
42
|
+
<WarningCircleIcon size={16} aria-hidden="true" />
|
|
43
|
+
{children}
|
|
44
|
+
</p>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function exportDesign(design: DesignSystem) {
|
|
49
|
+
const blob = new Blob([designToJson(design)], { type: "application/json" });
|
|
50
|
+
const url = URL.createObjectURL(blob);
|
|
51
|
+
const link = document.createElement("a");
|
|
52
|
+
link.href = url;
|
|
53
|
+
link.download = "emvb-design.json";
|
|
54
|
+
link.click();
|
|
55
|
+
URL.revokeObjectURL(url);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Site styles drawer — Variables Manager and Classes Manager (W-032 / W-071).
|
|
60
|
+
* Elementor v4–inspired workflow on EmVB tokens; saves via CAS (D-013 / D-EV4-03).
|
|
61
|
+
*/
|
|
62
|
+
export function SiteStylesDrawer({
|
|
63
|
+
design,
|
|
64
|
+
layout,
|
|
65
|
+
onDesignChange,
|
|
66
|
+
unpublished = false,
|
|
67
|
+
onPublishStyles,
|
|
68
|
+
onLayoutChange,
|
|
69
|
+
onClose,
|
|
70
|
+
}: Props) {
|
|
71
|
+
const [tab, setTab] = React.useState<"variables" | "classes" | "defaults">("variables");
|
|
72
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
73
|
+
const [confirm, setConfirm] = React.useState<
|
|
74
|
+
| { kind: "variable"; variableKind: VariableKind; id: string; name: string }
|
|
75
|
+
| { kind: "class"; id: string; name: string }
|
|
76
|
+
| null
|
|
77
|
+
>(null);
|
|
78
|
+
const fileRef = React.useRef<HTMLInputElement>(null);
|
|
79
|
+
|
|
80
|
+
const save = async (next: DesignSystem) => {
|
|
81
|
+
setError(null);
|
|
82
|
+
try {
|
|
83
|
+
await onDesignChange(next);
|
|
84
|
+
} catch (err) {
|
|
85
|
+
setError(err instanceof Error ? err.message : "Couldn't save site styles. Try again.");
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const publish = async () => {
|
|
90
|
+
if (!onPublishStyles) return;
|
|
91
|
+
setError(null);
|
|
92
|
+
try {
|
|
93
|
+
await onPublishStyles();
|
|
94
|
+
} catch (err) {
|
|
95
|
+
setError(err instanceof Error ? err.message : "Couldn't publish site styles. Try again.");
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const importDesign = async (file: File) => {
|
|
100
|
+
setError(null);
|
|
101
|
+
const text = await file.text();
|
|
102
|
+
const result = designFromJson(text);
|
|
103
|
+
if (!result.ok) {
|
|
104
|
+
setError(result.message);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
await save(result.design);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<div
|
|
112
|
+
className="emvb-panel-body emvb-site-styles"
|
|
113
|
+
data-emvb-site-styles=""
|
|
114
|
+
onKeyDown={stopEditorShortcuts}
|
|
115
|
+
>
|
|
116
|
+
<div className="emvb-site-styles-head">
|
|
117
|
+
<div className="emvb-site-styles-titles">
|
|
118
|
+
<h2 className="emvb-panel-title">Site styles</h2>
|
|
119
|
+
<p className="emvb-helper emvb-site-styles-subtitle" data-emvb-manager-label="">
|
|
120
|
+
{tab === "variables"
|
|
121
|
+
? "Variables Manager"
|
|
122
|
+
: tab === "classes"
|
|
123
|
+
? "Classes Manager"
|
|
124
|
+
: "Defaults"}
|
|
125
|
+
</p>
|
|
126
|
+
</div>
|
|
127
|
+
<Button
|
|
128
|
+
type="button"
|
|
129
|
+
variant="ghost"
|
|
130
|
+
shape="square"
|
|
131
|
+
className="emvb-icon-btn"
|
|
132
|
+
aria-label="Close site styles"
|
|
133
|
+
icon={<XIcon aria-hidden="true" />}
|
|
134
|
+
onClick={onClose}
|
|
135
|
+
/>
|
|
136
|
+
</div>
|
|
137
|
+
{/* W-115: the actions get their own wrapping row, so the title is never squeezed. */}
|
|
138
|
+
<div
|
|
139
|
+
className="emvb-site-styles-actions"
|
|
140
|
+
role="group"
|
|
141
|
+
aria-label="Site styles actions"
|
|
142
|
+
data-emvb-site-styles-actions=""
|
|
143
|
+
>
|
|
144
|
+
{unpublished && (
|
|
145
|
+
<Button type="button" variant="primary" size="sm" onClick={() => void publish()}>
|
|
146
|
+
Publish styles
|
|
147
|
+
</Button>
|
|
148
|
+
)}
|
|
149
|
+
<Button type="button" variant="secondary" size="sm" onClick={() => exportDesign(design)}>
|
|
150
|
+
Export
|
|
151
|
+
</Button>
|
|
152
|
+
<Button
|
|
153
|
+
type="button"
|
|
154
|
+
variant="secondary"
|
|
155
|
+
size="sm"
|
|
156
|
+
onClick={() => fileRef.current?.click()}
|
|
157
|
+
>
|
|
158
|
+
Import
|
|
159
|
+
</Button>
|
|
160
|
+
<input
|
|
161
|
+
ref={fileRef}
|
|
162
|
+
type="file"
|
|
163
|
+
accept="application/json,.json"
|
|
164
|
+
hidden
|
|
165
|
+
data-emvb-design-import=""
|
|
166
|
+
onChange={(event) => {
|
|
167
|
+
const file = event.target.files?.[0];
|
|
168
|
+
event.target.value = "";
|
|
169
|
+
if (file) void importDesign(file);
|
|
170
|
+
}}
|
|
171
|
+
/>
|
|
172
|
+
</div>
|
|
173
|
+
<Tabs
|
|
174
|
+
variant="underline"
|
|
175
|
+
className="emvb-tabs"
|
|
176
|
+
tabs={[
|
|
177
|
+
{ value: "variables", label: "Variables" },
|
|
178
|
+
{ value: "classes", label: "Classes" },
|
|
179
|
+
{ value: "defaults", label: "Defaults" },
|
|
180
|
+
]}
|
|
181
|
+
value={tab}
|
|
182
|
+
onValueChange={(value) =>
|
|
183
|
+
setTab(value === "classes" ? "classes" : value === "defaults" ? "defaults" : "variables")
|
|
184
|
+
}
|
|
185
|
+
/>
|
|
186
|
+
{error && <InlineError>{error}</InlineError>}
|
|
187
|
+
{tab === "variables" && (
|
|
188
|
+
<div data-emvb-site-tab="variables" className="emvb-site-styles-body">
|
|
189
|
+
<VariableSection
|
|
190
|
+
title="Colors"
|
|
191
|
+
kind="color"
|
|
192
|
+
design={design}
|
|
193
|
+
layout={layout}
|
|
194
|
+
onSave={save}
|
|
195
|
+
onAskDelete={(id, name) =>
|
|
196
|
+
setConfirm({ kind: "variable", variableKind: "color", id, name })
|
|
197
|
+
}
|
|
198
|
+
/>
|
|
199
|
+
<VariableSection
|
|
200
|
+
title="Fonts"
|
|
201
|
+
kind="font"
|
|
202
|
+
design={design}
|
|
203
|
+
layout={layout}
|
|
204
|
+
onSave={save}
|
|
205
|
+
onAskDelete={(id, name) =>
|
|
206
|
+
setConfirm({ kind: "variable", variableKind: "font", id, name })
|
|
207
|
+
}
|
|
208
|
+
/>
|
|
209
|
+
<VariableSection
|
|
210
|
+
title="Font sizes"
|
|
211
|
+
kind="fontSize"
|
|
212
|
+
design={design}
|
|
213
|
+
layout={layout}
|
|
214
|
+
onSave={save}
|
|
215
|
+
onAskDelete={(id, name) =>
|
|
216
|
+
setConfirm({ kind: "variable", variableKind: "fontSize", id, name })
|
|
217
|
+
}
|
|
218
|
+
/>
|
|
219
|
+
<VariableSection
|
|
220
|
+
title="Spacing"
|
|
221
|
+
kind="spacing"
|
|
222
|
+
design={design}
|
|
223
|
+
layout={layout}
|
|
224
|
+
onSave={save}
|
|
225
|
+
onAskDelete={(id, name) =>
|
|
226
|
+
setConfirm({ kind: "variable", variableKind: "spacing", id, name })
|
|
227
|
+
}
|
|
228
|
+
/>
|
|
229
|
+
</div>
|
|
230
|
+
)}
|
|
231
|
+
{tab === "classes" && (
|
|
232
|
+
<div data-emvb-site-tab="classes" className="emvb-site-styles-body">
|
|
233
|
+
<ClassesSection
|
|
234
|
+
design={design}
|
|
235
|
+
layout={layout}
|
|
236
|
+
onSave={save}
|
|
237
|
+
onAskDelete={(id, name) => setConfirm({ kind: "class", id, name })}
|
|
238
|
+
/>
|
|
239
|
+
</div>
|
|
240
|
+
)}
|
|
241
|
+
{tab === "defaults" && (
|
|
242
|
+
<div data-emvb-site-tab="defaults" className="emvb-site-styles-body">
|
|
243
|
+
<DefaultsSection design={design} onSave={save} />
|
|
244
|
+
</div>
|
|
245
|
+
)}
|
|
246
|
+
<p className="emvb-helper emvb-site-styles-footer">{STYLE_NOTE}</p>
|
|
247
|
+
{confirm && (
|
|
248
|
+
<DeleteConfirm
|
|
249
|
+
confirm={confirm}
|
|
250
|
+
design={design}
|
|
251
|
+
layout={layout}
|
|
252
|
+
onCancel={() => setConfirm(null)}
|
|
253
|
+
onConfirm={async () => {
|
|
254
|
+
if (confirm.kind === "variable") {
|
|
255
|
+
if (layout) {
|
|
256
|
+
const result = deleteVariable(design, layout, confirm.id, confirm.variableKind);
|
|
257
|
+
onLayoutChange(result.layout);
|
|
258
|
+
await save(result.design);
|
|
259
|
+
} else {
|
|
260
|
+
await save(removeVariable(design, confirm.id, confirm.variableKind));
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
const classes = (design.classes ?? []).filter((c) => c.id !== confirm.id);
|
|
264
|
+
if (layout) onLayoutChange(clearClassRefs(layout, confirm.id));
|
|
265
|
+
await save({ ...design, classes });
|
|
266
|
+
}
|
|
267
|
+
setConfirm(null);
|
|
268
|
+
}}
|
|
269
|
+
/>
|
|
270
|
+
)}
|
|
271
|
+
</div>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const plural = (n: number, one: string, many: string) => `${n} ${n === 1 ? one : many}`;
|
|
276
|
+
|
|
277
|
+
/** "2 places on this page and 1 class", or null when nothing uses it. */
|
|
278
|
+
function usedIn(pageUses: number, classUses: number): string | null {
|
|
279
|
+
const parts = [
|
|
280
|
+
pageUses > 0 ? `${plural(pageUses, "place", "places")} on this page` : "",
|
|
281
|
+
classUses > 0 ? plural(classUses, "class", "classes") : "",
|
|
282
|
+
].filter(Boolean);
|
|
283
|
+
return parts.length > 0 ? parts.join(" and ") : null;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function DeleteConfirm({
|
|
287
|
+
confirm,
|
|
288
|
+
design,
|
|
289
|
+
layout,
|
|
290
|
+
onCancel,
|
|
291
|
+
onConfirm,
|
|
292
|
+
}: {
|
|
293
|
+
confirm:
|
|
294
|
+
| { kind: "variable"; variableKind: VariableKind; id: string; name: string }
|
|
295
|
+
| { kind: "class"; id: string; name: string };
|
|
296
|
+
design: DesignSystem;
|
|
297
|
+
layout: Layout | null;
|
|
298
|
+
onCancel: () => void;
|
|
299
|
+
onConfirm: () => void;
|
|
300
|
+
}) {
|
|
301
|
+
const variable = confirm.kind === "variable";
|
|
302
|
+
const pageUses = !layout
|
|
303
|
+
? 0
|
|
304
|
+
: variable
|
|
305
|
+
? findVariableUsages(layout, confirm.id, confirm.variableKind).length
|
|
306
|
+
: findClassUsages(layout, confirm.id).length;
|
|
307
|
+
const classUses = variable
|
|
308
|
+
? new Set(
|
|
309
|
+
findVariableUsagesInDesign(design, confirm.id, confirm.variableKind).map((u) => u.classId),
|
|
310
|
+
).size
|
|
311
|
+
: 0;
|
|
312
|
+
const where = usedIn(pageUses, classUses);
|
|
313
|
+
return (
|
|
314
|
+
<div className="emvb-site-confirm" data-emvb-site-confirm="" role="alertdialog">
|
|
315
|
+
<p className="emvb-field-label">Delete {confirm.name}?</p>
|
|
316
|
+
<p className="emvb-helper">
|
|
317
|
+
{where
|
|
318
|
+
? `In use in ${where}. Deleting drops those bindings.`
|
|
319
|
+
: variable
|
|
320
|
+
? "Not used on this page or by any class."
|
|
321
|
+
: "Not used on this page."}
|
|
322
|
+
</p>
|
|
323
|
+
<div className="emvb-dialog-actions">
|
|
324
|
+
<Button type="button" variant="secondary" className={BUTTON} onClick={onCancel}>
|
|
325
|
+
Cancel
|
|
326
|
+
</Button>
|
|
327
|
+
<Button
|
|
328
|
+
type="button"
|
|
329
|
+
variant="destructive"
|
|
330
|
+
className={BUTTON}
|
|
331
|
+
style={SOLID_DESTRUCTIVE}
|
|
332
|
+
onClick={onConfirm}
|
|
333
|
+
>
|
|
334
|
+
Delete
|
|
335
|
+
</Button>
|
|
336
|
+
</div>
|
|
337
|
+
</div>
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const DEFAULT_KEYS = ["color", "fontSize", "fontWeight", "textAlign"] as const;
|
|
342
|
+
|
|
343
|
+
function DefaultsSection({
|
|
344
|
+
design,
|
|
345
|
+
onSave,
|
|
346
|
+
}: {
|
|
347
|
+
design: DesignSystem;
|
|
348
|
+
onSave: (design: DesignSystem) => Promise<void>;
|
|
349
|
+
}) {
|
|
350
|
+
const [tag, setTag] = React.useState<DefaultStyleTag>("p");
|
|
351
|
+
const style = design.defaults?.[tag];
|
|
352
|
+
const patch = (partial: Partial<StyleProps>) => {
|
|
353
|
+
const next: StyleProps = { ...style, ...partial };
|
|
354
|
+
for (const key of Object.keys(partial) as (keyof StyleProps)[]) {
|
|
355
|
+
if (partial[key] === undefined) delete next[key];
|
|
356
|
+
}
|
|
357
|
+
const defaults = {
|
|
358
|
+
...design.defaults,
|
|
359
|
+
[tag]: Object.keys(next).length > 0 ? next : undefined,
|
|
360
|
+
};
|
|
361
|
+
void onSave({ ...design, defaults });
|
|
362
|
+
};
|
|
363
|
+
return (
|
|
364
|
+
<>
|
|
365
|
+
<p className="emvb-helper">
|
|
366
|
+
Elements of this tag start here. A class or a local style still wins.
|
|
367
|
+
</p>
|
|
368
|
+
<Select
|
|
369
|
+
label="Tag"
|
|
370
|
+
className={FIELD}
|
|
371
|
+
value={tag}
|
|
372
|
+
onValueChange={(value) => setTag(value as DefaultStyleTag)}
|
|
373
|
+
>
|
|
374
|
+
{DEFAULT_STYLE_TAGS.map((item) => (
|
|
375
|
+
<Select.Option key={item} value={item}>
|
|
376
|
+
{item}
|
|
377
|
+
</Select.Option>
|
|
378
|
+
))}
|
|
379
|
+
</Select>
|
|
380
|
+
{DEFAULT_KEYS.map((key) => (
|
|
381
|
+
<StyleRow
|
|
382
|
+
key={`${tag}:${key}`}
|
|
383
|
+
styleKey={key}
|
|
384
|
+
style={style}
|
|
385
|
+
design={design}
|
|
386
|
+
onPatch={patch}
|
|
387
|
+
onDesignChange={onSave}
|
|
388
|
+
/>
|
|
389
|
+
))}
|
|
390
|
+
</>
|
|
391
|
+
);
|
|
392
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Input } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { clampScrollPercent, type PopupOpenTrigger, TRIGGER_LIMITS } from "../../../core/index.ts";
|
|
4
|
+
import { FIELD } from "../../ui.ts";
|
|
5
|
+
|
|
6
|
+
const clamp = (n: number, min: number, max: number) => Math.min(max, Math.max(min, n));
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A number field that keeps what is typed and commits on blur or Enter (W-087), so a lower bound
|
|
10
|
+
* never rewrites the first keystroke (typing 5000 into Idle time used to jump to 1000).
|
|
11
|
+
*/
|
|
12
|
+
function NumberField({
|
|
13
|
+
label,
|
|
14
|
+
value,
|
|
15
|
+
min,
|
|
16
|
+
max,
|
|
17
|
+
description,
|
|
18
|
+
normalize,
|
|
19
|
+
onCommit,
|
|
20
|
+
}: {
|
|
21
|
+
label: string;
|
|
22
|
+
value: number;
|
|
23
|
+
min: number;
|
|
24
|
+
max: number;
|
|
25
|
+
description?: string;
|
|
26
|
+
normalize: (raw: string) => number;
|
|
27
|
+
onCommit: (value: number) => void;
|
|
28
|
+
}) {
|
|
29
|
+
const [draft, setDraft] = React.useState(String(value));
|
|
30
|
+
const commit = () => {
|
|
31
|
+
const next = normalize(draft);
|
|
32
|
+
setDraft(String(next));
|
|
33
|
+
if (next !== value) onCommit(next);
|
|
34
|
+
};
|
|
35
|
+
return (
|
|
36
|
+
<Input
|
|
37
|
+
label={label}
|
|
38
|
+
className={FIELD}
|
|
39
|
+
type="number"
|
|
40
|
+
min={min}
|
|
41
|
+
max={max}
|
|
42
|
+
description={description}
|
|
43
|
+
value={draft}
|
|
44
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
45
|
+
onBlur={commit}
|
|
46
|
+
onKeyDown={(event) => {
|
|
47
|
+
if (event.key === "Enter") commit();
|
|
48
|
+
}}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const seconds = (ms: number) =>
|
|
54
|
+
`${(ms / 1000).toLocaleString("en", { maximumFractionDigits: 1 })} s`;
|
|
55
|
+
|
|
56
|
+
/** The per-type settings row inside a popup trigger (S7b / W-081). */
|
|
57
|
+
export function TriggerSettings({
|
|
58
|
+
trigger,
|
|
59
|
+
onChange,
|
|
60
|
+
}: {
|
|
61
|
+
trigger: PopupOpenTrigger;
|
|
62
|
+
onChange: (next: PopupOpenTrigger) => void;
|
|
63
|
+
}) {
|
|
64
|
+
if (trigger.type === "delay") {
|
|
65
|
+
return (
|
|
66
|
+
<NumberField
|
|
67
|
+
key={trigger.ms}
|
|
68
|
+
label="Delay (ms)"
|
|
69
|
+
value={trigger.ms}
|
|
70
|
+
min={0}
|
|
71
|
+
max={TRIGGER_LIMITS.maxDelayMs}
|
|
72
|
+
description={`${seconds(trigger.ms)} after the page loads. Up to 120 000 ms.`}
|
|
73
|
+
normalize={(raw) => clamp(Number(raw) || 0, 0, TRIGGER_LIMITS.maxDelayMs)}
|
|
74
|
+
onCommit={(ms) => onChange({ type: "delay", ms })}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (trigger.type === "scroll") {
|
|
79
|
+
return (
|
|
80
|
+
<NumberField
|
|
81
|
+
key={trigger.percent}
|
|
82
|
+
label="Scroll percent"
|
|
83
|
+
value={trigger.percent}
|
|
84
|
+
min={0}
|
|
85
|
+
max={TRIGGER_LIMITS.maxScrollPercent}
|
|
86
|
+
description="How far down the page, from 0 to 100."
|
|
87
|
+
normalize={clampScrollPercent}
|
|
88
|
+
onCommit={(percent) => onChange({ type: "scroll", percent })}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (trigger.type === "click") {
|
|
93
|
+
return (
|
|
94
|
+
<Input
|
|
95
|
+
label="CSS selector"
|
|
96
|
+
className={`${FIELD} emvb-mono`}
|
|
97
|
+
value={trigger.selector}
|
|
98
|
+
placeholder=".open-popup"
|
|
99
|
+
description="Clicking any element that matches opens the popup."
|
|
100
|
+
onChange={(event) => onChange({ type: "click", selector: event.target.value })}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
if (trigger.type === "exit_intent") {
|
|
105
|
+
return (
|
|
106
|
+
<p className="emvb-helper">
|
|
107
|
+
Opens when the pointer leaves toward the top of the viewport (desktop).
|
|
108
|
+
</p>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
if (trigger.type === "inactivity") {
|
|
112
|
+
return (
|
|
113
|
+
<NumberField
|
|
114
|
+
key={trigger.ms}
|
|
115
|
+
label="Idle time (ms)"
|
|
116
|
+
value={trigger.ms}
|
|
117
|
+
min={TRIGGER_LIMITS.minIdleMs}
|
|
118
|
+
max={TRIGGER_LIMITS.maxDelayMs}
|
|
119
|
+
description={`${seconds(trigger.ms)} without scrolling, typing, clicking or moving the pointer.`}
|
|
120
|
+
normalize={(raw) =>
|
|
121
|
+
clamp(
|
|
122
|
+
Number(raw) || TRIGGER_LIMITS.minIdleMs,
|
|
123
|
+
TRIGGER_LIMITS.minIdleMs,
|
|
124
|
+
TRIGGER_LIMITS.maxDelayMs,
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
onCommit={(ms) => onChange({ type: "inactivity", ms })}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|