@perkyzz/emvb 0.5.0 → 0.7.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 -0
- package/THIRD_PARTY_NOTICES.md +23 -1
- package/licenses/exif-js.LICENSE +21 -0
- package/licenses/fflate.LICENSE +21 -0
- package/licenses/glfx.js.LICENSE +19 -0
- package/licenses/mini-photo-editor.LICENSE +21 -0
- package/licenses/photocn.LICENSE +21 -0
- package/package.json +2 -1
- package/src/admin/access/RequireEditor.tsx +7 -7
- package/src/admin/access/role.ts +5 -2
- package/src/admin/content-api.ts +10 -3
- package/src/admin/content-item.ts +1 -1
- package/src/admin/editor/A11yCopilot.tsx +104 -56
- package/src/admin/editor/CommandPalette.tsx +29 -13
- package/src/admin/editor/Editor.tsx +88 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +97 -72
- package/src/admin/editor/ShareLink.tsx +107 -72
- package/src/admin/editor/ShortcutsDialog.tsx +27 -16
- package/src/admin/editor/Timeline.tsx +255 -160
- package/src/admin/editor/TopBar.tsx +71 -14
- package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
- package/src/admin/editor/canvas/drop-line.ts +11 -3
- package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
- package/src/admin/editor/canvas/vnode-react.tsx +7 -0
- package/src/admin/editor/collection-previews.ts +16 -1
- package/src/admin/editor/dialogs.tsx +38 -14
- package/src/admin/editor/dnd/drop-target.ts +26 -1
- package/src/admin/editor/edited-noun.ts +15 -0
- package/src/admin/editor/editor-chrome.tsx +108 -7
- package/src/admin/editor/editor-commands.ts +15 -1
- package/src/admin/editor/editor-css.ts +75 -22
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +45 -13
- package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
- package/src/admin/editor/icons/library.ts +1 -1
- package/src/admin/editor/icons/use-icon-library.ts +5 -2
- package/src/admin/editor/ime.ts +29 -0
- package/src/admin/editor/palette-items.ts +10 -3
- package/src/admin/editor/panels/AddPanel.tsx +35 -10
- package/src/admin/editor/panels/ClassesSection.tsx +18 -7
- package/src/admin/editor/panels/ColorControl.tsx +135 -27
- package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
- package/src/admin/editor/panels/ElementPanel.tsx +134 -24
- package/src/admin/editor/panels/LayersPanel.tsx +68 -22
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
- package/src/admin/editor/panels/TokenScales.tsx +76 -36
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
- package/src/admin/editor/panels/VariableSection.tsx +53 -21
- package/src/admin/editor/panels/color-space.ts +9 -3
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
- package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
- package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
- package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
- package/src/admin/editor/panels/settings/FieldControl.tsx +38 -15
- package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
- package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
- package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
- package/src/admin/editor/panels/settings/MediaPicker.tsx +274 -20
- package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
- package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
- package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +141 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
- package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
- package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
- package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
- package/src/admin/editor/panels/settings/query-style.ts +38 -9
- package/src/admin/editor/panels/settings/svg-images.ts +13 -0
- package/src/admin/editor/panels/site-list.tsx +20 -6
- package/src/admin/editor/panels/variable-values.ts +25 -4
- package/src/admin/editor/restore-deleted.ts +21 -2
- package/src/admin/editor/section-templates.ts +81 -12
- package/src/admin/editor/shortcuts.ts +17 -2
- package/src/admin/editor/store.ts +14 -3
- package/src/admin/editor/useEditorCommands.ts +61 -15
- package/src/admin/editor/useEditorData.ts +4 -2
- package/src/admin/editor/useEditorShortcuts.ts +17 -7
- package/src/admin/editor/useNodeActions.ts +61 -6
- package/src/admin/editor/useSave.ts +22 -7
- package/src/admin/forms-api.ts +2 -0
- package/src/admin/image-editor/BlurFocus.tsx +112 -0
- package/src/admin/image-editor/Canvas.tsx +261 -0
- package/src/admin/image-editor/CropOverlay.tsx +390 -0
- package/src/admin/image-editor/CurvesPanel.tsx +395 -0
- package/src/admin/image-editor/ExportDialog.tsx +384 -0
- package/src/admin/image-editor/ImageEditButton.tsx +83 -0
- package/src/admin/image-editor/ImageEditorDialog.tsx +828 -0
- package/src/admin/image-editor/MetadataPanel.tsx +194 -0
- package/src/admin/image-editor/announce.tsx +65 -0
- package/src/admin/image-editor/crop-geometry.ts +162 -0
- package/src/admin/image-editor/curve-math.ts +177 -0
- package/src/admin/image-editor/data-url-fetch.ts +59 -0
- package/src/admin/image-editor/engine.ts +55 -0
- package/src/admin/image-editor/exif.ts +82 -0
- package/src/admin/image-editor/flatten.ts +54 -0
- package/src/admin/image-editor/gpu-fit.ts +81 -0
- package/src/admin/image-editor/image-editor-css.ts +400 -0
- package/src/admin/image-editor/load.ts +116 -0
- package/src/admin/image-editor/panels.tsx +287 -0
- package/src/admin/image-editor/parts.tsx +614 -0
- package/src/admin/image-editor/save.ts +141 -0
- package/src/admin/image-editor/tone-panels.tsx +338 -0
- package/src/admin/image-editor/tools.ts +59 -0
- package/src/admin/image-editor/worker.ts +111 -0
- package/src/admin/media-api.ts +114 -3
- package/src/admin/pages/AgentsPage.tsx +138 -27
- package/src/admin/pages/CreateDialog.tsx +97 -30
- package/src/admin/pages/NewPageDialog.tsx +21 -3
- package/src/admin/pages/NewThemePartDialog.tsx +11 -3
- package/src/admin/pages/PageList.tsx +14 -6
- package/src/admin/pages/SetupShell.tsx +28 -12
- package/src/admin/pages/ThemePartList.tsx +27 -7
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +13 -3
- package/src/admin/ui.ts +78 -22
- package/src/astro/EmVBPage.astro +11 -2
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +33 -3
- package/src/astro/render.ts +6 -0
- package/src/astro/resolve-theme.ts +67 -14
- package/src/astro/resolve.ts +9 -1
- package/src/astro/tabs/runtime.ts +12 -0
- package/src/astro/theme-posts.ts +2 -2
- package/src/astro/visitor.ts +6 -3
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +171 -24
- package/src/core/arrange.ts +29 -6
- package/src/core/audience/rules.ts +5 -1
- package/src/core/audience/variants.ts +29 -3
- package/src/core/clipboard.ts +7 -0
- package/src/core/css/generate.ts +31 -6
- package/src/core/data/bindings.ts +19 -6
- package/src/core/design/classes.ts +20 -9
- package/src/core/design/diff.ts +9 -1
- package/src/core/design/merge.ts +93 -3
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +46 -8
- package/src/core/design/variables.ts +32 -10
- package/src/core/elements/dynamic-elements.ts +53 -6
- package/src/core/elements/form-elements.ts +68 -30
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -19
- package/src/core/elements/plain-text.ts +2 -2
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +190 -2
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +49 -4
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +155 -0
- package/src/core/image-edit/summary.ts +61 -0
- package/src/core/index.ts +29 -1
- package/src/core/limits.ts +21 -0
- package/src/core/migrate/index.ts +3 -1
- package/src/core/perf/meter.ts +51 -8
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +71 -13
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +164 -12
- package/src/core/render/index.ts +179 -22
- package/src/core/render/loop.ts +43 -7
- package/src/core/render/pagination.ts +18 -4
- package/src/core/render/section.ts +27 -0
- package/src/core/render/tabs.ts +12 -3
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +15 -2
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/schema/layout.ts +26 -7
- package/src/core/share/link.ts +5 -2
- package/src/core/stable-json.ts +15 -0
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +57 -23
- package/src/core/theme/float.ts +9 -2
- package/src/core/theme/pagination.ts +57 -10
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +11 -5
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/ports.ts +8 -1
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +82 -3
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/tools.ts +1 -1
- package/src/mcp/write.ts +271 -25
- package/src/server/agent-settings.ts +29 -4
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +33 -9
- package/src/server/mcp-routes.ts +74 -11
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
collectLoopItemPartIds,
|
|
4
|
+
collectSectionPartIds,
|
|
5
|
+
type Layout,
|
|
6
|
+
type ThemePartType,
|
|
7
|
+
} from "../../core/index.ts";
|
|
3
8
|
import type { Fetcher } from "../api.ts";
|
|
4
9
|
import { themePartLayout } from "../theme-api.ts";
|
|
5
10
|
|
|
@@ -40,27 +45,91 @@ export async function loadSectionTemplates(
|
|
|
40
45
|
return acc;
|
|
41
46
|
}
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
export interface PartTemplates {
|
|
49
|
+
sectionTemplates: Record<string, Layout>;
|
|
50
|
+
loopTemplates: Record<string, Layout>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const MAX_PARTS = 64;
|
|
54
|
+
|
|
55
|
+
function partRefs(part: Layout): Array<[string, "section" | "loop_item"]> {
|
|
56
|
+
return [
|
|
57
|
+
...collectSectionPartIds(part).map((id) => [id, "section"] as [string, "section"]),
|
|
58
|
+
...collectLoopItemPartIds(part).map((id) => [id, "loop_item"] as [string, "loop_item"]),
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* W-658: synced sections and Loop Item parts referenced by the open layout, following parts nested
|
|
64
|
+
* in either kind (a Loop inside a section, a section or Loop inside a loop item). The canvas used to
|
|
65
|
+
* load only sections, so a Loop with a chosen Loop Item showed "Choose a Loop Item" instead of it.
|
|
66
|
+
*/
|
|
67
|
+
export async function loadPartTemplates(
|
|
46
68
|
fetcher: Fetcher,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
69
|
+
layout: Layout,
|
|
70
|
+
read: (id: string, kind: ThemePartType) => Promise<Layout | null> = (id, kind) =>
|
|
71
|
+
themePartLayout(fetcher, id, kind),
|
|
72
|
+
): Promise<PartTemplates> {
|
|
73
|
+
const out: PartTemplates = { sectionTemplates: {}, loopTemplates: {} };
|
|
74
|
+
const seen = new Set<string>();
|
|
75
|
+
let next = partRefs(layout);
|
|
76
|
+
for (let depth = 0; depth <= MAX_DEPTH && next.length > 0; depth++) {
|
|
77
|
+
const pending = next.filter(([id, kind]) => {
|
|
78
|
+
const key = `${kind}\0${id}`;
|
|
79
|
+
if (seen.has(key) || seen.size >= MAX_PARTS) return false;
|
|
80
|
+
seen.add(key);
|
|
81
|
+
return true;
|
|
82
|
+
});
|
|
83
|
+
// Each depth waits on the one before it: its ids come from the parts just read.
|
|
84
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
85
|
+
const loaded = await Promise.all(
|
|
86
|
+
pending.map(async ([id, kind]) => {
|
|
87
|
+
try {
|
|
88
|
+
return [id, kind, await read(id, kind)] as const;
|
|
89
|
+
} catch {
|
|
90
|
+
return [id, kind, null] as const;
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
next = [];
|
|
95
|
+
for (const [id, kind, part] of loaded) {
|
|
96
|
+
if (!part) continue;
|
|
97
|
+
(kind === "section" ? out.sectionTemplates : out.loopTemplates)[id] = part;
|
|
98
|
+
next.push(...partRefs(part));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function partKey(layout: Layout | null): string {
|
|
105
|
+
if (!layout) return "";
|
|
106
|
+
const s = collectSectionPartIds(layout);
|
|
107
|
+
const l = collectLoopItemPartIds(layout);
|
|
108
|
+
return s.length + l.length === 0 ? "" : JSON.stringify([s, l]);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const NO_PARTS: PartTemplates = { sectionTemplates: {}, loopTemplates: {} };
|
|
112
|
+
|
|
113
|
+
/** Section and Loop Item parts for the canvas (W-658). */
|
|
114
|
+
export function usePartTemplates(layout: Layout | null, fetcher: Fetcher): PartTemplates {
|
|
115
|
+
const key = partKey(layout);
|
|
116
|
+
const layoutRef = React.useRef(layout);
|
|
117
|
+
layoutRef.current = layout;
|
|
118
|
+
const [templates, setTemplates] = React.useState<PartTemplates>(NO_PARTS);
|
|
50
119
|
|
|
51
120
|
React.useEffect(() => {
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
setTemplates(
|
|
121
|
+
const current = layoutRef.current;
|
|
122
|
+
if (!key || !current) {
|
|
123
|
+
setTemplates(NO_PARTS);
|
|
55
124
|
return;
|
|
56
125
|
}
|
|
57
126
|
let cancelled = false;
|
|
58
|
-
void
|
|
127
|
+
void loadPartTemplates(fetcher, current).then(
|
|
59
128
|
(acc) => {
|
|
60
129
|
if (!cancelled) setTemplates(acc);
|
|
61
130
|
},
|
|
62
131
|
() => {
|
|
63
|
-
if (!cancelled) setTemplates(
|
|
132
|
+
if (!cancelled) setTemplates(NO_PARTS);
|
|
64
133
|
},
|
|
65
134
|
);
|
|
66
135
|
return () => {
|
|
@@ -6,19 +6,34 @@ export const SHORTCUTS: readonly { action: string; keys: string }[] = [
|
|
|
6
6
|
{ action: "Select first child / parent", keys: "Enter / Shift+Enter" },
|
|
7
7
|
{ action: "Clear selection", keys: "Esc" },
|
|
8
8
|
{ action: "Expand or collapse (Layers)", keys: "← / →" },
|
|
9
|
+
// UX-085: F2 renames the focused layer or class chip; the list never said so.
|
|
10
|
+
{ action: "Rename (layer or class chip)", keys: "F2" },
|
|
9
11
|
{ action: "Move up / down", keys: "Alt+↑ / Alt+↓" },
|
|
10
12
|
{ action: "Move out / in", keys: "Alt+← / Alt+→" },
|
|
11
13
|
{ action: "Duplicate", keys: "Ctrl/Cmd+D" },
|
|
12
14
|
{ action: "Copy / paste element", keys: "Ctrl/Cmd+C / Ctrl/Cmd+V" },
|
|
13
15
|
{ action: "Paste style", keys: "Ctrl/Cmd+Shift+V" },
|
|
14
16
|
{ action: "Delete", keys: "Delete or Backspace" },
|
|
15
|
-
|
|
17
|
+
// W-775: Ctrl/Cmd+Y redoes too (useEditorShortcuts); the list never said so.
|
|
18
|
+
{ action: "Undo / redo", keys: "Ctrl/Cmd+Z / Ctrl/Cmd+Shift+Z or Ctrl/Cmd+Y" },
|
|
16
19
|
{ action: "Save draft", keys: "Ctrl/Cmd+S" },
|
|
17
20
|
];
|
|
18
21
|
|
|
22
|
+
/**
|
|
23
|
+
* W-565: the letter of a Ctrl/Cmd shortcut on any keyboard layout. A Russian, Greek, Hebrew or
|
|
24
|
+
* Arabic layout reports its own letter (Ctrl+Z is "я"), so the key's position stands in when the
|
|
25
|
+
* key isn't a Latin letter. Latin layouts (AZERTY, Dvorak) keep the letter they type.
|
|
26
|
+
*/
|
|
27
|
+
export function shortcutKey(event: KeyboardEvent): string {
|
|
28
|
+
const key = event.key.toLowerCase();
|
|
29
|
+
if (/^[a-z]$/.test(key)) return key;
|
|
30
|
+
const position = /^Key([A-Z])$/.exec(event.code ?? "");
|
|
31
|
+
return position?.[1] ? position[1].toLowerCase() : key;
|
|
32
|
+
}
|
|
33
|
+
|
|
19
34
|
/** Ctrl/Cmd+K opens the host command palette, which would stack over the editor (S0-6). */
|
|
20
35
|
export const isPaletteShortcut = (event: KeyboardEvent) =>
|
|
21
|
-
(event.ctrlKey || event.metaKey) && !event.altKey && event
|
|
36
|
+
(event.ctrlKey || event.metaKey) && !event.altKey && shortcutKey(event) === "k";
|
|
22
37
|
|
|
23
38
|
/** Focus is inside an open dialog, where only Save fires. */
|
|
24
39
|
export const inDialog = (target: EventTarget | null) =>
|
|
@@ -59,6 +59,11 @@ export type EditorAction =
|
|
|
59
59
|
| { type: "saved"; rev: string; version: number }
|
|
60
60
|
| { type: "published"; rev: string }
|
|
61
61
|
| { type: "set-design"; design: DesignSystem; revision: string | null }
|
|
62
|
+
/**
|
|
63
|
+
* W-536: a site styles edit shown before its save lands, so the next edit builds on it. The
|
|
64
|
+
* save's `set-design` (or a refusal) follows.
|
|
65
|
+
*/
|
|
66
|
+
| { type: "preview-design"; design: DesignSystem }
|
|
62
67
|
| { type: "publish-design"; revision: string }
|
|
63
68
|
/** The site styles as saved elsewhere, after a refused save (W-212). */
|
|
64
69
|
| {
|
|
@@ -87,8 +92,12 @@ const withLayout = (
|
|
|
87
92
|
): EditorState => ({ ...edited(state, { ...state.page, layout }), selectedId, lastDeleted });
|
|
88
93
|
|
|
89
94
|
/** Applies an arrange result; a refused one leaves the state unchanged. */
|
|
90
|
-
const arranged = (state: EditorState, result: Arranged): EditorState =>
|
|
91
|
-
|
|
95
|
+
const arranged = (state: EditorState, result: Arranged): EditorState => {
|
|
96
|
+
if (!result.ok) return state;
|
|
97
|
+
// W-521: an unchanged layout (a drop on its own spot) only selects: no undo step, not unsaved.
|
|
98
|
+
if (result.layout === state.page.layout) return { ...state, selectedId: result.selected };
|
|
99
|
+
return withLayout(state, result.layout, result.selected);
|
|
100
|
+
};
|
|
92
101
|
|
|
93
102
|
/** Page edits kept for undo. Save, publish and design stay on the live state (D-035, proposed). */
|
|
94
103
|
const PAGE_HISTORY_LIMIT = 100;
|
|
@@ -209,7 +218,7 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
209
218
|
if (!state.page.layout) return state;
|
|
210
219
|
return arranged(state, moveNode(state.page.layout, action.id, action.parentId, action.index));
|
|
211
220
|
case "apply-arranged":
|
|
212
|
-
return
|
|
221
|
+
return arranged(state, { ok: true, layout: action.layout, selected: action.selected });
|
|
213
222
|
case "saved":
|
|
214
223
|
// A saved draft on a published entry is not live until Publish (W-190).
|
|
215
224
|
return {
|
|
@@ -220,6 +229,8 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
220
229
|
};
|
|
221
230
|
case "published":
|
|
222
231
|
return { ...state, rev: action.rev, status: "published" };
|
|
232
|
+
case "preview-design":
|
|
233
|
+
return { ...state, design: action.design };
|
|
223
234
|
case "set-design":
|
|
224
235
|
return {
|
|
225
236
|
...state,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import type { createKumoToastManager } from "@cloudflare/kumo";
|
|
3
|
+
import { ArrowSquareOutIcon } from "@phosphor-icons/react";
|
|
3
4
|
import {
|
|
4
5
|
DEVICE_PREVIEW_PX,
|
|
5
6
|
mergeDesign,
|
|
@@ -121,7 +122,14 @@ export function useEditorCommands({
|
|
|
121
122
|
]
|
|
122
123
|
: []),
|
|
123
124
|
{
|
|
124
|
-
|
|
125
|
+
// UX-082: an icon, not "↗" read aloud as an arrow; the new tab is said in words.
|
|
126
|
+
children: React.createElement(
|
|
127
|
+
React.Fragment,
|
|
128
|
+
null,
|
|
129
|
+
"View page",
|
|
130
|
+
React.createElement(ArrowSquareOutIcon, { "aria-hidden": true, size: 14 }),
|
|
131
|
+
React.createElement("span", { className: "emvb-sr-only" }, " (opens in a new tab)"),
|
|
132
|
+
),
|
|
125
133
|
variant: "secondary",
|
|
126
134
|
onClick: () => window.open(path, "_blank", "noopener"),
|
|
127
135
|
},
|
|
@@ -145,14 +153,24 @@ export function useEditorCommands({
|
|
|
145
153
|
|
|
146
154
|
// W-325: design saves run one at a time, each against the newest revision, like page saves.
|
|
147
155
|
// 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
|
|
149
|
-
// the store catches up (the ref updates on the next render).
|
|
156
|
+
// was refused with a 409 by the first. `written` remembers the revision the last save produced
|
|
157
|
+
// until the store catches up (the ref updates on the next render).
|
|
150
158
|
const designQueue = React.useRef<Promise<unknown>>(Promise.resolve());
|
|
151
|
-
|
|
159
|
+
// W-536: every revision this tab's run of saves went through, not just the last one. The store
|
|
160
|
+
// can render an older one of them mid-run (save 1's revision while save 2 is out), which used
|
|
161
|
+
// to send that stale revision with save 3 and get a 409.
|
|
162
|
+
const written = React.useRef<{ chain: Set<string | null>; to: string } | null>(null);
|
|
152
163
|
const baseRevision = () => {
|
|
153
164
|
const current = latest.current.designRevision;
|
|
154
165
|
const last = written.current;
|
|
155
|
-
return last && last.
|
|
166
|
+
return last && last.chain.has(current) ? last.to : current;
|
|
167
|
+
};
|
|
168
|
+
const wrote = (sent: string | null, revision: string) => {
|
|
169
|
+
const chain = written.current?.chain.has(sent) ? written.current.chain : new Set([sent]);
|
|
170
|
+
// What the store shows now is behind this save too.
|
|
171
|
+
chain.add(latest.current.designRevision);
|
|
172
|
+
chain.add(revision);
|
|
173
|
+
written.current = { chain, to: revision };
|
|
156
174
|
};
|
|
157
175
|
const queueDesign = <T>(task: () => Promise<T>): Promise<T> => {
|
|
158
176
|
const run = designQueue.current.then(task, task);
|
|
@@ -160,24 +178,48 @@ export function useEditorCommands({
|
|
|
160
178
|
return run;
|
|
161
179
|
};
|
|
162
180
|
|
|
163
|
-
|
|
181
|
+
// W-536: the newest edit, shown at once. Each edit is built from the `design` the panels render,
|
|
182
|
+
// which used to change only after the save came back, so a second quick edit to the same
|
|
183
|
+
// class (Opacity, then Add shadow) was built without the first and saved over it.
|
|
184
|
+
const shownDesign = React.useRef<DesignSystem | null>(null);
|
|
185
|
+
const changeDesign = (next: DesignSystem) => {
|
|
186
|
+
const base = latest.current.design;
|
|
187
|
+
shownDesign.current = next;
|
|
188
|
+
dispatch({ type: "preview-design", design: next });
|
|
189
|
+
return queueDesign(() => saveDesignNow(next, base));
|
|
190
|
+
};
|
|
164
191
|
|
|
165
|
-
const saveDesignNow = async (next: DesignSystem) => {
|
|
192
|
+
const saveDesignNow = async (next: DesignSystem, base: DesignSystem) => {
|
|
166
193
|
try {
|
|
167
|
-
const
|
|
168
|
-
const revision = await saveDesign(fetcher, next,
|
|
169
|
-
|
|
170
|
-
|
|
194
|
+
const sent = baseRevision();
|
|
195
|
+
const revision = await saveDesign(fetcher, next, sent);
|
|
196
|
+
wrote(sent, revision);
|
|
197
|
+
// A newer edit waiting in the queue stays on screen; its own save follows.
|
|
198
|
+
dispatch({ type: "set-design", design: shownDesign.current ?? next, revision });
|
|
199
|
+
if (shownDesign.current === next) shownDesign.current = null;
|
|
171
200
|
} catch (error) {
|
|
172
201
|
written.current = null;
|
|
202
|
+
// A newer edit already on screen was built on this one, so it stays shown (W-536).
|
|
203
|
+
const newer =
|
|
204
|
+
shownDesign.current !== null && shownDesign.current !== next ? shownDesign.current : null;
|
|
205
|
+
const settled = () => {
|
|
206
|
+
if (!newer) shownDesign.current = null;
|
|
207
|
+
};
|
|
208
|
+
// Take back an edit that didn't save, unless a newer one is already on screen.
|
|
209
|
+
const takeBack = () => {
|
|
210
|
+
if (shownDesign.current !== next) return;
|
|
211
|
+
shownDesign.current = null;
|
|
212
|
+
dispatch({ type: "preview-design", design: base });
|
|
213
|
+
};
|
|
173
214
|
if (error instanceof ApiError && error.status === 409) {
|
|
174
215
|
// W-333: replay this tab's edit onto the styles saved elsewhere when those keys
|
|
175
216
|
// were not also changed there. A real clash still loads the server copy (W-212).
|
|
176
217
|
try {
|
|
177
218
|
const fresh = await loadDesign(fetcher);
|
|
178
|
-
const merged = mergeDesign(
|
|
219
|
+
const merged = mergeDesign(base, next, fresh.design);
|
|
179
220
|
const names = merged.conflicts.map((conflict) => conflict.name).join(", ");
|
|
180
221
|
if (merged.conflicts.length > 0) {
|
|
222
|
+
shownDesign.current = null;
|
|
181
223
|
dispatch({ type: "load-design", ...fresh });
|
|
182
224
|
throw new Error(
|
|
183
225
|
`Site styles were changed in another tab or window (${names}). The latest styles are loaded now: make your change again.`,
|
|
@@ -186,12 +228,14 @@ export function useEditorCommands({
|
|
|
186
228
|
}
|
|
187
229
|
const unchanged = JSON.stringify(merged.design) === JSON.stringify(fresh.design);
|
|
188
230
|
if (unchanged) {
|
|
189
|
-
dispatch({ type: "load-design", ...fresh });
|
|
231
|
+
dispatch({ type: "load-design", ...fresh, ...(newer ? { design: newer } : {}) });
|
|
232
|
+
settled();
|
|
190
233
|
return;
|
|
191
234
|
}
|
|
192
235
|
const revision = await saveDesign(fetcher, merged.design, fresh.revision);
|
|
193
|
-
|
|
194
|
-
dispatch({ type: "set-design", design: merged.design, revision });
|
|
236
|
+
wrote(fresh.revision, revision);
|
|
237
|
+
dispatch({ type: "set-design", design: newer ?? merged.design, revision });
|
|
238
|
+
settled();
|
|
195
239
|
return;
|
|
196
240
|
} catch (retry) {
|
|
197
241
|
if (
|
|
@@ -200,12 +244,14 @@ export function useEditorCommands({
|
|
|
200
244
|
) {
|
|
201
245
|
throw retry;
|
|
202
246
|
}
|
|
247
|
+
takeBack();
|
|
203
248
|
throw new Error(
|
|
204
249
|
"Site styles were changed somewhere else. Reload the editor and try again.",
|
|
205
250
|
{ cause: retry },
|
|
206
251
|
);
|
|
207
252
|
}
|
|
208
253
|
}
|
|
254
|
+
takeBack();
|
|
209
255
|
throw new Error(
|
|
210
256
|
error instanceof ApiError
|
|
211
257
|
? `Couldn't save site styles. ${error.message}`
|
|
@@ -54,7 +54,7 @@ export type EditorData =
|
|
|
54
54
|
| { state: "loading" }
|
|
55
55
|
| { state: "ready"; entry: EditorEntry; design: LoadedDesign }
|
|
56
56
|
| { state: "not-found" | "forbidden" }
|
|
57
|
-
| { state: "error"; message: string };
|
|
57
|
+
| { state: "error"; message: string; retry: () => void };
|
|
58
58
|
|
|
59
59
|
const UNREADABLE = "This page's layout can't be read.";
|
|
60
60
|
|
|
@@ -173,6 +173,7 @@ export function useEditorData(
|
|
|
173
173
|
collection: string = PAGES_COLLECTION,
|
|
174
174
|
): EditorData {
|
|
175
175
|
const [data, setData] = React.useState<EditorData>({ state: "loading" });
|
|
176
|
+
const [attempt, setAttempt] = React.useState(0);
|
|
176
177
|
React.useEffect(() => {
|
|
177
178
|
let active = true;
|
|
178
179
|
setData({ state: "loading" });
|
|
@@ -187,6 +188,7 @@ export function useEditorData(
|
|
|
187
188
|
setData({
|
|
188
189
|
state: "error",
|
|
189
190
|
message: error instanceof Error ? error.message : String(error),
|
|
191
|
+
retry: () => setAttempt((n) => n + 1),
|
|
190
192
|
});
|
|
191
193
|
}
|
|
192
194
|
},
|
|
@@ -194,6 +196,6 @@ export function useEditorData(
|
|
|
194
196
|
return () => {
|
|
195
197
|
active = false;
|
|
196
198
|
};
|
|
197
|
-
}, [fetcher, entryId, collection]);
|
|
199
|
+
}, [fetcher, entryId, collection, attempt]);
|
|
198
200
|
return data;
|
|
199
201
|
}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "../../core/index.ts";
|
|
14
14
|
import { runCommand, type CommandRunners } from "./editor-commands.ts";
|
|
15
15
|
import type { EditorState, HistoryAction } from "./store.ts";
|
|
16
|
-
import { inDialog, isPaletteShortcut } from "./shortcuts.ts";
|
|
16
|
+
import { inDialog, isPaletteShortcut, shortcutKey } from "./shortcuts.ts";
|
|
17
17
|
|
|
18
18
|
const isTextField = (target: EventTarget | null) => {
|
|
19
19
|
const element = target as HTMLElement | null;
|
|
@@ -127,18 +127,29 @@ export function useEditorShortcuts({
|
|
|
127
127
|
handlers.current.palette?.();
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
|
-
if ((event.ctrlKey || event.metaKey) && event
|
|
130
|
+
if ((event.ctrlKey || event.metaKey) && shortcutKey(event) === "s") {
|
|
131
131
|
event.preventDefault();
|
|
132
132
|
runCommand(runners(), "save", null);
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
+
// W-622: holding Delete, Ctrl+D or Ctrl+V auto-repeats; each repeat acted on the next selected
|
|
136
|
+
// element, so a long press emptied whole sections. They act once per press.
|
|
137
|
+
const destructive =
|
|
138
|
+
event.key === "Delete" ||
|
|
139
|
+
event.key === "Backspace" ||
|
|
140
|
+
((event.ctrlKey || event.metaKey) && ["d", "v"].includes(shortcutKey(event)));
|
|
141
|
+
if (event.repeat && destructive) {
|
|
142
|
+
// A held Backspace in a text field still deletes text as usual.
|
|
143
|
+
if (!isTextField(event.target) && !inDialog(event.target)) event.preventDefault();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
135
146
|
if (isTextField(event.target) || inDialog(event.target)) return;
|
|
136
|
-
if ((event.ctrlKey || event.metaKey) && !event.altKey && event
|
|
147
|
+
if ((event.ctrlKey || event.metaKey) && !event.altKey && shortcutKey(event) === "z") {
|
|
137
148
|
event.preventDefault();
|
|
138
149
|
runCommand(runners(), event.shiftKey ? "redo" : "undo", null);
|
|
139
150
|
return;
|
|
140
151
|
}
|
|
141
|
-
if ((event.ctrlKey || event.metaKey) && !event.altKey && event
|
|
152
|
+
if ((event.ctrlKey || event.metaKey) && !event.altKey && shortcutKey(event) === "y") {
|
|
142
153
|
event.preventDefault();
|
|
143
154
|
runCommand(runners(), "redo", null);
|
|
144
155
|
return;
|
|
@@ -146,13 +157,12 @@ export function useEditorShortcuts({
|
|
|
146
157
|
if (!onCanvasOrLayers(event.target)) return;
|
|
147
158
|
const layout = latest.current.page.layout;
|
|
148
159
|
const selected = latest.current.selectedId;
|
|
149
|
-
if ((event.ctrlKey || event.metaKey) && event
|
|
160
|
+
if ((event.ctrlKey || event.metaKey) && shortcutKey(event) === "d" && selected) {
|
|
150
161
|
event.preventDefault();
|
|
151
162
|
runCommand(runners(), "duplicate", selected);
|
|
152
163
|
return;
|
|
153
164
|
}
|
|
154
|
-
const clipKey =
|
|
155
|
-
(event.ctrlKey || event.metaKey) && !event.altKey ? event.key.toLowerCase() : "";
|
|
165
|
+
const clipKey = (event.ctrlKey || event.metaKey) && !event.altKey ? shortcutKey(event) : "";
|
|
156
166
|
if (clipKey === "c" && !event.shiftKey && selected && !hasTextSelection(event.target)) {
|
|
157
167
|
event.preventDefault();
|
|
158
168
|
runCommand(runners(), "copy", selected);
|
|
@@ -9,8 +9,13 @@ import {
|
|
|
9
9
|
type WrapType,
|
|
10
10
|
ELEMENT_DESCRIPTORS,
|
|
11
11
|
findNode,
|
|
12
|
+
LAYOUT_SCHEMA_VERSION,
|
|
12
13
|
moveDown,
|
|
14
|
+
moveIn,
|
|
15
|
+
moveOut,
|
|
16
|
+
newNodeId,
|
|
13
17
|
moveUp,
|
|
18
|
+
parentOf,
|
|
14
19
|
recipeNode,
|
|
15
20
|
withFreshIds,
|
|
16
21
|
subtreeSize,
|
|
@@ -24,9 +29,40 @@ import { ELEMENT_NAMES } from "./element-chrome.ts";
|
|
|
24
29
|
import type { ItemActions } from "./panels/settings/ItemList.tsx";
|
|
25
30
|
import type { EditorAction, EditorState } from "./store.ts";
|
|
26
31
|
|
|
32
|
+
const MOVES = new Set<unknown>([moveUp, moveDown, moveIn, moveOut]);
|
|
33
|
+
|
|
34
|
+
/** "Moved. Heading is 2 of 3 in Container." for the screen reader after an Alt+arrow move. */
|
|
35
|
+
function movedTo(layout: Layout, id: string): string {
|
|
36
|
+
const node = findNode(layout, id);
|
|
37
|
+
const parentId = parentOf(layout, id);
|
|
38
|
+
const parent = parentId ? findNode(layout, parentId) : undefined;
|
|
39
|
+
const siblings: LayoutNode[] =
|
|
40
|
+
parent && "children" in parent && Array.isArray(parent.children) ? parent.children : [];
|
|
41
|
+
const index = siblings.findIndex((child) => child.id === id);
|
|
42
|
+
const name = ELEMENT_NAMES[node?.type ?? "container"] ?? "Element";
|
|
43
|
+
const where = ELEMENT_NAMES[parent?.type ?? "container"] ?? "its container";
|
|
44
|
+
return `Moved. ${name} is ${index + 1} of ${siblings.length} in ${where}.`;
|
|
45
|
+
}
|
|
46
|
+
|
|
27
47
|
const RESTORE_TIMEOUT_MS = 6000;
|
|
28
48
|
const NOTICE_TIMEOUT_MS = 4000;
|
|
29
49
|
|
|
50
|
+
/**
|
|
51
|
+
* UX-070: when an action removes the focused control (a deleted row, a closing toast), move focus
|
|
52
|
+
* to the selected layer, the Layers tree, or the canvas, instead of leaving it on the page body.
|
|
53
|
+
*/
|
|
54
|
+
function keepFocusInLayers(force = false) {
|
|
55
|
+
requestAnimationFrame(() => {
|
|
56
|
+
const active = document.activeElement;
|
|
57
|
+
if (!force && active && active !== document.body && active.isConnected) return;
|
|
58
|
+
(
|
|
59
|
+
document.querySelector<HTMLElement>('.emvb-layer-select[aria-current="true"]') ??
|
|
60
|
+
document.querySelector<HTMLElement>('[data-emvb-editor] [role="tree"]') ??
|
|
61
|
+
document.querySelector<HTMLElement>("iframe[data-emvb-canvas]")
|
|
62
|
+
)?.focus({ preventScroll: true });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
30
66
|
/** Node actions on the layout tree: delete (with restore toast), duplicate, and add from the panel. */
|
|
31
67
|
export function useNodeActions({
|
|
32
68
|
state,
|
|
@@ -52,11 +88,18 @@ export function useNodeActions({
|
|
|
52
88
|
const canMove = canDelete;
|
|
53
89
|
|
|
54
90
|
const finishDelete = (id: string) => {
|
|
91
|
+
// UX-062: the toast names what went, as the confirm button does ("Delete 3 elements").
|
|
92
|
+
const layout = latest.current.page.layout;
|
|
93
|
+
const count = layout ? subtreeSize(layout, id) : 1;
|
|
94
|
+
const name = ELEMENT_NAMES[(layout && findNode(layout, id)?.type) || "container"] ?? "Element";
|
|
95
|
+
const title = count > 1 ? `${count} elements deleted` : `${name} deleted`;
|
|
55
96
|
dispatch({ type: "delete-node", id });
|
|
97
|
+
// UX-070: the deleted row or canvas element took focus with it; keep the keyboard in Layers.
|
|
98
|
+
keepFocusInLayers();
|
|
56
99
|
setDeleteAsk(null);
|
|
57
100
|
if (lastToast.current) toasts.close(lastToast.current);
|
|
58
101
|
const toastId: string = toasts.add({
|
|
59
|
-
title
|
|
102
|
+
title,
|
|
60
103
|
timeout: RESTORE_TIMEOUT_MS,
|
|
61
104
|
actions: [
|
|
62
105
|
{
|
|
@@ -65,6 +108,8 @@ export function useNodeActions({
|
|
|
65
108
|
onClick: () => {
|
|
66
109
|
dispatch({ type: "restore" });
|
|
67
110
|
toasts.close(toastId);
|
|
111
|
+
// The toast is closing with focus in it; the restored element's row takes it.
|
|
112
|
+
keepFocusInLayers(true);
|
|
68
113
|
},
|
|
69
114
|
},
|
|
70
115
|
],
|
|
@@ -99,6 +144,8 @@ export function useNodeActions({
|
|
|
99
144
|
return;
|
|
100
145
|
}
|
|
101
146
|
dispatch({ type: "apply-arranged", layout: result.layout, selected: result.selected });
|
|
147
|
+
// W-770: a keyboard move only announced refusals; say where the element landed.
|
|
148
|
+
if (MOVES.has(run)) announce(movedTo(result.layout, id));
|
|
102
149
|
if (result.note) {
|
|
103
150
|
announce(`Duplicated. ${result.note}`);
|
|
104
151
|
if (lastToast.current) toasts.close(lastToast.current);
|
|
@@ -176,11 +223,14 @@ export function useNodeActions({
|
|
|
176
223
|
};
|
|
177
224
|
|
|
178
225
|
const addFromPanel = (type: ElementType) => {
|
|
179
|
-
const
|
|
180
|
-
if (!
|
|
181
|
-
|
|
226
|
+
const current = latest.current.page.layout;
|
|
227
|
+
if (!current && type === "container") {
|
|
228
|
+
dispatch({ type: "add-root-container" });
|
|
182
229
|
return;
|
|
183
230
|
}
|
|
231
|
+
// UX-094: an empty page (one made outside EmVB has no layout) gets its container first, so
|
|
232
|
+
// a click or palette insert lands instead of doing nothing.
|
|
233
|
+
const layout = current ?? startingLayout();
|
|
184
234
|
const node = newElement(type);
|
|
185
235
|
if (!node) return;
|
|
186
236
|
place(layout, node, ELEMENT_DESCRIPTORS.find((d) => d.type === type)?.name ?? type);
|
|
@@ -188,8 +238,7 @@ export function useNodeActions({
|
|
|
188
238
|
|
|
189
239
|
/** A section recipe built from the site's styles (W-320). */
|
|
190
240
|
const addRecipe = (id: string) => {
|
|
191
|
-
const layout = latest.current.page.layout;
|
|
192
|
-
if (!layout) return;
|
|
241
|
+
const layout = latest.current.page.layout ?? startingLayout();
|
|
193
242
|
const node = recipeNode(id, latest.current.design, layout);
|
|
194
243
|
if (!node) return;
|
|
195
244
|
place(layout, withFreshIds(layout, node), `${node.label ?? "Section"} section`, true);
|
|
@@ -210,3 +259,9 @@ export function useNodeActions({
|
|
|
210
259
|
items,
|
|
211
260
|
};
|
|
212
261
|
}
|
|
262
|
+
|
|
263
|
+
/** One empty container, the start of a page that has no layout yet (UX-094). */
|
|
264
|
+
const startingLayout = (): Layout => ({
|
|
265
|
+
schemaVersion: LAYOUT_SCHEMA_VERSION,
|
|
266
|
+
root: { id: newNodeId(), type: "container", props: {}, children: [] },
|
|
267
|
+
});
|
|
@@ -65,7 +65,12 @@ export function saveFailure(
|
|
|
65
65
|
if (error.status === 400 || error.status === 422) {
|
|
66
66
|
const path = /\broot(?:\.children\[\d+\])*/.exec(error.message)?.[0];
|
|
67
67
|
const id = path && page.layout ? nodeIdAtPath(page.layout, path) : null;
|
|
68
|
-
|
|
68
|
+
// UX-095: with no element to highlight, "fix the highlighted setting" pointed at nothing.
|
|
69
|
+
if (!id) {
|
|
70
|
+
const message = `Couldn't save. ${error.message}`;
|
|
71
|
+
return { status: { kind: "error", message, retry: false }, rejection: error.message };
|
|
72
|
+
}
|
|
73
|
+
return { status: fixAndSave, rejection: error.message, select: id };
|
|
69
74
|
}
|
|
70
75
|
return { status: { kind: "error", message: `Couldn't save. ${error.message}`, retry: false } };
|
|
71
76
|
}
|
|
@@ -189,14 +194,24 @@ export function useSave(
|
|
|
189
194
|
}, [start]);
|
|
190
195
|
|
|
191
196
|
/** Conflict → Overwrite: take the stored revision and save over it. */
|
|
197
|
+
// W-836: the overwrite counts as the save in flight, so a save asked for meanwhile (Save draft,
|
|
198
|
+
// Ctrl+S, autosave) waits for it and uses its new revision instead of the stale one, which
|
|
199
|
+
// reopened the conflict right after a successful overwrite.
|
|
192
200
|
const overwrite = React.useCallback(async () => {
|
|
193
201
|
setConflict(false);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
202
|
+
const run: Promise<string | null> = (async () => {
|
|
203
|
+
try {
|
|
204
|
+
const stored = await loadEntry(fetcher, latest.current.id, collection);
|
|
205
|
+
return await write(stored.rev);
|
|
206
|
+
} catch {
|
|
207
|
+
setStatus({ kind: "error", message: OFFLINE, retry: true });
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
})().finally(() => {
|
|
211
|
+
if (inFlight.current === run) inFlight.current = null;
|
|
212
|
+
});
|
|
213
|
+
inFlight.current = run;
|
|
214
|
+
await run;
|
|
200
215
|
}, [fetcher, write, collection]);
|
|
201
216
|
|
|
202
217
|
const publish = React.useCallback(async (): Promise<boolean> => {
|
package/src/admin/forms-api.ts
CHANGED
|
@@ -66,6 +66,8 @@ export type DefinitionField = {
|
|
|
66
66
|
type: string;
|
|
67
67
|
label: string;
|
|
68
68
|
required: boolean;
|
|
69
|
+
options?: ReadonlyArray<{ label: string; value: string }>;
|
|
70
|
+
validation?: { minLength?: number; maxLength?: number; min?: number; max?: number };
|
|
69
71
|
};
|
|
70
72
|
|
|
71
73
|
export async function loadFormFields(
|