@conloca/cms-spa 0.2.2 → 0.2.3
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/README.md +26 -0
- package/dist/spa/main.css +223 -1
- package/dist/ts/.build-inputs.json +178 -0
- package/dist/ts/App.d.ts +5 -1
- package/dist/ts/App.d.ts.map +1 -1
- package/dist/ts/App.js +13 -6
- package/dist/ts/App.js.map +1 -1
- package/dist/ts/CmsSpaApp.d.ts.map +1 -1
- package/dist/ts/CmsSpaApp.js +4 -1
- package/dist/ts/CmsSpaApp.js.map +1 -1
- package/dist/ts/components/cards/DataEntryCard.d.ts +1 -1
- package/dist/ts/components/cards/DataEntryCard.d.ts.map +1 -1
- package/dist/ts/components/cards/SectionCard.d.ts +1 -1
- package/dist/ts/components/cards/SectionCard.d.ts.map +1 -1
- package/dist/ts/components/dialogs/DeleteConfirmDialog.d.ts +1 -1
- package/dist/ts/components/dialogs/DeleteConfirmDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts +1 -1
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/MoveFolderDialog.d.ts +1 -1
- package/dist/ts/components/dialogs/MoveFolderDialog.d.ts.map +1 -1
- package/dist/ts/components/editor/CMSMDXEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/CMSMDXEditor.js +46 -55
- package/dist/ts/components/editor/CMSMDXEditor.js.map +1 -1
- package/dist/ts/components/editor/LocaleSelector.d.ts +1 -1
- package/dist/ts/components/editor/LocaleSelector.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditor.d.ts +1 -1
- package/dist/ts/components/editor/PageEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditor.js +46 -17
- package/dist/ts/components/editor/PageEditor.js.map +1 -1
- package/dist/ts/components/editor/PageEditorHeaderActions.d.ts +1 -1
- package/dist/ts/components/editor/PageEditorHeaderActions.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditorWrapper.js +31 -5
- package/dist/ts/components/editor/PageEditorWrapper.js.map +1 -1
- package/dist/ts/components/editor/draft-media-config.d.ts +19 -1
- package/dist/ts/components/editor/draft-media-config.d.ts.map +1 -1
- package/dist/ts/components/editor/draft-media-config.js +112 -21
- package/dist/ts/components/editor/draft-media-config.js.map +1 -1
- package/dist/ts/components/editor/page-setting-targets.d.ts +1 -1
- package/dist/ts/components/editor/page-setting-targets.d.ts.map +1 -1
- package/dist/ts/components/editor/preview-availability.d.ts +6 -5
- package/dist/ts/components/editor/preview-availability.d.ts.map +1 -1
- package/dist/ts/components/editor/preview-availability.js +6 -5
- package/dist/ts/components/editor/preview-availability.js.map +1 -1
- package/dist/ts/components/editors/DataEditor.d.ts +1 -1
- package/dist/ts/components/editors/DataEditor.d.ts.map +1 -1
- package/dist/ts/components/media/AssetCard.d.ts +1 -1
- package/dist/ts/components/media/AssetCard.d.ts.map +1 -1
- package/dist/ts/components/media/AssetCard.js +3 -2
- package/dist/ts/components/media/AssetCard.js.map +1 -1
- package/dist/ts/components/media/AssetDetailSidebar.d.ts +1 -1
- package/dist/ts/components/media/AssetDetailSidebar.d.ts.map +1 -1
- package/dist/ts/components/media/AssetDetailSidebar.js +4 -2
- package/dist/ts/components/media/AssetDetailSidebar.js.map +1 -1
- package/dist/ts/components/media/MediaLibrary.d.ts +1 -1
- package/dist/ts/components/media/MediaLibrary.d.ts.map +1 -1
- package/dist/ts/components/media/MediaToolbar.d.ts +1 -1
- package/dist/ts/components/media/MediaToolbar.d.ts.map +1 -1
- package/dist/ts/components/pages/PageList.d.ts.map +1 -1
- package/dist/ts/components/pages/PageList.js +10 -4
- package/dist/ts/components/pages/PageList.js.map +1 -1
- package/dist/ts/components/sandbox/ContentSandbox.d.ts +1 -1
- package/dist/ts/components/sandbox/ContentSandbox.d.ts.map +1 -1
- package/dist/ts/components/sandbox/ContentSandbox.js +36 -5
- package/dist/ts/components/sandbox/ContentSandbox.js.map +1 -1
- package/dist/ts/components/ui/IconButton.d.ts +1 -1
- package/dist/ts/components/ui/IconButton.d.ts.map +1 -1
- package/dist/ts/content-wrapper.d.ts +65 -0
- package/dist/ts/content-wrapper.d.ts.map +1 -0
- package/dist/ts/content-wrapper.js +190 -0
- package/dist/ts/content-wrapper.js.map +1 -0
- package/dist/ts/data-schemas.d.ts.map +1 -1
- package/dist/ts/frame/channel.d.ts +40 -0
- package/dist/ts/frame/channel.d.ts.map +1 -0
- package/dist/ts/frame/channel.js +233 -0
- package/dist/ts/frame/channel.js.map +1 -0
- package/dist/ts/frame/editor-frame.d.ts +23 -0
- package/dist/ts/frame/editor-frame.d.ts.map +1 -0
- package/dist/ts/frame/editor-frame.js +154 -0
- package/dist/ts/frame/editor-frame.js.map +1 -0
- package/dist/ts/frame/media-cache.d.ts +26 -0
- package/dist/ts/frame/media-cache.d.ts.map +1 -0
- package/dist/ts/frame/media-cache.js +123 -0
- package/dist/ts/frame/media-cache.js.map +1 -0
- package/dist/ts/frame/memory-router.d.ts +10 -0
- package/dist/ts/frame/memory-router.d.ts.map +1 -0
- package/dist/ts/frame/memory-router.js +39 -0
- package/dist/ts/frame/memory-router.js.map +1 -0
- package/dist/ts/frame/parent-hello.d.ts +11 -0
- package/dist/ts/frame/parent-hello.d.ts.map +1 -0
- package/dist/ts/frame/parent-hello.js +53 -0
- package/dist/ts/frame/parent-hello.js.map +1 -0
- package/dist/ts/frame/protocol.d.ts +201 -0
- package/dist/ts/frame/protocol.d.ts.map +1 -0
- package/dist/ts/frame/protocol.js +195 -0
- package/dist/ts/frame/protocol.js.map +1 -0
- package/dist/ts/frame/rpc-content-client.d.ts +10 -0
- package/dist/ts/frame/rpc-content-client.d.ts.map +1 -0
- package/dist/ts/frame/rpc-content-client.js +51 -0
- package/dist/ts/frame/rpc-content-client.js.map +1 -0
- package/dist/ts/frame/save-shortcut.d.ts +8 -0
- package/dist/ts/frame/save-shortcut.d.ts.map +1 -0
- package/dist/ts/frame/save-shortcut.js +26 -0
- package/dist/ts/frame/save-shortcut.js.map +1 -0
- package/dist/ts/host-style-probe.d.ts +32 -37
- package/dist/ts/host-style-probe.d.ts.map +1 -1
- package/dist/ts/host-style-probe.js +86 -68
- package/dist/ts/host-style-probe.js.map +1 -1
- package/dist/ts/index.d.ts +4 -2
- package/dist/ts/index.d.ts.map +1 -1
- package/dist/ts/index.js +6 -2
- package/dist/ts/index.js.map +1 -1
- package/dist/ts/main-spa.d.ts.map +1 -1
- package/dist/ts/main-spa.js +2 -1
- package/dist/ts/main-spa.js.map +1 -1
- package/dist/ts/page-schemas.d.ts.map +1 -1
- package/dist/ts/prose-surface-css.d.ts +3 -5
- package/dist/ts/prose-surface-css.d.ts.map +1 -1
- package/dist/ts/prose-surface-css.js +3 -5
- package/dist/ts/prose-surface-css.js.map +1 -1
- package/dist/ts/puck-config.d.ts.map +1 -1
- package/dist/ts/selected-block.d.ts.map +1 -1
- package/dist/ts/site-styles.d.ts +4 -21
- package/dist/ts/site-styles.d.ts.map +1 -1
- package/dist/ts/site-styles.js.map +1 -1
- package/dist/ts/ui-config.d.ts +50 -1
- package/dist/ts/ui-config.d.ts.map +1 -1
- package/dist/ts/ui-config.js +4 -0
- package/dist/ts/ui-config.js.map +1 -1
- package/package.json +20 -10
- package/src/App.tsx +22 -10
- package/src/CmsSpaApp.tsx +5 -1
- package/src/components/editor/CMSMDXEditor.tsx +49 -69
- package/src/components/editor/PageEditor.tsx +45 -17
- package/src/components/editor/PageEditorWrapper.tsx +34 -5
- package/src/components/editor/draft-media-config.ts +125 -23
- package/src/components/editor/preview-availability.ts +6 -5
- package/src/components/media/AssetCard.tsx +10 -7
- package/src/components/media/AssetDetailSidebar.tsx +6 -6
- package/src/components/pages/PageList.tsx +12 -4
- package/src/components/sandbox/ContentSandbox.tsx +34 -5
- package/src/content-wrapper.ts +284 -0
- package/src/frame/channel.ts +258 -0
- package/src/frame/editor-frame.ts +180 -0
- package/src/frame/media-cache.ts +144 -0
- package/src/frame/memory-router.ts +39 -0
- package/src/frame/parent-hello.ts +62 -0
- package/src/frame/protocol.ts +323 -0
- package/src/frame/rpc-content-client.ts +58 -0
- package/src/frame/save-shortcut.ts +25 -0
- package/src/host-style-probe.ts +104 -90
- package/src/index.ts +7 -2
- package/src/main-spa.tsx +2 -0
- package/src/main.css +2 -1
- package/src/prose-surface-css.ts +3 -5
- package/src/site-styles.ts +4 -22
- package/src/ui-config.ts +52 -1
- package/dist/ts/host-discovery.d.ts +0 -40
- package/dist/ts/host-discovery.d.ts.map +0 -1
- package/dist/ts/host-discovery.js +0 -39
- package/dist/ts/host-discovery.js.map +0 -1
- package/src/host-discovery.ts +0 -77
|
@@ -3,6 +3,7 @@ import { type Config, createUsePuck } from '@puckeditor/core';
|
|
|
3
3
|
import { Monitor, Smartphone, Tablet } from 'lucide-react';
|
|
4
4
|
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { notifyEditorDirtyChanged, registerEditorFlushHandler } from '../../editor-flush.js';
|
|
6
|
+
import { useCanvasSaveShortcut } from '../../frame/save-shortcut.js';
|
|
6
7
|
import { useSiteBaseUrl } from '../../hooks/index.js';
|
|
7
8
|
import { useCanvasTheme } from '../../hooks/useCanvasTheme.js';
|
|
8
9
|
import { useUnsavedChangesGuard } from '../../hooks/useUnsavedChangesGuard.js';
|
|
@@ -185,6 +186,7 @@ export function IframeBridge({ children, document: iframeDoc }: { children: Reac
|
|
|
185
186
|
const { canvasTheme } = useCanvasTheme();
|
|
186
187
|
const siteStyles = useSiteStyles();
|
|
187
188
|
usePageSettingTargets(iframeDoc);
|
|
189
|
+
useCanvasSaveShortcut(iframeDoc);
|
|
188
190
|
|
|
189
191
|
React.useEffect(() => {
|
|
190
192
|
if (!iframeDoc?.documentElement) return;
|
|
@@ -260,6 +262,17 @@ function IframeWithInsertMarker({ children, document: iframeDoc }: { children: R
|
|
|
260
262
|
return <IframeBridge document={iframeDoc}>{children}</IframeBridge>;
|
|
261
263
|
}
|
|
262
264
|
|
|
265
|
+
/**
|
|
266
|
+
* A genuine preview failure, which is a DIFFERENT situation and must not read as though the site is misconfigured.
|
|
267
|
+
* Not latched: a transient fault must not disable a working button.
|
|
268
|
+
*/
|
|
269
|
+
function reportPreviewFailure(error: unknown) {
|
|
270
|
+
toast.error('Could not open preview', {
|
|
271
|
+
description: 'Something went wrong creating the preview link. Please try again.',
|
|
272
|
+
});
|
|
273
|
+
console.error('[PageEditor] openPreview failed:', error);
|
|
274
|
+
}
|
|
275
|
+
|
|
263
276
|
export function PageEditor({
|
|
264
277
|
entry,
|
|
265
278
|
config,
|
|
@@ -404,7 +417,7 @@ export function PageEditor({
|
|
|
404
417
|
|
|
405
418
|
const handlePreview = useCallback(() => {
|
|
406
419
|
const pathname = entry.localized.pathname || '/';
|
|
407
|
-
const openPreview = getUIConfig()
|
|
420
|
+
const { openPreview, openSiteUrl, previewTab: previewTabOwner } = getUIConfig();
|
|
408
421
|
if (openPreview) {
|
|
409
422
|
// Already known to be impossible: explain it without flashing a blank
|
|
410
423
|
// tab open and shut, which reads as a bug even when it is correct.
|
|
@@ -412,6 +425,26 @@ export function PageEditor({
|
|
|
412
425
|
toast.error(PREVIEW_UNAVAILABLE_TITLE, { description: previewBlockedReason, duration: 10_000 });
|
|
413
426
|
return;
|
|
414
427
|
}
|
|
428
|
+
// The site does not serve draft preview, so no URL exists that could
|
|
429
|
+
// work. Say so where the user is looking instead of navigating a tab to
|
|
430
|
+
// a 404 on their own domain, and remember it so the control goes
|
|
431
|
+
// disabled rather than staying a trap.
|
|
432
|
+
const markPreviewUnavailable = (message: string) => {
|
|
433
|
+
const detail = message !== '' ? message : PREVIEW_UNAVAILABLE_DETAIL;
|
|
434
|
+
setPreviewBlockedReason(detail);
|
|
435
|
+
setPreviewCapability('unavailable');
|
|
436
|
+
toast.error(PREVIEW_UNAVAILABLE_TITLE, { description: detail, duration: 10_000 });
|
|
437
|
+
};
|
|
438
|
+
// The parent frame opens the tab during the click itself; a blocked
|
|
439
|
+
// popup is the parent's to explain, so the editor shows nothing for it.
|
|
440
|
+
if (previewTabOwner === 'parent') {
|
|
441
|
+
void openPreview({ path: pathname })
|
|
442
|
+
.then((result) => {
|
|
443
|
+
if (!result.ok && result.reason === 'not-deployed') markPreviewUnavailable(result.message);
|
|
444
|
+
})
|
|
445
|
+
.catch(reportPreviewFailure);
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
415
448
|
// Popup blockers only allow window creation during the click itself.
|
|
416
449
|
// `openPreview` answers asynchronously, so reserve a blank tab now and
|
|
417
450
|
// navigate it once the preview URL arrives.
|
|
@@ -424,31 +457,26 @@ export function PageEditor({
|
|
|
424
457
|
void openPreview({ path: pathname })
|
|
425
458
|
.then((result) => {
|
|
426
459
|
if (result.ok) {
|
|
427
|
-
previewTab.location.href = result.url;
|
|
460
|
+
if ('url' in result) previewTab.location.href = result.url;
|
|
461
|
+
else previewTab.close();
|
|
428
462
|
return;
|
|
429
463
|
}
|
|
430
|
-
// The site does not serve draft preview, so no URL exists that could
|
|
431
|
-
// work. Say so where the user is looking instead of navigating the
|
|
432
|
-
// tab to a 404 on their own domain, and remember it so the control
|
|
433
|
-
// goes disabled rather than staying a trap.
|
|
434
464
|
previewTab.close();
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
setPreviewCapability('unavailable');
|
|
438
|
-
toast.error(PREVIEW_UNAVAILABLE_TITLE, { description: detail, duration: 10_000 });
|
|
465
|
+
// `popup-blocked` cannot happen here, the editor holds the tab.
|
|
466
|
+
if (result.reason === 'not-deployed') markPreviewUnavailable(result.message);
|
|
439
467
|
})
|
|
440
468
|
.catch((error: unknown) => {
|
|
441
|
-
// A genuine failure, which is a DIFFERENT situation and must not
|
|
442
|
-
// read as though the site is misconfigured. Not latched:
|
|
443
|
-
// a transient fault must not disable a working button.
|
|
444
469
|
previewTab.close();
|
|
445
|
-
|
|
446
|
-
description: 'Something went wrong creating the preview link. Please try again.',
|
|
447
|
-
});
|
|
448
|
-
console.error('[PageEditor] openPreview failed:', error);
|
|
470
|
+
reportPreviewFailure(error);
|
|
449
471
|
});
|
|
450
472
|
return;
|
|
451
473
|
}
|
|
474
|
+
if (openSiteUrl) {
|
|
475
|
+
void openSiteUrl({ path: pathname }).catch((error: unknown) =>
|
|
476
|
+
console.error('[PageEditor] openSiteUrl failed:', error),
|
|
477
|
+
);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
452
480
|
const previewUrl = buildUrl(pathname);
|
|
453
481
|
const cacheBustedUrl = `${previewUrl}${previewUrl.includes('?') ? '&' : '?'}_t=${Date.now()}`;
|
|
454
482
|
window.open(cacheBustedUrl, '_blank');
|
|
@@ -330,9 +330,28 @@ function PuckPageEditorInner({ puckConfig, initialLocale }: PageEditorWrapperPro
|
|
|
330
330
|
const puckData = content?.localized?.content?.puckData;
|
|
331
331
|
|
|
332
332
|
// Resolving again replaces the editor, unsaved block edits included, so it
|
|
333
|
-
// runs when the blocks
|
|
334
|
-
//
|
|
335
|
-
// canvas takes from
|
|
333
|
+
// runs when the blocks change other than by the editor's own save, or the
|
|
334
|
+
// data their route binds changes, and reads the page when it runs: a Page
|
|
335
|
+
// settings save changes only the page, which the canvas takes from
|
|
336
|
+
// `metadata` without remounting.
|
|
337
|
+
//
|
|
338
|
+
// The editor's own save puts the page it read back into the cache, but the
|
|
339
|
+
// editor already holds that page, and anything typed while the save was
|
|
340
|
+
// out, which a new editor would drop. So a change to the blocks counts only
|
|
341
|
+
// when it is not that page: another etag, or another locale than the one the
|
|
342
|
+
// editor holds.
|
|
343
|
+
const ownSaveRef = useRef<{ locale: string; etag: string } | null>(null);
|
|
344
|
+
const blocksRef = useRef({ puckData, locale: currentLocale, changes: 0 });
|
|
345
|
+
if (puckData !== blocksRef.current.puckData) {
|
|
346
|
+
const own = ownSaveRef.current;
|
|
347
|
+
const ownSave =
|
|
348
|
+
own !== null &&
|
|
349
|
+
own.locale === currentLocale &&
|
|
350
|
+
blocksRef.current.locale === currentLocale &&
|
|
351
|
+
own.etag === content?.localized?.etag;
|
|
352
|
+
blocksRef.current = { puckData, locale: currentLocale, changes: blocksRef.current.changes + (ownSave ? 0 : 1) };
|
|
353
|
+
}
|
|
354
|
+
const blockChanges = blocksRef.current.changes;
|
|
336
355
|
const dataContextRef = useRef(dataContext);
|
|
337
356
|
dataContextRef.current = dataContext;
|
|
338
357
|
const routeCollections = dataContext?.collections;
|
|
@@ -341,7 +360,7 @@ function PuckPageEditorInner({ puckConfig, initialLocale }: PageEditorWrapperPro
|
|
|
341
360
|
// Pre-resolve component data using resolveAllData.
|
|
342
361
|
// This runs each component's resolveData with the data context as its
|
|
343
362
|
// metadata, ensuring data-bound components have their data BEFORE Puck mounts.
|
|
344
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: the route's bound data
|
|
363
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the blocks' changes and the route's bound data are the events; the page and its data context are read when it runs.
|
|
345
364
|
useEffect(() => {
|
|
346
365
|
let cancelled = false;
|
|
347
366
|
|
|
@@ -375,7 +394,7 @@ function PuckPageEditorInner({ puckConfig, initialLocale }: PageEditorWrapperPro
|
|
|
375
394
|
return () => {
|
|
376
395
|
cancelled = true;
|
|
377
396
|
};
|
|
378
|
-
}, [
|
|
397
|
+
}, [blockChanges, enhancedConfig, routeCollections, routePages]);
|
|
379
398
|
|
|
380
399
|
const pageMetadata = useMemo(() => (content?.localized ? extractPageMetadata(content) : null), [content]);
|
|
381
400
|
|
|
@@ -439,6 +458,16 @@ function PuckPageEditorInner({ puckConfig, initialLocale }: PageEditorWrapperPro
|
|
|
439
458
|
if (result.success && result.etag) {
|
|
440
459
|
setCurrentEtag(result.etag);
|
|
441
460
|
}
|
|
461
|
+
// Recorded before this component renders the page the save read back: the cache tells its readers
|
|
462
|
+
// on a later task, and `mutateAsync` settles first. Only a read-back of exactly this write is the
|
|
463
|
+
// editor's own; one someone else saved since must open, or the next save would write over it.
|
|
464
|
+
if (
|
|
465
|
+
'updatedContent' in result &&
|
|
466
|
+
result.updatedContent &&
|
|
467
|
+
result.updatedContent.localized.etag === result.etag
|
|
468
|
+
) {
|
|
469
|
+
ownSaveRef.current = { locale: currentLocale, etag: result.updatedContent.localized.etag };
|
|
470
|
+
}
|
|
442
471
|
|
|
443
472
|
return result;
|
|
444
473
|
} catch (error) {
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
/** Resolve unpublished draft images for site renderers without changing Puck's persisted data. */
|
|
2
|
+
/* oxlint-disable anti-slop/no-unsafe-dictionary-type, anti-slop/no-unknown-returns -- block props are whatever the site's components take; this walk only swaps image strings and passes every other value through as it came. */
|
|
2
3
|
import { IMAGE_EXTENSION_MIME } from '@conloca/content-api-client';
|
|
3
4
|
import type { Config, Field, Fields } from '@puckeditor/core';
|
|
4
5
|
import { type ComponentType, createElement, isValidElement } from 'react';
|
|
6
|
+
import { loadedMedia, mediaObjectUrl, useMediaCacheVersion } from '../../frame/media-cache.js';
|
|
7
|
+
import { getUIConfig } from '../../ui-config.js';
|
|
5
8
|
import { appendAssetUrlPath } from '../../utils/asset-url.js';
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
/** What a validated draft image path renders as; `undefined` keeps the canonical value. */
|
|
11
|
+
type DraftImageResolver = (path: string) => string | undefined;
|
|
12
|
+
|
|
13
|
+
/** The raw media path of a canonical `/assets/<path>` image reference, or `undefined` when it is not a safe image path. */
|
|
14
|
+
function draftImagePath(value: string): string | undefined {
|
|
15
|
+
if (!value.startsWith('/assets/')) return undefined;
|
|
9
16
|
const path = value.slice('/assets/'.length);
|
|
10
|
-
if (/[\\?#]/.test(path)) return
|
|
17
|
+
if (/[\\?#]/.test(path)) return undefined;
|
|
11
18
|
const segments = path.split('/');
|
|
12
19
|
for (const part of segments) {
|
|
13
20
|
if (
|
|
@@ -16,43 +23,122 @@ function draftImageUrl(value: string, base: string): string {
|
|
|
16
23
|
part === '..' ||
|
|
17
24
|
[...part].some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127)
|
|
18
25
|
) {
|
|
19
|
-
return
|
|
26
|
+
return undefined;
|
|
20
27
|
}
|
|
21
28
|
}
|
|
22
29
|
const filename = segments[segments.length - 1] ?? '';
|
|
23
30
|
const dot = filename.lastIndexOf('.');
|
|
24
|
-
if (dot <= 0) return
|
|
31
|
+
if (dot <= 0) return undefined;
|
|
25
32
|
const extension = filename.slice(dot + 1).toLowerCase();
|
|
26
|
-
if (!Object.prototype.hasOwnProperty.call(IMAGE_EXTENSION_MIME, extension)) return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
if (!Object.prototype.hasOwnProperty.call(IMAGE_EXTENSION_MIME, extension)) return undefined;
|
|
34
|
+
return path;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function draftImageUrl(path: string, base: string): string {
|
|
38
|
+
const encoded = path
|
|
39
|
+
.split('/')
|
|
40
|
+
.map((part) =>
|
|
41
|
+
encodeURIComponent(part).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`),
|
|
42
|
+
);
|
|
30
43
|
return appendAssetUrlPath(base, encoded.join('/'));
|
|
31
44
|
}
|
|
32
45
|
|
|
46
|
+
/**
|
|
47
|
+
* What the MDX editor canvas shows for an image `src`: the loaded bytes of a draft image, else `src` itself.
|
|
48
|
+
* The URL is the media cache's own, which a media write or eviction revokes; mdxeditor resolves an image again only
|
|
49
|
+
* when its `src` changes or it remounts, so a mounted image keeps painting its decoded bytes from a revoked URL.
|
|
50
|
+
*/
|
|
51
|
+
export async function draftImagePreview(src: string): Promise<string> {
|
|
52
|
+
const path = draftImagePath(src);
|
|
53
|
+
return (path === undefined ? undefined : (await loadedMedia('draft', path))?.url) ?? src;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function dataUrl(blob: Blob): Promise<string> {
|
|
57
|
+
// The package's lib target predates Promise.withResolvers.
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
const reader = new FileReader();
|
|
60
|
+
reader.addEventListener('load', () => {
|
|
61
|
+
if (typeof reader.result === 'string') resolve(reader.result);
|
|
62
|
+
else reject(new Error('The image could not be read as a data URL.'));
|
|
63
|
+
});
|
|
64
|
+
reader.addEventListener('error', () => {
|
|
65
|
+
reject(reader.error ?? new Error('The image could not be read.'));
|
|
66
|
+
});
|
|
67
|
+
reader.readAsDataURL(blob);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Keyed by the cached Blob, so a cleared or evicted cache entry frees its string too.
|
|
72
|
+
const dataUrls = new WeakMap<Blob, Promise<string>>();
|
|
73
|
+
|
|
74
|
+
async function draftImageDataUrl(src: string): Promise<string | undefined> {
|
|
75
|
+
const path = draftImagePath(src);
|
|
76
|
+
const media = path === undefined ? undefined : await loadedMedia('draft', path);
|
|
77
|
+
if (!media) return undefined;
|
|
78
|
+
let url = dataUrls.get(media.blob);
|
|
79
|
+
if (!url) {
|
|
80
|
+
url = dataUrl(media.blob);
|
|
81
|
+
dataUrls.set(media.blob, url);
|
|
82
|
+
}
|
|
83
|
+
return url;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** How long a preview update waits for its draft images before it goes without the ones still loading. */
|
|
87
|
+
export const DRAFT_IMAGE_WAIT_MS = 5000;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Data URLs of the draft images a compiled MDX body names, keyed by their canonical `src`, for the
|
|
91
|
+
* opaque-origin preview frame, which cannot read this page's blob URLs. Images that fail to load, or are
|
|
92
|
+
* still loading after `DRAFT_IMAGE_WAIT_MS`, are left out.
|
|
93
|
+
*/
|
|
94
|
+
export async function draftImageData(code: string): Promise<Record<string, string>> {
|
|
95
|
+
// shortcut: finds srcs only as plain double-quoted literals, the form the MDX compiler emits for these paths; widen if an escaped path must preview.
|
|
96
|
+
const srcs = new Set(code.match(/"\/assets\/[^"\\]*"/g)?.map((literal) => literal.slice(1, -1)));
|
|
97
|
+
const images: Record<string, string> = {};
|
|
98
|
+
let timer: number | undefined;
|
|
99
|
+
const expired = new Promise<undefined>((resolve) => {
|
|
100
|
+
timer = window.setTimeout(resolve, DRAFT_IMAGE_WAIT_MS, undefined);
|
|
101
|
+
});
|
|
102
|
+
await Promise.all(
|
|
103
|
+
[...srcs].map(async (src) => {
|
|
104
|
+
const url = await Promise.race([draftImageDataUrl(src).catch(() => undefined), expired]);
|
|
105
|
+
if (url !== undefined) images[src] = url;
|
|
106
|
+
}),
|
|
107
|
+
);
|
|
108
|
+
window.clearTimeout(timer);
|
|
109
|
+
return images;
|
|
110
|
+
}
|
|
111
|
+
|
|
33
112
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
34
113
|
if (value === null || typeof value !== 'object' || isValidElement(value)) return false;
|
|
35
114
|
const prototype: unknown = Object.getPrototypeOf(value);
|
|
36
115
|
return prototype === Object.prototype || prototype === null;
|
|
37
116
|
}
|
|
38
117
|
|
|
39
|
-
function fieldValue(value: unknown, field: Field,
|
|
118
|
+
function fieldValue(value: unknown, field: Field, resolve: DraftImageResolver): unknown {
|
|
40
119
|
if (field.type === 'slot') return value;
|
|
41
|
-
if (typeof value === 'string')
|
|
42
|
-
|
|
120
|
+
if (typeof value === 'string') {
|
|
121
|
+
const path = draftImagePath(value);
|
|
122
|
+
return path === undefined ? value : (resolve(path) ?? value);
|
|
123
|
+
}
|
|
124
|
+
if (field.type === 'object' && isRecord(value)) return fieldProps(value, field.objectFields, resolve);
|
|
43
125
|
if (field.type === 'array' && Array.isArray(value)) {
|
|
44
|
-
const next = value.map((item: unknown) => (isRecord(item) ? fieldProps(item, field.arrayFields,
|
|
126
|
+
const next = value.map((item: unknown) => (isRecord(item) ? fieldProps(item, field.arrayFields, resolve) : item));
|
|
45
127
|
return next.some((item, index) => item !== value[index]) ? next : value;
|
|
46
128
|
}
|
|
47
129
|
return value;
|
|
48
130
|
}
|
|
49
131
|
|
|
50
|
-
function fieldProps(
|
|
132
|
+
function fieldProps(
|
|
133
|
+
props: Record<string, unknown>,
|
|
134
|
+
fields: Fields | undefined,
|
|
135
|
+
resolve: DraftImageResolver,
|
|
136
|
+
): Record<string, unknown> {
|
|
51
137
|
let next = props;
|
|
52
138
|
for (const [name, field] of Object.entries(fields ?? {})) {
|
|
53
139
|
if (name === 'puck' || name === 'children' || name === 'editMode') continue;
|
|
54
140
|
if (field === undefined || !Object.prototype.hasOwnProperty.call(props, name)) continue;
|
|
55
|
-
const value = fieldValue(props[name], field,
|
|
141
|
+
const value = fieldValue(props[name], field, resolve);
|
|
56
142
|
if (value === props[name]) continue;
|
|
57
143
|
if (next === props) next = { ...props };
|
|
58
144
|
next[name] = value;
|
|
@@ -60,9 +146,18 @@ function fieldProps(props: Record<string, unknown>, fields: Fields | undefined,
|
|
|
60
146
|
return next;
|
|
61
147
|
}
|
|
62
148
|
|
|
63
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* Static declared fields bound traversal; dynamic field resolvers and runtime contexts remain untouched.
|
|
151
|
+
* With `UIConfig.loadMedia` set, `base` is ignored: draft images show object URLs of the loaded bytes,
|
|
152
|
+
* the canonical value until they arrive.
|
|
153
|
+
*/
|
|
64
154
|
export function withDraftMediaRendering(config: Config, base: string | undefined): Config {
|
|
65
|
-
|
|
155
|
+
const resolve: DraftImageResolver | undefined = getUIConfig().loadMedia
|
|
156
|
+
? (path) => mediaObjectUrl('draft', path)
|
|
157
|
+
: base === undefined
|
|
158
|
+
? undefined
|
|
159
|
+
: (path) => draftImageUrl(path, base);
|
|
160
|
+
if (resolve === undefined) return config;
|
|
66
161
|
const root = config.root;
|
|
67
162
|
const rootRender = root?.render;
|
|
68
163
|
return {
|
|
@@ -73,11 +168,16 @@ export function withDraftMediaRendering(config: Config, base: string | undefined
|
|
|
73
168
|
...root,
|
|
74
169
|
// Rendered as an element so memo/forwardRef roots keep working. Root props are a
|
|
75
170
|
// children/no-children union, so name the component's own prop type for createElement.
|
|
76
|
-
render: (props: Parameters<typeof rootRender>[0]) =>
|
|
77
|
-
|
|
171
|
+
render: (props: Parameters<typeof rootRender>[0]) => {
|
|
172
|
+
// Re-render when a loaded image arrives.
|
|
173
|
+
useMediaCacheVersion();
|
|
174
|
+
// SAFETY: `props` is typed from `rootRender` itself; the cast only picks one member of Puck's root union.
|
|
175
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- see the SAFETY note.
|
|
176
|
+
return createElement(rootRender as ComponentType<typeof props>, {
|
|
78
177
|
...props,
|
|
79
|
-
...fieldProps(props, root.fields,
|
|
80
|
-
})
|
|
178
|
+
...fieldProps(props, root.fields, resolve),
|
|
179
|
+
});
|
|
180
|
+
},
|
|
81
181
|
},
|
|
82
182
|
}
|
|
83
183
|
: {}),
|
|
@@ -86,8 +186,10 @@ export function withDraftMediaRendering(config: Config, base: string | undefined
|
|
|
86
186
|
name,
|
|
87
187
|
{
|
|
88
188
|
...component,
|
|
89
|
-
render: (props: Parameters<typeof component.render>[0]) =>
|
|
90
|
-
|
|
189
|
+
render: (props: Parameters<typeof component.render>[0]) => {
|
|
190
|
+
useMediaCacheVersion();
|
|
191
|
+
return createElement(component.render, { ...props, ...fieldProps(props, component.fields, resolve) });
|
|
192
|
+
},
|
|
91
193
|
},
|
|
92
194
|
]),
|
|
93
195
|
),
|
|
@@ -8,13 +8,14 @@
|
|
|
8
8
|
* `@lexical`.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
/** Toast heading when the
|
|
12
|
-
export const PREVIEW_UNAVAILABLE_TITLE = 'Preview is not available for this
|
|
11
|
+
/** Toast heading when the branch cannot show a preview. */
|
|
12
|
+
export const PREVIEW_UNAVAILABLE_TITLE = 'Preview is not available for this branch';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* The explanation, used both as the toast body and as the disabled control's
|
|
16
|
-
* reason.
|
|
17
|
-
*
|
|
16
|
+
* reason. Preview support is checked per branch (one origin can serve one
|
|
17
|
+
* branch's drafts and not another's), so it names the branch, never the whole
|
|
18
|
+
* site; it reassures that nothing they did is broken.
|
|
18
19
|
*/
|
|
19
20
|
export const PREVIEW_UNAVAILABLE_DETAIL =
|
|
20
|
-
'This
|
|
21
|
+
'This branch has no preview server, so there is no preview page to open. Your draft is still saved, and publishing and the live site are unaffected.';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { useAssetServeSrc } from '../../frame/media-cache.js';
|
|
1
2
|
import type { AssetEntry } from '../../hooks/index.js';
|
|
2
3
|
import { AssetScopePill } from '../../media/AssetScopePill.js';
|
|
3
4
|
import { MediaIssueBadge } from '../../media/MediaIssueBadge.js';
|
|
4
5
|
import { useAssetScope } from '../../media/use-asset-scope.js';
|
|
5
6
|
import { useMediaIssue } from '../../media/use-media-issue.js';
|
|
6
|
-
import { buildAssetServeUrl } from '../../utils/asset-url.js';
|
|
7
7
|
import { cn } from '../../utils/cn.js';
|
|
8
8
|
|
|
9
9
|
interface AssetCardProps {
|
|
@@ -33,6 +33,7 @@ export function AssetCard({
|
|
|
33
33
|
// reports. Returns null when the host has no opinion — surfaces
|
|
34
34
|
// degrade exactly like the scope pill in standalone mounts.
|
|
35
35
|
const issue = useMediaIssue(asset.filename, asset.folder);
|
|
36
|
+
const src = useAssetServeSrc(assetsBasePath, asset.folder, asset.filename);
|
|
36
37
|
|
|
37
38
|
const handleClick = () => {
|
|
38
39
|
onClick?.();
|
|
@@ -55,12 +56,14 @@ export function AssetCard({
|
|
|
55
56
|
>
|
|
56
57
|
{/* Thumbnail */}
|
|
57
58
|
<div className="relative aspect-square bg-grey-11 dark:bg-grey-03 flex items-center justify-center overflow-hidden">
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
{src ? (
|
|
60
|
+
<img
|
|
61
|
+
src={src}
|
|
62
|
+
alt={asset.alt || asset.originalName}
|
|
63
|
+
className="w-full h-full object-contain"
|
|
64
|
+
loading="lazy"
|
|
65
|
+
/>
|
|
66
|
+
) : null}
|
|
64
67
|
{/* Scope pill — renders only when a host bridge supplied a
|
|
65
68
|
non-null scope. Top-left corner so it sits above the
|
|
66
69
|
asset's own visual focus point without clipping the
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { formatFileSize } from '@conloca/content-api-client';
|
|
2
2
|
import { FolderInput, Loader2, Trash2, X } from 'lucide-react';
|
|
3
3
|
import { useMemo, useState } from 'react';
|
|
4
|
+
import { useAssetServeSrc } from '../../frame/media-cache.js';
|
|
4
5
|
import type { AssetEntry } from '../../hooks/index.js';
|
|
5
6
|
import { useAssetUsage, useDeleteAsset, useMoveAssets, useUpdateAssetMetadata } from '../../hooks/index.js';
|
|
6
7
|
import { AssetScopePill } from '../../media/AssetScopePill.js';
|
|
7
8
|
import { MediaIssueBadge } from '../../media/MediaIssueBadge.js';
|
|
8
9
|
import { useAssetScope } from '../../media/use-asset-scope.js';
|
|
9
10
|
import { useMediaIssue } from '../../media/use-media-issue.js';
|
|
10
|
-
import { buildAssetPath
|
|
11
|
+
import { buildAssetPath } from '../../utils/asset-url.js';
|
|
11
12
|
import { MoveFolderDialog } from '../dialogs/index.js';
|
|
12
13
|
import { Button, IconButton, Input } from '../ui/index.js';
|
|
13
14
|
|
|
@@ -55,6 +56,7 @@ export function AssetDetailSidebar({
|
|
|
55
56
|
// Returns null when the host has no opinion or the asset is
|
|
56
57
|
// healthy; the badge collapses to nothing in either case.
|
|
57
58
|
const issue = useMediaIssue(asset.filename, asset.folder);
|
|
59
|
+
const src = useAssetServeSrc(assetsBasePath, asset.folder, asset.filename);
|
|
58
60
|
// Folder + filename is the asset identity used by metadata, usage and delete routes.
|
|
59
61
|
const path = useMemo(() => buildAssetPath(asset.folder, asset.filename), [asset.folder, asset.filename]);
|
|
60
62
|
|
|
@@ -177,11 +179,9 @@ export function AssetDetailSidebar({
|
|
|
177
179
|
<div className="flex-1 overflow-y-auto">
|
|
178
180
|
{/* Thumbnail preview */}
|
|
179
181
|
<div className="aspect-square bg-subtle flex items-center justify-center overflow-hidden border-b border-line">
|
|
180
|
-
|
|
181
|
-
src={
|
|
182
|
-
|
|
183
|
-
className="max-w-full max-h-full object-contain"
|
|
184
|
-
/>
|
|
182
|
+
{src ? (
|
|
183
|
+
<img src={src} alt={asset.alt || asset.originalName} className="max-w-full max-h-full object-contain" />
|
|
184
|
+
) : null}
|
|
185
185
|
</div>
|
|
186
186
|
|
|
187
187
|
{/* File info (read-only) */}
|
|
@@ -4,6 +4,7 @@ import { useMemo, useState } from 'react';
|
|
|
4
4
|
import { useNavigate } from 'react-router-dom';
|
|
5
5
|
import { useErrorModal, useSiteBaseUrl } from '../../hooks/index.js';
|
|
6
6
|
import type { Page } from '../../types.js';
|
|
7
|
+
import { getUIConfig } from '../../ui-config.js';
|
|
7
8
|
import { contentFailureMessage, isStaleWrite } from '../../utils/content-failure.js';
|
|
8
9
|
import { formatDate } from '../../utils/format-date.js';
|
|
9
10
|
import { CreatePageFlow } from '../dialogs/CreatePageFlow.js';
|
|
@@ -38,9 +39,16 @@ export function PageList({ selectedSite, selectedLocale: initialLocale }: PageLi
|
|
|
38
39
|
const navigate = useNavigate();
|
|
39
40
|
const deleteContent = useDeleteContent();
|
|
40
41
|
|
|
41
|
-
const
|
|
42
|
+
const openLiveSite = (pagePath: string) => {
|
|
43
|
+
const openSiteUrl = getUIConfig().openSiteUrl;
|
|
44
|
+
if (openSiteUrl) {
|
|
45
|
+
void openSiteUrl({ path: pagePath }).catch((error: unknown) =>
|
|
46
|
+
console.error('[PageList] openSiteUrl failed:', error),
|
|
47
|
+
);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
42
50
|
const previewUrl = buildUrl(pagePath);
|
|
43
|
-
|
|
51
|
+
window.open(`${previewUrl}${previewUrl.includes('?') ? '&' : '?'}_t=${Date.now()}`, '_blank');
|
|
44
52
|
};
|
|
45
53
|
|
|
46
54
|
// Use provided site or default
|
|
@@ -398,7 +406,7 @@ export function PageList({ selectedSite, selectedLocale: initialLocale }: PageLi
|
|
|
398
406
|
data-testid={`page-title-${page.id}`}
|
|
399
407
|
onClick={(e) => {
|
|
400
408
|
e.preventDefault();
|
|
401
|
-
|
|
409
|
+
openLiveSite(page.path);
|
|
402
410
|
}}
|
|
403
411
|
>
|
|
404
412
|
{page.title}
|
|
@@ -429,7 +437,7 @@ export function PageList({ selectedSite, selectedLocale: initialLocale }: PageLi
|
|
|
429
437
|
className="text-grey-04 dark:text-grey-07 hover:text-azure-04 dark:hover:text-azure-06 hover:underline transition-colors font-mono text-xs"
|
|
430
438
|
onClick={(e) => {
|
|
431
439
|
e.preventDefault();
|
|
432
|
-
|
|
440
|
+
openLiveSite(page.path);
|
|
433
441
|
}}
|
|
434
442
|
>
|
|
435
443
|
{page.path}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import cn from 'clsx';
|
|
2
2
|
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { getUIConfig } from '../../ui-config.js';
|
|
4
|
+
import { draftImageData } from '../editor/draft-media-config.js';
|
|
3
5
|
import { SANDBOX_FRAME_PATH, type SandboxOutboundMessage } from './frame-runtime.js';
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -22,10 +24,31 @@ function ensureSandboxHeightBus(win: Window): void {
|
|
|
22
24
|
if (!data.k || !(data.px > 0)) return;
|
|
23
25
|
const doc = win.document;
|
|
24
26
|
const el = doc.querySelector(`iframe[data-sandbox-k="${data.k}"]`) as HTMLIFrameElement | null;
|
|
25
|
-
if (el) el.style.height = `${Math.ceil(data.px)}px`;
|
|
27
|
+
if (el && event.source === el.contentWindow) el.style.height = `${Math.ceil(data.px)}px`;
|
|
26
28
|
});
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Data URLs of the draft images in `code`, which the opaque-origin frame cannot fetch from the site or read as
|
|
33
|
+
* this page's blob URLs; `null` while they load (bounded by `draftImageData`), `undefined` when `code` is `undefined`.
|
|
34
|
+
*/
|
|
35
|
+
function useDraftImageData(code: string | undefined): Record<string, string> | null | undefined {
|
|
36
|
+
const [loaded, setLoaded] = useState<{ code: string; images: Record<string, string> }>();
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
let live = true;
|
|
39
|
+
if (code !== undefined) {
|
|
40
|
+
void draftImageData(code).then((images) => {
|
|
41
|
+
if (live) setLoaded({ code, images });
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return () => {
|
|
45
|
+
live = false;
|
|
46
|
+
};
|
|
47
|
+
}, [code]);
|
|
48
|
+
if (code === undefined) return undefined;
|
|
49
|
+
return loaded?.code === code ? loaded.images : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
29
52
|
export interface ContentSandboxProps {
|
|
30
53
|
/** `mdx` delivers a compiled MDX function body; `html` a sanitized HTML string. */
|
|
31
54
|
mode: 'mdx' | 'html';
|
|
@@ -69,7 +92,7 @@ export function ContentSandbox({
|
|
|
69
92
|
const iframeRef = useRef<HTMLIFrameElement | null>(null);
|
|
70
93
|
const reactId = useId().replace(/:/g, '');
|
|
71
94
|
const frameKeyRef = useRef(`sf_${reactId}_${Math.random().toString(36).slice(2, 10)}`);
|
|
72
|
-
const frameSrc = `${SANDBOX_FRAME_PATH}?k=${encodeURIComponent(frameKeyRef.current)}`;
|
|
95
|
+
const frameSrc = `${getUIConfig().sandboxFramePath ?? SANDBOX_FRAME_PATH}?k=${encodeURIComponent(frameKeyRef.current)}`;
|
|
73
96
|
|
|
74
97
|
const modeRef = useRef(mode);
|
|
75
98
|
const contentRef = useRef(content);
|
|
@@ -77,13 +100,16 @@ export function ContentSandbox({
|
|
|
77
100
|
modeRef.current = mode;
|
|
78
101
|
contentRef.current = content;
|
|
79
102
|
stylesRef.current = styles;
|
|
103
|
+
const images = useDraftImageData(mode === 'mdx' && getUIConfig().loadMedia ? content : undefined);
|
|
104
|
+
const imagesRef = useRef(images);
|
|
105
|
+
imagesRef.current = images;
|
|
80
106
|
|
|
81
107
|
const [height, setHeight] = useState(0);
|
|
82
108
|
const [ready, setReady] = useState(false);
|
|
83
109
|
const readyRef = useRef(false);
|
|
84
110
|
|
|
85
111
|
const deliver = useCallback(() => {
|
|
86
|
-
if (!readyRef.current) return;
|
|
112
|
+
if (!readyRef.current || imagesRef.current === null) return;
|
|
87
113
|
const payload = contentRef.current;
|
|
88
114
|
iframeRef.current?.contentWindow?.postMessage(
|
|
89
115
|
{
|
|
@@ -92,6 +118,7 @@ export function ContentSandbox({
|
|
|
92
118
|
mode: modeRef.current,
|
|
93
119
|
payload,
|
|
94
120
|
styles: stylesRef.current,
|
|
121
|
+
...(imagesRef.current ? { images: imagesRef.current } : {}),
|
|
95
122
|
},
|
|
96
123
|
'*',
|
|
97
124
|
);
|
|
@@ -114,6 +141,8 @@ export function ContentSandbox({
|
|
|
114
141
|
const data = event.data as SandboxOutboundMessage | undefined;
|
|
115
142
|
if (data?.__conlocaSandbox !== true) return;
|
|
116
143
|
if (data.k !== frameKey) return;
|
|
144
|
+
// The key is readable by anything that saw the frame URL; the source is not forgeable.
|
|
145
|
+
if (event.source === null || event.source !== iframeRef.current?.contentWindow) return;
|
|
117
146
|
switch (data.kind) {
|
|
118
147
|
case 'ready':
|
|
119
148
|
markReady();
|
|
@@ -160,11 +189,11 @@ export function ContentSandbox({
|
|
|
160
189
|
};
|
|
161
190
|
}, [ready, deliver]);
|
|
162
191
|
|
|
163
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: Mode, content, and
|
|
192
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: Mode, content, styles and images are delivery events; deliver reads their current values from refs to keep message listeners stable.
|
|
164
193
|
useEffect(() => {
|
|
165
194
|
if (!ready) return;
|
|
166
195
|
deliver();
|
|
167
|
-
}, [ready, mode, content, styles, deliver]);
|
|
196
|
+
}, [ready, mode, content, styles, images, deliver]);
|
|
168
197
|
|
|
169
198
|
return (
|
|
170
199
|
<iframe
|