@perkyzz/emvb 0.1.0 → 0.2.1
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 +6 -4
- package/THIRD_PARTY_NOTICES.md +32 -0
- package/licenses/fontawesome-free.LICENSE +165 -0
- package/licenses/lucide-static.LICENSE +43 -0
- package/licenses/remixicon.LICENSE +201 -0
- package/licenses/tabler-icons.LICENSE +21 -0
- package/package.json +9 -5
- package/src/admin/api.ts +27 -0
- package/src/admin/content-api.ts +72 -9
- package/src/admin/editor/Editor.tsx +89 -14
- package/src/admin/editor/EditorOverlay.tsx +12 -0
- package/src/admin/editor/SmallScreenNotice.tsx +4 -3
- package/src/admin/editor/TopBar.tsx +76 -12
- package/src/admin/editor/canvas/CanvasFrame.tsx +224 -43
- package/src/admin/editor/canvas/DeviceBar.tsx +43 -2
- package/src/admin/editor/canvas/SelectionOverlay.tsx +60 -6
- package/src/admin/editor/canvas/canvas-events.ts +20 -7
- package/src/admin/editor/canvas/tab-reveal.ts +66 -0
- package/src/admin/editor/canvas/vnode-react.tsx +21 -1
- package/src/admin/editor/dialogs.tsx +39 -0
- package/src/admin/editor/dnd/drop-target.ts +63 -16
- package/src/admin/editor/dnd/new-element.ts +76 -1
- package/src/admin/editor/editor-css.ts +101 -15
- package/src/admin/editor/host.ts +30 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
- package/src/admin/editor/icons/library.ts +243 -0
- package/src/admin/editor/icons/set-format.ts +29 -0
- package/src/admin/editor/icons/sets/fontawesome.json +1 -0
- package/src/admin/editor/icons/sets/lucide.json +1 -0
- package/src/admin/editor/icons/sets/remix.json +1 -0
- package/src/admin/editor/icons/sets/tabler.json +1 -0
- package/src/admin/editor/panels/AddPanel.tsx +7 -3
- package/src/admin/editor/panels/ClassesSection.tsx +44 -6
- package/src/admin/editor/panels/ColorControl.tsx +268 -21
- package/src/admin/editor/panels/ElementPanel.tsx +237 -93
- package/src/admin/editor/panels/LayersPanel.tsx +303 -66
- package/src/admin/editor/panels/LeftPanel.tsx +4 -0
- package/src/admin/editor/panels/PageSettings.tsx +134 -5
- package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +158 -2
- package/src/admin/editor/panels/TriggersEditor.tsx +19 -2
- package/src/admin/editor/panels/VariableSection.tsx +47 -9
- package/src/admin/editor/panels/color-space.ts +195 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +153 -55
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
- package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
- package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +104 -2
- package/src/admin/editor/panels/settings/DraftTextField.tsx +44 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +25 -16
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +53 -17
- package/src/admin/editor/panels/settings/FieldControl.tsx +129 -9
- package/src/admin/editor/panels/settings/FormBindControl.tsx +14 -5
- package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +133 -72
- package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
- package/src/admin/editor/panels/settings/LengthRow.tsx +97 -61
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +10 -4
- package/src/admin/editor/panels/settings/MediaPicker.tsx +4 -2
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +158 -75
- package/src/admin/editor/panels/settings/VariableBinding.tsx +5 -1
- package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
- package/src/admin/editor/panels/settings/background-mode.ts +112 -0
- package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
- package/src/admin/editor/panels/settings/box-sides.ts +153 -0
- package/src/admin/editor/panels/settings/button-url.ts +27 -0
- package/src/admin/editor/panels/settings/class-suggest.ts +5 -3
- package/src/admin/editor/panels/settings/form-names.ts +38 -0
- package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
- package/src/admin/editor/panels/settings/image-alt.ts +25 -0
- package/src/admin/editor/panels/settings/length-units.ts +40 -7
- package/src/admin/editor/panels/settings/loop-context.ts +26 -0
- package/src/admin/editor/panels/settings/style-sections.ts +114 -11
- package/src/admin/editor/panels/settings/svg-images.ts +14 -0
- package/src/admin/editor/panels/site-list.tsx +3 -0
- package/src/admin/editor/restore-deleted.ts +80 -0
- package/src/admin/editor/shortcuts.ts +1 -1
- package/src/admin/editor/store.ts +35 -7
- package/src/admin/editor/useEditorCommands.ts +66 -5
- package/src/admin/editor/useEditorData.ts +29 -3
- package/src/admin/editor/useEditorShortcuts.ts +34 -2
- package/src/admin/editor/useNodeActions.ts +68 -6
- package/src/admin/editor/useSave.ts +60 -3
- package/src/admin/entry-status.ts +19 -0
- package/src/admin/icon-uploads-api.ts +44 -0
- package/src/admin/pages/PageList.tsx +22 -2
- package/src/admin/pages/ThemePartList.tsx +23 -4
- package/src/admin/pages/list-kit.tsx +52 -2
- package/src/admin/setup/spec.ts +7 -0
- package/src/admin/theme-api.ts +61 -14
- package/src/admin/ui.ts +17 -4
- package/src/astro/EmVBPage.astro +28 -2
- package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
- package/src/astro/floats/index.ts +1 -0
- package/src/astro/floats/runtime.ts +78 -0
- package/src/astro/forms-definitions.ts +22 -0
- package/src/astro/index.ts +1 -0
- package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
- package/src/astro/menu/index.ts +1 -0
- package/src/astro/menu/runtime.ts +37 -0
- package/src/astro/popups/runtime.ts +54 -4
- package/src/astro/render.ts +47 -13
- package/src/astro/resolve-theme.ts +168 -24
- package/src/astro/tabs/runtime.ts +6 -1
- package/src/astro/theme-context.ts +25 -5
- package/src/astro/theme-posts.ts +19 -1
- package/src/constants.ts +1 -1
- package/src/core/arrange.ts +98 -10
- package/src/core/clipboard.ts +91 -9
- package/src/core/css/generate.ts +21 -4
- package/src/core/design/classes.ts +95 -9
- package/src/core/design/transfer.ts +101 -2
- package/src/core/design/variables.ts +51 -11
- package/src/core/elements/dynamic-elements.ts +57 -5
- package/src/core/elements/field-id.ts +6 -0
- package/src/core/elements/form-elements.ts +23 -8
- package/src/core/elements/index.ts +267 -49
- package/src/core/elements/menu.ts +190 -0
- package/src/core/forms/definition.ts +11 -0
- package/src/core/index.ts +67 -3
- package/src/core/limits.ts +2 -0
- package/src/core/migrate/index.ts +51 -1
- package/src/core/nesting.ts +51 -0
- package/src/core/render/context.ts +7 -0
- package/src/core/render/dynamic-post.ts +39 -11
- package/src/core/render/extras.ts +22 -3
- package/src/core/render/form.ts +134 -36
- package/src/core/render/index.ts +123 -25
- package/src/core/render/loop.ts +10 -3
- package/src/core/render/pagination.ts +76 -0
- package/src/core/render/section.ts +5 -1
- package/src/core/render/tabs.ts +8 -4
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +197 -17
- package/src/core/sanitize/embed-url.ts +64 -7
- package/src/core/sanitize/svg-upload.ts +203 -0
- package/src/core/sanitize/svg.ts +102 -21
- package/src/core/schema/descriptors.ts +4 -0
- package/src/core/schema/design.ts +7 -2
- package/src/core/schema/layout.ts +210 -19
- package/src/core/schema/style.ts +87 -8
- package/src/core/tabs/presence.ts +9 -0
- package/src/core/theme/conditions.ts +4 -1
- package/src/core/theme/dynamic.ts +10 -0
- package/src/core/theme/float.ts +113 -0
- package/src/core/theme/pagination.ts +97 -0
- package/src/core/theme/part-types.ts +2 -0
- package/src/core/theme/popup-markup.ts +3 -1
- package/src/core/theme/popup-rules.ts +4 -3
- package/src/server/hooks.ts +20 -0
- package/src/server/icon-routes.ts +79 -0
- package/src/server/plugin.ts +5 -1
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import { Collapsible, Input, Select } from "@cloudflare/kumo";
|
|
1
|
+
import { Button, Collapsible, Input, Select, Switch } from "@cloudflare/kumo";
|
|
2
2
|
import { CaretDownIcon, CaretRightIcon } from "@phosphor-icons/react";
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
defaultFloatSettings,
|
|
6
|
+
FLOAT_EDGES,
|
|
7
|
+
THEME_PART_TYPE_LABELS,
|
|
8
|
+
type FloatEdge,
|
|
9
|
+
type LayoutNode,
|
|
10
|
+
} from "../../../core/index.ts";
|
|
11
|
+
import type { Fetcher } from "../../api.ts";
|
|
12
|
+
import { canonicalProblem, type PageDraft } from "../../content-api.ts";
|
|
13
|
+
import { BUTTON, FIELD } from "../../ui.ts";
|
|
7
14
|
import type { PagePatch } from "../store.ts";
|
|
8
15
|
import { ConditionsEditor } from "./ConditionsEditor.tsx";
|
|
16
|
+
import { MediaPicker } from "./settings/MediaPicker.tsx";
|
|
9
17
|
import { TriggersEditor } from "./TriggersEditor.tsx";
|
|
10
18
|
|
|
11
19
|
const LAYOUTS = [
|
|
@@ -19,11 +27,14 @@ export function PageSettings({
|
|
|
19
27
|
slugError,
|
|
20
28
|
onChange,
|
|
21
29
|
kind = "page",
|
|
30
|
+
fetcher,
|
|
22
31
|
}: {
|
|
23
32
|
page: PageDraft;
|
|
24
33
|
slugError: string | null;
|
|
25
34
|
onChange: (patch: PagePatch) => void;
|
|
26
35
|
kind?: "page" | "theme-part";
|
|
36
|
+
/** For the Social image picker (W-287); without it the field isn't offered. */
|
|
37
|
+
fetcher?: Fetcher;
|
|
27
38
|
}) {
|
|
28
39
|
// Hooks run before the theme-part branch, so switching `kind` keeps the hook order (W-092).
|
|
29
40
|
const [seoOpen, setSeoOpen] = React.useState(false);
|
|
@@ -54,11 +65,24 @@ export function PageSettings({
|
|
|
54
65
|
onChange={(triggers) => onChange({ triggers })}
|
|
55
66
|
/>
|
|
56
67
|
)}
|
|
68
|
+
{page.partType === "float" && (
|
|
69
|
+
<FloatSettingsFields
|
|
70
|
+
settings={page.float ?? defaultFloatSettings()}
|
|
71
|
+
onChange={(float) => onChange({ float })}
|
|
72
|
+
/>
|
|
73
|
+
)}
|
|
57
74
|
</div>
|
|
58
75
|
);
|
|
59
76
|
}
|
|
60
77
|
|
|
61
|
-
const seoCount =
|
|
78
|
+
const seoCount = [
|
|
79
|
+
page.seoTitle,
|
|
80
|
+
page.seoDescription,
|
|
81
|
+
page.seoCanonical?.trim(),
|
|
82
|
+
page.seoNoIndex,
|
|
83
|
+
page.seoImage?.trim(),
|
|
84
|
+
].filter(Boolean).length;
|
|
85
|
+
const canonicalError = canonicalProblem(page.seoCanonical ?? "");
|
|
62
86
|
return (
|
|
63
87
|
<div className="emvb-panel-body" data-emvb-panel="page-settings">
|
|
64
88
|
<h2 className="emvb-panel-title">Page settings</h2>
|
|
@@ -119,8 +143,113 @@ export function PageSettings({
|
|
|
119
143
|
value={page.seoDescription}
|
|
120
144
|
onChange={(event) => onChange({ seoDescription: event.target.value })}
|
|
121
145
|
/>
|
|
146
|
+
{/* W-284: EmDash stores these; the public page prints them (W-274). */}
|
|
147
|
+
<Input
|
|
148
|
+
label="Canonical URL"
|
|
149
|
+
type="url"
|
|
150
|
+
className={FIELD}
|
|
151
|
+
maxLength={500}
|
|
152
|
+
value={page.seoCanonical ?? ""}
|
|
153
|
+
placeholder="https://"
|
|
154
|
+
error={canonicalError ?? undefined}
|
|
155
|
+
onChange={(event) => onChange({ seoCanonical: event.target.value })}
|
|
156
|
+
/>
|
|
157
|
+
<p className="emvb-helper">
|
|
158
|
+
Only if this page copies another one: the address search engines should list instead.
|
|
159
|
+
</p>
|
|
160
|
+
{fetcher && (
|
|
161
|
+
<div data-emvb-seo-image="">
|
|
162
|
+
{/* W-287: the Image element's picker on a stand-in node; only `src` is kept. */}
|
|
163
|
+
<MediaPicker
|
|
164
|
+
label="Social image"
|
|
165
|
+
node={
|
|
166
|
+
{
|
|
167
|
+
id: "seo-image",
|
|
168
|
+
type: "image",
|
|
169
|
+
props: { src: page.seoImage ?? "" },
|
|
170
|
+
} as LayoutNode
|
|
171
|
+
}
|
|
172
|
+
fetcher={fetcher}
|
|
173
|
+
onChange={(next) => {
|
|
174
|
+
const src = (next.props as { src?: unknown }).src;
|
|
175
|
+
onChange({ seoImage: typeof src === "string" ? src : "" });
|
|
176
|
+
}}
|
|
177
|
+
/>
|
|
178
|
+
<p className="emvb-helper">
|
|
179
|
+
Shown when the page is shared on social sites. 1200 × 630 px works best.
|
|
180
|
+
</p>
|
|
181
|
+
{page.seoImage?.trim() && (
|
|
182
|
+
<Button
|
|
183
|
+
type="button"
|
|
184
|
+
variant="secondary"
|
|
185
|
+
className={BUTTON}
|
|
186
|
+
onClick={() => onChange({ seoImage: "" })}
|
|
187
|
+
>
|
|
188
|
+
Remove social image
|
|
189
|
+
</Button>
|
|
190
|
+
)}
|
|
191
|
+
</div>
|
|
192
|
+
)}
|
|
193
|
+
<Switch
|
|
194
|
+
label="Hide from search engines"
|
|
195
|
+
checked={page.seoNoIndex === true}
|
|
196
|
+
onCheckedChange={(checked) => onChange({ seoNoIndex: checked === true })}
|
|
197
|
+
/>
|
|
198
|
+
<p className="emvb-helper" data-emvb-noindex-help="">
|
|
199
|
+
Search engines are asked not to list this page or follow its links (noindex, nofollow).
|
|
200
|
+
</p>
|
|
122
201
|
</Collapsible.Panel>
|
|
123
202
|
</Collapsible.Root>
|
|
124
203
|
</div>
|
|
125
204
|
);
|
|
126
205
|
}
|
|
206
|
+
|
|
207
|
+
const FLOAT_EDGE_LABELS: Record<FloatEdge, string> = {
|
|
208
|
+
top: "Top bar",
|
|
209
|
+
bottom: "Bottom bar",
|
|
210
|
+
"start-top": "Corner, top start",
|
|
211
|
+
"end-top": "Corner, top end",
|
|
212
|
+
"start-bottom": "Corner, bottom start",
|
|
213
|
+
"end-bottom": "Corner, bottom end",
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/** Edge and close button for a Float theme part. The layout itself is the bar or button. */
|
|
217
|
+
function FloatSettingsFields({
|
|
218
|
+
settings,
|
|
219
|
+
onChange,
|
|
220
|
+
}: {
|
|
221
|
+
settings: NonNullable<PageDraft["float"]>;
|
|
222
|
+
onChange: (settings: NonNullable<PageDraft["float"]>) => void;
|
|
223
|
+
}) {
|
|
224
|
+
return (
|
|
225
|
+
<div data-emvb-panel="float">
|
|
226
|
+
<Select
|
|
227
|
+
label="Place"
|
|
228
|
+
className={FIELD}
|
|
229
|
+
value={settings.edge}
|
|
230
|
+
onValueChange={(value) => {
|
|
231
|
+
const edge = FLOAT_EDGES.find((item) => item === value);
|
|
232
|
+
if (edge) onChange({ ...settings, edge });
|
|
233
|
+
}}
|
|
234
|
+
renderValue={(value: unknown) => FLOAT_EDGE_LABELS[value as FloatEdge] ?? String(value)}
|
|
235
|
+
>
|
|
236
|
+
{FLOAT_EDGES.map((edge) => (
|
|
237
|
+
<Select.Option key={edge} value={edge}>
|
|
238
|
+
{FLOAT_EDGE_LABELS[edge]}
|
|
239
|
+
</Select.Option>
|
|
240
|
+
))}
|
|
241
|
+
</Select>
|
|
242
|
+
<p className="emvb-helper">
|
|
243
|
+
A bar stays on that edge and leaves room for the page. A corner sits over the page.
|
|
244
|
+
</p>
|
|
245
|
+
<Switch
|
|
246
|
+
label="Close button"
|
|
247
|
+
checked={settings.dismiss}
|
|
248
|
+
onCheckedChange={(checked) => onChange({ ...settings, dismiss: checked === true })}
|
|
249
|
+
/>
|
|
250
|
+
<p className="emvb-helper">
|
|
251
|
+
Closing hides it until the next visit. Nothing is stored in a cookie.
|
|
252
|
+
</p>
|
|
253
|
+
</div>
|
|
254
|
+
);
|
|
255
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type * as React from "react";
|
|
2
|
+
import type { Deletion } from "../restore-deleted.ts";
|
|
2
3
|
import type { DesignSystem, LayoutNode, PopupDevice } from "../../../core/index.ts";
|
|
3
4
|
import type { Fetcher } from "../../api.ts";
|
|
4
5
|
import type { EditorAction, EditorState } from "../store.ts";
|
|
5
6
|
import { ElementPanel } from "./ElementPanel.tsx";
|
|
7
|
+
import type { ItemActions } from "./settings/ItemList.tsx";
|
|
6
8
|
import type { StyleStateChoice } from "./settings/StateSwitcher.tsx";
|
|
7
9
|
import { PageSettings } from "./PageSettings.tsx";
|
|
8
10
|
import { SiteStylesDrawer } from "./SiteStylesDrawer.tsx";
|
|
@@ -17,6 +19,7 @@ export function SettingsPanel({
|
|
|
17
19
|
onCloseSiteStyles,
|
|
18
20
|
onDesignChange,
|
|
19
21
|
onPublishStyles,
|
|
22
|
+
onDesignItemDeleted,
|
|
20
23
|
fetcher,
|
|
21
24
|
formsAvailable,
|
|
22
25
|
rejection,
|
|
@@ -25,6 +28,7 @@ export function SettingsPanel({
|
|
|
25
28
|
kind,
|
|
26
29
|
onStyleState,
|
|
27
30
|
device = "desktop",
|
|
31
|
+
items,
|
|
28
32
|
}: {
|
|
29
33
|
state: EditorState;
|
|
30
34
|
latest: React.RefObject<EditorState>;
|
|
@@ -34,6 +38,8 @@ export function SettingsPanel({
|
|
|
34
38
|
onCloseSiteStyles: () => void;
|
|
35
39
|
onDesignChange: (design: DesignSystem) => Promise<void>;
|
|
36
40
|
onPublishStyles: () => Promise<void>;
|
|
41
|
+
/** W-252: a variable or class deleted from Site styles, so undo can put it back. */
|
|
42
|
+
onDesignItemDeleted?: (deletion: Deletion) => void;
|
|
37
43
|
fetcher: Fetcher;
|
|
38
44
|
formsAvailable: boolean;
|
|
39
45
|
rejection: string | null;
|
|
@@ -44,6 +50,8 @@ export function SettingsPanel({
|
|
|
44
50
|
onStyleState?: (nodeId: string, state: StyleStateChoice) => void;
|
|
45
51
|
/** Which device's styles the Style tab edits (W-096). */
|
|
46
52
|
device?: PopupDevice;
|
|
53
|
+
/** Accordion and Tabs item actions (W-130). */
|
|
54
|
+
items?: ItemActions;
|
|
47
55
|
}) {
|
|
48
56
|
return (
|
|
49
57
|
<aside
|
|
@@ -59,6 +67,7 @@ export function SettingsPanel({
|
|
|
59
67
|
onDesignChange={onDesignChange}
|
|
60
68
|
unpublished={state.designUnpublished === true}
|
|
61
69
|
onPublishStyles={onPublishStyles}
|
|
70
|
+
{...(onDesignItemDeleted ? { onDeleted: onDesignItemDeleted } : {})}
|
|
62
71
|
onLayoutChange={(layout) =>
|
|
63
72
|
dispatch({
|
|
64
73
|
type: "apply-arranged",
|
|
@@ -84,12 +93,15 @@ export function SettingsPanel({
|
|
|
84
93
|
onSelect={(id) => dispatch({ type: "select", id })}
|
|
85
94
|
onStyleState={onStyleState}
|
|
86
95
|
device={device}
|
|
96
|
+
items={items}
|
|
97
|
+
partType={state.page.partType}
|
|
87
98
|
/>
|
|
88
99
|
) : (
|
|
89
100
|
<PageSettings
|
|
90
101
|
page={state.page}
|
|
91
102
|
slugError={slugError}
|
|
92
103
|
kind={kind}
|
|
104
|
+
fetcher={fetcher}
|
|
93
105
|
onChange={(patch) => {
|
|
94
106
|
if (patch.slug !== undefined) onSlugEdit();
|
|
95
107
|
dispatch({ type: "set-page", patch });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Button, Select, Tabs } from "@cloudflare/kumo";
|
|
2
|
+
import { deletionOf, type Deletion } from "../restore-deleted.ts";
|
|
2
3
|
import { WarningCircleIcon, XIcon } from "@phosphor-icons/react";
|
|
3
4
|
import * as React from "react";
|
|
4
5
|
import {
|
|
@@ -9,6 +10,9 @@ import {
|
|
|
9
10
|
findClassUsages,
|
|
10
11
|
findVariableUsages,
|
|
11
12
|
findVariableUsagesInDesign,
|
|
13
|
+
importLosses,
|
|
14
|
+
type ImportRename,
|
|
15
|
+
MAX_DESIGN_FILE_BYTES,
|
|
12
16
|
removeVariable,
|
|
13
17
|
DEFAULT_STYLE_TAGS,
|
|
14
18
|
type DefaultStyleTag,
|
|
@@ -33,6 +37,8 @@ type Props = {
|
|
|
33
37
|
unpublished?: boolean;
|
|
34
38
|
onPublishStyles?: () => Promise<void>;
|
|
35
39
|
onLayoutChange: (layout: Layout) => void;
|
|
40
|
+
/** W-252: called with what a delete removes, before the page loses its uses. */
|
|
41
|
+
onDeleted?: (deletion: Deletion) => void;
|
|
36
42
|
onClose: () => void;
|
|
37
43
|
};
|
|
38
44
|
|
|
@@ -66,6 +72,7 @@ export function SiteStylesDrawer({
|
|
|
66
72
|
unpublished = false,
|
|
67
73
|
onPublishStyles,
|
|
68
74
|
onLayoutChange,
|
|
75
|
+
onDeleted,
|
|
69
76
|
onClose,
|
|
70
77
|
}: Props) {
|
|
71
78
|
const [tab, setTab] = React.useState<"variables" | "classes" | "defaults">("variables");
|
|
@@ -76,6 +83,11 @@ export function SiteStylesDrawer({
|
|
|
76
83
|
| null
|
|
77
84
|
>(null);
|
|
78
85
|
const fileRef = React.useRef<HTMLInputElement>(null);
|
|
86
|
+
const [pendingImport, setPendingImport] = React.useState<{
|
|
87
|
+
name: string;
|
|
88
|
+
design: DesignSystem;
|
|
89
|
+
renamed: ImportRename[];
|
|
90
|
+
} | null>(null);
|
|
79
91
|
|
|
80
92
|
const save = async (next: DesignSystem) => {
|
|
81
93
|
setError(null);
|
|
@@ -96,15 +108,21 @@ export function SiteStylesDrawer({
|
|
|
96
108
|
}
|
|
97
109
|
};
|
|
98
110
|
|
|
111
|
+
// W-214: Import replaces every class and variable, so it reads a sane size and asks first.
|
|
99
112
|
const importDesign = async (file: File) => {
|
|
100
113
|
setError(null);
|
|
114
|
+
setPendingImport(null);
|
|
115
|
+
if (file.size > MAX_DESIGN_FILE_BYTES) {
|
|
116
|
+
setError("That file is too big to be an EmVB design (over 1 MB).");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
101
119
|
const text = await file.text();
|
|
102
120
|
const result = designFromJson(text);
|
|
103
121
|
if (!result.ok) {
|
|
104
122
|
setError(result.message);
|
|
105
123
|
return;
|
|
106
124
|
}
|
|
107
|
-
|
|
125
|
+
setPendingImport({ name: file.name, design: result.design, renamed: result.renamed });
|
|
108
126
|
};
|
|
109
127
|
|
|
110
128
|
return (
|
|
@@ -240,10 +258,24 @@ export function SiteStylesDrawer({
|
|
|
240
258
|
)}
|
|
241
259
|
{tab === "defaults" && (
|
|
242
260
|
<div data-emvb-site-tab="defaults" className="emvb-site-styles-body">
|
|
261
|
+
<DirectionSelect design={design} onSave={save} />
|
|
243
262
|
<DefaultsSection design={design} onSave={save} />
|
|
244
263
|
</div>
|
|
245
264
|
)}
|
|
246
265
|
<p className="emvb-helper emvb-site-styles-footer">{STYLE_NOTE}</p>
|
|
266
|
+
{pendingImport && (
|
|
267
|
+
<ImportConfirm
|
|
268
|
+
name={pendingImport.name}
|
|
269
|
+
renamed={pendingImport.renamed}
|
|
270
|
+
losses={importLosses(design, pendingImport.design, layout)}
|
|
271
|
+
onCancel={() => setPendingImport(null)}
|
|
272
|
+
onConfirm={async () => {
|
|
273
|
+
const next = pendingImport.design;
|
|
274
|
+
setPendingImport(null);
|
|
275
|
+
await save(next);
|
|
276
|
+
}}
|
|
277
|
+
/>
|
|
278
|
+
)}
|
|
247
279
|
{confirm && (
|
|
248
280
|
<DeleteConfirm
|
|
249
281
|
confirm={confirm}
|
|
@@ -251,6 +283,16 @@ export function SiteStylesDrawer({
|
|
|
251
283
|
layout={layout}
|
|
252
284
|
onCancel={() => setConfirm(null)}
|
|
253
285
|
onConfirm={async () => {
|
|
286
|
+
if (layout) {
|
|
287
|
+
const deletion = deletionOf(
|
|
288
|
+
design,
|
|
289
|
+
layout,
|
|
290
|
+
confirm.kind === "variable"
|
|
291
|
+
? { kind: "variable", id: confirm.id, variableKind: confirm.variableKind }
|
|
292
|
+
: { kind: "class", id: confirm.id },
|
|
293
|
+
);
|
|
294
|
+
if (deletion) onDeleted?.(deletion);
|
|
295
|
+
}
|
|
254
296
|
if (confirm.kind === "variable") {
|
|
255
297
|
if (layout) {
|
|
256
298
|
const result = deleteVariable(design, layout, confirm.id, confirm.variableKind);
|
|
@@ -274,6 +316,13 @@ export function SiteStylesDrawer({
|
|
|
274
316
|
|
|
275
317
|
const plural = (n: number, one: string, many: string) => `${n} ${n === 1 ? one : many}`;
|
|
276
318
|
|
|
319
|
+
/**
|
|
320
|
+
* W-251: only this page and the design are checked; other pages and theme parts that use the
|
|
321
|
+
* class or variable lose that styling, so the dialog says so instead of implying it is unused.
|
|
322
|
+
*/
|
|
323
|
+
const NOT_CHECKED =
|
|
324
|
+
"Other pages and theme parts aren't checked; any that use it lose that styling.";
|
|
325
|
+
|
|
277
326
|
/** "2 places on this page and 1 class", or null when nothing uses it. */
|
|
278
327
|
function usedIn(pageUses: number, classUses: number): string | null {
|
|
279
328
|
const parts = [
|
|
@@ -318,7 +367,8 @@ function DeleteConfirm({
|
|
|
318
367
|
? `In use in ${where}. Deleting drops those bindings.`
|
|
319
368
|
: variable
|
|
320
369
|
? "Not used on this page or by any class."
|
|
321
|
-
: "Not used on this page."}
|
|
370
|
+
: "Not used on this page."}{" "}
|
|
371
|
+
{NOT_CHECKED}
|
|
322
372
|
</p>
|
|
323
373
|
<div className="emvb-dialog-actions">
|
|
324
374
|
<Button type="button" variant="secondary" className={BUTTON} onClick={onCancel}>
|
|
@@ -390,3 +440,109 @@ function DefaultsSection({
|
|
|
390
440
|
</>
|
|
391
441
|
);
|
|
392
442
|
}
|
|
443
|
+
|
|
444
|
+
/** W-214: confirms an Import, which replaces the whole design (there is no revision history). */
|
|
445
|
+
/** W-283: how many renamed names the Import confirm lists before "and N more". */
|
|
446
|
+
const MAX_RENAMES_LISTED = 5;
|
|
447
|
+
|
|
448
|
+
function ImportConfirm({
|
|
449
|
+
name,
|
|
450
|
+
renamed,
|
|
451
|
+
losses,
|
|
452
|
+
onCancel,
|
|
453
|
+
onConfirm,
|
|
454
|
+
}: {
|
|
455
|
+
name: string;
|
|
456
|
+
renamed: ImportRename[];
|
|
457
|
+
losses: ReturnType<typeof importLosses>;
|
|
458
|
+
onCancel: () => void;
|
|
459
|
+
onConfirm: () => void;
|
|
460
|
+
}) {
|
|
461
|
+
const lost = [
|
|
462
|
+
losses.classes > 0 ? plural(losses.classes, "class", "classes") : "",
|
|
463
|
+
losses.variables > 0 ? plural(losses.variables, "variable", "variables") : "",
|
|
464
|
+
].filter(Boolean);
|
|
465
|
+
return (
|
|
466
|
+
<div className="emvb-site-confirm" data-emvb-import-confirm="" role="alertdialog">
|
|
467
|
+
<p className="emvb-field-label">Replace site styles with {name}?</p>
|
|
468
|
+
<p className="emvb-helper">
|
|
469
|
+
{lost.length > 0
|
|
470
|
+
? `${lost.join(" and ")} that the file doesn't have will be removed. `
|
|
471
|
+
: "Every class and variable is replaced by the file's. "}
|
|
472
|
+
{losses.usedOnPage > 0 &&
|
|
473
|
+
`This page uses ${losses.usedOnPage} of them, so those elements lose that styling. `}
|
|
474
|
+
Export first to keep a copy.
|
|
475
|
+
</p>
|
|
476
|
+
{renamed.length > 0 && (
|
|
477
|
+
<p className="emvb-helper" data-emvb-import-renamed="">
|
|
478
|
+
{`The file repeats some names, so ${renamed.length === 1 ? "one is" : "these are"} renamed: `}
|
|
479
|
+
{renamed
|
|
480
|
+
.slice(0, MAX_RENAMES_LISTED)
|
|
481
|
+
.map((r) => `${r.from} → ${r.to}`)
|
|
482
|
+
.join(", ")}
|
|
483
|
+
{renamed.length > MAX_RENAMES_LISTED
|
|
484
|
+
? ` and ${renamed.length - MAX_RENAMES_LISTED} more.`
|
|
485
|
+
: "."}
|
|
486
|
+
</p>
|
|
487
|
+
)}
|
|
488
|
+
<div className="emvb-dialog-actions">
|
|
489
|
+
<Button type="button" variant="secondary" className={BUTTON} onClick={onCancel}>
|
|
490
|
+
Cancel
|
|
491
|
+
</Button>
|
|
492
|
+
<Button
|
|
493
|
+
type="button"
|
|
494
|
+
variant="destructive"
|
|
495
|
+
className={BUTTON}
|
|
496
|
+
style={SOLID_DESTRUCTIVE}
|
|
497
|
+
onClick={onConfirm}
|
|
498
|
+
>
|
|
499
|
+
Replace
|
|
500
|
+
</Button>
|
|
501
|
+
</div>
|
|
502
|
+
</div>
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const DIRECTIONS = [
|
|
507
|
+
{ value: "ltr", label: "Left to right" },
|
|
508
|
+
{ value: "rtl", label: "Right to left" },
|
|
509
|
+
{ value: "auto", label: "From the content" },
|
|
510
|
+
] as const;
|
|
511
|
+
|
|
512
|
+
/** Site text direction (W-230): `dir` on every EmVB root and the host's `<html>`. */
|
|
513
|
+
function DirectionSelect({
|
|
514
|
+
design,
|
|
515
|
+
onSave,
|
|
516
|
+
}: {
|
|
517
|
+
design: DesignSystem;
|
|
518
|
+
onSave: (next: DesignSystem) => Promise<unknown> | void;
|
|
519
|
+
}) {
|
|
520
|
+
return (
|
|
521
|
+
<div data-emvb-site-direction="">
|
|
522
|
+
<Select
|
|
523
|
+
label="Text direction"
|
|
524
|
+
className={FIELD}
|
|
525
|
+
value={design.direction ?? "ltr"}
|
|
526
|
+
renderValue={(v: unknown) =>
|
|
527
|
+
DIRECTIONS.find((item) => item.value === String(v))?.label ?? String(v)
|
|
528
|
+
}
|
|
529
|
+
onValueChange={(value) => {
|
|
530
|
+
const { direction: _old, ...rest } = design;
|
|
531
|
+
// Left to right is the default, so it is stored as no setting.
|
|
532
|
+
const next: DesignSystem =
|
|
533
|
+
value === "rtl" || value === "auto" ? { ...rest, direction: value } : rest;
|
|
534
|
+
if ((next.direction ?? "ltr") !== (design.direction ?? "ltr")) void onSave(next);
|
|
535
|
+
}}
|
|
536
|
+
>
|
|
537
|
+
{DIRECTIONS.map((item) => (
|
|
538
|
+
<Select.Option key={item.value} value={item.value}>
|
|
539
|
+
{item.label}
|
|
540
|
+
</Select.Option>
|
|
541
|
+
))}
|
|
542
|
+
</Select>
|
|
543
|
+
<p className="emvb-helper">
|
|
544
|
+
Right to left mirrors the layout for Arabic, Hebrew and other right-to-left sites.
|
|
545
|
+
</p>
|
|
546
|
+
</div>
|
|
547
|
+
);
|
|
548
|
+
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Button, Input, Select } from "@cloudflare/kumo";
|
|
2
2
|
import { PlusIcon, TrashIcon } from "@phosphor-icons/react";
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
defaultTriggers,
|
|
6
|
+
MAX_POPUP_TRIGGERS,
|
|
7
|
+
type PopupOpenTrigger,
|
|
8
|
+
type TriggersDoc,
|
|
9
|
+
} from "../../../core/index.ts";
|
|
5
10
|
import { BUTTON, FIELD } from "../../ui.ts";
|
|
6
11
|
import { TriggerSettings } from "./TriggerSettings.tsx";
|
|
7
12
|
|
|
@@ -92,6 +97,9 @@ export function TriggersEditor({ triggers, onChange }: Props) {
|
|
|
92
97
|
const advanced = doc.advanced ?? {};
|
|
93
98
|
/** Removing the only On page load trigger would only put it back, so it can't be removed. */
|
|
94
99
|
const onlyDefault = doc.open.length === 1 && doc.open[0]?.type === "page_load";
|
|
100
|
+
/** W-280: a popup saves with at most this many triggers; one more would make the save fail. */
|
|
101
|
+
const full = doc.open.length >= MAX_POPUP_TRIGGERS;
|
|
102
|
+
const fullReason = `${MAX_POPUP_TRIGGERS} triggers is the most one popup can have. Remove one to add another.`;
|
|
95
103
|
|
|
96
104
|
return (
|
|
97
105
|
<div className="emvb-triggers" data-emvb-panel="triggers">
|
|
@@ -142,10 +150,19 @@ export function TriggersEditor({ triggers, onChange }: Props) {
|
|
|
142
150
|
variant="secondary"
|
|
143
151
|
className={BUTTON}
|
|
144
152
|
icon={<PlusIcon aria-hidden="true" />}
|
|
145
|
-
|
|
153
|
+
disabled={full}
|
|
154
|
+
title={full ? fullReason : undefined}
|
|
155
|
+
onClick={() => {
|
|
156
|
+
if (!full) setOpen([...doc.open, blankTrigger("page_load")]);
|
|
157
|
+
}}
|
|
146
158
|
>
|
|
147
159
|
Add trigger
|
|
148
160
|
</Button>
|
|
161
|
+
{full && (
|
|
162
|
+
<p className="emvb-helper" data-emvb-triggers-full="">
|
|
163
|
+
{fullReason}
|
|
164
|
+
</p>
|
|
165
|
+
)}
|
|
149
166
|
|
|
150
167
|
<h3 className="emvb-section-label">Advanced</h3>
|
|
151
168
|
<p className="emvb-helper">Limit how often the popup shows, and on which devices.</p>
|
|
@@ -14,10 +14,14 @@ import {
|
|
|
14
14
|
} from "@phosphor-icons/react";
|
|
15
15
|
import * as React from "react";
|
|
16
16
|
import {
|
|
17
|
+
cleanClassName,
|
|
17
18
|
duplicateVariable,
|
|
19
|
+
variableListFull,
|
|
18
20
|
findVariableUsages,
|
|
19
21
|
findVariableUsagesInDesign,
|
|
20
22
|
renameVariable,
|
|
23
|
+
variableNameTaken,
|
|
24
|
+
variableNameTakenMessage,
|
|
21
25
|
type DesignSystem,
|
|
22
26
|
type Layout,
|
|
23
27
|
type VariableKind,
|
|
@@ -218,6 +222,12 @@ function ValueEditor({
|
|
|
218
222
|
);
|
|
219
223
|
}
|
|
220
224
|
|
|
225
|
+
/** "2 on page", and the classes that use it too: "2 on page · 1 class" (W-150). */
|
|
226
|
+
const usageText = (onPage: number, inClasses: number) =>
|
|
227
|
+
inClasses
|
|
228
|
+
? `${onPage} on page · ${inClasses} ${inClasses === 1 ? "class" : "classes"}`
|
|
229
|
+
: `${onPage} on page`;
|
|
230
|
+
|
|
221
231
|
export function VariableSection({
|
|
222
232
|
title,
|
|
223
233
|
kind,
|
|
@@ -239,7 +249,12 @@ export function VariableSection({
|
|
|
239
249
|
const [filter, setFilter] = React.useState("");
|
|
240
250
|
const [name, setName] = React.useState("");
|
|
241
251
|
const [value, setValue] = React.useState(NEW_VALUE[kind]);
|
|
242
|
-
|
|
252
|
+
// W-281: a name clash and a bad value are told apart, so only the field at fault is invalid.
|
|
253
|
+
const [createError, setCreateError] = React.useState<{
|
|
254
|
+
field: "name" | "value";
|
|
255
|
+
message: string;
|
|
256
|
+
} | null>(null);
|
|
257
|
+
const [nameError, setNameError] = React.useState<string | null>(null);
|
|
243
258
|
const [open, setOpen] = React.useState<string | null>(null);
|
|
244
259
|
const [renaming, setRenaming] = React.useState<string | null>(null);
|
|
245
260
|
const [copied, setCopied] = React.useState<string | null>(null);
|
|
@@ -262,11 +277,15 @@ export function VariableSection({
|
|
|
262
277
|
: items;
|
|
263
278
|
|
|
264
279
|
const create = async () => {
|
|
265
|
-
const trimmed = name
|
|
266
|
-
if (!trimmed) return;
|
|
280
|
+
const trimmed = cleanClassName(name);
|
|
281
|
+
if (!trimmed || variableListFull(design, kind)) return;
|
|
282
|
+
if (variableNameTaken(design, kind, trimmed)) {
|
|
283
|
+
setCreateError({ field: "name", message: variableNameTakenMessage(trimmed) });
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
267
286
|
const parsed = parseValue(kind, value);
|
|
268
287
|
if (!parsed.ok) {
|
|
269
|
-
setCreateError(parsed.error);
|
|
288
|
+
setCreateError({ field: "value", message: parsed.error });
|
|
270
289
|
return;
|
|
271
290
|
}
|
|
272
291
|
const id = uniqueId(
|
|
@@ -284,6 +303,11 @@ export function VariableSection({
|
|
|
284
303
|
const rename = (id: string, next: string | null) => {
|
|
285
304
|
setRenaming(null);
|
|
286
305
|
requestAnimationFrame(() => rows.current.get(id)?.focus());
|
|
306
|
+
if (next && variableNameTaken(design, kind, next, id)) {
|
|
307
|
+
setNameError(variableNameTakenMessage(next));
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
setNameError(null);
|
|
287
311
|
if (next) void onSave(renameVariable(design, id, kind, next));
|
|
288
312
|
};
|
|
289
313
|
|
|
@@ -305,6 +329,7 @@ export function VariableSection({
|
|
|
305
329
|
count={items.length}
|
|
306
330
|
countProps={{ "data-emvb-var-count": "" }}
|
|
307
331
|
onNew={() => setCreating(true)}
|
|
332
|
+
newDisabled={variableListFull(design, kind)}
|
|
308
333
|
/>
|
|
309
334
|
{items.length > 3 && (
|
|
310
335
|
<SiteSearch
|
|
@@ -410,7 +435,7 @@ export function VariableSection({
|
|
|
410
435
|
data-emvb-usage=""
|
|
411
436
|
aria-live="polite"
|
|
412
437
|
>
|
|
413
|
-
{copied === item.id ? "Copied" :
|
|
438
|
+
{copied === item.id ? "Copied" : usageText(onPage, inClasses)}
|
|
414
439
|
</span>
|
|
415
440
|
<RowMenu
|
|
416
441
|
label={`Actions for ${item.name}`}
|
|
@@ -429,7 +454,10 @@ export function VariableSection({
|
|
|
429
454
|
{
|
|
430
455
|
label: "Duplicate",
|
|
431
456
|
icon: CopySimpleIcon,
|
|
432
|
-
onSelect: () =>
|
|
457
|
+
onSelect: () => {
|
|
458
|
+
const next = duplicateVariable(design, item.id, kind);
|
|
459
|
+
if (next !== design) void onSave(next);
|
|
460
|
+
},
|
|
433
461
|
},
|
|
434
462
|
{
|
|
435
463
|
label: "Copy CSS variable",
|
|
@@ -458,6 +486,11 @@ export function VariableSection({
|
|
|
458
486
|
);
|
|
459
487
|
})}
|
|
460
488
|
</ul>
|
|
489
|
+
{nameError && (
|
|
490
|
+
<div data-emvb-var-name-error="">
|
|
491
|
+
<InlineError>{nameError}</InlineError>
|
|
492
|
+
</div>
|
|
493
|
+
)}
|
|
461
494
|
{creating && (
|
|
462
495
|
<CreateRow
|
|
463
496
|
rowProps={{ "data-emvb-var-create": kind }}
|
|
@@ -472,19 +505,24 @@ export function VariableSection({
|
|
|
472
505
|
label="Name"
|
|
473
506
|
className={FIELD}
|
|
474
507
|
value={name}
|
|
475
|
-
|
|
508
|
+
aria-invalid={createError?.field === "name" ? true : undefined}
|
|
509
|
+
onChange={(e) => {
|
|
510
|
+
setName(e.target.value);
|
|
511
|
+
setCreateError(null);
|
|
512
|
+
}}
|
|
476
513
|
/>
|
|
514
|
+
{createError?.field === "name" && <InlineError>{createError.message}</InlineError>}
|
|
477
515
|
<Input
|
|
478
516
|
label={isLengthKind(kind) ? "Value (px, rem, em or %)" : "Value"}
|
|
479
517
|
className={FIELD}
|
|
480
518
|
value={value}
|
|
481
|
-
aria-invalid={createError ? true : undefined}
|
|
519
|
+
aria-invalid={createError?.field === "value" ? true : undefined}
|
|
482
520
|
onChange={(e) => {
|
|
483
521
|
setValue(e.target.value);
|
|
484
522
|
setCreateError(null);
|
|
485
523
|
}}
|
|
486
524
|
/>
|
|
487
|
-
{createError && <InlineError>{createError}</InlineError>}
|
|
525
|
+
{createError?.field === "value" && <InlineError>{createError.message}</InlineError>}
|
|
488
526
|
</CreateRow>
|
|
489
527
|
)}
|
|
490
528
|
</section>
|