@conloca/cms-spa 0.2.1 → 0.2.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/dist/spa/main.css +17 -3
- package/dist/ts/App.d.ts +5 -1
- package/dist/ts/App.d.ts.map +1 -1
- package/dist/ts/App.js +7 -2
- package/dist/ts/App.js.map +1 -1
- package/dist/ts/components/CMSDashboard.d.ts.map +1 -1
- package/dist/ts/components/CMSDashboard.js +6 -2
- package/dist/ts/components/CMSDashboard.js.map +1 -1
- package/dist/ts/components/RouteErrorPage.d.ts +11 -0
- package/dist/ts/components/RouteErrorPage.d.ts.map +1 -0
- package/dist/ts/components/RouteErrorPage.js +44 -0
- package/dist/ts/components/RouteErrorPage.js.map +1 -0
- 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/dashboard/RecentActivity.d.ts.map +1 -1
- package/dist/ts/components/dashboard/RecentActivity.js +2 -8
- package/dist/ts/components/dashboard/RecentActivity.js.map +1 -1
- package/dist/ts/components/dialogs/CreateDataDialog.js +2 -2
- package/dist/ts/components/dialogs/CreateDataDialog.js.map +1 -1
- package/dist/ts/components/dialogs/CreateFolderDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/CreateFolderDialog.js +2 -1
- package/dist/ts/components/dialogs/CreateFolderDialog.js.map +1 -1
- package/dist/ts/components/dialogs/CreatePageFlow.d.ts +13 -0
- package/dist/ts/components/dialogs/CreatePageFlow.d.ts.map +1 -0
- package/dist/ts/components/dialogs/CreatePageFlow.js +100 -0
- package/dist/ts/components/dialogs/CreatePageFlow.js.map +1 -0
- package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts +1 -1
- package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/DataPropertiesDialog.js +2 -2
- package/dist/ts/components/dialogs/DataPropertiesDialog.js.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 +2 -2
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.js +2 -2
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.js.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/dialogs/PageMetadataDialog.d.ts +2 -12
- package/dist/ts/components/dialogs/PageMetadataDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/PageMetadataDialog.js +3 -21
- package/dist/ts/components/dialogs/PageMetadataDialog.js.map +1 -1
- package/dist/ts/components/editor/DrawerItemOverride.d.ts +2 -0
- package/dist/ts/components/editor/DrawerItemOverride.d.ts.map +1 -1
- package/dist/ts/components/editor/DrawerItemOverride.js +4 -3
- package/dist/ts/components/editor/DrawerItemOverride.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 +7 -8
- package/dist/ts/components/editor/PageEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditor.js +78 -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/PageEditorHeaderActions.js +1 -1
- package/dist/ts/components/editor/PageEditorHeaderActions.js.map +1 -1
- package/dist/ts/components/editor/PageEditorWrapper.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditorWrapper.js +17 -7
- package/dist/ts/components/editor/PageEditorWrapper.js.map +1 -1
- package/dist/ts/components/editor/draft-media-config.d.ts +4 -0
- package/dist/ts/components/editor/draft-media-config.d.ts.map +1 -0
- package/dist/ts/components/editor/draft-media-config.js +95 -0
- package/dist/ts/components/editor/draft-media-config.js.map +1 -0
- 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/editors/DataEditor.d.ts +3 -3
- package/dist/ts/components/editors/DataEditor.d.ts.map +1 -1
- package/dist/ts/components/forms/HintForm.js +8 -5
- package/dist/ts/components/forms/HintForm.js.map +1 -1
- package/dist/ts/components/forms/SchemaForm.d.ts +17 -5
- package/dist/ts/components/forms/SchemaForm.d.ts.map +1 -1
- package/dist/ts/components/forms/SchemaForm.js +16 -9
- package/dist/ts/components/forms/SchemaForm.js.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/AssetDetailSidebar.d.ts +1 -1
- package/dist/ts/components/media/AssetDetailSidebar.d.ts.map +1 -1
- package/dist/ts/components/media/FolderTreeSidebar.d.ts.map +1 -1
- package/dist/ts/components/media/FolderTreeSidebar.js +4 -1
- package/dist/ts/components/media/FolderTreeSidebar.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 +4 -96
- 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/ui/IconButton.d.ts +1 -1
- package/dist/ts/components/ui/IconButton.d.ts.map +1 -1
- package/dist/ts/content-form-fields.d.ts +41 -0
- package/dist/ts/content-form-fields.d.ts.map +1 -0
- package/dist/ts/content-form-fields.js +70 -0
- package/dist/ts/content-form-fields.js.map +1 -0
- package/dist/ts/data-schemas.d.ts +4 -3
- package/dist/ts/data-schemas.d.ts.map +1 -1
- package/dist/ts/data-schemas.js.map +1 -1
- package/dist/ts/host-discovery.d.ts.map +1 -1
- package/dist/ts/host-schema.d.ts +73 -0
- package/dist/ts/host-schema.d.ts.map +1 -0
- package/dist/ts/host-schema.js +66 -0
- package/dist/ts/host-schema.js.map +1 -0
- package/dist/ts/host-style-probe.d.ts.map +1 -1
- package/dist/ts/host-style-probe.js +16 -0
- package/dist/ts/host-style-probe.js.map +1 -1
- package/dist/ts/page-schema-define.d.ts +14 -12
- package/dist/ts/page-schema-define.d.ts.map +1 -1
- package/dist/ts/page-schema-define.js +8 -5
- package/dist/ts/page-schema-define.js.map +1 -1
- package/dist/ts/page-schemas.d.ts.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.map +1 -1
- package/dist/ts/ui-config.d.ts +2 -0
- package/dist/ts/ui-config.d.ts.map +1 -1
- package/dist/ts/ui-config.js.map +1 -1
- package/dist/ts/utils/asset-url.d.ts +2 -0
- package/dist/ts/utils/asset-url.d.ts.map +1 -1
- package/dist/ts/utils/asset-url.js +7 -0
- package/dist/ts/utils/asset-url.js.map +1 -1
- package/dist/ts/utils/pageMetadata.d.ts.map +1 -1
- package/dist/ts/utils/pageMetadata.js +27 -10
- package/dist/ts/utils/pageMetadata.js.map +1 -1
- package/dist/ts/utils/schema-fields.d.ts +23 -0
- package/dist/ts/utils/schema-fields.d.ts.map +1 -0
- package/dist/ts/utils/schema-fields.js +82 -0
- package/dist/ts/utils/schema-fields.js.map +1 -0
- package/package.json +41 -13
- package/src/App.tsx +13 -4
- package/src/components/CMSDashboard.tsx +12 -4
- package/src/components/RouteErrorPage.tsx +75 -0
- package/src/components/dashboard/RecentActivity.tsx +3 -7
- package/src/components/dialogs/CreateDataDialog.tsx +2 -2
- package/src/components/dialogs/CreateFolderDialog.tsx +2 -1
- package/src/components/dialogs/CreatePageFlow.tsx +117 -0
- package/src/components/dialogs/DataPropertiesDialog.tsx +3 -2
- package/src/components/dialogs/FragmentPropertiesDialog.tsx +3 -2
- package/src/components/dialogs/PageMetadataDialog.tsx +5 -28
- package/src/components/editor/DrawerItemOverride.tsx +14 -8
- package/src/components/editor/PageEditor.tsx +90 -19
- package/src/components/editor/PageEditorHeaderActions.tsx +1 -1
- package/src/components/editor/PageEditorWrapper.tsx +17 -7
- package/src/components/editor/draft-media-config.ts +95 -0
- package/src/components/editors/DataEditor.tsx +2 -2
- package/src/components/forms/HintForm.tsx +7 -5
- package/src/components/forms/SchemaForm.tsx +41 -12
- package/src/components/media/FolderTreeSidebar.tsx +3 -1
- package/src/components/pages/PageList.tsx +6 -116
- package/src/content-form-fields.ts +79 -0
- package/src/data-schemas.ts +4 -3
- package/src/host-schema.ts +122 -0
- package/src/host-style-probe.ts +16 -0
- package/src/main.css +10 -7
- package/src/page-schema-define.ts +29 -17
- package/src/ui-config.ts +2 -0
- package/src/utils/asset-url.ts +8 -0
- package/src/utils/pageMetadata.ts +27 -10
- package/src/utils/schema-fields.ts +106 -0
- package/dist/ts/utils/zodIntrospect.d.ts +0 -19
- package/dist/ts/utils/zodIntrospect.d.ts.map +0 -1
- package/dist/ts/utils/zodIntrospect.js +0 -95
- package/dist/ts/utils/zodIntrospect.js.map +0 -1
- package/src/utils/zodIntrospect.ts +0 -136
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DataContext, LocalizedEntry, UpdateResult } from '@conloca/content-api-client';
|
|
2
|
-
import type
|
|
2
|
+
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';
|
|
@@ -14,7 +14,8 @@ import { ConflictDialog } from '../dialogs/ConflictDialog.js';
|
|
|
14
14
|
import { UnsavedChangesDialog } from '../dialogs/UnsavedChangesDialog.js';
|
|
15
15
|
import { ImageFieldRender } from '../fields/ImageField.js';
|
|
16
16
|
import { toast } from '../toast.js';
|
|
17
|
-
import { DrawerItemOverride } from './DrawerItemOverride.js';
|
|
17
|
+
import { DrawerItemOverride, PUCK_ROOT_DROP_ZONE } from './DrawerItemOverride.js';
|
|
18
|
+
import { withDraftMediaRendering } from './draft-media-config.js';
|
|
18
19
|
import { PageEditorHeaderActions } from './PageEditorHeaderActions.js';
|
|
19
20
|
import { PuckWithUntouchedMetadata } from './PuckWithUntouchedMetadata.js';
|
|
20
21
|
import {
|
|
@@ -44,6 +45,20 @@ const viewports = [
|
|
|
44
45
|
{ width: 1280, height: 'auto' as const, label: 'Desktop', icon: <Monitor size={16} /> },
|
|
45
46
|
];
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* The canvas options, a module constant on purpose. `<Puck>` re-runs its canvas viewport effect whenever `iframe`
|
|
50
|
+
* changes identity (https://github.com/puckeditor/puck/pull/1864, open against 0.23), and while the undo history
|
|
51
|
+
* still holds only its first entry that effect overwrites the entry with the page as it is by then. This editor
|
|
52
|
+
* re-renders on every edit, so an inline object would replace the loaded page in the history with the result of the
|
|
53
|
+
* first edit before Puck records that edit: Undo would then flip the history buttons and leave the edit on the canvas.
|
|
54
|
+
*
|
|
55
|
+
* The canvas shows the SITE, so it gets the site's stylesheets and nothing else. Puck's default mirrors this admin
|
|
56
|
+
* document's head into the iframe, which for a consumer whose editor and site are separate apps means the CMS
|
|
57
|
+
* chrome's own CSS lands on top of the page being edited — Tailwind's preflight there flattens headings the site
|
|
58
|
+
* styles by element rather than by utility class.
|
|
59
|
+
*/
|
|
60
|
+
const CANVAS_IFRAME = { syncHostStyles: false };
|
|
61
|
+
|
|
47
62
|
/**
|
|
48
63
|
* Stable field type overrides for Puck.
|
|
49
64
|
* Defined at module level to maintain referential stability across renders.
|
|
@@ -77,6 +92,29 @@ const drawerItemOverride = ({ children, name }: { children: React.ReactNode; nam
|
|
|
77
92
|
<DrawerItemOverride name={name}>{children}</DrawerItemOverride>
|
|
78
93
|
);
|
|
79
94
|
|
|
95
|
+
/** On the canvas's scaled-down view (about half size) this still reads at a normal text size. */
|
|
96
|
+
const EMPTY_PAGE_HINT_FONT_SIZE = '24px';
|
|
97
|
+
|
|
98
|
+
const EMPTY_PAGE_HINT = 'Drag a block here, or double-click one in the list';
|
|
99
|
+
|
|
100
|
+
const EMPTY_PAGE_HINT_DECLARATIONS = [
|
|
101
|
+
`content: ${JSON.stringify(EMPTY_PAGE_HINT)}`,
|
|
102
|
+
'display: flex',
|
|
103
|
+
'align-items: center',
|
|
104
|
+
'justify-content: center',
|
|
105
|
+
'box-sizing: border-box',
|
|
106
|
+
'height: 100%',
|
|
107
|
+
'min-height: inherit',
|
|
108
|
+
'padding: 16px',
|
|
109
|
+
'text-align: center',
|
|
110
|
+
'font-family: var(--puck-font-family)',
|
|
111
|
+
`font-size: ${EMPTY_PAGE_HINT_FONT_SIZE}`,
|
|
112
|
+
'color: var(--puck-color-grey-05)',
|
|
113
|
+
].join('; ');
|
|
114
|
+
|
|
115
|
+
const CAN_INSERT_ATTRIBUTE = 'data-conloca-can-insert';
|
|
116
|
+
const CAN_INSERT_SELECTOR = `html[${CAN_INSERT_ATTRIBUTE}]`;
|
|
117
|
+
|
|
80
118
|
/**
|
|
81
119
|
* An editing rule the preview canvas gets from the CMS. The <Puck> below
|
|
82
120
|
* opts out of Puck's host-style mirror, so main.css never reaches the canvas;
|
|
@@ -91,9 +129,27 @@ const drawerItemOverride = ({ children, name }: { children: React.ReactNode; nam
|
|
|
91
129
|
* a child), keeps Puck's highlight. `[data-puck-dropzone]` is the attribute
|
|
92
130
|
* Puck puts on every drop area; matching class names would also catch Puck's
|
|
93
131
|
* drop-position line and hide it.
|
|
132
|
+
*
|
|
133
|
+
* A page with no blocks also says how to add one: the empty root area is the
|
|
134
|
+
* whole canvas, so a line of text centred in it is where an author looks first.
|
|
135
|
+
* It is the area's `::before`, so it goes as soon as the area holds a block or
|
|
136
|
+
* a drop preview, and it never becomes content that can be saved. It is sized
|
|
137
|
+
* for the canvas's scaled-down view, where it must stay readable. It shows in
|
|
138
|
+
* edit mode only (the interactive preview renders the published page) and only
|
|
139
|
+
* while the editor marks the canvas as one that can take a block, because both
|
|
140
|
+
* ways the hint names do nothing when no block may be inserted.
|
|
94
141
|
*/
|
|
95
|
-
const EMPTY_DROP_AREA_CSS =
|
|
96
|
-
'[data-puck-dropzone]:empty { --puck-slot-color-bg: transparent; --puck-slot-color-border: var(--puck-color-grey-07); }'
|
|
142
|
+
const EMPTY_DROP_AREA_CSS = [
|
|
143
|
+
'[data-puck-dropzone]:empty { --puck-slot-color-bg: transparent; --puck-slot-color-border: var(--puck-color-grey-07); }',
|
|
144
|
+
`${CAN_INSERT_SELECTOR} [data-puck-entry][data-puck-preview-mode="edit"] [data-puck-dropzone="${PUCK_ROOT_DROP_ZONE}"]:empty::before { ${EMPTY_PAGE_HINT_DECLARATIONS} }`,
|
|
145
|
+
].join('\n');
|
|
146
|
+
|
|
147
|
+
const usePuck = createUsePuck();
|
|
148
|
+
|
|
149
|
+
/** Whether any block may be added to the page: the hint's two ways of adding one both need it. */
|
|
150
|
+
function usePageCanTakeAnInsert(): boolean {
|
|
151
|
+
return usePuck((state) => Object.keys(state.config.components).some((type) => state.getPermissions({ type }).insert));
|
|
152
|
+
}
|
|
97
153
|
|
|
98
154
|
/**
|
|
99
155
|
* Bridges CMS editor state into Puck's preview iframe.
|
|
@@ -108,12 +164,11 @@ const EMPTY_DROP_AREA_CSS =
|
|
|
108
164
|
* rules (e.g. `body { color: var(...) }`) cannot cascade into Puck's
|
|
109
165
|
* chrome — the iframe is the only intended consumer.
|
|
110
166
|
*
|
|
111
|
-
* The `<Puck>` below turns off Puck's host-style mirror
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* cleanup.
|
|
167
|
+
* The `<Puck>` below turns off Puck's host-style mirror (`CANVAS_IFRAME`),
|
|
168
|
+
* so the iframe head holds only Puck's own interaction CSS, the
|
|
169
|
+
* empty-drop-area rule (point 3), the page-setting cursor rule (point 4)
|
|
170
|
+
* and these tags. Nothing else touches them, so they are appended on
|
|
171
|
+
* every `siteStyles` change and removed on cleanup.
|
|
117
172
|
*
|
|
118
173
|
* 3. Injects `EMPTY_DROP_AREA_CSS` once per iframe document.
|
|
119
174
|
*
|
|
@@ -188,6 +243,23 @@ export function IframeBridge({ children, document: iframeDoc }: { children: Reac
|
|
|
188
243
|
return <>{children}</>;
|
|
189
244
|
}
|
|
190
245
|
|
|
246
|
+
/**
|
|
247
|
+
* `IframeBridge` for the canvas inside <Puck>: also marks the canvas document while the page can take a block, which
|
|
248
|
+
* the empty-page hint in `EMPTY_DROP_AREA_CSS` waits for. Separate because the marker reads Puck's state, so it only
|
|
249
|
+
* works inside <Puck>, while the bridge also renders on its own.
|
|
250
|
+
*/
|
|
251
|
+
function IframeWithInsertMarker({ children, document: iframeDoc }: { children: React.ReactNode; document?: Document }) {
|
|
252
|
+
const canTakeAnInsert = usePageCanTakeAnInsert();
|
|
253
|
+
React.useEffect(() => {
|
|
254
|
+
const html = iframeDoc?.documentElement;
|
|
255
|
+
if (!html) return undefined;
|
|
256
|
+
html.toggleAttribute(CAN_INSERT_ATTRIBUTE, canTakeAnInsert);
|
|
257
|
+
return () => html.removeAttribute(CAN_INSERT_ATTRIBUTE);
|
|
258
|
+
}, [iframeDoc, canTakeAnInsert]);
|
|
259
|
+
|
|
260
|
+
return <IframeBridge document={iframeDoc}>{children}</IframeBridge>;
|
|
261
|
+
}
|
|
262
|
+
|
|
191
263
|
export function PageEditor({
|
|
192
264
|
entry,
|
|
193
265
|
config,
|
|
@@ -200,6 +272,11 @@ export function PageEditor({
|
|
|
200
272
|
onReload,
|
|
201
273
|
onPublish,
|
|
202
274
|
}: PageEditorProps) {
|
|
275
|
+
const draftAssetsBasePath = getUIConfig().draftAssetsBasePath;
|
|
276
|
+
const renderConfig = useMemo(
|
|
277
|
+
() => withDraftMediaRendering(config, draftAssetsBasePath),
|
|
278
|
+
[config, draftAssetsBasePath],
|
|
279
|
+
);
|
|
203
280
|
const [data, setData] = useState(entry.localized.content.puckData);
|
|
204
281
|
const [saveState, setSaveState] = useState<SaveState>('idle');
|
|
205
282
|
const [isDirty, setIsDirty] = useState(false);
|
|
@@ -436,7 +513,7 @@ export function PageEditor({
|
|
|
436
513
|
},
|
|
437
514
|
drawerItem: drawerItemOverride,
|
|
438
515
|
fields: FieldsWithPageSettingsHint,
|
|
439
|
-
iframe:
|
|
516
|
+
iframe: IframeWithInsertMarker,
|
|
440
517
|
}),
|
|
441
518
|
[],
|
|
442
519
|
);
|
|
@@ -465,20 +542,14 @@ export function PageEditor({
|
|
|
465
542
|
<PageSettingTargetsProvider onOpen={onOpenMetadata}>
|
|
466
543
|
{/* Not <Puck> itself: on the canvas Puck rewrites the page data it hands blocks; see PuckWithUntouchedMetadata.tsx. */}
|
|
467
544
|
<PuckWithUntouchedMetadata
|
|
468
|
-
config={
|
|
545
|
+
config={renderConfig}
|
|
469
546
|
data={data}
|
|
470
547
|
metadata={metadata}
|
|
471
548
|
onChange={handleDataChange}
|
|
472
549
|
headerTitle={entry.localized.meta.title || 'Untitled Page'}
|
|
473
550
|
viewports={viewports}
|
|
474
551
|
overrides={overrides}
|
|
475
|
-
|
|
476
|
-
// nothing else. Puck's default mirrors this admin document's head
|
|
477
|
-
// into the iframe, which for a consumer whose editor and site are
|
|
478
|
-
// separate apps means the CMS chrome's own CSS lands on top of the
|
|
479
|
-
// page being edited — Tailwind's preflight there flattens headings
|
|
480
|
-
// the site styles by element rather than by utility class.
|
|
481
|
-
iframe={{ syncHostStyles: false }}
|
|
552
|
+
iframe={CANVAS_IFRAME}
|
|
482
553
|
/>
|
|
483
554
|
</PageSettingTargetsProvider>
|
|
484
555
|
</div>
|
|
@@ -109,7 +109,7 @@ export function PageEditorHeaderActions({
|
|
|
109
109
|
onClick={onSave}
|
|
110
110
|
disabled={!isDirty && saveState !== 'error' && saveState !== 'conflict'}
|
|
111
111
|
className={cn(
|
|
112
|
-
'w-[100px] px-4 py-2 rounded-md text-sm transition-all duration-150 flex items-center justify-center gap-1 whitespace-nowrap font-medium',
|
|
112
|
+
'w-[100px] px-4 py-2 rounded-md text-sm transition-all duration-150 flex items-center justify-center gap-1 whitespace-nowrap font-medium disabled:cursor-not-allowed',
|
|
113
113
|
saveState === 'saved' && 'bg-green-10 text-green-06 cursor-pointer',
|
|
114
114
|
saveState === 'error' && 'bg-red-10 text-red-06 hover:bg-red-09 cursor-pointer',
|
|
115
115
|
saveState === 'conflict' && 'bg-yellow-10 text-yellow-06 hover:bg-yellow-09 cursor-pointer',
|
|
@@ -259,20 +259,30 @@ export function PageEditorWrapper({ puckConfig }: PageEditorWrapperProps) {
|
|
|
259
259
|
return <MdxPageEditor />;
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
// Keyed by page: the route element survives navigation between pages, and
|
|
263
|
+
// the locale state must restart from the newly opened page's locales.
|
|
264
|
+
return <PuckPageEditorInner key={id} puckConfig={puckConfig} initialLocale={initialPageLocale(content.locales)} />;
|
|
263
265
|
}
|
|
264
266
|
|
|
265
|
-
|
|
267
|
+
/**
|
|
268
|
+
* The locale the editor opens a page in: English when the page has it, as
|
|
269
|
+
* before, otherwise a locale the page actually has — opening on a locale with
|
|
270
|
+
* no variant fails the load with no way to reach the switcher.
|
|
271
|
+
*/
|
|
272
|
+
function initialPageLocale(locales: Record<string, unknown>): string {
|
|
273
|
+
if (locales.en) return 'en';
|
|
274
|
+
return Object.keys(locales).find((locale) => locales[locale]) ?? 'en';
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function PuckPageEditorInner({ puckConfig, initialLocale }: PageEditorWrapperProps & { initialLocale: string }) {
|
|
266
278
|
const { id } = useParams();
|
|
267
279
|
const navigate = useNavigate();
|
|
268
280
|
const updateContent = useUpdateLocalized();
|
|
269
281
|
|
|
270
282
|
// Mirrors FragmentEditor / MdxPageEditor: derive the locale list from the
|
|
271
|
-
// host's sites config and let the editor switch between them.
|
|
272
|
-
//
|
|
273
|
-
|
|
274
|
-
// from the switcher PageEditor renders when availableLocales.length > 1.
|
|
275
|
-
const [currentLocale, setCurrentLocale] = useState<string>('en');
|
|
283
|
+
// host's sites config and let the editor switch between them. It opens on
|
|
284
|
+
// a locale the page has (see initialPageLocale).
|
|
285
|
+
const [currentLocale, setCurrentLocale] = useState<string>(initialLocale);
|
|
276
286
|
const { data: sitesConfig } = useSitesConfig();
|
|
277
287
|
const availableLocales = sitesConfig?.globalLocales || ['en'];
|
|
278
288
|
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** Resolve unpublished draft images for site renderers without changing Puck's persisted data. */
|
|
2
|
+
import { IMAGE_EXTENSION_MIME } from '@conloca/content-api-client';
|
|
3
|
+
import type { Config, Field, Fields } from '@puckeditor/core';
|
|
4
|
+
import { type ComponentType, createElement, isValidElement } from 'react';
|
|
5
|
+
import { appendAssetUrlPath } from '../../utils/asset-url.js';
|
|
6
|
+
|
|
7
|
+
function draftImageUrl(value: string, base: string): string {
|
|
8
|
+
if (!value.startsWith('/assets/')) return value;
|
|
9
|
+
const path = value.slice('/assets/'.length);
|
|
10
|
+
if (/[\\?#]/.test(path)) return value;
|
|
11
|
+
const segments = path.split('/');
|
|
12
|
+
for (const part of segments) {
|
|
13
|
+
if (
|
|
14
|
+
part === '' ||
|
|
15
|
+
part === '.' ||
|
|
16
|
+
part === '..' ||
|
|
17
|
+
[...part].some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127)
|
|
18
|
+
) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const filename = segments[segments.length - 1] ?? '';
|
|
23
|
+
const dot = filename.lastIndexOf('.');
|
|
24
|
+
if (dot <= 0) return value;
|
|
25
|
+
const extension = filename.slice(dot + 1).toLowerCase();
|
|
26
|
+
if (!Object.prototype.hasOwnProperty.call(IMAGE_EXTENSION_MIME, extension)) return value;
|
|
27
|
+
const encoded = segments.map((part) =>
|
|
28
|
+
encodeURIComponent(part).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`),
|
|
29
|
+
);
|
|
30
|
+
return appendAssetUrlPath(base, encoded.join('/'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
34
|
+
if (value === null || typeof value !== 'object' || isValidElement(value)) return false;
|
|
35
|
+
const prototype: unknown = Object.getPrototypeOf(value);
|
|
36
|
+
return prototype === Object.prototype || prototype === null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function fieldValue(value: unknown, field: Field, base: string): unknown {
|
|
40
|
+
if (field.type === 'slot') return value;
|
|
41
|
+
if (typeof value === 'string') return draftImageUrl(value, base);
|
|
42
|
+
if (field.type === 'object' && isRecord(value)) return fieldProps(value, field.objectFields, base);
|
|
43
|
+
if (field.type === 'array' && Array.isArray(value)) {
|
|
44
|
+
const next = value.map((item: unknown) => (isRecord(item) ? fieldProps(item, field.arrayFields, base) : item));
|
|
45
|
+
return next.some((item, index) => item !== value[index]) ? next : value;
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function fieldProps(props: Record<string, unknown>, fields: Fields | undefined, base: string): Record<string, unknown> {
|
|
51
|
+
let next = props;
|
|
52
|
+
for (const [name, field] of Object.entries(fields ?? {})) {
|
|
53
|
+
if (name === 'puck' || name === 'children' || name === 'editMode') continue;
|
|
54
|
+
if (field === undefined || !Object.prototype.hasOwnProperty.call(props, name)) continue;
|
|
55
|
+
const value = fieldValue(props[name], field, base);
|
|
56
|
+
if (value === props[name]) continue;
|
|
57
|
+
if (next === props) next = { ...props };
|
|
58
|
+
next[name] = value;
|
|
59
|
+
}
|
|
60
|
+
return next;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Static declared fields bound traversal; dynamic field resolvers and runtime contexts remain untouched. */
|
|
64
|
+
export function withDraftMediaRendering(config: Config, base: string | undefined): Config {
|
|
65
|
+
if (base === undefined) return config;
|
|
66
|
+
const root = config.root;
|
|
67
|
+
const rootRender = root?.render;
|
|
68
|
+
return {
|
|
69
|
+
...config,
|
|
70
|
+
...(root && rootRender
|
|
71
|
+
? {
|
|
72
|
+
root: {
|
|
73
|
+
...root,
|
|
74
|
+
// Rendered as an element so memo/forwardRef roots keep working. Root props are a
|
|
75
|
+
// children/no-children union, so name the component's own prop type for createElement.
|
|
76
|
+
render: (props: Parameters<typeof rootRender>[0]) =>
|
|
77
|
+
createElement(rootRender as ComponentType<typeof props>, {
|
|
78
|
+
...props,
|
|
79
|
+
...fieldProps(props, root.fields, base),
|
|
80
|
+
}),
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
: {}),
|
|
84
|
+
components: Object.fromEntries(
|
|
85
|
+
Object.entries(config.components).map(([name, component]) => [
|
|
86
|
+
name,
|
|
87
|
+
{
|
|
88
|
+
...component,
|
|
89
|
+
render: (props: Parameters<typeof component.render>[0]) =>
|
|
90
|
+
createElement(component.render, { ...props, ...fieldProps(props, component.fields, base) }),
|
|
91
|
+
},
|
|
92
|
+
]),
|
|
93
|
+
),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getContentAPIClient, useLocalizedContent, useUpdateLocalized } from '@conloca/content-api-client';
|
|
2
2
|
import { AlertCircle, Code2, Loader2, Save } from 'lucide-react';
|
|
3
3
|
import { useEffect, useRef, useState } from 'react';
|
|
4
|
-
import type {
|
|
4
|
+
import type { HostSchema } from '../../host-schema.js';
|
|
5
5
|
import { contentFailureMessage } from '../../utils/content-failure.js';
|
|
6
6
|
import { UnsavedChangesDialog } from '../dialogs/UnsavedChangesDialog.js';
|
|
7
7
|
import { LocaleSelector } from '../editor/LocaleSelector.js';
|
|
@@ -12,7 +12,7 @@ interface DataEditorProps {
|
|
|
12
12
|
collection: string;
|
|
13
13
|
initialLocale: string;
|
|
14
14
|
existingLocales: string[];
|
|
15
|
-
schema:
|
|
15
|
+
schema: HostSchema | null;
|
|
16
16
|
onSave?: () => void;
|
|
17
17
|
onCancel?: () => void;
|
|
18
18
|
}
|
|
@@ -138,7 +138,9 @@ function HintField({ name, hint, value, onChange }: HintFieldProps) {
|
|
|
138
138
|
id={inputId}
|
|
139
139
|
type="datetime-local"
|
|
140
140
|
value={formatDateValue(value)}
|
|
141
|
-
|
|
141
|
+
// The picker's digits carry no zone or seconds; a host's `Format<'date-time'>`
|
|
142
|
+
// validator needs a full timestamp, so they are saved as the UTC instant they mean.
|
|
143
|
+
onChange={(e) => onChange(e.target.value ? `${e.target.value}:00.000Z` : undefined)}
|
|
142
144
|
/>
|
|
143
145
|
</Wrapper>
|
|
144
146
|
);
|
|
@@ -417,10 +419,10 @@ function formatLabel(name: string): string {
|
|
|
417
419
|
}
|
|
418
420
|
|
|
419
421
|
/**
|
|
420
|
-
* Host date hints
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
* authors west of UTC.
|
|
422
|
+
* Host date hints save the picker's digits as a UTC instant, and older pages
|
|
423
|
+
* may hold the bare zone-less digits, which readers also take as UTC. Slicing
|
|
424
|
+
* UTC hours off a Date or ISO string keeps the picker on that convention; local
|
|
425
|
+
* hours would shift the stored day across midnight for authors west of UTC.
|
|
424
426
|
*/
|
|
425
427
|
function formatDateValue(value: unknown): string {
|
|
426
428
|
if (!value) return '';
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { Loader2 } from 'lucide-react';
|
|
2
2
|
import { useId } from 'react';
|
|
3
|
-
import type
|
|
4
|
-
import { toDatetimeLocalValue } from '../../utils/pageMetadata.js';
|
|
5
|
-
import { type FieldInfo,
|
|
3
|
+
import { type HostSchema, isHostSchema } from '../../host-schema.js';
|
|
4
|
+
import { fromDatetimeLocalValue, toDatetimeLocalValue } from '../../utils/pageMetadata.js';
|
|
5
|
+
import { type FieldInfo, type FormFields, fieldsOfHostSchema } from '../../utils/schema-fields.js';
|
|
6
6
|
import { ImageFieldRender } from '../fields/ImageField.js';
|
|
7
7
|
import { Input, Select, Textarea } from '../ui/index.js';
|
|
8
8
|
import { ChipArrayField } from './ChipArrayField.js';
|
|
9
9
|
|
|
10
10
|
interface SchemaFormProps {
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* A host-declared schema, rendered from its generated JSON Schema metadata.
|
|
13
|
+
* This is the dynamic path: a site's `pageSchemas`/`dataSchemas` entry exists
|
|
14
|
+
* only at runtime, so its field shape is read off the metadata it carries.
|
|
15
|
+
*/
|
|
16
|
+
schema?: HostSchema | null;
|
|
17
|
+
/**
|
|
18
|
+
* An already-resolved field record — how the CMS's own metadata sections are
|
|
19
|
+
* declared now that they are no longer schema objects (`content-form-fields`).
|
|
20
|
+
* Takes precedence over `schema` when both are given.
|
|
21
|
+
*/
|
|
22
|
+
fields?: FormFields | null;
|
|
12
23
|
values: Record<string, unknown>;
|
|
13
24
|
onChange: (values: Record<string, unknown>) => void;
|
|
14
25
|
isLoading?: boolean;
|
|
@@ -16,10 +27,10 @@ interface SchemaFormProps {
|
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
/**
|
|
19
|
-
* Renders a form
|
|
20
|
-
* Fields are rendered automatically based on
|
|
30
|
+
* Renders a form from a host schema or a field record.
|
|
31
|
+
* Fields are rendered automatically based on their {@link FieldInfo}.
|
|
21
32
|
*/
|
|
22
|
-
export function SchemaForm({ schema, values, onChange, isLoading, className }: SchemaFormProps) {
|
|
33
|
+
export function SchemaForm({ schema, fields, values, onChange, isLoading, className }: SchemaFormProps) {
|
|
23
34
|
const handleFieldChange = (field: string, value: unknown) => {
|
|
24
35
|
onChange({ ...values, [field]: value });
|
|
25
36
|
};
|
|
@@ -32,7 +43,25 @@ export function SchemaForm({ schema, values, onChange, isLoading, className }: S
|
|
|
32
43
|
);
|
|
33
44
|
}
|
|
34
45
|
|
|
35
|
-
if (!schema) {
|
|
46
|
+
if (!fields && schema && !isHostSchema(schema)) {
|
|
47
|
+
return (
|
|
48
|
+
<div
|
|
49
|
+
role="alert"
|
|
50
|
+
data-testid="schema-form-outdated-schema"
|
|
51
|
+
className="text-center py-8 text-grey-04 dark:text-grey-07"
|
|
52
|
+
>
|
|
53
|
+
<p className="mb-2 font-medium text-grey-01 dark:text-grey-12">This form cannot be shown.</p>
|
|
54
|
+
<p>
|
|
55
|
+
This schema is out of date: it is not a generated host schema. Ask whoever maintains the site to declare it
|
|
56
|
+
with defineHostSchema and Typia, then rebuild the site.
|
|
57
|
+
</p>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const resolvedFields = fields ?? (schema ? fieldsOfHostSchema(schema) : null);
|
|
63
|
+
|
|
64
|
+
if (!resolvedFields) {
|
|
36
65
|
return (
|
|
37
66
|
<div className="text-center py-8 text-grey-04 dark:text-grey-07">
|
|
38
67
|
<p>No schema defined.</p>
|
|
@@ -40,12 +69,10 @@ export function SchemaForm({ schema, values, onChange, isLoading, className }: S
|
|
|
40
69
|
);
|
|
41
70
|
}
|
|
42
71
|
|
|
43
|
-
const fields = getZodShape(schema);
|
|
44
|
-
|
|
45
72
|
return (
|
|
46
73
|
<div className={className}>
|
|
47
74
|
<div className="space-y-6">
|
|
48
|
-
{Object.entries(
|
|
75
|
+
{Object.entries(resolvedFields).map(([fieldName, fieldInfo]) => (
|
|
49
76
|
// Names the field, so a dialog can open at it (see PageMetadataDialog's focusField).
|
|
50
77
|
<div key={fieldName} data-field-name={fieldName}>
|
|
51
78
|
<SchemaField
|
|
@@ -86,7 +113,9 @@ function SchemaField({ name, fieldInfo, value, onChange }: SchemaFieldProps) {
|
|
|
86
113
|
id={inputId}
|
|
87
114
|
type="datetime-local"
|
|
88
115
|
value={formatDateValue(value)}
|
|
89
|
-
|
|
116
|
+
// The input's wall-clock digits carry no zone or seconds; a host's `Format<'date-time'>`
|
|
117
|
+
// validator needs a full timestamp, so the value saved is the instant those digits name.
|
|
118
|
+
onChange={(e) => onChange(fromDatetimeLocalValue(e.target.value)?.toISOString())}
|
|
90
119
|
/>
|
|
91
120
|
{description && <p className="mt-1 text-sm text-grey-04 dark:text-grey-07">{description}</p>}
|
|
92
121
|
</div>
|
|
@@ -99,7 +99,9 @@ export function FolderTreeSidebar({ currentFolder, onFolderSelect, dropTargetFol
|
|
|
99
99
|
<button
|
|
100
100
|
type="button"
|
|
101
101
|
onClick={() => {
|
|
102
|
-
|
|
102
|
+
// Resetting an in-flight mutation detaches its success callback, so a reopened
|
|
103
|
+
// dialog would stay open with Create enabled after the folder was made.
|
|
104
|
+
if (!createFolder.isPending) createFolder.reset();
|
|
103
105
|
setShowCreateFolderDialog(true);
|
|
104
106
|
}}
|
|
105
107
|
className="p-1.5 rounded-md hover:bg-grey-11 dark:hover:bg-grey-03 transition-colors"
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
APIClientError,
|
|
3
|
-
isContentPublished,
|
|
4
|
-
localesOf,
|
|
5
|
-
useCreateContent,
|
|
6
|
-
useDeleteContent,
|
|
7
|
-
useSitePages,
|
|
8
|
-
} from '@conloca/content-api-client';
|
|
1
|
+
import { localesOf, pageStatusOf, useDeleteContent, useSitePages } from '@conloca/content-api-client';
|
|
9
2
|
import { AlertCircle, Clock, Edit, FileCode, FileText, Loader2, Plus, Search, Trash2 } from 'lucide-react';
|
|
10
3
|
import { useMemo, useState } from 'react';
|
|
11
4
|
import { useNavigate } from 'react-router-dom';
|
|
12
5
|
import { useErrorModal, useSiteBaseUrl } from '../../hooks/index.js';
|
|
13
|
-
import type {
|
|
14
|
-
import { getUIConfig } from '../../ui-config.js';
|
|
6
|
+
import type { Page } from '../../types.js';
|
|
15
7
|
import { contentFailureMessage, isStaleWrite } from '../../utils/content-failure.js';
|
|
16
8
|
import { formatDate } from '../../utils/format-date.js';
|
|
17
|
-
import {
|
|
9
|
+
import { CreatePageFlow } from '../dialogs/CreatePageFlow.js';
|
|
18
10
|
import { DeleteConfirmDialog } from '../dialogs/DeleteConfirmDialog.js';
|
|
19
11
|
import { ErrorModal } from '../dialogs/ErrorModal.js';
|
|
20
12
|
import { Tooltip } from '../ui/Tooltip.js';
|
|
@@ -44,7 +36,6 @@ export function PageList({ selectedSite, selectedLocale: initialLocale }: PageLi
|
|
|
44
36
|
const { buildUrl } = useSiteBaseUrl();
|
|
45
37
|
|
|
46
38
|
const navigate = useNavigate();
|
|
47
|
-
const createContent = useCreateContent();
|
|
48
39
|
const deleteContent = useDeleteContent();
|
|
49
40
|
|
|
50
41
|
const getPreviewUrl = (pagePath: string) => {
|
|
@@ -83,7 +74,7 @@ export function PageList({ selectedSite, selectedLocale: initialLocale }: PageLi
|
|
|
83
74
|
title: firstLocale.meta.title || entry.id,
|
|
84
75
|
path: firstLocale.pathname || '/',
|
|
85
76
|
type: entry.type === 'mdx' ? 'mdx' : 'puck',
|
|
86
|
-
status:
|
|
77
|
+
status: pageStatusOf(entry),
|
|
87
78
|
modified: new Date(firstLocale.modified),
|
|
88
79
|
locales: Array.from(localesOf(entry)).map((v) => v.locale),
|
|
89
80
|
etags: {},
|
|
@@ -94,7 +85,6 @@ export function PageList({ selectedSite, selectedLocale: initialLocale }: PageLi
|
|
|
94
85
|
|
|
95
86
|
const page = pageMap.get(entry.id)!;
|
|
96
87
|
|
|
97
|
-
// Update status based on publish dates
|
|
98
88
|
for (const localeData of localesOf(entry)) {
|
|
99
89
|
// Store etag for each locale
|
|
100
90
|
page.etags[localeData.locale] = localeData.etag;
|
|
@@ -102,16 +92,6 @@ export function PageList({ selectedSite, selectedLocale: initialLocale }: PageLi
|
|
|
102
92
|
page.localeTitles[localeData.locale] = localeData.meta.title || entry.id;
|
|
103
93
|
// Store path for each locale
|
|
104
94
|
page.localePaths[localeData.locale] = localeData.pathname || '/';
|
|
105
|
-
|
|
106
|
-
const now = new Date();
|
|
107
|
-
const publishAt = localeData.publishAt ? new Date(localeData.publishAt) : null;
|
|
108
|
-
|
|
109
|
-
if (publishAt && publishAt > now) {
|
|
110
|
-
page.status = 'scheduled';
|
|
111
|
-
} else if (!isContentPublished(localeData, now)) {
|
|
112
|
-
page.status = 'draft';
|
|
113
|
-
}
|
|
114
|
-
|
|
115
95
|
// Update modified date to the most recent
|
|
116
96
|
const modifiedDate = new Date(localeData.modified);
|
|
117
97
|
if (modifiedDate > page.modified) {
|
|
@@ -213,91 +193,6 @@ export function PageList({ selectedSite, selectedLocale: initialLocale }: PageLi
|
|
|
213
193
|
setShowCreateDialog(true);
|
|
214
194
|
};
|
|
215
195
|
|
|
216
|
-
const createTemplateContent = (componentName: string) => [
|
|
217
|
-
{
|
|
218
|
-
type: componentName,
|
|
219
|
-
props: {
|
|
220
|
-
id: `${componentName}-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
];
|
|
224
|
-
|
|
225
|
-
const handleCreatePage = async (data: CreatePageData) => {
|
|
226
|
-
try {
|
|
227
|
-
const config = getUIConfig();
|
|
228
|
-
const templateConfig = config.templates?.[data.template];
|
|
229
|
-
|
|
230
|
-
// Shared metadata. Description is only added when MDX picked it
|
|
231
|
-
// up — Puck pages don't render it today, so the manifest stays
|
|
232
|
-
// clean for them.
|
|
233
|
-
const meta: { title: string; description?: string } = { title: data.title };
|
|
234
|
-
if (data.format === 'mdx' && data.description) {
|
|
235
|
-
meta.description = data.description;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Build a type-specific content payload. MDX pages send an empty
|
|
239
|
-
// body — the editor opens to a blank canvas. Puck pages keep the
|
|
240
|
-
// existing template-driven payload.
|
|
241
|
-
const templateContent =
|
|
242
|
-
data.format !== 'mdx' && templateConfig?.component ? createTemplateContent(templateConfig.component) : [];
|
|
243
|
-
const result = await (data.format === 'mdx'
|
|
244
|
-
? createContent.mutateAsync({
|
|
245
|
-
kind: 'page',
|
|
246
|
-
site: currentSite,
|
|
247
|
-
collection: 'pages',
|
|
248
|
-
type: 'mdx',
|
|
249
|
-
meta,
|
|
250
|
-
locales: {
|
|
251
|
-
[data.locale]: {
|
|
252
|
-
meta,
|
|
253
|
-
pathname: data.path,
|
|
254
|
-
// Empty body — backend stamps id/created/modified into
|
|
255
|
-
// frontmatter automatically (see
|
|
256
|
-
// filesystem-content-api.ts createContent, type === 'mdx'
|
|
257
|
-
// branch).
|
|
258
|
-
content: { mdx: '' },
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
})
|
|
262
|
-
: createContent.mutateAsync({
|
|
263
|
-
kind: 'page',
|
|
264
|
-
site: currentSite,
|
|
265
|
-
collection: 'pages',
|
|
266
|
-
type: 'puck',
|
|
267
|
-
meta,
|
|
268
|
-
locales: {
|
|
269
|
-
[data.locale]: {
|
|
270
|
-
meta,
|
|
271
|
-
pathname: data.path,
|
|
272
|
-
content: {
|
|
273
|
-
puckData: {
|
|
274
|
-
root: {},
|
|
275
|
-
content: templateContent,
|
|
276
|
-
zones: {},
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
|
-
}));
|
|
282
|
-
|
|
283
|
-
if (result.success && result.id) {
|
|
284
|
-
// Navigate to the new page editor with the actual ID.
|
|
285
|
-
// PageEditorWrapper dispatches by content.type so MDX pages
|
|
286
|
-
// land on MdxPageEditor and Puck pages on the Puck canvas.
|
|
287
|
-
navigate(`/pages/${result.id}`);
|
|
288
|
-
} else {
|
|
289
|
-
// The dialog has already closed, so this is the author's only answer:
|
|
290
|
-
// say why (a path taken since the check), not just "try again".
|
|
291
|
-
showError(contentFailureMessage(result, 'Failed to create page. Please try again.'), result.error);
|
|
292
|
-
}
|
|
293
|
-
} catch (error) {
|
|
294
|
-
console.error('Failed to create page:', error);
|
|
295
|
-
// The content-API router answers a refusal, such as a path another page took since the check,
|
|
296
|
-
// with an error status, which the client throws: say why, as for a refusal the result carries.
|
|
297
|
-
showError(error instanceof APIClientError ? error.message : 'Failed to create page. Please try again.', error);
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
|
|
301
196
|
const handleEditPage = (pageId: string) => {
|
|
302
197
|
// Navigate with the actual content ID
|
|
303
198
|
navigate(`/pages/${pageId}`);
|
|
@@ -651,13 +546,8 @@ export function PageList({ selectedSite, selectedLocale: initialLocale }: PageLi
|
|
|
651
546
|
</div>
|
|
652
547
|
)}
|
|
653
548
|
|
|
654
|
-
{/* Create Page
|
|
655
|
-
<
|
|
656
|
-
open={showCreateDialog}
|
|
657
|
-
onOpenChange={setShowCreateDialog}
|
|
658
|
-
onCreatePage={handleCreatePage}
|
|
659
|
-
site={currentSite}
|
|
660
|
-
/>
|
|
549
|
+
{/* Create Page Flow: the dialog plus its own create-error modal */}
|
|
550
|
+
<CreatePageFlow open={showCreateDialog} onOpenChange={setShowCreateDialog} site={currentSite} />
|
|
661
551
|
|
|
662
552
|
{/* Delete Confirmation Dialog */}
|
|
663
553
|
<DeleteConfirmDialog
|