@perkyzz/emvb 0.3.0 → 0.4.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 +1 -1
- package/package.json +3 -1
- package/src/admin/access/role.ts +9 -3
- 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/Editor.tsx +106 -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 +16 -3
- 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/element-chrome.ts +89 -0
- package/src/admin/editor/feature-css.ts +15 -15
- 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 +3 -2
- package/src/admin/editor/panels/AddPanel.tsx +2 -67
- package/src/admin/editor/panels/ColorControl.tsx +2 -10
- 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/VariableSection.tsx +1 -10
- package/src/admin/editor/panels/inline-error.tsx +11 -0
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +73 -3
- package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
- package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -2
- 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/style-sections.ts +5 -1
- package/src/admin/editor/panels/style-target.ts +105 -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/theme-api.ts +5 -18
- package/src/astro/content-port.ts +24 -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/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/theme-posts.ts +16 -5
- package/src/astro/visitor.ts +67 -5
- package/src/constants.ts +1 -1
- package/src/core/arrange.ts +63 -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 +9 -0
- 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 +1 -0
- package/src/core/elements/index.ts +183 -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 +1 -2
- package/src/core/render/form.ts +133 -10
- package/src/core/render/index.ts +155 -13
- package/src/core/render/vnode.ts +12 -2
- package/src/core/sanitize/css.ts +90 -77
- package/src/core/sanitize/svg.ts +8 -3
- package/src/core/sanitize/url.ts +10 -1
- package/src/core/schema/design.ts +5 -7
- package/src/core/schema/layout.ts +153 -181
- package/src/core/schema/style.ts +53 -63
- package/src/core/share/link.ts +68 -28
- package/src/core/tabs/presence.ts +7 -17
- package/src/core/theme/dynamic.ts +200 -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/server/design-routes.ts +4 -1
- package/src/server/icon-routes.ts +68 -16
- package/src/server/plugin.ts +8 -2
- 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,360 @@
|
|
|
1
|
+
import type { PasteMode, PopupDevice, WrapType } from "../../core/index.ts";
|
|
2
|
+
|
|
3
|
+
/** Where an editor command is offered. Shortcuts call `runCommand` for the same ids. */
|
|
4
|
+
export type CommandSurface = "palette" | "layers" | "overlay" | "device";
|
|
5
|
+
|
|
6
|
+
export type EditorCommand = {
|
|
7
|
+
id: string;
|
|
8
|
+
label: string;
|
|
9
|
+
hint?: string;
|
|
10
|
+
keywords?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
danger?: boolean;
|
|
13
|
+
surfaces: readonly CommandSurface[];
|
|
14
|
+
run: () => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** The actions a surface can invoke. Each surface fills the ones it shows. */
|
|
18
|
+
export type CommandRunners = {
|
|
19
|
+
duplicate?: (id: string) => void;
|
|
20
|
+
remove?: (id: string) => void;
|
|
21
|
+
wrap?: (id: string, type: WrapType) => void;
|
|
22
|
+
moveUp?: (id: string) => void;
|
|
23
|
+
moveDown?: (id: string) => void;
|
|
24
|
+
copy?: (id: string) => void;
|
|
25
|
+
paste?: (id: string | null, mode?: PasteMode) => void;
|
|
26
|
+
copyStyle?: (id: string) => void;
|
|
27
|
+
pasteStyle?: (id: string | null) => void;
|
|
28
|
+
pasteBlocked?: string | null;
|
|
29
|
+
pasteStyleBlocked?: string | null;
|
|
30
|
+
toggleHidden?: () => void;
|
|
31
|
+
save?: () => void;
|
|
32
|
+
publish?: () => void;
|
|
33
|
+
preview?: () => void;
|
|
34
|
+
undo?: () => void;
|
|
35
|
+
redo?: () => void;
|
|
36
|
+
deselect?: () => void;
|
|
37
|
+
openSiteStyles?: () => void;
|
|
38
|
+
openA11y?: () => void;
|
|
39
|
+
openTimeline?: () => void;
|
|
40
|
+
openShare?: () => void;
|
|
41
|
+
openWeight?: () => void;
|
|
42
|
+
setDevice?: (device: PopupDevice) => void;
|
|
43
|
+
openShortcuts?: () => void;
|
|
44
|
+
rename?: () => void;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type CommandInput = {
|
|
48
|
+
surface: CommandSurface;
|
|
49
|
+
targetId: string | null;
|
|
50
|
+
isRoot: boolean;
|
|
51
|
+
isParent: boolean;
|
|
52
|
+
device: PopupDevice;
|
|
53
|
+
/** Duplicate and wrap. False on the root and when nothing is selected. */
|
|
54
|
+
canDuplicate: boolean;
|
|
55
|
+
/** Delete and the sibling moves. False on the root. */
|
|
56
|
+
canDelete: boolean;
|
|
57
|
+
runners: CommandRunners;
|
|
58
|
+
a11yHint?: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type Spec = {
|
|
62
|
+
id: string;
|
|
63
|
+
labels: Partial<Record<CommandSurface, string>>;
|
|
64
|
+
hint?: string;
|
|
65
|
+
keywords?: string;
|
|
66
|
+
surfaces: readonly CommandSurface[];
|
|
67
|
+
danger?: boolean;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// One row per command. A surface shows a row when its name is in `surfaces` and `shown` agrees.
|
|
71
|
+
// Labels stay per surface: the palette, Layers and the overlay do not share wording.
|
|
72
|
+
const SPECS: readonly Spec[] = [
|
|
73
|
+
{ id: "rename", labels: { layers: "Rename" }, surfaces: ["layers"] },
|
|
74
|
+
{
|
|
75
|
+
id: "copy",
|
|
76
|
+
labels: { layers: "Copy", overlay: "Copy" },
|
|
77
|
+
surfaces: ["layers", "overlay"],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: "paste",
|
|
81
|
+
labels: { layers: "Paste", overlay: "Paste" },
|
|
82
|
+
surfaces: ["layers", "overlay"],
|
|
83
|
+
},
|
|
84
|
+
{ id: "paste-inside", labels: { layers: "Paste inside" }, surfaces: ["layers"] },
|
|
85
|
+
{
|
|
86
|
+
id: "copy-style",
|
|
87
|
+
labels: { layers: "Copy style", overlay: "Copy style" },
|
|
88
|
+
surfaces: ["layers", "overlay"],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: "paste-style",
|
|
92
|
+
labels: { layers: "Paste style", overlay: "Paste style" },
|
|
93
|
+
surfaces: ["layers", "overlay"],
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "duplicate",
|
|
97
|
+
labels: {
|
|
98
|
+
layers: "Duplicate",
|
|
99
|
+
overlay: "Duplicate element",
|
|
100
|
+
palette: "Duplicate selected element",
|
|
101
|
+
},
|
|
102
|
+
hint: "Ctrl/Cmd+D",
|
|
103
|
+
surfaces: ["layers", "overlay", "palette"],
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "delete",
|
|
107
|
+
labels: {
|
|
108
|
+
layers: "Delete",
|
|
109
|
+
overlay: "Delete element",
|
|
110
|
+
palette: "Delete selected element",
|
|
111
|
+
},
|
|
112
|
+
hint: "Delete",
|
|
113
|
+
surfaces: ["layers", "overlay", "palette"],
|
|
114
|
+
danger: true,
|
|
115
|
+
},
|
|
116
|
+
{ id: "move-up", labels: { layers: "Move up" }, surfaces: ["layers"] },
|
|
117
|
+
{ id: "move-down", labels: { layers: "Move down" }, surfaces: ["layers"] },
|
|
118
|
+
{
|
|
119
|
+
id: "wrap-flexbox",
|
|
120
|
+
labels: { palette: "Wrap in Flexbox" },
|
|
121
|
+
keywords: "wrap box container",
|
|
122
|
+
surfaces: ["palette"],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: "wrap-grid",
|
|
126
|
+
labels: { palette: "Wrap in Grid" },
|
|
127
|
+
keywords: "wrap box columns",
|
|
128
|
+
surfaces: ["palette"],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: "wrap-div",
|
|
132
|
+
labels: { palette: "Wrap in Div Block" },
|
|
133
|
+
keywords: "wrap box",
|
|
134
|
+
surfaces: ["palette"],
|
|
135
|
+
},
|
|
136
|
+
{ id: "save", labels: { palette: "Save draft" }, hint: "Ctrl/Cmd+S", surfaces: ["palette"] },
|
|
137
|
+
{ id: "publish", labels: { palette: "Publish" }, surfaces: ["palette"] },
|
|
138
|
+
{ id: "preview", labels: { palette: "Preview" }, keywords: "open view", surfaces: ["palette"] },
|
|
139
|
+
{ id: "undo", labels: { palette: "Undo" }, hint: "Ctrl/Cmd+Z", surfaces: ["palette"] },
|
|
140
|
+
{ id: "redo", labels: { palette: "Redo" }, hint: "Ctrl/Cmd+Shift+Z", surfaces: ["palette"] },
|
|
141
|
+
{
|
|
142
|
+
id: "deselect",
|
|
143
|
+
labels: { palette: "Clear selection" },
|
|
144
|
+
hint: "Esc",
|
|
145
|
+
surfaces: ["palette"],
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: "site-styles",
|
|
149
|
+
labels: { palette: "Open Site styles" },
|
|
150
|
+
keywords: "design variables classes colors fonts",
|
|
151
|
+
surfaces: ["palette"],
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: "a11y",
|
|
155
|
+
labels: { palette: "Check accessibility" },
|
|
156
|
+
keywords: "a11y contrast alt headings audit",
|
|
157
|
+
surfaces: ["palette"],
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
id: "timeline",
|
|
161
|
+
labels: { palette: "Version timeline" },
|
|
162
|
+
keywords: "history revisions restore diff",
|
|
163
|
+
surfaces: ["palette"],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
id: "share",
|
|
167
|
+
labels: { palette: "Share as a playground link" },
|
|
168
|
+
keywords: "copy link url playground share send",
|
|
169
|
+
surfaces: ["palette"],
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
id: "weight",
|
|
173
|
+
labels: { palette: "Show page weight" },
|
|
174
|
+
keywords: "performance budget size speed",
|
|
175
|
+
surfaces: ["palette"],
|
|
176
|
+
},
|
|
177
|
+
{ id: "device-desktop", labels: { palette: "View on desktop" }, surfaces: ["palette"] },
|
|
178
|
+
{ id: "device-tablet", labels: { palette: "View on tablet" }, surfaces: ["palette"] },
|
|
179
|
+
{ id: "device-mobile", labels: { palette: "View on mobile" }, surfaces: ["palette"] },
|
|
180
|
+
{ id: "shortcuts", labels: { palette: "Keyboard shortcuts" }, surfaces: ["palette"] },
|
|
181
|
+
{ id: "hide-on-device", labels: {}, surfaces: ["device"] },
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
const ORDER: Record<CommandSurface, readonly string[]> = {
|
|
185
|
+
layers: [
|
|
186
|
+
"rename",
|
|
187
|
+
"copy",
|
|
188
|
+
"paste",
|
|
189
|
+
"paste-inside",
|
|
190
|
+
"duplicate",
|
|
191
|
+
"copy-style",
|
|
192
|
+
"paste-style",
|
|
193
|
+
"move-up",
|
|
194
|
+
"move-down",
|
|
195
|
+
"delete",
|
|
196
|
+
],
|
|
197
|
+
overlay: ["duplicate", "copy", "paste", "copy-style", "paste-style", "delete"],
|
|
198
|
+
palette: [
|
|
199
|
+
"wrap-flexbox",
|
|
200
|
+
"wrap-grid",
|
|
201
|
+
"wrap-div",
|
|
202
|
+
"save",
|
|
203
|
+
"publish",
|
|
204
|
+
"preview",
|
|
205
|
+
"undo",
|
|
206
|
+
"redo",
|
|
207
|
+
"duplicate",
|
|
208
|
+
"delete",
|
|
209
|
+
"deselect",
|
|
210
|
+
"site-styles",
|
|
211
|
+
"a11y",
|
|
212
|
+
"timeline",
|
|
213
|
+
"share",
|
|
214
|
+
"weight",
|
|
215
|
+
"device-desktop",
|
|
216
|
+
"device-tablet",
|
|
217
|
+
"device-mobile",
|
|
218
|
+
"shortcuts",
|
|
219
|
+
],
|
|
220
|
+
device: ["hide-on-device"],
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const CLIP_IDS = new Set(["copy", "paste", "paste-inside", "copy-style", "paste-style"]);
|
|
224
|
+
const WRAP_IDS = new Set(["wrap-flexbox", "wrap-grid", "wrap-div"]);
|
|
225
|
+
const MOVE_IDS = new Set(["move-up", "move-down", "delete"]);
|
|
226
|
+
|
|
227
|
+
function shown(id: string, input: CommandInput): boolean {
|
|
228
|
+
const clip = !!input.runners.copy;
|
|
229
|
+
if (id === "rename") return !!input.runners.rename;
|
|
230
|
+
if (id === "paste-inside") return clip && input.isParent;
|
|
231
|
+
if (id === "paste") return clip && (input.surface !== "layers" || !input.isRoot);
|
|
232
|
+
if (CLIP_IDS.has(id)) return clip;
|
|
233
|
+
if (id === "duplicate" || WRAP_IDS.has(id)) return input.canDuplicate;
|
|
234
|
+
if (MOVE_IDS.has(id)) return input.canDelete;
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function blocked(id: string, input: CommandInput): boolean {
|
|
239
|
+
if (id === "paste" || id === "paste-inside") return !!input.runners.pasteBlocked;
|
|
240
|
+
if (id === "paste-style") return !!input.runners.pasteStyleBlocked;
|
|
241
|
+
if (id === "hide-on-device") return !input.targetId;
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function labelFor(spec: Spec, input: CommandInput): string {
|
|
246
|
+
if (spec.id === "hide-on-device") return `Hide on ${input.device}`;
|
|
247
|
+
return spec.labels[input.surface] ?? spec.id;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Commands one surface shows for this target, in that surface's order. */
|
|
251
|
+
export function editorCommands(input: CommandInput): EditorCommand[] {
|
|
252
|
+
const rank = new Map(ORDER[input.surface].map((id, index) => [id, index]));
|
|
253
|
+
return SPECS.filter((spec) => spec.surfaces.includes(input.surface) && shown(spec.id, input))
|
|
254
|
+
.toSorted((a, b) => (rank.get(a.id) ?? 999) - (rank.get(b.id) ?? 999))
|
|
255
|
+
.map((spec) => ({
|
|
256
|
+
id: spec.id,
|
|
257
|
+
label: labelFor(spec, input),
|
|
258
|
+
hint: spec.id === "a11y" ? input.a11yHint : spec.hint,
|
|
259
|
+
keywords: spec.keywords,
|
|
260
|
+
disabled: blocked(spec.id, input),
|
|
261
|
+
danger: spec.danger,
|
|
262
|
+
surfaces: spec.surfaces,
|
|
263
|
+
run: () => runCommand(input.runners, spec.id, input.targetId),
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** One implementation for the palette, Layers, the overlay, the device bar and shortcuts. */
|
|
268
|
+
export function runCommand(runners: CommandRunners, id: string, targetId: string | null): void {
|
|
269
|
+
switch (id) {
|
|
270
|
+
case "rename":
|
|
271
|
+
runners.rename?.();
|
|
272
|
+
return;
|
|
273
|
+
case "copy":
|
|
274
|
+
if (targetId) runners.copy?.(targetId);
|
|
275
|
+
return;
|
|
276
|
+
case "paste":
|
|
277
|
+
runners.paste?.(targetId);
|
|
278
|
+
return;
|
|
279
|
+
case "paste-inside":
|
|
280
|
+
runners.paste?.(targetId, "inside");
|
|
281
|
+
return;
|
|
282
|
+
case "copy-style":
|
|
283
|
+
if (targetId) runners.copyStyle?.(targetId);
|
|
284
|
+
return;
|
|
285
|
+
case "paste-style":
|
|
286
|
+
runners.pasteStyle?.(targetId);
|
|
287
|
+
return;
|
|
288
|
+
case "duplicate":
|
|
289
|
+
if (targetId) runners.duplicate?.(targetId);
|
|
290
|
+
return;
|
|
291
|
+
case "delete":
|
|
292
|
+
if (targetId) runners.remove?.(targetId);
|
|
293
|
+
return;
|
|
294
|
+
case "move-up":
|
|
295
|
+
if (targetId) runners.moveUp?.(targetId);
|
|
296
|
+
return;
|
|
297
|
+
case "move-down":
|
|
298
|
+
if (targetId) runners.moveDown?.(targetId);
|
|
299
|
+
return;
|
|
300
|
+
case "wrap-flexbox":
|
|
301
|
+
if (targetId) runners.wrap?.(targetId, "flexbox");
|
|
302
|
+
return;
|
|
303
|
+
case "wrap-grid":
|
|
304
|
+
if (targetId) runners.wrap?.(targetId, "grid");
|
|
305
|
+
return;
|
|
306
|
+
case "wrap-div":
|
|
307
|
+
if (targetId) runners.wrap?.(targetId, "div-block");
|
|
308
|
+
return;
|
|
309
|
+
case "save":
|
|
310
|
+
runners.save?.();
|
|
311
|
+
return;
|
|
312
|
+
case "publish":
|
|
313
|
+
runners.publish?.();
|
|
314
|
+
return;
|
|
315
|
+
case "preview":
|
|
316
|
+
runners.preview?.();
|
|
317
|
+
return;
|
|
318
|
+
case "undo":
|
|
319
|
+
runners.undo?.();
|
|
320
|
+
return;
|
|
321
|
+
case "redo":
|
|
322
|
+
runners.redo?.();
|
|
323
|
+
return;
|
|
324
|
+
case "deselect":
|
|
325
|
+
runners.deselect?.();
|
|
326
|
+
return;
|
|
327
|
+
case "site-styles":
|
|
328
|
+
runners.openSiteStyles?.();
|
|
329
|
+
return;
|
|
330
|
+
case "a11y":
|
|
331
|
+
runners.openA11y?.();
|
|
332
|
+
return;
|
|
333
|
+
case "timeline":
|
|
334
|
+
runners.openTimeline?.();
|
|
335
|
+
return;
|
|
336
|
+
case "share":
|
|
337
|
+
runners.openShare?.();
|
|
338
|
+
return;
|
|
339
|
+
case "weight":
|
|
340
|
+
runners.openWeight?.();
|
|
341
|
+
return;
|
|
342
|
+
case "device-desktop":
|
|
343
|
+
runners.setDevice?.("desktop");
|
|
344
|
+
return;
|
|
345
|
+
case "device-tablet":
|
|
346
|
+
runners.setDevice?.("tablet");
|
|
347
|
+
return;
|
|
348
|
+
case "device-mobile":
|
|
349
|
+
runners.setDevice?.("mobile");
|
|
350
|
+
return;
|
|
351
|
+
case "shortcuts":
|
|
352
|
+
runners.openShortcuts?.();
|
|
353
|
+
return;
|
|
354
|
+
case "hide-on-device":
|
|
355
|
+
runners.toggleHidden?.();
|
|
356
|
+
return;
|
|
357
|
+
default:
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArrowsLeftRightIcon,
|
|
3
|
+
ArrowsVerticalIcon,
|
|
4
|
+
ArticleIcon,
|
|
5
|
+
BrowserIcon,
|
|
6
|
+
CaretCircleDownIcon,
|
|
7
|
+
CaretDownIcon,
|
|
8
|
+
CheckSquareIcon,
|
|
9
|
+
CursorClickIcon,
|
|
10
|
+
GraphIcon,
|
|
11
|
+
GridFourIcon,
|
|
12
|
+
ImageIcon,
|
|
13
|
+
LinkIcon,
|
|
14
|
+
ListBulletsIcon,
|
|
15
|
+
MinusIcon,
|
|
16
|
+
NotePencilIcon,
|
|
17
|
+
PaperPlaneRightIcon,
|
|
18
|
+
RadioButtonIcon,
|
|
19
|
+
RowsIcon,
|
|
20
|
+
SmileyIcon,
|
|
21
|
+
SquareIcon,
|
|
22
|
+
SquaresFourIcon,
|
|
23
|
+
TextAaIcon,
|
|
24
|
+
TextAlignLeftIcon,
|
|
25
|
+
TextboxIcon,
|
|
26
|
+
TextHIcon,
|
|
27
|
+
TextTIcon,
|
|
28
|
+
VideoCameraIcon,
|
|
29
|
+
type Icon,
|
|
30
|
+
} from "@phosphor-icons/react";
|
|
31
|
+
import { ELEMENT_DESCRIPTORS } from "../../core/index.ts";
|
|
32
|
+
|
|
33
|
+
/** Labels for element types. One list, from the descriptors (W-361). */
|
|
34
|
+
export const ELEMENT_NAMES: Record<string, string> = Object.fromEntries(
|
|
35
|
+
ELEMENT_DESCRIPTORS.map((descriptor) => [descriptor.type, descriptor.name]),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Phosphor icon for each element. The names in `docs/DESIGN.md` win. Types that table
|
|
40
|
+
* does not list keep the icon the add panel already showed.
|
|
41
|
+
*/
|
|
42
|
+
export const ELEMENT_ICONS: Record<string, Icon> = {
|
|
43
|
+
container: SquaresFourIcon,
|
|
44
|
+
"div-block": SquareIcon,
|
|
45
|
+
"layout-section": RowsIcon,
|
|
46
|
+
section: RowsIcon,
|
|
47
|
+
flexbox: SquaresFourIcon,
|
|
48
|
+
grid: GridFourIcon,
|
|
49
|
+
spacer: ArrowsVerticalIcon,
|
|
50
|
+
divider: MinusIcon,
|
|
51
|
+
heading: TextHIcon,
|
|
52
|
+
text: TextAlignLeftIcon,
|
|
53
|
+
label: TextTIcon,
|
|
54
|
+
link: LinkIcon,
|
|
55
|
+
button: CursorClickIcon,
|
|
56
|
+
list: ListBulletsIcon,
|
|
57
|
+
image: ImageIcon,
|
|
58
|
+
icon: SmileyIcon,
|
|
59
|
+
svg: GraphIcon,
|
|
60
|
+
tabs: BrowserIcon,
|
|
61
|
+
"tab-panel": BrowserIcon,
|
|
62
|
+
accordion: ListBulletsIcon,
|
|
63
|
+
"accordion-item": ListBulletsIcon,
|
|
64
|
+
menu: CaretDownIcon,
|
|
65
|
+
"menu-item": CaretDownIcon,
|
|
66
|
+
toc: ListBulletsIcon,
|
|
67
|
+
video: VideoCameraIcon,
|
|
68
|
+
form: ArticleIcon,
|
|
69
|
+
"text-input": TextboxIcon,
|
|
70
|
+
textarea: TextAaIcon,
|
|
71
|
+
select: CaretCircleDownIcon,
|
|
72
|
+
checkbox: CheckSquareIcon,
|
|
73
|
+
radio: RadioButtonIcon,
|
|
74
|
+
submit: PaperPlaneRightIcon,
|
|
75
|
+
"post-title": TextHIcon,
|
|
76
|
+
"post-excerpt": TextAlignLeftIcon,
|
|
77
|
+
"post-content": NotePencilIcon,
|
|
78
|
+
"post-image": ImageIcon,
|
|
79
|
+
"post-link": LinkIcon,
|
|
80
|
+
"post-date": TextTIcon,
|
|
81
|
+
"post-author": TextTIcon,
|
|
82
|
+
loop: ListBulletsIcon,
|
|
83
|
+
"loop-empty": SquareIcon,
|
|
84
|
+
pagination: ArrowsLeftRightIcon,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export function elementIcon(type: string): Icon {
|
|
88
|
+
return ELEMENT_ICONS[type] ?? SquaresFourIcon;
|
|
89
|
+
}
|
|
@@ -25,22 +25,22 @@ export const FEATURE_CSS = `
|
|
|
25
25
|
.emvb-bind-live > b { font-weight: 600; }
|
|
26
26
|
.emvb-bind-outside { grid-column: 1 / -1; display: grid; gap: 4px; }
|
|
27
27
|
.emvb-bind-outside > label { display: flex; gap: 6px; align-items: center; font-size: 12px; }
|
|
28
|
-
.emvb-bind-warning { margin: 0; padding: 6px 8px; border-radius: 6px; font-size: 12px; background: var(--color-kumo-warning-tint
|
|
29
|
-
.emvb-js-badge { margin-left: auto; padding: 0 4px; border-radius: 4px; font-size: 10px; font-weight: 700; line-height: 16px; background: var(--color-kumo-warning-tint
|
|
28
|
+
.emvb-bind-warning { margin: 0; padding: 6px 8px; border-radius: 6px; font-size: 12px; background: var(--color-kumo-warning-tint); color: var(--text-color-kumo-default); }
|
|
29
|
+
.emvb-js-badge { margin-left: auto; padding: 0 4px; border-radius: 4px; font-size: 10px; font-weight: 700; line-height: 16px; background: var(--color-kumo-warning-tint); color: var(--text-color-kumo-default); }
|
|
30
30
|
.emvb-element-tile { position: relative; }
|
|
31
31
|
.emvb-element-tile > .emvb-js-badge { position: absolute; top: 4px; right: 4px; }
|
|
32
32
|
.emvb-perf-bars { display: grid; gap: 8px; margin: 12px 0; padding: 0; list-style: none; }
|
|
33
33
|
.emvb-perf-bars > li { display: grid; grid-template-columns: 90px 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
|
|
34
34
|
.emvb-perf-bar { display: block; height: 8px; border-radius: 4px; background: var(--color-kumo-tint); overflow: hidden; }
|
|
35
35
|
.emvb-perf-bar > span { display: block; height: 100%; background: var(--color-kumo-brand); }
|
|
36
|
-
.emvb-perf-bars > li[data-over] .emvb-perf-bar > span { background: var(--color-kumo-danger
|
|
36
|
+
.emvb-perf-bars > li[data-over] .emvb-perf-bar > span { background: var(--color-kumo-danger); }
|
|
37
37
|
.emvb-perf-value { font-variant-numeric: tabular-nums; color: var(--text-color-kumo-subtle); }
|
|
38
38
|
.emvb-perf-warnings { margin: 8px 0; padding-left: 18px; font-size: 13px; }
|
|
39
39
|
.emvb-perf-heading { margin: 12px 0 4px; font-size: 13px; font-weight: 600; }
|
|
40
40
|
.emvb-perf-sections { margin: 0 0 8px; padding-left: 18px; font-size: 13px; }
|
|
41
41
|
.emvb-topbar-meter { font-variant-numeric: tabular-nums; font-size: 12px; }
|
|
42
42
|
.emvb-js-badge + .emvb-ab-badge { margin-left: 2px; }
|
|
43
|
-
.emvb-ab-badge { background: var(--color-kumo-info-tint
|
|
43
|
+
.emvb-ab-badge { background: var(--color-kumo-info-tint); }
|
|
44
44
|
.emvb-aud-checks { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 0; padding: 0; border: 0; font-size: 12px; }
|
|
45
45
|
.emvb-aud-checks > legend { width: 100%; padding: 0; margin-bottom: 2px; }
|
|
46
46
|
.emvb-palette { padding: 0; overflow: hidden; }
|
|
@@ -60,13 +60,13 @@ export const FEATURE_CSS = `
|
|
|
60
60
|
.emvb-timeline-frames { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
|
|
61
61
|
.emvb-timeline-frames figure { margin: 0; }
|
|
62
62
|
.emvb-timeline-frames figcaption { font-size: 12px; color: var(--text-color-kumo-subtle); margin-bottom: 4px; }
|
|
63
|
-
.emvb-timeline-frame { width: 100%; height: 260px; border: 1px solid var(--color-kumo-line); border-radius: 6px; background:
|
|
63
|
+
.emvb-timeline-frame { width: 100%; height: 260px; border: 1px solid var(--color-kumo-line); border-radius: 6px; background: var(--color-kumo-base); }
|
|
64
64
|
.emvb-timeline-changes { margin: 8px 0; padding: 0; list-style: none; font-size: 13px; display: grid; gap: 4px; }
|
|
65
65
|
.emvb-timeline-changes > li { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
|
|
66
66
|
.emvb-timeline-kind { font-weight: 600; }
|
|
67
|
-
.emvb-timeline-changes > li[data-kind="added"] .emvb-timeline-kind { color:
|
|
68
|
-
.emvb-timeline-changes > li[data-kind="removed"] .emvb-timeline-kind { color:
|
|
69
|
-
.emvb-timeline-changes > li[data-kind="changed"] .emvb-timeline-kind { color:
|
|
67
|
+
.emvb-timeline-changes > li[data-kind="added"] .emvb-timeline-kind { color: var(--text-color-kumo-success); }
|
|
68
|
+
.emvb-timeline-changes > li[data-kind="removed"] .emvb-timeline-kind { color: var(--text-color-kumo-danger); }
|
|
69
|
+
.emvb-timeline-changes > li[data-kind="changed"] .emvb-timeline-kind { color: var(--text-color-kumo-warning); }
|
|
70
70
|
.emvb-tokens-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
|
|
71
71
|
.emvb-tokens-grid > label { display: grid; gap: 4px; min-width: 0; }
|
|
72
72
|
.emvb-tokens-fluid { display: flex !important; align-items: center; gap: 4px; font-size: 12px; }
|
|
@@ -76,21 +76,21 @@ export const FEATURE_CSS = `
|
|
|
76
76
|
.emvb-tokens-preview .emvb-tokens-sample:empty { height: 8px; border-radius: 2px; background: var(--color-kumo-brand); }
|
|
77
77
|
.emvb-tokens-preview code { font-size: 11px; color: var(--text-color-kumo-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
|
|
78
78
|
.emvb-a11y-score { height: 28px; padding: 0 8px; border: 1px solid var(--color-kumo-line); border-radius: 999px; background: transparent; color: var(--text-color-kumo-default); font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap; }
|
|
79
|
-
.emvb-a11y-score[data-band="good"] b, .emvb-a11y [data-band="good"] { color:
|
|
80
|
-
.emvb-a11y-score[data-band="fair"] b, .emvb-a11y [data-band="fair"] { color:
|
|
81
|
-
.emvb-a11y-score[data-band="poor"] b, .emvb-a11y [data-band="poor"] { color:
|
|
79
|
+
.emvb-a11y-score[data-band="good"] b, .emvb-a11y [data-band="good"] { color: var(--text-color-kumo-success); }
|
|
80
|
+
.emvb-a11y-score[data-band="fair"] b, .emvb-a11y [data-band="fair"] { color: var(--text-color-kumo-warning); }
|
|
81
|
+
.emvb-a11y-score[data-band="poor"] b, .emvb-a11y [data-band="poor"] { color: var(--text-color-kumo-danger); }
|
|
82
82
|
.emvb-a11y-score:focus-visible { outline: 2px solid var(--color-kumo-brand); outline-offset: 1px; }
|
|
83
83
|
.emvb-a11y-issues { margin: 12px 0; padding: 0; list-style: none; display: grid; gap: 8px; max-height: 50vh; overflow-y: auto; }
|
|
84
|
-
.emvb-a11y-issues > li { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; font-size: 13px; padding-left: 8px; border-left: 3px solid
|
|
85
|
-
.emvb-a11y-issues > li[data-severity="error"] { border-left-color:
|
|
84
|
+
.emvb-a11y-issues > li { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; font-size: 13px; padding-left: 8px; border-left: 3px solid var(--color-kumo-warning); }
|
|
85
|
+
.emvb-a11y-issues > li[data-severity="error"] { border-left-color: var(--color-kumo-danger); }
|
|
86
86
|
.emvb-a11y-actions { display: flex; gap: 8px; justify-content: flex-end; }
|
|
87
87
|
.emvb-sources { margin: 4px 0 8px; font-size: 12px; }
|
|
88
88
|
.emvb-sources > summary { cursor: pointer; display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
|
|
89
89
|
.emvb-sources-count { font-weight: 400; color: var(--text-color-kumo-subtle); }
|
|
90
90
|
.emvb-sources ul { margin: 6px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
|
|
91
91
|
.emvb-sources li { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; padding-left: 6px; border-left: 2px solid var(--color-kumo-line); }
|
|
92
|
-
.emvb-sources li[data-kind="class"] { border-left-color:
|
|
93
|
-
.emvb-sources li[data-kind="default"] { border-left-color:
|
|
92
|
+
.emvb-sources li[data-kind="class"] { border-left-color: var(--color-kumo-info); }
|
|
93
|
+
.emvb-sources li[data-kind="default"] { border-left-color: var(--color-kumo-success); }
|
|
94
94
|
.emvb-sources li[data-kind="local"] { border-left-color: var(--color-kumo-brand); }
|
|
95
95
|
.emvb-sources-value { font-family: ui-monospace, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
|
|
96
96
|
.emvb-sources-from, .emvb-sources-over { grid-column: 1 / -1; color: var(--text-color-kumo-subtle); }
|
package/src/admin/editor/host.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { PLUGIN_ID } from "../../constants.ts";
|
|
3
|
+
import { canvasStyleUrls } from "../../core/canvas-styles.ts";
|
|
4
|
+
import { requestJson, type Fetcher } from "../api.ts";
|
|
2
5
|
import { exitTarget, PAGES_URL } from "./exit.ts";
|
|
3
6
|
|
|
4
7
|
/**
|
|
@@ -17,6 +20,11 @@ export type EditorHost = {
|
|
|
17
20
|
adminLinks?: boolean;
|
|
18
21
|
/** Where shared page links open (W-321). Default emvb.dev/playground. */
|
|
19
22
|
playgroundUrl?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Stylesheets the canvas loads before EmVB's CSS (W-327). Unset: the editor asks the plugin
|
|
25
|
+
* for the host's `emvb({ canvasStyles })`.
|
|
26
|
+
*/
|
|
27
|
+
canvasStyles?: readonly string[];
|
|
20
28
|
};
|
|
21
29
|
|
|
22
30
|
const defaultEditorHost: EditorHost = {
|
|
@@ -30,3 +38,28 @@ export const useEditorHost = (): EditorHost => React.useContext(EditorHostContex
|
|
|
30
38
|
|
|
31
39
|
/** False when the editor runs outside the EmDash admin, where admin links would lead nowhere. */
|
|
32
40
|
export const useAdminLinks = (): boolean => useEditorHost().adminLinks !== false;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* W-327: the host's canvas stylesheets, from the EditorHost or else the plugin's
|
|
44
|
+
* `editor/config` route. Empty while loading and when the route fails.
|
|
45
|
+
*/
|
|
46
|
+
export function useCanvasStyles(fetcher: Fetcher): readonly string[] {
|
|
47
|
+
const provided = useEditorHost().canvasStyles;
|
|
48
|
+
const [loaded, setLoaded] = React.useState<readonly string[]>([]);
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
if (provided) return;
|
|
51
|
+
let cancelled = false;
|
|
52
|
+
void requestJson<{ canvasStyles?: unknown }>(
|
|
53
|
+
fetcher,
|
|
54
|
+
`/_emdash/api/plugins/${PLUGIN_ID}/editor/config`,
|
|
55
|
+
)
|
|
56
|
+
.then((body) => {
|
|
57
|
+
if (!cancelled) setLoaded(canvasStyleUrls(body?.canvasStyles));
|
|
58
|
+
})
|
|
59
|
+
.catch(() => undefined);
|
|
60
|
+
return () => {
|
|
61
|
+
cancelled = true;
|
|
62
|
+
};
|
|
63
|
+
}, [fetcher, provided]);
|
|
64
|
+
return provided ? canvasStyleUrls(provided) : loaded;
|
|
65
|
+
}
|