@storystick/preview 0.0.0-stage → 0.2.0-rc.0
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/LICENSE +112 -0
- package/PUBLIC-API.md +55 -0
- package/README.md +42 -2
- package/dist/.source-hash +1 -0
- package/dist/authoring/runtime-contract.d.ts +89 -0
- package/dist/authoring/runtime-contract.js +28 -0
- package/dist/channel-taxonomy.d.ts +17 -0
- package/dist/channel-taxonomy.js +46 -0
- package/dist/context-command.d.ts +18 -0
- package/dist/context-command.js +38 -0
- package/dist/dev/suspicious-codeword-detector.d.ts +15 -0
- package/dist/dev/suspicious-codeword-detector.js +220 -0
- package/dist/dev/suspicious-codeword-detector.noop.d.ts +3 -0
- package/dist/dev/suspicious-codeword-detector.noop.js +4 -0
- package/dist/framework/browser-context.d.ts +2 -0
- package/dist/framework/browser-context.js +2 -0
- package/dist/framework/generation-refresh.d.ts +23 -0
- package/dist/framework/generation-refresh.js +82 -0
- package/dist/framework/generation-signal.d.ts +8 -0
- package/dist/framework/generation-signal.js +17 -0
- package/dist/framework/projection-generation-watch.d.ts +5 -0
- package/dist/framework/projection-generation-watch.js +53 -0
- package/dist/framework/render-receipt.d.ts +8 -0
- package/dist/framework/render-receipt.js +10 -0
- package/dist/framework/runtime-adapter-store.d.ts +30 -0
- package/dist/framework/runtime-adapter-store.js +81 -0
- package/dist/grant-coordinator.d.ts +53 -0
- package/dist/grant-coordinator.js +329 -0
- package/dist/grant-lifecycle.d.ts +52 -0
- package/dist/grant-lifecycle.js +74 -0
- package/dist/identity/__test-adapter.d.ts +34 -0
- package/dist/identity/__test-adapter.js +59 -0
- package/dist/identity/browser-context-gate.d.ts +4 -0
- package/dist/identity/browser-context-gate.js +22 -0
- package/dist/identity/browser-context.d.ts +13 -0
- package/dist/identity/browser-context.js +22 -0
- package/dist/identity/carriers/postmessage.d.ts +84 -0
- package/dist/identity/carriers/postmessage.js +177 -0
- package/dist/identity/carriers/storage-state.d.ts +41 -0
- package/dist/identity/carriers/storage-state.js +99 -0
- package/dist/identity/carriers/storage.d.ts +39 -0
- package/dist/identity/carriers/storage.js +182 -0
- package/dist/identity/carriers/url.d.ts +19 -0
- package/dist/identity/carriers/url.js +38 -0
- package/dist/identity/identity-state-machine.d.ts +70 -0
- package/dist/identity/identity-state-machine.js +244 -0
- package/dist/identity/identity-types.d.ts +192 -0
- package/dist/identity/identity-types.js +22 -0
- package/dist/identity/index.d.ts +18 -0
- package/dist/identity/index.js +16 -0
- package/dist/identity/preview-cookie.d.ts +9 -0
- package/dist/identity/preview-cookie.js +12 -0
- package/dist/identity/preview-draft.d.ts +6 -0
- package/dist/identity/preview-draft.js +25 -0
- package/dist/identity/preview-identity.d.ts +28 -0
- package/dist/identity/preview-identity.js +84 -0
- package/dist/identity/preview-scope.d.ts +28 -0
- package/dist/identity/preview-scope.js +47 -0
- package/dist/identity/resolver.d.ts +110 -0
- package/dist/identity/resolver.js +334 -0
- package/dist/identity/session-query.d.ts +4 -0
- package/dist/identity/session-query.js +19 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +788 -0
- package/dist/interaction-mode.d.ts +58 -0
- package/dist/interaction-mode.js +93 -0
- package/dist/nav-handler.d.ts +95 -0
- package/dist/nav-handler.js +84 -0
- package/dist/overlay-label.d.ts +79 -0
- package/dist/overlay-label.js +73 -0
- package/dist/provenance/anchor-map.d.ts +95 -0
- package/dist/provenance/anchor-map.js +177 -0
- package/dist/provenance/carrier-plan.d.ts +51 -0
- package/dist/provenance/carrier-plan.js +90 -0
- package/dist/provenance/coded-text.d.ts +20 -0
- package/dist/provenance/coded-text.js +302 -0
- package/dist/provenance/direct-edit-locator.d.ts +29 -0
- package/dist/provenance/direct-edit-locator.js +218 -0
- package/dist/provenance/editable-leaf.d.ts +134 -0
- package/dist/provenance/editable-leaf.js +483 -0
- package/dist/provenance/editor-target.d.ts +29 -0
- package/dist/provenance/editor-target.js +46 -0
- package/dist/provenance/field-leaf-walker.d.ts +21 -0
- package/dist/provenance/field-leaf-walker.js +98 -0
- package/dist/provenance/frame-dependencies.d.ts +212 -0
- package/dist/provenance/frame-dependencies.js +550 -0
- package/dist/provenance/index.d.ts +26 -0
- package/dist/provenance/index.js +26 -0
- package/dist/provenance/local-events.d.ts +1 -0
- package/dist/provenance/local-events.js +1 -0
- package/dist/provenance/markers.d.ts +21 -0
- package/dist/provenance/markers.js +70 -0
- package/dist/provenance/multi-frame-anchor-map.d.ts +54 -0
- package/dist/provenance/multi-frame-anchor-map.js +109 -0
- package/dist/provenance/normalize.d.ts +2 -0
- package/dist/provenance/normalize.js +19 -0
- package/dist/provenance/overlay-focus-echo.d.ts +17 -0
- package/dist/provenance/overlay-focus-echo.js +16 -0
- package/dist/provenance/overlay-projection.d.ts +65 -0
- package/dist/provenance/overlay-projection.js +201 -0
- package/dist/provenance/owner-map.d.ts +55 -0
- package/dist/provenance/owner-map.js +239 -0
- package/dist/provenance/read-carrier.d.ts +22 -0
- package/dist/provenance/read-carrier.js +92 -0
- package/dist/provenance/recorder.d.ts +38 -0
- package/dist/provenance/recorder.js +82 -0
- package/dist/provenance/render-context.d.ts +106 -0
- package/dist/provenance/render-context.js +338 -0
- package/dist/provenance/reveal-contract.d.ts +44 -0
- package/dist/provenance/reveal-contract.js +1 -0
- package/dist/provenance/richtext-slice-embed-address.d.ts +20 -0
- package/dist/provenance/richtext-slice-embed-address.js +35 -0
- package/dist/provenance/runtime-script.d.ts +1 -0
- package/dist/provenance/runtime-script.js +2217 -0
- package/dist/provenance/sidecar-store.d.ts +63 -0
- package/dist/provenance/sidecar-store.js +151 -0
- package/dist/provenance/sidecar.d.ts +34 -0
- package/dist/provenance/sidecar.js +227 -0
- package/dist/provenance/slice-model.d.ts +28 -0
- package/dist/provenance/slice-model.js +86 -0
- package/dist/provenance/source-identity.d.ts +3 -0
- package/dist/provenance/source-identity.js +7 -0
- package/dist/provenance/source-map-materializer.d.ts +76 -0
- package/dist/provenance/source-map-materializer.js +286 -0
- package/dist/provenance/source-registry.d.ts +103 -0
- package/dist/provenance/source-registry.js +562 -0
- package/dist/provenance/transformed-output-gate.d.ts +161 -0
- package/dist/provenance/transformed-output-gate.js +171 -0
- package/dist/provenance/types.d.ts +102 -0
- package/dist/provenance/types.js +1 -0
- package/dist/refresh-policy.d.ts +11 -0
- package/dist/refresh-policy.js +14 -0
- package/dist/reveal-target.d.ts +8 -0
- package/dist/reveal-target.js +47 -0
- package/dist/route-paths.d.ts +11 -0
- package/dist/route-paths.js +14 -0
- package/dist/router-subscriber.d.ts +92 -0
- package/dist/router-subscriber.js +44 -0
- package/dist/runtime/anchor-types.d.ts +5 -0
- package/dist/runtime/anchor-types.js +1 -0
- package/dist/runtime/authority-store.d.ts +31 -0
- package/dist/runtime/authority-store.js +56 -0
- package/dist/runtime/boot.d.ts +52 -0
- package/dist/runtime/boot.js +379 -0
- package/dist/runtime/content-refresh.d.ts +30 -0
- package/dist/runtime/content-refresh.js +68 -0
- package/dist/runtime/emit-runtime-error.d.ts +51 -0
- package/dist/runtime/emit-runtime-error.js +64 -0
- package/dist/runtime/field-proxy.d.ts +112 -0
- package/dist/runtime/field-proxy.js +471 -0
- package/dist/runtime/form-contract-reporter.d.ts +99 -0
- package/dist/runtime/form-contract-reporter.js +391 -0
- package/dist/runtime/invalidation-adapter.d.ts +17 -0
- package/dist/runtime/invalidation-adapter.js +42 -0
- package/dist/runtime/live-query-overlay.d.ts +39 -0
- package/dist/runtime/live-query-overlay.js +345 -0
- package/dist/runtime/momentary-navigate.d.ts +16 -0
- package/dist/runtime/momentary-navigate.js +106 -0
- package/dist/runtime/observation-scheduler.d.ts +15 -0
- package/dist/runtime/observation-scheduler.js +42 -0
- package/dist/runtime/perf-metrics.d.ts +28 -0
- package/dist/runtime/perf-metrics.js +90 -0
- package/dist/runtime/preview-interaction-policy.d.ts +1 -0
- package/dist/runtime/preview-interaction-policy.js +103 -0
- package/dist/runtime/preview-overlay-painter.d.ts +27 -0
- package/dist/runtime/preview-overlay-painter.js +1732 -0
- package/dist/runtime/preview-overlay-sidecar.d.ts +26 -0
- package/dist/runtime/preview-overlay-sidecar.js +45 -0
- package/dist/runtime/preview-perspective-alignment.d.ts +15 -0
- package/dist/runtime/preview-perspective-alignment.js +40 -0
- package/dist/runtime/preview-perspective-intent-state.d.ts +23 -0
- package/dist/runtime/preview-perspective-intent-state.js +5 -0
- package/dist/runtime/preview-transition-state.d.ts +142 -0
- package/dist/runtime/preview-transition-state.js +257 -0
- package/dist/runtime/render-mode-state.d.ts +51 -0
- package/dist/runtime/render-mode-state.js +76 -0
- package/dist/runtime/request-id.d.ts +4 -0
- package/dist/runtime/request-id.js +8 -0
- package/dist/runtime/resolve-schema-field.d.ts +99 -0
- package/dist/runtime/resolve-schema-field.js +356 -0
- package/dist/runtime/runtime-error-dispatch.d.ts +23 -0
- package/dist/runtime/runtime-error-dispatch.js +75 -0
- package/dist/runtime/schema-store.d.ts +121 -0
- package/dist/runtime/schema-store.js +667 -0
- package/dist/runtime/snapshot-assembly.d.ts +104 -0
- package/dist/runtime/snapshot-assembly.js +553 -0
- package/dist/runtime/snapshot-reporter.d.ts +55 -0
- package/dist/runtime/snapshot-reporter.js +375 -0
- package/dist/runtime/standalone-overlay-controller.d.ts +33 -0
- package/dist/runtime/standalone-overlay-controller.js +281 -0
- package/dist/runtime/store.d.ts +307 -0
- package/dist/runtime/store.js +1026 -0
- package/dist/runtime/windowed-minimap-projection.d.ts +28 -0
- package/dist/runtime/windowed-minimap-projection.js +189 -0
- package/dist/runtime/workspace-shortcuts.d.ts +30 -0
- package/dist/runtime/workspace-shortcuts.js +188 -0
- package/dist/sdk-error-copy.d.ts +48 -0
- package/dist/sdk-error-copy.js +182 -0
- package/dist/select-cursor.d.ts +2 -0
- package/dist/select-cursor.js +23 -0
- package/dist/server/admission-cookie.d.ts +38 -0
- package/dist/server/admission-cookie.js +122 -0
- package/dist/server/control-client.d.ts +29 -0
- package/dist/server/control-client.js +22 -0
- package/dist/server/control-errors.d.ts +22 -0
- package/dist/server/control-errors.js +165 -0
- package/dist/server/draft-route.d.ts +12 -0
- package/dist/server/draft-route.js +45 -0
- package/dist/server/extract-token.d.ts +30 -0
- package/dist/server/extract-token.js +98 -0
- package/dist/server/grant.d.ts +128 -0
- package/dist/server/grant.js +395 -0
- package/dist/server/ordinary-read-provenance.d.ts +11 -0
- package/dist/server/ordinary-read-provenance.js +124 -0
- package/dist/server/preview-read-metadata.d.ts +10 -0
- package/dist/server/preview-read-metadata.js +27 -0
- package/dist/server/provenance-frame-builder.d.ts +53 -0
- package/dist/server/provenance-frame-builder.js +102 -0
- package/dist/server/provenance-runtime.d.ts +70 -0
- package/dist/server/provenance-runtime.js +46 -0
- package/dist/server/read-context-command.d.ts +11 -0
- package/dist/server/read-context-command.js +53 -0
- package/dist/server/read-identity.d.ts +3 -0
- package/dist/server/read-identity.js +63 -0
- package/dist/server/read-lifecycle.d.ts +17 -0
- package/dist/server/read-lifecycle.js +52 -0
- package/dist/server/render-frame-provenance.d.ts +133 -0
- package/dist/server/render-frame-provenance.js +676 -0
- package/dist/server/render-id.d.ts +15 -0
- package/dist/server/render-id.js +22 -0
- package/dist/server/route-document-provenance.d.ts +77 -0
- package/dist/server/route-document-provenance.js +1327 -0
- package/dist/server/route-session-cookie.d.ts +33 -0
- package/dist/server/route-session-cookie.js +54 -0
- package/dist/session-projections.d.ts +33 -0
- package/dist/session-projections.js +43 -0
- package/dist/session-subscriber.d.ts +124 -0
- package/dist/session-subscriber.js +79 -0
- package/dist/sha256-fallback.d.ts +30 -0
- package/dist/sha256-fallback.js +126 -0
- package/dist/types.d.ts +446 -0
- package/dist/types.js +85 -0
- package/dist/validators.d.ts +61 -0
- package/dist/validators.js +110 -0
- package/package.json +206 -3
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
import { previewPaintRenderIdentityFromAnchorMap, } from "./multi-frame-anchor-map.js";
|
|
2
|
+
import { previewPaintRenderIdentityEquals, } from "./anchor-map.js";
|
|
3
|
+
import { findPreviewOverlayClickTarget, } from "./overlay-projection.js";
|
|
4
|
+
import { normalizePreviewVariantId } from "../identity/preview-identity.js";
|
|
5
|
+
export function createPreviewV2SourceIdentitySnapshot(input) {
|
|
6
|
+
if (input.ownerMap?.valid !== true)
|
|
7
|
+
return null;
|
|
8
|
+
const routeFrame = activeRouteFrame(input);
|
|
9
|
+
if (routeFrame === null || input.anchorMap === null)
|
|
10
|
+
return null;
|
|
11
|
+
const renderIdentity = previewPaintRenderIdentityFromAnchorMap(input.anchorMap);
|
|
12
|
+
if (renderIdentity === null)
|
|
13
|
+
return null;
|
|
14
|
+
const entries = new Map();
|
|
15
|
+
const markerIdsBySourceKey = new Map();
|
|
16
|
+
for (const owner of input.ownerMap.owners) {
|
|
17
|
+
const ownerFrame = activeFrameForOwner(input, owner);
|
|
18
|
+
if (ownerFrame === null)
|
|
19
|
+
continue;
|
|
20
|
+
const entry = {
|
|
21
|
+
sourceKey: owner.sourceSetId,
|
|
22
|
+
sourceKind: owner.sourceKind,
|
|
23
|
+
frameId: ownerFrame.frameId,
|
|
24
|
+
routeHash: ownerFrame.routeHash,
|
|
25
|
+
variantId: ownerFrame.variantId,
|
|
26
|
+
codeVersion: ownerFrame.codeVersion,
|
|
27
|
+
renderId: ownerFrame.renderId,
|
|
28
|
+
sourceMapBytes: input.sourceMapBytes,
|
|
29
|
+
};
|
|
30
|
+
entries.set(previewV2SourceIdentityRegistryKey({
|
|
31
|
+
documentId: owner.documentId,
|
|
32
|
+
anchoredPath: owner.canonicalPath,
|
|
33
|
+
}), entry);
|
|
34
|
+
for (const anchor of owner.pathAnchors) {
|
|
35
|
+
entries.set(previewV2SourceIdentityRegistryKey({
|
|
36
|
+
documentId: owner.documentId,
|
|
37
|
+
anchoredPath: owner.canonicalPath,
|
|
38
|
+
sliceKey: anchor.key,
|
|
39
|
+
}), entry);
|
|
40
|
+
}
|
|
41
|
+
if (owner.navigationPath !== undefined) {
|
|
42
|
+
entries.set(previewV2SourceIdentityRegistryKey({
|
|
43
|
+
documentId: owner.documentId,
|
|
44
|
+
anchoredPath: owner.navigationPath,
|
|
45
|
+
}), entry);
|
|
46
|
+
for (const anchor of owner.navigationAnchors ?? []) {
|
|
47
|
+
entries.set(previewV2SourceIdentityRegistryKey({
|
|
48
|
+
documentId: owner.documentId,
|
|
49
|
+
anchoredPath: owner.navigationPath,
|
|
50
|
+
sliceKey: anchor.key,
|
|
51
|
+
}), entry);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const markerIds = markerIdsBySourceKey.get(owner.sourceSetId) ?? [];
|
|
55
|
+
markerIds.push(owner.markerId);
|
|
56
|
+
markerIdsBySourceKey.set(owner.sourceSetId, markerIds);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
renderIdentity,
|
|
60
|
+
entries,
|
|
61
|
+
markerIdsBySourceKey,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function createPreviewV2SourceRegistry(input) {
|
|
65
|
+
const sourceMapBytes = input.sourceMapBytes;
|
|
66
|
+
const resolveSourceIdentity = (request) => {
|
|
67
|
+
const owner = findOwnerForStudioTarget(input, request);
|
|
68
|
+
if (owner === null) {
|
|
69
|
+
return cachedSourceIdentityForStudioTarget(input, request);
|
|
70
|
+
}
|
|
71
|
+
const ownerFrame = activeFrameForOwner(input, owner);
|
|
72
|
+
if (ownerFrame === null) {
|
|
73
|
+
return cachedSourceIdentityForStudioTarget(input, request, {
|
|
74
|
+
allowWithValidOwnerMap: true,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
sourceKey: owner.sourceSetId,
|
|
79
|
+
sourceKind: owner.sourceKind,
|
|
80
|
+
frameId: ownerFrame.frameId,
|
|
81
|
+
routeHash: ownerFrame.routeHash,
|
|
82
|
+
variantId: ownerFrame.variantId,
|
|
83
|
+
codeVersion: ownerFrame.codeVersion,
|
|
84
|
+
renderId: ownerFrame.renderId,
|
|
85
|
+
markerIds: [...markerIdsForSourceKey(input, owner.sourceSetId)],
|
|
86
|
+
sourceMapBytes,
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
const resolveActiveRenderTargetCandidates = (sourceKey) => {
|
|
90
|
+
const sourceFrames = activeSourceFramesForSourceKey(input, sourceKey);
|
|
91
|
+
if (sourceFrames.length === 0)
|
|
92
|
+
return [];
|
|
93
|
+
const targets = [];
|
|
94
|
+
for (const { frame, markerIds } of sourceFrames) {
|
|
95
|
+
for (const anchor of frame.anchors) {
|
|
96
|
+
if (!markerIds.has(anchor.markerId))
|
|
97
|
+
continue;
|
|
98
|
+
if (anchor.paintId === undefined || anchor.paintId.length === 0)
|
|
99
|
+
continue;
|
|
100
|
+
targets.push({
|
|
101
|
+
target: {
|
|
102
|
+
renderTargetId: anchor.paintId,
|
|
103
|
+
markerId: anchor.markerId,
|
|
104
|
+
},
|
|
105
|
+
...(anchor.documentRect !== undefined
|
|
106
|
+
? { documentRect: anchor.documentRect }
|
|
107
|
+
: {}),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return targets;
|
|
112
|
+
};
|
|
113
|
+
const resolveActiveRenderTargets = (sourceKey) => resolveActiveRenderTargetCandidates(sourceKey).map((candidate) => candidate.target);
|
|
114
|
+
const resolveActivePaintTarget = (args) => {
|
|
115
|
+
if (input.anchorMap === null || input.ownerMap?.valid !== true)
|
|
116
|
+
return null;
|
|
117
|
+
let resolved = null;
|
|
118
|
+
for (const frame of input.anchorMap.maps) {
|
|
119
|
+
for (const anchor of frame.anchors) {
|
|
120
|
+
if (anchor.paintId !== args.activePaint.paintId ||
|
|
121
|
+
anchor.markerId !== args.activePaint.markerId)
|
|
122
|
+
continue;
|
|
123
|
+
const owner = input.ownerMap.ownerByMarkerId.get(anchor.markerId);
|
|
124
|
+
if (owner === undefined ||
|
|
125
|
+
owner.frameId !== frame.frameId ||
|
|
126
|
+
owner.documentId !== args.owner.documentId ||
|
|
127
|
+
owner.sourceSetId !== args.owner.sourceSetId ||
|
|
128
|
+
owner.markerId !== args.owner.markerId ||
|
|
129
|
+
args.activePaint.sourceSetId !== args.owner.sourceSetId) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (resolved !== null)
|
|
133
|
+
return null;
|
|
134
|
+
resolved = {
|
|
135
|
+
target: {
|
|
136
|
+
renderTargetId: anchor.paintId,
|
|
137
|
+
markerId: anchor.markerId,
|
|
138
|
+
},
|
|
139
|
+
sourceKey: owner.sourceSetId,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return resolved;
|
|
144
|
+
};
|
|
145
|
+
const resolveRevealPayloadForStudioTarget = (args) => {
|
|
146
|
+
const identity = resolveSourceIdentity(args.request);
|
|
147
|
+
if (identity === null) {
|
|
148
|
+
return { ok: false, sourceKey: null, status: "unknownSource" };
|
|
149
|
+
}
|
|
150
|
+
const routeFrame = activeRouteFrame(input);
|
|
151
|
+
if (routeFrame === null || input.anchorMap === null) {
|
|
152
|
+
return {
|
|
153
|
+
ok: false,
|
|
154
|
+
sourceKey: identity.sourceKey,
|
|
155
|
+
status: "routeMissing",
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const owner = findOwnerForStudioTarget(input, args.request);
|
|
159
|
+
const activePaint = owner === null
|
|
160
|
+
? null
|
|
161
|
+
: (input.activePaintFor?.(owner.documentId, owner.sourceSetId) ?? null);
|
|
162
|
+
if (owner !== null &&
|
|
163
|
+
activePaint !== null &&
|
|
164
|
+
activePaintMatchesRenderIdentity(activePaint, input.anchorMap)) {
|
|
165
|
+
const activeTarget = resolveActivePaintTarget({
|
|
166
|
+
activePaint,
|
|
167
|
+
owner,
|
|
168
|
+
});
|
|
169
|
+
if (activeTarget !== null) {
|
|
170
|
+
return {
|
|
171
|
+
ok: true,
|
|
172
|
+
expectedStatus: "found",
|
|
173
|
+
selection: { kind: "active-paint", paintId: activePaint.paintId },
|
|
174
|
+
payload: {
|
|
175
|
+
generation: input.anchorMap.generation,
|
|
176
|
+
routeHash: input.anchorMap.routeHash,
|
|
177
|
+
variantId: input.anchorMap.variantId,
|
|
178
|
+
codeVersion: input.anchorMap.codeVersion,
|
|
179
|
+
renderId: routeFrame.renderId,
|
|
180
|
+
requestId: args.requestId,
|
|
181
|
+
sourceKey: activeTarget.sourceKey,
|
|
182
|
+
targetSelection: "active-paint",
|
|
183
|
+
targets: [activeTarget.target],
|
|
184
|
+
behavior: args.behavior,
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const candidates = resolveActiveRenderTargetCandidates(identity.sourceKey);
|
|
190
|
+
if (candidates.length === 0) {
|
|
191
|
+
return {
|
|
192
|
+
ok: false,
|
|
193
|
+
sourceKey: identity.sourceKey,
|
|
194
|
+
status: "notMounted",
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const fallback = fallbackRenderTarget(candidates, input.currentViewport?.() ?? input.anchorMap.viewport);
|
|
198
|
+
return {
|
|
199
|
+
ok: true,
|
|
200
|
+
expectedStatus: "found",
|
|
201
|
+
selection: {
|
|
202
|
+
kind: fallback.usedViewport
|
|
203
|
+
? "nearest-viewport-fallback"
|
|
204
|
+
: "first-document-fallback",
|
|
205
|
+
paintId: fallback.candidate.target.renderTargetId,
|
|
206
|
+
},
|
|
207
|
+
payload: {
|
|
208
|
+
generation: input.anchorMap.generation,
|
|
209
|
+
routeHash: input.anchorMap.routeHash,
|
|
210
|
+
variantId: input.anchorMap.variantId,
|
|
211
|
+
codeVersion: input.anchorMap.codeVersion,
|
|
212
|
+
renderId: routeFrame.renderId,
|
|
213
|
+
requestId: args.requestId,
|
|
214
|
+
sourceKey: identity.sourceKey,
|
|
215
|
+
targetSelection: fallback.usedViewport
|
|
216
|
+
? "nearest-viewport-fallback"
|
|
217
|
+
: "first-document-fallback",
|
|
218
|
+
targets: [fallback.candidate.target],
|
|
219
|
+
behavior: args.behavior,
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
const resolveRevealPayloadForStudioSlice = (args) => {
|
|
224
|
+
const ownerMap = input.ownerMap;
|
|
225
|
+
if (ownerMap?.valid !== true) {
|
|
226
|
+
return { ok: false, sourceKey: null, status: "unknownSource" };
|
|
227
|
+
}
|
|
228
|
+
const candidates = ownerMap.owners.filter((owner) => owner.documentId === args.request.documentId &&
|
|
229
|
+
ownerAnchors(owner).some((anchor) => anchor.key === args.request.sliceKey));
|
|
230
|
+
const revealTargetsForOwner = (candidate) => resolveActiveRenderTargets(candidate.sourceSetId).filter((target) => target.markerId === candidate.markerId);
|
|
231
|
+
const owner = candidates.find((candidate) => revealTargetsForOwner(candidate).length > 0) ??
|
|
232
|
+
candidates.find((candidate) => activeFrameForOwner(input, candidate)) ??
|
|
233
|
+
candidates[0] ??
|
|
234
|
+
null;
|
|
235
|
+
if (owner === null) {
|
|
236
|
+
return { ok: false, sourceKey: null, status: "unknownSource" };
|
|
237
|
+
}
|
|
238
|
+
const routeFrame = activeRouteFrame(input);
|
|
239
|
+
if (routeFrame === null || input.anchorMap === null) {
|
|
240
|
+
return {
|
|
241
|
+
ok: false,
|
|
242
|
+
sourceKey: owner.sourceSetId,
|
|
243
|
+
status: "routeMissing",
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
// Slice focus is structural and singular. Use the exact owner's first
|
|
247
|
+
// mounted marker to scroll the iframe, while the parent-rendered slice
|
|
248
|
+
// overlay owns the persistent visual. This avoids flashing a field or
|
|
249
|
+
// surfacing an irrelevant "multiple matches" notice.
|
|
250
|
+
const targets = revealTargetsForOwner(owner).slice(0, 1);
|
|
251
|
+
if (targets.length === 0) {
|
|
252
|
+
return {
|
|
253
|
+
ok: false,
|
|
254
|
+
sourceKey: owner.sourceSetId,
|
|
255
|
+
status: "notMounted",
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
ok: true,
|
|
260
|
+
expectedStatus: "found",
|
|
261
|
+
selection: {
|
|
262
|
+
kind: "first-document-fallback",
|
|
263
|
+
paintId: targets[0].renderTargetId,
|
|
264
|
+
},
|
|
265
|
+
payload: {
|
|
266
|
+
generation: input.anchorMap.generation,
|
|
267
|
+
routeHash: input.anchorMap.routeHash,
|
|
268
|
+
variantId: input.anchorMap.variantId,
|
|
269
|
+
codeVersion: input.anchorMap.codeVersion,
|
|
270
|
+
renderId: routeFrame.renderId,
|
|
271
|
+
requestId: args.requestId,
|
|
272
|
+
sourceKey: owner.sourceSetId,
|
|
273
|
+
targetSelection: "first-document-fallback",
|
|
274
|
+
targets,
|
|
275
|
+
behavior: args.behavior,
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
const resolveEditableTargetFromOverlayClick = (payload, options = {}) => {
|
|
280
|
+
const active = input.activeOverlayTargets ?? null;
|
|
281
|
+
if (active === null)
|
|
282
|
+
return null;
|
|
283
|
+
if (options.expectedPresentationDocumentId !== undefined &&
|
|
284
|
+
options.expectedPresentationDocumentId !==
|
|
285
|
+
active.presentationFrameIdentity.documentId) {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
if (active.generation !== payload.generation)
|
|
289
|
+
return null;
|
|
290
|
+
if (active.renderIdentity.routeHash !== payload.routeHash)
|
|
291
|
+
return null;
|
|
292
|
+
if (active.renderIdentity.codeVersion !== payload.codeVersion)
|
|
293
|
+
return null;
|
|
294
|
+
if (active.renderIdentity.renderId !== payload.renderId)
|
|
295
|
+
return null;
|
|
296
|
+
const target = findPreviewOverlayClickTarget(active.targets, payload);
|
|
297
|
+
if (target === null)
|
|
298
|
+
return null;
|
|
299
|
+
const activeVariantId = normalizePreviewVariantId(active.renderIdentity.variantId);
|
|
300
|
+
if (activeVariantId !== null &&
|
|
301
|
+
target.documentId === active.presentationFrameIdentity.documentId) {
|
|
302
|
+
return {
|
|
303
|
+
...target,
|
|
304
|
+
variantId: activeVariantId,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
return target;
|
|
308
|
+
};
|
|
309
|
+
return {
|
|
310
|
+
resolveSourceIdentity,
|
|
311
|
+
resolveActiveRenderTargets,
|
|
312
|
+
resolveRevealPayloadForStudioTarget,
|
|
313
|
+
resolveRevealPayloadForStudioSlice,
|
|
314
|
+
resolveEditableTargetFromOverlayClick,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function findOwnerForStudioTarget(input, request) {
|
|
318
|
+
const ownerMap = input.ownerMap;
|
|
319
|
+
if (ownerMap?.valid !== true)
|
|
320
|
+
return null;
|
|
321
|
+
const candidates = ownerMap.owners.filter((candidate) => {
|
|
322
|
+
if (candidate.documentId !== request.documentId)
|
|
323
|
+
return false;
|
|
324
|
+
if (request.expectedSourceKey !== undefined &&
|
|
325
|
+
candidate.sourceSetId !== request.expectedSourceKey)
|
|
326
|
+
return false;
|
|
327
|
+
if (!ownerPathMatchesRequest(candidate, request))
|
|
328
|
+
return false;
|
|
329
|
+
if (!matchesExpectedSourceKind(candidate, request))
|
|
330
|
+
return false;
|
|
331
|
+
if (!matchesRichTextTextNode(candidate, request))
|
|
332
|
+
return false;
|
|
333
|
+
if (!matchesRichTextSliceEmbed(candidate, request))
|
|
334
|
+
return false;
|
|
335
|
+
if (request.sliceKey === undefined)
|
|
336
|
+
return true;
|
|
337
|
+
return ownerAnchors(candidate).some((anchor) => anchor.key === request.sliceKey);
|
|
338
|
+
});
|
|
339
|
+
if (candidates.length === 0)
|
|
340
|
+
return null;
|
|
341
|
+
if (request.expectedSourceKind !== "richtext")
|
|
342
|
+
return candidates[0] ?? null;
|
|
343
|
+
return ([...candidates].sort((a, b) => richtextOwnerRenderRank(input, a) - richtextOwnerRenderRank(input, b))[0] ?? null);
|
|
344
|
+
}
|
|
345
|
+
function activePaintMatchesRenderIdentity(activePaint, anchorMap) {
|
|
346
|
+
const anchorIdentity = previewPaintRenderIdentityFromAnchorMap(anchorMap);
|
|
347
|
+
return (anchorIdentity !== null &&
|
|
348
|
+
previewPaintRenderIdentityEquals(activePaint.renderIdentity, anchorIdentity));
|
|
349
|
+
}
|
|
350
|
+
function fallbackRenderTarget(candidates, viewport) {
|
|
351
|
+
const first = candidates[0];
|
|
352
|
+
if (!isFiniteRect(viewport)) {
|
|
353
|
+
return { candidate: first, usedViewport: false };
|
|
354
|
+
}
|
|
355
|
+
let nearest = null;
|
|
356
|
+
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
357
|
+
for (const candidate of candidates) {
|
|
358
|
+
if (!isFiniteRect(candidate.documentRect))
|
|
359
|
+
continue;
|
|
360
|
+
const distance = squaredDistanceBetweenRects(candidate.documentRect, viewport);
|
|
361
|
+
if (distance >= nearestDistance)
|
|
362
|
+
continue;
|
|
363
|
+
nearest = candidate;
|
|
364
|
+
nearestDistance = distance;
|
|
365
|
+
}
|
|
366
|
+
return nearest === null
|
|
367
|
+
? { candidate: first, usedViewport: false }
|
|
368
|
+
: { candidate: nearest, usedViewport: true };
|
|
369
|
+
}
|
|
370
|
+
function squaredDistanceBetweenRects(left, right) {
|
|
371
|
+
const horizontalGap = Math.max(right.x - (left.x + left.width), left.x - (right.x + right.width), 0);
|
|
372
|
+
const verticalGap = Math.max(right.y - (left.y + left.height), left.y - (right.y + right.height), 0);
|
|
373
|
+
return horizontalGap * horizontalGap + verticalGap * verticalGap;
|
|
374
|
+
}
|
|
375
|
+
function isFiniteRect(rect) {
|
|
376
|
+
return (rect !== undefined &&
|
|
377
|
+
Number.isFinite(rect.x) &&
|
|
378
|
+
Number.isFinite(rect.y) &&
|
|
379
|
+
Number.isFinite(rect.width) &&
|
|
380
|
+
rect.width >= 0 &&
|
|
381
|
+
Number.isFinite(rect.height) &&
|
|
382
|
+
rect.height >= 0);
|
|
383
|
+
}
|
|
384
|
+
function richtextOwnerRenderRank(input, owner) {
|
|
385
|
+
const frame = activeFrameById(input, owner.frameId);
|
|
386
|
+
if (frame === null)
|
|
387
|
+
return 3;
|
|
388
|
+
const anchors = frame.anchors.filter((anchor) => anchor.markerId === owner.markerId);
|
|
389
|
+
if (anchors.some((anchor) => anchor.carrier !== "coded-text"))
|
|
390
|
+
return 0;
|
|
391
|
+
if (anchors.some((anchor) => anchor.carrier === "coded-text"))
|
|
392
|
+
return 1;
|
|
393
|
+
return 2;
|
|
394
|
+
}
|
|
395
|
+
function ownerPathMatchesRequest(owner, request) {
|
|
396
|
+
return (owner.canonicalPath === request.anchoredPath ||
|
|
397
|
+
owner.navigationPath === request.anchoredPath);
|
|
398
|
+
}
|
|
399
|
+
function ownerAnchors(owner) {
|
|
400
|
+
return [...owner.pathAnchors, ...(owner.navigationAnchors ?? [])];
|
|
401
|
+
}
|
|
402
|
+
function matchesRichTextTextNode(owner, request) {
|
|
403
|
+
return (request.richTextTextNodeIndex === undefined ||
|
|
404
|
+
owner.richTextTextNodeIndex === request.richTextTextNodeIndex);
|
|
405
|
+
}
|
|
406
|
+
function matchesRichTextSliceEmbed(owner, request) {
|
|
407
|
+
if (request.richTextSliceEmbedIndex !== undefined &&
|
|
408
|
+
owner.richTextSliceEmbedIndex !== request.richTextSliceEmbedIndex) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
return (request.richTextSliceEmbedKey === undefined ||
|
|
412
|
+
owner.richTextSliceEmbedKey === request.richTextSliceEmbedKey);
|
|
413
|
+
}
|
|
414
|
+
function cachedSourceIdentityForStudioTarget(input, request, options = {}) {
|
|
415
|
+
if (request.expectedSourceKind === "richtext")
|
|
416
|
+
return null;
|
|
417
|
+
const snapshot = activeSourceIdentitySnapshot(input);
|
|
418
|
+
if (snapshot === null)
|
|
419
|
+
return null;
|
|
420
|
+
const entry = snapshot.entries.get(previewV2SourceIdentityRegistryKey(request)) ?? null;
|
|
421
|
+
if (entry === null)
|
|
422
|
+
return null;
|
|
423
|
+
if (!cachedFrameIdentityStillCurrent(input, entry))
|
|
424
|
+
return null;
|
|
425
|
+
if (input.ownerMap?.valid === true &&
|
|
426
|
+
options.allowWithValidOwnerMap !== true &&
|
|
427
|
+
activeFrameById(input, entry.frameId) !== null) {
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
if (entry.sourceKind === "richtext")
|
|
431
|
+
return null;
|
|
432
|
+
if (!matchesExpectedSourceKind(entry, request))
|
|
433
|
+
return null;
|
|
434
|
+
return {
|
|
435
|
+
...entry,
|
|
436
|
+
markerIds: [...(snapshot.markerIdsBySourceKey.get(entry.sourceKey) ?? [])],
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
function cachedFrameIdentityStillCurrent(input, frame) {
|
|
440
|
+
const activeFrame = activeFrameById(input, frame.frameId);
|
|
441
|
+
return (activeFrame === null ||
|
|
442
|
+
(activeFrame.routeHash === frame.routeHash &&
|
|
443
|
+
normalizePreviewVariantId(activeFrame.variantId) ===
|
|
444
|
+
normalizePreviewVariantId(frame.variantId) &&
|
|
445
|
+
activeFrame.codeVersion === frame.codeVersion &&
|
|
446
|
+
activeFrame.renderId === frame.renderId));
|
|
447
|
+
}
|
|
448
|
+
function matchesExpectedSourceKind(owner, request) {
|
|
449
|
+
return (request.expectedSourceKind === undefined ||
|
|
450
|
+
owner.sourceKind === request.expectedSourceKind);
|
|
451
|
+
}
|
|
452
|
+
function activeSourceIdentitySnapshot(input) {
|
|
453
|
+
const snapshot = input.sourceIdentitySnapshot ?? null;
|
|
454
|
+
if (snapshot === null)
|
|
455
|
+
return null;
|
|
456
|
+
const routeFrame = activeRouteFrameIdentity(input);
|
|
457
|
+
if (routeFrame === null || input.anchorMap === null)
|
|
458
|
+
return null;
|
|
459
|
+
const renderIdentity = previewPaintRenderIdentityFromAnchorMap(input.anchorMap);
|
|
460
|
+
if (renderIdentity === null)
|
|
461
|
+
return null;
|
|
462
|
+
if (!previewPaintRenderIdentityEquals(snapshot.renderIdentity, renderIdentity)) {
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
return snapshot;
|
|
466
|
+
}
|
|
467
|
+
function ownersForSourceKey(input, sourceKey) {
|
|
468
|
+
const ownerMap = input.ownerMap;
|
|
469
|
+
if (ownerMap?.valid !== true)
|
|
470
|
+
return [];
|
|
471
|
+
return ownerMap.owners.filter((owner) => owner.sourceSetId === sourceKey);
|
|
472
|
+
}
|
|
473
|
+
function markerIdsForSourceKey(input, sourceKey) {
|
|
474
|
+
if (input.ownerMap?.valid === true) {
|
|
475
|
+
return new Set(ownersForSourceKey(input, sourceKey).map((owner) => owner.markerId));
|
|
476
|
+
}
|
|
477
|
+
const snapshot = activeSourceIdentitySnapshot(input);
|
|
478
|
+
return new Set(snapshot?.markerIdsBySourceKey.get(sourceKey) ?? []);
|
|
479
|
+
}
|
|
480
|
+
function activeSourceFramesForSourceKey(input, sourceKey) {
|
|
481
|
+
if (input.ownerMap?.valid === true) {
|
|
482
|
+
const markerIdsByFrameId = new Map();
|
|
483
|
+
for (const owner of ownersForSourceKey(input, sourceKey)) {
|
|
484
|
+
const markerIds = markerIdsByFrameId.get(owner.frameId) ?? new Set();
|
|
485
|
+
markerIds.add(owner.markerId);
|
|
486
|
+
markerIdsByFrameId.set(owner.frameId, markerIds);
|
|
487
|
+
}
|
|
488
|
+
return [...markerIdsByFrameId.entries()].flatMap(([frameId, markerIds]) => {
|
|
489
|
+
const frame = activeFrameById(input, frameId);
|
|
490
|
+
return frame === null ? [] : [{ frame, markerIds }];
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
const snapshot = activeSourceIdentitySnapshot(input);
|
|
494
|
+
if (snapshot === null)
|
|
495
|
+
return [];
|
|
496
|
+
const markerIds = new Set(snapshot.markerIdsBySourceKey.get(sourceKey) ?? []);
|
|
497
|
+
if (markerIds.size === 0)
|
|
498
|
+
return [];
|
|
499
|
+
const frameIds = new Set([...snapshot.entries.values()]
|
|
500
|
+
.filter((entry) => entry.sourceKey === sourceKey)
|
|
501
|
+
.map((entry) => entry.frameId));
|
|
502
|
+
return [...frameIds].flatMap((frameId) => {
|
|
503
|
+
const frame = activeFrameById(input, frameId);
|
|
504
|
+
return frame === null ? [] : [{ frame, markerIds }];
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
function activeRouteFrame(input) {
|
|
508
|
+
const routeFrame = activeRouteFrameIdentity(input);
|
|
509
|
+
if (routeFrame === null || input.anchorMap === null)
|
|
510
|
+
return null;
|
|
511
|
+
if (!input.anchorMap.valid || !routeFrame.valid)
|
|
512
|
+
return null;
|
|
513
|
+
return routeFrame;
|
|
514
|
+
}
|
|
515
|
+
function activeFrameForOwner(input, owner) {
|
|
516
|
+
return activeFrameById(input, owner.frameId);
|
|
517
|
+
}
|
|
518
|
+
function activeFrameById(input, frameId) {
|
|
519
|
+
const { sessionId, anchorMap } = input;
|
|
520
|
+
if (sessionId === null || anchorMap === null)
|
|
521
|
+
return null;
|
|
522
|
+
if (anchorMap.pending || !anchorMap.valid)
|
|
523
|
+
return null;
|
|
524
|
+
if (anchorMap.sessionId !== sessionId)
|
|
525
|
+
return null;
|
|
526
|
+
const frame = anchorMap.maps.find((map) => map.frameId === frameId);
|
|
527
|
+
if (frame === undefined)
|
|
528
|
+
return null;
|
|
529
|
+
if (!frame.valid)
|
|
530
|
+
return null;
|
|
531
|
+
if (frame.codeVersion !== anchorMap.codeVersion)
|
|
532
|
+
return null;
|
|
533
|
+
if (frame.renderId.length === 0)
|
|
534
|
+
return null;
|
|
535
|
+
return frame;
|
|
536
|
+
}
|
|
537
|
+
function activeRouteFrameIdentity(input) {
|
|
538
|
+
const { sessionId, anchorMap } = input;
|
|
539
|
+
if (sessionId === null || anchorMap === null)
|
|
540
|
+
return null;
|
|
541
|
+
if (anchorMap.pending)
|
|
542
|
+
return null;
|
|
543
|
+
if (anchorMap.sessionId !== sessionId)
|
|
544
|
+
return null;
|
|
545
|
+
const routeFrame = anchorMap.maps.find((map) => map.frameId === "route");
|
|
546
|
+
if (routeFrame === undefined)
|
|
547
|
+
return null;
|
|
548
|
+
if (routeFrame.routeHash !== anchorMap.routeHash)
|
|
549
|
+
return null;
|
|
550
|
+
if (routeFrame.codeVersion !== anchorMap.codeVersion)
|
|
551
|
+
return null;
|
|
552
|
+
if (routeFrame.renderId.length === 0)
|
|
553
|
+
return null;
|
|
554
|
+
return routeFrame;
|
|
555
|
+
}
|
|
556
|
+
function previewV2SourceIdentityRegistryKey(request) {
|
|
557
|
+
return [
|
|
558
|
+
request.documentId,
|
|
559
|
+
request.anchoredPath,
|
|
560
|
+
request.sliceKey ?? "",
|
|
561
|
+
].join("\u0000");
|
|
562
|
+
}
|