@hyperframes/studio 0.8.15 → 0.8.17

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.
Files changed (62) hide show
  1. package/dist/assets/hyperframes-player-DejBDgXB.js +459 -0
  2. package/dist/assets/index-BX3KHhGX.js +71 -0
  3. package/dist/assets/{index-DKoZIpw1.js → index-CU6o8PuW.js} +180 -180
  4. package/dist/assets/{index-CVtYYTnA.js → index-CklNVmi3.js} +1 -1
  5. package/dist/assets/{index-CtDg2lB7.js → index-uu4Zd3BU.js} +1 -1
  6. package/dist/index.d.ts +9 -13
  7. package/dist/index.html +1 -1
  8. package/dist/index.js +1660 -1284
  9. package/dist/index.js.map +1 -1
  10. package/package.json +8 -7
  11. package/src/components/EditorShell.tsx +4 -0
  12. package/src/components/editor/DomEditCropHandles.test.tsx +1 -1
  13. package/src/components/editor/DomEditCropHandles.tsx +1 -1
  14. package/src/components/editor/DomEditOverlay.tsx +1 -1
  15. package/src/components/editor/DomEditSelectionChrome.tsx +1 -1
  16. package/src/components/editor/anchoredResizeCommitFeedsOffset.test.ts +38 -4
  17. package/src/components/editor/propertyPanelCommitField.tsx +1 -1
  18. package/src/components/editor/propertyPanelFlatLayoutSection.tsx +3 -3
  19. package/src/components/editor/propertyPanelFlatMaskInsetRows.tsx +1 -1
  20. package/src/components/editor/propertyPanelFlatMediaSection.tsx +1 -1
  21. package/src/components/editor/propertyPanelFlatPrimitives.tsx +1 -1
  22. package/src/components/editor/propertyPanelFlatStyleSections.tsx +8 -8
  23. package/src/components/editor/propertyPanelMediaSection.tsx +1 -1
  24. package/src/components/editor/propertyPanelPrimitives.tsx +1 -1
  25. package/src/components/editor/propertyPanelStyleSections.tsx +1 -1
  26. package/src/components/editor/propertyPanelTypes.ts +1 -1
  27. package/src/components/editor/useDomEditOverlayGestures.ts +8 -2
  28. package/src/components/editor/useInspectorGestureTransaction.ts +3 -3
  29. package/src/components/sidebar/AudioRow.tsx +13 -2
  30. package/src/hooks/domEditCommitRunner.ts +47 -0
  31. package/src/hooks/useDomEditPositionPatchCommit.test.tsx +116 -0
  32. package/src/hooks/useDomEditPositionPatchCommit.ts +6 -1
  33. package/src/hooks/useDomEditTextCommits.test.tsx +175 -21
  34. package/src/hooks/useDomEditTextCommits.ts +17 -9
  35. package/src/hooks/useDomEditWiring.ts +1 -1
  36. package/src/hooks/useDomGeometryCommits.test.tsx +1 -0
  37. package/src/hooks/useDomGeometryCommits.ts +10 -2
  38. package/src/hooks/useDomSelection.test.ts +48 -0
  39. package/src/hooks/useDomSelection.ts +26 -82
  40. package/src/hooks/useDomSelectionTypes.ts +82 -0
  41. package/src/hooks/useElementLifecycleOps.multiDelete.test.tsx +81 -31
  42. package/src/hooks/useElementLifecycleOps.ts +11 -5
  43. package/src/hooks/useGsapSelectionHandlers.ts +4 -2
  44. package/src/hooks/usePanelLayout.test.ts +38 -0
  45. package/src/hooks/usePanelLayout.ts +21 -6
  46. package/src/player/lib/playbackTypes.ts +3 -12
  47. package/src/player/lib/runtimeProtocol.test.ts +1 -0
  48. package/src/utils/studioUiPreferences.ts +11 -0
  49. package/src/webmcp/StudioAgentTools.tsx +46 -0
  50. package/src/webmcp/handles.test.ts +130 -0
  51. package/src/webmcp/handles.ts +129 -0
  52. package/src/webmcp/polyfill.test.ts +98 -0
  53. package/src/webmcp/polyfill.ts +60 -0
  54. package/src/webmcp/registrar.test.ts +150 -0
  55. package/src/webmcp/registrar.ts +115 -0
  56. package/src/webmcp/toolResult.ts +67 -0
  57. package/src/webmcp/tools/lookTools.test.ts +225 -0
  58. package/src/webmcp/tools/lookTools.ts +201 -0
  59. package/src/webmcp/types.ts +90 -0
  60. package/src/webmcp/useStudioAgentTools.test.tsx +221 -0
  61. package/src/webmcp/useStudioAgentTools.ts +119 -0
  62. package/dist/assets/hyperframes-player-BlIp1Y-b.js +0 -459
