@conloca/cms-spa 0.2.0 → 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.
Files changed (182) hide show
  1. package/dist/spa/main.css +17 -3
  2. package/dist/ts/App.d.ts +5 -1
  3. package/dist/ts/App.d.ts.map +1 -1
  4. package/dist/ts/App.js +7 -2
  5. package/dist/ts/App.js.map +1 -1
  6. package/dist/ts/components/CMSDashboard.d.ts.map +1 -1
  7. package/dist/ts/components/CMSDashboard.js +6 -2
  8. package/dist/ts/components/CMSDashboard.js.map +1 -1
  9. package/dist/ts/components/RouteErrorPage.d.ts +11 -0
  10. package/dist/ts/components/RouteErrorPage.d.ts.map +1 -0
  11. package/dist/ts/components/RouteErrorPage.js +44 -0
  12. package/dist/ts/components/RouteErrorPage.js.map +1 -0
  13. package/dist/ts/components/cards/DataEntryCard.d.ts +1 -1
  14. package/dist/ts/components/cards/DataEntryCard.d.ts.map +1 -1
  15. package/dist/ts/components/cards/SectionCard.d.ts +1 -1
  16. package/dist/ts/components/cards/SectionCard.d.ts.map +1 -1
  17. package/dist/ts/components/dashboard/RecentActivity.d.ts.map +1 -1
  18. package/dist/ts/components/dashboard/RecentActivity.js +2 -8
  19. package/dist/ts/components/dashboard/RecentActivity.js.map +1 -1
  20. package/dist/ts/components/dialogs/CreateDataDialog.js +2 -2
  21. package/dist/ts/components/dialogs/CreateDataDialog.js.map +1 -1
  22. package/dist/ts/components/dialogs/CreateFolderDialog.d.ts.map +1 -1
  23. package/dist/ts/components/dialogs/CreateFolderDialog.js +2 -1
  24. package/dist/ts/components/dialogs/CreateFolderDialog.js.map +1 -1
  25. package/dist/ts/components/dialogs/CreatePageFlow.d.ts +13 -0
  26. package/dist/ts/components/dialogs/CreatePageFlow.d.ts.map +1 -0
  27. package/dist/ts/components/dialogs/CreatePageFlow.js +100 -0
  28. package/dist/ts/components/dialogs/CreatePageFlow.js.map +1 -0
  29. package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts +1 -1
  30. package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts.map +1 -1
  31. package/dist/ts/components/dialogs/DataPropertiesDialog.js +2 -2
  32. package/dist/ts/components/dialogs/DataPropertiesDialog.js.map +1 -1
  33. package/dist/ts/components/dialogs/DeleteConfirmDialog.d.ts +1 -1
  34. package/dist/ts/components/dialogs/DeleteConfirmDialog.d.ts.map +1 -1
  35. package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts +2 -2
  36. package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts.map +1 -1
  37. package/dist/ts/components/dialogs/FragmentPropertiesDialog.js +2 -2
  38. package/dist/ts/components/dialogs/FragmentPropertiesDialog.js.map +1 -1
  39. package/dist/ts/components/dialogs/MoveFolderDialog.d.ts +1 -1
  40. package/dist/ts/components/dialogs/MoveFolderDialog.d.ts.map +1 -1
  41. package/dist/ts/components/dialogs/PageMetadataDialog.d.ts +2 -12
  42. package/dist/ts/components/dialogs/PageMetadataDialog.d.ts.map +1 -1
  43. package/dist/ts/components/dialogs/PageMetadataDialog.js +3 -21
  44. package/dist/ts/components/dialogs/PageMetadataDialog.js.map +1 -1
  45. package/dist/ts/components/editor/DrawerItemOverride.d.ts +2 -0
  46. package/dist/ts/components/editor/DrawerItemOverride.d.ts.map +1 -1
  47. package/dist/ts/components/editor/DrawerItemOverride.js +4 -3
  48. package/dist/ts/components/editor/DrawerItemOverride.js.map +1 -1
  49. package/dist/ts/components/editor/GenericBlock.js +2 -2
  50. package/dist/ts/components/editor/GenericBlock.js.map +1 -1
  51. package/dist/ts/components/editor/LocaleSelector.d.ts +1 -1
  52. package/dist/ts/components/editor/LocaleSelector.d.ts.map +1 -1
  53. package/dist/ts/components/editor/PageEditor.d.ts +7 -8
  54. package/dist/ts/components/editor/PageEditor.d.ts.map +1 -1
  55. package/dist/ts/components/editor/PageEditor.js +78 -17
  56. package/dist/ts/components/editor/PageEditor.js.map +1 -1
  57. package/dist/ts/components/editor/PageEditorHeaderActions.d.ts +1 -1
  58. package/dist/ts/components/editor/PageEditorHeaderActions.d.ts.map +1 -1
  59. package/dist/ts/components/editor/PageEditorHeaderActions.js +1 -1
  60. package/dist/ts/components/editor/PageEditorHeaderActions.js.map +1 -1
  61. package/dist/ts/components/editor/PageEditorWrapper.d.ts.map +1 -1
  62. package/dist/ts/components/editor/PageEditorWrapper.js +17 -7
  63. package/dist/ts/components/editor/PageEditorWrapper.js.map +1 -1
  64. package/dist/ts/components/editor/draft-media-config.d.ts +4 -0
  65. package/dist/ts/components/editor/draft-media-config.d.ts.map +1 -0
  66. package/dist/ts/components/editor/draft-media-config.js +95 -0
  67. package/dist/ts/components/editor/draft-media-config.js.map +1 -0
  68. package/dist/ts/components/editor/page-setting-targets.d.ts +1 -1
  69. package/dist/ts/components/editor/page-setting-targets.d.ts.map +1 -1
  70. package/dist/ts/components/editors/DataEditor.d.ts +3 -3
  71. package/dist/ts/components/editors/DataEditor.d.ts.map +1 -1
  72. package/dist/ts/components/forms/HintForm.js +8 -5
  73. package/dist/ts/components/forms/HintForm.js.map +1 -1
  74. package/dist/ts/components/forms/SchemaForm.d.ts +17 -5
  75. package/dist/ts/components/forms/SchemaForm.d.ts.map +1 -1
  76. package/dist/ts/components/forms/SchemaForm.js +16 -9
  77. package/dist/ts/components/forms/SchemaForm.js.map +1 -1
  78. package/dist/ts/components/media/AssetCard.d.ts +1 -1
  79. package/dist/ts/components/media/AssetCard.d.ts.map +1 -1
  80. package/dist/ts/components/media/AssetDetailSidebar.d.ts +1 -1
  81. package/dist/ts/components/media/AssetDetailSidebar.d.ts.map +1 -1
  82. package/dist/ts/components/media/FolderTreeSidebar.d.ts.map +1 -1
  83. package/dist/ts/components/media/FolderTreeSidebar.js +4 -1
  84. package/dist/ts/components/media/FolderTreeSidebar.js.map +1 -1
  85. package/dist/ts/components/media/MediaLibrary.d.ts +1 -1
  86. package/dist/ts/components/media/MediaLibrary.d.ts.map +1 -1
  87. package/dist/ts/components/media/MediaToolbar.d.ts +1 -1
  88. package/dist/ts/components/media/MediaToolbar.d.ts.map +1 -1
  89. package/dist/ts/components/pages/DataList.d.ts.map +1 -1
  90. package/dist/ts/components/pages/DataList.js +6 -4
  91. package/dist/ts/components/pages/DataList.js.map +1 -1
  92. package/dist/ts/components/pages/PageList.d.ts.map +1 -1
  93. package/dist/ts/components/pages/PageList.js +4 -96
  94. package/dist/ts/components/pages/PageList.js.map +1 -1
  95. package/dist/ts/components/sandbox/ContentSandbox.d.ts +1 -1
  96. package/dist/ts/components/sandbox/ContentSandbox.d.ts.map +1 -1
  97. package/dist/ts/components/ui/IconButton.d.ts +1 -1
  98. package/dist/ts/components/ui/IconButton.d.ts.map +1 -1
  99. package/dist/ts/content-form-fields.d.ts +41 -0
  100. package/dist/ts/content-form-fields.d.ts.map +1 -0
  101. package/dist/ts/content-form-fields.js +70 -0
  102. package/dist/ts/content-form-fields.js.map +1 -0
  103. package/dist/ts/data-schemas.d.ts +4 -3
  104. package/dist/ts/data-schemas.d.ts.map +1 -1
  105. package/dist/ts/data-schemas.js.map +1 -1
  106. package/dist/ts/host-discovery.d.ts.map +1 -1
  107. package/dist/ts/host-schema.d.ts +73 -0
  108. package/dist/ts/host-schema.d.ts.map +1 -0
  109. package/dist/ts/host-schema.js +66 -0
  110. package/dist/ts/host-schema.js.map +1 -0
  111. package/dist/ts/host-style-probe.d.ts.map +1 -1
  112. package/dist/ts/host-style-probe.js +16 -0
  113. package/dist/ts/host-style-probe.js.map +1 -1
  114. package/dist/ts/main-spa.d.ts.map +1 -1
  115. package/dist/ts/main-spa.js +2 -3
  116. package/dist/ts/main-spa.js.map +1 -1
  117. package/dist/ts/page-schema-define.d.ts +14 -12
  118. package/dist/ts/page-schema-define.d.ts.map +1 -1
  119. package/dist/ts/page-schema-define.js +8 -5
  120. package/dist/ts/page-schema-define.js.map +1 -1
  121. package/dist/ts/page-schemas.d.ts.map +1 -1
  122. package/dist/ts/puck-config.d.ts.map +1 -1
  123. package/dist/ts/selected-block.d.ts.map +1 -1
  124. package/dist/ts/site-styles.d.ts +3 -2
  125. package/dist/ts/site-styles.d.ts.map +1 -1
  126. package/dist/ts/site-styles.js +6 -4
  127. package/dist/ts/site-styles.js.map +1 -1
  128. package/dist/ts/ui-config.d.ts +13 -4
  129. package/dist/ts/ui-config.d.ts.map +1 -1
  130. package/dist/ts/ui-config.js +9 -0
  131. package/dist/ts/ui-config.js.map +1 -1
  132. package/dist/ts/utils/asset-url.d.ts +2 -0
  133. package/dist/ts/utils/asset-url.d.ts.map +1 -1
  134. package/dist/ts/utils/asset-url.js +7 -0
  135. package/dist/ts/utils/asset-url.js.map +1 -1
  136. package/dist/ts/utils/pageMetadata.d.ts.map +1 -1
  137. package/dist/ts/utils/pageMetadata.js +27 -10
  138. package/dist/ts/utils/pageMetadata.js.map +1 -1
  139. package/dist/ts/utils/schema-fields.d.ts +23 -0
  140. package/dist/ts/utils/schema-fields.d.ts.map +1 -0
  141. package/dist/ts/utils/schema-fields.js +82 -0
  142. package/dist/ts/utils/schema-fields.js.map +1 -0
  143. package/package.json +41 -13
  144. package/src/App.tsx +13 -4
  145. package/src/components/CMSDashboard.tsx +12 -4
  146. package/src/components/RouteErrorPage.tsx +75 -0
  147. package/src/components/dashboard/RecentActivity.tsx +3 -7
  148. package/src/components/dialogs/CreateDataDialog.tsx +2 -2
  149. package/src/components/dialogs/CreateFolderDialog.tsx +2 -1
  150. package/src/components/dialogs/CreatePageFlow.tsx +117 -0
  151. package/src/components/dialogs/DataPropertiesDialog.tsx +3 -2
  152. package/src/components/dialogs/FragmentPropertiesDialog.tsx +3 -2
  153. package/src/components/dialogs/PageMetadataDialog.tsx +5 -28
  154. package/src/components/editor/DrawerItemOverride.tsx +14 -8
  155. package/src/components/editor/GenericBlock.tsx +2 -2
  156. package/src/components/editor/PageEditor.tsx +90 -19
  157. package/src/components/editor/PageEditorHeaderActions.tsx +1 -1
  158. package/src/components/editor/PageEditorWrapper.tsx +17 -7
  159. package/src/components/editor/draft-media-config.ts +95 -0
  160. package/src/components/editors/DataEditor.tsx +2 -2
  161. package/src/components/forms/HintForm.tsx +7 -5
  162. package/src/components/forms/SchemaForm.tsx +41 -12
  163. package/src/components/media/FolderTreeSidebar.tsx +3 -1
  164. package/src/components/pages/DataList.tsx +6 -4
  165. package/src/components/pages/PageList.tsx +6 -116
  166. package/src/content-form-fields.ts +79 -0
  167. package/src/data-schemas.ts +4 -3
  168. package/src/host-schema.ts +122 -0
  169. package/src/host-style-probe.ts +16 -0
  170. package/src/main-spa.tsx +2 -3
  171. package/src/main.css +10 -7
  172. package/src/page-schema-define.ts +29 -17
  173. package/src/site-styles.ts +6 -4
  174. package/src/ui-config.ts +16 -4
  175. package/src/utils/asset-url.ts +8 -0
  176. package/src/utils/pageMetadata.ts +27 -10
  177. package/src/utils/schema-fields.ts +106 -0
  178. package/dist/ts/utils/zodIntrospect.d.ts +0 -19
  179. package/dist/ts/utils/zodIntrospect.d.ts.map +0 -1
  180. package/dist/ts/utils/zodIntrospect.js +0 -95
  181. package/dist/ts/utils/zodIntrospect.js.map +0 -1
  182. package/src/utils/zodIntrospect.ts +0 -136
