@perkyzz/emvb 0.2.1 → 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 +126 -0
- package/src/admin/editor/CommandPalette.tsx +118 -0
- package/src/admin/editor/Editor.tsx +188 -152
- package/src/admin/editor/EditorOverlay.tsx +9 -1
- package/src/admin/editor/PerfMeter.tsx +121 -0
- package/src/admin/editor/ShareLink.tsx +164 -0
- package/src/admin/editor/ShortcutsDialog.tsx +4 -1
- package/src/admin/editor/Timeline.tsx +287 -0
- package/src/admin/editor/TopBar.tsx +4 -0
- package/src/admin/editor/canvas/CanvasFrame.tsx +62 -370
- package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
- package/src/admin/editor/canvas/SelectionOverlay.tsx +87 -47
- 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 +114 -0
- package/src/admin/editor/editor-chrome.tsx +346 -0
- package/src/admin/editor/editor-commands.ts +360 -0
- package/src/admin/editor/editor-css.ts +5 -3
- package/src/admin/editor/element-chrome.ts +89 -0
- package/src/admin/editor/feature-css.ts +105 -0
- package/src/admin/editor/host.ts +35 -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/live-data.tsx +71 -0
- package/src/admin/editor/palette-items.ts +136 -0
- package/src/admin/editor/palette.ts +68 -0
- package/src/admin/editor/panels/AddPanel.tsx +48 -68
- package/src/admin/editor/panels/ClassesSection.tsx +5 -1
- package/src/admin/editor/panels/ColorControl.tsx +2 -10
- package/src/admin/editor/panels/ElementPanel.tsx +74 -102
- package/src/admin/editor/panels/LayersPanel.tsx +72 -63
- package/src/admin/editor/panels/LeftPanel.tsx +4 -1
- package/src/admin/editor/panels/SettingsPanel.tsx +13 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +18 -10
- package/src/admin/editor/panels/TokenScales.tsx +168 -0
- package/src/admin/editor/panels/VariableSection.tsx +10 -14
- 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 +285 -0
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
- package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
- package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
- 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/MotionControl.tsx +252 -0
- package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +26 -2
- package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
- package/src/admin/editor/panels/settings/form-names.ts +7 -11
- package/src/admin/editor/panels/settings/length-units.ts +16 -5
- package/src/admin/editor/panels/settings/style-sections.ts +7 -2
- 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 +6 -1
- 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 +30 -14
- package/src/admin/editor/useNodeActions.ts +44 -16
- 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/admin/ui.ts +4 -4
- 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 +109 -0
- package/src/astro/resolve-theme.ts +184 -64
- package/src/astro/resolve.ts +63 -16
- package/src/astro/theme-posts.ts +48 -5
- package/src/astro/visitor.ts +204 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +282 -0
- package/src/core/arrange.ts +150 -34
- package/src/core/audience/rules.ts +124 -0
- package/src/core/audience/variants.ts +51 -0
- package/src/core/canvas-styles.ts +24 -0
- package/src/core/clipboard.ts +11 -32
- package/src/core/css/generate.ts +29 -2
- package/src/core/css/print.ts +12 -0
- package/src/core/css/scope.ts +3 -3
- package/src/core/css/trace.ts +169 -0
- package/src/core/css-keywords.ts +83 -0
- package/src/core/data/bindings.ts +255 -0
- 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/tokens.ts +127 -0
- package/src/core/design/variables.ts +25 -21
- package/src/core/elements/dynamic-elements.ts +117 -2
- package/src/core/elements/form-elements.ts +1 -0
- package/src/core/elements/index.ts +185 -7
- package/src/core/forms/binding.ts +4 -13
- package/src/core/history/diff.ts +152 -0
- package/src/core/index.ts +121 -0
- package/src/core/local-style.ts +27 -0
- package/src/core/migrate/index.ts +12 -4
- package/src/core/nesting.ts +4 -22
- package/src/core/perf/meter.ts +160 -0
- package/src/core/perf/scripts.ts +61 -0
- package/src/core/recipes/index.ts +433 -0
- 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 +206 -17
- package/src/core/render/loop.ts +54 -7
- package/src/core/render/pagination.ts +9 -1
- package/src/core/render/vnode.ts +12 -2
- package/src/core/sanitize/css.ts +129 -80
- package/src/core/sanitize/motion.ts +129 -0
- package/src/core/sanitize/svg.ts +8 -3
- package/src/core/sanitize/url.ts +10 -1
- package/src/core/schema/design.ts +29 -8
- package/src/core/schema/layout.ts +291 -169
- package/src/core/schema/motion.ts +14 -0
- package/src/core/schema/style.ts +101 -66
- package/src/core/share/link.ts +187 -0
- package/src/core/tabs/presence.ts +7 -17
- package/src/core/theme/dynamic.ts +242 -32
- package/src/core/theme/float.ts +1 -1
- package/src/core/theme/pagination.ts +56 -0
- 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
|
@@ -1,50 +1,22 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
1
|
import { createPortal } from "react-dom";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
canDrop,
|
|
6
|
-
findNode,
|
|
7
|
-
isPlainTextNode,
|
|
8
|
-
isMultilineText,
|
|
9
|
-
plainTextOf,
|
|
10
|
-
DEVICE_PREVIEW_PX,
|
|
11
|
-
REASONS,
|
|
12
|
-
type DragSource,
|
|
13
|
-
type PopupDevice,
|
|
14
|
-
type Layout,
|
|
15
|
-
type LayoutNode,
|
|
16
|
-
type VNode,
|
|
17
|
-
} from "../../../core/index.ts";
|
|
18
|
-
import {
|
|
19
|
-
dropContainer,
|
|
20
|
-
dropIndex,
|
|
21
|
-
edgeDrop,
|
|
22
|
-
EXISTING_ELEMENT_MIME,
|
|
23
|
-
idAt,
|
|
24
|
-
NEW_ELEMENT_MIME,
|
|
25
|
-
transferKinds,
|
|
26
|
-
type Rect,
|
|
27
|
-
} from "../dnd/drop-target.ts";
|
|
28
|
-
import { dragStash } from "../dnd/drag-stash.ts";
|
|
29
|
-
import { newElement } from "../dnd/new-element.ts";
|
|
30
|
-
import { useCanvasEvents } from "./canvas-events.ts";
|
|
31
|
-
import {
|
|
32
|
-
SelectionOverlay,
|
|
33
|
-
type Box,
|
|
34
|
-
type DropTarget,
|
|
35
|
-
type InvalidDrop,
|
|
36
|
-
} from "./SelectionOverlay.tsx";
|
|
37
|
-
import { applyStatePreview, type StatePreview } from "./state-preview.ts";
|
|
38
|
-
import { revealInAccordions, revealInMenus, revealInTabs } from "./tab-reveal.ts";
|
|
2
|
+
import { isMultilineText, type Layout, type PopupDevice, type VNode } from "../../../core/index.ts";
|
|
3
|
+
import type { PasteRefusal } from "../useClipboardActions.ts";
|
|
39
4
|
import { CanvasTextEdit } from "./CanvasTextEdit.tsx";
|
|
40
|
-
import {
|
|
41
|
-
import
|
|
5
|
+
import { type CanvasZoom } from "./canvas-scale.ts";
|
|
6
|
+
import { SelectionOverlay, type Box, type InvalidDrop } from "./SelectionOverlay.tsx";
|
|
7
|
+
import type { StatePreview } from "./state-preview.ts";
|
|
8
|
+
import { useCanvasDnD } from "./use-canvas-dnd.ts";
|
|
9
|
+
import { useCanvasSession, type CanvasSelection } from "./use-canvas-session.ts";
|
|
10
|
+
|
|
11
|
+
export { canvasScale, type CanvasZoom } from "./canvas-scale.ts";
|
|
12
|
+
export { dropLineBox } from "./drop-line.ts";
|
|
13
|
+
export type { CanvasSelection } from "./use-canvas-session.ts";
|
|
42
14
|
|
|
43
15
|
const SRCDOC =
|
|
44
16
|
'<!doctype html><html><head><meta charset="utf-8"><style>html,body{margin:0}</style></head><body></body></html>';
|
|
45
17
|
|
|
46
18
|
/** Element types that hold other elements and show the empty drop placeholder (W-128). */
|
|
47
|
-
const DROP_BOXES = ["container", "div-block", "flexbox", "grid", "section", "form"]
|
|
19
|
+
const DROP_BOXES = ["container", "div-block", "flexbox", "grid", "section", "form", "loop-empty"]
|
|
48
20
|
.map((type) => `.emvb-${type}:empty`)
|
|
49
21
|
.join(",");
|
|
50
22
|
/**
|
|
@@ -72,7 +44,16 @@ const EDITOR_CANVAS_CSS =
|
|
|
72
44
|
`:where(${NO_ITEMS}){min-height:48px}` +
|
|
73
45
|
`:is(${NO_ITEMS}){outline:1px dashed #94a3b8;outline-offset:-1px}` +
|
|
74
46
|
`:is(${NO_ITEMS})::after{content:"No items yet: add them in this element's Content settings";display:block;line-height:48px;text-align:center;${HINT}}` +
|
|
75
|
-
".emvb-image-missing{display:inline-block;min-width:48px;min-height:48px;background:var(--color-kumo-tint, #eee)}[data-emvb-editing]{color:transparent !important}"
|
|
47
|
+
".emvb-image-missing{display:inline-block;min-width:48px;min-height:48px;background:var(--color-kumo-tint, #eee)}[data-emvb-editing]{color:transparent !important}" +
|
|
48
|
+
// W-307: a bound element shows a thin violet underline so live values read as live.
|
|
49
|
+
"[data-emvb-bound]{text-decoration-line:underline;text-decoration-style:dotted;text-decoration-color:#7c3aed;text-underline-offset:3px}" +
|
|
50
|
+
// W-312: every A/B arm shows on the canvas, outlined so it's clear visitors see only one.
|
|
51
|
+
"[data-emvb-variant]{outline:1px dashed #d97706;outline-offset:2px}" +
|
|
52
|
+
// W-313: visitor-aware elements show on the canvas, outlined in teal.
|
|
53
|
+
"[data-emvb-audience]{outline:1px dashed #0d9488;outline-offset:2px}" +
|
|
54
|
+
// W-308: the Loop's Empty state shows under its items in the editor, marked as such.
|
|
55
|
+
".emvb-loop-item~.emvb-loop-empty{outline:1px dashed #94a3b8;outline-offset:2px;position:relative}" +
|
|
56
|
+
`.emvb-loop-item~.emvb-loop-empty::before{content:"Empty state: shown when there are no entries";display:block;${HINT}}`;
|
|
76
57
|
|
|
77
58
|
/**
|
|
78
59
|
* Tablet and Mobile previews scroll without a visible scrollbar (W-140), as phones and tablets
|
|
@@ -80,25 +61,6 @@ const EDITOR_CANVAS_CSS =
|
|
|
80
61
|
*/
|
|
81
62
|
const PREVIEW_SCROLL_CSS = "html{scrollbar-width:none}html::-webkit-scrollbar{display:none}";
|
|
82
63
|
|
|
83
|
-
/** Fit scales the canvas down to the stage; Actual shows it at 100% and scrolls (W-158). */
|
|
84
|
-
export type CanvasZoom = "fit" | "actual";
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* The canvas's page width and on-screen scale (W-158, D-046). Desktop lays the page out at least
|
|
88
|
-
* 1280 px wide (wider when the stage is), Tablet at 768 and Mobile at 390. Fit scales it down to
|
|
89
|
-
* the stage width, never up; Actual keeps 100% and the stage scrolls sideways.
|
|
90
|
-
*/
|
|
91
|
-
export function canvasScale(
|
|
92
|
-
device: PopupDevice,
|
|
93
|
-
stageWidth: number,
|
|
94
|
-
zoom: CanvasZoom,
|
|
95
|
-
): { width: number; scale: number } {
|
|
96
|
-
const base = DEVICE_PREVIEW_PX[device];
|
|
97
|
-
const width = device === "desktop" ? Math.max(base, Math.floor(stageWidth)) : base;
|
|
98
|
-
if (zoom === "actual" || stageWidth <= 0) return { width, scale: 1 };
|
|
99
|
-
return { width, scale: Math.min(1, stageWidth / width) };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
64
|
/** A box measured inside the canvas page, in the overlay's on-screen pixels (W-158). */
|
|
103
65
|
export const zoomBox = (box: Box, scale: number): Box =>
|
|
104
66
|
scale === 1
|
|
@@ -118,88 +80,6 @@ const zoomInvalid = (drop: InvalidDrop | null, scale: number): InvalidDrop | nul
|
|
|
118
80
|
label: { ...drop.label, x: drop.label.x * scale, y: drop.label.y * scale },
|
|
119
81
|
};
|
|
120
82
|
|
|
121
|
-
const boxOf = (doc: Document, id: string | null): Box | null => {
|
|
122
|
-
if (!id) return null;
|
|
123
|
-
const element = doc.querySelector(`[data-emvb-id="${CSS.escape(id)}"]`);
|
|
124
|
-
if (!element) return null;
|
|
125
|
-
const rect = element.getBoundingClientRect();
|
|
126
|
-
return { top: rect.top, left: rect.left, width: rect.width, height: rect.height };
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const rectOf = (doc: Document, id: string): Rect | null => {
|
|
130
|
-
const box = boxOf(doc, id);
|
|
131
|
-
return box ? { top: box.top, left: box.left, width: box.width, height: box.height } : null;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const sameBox = (a: Box | null, b: Box | null) =>
|
|
135
|
-
a === b ||
|
|
136
|
-
(!!a &&
|
|
137
|
-
!!b &&
|
|
138
|
-
a.top === b.top &&
|
|
139
|
-
a.left === b.left &&
|
|
140
|
-
a.width === b.width &&
|
|
141
|
-
a.height === b.height);
|
|
142
|
-
|
|
143
|
-
const directionOf = (node: LayoutNode) =>
|
|
144
|
-
(isParentNode(node) ? node.style?.flexDirection : undefined) ?? "column";
|
|
145
|
-
|
|
146
|
-
const childrenOf = (node: LayoutNode): LayoutNode[] => (isParentNode(node) ? node.children : []);
|
|
147
|
-
|
|
148
|
-
/** Refusals that end the walk to an accepting ancestor, so the user sees why (W-128). */
|
|
149
|
-
const STOPS = new Set<string>([REASONS.intoItself, REASONS.tooDeep, REASONS.tooMany]);
|
|
150
|
-
|
|
151
|
-
/** Insertion line for the drop index inside a container (DESIGN: brand accent). */
|
|
152
|
-
export function dropLineBox(
|
|
153
|
-
direction: string,
|
|
154
|
-
container: Rect,
|
|
155
|
-
children: Rect[],
|
|
156
|
-
index: number,
|
|
157
|
-
): Box {
|
|
158
|
-
const row = direction.startsWith("row");
|
|
159
|
-
const [start, size] = row ? (["left", "width"] as const) : (["top", "height"] as const);
|
|
160
|
-
const first = children[0];
|
|
161
|
-
const last = children.at(-1);
|
|
162
|
-
const before = index > 0 ? children[index - 1] : undefined;
|
|
163
|
-
const after = index < children.length ? children[index] : undefined;
|
|
164
|
-
let at = container[start];
|
|
165
|
-
if (first && index <= 0) at = first[start];
|
|
166
|
-
else if (last && index >= children.length) at = last[start] + last[size];
|
|
167
|
-
else if (before && after) at = (before[start] + before[size] + after[start]) / 2;
|
|
168
|
-
return row
|
|
169
|
-
? { top: container.top, left: at - 1, width: 2, height: container.height }
|
|
170
|
-
: { top: at - 1, left: container.left, width: container.width, height: 2 };
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/** What is being dragged over the canvas, or null while the browser still hides it. */
|
|
174
|
-
function draggedSource(transfer: DataTransfer | null, existing: boolean): DragSource | null {
|
|
175
|
-
if (existing) {
|
|
176
|
-
// Chromium may omit getData until drop, so the session stash wins during dragover.
|
|
177
|
-
const id =
|
|
178
|
-
dragStash.id() ??
|
|
179
|
-
(transfer?.getData(EXISTING_ELEMENT_MIME) ||
|
|
180
|
-
(transfer as DataTransfer & { emvbId?: string }).emvbId ||
|
|
181
|
-
"");
|
|
182
|
-
return id ? { kind: "existing", id } : null;
|
|
183
|
-
}
|
|
184
|
-
const type = transfer?.getData(NEW_ELEMENT_MIME) || dragStash.type() || "";
|
|
185
|
-
const node = type ? newElement(type) : null;
|
|
186
|
-
return node ? { kind: "new", node } : null;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export type CanvasSelection = {
|
|
190
|
-
selectedId: string | null;
|
|
191
|
-
labelFor: (id: string) => string;
|
|
192
|
-
canDelete: (id: string) => boolean;
|
|
193
|
-
canMove: (id: string) => boolean;
|
|
194
|
-
canDuplicate: (id: string) => boolean;
|
|
195
|
-
onSelect: (id: string | null) => void;
|
|
196
|
-
onDelete: (id: string) => void;
|
|
197
|
-
onDuplicate: (id: string) => void;
|
|
198
|
-
onKeyDown: (event: KeyboardEvent) => void;
|
|
199
|
-
/** Copy and paste in the quick actions (W-093). */
|
|
200
|
-
clipboard?: ClipboardActions;
|
|
201
|
-
};
|
|
202
|
-
|
|
203
83
|
/**
|
|
204
84
|
* The canvas: a sandboxed `srcdoc` iframe without `allow-scripts` (D-011, D-014).
|
|
205
85
|
* W-015/W-019: Add-tile and existing-element drops (native HTML5 DnD, K16).
|
|
@@ -207,6 +87,7 @@ export type CanvasSelection = {
|
|
|
207
87
|
export function CanvasFrame({
|
|
208
88
|
vnode,
|
|
209
89
|
css,
|
|
90
|
+
canvasStyles = [],
|
|
210
91
|
layout,
|
|
211
92
|
selection,
|
|
212
93
|
statePreview = null,
|
|
@@ -220,6 +101,8 @@ export function CanvasFrame({
|
|
|
220
101
|
}: {
|
|
221
102
|
vnode: VNode | null;
|
|
222
103
|
css: string;
|
|
104
|
+
/** The host's stylesheets, loaded before EmVB's CSS (W-327). */
|
|
105
|
+
canvasStyles?: readonly string[];
|
|
223
106
|
layout: Layout | null;
|
|
224
107
|
selection: CanvasSelection;
|
|
225
108
|
/** The style state chosen in the Style tab, shown on the selected element (W-089). */
|
|
@@ -237,236 +120,45 @@ export function CanvasFrame({
|
|
|
237
120
|
/** Stores a canvas plain-text edit (W-097). */
|
|
238
121
|
onCommitText: (id: string, text: string) => void;
|
|
239
122
|
}) {
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
observer.observe(element);
|
|
251
|
-
return () => observer.disconnect();
|
|
252
|
-
}, []);
|
|
253
|
-
const { width: pageWidth, scale } = canvasScale(device, stageWidth, zoom);
|
|
254
|
-
const scaleRef = React.useRef(scale);
|
|
255
|
-
scaleRef.current = scale;
|
|
256
|
-
const scaleReport = React.useRef(onScale);
|
|
257
|
-
scaleReport.current = onScale;
|
|
258
|
-
React.useEffect(() => scaleReport.current?.(scale), [scale]);
|
|
259
|
-
const [doc, setDoc] = React.useState<Document | null>(null);
|
|
260
|
-
const [hoverId, setHoverId] = React.useState<string | null>(null);
|
|
261
|
-
// W-268: the page's React tree is built once per render of the layout, not on every hover,
|
|
262
|
-
// selection or overlay change. With the same element objects React skips the whole canvas
|
|
263
|
-
// subtree; rebuilding it walked every element on each mouse move (300+ elements: ~20 ms a move).
|
|
264
|
-
const pageTree = React.useMemo(() => (vnode ? vnodeToReact(vnode) : null), [vnode]);
|
|
265
|
-
const [dropLine, setDropLine] = React.useState<Box | null>(null);
|
|
266
|
-
const [invalid, setInvalid] = React.useState<InvalidDrop | null>(null);
|
|
267
|
-
const [dropTarget, setDropTarget] = React.useState<DropTarget | null>(null);
|
|
268
|
-
const [boxes, setBoxes] = React.useState<{ hover: Box | null; selected: Box | null }>({
|
|
269
|
-
hover: null,
|
|
270
|
-
selected: null,
|
|
123
|
+
const session = useCanvasSession({
|
|
124
|
+
vnode,
|
|
125
|
+
canvasStyles,
|
|
126
|
+
layout,
|
|
127
|
+
selection,
|
|
128
|
+
statePreview,
|
|
129
|
+
device,
|
|
130
|
+
zoom,
|
|
131
|
+
onScale,
|
|
132
|
+
refusal,
|
|
271
133
|
});
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
selection.onSelect(id);
|
|
282
|
-
setEditingId(id);
|
|
283
|
-
}
|
|
284
|
-
},
|
|
285
|
-
};
|
|
286
|
-
const dropRef = React.useRef(onDropNew);
|
|
287
|
-
dropRef.current = onDropNew;
|
|
288
|
-
const moveRef = React.useRef(onMove);
|
|
289
|
-
moveRef.current = onMove;
|
|
290
|
-
const cancelled = React.useRef(false);
|
|
291
|
-
|
|
292
|
-
const clearDrag = React.useCallback(() => {
|
|
293
|
-
setDropLine(null);
|
|
294
|
-
setDropTarget(null);
|
|
295
|
-
setInvalid(null);
|
|
296
|
-
}, []);
|
|
297
|
-
|
|
298
|
-
const onLoad = React.useCallback(() => {
|
|
299
|
-
const loaded = frame.current?.contentDocument;
|
|
300
|
-
if (loaded?.body) setDoc(loaded);
|
|
301
|
-
}, []);
|
|
302
|
-
|
|
303
|
-
const resolveDrop = React.useCallback(
|
|
304
|
-
(
|
|
305
|
-
clientX: number,
|
|
306
|
-
clientY: number,
|
|
307
|
-
target: EventTarget | null,
|
|
308
|
-
source: DragSource | null = null,
|
|
309
|
-
) => {
|
|
310
|
-
const current = layoutRef.current;
|
|
311
|
-
const currentDoc = frame.current?.contentDocument;
|
|
312
|
-
if (!current || !currentDoc) return null;
|
|
313
|
-
// W-128: the nearest element that takes the dragged one. A refusal the user must see
|
|
314
|
-
// (into itself, too deep, too many) stops the walk so the invalid outline still shows.
|
|
315
|
-
const verdict = (parent: LayoutNode) =>
|
|
316
|
-
source ? canDrop(current, source, parent.id) : { ok: isParentNode(parent) };
|
|
317
|
-
const accepts = (parent: LayoutNode) => {
|
|
318
|
-
const result = verdict(parent);
|
|
319
|
-
return result.ok || ("reason" in result && STOPS.has(result.reason as string));
|
|
320
|
-
};
|
|
321
|
-
const activePanel = (tabsId: string) => {
|
|
322
|
-
const tabs = findNode(current, tabsId);
|
|
323
|
-
return childrenOf(tabs ?? current.root).find(
|
|
324
|
-
(panel) => (rectOf(currentDoc, panel.id)?.height ?? 0) > 0,
|
|
325
|
-
)?.id;
|
|
326
|
-
};
|
|
327
|
-
const point = { x: clientX, y: clientY };
|
|
328
|
-
const hovered = dropContainer(current, idAt(target), accepts, activePanel);
|
|
329
|
-
const hoveredBox = rectOf(currentDoc, hovered.id);
|
|
330
|
-
const edge =
|
|
331
|
-
hoveredBox && hovered.id !== current.root.id
|
|
332
|
-
? edgeDrop(current, hovered, hoveredBox, point, (parent) => verdict(parent).ok)
|
|
333
|
-
: null;
|
|
334
|
-
const container = (edge && findNode(current, edge.parentId)) || hovered;
|
|
335
|
-
const direction = directionOf(container);
|
|
336
|
-
const kids = childrenOf(container);
|
|
337
|
-
const rects = kids.map((child) => {
|
|
338
|
-
const rect = rectOf(currentDoc, child.id);
|
|
339
|
-
return rect ?? { top: clientY, left: clientX, width: 0, height: 0 };
|
|
340
|
-
});
|
|
341
|
-
const index = edge ? edge.index : dropIndex(direction, rects, point);
|
|
342
|
-
const containerBox = edge ? rectOf(currentDoc, container.id) : hoveredBox;
|
|
343
|
-
return {
|
|
344
|
-
parentId: container.id,
|
|
345
|
-
index,
|
|
346
|
-
line: containerBox ? dropLineBox(direction, containerBox, rects, index) : null,
|
|
347
|
-
outline: containerBox,
|
|
348
|
-
};
|
|
349
|
-
},
|
|
350
|
-
[],
|
|
351
|
-
);
|
|
352
|
-
|
|
353
|
-
const paintDrag = React.useCallback(
|
|
354
|
-
(
|
|
355
|
-
transfer: DataTransfer | null,
|
|
356
|
-
clientX: number,
|
|
357
|
-
clientY: number,
|
|
358
|
-
target: EventTarget | null,
|
|
359
|
-
) => {
|
|
360
|
-
const kinds = transferKinds(transfer);
|
|
361
|
-
if (!kinds.neu && !kinds.existing) return false;
|
|
362
|
-
const current = layoutRef.current;
|
|
363
|
-
if (!current) return false;
|
|
364
|
-
const source = draggedSource(transfer, kinds.existing);
|
|
365
|
-
const next = resolveDrop(clientX, clientY, target, source);
|
|
366
|
-
if (!next) {
|
|
367
|
-
clearDrag();
|
|
368
|
-
return true;
|
|
369
|
-
}
|
|
370
|
-
// Until the source is known the line is provisional; canDrop runs again on drop.
|
|
371
|
-
const allowed = source ? canDrop(current, source, next.parentId) : null;
|
|
372
|
-
if (allowed && !allowed.ok) {
|
|
373
|
-
setDropLine(null);
|
|
374
|
-
setInvalid(
|
|
375
|
-
next.outline
|
|
376
|
-
? { outline: next.outline, label: { x: clientX, y: clientY, reason: allowed.reason } }
|
|
377
|
-
: null,
|
|
378
|
-
);
|
|
379
|
-
if (transfer) transfer.dropEffect = "none";
|
|
380
|
-
return true;
|
|
381
|
-
}
|
|
382
|
-
setInvalid(null);
|
|
383
|
-
setDropLine(next.line);
|
|
384
|
-
setDropTarget(
|
|
385
|
-
next.outline
|
|
386
|
-
? {
|
|
387
|
-
outline: next.outline,
|
|
388
|
-
// The root is the page itself, so say so rather than "Container" (W-128).
|
|
389
|
-
label:
|
|
390
|
-
next.parentId === current.root.id
|
|
391
|
-
? "Inside Page"
|
|
392
|
-
: `Inside ${handlers.current.labelFor(next.parentId)}`,
|
|
393
|
-
}
|
|
394
|
-
: null,
|
|
395
|
-
);
|
|
396
|
-
if (allowed && transfer) transfer.dropEffect = kinds.existing ? "move" : "copy";
|
|
397
|
-
return true;
|
|
398
|
-
},
|
|
399
|
-
[clearDrag, resolveDrop],
|
|
400
|
-
);
|
|
401
|
-
|
|
402
|
-
useCanvasEvents({
|
|
403
|
-
doc,
|
|
404
|
-
frame,
|
|
405
|
-
handlers,
|
|
406
|
-
layoutRef,
|
|
407
|
-
moveRef,
|
|
408
|
-
dropRef,
|
|
409
|
-
cancelled,
|
|
410
|
-
clearDrag,
|
|
411
|
-
resolveDrop,
|
|
412
|
-
paintDrag,
|
|
413
|
-
setHoverId,
|
|
414
|
-
scale: scaleRef,
|
|
134
|
+
const { dropLine, dropTarget, invalid } = useCanvasDnD({
|
|
135
|
+
doc: session.doc,
|
|
136
|
+
frame: session.frame,
|
|
137
|
+
handlers: session.handlers,
|
|
138
|
+
layoutRef: session.layoutRef,
|
|
139
|
+
setHoverId: session.setHoverId,
|
|
140
|
+
scaleRef: session.scaleRef,
|
|
141
|
+
onDropNew,
|
|
142
|
+
onMove,
|
|
415
143
|
});
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
: null;
|
|
435
|
-
React.useEffect(() => {
|
|
436
|
-
if (!doc) return;
|
|
437
|
-
revealInTabs(doc, selectedId);
|
|
438
|
-
revealInAccordions(doc, selectedId, (itemId) => {
|
|
439
|
-
const item = layout ? findNode(layout, itemId) : undefined;
|
|
440
|
-
return item?.type === "accordion-item" && item.props.open === true;
|
|
441
|
-
});
|
|
442
|
-
revealInMenus(doc, selectedId);
|
|
443
|
-
}, [doc, selectedId, vnode, layout]);
|
|
444
|
-
const previewId = statePreview?.id === selectedId ? statePreview.id : null;
|
|
445
|
-
const previewState = previewId ? statePreview?.state : undefined;
|
|
446
|
-
React.useEffect(() => {
|
|
447
|
-
if (doc)
|
|
448
|
-
applyStatePreview(
|
|
449
|
-
doc,
|
|
450
|
-
previewId && previewState ? { id: previewId, state: previewState } : null,
|
|
451
|
-
);
|
|
452
|
-
}, [doc, previewId, previewState, vnode]);
|
|
453
|
-
|
|
454
|
-
React.useEffect(() => {
|
|
455
|
-
if (!doc) return;
|
|
456
|
-
let frameId = 0;
|
|
457
|
-
const track = () => {
|
|
458
|
-
const hover = hoverId === selectedId ? null : boxOf(doc, hoverId);
|
|
459
|
-
const selected = boxOf(doc, selectedId);
|
|
460
|
-
setBoxes((current) =>
|
|
461
|
-
sameBox(current.hover, hover) && sameBox(current.selected, selected)
|
|
462
|
-
? current
|
|
463
|
-
: { hover, selected },
|
|
464
|
-
);
|
|
465
|
-
frameId = requestAnimationFrame(track);
|
|
466
|
-
};
|
|
467
|
-
track();
|
|
468
|
-
return () => cancelAnimationFrame(frameId);
|
|
469
|
-
}, [doc, hoverId, selectedId]);
|
|
144
|
+
const {
|
|
145
|
+
stage,
|
|
146
|
+
pageWidth,
|
|
147
|
+
scale,
|
|
148
|
+
frame,
|
|
149
|
+
onLoad,
|
|
150
|
+
editingId,
|
|
151
|
+
editingText,
|
|
152
|
+
editingBox,
|
|
153
|
+
editingEl,
|
|
154
|
+
editingNode,
|
|
155
|
+
setEditingId,
|
|
156
|
+
boxes,
|
|
157
|
+
selectedId,
|
|
158
|
+
refused,
|
|
159
|
+
doc,
|
|
160
|
+
pageTree,
|
|
161
|
+
} = session;
|
|
470
162
|
|
|
471
163
|
return (
|
|
472
164
|
<div className="emvb-stage" ref={stage} data-emvb-zoom={zoom}>
|
|
@@ -31,6 +31,7 @@ export function DeviceBar({
|
|
|
31
31
|
device,
|
|
32
32
|
hidden,
|
|
33
33
|
canHide,
|
|
34
|
+
hideLabel,
|
|
34
35
|
onDevice,
|
|
35
36
|
onToggleHidden,
|
|
36
37
|
zoom = "fit",
|
|
@@ -41,6 +42,8 @@ export function DeviceBar({
|
|
|
41
42
|
/** Whether the selected element is hidden on `device`. */
|
|
42
43
|
hidden: boolean;
|
|
43
44
|
canHide: boolean;
|
|
45
|
+
/** From the hide-on-device command, so the checkbox wording has one source. */
|
|
46
|
+
hideLabel: string;
|
|
44
47
|
onDevice: (device: PopupDevice) => void;
|
|
45
48
|
onToggleHidden: () => void;
|
|
46
49
|
/** Fit or 100% (W-158), with the current on-screen scale for the readout. */
|
|
@@ -71,7 +74,7 @@ export function DeviceBar({
|
|
|
71
74
|
</div>
|
|
72
75
|
<label className="emvb-device-hide">
|
|
73
76
|
<input type="checkbox" checked={hidden} disabled={!canHide} onChange={onToggleHidden} />
|
|
74
|
-
|
|
77
|
+
{hideLabel}
|
|
75
78
|
</label>
|
|
76
79
|
{onZoom && (
|
|
77
80
|
<Button
|