@storystick/preview 0.2.0-rc.5 → 0.2.0-rc.6
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/PUBLIC-API.md +4 -2
- package/dist/.source-hash +1 -1
- package/dist/authoring/runtime-contract.d.ts +13 -2
- package/dist/authoring/runtime-contract.js +1 -1
- package/dist/channel-taxonomy.js +1 -0
- package/dist/framework/preview-copy.d.ts +1 -1
- package/dist/framework/preview-copy.js +1 -1
- package/dist/framework/preview-feedback.js +1 -0
- package/dist/identity/carriers/postmessage.js +7 -16
- package/dist/index.js +12 -17
- package/dist/overlay-label.d.ts +75 -1
- package/dist/overlay-label.js +93 -1
- package/dist/provenance/comment-markers.d.ts +23 -0
- package/dist/provenance/comment-markers.js +65 -0
- package/dist/provenance/markers.js +2 -2
- package/dist/provenance/runtime-script.js +3 -0
- package/dist/query-render.d.ts +13 -0
- package/dist/query-render.js +33 -0
- package/dist/runtime/boot.js +15 -1
- package/dist/runtime/preview-interaction-policy.js +4 -2
- package/dist/runtime/preview-overlay-painter.d.ts +1 -0
- package/dist/runtime/preview-overlay-painter.js +465 -64
- package/dist/runtime/standalone-overlay-controller.d.ts +3 -1
- package/dist/runtime/standalone-overlay-controller.js +11 -4
- package/dist/server/ordinary-read-provenance.js +4 -3
- package/dist/sha256.d.ts +3 -0
- package/dist/sha256.js +13 -0
- package/package.json +12 -4
package/PUBLIC-API.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# @storystick/preview API contract
|
|
2
2
|
|
|
3
|
-
Install this candidate explicitly with `@storystick/preview@0.2.0-rc.
|
|
3
|
+
Install this candidate explicitly with `@storystick/preview@0.2.0-rc.6` after registry bootstrap and publication. This repository alone does not make the candidate or beta channel available on npm.
|
|
4
4
|
|
|
5
|
-
Version 0.2.0-rc.
|
|
5
|
+
Version 0.2.0-rc.6, cohort `sdk-0.2.0-rc.8`. ESM distribution; no CommonJS or universal Edge compatibility is promised.
|
|
6
6
|
|
|
7
7
|
This package supports the integration facades; installing it directly is an advanced use. Reserved contracts are required between SDK packages and must be upgraded with the same cohort. Their public export paths do not promise independent stability.
|
|
8
8
|
|
|
9
9
|
| Entry | Status |
|
|
10
10
|
| --- | --- |
|
|
11
|
+
| `./provenance/comment-markers` | Reserved SDK contract |
|
|
11
12
|
| `.` | Reserved SDK contract |
|
|
12
13
|
| `./runtime/store` | Reserved SDK contract |
|
|
13
14
|
| `./runtime/request-id` | Reserved SDK contract |
|
|
@@ -48,6 +49,7 @@ This package supports the integration facades; installing it directly is an adva
|
|
|
48
49
|
| `./server/*` | Reserved SDK contract |
|
|
49
50
|
| `./provenance/render-context` | Reserved SDK contract |
|
|
50
51
|
| `./provenance/slice-model` | Reserved SDK contract |
|
|
52
|
+
| `./query-render` | Reserved SDK contract |
|
|
51
53
|
|
|
52
54
|
Supported consumer Node versions: `^22.13.0 || ^24.19.0`. The release build toolchain remains Node 24.19.0 and pnpm 9.15.9. Next uses App Router 15.5.28, Sharp 0.35.5 and React/React DOM 19.2.8; Astro uses 7.4.4 with the Node adapter 11.1.9. Browser delivery is verified by bundling; hosted Preview activation and cross-browser behavior require the staging manual check. Source/CLI are Node tools, server entries belong on the server, and browser entries must never receive a server API key.
|
|
53
55
|
|
package/dist/.source-hash
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
ef6958bd732af5b1c0635ec7ec883ee0f7e48cc0fd66bff5c1d9977a56096cf3
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { PreviewCommentMarkers } from '../provenance/comment-markers.js';
|
|
2
|
+
import type { EditorialAnchor } from '@storystick/types/editorial-target';
|
|
1
3
|
import { type StudioContentShapeDescriptor } from '@storystick/types';
|
|
2
4
|
import type { PreviewPerspective, PreviewReadContext } from '@storystick/types/preview-query-targeting';
|
|
3
5
|
import type { PreviewV2RevealSourceRequest, PreviewV2RevealSliceRequest } from '../provenance/reveal-contract.js';
|
|
4
6
|
import type { ImperativeEditorNavigationTarget } from '@storystick/types/editor-destination';
|
|
5
|
-
export declare const STORYSTICK_AUTHORING_RUNTIME_CONTRACT_VERSION:
|
|
7
|
+
export declare const STORYSTICK_AUTHORING_RUNTIME_CONTRACT_VERSION: 13;
|
|
6
8
|
export declare const STORYSTICK_AUTHORING_RUNTIME_GLOBAL: "StorystickAuthoringRuntime";
|
|
7
9
|
export declare const STORYSTICK_AUTHORING_RUNTIME_PATH: "/authoring-runtime/authoring-runtime.js";
|
|
8
10
|
export interface PreviewAuthoringAdmission {
|
|
@@ -42,7 +44,13 @@ export interface PreviewAuthoringPresentation {
|
|
|
42
44
|
pathname: string;
|
|
43
45
|
perspective: PreviewPerspective;
|
|
44
46
|
}
|
|
45
|
-
export type PreviewAuthoringSurface = 'editor' | 'assistant';
|
|
47
|
+
export type PreviewAuthoringSurface = 'editor' | 'assistant' | 'comments';
|
|
48
|
+
export interface PreviewCommentRequest {
|
|
49
|
+
intent?: 'create' | 'view';
|
|
50
|
+
target: PreviewAuthoringTarget;
|
|
51
|
+
anchor?: EditorialAnchor;
|
|
52
|
+
quote?: string;
|
|
53
|
+
}
|
|
46
54
|
export interface PreviewAuthoringRuntimeMountOptions {
|
|
47
55
|
root: ShadowRoot;
|
|
48
56
|
container: HTMLElement;
|
|
@@ -53,6 +61,8 @@ export interface PreviewAuthoringRuntimeMountOptions {
|
|
|
53
61
|
title: HTMLElement;
|
|
54
62
|
trailing: HTMLElement;
|
|
55
63
|
};
|
|
64
|
+
commentRequest?: PreviewCommentRequest;
|
|
65
|
+
onCommentMarkers?(state: PreviewCommentMarkers | null): void;
|
|
56
66
|
assistantThreadId?: string | null;
|
|
57
67
|
onSurface?(surface: PreviewAuthoringSurface): void;
|
|
58
68
|
onAssistantThread?(threadId: string | null): void;
|
|
@@ -82,6 +92,7 @@ export declare function isPreviewAuthoringAdmission(value: unknown, now?: number
|
|
|
82
92
|
export type PreviewAuthoringRuntimeStatus = 'connecting' | 'ready' | 'unauthorized' | 'disposed';
|
|
83
93
|
export interface PreviewAuthoringRuntimeHandle {
|
|
84
94
|
setSurface(surface: PreviewAuthoringSurface | null): void;
|
|
95
|
+
openComments(request: PreviewCommentRequest): void;
|
|
85
96
|
/** A host observation may become obsolete while the current draft is saved. */
|
|
86
97
|
open(target: PreviewAuthoringTarget, isCurrent?: () => boolean): Promise<void>;
|
|
87
98
|
dispose(): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isStudioContentShapeDescriptor } from '@storystick/types';
|
|
2
|
-
export const STORYSTICK_AUTHORING_RUNTIME_CONTRACT_VERSION =
|
|
2
|
+
export const STORYSTICK_AUTHORING_RUNTIME_CONTRACT_VERSION = 13;
|
|
3
3
|
export const STORYSTICK_AUTHORING_RUNTIME_GLOBAL = 'StorystickAuthoringRuntime';
|
|
4
4
|
export const STORYSTICK_AUTHORING_RUNTIME_PATH = '/authoring-runtime/authoring-runtime.js';
|
|
5
5
|
export function isPreviewAuthoringAdmission(value, now = Date.now()) {
|
package/dist/channel-taxonomy.js
CHANGED
|
@@ -26,6 +26,7 @@ export function classifyPreviewEnvelopeType(type) {
|
|
|
26
26
|
case 'storystick.preview.overlay-ready':
|
|
27
27
|
case 'storystick.preview.overlay-click':
|
|
28
28
|
case 'storystick.preview.iframe-interaction':
|
|
29
|
+
case 'storystick.preview.host-interaction':
|
|
29
30
|
return 'overlay';
|
|
30
31
|
case 'storystick.preview.v2.reveal-source':
|
|
31
32
|
case 'storystick.preview.v2.reveal-result':
|
|
@@ -54,7 +54,7 @@ export declare const PREVIEW_COPY: {
|
|
|
54
54
|
};
|
|
55
55
|
readonly "connection-delayed": {
|
|
56
56
|
readonly title: "Preview is taking longer";
|
|
57
|
-
readonly body: "
|
|
57
|
+
readonly body: "We’re still waiting for the preview connection.";
|
|
58
58
|
};
|
|
59
59
|
readonly "connection-unconfirmed": {
|
|
60
60
|
readonly title: "Preview couldn’t connect";
|
|
@@ -11,7 +11,7 @@ export const PREVIEW_COPY = {
|
|
|
11
11
|
"preparing": { "title": "Preparing preview", "body": "Your site will appear here when it’s ready." },
|
|
12
12
|
"page-loading": { "title": "Loading your site", "body": "Waiting for the page to respond." },
|
|
13
13
|
"connecting": { "title": "Connecting preview", "body": "Connecting this site to Studio." },
|
|
14
|
-
"connection-delayed": { "title": "Preview is taking longer", "body": "
|
|
14
|
+
"connection-delayed": { "title": "Preview is taking longer", "body": "We’re still waiting for the preview connection." },
|
|
15
15
|
"connection-unconfirmed": { "title": "Preview couldn’t connect", "body": "The site didn’t confirm its connection to Studio. Check that it is running and accessible, then retry." },
|
|
16
16
|
"workspace-creating": { "title": "Starting computer", "body": "Preparing the computer for this working version." },
|
|
17
17
|
"workspace-restoring": { "title": "Waking computer", "body": "Restoring its saved work." },
|
|
@@ -68,6 +68,7 @@ export const PREVIEW_FEEDBACK = {
|
|
|
68
68
|
'runtime.preview_context_superseded': feedback('selection-superseded', 'page', 'choose-version', 'attention', { invalidatesPresentation: true }),
|
|
69
69
|
'runtime.schema_sync_delayed': feedback('visual-connecting', 'visual-editing', null, 'neutral'),
|
|
70
70
|
'runtime.cache_unavailable': visualLimited,
|
|
71
|
+
'runtime.provenance_unavailable': visualLimited,
|
|
71
72
|
'runtime.schema_delivery_failed': visualLimited,
|
|
72
73
|
'runtime.schema_upgrade_required': feedback('visual-update', 'visual-editing', 'editor', 'attention'),
|
|
73
74
|
'runtime.suspicious_codeword_sink': feedback('marker-diagnostic', 'visual-editing', null, 'attention', { audience: 'developer' }),
|
|
@@ -116,23 +116,14 @@ export function attachBroadcastListener(args) {
|
|
|
116
116
|
if (!parsed.ok)
|
|
117
117
|
return;
|
|
118
118
|
args.onBroadcast(parsed.identity, event.origin);
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
// postMessage as a liveness proof. An authenticated + idle
|
|
122
|
-
// iframe doesn't naturally produce any reply postMessage when it
|
|
123
|
-
// receives a broadcast, so the alive path would false-negative
|
|
124
|
-
// (codex review R2 P2). Echo the broadcast back to Studio as a
|
|
125
|
-
// session-request envelope — handleSessionRequestEnvelope already
|
|
126
|
-
// routes session-requests for the queue-drain flow, and the
|
|
127
|
-
// existing 8/10s per-Window rate limiter caps the extra traffic.
|
|
128
|
-
// Origin policy : reply to `event.origin` (the broadcast's
|
|
129
|
-
// sender), not '*' — once the iframe has received a confirmed
|
|
130
|
-
// broadcast the parent origin is known.
|
|
119
|
+
// Reply within the existing recovery envelope. The broadcast request ID
|
|
120
|
+
// and confirmed session correlate a wake probe without a new wire type.
|
|
131
121
|
try {
|
|
132
|
-
const reply =
|
|
133
|
-
projectId: args.expectedProjectId,
|
|
134
|
-
|
|
135
|
-
|
|
122
|
+
const reply = {
|
|
123
|
+
...buildSessionRequest({ projectId: args.expectedProjectId, reason: 'recovery' }),
|
|
124
|
+
sessionId: parsed.identity.sessionId,
|
|
125
|
+
requestId: event.data.requestId,
|
|
126
|
+
};
|
|
136
127
|
// `event.source` is typed as MessageEventSource (Window | MessagePort | ServiceWorker)
|
|
137
128
|
// ; postMessage exists on Window. Defensive try/catch handles
|
|
138
129
|
// exotic source types without breaking the broadcast handler.
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readStandalonePreviewSessionId } from './identity/browser-context.js';
|
|
2
2
|
import { createPreviewRequestId } from './runtime/request-id.js';
|
|
3
|
+
import { sha256Hex as computeRouteHash } from './sha256.js';
|
|
3
4
|
/**
|
|
4
5
|
* @storystick/preview — Visual editing overlay
|
|
5
6
|
*
|
|
@@ -35,25 +36,9 @@ import { startStandaloneOverlayController } from './runtime/standalone-overlay-c
|
|
|
35
36
|
* of FIPS PUB 180-4 §6.2. Production paths (HTTPS↔HTTPS) always hit
|
|
36
37
|
* the Web Crypto branch.
|
|
37
38
|
*/
|
|
38
|
-
async function computeRouteHash(routeUrl) {
|
|
39
|
-
// crypto.subtle returns undefined in non-secure contexts ; guard
|
|
40
|
-
// explicitly rather than letting `crypto.subtle.digest` throw a
|
|
41
|
-
// `TypeError: Cannot read properties of undefined` every snapshot tick.
|
|
42
|
-
if (typeof crypto !== 'undefined' &&
|
|
43
|
-
crypto.subtle !== undefined &&
|
|
44
|
-
typeof crypto.subtle.digest === 'function') {
|
|
45
|
-
const bytes = new TextEncoder().encode(routeUrl);
|
|
46
|
-
const digest = await crypto.subtle.digest('SHA-256', bytes);
|
|
47
|
-
return Array.from(new Uint8Array(digest))
|
|
48
|
-
.map((b) => b.toString(16).padStart(2, '0'))
|
|
49
|
-
.join('');
|
|
50
|
-
}
|
|
51
|
-
const { sha256HexFallback } = await import('./sha256-fallback.js');
|
|
52
|
-
return sha256HexFallback(routeUrl);
|
|
53
|
-
}
|
|
54
39
|
import { startFormContractReporter, } from './runtime/form-contract-reporter.js';
|
|
55
40
|
import { validateNavigate, validateOverlayClear, validateOverlayMap, } from './validators.js';
|
|
56
|
-
import { applyPreviewOverlayMap, clearPreviewOverlayPaint, installPreviewEditInteractionGuard, } from './runtime/preview-overlay-painter.js';
|
|
41
|
+
import { applyPreviewOverlayMap, clearPreviewOverlayPaint, dismissPreviewOverlayMenu, installPreviewEditInteractionGuard, } from './runtime/preview-overlay-painter.js';
|
|
57
42
|
import { getAnchorFromPreviewClickEvent, installMomentaryNavigateKeyRelay, normalizeMomentaryNavigateLinkClick, } from './runtime/momentary-navigate.js';
|
|
58
43
|
import { getNavigateHandler, getReloadHandler, hasNavigateHandler, } from './nav-handler.js';
|
|
59
44
|
import { setRouterSubscriber, } from './router-subscriber.js';
|
|
@@ -594,6 +579,16 @@ export function activate(config) {
|
|
|
594
579
|
return;
|
|
595
580
|
}
|
|
596
581
|
}
|
|
582
|
+
if (base.ok && base.message.type === 'storystick.preview.host-interaction') {
|
|
583
|
+
if (parentOriginLock === null || event.source !== window.parent)
|
|
584
|
+
return;
|
|
585
|
+
if (event.origin !== parentOriginLock)
|
|
586
|
+
return;
|
|
587
|
+
if (base.message.sessionId !== config.sessionId || base.message.projectId !== projectId)
|
|
588
|
+
return;
|
|
589
|
+
dismissPreviewOverlayMenu();
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
597
592
|
// ADR-108 D2 — interaction-mode envelope routed first because
|
|
598
593
|
// it has its own discriminator + parentOrigin lock guard. The
|
|
599
594
|
// `validateNavigate` path below short-circuits on the wrong
|
package/dist/overlay-label.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared visual
|
|
2
|
+
* Shared visual primitives for preview overlay labels and discussion pins.
|
|
3
3
|
*
|
|
4
4
|
* Studio renders slice labels in its React overlay while the preview runtime
|
|
5
5
|
* renders field labels directly in the customer iframe. They intentionally
|
|
@@ -7,6 +7,68 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const PREVIEW_OVERLAY_LABEL_GAP_PX = 4;
|
|
9
9
|
export declare const PREVIEW_OVERLAY_LABEL_HEIGHT_PX = 20;
|
|
10
|
+
/** One compact pin vocabulary in the Studio and the isolated iframe painter. */
|
|
11
|
+
export declare const COMMENT_MARKER_SIZE_PX = 28;
|
|
12
|
+
export declare const COMMENT_MARKER_GAP_PX = 6;
|
|
13
|
+
export declare const COMMENT_AVATAR_STEP_PX = 12;
|
|
14
|
+
export type CommentMarkerAnchorCorner = 'top-left' | 'bottom-right';
|
|
15
|
+
/** Match the pointer to the final placement, including collision adjustments. */
|
|
16
|
+
export declare function commentMarkerAnchorCorner(target: {
|
|
17
|
+
top: number;
|
|
18
|
+
}, position: {
|
|
19
|
+
y: number;
|
|
20
|
+
}): CommentMarkerAnchorCorner;
|
|
21
|
+
export declare function commentMarkerWidth(avatarCount?: number): number;
|
|
22
|
+
export declare function commentAvatarVisualStyle(index: number, hue: number, anchorCorner?: CommentMarkerAnchorCorner): {
|
|
23
|
+
readonly position: "absolute";
|
|
24
|
+
readonly left: string;
|
|
25
|
+
readonly right: string;
|
|
26
|
+
readonly top: "2px";
|
|
27
|
+
readonly width: "24px";
|
|
28
|
+
readonly height: "24px";
|
|
29
|
+
readonly boxSizing: "border-box";
|
|
30
|
+
readonly borderRadius: "50%";
|
|
31
|
+
readonly border: "2px solid var(--ss-surface-card, #fff)";
|
|
32
|
+
readonly overflow: "hidden";
|
|
33
|
+
readonly zIndex: number;
|
|
34
|
+
readonly display: "inline-flex";
|
|
35
|
+
readonly alignItems: "center";
|
|
36
|
+
readonly justifyContent: "center";
|
|
37
|
+
readonly background: `oklch(0.93 0.035 ${number})`;
|
|
38
|
+
readonly color: `oklch(0.34 0.07 ${number})`;
|
|
39
|
+
readonly font: "600 10px/1 \"Inter Variable\", ui-sans-serif, system-ui, sans-serif";
|
|
40
|
+
};
|
|
41
|
+
export declare function commentMarkerVisualStyle(unread: boolean, anchorCorner?: CommentMarkerAnchorCorner): {
|
|
42
|
+
readonly width: "28px";
|
|
43
|
+
readonly boxSizing: "border-box";
|
|
44
|
+
readonly minWidth: "28px";
|
|
45
|
+
readonly height: "28px";
|
|
46
|
+
readonly padding: "0";
|
|
47
|
+
readonly border: "2px solid var(--ss-surface-card, #fff)";
|
|
48
|
+
readonly borderRadius: "50% 50% 5px 50%" | "5px 50% 50% 50%";
|
|
49
|
+
readonly left: "0" | "auto";
|
|
50
|
+
readonly right: "0" | "auto";
|
|
51
|
+
readonly background: "var(--ss-color-notification-dot, oklch(0.58 0.19 253))" | "var(--ss-text-secondary, #666)";
|
|
52
|
+
readonly color: "var(--ss-surface-card, #fff)";
|
|
53
|
+
readonly boxShadow: "0 1px 4px rgb(0 0 0 / .18)";
|
|
54
|
+
readonly font: "600 11px/1 \"Inter Variable\", ui-sans-serif, system-ui, sans-serif";
|
|
55
|
+
readonly fontVariantNumeric: "tabular-nums";
|
|
56
|
+
};
|
|
57
|
+
/** Keep pins beside their target, inside the viewport and clear of earlier pins. */
|
|
58
|
+
export declare function placeCommentMarker(target: {
|
|
59
|
+
right: number;
|
|
60
|
+
top: number;
|
|
61
|
+
}, viewport: {
|
|
62
|
+
width: number;
|
|
63
|
+
height: number;
|
|
64
|
+
}, occupied?: ReadonlyArray<{
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
width?: number;
|
|
68
|
+
}>, width?: number): {
|
|
69
|
+
x: number;
|
|
70
|
+
y: number;
|
|
71
|
+
};
|
|
10
72
|
export type PreviewOverlayTone = 'default' | 'model';
|
|
11
73
|
export declare const PREVIEW_OVERLAY_VISUAL_STYLES: {
|
|
12
74
|
readonly default: {
|
|
@@ -58,6 +120,18 @@ export declare function previewOverlayLabelVisualStyle(tone: PreviewOverlayTone)
|
|
|
58
120
|
readonly color: "white";
|
|
59
121
|
readonly boxShadow: "0 0 0 1px oklch(1 0 0 / 0.72)";
|
|
60
122
|
};
|
|
123
|
+
/** A compact action tab joined to the overlay's top-right edge. */
|
|
124
|
+
export declare function previewOverlayActionVisualStyle(tone: PreviewOverlayTone): {
|
|
125
|
+
readonly width: "24px";
|
|
126
|
+
readonly minWidth: "24px";
|
|
127
|
+
readonly height: "20px";
|
|
128
|
+
readonly padding: "0";
|
|
129
|
+
readonly border: "0";
|
|
130
|
+
readonly borderRadius: "0 0 0 4px";
|
|
131
|
+
readonly color: "white";
|
|
132
|
+
readonly background: "oklch(0.614 0.194 257 / 0.9)" | "oklch(0.635 0.19 322 / 0.9)";
|
|
133
|
+
readonly boxShadow: "none";
|
|
134
|
+
};
|
|
61
135
|
export interface PreviewOverlayLabelHorizontalPositionInput {
|
|
62
136
|
targetLeft: number;
|
|
63
137
|
targetWidth: number;
|
package/dist/overlay-label.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared visual
|
|
2
|
+
* Shared visual primitives for preview overlay labels and discussion pins.
|
|
3
3
|
*
|
|
4
4
|
* Studio renders slice labels in its React overlay while the preview runtime
|
|
5
5
|
* renders field labels directly in the customer iframe. They intentionally
|
|
@@ -7,6 +7,84 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export const PREVIEW_OVERLAY_LABEL_GAP_PX = 4;
|
|
9
9
|
export const PREVIEW_OVERLAY_LABEL_HEIGHT_PX = 20;
|
|
10
|
+
/** One compact pin vocabulary in the Studio and the isolated iframe painter. */
|
|
11
|
+
export const COMMENT_MARKER_SIZE_PX = 28;
|
|
12
|
+
export const COMMENT_MARKER_GAP_PX = 6;
|
|
13
|
+
export const COMMENT_AVATAR_STEP_PX = 12;
|
|
14
|
+
/** Match the pointer to the final placement, including collision adjustments. */
|
|
15
|
+
export function commentMarkerAnchorCorner(target, position) {
|
|
16
|
+
return position.y + COMMENT_MARKER_SIZE_PX <= target.top ? 'bottom-right' : 'top-left';
|
|
17
|
+
}
|
|
18
|
+
export function commentMarkerWidth(avatarCount = 0) {
|
|
19
|
+
return COMMENT_MARKER_SIZE_PX + Math.min(3, Math.max(0, avatarCount)) * COMMENT_AVATAR_STEP_PX;
|
|
20
|
+
}
|
|
21
|
+
export function commentAvatarVisualStyle(index, hue, anchorCorner = 'top-left') {
|
|
22
|
+
const offset = `${4 + (index + 1) * COMMENT_AVATAR_STEP_PX}px`;
|
|
23
|
+
return {
|
|
24
|
+
position: 'absolute',
|
|
25
|
+
left: anchorCorner === 'bottom-right' ? 'auto' : offset,
|
|
26
|
+
right: anchorCorner === 'bottom-right' ? offset : 'auto',
|
|
27
|
+
top: '2px',
|
|
28
|
+
width: '24px', height: '24px', boxSizing: 'border-box', borderRadius: '50%',
|
|
29
|
+
border: '2px solid var(--ss-surface-card, #fff)', overflow: 'hidden',
|
|
30
|
+
zIndex: 3 - index, display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
|
|
31
|
+
background: `oklch(0.93 0.035 ${hue})`, color: `oklch(0.34 0.07 ${hue})`,
|
|
32
|
+
font: '600 10px/1 "Inter Variable", ui-sans-serif, system-ui, sans-serif',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function commentMarkerVisualStyle(unread, anchorCorner = 'top-left') {
|
|
36
|
+
return {
|
|
37
|
+
width: `${COMMENT_MARKER_SIZE_PX}px`,
|
|
38
|
+
boxSizing: 'border-box',
|
|
39
|
+
minWidth: `${COMMENT_MARKER_SIZE_PX}px`,
|
|
40
|
+
height: `${COMMENT_MARKER_SIZE_PX}px`,
|
|
41
|
+
padding: '0',
|
|
42
|
+
border: '2px solid var(--ss-surface-card, #fff)',
|
|
43
|
+
borderRadius: anchorCorner === 'bottom-right' ? '50% 50% 5px 50%' : '5px 50% 50% 50%',
|
|
44
|
+
left: anchorCorner === 'bottom-right' ? 'auto' : '0',
|
|
45
|
+
right: anchorCorner === 'bottom-right' ? '0' : 'auto',
|
|
46
|
+
background: unread
|
|
47
|
+
? 'var(--ss-color-notification-dot, oklch(0.58 0.19 253))'
|
|
48
|
+
: 'var(--ss-text-secondary, #666)',
|
|
49
|
+
color: 'var(--ss-surface-card, #fff)',
|
|
50
|
+
boxShadow: '0 1px 4px rgb(0 0 0 / .18)',
|
|
51
|
+
font: '600 11px/1 "Inter Variable", ui-sans-serif, system-ui, sans-serif',
|
|
52
|
+
fontVariantNumeric: 'tabular-nums',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Keep pins beside their target, inside the viewport and clear of earlier pins. */
|
|
56
|
+
export function placeCommentMarker(target, viewport, occupied = [], width = COMMENT_MARKER_SIZE_PX) {
|
|
57
|
+
const size = COMMENT_MARKER_SIZE_PX;
|
|
58
|
+
const step = size + COMMENT_MARKER_GAP_PX;
|
|
59
|
+
const maxX = Math.max(4, viewport.width - width - 4);
|
|
60
|
+
const maxY = Math.max(4, viewport.height - size - 4);
|
|
61
|
+
const clamp = ({ x, y }) => ({
|
|
62
|
+
x: Math.max(4, Math.min(maxX, x)),
|
|
63
|
+
y: Math.max(4, Math.min(maxY, y)),
|
|
64
|
+
});
|
|
65
|
+
const fitsBeside = target.right + COMMENT_MARKER_GAP_PX <= maxX;
|
|
66
|
+
const desired = clamp({
|
|
67
|
+
x: fitsBeside
|
|
68
|
+
? target.right + COMMENT_MARKER_GAP_PX
|
|
69
|
+
: target.right - width - COMMENT_MARKER_GAP_PX,
|
|
70
|
+
// The inset fallback stays above the overlay's top-right menu tab.
|
|
71
|
+
y: fitsBeside ? target.top : target.top >= step + 4 ? target.top - step : target.top + 26,
|
|
72
|
+
});
|
|
73
|
+
const candidates = [desired, ...occupied.flatMap(pin => [
|
|
74
|
+
{ x: desired.x, y: pin.y + step },
|
|
75
|
+
{ x: desired.x, y: pin.y - step },
|
|
76
|
+
{ x: pin.x - width - COMMENT_MARKER_GAP_PX, y: desired.y },
|
|
77
|
+
{ x: pin.x + (pin.width ?? size) + COMMENT_MARKER_GAP_PX, y: desired.y },
|
|
78
|
+
])].map(clamp);
|
|
79
|
+
candidates.sort((a, b) => Math.hypot(a.x - desired.x, a.y - desired.y) - Math.hypot(b.x - desired.x, b.y - desired.y));
|
|
80
|
+
return candidates.find(pin => {
|
|
81
|
+
const overlapsMenu = pin.x < target.right + 4 && pin.x + width > target.right - 28 &&
|
|
82
|
+
pin.y < target.top + 24 && pin.y + size > target.top - 4;
|
|
83
|
+
return !overlapsMenu && occupied.every(other => pin.x + width + COMMENT_MARKER_GAP_PX <= other.x ||
|
|
84
|
+
other.x + (other.width ?? size) + COMMENT_MARKER_GAP_PX <= pin.x ||
|
|
85
|
+
Math.abs(pin.y - other.y) >= step);
|
|
86
|
+
}) ?? desired;
|
|
87
|
+
}
|
|
10
88
|
export const PREVIEW_OVERLAY_VISUAL_STYLES = {
|
|
11
89
|
default: {
|
|
12
90
|
color: 'oklch(0.614 0.194 257 / 0.9)',
|
|
@@ -40,6 +118,20 @@ export function previewOverlayVisualStyle(tone) {
|
|
|
40
118
|
export function previewOverlayLabelVisualStyle(tone) {
|
|
41
119
|
return PREVIEW_OVERLAY_LABEL_VISUAL_STYLES[tone];
|
|
42
120
|
}
|
|
121
|
+
/** A compact action tab joined to the overlay's top-right edge. */
|
|
122
|
+
export function previewOverlayActionVisualStyle(tone) {
|
|
123
|
+
return {
|
|
124
|
+
width: '24px',
|
|
125
|
+
minWidth: '24px',
|
|
126
|
+
height: `${PREVIEW_OVERLAY_LABEL_HEIGHT_PX}px`,
|
|
127
|
+
padding: '0',
|
|
128
|
+
border: '0',
|
|
129
|
+
borderRadius: '0 0 0 4px',
|
|
130
|
+
color: 'white',
|
|
131
|
+
background: PREVIEW_OVERLAY_VISUAL_STYLES[tone].color,
|
|
132
|
+
boxShadow: 'none',
|
|
133
|
+
};
|
|
134
|
+
}
|
|
43
135
|
/**
|
|
44
136
|
* Prefer the target's right edge while the label fits inside it. A label wider
|
|
45
137
|
* than its target instead grows from the target's left edge, unless that would
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type EditorialAnchor, type EditorialTarget } from "@storystick/types/editorial-target";
|
|
2
|
+
import type { PreviewPerspective } from "@storystick/types/preview-query-targeting";
|
|
3
|
+
import type { PreviewCommentAvatar, PreviewOverlayMapPayload } from "@storystick/transport-allowlist";
|
|
4
|
+
import type { PreviewOverlayClickTarget } from "./overlay-projection.js";
|
|
5
|
+
/** Private metadata supplied by an admitted authoring host, never by page content. */
|
|
6
|
+
export interface PreviewCommentMarkers {
|
|
7
|
+
target: EditorialTarget;
|
|
8
|
+
markers: Array<{
|
|
9
|
+
anchor: EditorialAnchor;
|
|
10
|
+
unread: boolean;
|
|
11
|
+
participants?: Array<PreviewCommentAvatar & {
|
|
12
|
+
userId: string;
|
|
13
|
+
}>;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export declare function uniqueCommentParticipants<T extends {
|
|
17
|
+
userId: string;
|
|
18
|
+
}>(participants: Iterable<T>): T[];
|
|
19
|
+
export declare function previewCommentCount(address: PreviewOverlayClickTarget, state: PreviewCommentMarkers | null, perspective: PreviewPerspective | null): {
|
|
20
|
+
count: number;
|
|
21
|
+
unread: boolean;
|
|
22
|
+
};
|
|
23
|
+
export declare function withPreviewCommentMarkers(payload: PreviewOverlayMapPayload, targets: ReadonlyMap<string, PreviewOverlayClickTarget>, state: PreviewCommentMarkers | null, perspective: PreviewPerspective | null): PreviewOverlayMapPayload;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { editorialAnchorKey, editorialPathFromNavigation, } from "@storystick/types/editorial-target";
|
|
2
|
+
import { overlayEditorLocale, overlayEditorTarget } from "./editor-target.js";
|
|
3
|
+
export function uniqueCommentParticipants(participants) {
|
|
4
|
+
const unique = new Map();
|
|
5
|
+
for (const person of participants) {
|
|
6
|
+
if (!unique.has(person.userId))
|
|
7
|
+
unique.set(person.userId, person);
|
|
8
|
+
if (unique.size === 3)
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
return [...unique.values()];
|
|
12
|
+
}
|
|
13
|
+
function matchingCommentMarkers(address, state, perspective) {
|
|
14
|
+
const navigation = overlayEditorTarget(address);
|
|
15
|
+
if (!state ||
|
|
16
|
+
!perspective ||
|
|
17
|
+
address.sourceKind === "model" ||
|
|
18
|
+
address.documentId !== state.target.documentId ||
|
|
19
|
+
navigation.kind !== "field" ||
|
|
20
|
+
(overlayEditorLocale(address, state.target.locale) ?? "default") !==
|
|
21
|
+
state.target.locale)
|
|
22
|
+
return [];
|
|
23
|
+
const scope = state.target.scope;
|
|
24
|
+
if (perspective.kind === "published"
|
|
25
|
+
? scope.kind !== "published"
|
|
26
|
+
: scope.kind === "published")
|
|
27
|
+
return [];
|
|
28
|
+
if (perspective.kind !== "published") {
|
|
29
|
+
const variantId = address.variantId ?? address.readScope?.appliedVariantId ?? null;
|
|
30
|
+
const releaseId = address.readScope?.appliedReleaseId ?? null;
|
|
31
|
+
if (variantId
|
|
32
|
+
? scope.kind !== "variant" || scope.variantId !== variantId
|
|
33
|
+
: releaseId
|
|
34
|
+
? scope.kind !== "release" || scope.releaseId !== releaseId
|
|
35
|
+
: scope.kind !== "living")
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
const path = editorialPathFromNavigation(navigation.path, navigation.anchors);
|
|
39
|
+
if (!path)
|
|
40
|
+
return [];
|
|
41
|
+
const key = editorialAnchorKey({ kind: "field", path });
|
|
42
|
+
const rows = state.markers.filter((m) => m.anchor.kind !== "document" &&
|
|
43
|
+
editorialAnchorKey({ kind: "field", path: m.anchor.path }) === key);
|
|
44
|
+
return rows;
|
|
45
|
+
}
|
|
46
|
+
export function previewCommentCount(address, state, perspective) {
|
|
47
|
+
const rows = matchingCommentMarkers(address, state, perspective);
|
|
48
|
+
return { count: rows.length, unread: rows.some(row => row.unread) };
|
|
49
|
+
}
|
|
50
|
+
export function withPreviewCommentMarkers(payload, targets, state, perspective) {
|
|
51
|
+
return {
|
|
52
|
+
...payload,
|
|
53
|
+
items: payload.items.map((item) => {
|
|
54
|
+
const address = targets.get(item.paintKey);
|
|
55
|
+
const rows = address ? matchingCommentMarkers(address, state, perspective) : [];
|
|
56
|
+
return {
|
|
57
|
+
...item,
|
|
58
|
+
commentCount: rows.length,
|
|
59
|
+
commentUnread: rows.some(row => row.unread),
|
|
60
|
+
commentAvatars: uniqueCommentParticipants(rows.flatMap(row => row.participants ?? []))
|
|
61
|
+
.map(({ userId: _userId, ...avatar }) => avatar),
|
|
62
|
+
};
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { normalizePreviewVariantId } from '../identity/preview-identity.js';
|
|
2
2
|
import { hasCoherentPreviewProvenanceSourceIdentity } from './source-identity.js';
|
|
3
|
+
import { sha256Bytes } from '../sha256.js';
|
|
3
4
|
export async function createDirectEditMarkerId(input) {
|
|
4
5
|
const payload = JSON.stringify([
|
|
5
6
|
input.sessionId ?? null,
|
|
@@ -11,8 +12,7 @@ export async function createDirectEditMarkerId(input) {
|
|
|
11
12
|
input.renderId,
|
|
12
13
|
input.sourceSetId,
|
|
13
14
|
]);
|
|
14
|
-
|
|
15
|
-
return `p_${base64url(new Uint8Array(digest)).slice(0, 22)}`;
|
|
15
|
+
return `p_${base64url(await sha256Bytes(payload)).slice(0, 22)}`;
|
|
16
16
|
}
|
|
17
17
|
export function validateProvenanceFrame(frame, authoritativeSet) {
|
|
18
18
|
if (frame.routeHash !== authoritativeSet.routeHash)
|
|
@@ -2213,5 +2213,8 @@ export const previewProvenanceRuntimeScript = /* @__PURE__ */ (() => String.raw
|
|
|
2213
2213
|
// to replay its current contract only after our message listener is installed;
|
|
2214
2214
|
// a previously posted render-mode cannot establish this reporter's identity.
|
|
2215
2215
|
if (window.parent !== window) window.parent.postMessage({ type: 'ready' }, studioTargetOrigin())
|
|
2216
|
+
// The entry flag guards against duplicate partial installations; completion
|
|
2217
|
+
// is separate so the framework loader can distinguish load from execution.
|
|
2218
|
+
window.__ssPreviewProvenanceRuntimeReady = true
|
|
2216
2219
|
})()
|
|
2217
2220
|
`)();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PreviewProvenanceReadLifecycle } from '@storystick/client/internal';
|
|
2
|
+
import type { PreviewProvenanceEditableTextPathManifest } from './provenance/editable-leaf.js';
|
|
3
|
+
import { type PreviewPrimaryPage } from './provenance/read-carrier.js';
|
|
4
|
+
/** Public render rules, never credentials or proof that a browser read occurred. */
|
|
5
|
+
export interface PreviewQueryRenderDefinition {
|
|
6
|
+
readonly version: 1;
|
|
7
|
+
readonly codeVersion: string;
|
|
8
|
+
readonly manifest: PreviewProvenanceEditableTextPathManifest;
|
|
9
|
+
/** Explicit route identity; attached only when that document is read again. */
|
|
10
|
+
readonly primaryPage?: PreviewPrimaryPage;
|
|
11
|
+
}
|
|
12
|
+
/** Use the same provenance preparation after a fresh, authenticated browser read. */
|
|
13
|
+
export declare function createPreviewQueryReadLifecycle(definition: PreviewQueryRenderDefinition, projectId: string): PreviewProvenanceReadLifecycle;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createPreviewReadLifecycle } from './server/read-lifecycle.js';
|
|
2
|
+
import { selectPreviewPrimaryPage } from './provenance/read-carrier.js';
|
|
3
|
+
/** Use the same provenance preparation after a fresh, authenticated browser read. */
|
|
4
|
+
export function createPreviewQueryReadLifecycle(definition, projectId) {
|
|
5
|
+
if (definition.version !== 1 || typeof definition.codeVersion !== 'string' ||
|
|
6
|
+
!definition.codeVersion || !definition.manifest || typeof definition.manifest !== 'object') {
|
|
7
|
+
throw new TypeError('Invalid Preview query render definition.');
|
|
8
|
+
}
|
|
9
|
+
if (definition.primaryPage && !selectPreviewPrimaryPage([definition.primaryPage], definition.primaryPage.publicPathname))
|
|
10
|
+
throw new TypeError('Invalid Preview primary page.');
|
|
11
|
+
const runtime = {
|
|
12
|
+
config: {
|
|
13
|
+
isEnabled: () => true,
|
|
14
|
+
isProduction: () => true,
|
|
15
|
+
resolveCodeVersion: () => definition.codeVersion,
|
|
16
|
+
resolveSemanticManifest: async () => definition.manifest,
|
|
17
|
+
resolveSemanticConfig: () => ({ enabled: true, fixtureEnabled: false,
|
|
18
|
+
sessionId: '', codeVersion: definition.codeVersion, fixture: null }),
|
|
19
|
+
},
|
|
20
|
+
recorder: {
|
|
21
|
+
markNoStore: () => { },
|
|
22
|
+
readSessionId: async () => null,
|
|
23
|
+
resolveRouteIdentity: async () => {
|
|
24
|
+
throw new Error('Browser query provenance requires its own read context.');
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
// Each mounted query owns its reads; no cross-query raw-response cache.
|
|
29
|
+
return createPreviewReadLifecycle({
|
|
30
|
+
projectId, endpoint: '', runtime, rawReadCache: new Map(),
|
|
31
|
+
primaryPage: definition.primaryPage,
|
|
32
|
+
});
|
|
33
|
+
}
|
package/dist/runtime/boot.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import { bootSchema, startSchemaRetryLoop } from "./schema-store.js";
|
|
24
24
|
import { previewRuntime } from "./store.js";
|
|
25
|
-
import { applyPreviewOverlayMap, clearPreviewOverlayPaint, installPreviewEditInteractionGuard, revealPreviewV2SourceInIframe, } from "./preview-overlay-painter.js";
|
|
25
|
+
import { applyPreviewOverlayMap, clearPreviewOverlayPaint, dismissPreviewOverlayMenu, installPreviewEditInteractionGuard, revealPreviewV2SourceInIframe, } from "./preview-overlay-painter.js";
|
|
26
26
|
import { installPreviewWorkspaceShortcuts } from "./workspace-shortcuts.js";
|
|
27
27
|
import { installMomentaryNavigateKeyRelay } from "./momentary-navigate.js";
|
|
28
28
|
import { validateOverlayClear, validateOverlayMap, validatePreviewV2RevealSource, } from "../validators.js";
|
|
@@ -211,6 +211,20 @@ export function bootIframeRuntime(opts) {
|
|
|
211
211
|
const rawType = data !== null && typeof data === "object"
|
|
212
212
|
? data.type
|
|
213
213
|
: null;
|
|
214
|
+
if (rawType === "storystick.preview.host-interaction") {
|
|
215
|
+
const identity = previewRuntime.getState().identity;
|
|
216
|
+
if (identity === null || identity.parentOrigin === null)
|
|
217
|
+
return;
|
|
218
|
+
const base = validatePreviewEnvelope(data);
|
|
219
|
+
if (!base.ok || base.message.type !== "storystick.preview.host-interaction")
|
|
220
|
+
return;
|
|
221
|
+
if (ev.source !== view.parent || ev.origin !== identity.parentOrigin)
|
|
222
|
+
return;
|
|
223
|
+
if (base.message.sessionId !== identity.sessionId || base.message.projectId !== identity.projectId)
|
|
224
|
+
return;
|
|
225
|
+
dismissPreviewOverlayMenu();
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
214
228
|
if (rawType === "storystick.preview.interaction-mode") {
|
|
215
229
|
const identity = previewRuntime.getState().identity;
|
|
216
230
|
if (identity === null || identity.parentOrigin === null)
|
|
@@ -5,7 +5,8 @@ const INTERACTION_ATTR = "data-ss-preview-interaction";
|
|
|
5
5
|
// `:root` is stable state-free specificity. It keeps the policy above common
|
|
6
6
|
// customer utility classes that also declare an `!important` cursor, without
|
|
7
7
|
// putting any mutable interaction state back on a React-owned singleton.
|
|
8
|
-
|
|
8
|
+
function editInteractionCss() {
|
|
9
|
+
return `
|
|
9
10
|
html:root,
|
|
10
11
|
html:root body,
|
|
11
12
|
html:root body * {
|
|
@@ -14,6 +15,7 @@ const EDIT_INTERACTION_CSS = `
|
|
|
14
15
|
user-select: none !important;
|
|
15
16
|
}
|
|
16
17
|
`;
|
|
18
|
+
}
|
|
17
19
|
const POLICY_STATE_KEY = Symbol.for("storystick.preview.interaction-policy-state.v1");
|
|
18
20
|
export function installPreviewInteractionPolicy(win) {
|
|
19
21
|
const existing = getPolicyInstallation(win);
|
|
@@ -76,7 +78,7 @@ function applyInteractionMode(doc, mode) {
|
|
|
76
78
|
// remains the default across every route commit. Browse opts out by leaving
|
|
77
79
|
// the policy stylesheet empty, preserving the customer's own cursor rules.
|
|
78
80
|
style.setAttribute(INTERACTION_ATTR, mode);
|
|
79
|
-
const nextCss = mode === "edit" ?
|
|
81
|
+
const nextCss = mode === "edit" ? editInteractionCss() : "";
|
|
80
82
|
if (style.textContent !== nextCss)
|
|
81
83
|
style.textContent = nextCss;
|
|
82
84
|
}
|
|
@@ -23,5 +23,6 @@ export interface PreviewV2RevealResult {
|
|
|
23
23
|
}
|
|
24
24
|
export declare function applyPreviewOverlayMap(payload: PreviewOverlayMapPayload, win: Window, options?: PreviewOverlayPainterOptions | ((payload: PreviewOverlayClickPayload) => void)): PreviewOverlayPaintResult;
|
|
25
25
|
export declare function clearPreviewOverlayPaint(): void;
|
|
26
|
+
export declare function dismissPreviewOverlayMenu(): void;
|
|
26
27
|
export declare function installPreviewEditInteractionGuard(win: Window, options?: PreviewEditInteractionGuardOptions): () => void;
|
|
27
28
|
export declare function revealPreviewV2SourceInIframe(payload: PreviewV2RevealSourcePayload, win: Window): PreviewV2RevealResult;
|