@@ -66,6 +66,42 @@ function selectionFor(element: HTMLElement): DomEditSelection {
66
66
  };
67
67
  }
68
68
 
69
+ /** A preview element inside a real iframe, which is where Studio's chrome expects to find it. */
70
+ function previewElement(
71
+ html: string,
72
+ id: string,
73
+ ): { iframe: HTMLIFrameElement; element: HTMLElement } {
74
+ const iframe = document.createElement("iframe");
75
+ document.body.append(iframe);
76
+ const doc = iframe.contentDocument;
77
+ if (!doc) throw new Error("expected iframe document");
78
+ doc.body.innerHTML = html;
79
+ const element = doc.getElementById(id);
80
+ const HTMLElementCtor = doc.defaultView?.HTMLElement;
81
+ if (!HTMLElementCtor || !(element instanceof HTMLElementCtor)) {
82
+ throw new Error("expected preview element");
83
+ }
84
+ return { iframe, element };
85
+ }
86
+
87
+ /** Hook params with nothing selected and a writer that succeeds; override what the test is about. */
88
+ function commitParams(
89
+ overrides: Partial<UseDomEditTextCommitsParams> = {},
90
+ ): UseDomEditTextCommitsParams {
91
+ return {
92
+ activeCompPath: "index.html",
93
+ previewIframeRef: { current: null },
94
+ showToast: vi.fn(),
95
+ domEditSelection: null,
96
+ applyDomSelection: vi.fn(),
97
+ refreshDomEditSelectionFromPreview: vi.fn(),
98
+ buildDomSelectionFromTarget: vi.fn(async () => null),
99
+ persistDomEditOperations: vi.fn().mockResolvedValue(undefined),
100
+ resolveImportedFontAsset: () => null,
101
+ ...overrides,
102
+ };
103
+ }
104
+
69
105
  let cleanup: (() => void) | null = null;
70
106
 
