@perkyzz/emvb 0.1.0 → 0.2.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 +4 -2
- 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 +8 -4
- 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 +23 -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 +164 -20
- package/src/astro/tabs/runtime.ts +6 -1
- package/src/astro/theme-context.ts +11 -3
- 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
|
@@ -23,11 +23,13 @@ export function SectionHead({
|
|
|
23
23
|
count,
|
|
24
24
|
countProps,
|
|
25
25
|
onNew,
|
|
26
|
+
newDisabled,
|
|
26
27
|
}: {
|
|
27
28
|
title: React.ReactNode;
|
|
28
29
|
count: number;
|
|
29
30
|
countProps?: Record<string, string>;
|
|
30
31
|
onNew: () => void;
|
|
32
|
+
newDisabled?: boolean;
|
|
31
33
|
}) {
|
|
32
34
|
return (
|
|
33
35
|
<div className="emvb-site-section-head">
|
|
@@ -44,6 +46,7 @@ export function SectionHead({
|
|
|
44
46
|
className={BUTTON}
|
|
45
47
|
icon={<PlusIcon aria-hidden="true" />}
|
|
46
48
|
onClick={onNew}
|
|
49
|
+
disabled={newDisabled}
|
|
47
50
|
>
|
|
48
51
|
New
|
|
49
52
|
</Button>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { DesignSystem, Layout, VariableKind } from "../../core/index.ts";
|
|
2
|
+
|
|
3
|
+
type Variables = DesignSystem["variables"];
|
|
4
|
+
type ListKey = keyof Variables;
|
|
5
|
+
type StyleClass = NonNullable<DesignSystem["classes"]>[number];
|
|
6
|
+
type AnyVariable = NonNullable<Variables[ListKey]>[number];
|
|
7
|
+
|
|
8
|
+
const LIST: Record<VariableKind, ListKey> = {
|
|
9
|
+
color: "colors",
|
|
10
|
+
font: "fonts",
|
|
11
|
+
fontSize: "fontSizes",
|
|
12
|
+
spacing: "spacings",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** A variable or class deleted from Site styles, where it stood, and the page just before. */
|
|
16
|
+
export type Deletion = {
|
|
17
|
+
before: Layout;
|
|
18
|
+
index: number;
|
|
19
|
+
} & (
|
|
20
|
+
| { kind: "variable"; variableKind: VariableKind; variable: AnyVariable }
|
|
21
|
+
| { kind: "class"; cls: StyleClass }
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/** The deletion of `id` from `design`, or undefined when the design doesn't have it. */
|
|
25
|
+
export function deletionOf(
|
|
26
|
+
design: DesignSystem,
|
|
27
|
+
before: Layout,
|
|
28
|
+
target:
|
|
29
|
+
| { kind: "variable"; id: string; variableKind: VariableKind }
|
|
30
|
+
| { kind: "class"; id: string },
|
|
31
|
+
): Deletion | undefined {
|
|
32
|
+
if (target.kind === "class") {
|
|
33
|
+
const classes = design.classes ?? [];
|
|
34
|
+
const index = classes.findIndex((c) => c.id === target.id);
|
|
35
|
+
const cls = classes[index];
|
|
36
|
+
return cls ? { kind: "class", cls, index, before } : undefined;
|
|
37
|
+
}
|
|
38
|
+
const list: readonly AnyVariable[] = design.variables[LIST[target.variableKind]] ?? [];
|
|
39
|
+
const index = list.findIndex((v) => v.id === target.id);
|
|
40
|
+
const variable = list[index];
|
|
41
|
+
return variable
|
|
42
|
+
? { kind: "variable", variableKind: target.variableKind, variable, index, before }
|
|
43
|
+
: undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* W-252: Site styles changes aren't undo steps, but deleting a variable or class also clears its
|
|
48
|
+
* uses on the page, which is one. Undoing that brought the uses back with nothing defining them.
|
|
49
|
+
* When the page is again exactly the one from before a deletion (undo restores that object), the
|
|
50
|
+
* deleted items go back into the design where they were. Null when nothing needs restoring.
|
|
51
|
+
*/
|
|
52
|
+
export function restoreOnUndo(
|
|
53
|
+
design: DesignSystem,
|
|
54
|
+
layout: Layout,
|
|
55
|
+
deletions: readonly Deletion[],
|
|
56
|
+
): DesignSystem | null {
|
|
57
|
+
const classes = [...(design.classes ?? [])];
|
|
58
|
+
const variables: Partial<Record<ListKey, AnyVariable[]>> = {};
|
|
59
|
+
let classRestored = false;
|
|
60
|
+
for (const deletion of deletions) {
|
|
61
|
+
if (deletion.before !== layout) continue;
|
|
62
|
+
if (deletion.kind === "class") {
|
|
63
|
+
if (classes.some((c) => c.id === deletion.cls.id)) continue;
|
|
64
|
+
classes.splice(Math.min(deletion.index, classes.length), 0, deletion.cls);
|
|
65
|
+
classRestored = true;
|
|
66
|
+
} else {
|
|
67
|
+
const key = LIST[deletion.variableKind];
|
|
68
|
+
const list = variables[key] ?? [...(design.variables[key] ?? [])];
|
|
69
|
+
if (list.some((v) => v.id === deletion.variable.id)) continue;
|
|
70
|
+
list.splice(Math.min(deletion.index, list.length), 0, deletion.variable);
|
|
71
|
+
variables[key] = list;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (!classRestored && Object.keys(variables).length === 0) return null;
|
|
75
|
+
return {
|
|
76
|
+
...design,
|
|
77
|
+
...(classRestored ? { classes } : {}),
|
|
78
|
+
variables: { ...design.variables, ...variables } as Variables,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** The editor's keyboard shortcuts
|
|
1
|
+
/** The editor's keyboard shortcuts, shown in the Shortcuts dialog. */
|
|
2
2
|
export const SHORTCUTS: readonly { action: string; keys: string }[] = [
|
|
3
3
|
{ action: "Move focus between regions", keys: "Tab / Shift+Tab" },
|
|
4
4
|
{ action: "Next or previous element", keys: "↑ / ↓" },
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type Removed,
|
|
15
15
|
LAYOUT_SCHEMA_VERSION,
|
|
16
16
|
} from "../../core/index.ts";
|
|
17
|
+
import { withPageHeadingLevel } from "./dnd/new-element.ts";
|
|
17
18
|
import type { PageDraft } from "../content-api.ts";
|
|
18
19
|
|
|
19
20
|
/** Editor state (A-07): a pure reducer, so every edit is testable without a browser. */
|
|
@@ -32,6 +33,11 @@ export type EditorState = {
|
|
|
32
33
|
/** Bumped on every page edit. A save only clears `dirty` if nothing changed while it ran. */
|
|
33
34
|
version: number;
|
|
34
35
|
savedVersion: number;
|
|
36
|
+
/**
|
|
37
|
+
* The highest version handed out so far. Undo restores an older `version`, so the next edit
|
|
38
|
+
* numbers from here; reusing a number could match `savedVersion` with unsaved content (W-255).
|
|
39
|
+
*/
|
|
40
|
+
lastVersion?: number;
|
|
35
41
|
/** The most recent delete, for the one-step Restore toast (D-025). */
|
|
36
42
|
lastDeleted: Removed | null;
|
|
37
43
|
};
|
|
@@ -52,15 +58,22 @@ export type EditorAction =
|
|
|
52
58
|
| { type: "published"; rev: string }
|
|
53
59
|
| { type: "set-design"; design: DesignSystem; revision: string | null }
|
|
54
60
|
| { type: "publish-design"; revision: string }
|
|
61
|
+
/** The site styles as saved elsewhere, after a refused save (W-212). */
|
|
62
|
+
| {
|
|
63
|
+
type: "load-design";
|
|
64
|
+
design: DesignSystem;
|
|
65
|
+
revision: string | null;
|
|
66
|
+
publishedRevision: string | null;
|
|
67
|
+
unpublished: boolean;
|
|
68
|
+
}
|
|
55
69
|
| { type: "reset"; state: EditorState };
|
|
56
70
|
|
|
57
71
|
export const isDirty = (state: EditorState) => state.version !== state.savedVersion;
|
|
58
72
|
|
|
59
|
-
const edited = (state: EditorState, page: PageDraft): EditorState =>
|
|
60
|
-
|
|
61
|
-
page,
|
|
62
|
-
|
|
63
|
-
});
|
|
73
|
+
const edited = (state: EditorState, page: PageDraft): EditorState => {
|
|
74
|
+
const version = Math.max(state.version, state.lastVersion ?? 0) + 1;
|
|
75
|
+
return { ...state, page, version, lastVersion: version };
|
|
76
|
+
};
|
|
64
77
|
|
|
65
78
|
/** A layout edit that also moves the selection. */
|
|
66
79
|
const withLayout = (
|
|
@@ -186,7 +199,8 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
186
199
|
case "add-node": {
|
|
187
200
|
if (!state.page.layout) return state;
|
|
188
201
|
const place = { parentId: action.parentId, index: action.index };
|
|
189
|
-
|
|
202
|
+
const node = withPageHeadingLevel(action.node, state.page.layout);
|
|
203
|
+
return arranged(state, addNode(state.page.layout, node, place));
|
|
190
204
|
}
|
|
191
205
|
case "move-node":
|
|
192
206
|
if (!state.page.layout) return state;
|
|
@@ -194,7 +208,13 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
194
208
|
case "apply-arranged":
|
|
195
209
|
return withLayout(state, action.layout, action.selected);
|
|
196
210
|
case "saved":
|
|
197
|
-
|
|
211
|
+
// A saved draft on a published entry is not live until Publish (W-190).
|
|
212
|
+
return {
|
|
213
|
+
...state,
|
|
214
|
+
rev: action.rev,
|
|
215
|
+
savedVersion: action.version,
|
|
216
|
+
status: state.status === "published" ? "changed" : state.status,
|
|
217
|
+
};
|
|
198
218
|
case "published":
|
|
199
219
|
return { ...state, rev: action.rev, status: "published" };
|
|
200
220
|
case "set-design":
|
|
@@ -206,6 +226,14 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
206
226
|
};
|
|
207
227
|
case "publish-design":
|
|
208
228
|
return { ...state, designUnpublished: false, publishedRevision: action.revision };
|
|
229
|
+
case "load-design":
|
|
230
|
+
return {
|
|
231
|
+
...state,
|
|
232
|
+
design: action.design,
|
|
233
|
+
designRevision: action.revision,
|
|
234
|
+
publishedRevision: action.publishedRevision,
|
|
235
|
+
designUnpublished: action.unpublished,
|
|
236
|
+
};
|
|
209
237
|
case "reset":
|
|
210
238
|
return action.state;
|
|
211
239
|
}
|
|
@@ -1,25 +1,40 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import type { createKumoToastManager } from "@cloudflare/kumo";
|
|
3
|
-
import type
|
|
3
|
+
import { DEVICE_PREVIEW_PX, type DesignSystem, type PopupDevice } from "../../core/index.ts";
|
|
4
4
|
import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
5
5
|
import { ApiError, type Fetcher } from "../api.ts";
|
|
6
6
|
import { previewUrl, publishDesign, saveDesign } from "../content-api.ts";
|
|
7
7
|
import { readCollection } from "../setup/run.ts";
|
|
8
8
|
import { isDirty, type EditorAction, type EditorState } from "./store.ts";
|
|
9
|
+
import { loadDesign } from "./useEditorData.ts";
|
|
9
10
|
import type { useSave } from "./useSave.ts";
|
|
10
11
|
|
|
11
12
|
const publicPath = (pattern: string | null | undefined, slug: string) =>
|
|
12
13
|
(pattern || "/{slug}").replace("{slug}", encodeURIComponent(slug));
|
|
13
14
|
|
|
15
|
+
/** Window heights for the sized Tablet and Mobile previews (W-158); widths are the canvas's. */
|
|
16
|
+
const PREVIEW_HEIGHT = { tablet: 1024, mobile: 844 } as const;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `window.open` features for a device preview (W-158): Desktop is an ordinary tab; Tablet and
|
|
20
|
+
* Mobile open a window whose page area is the device width, so the page's own media queries apply.
|
|
21
|
+
*/
|
|
22
|
+
export function previewWindowFeatures(device: PopupDevice): string | undefined {
|
|
23
|
+
if (device === "desktop") return undefined;
|
|
24
|
+
return `popup,width=${DEVICE_PREVIEW_PX[device]},height=${PREVIEW_HEIGHT[device]}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
14
27
|
/**
|
|
15
28
|
* Opens a tab synchronously (so pop-up blockers allow it), then points it at `url` when known.
|
|
16
29
|
* `url` resolves null when it already told the user why (a failed save); a throw goes to `onError`.
|
|
30
|
+
* `features` opens a sized window instead of a tab (W-158).
|
|
17
31
|
*/
|
|
18
32
|
export async function openInNewTab(
|
|
19
33
|
url: () => Promise<string | null>,
|
|
20
34
|
onError: (error: unknown) => void,
|
|
35
|
+
features?: string,
|
|
21
36
|
) {
|
|
22
|
-
const tab = window.open("", "_blank");
|
|
37
|
+
const tab = features ? window.open("", "_blank", features) : window.open("", "_blank");
|
|
23
38
|
const target = await url().catch((error: unknown) => {
|
|
24
39
|
onError(error);
|
|
25
40
|
return null;
|
|
@@ -30,6 +45,9 @@ export async function openInNewTab(
|
|
|
30
45
|
tab.location.href = target;
|
|
31
46
|
}
|
|
32
47
|
|
|
48
|
+
const STYLES_PENDING =
|
|
49
|
+
"Site styles have unpublished changes, so the public page may look unstyled until you publish styles.";
|
|
50
|
+
|
|
33
51
|
/** Persistence commands: save, publish, preview and site-styles save (with the busy flag). */
|
|
34
52
|
export function useEditorCommands({
|
|
35
53
|
fetcher,
|
|
@@ -73,9 +91,30 @@ export function useEditorCommands({
|
|
|
73
91
|
() => null,
|
|
74
92
|
);
|
|
75
93
|
const path = publicPath(pattern, latest.current.page.slug);
|
|
94
|
+
// W-126: unpublished site styles (a new colour variable, a class) are not on the public
|
|
95
|
+
// page yet, so it can look unstyled. Say so and offer to publish them.
|
|
96
|
+
const stylesPending = latest.current.designUnpublished === true;
|
|
76
97
|
toasts.add({
|
|
77
98
|
title: "Published",
|
|
99
|
+
...(stylesPending ? { description: STYLES_PENDING } : {}),
|
|
78
100
|
actions: [
|
|
101
|
+
...(stylesPending
|
|
102
|
+
? [
|
|
103
|
+
{
|
|
104
|
+
children: "Publish site styles",
|
|
105
|
+
variant: "primary" as const,
|
|
106
|
+
onClick: () =>
|
|
107
|
+
void publishStyles().then(
|
|
108
|
+
() => toasts.add({ title: "Site styles published" }),
|
|
109
|
+
(error: unknown) =>
|
|
110
|
+
toasts.add({
|
|
111
|
+
title: "Couldn't publish site styles",
|
|
112
|
+
description: error instanceof Error ? error.message : String(error),
|
|
113
|
+
}),
|
|
114
|
+
),
|
|
115
|
+
},
|
|
116
|
+
]
|
|
117
|
+
: []),
|
|
79
118
|
{
|
|
80
119
|
children: "View page ↗",
|
|
81
120
|
variant: "secondary",
|
|
@@ -85,7 +124,7 @@ export function useEditorCommands({
|
|
|
85
124
|
});
|
|
86
125
|
};
|
|
87
126
|
|
|
88
|
-
const preview = () =>
|
|
127
|
+
const preview = (device: PopupDevice = "desktop") =>
|
|
89
128
|
void openInNewTab(
|
|
90
129
|
async () => {
|
|
91
130
|
if (isDirty(latest.current) && !(await save())) return null;
|
|
@@ -96,6 +135,7 @@ export function useEditorCommands({
|
|
|
96
135
|
title: "Couldn't open the preview",
|
|
97
136
|
description: error instanceof Error ? error.message : String(error),
|
|
98
137
|
}),
|
|
138
|
+
previewWindowFeatures(device),
|
|
99
139
|
);
|
|
100
140
|
|
|
101
141
|
const changeDesign = async (next: DesignSystem) => {
|
|
@@ -104,8 +144,19 @@ export function useEditorCommands({
|
|
|
104
144
|
dispatch({ type: "set-design", design: next, revision });
|
|
105
145
|
} catch (error) {
|
|
106
146
|
if (error instanceof ApiError && error.status === 409) {
|
|
147
|
+
// W-212: take the styles saved elsewhere (another editor tab, say), so the next change
|
|
148
|
+
// can save, instead of every change failing until a reload that drops page edits.
|
|
149
|
+
try {
|
|
150
|
+
const fresh = await loadDesign(fetcher);
|
|
151
|
+
dispatch({ type: "load-design", ...fresh });
|
|
152
|
+
} catch {
|
|
153
|
+
throw new Error(
|
|
154
|
+
"Site styles were changed somewhere else. Reload the editor and try again.",
|
|
155
|
+
{ cause: error },
|
|
156
|
+
);
|
|
157
|
+
}
|
|
107
158
|
throw new Error(
|
|
108
|
-
"Site styles were changed
|
|
159
|
+
"Site styles were changed in another tab or window. The latest styles are loaded now: make your change again.",
|
|
109
160
|
{ cause: error },
|
|
110
161
|
);
|
|
111
162
|
}
|
|
@@ -124,8 +175,18 @@ export function useEditorCommands({
|
|
|
124
175
|
dispatch({ type: "publish-design", revision });
|
|
125
176
|
} catch (error) {
|
|
126
177
|
if (error instanceof ApiError && error.status === 409) {
|
|
178
|
+
// W-212: as for a save, take what the other tab published so Publish can work again.
|
|
179
|
+
try {
|
|
180
|
+
const fresh = await loadDesign(fetcher);
|
|
181
|
+
dispatch({ type: "load-design", ...fresh });
|
|
182
|
+
} catch {
|
|
183
|
+
throw new Error(
|
|
184
|
+
"Site styles were published somewhere else. Reload the editor and try again.",
|
|
185
|
+
{ cause: error },
|
|
186
|
+
);
|
|
187
|
+
}
|
|
127
188
|
throw new Error(
|
|
128
|
-
"Site styles were published
|
|
189
|
+
"Site styles were published in another tab or window. The latest styles are loaded now: check them, then publish again.",
|
|
129
190
|
{ cause: error },
|
|
130
191
|
);
|
|
131
192
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import {
|
|
3
3
|
defaultConditions,
|
|
4
|
+
defaultFloatSettings,
|
|
4
5
|
defaultTriggers,
|
|
6
|
+
validateFloatSettings,
|
|
5
7
|
emptyDesign,
|
|
6
8
|
parseThemePartType,
|
|
7
9
|
validateConditions,
|
|
@@ -10,12 +12,14 @@ import {
|
|
|
10
12
|
validateTriggers,
|
|
11
13
|
type ConditionsDoc,
|
|
12
14
|
type DesignSystem,
|
|
15
|
+
type FloatSettings,
|
|
13
16
|
type Layout,
|
|
14
17
|
type ThemePartType,
|
|
15
18
|
type TriggersDoc,
|
|
16
19
|
} from "../../core/index.ts";
|
|
17
20
|
import { PAGES_COLLECTION, PLUGIN_ID, THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
18
21
|
import { ApiError, requestJson, type Fetcher } from "../api.ts";
|
|
22
|
+
import { entryStatus } from "../entry-status.ts";
|
|
19
23
|
|
|
20
24
|
export type EditorEntry = {
|
|
21
25
|
id: string;
|
|
@@ -25,12 +29,16 @@ export type EditorEntry = {
|
|
|
25
29
|
canvasMode: string;
|
|
26
30
|
seoTitle: string;
|
|
27
31
|
seoDescription: string;
|
|
32
|
+
seoCanonical?: string;
|
|
33
|
+
seoNoIndex?: boolean;
|
|
34
|
+
seoImage?: string;
|
|
28
35
|
status: string;
|
|
29
36
|
rev: string | null;
|
|
30
37
|
layout: Layout | null;
|
|
31
38
|
partType?: ThemePartType;
|
|
32
39
|
conditions?: ConditionsDoc;
|
|
33
40
|
triggers?: TriggersDoc;
|
|
41
|
+
float?: FloatSettings;
|
|
34
42
|
};
|
|
35
43
|
|
|
36
44
|
export type LoadedDesign = {
|
|
@@ -53,8 +61,15 @@ type ContentResponse = {
|
|
|
53
61
|
id?: string;
|
|
54
62
|
slug?: string | null;
|
|
55
63
|
status?: string;
|
|
64
|
+
draftRevisionId?: string | null;
|
|
56
65
|
data?: Record<string, unknown>;
|
|
57
|
-
seo?: {
|
|
66
|
+
seo?: {
|
|
67
|
+
title?: string | null;
|
|
68
|
+
description?: string | null;
|
|
69
|
+
canonical?: string | null;
|
|
70
|
+
noIndex?: boolean | null;
|
|
71
|
+
image?: string | null;
|
|
72
|
+
} | null;
|
|
58
73
|
};
|
|
59
74
|
_rev?: string;
|
|
60
75
|
};
|
|
@@ -79,7 +94,10 @@ export async function loadEntry(
|
|
|
79
94
|
canvasMode: text(data["canvas_mode"]) || "site-layout",
|
|
80
95
|
seoTitle: text(body?.item?.seo?.title),
|
|
81
96
|
seoDescription: text(body?.item?.seo?.description),
|
|
82
|
-
|
|
97
|
+
seoCanonical: text(body?.item?.seo?.canonical),
|
|
98
|
+
seoNoIndex: body?.item?.seo?.noIndex === true,
|
|
99
|
+
seoImage: text(body?.item?.seo?.image),
|
|
100
|
+
status: entryStatus(body?.item),
|
|
83
101
|
rev: body?.["_rev"] ?? null,
|
|
84
102
|
layout: readLayout(data["layout"]),
|
|
85
103
|
};
|
|
@@ -101,9 +119,17 @@ export async function loadEntry(
|
|
|
101
119
|
partType: parseThemePartType(data["part_type"]) ?? "header",
|
|
102
120
|
conditions: validated.ok ? validated.conditions : defaultConditions(),
|
|
103
121
|
triggers: triggersValidated.ok ? triggersValidated.triggers : defaultTriggers(),
|
|
122
|
+
float: readFloat(data["float"]),
|
|
104
123
|
};
|
|
105
124
|
}
|
|
106
125
|
|
|
126
|
+
function readFloat(raw: unknown): FloatSettings {
|
|
127
|
+
const validated = validateFloatSettings(
|
|
128
|
+
raw === undefined || raw === null || raw === "" ? defaultFloatSettings() : raw,
|
|
129
|
+
);
|
|
130
|
+
return validated.ok ? validated.settings : defaultFloatSettings();
|
|
131
|
+
}
|
|
132
|
+
|
|
107
133
|
function readLayout(raw: unknown): Layout | null {
|
|
108
134
|
if (raw === null || raw === undefined || raw === "") return null;
|
|
109
135
|
let value: unknown = raw;
|
|
@@ -119,7 +145,7 @@ function readLayout(raw: unknown): Layout | null {
|
|
|
119
145
|
return result.layout;
|
|
120
146
|
}
|
|
121
147
|
|
|
122
|
-
async function loadDesign(fetcher: Fetcher): Promise<LoadedDesign> {
|
|
148
|
+
export async function loadDesign(fetcher: Fetcher): Promise<LoadedDesign> {
|
|
123
149
|
const body = await requestJson<{
|
|
124
150
|
design?: unknown;
|
|
125
151
|
revision?: string | null;
|
|
@@ -26,6 +26,35 @@ const isTextField = (target: EventTarget | null) => {
|
|
|
26
26
|
const inDialog = (target: EventTarget | null) =>
|
|
27
27
|
!!(target as HTMLElement | null)?.closest?.('[role="dialog"], [role="alertdialog"]');
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Element shortcuts (traverse, arrange, delete, duplicate, copy, paste, Escape) act only from the
|
|
31
|
+
* canvas, Layers, or with nothing focused, never from the settings panel, its tabs and section
|
|
32
|
+
* headers, the Add panel or the top bar: ↑ on the Style tab used to select the previous element,
|
|
33
|
+
* often the parent (W-132). Keys from the canvas iframe arrive with targets in its own document.
|
|
34
|
+
*/
|
|
35
|
+
const onCanvasOrLayers = (target: EventTarget | null) => {
|
|
36
|
+
const element = target as Element | null;
|
|
37
|
+
if (!element || typeof element.closest !== "function") return true;
|
|
38
|
+
const doc = element.ownerDocument;
|
|
39
|
+
if (doc !== document) return true;
|
|
40
|
+
if (element === doc.body || element === doc.documentElement) return true;
|
|
41
|
+
return !!element.closest(
|
|
42
|
+
'[data-emvb-panel="layers"], .emvb-overlay, .emvb-stage, iframe[data-emvb-canvas]',
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A focused control that owns the key (W-258): Enter on a button other than a Layers row
|
|
48
|
+
* activates it, and keys in a Layers row menu stay there, instead of walking the tree.
|
|
49
|
+
*/
|
|
50
|
+
const ownsKey = (target: EventTarget | null, key: string): boolean => {
|
|
51
|
+
const element = target as Element | null;
|
|
52
|
+
if (!element || typeof element.closest !== "function") return false;
|
|
53
|
+
if (element.closest(".emvb-layer-menu")) return true;
|
|
54
|
+
if (key !== "Enter" || element.closest(".emvb-layer-select")) return false;
|
|
55
|
+
return !!element.closest('button, a[href], summary, [role="button"], [role="menuitem"]');
|
|
56
|
+
};
|
|
57
|
+
|
|
29
58
|
/** Selected text on the page or the canvas: Ctrl/Cmd+C then copies the text, as usual (W-093). */
|
|
30
59
|
const hasTextSelection = (target: EventTarget | null) => {
|
|
31
60
|
const docs = new Set([document, (target as Node | null)?.ownerDocument ?? document]);
|
|
@@ -68,7 +97,8 @@ export type ShortcutHandlers = {
|
|
|
68
97
|
/**
|
|
69
98
|
* Window-level editor shortcuts (W-020): save, undo and redo (W-095), duplicate, copy and paste
|
|
70
99
|
* (W-093), delete, escape, arrange and traverse. Inside text fields and dialogs only Save works, so
|
|
71
|
-
* typing, native undo, copy and paste keep working there.
|
|
100
|
+
* typing, native undo, copy and paste keep working there. Element shortcuts also need focus on
|
|
101
|
+
* the canvas, Layers, or nothing (W-132); Save, undo and redo work from the panels too.
|
|
72
102
|
*/
|
|
73
103
|
export function useEditorShortcuts({
|
|
74
104
|
latest,
|
|
@@ -96,6 +126,7 @@ export function useEditorShortcuts({
|
|
|
96
126
|
dispatch({ type: "redo" });
|
|
97
127
|
return;
|
|
98
128
|
}
|
|
129
|
+
if (!onCanvasOrLayers(event.target)) return;
|
|
99
130
|
const layout = latest.current.page.layout;
|
|
100
131
|
const selected = latest.current.selectedId;
|
|
101
132
|
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "d" && selected) {
|
|
@@ -133,7 +164,8 @@ export function useEditorShortcuts({
|
|
|
133
164
|
return;
|
|
134
165
|
}
|
|
135
166
|
const traverse = TRAVERSE_KEYS.get(event.key);
|
|
136
|
-
|
|
167
|
+
// W-257: the Layers tree already moved the selection for this key; moving again skipped a row.
|
|
168
|
+
if (!traverse || event.defaultPrevented || ownsKey(event.target, event.key)) return;
|
|
137
169
|
event.preventDefault();
|
|
138
170
|
const target = traverse(layout, selected, event.shiftKey);
|
|
139
171
|
if (target) dispatch({ type: "select", id: target });
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import type { createKumoToastManager } from "@cloudflare/kumo";
|
|
3
3
|
import {
|
|
4
|
+
addNode,
|
|
5
|
+
addNodeNear,
|
|
4
6
|
duplicateNode,
|
|
5
7
|
ELEMENT_DESCRIPTORS,
|
|
6
8
|
findNode,
|
|
7
|
-
|
|
9
|
+
moveDown,
|
|
10
|
+
moveUp,
|
|
8
11
|
subtreeSize,
|
|
9
12
|
type Arranged,
|
|
10
13
|
type ElementType,
|
|
@@ -12,9 +15,11 @@ import {
|
|
|
12
15
|
} from "../../core/index.ts";
|
|
13
16
|
import { newElement } from "./dnd/new-element.ts";
|
|
14
17
|
import { ELEMENT_NAMES } from "./panels/ElementPanel.tsx";
|
|
18
|
+
import type { ItemActions } from "./panels/settings/ItemList.tsx";
|
|
15
19
|
import type { EditorAction, EditorState } from "./store.ts";
|
|
16
20
|
|
|
17
21
|
const RESTORE_TIMEOUT_MS = 6000;
|
|
22
|
+
const NOTICE_TIMEOUT_MS = 4000;
|
|
18
23
|
|
|
19
24
|
/** Node actions on the layout tree: delete (with restore toast), duplicate, and add from the panel. */
|
|
20
25
|
export function useNodeActions({
|
|
@@ -88,10 +93,52 @@ export function useNodeActions({
|
|
|
88
93
|
return;
|
|
89
94
|
}
|
|
90
95
|
dispatch({ type: "apply-arranged", layout: result.layout, selected: result.selected });
|
|
96
|
+
if (result.note) {
|
|
97
|
+
announce(`Duplicated. ${result.note}`);
|
|
98
|
+
if (lastToast.current) toasts.close(lastToast.current);
|
|
99
|
+
lastToast.current = toasts.add({
|
|
100
|
+
title: "Duplicated",
|
|
101
|
+
description: result.note,
|
|
102
|
+
timeout: NOTICE_TIMEOUT_MS,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
91
105
|
};
|
|
92
106
|
|
|
93
107
|
const duplicate = (id: string) => arrange(id, duplicateNode);
|
|
94
108
|
|
|
109
|
+
/** Accordion and Tabs item list (W-130): the parent stays selected so the list stays open. */
|
|
110
|
+
const items: ItemActions = {
|
|
111
|
+
add: (parentId, node) => {
|
|
112
|
+
const layout = latest.current.page.layout;
|
|
113
|
+
const parent = layout ? findNode(layout, parentId) : undefined;
|
|
114
|
+
if (!layout || !parent) return;
|
|
115
|
+
const index =
|
|
116
|
+
"children" in parent && Array.isArray(parent.children) ? parent.children.length : 0;
|
|
117
|
+
const result = addNode(layout, node, { parentId, index });
|
|
118
|
+
if (!result.ok) {
|
|
119
|
+
announce(result.reason);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
dispatch({ type: "apply-arranged", layout: result.layout, selected: parentId });
|
|
123
|
+
announce(`${ELEMENT_NAMES[node.type] ?? "Item"} added`);
|
|
124
|
+
},
|
|
125
|
+
remove: (id) => remove(id),
|
|
126
|
+
move: (id, direction) => {
|
|
127
|
+
const layout = latest.current.page.layout;
|
|
128
|
+
if (!layout) return;
|
|
129
|
+
const result = (direction === "up" ? moveUp : moveDown)(layout, id);
|
|
130
|
+
if (!result.ok) {
|
|
131
|
+
announce(result.reason);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
dispatch({
|
|
135
|
+
type: "apply-arranged",
|
|
136
|
+
layout: result.layout,
|
|
137
|
+
selected: latest.current.selectedId ?? result.selected,
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
95
142
|
const addFromPanel = (type: ElementType) => {
|
|
96
143
|
const layout = latest.current.page.layout;
|
|
97
144
|
if (!layout) {
|
|
@@ -100,12 +147,26 @@ export function useNodeActions({
|
|
|
100
147
|
}
|
|
101
148
|
const node = newElement(type);
|
|
102
149
|
if (!node) return;
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
150
|
+
const notice = (message: string) => {
|
|
151
|
+
announce(message);
|
|
152
|
+
if (lastToast.current) toasts.close(lastToast.current);
|
|
153
|
+
lastToast.current = toasts.add({ title: message, timeout: NOTICE_TIMEOUT_MS });
|
|
154
|
+
};
|
|
155
|
+
const result = addNodeNear(layout, node, latest.current.selectedId);
|
|
156
|
+
if (!result.ok) {
|
|
157
|
+
notice(result.reason);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
dispatch({ type: "apply-arranged", layout: result.layout, selected: result.selected });
|
|
161
|
+
const nameOf = (id: string) => ELEMENT_NAMES[findNode(layout, id)?.type ?? "container"];
|
|
106
162
|
const label = ELEMENT_DESCRIPTORS.find((d) => d.type === type)?.name ?? type;
|
|
107
|
-
|
|
108
|
-
|
|
163
|
+
if (result.fallback) {
|
|
164
|
+
// Added next to the nearest ancestor that takes it, rather than refused (W-175).
|
|
165
|
+
const after = nameOf(result.fallback.after) ?? "the selection";
|
|
166
|
+
notice(`${label} added after ${after} instead. ${result.fallback.refused}`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
announce(`${label} added inside ${nameOf(result.parentId) ?? "Container"}`);
|
|
109
170
|
};
|
|
110
171
|
|
|
111
172
|
return {
|
|
@@ -118,5 +179,6 @@ export function useNodeActions({
|
|
|
118
179
|
arrange,
|
|
119
180
|
duplicate,
|
|
120
181
|
addFromPanel,
|
|
182
|
+
items,
|
|
121
183
|
};
|
|
122
184
|
}
|