@hyperframes/studio 0.9.42 → 0.9.44
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-CKqLGYc6.js → codec-DYhkxayl.js} +1 -1
- package/dist/assets/{hyperframes-player-DoEYqOIa.js → hyperframes-player-pPwFQY2W.js} +1 -1
- package/dist/assets/{index-4VGEAZyf.css → index-CU24FmKd.css} +1 -1
- package/dist/assets/{index-DLyQ91Ek.js → index-Crhhpl7F.js} +133 -133
- package/dist/assets/{index-s9iqoWnr.js → index-Cv1BkoPn.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-B-ReRg6i.js → pausedVideoDecoder-Cns-60-8.js} +1 -1
- package/dist/{chunk-4QQMX4BX.js → chunk-67DSVBEI.js} +1 -1
- package/dist/{chunk-52AJB4PN.js → chunk-ZNUWV4FN.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/index.js +790 -709
- package/dist/player.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/ui.js +1 -1
- package/package.json +8 -8
- package/src/components/StudioOverlays.tsx +15 -13
- package/src/components/StudioToast.test.tsx +41 -0
- package/src/components/StudioToast.tsx +23 -39
- package/src/components/editor/domEditOverlayGeometry.ts +2 -0
- package/src/components/editor/domEditOverlayStartGesture.ts +31 -7
- package/src/components/editor/manualOffsetDrag.ts +10 -5
- package/src/components/editor/plainTranslate.ts +2 -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/previewOverlayRects.test.ts +62 -0
- package/src/components/editor/previewOverlayRects.ts +8 -20
- package/src/components/editor/snapTargetCollection.ts +26 -62
- package/src/components/feedback/StudioFeedbackCard.tsx +5 -2
- package/src/components/ui/Menu.test.tsx +30 -1
- package/src/components/ui/Menu.tsx +1 -1
- package/src/hooks/timelineEditingHelpers.test.ts +48 -0
- package/src/hooks/timelineEditingHelpers.ts +2 -0
- package/src/hooks/timelineElementsAttribute.test.ts +46 -0
- package/src/hooks/timelineElementsAttribute.ts +14 -16
- package/src/hooks/timelineTrackVisibility.test.ts +34 -0
- package/src/hooks/useElementPicker.test.ts +9 -2
- package/src/hooks/useElementPicker.ts +4 -2
- package/src/hooks/useToast.ts +6 -18
- package/src/player/lib/previewElements.ts +37 -0
- package/src/player/lib/thumbnailFrameSink.test.ts +92 -0
- package/src/player/lib/thumbnailFrameSink.ts +83 -0
- package/src/player/lib/thumbnailVideoDecoder.test.ts +43 -16
- package/src/player/lib/thumbnailVideoDecoder.ts +6 -6
- package/src/styles/components.css +19 -1
- package/src/styles/theme.css +3 -0
- package/src/utils/previewSafeMargins.ts +6 -10
- package/src/utils/sourcePatcher.test.ts +21 -0
- package/src/utils/sourcePatcher.ts +16 -8
|
@@ -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
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { memo, useState, useCallback, useRef, useEffect } from "react";
|
|
2
|
-
import { toastSurface } from "../StudioToast";
|
|
3
2
|
import {
|
|
4
3
|
trackStudioFeedback,
|
|
5
4
|
trackStudioFeedbackShown,
|
|
@@ -213,7 +212,7 @@ export const StudioFeedbackCard = memo(function StudioFeedbackCard() {
|
|
|
213
212
|
}}
|
|
214
213
|
>
|
|
215
214
|
<div
|
|
216
|
-
className={`flex w-[min(340px,calc(100vw-48px))] flex-col gap-2.5 overflow-hidden rounded-2xl px-3.5 py-3 ${
|
|
215
|
+
className={`flex w-[min(340px,calc(100vw-48px))] flex-col gap-2.5 overflow-hidden rounded-2xl px-3.5 py-3 ${cardSurface(failed)}`}
|
|
217
216
|
>
|
|
218
217
|
<div className="flex items-start gap-3">
|
|
219
218
|
<p
|
|
@@ -359,3 +358,7 @@ export const StudioFeedbackCard = memo(function StudioFeedbackCard() {
|
|
|
359
358
|
</div>
|
|
360
359
|
);
|
|
361
360
|
});
|
|
361
|
+
|
|
362
|
+
function cardSurface(isError: boolean): string {
|
|
363
|
+
return `border shadow-popover bg-raised ${isError ? "border-danger/40" : "border-border"}`;
|
|
364
|
+
}
|
|
@@ -6,7 +6,15 @@ import React, { act, useState } from "react";
|
|
|
6
6
|
import { compile } from "tailwindcss";
|
|
7
7
|
import { afterEach, beforeAll, describe, expect, it } from "vitest";
|
|
8
8
|
import { loadStylesheet, STYLES_DIR } from "../../styles/styleSources";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
ContextMenu,
|
|
11
|
+
floatingMotion,
|
|
12
|
+
Menu,
|
|
13
|
+
MenuItem,
|
|
14
|
+
MenuRadioGroup,
|
|
15
|
+
MenuRadioItem,
|
|
16
|
+
MenuSeparator,
|
|
17
|
+
} from "./Menu";
|
|
10
18
|
import { Popover } from "./Popover";
|
|
11
19
|
import { isTypingTarget } from "../../utils/typingTarget";
|
|
12
20
|
import { shouldIgnorePlaybackShortcutTarget } from "../../player/lib/playbackShortcuts";
|
|
@@ -443,3 +451,24 @@ describe("open motion", () => {
|
|
|
443
451
|
expect(compileStudioCss([rowRadius])).toMatch(/calc\(var\(--radius-lg\) \+ 6px\)/);
|
|
444
452
|
});
|
|
445
453
|
});
|
|
454
|
+
|
|
455
|
+
describe("floatingMotion", () => {
|
|
456
|
+
it("transitions every property its starting and ending styles set", () => {
|
|
457
|
+
const classes = floatingMotion("duration-open").split(/\s+/);
|
|
458
|
+
const transitioned = classes.flatMap(
|
|
459
|
+
(c) => c.match(/^transition-\[(.+)\]$/)?.[1].split(",") ?? [],
|
|
460
|
+
);
|
|
461
|
+
const animated = classes
|
|
462
|
+
.flatMap(
|
|
463
|
+
(c) =>
|
|
464
|
+
c
|
|
465
|
+
.match(
|
|
466
|
+
/^data-\[(?:starting|ending)-style\]:(?:\[([\w-]+):|(opacity|scale|translate|rotate)-)/,
|
|
467
|
+
)
|
|
468
|
+
?.slice(1) ?? [],
|
|
469
|
+
)
|
|
470
|
+
.filter(Boolean);
|
|
471
|
+
expect(new Set(animated)).toEqual(new Set(["opacity", "scale"]));
|
|
472
|
+
for (const property of animated) expect(transitioned).toContain(property);
|
|
473
|
+
});
|
|
474
|
+
});
|
|
@@ -47,7 +47,7 @@ const VIEWPORT_MARGIN = 8;
|
|
|
47
47
|
export function floatingMotion(openDuration: "duration-open" | "duration-tooltip") {
|
|
48
48
|
return cn(
|
|
49
49
|
"origin-[var(--transform-origin)] outline-hidden",
|
|
50
|
-
"transition-[opacity,
|
|
50
|
+
"transition-[opacity,scale] ease-out-quint",
|
|
51
51
|
openDuration,
|
|
52
52
|
"data-[ending-style]:duration-close data-[ending-style]:ease-in",
|
|
53
53
|
"data-[starting-style]:[opacity:var(--popup-enter-opacity)]",
|
|
@@ -11,8 +11,11 @@ import {
|
|
|
11
11
|
persistElementAttribute,
|
|
12
12
|
persistTimelineBatchEdit,
|
|
13
13
|
persistTimelineEdit,
|
|
14
|
+
readTargetAttribute,
|
|
14
15
|
type PersistTimelineBatchChange,
|
|
15
16
|
} from "./timelineEditingHelpers";
|
|
17
|
+
import { ensureHfIds } from "@hyperframes/parsers/hf-ids";
|
|
18
|
+
import { parseTimelineFromDOM } from "../player/lib/timelineDOM";
|
|
16
19
|
import type { TimelineElement } from "../player/store/playerStore";
|
|
17
20
|
import { readMediaOffsetSeconds } from "@hyperframes/parsers/media-duration";
|
|
18
21
|
import { usePlayerStore } from "../player/store/playerStore";
|
|
@@ -684,6 +687,51 @@ describe("persistElementAttribute", () => {
|
|
|
684
687
|
});
|
|
685
688
|
});
|
|
686
689
|
|
|
690
|
+
describe("a clip whose file has no ids yet", () => {
|
|
691
|
+
// Added outside Studio: no id, no class, and nothing has stamped the file since. The preview mints its hf-id.
|
|
692
|
+
const ON_DISK = `<div data-composition-id="main" data-start="0" data-duration="10"><img src="a.png" data-start="1" data-duration="3" data-volume="0.5"></div>`;
|
|
693
|
+
const served = () => {
|
|
694
|
+
const doc = document.implementation.createHTMLDocument("");
|
|
695
|
+
doc.body.innerHTML = ensureHfIds(ON_DISK);
|
|
696
|
+
const [clip] = parseTimelineFromDOM(doc, 10);
|
|
697
|
+
if (!clip?.hfId) throw new Error("expected the served clip to carry an hf-id");
|
|
698
|
+
return { hfId: clip.hfId };
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
afterEach(() => {
|
|
702
|
+
vi.unstubAllGlobals();
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
it("saves an attribute on it by the id the preview served it with", async () => {
|
|
706
|
+
vi.stubGlobal(
|
|
707
|
+
"fetch",
|
|
708
|
+
vi.fn(async () => new Response(JSON.stringify({ content: ON_DISK }))),
|
|
709
|
+
);
|
|
710
|
+
const target = served();
|
|
711
|
+
const writes: string[] = [];
|
|
712
|
+
|
|
713
|
+
await persistElementAttribute({
|
|
714
|
+
projectId: "p",
|
|
715
|
+
targetPath: "index.html",
|
|
716
|
+
patchTarget: target,
|
|
717
|
+
attr: "data-volume",
|
|
718
|
+
value: "0.9",
|
|
719
|
+
label: "Set volume",
|
|
720
|
+
writeProjectFile: async (_path, content) => void writes.push(content),
|
|
721
|
+
recordEdit: vi.fn(async () => {}),
|
|
722
|
+
pendingTimelineEditPathRef: { current: new Set() },
|
|
723
|
+
onFileRead: vi.fn(),
|
|
724
|
+
patchLive: vi.fn(),
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
expect(readTargetAttribute(writes[0] ?? "", target, "data-volume")).toBe("0.9");
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
it("reads its attribute by that id", () => {
|
|
731
|
+
expect(readTargetAttribute(ON_DISK, served(), "data-volume")).toBe("0.5");
|
|
732
|
+
});
|
|
733
|
+
});
|
|
734
|
+
|
|
687
735
|
describe("persistElementAttribute — unwind value", () => {
|
|
688
736
|
/**
|
|
689
737
|
* The unwind has to restore the value on DISK, not the one in the preview.
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
findTagByTarget,
|
|
8
8
|
readAttributeByTarget,
|
|
9
9
|
readTagSnippetByTarget,
|
|
10
|
+
servedSource,
|
|
10
11
|
type PatchOperation,
|
|
11
12
|
} from "../utils/sourcePatcher";
|
|
12
13
|
import {
|
|
@@ -420,6 +421,7 @@ export function patchTimelineChangesInSource(
|
|
|
420
421
|
for (const { element, buildPatches } of changes) {
|
|
421
422
|
const target = buildPatchTarget(element);
|
|
422
423
|
if (!target) throw new Error(`Timeline element ${element.id} is missing a patchable target`);
|
|
424
|
+
current = servedSource(current, target);
|
|
423
425
|
// Resolve first: a member already at its target values patches to the same string, a missing one must throw.
|
|
424
426
|
if (!findTagByTarget(current, target)) {
|
|
425
427
|
throw new Error(
|
|
@@ -5,6 +5,8 @@ import { describe, expect, it, vi } from "vitest";
|
|
|
5
5
|
|
|
6
6
|
Object.defineProperty(globalThis, "IS_REACT_ACT_ENVIRONMENT", { configurable: true, value: true });
|
|
7
7
|
import type { TimelineElement } from "../player";
|
|
8
|
+
import { ensureHfIds } from "@hyperframes/parsers/hf-ids";
|
|
9
|
+
import { parseTimelineFromDOM } from "../player/lib/timelineDOM";
|
|
8
10
|
|
|
9
11
|
const saved = vi.hoisted(() => ({ inputs: [] as Array<Record<string, unknown>> }));
|
|
10
12
|
vi.mock("../utils/studioFileHistory", () => ({
|
|
@@ -68,6 +70,50 @@ describe("useSetElementsAttribute", () => {
|
|
|
68
70
|
expect(out).toMatch(/id="b"[^>]*data-volume="2"/);
|
|
69
71
|
});
|
|
70
72
|
|
|
73
|
+
it("saves clips whose file has no ids yet by the ids the preview served them with, and refuses a clip the file lacks", async () => {
|
|
74
|
+
saved.inputs.length = 0;
|
|
75
|
+
// Added outside Studio: no id, no class, and nothing has stamped the file since.
|
|
76
|
+
const onDisk = `<div data-composition-id="main" data-start="0" data-duration="10"><audio src="a.mp3" data-start="0" data-duration="4" data-track-index="0"></audio><audio src="b.mp3" data-start="4" data-duration="4" data-track-index="1"></audio></div>`;
|
|
77
|
+
const doc = document.implementation.createHTMLDocument("");
|
|
78
|
+
doc.body.innerHTML = ensureHfIds(onDisk);
|
|
79
|
+
const served = parseTimelineFromDOM(doc, 10);
|
|
80
|
+
expect(served.map((element) => element.hfId).every(Boolean)).toBe(true);
|
|
81
|
+
let write: ReturnType<typeof useSetElementsAttribute> | null = null;
|
|
82
|
+
function Probe() {
|
|
83
|
+
write = useSetElementsAttribute({
|
|
84
|
+
projectIdRef: { current: "p1" },
|
|
85
|
+
activeCompPath: "index.html",
|
|
86
|
+
showToast: vi.fn(),
|
|
87
|
+
writeProjectFile: vi.fn(async () => {}),
|
|
88
|
+
recordEdit: vi.fn(async () => {}),
|
|
89
|
+
previewIframeRef: { current: null },
|
|
90
|
+
pendingTimelineEditPathRef: { current: new Set<string>() },
|
|
91
|
+
});
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const root = createRoot(document.createElement("div"));
|
|
95
|
+
act(() => root.render(createElement(Probe)));
|
|
96
|
+
await write?.(
|
|
97
|
+
served.map((element) => ({ element, value: "0.3" })),
|
|
98
|
+
"data-volume",
|
|
99
|
+
"Audio Gain",
|
|
100
|
+
);
|
|
101
|
+
await write?.(
|
|
102
|
+
[{ element: { ...served[0]!, hfId: "hf-gone" }, value: "0.3" }],
|
|
103
|
+
"data-volume",
|
|
104
|
+
"Audio Gain",
|
|
105
|
+
);
|
|
106
|
+
act(() => root.unmount());
|
|
107
|
+
const build = (n: number) => {
|
|
108
|
+
const files = saved.inputs[n]?.["files"];
|
|
109
|
+
const fn = typeof files === "object" && files !== null && Reflect.get(files, "index.html");
|
|
110
|
+
if (typeof fn !== "function") throw new Error("no builder for index.html");
|
|
111
|
+
return (html: string) => String(fn(html));
|
|
112
|
+
};
|
|
113
|
+
expect(build(0)(onDisk).match(/data-volume="0\.3"/g)).toHaveLength(2);
|
|
114
|
+
expect(() => build(1)(onDisk)).toThrow("Unable to patch timeline element");
|
|
115
|
+
});
|
|
116
|
+
|
|
71
117
|
it("refuses while recording, like the single-clip write", async () => {
|
|
72
118
|
saved.inputs.length = 0;
|
|
73
119
|
const showToast = vi.fn();
|
|
@@ -4,9 +4,10 @@ import { syncStoredElementAttribute } from "../player/lib/automationStoreSync";
|
|
|
4
4
|
import { saveProjectFilesWithHistory } from "../utils/studioFileHistory";
|
|
5
5
|
import { applyPatchByTarget } from "../utils/sourcePatcher";
|
|
6
6
|
import {
|
|
7
|
-
buildPatchTarget,
|
|
8
7
|
findTimelineElementInIframe,
|
|
8
|
+
patchTimelineChangesInSource,
|
|
9
9
|
readFileContent,
|
|
10
|
+
type PersistTimelineBatchChange,
|
|
10
11
|
} from "./timelineEditingHelpers";
|
|
11
12
|
import type { UseTimelineElementVisibilityEditingInput } from "./timelineTrackVisibility";
|
|
12
13
|
import { projectForTimelineSave, type TimelineEditOutcome } from "./timelineEditPermission";
|
|
@@ -15,18 +16,20 @@ type ElementAttributeEdits = Parameters<
|
|
|
15
16
|
NonNullable<TimelineEditCallbacks["onSetElementsAttributeQuiet"]>
|
|
16
17
|
>[0];
|
|
17
18
|
|
|
18
|
-
type PatchTarget = NonNullable<ReturnType<typeof buildPatchTarget>>;
|
|
19
|
-
|
|
20
19
|
function editsByFile(
|
|
21
20
|
edits: ElementAttributeEdits,
|
|
21
|
+
attr: string,
|
|
22
22
|
activeCompPath: string | null,
|
|
23
|
-
): Map<string,
|
|
24
|
-
const byFile = new Map<string,
|
|
23
|
+
): Map<string, PersistTimelineBatchChange[]> {
|
|
24
|
+
const byFile = new Map<string, PersistTimelineBatchChange[]>();
|
|
25
25
|
for (const { element, value } of edits) {
|
|
26
|
-
const target = buildPatchTarget(element);
|
|
27
|
-
if (!target) throw new Error("A clip has no id to save it by");
|
|
28
26
|
const path = element.sourceFile || activeCompPath || "index.html";
|
|
29
|
-
|
|
27
|
+
const change: PersistTimelineBatchChange = {
|
|
28
|
+
element,
|
|
29
|
+
buildPatches: (html, target) =>
|
|
30
|
+
applyPatchByTarget(html, target, { type: "attribute", property: attr, value }),
|
|
31
|
+
};
|
|
32
|
+
byFile.set(path, [...(byFile.get(path) ?? []), change]);
|
|
30
33
|
}
|
|
31
34
|
return byFile;
|
|
32
35
|
}
|
|
@@ -70,16 +73,11 @@ export function useSetElementsAttribute({
|
|
|
70
73
|
if (typeof projectId !== "string") return projectId;
|
|
71
74
|
if (edits.length === 0) return { status: "saved" };
|
|
72
75
|
try {
|
|
73
|
-
const byFile = editsByFile(edits, activeCompPath);
|
|
76
|
+
const byFile = editsByFile(edits, attr, activeCompPath);
|
|
74
77
|
const files = Object.fromEntries(
|
|
75
|
-
[...byFile].map(([path,
|
|
78
|
+
[...byFile].map(([path, changes]) => [
|
|
76
79
|
path,
|
|
77
|
-
(before: string) =>
|
|
78
|
-
patches.reduce(
|
|
79
|
-
(html, { target, value }) =>
|
|
80
|
-
applyPatchByTarget(html, target, { type: "attribute", property: attr, value }),
|
|
81
|
-
before,
|
|
82
|
-
),
|
|
80
|
+
(before: string) => patchTimelineChangesInSource(before, path, changes),
|
|
83
81
|
]),
|
|
84
82
|
);
|
|
85
83
|
for (const path of byFile.keys()) pendingTimelineEditPathRef.current.add(path);
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
4
|
import { usePlayerStore, type TimelineElement } from "../player";
|
|
5
5
|
import { resolveAudioGroups } from "@hyperframes/core/audio-groups";
|
|
6
|
+
import { ensureHfIds } from "@hyperframes/parsers/hf-ids";
|
|
7
|
+
import { parseTimelineFromDOM } from "../player/lib/timelineDOM";
|
|
6
8
|
import { readTagSnippetByTarget } from "../utils/sourcePatcher";
|
|
7
9
|
import { createAudioGroupAndAssignMembers } from "./timelineAudioGroupCreate";
|
|
8
10
|
import { toggleTimelineElementHidden, toggleTimelineTrackHidden } from "./timelineTrackVisibility";
|
|
@@ -302,6 +304,38 @@ describe("toggleTimelineTrackHidden", () => {
|
|
|
302
304
|
});
|
|
303
305
|
|
|
304
306
|
describe("toggleTimelineElementHidden", () => {
|
|
307
|
+
it("hides a clip whose file has no ids yet, by the id the preview served it with", async () => {
|
|
308
|
+
// A clip added outside Studio: no id, no class, and nothing has stamped the file since.
|
|
309
|
+
const onDisk = `<div data-composition-id="main" data-start="0" data-duration="10"><p data-start="1" data-duration="3" data-track-index="0">Title</p></div>`;
|
|
310
|
+
stubProjectFiles(new Map([["index.html", onDisk]]));
|
|
311
|
+
const iframe = document.createElement("iframe");
|
|
312
|
+
document.body.append(iframe);
|
|
313
|
+
const doc = iframe.contentDocument;
|
|
314
|
+
if (!doc) throw new Error("expected iframe document");
|
|
315
|
+
doc.body.innerHTML = ensureHfIds(onDisk);
|
|
316
|
+
const [clip] = parseTimelineFromDOM(doc, 10);
|
|
317
|
+
if (!clip?.hfId) throw new Error("expected the served clip to carry an hf-id");
|
|
318
|
+
const writes = new Map<string, string>();
|
|
319
|
+
|
|
320
|
+
await toggleTimelineElementHidden({
|
|
321
|
+
projectId: "project-1",
|
|
322
|
+
activeCompPath: "index.html",
|
|
323
|
+
timelineElements: [clip],
|
|
324
|
+
elementKey: clip.key ?? clip.id,
|
|
325
|
+
hidden: true,
|
|
326
|
+
previewIframe: iframe,
|
|
327
|
+
writeProjectFile: async (path, content) => {
|
|
328
|
+
writes.set(path, content);
|
|
329
|
+
},
|
|
330
|
+
recordEdit: vi.fn(),
|
|
331
|
+
pendingTimelineEditPathRef: { current: new Set() },
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
expect(readTagSnippetByTarget(writes.get("index.html") ?? "", { hfId: clip.hfId })).toContain(
|
|
335
|
+
'data-hidden=""',
|
|
336
|
+
);
|
|
337
|
+
});
|
|
338
|
+
|
|
305
339
|
it("persists data-hidden for only the selected element and updates the player store", async () => {
|
|
306
340
|
const iframe = document.createElement("iframe");
|
|
307
341
|
document.body.append(iframe);
|
|
@@ -8,10 +8,11 @@ import { useElementPicker } from "./useElementPicker";
|
|
|
8
8
|
import { serveEditingRequests } from "../player/hooks/timelinePlayerTestHarness";
|
|
9
9
|
|
|
10
10
|
// As the host leaves it on disk: hf-ids pinned, no element ids.
|
|
11
|
-
const
|
|
11
|
+
const UNSTAMPED = `<!doctype html><html><body>
|
|
12
12
|
<div data-composition-id="main" data-start="0" data-duration="10">
|
|
13
13
|
<h1 class="clip" data-start="2" data-duration="3" data-track-index="0">Title</h1>
|
|
14
|
-
</div></body></html
|
|
14
|
+
</div></body></html>`;
|
|
15
|
+
const SAVED = ensureHfIds(UNSTAMPED);
|
|
15
16
|
|
|
16
17
|
let root: Root | null = null;
|
|
17
18
|
afterEach(() => {
|
|
@@ -354,6 +355,12 @@ describe("an edit to a picked element without an id", () => {
|
|
|
354
355
|
);
|
|
355
356
|
});
|
|
356
357
|
|
|
358
|
+
it("writes the edit into a file nothing has stamped yet, by the id the preview served", () => {
|
|
359
|
+
const { picker, synced } = mountPicker({ "index.html": UNSTAMPED });
|
|
360
|
+
act(() => picker().setStyle("color", "red"));
|
|
361
|
+
expect(synced[0]?.["index.html"]).toMatch(/<h1 [^>]*style="color: red"[^>]*>Title<\/h1>/);
|
|
362
|
+
});
|
|
363
|
+
|
|
357
364
|
it("writes nothing when no saved file holds the element", () => {
|
|
358
365
|
const { picker, synced } = mountPicker({ "index.html": "<div>other</div>" });
|
|
359
366
|
act(() => picker().setStyle("color", "red"));
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
resolveSourceFile,
|
|
5
5
|
applyPatch,
|
|
6
6
|
applyPatchByTarget,
|
|
7
|
-
|
|
7
|
+
readTagSnippetByTarget,
|
|
8
8
|
type PatchOperation,
|
|
9
9
|
} from "../utils/sourcePatcher";
|
|
10
10
|
import {
|
|
@@ -554,7 +554,9 @@ function patchByHfId(
|
|
|
554
554
|
ownFile: string,
|
|
555
555
|
op: PatchOperation,
|
|
556
556
|
): SourcePatch | null {
|
|
557
|
-
const matches = Object.keys(files).filter(
|
|
557
|
+
const matches = Object.keys(files).filter(
|
|
558
|
+
(file) => readTagSnippetByTarget(files[file] ?? "", { hfId }) !== undefined,
|
|
559
|
+
);
|
|
558
560
|
const path = matches.includes(ownFile) ? ownFile : matches.length === 1 ? matches[0] : undefined;
|
|
559
561
|
const before = path ? files[path] : undefined;
|
|
560
562
|
return path && before ? { path, before, after: applyPatchByTarget(before, { hfId }, op) } : null;
|
package/src/hooks/useToast.ts
CHANGED
|
@@ -4,19 +4,18 @@ import type { AppToast } from "../utils/studioHelpers";
|
|
|
4
4
|
|
|
5
5
|
interface ToastItem extends AppToast {
|
|
6
6
|
id: number;
|
|
7
|
-
/** True while the exit animation plays, just before removal. */
|
|
8
|
-
leaving?: boolean;
|
|
9
7
|
}
|
|
10
8
|
|
|
11
9
|
const AUTO_DISMISS_MS = 4000;
|
|
12
|
-
const EXIT_MS = 160;
|
|
13
10
|
const MAX_TOASTS = 3;
|
|
14
11
|
|
|
12
|
+
/** Error toasts persist until dismissed so failures can't silently vanish. */
|
|
13
|
+
export const toastPersists = (tone: AppToast["tone"]) => tone === "error";
|
|
14
|
+
|
|
15
15
|
let nextToastId = 1;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Stacked toasts (max 3). Info toasts auto-dismiss after 4s; error toasts
|
|
19
|
-
* persist until explicitly dismissed so failures can't silently vanish.
|
|
18
|
+
* Stacked toasts (max 3). Info toasts auto-dismiss after 4s; error toasts persist.
|
|
20
19
|
*/
|
|
21
20
|
export function useToast() {
|
|
22
21
|
const [toasts, setToasts] = useState<ToastItem[]>([]);
|
|
@@ -30,7 +29,7 @@ export function useToast() {
|
|
|
30
29
|
}
|
|
31
30
|
}, []);
|
|
32
31
|
|
|
33
|
-
const
|
|
32
|
+
const dismissToast = useCallback(
|
|
34
33
|
(id: number) => {
|
|
35
34
|
clearTimer(id);
|
|
36
35
|
setToasts((prev) => prev.filter((t) => t.id !== id));
|
|
@@ -38,17 +37,6 @@ export function useToast() {
|
|
|
38
37
|
[clearTimer],
|
|
39
38
|
);
|
|
40
39
|
|
|
41
|
-
const dismissToast = useCallback(
|
|
42
|
-
(id: number) => {
|
|
43
|
-
clearTimer(id);
|
|
44
|
-
// Mark leaving so the exit animation plays, then remove.
|
|
45
|
-
setToasts((prev) => prev.map((t) => (t.id === id ? { ...t, leaving: true } : t)));
|
|
46
|
-
const timer = setTimeout(() => removeToast(id), EXIT_MS);
|
|
47
|
-
timersRef.current.set(id, timer);
|
|
48
|
-
},
|
|
49
|
-
[clearTimer, removeToast],
|
|
50
|
-
);
|
|
51
|
-
|
|
52
40
|
const showToast = useCallback(
|
|
53
41
|
(message: string, tone: AppToast["tone"] = "error"): number => {
|
|
54
42
|
const id = nextToastId++;
|
|
@@ -61,7 +49,7 @@ export function useToast() {
|
|
|
61
49
|
}
|
|
62
50
|
return next;
|
|
63
51
|
});
|
|
64
|
-
if (tone
|
|
52
|
+
if (!toastPersists(tone)) {
|
|
65
53
|
const timer = setTimeout(() => dismissToast(id), AUTO_DISMISS_MS);
|
|
66
54
|
timersRef.current.set(id, timer);
|
|
67
55
|
}
|
|
@@ -8,9 +8,11 @@ import {
|
|
|
8
8
|
MAX_ELEMENT_ENTRIES,
|
|
9
9
|
MAX_ELEMENT_VALUE,
|
|
10
10
|
MAX_GEOMETRY_CHILDREN,
|
|
11
|
+
MAX_SNAP_TARGETS,
|
|
11
12
|
type EditingElementBox,
|
|
12
13
|
type EditingElementDescription,
|
|
13
14
|
type EditingElementGeometry,
|
|
15
|
+
type EditingGestureStart,
|
|
14
16
|
type EditingElementHit,
|
|
15
17
|
type EditingElementMatch,
|
|
16
18
|
type EditingElementSource,
|
|
@@ -226,6 +228,41 @@ export async function previewGeometry(
|
|
|
226
228
|
};
|
|
227
229
|
}
|
|
228
230
|
|
|
231
|
+
const isFlag = (value: unknown) => typeof value === "boolean";
|
|
232
|
+
const isFiniteFields = (value: unknown, keys: string[]) =>
|
|
233
|
+
isFields(value) && keys.every((key) => Number.isFinite(value[key]));
|
|
234
|
+
|
|
235
|
+
const readGestureStart = (value: unknown): EditingGestureStart | null => {
|
|
236
|
+
if (!readGeometry(value) || !isFields(value)) return null;
|
|
237
|
+
const { layout, move, gsap } = value;
|
|
238
|
+
const valid = [
|
|
239
|
+
isFiniteFields(layout, ["width", "height"]),
|
|
240
|
+
move === null || isFiniteFields(move, ["a", "b", "c", "d"]),
|
|
241
|
+
gsap === null || (isFields(gsap) && isFiniteFields(gsap, ["x", "y"]) && isFlag(gsap.moving)),
|
|
242
|
+
];
|
|
243
|
+
return valid.includes(false) ? null : (value as unknown as EditingGestureStart);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export interface PreviewGestureStartReply {
|
|
247
|
+
/** One entry per handle, in order: null for an element the frame no longer has. */
|
|
248
|
+
elements: Array<EditingGestureStart | null>;
|
|
249
|
+
snap: EditingElementBox[];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** What a gesture on `handles` starts from, in one read; null when the runtime cannot answer. */
|
|
253
|
+
export async function previewGestureStart(
|
|
254
|
+
iframe: HTMLIFrameElement,
|
|
255
|
+
handles: readonly string[],
|
|
256
|
+
): Promise<PreviewGestureStartReply | null> {
|
|
257
|
+
if (!handles.length || handles.length > MAX_DESCRIBE_HANDLES) return null;
|
|
258
|
+
const reply = await previewRequest(iframe, "gesture-start", { handles: [...handles] });
|
|
259
|
+
const elements: unknown = reply?.elements;
|
|
260
|
+
const snap: unknown = reply?.snap;
|
|
261
|
+
if (!Array.isArray(elements) || elements.length !== handles.length) return null;
|
|
262
|
+
if (!Array.isArray(snap) || snap.length > MAX_SNAP_TARGETS || !snap.every(isBox)) return null;
|
|
263
|
+
return { elements: elements.map(readGestureStart), snap };
|
|
264
|
+
}
|
|
265
|
+
|
|
229
266
|
const LAYER_KINDS = new Set(["image", "video", "audio", "vector", "group", "text", "shape"]);
|
|
230
267
|
const isLayer = (value: unknown): value is EditingLayer =>
|
|
231
268
|
isFields(value) &&
|