@hyperframes/studio 0.9.41 → 0.9.43
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/dist/assets/{codec-B_mpbc4w.js → codec-DHChmhF2.js} +1 -1
- package/dist/assets/{hyperframes-player-Dvi3I_mv.js → hyperframes-player-CdbweVDs.js} +1 -1
- package/dist/assets/{index-B5ExwsOp.js → index-CjWDrWWG.js} +166 -166
- package/dist/assets/{index-BrFm9Y5k.js → index-l-ti2dV8.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-MHQ57yZ6.js → pausedVideoDecoder-xqOQ0ciK.js} +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.html +1 -1
- package/dist/index.js +1380 -989
- package/package.json +10 -10
- package/src/components/editor/LayersPanel.opaque.test.ts +176 -0
- package/src/components/editor/LayersPanel.tsx +41 -10
- package/src/components/editor/domEditInlineText.ts +1 -16
- package/src/components/editor/domEditOverlayGeometry.ts +2 -0
- package/src/components/editor/domEditOverlayStartGesture.ts +31 -7
- package/src/components/editor/domEditingTypes.ts +7 -1
- package/src/components/editor/gestureUndoRevert.ts +18 -1
- package/src/components/editor/inlineTextStyleRange.fill.test.ts +129 -0
- package/src/components/editor/inlineTextStyleRange.test.ts +0 -82
- package/src/components/editor/layerKind.ts +2 -19
- package/src/components/editor/layersPanelSort.ts +2 -2
- package/src/components/editor/manualEdits.ts +1 -0
- package/src/components/editor/manualEditsSnapshot.ts +10 -0
- package/src/components/editor/manualOffsetDrag.test.ts +1 -1
- package/src/components/editor/manualOffsetDrag.ts +17 -6
- package/src/components/editor/marqueeCommit.ts +47 -4
- package/src/components/editor/plainTranslate.ts +37 -16
- package/src/components/editor/previewDrafts.test.ts +263 -0
- package/src/components/editor/previewDrafts.ts +73 -0
- package/src/components/editor/previewGestureStartRead.test.ts +279 -0
- package/src/components/editor/previewGestureStartRead.ts +67 -0
- package/src/components/editor/previewGestureStarts.ts +21 -15
- package/src/components/editor/previewLayers.test.ts +308 -0
- package/src/components/editor/previewLayers.ts +164 -0
- package/src/components/editor/previewOverlayRects.test.ts +62 -0
- package/src/components/editor/previewOverlayRects.ts +23 -8
- package/src/components/editor/previewPointerTargets.test.ts +68 -1
- package/src/components/editor/previewSelection.ts +55 -11
- package/src/components/editor/resizeDraft.ts +38 -0
- package/src/components/editor/snapTargetCollection.ts +26 -62
- package/src/components/editor/useDomEditOverlayGestures.ts +2 -2
- package/src/components/editor/useLayerDrag.ts +1 -1
- package/src/components/nle/NLEPreview.slowBoot.test.ts +0 -1
- package/src/hooks/domEditDeleteMembers.test.ts +7 -0
- package/src/hooks/domSelectionTimelineMirror.ts +3 -1
- package/src/hooks/timelineTimingSync.ts +4 -1
- package/src/hooks/useDomSelection.ts +2 -0
- package/src/hooks/useEditorSave.test.tsx +22 -1
- package/src/hooks/useEditorSave.ts +3 -1
- package/src/hooks/usePreviewInteraction.ts +4 -1
- package/src/hooks/useProjectFileWriter.ts +7 -3
- package/src/hooks/useTimelineSelectionPreviewSync.test.tsx +30 -0
- package/src/hooks/useTimelineSelectionPreviewSync.ts +7 -2
- package/src/player/lib/layerOrdering.ts +2 -11
- package/src/player/lib/previewElements.ts +68 -0
- package/src/test-setup.ts +2 -0
- package/src/utils/gsapSoftReload.ts +1 -1
- package/src/utils/studioFileHistory.ts +1 -1
- package/src/utils/studioHelpers.ts +27 -4
- package/src/utils/studioSaveDiagnostics.test.ts +34 -0
- package/src/utils/studioSaveDiagnostics.ts +35 -6
- package/src/utils/timelineCompositionInsert.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/studio",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.43",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
"dockview-react": "8.3.1",
|
|
65
65
|
"gsap": "^3.13.0",
|
|
66
66
|
"mediabunny": "^1.65.2",
|
|
67
|
-
"@hyperframes/core": "0.9.
|
|
68
|
-
"@hyperframes/parsers": "0.9.
|
|
69
|
-
"@hyperframes/player": "0.9.
|
|
70
|
-
"@hyperframes/
|
|
71
|
-
"@hyperframes/
|
|
72
|
-
"@hyperframes/studio-server": "0.9.
|
|
67
|
+
"@hyperframes/core": "0.9.43",
|
|
68
|
+
"@hyperframes/parsers": "0.9.43",
|
|
69
|
+
"@hyperframes/player": "0.9.43",
|
|
70
|
+
"@hyperframes/shader-transitions": "0.9.43",
|
|
71
|
+
"@hyperframes/sdk": "0.9.43",
|
|
72
|
+
"@hyperframes/studio-server": "0.9.43"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -83,10 +83,10 @@
|
|
|
83
83
|
"tailwindcss": "^4.3.3",
|
|
84
84
|
"tsup": "^8.0.0",
|
|
85
85
|
"typescript": "^5.0.0",
|
|
86
|
-
"vite": "^6.4.
|
|
87
|
-
"vitest": "^4.1.
|
|
86
|
+
"vite": "^6.4.5",
|
|
87
|
+
"vitest": "^4.1.12",
|
|
88
88
|
"zustand": "^5.0.0",
|
|
89
|
-
"@hyperframes/producer": "0.9.
|
|
89
|
+
"@hyperframes/producer": "0.9.43"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"react": "19",
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { act, createElement } from "react";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
6
|
+
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
7
|
+
import { installEditingAgent } from "../../../../core/src/runtime/editingAgent";
|
|
8
|
+
import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
|
|
9
|
+
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
10
|
+
import { usePreviewIframeStore } from "../../player/store/previewIframeStore";
|
|
11
|
+
import type { DomEditSelection } from "./domEditing";
|
|
12
|
+
import { LayersPanel } from "./LayersPanel";
|
|
13
|
+
import { announcePreviewDocumentLoaded } from "../../player/sceneSwap";
|
|
14
|
+
import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
|
|
15
|
+
import { standInFor } from "./previewSelection";
|
|
16
|
+
|
|
17
|
+
installReactActEnvironment();
|
|
18
|
+
|
|
19
|
+
const mocks = vi.hoisted(() => ({
|
|
20
|
+
previewIframeRef: { current: null } as { current: unknown },
|
|
21
|
+
activeGroupElement: null as HTMLElement | null,
|
|
22
|
+
applyDomSelection: vi.fn(),
|
|
23
|
+
setActiveGroupElement: vi.fn(),
|
|
24
|
+
// While set, a layers read waits on it after the frame answers.
|
|
25
|
+
hold: null as Promise<void> | null,
|
|
26
|
+
answered: 0,
|
|
27
|
+
}));
|
|
28
|
+
vi.mock("../../player/lib/previewElements", async (importOriginal) => {
|
|
29
|
+
const actual = await importOriginal<typeof import("../../player/lib/previewElements")>();
|
|
30
|
+
return {
|
|
31
|
+
...actual,
|
|
32
|
+
previewLayers: async (...args: Parameters<typeof actual.previewLayers>) => {
|
|
33
|
+
const reply = await actual.previewLayers(...args);
|
|
34
|
+
mocks.answered += 1;
|
|
35
|
+
await mocks.hold;
|
|
36
|
+
return reply;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
vi.mock("../../contexts/StudioContext", () => ({
|
|
41
|
+
useStudioShellContextOptional: () => ({
|
|
42
|
+
previewIframeRef: mocks.previewIframeRef,
|
|
43
|
+
activeCompPath: "index.html",
|
|
44
|
+
showToast: vi.fn(),
|
|
45
|
+
}),
|
|
46
|
+
useStudioPlaybackContextOptional: () => ({
|
|
47
|
+
refreshKey: 0,
|
|
48
|
+
compositionLoading: false,
|
|
49
|
+
timelineElements: [],
|
|
50
|
+
isPlaying: false,
|
|
51
|
+
}),
|
|
52
|
+
}));
|
|
53
|
+
vi.mock("../../contexts/DomEditContext", () => ({
|
|
54
|
+
useDomEditContext: () => ({
|
|
55
|
+
domEditSelection: null,
|
|
56
|
+
activeGroupElement: mocks.activeGroupElement,
|
|
57
|
+
applyDomSelection: mocks.applyDomSelection,
|
|
58
|
+
updateDomEditHoverSelection: vi.fn(),
|
|
59
|
+
handleDomZIndexReorderCommit: vi.fn(),
|
|
60
|
+
setActiveGroupElement: mocks.setActiveGroupElement,
|
|
61
|
+
}),
|
|
62
|
+
}));
|
|
63
|
+
vi.mock("../nle/useCanvasZOrderTimelineMirror", () => ({
|
|
64
|
+
useLayerReorderTimelineMirror: () => vi.fn(),
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
const closers: Array<() => void> = [];
|
|
68
|
+
afterEach(() => {
|
|
69
|
+
closers.splice(0).forEach((close) => close());
|
|
70
|
+
mocks.activeGroupElement = null;
|
|
71
|
+
mocks.hold = null;
|
|
72
|
+
mocks.answered = 0;
|
|
73
|
+
vi.clearAllMocks();
|
|
74
|
+
usePreviewIframeStore.setState({ iframe: null });
|
|
75
|
+
document.body.innerHTML = "";
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
79
|
+
function opaqueFrame() {
|
|
80
|
+
const frame: Record<string, unknown> = {};
|
|
81
|
+
const iframe = detachedFakeIframe(frame);
|
|
82
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
83
|
+
Object.defineProperty(frame, "document", {
|
|
84
|
+
get: () => {
|
|
85
|
+
throw new DOMException("blocked", "SecurityError");
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
const parent = {
|
|
89
|
+
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
90
|
+
window.dispatchEvent(
|
|
91
|
+
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
92
|
+
),
|
|
93
|
+
} as unknown as Window;
|
|
94
|
+
const agent = installEditingAgent(parent);
|
|
95
|
+
frame.postMessage = (data: unknown) =>
|
|
96
|
+
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
97
|
+
closers.push(() => agent.dispose());
|
|
98
|
+
return iframe;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
it("lists an opaque frame's layers, selects a row, and drills into a group row", async () => {
|
|
102
|
+
document.body.innerHTML = `<main data-composition-id="main">
|
|
103
|
+
<div id="card"><h1 id="title">Hi</h1></div>
|
|
104
|
+
<div id="pair" data-hf-group="pair"><i id="a"></i></div>
|
|
105
|
+
<div id="host" data-composition-src="compositions/intro-card.html"></div></main>`;
|
|
106
|
+
const iframe = opaqueFrame();
|
|
107
|
+
mocks.previewIframeRef.current = iframe;
|
|
108
|
+
usePreviewIframeStore.setState({ iframe });
|
|
109
|
+
const host = document.createElement("div");
|
|
110
|
+
document.body.append(host);
|
|
111
|
+
const root = createRoot(host);
|
|
112
|
+
act(() => root.render(createElement(LayersPanel)));
|
|
113
|
+
closers.push(() => act(() => root.unmount()));
|
|
114
|
+
|
|
115
|
+
const rows = () => [...host.querySelectorAll<HTMLElement>("[data-layer-index]")];
|
|
116
|
+
await vi.waitFor(() => expect(rows()).toHaveLength(5));
|
|
117
|
+
const named = (label: string) => rows().find((r) => r.textContent?.includes(label))!;
|
|
118
|
+
expect(named("Title").querySelector("[data-layer-kind]")!.getAttribute("data-layer-kind")).toBe(
|
|
119
|
+
"text",
|
|
120
|
+
);
|
|
121
|
+
expect(named("pair").title).toBe("This layer can't be reordered");
|
|
122
|
+
const hostIcon = named("Intro").querySelector("[data-layer-kind]")!;
|
|
123
|
+
expect(hostIcon.className).toContain("bg-on");
|
|
124
|
+
|
|
125
|
+
act(() => named("Title").click());
|
|
126
|
+
await vi.waitFor(() => expect(mocks.applyDomSelection).toHaveBeenCalled());
|
|
127
|
+
const picked = mocks.applyDomSelection.mock.calls[0]![0] as DomEditSelection;
|
|
128
|
+
expect(picked).toMatchObject({ id: "title", selector: "#title" });
|
|
129
|
+
expect(picked.handle).toBeTruthy();
|
|
130
|
+
|
|
131
|
+
act(() => void named("pair").dispatchEvent(new MouseEvent("dblclick", { bubbles: true })));
|
|
132
|
+
await vi.waitFor(() => expect(mocks.setActiveGroupElement).toHaveBeenCalledOnce());
|
|
133
|
+
const group = mocks.setActiveGroupElement.mock.calls[0]![0] as HTMLElement;
|
|
134
|
+
expect(group.hasAttribute("data-hf-group")).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
function renderPanel(iframe: HTMLIFrameElement) {
|
|
138
|
+
mocks.previewIframeRef.current = iframe;
|
|
139
|
+
usePreviewIframeStore.setState({ iframe });
|
|
140
|
+
const host = document.createElement("div");
|
|
141
|
+
document.body.append(host);
|
|
142
|
+
const root = createRoot(host);
|
|
143
|
+
act(() => root.render(createElement(LayersPanel)));
|
|
144
|
+
closers.push(() => act(() => root.unmount()));
|
|
145
|
+
return () =>
|
|
146
|
+
[...host.querySelectorAll<HTMLElement>("[data-layer-index]")].map((r) => r.textContent);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
it("leaves a drill-in whose group a reload took, rather than list the whole page under it", async () => {
|
|
150
|
+
document.body.innerHTML = `<main data-composition-id="main">
|
|
151
|
+
<div id="card"></div><div id="pair" data-hf-group="pair"><i id="a"></i></div></main>`;
|
|
152
|
+
const iframe = opaqueFrame();
|
|
153
|
+
const [pair] = (await queryPreviewElements(iframe, "#pair"))!.matches;
|
|
154
|
+
const [described] = (await describePreviewElements(iframe, [pair!.handle]))!;
|
|
155
|
+
mocks.activeGroupElement = standInFor(iframe, described!);
|
|
156
|
+
document.getElementById("pair")!.remove();
|
|
157
|
+
const rows = renderPanel(iframe);
|
|
158
|
+
await vi.waitFor(() => expect(mocks.setActiveGroupElement).toHaveBeenCalledWith(null));
|
|
159
|
+
expect(rows()).toEqual([]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("reads the layers once more when a refresh lands while a read is in flight", async () => {
|
|
163
|
+
document.body.innerHTML = `<main data-composition-id="main"><div id="card"></div></main>`;
|
|
164
|
+
let release!: () => void;
|
|
165
|
+
mocks.hold = new Promise<void>((resolve) => (release = resolve));
|
|
166
|
+
const iframe = opaqueFrame();
|
|
167
|
+
const rows = renderPanel(iframe);
|
|
168
|
+
await vi.waitFor(() => expect(mocks.answered).toBe(1));
|
|
169
|
+
// Past the panel's settle timer, so only the announced refresh can bring the new layer.
|
|
170
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
171
|
+
// The first read has its answer and is waiting; the page changes and announces it.
|
|
172
|
+
document.querySelector("main")!.insertAdjacentHTML("beforeend", `<div id="late"></div>`);
|
|
173
|
+
act(() => announcePreviewDocumentLoaded(iframe));
|
|
174
|
+
act(() => release());
|
|
175
|
+
await vi.waitFor(() => expect(rows()).toEqual(["Late", "Card"]));
|
|
176
|
+
});
|
|
@@ -40,6 +40,10 @@ import { zReorderCoalesceKey } from "../../hooks/useElementLifecycleOps";
|
|
|
40
40
|
import { useLayerReorderTimelineMirror } from "../nle/useCanvasZOrderTimelineMirror";
|
|
41
41
|
import { runZLaneGesture } from "../nle/zLaneGesture";
|
|
42
42
|
import { useLayerRevealOverride } from "./useLayerRevealOverride";
|
|
43
|
+
import { previewFrameOpaque } from "../../player/lib/previewChannel";
|
|
44
|
+
import { describePreviewElements } from "../../player/lib/previewElements";
|
|
45
|
+
import { collectPreviewLayerItems, layerDataAttribute } from "./previewLayers";
|
|
46
|
+
import { resolvePreviewSelection, selectionDataAttribute } from "./previewSelection";
|
|
43
47
|
|
|
44
48
|
// Rows this panel renders before it stops. A display budget, not a document limit.
|
|
45
49
|
const LAYERS_PANEL_MAX_ROWS = 80;
|
|
@@ -146,9 +150,26 @@ export const LayersPanel = memo(function LayersPanel({ host }: { host?: LayersPa
|
|
|
146
150
|
const isMasterView = !activeCompPath || activeCompPath === "index.html";
|
|
147
151
|
|
|
148
152
|
const livePreviewIframe = useLivePreviewIframe();
|
|
153
|
+
// The opaque read in flight; `again` holds a refresh that arrived meanwhile, run once it settles.
|
|
154
|
+
const opaqueRead = useRef<{ again: boolean } | null>(null);
|
|
149
155
|
const collectLayers = useCallback(() => {
|
|
150
156
|
const iframe = previewIframeRef.current;
|
|
151
157
|
if (!iframe) return;
|
|
158
|
+
if (previewFrameOpaque(iframe)) {
|
|
159
|
+
if (opaqueRead.current) return void (opaqueRead.current.again = true);
|
|
160
|
+
const read = { again: false };
|
|
161
|
+
opaqueRead.current = read;
|
|
162
|
+
const scope = { activeCompositionPath: activeCompPath, activeGroupElement };
|
|
163
|
+
void collectPreviewLayerItems(iframe, scope, LAYERS_PANEL_MAX_ROWS).then((reply) => {
|
|
164
|
+
if (opaqueRead.current !== read) return;
|
|
165
|
+
opaqueRead.current = null;
|
|
166
|
+
// A reload took the drilled-into group; leave it as same-origin does below.
|
|
167
|
+
if (reply?.missingGroup) return setActiveGroupElement(null);
|
|
168
|
+
if (reply) setLayers(sortLayersByZIndex(reply.items));
|
|
169
|
+
if (read.again) collectLayers();
|
|
170
|
+
});
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
152
173
|
let doc: Document | null = null;
|
|
153
174
|
try {
|
|
154
175
|
doc = iframe.contentDocument;
|
|
@@ -175,6 +196,7 @@ export const LayersPanel = memo(function LayersPanel({ host }: { host?: LayersPa
|
|
|
175
196
|
}, [previewIframeRef, activeCompPath, isMasterView, activeGroupElement, setActiveGroupElement]);
|
|
176
197
|
|
|
177
198
|
useEffect(() => {
|
|
199
|
+
opaqueRead.current = null;
|
|
178
200
|
collectLayers();
|
|
179
201
|
}, [collectLayers, refreshKey, zEditVersion, livePreviewIframe]);
|
|
180
202
|
|
|
@@ -210,15 +232,20 @@ export const LayersPanel = memo(function LayersPanel({ host }: { host?: LayersPa
|
|
|
210
232
|
}, [collectLayers]);
|
|
211
233
|
|
|
212
234
|
const resolveSelection = useCallback(
|
|
213
|
-
(layer: DomEditLayerItem) => {
|
|
214
|
-
const
|
|
215
|
-
const
|
|
216
|
-
return resolveDomEditSelection(el, {
|
|
235
|
+
async (layer: DomEditLayerItem) => {
|
|
236
|
+
const iframe = previewIframeRef.current;
|
|
237
|
+
const options = {
|
|
217
238
|
activeCompositionPath: activeCompPath,
|
|
218
239
|
isMasterView,
|
|
219
240
|
preferClipAncestor: false,
|
|
220
241
|
activeGroupElement,
|
|
221
|
-
}
|
|
242
|
+
};
|
|
243
|
+
if (layer.preview && iframe) {
|
|
244
|
+
const [described] = (await describePreviewElements(iframe, [layer.preview.handle])) ?? [];
|
|
245
|
+
return described ? resolvePreviewSelection(iframe, described, options) : null;
|
|
246
|
+
}
|
|
247
|
+
const el = liveLayerElement(layer, iframe?.contentDocument, activeCompPath);
|
|
248
|
+
return resolveDomEditSelection(el, options);
|
|
222
249
|
},
|
|
223
250
|
[activeCompPath, isMasterView, previewIframeRef, activeGroupElement],
|
|
224
251
|
);
|
|
@@ -228,7 +255,8 @@ export const LayersPanel = memo(function LayersPanel({ host }: { host?: LayersPa
|
|
|
228
255
|
const selection = await resolveSelection(layer);
|
|
229
256
|
if (!selection) return;
|
|
230
257
|
|
|
231
|
-
|
|
258
|
+
const scope = activeCompPath || "index.html";
|
|
259
|
+
let matchedId = findMatchingTimelineElementId(selection, timelineElements, scope);
|
|
232
260
|
|
|
233
261
|
if (!matchedId) {
|
|
234
262
|
const sourceFile = selection.sourceFile ?? "index.html";
|
|
@@ -253,7 +281,7 @@ export const LayersPanel = memo(function LayersPanel({ host }: { host?: LayersPa
|
|
|
253
281
|
}
|
|
254
282
|
}
|
|
255
283
|
},
|
|
256
|
-
[currentTime, resolveSelection, timelineElements],
|
|
284
|
+
[activeCompPath, currentTime, resolveSelection, timelineElements],
|
|
257
285
|
);
|
|
258
286
|
|
|
259
287
|
const handleSelectLayer = useCallback(
|
|
@@ -275,7 +303,7 @@ export const LayersPanel = memo(function LayersPanel({ host }: { host?: LayersPa
|
|
|
275
303
|
const handleLayerDoubleClick = useCallback(
|
|
276
304
|
async (layer: DomEditLayerItem) => {
|
|
277
305
|
const selection = await resolveSelection(layer);
|
|
278
|
-
if (selection
|
|
306
|
+
if (selection && selectionDataAttribute(selection, "data-hf-group") !== null) {
|
|
279
307
|
setActiveGroupElement(selection.element);
|
|
280
308
|
} else {
|
|
281
309
|
await handleSelectLayer(layer);
|
|
@@ -456,8 +484,11 @@ export const LayersPanel = memo(function LayersPanel({ host }: { host?: LayersPa
|
|
|
456
484
|
const draggable = isLayerDraggable(layer);
|
|
457
485
|
const isCollapsed = collapsed[layer.key] ?? false;
|
|
458
486
|
const hasChildren = layer.childCount > 0;
|
|
459
|
-
const isCompHost =
|
|
460
|
-
|
|
487
|
+
const isCompHost = layer.preview
|
|
488
|
+
? layerDataAttribute(layer, "data-composition-src") !== null ||
|
|
489
|
+
layerDataAttribute(layer, "data-composition-file") !== null
|
|
490
|
+
: isCompositionHost(layer.element);
|
|
491
|
+
const kind = layer.preview?.kind ?? layerKindOf(layer.element, hasChildren);
|
|
461
492
|
const KindIcon = KIND_ICON[kind];
|
|
462
493
|
const kindName = kind[0].toUpperCase() + kind.slice(1);
|
|
463
494
|
const hint = draggable
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hasOnlyFormattingChildren } from "@hyperframes/core/runtime/editing-port";
|
|
2
2
|
import type { DomEditSelection } from "./domEditingTypes";
|
|
3
3
|
import { isTextEditableSelection } from "./domEditingLayers";
|
|
4
4
|
|
|
@@ -53,21 +53,6 @@ export function canEditElementTextInline(element: HTMLElement | null): boolean {
|
|
|
53
53
|
return (element.textContent ?? "").trim().length > 0;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export function hasOnlyFormattingChildren(element: HTMLElement): boolean {
|
|
57
|
-
for (const child of Array.from(element.children)) {
|
|
58
|
-
if (!isRichTextFormattingTag(child.tagName)) return false;
|
|
59
|
-
if (!isHtmlFromAnyWindow(child)) return false;
|
|
60
|
-
// Formatting nests, and a structural child hidden inside a span is still
|
|
61
|
-
// structural.
|
|
62
|
-
if (!hasOnlyFormattingChildren(child as HTMLElement)) return false;
|
|
63
|
-
}
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function isHtmlFromAnyWindow(node: Element): boolean {
|
|
68
|
-
return node.namespaceURI === "http://www.w3.org/1999/xhtml";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
56
|
/** Where and when a press landed, for recognising the next one as a pair. */
|
|
72
57
|
export interface PressMark {
|
|
73
58
|
x: number;
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
type ElementTransformSnapshot,
|
|
16
16
|
} from "@hyperframes/core/runtime/editing-port";
|
|
17
17
|
import { type OverlayMeasurePass, readThroughPass } from "./domEditOverlayMeasurePass";
|
|
18
|
+
import type { PreviewGestureStart } from "./previewGestureStartRead";
|
|
18
19
|
|
|
19
20
|
export const RESIZE_HANDLE_HIT_PX = 16;
|
|
20
21
|
|
|
@@ -40,6 +41,7 @@ export interface GroupOverlayItem {
|
|
|
40
41
|
selection: DomEditSelection;
|
|
41
42
|
element: HTMLElement;
|
|
42
43
|
rect: OverlayRect;
|
|
44
|
+
start?: PreviewGestureStart;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
export type ResolvedElementRef = {
|
|
@@ -34,7 +34,9 @@ import {
|
|
|
34
34
|
type ResizeHandle,
|
|
35
35
|
type UseDomEditOverlayGesturesOptions,
|
|
36
36
|
} from "./domEditOverlayGestures";
|
|
37
|
-
import { collectSnapContext, buildExcludeElements } from "./snapTargetCollection";
|
|
37
|
+
import { collectSnapContext, buildExcludeElements, type SnapContext } from "./snapTargetCollection";
|
|
38
|
+
import { MOVING_LAYER_UNREADABLE } from "./plainTranslate";
|
|
39
|
+
import type { PreviewGestureStart } from "./previewGestureStartRead";
|
|
38
40
|
import { editsPlainCss } from "../../hooks/gsapRuntimeKeyframes";
|
|
39
41
|
import { logResize, resetResizeMoveLog } from "../../utils/resizeDebug";
|
|
40
42
|
import { logDrag, readDragPositions, resetDragMoveLog } from "../../utils/dragDebug";
|
|
@@ -52,6 +54,7 @@ export function startGroupDrag(
|
|
|
52
54
|
e: React.PointerEvent<HTMLElement>,
|
|
53
55
|
opts: UseDomEditOverlayGesturesOptions,
|
|
54
56
|
at?: EditMoment,
|
|
57
|
+
snap?: SnapContext,
|
|
55
58
|
): boolean {
|
|
56
59
|
const items = opts.groupOverlayItemsRef.current;
|
|
57
60
|
if (items.length <= 1) return false;
|
|
@@ -65,6 +68,13 @@ export function startGroupDrag(
|
|
|
65
68
|
notifyBlockedPress(e, opts, blockedSelection);
|
|
66
69
|
return false;
|
|
67
70
|
}
|
|
71
|
+
const moving = items.find((item) => item.start?.gsap?.moving)?.selection;
|
|
72
|
+
if (moving) {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
e.stopPropagation();
|
|
75
|
+
opts.onBlockedMoveRef.current(moving, MOVING_LAYER_UNREADABLE);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
68
78
|
|
|
69
79
|
opts.onManualDragStartRef.current?.();
|
|
70
80
|
const dragItems = filterNestedDomEditGroupItems(items);
|
|
@@ -77,6 +87,7 @@ export function startGroupDrag(
|
|
|
77
87
|
rect: item.rect,
|
|
78
88
|
gesture: "drag",
|
|
79
89
|
at,
|
|
90
|
+
start: item.start,
|
|
80
91
|
});
|
|
81
92
|
if (!result.ok) {
|
|
82
93
|
restoreManualOffsetDragMembers(members);
|
|
@@ -108,7 +119,8 @@ export function startGroupDrag(
|
|
|
108
119
|
const overlayEl = opts.overlayRef.current;
|
|
109
120
|
const iframe = opts.iframeRef.current;
|
|
110
121
|
const snapContext =
|
|
111
|
-
|
|
122
|
+
snap ??
|
|
123
|
+
(overlayEl && iframe
|
|
112
124
|
? collectSnapContext({
|
|
113
125
|
overlayEl,
|
|
114
126
|
iframe,
|
|
@@ -117,7 +129,7 @@ export function startGroupDrag(
|
|
|
117
129
|
groupSelections: items.map((i) => i.selection),
|
|
118
130
|
}),
|
|
119
131
|
})
|
|
120
|
-
: undefined;
|
|
132
|
+
: undefined);
|
|
121
133
|
|
|
122
134
|
e.preventDefault();
|
|
123
135
|
e.stopPropagation();
|
|
@@ -150,9 +162,13 @@ export function startGesture(
|
|
|
150
162
|
resizeHandle?: ResizeHandle;
|
|
151
163
|
resizeCorner?: { x: number; y: number };
|
|
152
164
|
at?: EditMoment;
|
|
165
|
+
/** Read off a frame Studio cannot script at the press: the element's start and the snap targets. */
|
|
166
|
+
start?: PreviewGestureStart;
|
|
167
|
+
snap?: SnapContext;
|
|
153
168
|
},
|
|
154
169
|
): boolean {
|
|
155
170
|
const at = options?.at;
|
|
171
|
+
const start = options?.start;
|
|
156
172
|
const sel = options?.selection ?? opts.selectionRef.current;
|
|
157
173
|
const rect = options?.rect ?? opts.overlayRectRef.current;
|
|
158
174
|
const box = opts.boxRef.current;
|
|
@@ -172,8 +188,8 @@ export function startGesture(
|
|
|
172
188
|
// layout size. offsetWidth/Height are transform-free; the overlay-rect
|
|
173
189
|
// fallback (rect / editScale) includes the element's own GSAP scale and
|
|
174
190
|
// would make a rescaled element's draft grow from the RENDERED size.
|
|
175
|
-
const layoutWidth = sel.element.offsetWidth;
|
|
176
|
-
const layoutHeight = sel.element.offsetHeight;
|
|
191
|
+
const layoutWidth = start?.layout.width ?? sel.element.offsetWidth;
|
|
192
|
+
const layoutHeight = start?.layout.height ?? sel.element.offsetHeight;
|
|
177
193
|
const actualWidth =
|
|
178
194
|
size.width > 0 ? size.width : layoutWidth > 0 ? layoutWidth : rect.width / rect.editScaleX;
|
|
179
195
|
const actualHeight =
|
|
@@ -196,6 +212,11 @@ export function startGesture(
|
|
|
196
212
|
let pathOffsetMember: ManualOffsetDragMember | undefined;
|
|
197
213
|
|
|
198
214
|
if (kind === "drag") {
|
|
215
|
+
if (start?.gsap?.moving) {
|
|
216
|
+
opts.onBlockedMoveRef.current(sel, MOVING_LAYER_UNREADABLE);
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
199
220
|
opts.onManualDragStartRef.current?.();
|
|
200
221
|
const result = createManualOffsetDragMember({
|
|
201
222
|
key: selectionCacheKey(sel),
|
|
@@ -204,6 +225,7 @@ export function startGesture(
|
|
|
204
225
|
rect,
|
|
205
226
|
gesture: "drag",
|
|
206
227
|
at,
|
|
228
|
+
start,
|
|
207
229
|
});
|
|
208
230
|
if (!result.ok) {
|
|
209
231
|
opts.onBlockedMoveRef.current(result.selection, result.reason);
|
|
@@ -226,6 +248,7 @@ export function startGesture(
|
|
|
226
248
|
rect,
|
|
227
249
|
gesture: "resize",
|
|
228
250
|
at,
|
|
251
|
+
start,
|
|
229
252
|
});
|
|
230
253
|
if (result.ok) {
|
|
231
254
|
pathOffsetMember = result.member;
|
|
@@ -267,11 +290,12 @@ export function startGesture(
|
|
|
267
290
|
}
|
|
268
291
|
const snapContext =
|
|
269
292
|
(kind === "drag" || kind === "resize") && overlayEl && iframe
|
|
270
|
-
?
|
|
293
|
+
? (options?.snap ??
|
|
294
|
+
collectSnapContext({
|
|
271
295
|
overlayEl,
|
|
272
296
|
iframe,
|
|
273
297
|
excludeElements: buildExcludeElements({ iframe, selection: sel }),
|
|
274
|
-
})
|
|
298
|
+
}))
|
|
275
299
|
: undefined;
|
|
276
300
|
e.preventDefault();
|
|
277
301
|
e.stopPropagation();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PatchTarget } from "../../utils/sourcePatcher";
|
|
2
2
|
import type { GsapAnimation } from "@hyperframes/parsers/gsap-parser";
|
|
3
|
-
import type { EditingElementHandle } from "@hyperframes/core/runtime/editing-port";
|
|
3
|
+
import type { EditingElementHandle, LayerKind } from "@hyperframes/core/runtime/editing-port";
|
|
4
4
|
|
|
5
5
|
export const CURATED_STYLE_PROPERTIES = [
|
|
6
6
|
"position",
|
|
@@ -112,6 +112,12 @@ export interface DomEditLayerItem {
|
|
|
112
112
|
selector?: string;
|
|
113
113
|
selectorIndex?: number;
|
|
114
114
|
sourceFile: string;
|
|
115
|
+
preview?: {
|
|
116
|
+
handle: string;
|
|
117
|
+
zIndex: number;
|
|
118
|
+
kind: LayerKind;
|
|
119
|
+
dataAttributes: Record<string, string>;
|
|
120
|
+
};
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
export interface DomEditContextOptions {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
captureStudioPathOffset,
|
|
3
|
+
readAppliedStudioPathOffset,
|
|
3
4
|
restoreStudioPathOffset,
|
|
4
5
|
type StudioPathOffsetSnapshot,
|
|
5
6
|
} from "./manualEdits";
|
|
7
|
+
import { readTranslatePx } from "./plainTranslate";
|
|
8
|
+
import { drawPreviewDraft } from "./previewDrafts";
|
|
6
9
|
import {
|
|
7
10
|
getOffsetDragGsap,
|
|
8
11
|
stampGestureBase,
|
|
@@ -49,6 +52,16 @@ function showMemberPosition(member: ManualOffsetDragMember, position: MemberPosi
|
|
|
49
52
|
stampGestureBase(member.element, member.initialOffset, member.baseGsap);
|
|
50
53
|
}
|
|
51
54
|
|
|
55
|
+
function redrawMemberOnFrame(member: ManualOffsetDragMember): void {
|
|
56
|
+
const { element, initialOffset } = member;
|
|
57
|
+
const offset = member.plainTranslate
|
|
58
|
+
? readTranslatePx(element)
|
|
59
|
+
: readAppliedStudioPathOffset(element);
|
|
60
|
+
const translate = { x: offset.x - initialOffset.x, y: offset.y - initialOffset.y };
|
|
61
|
+
if (Number.isFinite(translate.x) && Number.isFinite(translate.y) && (translate.x || translate.y))
|
|
62
|
+
drawPreviewDraft(element, { translate });
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
/** Undo's live revert of a move: its members at gesture start. */
|
|
53
66
|
export function manualOffsetMoveRevert(members: ManualOffsetDragMember[]): StudioEditRevert {
|
|
54
67
|
const startPlacement = members.map((member) => placementOf(member.element));
|
|
@@ -61,7 +74,11 @@ export function manualOffsetMoveRevert(members: ManualOffsetDragMember[]): Studi
|
|
|
61
74
|
placement: startPlacement[i]!,
|
|
62
75
|
}),
|
|
63
76
|
);
|
|
64
|
-
return () =>
|
|
77
|
+
return () =>
|
|
78
|
+
members.forEach((member, i) => {
|
|
79
|
+
showMemberPosition(member, shown[i]!);
|
|
80
|
+
redrawMemberOnFrame(member);
|
|
81
|
+
});
|
|
65
82
|
};
|
|
66
83
|
}
|
|
67
84
|
|