mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
fix(studio): moving and nudging an element works in a sealed preview (#8263)
* fix(studio): arrow keys nudge the selected element in a sealed preview A sealed preview's selection is a stand-in that is never in the page, so the nudge's check that the element is still there refused every key and nothing moved. It now uses the same check the selection publisher uses, which keeps a sealed selection until it is replaced. * fix(studio): a sealed nudge moves an animated element by its tween and saves where it was drawn A sealed preview's selected element is a stand-in with no animation or translate of its own, so a nudge guessed both from an empty page: it wrote a plain translate over the stylesheet's and the element landed elsewhere after a reload. The nudge now waits for the frame's gesture-start read, the one a press uses, and keys pressed meanwhile join the burst. * test(studio): pass the nudge its frame refs in the undo paint test * fix(studio): a sealed move on GSAP's route lands where it was drawn, not twice as far When a move ends, the sealed frame kept the translate the gesture drew. A move on GSAP's route saves the new position as GSAP's x and y, so the layer then showed the move twice until the frame loaded again. The frame now drops the drawn translate for those moves; a move saved as a plain translate still keeps it. * refactor(studio): split the sealed nudge key handler so each step reads on its own * fix(studio): a sealed nudge waiting on its frame gives way to a drag, selection or other edit * fix(studio): an arrow pressed while a canvas press waits on the preview does not start a nudge * fix(studio): a sealed resize on GSAP's route keeps the size it drew when it ends * refactor(studio): name the size-keeping draft end instead of commenting it * fix(studio): a sealed resize saved as GSAP scale drops the size it drew when it ends * fix(studio): a sealed resize keeps its drawn size unless its save wrote the size as scale * fix(studio): a whole-tween resize of a width/height tween says it saved the size, not scale * test(studio): cover the resize writer's held-size and unnamed-element returns * test(studio): reach the resize writer's no-selector refusal with an element no selector addresses
This commit is contained in:
@@ -326,12 +326,16 @@ export const DomEditOverlay = memo(function DomEditOverlay({
|
||||
selection,
|
||||
groupSelections,
|
||||
allowCanvasMovement: allowCanvasMovement && !readOnly,
|
||||
iframeRef,
|
||||
overlayRef,
|
||||
activeCompositionPathRef,
|
||||
selectionRef,
|
||||
overlayRectRef,
|
||||
groupOverlayItemsRef,
|
||||
gestureRef,
|
||||
groupGestureRef,
|
||||
blockedMoveRef,
|
||||
waitingPressRef,
|
||||
onBlockedMoveRef,
|
||||
onManualDragStartRef,
|
||||
onPathOffsetCommitRef,
|
||||
|
||||
@@ -354,6 +354,26 @@ describe("a press while a script write is out", () => {
|
||||
await waitFor(() => expect(file.title).toBe("translate: 40px 20px"));
|
||||
});
|
||||
|
||||
// fails without the fix: an arrow during the wait started a nudge that the drag then ran under.
|
||||
it("ignores an arrow pressed while a press waits, and saves only the drag", async () => {
|
||||
const editor = mountEditor(false);
|
||||
let land: () => void = () => {};
|
||||
const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));
|
||||
pointer(editor.box, "pointerdown", 150, 150);
|
||||
const arrow = new KeyboardEvent("keydown", { key: "ArrowRight", cancelable: true });
|
||||
act(() => void window.dispatchEvent(arrow));
|
||||
expect(marked(editor.live.contentDocument!), "no nudge while the press waits").toHaveLength(0);
|
||||
pointer(editor.overlay, "pointermove", 190, 170);
|
||||
pointer(editor.overlay, "pointerup", 190, 170);
|
||||
|
||||
await act(async () => {
|
||||
land();
|
||||
await write;
|
||||
});
|
||||
await waitFor(() => expect(file.title).toBe("translate: 40px 20px"));
|
||||
expect(editor.onPathOffsetCommit).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("keeps a released press when the browser releases pointer capture", async () => {
|
||||
const editor = mountEditor(false);
|
||||
let land: () => void = () => {};
|
||||
|
||||
@@ -17,7 +17,9 @@ import {
|
||||
applyManualOffsetDragDraft,
|
||||
createManualOffsetDragMember,
|
||||
endManualOffsetDragMembers,
|
||||
type ManualOffsetDragMember,
|
||||
} from "./manualOffsetDrag";
|
||||
import { drawPreviewDraft } from "./previewDrafts";
|
||||
import { measurePreviewGestureStart } from "./previewGestureStartRead";
|
||||
import { captureStudioRotation } from "./manualEditsSnapshot";
|
||||
import {
|
||||
@@ -142,6 +144,7 @@ const press = () =>
|
||||
async function dragBoxOnSealedFrame(
|
||||
script: string,
|
||||
beforePress?: (iframe: HTMLIFrameElement) => void,
|
||||
beforeEnd?: (standIn: Element, member: ManualOffsetDragMember) => void,
|
||||
) {
|
||||
const box = document.getElementById("box")!;
|
||||
const iframe = opaqueFrame();
|
||||
@@ -174,10 +177,42 @@ async function dragBoxOnSealedFrame(
|
||||
stamp: freezeDragStamp(standIn),
|
||||
},
|
||||
);
|
||||
beforeEnd?.(standIn, member);
|
||||
endManualOffsetDragMembers([member]);
|
||||
return { started, start, anim: anim!, outcome, commit };
|
||||
}
|
||||
|
||||
// fails without the fix: the frame kept the drag's drawn translate on top of the x the save gave GSAP.
|
||||
it("ends a sealed drag on GSAP's route without its drawn translate, so the saved x alone places the layer", async () => {
|
||||
mount(SCRIPT);
|
||||
await dragBoxOnSealedFrame(SCRIPT);
|
||||
|
||||
await vi.waitFor(() => expect(document.getElementById("box")!.style.translate).toBe(""));
|
||||
});
|
||||
|
||||
// fails without the fix: ending the draft on GSAP's route took back the size a resize had drawn too.
|
||||
it("keeps the size a sealed resize drew when its anchor ends on GSAP's route", async () => {
|
||||
mount(SCRIPT);
|
||||
await dragBoxOnSealedFrame(SCRIPT, undefined, (standIn) =>
|
||||
drawPreviewDraft(standIn, { size: { width: 300, height: 200 } }),
|
||||
);
|
||||
|
||||
const box = document.getElementById("box")!;
|
||||
await vi.waitFor(() => expect([box.style.width, box.style.translate]).toEqual(["300px", ""]));
|
||||
});
|
||||
|
||||
// fails without the fix: a resize saved as GSAP scale kept its drawn CSS size, and the scale grew it again.
|
||||
it("drops the size a sealed resize drew when its save writes the size as GSAP scale", async () => {
|
||||
mount(SCRIPT);
|
||||
await dragBoxOnSealedFrame(SCRIPT, undefined, (standIn, member) => {
|
||||
drawPreviewDraft(standIn, { size: { width: 300, height: 200 } });
|
||||
member.sizeSavedAsScale = true;
|
||||
});
|
||||
|
||||
const box = document.getElementById("box")!;
|
||||
await vi.waitFor(() => expect([box.style.width, box.style.translate]).toEqual(["", ""]));
|
||||
});
|
||||
|
||||
// fails without the fix: a sealed preview refused to drag a layer its animation moves.
|
||||
it("drags a layer its tween moves in a sealed preview: it moves live and saves a keyframe there", async () => {
|
||||
mount(SCRIPT);
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
} from "../../hooks/draggedGsapPosition";
|
||||
import { editsPlainCss } from "../../hooks/gsapRuntimeKeyframes";
|
||||
import { readTranslatePx, UNREADABLE_TRANSLATE, writeTranslatePx } from "./plainTranslate";
|
||||
import { drawPreviewDraft, endPreviewDraft } from "./previewDrafts";
|
||||
import { drawPreviewDraft, endPreviewDraft, endPreviewDraftKeepingSizeOnly } from "./previewDrafts";
|
||||
import type { PreviewGestureStart } from "./previewGestureStartRead";
|
||||
|
||||
interface OffsetDragGsap {
|
||||
@@ -90,6 +90,7 @@ export interface ManualOffsetDragMember {
|
||||
initialOffset: { x: number; y: number };
|
||||
/** The move writes the element's own inline `translate`; offsets are then absolute translate px. */
|
||||
plainTranslate: boolean;
|
||||
sizeSavedAsScale?: boolean;
|
||||
/**
|
||||
* The element's GSAP x/y at gesture start, captured in JS so a mid-drag
|
||||
* re-render (which reverts inline style + wipes the `data-hf-drag-gsap-base-*`
|
||||
@@ -536,11 +537,17 @@ function settleDraftTranslate(element: HTMLElement, gsapOwnsPosition: boolean):
|
||||
}
|
||||
|
||||
/** Teardown after a COMMITTED drag. */
|
||||
function endDraftKeepingWhatTheSaveWrites(member: ManualOffsetDragMember): void {
|
||||
if (member.plainTranslate) endPreviewDraft(member.element, "keep");
|
||||
else if (member.sizeSavedAsScale) endPreviewDraft(member.element, "restore");
|
||||
else endPreviewDraftKeepingSizeOnly(member.element);
|
||||
}
|
||||
|
||||
export function endManualOffsetDragMembers(members: ManualOffsetDragMember[]): void {
|
||||
for (const member of members) {
|
||||
if (!isStudioManualEditGestureCurrent(member.element, member.gestureToken)) continue;
|
||||
endStudioManualEditGesture(member.element, member.gestureToken);
|
||||
endPreviewDraft(member.element, "keep");
|
||||
endDraftKeepingWhatTheSaveWrites(member);
|
||||
member.element.removeAttribute("data-hf-drag-initial-offset-x");
|
||||
member.element.removeAttribute("data-hf-drag-initial-offset-y");
|
||||
member.element.removeAttribute("data-hf-drag-gsap-base-x");
|
||||
|
||||
@@ -76,6 +76,13 @@ export function drawPreviewDraft(element: Element, part: Partial<Drawn>): void {
|
||||
send(target.iframe, queue);
|
||||
}
|
||||
|
||||
export function endPreviewDraftKeepingSizeOnly(element: Element): void {
|
||||
const target = standIns.get(element);
|
||||
if (!target || !queueFor(target.iframe).drawn.has(target.handle)) return;
|
||||
drawPreviewDraft(element, { translate: null });
|
||||
endPreviewDraft(element, "keep");
|
||||
}
|
||||
|
||||
/** Ends the stand-in's draft on its frame: "keep" once saved or regrabbed mid-save, else "restore". */
|
||||
export function endPreviewDraft(element: Element, end: "keep" | "restore"): void {
|
||||
const target = standIns.get(element);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
/** A gesture on a frame Studio cannot script starts from one `gesture-start` read (core `editingGestureStart.ts`). */
|
||||
import { previewGestureStart } from "../../player/lib/previewElements";
|
||||
import { computeOverlayRootScale } from "./domEditOverlayBasis";
|
||||
import type { DomEditSelection } from "./domEditing";
|
||||
import type { CropFrameStart } from "./domEditOverlayCrop";
|
||||
import type { OverlayRect } from "./domEditOverlayGeometry";
|
||||
import { invertManualOffsetDragMatrix, type ManualOffsetDragMatrix } from "./manualOffsetDrag";
|
||||
import { flatVisibleRect, groupAwareRect } from "./previewOverlayRects";
|
||||
import { findPreviewElementForSelection } from "./previewSelection";
|
||||
import { snapContextFromRects, type SnapContext } from "./snapTargetCollection";
|
||||
|
||||
export interface PreviewGestureStart {
|
||||
@@ -78,6 +80,29 @@ export async function measurePreviewGestureStart(
|
||||
};
|
||||
}
|
||||
|
||||
export type Shown = { selection: DomEditSelection; rect: OverlayRect; start?: PreviewGestureStart };
|
||||
export type OverChannel = { shown: Shown[]; snap: SnapContext };
|
||||
|
||||
/** An opaque frame's `selections` on the page it shows now and what a gesture on them starts from. */
|
||||
export async function readShownGestureStarts(
|
||||
iframe: HTMLIFrameElement,
|
||||
overlay: HTMLDivElement | null,
|
||||
path: string | null,
|
||||
selections: DomEditSelection[],
|
||||
): Promise<OverChannel | null> {
|
||||
const found = await Promise.all(
|
||||
selections.map((selection) => findPreviewElementForSelection(iframe, selection, path)),
|
||||
);
|
||||
const handles = found.map((element) => element?.handle);
|
||||
if (!overlay || !handles.length || !handles.every(Boolean)) return null;
|
||||
const read = await measurePreviewGestureStart(iframe, overlay, handles as string[]);
|
||||
const shown = selections.flatMap((selection, i) => {
|
||||
const element = read?.elements[i];
|
||||
return element ? [{ selection: { ...selection, handle: handles[i] }, ...element }] : [];
|
||||
});
|
||||
return read && shown.length === selections.length ? { shown, snap: read.snap } : null;
|
||||
}
|
||||
|
||||
export async function readCropFrameStart(
|
||||
iframe: HTMLIFrameElement,
|
||||
handle: string,
|
||||
|
||||
@@ -22,12 +22,8 @@ import { setStudioWaitingPressCancel } from "../../utils/studioPendingEdits";
|
||||
import { playheadMoment } from "../../hooks/editMoment";
|
||||
import type { EditMoment } from "./manualEditsTypes";
|
||||
import { previewFrameOpaque } from "../../player/lib/previewChannel";
|
||||
import { findPreviewElementForSelection } from "./previewSelection";
|
||||
import { measurePreviewGestureStart, type PreviewGestureStart } from "./previewGestureStartRead";
|
||||
import type { SnapContext } from "./snapTargetCollection";
|
||||
import { readShownGestureStarts, type OverChannel, type Shown } from "./previewGestureStartRead";
|
||||
|
||||
type Shown = { selection: DomEditSelection; rect: OverlayRect; start?: PreviewGestureStart };
|
||||
type OverChannel = { shown: Shown[]; snap: SnapContext };
|
||||
type ShownStart = (
|
||||
e: React.PointerEvent<HTMLElement>,
|
||||
at: EditMoment,
|
||||
@@ -141,26 +137,6 @@ export function createPreviewGestureStarts(
|
||||
};
|
||||
};
|
||||
|
||||
/** An opaque frame's `selections` on the page it shows now and what a gesture on them starts from. */
|
||||
const shownOverChannel = async (
|
||||
iframe: HTMLIFrameElement,
|
||||
selections: DomEditSelection[],
|
||||
): Promise<OverChannel | null> => {
|
||||
const overlay = opts.overlayRef.current;
|
||||
const path = opts.activeCompositionPathRef.current;
|
||||
const found = await Promise.all(
|
||||
selections.map((selection) => findPreviewElementForSelection(iframe, selection, path)),
|
||||
);
|
||||
const handles = found.map((element) => element?.handle);
|
||||
if (!overlay || !handles.length || !handles.every(Boolean)) return null;
|
||||
const read = await measurePreviewGestureStart(iframe, overlay, handles as string[]);
|
||||
const shown = selections.flatMap((selection, i) => {
|
||||
const element = read?.elements[i];
|
||||
return element ? [{ selection: { ...selection, handle: handles[i] }, ...element }] : [];
|
||||
});
|
||||
return read && shown.length === selections.length ? { shown, snap: read.snap } : null;
|
||||
};
|
||||
|
||||
// A press on the page a reload is replacing would edit it by its old rules: it starts on the new page instead.
|
||||
const startOnShownPreview = (
|
||||
e: React.PointerEvent<HTMLElement>,
|
||||
@@ -216,7 +192,12 @@ export function createPreviewGestureStarts(
|
||||
if (isPreviewChanging() && !overdue) return "wait";
|
||||
if (!asked) {
|
||||
asked = true;
|
||||
void shownOverChannel(frame, targets()).then((shown) => (overChannel = shown));
|
||||
void readShownGestureStarts(
|
||||
frame,
|
||||
opts.overlayRef.current,
|
||||
opts.activeCompositionPathRef.current,
|
||||
targets(),
|
||||
).then((shown) => (overChannel = shown));
|
||||
}
|
||||
if (overChannel === undefined) return "wait";
|
||||
return overChannel ? "run" : "lost";
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
// @vitest-environment happy-dom
|
||||
import React, { act } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
||||
import { installReactActEnvironment, makeSelection } from "../../hooks/domSelectionTestHarness";
|
||||
import { __resetForTests } from "../../utils/canvasNudgeGate";
|
||||
import { flushStudioPendingEdits, trackedStudioEdit } from "../../utils/studioPendingEdits";
|
||||
import { CANVAS_NUDGE_COMMIT_DEBOUNCE_MS } from "./domEditNudge";
|
||||
import type { WaitingPressState } from "./domEditOverlayGestures";
|
||||
import type { OverChannel, Shown } from "./previewGestureStartRead";
|
||||
import { useDomEditNudge } from "./useDomEditNudge";
|
||||
|
||||
const { readShownGestureStarts } = vi.hoisted(() => ({ readShownGestureStarts: vi.fn() }));
|
||||
vi.mock("../../player/lib/previewChannel", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("../../player/lib/previewChannel")>()),
|
||||
previewFrameOpaque: () => true,
|
||||
}));
|
||||
vi.mock("./previewGestureStartRead", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("./previewGestureStartRead")>()),
|
||||
readShownGestureStarts,
|
||||
}));
|
||||
|
||||
installReactActEnvironment();
|
||||
const ref = <T,>(current: T) => ({ current });
|
||||
const RECT = { left: 0, top: 0, width: 100, height: 50, editScaleX: 1, editScaleY: 1 };
|
||||
const NONE: never[] = [];
|
||||
// A sealed selection's element is a stand-in, never in the page.
|
||||
const sealed = (label: string, handle: string) => ({
|
||||
...makeSelection(label, document.createElement("div")),
|
||||
handle,
|
||||
});
|
||||
|
||||
function Harness({
|
||||
commit,
|
||||
selection,
|
||||
flush,
|
||||
pressing = ref(null),
|
||||
}: {
|
||||
commit: () => Promise<unknown>;
|
||||
selection: ReturnType<typeof sealed>;
|
||||
flush?: { current: () => void };
|
||||
pressing?: { current: WaitingPressState | null };
|
||||
}) {
|
||||
const { flushNudge } = useDomEditNudge({
|
||||
selection,
|
||||
groupSelections: NONE,
|
||||
allowCanvasMovement: true,
|
||||
iframeRef: ref(document.createElement("iframe")),
|
||||
overlayRef: ref(document.createElement("div")),
|
||||
activeCompositionPathRef: ref("index.html"),
|
||||
selectionRef: ref(selection),
|
||||
overlayRectRef: ref(RECT),
|
||||
groupOverlayItemsRef: ref([]),
|
||||
gestureRef: ref(null),
|
||||
groupGestureRef: ref(null),
|
||||
blockedMoveRef: ref(null),
|
||||
waitingPressRef: pressing,
|
||||
onManualDragStartRef: ref(() => {}),
|
||||
onBlockedMoveRef: ref(() => {}),
|
||||
onPathOffsetCommitRef: ref(commit),
|
||||
onGroupPathOffsetCommitRef: ref(async () => {}),
|
||||
});
|
||||
if (flush) flush.current = flushNudge;
|
||||
return null;
|
||||
}
|
||||
|
||||
const arrowRight = () =>
|
||||
window.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowRight", cancelable: true }));
|
||||
|
||||
/** Each frame read waits until the test answers it, in any order. */
|
||||
function heldReads() {
|
||||
const answers: ((read: OverChannel) => void)[] = [];
|
||||
readShownGestureStarts.mockImplementation(
|
||||
() => new Promise<OverChannel>((resolve) => answers.push(resolve)),
|
||||
);
|
||||
return async (i: number) => {
|
||||
const [, , , [selection]] = readShownGestureStarts.mock.calls[i]!;
|
||||
const shown: Shown = {
|
||||
selection,
|
||||
rect: RECT,
|
||||
start: {
|
||||
layout: { width: 100, height: 50 },
|
||||
screenToOffset: null,
|
||||
gsap: { x: 60, y: 0, moving: false },
|
||||
},
|
||||
};
|
||||
const snap = { targets: [], compositionTarget: null, gridEdges: null, snapEnabled: false };
|
||||
await act(async () => answers[i]!({ shown: [shown], snap }));
|
||||
};
|
||||
}
|
||||
|
||||
const settle = () =>
|
||||
act(async () => {
|
||||
for (let i = 0; i < 20; i++) await Promise.resolve();
|
||||
});
|
||||
|
||||
let root: ReturnType<typeof createRoot> | null = null;
|
||||
let dot = sealed("Dot", "e1");
|
||||
function mount(props: React.ComponentProps<typeof Harness>) {
|
||||
root ??= createRoot(document.createElement("div"));
|
||||
act(() => root!.render(React.createElement(Harness, props)));
|
||||
}
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
__resetForTests();
|
||||
readShownGestureStarts.mockReset();
|
||||
dot = sealed("Dot", "e1");
|
||||
});
|
||||
afterEach(() => {
|
||||
act(() => root?.unmount());
|
||||
root = null;
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("moves a sealed element GSAP animates by its tween, counting the keys pressed while the frame answered", async () => {
|
||||
const answer = heldReads();
|
||||
const commit = vi.fn(async () => {});
|
||||
mount({ commit, selection: dot });
|
||||
|
||||
act(() => {
|
||||
arrowRight();
|
||||
arrowRight();
|
||||
arrowRight();
|
||||
});
|
||||
await answer(0);
|
||||
act(() => vi.advanceTimersByTime(CANVAS_NUDGE_COMMIT_DEBOUNCE_MS));
|
||||
|
||||
expect(readShownGestureStarts).toHaveBeenCalledOnce();
|
||||
expect(commit).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({ handle: "e1" }),
|
||||
{ x: 3, y: 0 },
|
||||
{ plainTranslate: false },
|
||||
);
|
||||
});
|
||||
|
||||
// fails without the fix: the flush handed the edit queue the read's promise, and the late nudge then waited on it.
|
||||
it("lets another edit save while a sealed nudge waits on its frame, and drops that nudge", async () => {
|
||||
const answer = heldReads();
|
||||
const commit = vi.fn(async () => {});
|
||||
mount({ commit, selection: dot });
|
||||
let otherSaved = false;
|
||||
const other = trackedStudioEdit(async () => void (otherSaved = true), { afterOlderSaves: true });
|
||||
|
||||
act(() => arrowRight());
|
||||
act(() => void other());
|
||||
await answer(0);
|
||||
let drained = false;
|
||||
void flushStudioPendingEdits().then(() => (drained = true));
|
||||
await settle();
|
||||
act(() => vi.advanceTimersByTime(CANVAS_NUDGE_COMMIT_DEBOUNCE_MS));
|
||||
await settle();
|
||||
|
||||
expect(otherSaved).toBe(true);
|
||||
expect(drained).toBe(true);
|
||||
expect(commit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// fails without the fix: the old element's read stayed open, so the new selection's arrow moved the old element.
|
||||
it("moves the newly selected element, not the one still waiting on its frame", async () => {
|
||||
const answer = heldReads();
|
||||
const commit = vi.fn(async () => {});
|
||||
mount({ commit, selection: dot });
|
||||
|
||||
act(() => arrowRight());
|
||||
mount({ commit, selection: sealed("Ring", "e2") });
|
||||
act(() => arrowRight());
|
||||
await answer(0);
|
||||
await answer(1);
|
||||
act(() => vi.advanceTimersByTime(CANVAS_NUDGE_COMMIT_DEBOUNCE_MS));
|
||||
|
||||
expect(commit).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({ handle: "e2" }),
|
||||
{ x: 1, y: 0 },
|
||||
{ plainTranslate: false },
|
||||
);
|
||||
});
|
||||
|
||||
// fails without the fix: the frame's late answer started and saved the nudge under the drag that had begun.
|
||||
it("drops a sealed nudge still waiting on its frame when a drag takes the element", async () => {
|
||||
const answer = heldReads();
|
||||
const commit = vi.fn(async () => {});
|
||||
const flush = { current: () => {} };
|
||||
mount({ commit, selection: dot, flush });
|
||||
|
||||
act(() => arrowRight());
|
||||
act(() => flush.current());
|
||||
await answer(0);
|
||||
act(() => vi.advanceTimersByTime(CANVAS_NUDGE_COMMIT_DEBOUNCE_MS));
|
||||
act(() => arrowRight());
|
||||
await answer(1);
|
||||
act(() => vi.advanceTimersByTime(CANVAS_NUDGE_COMMIT_DEBOUNCE_MS));
|
||||
|
||||
expect(commit).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({ handle: "e1" }),
|
||||
{ x: 1, y: 0 },
|
||||
{ plainTranslate: false },
|
||||
);
|
||||
});
|
||||
|
||||
// fails without the fix: an arrow during a press still waiting on its frame started a nudge the drag then ran under.
|
||||
it("asks the frame nothing for an arrow pressed while a canvas press waits, and nudges once it ends", async () => {
|
||||
const answer = heldReads();
|
||||
const commit = vi.fn(async () => {});
|
||||
const pressing = { current: {} as WaitingPressState | null };
|
||||
mount({ commit, selection: dot, pressing });
|
||||
|
||||
act(() => arrowRight());
|
||||
expect(readShownGestureStarts).not.toHaveBeenCalled();
|
||||
|
||||
pressing.current = null;
|
||||
act(() => arrowRight());
|
||||
await answer(0);
|
||||
act(() => vi.advanceTimersByTime(CANVAS_NUDGE_COMMIT_DEBOUNCE_MS));
|
||||
expect(commit).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.objectContaining({ handle: "e1" }),
|
||||
{ x: 1, y: 0 },
|
||||
{ plainTranslate: false },
|
||||
);
|
||||
});
|
||||
@@ -49,12 +49,16 @@ function Harness({
|
||||
selection,
|
||||
groupSelections: EMPTY_GROUP_SELECTIONS,
|
||||
allowCanvasMovement: true,
|
||||
iframeRef: makeRef(null),
|
||||
overlayRef: makeRef(null),
|
||||
activeCompositionPathRef: makeRef(null),
|
||||
selectionRef: makeRef(selection),
|
||||
overlayRectRef: makeRef(REST_RECT),
|
||||
groupOverlayItemsRef: makeRef([]),
|
||||
gestureRef: makeRef(null),
|
||||
groupGestureRef: makeRef(null),
|
||||
blockedMoveRef: makeRef(null),
|
||||
waitingPressRef: makeRef(null),
|
||||
onManualDragStartRef: makeRef(onManualDragStart),
|
||||
onBlockedMoveRef: makeRef(() => {}),
|
||||
onPathOffsetCommitRef: makeRef(onPathOffsetCommit),
|
||||
@@ -388,6 +392,15 @@ describe("useDomEditNudge pauses playback before it snapshots the timelines", ()
|
||||
expect(element.hasAttribute("data-hf-drag-paused-timelines")).toBe(false);
|
||||
});
|
||||
|
||||
it("starts a nudge on a sealed preview's selection, whose stand-in is never connected", () => {
|
||||
const standIn = document.createElement("div");
|
||||
mount({ ...makeSelection("Dot", standIn), handle: "e1" });
|
||||
|
||||
act(() => dispatchArrowRight());
|
||||
|
||||
expect(pause).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("leaves playback alone when no layer can move", () => {
|
||||
mount(null);
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import type {
|
||||
MoveCommitOptions,
|
||||
GestureState,
|
||||
GroupGestureState,
|
||||
WaitingPressState,
|
||||
} from "./domEditOverlayGestures";
|
||||
import {
|
||||
applyManualOffsetNudgeCommit,
|
||||
@@ -42,6 +43,9 @@ import {
|
||||
canCanvasNudgeTargets,
|
||||
resolveCanvasNudgeDelta,
|
||||
} from "./domEditNudge";
|
||||
import { selectionElementLive } from "./previewSelection";
|
||||
import { previewFrameOpaque } from "../../player/lib/previewChannel";
|
||||
import { readShownGestureStarts, type PreviewGestureStart } from "./previewGestureStartRead";
|
||||
|
||||
interface NudgeSession {
|
||||
members: ManualOffsetDragMember[];
|
||||
@@ -52,16 +56,26 @@ interface NudgeSession {
|
||||
edit: ReturnType<typeof beginStudioPendingEdit>;
|
||||
}
|
||||
|
||||
/** A burst on a sealed frame waits for the frame's gesture-start read; keys meanwhile add to `accum`. */
|
||||
interface SealedStartRead {
|
||||
accum: { x: number; y: number };
|
||||
dropped: boolean;
|
||||
}
|
||||
|
||||
export interface UseDomEditNudgeParams {
|
||||
selection: DomEditSelection | null;
|
||||
groupSelections: DomEditSelection[];
|
||||
allowCanvasMovement: boolean;
|
||||
iframeRef: RefObject<HTMLIFrameElement | null>;
|
||||
overlayRef: RefObject<HTMLDivElement | null>;
|
||||
activeCompositionPathRef: RefObject<string | null>;
|
||||
selectionRef: RefObject<DomEditSelection | null>;
|
||||
overlayRectRef: RefObject<OverlayRect | null>;
|
||||
groupOverlayItemsRef: RefObject<GroupOverlayItem[]>;
|
||||
gestureRef: RefObject<GestureState | null>;
|
||||
groupGestureRef: RefObject<GroupGestureState | null>;
|
||||
blockedMoveRef: RefObject<BlockedMoveState | null>;
|
||||
waitingPressRef: RefObject<WaitingPressState | null>;
|
||||
onManualDragStartRef: RefObject<(() => void) | undefined>;
|
||||
onBlockedMoveRef: RefObject<(selection: DomEditSelection, reason?: string) => void>;
|
||||
onPathOffsetCommitRef: RefObject<
|
||||
@@ -81,6 +95,7 @@ type NudgeTarget = {
|
||||
selection: DomEditSelection;
|
||||
element: HTMLElement;
|
||||
rect: OverlayRect;
|
||||
start?: PreviewGestureStart;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -126,7 +141,7 @@ function resolveSingleNudgeTarget(
|
||||
sel: DomEditSelection | null,
|
||||
rect: OverlayRect | null,
|
||||
): NudgeTarget[] | null {
|
||||
if (!sel || !rect || !sel.capabilities.canApplyManualOffset || !sel.element.isConnected) {
|
||||
if (!sel || !rect || !sel.capabilities.canApplyManualOffset || !selectionElementLive(sel)) {
|
||||
return null;
|
||||
}
|
||||
return [{ key: sel.id ?? sel.selector ?? sel.label, selection: sel, element: sel.element, rect }];
|
||||
@@ -134,16 +149,18 @@ function resolveSingleNudgeTarget(
|
||||
|
||||
/**
|
||||
* True when a keydown must not start/extend a nudge: canvas movement disabled,
|
||||
* a pointer gesture already owns the element, or focus is in a field or a native player.
|
||||
* a pointer gesture owns or is about to own the element, or focus is in a field or a player.
|
||||
*/
|
||||
function shouldIgnoreNudgeKey(p: UseDomEditNudgeParams, event: KeyboardEvent): boolean {
|
||||
if (!p.allowCanvasMovement || event.defaultPrevented) return true;
|
||||
if (p.gestureRef.current || p.groupGestureRef.current || p.blockedMoveRef.current) return true;
|
||||
if (p.waitingPressRef.current) return true;
|
||||
return ownsPlainKeys(event.target);
|
||||
}
|
||||
|
||||
export function useDomEditNudge(params: UseDomEditNudgeParams): { flushNudge: () => void } {
|
||||
const sessionRef = useRef<NudgeSession | null>(null);
|
||||
const readingRef = useRef<SealedStartRead | null>(null);
|
||||
const paramsRef = useRef(params);
|
||||
paramsRef.current = params;
|
||||
|
||||
@@ -151,6 +168,7 @@ export function useDomEditNudge(params: UseDomEditNudgeParams): { flushNudge: ()
|
||||
// Mirrors the drag's onPointerUp — same commit callbacks, same failure
|
||||
// restore, same member teardown.
|
||||
const commitSession = (): Promise<unknown> | undefined => {
|
||||
if (cancelSealedRead()) return undefined;
|
||||
const session = sessionRef.current;
|
||||
if (!session) return undefined;
|
||||
sessionRef.current = null;
|
||||
@@ -188,11 +206,22 @@ export function useDomEditNudge(params: UseDomEditNudgeParams): { flushNudge: ()
|
||||
session.edit.settle(saved);
|
||||
}
|
||||
};
|
||||
// Whatever flushes a burst still waiting on its frame (a drag, a selection change, another edit) owns the element
|
||||
// now: the keys are dropped, nothing was drawn yet, and the next arrow starts a fresh read on the current target.
|
||||
const cancelSealedRead = (): boolean => {
|
||||
const reading = readingRef.current;
|
||||
if (!reading) return false;
|
||||
reading.dropped = true;
|
||||
readingRef.current = null;
|
||||
return true;
|
||||
};
|
||||
const commitSessionRef = useRef(commitSession);
|
||||
commitSessionRef.current = commitSession;
|
||||
|
||||
useEffect(() => {
|
||||
if (params.allowCanvasMovement || !sessionRef.current) return;
|
||||
if (params.allowCanvasMovement) return;
|
||||
cancelSealedRead();
|
||||
if (!sessionRef.current) return;
|
||||
const session = sessionRef.current;
|
||||
sessionRef.current = null;
|
||||
if (session.timer) clearTimeout(session.timer);
|
||||
@@ -204,14 +233,22 @@ export function useDomEditNudge(params: UseDomEditNudgeParams): { flushNudge: ()
|
||||
// Build drag members for the current target set — the same member snapshot a
|
||||
// pointer drag starts from (startGesture / startGroupDrag), so the nudge
|
||||
// commit converts offsets → GSAP x/y with identical math.
|
||||
const beginSession = (event: KeyboardEvent): NudgeSession | "refused" | null => {
|
||||
const nudgeTargets = () => {
|
||||
const p = paramsRef.current;
|
||||
const groupItems = p.groupOverlayItemsRef.current;
|
||||
const isGroup = groupItems.length > 1;
|
||||
const targets = isGroup
|
||||
? resolveGroupNudgeTargets(groupItems)
|
||||
: resolveSingleNudgeTarget(p.selectionRef.current, p.overlayRectRef.current);
|
||||
if (!targets) return null;
|
||||
return targets && { targets, isGroup };
|
||||
};
|
||||
|
||||
const beginSession = (
|
||||
found: { targets: NudgeTarget[]; isGroup: boolean },
|
||||
repeat: boolean,
|
||||
): NudgeSession | "refused" | null => {
|
||||
const p = paramsRef.current;
|
||||
const { targets, isGroup } = found;
|
||||
// Same side effect a drag start has (pauses preview playback).
|
||||
p.onManualDragStartRef.current?.();
|
||||
const members: ManualOffsetDragMember[] = [];
|
||||
@@ -219,7 +256,7 @@ export function useDomEditNudge(params: UseDomEditNudgeParams): { flushNudge: ()
|
||||
const result = createManualOffsetDragMember({ ...target, gesture: "nudge" });
|
||||
if (!result.ok) {
|
||||
restoreManualOffsetDragMembers(members);
|
||||
if (!event.repeat) p.onBlockedMoveRef.current(result.selection, result.reason);
|
||||
if (!repeat) p.onBlockedMoveRef.current(result.selection, result.reason);
|
||||
return "refused";
|
||||
}
|
||||
members.push(result.member);
|
||||
@@ -229,20 +266,65 @@ export function useDomEditNudge(params: UseDomEditNudgeParams): { flushNudge: ()
|
||||
return { members, isGroup, accum: { x: 0, y: 0 }, timer: null, edit };
|
||||
};
|
||||
|
||||
const startBurst = (session: NudgeSession) => {
|
||||
sessionRef.current = session;
|
||||
for (const member of session.members) applyManualOffsetNudgeDraft(member, session.accum);
|
||||
if (session.timer) clearTimeout(session.timer);
|
||||
session.timer = setTimeout(() => commitSessionRef.current(), CANVAS_NUDGE_COMMIT_DEBOUNCE_MS);
|
||||
};
|
||||
|
||||
// A sealed frame's stand-in has no GSAP or translate: its members start from the frame's read, as a press does.
|
||||
const readSealedStart = (): SealedStartRead | null => {
|
||||
const p = paramsRef.current;
|
||||
const iframe = p.iframeRef.current;
|
||||
const found = iframe && previewFrameOpaque(iframe) ? nudgeTargets() : null;
|
||||
if (!iframe || !found) return null;
|
||||
const selections = found.targets.map((target) => target.selection);
|
||||
const read: SealedStartRead = { accum: { x: 0, y: 0 }, dropped: false };
|
||||
void readShownGestureStarts(
|
||||
iframe,
|
||||
p.overlayRef.current,
|
||||
p.activeCompositionPathRef.current,
|
||||
selections,
|
||||
)
|
||||
.catch(() => null)
|
||||
.then((shown) => {
|
||||
if (readingRef.current === read) readingRef.current = null;
|
||||
if (read.dropped || !shown) return;
|
||||
const targets = found.targets.map((target, i) => ({ ...target, ...shown.shown[i] }));
|
||||
const session = beginSession({ targets, isGroup: found.isGroup }, false);
|
||||
if (!session || session === "refused") return;
|
||||
session.accum = read.accum;
|
||||
startBurst(session);
|
||||
});
|
||||
return read;
|
||||
};
|
||||
|
||||
const joinSealedRead = (delta: { dx: number; dy: number }): boolean => {
|
||||
const reading = readingRef.current ?? (sessionRef.current ? null : readSealedStart());
|
||||
if (!reading) return false;
|
||||
readingRef.current = reading;
|
||||
reading.accum = { x: reading.accum.x + delta.dx, y: reading.accum.y + delta.dy };
|
||||
return true;
|
||||
};
|
||||
|
||||
const openSession = (repeat: boolean) => {
|
||||
const found = nudgeTargets();
|
||||
return found && beginSession(found, repeat);
|
||||
};
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
const p = paramsRef.current;
|
||||
if (shouldIgnoreNudgeKey(p, event)) return;
|
||||
const delta = resolveCanvasNudgeDelta(event);
|
||||
if (!delta) return;
|
||||
const session = sessionRef.current ?? beginSession(event);
|
||||
if (joinSealedRead(delta)) return void event.preventDefault();
|
||||
const session = sessionRef.current ?? openSession(event.repeat);
|
||||
if (session === "refused") return void event.preventDefault();
|
||||
if (!session) return;
|
||||
sessionRef.current = session;
|
||||
event.preventDefault();
|
||||
session.accum = { x: session.accum.x + delta.dx, y: session.accum.y + delta.dy };
|
||||
for (const member of session.members) applyManualOffsetNudgeDraft(member, session.accum);
|
||||
if (session.timer) clearTimeout(session.timer);
|
||||
session.timer = setTimeout(() => commitSessionRef.current(), CANVAS_NUDGE_COMMIT_DEBOUNCE_MS);
|
||||
startBurst(session);
|
||||
};
|
||||
const handleKeyDownRef = useRef(handleKeyDown);
|
||||
handleKeyDownRef.current = handleKeyDown;
|
||||
|
||||
@@ -65,6 +65,7 @@ export type GsapEditOutcome =
|
||||
* and the element snapped back to its authored position on every drag.
|
||||
*/
|
||||
ownsDragOffset?: boolean;
|
||||
savedAsScale?: true;
|
||||
}
|
||||
| { status: "blocked"; reason: GsapEditBlockReason; detail?: GsapEditBlockDetail }
|
||||
| { status: "element-offset" }
|
||||
|
||||
@@ -311,7 +311,7 @@ async function runResize(
|
||||
commitMutation as never,
|
||||
async () => [keyframedScaleFixture()],
|
||||
);
|
||||
expect(handled).toMatchObject({ status: "persisted" });
|
||||
expect(handled).toMatchObject({ status: "persisted", savedAsScale: true });
|
||||
return committed;
|
||||
}
|
||||
|
||||
@@ -753,6 +753,59 @@ it.each([
|
||||
document.querySelector("#__hf_color_grading_clip")?.remove();
|
||||
});
|
||||
|
||||
// fails without the fix: a width/height tween resized as a whole reported its size as saved as scale.
|
||||
describe("a resize with auto-keyframe off nudges the whole tween", () => {
|
||||
afterEach(() => usePlayerStore.setState({ autoKeyframeEnabled: true }));
|
||||
|
||||
it("of a width/height tween, and says it saved the size as width and height", async () => {
|
||||
usePlayerStore.setState({ autoKeyframeEnabled: false, currentTime: 1 });
|
||||
const selection = titleSelection();
|
||||
selection.element.setAttribute("data-hf-studio-original-box-width", "260");
|
||||
selection.element.setAttribute("data-hf-studio-original-box-height", "160");
|
||||
const grow = tween({
|
||||
id: "#title-to-0-size",
|
||||
targetSelector: "#title",
|
||||
propertyGroup: "size",
|
||||
method: "to",
|
||||
properties: { width: 320, height: 200 },
|
||||
resolvedStart: 0,
|
||||
duration: 2,
|
||||
ease: "none",
|
||||
});
|
||||
const commitMutation = vi.fn();
|
||||
|
||||
const outcome = await tryGsapResizeIntercept(
|
||||
selection,
|
||||
{ width: 300, height: 180 },
|
||||
[grow],
|
||||
null,
|
||||
commitMutation,
|
||||
async () => [grow],
|
||||
);
|
||||
|
||||
expect(outcome.status).toBe("persisted");
|
||||
expect(outcome).not.toHaveProperty("savedAsScale");
|
||||
expect(commitMutation).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("of a scale tween, and says it saved the size as scale", async () => {
|
||||
usePlayerStore.setState({ autoKeyframeEnabled: false, currentTime: 0.5 });
|
||||
const el = makeGradedElement();
|
||||
const iframe = fakeIframe(el, { scale: 1, scaleX: 1, scaleY: 1, opacity: 0, rotation: 0 });
|
||||
|
||||
const outcome = await tryGsapResizeIntercept(
|
||||
{ id: "clip", selector: "#clip", element: el } as DomEditSelection,
|
||||
{ width: 800, height: 450 },
|
||||
[scaleFromTween()],
|
||||
iframe,
|
||||
vi.fn(),
|
||||
async () => [keyframedScaleFixture()],
|
||||
);
|
||||
|
||||
expect(outcome).toMatchObject({ status: "persisted", savedAsScale: true });
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
["the draft marked the element", false],
|
||||
["the element is a sealed frame's stand-in, measured at the press", true],
|
||||
|
||||
@@ -535,7 +535,11 @@ export async function tryGsapResizeIntercept(
|
||||
{ commitMutation, fetchAnimations: fetchFallbackAnimations },
|
||||
"Resize animation",
|
||||
);
|
||||
return { status: "persisted", ownsDragOffset: await finalizeScaleResizeCommit() };
|
||||
return {
|
||||
status: "persisted",
|
||||
ownsDragOffset: await finalizeScaleResizeCommit(),
|
||||
...(resizeGroup === "scale" && { savedAsScale: true }),
|
||||
};
|
||||
}
|
||||
|
||||
const callbacks = { commitMutation, fetchAnimations: fetchFallbackAnimations, stamp };
|
||||
@@ -555,7 +559,11 @@ export async function tryGsapResizeIntercept(
|
||||
backfill: resizeBackfill,
|
||||
});
|
||||
if (written.status !== "persisted") return written;
|
||||
return { status: "persisted", ownsDragOffset: await finalizeScaleResizeCommit() };
|
||||
return {
|
||||
status: "persisted",
|
||||
ownsDragOffset: await finalizeScaleResizeCommit(),
|
||||
savedAsScale: true,
|
||||
};
|
||||
}
|
||||
|
||||
// ── Rotation intercept ────────────────────────────────────────────────────
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* the intercept sends that is not in the list it was last handed reproduces the
|
||||
* failure.
|
||||
*/
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
|
||||
import type { DomEditSelection } from "../components/editor/domEditingTypes";
|
||||
import { usePlayerStore } from "../player/store/playerStore";
|
||||
@@ -165,3 +165,54 @@ it("leaves the drag offset to the caller when it commits size, not scale", async
|
||||
|
||||
expect(outcome.status).toBe("element-size");
|
||||
});
|
||||
|
||||
describe("a resize of an element whose size is held, never says it saved scale", () => {
|
||||
const card = () => {
|
||||
const el = document.createElement("div");
|
||||
el.id = "card";
|
||||
el.setAttribute("data-hf-studio-original-box-width", "300");
|
||||
el.setAttribute("data-hf-studio-original-box-height", "200");
|
||||
document.body.append(el);
|
||||
return el;
|
||||
};
|
||||
|
||||
it("keys the size into the tween that animates it when a hold sits at the playhead", async () => {
|
||||
const el = card();
|
||||
const sizeHold = hold("#card-to-0-size", "size", { width: 300, height: 200 });
|
||||
const grow = {
|
||||
...hold("#card-to-2000-size", "size", { width: 400, height: 260 }),
|
||||
position: 2,
|
||||
resolvedStart: 2,
|
||||
duration: 1,
|
||||
extras: {},
|
||||
} as unknown as GsapAnimation;
|
||||
usePlayerStore.setState({ currentTime: 1 });
|
||||
|
||||
const outcome = await tryGsapResizeIntercept(
|
||||
{ id: "card", selector: "#card", element: el } as DomEditSelection,
|
||||
{ width: 340, height: 220 },
|
||||
[sizeHold, grow],
|
||||
null,
|
||||
vi.fn() as never,
|
||||
async () => [sizeHold, grow],
|
||||
);
|
||||
|
||||
expect(outcome).not.toHaveProperty("savedAsScale");
|
||||
});
|
||||
|
||||
it("refuses an element no selector addresses", async () => {
|
||||
const el = document.createElement("div");
|
||||
const sizeHold = hold("#card-to-0-size", "size", { width: 300, height: 200 });
|
||||
|
||||
const outcome = await tryGsapResizeIntercept(
|
||||
{ element: el } as DomEditSelection,
|
||||
{ width: 340, height: 220 },
|
||||
[sizeHold],
|
||||
null,
|
||||
vi.fn() as never,
|
||||
async () => [sizeHold],
|
||||
);
|
||||
|
||||
expect(outcome).toEqual({ status: "blocked", reason: "no-selector" });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -202,12 +202,16 @@ function Nudge({ target, save }: { target: HTMLElement; save: () => Promise<void
|
||||
selection,
|
||||
groupSelections: [],
|
||||
allowCanvasMovement: true,
|
||||
iframeRef: ref(null),
|
||||
overlayRef: ref(null),
|
||||
activeCompositionPathRef: ref(null),
|
||||
selectionRef: ref(selection),
|
||||
overlayRectRef: ref({ left: 0, top: 0, width: 100, height: 40, editScaleX: 1, editScaleY: 1 }),
|
||||
groupOverlayItemsRef: ref([]),
|
||||
gestureRef: ref(null),
|
||||
groupGestureRef: ref(null),
|
||||
blockedMoveRef: ref(null),
|
||||
waitingPressRef: ref(null),
|
||||
onManualDragStartRef: ref(() => {}),
|
||||
onBlockedMoveRef: ref(() => {}),
|
||||
onPathOffsetCommitRef: ref(save),
|
||||
|
||||
@@ -288,6 +288,25 @@ describe("useGsapAwareEditing keeps the box route a resize chose at press", () =
|
||||
});
|
||||
});
|
||||
|
||||
describe("useGsapAwareEditing tells the resize how its save wrote the size", () => {
|
||||
// fails without the fix: a scale tween on the element read as "saved as scale" whatever the writer did.
|
||||
it.each([
|
||||
["as GSAP scale keys", { status: "persisted", savedAsScale: true }, true],
|
||||
["as width and height, beside an instant scale hold", { status: "element-size" }, false],
|
||||
["as width and height in a size tween", { status: "persisted" }, false],
|
||||
])("%s", async (_, outcome, asScale) => {
|
||||
mocks.resize.mockResolvedValue(outcome);
|
||||
const animation = { id: "a", propertyGroup: "scale" } as GsapAnimation;
|
||||
const h = mountResizeHandler([animation]);
|
||||
const route: { plainTranslate: boolean; sizeSavedAsScale?: boolean } = {
|
||||
plainTranslate: false,
|
||||
};
|
||||
await act(() => h.resize(h.selection, { width: 300, height: 200 }, undefined, vi.fn(), route));
|
||||
expect(route.sizeSavedAsScale).toBe(asScale);
|
||||
act(() => h.root.unmount());
|
||||
});
|
||||
});
|
||||
|
||||
describe("useGsapAwareEditing refuses a group GSAP took over before writing any member", () => {
|
||||
it("writes no member when one CSS-route member has been folded since the press", async () => {
|
||||
const stageElementPositionOffset = vi.fn(() => ({ save: vi.fn(), rollback: vi.fn() }));
|
||||
|
||||
@@ -211,7 +211,7 @@ export function useGsapAwareEditing({
|
||||
next: { width: number; height: number },
|
||||
offset?: { x: number; y: number },
|
||||
restore: () => void = () => undefined,
|
||||
route?: { plainTranslate: boolean },
|
||||
route?: { plainTranslate: boolean; sizeSavedAsScale?: boolean },
|
||||
) => {
|
||||
const writes = observeGsapGesture(gsapCommitMutation);
|
||||
const routed = route?.plainTranslate ?? editsPlainCssSettled(selection.element, "resize");
|
||||
@@ -315,6 +315,8 @@ export function useGsapAwareEditing({
|
||||
stamp,
|
||||
);
|
||||
assertGsapEditPersisted(outcome);
|
||||
if (route)
|
||||
route.sizeSavedAsScale = outcome.status === "persisted" && !!outcome.savedAsScale;
|
||||
// Saved before the buffered GSAP writes, so their reload stays the gesture's last render.
|
||||
if (outcome.status === "element-size") {
|
||||
const result = await writes.drawKeepingUndone(() =>
|
||||
|
||||
Reference in New Issue
Block a user