@perkyzz/emvb 0.3.0 → 0.5.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 +22 -4
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/package.json +5 -2
- package/src/admin/access/role.ts +9 -3
- package/src/admin/agents-api.ts +39 -0
- package/src/admin/api.ts +17 -7
- package/src/admin/content-api.ts +7 -51
- package/src/admin/content-item.ts +22 -0
- package/src/admin/design-api.ts +30 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/CommandPalette.tsx +43 -2
- package/src/admin/editor/Editor.tsx +133 -332
- package/src/admin/editor/EditorOverlay.tsx +3 -1
- package/src/admin/editor/PerfMeter.tsx +1 -1
- package/src/admin/editor/ShortcutsDialog.tsx +4 -1
- package/src/admin/editor/Timeline.tsx +124 -9
- package/src/admin/editor/canvas/CanvasFrame.tsx +51 -368
- package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
- package/src/admin/editor/canvas/SelectionOverlay.tsx +86 -46
- package/src/admin/editor/canvas/canvas-scale.ts +20 -0
- package/src/admin/editor/canvas/drop-line.ts +24 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
- package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
- package/src/admin/editor/collection-previews.ts +28 -5
- package/src/admin/editor/editor-chrome.tsx +346 -0
- package/src/admin/editor/editor-commands.ts +360 -0
- package/src/admin/editor/editor-css.ts +4 -0
- package/src/admin/editor/element-chrome.ts +89 -0
- package/src/admin/editor/feature-css.ts +37 -18
- package/src/admin/editor/host.ts +33 -0
- package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
- package/src/admin/editor/icons/library.ts +29 -19
- package/src/admin/editor/icons/use-icon-library.ts +315 -0
- package/src/admin/editor/palette-items.ts +36 -5
- package/src/admin/editor/palette.ts +9 -4
- package/src/admin/editor/panels/AddPanel.tsx +2 -67
- package/src/admin/editor/panels/ColorControl.tsx +21 -18
- package/src/admin/editor/panels/ElementPanel.tsx +40 -99
- package/src/admin/editor/panels/LayersPanel.tsx +34 -62
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +16 -10
- package/src/admin/editor/panels/TokenScales.tsx +4 -2
- package/src/admin/editor/panels/VariableSection.tsx +1 -10
- package/src/admin/editor/panels/color-space.ts +12 -1
- package/src/admin/editor/panels/inline-error.tsx +11 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +143 -1
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +115 -7
- package/src/admin/editor/panels/settings/DraftTextField.tsx +42 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +6 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
- package/src/admin/editor/panels/settings/IconPicker.tsx +21 -1
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +111 -0
- package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
- package/src/admin/editor/panels/settings/MediaPicker.tsx +2 -3
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +178 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- package/src/admin/editor/panels/settings/form-names.ts +7 -11
- package/src/admin/editor/panels/settings/length-units.ts +15 -4
- package/src/admin/editor/panels/settings/link-rules.ts +19 -0
- package/src/admin/editor/panels/settings/number-input.ts +11 -0
- package/src/admin/editor/panels/settings/query-style.ts +65 -0
- package/src/admin/editor/panels/settings/style-sections.ts +5 -1
- package/src/admin/editor/panels/style-target.ts +105 -0
- package/src/admin/editor/panels/variable-values.ts +4 -2
- package/src/admin/editor/remote-change.ts +67 -0
- package/src/admin/editor/section-templates.ts +43 -21
- package/src/admin/editor/shortcuts.ts +4 -0
- package/src/admin/editor/store.ts +10 -1
- package/src/admin/editor/useClipboardActions.ts +1 -1
- package/src/admin/editor/useEditorCommands.ts +61 -13
- package/src/admin/editor/useEditorData.ts +7 -1
- package/src/admin/editor/useEditorShortcuts.ts +23 -15
- package/src/admin/editor/useNodeActions.ts +6 -1
- package/src/admin/forms-api.ts +17 -6
- package/src/admin/icon-uploads-api.ts +18 -0
- package/src/admin/index.tsx +3 -1
- package/src/admin/media-api.ts +20 -0
- package/src/admin/pages/AgentsPage.tsx +274 -0
- package/src/admin/theme-api.ts +5 -18
- package/src/admin/ui.ts +28 -0
- package/src/astro/content-port.ts +24 -0
- package/src/astro/floats/runtime.ts +10 -0
- package/src/astro/forms/EmVBFormsClient.astro +11 -0
- package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
- package/src/astro/forms/client.ts +1 -0
- package/src/astro/forms-definitions.ts +24 -11
- package/src/astro/index.ts +1 -0
- package/src/astro/popups/runtime.ts +15 -0
- package/src/astro/render-session.ts +85 -0
- package/src/astro/request-data.ts +20 -8
- package/src/astro/resolve-theme.ts +166 -76
- package/src/astro/resolve.ts +57 -16
- package/src/astro/tabs/runtime.ts +60 -1
- package/src/astro/theme-posts.ts +16 -5
- package/src/astro/visitor.ts +67 -5
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +202 -26
- package/src/core/arrange.ts +71 -38
- package/src/core/audience/rules.ts +22 -2
- package/src/core/canvas-styles.ts +24 -0
- package/src/core/clipboard.ts +11 -32
- package/src/core/css/generate.ts +18 -1
- package/src/core/css/print.ts +12 -0
- package/src/core/css/scope.ts +3 -3
- package/src/core/css-keywords.ts +83 -0
- package/src/core/data/bindings.ts +4 -6
- package/src/core/design/classes.ts +13 -15
- package/src/core/design/diff.ts +55 -0
- package/src/core/design/merge.ts +127 -0
- package/src/core/design/variables.ts +25 -21
- package/src/core/elements/dynamic-elements.ts +30 -0
- package/src/core/elements/form-elements.ts +20 -3
- package/src/core/elements/index.ts +211 -7
- package/src/core/forms/binding.ts +4 -13
- package/src/core/index.ts +10 -0
- package/src/core/local-style.ts +27 -0
- package/src/core/migrate/index.ts +9 -4
- package/src/core/nesting.ts +4 -23
- package/src/core/perf/scripts.ts +9 -6
- package/src/core/record.ts +3 -0
- package/src/core/render/context.ts +2 -0
- package/src/core/render/dynamic-post.ts +22 -7
- package/src/core/render/form.ts +145 -15
- package/src/core/render/index.ts +195 -14
- package/src/core/render/pagination.ts +21 -2
- package/src/core/render/vnode.ts +12 -2
- package/src/core/sanitize/css.ts +90 -77
- package/src/core/sanitize/embed-url.ts +7 -1
- package/src/core/sanitize/href.ts +13 -1
- package/src/core/sanitize/svg.ts +8 -3
- package/src/core/sanitize/url.ts +10 -1
- package/src/core/schema/descriptors.ts +4 -1
- package/src/core/schema/design.ts +5 -7
- package/src/core/schema/layout.ts +160 -181
- package/src/core/schema/style.ts +53 -63
- package/src/core/share/link.ts +72 -29
- package/src/core/tabs/presence.ts +7 -17
- package/src/core/theme/dynamic.ts +205 -39
- package/src/core/theme/float.ts +1 -1
- package/src/core/tree-ops.ts +57 -0
- package/src/index.ts +14 -2
- package/src/mcp/errors.ts +44 -0
- package/src/mcp/index.ts +4 -0
- package/src/mcp/ports.ts +78 -0
- package/src/mcp/prompts.ts +76 -0
- package/src/mcp/publish.ts +60 -0
- package/src/mcp/queue.ts +19 -0
- package/src/mcp/rate-limit.ts +80 -0
- package/src/mcp/read.ts +419 -0
- package/src/mcp/refs.ts +84 -0
- package/src/mcp/settings.ts +18 -0
- package/src/mcp/tools.ts +265 -0
- package/src/mcp/write.ts +582 -0
- package/src/server/agent-settings.ts +134 -0
- package/src/server/design-routes.ts +75 -18
- package/src/server/icon-routes.ts +72 -16
- package/src/server/mcp-routes.ts +265 -0
- package/src/server/plugin.ts +40 -4
- package/src/admin/editor/icons/sets/fontawesome.json +0 -1
- package/src/admin/editor/icons/sets/lucide.json +0 -1
- package/src/admin/editor/icons/sets/remix.json +0 -1
- package/src/admin/editor/icons/sets/tabler.json +0 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { PLUGIN_ID } from "../../constants.ts";
|
|
3
|
+
import { requestJson, type Fetcher } from "../api.ts";
|
|
4
|
+
|
|
5
|
+
/** How often an idle editor checks whether the page changed elsewhere (W-466). */
|
|
6
|
+
const REMOTE_CHECK_MS = 20_000;
|
|
7
|
+
|
|
8
|
+
export type RemoteChange = null | "agent" | "other";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* What changed the stored draft since `rev`: null when nothing did, "agent" when the newest
|
|
12
|
+
* version is one an AI agent saved, "other" for anyone else.
|
|
13
|
+
*/
|
|
14
|
+
export async function checkRemoteChange(
|
|
15
|
+
fetcher: Fetcher,
|
|
16
|
+
collection: string,
|
|
17
|
+
id: string,
|
|
18
|
+
rev: string,
|
|
19
|
+
): Promise<RemoteChange> {
|
|
20
|
+
const body = await requestJson<{ item?: { draftRevisionId?: string | null }; _rev?: string }>(
|
|
21
|
+
fetcher,
|
|
22
|
+
`/_emdash/api/content/${collection}/${encodeURIComponent(id)}`,
|
|
23
|
+
);
|
|
24
|
+
const stored = body["_rev"];
|
|
25
|
+
if (!stored || stored === rev) return null;
|
|
26
|
+
const draft = body.item?.draftRevisionId;
|
|
27
|
+
if (!draft) return "other";
|
|
28
|
+
const agents = await requestJson<{ versions?: { revisionId: string }[] }>(
|
|
29
|
+
fetcher,
|
|
30
|
+
`/_emdash/api/plugins/${PLUGIN_ID}/agents/page`,
|
|
31
|
+
{ method: "POST", body: { pageId: id } },
|
|
32
|
+
).catch(() => ({ versions: [] }));
|
|
33
|
+
return (agents.versions ?? []).some((v) => v.revisionId === draft) ? "agent" : "other";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Polls while the editor is idle (no unsaved edits, nothing in flight, tab visible) and reports
|
|
38
|
+
* when the page changed elsewhere, so the person can reload before their next save conflicts.
|
|
39
|
+
*/
|
|
40
|
+
export function useRemoteChange(
|
|
41
|
+
fetcher: Fetcher,
|
|
42
|
+
collection: string,
|
|
43
|
+
id: string,
|
|
44
|
+
rev: string | null,
|
|
45
|
+
idle: boolean,
|
|
46
|
+
): RemoteChange {
|
|
47
|
+
const [change, setChange] = React.useState<RemoteChange>(null);
|
|
48
|
+
React.useEffect(() => setChange(null), [rev]);
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
if (!idle || !rev || change) return;
|
|
51
|
+
let cancelled = false;
|
|
52
|
+
const timer = setInterval(() => {
|
|
53
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
54
|
+
checkRemoteChange(fetcher, collection, id, rev).then(
|
|
55
|
+
(next) => {
|
|
56
|
+
if (!cancelled && next) setChange(next);
|
|
57
|
+
},
|
|
58
|
+
() => undefined,
|
|
59
|
+
);
|
|
60
|
+
}, REMOTE_CHECK_MS);
|
|
61
|
+
return () => {
|
|
62
|
+
cancelled = true;
|
|
63
|
+
clearInterval(timer);
|
|
64
|
+
};
|
|
65
|
+
}, [fetcher, collection, id, rev, idle, change]);
|
|
66
|
+
return change;
|
|
67
|
+
}
|
|
@@ -5,6 +5,41 @@ import { themePartLayout } from "../theme-api.ts";
|
|
|
5
5
|
|
|
6
6
|
const MAX_DEPTH = 8;
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Loads section parts one depth at a time. Siblings load together. A part that fails is left out;
|
|
10
|
+
* the ones that loaded stay.
|
|
11
|
+
*/
|
|
12
|
+
export async function loadSectionTemplates(
|
|
13
|
+
fetcher: Fetcher,
|
|
14
|
+
ids: readonly string[],
|
|
15
|
+
read: (id: string) => Promise<Layout | null> = (id) => themePartLayout(fetcher, id, "section"),
|
|
16
|
+
): Promise<Record<string, Layout>> {
|
|
17
|
+
const acc: Record<string, Layout> = {};
|
|
18
|
+
const walk = async (next: readonly string[], depth: number): Promise<void> => {
|
|
19
|
+
if (depth > MAX_DEPTH) return;
|
|
20
|
+
const pending = next.filter((id) => !acc[id]);
|
|
21
|
+
if (pending.length === 0) return;
|
|
22
|
+
const loaded = await Promise.all(
|
|
23
|
+
pending.map(async (id) => {
|
|
24
|
+
try {
|
|
25
|
+
return [id, await read(id)] as const;
|
|
26
|
+
} catch {
|
|
27
|
+
return [id, null] as const;
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
);
|
|
31
|
+
const nested: string[] = [];
|
|
32
|
+
for (const [id, part] of loaded) {
|
|
33
|
+
if (!part || acc[id]) continue;
|
|
34
|
+
acc[id] = part;
|
|
35
|
+
nested.push(...collectSectionPartIds(part));
|
|
36
|
+
}
|
|
37
|
+
await walk(nested, depth + 1);
|
|
38
|
+
};
|
|
39
|
+
await walk(ids, 0);
|
|
40
|
+
return acc;
|
|
41
|
+
}
|
|
42
|
+
|
|
8
43
|
/** Section theme parts referenced by the open layout, so the canvas shows the synced contents. */
|
|
9
44
|
export function useSectionTemplates(
|
|
10
45
|
layout: Layout | null,
|
|
@@ -20,27 +55,14 @@ export function useSectionTemplates(
|
|
|
20
55
|
return;
|
|
21
56
|
}
|
|
22
57
|
let cancelled = false;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const part = await themePartLayout(fetcher, id, "section");
|
|
32
|
-
if (!part) continue;
|
|
33
|
-
acc[id] = part;
|
|
34
|
-
// oxlint-disable-next-line no-await-in-loop
|
|
35
|
-
await walk(collectSectionPartIds(part), depth + 1);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
await walk(ids, 0);
|
|
39
|
-
if (!cancelled) setTemplates(acc);
|
|
40
|
-
};
|
|
41
|
-
void load().catch(() => {
|
|
42
|
-
if (!cancelled) setTemplates({});
|
|
43
|
-
});
|
|
58
|
+
void loadSectionTemplates(fetcher, ids).then(
|
|
59
|
+
(acc) => {
|
|
60
|
+
if (!cancelled) setTemplates(acc);
|
|
61
|
+
},
|
|
62
|
+
() => {
|
|
63
|
+
if (!cancelled) setTemplates({});
|
|
64
|
+
},
|
|
65
|
+
);
|
|
44
66
|
return () => {
|
|
45
67
|
cancelled = true;
|
|
46
68
|
};
|
|
@@ -19,3 +19,7 @@ export const SHORTCUTS: readonly { action: string; keys: string }[] = [
|
|
|
19
19
|
/** Ctrl/Cmd+K opens the host command palette, which would stack over the editor (S0-6). */
|
|
20
20
|
export const isPaletteShortcut = (event: KeyboardEvent) =>
|
|
21
21
|
(event.ctrlKey || event.metaKey) && !event.altKey && event.key.toLowerCase() === "k";
|
|
22
|
+
|
|
23
|
+
/** Focus is inside an open dialog, where only Save fires. */
|
|
24
|
+
export const inDialog = (target: EventTarget | null) =>
|
|
25
|
+
!!(target as HTMLElement | null)?.closest?.('[role="dialog"], [role="alertdialog"]');
|
|
@@ -29,6 +29,8 @@ export type EditorState = {
|
|
|
29
29
|
publishedRevision?: string | null;
|
|
30
30
|
/** True after a style edit that has not been published. */
|
|
31
31
|
designUnpublished?: boolean;
|
|
32
|
+
/** Published design, so Publish styles can list what will change (W-340). */
|
|
33
|
+
publishedDesign?: DesignSystem;
|
|
32
34
|
selectedId: string | null;
|
|
33
35
|
/** Bumped on every page edit. A save only clears `dirty` if nothing changed while it ran. */
|
|
34
36
|
version: number;
|
|
@@ -65,6 +67,7 @@ export type EditorAction =
|
|
|
65
67
|
revision: string | null;
|
|
66
68
|
publishedRevision: string | null;
|
|
67
69
|
unpublished: boolean;
|
|
70
|
+
published?: DesignSystem;
|
|
68
71
|
}
|
|
69
72
|
| { type: "reset"; state: EditorState };
|
|
70
73
|
|
|
@@ -225,7 +228,12 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
225
228
|
designUnpublished: true,
|
|
226
229
|
};
|
|
227
230
|
case "publish-design":
|
|
228
|
-
return {
|
|
231
|
+
return {
|
|
232
|
+
...state,
|
|
233
|
+
designUnpublished: false,
|
|
234
|
+
publishedRevision: action.revision,
|
|
235
|
+
publishedDesign: state.design,
|
|
236
|
+
};
|
|
229
237
|
case "load-design":
|
|
230
238
|
return {
|
|
231
239
|
...state,
|
|
@@ -233,6 +241,7 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
233
241
|
designRevision: action.revision,
|
|
234
242
|
publishedRevision: action.publishedRevision,
|
|
235
243
|
designUnpublished: action.unpublished,
|
|
244
|
+
...(action.published ? { publishedDesign: action.published } : {}),
|
|
236
245
|
};
|
|
237
246
|
case "reset":
|
|
238
247
|
return action.state;
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
type PasteMode,
|
|
20
20
|
} from "../../core/index.ts";
|
|
21
21
|
import { readClipboardText, useClipboardText, writeClipboardText } from "./clipboard-store.ts";
|
|
22
|
-
import { ELEMENT_NAMES } from "./
|
|
22
|
+
import { ELEMENT_NAMES } from "./element-chrome.ts";
|
|
23
23
|
import type { EditorAction, EditorState } from "./store.ts";
|
|
24
24
|
|
|
25
25
|
const NOTICE_TIMEOUT_MS = 4000;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import type { createKumoToastManager } from "@cloudflare/kumo";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
DEVICE_PREVIEW_PX,
|
|
5
|
+
mergeDesign,
|
|
6
|
+
type DesignSystem,
|
|
7
|
+
type PopupDevice,
|
|
8
|
+
} from "../../core/index.ts";
|
|
4
9
|
import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
5
10
|
import { ApiError, type Fetcher } from "../api.ts";
|
|
6
11
|
import { previewUrl, publishDesign, saveDesign } from "../content-api.ts";
|
|
@@ -138,27 +143,68 @@ export function useEditorCommands({
|
|
|
138
143
|
previewWindowFeatures(device),
|
|
139
144
|
);
|
|
140
145
|
|
|
141
|
-
|
|
146
|
+
// W-325: design saves run one at a time, each against the newest revision, like page saves.
|
|
147
|
+
// Two quick edits used to both send the revision the editor started with, so the second one
|
|
148
|
+
// was refused with a 409 by the first. `written` remembers the revision a save produced until
|
|
149
|
+
// the store catches up (the ref updates on the next render).
|
|
150
|
+
const designQueue = React.useRef<Promise<unknown>>(Promise.resolve());
|
|
151
|
+
const written = React.useRef<{ from: string | null; to: string } | null>(null);
|
|
152
|
+
const baseRevision = () => {
|
|
153
|
+
const current = latest.current.designRevision;
|
|
154
|
+
const last = written.current;
|
|
155
|
+
return last && last.from === current ? last.to : current;
|
|
156
|
+
};
|
|
157
|
+
const queueDesign = <T>(task: () => Promise<T>): Promise<T> => {
|
|
158
|
+
const run = designQueue.current.then(task, task);
|
|
159
|
+
designQueue.current = run.catch(() => undefined);
|
|
160
|
+
return run;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const changeDesign = (next: DesignSystem) => queueDesign(() => saveDesignNow(next));
|
|
164
|
+
|
|
165
|
+
const saveDesignNow = async (next: DesignSystem) => {
|
|
142
166
|
try {
|
|
143
|
-
const
|
|
167
|
+
const from = latest.current.designRevision;
|
|
168
|
+
const revision = await saveDesign(fetcher, next, baseRevision());
|
|
169
|
+
written.current = { from, to: revision };
|
|
144
170
|
dispatch({ type: "set-design", design: next, revision });
|
|
145
171
|
} catch (error) {
|
|
172
|
+
written.current = null;
|
|
146
173
|
if (error instanceof ApiError && error.status === 409) {
|
|
147
|
-
// W-
|
|
148
|
-
//
|
|
174
|
+
// W-333: replay this tab's edit onto the styles saved elsewhere when those keys
|
|
175
|
+
// were not also changed there. A real clash still loads the server copy (W-212).
|
|
149
176
|
try {
|
|
150
177
|
const fresh = await loadDesign(fetcher);
|
|
151
|
-
|
|
152
|
-
|
|
178
|
+
const merged = mergeDesign(latest.current.design, next, fresh.design);
|
|
179
|
+
const names = merged.conflicts.map((conflict) => conflict.name).join(", ");
|
|
180
|
+
if (merged.conflicts.length > 0) {
|
|
181
|
+
dispatch({ type: "load-design", ...fresh });
|
|
182
|
+
throw new Error(
|
|
183
|
+
`Site styles were changed in another tab or window (${names}). The latest styles are loaded now: make your change again.`,
|
|
184
|
+
{ cause: error },
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
const unchanged = JSON.stringify(merged.design) === JSON.stringify(fresh.design);
|
|
188
|
+
if (unchanged) {
|
|
189
|
+
dispatch({ type: "load-design", ...fresh });
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const revision = await saveDesign(fetcher, merged.design, fresh.revision);
|
|
193
|
+
written.current = { from: latest.current.designRevision, to: revision };
|
|
194
|
+
dispatch({ type: "set-design", design: merged.design, revision });
|
|
195
|
+
return;
|
|
196
|
+
} catch (retry) {
|
|
197
|
+
if (
|
|
198
|
+
retry instanceof Error &&
|
|
199
|
+
retry.message.includes("The latest styles are loaded now")
|
|
200
|
+
) {
|
|
201
|
+
throw retry;
|
|
202
|
+
}
|
|
153
203
|
throw new Error(
|
|
154
204
|
"Site styles were changed somewhere else. Reload the editor and try again.",
|
|
155
|
-
{ cause:
|
|
205
|
+
{ cause: retry },
|
|
156
206
|
);
|
|
157
207
|
}
|
|
158
|
-
throw new Error(
|
|
159
|
-
"Site styles were changed in another tab or window. The latest styles are loaded now: make your change again.",
|
|
160
|
-
{ cause: error },
|
|
161
|
-
);
|
|
162
208
|
}
|
|
163
209
|
throw new Error(
|
|
164
210
|
error instanceof ApiError
|
|
@@ -169,7 +215,9 @@ export function useEditorCommands({
|
|
|
169
215
|
}
|
|
170
216
|
};
|
|
171
217
|
|
|
172
|
-
const publishStyles =
|
|
218
|
+
const publishStyles = () => queueDesign(publishStylesNow);
|
|
219
|
+
|
|
220
|
+
const publishStylesNow = async () => {
|
|
173
221
|
try {
|
|
174
222
|
const revision = await publishDesign(fetcher, latest.current.publishedRevision ?? null);
|
|
175
223
|
dispatch({ type: "publish-design", revision });
|
|
@@ -43,6 +43,8 @@ export type EditorEntry = {
|
|
|
43
43
|
|
|
44
44
|
export type LoadedDesign = {
|
|
45
45
|
design: DesignSystem;
|
|
46
|
+
/** The published design, for the Publish styles diff (W-340). Absent on an older response. */
|
|
47
|
+
published?: DesignSystem;
|
|
46
48
|
revision: string | null;
|
|
47
49
|
publishedRevision: string | null;
|
|
48
50
|
unpublished: boolean;
|
|
@@ -148,13 +150,17 @@ function readLayout(raw: unknown): Layout | null {
|
|
|
148
150
|
export async function loadDesign(fetcher: Fetcher): Promise<LoadedDesign> {
|
|
149
151
|
const body = await requestJson<{
|
|
150
152
|
design?: unknown;
|
|
153
|
+
published?: unknown;
|
|
151
154
|
revision?: string | null;
|
|
152
155
|
publishedRevision?: string | null;
|
|
153
156
|
unpublished?: boolean;
|
|
154
157
|
}>(fetcher, `/_emdash/api/plugins/${PLUGIN_ID}/design/draft`);
|
|
155
158
|
const result = validateDesign(body?.design);
|
|
159
|
+
const published = validateDesign(body?.published);
|
|
160
|
+
const design = result.ok ? result.design : emptyDesign();
|
|
156
161
|
return {
|
|
157
|
-
design
|
|
162
|
+
design,
|
|
163
|
+
...(published.ok ? { published: published.design } : {}),
|
|
158
164
|
revision: body?.revision ?? null,
|
|
159
165
|
publishedRevision: body?.publishedRevision ?? null,
|
|
160
166
|
unpublished: body?.unpublished === true,
|
|
@@ -11,8 +11,9 @@ import {
|
|
|
11
11
|
parentOf,
|
|
12
12
|
previousInOrder,
|
|
13
13
|
} from "../../core/index.ts";
|
|
14
|
+
import { runCommand, type CommandRunners } from "./editor-commands.ts";
|
|
14
15
|
import type { EditorState, HistoryAction } from "./store.ts";
|
|
15
|
-
import { isPaletteShortcut } from "./shortcuts.ts";
|
|
16
|
+
import { inDialog, isPaletteShortcut } from "./shortcuts.ts";
|
|
16
17
|
|
|
17
18
|
const isTextField = (target: EventTarget | null) => {
|
|
18
19
|
const element = target as HTMLElement | null;
|
|
@@ -24,9 +25,6 @@ const isTextField = (target: EventTarget | null) => {
|
|
|
24
25
|
);
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
const inDialog = (target: EventTarget | null) =>
|
|
28
|
-
!!(target as HTMLElement | null)?.closest?.('[role="dialog"], [role="alertdialog"]');
|
|
29
|
-
|
|
30
28
|
/**
|
|
31
29
|
* Element shortcuts (traverse, arrange, delete, duplicate, copy, paste, Escape) act only from the
|
|
32
30
|
* canvas, Layers, or with nothing focused, never from the settings panel, its tabs and section
|
|
@@ -99,9 +97,10 @@ export type ShortcutHandlers = {
|
|
|
99
97
|
|
|
100
98
|
/**
|
|
101
99
|
* Window-level editor shortcuts (W-020): save, undo and redo (W-095), duplicate, copy and paste
|
|
102
|
-
* (W-093), delete, escape, arrange and traverse. Inside text fields and
|
|
103
|
-
* typing, native undo, copy and paste keep working there. Element
|
|
104
|
-
* the canvas, Layers, or nothing (W-132); Save, undo and redo work
|
|
100
|
+
* (W-093), delete, escape, arrange and traverse. Inside text fields only Save and the palette work,
|
|
101
|
+
* and inside dialogs only Save, so typing, native undo, copy and paste keep working there. Element
|
|
102
|
+
* shortcuts also need focus on the canvas, Layers, or nothing (W-132); Save, undo and redo work
|
|
103
|
+
* from the panels too.
|
|
105
104
|
*/
|
|
106
105
|
export function useEditorShortcuts({
|
|
107
106
|
latest,
|
|
@@ -113,6 +112,16 @@ export function useEditorShortcuts({
|
|
|
113
112
|
handlers: React.RefObject<ShortcutHandlers>;
|
|
114
113
|
}): (event: KeyboardEvent) => void {
|
|
115
114
|
const onKeyDown = React.useCallback((event: KeyboardEvent) => {
|
|
115
|
+
const runners = (): CommandRunners => ({
|
|
116
|
+
save: () => handlers.current.save(),
|
|
117
|
+
remove: handlers.current.remove,
|
|
118
|
+
duplicate: handlers.current.duplicate,
|
|
119
|
+
copy: handlers.current.copy,
|
|
120
|
+
paste: handlers.current.paste,
|
|
121
|
+
pasteStyle: handlers.current.pasteStyle,
|
|
122
|
+
undo: () => dispatch({ type: "undo" }),
|
|
123
|
+
redo: () => dispatch({ type: "redo" }),
|
|
124
|
+
});
|
|
116
125
|
if (isPaletteShortcut(event)) {
|
|
117
126
|
event.preventDefault();
|
|
118
127
|
handlers.current.palette?.();
|
|
@@ -120,18 +129,18 @@ export function useEditorShortcuts({
|
|
|
120
129
|
}
|
|
121
130
|
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "s") {
|
|
122
131
|
event.preventDefault();
|
|
123
|
-
|
|
132
|
+
runCommand(runners(), "save", null);
|
|
124
133
|
return;
|
|
125
134
|
}
|
|
126
135
|
if (isTextField(event.target) || inDialog(event.target)) return;
|
|
127
136
|
if ((event.ctrlKey || event.metaKey) && !event.altKey && event.key.toLowerCase() === "z") {
|
|
128
137
|
event.preventDefault();
|
|
129
|
-
|
|
138
|
+
runCommand(runners(), event.shiftKey ? "redo" : "undo", null);
|
|
130
139
|
return;
|
|
131
140
|
}
|
|
132
141
|
if ((event.ctrlKey || event.metaKey) && !event.altKey && event.key.toLowerCase() === "y") {
|
|
133
142
|
event.preventDefault();
|
|
134
|
-
|
|
143
|
+
runCommand(runners(), "redo", null);
|
|
135
144
|
return;
|
|
136
145
|
}
|
|
137
146
|
if (!onCanvasOrLayers(event.target)) return;
|
|
@@ -139,20 +148,19 @@ export function useEditorShortcuts({
|
|
|
139
148
|
const selected = latest.current.selectedId;
|
|
140
149
|
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "d" && selected) {
|
|
141
150
|
event.preventDefault();
|
|
142
|
-
|
|
151
|
+
runCommand(runners(), "duplicate", selected);
|
|
143
152
|
return;
|
|
144
153
|
}
|
|
145
154
|
const clipKey =
|
|
146
155
|
(event.ctrlKey || event.metaKey) && !event.altKey ? event.key.toLowerCase() : "";
|
|
147
156
|
if (clipKey === "c" && !event.shiftKey && selected && !hasTextSelection(event.target)) {
|
|
148
157
|
event.preventDefault();
|
|
149
|
-
|
|
158
|
+
runCommand(runners(), "copy", selected);
|
|
150
159
|
return;
|
|
151
160
|
}
|
|
152
161
|
if (clipKey === "v" && layout) {
|
|
153
162
|
event.preventDefault();
|
|
154
|
-
|
|
155
|
-
else handlers.current.paste(selected);
|
|
163
|
+
runCommand(runners(), event.shiftKey ? "paste-style" : "paste", selected);
|
|
156
164
|
return;
|
|
157
165
|
}
|
|
158
166
|
if (event.key === "Escape" && selected) {
|
|
@@ -161,7 +169,7 @@ export function useEditorShortcuts({
|
|
|
161
169
|
}
|
|
162
170
|
if ((event.key === "Delete" || event.key === "Backspace") && selected) {
|
|
163
171
|
event.preventDefault();
|
|
164
|
-
|
|
172
|
+
runCommand(runners(), "delete", selected);
|
|
165
173
|
return;
|
|
166
174
|
}
|
|
167
175
|
if (!layout || !selected) return;
|
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
addNodeNear,
|
|
6
6
|
addSectionNear,
|
|
7
7
|
duplicateNode,
|
|
8
|
+
wrapNode,
|
|
9
|
+
type WrapType,
|
|
8
10
|
ELEMENT_DESCRIPTORS,
|
|
9
11
|
findNode,
|
|
10
12
|
moveDown,
|
|
@@ -18,7 +20,7 @@ import {
|
|
|
18
20
|
type LayoutNode,
|
|
19
21
|
} from "../../core/index.ts";
|
|
20
22
|
import { newElement } from "./dnd/new-element.ts";
|
|
21
|
-
import { ELEMENT_NAMES } from "./
|
|
23
|
+
import { ELEMENT_NAMES } from "./element-chrome.ts";
|
|
22
24
|
import type { ItemActions } from "./panels/settings/ItemList.tsx";
|
|
23
25
|
import type { EditorAction, EditorState } from "./store.ts";
|
|
24
26
|
|
|
@@ -109,6 +111,8 @@ export function useNodeActions({
|
|
|
109
111
|
};
|
|
110
112
|
|
|
111
113
|
const duplicate = (id: string) => arrange(id, duplicateNode);
|
|
114
|
+
const wrap = (id: string, type: WrapType) =>
|
|
115
|
+
arrange(id, (layout, nodeId) => wrapNode(layout, nodeId, type));
|
|
112
116
|
|
|
113
117
|
/** Accordion and Tabs item list (W-130): the parent stays selected so the list stays open. */
|
|
114
118
|
const items: ItemActions = {
|
|
@@ -200,6 +204,7 @@ export function useNodeActions({
|
|
|
200
204
|
remove,
|
|
201
205
|
arrange,
|
|
202
206
|
duplicate,
|
|
207
|
+
wrap,
|
|
203
208
|
addFromPanel,
|
|
204
209
|
addRecipe,
|
|
205
210
|
items,
|
package/src/admin/forms-api.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { ApiError, requestJson, type Fetcher } from "./api.ts";
|
|
2
2
|
|
|
3
|
-
export type FormListItem = {
|
|
3
|
+
export type FormListItem = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
slug: string;
|
|
7
|
+
/** The forms plugin's "paused" status: the form isn't accepting responses (W-326). */
|
|
8
|
+
paused?: boolean;
|
|
9
|
+
};
|
|
4
10
|
|
|
5
11
|
export type FormsCapability =
|
|
6
12
|
| { status: "ready"; forms: FormListItem[]; canList: true }
|
|
@@ -29,6 +35,8 @@ async function formsPluginAnswers(fetcher: Fetcher): Promise<boolean> {
|
|
|
29
35
|
await requestJson(fetcher, DEFINITION, { method: "POST", body: { id: "__emvb_probe__" } });
|
|
30
36
|
return true;
|
|
31
37
|
} catch (error) {
|
|
38
|
+
// A 200 with no body still means the route answered. An empty list is handled above.
|
|
39
|
+
if (error instanceof ApiError && error.code === "MISSING_DATA") return true;
|
|
32
40
|
return probeFoundPlugin(error);
|
|
33
41
|
}
|
|
34
42
|
}
|
|
@@ -36,11 +44,14 @@ async function formsPluginAnswers(fetcher: Fetcher): Promise<boolean> {
|
|
|
36
44
|
/** Probe forms plugin + list (admin). Editors get manual-id fallback (D-015). */
|
|
37
45
|
export async function loadFormsCapability(fetcher: Fetcher): Promise<FormsCapability> {
|
|
38
46
|
try {
|
|
39
|
-
const data = await requestJson<{ items: FormListItem[] }>(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
const data = await requestJson<{ items: (FormListItem & { status?: unknown })[] }>(
|
|
48
|
+
fetcher,
|
|
49
|
+
LIST,
|
|
50
|
+
{ method: "POST", body: {} },
|
|
51
|
+
);
|
|
52
|
+
const forms = (data.items ?? []).map(({ id, name, slug, status }) =>
|
|
53
|
+
status === "paused" ? { id, name, slug, paused: true } : { id, name, slug },
|
|
54
|
+
);
|
|
44
55
|
return { status: "ready", canList: true, forms };
|
|
45
56
|
} catch (error) {
|
|
46
57
|
if (error instanceof ApiError && (error.status === 401 || error.status === 403)) {
|
|
@@ -42,3 +42,21 @@ export async function uploadIconFile(
|
|
|
42
42
|
{ method: "POST", body: { name: file.name, svg } },
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
/** Renames an upload in My uploads. Icons already on a page keep the SVG they stored. */
|
|
47
|
+
export async function renameUploadedIcon(
|
|
48
|
+
fetcher: Fetcher,
|
|
49
|
+
id: string,
|
|
50
|
+
name: string,
|
|
51
|
+
): Promise<UploadedIconItem> {
|
|
52
|
+
const data = await requestJson<{ item: UploadedIconItem }>(fetcher, `${BASE}/icons/rename`, {
|
|
53
|
+
method: "POST",
|
|
54
|
+
body: { id, name },
|
|
55
|
+
});
|
|
56
|
+
return data.item;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Removes an upload from My uploads. Placed icons are unchanged. */
|
|
60
|
+
export async function deleteUploadedIcon(fetcher: Fetcher, id: string): Promise<void> {
|
|
61
|
+
await requestJson(fetcher, `${BASE}/icons/delete`, { method: "POST", body: { id } });
|
|
62
|
+
}
|
package/src/admin/index.tsx
CHANGED
|
@@ -3,15 +3,17 @@ import { installSidebarShim } from "./access/sidebar-shim.ts";
|
|
|
3
3
|
import { defaultFetcher } from "./api.ts";
|
|
4
4
|
import { EditorPage } from "./pages/EditorPage.tsx";
|
|
5
5
|
import { PagesPage } from "./pages/PagesPage.tsx";
|
|
6
|
+
import { AgentsPage } from "./pages/AgentsPage.tsx";
|
|
6
7
|
import { ThemeBuilderPage } from "./pages/ThemeBuilderPage.tsx";
|
|
7
8
|
import { LayoutField } from "./widgets/LayoutField.tsx";
|
|
8
9
|
|
|
9
10
|
if (typeof document !== "undefined") void installSidebarShim(document, defaultFetcher);
|
|
10
11
|
|
|
11
|
-
/** `/pages` and `/
|
|
12
|
+
/** `/pages`, `/theme` and `/agents` are declared; `/editor` renders by URL (D-024). */
|
|
12
13
|
export const pages: PluginAdminExports["pages"] = {
|
|
13
14
|
"/pages": PagesPage,
|
|
14
15
|
"/theme": ThemeBuilderPage,
|
|
16
|
+
"/agents": AgentsPage,
|
|
15
17
|
"/editor": EditorPage,
|
|
16
18
|
};
|
|
17
19
|
|
package/src/admin/media-api.ts
CHANGED
|
@@ -53,12 +53,32 @@ export async function uploadImage(
|
|
|
53
53
|
return payload.data.item;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/** Applies a pasted URL onto an image node's props; the URL is already sanitized. */
|
|
57
|
+
export function propsFromUrl(
|
|
58
|
+
current: Record<string, unknown>,
|
|
59
|
+
src: string,
|
|
60
|
+
): Record<string, unknown> {
|
|
61
|
+
const next: Record<string, unknown> = { ...current, src };
|
|
62
|
+
delete next.mediaId;
|
|
63
|
+
if (current.src === src) return next;
|
|
64
|
+
// W-422: a different picture drops the old one's extra sizes.
|
|
65
|
+
delete next.sources;
|
|
66
|
+
// W-425: a library image's width and height describe that file, not the pasted one.
|
|
67
|
+
if (current.mediaId) {
|
|
68
|
+
delete next.width;
|
|
69
|
+
delete next.height;
|
|
70
|
+
}
|
|
71
|
+
return next;
|
|
72
|
+
}
|
|
73
|
+
|
|
56
74
|
/** Applies a library item onto an image node's props (id, URL, alt, dimensions). */
|
|
57
75
|
export function propsFromMedia(
|
|
58
76
|
current: Record<string, unknown>,
|
|
59
77
|
item: MediaLibraryItem,
|
|
60
78
|
): Record<string, unknown> {
|
|
61
79
|
const next: Record<string, unknown> = { ...current, src: item.url, mediaId: item.id };
|
|
80
|
+
// W-422: extra sizes belong to the old picture; kept, the browser could still show it.
|
|
81
|
+
if (current.src !== item.url) delete next.sources;
|
|
62
82
|
if (item.width) next.width = item.width;
|
|
63
83
|
if (item.height) next.height = item.height;
|
|
64
84
|
const alt = current.alt;
|