@1agh/maude 1.7.1 → 1.8.1
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/apps/studio/acp/bridge.ts +1 -0
- package/apps/studio/acp/login-state.ts +1 -0
- package/apps/studio/acp/probe.ts +1 -0
- package/apps/studio/api.ts +412 -35
- package/apps/studio/asset-upload.ts +174 -0
- package/apps/studio/assets-s3.ts +37 -2
- package/apps/studio/bin/_pdf-playwright.mjs +22 -1
- package/apps/studio/bin/_png-playwright.mjs +20 -1
- package/apps/studio/bin/_region.mjs +92 -0
- package/apps/studio/canvas-build.ts +59 -4
- package/apps/studio/canvas-lib.tsx +48 -1
- package/apps/studio/canvas-shell.tsx +28 -4
- package/apps/studio/client/app.jsx +109 -22
- package/apps/studio/client/canvas-url.js +9 -0
- package/apps/studio/client/embed-view.jsx +284 -0
- package/apps/studio/client/embed.js +101 -0
- package/apps/studio/client/export-center.jsx +2 -0
- package/apps/studio/client/github.js +36 -3
- package/apps/studio/client/report-bug.jsx +8 -2
- package/apps/studio/context.ts +7 -0
- package/apps/studio/dist/client.bundle.js +2682 -2682
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/embed-origins.ts +52 -0
- package/apps/studio/export-dialog.tsx +55 -3
- package/apps/studio/exporters/format-scopes.ts +11 -3
- package/apps/studio/exporters/index.ts +17 -2
- package/apps/studio/exporters/jobs.ts +16 -8
- package/apps/studio/exporters/pdf.ts +10 -2
- package/apps/studio/exporters/png.ts +10 -2
- package/apps/studio/exporters/scope.ts +74 -3
- package/apps/studio/generation/runtime-probe.ts +1 -1
- package/apps/studio/git/service.ts +1 -0
- package/apps/studio/http.ts +186 -13
- package/apps/studio/input-router.tsx +7 -1
- package/apps/studio/path-containment.ts +72 -0
- package/apps/studio/paths.ts +14 -1
- package/apps/studio/read-only-mode.ts +53 -0
- package/apps/studio/server.ts +9 -0
- package/apps/studio/sync/index.ts +74 -13
- package/apps/studio/sync/park.ts +39 -0
- package/apps/studio/sync/presentation.ts +9 -3
- package/apps/studio/sync/writer-registry.ts +5 -0
- package/apps/studio/use-canvas-media-drop.tsx +8 -28
- package/apps/studio/whats-new.json +27 -0
- package/cli/commands/design.mjs +9 -2
- package/cli/commands/hub-workspace.mjs +25 -0
- package/cli/lib/workspace-plan.mjs +51 -0
- package/package.json +9 -9
- package/plugins/design/templates/_shell.html +58 -0
|
@@ -60,6 +60,8 @@ import SyncConsentDialog from './panels/SyncConsentDialog.jsx';
|
|
|
60
60
|
import SyncPanel from './panels/SyncPanel.jsx';
|
|
61
61
|
import CloudBar from './panels/CloudBar.jsx';
|
|
62
62
|
import { buildShareLinks, normalizeOpenPath, readOpenParam, withOpenParam } from './share-link.js';
|
|
63
|
+
import { isEmbedLocation } from './embed.js';
|
|
64
|
+
import EmbedView from './embed-view.jsx';
|
|
63
65
|
import { ShareDialog, copyShareLink } from './share-dialog.jsx';
|
|
64
66
|
import IdentityBar from './panels/IdentityBar.jsx';
|
|
65
67
|
import OnboardingWizard from './panels/OnboardingWizard.jsx';
|
|
@@ -122,8 +124,10 @@ import {
|
|
|
122
124
|
isNativeApp,
|
|
123
125
|
onMenuReportBug,
|
|
124
126
|
onUpdateReady,
|
|
127
|
+
pickedMediaSource,
|
|
125
128
|
pickMediaFile,
|
|
126
129
|
pickMediaFiles,
|
|
130
|
+
readPickedMediaBlob,
|
|
127
131
|
restartToUpdate,
|
|
128
132
|
} from './github.js';
|
|
129
133
|
import { COLLAB_TOUR } from './tour/collab-tour.js';
|
|
@@ -131,6 +135,7 @@ import { TourOverlay } from './tour/overlay.jsx';
|
|
|
131
135
|
import { QUICK_SETUP_TOUR } from './tour/quick-setup-tour.js';
|
|
132
136
|
import { USAGE_TOUR } from './tour/usage-tour.js';
|
|
133
137
|
import { dismissNotice, NotificationHost, notify, notifyCanvasText } from '../notifications.tsx';
|
|
138
|
+
import { uploadAsset } from '../asset-upload.ts';
|
|
134
139
|
import { acceptCanvasNotice } from '../canvas-notice-message.ts';
|
|
135
140
|
import { ExportBadge, ExportPanel, ExportToast, useExportCenter } from './export-center.jsx';
|
|
136
141
|
import { ReportBugDialog } from './report-bug.jsx';
|
|
@@ -1137,8 +1142,13 @@ const EXPORT_SCOPE_LABELS = {
|
|
|
1137
1142
|
selection: 'Current selection',
|
|
1138
1143
|
artboard: 'Active artboard',
|
|
1139
1144
|
'canvas-as-separate': 'Canvas · artboards separate',
|
|
1145
|
+
'canvas-whole': 'Whole canvas · one image',
|
|
1146
|
+
'selection-bounds': 'Selection area · one image',
|
|
1140
1147
|
'project-raw': 'Whole project (raw)',
|
|
1141
1148
|
};
|
|
1149
|
+
// Issue #125 — scopes that capture a world-plane region as one unit; the only
|
|
1150
|
+
// ones that can carry the annotation layer.
|
|
1151
|
+
const EXPORT_REGION_SCOPES = new Set(['canvas-whole', 'selection-bounds']);
|
|
1142
1152
|
const PNG_SCALES = [
|
|
1143
1153
|
{ value: 1, label: '1× (native)' },
|
|
1144
1154
|
{ value: 2, label: '2× (retina)' },
|
|
@@ -1241,6 +1251,7 @@ function AssetPicker({
|
|
|
1241
1251
|
}) {
|
|
1242
1252
|
const [assets, setAssets] = useState(null);
|
|
1243
1253
|
const [busy, setBusy] = useState(false);
|
|
1254
|
+
const [progress, setProgress] = useState(null);
|
|
1244
1255
|
const [err, setErr] = useState(null);
|
|
1245
1256
|
// feature-bulk-media-insert — multi-select state. `kindByPath` merges the
|
|
1246
1257
|
// fetched listing with freshly uploaded assets (the upload response carries
|
|
@@ -1304,17 +1315,12 @@ function AssetPicker({
|
|
|
1304
1315
|
|
|
1305
1316
|
// Shared upload core — both the single-pick `doUpload` and the multi-file
|
|
1306
1317
|
// `doUploadMany` post through here, so neither duplicates the request shape.
|
|
1318
|
+
// The shared client chunks a large clip (issue #126) — the same path the
|
|
1319
|
+
// canvas drop takes, so the picker isn't left at the one-shot cap.
|
|
1307
1320
|
const uploadOne = async (f) => {
|
|
1308
|
-
const res = await
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
body: f,
|
|
1312
|
-
});
|
|
1313
|
-
const j = await res.json().catch(() => ({}));
|
|
1314
|
-
// /_api/asset returns 201 { path } on success — NO `ok` field (the bug: a
|
|
1315
|
-
// `j.ok` check always failed → "upload failed" even on a good upload).
|
|
1316
|
-
if (res.ok && j.path) return { ok: true, path: j.path };
|
|
1317
|
-
return { ok: false, error: j.error || `upload failed (HTTP ${res.status})` };
|
|
1321
|
+
const res = await uploadAsset(f, { onProgress: setProgress });
|
|
1322
|
+
setProgress(null);
|
|
1323
|
+
return 'path' in res ? { ok: true, path: res.path } : { ok: false, error: res.error };
|
|
1318
1324
|
};
|
|
1319
1325
|
|
|
1320
1326
|
const doUpload = async (f) => {
|
|
@@ -1370,20 +1376,30 @@ function AssetPicker({
|
|
|
1370
1376
|
setBusy(true);
|
|
1371
1377
|
setErr(null);
|
|
1372
1378
|
try {
|
|
1379
|
+
// The picker hands back tokens, not bytes; each source reads its file in
|
|
1380
|
+
// slices as the upload needs them (issue #126 — a 500 MB clip must not
|
|
1381
|
+
// cross IPC whole). The server sniffs the bytes, so the ext-derived type
|
|
1382
|
+
// only routes small images to the one-shot path.
|
|
1373
1383
|
if (multiple) {
|
|
1374
1384
|
const picked = await pickMediaFiles();
|
|
1375
|
-
const
|
|
1376
|
-
(p) => new File([new Uint8Array(p.bytes)], p.name, { type: mimeFromExt(p.name) })
|
|
1377
|
-
);
|
|
1385
|
+
const sources = (picked || []).map((p) => pickedMediaSource(p, mimeFromExt(p.name)));
|
|
1378
1386
|
setBusy(false);
|
|
1379
|
-
|
|
1387
|
+
try {
|
|
1388
|
+
if (sources.length) await doUploadMany(sources);
|
|
1389
|
+
} finally {
|
|
1390
|
+
for (const src of sources) src.release();
|
|
1391
|
+
}
|
|
1380
1392
|
return;
|
|
1381
1393
|
}
|
|
1382
1394
|
const picked = await pickMediaFile();
|
|
1383
|
-
if (picked
|
|
1384
|
-
//
|
|
1385
|
-
|
|
1386
|
-
|
|
1395
|
+
if (picked) {
|
|
1396
|
+
// (doUpload sets its own busy=false.)
|
|
1397
|
+
const src = pickedMediaSource(picked, mimeFromExt(picked.name));
|
|
1398
|
+
try {
|
|
1399
|
+
await doUpload(src);
|
|
1400
|
+
} finally {
|
|
1401
|
+
src.release();
|
|
1402
|
+
}
|
|
1387
1403
|
return;
|
|
1388
1404
|
}
|
|
1389
1405
|
} catch (e) {
|
|
@@ -1441,7 +1457,11 @@ function AssetPicker({
|
|
|
1441
1457
|
<div className="st-dialog-bd">
|
|
1442
1458
|
<div className="st-ap-toolbar">
|
|
1443
1459
|
<button type="button" className="st-btn" onClick={openFilePicker} disabled={busy}>
|
|
1444
|
-
{busy
|
|
1460
|
+
{busy
|
|
1461
|
+
? progress == null
|
|
1462
|
+
? 'Uploading…'
|
|
1463
|
+
: `Uploading… ${Math.round(progress * 100)}%`
|
|
1464
|
+
: 'Upload…'}
|
|
1445
1465
|
</button>
|
|
1446
1466
|
{err && <span className="st-ap-err">{err}</span>}
|
|
1447
1467
|
</div>
|
|
@@ -1546,6 +1566,7 @@ function ExportDialog({
|
|
|
1546
1566
|
selection = null,
|
|
1547
1567
|
exportLane = 'local',
|
|
1548
1568
|
onBrowserCapture = null,
|
|
1569
|
+
onQuerySelection = null,
|
|
1549
1570
|
onClose,
|
|
1550
1571
|
}) {
|
|
1551
1572
|
// feature-cloud-export-render-workers — on a cell with no render service
|
|
@@ -1592,6 +1613,8 @@ function ExportDialog({
|
|
|
1592
1613
|
const [pdfMarksRegistration, setPdfMarksRegistration] = useState(false);
|
|
1593
1614
|
const [pdfDpiId, setPdfDpiId] = useState(PDF_DPI_DEFAULT);
|
|
1594
1615
|
const [pdfTextId, setPdfTextId] = useState(PDF_TEXT_DEFAULT);
|
|
1616
|
+
// Issue #125 — opt-in, region scopes only. Comment pins never export.
|
|
1617
|
+
const [includeAnnotations, setIncludeAnnotations] = useState(false);
|
|
1595
1618
|
// DDR-148 addendum — mp4/webm of a registered video-comp render through
|
|
1596
1619
|
// renderMediaOnWeb, which produces real audio (Remotion owns the
|
|
1597
1620
|
// TransitionSeries/volume-closure timeline). gif has no audio track at all
|
|
@@ -1715,6 +1738,11 @@ function ExportDialog({
|
|
|
1715
1738
|
// the in-canvas dialog's captureScopeHints.
|
|
1716
1739
|
if (activeArtboardId) options.artboardId = activeArtboardId;
|
|
1717
1740
|
if (selection?.selector) options.selection = selection;
|
|
1741
|
+
if (EXPORT_REGION_SCOPES.has(scope) && includeAnnotations) options.includeAnnotations = true;
|
|
1742
|
+
if (scope === 'selection-bounds' && typeof onQuerySelection === 'function') {
|
|
1743
|
+
const all = await onQuerySelection();
|
|
1744
|
+
if (all?.length) options.selectionAll = all;
|
|
1745
|
+
}
|
|
1718
1746
|
// Which canvas FILE this dialog is exporting — the server's `_active.json`
|
|
1719
1747
|
// lags a tab switch, and a job resolved against the stale file renders the
|
|
1720
1748
|
// wrong canvas (with this dialog's artboardId, which then never matches).
|
|
@@ -1926,6 +1954,23 @@ function ExportDialog({
|
|
|
1926
1954
|
</select>
|
|
1927
1955
|
</div>
|
|
1928
1956
|
)}
|
|
1957
|
+
{!card.handoff && EXPORT_REGION_SCOPES.has(scope) && (
|
|
1958
|
+
<div className="st-dialog-row">
|
|
1959
|
+
<label className="st-dialog-lbl" htmlFor="st-export-annotations">
|
|
1960
|
+
Annotations
|
|
1961
|
+
</label>
|
|
1962
|
+
<label style={{ display: 'flex', alignItems: 'center', gap: 8, cursor: 'pointer' }}>
|
|
1963
|
+
<input
|
|
1964
|
+
id="st-export-annotations"
|
|
1965
|
+
type="checkbox"
|
|
1966
|
+
data-testid="export-include-annotations"
|
|
1967
|
+
checked={includeAnnotations}
|
|
1968
|
+
onChange={(e) => setIncludeAnnotations(e.target.checked)}
|
|
1969
|
+
/>
|
|
1970
|
+
Include annotations
|
|
1971
|
+
</label>
|
|
1972
|
+
</div>
|
|
1973
|
+
)}
|
|
1929
1974
|
{!card.handoff && card.format === 'png' && (
|
|
1930
1975
|
<div className="st-dialog-row">
|
|
1931
1976
|
<label className="st-dialog-lbl" htmlFor="st-export-size">
|
|
@@ -10463,6 +10508,10 @@ function App() {
|
|
|
10463
10508
|
// dialogs gate on it. Absent on older servers → undefined, treated
|
|
10464
10509
|
// as `local` (the pre-lane behavior) everywhere it is read.
|
|
10465
10510
|
exportLane: data.exportLane,
|
|
10511
|
+
// DDR-247 — the apps allowed to frame this studio. Read by the
|
|
10512
|
+
// `?embed=1` root (embed-view.jsx), which never mounts <App>; named
|
|
10513
|
+
// here so the projection stays total (config-projection.test.ts).
|
|
10514
|
+
embedOrigins: data.embedOrigins,
|
|
10466
10515
|
}));
|
|
10467
10516
|
})
|
|
10468
10517
|
.catch(() => {});
|
|
@@ -11130,6 +11179,41 @@ function App() {
|
|
|
11130
11179
|
[activePath]
|
|
11131
11180
|
);
|
|
11132
11181
|
|
|
11182
|
+
// Issue #125 — "Selection area" needs every selected item, canvas elements
|
|
11183
|
+
// AND annotations; the shell tracks only one, so ask the canvas. Resolves
|
|
11184
|
+
// null (→ the single tracked selection) when the canvas doesn't answer.
|
|
11185
|
+
const querySelectionFromCanvas = useCallback(
|
|
11186
|
+
() =>
|
|
11187
|
+
new Promise((resolve) => {
|
|
11188
|
+
const el = activePath ? iframesRef.current.get(activePath) : null;
|
|
11189
|
+
if (!el || !el.contentWindow) {
|
|
11190
|
+
resolve(null);
|
|
11191
|
+
return;
|
|
11192
|
+
}
|
|
11193
|
+
const cw = el.contentWindow;
|
|
11194
|
+
const id = `sel-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
11195
|
+
const onMsg = (e) => {
|
|
11196
|
+
if (e.source !== cw) return;
|
|
11197
|
+
const m = e.data;
|
|
11198
|
+
if (!m || m.dgn !== 'export-selection' || m.id !== id) return;
|
|
11199
|
+
done(Array.isArray(m.selectors) ? m.selectors.filter((x) => typeof x === 'string') : null);
|
|
11200
|
+
};
|
|
11201
|
+
const timer = setTimeout(() => done(null), 1500);
|
|
11202
|
+
function done(v) {
|
|
11203
|
+
clearTimeout(timer);
|
|
11204
|
+
window.removeEventListener('message', onMsg);
|
|
11205
|
+
resolve(v);
|
|
11206
|
+
}
|
|
11207
|
+
window.addEventListener('message', onMsg);
|
|
11208
|
+
try {
|
|
11209
|
+
cw.postMessage({ dgn: 'export-selection-query', id }, '*');
|
|
11210
|
+
} catch {
|
|
11211
|
+
done(null);
|
|
11212
|
+
}
|
|
11213
|
+
}),
|
|
11214
|
+
[activePath]
|
|
11215
|
+
);
|
|
11216
|
+
|
|
11133
11217
|
// ── feature-photo-editor — the Photo tab's three channels ─────────────────
|
|
11134
11218
|
// (1) live preview: broadcast the edit DOWN to the active canvas iframe, whose
|
|
11135
11219
|
// canvas-lib `PhotoPreviewBridge` bakes the composite and swaps it directly
|
|
@@ -17035,8 +17119,8 @@ function App() {
|
|
|
17035
17119
|
};
|
|
17036
17120
|
if (isNativeApp()) {
|
|
17037
17121
|
pickMediaFile()
|
|
17038
|
-
.then((picked) => {
|
|
17039
|
-
if (picked
|
|
17122
|
+
.then(async (picked) => {
|
|
17123
|
+
if (picked) uploadPicked(await readPickedMediaBlob(picked), '');
|
|
17040
17124
|
})
|
|
17041
17125
|
.catch((e2) => shellToast(`Image pick failed: ${e2?.message || 'dialog error'}`));
|
|
17042
17126
|
return;
|
|
@@ -17179,6 +17263,7 @@ function App() {
|
|
|
17179
17263
|
selection={selected?.selector ? { selector: selected.selector, file: selected.file } : null}
|
|
17180
17264
|
exportLane={cfg.exportLane || 'local'}
|
|
17181
17265
|
onBrowserCapture={captureFromCanvas}
|
|
17266
|
+
onQuerySelection={querySelectionFromCanvas}
|
|
17182
17267
|
onClose={() => setExportDialog(null)}
|
|
17183
17268
|
/>
|
|
17184
17269
|
)}
|
|
@@ -17354,4 +17439,6 @@ function App() {
|
|
|
17354
17439
|
);
|
|
17355
17440
|
}
|
|
17356
17441
|
|
|
17357
|
-
|
|
17442
|
+
// DDR-247 — `?embed=1` is a different root, not a mode of <App>: nothing the
|
|
17443
|
+
// shell does (prefs, address bar, panels) runs inside another app's frame.
|
|
17444
|
+
createRoot(document.getElementById('root')).render(isEmbedLocation(location) ? <EmbedView /> : <App />);
|
|
@@ -93,6 +93,15 @@ export function canvasUrl(p, cfg, opts) {
|
|
|
93
93
|
// reads this flag). Boot-static on purpose — a role is per-session, and a
|
|
94
94
|
// query param can't race the way a post-load message could.
|
|
95
95
|
if (cfg?.readOnly) params.set('ro', '1');
|
|
96
|
+
// DDR-247 — the chromeless `?embed=1` view another app frames. Read-only
|
|
97
|
+
// whatever the viewer's role (the embed offers looking, nothing else), no
|
|
98
|
+
// comment layer, and `embed=1` so the canvas keeps its camera to itself
|
|
99
|
+
// instead of persisting the embed's fit over the designer's own view.
|
|
100
|
+
if (opts?.embed) {
|
|
101
|
+
params.set('ro', '1');
|
|
102
|
+
params.set('comments', '0');
|
|
103
|
+
params.set('embed', '1');
|
|
104
|
+
}
|
|
96
105
|
// Cloud Phase 27 (DDR-209) — the canvas origin's capability. On a desktop the
|
|
97
106
|
// canvas origin is loopback and needs none, so this is absent and the URL is
|
|
98
107
|
// byte-identical to before. In the cloud it is a cookieless, cross-site
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// DDR-247 — the chromeless, read-only `?embed=1&open=<rel>[&artboard=<id>]`
|
|
2
|
+
// view another app frames (orbit showing a design next to a task).
|
|
3
|
+
//
|
|
4
|
+
// A SEPARATE ROOT, not a mode of <App>. The studio shell persists view prefs,
|
|
5
|
+
// rewrites the address bar, mounts panels, chat and export — every one of which
|
|
6
|
+
// an embed must not do. Rendering this instead of <App> means none of it runs,
|
|
7
|
+
// rather than each of it remembering to check a flag. What IS shared is the
|
|
8
|
+
// canvas: the same `canvasUrl()` and the same in-canvas Presentation Mode
|
|
9
|
+
// (`view-chrome` `present`), with `ro=1` + `comments=0` + `embed=1` on the URL.
|
|
10
|
+
//
|
|
11
|
+
// It speaks the one-way contract in `embed.js` to the parent and accepts
|
|
12
|
+
// nothing from it.
|
|
13
|
+
import { useEffect, useRef, useState } from 'react';
|
|
14
|
+
|
|
15
|
+
import { canvasTokenRefreshDelay, canvasUrl, setLiveCanvasToken } from './canvas-url.js';
|
|
16
|
+
import { postToEmbedder, readEmbedParams } from './embed.js';
|
|
17
|
+
import { normalizeOpenPath } from './share-link.js';
|
|
18
|
+
|
|
19
|
+
const CANVAS_EXT_RE = /\.(tsx|html?)$/i;
|
|
20
|
+
// DDR-247 — every config read this view makes says it is the embed, so a hub
|
|
21
|
+
// mints it a read-only canvas capability (the canvas door then refuses writes).
|
|
22
|
+
const EMBED_CONFIG_URL = '/_config?embed=1';
|
|
23
|
+
// Same order of magnitude as the studio's own compile cap (issue #115): past
|
|
24
|
+
// this the canvas is not coming, and the embedder deserves an answer.
|
|
25
|
+
const LOAD_TIMEOUT_MS = 20_000;
|
|
26
|
+
// `dgn:'loaded'` fires from the inline inspector script BEFORE the React canvas
|
|
27
|
+
// shell mounts its listener (app.jsx says the same), so the view is seeded on a
|
|
28
|
+
// short ladder rather than once. Every message on it is idempotent.
|
|
29
|
+
const SEED_LADDER_MS = [0, 150, 500, 1200, 2500];
|
|
30
|
+
|
|
31
|
+
const ROOT_STYLE = { position: 'fixed', inset: 0, overflow: 'hidden', background: 'var(--u-bg-0)' };
|
|
32
|
+
const FRAME_STYLE = { width: '100%', height: '100%', border: 0, display: 'block' };
|
|
33
|
+
const NOTE_STYLE = {
|
|
34
|
+
position: 'absolute',
|
|
35
|
+
inset: 0,
|
|
36
|
+
display: 'grid',
|
|
37
|
+
placeItems: 'center',
|
|
38
|
+
padding: 24,
|
|
39
|
+
textAlign: 'center',
|
|
40
|
+
color: 'var(--u-fg-2)',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function originOf(value) {
|
|
44
|
+
try {
|
|
45
|
+
return new URL(value, location.href).origin;
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function readJson(url) {
|
|
52
|
+
const r = await fetch(url, { cache: 'no-store', credentials: 'same-origin' });
|
|
53
|
+
if (!r.ok) throw Object.assign(new Error(`${url} → ${r.status}`), { status: r.status });
|
|
54
|
+
return r.json();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default function EmbedView() {
|
|
58
|
+
// loading | canvas | missing | signed-out
|
|
59
|
+
const [view, setView] = useState({ phase: 'loading' });
|
|
60
|
+
const frameRef = useRef(null);
|
|
61
|
+
// The allowlist and the echo travel in refs: posting must never wait on a render.
|
|
62
|
+
const allowRef = useRef([]);
|
|
63
|
+
const openRef = useRef('');
|
|
64
|
+
const post = (type, title) => postToEmbedder(window, allowRef.current, type, openRef.current, title);
|
|
65
|
+
|
|
66
|
+
// Follow the OS theme for the little chrome there is. Never persisted.
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const mq = window.matchMedia?.('(prefers-color-scheme: light)');
|
|
69
|
+
document.documentElement.dataset.theme = mq?.matches ? 'light' : 'dark';
|
|
70
|
+
}, []);
|
|
71
|
+
|
|
72
|
+
// Escape pressed on this page itself (focus outside the canvas frame) goes
|
|
73
|
+
// to the embedder too, when nothing here consumed it. This view never moves
|
|
74
|
+
// focus on its own — keys only arrive here after the person clicked in.
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const onKey = (e) => {
|
|
77
|
+
if (e.key !== 'Escape' || e.isComposing) return;
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
if (!e.defaultPrevented) post('escape');
|
|
80
|
+
}, 0);
|
|
81
|
+
};
|
|
82
|
+
window.addEventListener('keydown', onKey);
|
|
83
|
+
return () => window.removeEventListener('keydown', onKey);
|
|
84
|
+
}, []);
|
|
85
|
+
|
|
86
|
+
// Boot: config → resolve the identity against the project index → frame it.
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
let cancelled = false;
|
|
89
|
+
const miss = () => {
|
|
90
|
+
if (cancelled) return;
|
|
91
|
+
setView({ phase: 'missing' });
|
|
92
|
+
post('not-found');
|
|
93
|
+
};
|
|
94
|
+
(async () => {
|
|
95
|
+
let data;
|
|
96
|
+
try {
|
|
97
|
+
// `embed=1` asks the hub for a READ-ONLY canvas capability (DDR-247).
|
|
98
|
+
data = await readJson(EMBED_CONFIG_URL);
|
|
99
|
+
} catch (err) {
|
|
100
|
+
if (cancelled) return;
|
|
101
|
+
// The session ended between the hub letting the page through and this
|
|
102
|
+
// fetch — the hub answers an API call 401 rather than redirecting it.
|
|
103
|
+
if (err?.status === 401) {
|
|
104
|
+
setView({ phase: 'signed-out' });
|
|
105
|
+
post('auth-required');
|
|
106
|
+
} else miss();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const designRel = (data.designRoot || '.design').replace(/^\/+|\/+$/g, '');
|
|
110
|
+
allowRef.current = Array.isArray(data.embedOrigins) ? data.embedOrigins : [];
|
|
111
|
+
const params = readEmbedParams(location, designRel);
|
|
112
|
+
openRef.current = params.open ?? params.requested;
|
|
113
|
+
if (!params.open) return miss();
|
|
114
|
+
let index;
|
|
115
|
+
try {
|
|
116
|
+
index = await readJson('/_index-data');
|
|
117
|
+
} catch {
|
|
118
|
+
return miss();
|
|
119
|
+
}
|
|
120
|
+
const path = (index.groups ?? [])
|
|
121
|
+
.flatMap((g) => g.paths || [])
|
|
122
|
+
.find((p) => normalizeOpenPath(p, designRel) === params.open);
|
|
123
|
+
if (!path || !CANVAS_EXT_RE.test(path)) return miss();
|
|
124
|
+
let title = null;
|
|
125
|
+
try {
|
|
126
|
+
const meta = await readJson(`/_api/canvas-meta?file=${encodeURIComponent(path)}`);
|
|
127
|
+
if (typeof meta?.title === 'string' && meta.title.trim()) title = meta.title.trim().slice(0, 200);
|
|
128
|
+
} catch {
|
|
129
|
+
/* a canvas without a sidecar still renders — it just has no title */
|
|
130
|
+
}
|
|
131
|
+
if (cancelled) return;
|
|
132
|
+
const cfg = {
|
|
133
|
+
designRel,
|
|
134
|
+
tokensCssRel: data.tokensCssRel,
|
|
135
|
+
designSystems: data.designSystems,
|
|
136
|
+
canvasOrigin: data.canvasOrigin,
|
|
137
|
+
canvasToken: data.canvasToken,
|
|
138
|
+
canvasDesignSystems: index.canvasDesignSystems ?? {},
|
|
139
|
+
};
|
|
140
|
+
setView({
|
|
141
|
+
phase: 'canvas',
|
|
142
|
+
path,
|
|
143
|
+
title,
|
|
144
|
+
artboard: params.artboard,
|
|
145
|
+
cfg,
|
|
146
|
+
src: canvasUrl(path, cfg, { embed: true }),
|
|
147
|
+
});
|
|
148
|
+
})();
|
|
149
|
+
return () => {
|
|
150
|
+
cancelled = true;
|
|
151
|
+
};
|
|
152
|
+
}, []);
|
|
153
|
+
|
|
154
|
+
// While the canvas is up: announce `ready` once, seed the view on every
|
|
155
|
+
// (re)load, and give up with `not-found` if it never loads. Keyed on the
|
|
156
|
+
// canvas identity; `post` reads refs only.
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (view.phase !== 'canvas') return undefined;
|
|
159
|
+
const canvasOrigin = view.cfg.canvasOrigin ? originOf(view.cfg.canvasOrigin) : location.origin;
|
|
160
|
+
const timers = [];
|
|
161
|
+
let ready = false;
|
|
162
|
+
let giveUp = null;
|
|
163
|
+
const seed = () => {
|
|
164
|
+
const win = frameRef.current?.contentWindow;
|
|
165
|
+
if (!win || !canvasOrigin) return;
|
|
166
|
+
const theme = document.documentElement.dataset.theme === 'light' ? 'light' : 'dark';
|
|
167
|
+
const messages = [
|
|
168
|
+
{ dgn: 'comments-set', comments: [] },
|
|
169
|
+
{ dgn: 'theme', theme },
|
|
170
|
+
{ dgn: 'view-chrome', minimap: false, zoom: false, present: true },
|
|
171
|
+
view.artboard ? { dgn: 'zoom', op: 'artboard', id: view.artboard } : { dgn: 'zoom', op: 'fit' },
|
|
172
|
+
];
|
|
173
|
+
for (const m of messages) {
|
|
174
|
+
try {
|
|
175
|
+
win.postMessage(m, canvasOrigin);
|
|
176
|
+
} catch {
|
|
177
|
+
/* frame navigated away — the next load re-seeds */
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const loaded = () => {
|
|
182
|
+
if (!ready) {
|
|
183
|
+
ready = true;
|
|
184
|
+
clearTimeout(giveUp);
|
|
185
|
+
post('ready', view.title ?? undefined);
|
|
186
|
+
}
|
|
187
|
+
for (const ms of SEED_LADDER_MS) timers.push(setTimeout(seed, ms));
|
|
188
|
+
};
|
|
189
|
+
giveUp = setTimeout(() => {
|
|
190
|
+
if (ready) return;
|
|
191
|
+
setView({ phase: 'missing' });
|
|
192
|
+
post('not-found');
|
|
193
|
+
}, LOAD_TIMEOUT_MS);
|
|
194
|
+
function onMessage(e) {
|
|
195
|
+
// Only the frame we built, from the origin we built it on.
|
|
196
|
+
if (e.origin !== canvasOrigin || e.source !== frameRef.current?.contentWindow) return;
|
|
197
|
+
if (!e.data || typeof e.data !== 'object') return;
|
|
198
|
+
if (e.data.dgn === 'loaded') loaded();
|
|
199
|
+
// An Escape the canvas did not consume (read-only-mode.ts) belongs to
|
|
200
|
+
// the app around the embed — its dialog must still close.
|
|
201
|
+
else if (e.data.dgn === 'embed-escape') post('escape');
|
|
202
|
+
}
|
|
203
|
+
window.addEventListener('message', onMessage);
|
|
204
|
+
// A legacy `.html` canvas never posts `loaded`; its frame load is the signal.
|
|
205
|
+
const frame = frameRef.current;
|
|
206
|
+
const onFrameLoad = () => {
|
|
207
|
+
if (!view.path.endsWith('.tsx')) loaded();
|
|
208
|
+
};
|
|
209
|
+
frame?.addEventListener('load', onFrameLoad);
|
|
210
|
+
return () => {
|
|
211
|
+
window.removeEventListener('message', onMessage);
|
|
212
|
+
frame?.removeEventListener('load', onFrameLoad);
|
|
213
|
+
clearTimeout(giveUp);
|
|
214
|
+
for (const t of timers) clearTimeout(t);
|
|
215
|
+
};
|
|
216
|
+
}, [view.phase, view.path]);
|
|
217
|
+
|
|
218
|
+
// THE CANVAS CAPABILITY EXPIRES (render-token.mjs). Same re-mint the studio
|
|
219
|
+
// shell runs (app.jsx), for the one frame this view holds: an embed left open
|
|
220
|
+
// on a task must keep loading after a teammate's edit re-imports the module.
|
|
221
|
+
useEffect(() => {
|
|
222
|
+
if (view.phase !== 'canvas' || !view.cfg.canvasToken) return undefined;
|
|
223
|
+
const target = originOf(view.cfg.canvasOrigin);
|
|
224
|
+
let stopped = false;
|
|
225
|
+
let timer = null;
|
|
226
|
+
const schedule = (token) => {
|
|
227
|
+
timer = setTimeout(refresh, canvasTokenRefreshDelay(token));
|
|
228
|
+
};
|
|
229
|
+
async function refresh() {
|
|
230
|
+
let token = null;
|
|
231
|
+
try {
|
|
232
|
+
// Re-mint the SAME read-only capability — never a full one.
|
|
233
|
+
token = (await readJson(EMBED_CONFIG_URL))?.canvasToken;
|
|
234
|
+
} catch {
|
|
235
|
+
/* retried below; the current capability may still be valid */
|
|
236
|
+
}
|
|
237
|
+
if (stopped) return;
|
|
238
|
+
if (typeof token !== 'string' || !token) {
|
|
239
|
+
timer = setTimeout(refresh, 30_000);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
setLiveCanvasToken(token);
|
|
243
|
+
if (target) {
|
|
244
|
+
try {
|
|
245
|
+
frameRef.current?.contentWindow?.postMessage({ dgn: 'canvas-cap', t: token }, target);
|
|
246
|
+
} catch {}
|
|
247
|
+
}
|
|
248
|
+
schedule(token);
|
|
249
|
+
}
|
|
250
|
+
schedule(view.cfg.canvasToken);
|
|
251
|
+
return () => {
|
|
252
|
+
stopped = true;
|
|
253
|
+
clearTimeout(timer);
|
|
254
|
+
};
|
|
255
|
+
}, [view.phase, view.cfg?.canvasToken, view.cfg?.canvasOrigin]);
|
|
256
|
+
|
|
257
|
+
return (
|
|
258
|
+
<div style={ROOT_STYLE} data-testid="embed-view">
|
|
259
|
+
{view.phase === 'canvas' && (
|
|
260
|
+
<iframe
|
|
261
|
+
ref={frameRef}
|
|
262
|
+
src={view.src}
|
|
263
|
+
title={view.title ? `Canvas: ${view.title}` : `Canvas: ${view.path}`}
|
|
264
|
+
style={FRAME_STYLE}
|
|
265
|
+
data-testid="embed-canvas-frame"
|
|
266
|
+
// Same containment the studio shell gives a cross-origin canvas.
|
|
267
|
+
{...(view.cfg.canvasOrigin
|
|
268
|
+
? { sandbox: 'allow-scripts allow-same-origin', allow: 'clipboard-write' }
|
|
269
|
+
: {})}
|
|
270
|
+
/>
|
|
271
|
+
)}
|
|
272
|
+
{view.phase === 'missing' && (
|
|
273
|
+
<div style={NOTE_STYLE} role="status">
|
|
274
|
+
This design is not in the project, or it could not be loaded.
|
|
275
|
+
</div>
|
|
276
|
+
)}
|
|
277
|
+
{view.phase === 'signed-out' && (
|
|
278
|
+
<div style={NOTE_STYLE} role="status">
|
|
279
|
+
Sign in to the design hub to see this design.
|
|
280
|
+
</div>
|
|
281
|
+
)}
|
|
282
|
+
</div>
|
|
283
|
+
);
|
|
284
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// DDR-247 — the chromeless `?embed=1` view another app frames, and the ONE-WAY
|
|
2
|
+
// message contract it speaks to that app. Pure (URLSearchParams + URL only) so
|
|
3
|
+
// `test/embed.test.ts` exercises it without React or a DOM.
|
|
4
|
+
//
|
|
5
|
+
// THE CONTRACT (v1) — embedders build against this shape, so it only grows:
|
|
6
|
+
//
|
|
7
|
+
// { source: 'maude-hub', v: 1,
|
|
8
|
+
// type: 'ready' | 'auth-required' | 'not-found' | 'escape',
|
|
9
|
+
// open: string, title?: string }
|
|
10
|
+
//
|
|
11
|
+
// `auth-required` is posted by the hub's signed-out embed page
|
|
12
|
+
// (apps/hub/src/embed-page.mjs), the others by `embed-view.jsx`. `escape`
|
|
13
|
+
// (added to v1, additive) means Escape was pressed inside the embed and
|
|
14
|
+
// nothing there consumed it — keys in a frame never reach the embedding page,
|
|
15
|
+
// so without it an embed inside a dialog would trap a keyboard user. The embed
|
|
16
|
+
// never takes focus on its own; only a click moves focus into it. Nothing is
|
|
17
|
+
// ever posted to '*': the target is the parent's exact origin, and only when
|
|
18
|
+
// that origin is on the server's embed allowlist. Nothing is accepted FROM the
|
|
19
|
+
// parent in v1.
|
|
20
|
+
import { readOpenParam } from './share-link.js';
|
|
21
|
+
|
|
22
|
+
export const EMBED_SOURCE = 'maude-hub';
|
|
23
|
+
export const EMBED_VERSION = 1;
|
|
24
|
+
|
|
25
|
+
/** Is this page load the embed view? Exactly `embed=1`, nothing looser. */
|
|
26
|
+
export function isEmbedLocation(location) {
|
|
27
|
+
try {
|
|
28
|
+
return new URLSearchParams(location?.search ?? '').get('embed') === '1';
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** An artboard id the embed may ask the canvas to frame. Only ever compared for
|
|
35
|
+
* equality against `data-dc-screen`, so the bound is length + no controls. */
|
|
36
|
+
export function validArtboardId(raw) {
|
|
37
|
+
return (
|
|
38
|
+
typeof raw === 'string' &&
|
|
39
|
+
raw.length > 0 &&
|
|
40
|
+
raw.length <= 120 &&
|
|
41
|
+
![...raw].some((c) => c.charCodeAt(0) < 32 || c.charCodeAt(0) === 127)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* What the embed was asked to show. `open` is the validated design-root
|
|
47
|
+
* relative identity (share-link.js rules) or null; `requested` is what the
|
|
48
|
+
* embedder sent, echoed back in `not-found` so it can tell its own requests
|
|
49
|
+
* apart.
|
|
50
|
+
*/
|
|
51
|
+
export function readEmbedParams(location, designRel = '.design') {
|
|
52
|
+
const params = new URLSearchParams(location?.search ?? '');
|
|
53
|
+
const values = params.getAll('open');
|
|
54
|
+
const artboard = params.get('artboard');
|
|
55
|
+
return {
|
|
56
|
+
open: readOpenParam(location, designRel),
|
|
57
|
+
requested: values.length === 1 ? values[0].slice(0, 512) : '',
|
|
58
|
+
artboard: validArtboardId(artboard) ? artboard : null,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The embedding page's origin. `ancestorOrigins` where the engine has it
|
|
64
|
+
* (Chromium, WebKit) — it cannot be influenced by the parent's referrer
|
|
65
|
+
* policy — else the referrer's origin (Firefox). Null when not framed at all.
|
|
66
|
+
*/
|
|
67
|
+
export function parentOrigin(win) {
|
|
68
|
+
try {
|
|
69
|
+
if (!win || win.parent === win) return null;
|
|
70
|
+
const ancestors = win.location?.ancestorOrigins;
|
|
71
|
+
if (ancestors && ancestors.length > 0) return ancestors[0];
|
|
72
|
+
const referrer = win.document?.referrer;
|
|
73
|
+
return referrer ? new URL(referrer).origin : null;
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The exact origin to post to, or null — never '*', never an unlisted parent. */
|
|
80
|
+
export function embedTarget(origin, allowlist) {
|
|
81
|
+
if (typeof origin !== 'string' || !origin || origin === 'null') return null;
|
|
82
|
+
return Array.isArray(allowlist) && allowlist.includes(origin) ? origin : null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function embedMessage(type, open, title) {
|
|
86
|
+
const msg = { source: EMBED_SOURCE, v: EMBED_VERSION, type, open: String(open ?? '') };
|
|
87
|
+
if (typeof title === 'string' && title) msg.title = title;
|
|
88
|
+
return msg;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Post one contract message to the parent, if the parent may hear it. */
|
|
92
|
+
export function postToEmbedder(win, allowlist, type, open, title) {
|
|
93
|
+
const target = embedTarget(parentOrigin(win), allowlist);
|
|
94
|
+
if (!target) return false;
|
|
95
|
+
try {
|
|
96
|
+
win.parent.postMessage(embedMessage(type, open, title), target);
|
|
97
|
+
return true;
|
|
98
|
+
} catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|