71
107
  function renderTextCommitHook(params: UseDomEditTextCommitsParams) {
@@ -89,16 +125,7 @@ afterEach(() => {
89
125
 
90
126
  describe("useDomEditTextCommits", () => {
91
127
  it("does not let a stale failed fields commit revert newer text", async () => {
92
- const iframe = document.createElement("iframe");
93
- document.body.append(iframe);
94
- const doc = iframe.contentDocument;
95
- if (!doc) throw new Error("expected iframe document");
96
- doc.body.innerHTML = '<div id="card">Original</div>';
97
- const element = doc.getElementById("card");
98
- const HTMLElementCtor = doc.defaultView?.HTMLElement;
99
- if (!HTMLElementCtor || !(element instanceof HTMLElementCtor)) {
100
- throw new Error("expected preview element");
101
- }
128
+ const { iframe, element } = previewElement("<div id='card'>Original</div>", "card");
102
129
  vi.spyOn(console, "warn").mockImplementation(() => {});
103
130
  const selection = selectionFor(element);
104
131
  const stalePersist = createDeferred<void>();
@@ -106,17 +133,13 @@ describe("useDomEditTextCommits", () => {
106
133
  .fn()
107
134
  .mockImplementationOnce(() => stalePersist.promise)
108
135
  .mockResolvedValueOnce(undefined);
109
- const hook = renderTextCommitHook({
110
- activeCompPath: "index.html",
111
- previewIframeRef: { current: iframe },
112
- showToast: vi.fn(),
113
- domEditSelection: selection,
114
- applyDomSelection: vi.fn(),
115
- refreshDomEditSelectionFromPreview: vi.fn(),
116
- buildDomSelectionFromTarget: vi.fn(async () => null),
117
- persistDomEditOperations,
118
- resolveImportedFontAsset: () => null,
119
- });
136
+ const hook = renderTextCommitHook(
137
+ commitParams({
138
+ previewIframeRef: { current: iframe },
139
+ domEditSelection: selection,
140
+ persistDomEditOperations,
141
+ }),
142
+ );
120
143
 
121
144
  let staleCommit: Promise<void> | undefined;
122
145
  act(() => {
@@ -132,4 +155,135 @@ describe("useDomEditTextCommits", () => {
132
155
 
133
156
  expect(element.innerHTML).toBe("Newest");
134
157
  });
158
+
159
+ it("reports persist failure from a style commit instead of resolving silently", async () => {
160
+ const { iframe, element } = previewElement("<div id='card'>Original</div>", "card");
161
+ const selection = selectionFor(element);
162
+ const showToast = vi.fn();
163
+ const hook = renderTextCommitHook(
164
+ commitParams({
165
+ previewIframeRef: { current: iframe },
166
+ showToast,
167
+ domEditSelection: selection,
168
+ persistDomEditOperations: vi.fn().mockRejectedValue(new Error("server said no")),
169
+ }),
170
+ );
171
+
172
+ let outcome: unknown;
173
+ await act(async () => {
174
+ outcome = await hook.handleDomStyleCommit("color", "red");
175
+ });
176
+
177
+ expect(outcome).toEqual({ ok: false, reason: "persist-failed" });
178
+ // The human-facing behaviour must be unchanged: still toasts, still reverts.
179
+ expect(showToast).toHaveBeenCalled();
180
+ expect(element.style.getPropertyValue("color")).toBe("");
181
+ });
182
+
183
+ it("reports a successful style commit", async () => {
184
+ const { iframe, element } = previewElement("<div id='card'>Original</div>", "card");
185
+ const selection = selectionFor(element);
186
+ const hook = renderTextCommitHook(
187
+ commitParams({ previewIframeRef: { current: iframe }, domEditSelection: selection }),
188
+ );
189
+
190
+ let outcome: unknown;
191
+ await act(async () => {
192
+ outcome = await hook.handleDomStyleCommit("color", "red");
193
+ });
194
+
195
+ expect(outcome).toEqual({ ok: true });
196
+ });
197
+
198
+ it("declines a style commit with no selection, without reaching the writer", async () => {
199
+ const persistDomEditOperations = vi.fn().mockResolvedValue(undefined);
200
+ const hook = renderTextCommitHook(
201
+ commitParams({
202
+ domEditSelection: null,
203
+ persistDomEditOperations,
204
+ }),
205
+ );
206
+
207
+ let outcome: unknown;
208
+ await act(async () => {
209
+ outcome = await hook.handleDomStyleCommit("color", "red");
210
+ });
211
+
212
+ expect(outcome).toEqual({ ok: false, reason: "no-selection" });
213
+ expect(persistDomEditOperations).not.toHaveBeenCalled();
214
+ });
215
+
216
+ it("declines a style commit for a manual-geometry property", async () => {
217
+ const persistDomEditOperations = vi.fn().mockResolvedValue(undefined);
218
+ const { element } = previewElement("<div id='card'>Original</div>", "card");
219
+ const hook = renderTextCommitHook(
220
+ commitParams({
221
+ domEditSelection: selectionFor(element),
222
+ persistDomEditOperations,
223
+ }),
224
+ );
225
+
226
+ let outcome: unknown;
227
+ await act(async () => {
228
+ // `left` is a manual-geometry property the style path deliberately refuses.
229
+ outcome = await hook.handleDomStyleCommit("left", "10px");
230
+ });
231
+
232
+ expect(outcome).toEqual({ ok: false, reason: "geometry-property" });
233
+ expect(persistDomEditOperations).not.toHaveBeenCalled();
234
+ });
235
+
236
+ it("declines a style commit when the selection cannot edit styles", async () => {
237
+ const persistDomEditOperations = vi.fn().mockResolvedValue(undefined);
238
+ const { element } = previewElement("<div id='card'>Original</div>", "card");
239
+ const locked = selectionFor(element);
240
+ locked.capabilities = { ...locked.capabilities, canEditStyles: false };
241
+ const hook = renderTextCommitHook(
242
+ commitParams({
243
+ domEditSelection: locked,
244
+ persistDomEditOperations,
245
+ }),
246
+ );
247
+
248
+ let outcome: unknown;
249
+ await act(async () => {
250
+ outcome = await hook.handleDomStyleCommit("color", "red");
251
+ });
252
+
253
+ expect(outcome).toEqual({ ok: false, reason: "styles-not-editable" });
254
+ expect(persistDomEditOperations).not.toHaveBeenCalled();
255
+ });
256
+
257
+ it("reports persist failure from a text commit instead of resolving silently", async () => {
258
+ const { iframe, element } = previewElement("<div id='card'>Original</div>", "card");
259
+ const selection = selectionFor(element);
260
+ const hook = renderTextCommitHook(
261
+ commitParams({
262
+ previewIframeRef: { current: iframe },
263
+ domEditSelection: selection,
264
+ persistDomEditOperations: vi.fn().mockRejectedValue(new Error("server said no")),
265
+ }),
266
+ );
267
+
268
+ let outcome: unknown;
269
+ await act(async () => {
270
+ outcome = await hook.handleDomTextCommit("Updated");
271
+ });
272
+
273
+ expect(outcome).toEqual({ ok: false, reason: "persist-failed" });
274
+ expect(element.innerHTML).toBe("Original");
275
+ });
276
+
277
+ it("reports a text commit declined for an unselected target", async () => {
278
+ const persistDomEditOperations = vi.fn().mockResolvedValue(undefined);
279
+ const hook = renderTextCommitHook(commitParams({ persistDomEditOperations }));
280
+
281
+ let outcome: unknown;
282
+ await act(async () => {
283
+ outcome = await hook.handleDomTextCommit("Updated");
284
+ });
285
+
286
+ expect(outcome).toEqual({ ok: false, reason: "no-selection" });
287
+ expect(persistDomEditOperations).not.toHaveBeenCalled();
288
+ });
135
289
  });
@@ -30,7 +30,10 @@ import { reportDomEditPersistFailure } from "./domEditPersistFailure";
30
30
  import {
31
31
  bumpDomEditCommitMapVersion,
32
32
  bumpDomEditCommitVersion,
33
+ domEditCommitDeclined,
33
34
  runDomEditCommit,
35
+ runReportedDomEditCommit,
36
+ type DomEditCommitOutcome,
34
37
  } from "./domEditCommitRunner";
35
38
  import { useDomEditAttributeCommits } from "./useDomEditAttributeCommits";
36
39
  import type { InlineTextEditCommit } from "./useInlineTextEdit";
@@ -186,10 +189,13 @@ export function useDomEditTextCommits({
186
189
  });
187
190
 
188
191
  const handleDomStyleCommit = useCallback(
189
- async (property: string, value: string) => {
190
- if (!domEditSelection) return;
191
- if (isManualGeometryStyleProperty(property)) return;
192
- if (!domEditSelection.capabilities.canEditStyles) return;
192
+ async (property: string, value: string): Promise<DomEditCommitOutcome> => {
193
+ if (!domEditSelection) return domEditCommitDeclined("no-selection");
194
+ if (isManualGeometryStyleProperty(property))
195
+ return domEditCommitDeclined("geometry-property");
196
+ if (!domEditSelection.capabilities.canEditStyles) {
197
+ return domEditCommitDeclined("styles-not-editable");
198
+ }
193
199
  const styleCommitKey = `${getDomEditTargetKey(domEditSelection)}:${property}`;
194
200
  const isLatestStyleCommit = bumpDomEditCommitMapVersion(
195
201
  domStyleCommitVersionRef.current,
@@ -210,7 +216,7 @@ export function useDomEditTextCommits({
210
216
  // element in-browser immediately, so a reload would only cost a black blink.
211
217
  const skipRefresh = true;
212
218
 
213
- await runDomEditCommit({
219
+ return runReportedDomEditCommit({
214
220
  capture: () => {
215
221
  if (!doc) return;
216
222
  const el = findElementForSelection(doc, domEditSelection, activeCompPath);
@@ -267,9 +273,11 @@ export function useDomEditTextCommits({
267
273
  );
268
274
 
269
275
  const handleDomTextCommit = useCallback(
270
- async (value: string, fieldKey?: string) => {
271
- if (!domEditSelection) return;
272
- if (!isTextEditableSelection(domEditSelection)) return;
276
+ async (value: string, fieldKey?: string): Promise<DomEditCommitOutcome> => {
277
+ if (!domEditSelection) return domEditCommitDeclined("no-selection");
278
+ if (!isTextEditableSelection(domEditSelection)) {
279
+ return domEditCommitDeclined("not-text-editable");
280
+ }
273
281
  const isLatestTextCommit = bumpDomEditCommitVersion(domTextCommitVersionRef);
274
282
  const nextTextFields = buildNextDomTextFields(domEditSelection.textFields, value, fieldKey);
275
283
  const textCommit = planDomTextCommit(domEditSelection.textFields, nextTextFields, value);
@@ -278,7 +286,7 @@ export function useDomEditTextCommits({
278
286
  let editedElement: HTMLElement | null = null;
279
287
  let previousInnerHtml: string | null = null;
280
288
 
281
- await runDomEditCommit({
289
+ return runReportedDomEditCommit({
282
290
  capture: () => {
283
291
  if (!doc) return;
284
292
  const el = findElementForSelection(doc, domEditSelection, activeCompPath);
@@ -107,7 +107,7 @@ export interface UseDomEditWiringParams {
107
107
  resolvedFromValues?: Record<string, number | string>,
108
108
  ) => Promise<void>;
109
109
  removeAllKeyframes: (sel: DomEditSelection, animId: string) => Promise<void>;
110
- handleDomManualEditsReset: (sel: DomEditSelection) => void;
110
+ handleDomManualEditsReset: (sel: DomEditSelection) => Promise<void>;
111
111
  }
112
112
 
113
113
  // fallow-ignore-next-line complexity
@@ -52,6 +52,7 @@ describe("useDomGeometryCommits rollback", () => {
52
52
  commits!.handleDomBoxSizeCommit(selection, { width: 200, height: 160 }, { x: 30, y: 40 }),
53
53
  ).rejects.toBe(failure);
54
54
  await expect(commits!.handleDomRotationCommit(selection, { angle: 45 })).rejects.toBe(failure);
55
+ await expect(commits!.handleDomManualEditsReset(selection)).rejects.toBe(failure);
55
56
 
56
57
  expect(readStudioPathOffset(element)).toEqual({ x: 10, y: 20 });
57
58
  expect(readStudioBoxSize(element)).toEqual({ width: 100, height: 80 });
@@ -130,6 +130,9 @@ export function useDomGeometryCommits({
130
130
  const handleDomManualEditsReset = useCallback(
131
131
  (selection: DomEditSelection) => {
132
132
  const element = selection.element;
133
+ const beforeOffset = captureStudioPathOffset(element);
134
+ const beforeSize = captureStudioBoxSize(element);
135
+ const beforeRotation = captureStudioRotation(element);
133
136
  const clearPatches = [
134
137
  ...buildClearPathOffsetPatches(element),
135
138
  ...buildClearBoxSizePatches(element),
@@ -139,11 +142,16 @@ export function useDomGeometryCommits({
139
142
  clearStudioBoxSize(element);
140
143
  clearStudioRotation(element);
141
144
  // skipRefresh:false triggers reloadPreview() which re-syncs selection on load
142
- void commitPositionPatchToHtml(selection, clearPatches, {
145
+ return commitPositionPatchToHtml(selection, clearPatches, {
143
146
  label: "Reset layer edits",
144
147
  coalesceKey: `manual-reset:${getDomEditTargetKey(selection)}`,
145
148
  skipRefresh: false,
146
- }).catch(() => undefined);
149
+ }).catch((error) => {
150
+ restoreStudioPathOffset(element, beforeOffset);
151
+ restoreStudioBoxSize(element, beforeSize);
152
+ restoreStudioRotation(element, beforeRotation);
153
+ throw error;
154
+ });
147
155
  },
148
156
  [commitPositionPatchToHtml],
149
157
  );
@@ -208,6 +208,54 @@ describe("useDomSelection additive", () => {
208
208
  });
209
209
 
210
210
  describe("useDomSelection", () => {
211
+ it("ignores a repeated non-additive selection of the same target", () => {
212
+ const element = document.createElement("div");
213
+ element.id = "headline";
214
+ const first = makeSelection("Headline", element);
215
+ const repeated = makeSelection("Headline", element);
216
+ const harness = renderHarness({
217
+ activeCompPath: "intro.html",
218
+ projectId: "project-1",
219
+ refreshKey: 0,
220
+ });
221
+
222
+ act(() => harness.current().applyDomSelection(first));
223
+ harness.timeline.setSelectedTimelineElementId.mockClear();
224
+ harness.timeline.setTimelineSelectionSet.mockClear();
225
+
226
+ act(() => harness.current().applyDomSelection(repeated));
227
+
228
+ expect(harness.current().domEditSelection).toBe(first);
229
+ expect(harness.current().domEditGroupSelections).toEqual([first]);
230
+ expect(harness.timeline.setSelectedTimelineElementId).not.toHaveBeenCalled();
231
+ expect(harness.timeline.setTimelineSelectionSet).not.toHaveBeenCalled();
232
+ harness.cleanup();
233
+ });
234
+
235
+ it("still refreshes selection data for the same target when preserving the group", () => {
236
+ const element = document.createElement("div");
237
+ element.id = "headline";
238
+ const first = makeSelection("Headline", element);
239
+ const refreshed = makeSelection("Updated headline", element);
240
+ const harness = renderHarness({
241
+ activeCompPath: "intro.html",
242
+ projectId: "project-1",
243
+ refreshKey: 0,
244
+ });
245
+
246
+ act(() => harness.current().applyDomSelection(first));
247
+ act(() =>
248
+ harness.current().applyDomSelection(refreshed, {
249
+ preserveGroup: true,
250
+ revealPanel: false,
251
+ }),
252
+ );
253
+
254
+ expect(harness.current().domEditSelection).toBe(refreshed);
255
+ expect(harness.current().domEditGroupSelections).toEqual([refreshed]);
256
+ harness.cleanup();
257
+ });
258
+
211
259
  it("clears a committed selection when the active composition path changes", () => {
212
260
  const { selection, harness } = setupSelectedHarness();
213
261
  expect(harness.current().domEditSelection).toBe(selection);
@@ -1,10 +1,9 @@
1
1
  import { useState, useCallback, useRef, useEffect } from "react";
2
- import type { SelectElementOptions, TimelineElement } from "../player";
2
+ import type { TimelineElement } from "../player";
3
3
  import {
4
4
  getAllPreviewTargetsFromPointer,
5
5
  getPreviewTargetFromPointer,
6
6
  } from "../utils/studioPreviewHelpers";
7
- import { type RightPanelTab } from "../utils/studioHelpers";
8
7
  import {
9
8
  domEditSelectionsTargetSame,
10
9
  domEditSelectionInGroup,
@@ -22,86 +21,18 @@ import { reapplyPositionEditsAfterSeek } from "../components/editor/manualEdits"
22
21
  import { useStudioTestHooks } from "./useStudioTestHooks";
23
22
  import { logSelect } from "../utils/selectDebug";
24
23
  import { announceTimelineSelection as announceSelectionToTimeline } from "./domSelectionTimelineMirror";
25
-
26
- // ── Types ──
27
-
28
- export interface ApplyDomSelectionOptions {
29
- revealPanel?: boolean;
30
- additive?: boolean;
31
- preserveGroup?: boolean;
32
- // A clear that came FROM the timeline must not be echoed back, or picking a
33
- // clip with no canvas node would deselect the clip you just picked.
34
- announce?: boolean;
35
- }
36
-
37
- export interface ResolveDomSelectionOptions {
38
- preferClipAncestor?: boolean;
39
- skipSourceProbe?: boolean;
40
- activeGroupElement?: HTMLElement | null;
41
- }
42
-
43
- export interface UseDomSelectionParams {
44
- projectId: string | null;
45
- activeCompPath: string | null;
46
- isMasterView: boolean;
47
- compIdToSrc: Map<string, string>;
48
- captionEditMode: boolean;
49
- previewIframeRef: React.MutableRefObject<HTMLIFrameElement | null>;
50
- timelineElements: TimelineElement[];
51
- getTimelineSelectionSet: () => ReadonlySet<string>;
52
- setSelectedTimelineElementId: (id: string | null, options?: SelectElementOptions) => void;
53
- /** Publishes a whole multi-selection to the timeline; the anchor is set separately. */
54
- setTimelineSelectionSet: (ids: Set<string>) => void;
55
- setRightCollapsed: (collapsed: boolean) => void;
56
- setRightPanelTab: (tab: RightPanelTab) => void;
57
- previewIframe: HTMLIFrameElement | null;
58
- refreshKey: number;
59
- rightPanelTab: RightPanelTab;
60
- }
61
-
62
- export interface UseDomSelectionReturn {
63
- // State
64
- domEditSelection: DomEditSelection | null;
65
- domEditGroupSelections: DomEditSelection[];
66
- domEditHoverSelection: DomEditSelection | null;
67
- activeGroupElement: HTMLElement | null;
68
- // Refs
69
- domEditSelectionRef: React.MutableRefObject<DomEditSelection | null>;
70
- domEditGroupSelectionsRef: React.MutableRefObject<DomEditSelection[]>;
71
- domEditHoverSelectionRef: React.MutableRefObject<DomEditSelection | null>;
72
- activeGroupElementRef: React.MutableRefObject<HTMLElement | null>;
73
- // State setters (needed by useDomEditSession for agent-prompt reset flows)
74
- setDomEditSelection: React.Dispatch<React.SetStateAction<DomEditSelection | null>>;
75
- setDomEditGroupSelections: React.Dispatch<React.SetStateAction<DomEditSelection[]>>;
76
- setActiveGroupElement: (el: HTMLElement | null) => void;
77
- // Callbacks
78
- applyDomSelection: (
79
- selection: DomEditSelection | null,
80
- options?: ApplyDomSelectionOptions,
81
- ) => void;
82
- clearDomSelection: () => void;
83
- buildDomSelectionFromTarget: (
84
- target: HTMLElement,
85
- options?: ResolveDomSelectionOptions,
86
- ) => Promise<DomEditSelection | null>;
87
- resolveDomSelectionFromPreviewPoint: (
88
- clientX: number,
89
- clientY: number,
90
- options?: ResolveDomSelectionOptions,
91
- ) => Promise<DomEditSelection | null>;
92
- resolveAllDomSelectionsFromPreviewPoint: (
93
- clientX: number,
94
- clientY: number,
95
- ) => Promise<DomEditSelection[]>;
96
- updateDomEditHoverSelection: (selection: DomEditSelection | null) => void;
97
- buildDomSelectionForTimelineElement: (
98
- element: TimelineElement,
99
- ) => Promise<DomEditSelection | null>;
100
- handleTimelineElementSelect: (element: TimelineElement | null) => Promise<void>;
101
- refreshDomEditSelectionFromPreview: (selection: DomEditSelection) => Promise<void>;
102
- refreshDomEditGroupSelectionsFromPreview: (selections: DomEditSelection[]) => Promise<void>;
103
- applyMarqueeSelection: (selections: DomEditSelection[], additive: boolean) => void;
104
- }
24
+ import type {
25
+ ApplyDomSelectionOptions,
26
+ UseDomSelectionParams,
27
+ UseDomSelectionReturn,
28
+ } from "./useDomSelectionTypes";
29
+
30
+ export type {
31
+ ApplyDomSelectionOptions,
32
+ ResolveDomSelectionOptions,
33
+ UseDomSelectionParams,
34
+ UseDomSelectionReturn,
35
+ } from "./useDomSelectionTypes";
105
36
 
106
37
  // ── Hook ──
107
38
 
@@ -187,6 +118,19 @@ export function useDomSelection({
187
118
  const isAdditiveSelection = Boolean(options?.additive);
188
119
  const currentSelection = domEditSelectionRef.current;
189
120
  const previousGroup = domEditGroupSelectionsRef.current;
121
+ const isRepeatedSingleSelection =
122
+ !isAdditiveSelection &&
123
+ !options?.preserveGroup &&
124
+ previousGroup.length === 1 &&
125
+ domEditSelectionsTargetSame(currentSelection, selection) &&
126
+ domEditSelectionsTargetSame(previousGroup[0], selection);
127
+ if (isRepeatedSingleSelection) {
128
+ if (options?.revealPanel !== false) {
129
+ setRightCollapsed(false);
130
+ if (rightPanelTabRef.current !== "variables") setRightPanelTab("design");
131
+ }
132
+ return;
133
+ }
190
134
  const currentGroup = isAdditiveSelection
191
135
  ? seedDomEditGroupWithSelection(previousGroup, currentSelection)
192
136
  : previousGroup;
@@ -0,0 +1,82 @@
1
+ import type { Dispatch, MutableRefObject, SetStateAction } from "react";
2
+ import type { DomEditSelection } from "../components/editor/domEditing";
3
+ import type { SelectElementOptions, TimelineElement } from "../player";
4
+ import type { RightPanelTab } from "../utils/studioHelpers";
5
+
6
+ export interface ApplyDomSelectionOptions {
7
+ revealPanel?: boolean;
8
+ additive?: boolean;
9
+ preserveGroup?: boolean;
10
+ // A clear that came FROM the timeline must not be echoed back, or picking a
11
+ // clip with no canvas node would deselect the clip you just picked.
12
+ announce?: boolean;
13
+ }
14
+
15
+ export interface ResolveDomSelectionOptions {
16
+ preferClipAncestor?: boolean;
17
+ skipSourceProbe?: boolean;
18
+ activeGroupElement?: HTMLElement | null;
19
+ }
20
+
21
+ export interface UseDomSelectionParams {
22
+ projectId: string | null;
23
+ activeCompPath: string | null;
24
+ isMasterView: boolean;
25
+ compIdToSrc: Map<string, string>;
26
+ captionEditMode: boolean;
27
+ previewIframeRef: MutableRefObject<HTMLIFrameElement | null>;
28
+ timelineElements: TimelineElement[];
29
+ getTimelineSelectionSet: () => ReadonlySet<string>;
30
+ setSelectedTimelineElementId: (id: string | null, options?: SelectElementOptions) => void;
31
+ /** Publishes a whole multi-selection to the timeline; the anchor is set separately. */
32
+ setTimelineSelectionSet: (ids: Set<string>) => void;
33
+ setRightCollapsed: (collapsed: boolean) => void;
34
+ setRightPanelTab: (tab: RightPanelTab) => void;
35
+ previewIframe: HTMLIFrameElement | null;
36
+ refreshKey: number;
37
+ rightPanelTab: RightPanelTab;
38
+ }
39
+
40
+ export interface UseDomSelectionReturn {
41
+ // State
42
+ domEditSelection: DomEditSelection | null;
43
+ domEditGroupSelections: DomEditSelection[];
44
+ domEditHoverSelection: DomEditSelection | null;
45
+ activeGroupElement: HTMLElement | null;
46
+ // Refs
47
+ domEditSelectionRef: MutableRefObject<DomEditSelection | null>;
48
+ domEditGroupSelectionsRef: MutableRefObject<DomEditSelection[]>;
49
+ domEditHoverSelectionRef: MutableRefObject<DomEditSelection | null>;
50
+ activeGroupElementRef: MutableRefObject<HTMLElement | null>;
51
+ // State setters (needed by useDomEditSession for agent-prompt reset flows)
52
+ setDomEditSelection: Dispatch<SetStateAction<DomEditSelection | null>>;
53
+ setDomEditGroupSelections: Dispatch<SetStateAction<DomEditSelection[]>>;
54
+ setActiveGroupElement: (el: HTMLElement | null) => void;
55
+ // Callbacks
56
+ applyDomSelection: (
57
+ selection: DomEditSelection | null,
58
+ options?: ApplyDomSelectionOptions,
59
+ ) => void;
60
+ clearDomSelection: () => void;
61
+ buildDomSelectionFromTarget: (
62
+ target: HTMLElement,
63
+ options?: ResolveDomSelectionOptions,
64
+ ) => Promise<DomEditSelection | null>;
65
+ resolveDomSelectionFromPreviewPoint: (
66
+ clientX: number,
67
+ clientY: number,
68
+ options?: ResolveDomSelectionOptions,
69
+ ) => Promise<DomEditSelection | null>;
70
+ resolveAllDomSelectionsFromPreviewPoint: (
71
+ clientX: number,
72
+ clientY: number,
73
+ ) => Promise<DomEditSelection[]>;
74
+ updateDomEditHoverSelection: (selection: DomEditSelection | null) => void;
75
+ buildDomSelectionForTimelineElement: (
76
+ element: TimelineElement,
77
+ ) => Promise<DomEditSelection | null>;
78
+ handleTimelineElementSelect: (element: TimelineElement | null) => Promise<void>;
79
+ refreshDomEditSelectionFromPreview: (selection: DomEditSelection) => Promise<void>;
80
+ refreshDomEditGroupSelectionsFromPreview: (selections: DomEditSelection[]) => Promise<void>;
81
+ applyMarqueeSelection: (selections: DomEditSelection[], additive: boolean) => void;
82
+ }