@conloca/cms-spa 0.2.1 → 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 +240 -4
- package/dist/ts/.build-inputs.json +178 -0
- package/dist/ts/App.d.ts +10 -2
- package/dist/ts/App.d.ts.map +1 -1
- package/dist/ts/App.js +20 -8
- 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/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/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/FragmentPropertiesDialog.d.ts +1 -1
- 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/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/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/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/PageEditor.d.ts +6 -7
- package/dist/ts/components/editor/PageEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditor.js +124 -34
- package/dist/ts/components/editor/PageEditor.js.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 +48 -12
- package/dist/ts/components/editor/PageEditorWrapper.js.map +1 -1
- package/dist/ts/components/editor/draft-media-config.d.ts +22 -0
- package/dist/ts/components/editor/draft-media-config.d.ts.map +1 -0
- package/dist/ts/components/editor/draft-media-config.js +186 -0
- package/dist/ts/components/editor/draft-media-config.js.map +1 -0
- 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 +2 -2
- 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.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.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/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/pages/PageList.d.ts.map +1 -1
- package/dist/ts/components/pages/PageList.js +13 -99
- package/dist/ts/components/pages/PageList.js.map +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/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/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 +4 -3
- package/dist/ts/data-schemas.d.ts.map +1 -1
- package/dist/ts/data-schemas.js.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-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 +32 -37
- package/dist/ts/host-style-probe.d.ts.map +1 -1
- package/dist/ts/host-style-probe.js +102 -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-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/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/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 +52 -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/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 +56 -18
- package/src/App.tsx +35 -14
- package/src/CmsSpaApp.tsx +5 -1
- 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/CMSMDXEditor.tsx +49 -69
- package/src/components/editor/DrawerItemOverride.tsx +14 -8
- package/src/components/editor/PageEditor.tsx +135 -36
- package/src/components/editor/PageEditorHeaderActions.tsx +1 -1
- package/src/components/editor/PageEditorWrapper.tsx +51 -12
- package/src/components/editor/draft-media-config.ts +197 -0
- package/src/components/editor/preview-availability.ts +6 -5
- 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/AssetCard.tsx +10 -7
- package/src/components/media/AssetDetailSidebar.tsx +6 -6
- package/src/components/media/FolderTreeSidebar.tsx +3 -1
- package/src/components/pages/PageList.tsx +17 -119
- package/src/components/sandbox/ContentSandbox.tsx +34 -5
- package/src/content-form-fields.ts +79 -0
- package/src/content-wrapper.ts +284 -0
- package/src/data-schemas.ts +4 -3
- 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-schema.ts +122 -0
- package/src/host-style-probe.ts +120 -90
- package/src/index.ts +7 -2
- package/src/main-spa.tsx +2 -0
- package/src/main.css +12 -8
- package/src/page-schema-define.ts +29 -17
- package/src/prose-surface-css.ts +3 -5
- package/src/site-styles.ts +4 -22
- package/src/ui-config.ts +54 -1
- 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/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/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/host-discovery.ts +0 -77
- package/src/utils/zodIntrospect.ts +0 -136
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { APIClientError, useCreateContent } from '@conloca/content-api-client';
|
|
2
|
+
import { useNavigate } from 'react-router-dom';
|
|
3
|
+
import { useErrorModal } from '../../hooks/index.js';
|
|
4
|
+
import type { CreatePageData } from '../../types.js';
|
|
5
|
+
import { getUIConfig } from '../../ui-config.js';
|
|
6
|
+
import { contentFailureMessage } from '../../utils/content-failure.js';
|
|
7
|
+
import { CreatePageDialog } from './CreatePageDialog.js';
|
|
8
|
+
import { ErrorModal } from './ErrorModal.js';
|
|
9
|
+
|
|
10
|
+
interface CreatePageFlowProps {
|
|
11
|
+
open: boolean;
|
|
12
|
+
onOpenChange: (open: boolean) => void;
|
|
13
|
+
site: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const createTemplateContent = (componentName: string) => [
|
|
17
|
+
{
|
|
18
|
+
type: componentName,
|
|
19
|
+
props: {
|
|
20
|
+
id: `${componentName}-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The create-page dialog together with what happens after Create: the page is created, its editor opens, and a
|
|
27
|
+
* refusal is shown in an error modal. Shared by the Dashboard and the Pages list, so both New Page buttons
|
|
28
|
+
* behave the same.
|
|
29
|
+
*/
|
|
30
|
+
export function CreatePageFlow({ open, onOpenChange, site }: CreatePageFlowProps) {
|
|
31
|
+
const { showError, errorModalProps } = useErrorModal();
|
|
32
|
+
const navigate = useNavigate();
|
|
33
|
+
const createContent = useCreateContent();
|
|
34
|
+
|
|
35
|
+
const handleCreatePage = async (data: CreatePageData) => {
|
|
36
|
+
try {
|
|
37
|
+
const config = getUIConfig();
|
|
38
|
+
const templateConfig = config.templates?.[data.template];
|
|
39
|
+
|
|
40
|
+
// Shared metadata. Description is only added when MDX picked it
|
|
41
|
+
// up — Puck pages don't render it today, so the manifest stays
|
|
42
|
+
// clean for them.
|
|
43
|
+
const meta =
|
|
44
|
+
data.format === 'mdx' && data.description
|
|
45
|
+
? { title: data.title, description: data.description }
|
|
46
|
+
: { title: data.title };
|
|
47
|
+
|
|
48
|
+
// Build a type-specific content payload. MDX pages send an empty
|
|
49
|
+
// body — the editor opens to a blank canvas. Puck pages keep the
|
|
50
|
+
// existing template-driven payload.
|
|
51
|
+
const templateContent =
|
|
52
|
+
data.format !== 'mdx' && templateConfig?.component ? createTemplateContent(templateConfig.component) : [];
|
|
53
|
+
const result = await (data.format === 'mdx'
|
|
54
|
+
? createContent.mutateAsync({
|
|
55
|
+
kind: 'page',
|
|
56
|
+
site,
|
|
57
|
+
collection: 'pages',
|
|
58
|
+
type: 'mdx',
|
|
59
|
+
meta,
|
|
60
|
+
locales: {
|
|
61
|
+
[data.locale]: {
|
|
62
|
+
meta,
|
|
63
|
+
pathname: data.path,
|
|
64
|
+
// Empty body — backend stamps id/created/modified into
|
|
65
|
+
// frontmatter automatically (see
|
|
66
|
+
// filesystem-content-api.ts createContent, type === 'mdx'
|
|
67
|
+
// branch).
|
|
68
|
+
content: { mdx: '' },
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
: createContent.mutateAsync({
|
|
73
|
+
kind: 'page',
|
|
74
|
+
site,
|
|
75
|
+
collection: 'pages',
|
|
76
|
+
type: 'puck',
|
|
77
|
+
meta,
|
|
78
|
+
locales: {
|
|
79
|
+
[data.locale]: {
|
|
80
|
+
meta,
|
|
81
|
+
pathname: data.path,
|
|
82
|
+
content: {
|
|
83
|
+
puckData: {
|
|
84
|
+
root: {},
|
|
85
|
+
content: templateContent,
|
|
86
|
+
zones: {},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
if (result.success && result.id) {
|
|
94
|
+
// Navigate to the new page editor with the actual ID.
|
|
95
|
+
// PageEditorWrapper dispatches by content.type so MDX pages
|
|
96
|
+
// land on MdxPageEditor and Puck pages on the Puck canvas.
|
|
97
|
+
void navigate(`/pages/${result.id}`);
|
|
98
|
+
} else {
|
|
99
|
+
// The dialog has already closed, so this is the author's only answer:
|
|
100
|
+
// say why (a path taken since the check), not just "try again".
|
|
101
|
+
showError(contentFailureMessage(result, 'Failed to create page. Please try again.'), result.error);
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.error('Failed to create page:', error);
|
|
105
|
+
// The content-API router answers a refusal, such as a path another page took since the check,
|
|
106
|
+
// with an error status, which the client throws: say why, as for a refusal the result carries.
|
|
107
|
+
showError(error instanceof APIClientError ? error.message : 'Failed to create page. Please try again.', error);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<>
|
|
113
|
+
<CreatePageDialog open={open} onOpenChange={onOpenChange} onCreatePage={handleCreatePage} site={site} />
|
|
114
|
+
<ErrorModal {...errorModalProps} />
|
|
115
|
+
</>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DataEditable } from '@conloca/content-api-client';
|
|
2
2
|
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { dataEditableFields } from '../../content-form-fields.js';
|
|
3
4
|
import { SchemaForm } from '../forms/SchemaForm.js';
|
|
4
5
|
import { Button } from '../ui/index.js';
|
|
5
6
|
|
|
@@ -62,7 +63,7 @@ export function DataPropertiesDialog({ initialMeta, isPending, onClose, onSave }
|
|
|
62
63
|
<h2 className="text-xl font-semibold text-grey-01 dark:text-grey-12 mb-4">Edit Data Properties</h2>
|
|
63
64
|
|
|
64
65
|
<div className="mb-4">
|
|
65
|
-
<SchemaForm
|
|
66
|
+
<SchemaForm fields={dataEditableFields} values={formValues} onChange={setFormValues} />
|
|
66
67
|
</div>
|
|
67
68
|
|
|
68
69
|
<div className="flex justify-end gap-3">
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FragmentEditable } from '@conloca/content-api-client';
|
|
2
2
|
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { fragmentEditableFields } from '../../content-form-fields.js';
|
|
3
4
|
import { SchemaForm } from '../forms/SchemaForm.js';
|
|
4
5
|
import { Button } from '../ui/index.js';
|
|
5
6
|
|
|
@@ -75,7 +76,7 @@ export function FragmentPropertiesDialog({
|
|
|
75
76
|
<h2 className="text-xl font-semibold text-grey-01 dark:text-grey-12 mb-4">Edit Fragment Properties</h2>
|
|
76
77
|
|
|
77
78
|
<div className="mb-4">
|
|
78
|
-
<SchemaForm
|
|
79
|
+
<SchemaForm fields={fragmentEditableFields} values={formValues} onChange={setFormValues} />
|
|
79
80
|
</div>
|
|
80
81
|
|
|
81
82
|
<div className="flex justify-end gap-3">
|
|
@@ -4,7 +4,7 @@ import { X } from 'lucide-react';
|
|
|
4
4
|
import type React from 'react';
|
|
5
5
|
/* oxlint-disable anti-slop/no-unsafe-dictionary-type -- Form state intentionally mirrors SchemaForm/HintForm's validated Record<string, unknown> contract until schema parsing materializes PageMetadata. */
|
|
6
6
|
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
7
|
-
import {
|
|
7
|
+
import { pathnameOnlyFields, publishWindowFields, seoPublishingFields } from '../../content-form-fields.js';
|
|
8
8
|
import { type PageSchemaDescriptor, resolvePageSchemaEntry, usePageSchemas } from '../../page-schemas.js';
|
|
9
9
|
import type { CorePageSettingName } from '../../page-setting-attributes.js';
|
|
10
10
|
import type { PageMetadata } from '../../types.js';
|
|
@@ -18,31 +18,8 @@ import { HintForm } from '../forms/HintForm.js';
|
|
|
18
18
|
import { SchemaForm } from '../forms/SchemaForm.js';
|
|
19
19
|
import { Button, FieldError, IconButton, Input } from '../ui/index.js';
|
|
20
20
|
|
|
21
|
-
const pathnameOnlySchema = z.object({
|
|
22
|
-
pathname: z.string().describe('URL path (e.g., /about)'),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const publishWindowSchema = z.object({
|
|
26
|
-
publishAt: z.coerce
|
|
27
|
-
.date()
|
|
28
|
-
.nullable()
|
|
29
|
-
.optional()
|
|
30
|
-
.describe(
|
|
31
|
-
'When the page goes live. Page lists that sort by date use this date, or the date the page was created when it is empty.',
|
|
32
|
-
),
|
|
33
|
-
unpublishAt: z.coerce.date().nullable().optional().describe('Schedule unpublish date/time'),
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const seoPublishingSchema = z
|
|
37
|
-
.object({
|
|
38
|
-
description: z.string().optional().describe('Meta description for search engines'),
|
|
39
|
-
robots: z.string().optional().describe('Robots meta tag (e.g., index, follow)'),
|
|
40
|
-
canonical: z.string().url().optional().describe('Canonical URL for duplicate content'),
|
|
41
|
-
})
|
|
42
|
-
.extend(publishWindowSchema.shape);
|
|
43
|
-
|
|
44
21
|
type Assert<T extends true> = T;
|
|
45
|
-
type DialogCoreField = 'title' | keyof
|
|
22
|
+
type DialogCoreField = 'title' | keyof typeof pathnameOnlyFields | keyof typeof seoPublishingFields;
|
|
46
23
|
/** A block can name exactly the core fields this dialog renders (CorePageSettingName): renaming a field here breaks the typecheck. */
|
|
47
24
|
export type CoreFieldNamesProof = Assert<
|
|
48
25
|
[DialogCoreField] extends [CorePageSettingName]
|
|
@@ -264,7 +241,7 @@ function PageMetadataForm({ formRef, page, descriptor, onSave, onSaved }: PageMe
|
|
|
264
241
|
)}
|
|
265
242
|
<SchemaForm
|
|
266
243
|
className={cn({ 'mt-6': mode === 'full' })}
|
|
267
|
-
|
|
244
|
+
fields={pathnameOnlyFields}
|
|
268
245
|
values={coreValues}
|
|
269
246
|
onChange={changeCoreValues}
|
|
270
247
|
/>
|
|
@@ -283,10 +260,10 @@ function PageMetadataForm({ formRef, page, descriptor, onSave, onSaved }: PageMe
|
|
|
283
260
|
))}
|
|
284
261
|
|
|
285
262
|
{mode === 'full' && (
|
|
286
|
-
<SchemaForm className="mt-6"
|
|
263
|
+
<SchemaForm className="mt-6" fields={seoPublishingFields} values={coreValues} onChange={changeCoreValues} />
|
|
287
264
|
)}
|
|
288
265
|
{mode === 'minimal' && (
|
|
289
|
-
<SchemaForm className="mt-6"
|
|
266
|
+
<SchemaForm className="mt-6" fields={publishWindowFields} values={coreValues} onChange={changeCoreValues} />
|
|
290
267
|
)}
|
|
291
268
|
|
|
292
269
|
{titleMissing && mode !== 'full' && <FieldError className="mt-6">Enter a page title before saving.</FieldError>}
|
|
@@ -10,7 +10,6 @@ import type { JsxComponentDescriptor, MDXEditorMethods, RealmPlugin } from '@mdx
|
|
|
10
10
|
import { forwardRef, useCallback, useMemo, useRef } from 'react';
|
|
11
11
|
import { useTheme } from '../../hooks/useTheme.js';
|
|
12
12
|
import { buildUploadFormData } from '../../hooks/useUpload.js';
|
|
13
|
-
import { useHostDiscovery } from '../../host-discovery.js';
|
|
14
13
|
import { useProbedHostStyles } from '../../host-style-probe.js';
|
|
15
14
|
import { isJsxDescriptor, toJsxComponentDescriptor, useMdxComponents } from '../../mdx-components.js';
|
|
16
15
|
import { deriveProseSurfaceStyles } from '../../prose-surface-css.js';
|
|
@@ -22,7 +21,9 @@ import {
|
|
|
22
21
|
useInjectHostStyles,
|
|
23
22
|
useSiteStyles,
|
|
24
23
|
} from '../../site-styles.js';
|
|
24
|
+
import { getUIConfig, inEditorFrame } from '../../ui-config.js';
|
|
25
25
|
import { buildAssetRef } from '../../utils/asset-url.js';
|
|
26
|
+
import { draftImagePreview } from './draft-media-config.js';
|
|
26
27
|
import { GenericBlock } from './GenericBlock.js';
|
|
27
28
|
import { hostWrapperPlugin } from './host-wrapper-plugin.js';
|
|
28
29
|
import { ImagePickerDialog } from './ImagePickerDialog.js';
|
|
@@ -68,35 +69,13 @@ export const CMSMDXEditor = forwardRef<MDXEditorMethods, CMSMDXEditorProps>(({ p
|
|
|
68
69
|
// Full host CSS must stay inside the editor surface. Site styles often
|
|
69
70
|
// contain bare `h1`, `button`, and Tailwind reset rules that would otherwise
|
|
70
71
|
// restyle the admin header and any host app around it.
|
|
71
|
-
const fetchedStyles = useFetchedSiteStyles(previewRouteUrl);
|
|
72
|
-
const staticEditorStyles = useEditorStyles();
|
|
73
|
-
// Registered discovery: the same facts the endpoints above serve, handed in
|
|
74
|
-
// by a host app (`setHostDiscovery`) when the editor cannot reach the site's
|
|
75
|
-
// dev server. Sits one tier below live discovery so the dev server always
|
|
76
|
-
// wins, and above the manual editorStyles path. Empty unless a host app
|
|
77
|
-
// writes the registry.
|
|
78
|
-
const registeredDiscovery = useHostDiscovery();
|
|
79
|
-
const registeredRouteStyles = useMemo<SiteStyles>(
|
|
80
|
-
() => (registeredDiscovery.routeCss ? [registeredDiscovery.routeCss] : []),
|
|
81
|
-
[registeredDiscovery],
|
|
82
|
-
);
|
|
83
|
-
// First tier with content wins: live discovery, then registered discovery,
|
|
84
|
-
// then the manually-configured path.
|
|
85
|
-
const activeStyles = [fetchedStyles, registeredRouteStyles, staticEditorStyles].find((tier) => tier.length > 0) ?? [];
|
|
86
|
-
// The editor mounts directly in the parent SPA's React tree, so the broad
|
|
87
|
-
// stylesheet is confined to `.conloca-mdx-editor-surround` below. The
|
|
88
|
-
// content still receives the site's complete cascade while adjacent admin
|
|
89
|
-
// chrome keeps its own tokens and utilities.
|
|
90
72
|
//
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
() => (EDITOR_CSS ? [...activeStyles, EDITOR_CSS] : activeStyles),
|
|
98
|
-
[activeStyles],
|
|
99
|
-
);
|
|
73
|
+
// Inside a parent frame the dev-server endpoints do not exist, so the
|
|
74
|
+
// probe's load of the real page stands in for them (see `routeStyles`).
|
|
75
|
+
const inFrame = inEditorFrame();
|
|
76
|
+
const devServerRouteUrl = inFrame ? undefined : previewRouteUrl;
|
|
77
|
+
const fetchedStyles = useFetchedSiteStyles(devServerRouteUrl);
|
|
78
|
+
const staticEditorStyles = useEditorStyles();
|
|
100
79
|
// Probe the host's computed styles for each prose tag from the
|
|
101
80
|
// actual live page and synthesize a stylesheet scoped to the
|
|
102
81
|
// editor's contenteditable. This catches what the wrapper auto-
|
|
@@ -116,13 +95,7 @@ export const CMSMDXEditor = forwardRef<MDXEditorMethods, CMSMDXEditorProps>(({ p
|
|
|
116
95
|
// surface naturally. It also threads `codeBlock` through to the
|
|
117
96
|
// code-block frame component (in @conloca/mdx) so it can carry the host's
|
|
118
97
|
// code-block classes and inherit the host's code-block CSS the same way.
|
|
119
|
-
const fetchedWrappers = useFetchedHostWrappers(
|
|
120
|
-
// Same tiering for the wrapper clone: whatever live discovery found, else
|
|
121
|
-
// the shape a host app registered.
|
|
122
|
-
const hostWrappers =
|
|
123
|
-
fetchedWrappers.content !== null || fetchedWrappers.codeBlock !== null
|
|
124
|
-
? fetchedWrappers
|
|
125
|
-
: (registeredDiscovery.wrappers ?? fetchedWrappers);
|
|
98
|
+
const fetchedWrappers = useFetchedHostWrappers(devServerRouteUrl);
|
|
126
99
|
// Editor and published page maintain independent theme preferences
|
|
127
100
|
// (CMS SPA → `conloca-theme`; Starlight → `starlight-theme`). The
|
|
128
101
|
// probe needs to capture styles in the EDITOR's current scheme, not
|
|
@@ -130,20 +103,32 @@ export const CMSMDXEditor = forwardRef<MDXEditorMethods, CMSMDXEditorProps>(({ p
|
|
|
130
103
|
// the user toggles theme inside the editor, the hook's dep on
|
|
131
104
|
// `theme` re-runs the probe and the new computed values land.
|
|
132
105
|
const { resolvedTheme } = useTheme();
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
//
|
|
139
|
-
//
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
106
|
+
const probe = useProbedHostStyles(previewRouteUrl, fetchedWrappers.content?.className ?? null, {
|
|
107
|
+
theme: resolvedTheme,
|
|
108
|
+
discover: inFrame,
|
|
109
|
+
});
|
|
110
|
+
const { css: probedStyles, settled: probeSettled } = probe;
|
|
111
|
+
// The route's own CSS and wrappers: from the dev endpoints locally, from the
|
|
112
|
+
// page the probe loaded in a frame.
|
|
113
|
+
const routeStyles = inFrame ? probe.styles : fetchedStyles;
|
|
114
|
+
const hostWrappers = inFrame ? probe.wrappers : fetchedWrappers;
|
|
115
|
+
// First tier with content wins: live discovery, then the manually-configured
|
|
116
|
+
// path.
|
|
117
|
+
const activeStyles = routeStyles.length > 0 ? routeStyles : staticEditorStyles;
|
|
118
|
+
// The editor mounts directly in the parent SPA's React tree, so the broad
|
|
119
|
+
// stylesheet is confined to `.conloca-mdx-editor-surround` below. The
|
|
120
|
+
// content still receives the site's complete cascade while adjacent admin
|
|
121
|
+
// chrome keeps its own tokens and utilities.
|
|
122
|
+
//
|
|
123
|
+
// The host can also append raw CSS via the integration's `editorCSS`
|
|
124
|
+
// option (see `ConlocaCMSOptions`) — concatenated AFTER auto-
|
|
125
|
+
// discovered styles so it sits later in the same cascade layer and
|
|
126
|
+
// wins on tie-breaks. Empty string when the host didn't set it; no
|
|
127
|
+
// marker `<style>` is emitted for the no-op case.
|
|
128
|
+
const editorCss = getUIConfig().editorCss ?? EDITOR_CSS;
|
|
129
|
+
const styleStack = useMemo<SiteStyles>(
|
|
130
|
+
() => (editorCss ? [...activeStyles, editorCss] : activeStyles),
|
|
131
|
+
[activeStyles, editorCss],
|
|
147
132
|
);
|
|
148
133
|
const probedStack = useMemo<SiteStyles>(() => (probedStyles ? [probedStyles] : []), [probedStyles]);
|
|
149
134
|
// Injected here, AFTER the probe has been read, so the bridge inside this
|
|
@@ -168,26 +153,19 @@ export const CMSMDXEditor = forwardRef<MDXEditorMethods, CMSMDXEditorProps>(({ p
|
|
|
168
153
|
});
|
|
169
154
|
useInjectHostStyles('conloca-host-defaults', probedStack, { layered: false });
|
|
170
155
|
// Production styles tier: prose-safe rules derived from the siteStyles
|
|
171
|
-
// registry (the
|
|
172
|
-
//
|
|
173
|
-
// discovery endpoint delivered (dev server), this stays empty so
|
|
156
|
+
// registry (the siteStyles option's CSS) plus a paper base. Fallback ONLY —
|
|
157
|
+
// when the discovery endpoint delivered (dev server), this stays empty so
|
|
174
158
|
// discovery-styled surfaces keep their host-painted look, paper included.
|
|
175
159
|
// Unlayered for the same reason as the probe stack: the editor's default
|
|
176
160
|
// prose scale is unlayered and would beat any layered override.
|
|
177
161
|
const siteStyles = useSiteStyles();
|
|
178
|
-
const activeHostCss = useMemo<SiteStyles>(
|
|
179
|
-
() => (registeredRouteStyles.length > 0 ? registeredRouteStyles : siteStyles),
|
|
180
|
-
[registeredRouteStyles, siteStyles],
|
|
181
|
-
);
|
|
182
162
|
const proseSurface = useMemo<SiteStyles>(
|
|
183
|
-
// Derived from
|
|
184
|
-
// have it, else the siteStyles registry), never from one fixed registry:
|
|
185
|
-
// the tier has to describe the same sheet the surface is showing.
|
|
163
|
+
// Derived from the siteStyles registry, the host CSS the surface shows.
|
|
186
164
|
//
|
|
187
|
-
// It must run ALONGSIDE
|
|
188
|
-
// into a cascade LAYER, the editor's default prose scale is
|
|
189
|
-
// layered always loses to unlayered — so
|
|
190
|
-
// heading metrics. This tier is the prose-scoped subset that is safe to
|
|
165
|
+
// It must run ALONGSIDE the layered host CSS, not instead of it. That CSS is
|
|
166
|
+
// injected into a cascade LAYER, the editor's default prose scale is
|
|
167
|
+
// unlayered, and layered always loses to unlayered — so the layered tier
|
|
168
|
+
// alone cannot restore heading metrics. This tier is the prose-scoped subset that is safe to
|
|
191
169
|
// inject unlayered, which is what actually beats the defaults. Live
|
|
192
170
|
// discovery is the exception: it ships the computed-style probe, itself
|
|
193
171
|
// unlayered and better at the same job.
|
|
@@ -203,20 +181,20 @@ export const CMSMDXEditor = forwardRef<MDXEditorMethods, CMSMDXEditorProps>(({ p
|
|
|
203
181
|
// `.sl-markdown-content h2:not(:where(…))` (0,1,1), since `:not(:where())`
|
|
204
182
|
// contributes nothing — so whichever is later in head order wins, and that
|
|
205
183
|
// is this tier. Without this gate a working probe would be a measurable
|
|
206
|
-
// no-op wherever a host
|
|
184
|
+
// no-op wherever a host sets siteStyles.
|
|
207
185
|
//
|
|
208
186
|
// `probeSettled` is the load-bearing half of the gate. `probedStyles === ''`
|
|
209
187
|
// alone is true on the initial render (probe still in flight) AND after a
|
|
210
188
|
// definitive empty failure, so gating only on the string paints this tier
|
|
211
189
|
// first, then tears it down when the probe lands — a visible flash on
|
|
212
|
-
// every editor open that relies on
|
|
190
|
+
// every editor open that relies on siteStyles. Hold the tier
|
|
213
191
|
// until the probe has resolved once; only then, if it settled empty, fill in
|
|
214
192
|
// with derived rules.
|
|
215
193
|
() =>
|
|
216
|
-
|
|
217
|
-
? deriveProseSurfaceStyles(
|
|
194
|
+
routeStyles.length === 0 && probeSettled && probedStyles === ''
|
|
195
|
+
? deriveProseSurfaceStyles(siteStyles, hostWrappers.content?.className)
|
|
218
196
|
: [],
|
|
219
|
-
[
|
|
197
|
+
[routeStyles, probeSettled, probedStyles, siteStyles, hostWrappers],
|
|
220
198
|
);
|
|
221
199
|
useInjectHostStyles('conloca-prose-surface', proseSurface, { layered: false });
|
|
222
200
|
// Recompose the plugins list whenever the wrappers change so the plugin
|
|
@@ -263,6 +241,8 @@ export const CMSMDXEditor = forwardRef<MDXEditorMethods, CMSMDXEditorProps>(({ p
|
|
|
263
241
|
disableImageSettingsButton={true}
|
|
264
242
|
imageButtonRef={insertImageRef}
|
|
265
243
|
imageUploadHandler={imageUploadHandler}
|
|
244
|
+
// The site does not serve branch drafts; with a loader, draft images show their loaded bytes.
|
|
245
|
+
imagePreviewHandler={getUIConfig().loadMedia ? draftImagePreview : undefined}
|
|
266
246
|
jsxComponentDescriptors={jsxComponentDescriptors}
|
|
267
247
|
extraPlugins={extraPlugins}
|
|
268
248
|
extraToolbarItems={<InsertMdxComponentButton />}
|
|
@@ -6,6 +6,9 @@ interface DrawerItemOverrideProps {
|
|
|
6
6
|
name: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/** Puck's root drop zone, which Puck does not export as a constant. */
|
|
10
|
+
export const PUCK_ROOT_DROP_ZONE = 'root:default-zone';
|
|
11
|
+
|
|
9
12
|
function generateId(componentType: string): string {
|
|
10
13
|
return `${componentType}-${crypto.randomUUID()}`;
|
|
11
14
|
}
|
|
@@ -24,8 +27,7 @@ export function DrawerItemOverride({ children, name }: DrawerItemOverrideProps)
|
|
|
24
27
|
type: 'insert',
|
|
25
28
|
componentType: name,
|
|
26
29
|
destinationIndex: puck.appState.data.content.length,
|
|
27
|
-
|
|
28
|
-
destinationZone: 'root:default-zone',
|
|
30
|
+
destinationZone: PUCK_ROOT_DROP_ZONE,
|
|
29
31
|
id,
|
|
30
32
|
recordHistory: true,
|
|
31
33
|
});
|
|
@@ -42,21 +44,25 @@ export function DrawerItemOverride({ children, name }: DrawerItemOverrideProps)
|
|
|
42
44
|
};
|
|
43
45
|
|
|
44
46
|
return (
|
|
47
|
+
// Not a real <button>: Puck's drag sensor refuses to start a drag from a press on an interactive element
|
|
48
|
+
// (button, link, input) inside a drawer item, so a <button> here made every block in the list undraggable.
|
|
45
49
|
// `block w-full`: this wrapper sits between Puck's drawer-item container
|
|
46
|
-
// and the row it lays out, so a default inline-block
|
|
50
|
+
// and the row it lays out, so a default inline-block wrapper would size to
|
|
47
51
|
// its content instead of the container. A drawer item's label is as wide
|
|
48
52
|
// as its text — a fragment is named after its content, so those names run
|
|
49
53
|
// past the sidebar — and the label's own `text-overflow: ellipsis` can
|
|
50
54
|
// only take effect while something above it is still bounded by the
|
|
51
|
-
// sidebar's width.
|
|
52
|
-
<button
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
// sidebar's width. `select-none` keeps a double-click from selecting the label's text, as it never did on a button.
|
|
56
|
+
// biome-ignore lint/a11y/useSemanticElements: a <button> here would stop Puck from dragging the block (see above)
|
|
57
|
+
<div
|
|
58
|
+
role="button"
|
|
59
|
+
tabIndex={0}
|
|
60
|
+
className="block w-full select-none"
|
|
55
61
|
onDoubleClick={handleDoubleClick}
|
|
56
62
|
onKeyDown={handleKeyDown}
|
|
57
63
|
data-testid={`drawer-item-${name}`}
|
|
58
64
|
>
|
|
59
65
|
{children}
|
|
60
|
-
</
|
|
66
|
+
</div>
|
|
61
67
|
);
|
|
62
68
|
}
|