@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
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* `domEditOverlayGeometry`'s, so both kinds of frame draw an element's chrome in the same place.
|
|
5
5
|
*/
|
|
6
6
|
import {
|
|
7
|
+
MAX_DESCRIBE_HANDLES,
|
|
7
8
|
ROTATION_GATE_EPSILON_DEG,
|
|
8
9
|
type EditingElementBox,
|
|
9
10
|
type EditingElementGeometry,
|
|
@@ -38,7 +39,7 @@ function orientedRect(scale: OverlayRootScale, box: EditingElementBox): OverlayR
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
/** `groupAwareOverlayRect`, or with `oriented`, `orientedGroupAwareOverlayRect`. */
|
|
41
|
-
function groupAwareRect(
|
|
42
|
+
export function groupAwareRect(
|
|
42
43
|
scale: OverlayRootScale,
|
|
43
44
|
geometry: EditingElementGeometry,
|
|
44
45
|
oriented: boolean,
|
|
@@ -53,6 +54,12 @@ function groupAwareRect(
|
|
|
53
54
|
return union ? { ...union, editScaleX: rect.editScaleX, editScaleY: rect.editScaleY } : rect;
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
/** `toVisibleOverlayRect`. */
|
|
58
|
+
export function flatVisibleRect(scale: OverlayRootScale, box: EditingElementBox): OverlayRect {
|
|
59
|
+
const rect = baseRect(scale, box);
|
|
60
|
+
return { ...rect, ...hugRectForClipPath(rect, box.clipPath) };
|
|
61
|
+
}
|
|
62
|
+
|
|
56
63
|
/** `orientedVisibleOverlayRect`. */
|
|
57
64
|
function visibleRect(scale: OverlayRootScale, box: EditingElementBox): OverlayRect {
|
|
58
65
|
const rect = orientedRect(scale, box);
|
|
@@ -110,14 +117,22 @@ export async function measurePreviewOverlay(
|
|
|
110
117
|
};
|
|
111
118
|
}
|
|
112
119
|
|
|
113
|
-
/** `
|
|
114
|
-
export async function
|
|
120
|
+
/** `toVisibleOverlayRect` for each handle, with its frame rect and whether it renders. */
|
|
121
|
+
export async function measurePreviewVisibleRects(
|
|
115
122
|
iframe: HTMLIFrameElement,
|
|
116
123
|
overlayEl: HTMLDivElement,
|
|
117
124
|
handles: string[],
|
|
118
|
-
)
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
) {
|
|
126
|
+
const measured: Array<{ rect: OverlayRect; frame: EditingRect; visible: boolean } | null> = [];
|
|
127
|
+
for (let at = 0; at < handles.length; at += MAX_DESCRIBE_HANDLES) {
|
|
128
|
+
const reply = await previewGeometry(iframe, handles.slice(at, at + MAX_DESCRIBE_HANDLES));
|
|
129
|
+
const scale = reply && computeOverlayRootScale(overlayEl, iframe, null);
|
|
130
|
+
if (!reply || !scale) return null;
|
|
131
|
+
for (const box of reply.elements) {
|
|
132
|
+
measured.push(
|
|
133
|
+
box && { rect: flatVisibleRect(scale, box), frame: box.rect, visible: box.visible },
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return measured;
|
|
123
138
|
}
|
|
@@ -20,6 +20,8 @@ import type { PreviewElement } from "../../player/lib/previewElements";
|
|
|
20
20
|
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
21
21
|
import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
|
|
22
22
|
import { useDomSelection } from "../../hooks/useDomSelection";
|
|
23
|
+
import { usePreviewInteraction } from "../../hooks/usePreviewInteraction";
|
|
24
|
+
import { useCanvasContextMenuState } from "./useCanvasContextMenuState";
|
|
23
25
|
import type { TimelineElement } from "../../player";
|
|
24
26
|
|
|
25
27
|
installReactActEnvironment();
|
|
@@ -172,7 +174,10 @@ describe("canvas hit-tests on an opaque frame match same-origin ones", () => {
|
|
|
172
174
|
});
|
|
173
175
|
|
|
174
176
|
describe("useDomSelection over an opaque frame's canvas", () => {
|
|
175
|
-
|
|
177
|
+
type Resolve = ReturnType<typeof useDomSelection>["resolveDomSelectionFromPreviewPoint"];
|
|
178
|
+
let interaction: ReturnType<typeof usePreviewInteraction> | null = null;
|
|
179
|
+
let menu: ReturnType<typeof useCanvasContextMenuState> | null = null;
|
|
180
|
+
function renderSelection(iframe: HTMLIFrameElement, wrapResolve = (resolve: Resolve) => resolve) {
|
|
176
181
|
let hook: ReturnType<typeof useDomSelection> | null = null;
|
|
177
182
|
function Harness() {
|
|
178
183
|
hook = useDomSelection({
|
|
@@ -192,6 +197,25 @@ describe("useDomSelection over an opaque frame's canvas", () => {
|
|
|
192
197
|
refreshKey: 0,
|
|
193
198
|
rightPanelTab: "design",
|
|
194
199
|
});
|
|
200
|
+
interaction = usePreviewInteraction({
|
|
201
|
+
captionEditMode: false,
|
|
202
|
+
compositionLoading: false,
|
|
203
|
+
previewIframeRef: { current: iframe },
|
|
204
|
+
showToast: vi.fn(),
|
|
205
|
+
applyDomSelection: hook.applyDomSelection,
|
|
206
|
+
resolveDomSelectionFromPreviewPoint: wrapResolve(hook.resolveDomSelectionFromPreviewPoint),
|
|
207
|
+
resolveAllDomSelectionsFromPreviewPoint: hook.resolveAllDomSelectionsFromPreviewPoint,
|
|
208
|
+
updateDomEditHoverSelection: hook.updateDomEditHoverSelection,
|
|
209
|
+
setActiveGroupElement: hook.setActiveGroupElement,
|
|
210
|
+
});
|
|
211
|
+
// The overlay's right-click path, which awaits the same lookup a pointer move runs.
|
|
212
|
+
menu = useCanvasContextMenuState({
|
|
213
|
+
selection: hook.domEditSelection,
|
|
214
|
+
selectionRef: { current: hook.domEditSelection },
|
|
215
|
+
hoverSelectionRef: { current: hook.domEditHoverSelection },
|
|
216
|
+
onCanvasPointerMoveRef: { current: interaction.handlePreviewCanvasPointerMove },
|
|
217
|
+
onSelectionChangeRef: { current: hook.applyDomSelection },
|
|
218
|
+
});
|
|
195
219
|
return null;
|
|
196
220
|
}
|
|
197
221
|
const root = createRoot(document.createElement("div"));
|
|
@@ -211,6 +235,49 @@ describe("useDomSelection over an opaque frame's canvas", () => {
|
|
|
211
235
|
expect(cycle.map((selection) => selection.id)).toEqual(["title", "mask", "block"]);
|
|
212
236
|
});
|
|
213
237
|
|
|
238
|
+
const move = (x: number, y: number) => {
|
|
239
|
+
const [clientX, clientY] = client(x, y);
|
|
240
|
+
const event = { clientX, clientY } as React.PointerEvent<HTMLDivElement>;
|
|
241
|
+
return interaction!.handlePreviewCanvasPointerMove(event);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
it.each([
|
|
245
|
+
["opaque", opaqueFrame],
|
|
246
|
+
["same-origin", liveFrame],
|
|
247
|
+
])("drops a hover the pointer left before it resolved (%s)", async (_kind, frame) => {
|
|
248
|
+
const hook = renderSelection(frame());
|
|
249
|
+
const moved = move(60, 60);
|
|
250
|
+
act(() => interaction!.handlePreviewCanvasPointerLeave());
|
|
251
|
+
await act(() => moved);
|
|
252
|
+
expect(hook().domEditHoverSelection).toBeNull();
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("keeps the newest move's hover when an older one resolves after it", async () => {
|
|
256
|
+
let calls = 0;
|
|
257
|
+
const hook = renderSelection(opaqueFrame(), (resolve) => async (...args) => {
|
|
258
|
+
const delay = ++calls === 1 ? 60 : 0;
|
|
259
|
+
const picked = await resolve(...args);
|
|
260
|
+
await new Promise((done) => setTimeout(done, delay));
|
|
261
|
+
return picked;
|
|
262
|
+
});
|
|
263
|
+
const older = move(60, 60);
|
|
264
|
+
const newer = move(1050, 650);
|
|
265
|
+
await act(() => Promise.all([older, newer]));
|
|
266
|
+
expect(hook().domEditHoverSelection).toMatchObject({ id: "pair" });
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("opens the menu on a right-click whose lookup a pointer move overtook", async () => {
|
|
270
|
+
const hook = renderSelection(opaqueFrame());
|
|
271
|
+
const [clientX, clientY] = client(60, 60);
|
|
272
|
+
const rightClick = { clientX, clientY, preventDefault: () => {} };
|
|
273
|
+
const opened = menu!.handleContextMenu(rightClick as React.MouseEvent<HTMLDivElement>);
|
|
274
|
+
const jitter = move(1050, 650);
|
|
275
|
+
await act(() => Promise.all([opened, jitter]));
|
|
276
|
+
expect(hook().domEditSelection).toMatchObject({ id: "title" });
|
|
277
|
+
expect(menu!.contextMenu?.sel).toMatchObject({ id: "title" });
|
|
278
|
+
expect(hook().domEditHoverSelection).toMatchObject({ id: "pair" });
|
|
279
|
+
});
|
|
280
|
+
|
|
214
281
|
it("takes a hover of the same element from a reloaded frame, whose handle is new", async () => {
|
|
215
282
|
const hook = renderSelection(opaqueFrame());
|
|
216
283
|
const picked = (await act(() =>
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* descriptions. Which element a selection lands on comes from `domEditSelectionRules.ts`, the
|
|
4
4
|
* rules a scriptable frame's selections use, so both kinds of frame select the same element.
|
|
5
5
|
*
|
|
6
|
-
* Such a selection's `element` is a stand-in: an element with
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* the selection's
|
|
6
|
+
* Such a selection's `element` is a stand-in: an element with the target's tag, in a document
|
|
7
|
+
* with no window, the same one for a handle for the whole frame load. Nothing in it loads, runs or
|
|
8
|
+
* renders; from the frame it takes only the inline translate, box and Studio marks a gesture starts
|
|
9
|
+
* from, and the px the frame renders that translate as. The frame's element is the selection's
|
|
10
|
+
* `handle`.
|
|
10
11
|
*/
|
|
11
12
|
import { resolveEditingAffordances } from "@hyperframes/core/editing";
|
|
12
13
|
import {
|
|
@@ -60,6 +61,17 @@ import {
|
|
|
60
61
|
getPreviewTargetFromPointer,
|
|
61
62
|
} from "../../utils/studioPreviewHelpers";
|
|
62
63
|
import { isVideoAudible } from "../../player/lib/timelineElementHelpers";
|
|
64
|
+
import { registerPreviewStandIn } from "./previewDrafts";
|
|
65
|
+
import {
|
|
66
|
+
STUDIO_HEIGHT_PROP,
|
|
67
|
+
STUDIO_OFFSET_X_PROP,
|
|
68
|
+
STUDIO_OFFSET_Y_PROP,
|
|
69
|
+
STUDIO_ORIGINAL_INLINE_TRANSLATE_ATTR,
|
|
70
|
+
STUDIO_ORIGINAL_TRANSLATE_ATTR,
|
|
71
|
+
STUDIO_PATH_OFFSET_ATTR,
|
|
72
|
+
STUDIO_WIDTH_PROP,
|
|
73
|
+
} from "./manualEditsTypes";
|
|
74
|
+
import { rememberFrameTranslate, TRANSLATE_PX_PROPERTIES, translatePx } from "./plainTranslate";
|
|
63
75
|
|
|
64
76
|
let inertDocument: Document | undefined;
|
|
65
77
|
const inert = () => (inertDocument ??= document.implementation.createHTMLDocument(""));
|
|
@@ -72,19 +84,40 @@ function inertElement(tag: string): HTMLElement {
|
|
|
72
84
|
}
|
|
73
85
|
}
|
|
74
86
|
|
|
87
|
+
const GESTURE_START_STYLES = [
|
|
88
|
+
"translate",
|
|
89
|
+
STUDIO_OFFSET_X_PROP,
|
|
90
|
+
STUDIO_OFFSET_Y_PROP,
|
|
91
|
+
STUDIO_WIDTH_PROP,
|
|
92
|
+
STUDIO_HEIGHT_PROP,
|
|
93
|
+
];
|
|
94
|
+
const GESTURE_START_ATTRS = [
|
|
95
|
+
STUDIO_PATH_OFFSET_ATTR,
|
|
96
|
+
STUDIO_ORIGINAL_TRANSLATE_ATTR,
|
|
97
|
+
STUDIO_ORIGINAL_INLINE_TRANSLATE_ATTR,
|
|
98
|
+
];
|
|
75
99
|
const standIns = new WeakMap<EditingPortClient, Map<string, HTMLElement>>();
|
|
76
100
|
const standInHandles = new WeakMap<Element, string>();
|
|
77
101
|
const standInAncestors = new WeakMap<Element, string[]>();
|
|
78
102
|
|
|
79
|
-
function standInFor(iframe: HTMLIFrameElement, element: PreviewElement): HTMLElement {
|
|
103
|
+
export function standInFor(iframe: HTMLIFrameElement, element: PreviewElement): HTMLElement {
|
|
80
104
|
const client = previewEditingClient(iframe);
|
|
81
105
|
const byHandle = standIns.get(client) ?? new Map<string, HTMLElement>();
|
|
82
106
|
standIns.set(client, byHandle);
|
|
83
107
|
let standIn = byHandle.get(element.handle);
|
|
84
108
|
if (!standIn) {
|
|
85
109
|
standIn = inertElement(element.tag);
|
|
110
|
+
for (const name of GESTURE_START_STYLES) {
|
|
111
|
+
const value = element.inlineStyles[name];
|
|
112
|
+
if (value && !mayBeCut(value)) standIn.style.setProperty(name, value);
|
|
113
|
+
}
|
|
114
|
+
for (const name of GESTURE_START_ATTRS) {
|
|
115
|
+
const value = attr(element, name);
|
|
116
|
+
if (value !== null && !mayBeCut(value)) standIn.setAttribute(name, value);
|
|
117
|
+
}
|
|
86
118
|
byHandle.set(element.handle, standIn);
|
|
87
119
|
standInHandles.set(standIn, element.handle);
|
|
120
|
+
registerPreviewStandIn(standIn, iframe, element.handle);
|
|
88
121
|
}
|
|
89
122
|
return standIn;
|
|
90
123
|
}
|
|
@@ -93,7 +126,7 @@ function standInFor(iframe: HTMLIFrameElement, element: PreviewElement): HTMLEle
|
|
|
93
126
|
* The description as an element of the inert document, discarded after the read, so the label,
|
|
94
127
|
* data-attribute and inline-style helpers read it as they read a live element.
|
|
95
128
|
*/
|
|
96
|
-
function readable(element: PreviewElement): HTMLElement {
|
|
129
|
+
export function readable(element: PreviewElement): HTMLElement {
|
|
97
130
|
const probe = inertElement(element.tag);
|
|
98
131
|
for (const [name, value] of element.attributes) {
|
|
99
132
|
if (name !== "id" && name !== "class" && !name.startsWith("data-")) continue;
|
|
@@ -262,7 +295,7 @@ function chainIndex(
|
|
|
262
295
|
});
|
|
263
296
|
}
|
|
264
297
|
|
|
265
|
-
function previewIdentity(current: PreviewElement, path: string | null) {
|
|
298
|
+
export function previewIdentity(current: PreviewElement, path: string | null) {
|
|
266
299
|
const selector = current.selector ?? undefined;
|
|
267
300
|
return {
|
|
268
301
|
id: current.id || undefined,
|
|
@@ -316,10 +349,18 @@ export async function resolvePreviewSelection(
|
|
|
316
349
|
const compositionSrc = compositionSourceOf(current);
|
|
317
350
|
const probe = readable(current);
|
|
318
351
|
const inlineStyles = getInlineStyles(probe);
|
|
319
|
-
const
|
|
320
|
-
...CURATED_STYLE_PROPERTIES,
|
|
352
|
+
const styles = await previewComputedStyles(iframe, current, [
|
|
353
|
+
...new Set([...CURATED_STYLE_PROPERTIES, ...TRANSLATE_PX_PROPERTIES]),
|
|
321
354
|
]);
|
|
322
|
-
if (!
|
|
355
|
+
if (!styles) return null;
|
|
356
|
+
// The stand-in has no box to size a % or em against: a move starts from what the frame renders.
|
|
357
|
+
rememberFrameTranslate(
|
|
358
|
+
element,
|
|
359
|
+
translatePx(styles.translate ?? "none", (p) => styles[p] ?? ""),
|
|
360
|
+
);
|
|
361
|
+
const computedStyles = Object.fromEntries(
|
|
362
|
+
CURATED_STYLE_PROPERTIES.flatMap((p) => (p in styles ? [[p, styles[p]!]] : [])),
|
|
363
|
+
);
|
|
323
364
|
const isCompositionRoot = await isPreviewCompositionRoot(iframe, chain, index, computedStyles);
|
|
324
365
|
if (isCompositionRoot === null) return null;
|
|
325
366
|
const isInsideLocked = chainLocked(chain, chainReader(chain), index);
|
|
@@ -414,6 +455,8 @@ export async function findOpaqueTimelineElement(
|
|
|
414
455
|
return (await findPreviewElementForTimelineElement(iframe, element, lookup)) ?? null;
|
|
415
456
|
}
|
|
416
457
|
|
|
458
|
+
export const standInHandle = (element: Element) => standInHandles.get(element);
|
|
459
|
+
|
|
417
460
|
export function elementWithin(container: HTMLElement, element: HTMLElement): boolean {
|
|
418
461
|
const handle = standInHandles.get(container);
|
|
419
462
|
if (handle === undefined) return container.contains(element);
|
|
@@ -440,7 +483,8 @@ export function pointerMayHitElement(iframe: HTMLIFrameElement, clientX: number,
|
|
|
440
483
|
if (!previewFrameOpaque(iframe))
|
|
441
484
|
return Boolean(getPreviewTargetFromPointer(iframe, clientX, clientY));
|
|
442
485
|
const answer = pointerAnswers.get(iframe);
|
|
443
|
-
|
|
486
|
+
const near = answer && Math.hypot(answer.x - clientX, answer.y - clientY) <= 2;
|
|
487
|
+
return near ? answer.found : true;
|
|
444
488
|
}
|
|
445
489
|
|
|
446
490
|
export async function findPointerTarget(
|
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
import { computeNextResizeAnchor, resizeRemainderShift } from "./domEditResizeLocal";
|
|
10
10
|
import type { ResizeDraftSizes } from "./domEditResizeLocal";
|
|
11
11
|
import { applyManualOffsetDragDraft } from "./manualOffsetDrag";
|
|
12
|
+
import { endStudioManualEditGesture, isStudioManualEditGestureCurrent } from "./manualEdits";
|
|
13
|
+
import { drawPreviewDraft, endPreviewDraft } from "./previewDrafts";
|
|
14
|
+
import { previewFrameOpaque } from "../../player/lib/previewChannel";
|
|
12
15
|
|
|
13
16
|
type Corners = ReturnType<typeof elementCornerOverlayPoints>;
|
|
14
17
|
|
|
@@ -80,6 +83,40 @@ function resolveAnchoredResizeDraft(
|
|
|
80
83
|
);
|
|
81
84
|
}
|
|
82
85
|
|
|
86
|
+
/** A frame Studio cannot measure: the box grows about its centre by the size the draft wrote. */
|
|
87
|
+
function resolveUnmeasuredResizeDraft(
|
|
88
|
+
g: GestureState,
|
|
89
|
+
element: HTMLElement,
|
|
90
|
+
{ written }: ResizeDraftSizes,
|
|
91
|
+
): OverlayRect {
|
|
92
|
+
const width = (g.originWidth * written.width) / g.actualWidth;
|
|
93
|
+
const height = (g.originHeight * written.height) / g.actualHeight;
|
|
94
|
+
if (g.pathOffsetMember) {
|
|
95
|
+
const anchor = {
|
|
96
|
+
dx: ((g.actualWidth - written.width) / 2) * g.editScaleX,
|
|
97
|
+
dy: ((g.actualHeight - written.height) / 2) * g.editScaleY,
|
|
98
|
+
};
|
|
99
|
+
g.lastResizeAnchor = anchor;
|
|
100
|
+
applyManualOffsetDragDraft(g.pathOffsetMember, anchor.dx, anchor.dy);
|
|
101
|
+
}
|
|
102
|
+
drawPreviewDraft(element, { size: written });
|
|
103
|
+
return {
|
|
104
|
+
left: g.originLeft + (g.originWidth - width) / 2,
|
|
105
|
+
top: g.originTop + (g.originHeight - height) / 2,
|
|
106
|
+
width,
|
|
107
|
+
height,
|
|
108
|
+
editScaleX: g.editScaleX,
|
|
109
|
+
editScaleY: g.editScaleY,
|
|
110
|
+
angle: g.actualRotation,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Ends a settled resize that has no offset member; a frame it drew on keeps the new size. */
|
|
115
|
+
export function endResizeWithoutMember(element: HTMLElement, token: string | undefined): void {
|
|
116
|
+
if (!token || isStudioManualEditGestureCurrent(element, token)) endPreviewDraft(element, "keep");
|
|
117
|
+
endStudioManualEditGesture(element, token);
|
|
118
|
+
}
|
|
119
|
+
|
|
83
120
|
/** The overlay rect to paint for the current resize pointer-move frame. */
|
|
84
121
|
export function resolveResizeDraftRect(
|
|
85
122
|
g: GestureState,
|
|
@@ -89,6 +126,7 @@ export function resolveResizeDraftRect(
|
|
|
89
126
|
measureOrientedRect: () => OverlayRect | null,
|
|
90
127
|
sizes: ResizeDraftSizes,
|
|
91
128
|
): OverlayRect {
|
|
129
|
+
if (iframe && previewFrameOpaque(iframe)) return resolveUnmeasuredResizeDraft(g, element, sizes);
|
|
92
130
|
if (g.pathOffsetMember) {
|
|
93
131
|
return resolveAnchoredResizeDraft(
|
|
94
132
|
g,
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
// fallow-ignore-file code-duplication
|
|
2
|
+
import { snapCandidates } from "@hyperframes/core/runtime/editing-port";
|
|
2
3
|
import type { DomEditSelection } from "./domEditing";
|
|
3
|
-
import {
|
|
4
|
-
isElementVisibleForOverlay,
|
|
5
|
-
toVisibleOverlayRect,
|
|
6
|
-
type OverlayRect,
|
|
7
|
-
} from "./domEditOverlayGeometry";
|
|
4
|
+
import { toVisibleOverlayRect, type OverlayRect } from "./domEditOverlayGeometry";
|
|
8
5
|
import {
|
|
9
6
|
extractSnapTargets,
|
|
10
7
|
buildCompositionSnapTarget,
|
|
@@ -27,33 +24,23 @@ function readPositiveDimension(value: string | null): number | null {
|
|
|
27
24
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (!isHtmlElement(child)) continue;
|
|
47
|
-
if (IGNORED_TAGS.has(child.tagName.toLowerCase())) continue;
|
|
48
|
-
if (child.hasAttribute("data-composition-id")) continue;
|
|
49
|
-
if (excludeElements.has(child)) continue;
|
|
50
|
-
if (!isElementVisibleForOverlay(child)) continue;
|
|
51
|
-
result.push(child);
|
|
52
|
-
visit(child);
|
|
53
|
-
}
|
|
27
|
+
export function snapContextFromRects(
|
|
28
|
+
composition: OverlayRect,
|
|
29
|
+
rects: ReadonlyArray<OverlayRect | null>,
|
|
30
|
+
): SnapContext {
|
|
31
|
+
const prefs = readStudioUiPreferences();
|
|
32
|
+
const entries = rects.flatMap((rect, i) => (rect ? [{ rect, id: `snap-target-${i}` }] : []));
|
|
33
|
+
const gridSpacing = prefs.gridSpacing ?? 50;
|
|
34
|
+
const snapToGrid = prefs.snapToGrid ?? false;
|
|
35
|
+
return {
|
|
36
|
+
targets: extractSnapTargets(entries),
|
|
37
|
+
compositionTarget: buildCompositionSnapTarget(composition),
|
|
38
|
+
gridEdges:
|
|
39
|
+
snapToGrid && gridSpacing > 0
|
|
40
|
+
? buildGridSnapEdges(composition, gridSpacing, composition.editScaleX)
|
|
41
|
+
: null,
|
|
42
|
+
snapEnabled: prefs.snapEnabled ?? true,
|
|
54
43
|
};
|
|
55
|
-
visit(root);
|
|
56
|
-
return result;
|
|
57
44
|
}
|
|
58
45
|
|
|
59
46
|
// fallow-ignore-next-line complexity
|
|
@@ -62,8 +49,7 @@ export function collectSnapContext(input: {
|
|
|
62
49
|
iframe: HTMLIFrameElement;
|
|
63
50
|
excludeElements: Set<HTMLElement>;
|
|
64
51
|
}): SnapContext {
|
|
65
|
-
const
|
|
66
|
-
const snapEnabled = prefs.snapEnabled ?? true;
|
|
52
|
+
const snapEnabled = readStudioUiPreferences().snapEnabled ?? true;
|
|
67
53
|
|
|
68
54
|
const doc = input.iframe.contentDocument;
|
|
69
55
|
if (!doc) {
|
|
@@ -84,41 +70,19 @@ export function collectSnapContext(input: {
|
|
|
84
70
|
|
|
85
71
|
const iframeRect = input.iframe.getBoundingClientRect();
|
|
86
72
|
const overlayRect = input.overlayEl.getBoundingClientRect();
|
|
87
|
-
const rootScaleX = iframeRect.width / rootWidth;
|
|
88
|
-
const rootScaleY = iframeRect.height / rootHeight;
|
|
89
|
-
|
|
90
73
|
const compositionOverlayRect: OverlayRect = {
|
|
91
74
|
left: iframeRect.left - overlayRect.left,
|
|
92
75
|
top: iframeRect.top - overlayRect.top,
|
|
93
76
|
width: iframeRect.width,
|
|
94
77
|
height: iframeRect.height,
|
|
95
|
-
editScaleX:
|
|
96
|
-
editScaleY:
|
|
78
|
+
editScaleX: iframeRect.width / rootWidth,
|
|
79
|
+
editScaleY: iframeRect.height / rootHeight,
|
|
97
80
|
};
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const entries: Array<{
|
|
104
|
-
rect: { left: number; top: number; width: number; height: number };
|
|
105
|
-
id: string;
|
|
106
|
-
}> = [];
|
|
107
|
-
for (let i = 0; i < elements.length; i++) {
|
|
108
|
-
const rect = toVisibleOverlayRect(input.overlayEl, input.iframe, elements[i]);
|
|
109
|
-
if (rect) entries.push({ rect, id: `snap-target-${i}` });
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const targets = extractSnapTargets(entries);
|
|
113
|
-
|
|
114
|
-
let gridEdges: { x: SnapEdge[]; y: SnapEdge[] } | null = null;
|
|
115
|
-
const gridSpacing = prefs.gridSpacing ?? 50;
|
|
116
|
-
const snapToGrid = prefs.snapToGrid ?? false;
|
|
117
|
-
if (snapToGrid && gridSpacing > 0) {
|
|
118
|
-
gridEdges = buildGridSnapEdges(compositionOverlayRect, gridSpacing, rootScaleX);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return { targets, compositionTarget, gridEdges, snapEnabled };
|
|
81
|
+
const elements = snapCandidates(root, input.excludeElements);
|
|
82
|
+
const rects = elements.map((element) =>
|
|
83
|
+
toVisibleOverlayRect(input.overlayEl, input.iframe, element),
|
|
84
|
+
);
|
|
85
|
+
return snapContextFromRects(compositionOverlayRect, rects);
|
|
122
86
|
}
|
|
123
87
|
|
|
124
88
|
// fallow-ignore-next-line complexity
|
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
resolveDomEditRotationGesture,
|
|
46
46
|
} from "./domEditOverlayGestures";
|
|
47
47
|
import { resolveCenterResizeSize } from "./domEditResizeLocal";
|
|
48
|
-
import { resolveResizeDraftRect } from "./resizeDraft";
|
|
48
|
+
import { endResizeWithoutMember, resolveResizeDraftRect } from "./resizeDraft";
|
|
49
49
|
import { notifyBlockedPress } from "./domEditOverlayStartGesture";
|
|
50
50
|
import { hugRectForElement } from "./domEditOverlayCrop";
|
|
51
51
|
import {
|
|
@@ -530,7 +530,7 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu
|
|
|
530
530
|
})
|
|
531
531
|
.finally(() => {
|
|
532
532
|
if (member) endManualOffsetDragMembers([member]);
|
|
533
|
-
else
|
|
533
|
+
else endResizeWithoutMember(sel.element, g.manualEditDragToken);
|
|
534
534
|
});
|
|
535
535
|
edit.settle(saved);
|
|
536
536
|
logResizeSettle(sel.element, "post-release");
|
|
@@ -36,7 +36,7 @@ export interface UseLayerDragReturn {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export function isLayerDraggable(layer: DomEditLayerItem): boolean {
|
|
39
|
-
if (!(layer.selector || layer.id)) return false;
|
|
39
|
+
if (!(layer.selector || layer.id) || layer.preview) return false;
|
|
40
40
|
let el: HTMLElement | null = layer.element;
|
|
41
41
|
while (el) {
|
|
42
42
|
if (el.hasAttribute("data-timeline-locked")) return false;
|
|
@@ -27,4 +27,11 @@ describe("timelineElementsForDelete", () => {
|
|
|
27
27
|
const elements = [clip("a", "clip-a")];
|
|
28
28
|
expect(timelineElementsForDelete([sel("nested-text")], elements)).toBeNull();
|
|
29
29
|
});
|
|
30
|
+
|
|
31
|
+
it("leaves an opaque frame's selection on the DOM path, as its clip-id row has no patch target", () => {
|
|
32
|
+
// An opaque frame's rows carry only the clip id; the selection carries the frame's handle.
|
|
33
|
+
const row = { id: "title", sourceFile: "index.html", start: 0, duration: 1, track: 0 };
|
|
34
|
+
const opaque = { ...sel("title"), handle: "0123456789abcdef:1" } as DomEditSelection;
|
|
35
|
+
expect(timelineElementsForDelete([opaque], [row as TimelineElement])).toBeNull();
|
|
36
|
+
});
|
|
30
37
|
});
|
|
@@ -6,6 +6,7 @@ import { logSelect } from "../utils/selectDebug";
|
|
|
6
6
|
|
|
7
7
|
interface TimelineMirrorDeps {
|
|
8
8
|
timelineElements: TimelineElement[];
|
|
9
|
+
activeCompPath: string | null;
|
|
9
10
|
getTimelineSelectionSet: () => ReadonlySet<string>;
|
|
10
11
|
setSelectedTimelineElementId: (id: string | null, options?: SelectElementOptions) => void;
|
|
11
12
|
setTimelineSelectionSet: (ids: Set<string>) => void;
|
|
@@ -32,6 +33,7 @@ export function announceTimelineSelection(
|
|
|
32
33
|
): void {
|
|
33
34
|
const {
|
|
34
35
|
timelineElements,
|
|
36
|
+
activeCompPath,
|
|
35
37
|
getTimelineSelectionSet,
|
|
36
38
|
setSelectedTimelineElementId,
|
|
37
39
|
setTimelineSelectionSet,
|
|
@@ -42,7 +44,7 @@ export function announceTimelineSelection(
|
|
|
42
44
|
return;
|
|
43
45
|
}
|
|
44
46
|
const timelineIdFor = (selection: DomEditSelection) =>
|
|
45
|
-
findMatchingTimelineElementId(selection, timelineElements) ??
|
|
47
|
+
findMatchingTimelineElementId(selection, timelineElements, activeCompPath || "index.html") ??
|
|
46
48
|
findTimelineIdByAncestor(
|
|
47
49
|
selection.element,
|
|
48
50
|
timelineElements,
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
type StudioProjectFileWriter,
|
|
31
31
|
} from "../utils/studioFileMutationCoordinator";
|
|
32
32
|
import { studioApiFetch } from "../utils/studioApiFetch";
|
|
33
|
+
import { createStudioSaveHttpError } from "../utils/studioSaveDiagnostics";
|
|
33
34
|
import { moveLiveTweens } from "../utils/gsapLiveRetime";
|
|
34
35
|
|
|
35
36
|
export async function readFileContent(projectId: string, targetPath: string): Promise<string> {
|
|
@@ -40,7 +41,9 @@ export async function readFileContent(projectId: string, targetPath: string): Pr
|
|
|
40
41
|
`/api/projects/${encodeURIComponent(projectId)}/files/${encodeURIComponent(targetPath)}`,
|
|
41
42
|
);
|
|
42
43
|
if (!response.ok) {
|
|
43
|
-
throw
|
|
44
|
+
throw await createStudioSaveHttpError(response, `Failed to read ${targetPath}`, {
|
|
45
|
+
path: targetPath,
|
|
46
|
+
});
|
|
44
47
|
}
|
|
45
48
|
const data = (await response.json()) as { content?: string };
|
|
46
49
|
if (typeof data.content !== "string") {
|
|
@@ -104,6 +104,7 @@ export function useDomSelection({
|
|
|
104
104
|
announceSelectionToTimeline(
|
|
105
105
|
{
|
|
106
106
|
timelineElements,
|
|
107
|
+
activeCompPath,
|
|
107
108
|
getTimelineSelectionSet,
|
|
108
109
|
setSelectedTimelineElementId,
|
|
109
110
|
setTimelineSelectionSet,
|
|
@@ -113,6 +114,7 @@ export function useDomSelection({
|
|
|
113
114
|
replaceSet,
|
|
114
115
|
),
|
|
115
116
|
[
|
|
117
|
+
activeCompPath,
|
|
116
118
|
getTimelineSelectionSet,
|
|
117
119
|
setSelectedTimelineElementId,
|
|
118
120
|
setTimelineSelectionSet,
|
|
@@ -9,7 +9,7 @@ vi.mock("../utils/studioSaveDiagnostics", async (importOriginal) => ({
|
|
|
9
9
|
trackStudioSaveFailure,
|
|
10
10
|
}));
|
|
11
11
|
|
|
12
|
-
import { StudioFileConflictError } from "../utils/studioSaveDiagnostics";
|
|
12
|
+
import { StudioFileConflictError, createStudioSaveHttpError } from "../utils/studioSaveDiagnostics";
|
|
13
13
|
import { useEditorSave, type EditorSaveHandle } from "./useEditorSave";
|
|
14
14
|
|
|
15
15
|
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
@@ -150,6 +150,27 @@ describe("useEditorSave pending work", () => {
|
|
|
150
150
|
await mounted.unmount();
|
|
151
151
|
});
|
|
152
152
|
|
|
153
|
+
// fails without the fix: the toast told the person to check the preview server for a file another program holds open.
|
|
154
|
+
it("toasts a held file in its own words, not the generic preview-server advice", async () => {
|
|
155
|
+
const held = await createStudioSaveHttpError(
|
|
156
|
+
new Response(JSON.stringify({ why: "busy" }), { status: 423 }),
|
|
157
|
+
"Failed to save index.html",
|
|
158
|
+
{ path: "index.html" },
|
|
159
|
+
);
|
|
160
|
+
const mounted = await mountEditorSave(async () => {
|
|
161
|
+
throw held;
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
act(() => mounted.handle.handleContentChange("edit"));
|
|
165
|
+
await mounted.handle.flushPendingSave();
|
|
166
|
+
|
|
167
|
+
expect(mounted.showToast).toHaveBeenCalledWith(
|
|
168
|
+
"index.html is open in another program. Close it there, then try again.",
|
|
169
|
+
"error",
|
|
170
|
+
);
|
|
171
|
+
await mounted.unmount();
|
|
172
|
+
});
|
|
173
|
+
|
|
153
174
|
it("emits a changed failure immediately and repeats after the burst window", async () => {
|
|
154
175
|
const now = vi.spyOn(Date, "now").mockReturnValue(1_000);
|
|
155
176
|
const writeProjectFile = vi
|
|
@@ -3,6 +3,7 @@ import { saveProjectFilesWithHistory } from "../utils/studioFileHistory";
|
|
|
3
3
|
import {
|
|
4
4
|
StudioFileConflictError,
|
|
5
5
|
buildStudioSaveFailureProperties,
|
|
6
|
+
heldFileWords,
|
|
6
7
|
trackStudioSaveFailure,
|
|
7
8
|
type StudioSaveDrainResult,
|
|
8
9
|
} from "../utils/studioSaveDiagnostics";
|
|
@@ -93,7 +94,8 @@ export function useEditorSave({
|
|
|
93
94
|
) {
|
|
94
95
|
lastFailureToastAtRef.current = now;
|
|
95
96
|
showToast(
|
|
96
|
-
|
|
97
|
+
heldFileWords(error) ??
|
|
98
|
+
`Couldn't save ${path}. Your latest edits are NOT persisted. Check the preview server; editing again retries the save.`,
|
|
97
99
|
"error",
|
|
98
100
|
);
|
|
99
101
|
}
|