@storystick/react 0.2.0-rc.1 → 0.2.0-rc.2

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # @storystick/react API contract
2
2
 
3
- Install this candidate explicitly with `@storystick/react@0.2.0-rc.1` after registry bootstrap and publication. This repository alone does not make the candidate or beta channel available on npm.
3
+ Install this candidate explicitly with `@storystick/react@0.2.0-rc.2` 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.1, cohort `sdk-0.2.0-rc.1`. ESM distribution; no CommonJS or universal Edge compatibility is promised.
5
+ Version 0.2.0-rc.2, cohort `sdk-0.2.0-rc.2`. ESM distribution; no CommonJS or universal Edge compatibility is promised.
6
6
 
7
7
  This package is a product integration facade. 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
 
@@ -27,6 +27,7 @@ This package is a product integration facade. Reserved contracts are required be
27
27
  | `./internal/resize-edge` | Reserved SDK contract |
28
28
  | `./internal/preview-toolbar-shell` | Reserved SDK contract |
29
29
  | `./internal/preview-page-state` | Reserved SDK contract |
30
+ | `./internal/preview-terminal-state` | Reserved SDK contract |
30
31
  | `./internal/authoring-skeleton` | Reserved SDK contract |
31
32
  | `./internal/preview-panel-state` | Reserved SDK contract |
32
33
  | `./internal/preview-host` | Reserved SDK contract |
package/dist/.source-hash CHANGED
@@ -1 +1 @@
1
- 4cb09a292c5e314adfbbfa1a1bdf1cad0ae376072cfd5a37269e4be8e69570da
1
+ cd953980c3d53fab939eb42eb894e0f0f2863a9790a73d70c830db6be353a266
@@ -10,6 +10,7 @@ export interface PreviewStandaloneControlsProps {
10
10
  pathname?: string | null;
11
11
  recovery?: {
12
12
  error: string | null;
13
+ pending?: boolean;
13
14
  retry: () => void;
14
15
  };
15
16
  }
@@ -1,5 +1,7 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { PREVIEW_COPY, previewCopy } from '@storystick/preview/framework/preview-copy';
4
+ import { lookupPreviewFeedback } from '@storystick/preview/framework/preview-feedback';
3
5
  import { useMomentaryPreviewInteractionOverride } from '@storystick/react/internal/use-momentary-preview-navigate-mode';
4
6
  import { PreviewPanelAction, PreviewPanelState } from '@storystick/react/internal/preview-panel-state';
5
7
  import { AuthoringPanelSkeleton } from '@storystick/react/internal/authoring-skeleton';
