@perkyzz/emvb 0.9.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/package.json +2 -2
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/bulk-api.ts +67 -0
- package/src/admin/content-api.ts +10 -6
- package/src/admin/copy-rich-text.ts +119 -0
- package/src/admin/dialog-tab-wrap.ts +78 -0
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +311 -250
- package/src/admin/editor/Timeline.tsx +8 -3
- package/src/admin/editor/TopBar.tsx +29 -7
- package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +31 -10
- package/src/admin/editor/canvas/canvas-scale.ts +3 -3
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/co-design.ts +190 -0
- package/src/admin/editor/dnd/new-element.ts +48 -4
- package/src/admin/editor/editor-chrome.tsx +8 -6
- package/src/admin/editor/editor-commands.ts +15 -4
- package/src/admin/editor/editor-css.ts +2 -1
- package/src/admin/editor/element-chrome.ts +3 -1
- package/src/admin/editor/extension-manifests.ts +20 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
- package/src/admin/editor/extensions-context.tsx +27 -0
- package/src/admin/editor/feature-css.ts +17 -0
- package/src/admin/editor/palette-items.ts +2 -2
- package/src/admin/editor/panels/AddPanel.tsx +31 -1
- package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
- package/src/admin/editor/panels/ClassesSection.tsx +9 -6
- package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ElementPanel.tsx +68 -20
- package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
- package/src/admin/editor/panels/LayersPanel.tsx +10 -6
- package/src/admin/editor/panels/LeftPanel.tsx +33 -5
- package/src/admin/editor/panels/PageSettings.tsx +4 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +72 -15
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
- package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
- package/src/admin/editor/panels/settings/EffectsControls.tsx +183 -10
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +25 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +63 -19
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +19 -1
- package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
- package/src/admin/editor/panels/settings/StyleRow.tsx +120 -13
- package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
- package/src/admin/editor/panels/settings/background-mode.ts +14 -11
- package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
- package/src/admin/editor/panels/settings/box-sides.ts +22 -14
- package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
- package/src/admin/editor/panels/settings/length-units.ts +68 -4
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +52 -10
- package/src/admin/editor/panels/style-target.ts +22 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/section-templates.ts +26 -4
- package/src/admin/editor/store.ts +14 -4
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +7 -5
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +18 -7
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/export-api.ts +221 -0
- package/src/admin/index.tsx +6 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +9 -26
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ExportDialog.tsx +395 -0
- package/src/admin/pages/ImportButton.tsx +18 -0
- package/src/admin/pages/ImportElementorDialog.tsx +669 -0
- package/src/admin/pages/ImportPageLinks.tsx +86 -0
- package/src/admin/pages/PageList.tsx +82 -3
- package/src/admin/pages/ThemePartList.tsx +52 -2
- package/src/admin/pages/bulk.tsx +303 -0
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/search.ts +20 -0
- package/src/admin/theme-api.ts +4 -0
- package/src/admin/ui.ts +50 -4
- package/src/admin/widgets/CanvasField.tsx +8 -0
- package/src/admin/widgets/ConvertToRichText.tsx +136 -0
- package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
- package/src/admin/widgets/convert-body.ts +73 -2
- package/src/astro/content-port.ts +14 -1
- package/src/astro/render.ts +6 -6
- package/src/astro/resolve-theme.ts +25 -8
- package/src/astro/resolve.ts +89 -2
- package/src/astro/tabs/runtime.ts +16 -6
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +45 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +305 -0
- package/src/core/css/generate.ts +151 -20
- package/src/core/css/scope.ts +10 -2
- package/src/core/css/trace.ts +47 -13
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +28 -9
- package/src/core/design/devices.ts +89 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +31 -5
- package/src/core/elements/dynamic-elements.ts +3 -3
- package/src/core/elements/index.ts +73 -9
- package/src/core/export/runtimes.generated.ts +9 -0
- package/src/core/export/site.ts +562 -0
- package/src/core/export/zip.ts +95 -0
- package/src/core/extensions/define.ts +13 -0
- package/src/core/extensions/index.ts +41 -0
- package/src/core/extensions/namespace.ts +82 -0
- package/src/core/extensions/normalize.ts +141 -0
- package/src/core/extensions/placeholder.ts +41 -0
- package/src/core/extensions/registry.ts +94 -0
- package/src/core/extensions/render-ext.ts +118 -0
- package/src/core/extensions/safe-nodes.ts +93 -0
- package/src/core/extensions/schema.ts +112 -0
- package/src/core/extensions/types.ts +159 -0
- package/src/core/forms/binding.ts +1 -1
- package/src/core/history/diff.ts +26 -1
- package/src/core/import/elementor/atomic.ts +1608 -0
- package/src/core/import/elementor/classes.ts +127 -0
- package/src/core/import/elementor/context.ts +429 -0
- package/src/core/import/elementor/counter-steps.ts +72 -0
- package/src/core/import/elementor/css.ts +445 -0
- package/src/core/import/elementor/html.ts +500 -0
- package/src/core/import/elementor/index.ts +967 -0
- package/src/core/import/elementor/inline-marks.ts +81 -0
- package/src/core/import/elementor/snapshots.ts +48 -0
- package/src/core/import/elementor/style.ts +429 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +96 -0
- package/src/core/json-schema.ts +114 -0
- package/src/core/limits.ts +19 -0
- package/src/core/migrate/index.ts +6 -1
- package/src/core/migrate/v18.ts +222 -0
- package/src/core/perf/meter.ts +42 -24
- package/src/core/portable-text-export.ts +243 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/public-attributes.ts +30 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +222 -23
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/tabs.ts +18 -11
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +151 -10
- package/src/core/sanitize/motion.ts +116 -0
- package/src/core/saved-sections.ts +6 -0
- package/src/core/schema/descriptors.ts +3 -1
- package/src/core/schema/design.ts +4 -3
- package/src/core/schema/layout.ts +92 -16
- package/src/core/schema/style.ts +296 -112
- package/src/core/search-text.ts +70 -0
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +2 -0
- package/src/core/theme/popup-rules.ts +33 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +24 -0
- package/src/mcp/errors.ts +3 -1
- package/src/mcp/ports.ts +67 -0
- package/src/mcp/prompts.ts +1 -11
- package/src/mcp/proposals.ts +281 -0
- package/src/mcp/read.ts +10 -10
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +5 -1
- package/src/server/icon-routes.ts +52 -12
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +35 -2
- package/src/server/presence.ts +78 -0
- package/src/server/proposals.ts +261 -0
- package/src/server/requests.ts +196 -0
- package/src/server/tools-served.ts +45 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { DesignSystem } from "../../core/schema/design.ts";
|
|
3
|
+
import {
|
|
4
|
+
cancelRequest,
|
|
5
|
+
createRequest,
|
|
6
|
+
recordAccepted,
|
|
7
|
+
withdrawProposal,
|
|
8
|
+
type PendingProposal,
|
|
9
|
+
} from "../proposals-api.ts";
|
|
10
|
+
import { ApiError, type Fetcher } from "../api.ts";
|
|
11
|
+
import { acceptOps, ghostCss, ghostOf, type EditorBase, type Ghost } from "./co-design.ts";
|
|
12
|
+
import type { EditorAction, EditorState } from "./store.ts";
|
|
13
|
+
import { useProposals, type ProposalsState } from "./useProposals.ts";
|
|
14
|
+
|
|
15
|
+
export type Decision = "accepted" | "rejected";
|
|
16
|
+
|
|
17
|
+
export type CoDesign = {
|
|
18
|
+
proposals: ProposalsState;
|
|
19
|
+
/** Per proposal id, per op index. Undecided ops are pending. */
|
|
20
|
+
decisions: Record<string, Record<number, Decision>>;
|
|
21
|
+
pending: (p: PendingProposal) => number[];
|
|
22
|
+
accept: (p: PendingProposal, indexes: readonly number[]) => void;
|
|
23
|
+
reject: (p: PendingProposal, indexes: readonly number[]) => void;
|
|
24
|
+
/** The proposal shown as a ghost on the canvas, if any. */
|
|
25
|
+
previewId: string | null;
|
|
26
|
+
setPreviewId: (id: string | null) => void;
|
|
27
|
+
ghost: (Ghost & { css: string }) | null;
|
|
28
|
+
/** Why the last accept was refused, in the editor's words. */
|
|
29
|
+
error: string | null;
|
|
30
|
+
clearError: () => void;
|
|
31
|
+
/** Changes accepted since the last save. */
|
|
32
|
+
unsaved: number;
|
|
33
|
+
/** W-931: sends a request to the person's agent; resolves to an error message, or null. */
|
|
34
|
+
ask: (prompt: string) => Promise<string | null>;
|
|
35
|
+
cancel: (requestId: string) => Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** The editor state as a proposal base, with the style revision the server compares against. */
|
|
39
|
+
const editorBase = (state: EditorState): EditorBase => ({
|
|
40
|
+
rev: state.rev,
|
|
41
|
+
layout: state.page.layout,
|
|
42
|
+
design: state.design,
|
|
43
|
+
designRevision: state.designRevision ?? state.publishedRevision ?? null,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const stalePage =
|
|
47
|
+
"This proposal was made for an earlier version of the page. Ask the agent to propose again.";
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* W-930: review state for the co-design panel. Accepted page changes are one undoable edit each
|
|
51
|
+
* (`apply-arranged`); accepted class and variable changes go through the normal style draft save.
|
|
52
|
+
* A proposal is withdrawn once every change in it is decided, and the next Save draft after any
|
|
53
|
+
* accept is labelled "Via agent" in the timeline.
|
|
54
|
+
*/
|
|
55
|
+
export function useCoDesign({
|
|
56
|
+
fetcher,
|
|
57
|
+
collection,
|
|
58
|
+
state,
|
|
59
|
+
dispatch,
|
|
60
|
+
changeDesign,
|
|
61
|
+
onError,
|
|
62
|
+
enabled = true,
|
|
63
|
+
}: {
|
|
64
|
+
fetcher: Fetcher;
|
|
65
|
+
collection: string;
|
|
66
|
+
state: EditorState;
|
|
67
|
+
dispatch: (action: EditorAction) => void;
|
|
68
|
+
changeDesign: (design: DesignSystem) => Promise<unknown>;
|
|
69
|
+
onError: (message: string) => void;
|
|
70
|
+
/** Off in field mode: agents propose to EmVB pages only. */
|
|
71
|
+
enabled?: boolean;
|
|
72
|
+
}): CoDesign {
|
|
73
|
+
const proposals = useProposals(fetcher, collection, state.id, enabled);
|
|
74
|
+
const [decisions, setDecisions] = React.useState<CoDesign["decisions"]>({});
|
|
75
|
+
const [previewId, setPreviewId] = React.useState<string | null>(null);
|
|
76
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
77
|
+
const [unsaved, setUnsaved] = React.useState(0);
|
|
78
|
+
const latest = React.useRef(state);
|
|
79
|
+
latest.current = state;
|
|
80
|
+
|
|
81
|
+
const pending = React.useCallback(
|
|
82
|
+
(p: PendingProposal) =>
|
|
83
|
+
p.proposal.ops.map((_, i) => i).filter((i) => decisions[p.id]?.[i] === undefined),
|
|
84
|
+
[decisions],
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const decide = (p: PendingProposal, indexes: readonly number[], decision: Decision) => {
|
|
88
|
+
const next = { ...decisions[p.id] };
|
|
89
|
+
for (const i of indexes) next[i] = decision;
|
|
90
|
+
setDecisions((all) => ({ ...all, [p.id]: next }));
|
|
91
|
+
if (p.proposal.ops.every((_, i) => next[i] !== undefined)) {
|
|
92
|
+
if (previewId === p.id) setPreviewId(null);
|
|
93
|
+
const decided = Object.values(next);
|
|
94
|
+
withdrawProposal(fetcher, p.id, {
|
|
95
|
+
accepted: decided.filter((d) => d === "accepted").length,
|
|
96
|
+
rejected: decided.filter((d) => d === "rejected").length,
|
|
97
|
+
}).then(proposals.refresh, () => undefined);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const accept = (p: PendingProposal, indexes: readonly number[]) => {
|
|
102
|
+
const current = latest.current;
|
|
103
|
+
const result = acceptOps(editorBase(current), p.proposal, indexes);
|
|
104
|
+
if (!result.ok) {
|
|
105
|
+
setError(result.code === "STALE_BASE" ? stalePage : result.reason);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
setError(null);
|
|
109
|
+
dispatch({
|
|
110
|
+
type: "apply-arranged",
|
|
111
|
+
layout: result.layout,
|
|
112
|
+
selected: current.selectedId ?? result.layout.root.id,
|
|
113
|
+
});
|
|
114
|
+
if (result.designChanged) {
|
|
115
|
+
changeDesign(result.design).catch((e: unknown) =>
|
|
116
|
+
onError(e instanceof Error ? e.message : "Couldn't save the accepted site styles."),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
setUnsaved((n) => n + indexes.length);
|
|
120
|
+
decide(p, indexes, "accepted");
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const reject = (p: PendingProposal, indexes: readonly number[]) => {
|
|
124
|
+
setError(null);
|
|
125
|
+
decide(p, indexes, "rejected");
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// The next save after an accept is a normal version, labelled "Via agent" (W-930).
|
|
129
|
+
const savedRev = React.useRef(state.rev);
|
|
130
|
+
const unsavedRef = React.useRef(unsaved);
|
|
131
|
+
unsavedRef.current = unsaved;
|
|
132
|
+
React.useEffect(() => {
|
|
133
|
+
if (state.rev === savedRev.current) return;
|
|
134
|
+
savedRev.current = state.rev;
|
|
135
|
+
const accepted = unsavedRef.current;
|
|
136
|
+
if (accepted <= 0) return;
|
|
137
|
+
setUnsaved(0);
|
|
138
|
+
recordAccepted(fetcher, collection, state.id, accepted).catch(() => undefined);
|
|
139
|
+
}, [state.rev, fetcher, collection, state.id]);
|
|
140
|
+
|
|
141
|
+
const previewed = proposals.items.find((p) => p.id === previewId) ?? null;
|
|
142
|
+
const ghost = React.useMemo(() => {
|
|
143
|
+
if (!previewed) return null;
|
|
144
|
+
const g = ghostOf(editorBase(state), previewed.proposal, pending(previewed));
|
|
145
|
+
return g ? { ...g, css: ghostCss(g) } : null;
|
|
146
|
+
}, [previewed, state, pending]);
|
|
147
|
+
|
|
148
|
+
const ask = async (prompt: string) => {
|
|
149
|
+
try {
|
|
150
|
+
await createRequest(fetcher, collection, state.id, prompt);
|
|
151
|
+
proposals.refresh();
|
|
152
|
+
return null;
|
|
153
|
+
} catch (e) {
|
|
154
|
+
return e instanceof ApiError ? e.message : "Couldn't send the request. Try again.";
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const cancel = async (requestId: string) => {
|
|
158
|
+
await cancelRequest(fetcher, requestId).catch(() => undefined);
|
|
159
|
+
proposals.refresh();
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
ask,
|
|
164
|
+
cancel,
|
|
165
|
+
proposals,
|
|
166
|
+
decisions,
|
|
167
|
+
pending,
|
|
168
|
+
accept,
|
|
169
|
+
reject,
|
|
170
|
+
previewId: previewed ? previewId : null,
|
|
171
|
+
setPreviewId,
|
|
172
|
+
ghost,
|
|
173
|
+
error,
|
|
174
|
+
clearError: () => setError(null),
|
|
175
|
+
unsaved,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -3,9 +3,10 @@ import type { createKumoToastManager } from "@cloudflare/kumo";
|
|
|
3
3
|
import { ArrowSquareOutIcon } from "@phosphor-icons/react";
|
|
4
4
|
import {
|
|
5
5
|
DEVICE_PREVIEW_PX,
|
|
6
|
+
WIDE_PREVIEW_PX,
|
|
6
7
|
mergeDesign,
|
|
7
8
|
type DesignSystem,
|
|
8
|
-
type
|
|
9
|
+
type EditorDevice,
|
|
9
10
|
} from "../../core/index.ts";
|
|
10
11
|
import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
11
12
|
import { ApiError, type Fetcher } from "../api.ts";
|
|
@@ -19,15 +20,16 @@ const publicPath = (pattern: string | null | undefined, slug: string) =>
|
|
|
19
20
|
(pattern || "/{slug}").replace("{slug}", encodeURIComponent(slug));
|
|
20
21
|
|
|
21
22
|
/** Window heights for the sized Tablet and Mobile previews (W-158); widths are the canvas's. */
|
|
22
|
-
const PREVIEW_HEIGHT = { tablet: 1024, mobile: 844 } as const;
|
|
23
|
+
const PREVIEW_HEIGHT = { wide: 1440, laptop: 800, tablet: 1024, mobile: 844 } as const;
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* `window.open` features for a device preview (W-158): Desktop is an ordinary tab; Tablet and
|
|
26
27
|
* Mobile open a window whose page area is the device width, so the page's own media queries apply.
|
|
27
28
|
*/
|
|
28
|
-
export function previewWindowFeatures(device:
|
|
29
|
+
export function previewWindowFeatures(device: EditorDevice): string | undefined {
|
|
29
30
|
if (device === "desktop") return undefined;
|
|
30
|
-
|
|
31
|
+
const width = device === "wide" ? WIDE_PREVIEW_PX : DEVICE_PREVIEW_PX[device];
|
|
32
|
+
return `popup,width=${width},height=${PREVIEW_HEIGHT[device]}`;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/**
|
|
@@ -137,7 +139,7 @@ export function useEditorCommands({
|
|
|
137
139
|
});
|
|
138
140
|
};
|
|
139
141
|
|
|
140
|
-
const preview = (device:
|
|
142
|
+
const preview = (device: EditorDevice = "desktop") =>
|
|
141
143
|
void openInNewTab(
|
|
142
144
|
async () => {
|
|
143
145
|
if (isDirty(latest.current) && !(await save())) return null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { PLUGIN_ID } from "../../constants.ts";
|
|
3
|
+
import type { ExtensionManifest } from "../../core/index.ts";
|
|
4
|
+
import { requestJson, type Fetcher } from "../api.ts";
|
|
5
|
+
import { setAdminExtensionManifests } from "./extension-manifests.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* W-927: extension manifests from `emvb({ extensions })`, via the plugin's editor/config route.
|
|
9
|
+
* Empty while loading and when the route fails or no extensions are registered.
|
|
10
|
+
*/
|
|
11
|
+
export function useExtensionManifests(fetcher: Fetcher): readonly ExtensionManifest[] {
|
|
12
|
+
const [loaded, setLoaded] = React.useState<readonly ExtensionManifest[]>([]);
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
let cancelled = false;
|
|
15
|
+
void requestJson<{ extensions?: unknown }>(
|
|
16
|
+
fetcher,
|
|
17
|
+
`/_emdash/api/plugins/${PLUGIN_ID}/editor/config`,
|
|
18
|
+
)
|
|
19
|
+
.then((body) => {
|
|
20
|
+
if (cancelled) return;
|
|
21
|
+
const list = Array.isArray(body?.extensions) ? body.extensions : [];
|
|
22
|
+
const ok: ExtensionManifest[] = [];
|
|
23
|
+
for (const item of list) {
|
|
24
|
+
if (!item || typeof item !== "object") continue;
|
|
25
|
+
const m = item as ExtensionManifest;
|
|
26
|
+
if (m.extensionApi !== 1 || typeof m.id !== "string") continue;
|
|
27
|
+
ok.push(m);
|
|
28
|
+
}
|
|
29
|
+
setAdminExtensionManifests(ok);
|
|
30
|
+
setLoaded(ok);
|
|
31
|
+
})
|
|
32
|
+
.catch(() => undefined);
|
|
33
|
+
return () => {
|
|
34
|
+
cancelled = true;
|
|
35
|
+
};
|
|
36
|
+
}, [fetcher]);
|
|
37
|
+
return loaded;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Flat list of element manifests for Add panel and inspector. */
|
|
41
|
+
export function extensionElementManifests(
|
|
42
|
+
extensions: readonly ExtensionManifest[],
|
|
43
|
+
): ExtensionManifest["elements"][number][] {
|
|
44
|
+
return extensions.flatMap((ext) => [...ext.elements]);
|
|
45
|
+
}
|
|
@@ -24,7 +24,8 @@ import {
|
|
|
24
24
|
type Layout,
|
|
25
25
|
type LayoutNode,
|
|
26
26
|
} from "../../core/index.ts";
|
|
27
|
-
import {
|
|
27
|
+
import { adminExtensionDefaults } from "./extension-manifests.ts";
|
|
28
|
+
import { newElement, withLoopPostTitleLevel, withPageHeadingLevel } from "./dnd/new-element.ts";
|
|
28
29
|
import { ELEMENT_NAMES } from "./element-chrome.ts";
|
|
29
30
|
import type { ItemActions } from "./panels/settings/ItemList.tsx";
|
|
30
31
|
import type { EditorAction, EditorState } from "./store.ts";
|
|
@@ -211,7 +212,9 @@ export function useNodeActions({
|
|
|
211
212
|
notice(result.reason);
|
|
212
213
|
return;
|
|
213
214
|
}
|
|
214
|
-
|
|
215
|
+
// W-968: a Post title placed inside a Loop starts as an H2.
|
|
216
|
+
const placed = withLoopPostTitleLevel(result.layout, node.id, latest.current.page.partType);
|
|
217
|
+
dispatch({ type: "apply-arranged", layout: placed, selected: result.selected });
|
|
215
218
|
const nameOf = (id: string) => ELEMENT_NAMES[findNode(layout, id)?.type ?? "container"];
|
|
216
219
|
if (result.fallback) {
|
|
217
220
|
// Added next to the nearest ancestor that takes it, rather than refused (W-175).
|
|
@@ -222,7 +225,7 @@ export function useNodeActions({
|
|
|
222
225
|
announce(`${label} added inside ${nameOf(result.parentId) ?? "Container"}`);
|
|
223
226
|
};
|
|
224
227
|
|
|
225
|
-
const addFromPanel = (type: ElementType) => {
|
|
228
|
+
const addFromPanel = (type: ElementType | string) => {
|
|
226
229
|
const current = latest.current.page.layout;
|
|
227
230
|
if (!current && type === "container") {
|
|
228
231
|
dispatch({ type: "add-root-container" });
|
|
@@ -231,9 +234,17 @@ export function useNodeActions({
|
|
|
231
234
|
// UX-094: an empty page (one made outside EmVB has no layout) gets its container first, so
|
|
232
235
|
// a click or palette insert lands instead of doing nothing.
|
|
233
236
|
const layout = current ?? startingLayout();
|
|
234
|
-
const
|
|
235
|
-
if (!
|
|
236
|
-
|
|
237
|
+
const added = newElement(type, undefined, adminExtensionDefaults(type));
|
|
238
|
+
if (!added) return;
|
|
239
|
+
// W-946: a click or palette insert picks the heading level the way a drop does.
|
|
240
|
+
const node = withPageHeadingLevel(added, layout, latest.current.page.partType);
|
|
241
|
+
const builtInName = ELEMENT_DESCRIPTORS.find((d) => d.type === type)?.name;
|
|
242
|
+
const label = builtInName
|
|
243
|
+
? builtInName
|
|
244
|
+
: type.startsWith("ext:")
|
|
245
|
+
? type.slice(type.lastIndexOf("/") + 1)
|
|
246
|
+
: type;
|
|
247
|
+
place(layout, node, label);
|
|
237
248
|
};
|
|
238
249
|
|
|
239
250
|
/** A section recipe built from the site's styles (W-320). */
|
|
@@ -241,7 +252,7 @@ export function useNodeActions({
|
|
|
241
252
|
const layout = latest.current.page.layout ?? startingLayout();
|
|
242
253
|
const node = recipeNode(id, latest.current.design, layout);
|
|
243
254
|
if (!node) return;
|
|
244
|
-
place(layout, withFreshIds(layout, node), `${node.
|
|
255
|
+
place(layout, withFreshIds(layout, node), `${node.editorLabel ?? "Section"} section`, true);
|
|
245
256
|
};
|
|
246
257
|
|
|
247
258
|
return {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
listProposals,
|
|
4
|
+
listRequests,
|
|
5
|
+
type AgentRequest,
|
|
6
|
+
type PendingProposal,
|
|
7
|
+
} from "../proposals-api.ts";
|
|
8
|
+
import type { Fetcher } from "../api.ts";
|
|
9
|
+
|
|
10
|
+
/** How often the open editor asks for new proposals (D-063: EmDash's MCP has no push). */
|
|
11
|
+
const POLL_MS = 5_000;
|
|
12
|
+
|
|
13
|
+
export type ProposalsState = {
|
|
14
|
+
items: PendingProposal[];
|
|
15
|
+
/** True once the first request answered; false while loading or after a failure. */
|
|
16
|
+
ready: boolean;
|
|
17
|
+
failed: boolean;
|
|
18
|
+
refresh: () => void;
|
|
19
|
+
/** W-931: the page's requests for agents, newest first. */
|
|
20
|
+
requests: AgentRequest[];
|
|
21
|
+
/** When an agent last checked for requests (any page), or null if none has yet. */
|
|
22
|
+
agentSeenAt: string | null;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* W-930: polls the page's proposals while the tab is visible. A failed poll keeps the last list
|
|
27
|
+
* and says so; the next tick retries.
|
|
28
|
+
*/
|
|
29
|
+
export function useProposals(
|
|
30
|
+
fetcher: Fetcher,
|
|
31
|
+
collection: string,
|
|
32
|
+
id: string,
|
|
33
|
+
enabled = true,
|
|
34
|
+
): ProposalsState {
|
|
35
|
+
const [items, setItems] = React.useState<PendingProposal[]>([]);
|
|
36
|
+
const [ready, setReady] = React.useState(false);
|
|
37
|
+
const [failed, setFailed] = React.useState(false);
|
|
38
|
+
const [tick, setTick] = React.useState(0);
|
|
39
|
+
const [requests, setRequests] = React.useState<AgentRequest[]>([]);
|
|
40
|
+
const [agentSeenAt, setAgentSeenAt] = React.useState<string | null>(null);
|
|
41
|
+
const refresh = React.useCallback(() => setTick((t) => t + 1), []);
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (!enabled) return;
|
|
44
|
+
let cancelled = false;
|
|
45
|
+
const load = () => {
|
|
46
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
47
|
+
listRequests(fetcher, collection, id).then(
|
|
48
|
+
(next) => {
|
|
49
|
+
if (cancelled) return;
|
|
50
|
+
setRequests((prev) => (sameRequests(prev, next.items) ? prev : next.items));
|
|
51
|
+
setAgentSeenAt(next.agentSeenAt);
|
|
52
|
+
},
|
|
53
|
+
() => undefined,
|
|
54
|
+
);
|
|
55
|
+
listProposals(fetcher, collection, id).then(
|
|
56
|
+
(next) => {
|
|
57
|
+
if (cancelled) return;
|
|
58
|
+
setItems((prev) => (sameList(prev, next) ? prev : next));
|
|
59
|
+
setReady(true);
|
|
60
|
+
setFailed(false);
|
|
61
|
+
},
|
|
62
|
+
() => {
|
|
63
|
+
if (!cancelled) setFailed(true);
|
|
64
|
+
},
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
load();
|
|
68
|
+
const timer = setInterval(load, POLL_MS);
|
|
69
|
+
return () => {
|
|
70
|
+
cancelled = true;
|
|
71
|
+
clearInterval(timer);
|
|
72
|
+
};
|
|
73
|
+
}, [fetcher, collection, id, tick, enabled]);
|
|
74
|
+
return { items, ready, failed, refresh, requests, agentSeenAt };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const sameList = (a: PendingProposal[], b: PendingProposal[]) =>
|
|
78
|
+
a.length === b.length && a.every((p, i) => p.id === b[i]?.id);
|
|
79
|
+
|
|
80
|
+
const sameRequests = (a: AgentRequest[], b: AgentRequest[]) =>
|
|
81
|
+
a.length === b.length && a.every((r, i) => r.id === b[i]?.id && r.status === b[i]?.status);
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildSiteExport,
|
|
3
|
+
withCopiedMedia,
|
|
4
|
+
type ExportPageInput,
|
|
5
|
+
type ExportPartInput,
|
|
6
|
+
type SiteExport,
|
|
7
|
+
} from "../core/export/site.ts";
|
|
8
|
+
import { zipFiles } from "../core/export/zip.ts";
|
|
9
|
+
import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../constants.ts";
|
|
10
|
+
import { listAllItems, type Fetcher } from "./api.ts";
|
|
11
|
+
import { titleOf, type ContentItem } from "./content-item.ts";
|
|
12
|
+
import { loadDesign } from "./editor/useEditorData.ts";
|
|
13
|
+
import { loadHostCollections } from "./setup/host-collections.ts";
|
|
14
|
+
import { readCollection } from "./setup/run.ts";
|
|
15
|
+
import { readFieldLayout } from "./widgets/field-fetcher.ts";
|
|
16
|
+
|
|
17
|
+
/** Only what visitors see: published entries (a saved draft on top stays out). */
|
|
18
|
+
const isLive = (item: ContentItem) => item.status === "published";
|
|
19
|
+
|
|
20
|
+
/** A canvas field holding a layout with at least one element. */
|
|
21
|
+
const hasLayout = (value: unknown) => {
|
|
22
|
+
const layout = readFieldLayout(value);
|
|
23
|
+
return !!layout && (layout.root.children ?? []).length > 0;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* W-977: one of your collections whose entries carry an EmVB layout (an `emvb:canvas` field), and
|
|
28
|
+
* where its entries are on the site.
|
|
29
|
+
*/
|
|
30
|
+
export type CanvasSource = {
|
|
31
|
+
collection: string;
|
|
32
|
+
label: string;
|
|
33
|
+
field: string;
|
|
34
|
+
urlPattern?: string | null;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Published entries of `source` with a layout, for picking one to export (W-977). */
|
|
38
|
+
export async function exportableEntries(
|
|
39
|
+
fetcher: Fetcher,
|
|
40
|
+
source: CanvasSource,
|
|
41
|
+
): Promise<{ id: string; title: string }[]> {
|
|
42
|
+
const items = await listAllItems<ContentItem>(
|
|
43
|
+
fetcher,
|
|
44
|
+
`/_emdash/api/content/${source.collection}`,
|
|
45
|
+
);
|
|
46
|
+
return items
|
|
47
|
+
.filter((item) => isLive(item) && hasLayout(item.data?.[source.field]))
|
|
48
|
+
.map((item) => ({ id: item.id, title: titleOf(item, "Untitled entry") }))
|
|
49
|
+
.toSorted((a, b) => a.title.localeCompare(b.title));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Collections with a canvas field, to export their entries like pages. */
|
|
53
|
+
export async function canvasSources(fetcher: Fetcher): Promise<CanvasSource[]> {
|
|
54
|
+
const { rows } = await loadHostCollections(fetcher);
|
|
55
|
+
const ready = rows.filter((row) => row.field === "ready" && row.fieldSlug);
|
|
56
|
+
const states = await Promise.all(ready.map((row) => readCollection(fetcher, row.slug)));
|
|
57
|
+
return ready.map((row, i) => ({
|
|
58
|
+
collection: row.slug,
|
|
59
|
+
label: row.label,
|
|
60
|
+
field: row.fieldSlug as string,
|
|
61
|
+
urlPattern: states[i]?.urlPattern ?? null,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* An entry's public path from its collection's URL pattern (`/blog/{slug}`, `{id}` too). Without
|
|
67
|
+
* a pattern EmDash serves entries at `/<collection>/<slug>` (W-980).
|
|
68
|
+
*/
|
|
69
|
+
export function entryPath(
|
|
70
|
+
pattern: string | null | undefined,
|
|
71
|
+
entry: { collection: string; slug: string; id: string },
|
|
72
|
+
): string {
|
|
73
|
+
const path = (pattern || `/${entry.collection}/{slug}`)
|
|
74
|
+
.replaceAll("{slug}", encodeURIComponent(entry.slug))
|
|
75
|
+
.replaceAll("{id}", encodeURIComponent(entry.id));
|
|
76
|
+
return path.startsWith("/") ? path : `/${path}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Published pages (or one), published theme parts and the published Site styles. */
|
|
80
|
+
export async function loadExportData(
|
|
81
|
+
fetcher: Fetcher,
|
|
82
|
+
/** One id, or (W-978) the ticked ones. */
|
|
83
|
+
onlyPageId?: string | readonly string[],
|
|
84
|
+
/** W-977: export this collection's entries (their canvas layouts) instead of EmVB pages. */
|
|
85
|
+
source?: CanvasSource,
|
|
86
|
+
) {
|
|
87
|
+
const [pageItems, partItems, design] = await Promise.all([
|
|
88
|
+
listAllItems<ContentItem>(
|
|
89
|
+
fetcher,
|
|
90
|
+
`/_emdash/api/content/${source ? source.collection : PAGES_COLLECTION}`,
|
|
91
|
+
),
|
|
92
|
+
listAllItems<ContentItem>(fetcher, `/_emdash/api/content/${THEME_PARTS_COLLECTION}`),
|
|
93
|
+
loadDesign(fetcher),
|
|
94
|
+
]);
|
|
95
|
+
const pages: ExportPageInput[] = pageItems
|
|
96
|
+
.filter(
|
|
97
|
+
(item) =>
|
|
98
|
+
isLive(item) &&
|
|
99
|
+
(!onlyPageId ||
|
|
100
|
+
(typeof onlyPageId === "string" ? item.id === onlyPageId : onlyPageId.includes(item.id))),
|
|
101
|
+
)
|
|
102
|
+
// An entry without a layout shows the site's own template, which an export can't hold.
|
|
103
|
+
.filter((item) => !source || hasLayout(item.data?.[source.field]))
|
|
104
|
+
.map((item) => {
|
|
105
|
+
const slug = item.slug ?? "";
|
|
106
|
+
const page: ExportPageInput = {
|
|
107
|
+
id: item.id,
|
|
108
|
+
title: titleOf(item, source ? "Untitled entry" : "Untitled page"),
|
|
109
|
+
slug,
|
|
110
|
+
layout: source ? readFieldLayout(item.data?.[source.field]) : item.data?.["layout"],
|
|
111
|
+
};
|
|
112
|
+
if (source) {
|
|
113
|
+
page.collection = source.collection;
|
|
114
|
+
page.path = entryPath(source.urlPattern, {
|
|
115
|
+
collection: source.collection,
|
|
116
|
+
slug,
|
|
117
|
+
id: item.id,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (item.seo?.description) page.description = item.seo.description;
|
|
121
|
+
return page;
|
|
122
|
+
})
|
|
123
|
+
.toSorted((a, b) => a.title.localeCompare(b.title));
|
|
124
|
+
const parts: ExportPartInput[] = partItems.filter(isLive).map((item) => ({
|
|
125
|
+
id: item.id,
|
|
126
|
+
title: titleOf(item, ""),
|
|
127
|
+
partType: item.data?.["part_type"],
|
|
128
|
+
layout: item.data?.["layout"],
|
|
129
|
+
conditions: item.data?.["conditions"],
|
|
130
|
+
triggers: item.data?.["triggers"],
|
|
131
|
+
float: item.data?.["float"],
|
|
132
|
+
updatedAt: item.updatedAt ?? "",
|
|
133
|
+
}));
|
|
134
|
+
return { pages, parts, design: design.published ?? design.design };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Media this site serves itself (same origin), which the export can copy. */
|
|
138
|
+
export function copyableMedia(urls: readonly string[], origin: string): string[] {
|
|
139
|
+
return urls.filter((url) => {
|
|
140
|
+
try {
|
|
141
|
+
return new URL(url, origin).origin === origin;
|
|
142
|
+
} catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Up to this many media files are copied, so an export can't fill the browser's memory. */
|
|
149
|
+
const MAX_COPIED_MEDIA = 500;
|
|
150
|
+
const MAX_COPIED_BYTES = 200 * 1024 * 1024;
|
|
151
|
+
|
|
152
|
+
/** Downloads media for the export; files that fail are left as links (and counted). */
|
|
153
|
+
async function fetchMedia(
|
|
154
|
+
urls: readonly string[],
|
|
155
|
+
origin: string,
|
|
156
|
+
get: (url: string) => Promise<Response>,
|
|
157
|
+
): Promise<{ copies: Map<string, Uint8Array>; failed: number }> {
|
|
158
|
+
const copies = new Map<string, Uint8Array>();
|
|
159
|
+
let failed = 0;
|
|
160
|
+
let total = 0;
|
|
161
|
+
for (const url of urls.slice(0, MAX_COPIED_MEDIA)) {
|
|
162
|
+
try {
|
|
163
|
+
// oxlint-disable-next-line no-await-in-loop -- one at a time keeps memory and load low
|
|
164
|
+
const response = await get(new URL(url, origin).href);
|
|
165
|
+
if (!response.ok) throw new Error(String(response.status));
|
|
166
|
+
// oxlint-disable-next-line no-await-in-loop -- same
|
|
167
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
168
|
+
total += bytes.length;
|
|
169
|
+
if (total > MAX_COPIED_BYTES) {
|
|
170
|
+
failed += 1;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
copies.set(url, bytes);
|
|
174
|
+
} catch {
|
|
175
|
+
failed += 1;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
failed += Math.max(0, urls.length - MAX_COPIED_MEDIA);
|
|
179
|
+
return { copies, failed };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export type ExportResult = {
|
|
183
|
+
zip: Uint8Array;
|
|
184
|
+
site: SiteExport;
|
|
185
|
+
copied: number;
|
|
186
|
+
failed: number;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/** The whole export as a zip, built in the browser from published content. */
|
|
190
|
+
export async function exportSite(
|
|
191
|
+
fetcher: Fetcher,
|
|
192
|
+
options: {
|
|
193
|
+
onlyPageId?: string | readonly string[];
|
|
194
|
+
/** W-977: a collection with a canvas field instead of EmVB pages. */
|
|
195
|
+
source?: CanvasSource;
|
|
196
|
+
copyMedia: boolean;
|
|
197
|
+
origin: string;
|
|
198
|
+
get?: (url: string) => Promise<Response>;
|
|
199
|
+
date?: string;
|
|
200
|
+
},
|
|
201
|
+
): Promise<ExportResult> {
|
|
202
|
+
const data = await loadExportData(fetcher, options.onlyPageId, options.source);
|
|
203
|
+
let site = buildSiteExport({
|
|
204
|
+
...data,
|
|
205
|
+
...(options.date ? { date: options.date } : {}),
|
|
206
|
+
});
|
|
207
|
+
let copied = 0;
|
|
208
|
+
let failed = 0;
|
|
209
|
+
if (options.copyMedia) {
|
|
210
|
+
const get = options.get ?? ((url: string) => fetch(url, { credentials: "same-origin" }));
|
|
211
|
+
const result = await fetchMedia(
|
|
212
|
+
copyableMedia(site.report.media, options.origin),
|
|
213
|
+
options.origin,
|
|
214
|
+
get,
|
|
215
|
+
);
|
|
216
|
+
site = withCopiedMedia(site, result.copies);
|
|
217
|
+
copied = result.copies.size;
|
|
218
|
+
failed = result.failed;
|
|
219
|
+
}
|
|
220
|
+
return { zip: zipFiles(site.files), site, copied, failed };
|
|
221
|
+
}
|
package/src/admin/index.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PluginAdminExports } from "emdash";
|
|
2
2
|
import { installSidebarShim } from "./access/sidebar-shim.ts";
|
|
3
3
|
import { defaultFetcher } from "./api.ts";
|
|
4
|
+
import { installDialogTabWrap } from "./dialog-tab-wrap.ts";
|
|
4
5
|
import { EditorPage } from "./pages/EditorPage.tsx";
|
|
5
6
|
import { PagesPage } from "./pages/PagesPage.tsx";
|
|
6
7
|
import { AgentsPage } from "./pages/AgentsPage.tsx";
|
|
@@ -9,7 +10,11 @@ import { ThemeBuilderPage } from "./pages/ThemeBuilderPage.tsx";
|
|
|
9
10
|
import { CanvasField } from "./widgets/CanvasField.tsx";
|
|
10
11
|
import { LayoutField } from "./widgets/LayoutField.tsx";
|
|
11
12
|
|
|
12
|
-
if (typeof document !== "undefined")
|
|
13
|
+
if (typeof document !== "undefined") {
|
|
14
|
+
void installSidebarShim(document, defaultFetcher);
|
|
15
|
+
// W-984: Tab stays inside EmVB dialogs.
|
|
16
|
+
installDialogTabWrap(document);
|
|
17
|
+
}
|
|
13
18
|
|
|
14
19
|
/** `/pages`, `/theme`, `/agents` and `/collections` are declared; `/editor` renders by URL (D-024). */
|
|
15
20
|
export const pages: PluginAdminExports["pages"] = {
|