@@ -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 { CreatePageData, Page } from '../../types.js';
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 { CreatePageDialog } from '../dialogs/CreatePageDialog.js';
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: 'published', // We'll determine this from publishAt dates
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 Dialog */}
655
- <CreatePageDialog
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
@@ -0,0 +1,79 @@
1
+ import type { FieldInfo, FormFields } from './utils/schema-fields.js';
2
+
3
+ /**
4
+ * Form definitions for the metadata the CMS itself owns.
5
+ *
6
+ * These were Zod objects built only so a Zod introspector could read a
7
+ * {@link FormFields} record back out of them — the schemas were never parsed
8
+ * with. They are the records directly now; validation of the same metadata is
9
+ * the generated validators in `@conloca/content-api/schemas`.
10
+ *
11
+ * Every entry below is pinned as a literal table in
12
+ * `test/content-form-fields.test.ts`, which also checks each field's
13
+ * type/optional/nullable against the Typia-generated metadata of the matching
14
+ * content-api type. Each record keeps its literal keys (`satisfies`), so a
15
+ * dialog can prove at compile time which fields it renders.
16
+ */
17
+
18
+ const requiredString = (description: string): FieldInfo => ({
19
+ type: 'string',
20
+ description,
21
+ isOptional: false,
22
+ isNullable: false,
23
+ });
24
+ const optionalString = (description: string): FieldInfo => ({
25
+ type: 'string',
26
+ description,
27
+ isOptional: true,
28
+ isNullable: false,
29
+ });
30
+ const optionalStringArray = (description: string): FieldInfo => ({
31
+ type: 'array',
32
+ description,
33
+ isOptional: true,
34
+ isNullable: false,
35
+ });
36
+ const optionalNullableDate = (description: string): FieldInfo => ({
37
+ type: 'date',
38
+ format: 'date-time',
39
+ description,
40
+ isOptional: true,
41
+ isNullable: true,
42
+ });
43
+
44
+ /** Pathname — the page-settings core section in every mode (the dialog renders the title itself). */
45
+ export const pathnameOnlyFields = {
46
+ pathname: requiredString('URL path (e.g., /about)'),
47
+ } satisfies FormFields;
48
+
49
+ /** Publishing window only — the page-settings trailing section in `minimal` mode. */
50
+ export const publishWindowFields = {
51
+ publishAt: optionalNullableDate(
52
+ '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.',
53
+ ),
54
+ unpublishAt: optionalNullableDate('Schedule unpublish date/time'),
55
+ } satisfies FormFields;
56
+
57
+ /** SEO + publishing window — the page-settings trailing section in `full` mode. */
58
+ export const seoPublishingFields = {
59
+ description: optionalString('Meta description for search engines'),
60
+ robots: optionalString('Robots meta tag (e.g., index, follow)'),
61
+ canonical: { ...optionalString('Canonical URL for duplicate content'), format: 'url' },
62
+ ...publishWindowFields,
63
+ } satisfies FormFields;
64
+
65
+ /** Editable fragment metadata — replaces `fragmentEditableSchema`. */
66
+ export const fragmentEditableFields = {
67
+ title: requiredString('Display name for the fragment'),
68
+ description: optionalString('Brief description of this fragment'),
69
+ category: optionalString('Category for organizing fragments (e.g., headers, cta, content)'),
70
+ tags: optionalStringArray('Tags for filtering and organization'),
71
+ } satisfies FormFields;
72
+
73
+ /** Editable data-entry metadata — replaces `dataEditableSchema`. */
74
+ export const dataEditableFields = {
75
+ title: requiredString('Display name for the entry'),
76
+ description: optionalString('Brief description of this entry'),
77
+ category: optionalString('Category for organizing entries'),
78
+ tags: optionalStringArray('Tags for filtering and organization'),
79
+ } satisfies FormFields;
@@ -1,11 +1,12 @@
1
1
  import { useEffect, useState } from 'react';