@@ -119,14 +121,15 @@ export function PreviewStandaloneControls({ state, projectId, recovery, basePath
119
121
  state.renderedReadContext?.revision === state.readContext.revision;
120
122
  const connected = state.state === 'authenticated' && state.readContextStatus === 'active';
121
123
  const connectionNotice = state.state === 'error' || recovery?.error
122
- ? 'Preview unavailable'
123
- : !connected
124
- ? 'Connecting to Preview…'
125
- : null;
124
+ ? lookupPreviewFeedback(state.errorCode).title
125
+ : recovery?.pending ? PREVIEW_COPY['taking-longer'].title
126
+ : !connected
127
+ ? PREVIEW_COPY.connecting.title
128
+ : null;
126
129
  const notice = state.readContextNotice === 'release-published'
127
- ? 'This release was published. Preview now follows Main, including its drafts.'
130
+ ? `${PREVIEW_COPY['release-follows-main'].title}. ${previewCopy('release-follows-main', { release: 'This release' }).body}`
128
131
  : state.readContextNotice === 'release-archived'
129
- ? 'This release was archived. Preview now follows Main, including its drafts.'
132
+ ? `${PREVIEW_COPY['release-archived'].title}. ${previewCopy('release-archived', { release: 'This release' }).body}`
130
133
  : null;
131
134
  const interactionSuspended = !connected || !rendered || presentation.transition.kind !== 'idle';
132
135
  // Render proof protects page overlays. An accepted editor gesture can load
@@ -147,8 +150,8 @@ export function PreviewStandaloneControls({ state, projectId, recovery, basePath
147
150
  (currentPageTarget !== null || overlays.available);
148
151
  const overlayNotice = overlays.rejections.length > 0
149
152
  ? overlays.rejections.some(rejection => rejection.reason === 'edit-locator-variant-mismatch')
150
- ? 'Element selection is unavailable because some elements do not match their editing context.'
151
- : 'Element selection is unavailable because this page has incomplete or conflicting editing information.'
153
+ ? PREVIEW_COPY['visual-unavailable'].body
154
+ : PREVIEW_COPY['visual-limited'].body
152
155
  : null;
153
156
  const shouldPreloadRuntime = canEdit && (interactionMode === 'edit' || menuOpen);
154
157
  useEffect(() => {
@@ -405,7 +408,7 @@ export function PreviewStandaloneControls({ state, projectId, recovery, basePath
405
408
  setEditorStatus('connecting');
406
409
  if (status === 'unauthorized') {
407
410
  setEditorStatus('error');
408
- setError('Editing access ended. Reopen Preview from Studio.');
411
+ setError(PREVIEW_COPY['editing-forbidden'].title);
409
412
  }
410
413
  },
411
414
  });
@@ -480,14 +483,14 @@ export function PreviewStandaloneControls({ state, projectId, recovery, basePath
480
483
  overlayNotice ||
481
484
  (!rendered && connected) ||
482
485
  recovery?.error ||
483
- error) && (_jsxs("div", { className: "notices", children: [connectionNotice && _jsx("p", { role: "status", children: connectionNotice }), notice && _jsx("p", { children: notice }), overlayNotice && _jsx("p", { role: "status", children: overlayNotice }), connected && !rendered && (_jsxs("p", { children: ["This page has not confirmed its rendered perspective.", ' ', _jsx("button", { type: "button", onClick: () => window.location.reload(), children: "Reload" })] })), recovery?.error && (_jsxs("p", { role: "alert", children: [recovery.error, ' ', _jsx("button", { type: "button", onClick: recovery.retry, disabled: false, children: "Retry" })] })), error && _jsxs("p", { role: "alert", children: [error, ' ', editorStatus === 'error' && !runtimeHandle.current ? (_jsx("button", { type: "button", onClick: () => setConnectAttempt(value => value + 1), children: "Retry" })) : null] })] }))] }), panel: _jsxs(_Fragment, { children: [surface === 'editor' && target === null && committedTarget === null && !continuation && (_jsxs("div", { className: "editor-empty", children: [_jsx(EditIcon, {}), _jsx("strong", { children: "Select an element on the page" }), _jsx("p", { children: "The matching field will open here." })] })), (editorStatus === 'idle' || editorStatus === 'connecting') &&
484
- (surface === 'assistant' || target || continuation) && (_jsx("div", { className: "editor-loading", children: _jsx(AuthoringPanelSkeleton, { surface: surface === 'assistant' ? 'assistant' : 'editor' }) })), editorStatus === 'error' && error && (_jsx("div", { className: "panel-state-overlay", children: _jsx(PreviewPanelState, { title: surface === 'assistant' ? 'Assistant unavailable' : 'Editor unavailable', description: error, actions: _jsx(PreviewPanelAction, { onClick: () => {
486
+ error) && (_jsxs("div", { className: "notices", children: [connectionNotice && _jsx("p", { role: "status", children: connectionNotice }), notice && _jsx("p", { children: notice }), overlayNotice && _jsx("p", { role: "status", children: overlayNotice }), connected && !rendered && (_jsxs("p", { children: [PREVIEW_COPY.updating.body, ' ', _jsx("button", { type: "button", onClick: () => window.location.reload(), children: "Reload" })] })), recovery?.error && (_jsxs("p", { role: "alert", children: [PREVIEW_COPY['connection-interrupted'].body, ' ', _jsx("button", { type: "button", onClick: recovery.retry, disabled: false, children: "Retry" })] })), error && _jsxs("p", { role: "alert", children: [error, ' ', editorStatus === 'error' && !runtimeHandle.current ? (_jsx("button", { type: "button", onClick: () => setConnectAttempt(value => value + 1), children: "Retry" })) : null] })] }))] }), panel: _jsxs(_Fragment, { children: [surface === 'editor' && target === null && committedTarget === null && !continuation && (_jsxs("div", { className: "editor-empty", children: [_jsx(EditIcon, {}), _jsx("strong", { children: PREVIEW_COPY['element-empty'].title }), _jsx("p", { children: PREVIEW_COPY['element-empty'].body })] })), (editorStatus === 'idle' || editorStatus === 'connecting') &&
487
+ (surface === 'assistant' || target || continuation) && (_jsx("div", { className: "editor-loading", children: _jsx(AuthoringPanelSkeleton, { surface: surface === 'assistant' ? 'assistant' : 'editor' }) })), editorStatus === 'error' && error && (_jsx("div", { className: "panel-state-overlay", children: _jsx(PreviewPanelState, { title: surface === 'assistant' ? 'Assistant unavailable' : PREVIEW_COPY['editor-unavailable'].title, description: error, actions: _jsx(PreviewPanelAction, { onClick: () => {
485
488
  setError(null);
486
489
  if (runtimeHandle.current && (committedTarget ?? target))
487
490
  requestEditorTarget({ ...(committedTarget ?? target) });
488
491
  else
489
492
  setConnectAttempt((value) => value + 1);
490
- }, children: "Retry" }) }) })), surface === 'editor' && presentation.transition.kind === 'unconfirmed' && (_jsx("div", { className: "panel-state-overlay", children: _jsx(PreviewPanelState, { title: "Page not confirmed", description: "The site has not confirmed this page. Reload the preview if it does not catch up.", actions: _jsx(PreviewPanelAction, { onClick: () => window.location.reload(), children: "Reload preview" }) }) })), _jsx("div", { ref: editorContainer, className: "editor-mount", inert: (surface === 'editor' ? editorSuspended : !connected) || editorStatus !== 'ready', "aria-busy": (surface === 'editor' && editorSuspended) || editorStatus === 'connecting' })] }) });
493
+ }, children: "Retry" }) }) })), surface === 'editor' && presentation.transition.kind === 'unconfirmed' && (_jsx("div", { className: "panel-state-overlay", children: _jsx(PreviewPanelState, { title: PREVIEW_COPY['update-failed'].title, description: PREVIEW_COPY['update-failed'].body, actions: _jsx(PreviewPanelAction, { onClick: () => window.location.reload(), children: "Reload preview" }) }) })), _jsx("div", { ref: editorContainer, className: "editor-mount", inert: (surface === 'editor' ? editorSuspended : !connected) || editorStatus !== 'ready', "aria-busy": (surface === 'editor' && editorSuspended) || editorStatus === 'connecting' })] }) });
491
494
  }
