@hyperframes/studio 0.9.39 → 0.9.41
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-CY6KnWXa.js → codec-B_mpbc4w.js} +1 -1
- package/dist/assets/{hyperframes-player-B9-CuG_h.js → hyperframes-player-Dvi3I_mv.js} +1 -1
- package/dist/assets/{index-_pkzoYYF.js → index-B5ExwsOp.js} +146 -146
- package/dist/assets/{index-Bjz2UaYv.js → index-BrFm9Y5k.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-Dr7nKUUu.js → pausedVideoDecoder-MHQ57yZ6.js} +1 -1
- package/dist/{chunk-NBULUIWH.js → chunk-4QQMX4BX.js} +17 -8
- package/dist/{chunk-ATDO3YLX.js → chunk-GVW7AU57.js} +190 -254
- package/dist/{chunk-44VRMER6.js → chunk-VHV2ZDKY.js} +17 -97
- package/dist/{domEditingLayers-FRVHP6IB.js → domEditingLayers-SA5KLSSS.js} +4 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.html +1 -1
- package/dist/index.js +898 -551
- package/dist/player.js +2 -2
- package/package.json +8 -8
- package/src/components/editor/DomEditOverlay.tsx +3 -15
- package/src/components/editor/clickAfterPreventedPress.test.tsx +17 -1
- package/src/components/editor/domEditOverlayBasis.ts +7 -2
- package/src/components/editor/domEditOverlayCrop.test.ts +1 -1
- package/src/components/editor/domEditOverlayCrop.ts +17 -3
- package/src/components/editor/domEditOverlayGeometry.ts +64 -139
- package/src/components/editor/domEditSelectionRules.ts +138 -0
- package/src/components/editor/domEditing.test.ts +6 -28
- package/src/components/editor/domEditingDom.preview.test.ts +3 -3
- package/src/components/editor/domEditingDom.ts +24 -165
- package/src/components/editor/domEditingElement.ts +19 -240
- package/src/components/editor/domEditingGroups.ts +0 -31
- package/src/components/editor/domEditingLayers.ts +95 -100
- package/src/components/editor/domEditingRootLayer.ts +35 -30
- package/src/components/editor/domEditingTypes.ts +4 -0
- package/src/components/editor/previewGestureStarts.ts +73 -10
- package/src/components/editor/previewOverlayRects.test.ts +316 -0
- package/src/components/editor/previewOverlayRects.ts +123 -0
- package/src/components/editor/previewPointerTargets.test.ts +260 -0
- package/src/components/editor/previewSelection.test.ts +481 -0
- package/src/components/editor/previewSelection.ts +472 -0
- package/src/components/editor/probeSourceElement.ts +19 -1
- package/src/components/editor/propertyPanelFill.tsx +5 -1
- package/src/components/editor/useDomEditOverlayRects.ts +80 -1
- package/src/components/editor/useInlineTextEditing.tsx +1 -6
- package/src/hooks/domSelectionTestHarness.ts +1 -1
- package/src/hooks/useDomEditSession.test.tsx +23 -1
- package/src/hooks/useDomEditSession.ts +2 -1
- package/src/hooks/useDomSelection.ts +61 -47
- package/src/hooks/useGsapSelectionHandlers.test.tsx +17 -0
- package/src/hooks/useGsapSelectionHandlers.ts +2 -1
- package/src/hooks/usePreviewInteraction.test.ts +10 -2
- package/src/hooks/usePreviewInteraction.ts +5 -4
- package/src/hooks/useStudioSelectionPublisher.test.tsx +50 -0
- package/src/hooks/useStudioSelectionPublisher.ts +9 -7
- package/src/player/lib/previewChannel.ts +26 -10
- package/src/player/lib/previewElements.test.ts +167 -0
- package/src/player/lib/previewElements.ts +226 -0
- package/src/styles/hex-baseline.json +1 -2
- package/src/utils/studioHelpers.ts +0 -13
- package/src/utils/studioPreviewHelpers.test.ts +8 -8
- package/src/utils/studioPreviewHelpers.ts +26 -242
- package/src/components/editor/domEditOverlayTransform.ts +0 -126
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isClipHiddenByRuntime, PREVIEW_ONLY_ATTRS } from "@hyperframes/core/studio-preview-mark";
|
|
2
|
-
import {
|
|
2
|
+
import { existsInSourceFile } from "./probeSourceElement";
|
|
3
3
|
import { isAudibleVideoNode } from "../../player/lib/timelineElementHelpers";
|
|
4
4
|
import type { PatchOperation } from "../../utils/sourcePatcher";
|
|
5
5
|
import {
|
|
@@ -7,7 +7,12 @@ import {
|
|
|
7
7
|
resolveEditingSections,
|
|
8
8
|
type EditableElementFacts,
|
|
9
9
|
} from "@hyperframes/core/editing";
|
|
10
|
-
import { groupScopedLayerRoots
|
|
10
|
+
import { groupScopedLayerRoots } from "./domEditingGroups";
|
|
11
|
+
import {
|
|
12
|
+
chainLocked,
|
|
13
|
+
selectionTargetIndex,
|
|
14
|
+
type SelectionChainReader,
|
|
15
|
+
} from "./domEditSelectionRules";
|
|
11
16
|
import type {
|
|
12
17
|
DomEditCapabilities,
|
|
13
18
|
DomEditContextOptions,
|
|
@@ -18,7 +23,6 @@ import type {
|
|
|
18
23
|
import {
|
|
19
24
|
buildElementLabel,
|
|
20
25
|
buildStableSelector,
|
|
21
|
-
findClosestByAttribute,
|
|
22
26
|
getCuratedComputedStyles,
|
|
23
27
|
getDataAttributes,
|
|
24
28
|
getInlineStyles,
|
|
@@ -27,11 +31,7 @@ import {
|
|
|
27
31
|
isEditableTextLeaf,
|
|
28
32
|
isHtmlElement,
|
|
29
33
|
} from "./domEditingDom";
|
|
30
|
-
import {
|
|
31
|
-
findElementForSelection,
|
|
32
|
-
getSelectionCandidate,
|
|
33
|
-
isDomLayerElement,
|
|
34
|
-
} from "./domEditingElement";
|
|
34
|
+
import { findElementForSelection, isDomLayerElement } from "./domEditingElement";
|
|
35
35
|
import { isCompositionRootLayer } from "./domEditingRootLayer";
|
|
36
36
|
import { withSelectorIndexPass } from "../../utils/sourceScopedSelectorIndex";
|
|
37
37
|
import { type DomEditLayerWalkCache, readDomEditLayerWalkEntry } from "./domEditLayerWalkCache";
|
|
@@ -206,7 +206,7 @@ export function buildTextFieldChildLocator(
|
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
function capabilityFacts(geometry: {
|
|
209
|
+
export function capabilityFacts(geometry: {
|
|
210
210
|
hasStableTarget: boolean;
|
|
211
211
|
tag: string;
|
|
212
212
|
inlineStyles: Record<string, string>;
|
|
@@ -248,7 +248,7 @@ export function domEditSelectionToFacts(
|
|
|
248
248
|
hasEditableText: selection.textFields.length > 0,
|
|
249
249
|
hasTimingStart: selection.dataAttributes.start != null,
|
|
250
250
|
animationCount,
|
|
251
|
-
hasAudio: isAudibleVideoNode(selection.element),
|
|
251
|
+
hasAudio: selection.hasAudio ?? isAudibleVideoNode(selection.element),
|
|
252
252
|
};
|
|
253
253
|
}
|
|
254
254
|
|
|
@@ -296,99 +296,94 @@ export async function resolveDomEditSelection(
|
|
|
296
296
|
): Promise<DomEditSelection | null> {
|
|
297
297
|
if (!startEl) return null;
|
|
298
298
|
const doc = startEl.ownerDocument;
|
|
299
|
-
|
|
300
|
-
let
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
if (selectorIndex != null) probeTarget.selectorIndex = selectorIndex;
|
|
342
|
-
let existsInSource = knownSourceAnswer(options.previous, current, sourceFile, probeTarget);
|
|
343
|
-
const probe = existsInSource === undefined && !options.skipSourceProbe;
|
|
344
|
-
if (probe && options.projectId && (current.id || selector || hfId)) {
|
|
345
|
-
existsInSource = await probeSourceElement(options.projectId, sourceFile, probeTarget);
|
|
346
|
-
}
|
|
347
|
-
const capabilities = resolveEditingAffordances(
|
|
348
|
-
capabilityFacts({
|
|
349
|
-
hasStableTarget: Boolean(selector || hfId),
|
|
350
|
-
tag: current.tagName.toLowerCase(),
|
|
351
|
-
inlineStyles,
|
|
352
|
-
computedStyles,
|
|
353
|
-
isCompositionHost: Boolean(compositionSrc),
|
|
354
|
-
isCompositionRoot,
|
|
355
|
-
isInsideLockedComposition: isInsideLocked,
|
|
356
|
-
isMasterView: options.isMasterView,
|
|
357
|
-
existsInSource: existsInSource ?? true,
|
|
358
|
-
}),
|
|
359
|
-
).capabilities;
|
|
360
|
-
const rect = current.getBoundingClientRect();
|
|
361
|
-
|
|
362
|
-
return {
|
|
363
|
-
element: current,
|
|
364
|
-
id: current.id || undefined,
|
|
365
|
-
hfId,
|
|
366
|
-
selector,
|
|
367
|
-
selectorIndex,
|
|
368
|
-
sourceFile,
|
|
369
|
-
compositionPath,
|
|
370
|
-
compositionSrc,
|
|
371
|
-
isCompositionHost: Boolean(compositionSrc),
|
|
372
|
-
isInsideLockedComposition: isInsideLocked,
|
|
373
|
-
label: buildElementLabel(current),
|
|
374
|
-
tagName: current.tagName.toLowerCase(),
|
|
375
|
-
boundingBox: {
|
|
376
|
-
x: rect.left,
|
|
377
|
-
y: rect.top,
|
|
378
|
-
width: rect.width,
|
|
379
|
-
height: rect.height,
|
|
380
|
-
},
|
|
381
|
-
textContent: current.textContent?.trim() || null,
|
|
382
|
-
dataAttributes: getDataAttributes(current),
|
|
299
|
+
const chain: HTMLElement[] = [];
|
|
300
|
+
for (let node: HTMLElement | null = startEl; node; node = node.parentElement) chain.push(node);
|
|
301
|
+
const read = liveChainReader(doc);
|
|
302
|
+
const active = options.activeGroupElement ?? null;
|
|
303
|
+
const index = selectionTargetIndex(chain, read, {
|
|
304
|
+
exactTarget: options.exactTarget,
|
|
305
|
+
preferClipAncestor: options.preferClipAncestor,
|
|
306
|
+
activeGroupIndex: active ? chain.indexOf(active) : null,
|
|
307
|
+
});
|
|
308
|
+
if (index === null) return null;
|
|
309
|
+
const current = chain[index]!;
|
|
310
|
+
const selector = buildStableSelector(current);
|
|
311
|
+
const hfId = readHfId(current);
|
|
312
|
+
const { sourceFile, compositionPath } = getSourceFileForElement(
|
|
313
|
+
current,
|
|
314
|
+
options.activeCompositionPath,
|
|
315
|
+
);
|
|
316
|
+
const selectorIndex = selector
|
|
317
|
+
? getSelectorIndex(doc, current, selector, sourceFile, options.activeCompositionPath)
|
|
318
|
+
: undefined;
|
|
319
|
+
const compositionSrc =
|
|
320
|
+
current.getAttribute("data-composition-src") ??
|
|
321
|
+
current.getAttribute("data-composition-file") ??
|
|
322
|
+
undefined;
|
|
323
|
+
const inlineStyles = getInlineStyles(current);
|
|
324
|
+
const computedStyles = getCuratedComputedStyles(current);
|
|
325
|
+
const isCompositionRoot =
|
|
326
|
+
(current.hasAttribute("data-composition-id") && !compositionSrc) ||
|
|
327
|
+
isCompositionRootLayer(current, doc, computedStyles);
|
|
328
|
+
const textFields = collectDomEditTextFields(current);
|
|
329
|
+
const isInsideLocked = chainLocked(chain, read, index);
|
|
330
|
+
const existsInSource = await existsInSourceFile(
|
|
331
|
+
options.previous,
|
|
332
|
+
current,
|
|
333
|
+
sourceFile,
|
|
334
|
+
{ id: current.id, hfId, selector, selectorIndex },
|
|
335
|
+
options,
|
|
336
|
+
);
|
|
337
|
+
const capabilities = resolveEditingAffordances(
|
|
338
|
+
capabilityFacts({
|
|
339
|
+
hasStableTarget: Boolean(selector || hfId),
|
|
340
|
+
tag: current.tagName.toLowerCase(),
|
|
383
341
|
inlineStyles,
|
|
384
342
|
computedStyles,
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
343
|
+
isCompositionHost: Boolean(compositionSrc),
|
|
344
|
+
isCompositionRoot,
|
|
345
|
+
isInsideLockedComposition: isInsideLocked,
|
|
346
|
+
isMasterView: options.isMasterView,
|
|
347
|
+
existsInSource: existsInSource ?? true,
|
|
348
|
+
}),
|
|
349
|
+
).capabilities;
|
|
350
|
+
const rect = current.getBoundingClientRect();
|
|
390
351
|
|
|
391
|
-
return
|
|
352
|
+
return {
|
|
353
|
+
element: current,
|
|
354
|
+
id: current.id || undefined,
|
|
355
|
+
hfId,
|
|
356
|
+
selector,
|
|
357
|
+
selectorIndex,
|
|
358
|
+
sourceFile,
|
|
359
|
+
compositionPath,
|
|
360
|
+
compositionSrc,
|
|
361
|
+
isCompositionHost: Boolean(compositionSrc),
|
|
362
|
+
isInsideLockedComposition: isInsideLocked,
|
|
363
|
+
label: buildElementLabel(current),
|
|
364
|
+
tagName: current.tagName.toLowerCase(),
|
|
365
|
+
boundingBox: {
|
|
366
|
+
x: rect.left,
|
|
367
|
+
y: rect.top,
|
|
368
|
+
width: rect.width,
|
|
369
|
+
height: rect.height,
|
|
370
|
+
},
|
|
371
|
+
textContent: current.textContent?.trim() || null,
|
|
372
|
+
dataAttributes: getDataAttributes(current),
|
|
373
|
+
inlineStyles,
|
|
374
|
+
computedStyles,
|
|
375
|
+
textFields,
|
|
376
|
+
capabilities,
|
|
377
|
+
existsInSource,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function liveChainReader(doc: Document): SelectionChainReader<HTMLElement> {
|
|
382
|
+
return {
|
|
383
|
+
attr: (el, name) => el.getAttribute(name),
|
|
384
|
+
selector: buildStableSelector,
|
|
385
|
+
isDocumentRoot: (el) => el === doc.body || el === doc.documentElement,
|
|
386
|
+
};
|
|
392
387
|
}
|
|
393
388
|
|
|
394
389
|
export async function refreshDomEditSelection(
|
|
@@ -12,32 +12,36 @@ function approximatelyEqual(a: number, b: number) {
|
|
|
12
12
|
return Math.abs(a - b) <= COMPOSITION_ROOT_LAYER_EPSILON_PX;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!root || !rootWidth || !rootHeight) return null;
|
|
21
|
-
return { rect: root.getBoundingClientRect(), width: rootWidth, height: rootHeight };
|
|
15
|
+
interface Box {
|
|
16
|
+
left: number;
|
|
17
|
+
top: number;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return width && height ? { width, height } : null;
|
|
22
|
+
export interface CompositionRootFacts {
|
|
23
|
+
rect: Box;
|
|
24
|
+
width: string | null;
|
|
25
|
+
height: string | null;
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
export function coversCompositionRoot(
|
|
29
|
+
layer: { rect: Box; computedStyles: Record<string, string> },
|
|
30
|
+
root: CompositionRootFacts | null,
|
|
31
|
+
): boolean {
|
|
32
|
+
if (isExplicitFullBleedLayer(layer.computedStyles)) return false;
|
|
33
|
+
const rootWidth = readPositiveDimension(root?.width ?? null);
|
|
34
|
+
const rootHeight = readPositiveDimension(root?.height ?? null);
|
|
35
|
+
if (!root || !rootWidth || !rootHeight) return false;
|
|
36
|
+
const width = layer.rect.width || parsePx(layer.computedStyles.width);
|
|
37
|
+
const height = layer.rect.height || parsePx(layer.computedStyles.height);
|
|
38
|
+
return Boolean(
|
|
39
|
+
width &&
|
|
40
|
+
height &&
|
|
41
|
+
approximatelyEqual(layer.rect.left, root.rect.left) &&
|
|
42
|
+
approximatelyEqual(layer.rect.top, root.rect.top) &&
|
|
43
|
+
approximatelyEqual(width, rootWidth) &&
|
|
44
|
+
approximatelyEqual(height, rootHeight),
|
|
41
45
|
);
|
|
42
46
|
}
|
|
43
47
|
|
|
@@ -52,13 +56,14 @@ export function isCompositionRootLayer(
|
|
|
52
56
|
) {
|
|
53
57
|
if (element.parentElement !== doc.body) return false;
|
|
54
58
|
if (element.hasAttribute("data-hf-allow-root-edit")) return false;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
const root =
|
|
60
|
+
doc.querySelector<HTMLElement>("[data-composition-id]") ?? doc.documentElement ?? null;
|
|
61
|
+
return coversCompositionRoot(
|
|
62
|
+
{ rect: element.getBoundingClientRect(), computedStyles },
|
|
63
|
+
root && {
|
|
64
|
+
rect: root.getBoundingClientRect(),
|
|
65
|
+
width: root.getAttribute("data-width"),
|
|
66
|
+
height: root.getAttribute("data-height"),
|
|
67
|
+
},
|
|
63
68
|
);
|
|
64
69
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PatchTarget } from "../../utils/sourcePatcher";
|
|
2
2
|
import type { GsapAnimation } from "@hyperframes/parsers/gsap-parser";
|
|
3
|
+
import type { EditingElementHandle } from "@hyperframes/core/runtime/editing-port";
|
|
3
4
|
|
|
4
5
|
export const CURATED_STYLE_PROPERTIES = [
|
|
5
6
|
"position",
|
|
@@ -78,6 +79,9 @@ export interface DomEditTextField {
|
|
|
78
79
|
|
|
79
80
|
export interface DomEditSelection extends PatchTarget {
|
|
80
81
|
element: HTMLElement;
|
|
82
|
+
handle?: EditingElementHandle;
|
|
83
|
+
hasAudio?: boolean;
|
|
84
|
+
src?: string | null;
|
|
81
85
|
label: string;
|
|
82
86
|
tagName: string;
|
|
83
87
|
sourceFile: string;
|
|
@@ -21,6 +21,17 @@ import { giveUpOnPreviewChange, isPreviewChanging } from "../../player/previewRe
|
|
|
21
21
|
import { setStudioWaitingPressCancel } from "../../utils/studioPendingEdits";
|
|
22
22
|
import { playheadMoment } from "../../hooks/editMoment";
|
|
23
23
|
import type { EditMoment } from "./manualEditsTypes";
|
|
24
|
+
import { previewFrameOpaque } from "../../player/lib/previewChannel";
|
|
25
|
+
import { findPreviewElementForSelection } from "./previewSelection";
|
|
26
|
+
import { measurePreviewRects } from "./previewOverlayRects";
|
|
27
|
+
|
|
28
|
+
type Shown = { selection: DomEditSelection; rect: OverlayRect };
|
|
29
|
+
type ShownStart = (
|
|
30
|
+
e: React.PointerEvent<HTMLElement>,
|
|
31
|
+
at: EditMoment,
|
|
32
|
+
waited: boolean,
|
|
33
|
+
overChannel?: Shown[],
|
|
34
|
+
) => boolean;
|
|
24
35
|
|
|
25
36
|
const MAX_SETTLED_WAIT_FRAMES = 60;
|
|
26
37
|
export const PRESS_WAIT_MAX_MS = 10_000;
|
|
@@ -128,12 +139,33 @@ export function createPreviewGestureStarts(
|
|
|
128
139
|
};
|
|
129
140
|
};
|
|
130
141
|
|
|
142
|
+
/** An opaque frame's `selections` on the page it shows now, read over its channel; null when any is gone. */
|
|
143
|
+
const shownOverChannel = async (
|
|
144
|
+
iframe: HTMLIFrameElement,
|
|
145
|
+
selections: DomEditSelection[],
|
|
146
|
+
): Promise<Shown[] | null> => {
|
|
147
|
+
const overlay = opts.overlayRef.current;
|
|
148
|
+
const path = opts.activeCompositionPathRef.current;
|
|
149
|
+
const found = await Promise.all(
|
|
150
|
+
selections.map((selection) => findPreviewElementForSelection(iframe, selection, path)),
|
|
151
|
+
);
|
|
152
|
+
const handles = found.map((element) => element?.handle);
|
|
153
|
+
if (!overlay || !handles.length || !handles.every(Boolean)) return null;
|
|
154
|
+
const rects = await measurePreviewRects(iframe, overlay, handles as string[]);
|
|
155
|
+
const shown = selections.flatMap((selection, i) => {
|
|
156
|
+
const rect = rects?.[i];
|
|
157
|
+
return rect ? [{ selection: { ...selection, handle: handles[i] }, rect }] : [];
|
|
158
|
+
});
|
|
159
|
+
return shown.length === selections.length ? shown : null;
|
|
160
|
+
};
|
|
161
|
+
|
|
131
162
|
// A press on the page a reload is replacing would edit it by its old rules: it starts on the new page instead.
|
|
132
163
|
const startOnShownPreview = (
|
|
133
164
|
e: React.PointerEvent<HTMLElement>,
|
|
134
165
|
pressed: () => HTMLElement[],
|
|
135
|
-
start:
|
|
166
|
+
start: ShownStart,
|
|
136
167
|
draw: WaitingPressState["draw"] = null,
|
|
168
|
+
targets: () => DomEditSelection[] = () => [],
|
|
137
169
|
): boolean => {
|
|
138
170
|
const at = playheadMoment();
|
|
139
171
|
if (!isPreviewChanging() && !opts.waitingPressRef.current) return start(e, at, false);
|
|
@@ -170,8 +202,25 @@ export function createPreviewGestureStarts(
|
|
|
170
202
|
settledFrames = settled ? settledFrames + 1 : 0;
|
|
171
203
|
return elements.length;
|
|
172
204
|
};
|
|
205
|
+
// An opaque frame's pressed elements are found over its channel, once the preview settles.
|
|
206
|
+
const iframe = opts.iframeRef.current;
|
|
207
|
+
const channel = iframe && previewFrameOpaque(iframe) ? iframe : null;
|
|
208
|
+
let overChannel: Shown[] | null | undefined;
|
|
209
|
+
let asked = false;
|
|
210
|
+
const channelStep = (frame: HTMLIFrameElement): "wait" | "lost" | "run" => {
|
|
211
|
+
const overdue = performance.now() - since > PRESS_WAIT_MAX_MS;
|
|
212
|
+
if (overdue) giveUpOnPreviewChange();
|
|
213
|
+
if (isPreviewChanging() && !overdue) return "wait";
|
|
214
|
+
if (!asked) {
|
|
215
|
+
asked = true;
|
|
216
|
+
void shownOverChannel(frame, targets()).then((shown) => (overChannel = shown));
|
|
217
|
+
}
|
|
218
|
+
if (overChannel === undefined) return "wait";
|
|
219
|
+
return overChannel ? "run" : "lost";
|
|
220
|
+
};
|
|
173
221
|
const waitStep = (): "wait" | "lost" | "run" => {
|
|
174
222
|
if (press.after && !press.after.ended) return "wait";
|
|
223
|
+
if (channel) return channelStep(channel);
|
|
175
224
|
const found = countFrame();
|
|
176
225
|
// A change that never ends (a save with no reply) would hold every press: run on the page shown.
|
|
177
226
|
const overdue = performance.now() - since > PRESS_WAIT_MAX_MS;
|
|
@@ -188,8 +237,8 @@ export function createPreviewGestureStarts(
|
|
|
188
237
|
return;
|
|
189
238
|
}
|
|
190
239
|
endWaitingPress(press);
|
|
191
|
-
|
|
192
|
-
|
|
240
|
+
const pointerDown = down as unknown as React.PointerEvent<HTMLElement>;
|
|
241
|
+
if (step === "lost" || !start(pointerDown, at, true, overChannel ?? undefined)) return;
|
|
193
242
|
if (press.moved) moveActiveGesture(press.moved);
|
|
194
243
|
if (press.released) releaseActiveGesture(press.released);
|
|
195
244
|
};
|
|
@@ -208,6 +257,11 @@ export function createPreviewGestureStarts(
|
|
|
208
257
|
const iframe = opts.iframeRef.current;
|
|
209
258
|
return overlay && iframe && orientedGroupAwareOverlayRect(overlay, iframe, element);
|
|
210
259
|
};
|
|
260
|
+
const shownOnPage = (target: DomEditSelection | null): Shown | null => {
|
|
261
|
+
const selection = target && shownSelection(target);
|
|
262
|
+
const rect = selection && shownRect(selection.element);
|
|
263
|
+
return selection && rect ? { selection, rect } : null;
|
|
264
|
+
};
|
|
211
265
|
|
|
212
266
|
const startGroupDrag = (e: React.PointerEvent<HTMLElement>) => {
|
|
213
267
|
const items = opts.groupOverlayItemsRef.current;
|
|
@@ -218,8 +272,16 @@ export function createPreviewGestureStarts(
|
|
|
218
272
|
const selection = shownSelection(item.selection);
|
|
219
273
|
return selection ? [selection.element] : [];
|
|
220
274
|
}),
|
|
221
|
-
(pressed, at, waited) => {
|
|
275
|
+
(pressed, at, waited, overChannel) => {
|
|
222
276
|
if (!waited) return _startGroupDrag(pressed, opts, at);
|
|
277
|
+
if (overChannel) {
|
|
278
|
+
const measured = items.map((item, i) => ({ ...item, ...overChannel[i]! }));
|
|
279
|
+
return _startGroupDrag(
|
|
280
|
+
pressed,
|
|
281
|
+
{ ...opts, groupOverlayItemsRef: { current: measured } },
|
|
282
|
+
at,
|
|
283
|
+
);
|
|
284
|
+
}
|
|
223
285
|
const overlay = opts.overlayRef.current;
|
|
224
286
|
const iframe = opts.iframeRef.current;
|
|
225
287
|
if (!overlay || !iframe) return false;
|
|
@@ -243,6 +305,7 @@ export function createPreviewGestureStarts(
|
|
|
243
305
|
opts.setGroupOverlayItems(
|
|
244
306
|
items.map((item) => ({ ...item, rect: shiftedOverlayRect(item.rect, dx, dy) })),
|
|
245
307
|
),
|
|
308
|
+
() => items.map((item) => item.selection),
|
|
246
309
|
);
|
|
247
310
|
};
|
|
248
311
|
const startGesture = (
|
|
@@ -270,15 +333,14 @@ export function createPreviewGestureStarts(
|
|
|
270
333
|
const shown = target && shownSelection(target);
|
|
271
334
|
return shown ? [shown.element] : [];
|
|
272
335
|
},
|
|
273
|
-
(pressed, at, waited) => {
|
|
336
|
+
(pressed, at, waited, overChannel) => {
|
|
274
337
|
if (!waited) return _startGesture(kind, pressed, opts, { ...options, at });
|
|
275
|
-
const
|
|
276
|
-
const rect = selection && shownRect(selection.element);
|
|
338
|
+
const shown = overChannel ? overChannel[0] : shownOnPage(target);
|
|
277
339
|
return (
|
|
278
|
-
!!
|
|
340
|
+
!!shown &&
|
|
279
341
|
_startGesture(kind, pressed, opts, {
|
|
280
|
-
selection,
|
|
281
|
-
rect,
|
|
342
|
+
selection: shown.selection,
|
|
343
|
+
rect: shown.rect,
|
|
282
344
|
resizeHandle: options?.resizeHandle,
|
|
283
345
|
resizeCorner: options?.resizeCorner,
|
|
284
346
|
at,
|
|
@@ -286,6 +348,7 @@ export function createPreviewGestureStarts(
|
|
|
286
348
|
);
|
|
287
349
|
},
|
|
288
350
|
draw,
|
|
351
|
+
() => (target ? [target] : []),
|
|
289
352
|
);
|
|
290
353
|
};
|
|
291
354
|
|