2
- import type { z } from 'zod';
2
+ import type { HostSchema } from './host-schema.js';
3
3
 
4
4
  /**
5
5
  * Type for a collection of data schemas.
6
- * Each key is a collection name, value is the Zod schema for that collection's data.
6
+ * Each key is a collection name, value is the {@link HostSchema} (generated
7
+ * Typia validator + JSON Schema metadata) for that collection's data payload.
7
8
  */
8
- export type DataSchemas = Record<string, z.ZodObject<z.ZodRawShape>>;
9
+ export type DataSchemas = Record<string, HostSchema>;
9
10
 
10
11
  /**
11
12
  * Shared state for data schemas across module instances.
@@ -0,0 +1,122 @@
1
+ import type { IJsonSchemaUnit, IValidation } from '@typia/interface';
2
+
3
+ /**
4
+ * The contract a site's `pageSchemas` / `dataSchemas` entries are written in.
5
+ *
6
+ * A site's content schema is dynamic from this package's point of view — it is
7
+ * declared in the host's own source and only reaches the CMS at runtime — so the
8
+ * CMS cannot generate anything for it. The host does, with Typia, where the type
9
+ * lives:
10
+ *
11
+ * ```ts
12
+ * import typia from 'typia';
13
+ *
14
+ * interface BlogFields {
15
+ * // A JSDoc comment here becomes the field's help text in the editor.
16
+ * excerpt?: string;
17
+ * }
18
+ *
19
+ * export const articleFields = defineHostSchema<BlogFields>({
20
+ * validate: typia.createValidate<BlogFields>(),
21
+ * metadata: typia.json.schema<BlogFields>(),
22
+ * });
23
+ * ```
24
+ *
25
+ * Both members are compiler output for the same `T`: `validate` is what the
26
+ * build validates stored entries with (`@conloca/astro-cms`'s loader), and
27
+ * `metadata` is the JSON Schema the editor renders its form from. Nothing here
28
+ * re-describes the shape by hand, and the `T` parameter ties the two together at
29
+ * compile time.
30
+ *
31
+ * `typia.plain.createValidatePrune<T>()` is the Zod-`z.object()` equivalent for
32
+ * `validate`: on success it also drops undeclared nested keys. Plain
33
+ * `typia.createValidate<T>()` keeps them.
34
+ */
35
+ export interface HostSchema<T extends object = object> {
36
+ /** A generated Typia validator for `T` (`typia.createValidate<T>()` or `typia.plain.createValidatePrune<T>()`). */
37
+ readonly validate: (input: unknown) => IValidation<T>;
38
+ /** Generated JSON Schema metadata for `T` (`typia.json.schema<T>()`). */
39
+ readonly metadata: IJsonSchemaUnit<'3.1', T>;
40
+ }
41
+
42
+ /** The value type a {@link HostSchema} validates — the `z.infer` of this contract. */
43
+ export type HostSchemaType<S> = S extends HostSchema<infer T> ? T : never;
44
+
45
+ /**
46
+ * Typed identity for a {@link HostSchema}. Refuses at declaration time what the
47
+ * editor and the loader could not use: a validator that is not a function, or
48
+ * metadata whose root is not an object type (content entries are records).
49
+ */
50
+ export function defineHostSchema<T extends object>(schema: HostSchema<T>): HostSchema<T> {
51
+ if (typeof schema.validate !== 'function') {
52
+ throw new Error('defineHostSchema: `validate` must be a generated Typia validator (typia.createValidate<T>()).');
53
+ }
54
+ if (schema.metadata?.version !== '3.1' || rootObjectOf(schema.metadata) === null) {
55
+ throw new Error(
56
+ 'defineHostSchema: `metadata` must be `typia.json.schema<T>()` (JSON Schema 3.1) for an object type T.',
57
+ );
58
+ }
59
+ return schema;
60
+ }
61
+
62
+ /**
63
+ * Whether a value is a generated host schema. A site's `dataSchemas` / `pageSchemas` reach the
64
+ * editor at runtime from the site's own bundle, so an entry written before the generated
65
+ * contract (a validator-library object, a hand-written descriptor) can arrive where the types
66
+ * promise a {@link HostSchema}; reading its `metadata` then throws. Check before reading.
67
+ */
68
+ // oxlint-disable-next-line anti-slop/no-unknown-parameters -- this is the boundary check that turns an untyped bundle export into a HostSchema.
69
+ export function isHostSchema(value: unknown): value is HostSchema {
70
+ if (typeof value !== 'object' || value === null) return false;
71
+ if (!('validate' in value) || typeof value.validate !== 'function') return false;
72
+ if (!('metadata' in value)) return false;
73
+ const { metadata } = value;
74
+ return (
75
+ typeof metadata === 'object' &&
76
+ metadata !== null &&
77
+ 'version' in metadata &&
78
+ metadata.version === '3.1' &&
79
+ 'schema' in metadata &&
80
+ typeof metadata.schema === 'object' &&
81
+ metadata.schema !== null &&
82
+ 'components' in metadata &&
83
+ typeof metadata.components === 'object' &&
84
+ metadata.components !== null
85
+ );
86
+ }
87
+
88
+ /** Generated JSON Schema metadata, whatever type it was generated for. */
89
+ export type HostSchemaMetadata = IJsonSchemaUnit.IV3_1<unknown>;
90
+ type JsonSchema = HostSchemaMetadata['schema'];
91
+ type JsonObjectSchema = Extract<JsonSchema, { type: 'object' }>;
92
+
93
+ /** `$ref`s generated by `typia.json.schema` all point into the unit's own components. */
94
+ const SCHEMA_REF_PREFIX = '#/components/schemas/';
95
+
96
+ /**
97
+ * Follow a generated `$ref` to its component. Returns the schema unchanged when
98
+ * it is not a reference, and `null` for a reference the unit does not carry.
99
+ */
100
+ export function resolveHostJsonSchema(
101
+ metadata: HostSchemaMetadata,
102
+ node: JsonSchema,
103
+ ): Exclude<JsonSchema, { $ref: string }> | null {
104
+ let current: JsonSchema | undefined = node;
105
+ // A named type can only alias another named type a bounded number of times.
106
+ for (let hops = 0; current && '$ref' in current; hops++) {
107
+ if (hops > 16 || !current.$ref.startsWith(SCHEMA_REF_PREFIX)) return null;
108
+ current = metadata.components.schemas?.[current.$ref.slice(SCHEMA_REF_PREFIX.length)];
109
+ }
110
+ return current ?? null;
111
+ }
112
+
113
+ /** The object schema at the root of generated metadata, or `null` when the root is not an object. */
114
+ export function rootObjectOf(metadata: HostSchemaMetadata): JsonObjectSchema | null {
115
+ const root = resolveHostJsonSchema(metadata, metadata.schema);
116
+ return root && 'type' in root && root.type === 'object' ? root : null;
117
+ }
118
+
119
+ /** The top-level field names a host schema declares, in declaration order. */
120
+ export function hostSchemaFieldNames(schema: HostSchema): string[] {
121
+ return Object.keys(rootObjectOf(schema.metadata)?.properties ?? {});
122
+ }
@@ -406,15 +406,31 @@ function makeProbeEl(doc: Document, tag: string): HTMLElement {
406
406
  * numbers. Filtered out for any tag other than ul/ol. */
407
407
  const LIST_STYLE_PROPS = new Set(['list-style-type', 'list-style-position']);
408
408
 
409
+ /** The properties `@conloca/mdx`'s L0 heading scale sets on `h1`..`h6`.
410
+ * Its `:where(.conloca-prose--editor) hN` rules are unlayered at (0,0,1),
411
+ * the same specificity as the rules emitted here, so the stylesheet that
412
+ * comes last in `<head>` would win the tie — and nothing orders the probe's
413
+ * `<style>` against a bundled or lazily loaded editor sheet. The probe
414
+ * therefore also publishes these values as `--conloca-host-hN-<prop>` on the
415
+ * heading itself, and the L0 rules read them through `var()`: whichever rule
416
+ * wins, the heading resolves to the host's value. */
417
+ const HEADING_SCALE_PROPS: Partial<Record<(typeof PROBE_PROPS)[number], true>> = {
418
+ 'font-size': true,
419
+ 'font-weight': true,
420
+ 'line-height': true,
421
+ };
422
+
409
423
  function generateRule(view: Window, sample: HTMLElement, tag: string): string {
410
424
  const cs = view.getComputedStyle(sample);
411
425
  const decls: string[] = [];
412
426
  const isListContainer = tag === 'ul' || tag === 'ol';
427
+ const isHeading = /^h[1-6]$/.test(tag);
413
428
  for (const prop of PROBE_PROPS) {
414
429
  if (LIST_STYLE_PROPS.has(prop) && !isListContainer) continue;
415
430
  const value = cs.getPropertyValue(prop);
416
431
  if (value && value !== 'normal' && value !== 'none') {
417
432
  decls.push(`${prop}: ${value}`);
433
+ if (isHeading && HEADING_SCALE_PROPS[prop]) decls.push(`--conloca-host-${tag}-${prop}: ${value}`);
418
434
  }
419
435
  }
420
436
  if (decls.length === 0) return '';
package/src/main-spa.tsx CHANGED
@@ -6,7 +6,7 @@ import App from './App.js';
6
6
  import { CanvasThemeProvider } from './hooks/useCanvasTheme.js';
7
7
  import { ThemeProvider } from './hooks/useTheme.js';
8
8
  import { installDiscoveredMdxComponents, type MdxComponents } from './mdx-components.js';
9
- import { getUIConfig } from './ui-config.js';
9
+ import { getCmsRoute, getUIConfig } from './ui-config.js';
10
10
 
11
11
  /**
12
12
  * Full SPA boot. Loaded by `main.tsx` when the document is the top
@@ -37,8 +37,7 @@ export function mountSpa(): void {
37
37
  // slotted installer merges them with the schemas-loader module's
38
38
  // host-authored list regardless of which of the two settles first —
39
39
  // see `installHostAuthoredMdxComponents` for the race this closes.
40
- const cmsBase = (config.basename ?? '/__cms').replace(/\/+$/, '');
41
- fetch(`${cmsBase}/api/registry`)
40
+ fetch(`${getCmsRoute()}/api/registry`)
42
41
  .then((res) => {
43
42
  if (!res.ok) throw new Error(`registry endpoint ${res.status}`);
44
43
  return res.json();
package/src/main.css CHANGED
@@ -425,11 +425,14 @@ body {
425
425
  padding: 0.375rem !important;
426
426
  }
427
427
 
428
- /* Disable undo/redo buttons when there's no history */
429
- [class*="MenuBar"] button[disabled],
430
- [class*="MenuBar"] button:disabled,
431
- [class*="MenuBar"] button[aria-disabled="true"],
432
- [class*="MenuBar"] button[aria-disabled="true"]:hover {
428
+ /* Disable undo/redo buttons when there's no history. Scoped to Puck's history
429
+ * group: the editor's own header actions also mount inside the MenuBar, and
430
+ * the unavailable Preview must still receive its click and hover to explain
431
+ * itself. */
432
+ [class*="MenuBar-history"] button[disabled],
433
+ [class*="MenuBar-history"] button:disabled,
434
+ [class*="MenuBar-history"] button[aria-disabled="true"],
435
+ [class*="MenuBar-history"] button[aria-disabled="true"]:hover {
433
436
  opacity: 0.4 !important;
434
437
  cursor: not-allowed !important;
435
438
  pointer-events: none !important;
@@ -438,13 +441,13 @@ body {
438
441
  }
439
442
 
440
443
  /* Style for enabled undo/redo buttons */
441
- [class*="MenuBar"] button:not([disabled]):not(:disabled):not([aria-disabled="true"]) {
444
+ [class*="MenuBar-history"] button:not([disabled]):not(:disabled):not([aria-disabled="true"]) {
442
445
  opacity: 1 !important;
443
446
  cursor: pointer !important;
444
447
  }
445
448
 
446
449
  /* Also target buttons that might use data attributes for disabled state */
447
- [class*="MenuBar"] button[data-disabled="true"] {
450
+ [class*="MenuBar-history"] button[data-disabled="true"] {
448
451
  opacity: 0.4 !important;
449
452
  cursor: not-allowed !important;
450
453
  pointer-events: none !important;
@@ -1,11 +1,12 @@
1
- import type { z } from 'zod';
1
+ import { type HostSchema, hostSchemaFieldNames } from './host-schema.js';
2
2
 
3
3
  /**
4
4
  * Form-UI hint vocabulary for page metadata fields.
5
5
  *
6
6
  * Hosts attach a hint to each field they want surfaced in the page-settings
7
7
  * dialog. The hint drives form rendering — control type, grouping, helper
8
- * text, etc. — independently of the Zod schema, which still owns validation.
8
+ * text, etc. — independently of the host schema, whose generated validator
9
+ * still owns validation.
9
10
  *
10
11
  * Dotted keys ('sidebar.label') are supported in the hint record; on save
11
12
  * they materialize into nested objects in YAML frontmatter, and on load
@@ -62,10 +63,10 @@ export type PageSchemaGroup = {
62
63
  */
63
64
  export type CoreFieldsMode = 'full' | 'minimal' | 'none';
64
65
 
65
- export interface PageSchemaDescriptor<S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> {
66
+ export interface PageSchemaDescriptor<S extends HostSchema = HostSchema> {
66
67
  /** Human-readable label shown in the dialog header. */
67
68
  label?: string;
68
- /** Zod schema used for validation and field-shape introspection. */
69
+ /** Host schema: its generated validator checks entries, its generated metadata shapes the form. */
69
70
  schema: S;
70
71
  /** Form-UI hints keyed by field name (dotted keys allowed for nested fields). */
71
72
  ui?: FieldHints;
@@ -80,15 +81,13 @@ export interface PageSchemaDescriptor<S extends z.ZodObject<z.ZodRawShape> = z.Z
80
81
  *
81
82
  * Mirrors Astro's `defineConfig` — purely for editor inference. The schema's
82
83
  * concrete type is carried through the descriptor (not widened), so a host
83
- * can recover its metadata type from `z.infer<typeof descriptor.schema>`.
84
+ * can recover its metadata type from `HostSchemaType<typeof descriptor.schema>`.
84
85
  *
85
86
  * Import this from `@conloca/astro-cms/page-schemas` in a content config so
86
87
  * the MDX editor / React registry is not pulled into Astro's content layer.
87
88
  */
88
- export function definePageSchema<S extends z.ZodObject<z.ZodRawShape>>(
89
- descriptor: PageSchemaDescriptor<S>,
90
- ): PageSchemaDescriptor<S> {
91
- if (descriptor.coreFields?.mode === 'none' && !('title' in descriptor.schema.shape)) {
89
+ export function definePageSchema<S extends HostSchema>(descriptor: PageSchemaDescriptor<S>): PageSchemaDescriptor<S> {
90
+ if (descriptor.coreFields?.mode === 'none' && !hostSchemaFieldNames(descriptor.schema).includes('title')) {
92
91
  throw new Error(
93
92
  "definePageSchema: coreFields.mode 'none' requires the schema to declare a `title` field " +
94
93
  '(ContentMeta.title is required by the content-api).',
@@ -98,10 +97,10 @@ export function definePageSchema<S extends z.ZodObject<z.ZodRawShape>>(
98
97
  }
99
98
 
100
99
  /**
101
- * Registry entry value: either a bare Zod object (legacy — wrapped as a
100
+ * Registry entry value: either a bare {@link HostSchema} (wrapped as a
102
101
  * descriptor with `coreFields.mode: 'full'`) or an explicit descriptor.
103
102
  */
104
- export type PageSchemaEntry = z.ZodObject<z.ZodRawShape> | PageSchemaDescriptor;
103
+ export type PageSchemaEntry<S extends HostSchema = HostSchema> = S | PageSchemaDescriptor<S>;
105
104
 
106
105
  /**
107
106
  * Page-schema registry keyed by match expression.
@@ -111,20 +110,22 @@ export type PageSchemaEntry = z.ZodObject<z.ZodRawShape> | PageSchemaDescriptor;
111
110
  * - `type:<puck|mdx>` — matches all pages of the given content type.
112
111
  * - pathname prefix (must start with `/`) — longest-prefix-match against the page's pathname.
113
112
  */
114
- export type PageSchemas = Record<string, PageSchemaEntry>;
113
+ export type PageSchemas<S extends HostSchema = HostSchema> = Record<string, PageSchemaEntry<S>>;
115
114
 
116
115
  /**
117
- * Normalize an entry to a descriptor. Bare Zod objects (legacy) get wrapped
118
- * with default `coreFields.mode: 'full'` so the dialog can render today's
116
+ * Normalize an entry to a descriptor. Bare host schemas get wrapped with
117
+ * default `coreFields.mode: 'full'` so the dialog can render today's
119
118
  * three-section layout unchanged.
120
119
  */
121
- export function toPageSchemaDescriptor(entry: PageSchemaEntry): PageSchemaDescriptor {
120
+ export function toPageSchemaDescriptor<S extends HostSchema = HostSchema>(
121
+ entry: PageSchemaEntry<S>,
122
+ ): PageSchemaDescriptor<S> {
122
123
  if (isPageSchemaDescriptor(entry)) return entry;
123
124
  return { schema: entry, coreFields: { mode: 'full' } };
124
125
  }
125
126
 
126
- function isPageSchemaDescriptor(value: PageSchemaEntry): value is PageSchemaDescriptor {
127
- return typeof value === 'object' && value !== null && 'schema' in value && !('shape' in value);
127
+ function isPageSchemaDescriptor<S extends HostSchema>(value: PageSchemaEntry<S>): value is PageSchemaDescriptor<S> {
128
+ return typeof value === 'object' && value !== null && 'schema' in value && !('validate' in value);
128
129
  }
129
130
 
130
131
  /**
@@ -174,3 +175,14 @@ export function resolvePageSchemaEntry(
174
175
  // The data-collection registry type, re-exported so content configs can
175
176
  // reference it without touching the runtime data-schemas module.
176
177
  export type { DataSchemas } from './data-schemas.js';
178
+ // The generated-schema contract both registries are keyed on.
179
+ export {
180
+ defineHostSchema,
181
+ type HostSchema,
182
+ type HostSchemaMetadata,
183
+ type HostSchemaType,
184
+ hostSchemaFieldNames,
185
+ isHostSchema,
186
+ resolveHostJsonSchema,
187
+ rootObjectOf,
188
+ } from './host-schema.js';
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { IMPORT_RE } from './site-css-layer.js';
3
+ import { getCmsRoute } from './ui-config.js';
3
4
 
4
5
  /**
5
6
  * Two parallel registries for host-supplied CSS strings: `siteStyles` for the
@@ -168,11 +169,11 @@ export function useEditorStyles(): SiteStyles {
168
169
  * Fetch the host's CSS for a route URL from the integration's
169
170
  * `/api/styles` endpoint and return it as a single-element array suitable
170
171
  * for `useInjectHostStyles`. Empty until the fetch resolves; empty if no
171
- * URL is given.
172
+ * URL is given. `cmsRoute` defaults to the route the CMS is mounted at.
172
173
  */
173
174
  export function useFetchedSiteStyles(routeUrl: string | undefined, options: { cmsRoute?: string } = {}): SiteStyles {
174
175
  const [styles, setStyles] = useState<SiteStyles>([]);
175
- const cmsRoute = options.cmsRoute ?? '/__cms';
176
+ const cmsRoute = options.cmsRoute ?? getCmsRoute();
176
177
 
177
178
  useEffect(() => {
178
179
  if (!routeUrl) {
@@ -251,14 +252,15 @@ export interface HostWrappers {
251
252
  *
252
253
  * Re-fetches whenever `routeUrl` changes (eg locale switch / doc
253
254
  * switch). Errors are logged and swallowed; the caller falls back to
254
- * the no-wrapper render path.
255
+ * the no-wrapper render path. `cmsRoute` defaults to the route the CMS is
256
+ * mounted at.
255
257
  */
256
258
  export function useFetchedHostWrappers(
257
259
  routeUrl: string | undefined,
258
260
  options: { cmsRoute?: string } = {},
259
261
  ): HostWrappers {
260
262
  const [wrappers, setWrappers] = useState<HostWrappers>({ content: null, codeBlock: null });
261
- const cmsRoute = options.cmsRoute ?? '/__cms';
263
+ const cmsRoute = options.cmsRoute ?? getCmsRoute();
262
264
 
263
265
  useEffect(() => {
264
266
  if (!routeUrl) {
package/src/ui-config.ts CHANGED
@@ -130,12 +130,14 @@ export interface UIConfig {
130
130
  * Base path the media surfaces build thumbnail URLs against
131
131
  * (`buildAssetServeUrl(assetsBasePath, folder, filename)`). A host
132
132
  * passes its own base here when it serves media somewhere other than
133
- * the `/__cms/api/assets/serve` default. When absent,
134
- * `MediaPage`/`ImagePicker` pass `undefined` and
135
- * `AssetCard`/`AssetDetailSidebar` keep their literal default — so
136
- * astro-cms / local dev render byte-identically.
133
+ * the `/__cms/api/assets/serve` default; astro-cms passes the one under
134
+ * the route it mounts the CMS at. When absent, `MediaPage`/`ImagePicker`
135
+ * pass `undefined` and `AssetCard`/`AssetDetailSidebar` keep their
136
+ * literal default.
137
137
  */
138
138
  assetsBasePath?: string;
139
+ /** Draft-image render base; render URLs must never replace canonical saved asset refs. */
140
+ draftAssetsBasePath?: string;
139
141
  /**
140
142
  * Base the STORED asset reference is built on (`buildAssetRef(folder,
141
143
  * filename)`) — the sibling of `assetsBasePath`, and deliberately a
@@ -332,3 +334,13 @@ export function getUIConfig(): UIConfig {
332
334
 
333
335
  return config;
334
336
  }
337
+
338
+ /**
339
+ * The route the CMS is mounted at, without a trailing slash. The integration
340
+ * serves the editor's own endpoints — styles, content wrapper, component
341
+ * render, registry — under `<route>/api`, so a site that moves the CMS off
342
+ * `/__cms` moves them with it.
343
+ */
344
+ export function getCmsRoute(): string {
345
+ return (getUIConfig().basename ?? '/__cms').replace(/\/+$/, '');
346
+ }