492
495
  function targetForPage(page, perspective) {
493
496
  return {
@@ -519,10 +522,10 @@ function authoringErrorMessage(error) {
519
522
  const code = error instanceof Error ? error.message : '';
520
523
  console.warn('[storystick] Preview authoring connection failed:', /^[A-Z][A-Z0-9_]{0,80}$/.test(code) ? code : 'AUTHORING_RUNTIME_ERROR');
521
524
  if (code.includes('AUTHORING_WRITE_FORBIDDEN')) {
522
- return 'You do not have permission to edit this project.';
525
+ return PREVIEW_COPY['editing-forbidden'].title;
523
526
  }
524
527
  if (code.includes('CONTENT_SHAPE_RELOAD_REQUIRED')) {
525
- return 'Reopen Preview from Studio after the site deployment changed.';
528
+ return PREVIEW_COPY['deployment-changed'].body;
526
529
  }
527
- return 'Editing is unavailable. Reopen Preview from Studio and try again.';
530
+ return PREVIEW_COPY['editor-unavailable'].body;
528
531
  }
@@ -0,0 +1,8 @@
1
+ export interface PreviewTerminalStateProps {
2
+ code?: string | null;
3
+ studioUrl?: string | null;
4
+ onRetryExit?: () => void;
5
+ }
6
+ /** A terminal Preview state owns its viewport, without changing customer DOM.
7
+ * Isolate product styling from the customer's page and its error boundary. */
8
+ export declare function PreviewTerminalState({ code, studioUrl, onRetryExit }: PreviewTerminalStateProps): import("react").JSX.Element;
@@ -0,0 +1,37 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useEffect, useRef, useState } from 'react';
4
+ import { createPortal } from 'react-dom';
5
+ import { lookupSdkCopy } from '@storystick/preview/sdk-error-copy';
6
+ import { safePreviewCode, previewDiagnostic } from '@storystick/preview/framework/preview-diagnostic';
7
+ import { PreviewPageState } from './preview-page-state.js';
8
+ /** A terminal Preview state owns its viewport, without changing customer DOM.
9
+ * Isolate product styling from the customer's page and its error boundary. */
10
+ export function PreviewTerminalState({ code, studioUrl, onRetryExit }) {
11
+ const copy = lookupSdkCopy(code);
12
+ const [copyStatus, setCopyStatus] = useState('idle');
13
+ const copyRequest = useRef(0);
14
+ const host = useRef(null);
15
+ const [root, setRoot] = useState(null);
16
+ useEffect(() => {
17
+ if (host.current)
18
+ setRoot(host.current.shadowRoot ?? host.current.attachShadow({ mode: 'open' }));
19
+ return () => { copyRequest.current++; };
20
+ }, []);
21
+ return _jsx("div", { ref: host, "data-storystick-preview-error": "", "data-storystick-preview-controls": "", style: {
22
+ all: 'initial', position: 'fixed', inset: 0, zIndex: 2147483646, background: '#fff',
23
+ }, children: root ? createPortal(_jsx(PreviewPageState, { title: copy.title, description: copy.body, role: "status", actions: _jsxs(_Fragment, { children: [copy.action === 'exit' && onRetryExit ? _jsx("button", { type: "button", "data-ss-preview-page-action": "primary", onClick: onRetryExit, children: "Retry exit" }) : null, ['retry', 'retry-page'].includes(copy.action ?? '') ? _jsx("button", { type: "button", "data-ss-preview-page-action": "primary", onClick: () => window.location.reload(), children: copy.actionLabel }) : null, studioUrl ? _jsx("a", { "data-ss-preview-page-action": "", href: studioUrl, children: "Return to Studio" }) : null] }), children: copy.diagnostic ? _jsxs("details", { children: [_jsx("summary", { children: "Diagnostic" }), _jsx("pre", { children: safePreviewCode(code) }), _jsx("button", { type: "button", "data-ss-preview-page-action": "", onClick: async () => {
24
+ const request = ++copyRequest.current;
25
+ try {
26
+ if (!navigator.clipboard)
27
+ throw new Error('Clipboard unavailable');
28
+ await navigator.clipboard.writeText(previewDiagnostic({ code }));
29
+ if (request === copyRequest.current)
30
+ setCopyStatus('copied');
31
+ }
32
+ catch {
33
+ if (request === copyRequest.current)
34
+ setCopyStatus('failed');
35
+ }
36
+ }, children: copyStatus === 'copied' ? 'Diagnostic copied' : 'Copy diagnostic' }), copyStatus === 'failed' ? _jsx("p", { role: "status", children: "Diagnostic couldn\u2019t be copied. Select the code above to share it." }) : null, copy.commonCauses.length ? _jsx("ul", { style: { textAlign: 'left', paddingLeft: 18 }, children: copy.commonCauses.map(cause => _jsx("li", { children: cause }, cause)) }) : null] }) : null }), root) : null });
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storystick/react",
3
- "version": "0.2.0-rc.1",
3
+ "version": "0.2.0-rc.2",
4
4
  "license": "FSL-1.1-MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -84,6 +84,10 @@
84
84
  "types": "./dist/preview-page-state.d.ts",
85
85
  "import": "./dist/preview-page-state.js"
86
86
  },
87
+ "./internal/preview-terminal-state": {
88
+ "types": "./dist/preview-terminal-state.d.ts",
89
+ "import": "./dist/preview-terminal-state.js"
90
+ },
87
91
  "./internal/authoring-skeleton": {
88
92
  "types": "./dist/authoring-skeleton.d.ts",
89
93
  "import": "./dist/authoring-skeleton.js"
@@ -112,10 +116,10 @@
112
116
  "dependencies": {
113
117
  "@tanstack/query-core": "5.101.4",
114
118
  "@base-ui/react": "1.3.0",
115
- "@storystick/client": "0.2.0-rc.1",
116
- "@storystick/media": "0.2.0-rc.1",
117
- "@storystick/types": "0.1.0-rc.1",
118
- "@storystick/preview": "0.2.0-rc.1"
119
+ "@storystick/client": "0.2.0-rc.2",
120
+ "@storystick/media": "0.2.0-rc.2",
121
+ "@storystick/preview": "0.2.0-rc.2",
122
+ "@storystick/types": "0.1.0-rc.2"
119
123
  },
120
124
  "peerDependencies": {
121
125
  "react": "^19.2.8",