@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
|
@@ -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;
|
package/src/data-schemas.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import type {
|
|
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
|
|
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,
|
|
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
|
+
}
|
package/src/host-style-probe.ts
CHANGED
|
@@ -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.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
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
[class*="MenuBar"] button[
|
|
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
|
|
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
|
|
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
|
|
66
|
+
export interface PageSchemaDescriptor<S extends HostSchema = HostSchema> {
|
|
66
67
|
/** Human-readable label shown in the dialog header. */
|
|
67
68
|
label?: string;
|
|
68
|
-
/**
|
|
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 `
|
|
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
|
|
89
|
-
descriptor
|
|
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
|
|
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 =
|
|
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
|
|
118
|
-
*
|
|
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
|
|
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 && !('
|
|
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';
|
package/src/ui-config.ts
CHANGED
|
@@ -136,6 +136,8 @@ export interface UIConfig {
|
|
|
136
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
|
package/src/utils/asset-url.ts
CHANGED
|
@@ -11,6 +11,14 @@ export function buildAssetPath(folder: string | undefined, filename: string): st
|
|
|
11
11
|
return assetPath(folder, filename);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/** Join asset paths without moving an existing query or fragment into the resource path. */
|
|
15
|
+
export function appendAssetUrlPath(base: string, path: string): string {
|
|
16
|
+
const suffixIndex = base.search(/[?#]/);
|
|
17
|
+
const pathname = suffixIndex === -1 ? base : base.slice(0, suffixIndex);
|
|
18
|
+
const suffix = suffixIndex === -1 ? '' : base.slice(suffixIndex);
|
|
19
|
+
return `${pathname.replace(/\/$/, '')}/${path}${suffix}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
/** Build a full asset serve URL, correctly handling subfolder paths. */
|
|
15
23
|
export function buildAssetServeUrl(basePath: string, folder: string | undefined, filename: string): string {
|
|
16
24
|
return `${basePath}/${assetPath(folder, filename)}`;
|
|
@@ -102,7 +102,7 @@ export function extractPageMetadata(
|
|
|
102
102
|
const customMeta: Record<string, unknown> = {};
|
|
103
103
|
for (const [key, value] of Object.entries(localized.meta)) {
|
|
104
104
|
if (!coreKeys.has(key)) {
|
|
105
|
-
customMeta
|
|
105
|
+
setDataKey(customMeta, key, value);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -144,7 +144,7 @@ export function buildMetadataUpdate(metadata: PageMetadata): MetadataUpdatePaylo
|
|
|
144
144
|
const cleared = (value: unknown) => (value === undefined || value === '' ? null : value);
|
|
145
145
|
const custom: Record<string, unknown> = {};
|
|
146
146
|
for (const [key, value] of Object.entries(metadata.customMeta || {})) {
|
|
147
|
-
custom
|
|
147
|
+
setDataKey(custom, key, cleared(value));
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
return {
|
|
@@ -200,8 +200,10 @@ export function flattenForHints(
|
|
|
200
200
|
const segments = dotted.split('.');
|
|
201
201
|
let cursor: unknown = value;
|
|
202
202
|
for (const seg of segments) {
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
// Own properties only: an inherited one is not the author's data.
|
|
204
|
+
const own = cursor && typeof cursor === 'object' ? Object.getOwnPropertyDescriptor(cursor, seg) : undefined;
|
|
205
|
+
if (own) {
|
|
206
|
+
cursor = own.value;
|
|
205
207
|
} else {
|
|
206
208
|
cursor = undefined;
|
|
207
209
|
break;
|
|
@@ -217,7 +219,7 @@ export function flattenForHints(
|
|
|
217
219
|
if (remainder === undefined) {
|
|
218
220
|
delete out[segments[0]];
|
|
219
221
|
} else {
|
|
220
|
-
out
|
|
222
|
+
setDataKey(out, segments[0], remainder);
|
|
221
223
|
}
|
|
222
224
|
}
|
|
223
225
|
}
|
|
@@ -242,13 +244,25 @@ function pruneLeaf(branch: unknown, path: string[]): unknown {
|
|
|
242
244
|
if (pruned === undefined) {
|
|
243
245
|
delete copy[head];
|
|
244
246
|
} else {
|
|
245
|
-
copy
|
|
247
|
+
setDataKey(copy, head, pruned);
|
|
246
248
|
}
|
|
247
249
|
}
|
|
248
250
|
|
|
249
251
|
return Object.keys(copy).length > 0 ? copy : undefined;
|
|
250
252
|
}
|
|
251
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Store a frontmatter key as data. Plain assignment of `__proto__` would run the legacy prototype setter,
|
|
256
|
+
* swapping the target's prototype and dropping the author's value (same rule as content-api's applyNullClearPatch).
|
|
257
|
+
*/
|
|
258
|
+
function setDataKey(target: Record<string, unknown>, key: string, value: unknown): void {
|
|
259
|
+
if (key === '__proto__') {
|
|
260
|
+
Object.defineProperty(target, key, { value, enumerable: true, configurable: true, writable: true });
|
|
261
|
+
} else {
|
|
262
|
+
target[key] = value;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
252
266
|
/**
|
|
253
267
|
* Inverse of `flattenForHints` — materialize dotted keys back into nested
|
|
254
268
|
* objects so YAML frontmatter renders as `sidebar: { label, order }`
|
|
@@ -264,22 +278,25 @@ export function unflattenFromHints(value: Record<string, unknown>): Record<strin
|
|
|
264
278
|
// remainder) has to be in place before dotted leaves merge into it,
|
|
265
279
|
// otherwise assigning it later would overwrite them.
|
|
266
280
|
for (const [key, val] of entries) {
|
|
267
|
-
if (!key.includes('.')) out
|
|
281
|
+
if (!key.includes('.')) setDataKey(out, key, val);
|
|
268
282
|
}
|
|
269
283
|
|
|
270
284
|
for (const [key, val] of entries) {
|
|
271
285
|
if (!key.includes('.')) continue;
|
|
272
286
|
const segments = key.split('.');
|
|
287
|
+
// Walk own properties only: an inherited one (`__proto__` resolves to
|
|
288
|
+
// Object.prototype) would make the leaf write below pollute every object.
|
|
289
|
+
// Names like `prototype` stay ordinary nested keys, so they still round-trip.
|
|
273
290
|
let cursor = out;
|
|
274
291
|
for (let i = 0; i < segments.length - 1; i++) {
|
|
275
292
|
const seg = segments[i];
|
|
276
|
-
const existing = cursor
|
|
293
|
+
const existing = Object.getOwnPropertyDescriptor(cursor, seg)?.value;
|
|
277
294
|
if (!existing || typeof existing !== 'object') {
|
|
278
|
-
cursor
|
|
295
|
+
setDataKey(cursor, seg, {});
|
|
279
296
|
}
|
|
280
297
|
cursor = cursor[seg] as Record<string, unknown>;
|
|
281
298
|
}
|
|
282
|
-
cursor
|
|
299
|
+
setDataKey(cursor, segments[segments.length - 1], val);
|
|
283
300
|
}
|
|
284
301
|
return out;
|
|
285
302
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { type HostSchema, type HostSchemaMetadata, resolveHostJsonSchema, rootObjectOf } from '../host-schema.js';
|
|
2
|
+
|
|
3
|
+
export interface FieldInfo {
|
|
4
|
+
type: 'string' | 'number' | 'boolean' | 'date' | 'array' | 'enum';
|
|
5
|
+
format?: 'url' | 'email' | 'date-time';
|
|
6
|
+
description?: string;
|
|
7
|
+
isOptional: boolean;
|
|
8
|
+
isNullable: boolean;
|
|
9
|
+
/** For enum types, the list of allowed values */
|
|
10
|
+
enumValues?: string[];
|
|
11
|
+
/** For string types, the max length constraint if defined */
|
|
12
|
+
maxLength?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A resolved form definition: one {@link FieldInfo} per field, in render order. */
|
|
16
|
+
export type FormFields = Record<string, FieldInfo>;
|
|
17
|
+
|
|
18
|
+
type JsonSchema = HostSchemaMetadata['schema'];
|
|
19
|
+
|
|
20
|
+
/** The control-relevant part of a field schema, after `$ref`s and `| null` are unwrapped. */
|
|
21
|
+
function describeField(
|
|
22
|
+
metadata: HostSchemaMetadata,
|
|
23
|
+
node: JsonSchema,
|
|
24
|
+
): Omit<FieldInfo, 'isOptional' | 'isNullable'> & {
|
|
25
|
+
isNullable: boolean;
|
|
26
|
+
} {
|
|
27
|
+
const resolved = resolveHostJsonSchema(metadata, node);
|
|
28
|
+
const description = node.description ?? resolved?.description;
|
|
29
|
+
const base = description === undefined ? {} : { description };
|
|
30
|
+
if (!resolved) return { type: 'string', ...base, isNullable: false };
|
|
31
|
+
|
|
32
|
+
if ('oneOf' in resolved) {
|
|
33
|
+
const members = resolved.oneOf.map((member) => resolveHostJsonSchema(metadata, member));
|
|
34
|
+
const isNullable = members.some((member) => member !== null && 'type' in member && member.type === 'null');
|
|
35
|
+
const rest = members.filter((member) => !(member !== null && 'type' in member && member.type === 'null'));
|
|
36
|
+
const constants = rest.flatMap((member) =>
|
|
37
|
+
member !== null && 'const' in member && typeof member.const === 'string' ? [member.const] : [],
|
|
38
|
+
);
|
|
39
|
+
if (rest.length > 0 && constants.length === rest.length) {
|
|
40
|
+
return { type: 'enum', enumValues: constants, ...base, isNullable };
|
|
41
|
+
}
|
|
42
|
+
const [only] = rest;
|
|
43
|
+
if (rest.length === 1 && only) return { ...describeField(metadata, only), ...base, isNullable };
|
|
44
|
+
// A union of unrelated shapes (`string | boolean`) has no single control;
|
|
45
|
+
// the text input is the same fallback an unknown field always got.
|
|
46
|
+
return { type: 'string', ...base, isNullable };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if ('const' in resolved) {
|
|
50
|
+
return typeof resolved.const === 'string'
|
|
51
|
+
? { type: 'enum', enumValues: [resolved.const], ...base, isNullable: false }
|
|
52
|
+
: { type: 'string', ...base, isNullable: false };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!('type' in resolved)) return { type: 'string', ...base, isNullable: false };
|
|
56
|
+
switch (resolved.type) {
|
|
57
|
+
case 'string': {
|
|
58
|
+
if (resolved.format === 'date-time') return { type: 'date', format: 'date-time', ...base, isNullable: false };
|
|
59
|
+
// A format and a length limit are independent constraints; the form keeps both.
|
|
60
|
+
const limit = resolved.maxLength === undefined ? {} : { maxLength: resolved.maxLength };
|
|
61
|
+
if (resolved.format === 'url' || resolved.format === 'uri') {
|
|
62
|
+
return { type: 'string', format: 'url', ...base, ...limit, isNullable: false };
|
|
63
|
+
}
|
|
64
|
+
if (resolved.format === 'email') return { type: 'string', format: 'email', ...base, ...limit, isNullable: false };
|
|
65
|
+
return { type: 'string', ...base, ...limit, isNullable: false };
|
|
66
|
+
}
|
|
67
|
+
case 'integer':
|
|
68
|
+
case 'number':
|
|
69
|
+
return { type: 'number', ...base, isNullable: false };
|
|
70
|
+
case 'boolean':
|
|
71
|
+
return { type: 'boolean', ...base, isNullable: false };
|
|
72
|
+
case 'array':
|
|
73
|
+
return { type: 'array', ...base, isNullable: false };
|
|
74
|
+
case 'null':
|
|
75
|
+
return { type: 'string', ...base, isNullable: true };
|
|
76
|
+
default:
|
|
77
|
+
return { type: 'string', ...base, isNullable: false };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Metadata is generated once and never mutated, so the derived form is too:
|
|
82
|
+
// resolving it once keeps every render handing out the same record.
|
|
83
|
+
const fieldsByMetadata = new WeakMap<HostSchemaMetadata, FormFields>();
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The form generated JSON Schema metadata (`typia.json.schema<T>()`) renders
|
|
87
|
+
* as: one {@link FieldInfo} per top-level property, in declaration order,
|
|
88
|
+
* optional when the property is not `required`.
|
|
89
|
+
*/
|
|
90
|
+
export function fieldsOfMetadata(metadata: HostSchemaMetadata): FormFields {
|
|
91
|
+
const cached = fieldsByMetadata.get(metadata);
|
|
92
|
+
if (cached) return cached;
|
|
93
|
+
const root = rootObjectOf(metadata);
|
|
94
|
+
const required = new Set(root?.required ?? []);
|
|
95
|
+
const fields: FormFields = {};
|
|
96
|
+
for (const [name, node] of Object.entries(root?.properties ?? {})) {
|
|
97
|
+
fields[name] = { ...describeField(metadata, node), isOptional: !required.has(name) };
|
|
98
|
+
}
|
|
99
|
+
fieldsByMetadata.set(metadata, fields);
|
|
100
|
+
return fields;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The form a {@link HostSchema} renders as — its metadata's {@link fieldsOfMetadata}. */
|
|
104
|
+
export function fieldsOfHostSchema(schema: HostSchema): FormFields {
|
|
105
|
+
return fieldsOfMetadata(schema.metadata);
|
|
106
|
+
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { z } from 'zod';
|
|
2
|
-
export interface FieldInfo {
|
|
3
|
-
type: 'string' | 'number' | 'boolean' | 'date' | 'array' | 'enum';
|
|
4
|
-
format?: 'url' | 'email' | 'date-time';
|
|
5
|
-
/** Help text the schema gives the field, from .describe() or .meta({ description }). */
|
|
6
|
-
description?: string;
|
|
7
|
-
isOptional: boolean;
|
|
8
|
-
isNullable: boolean;
|
|
9
|
-
enumValues?: string[];
|
|
10
|
-
maxLength?: number;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Introspects the subset of Zod 3/4 internals required to render form hints.
|
|
14
|
-
* The single assertion is the compatibility boundary; every field read after
|
|
15
|
-
* it is represented explicitly by ZodCompat/ZodDef.
|
|
16
|
-
*/
|
|
17
|
-
export declare function getZodFieldInfo(field: z.ZodRawShape[string]): FieldInfo;
|
|
18
|
-
export declare function getZodShape(schema: z.ZodObject<z.ZodRawShape>): Record<string, FieldInfo>;
|
|
19
|
-
//# sourceMappingURL=zodIntrospect.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zodIntrospect.d.ts","sourceRoot":"","sources":["../../../src/utils/zodIntrospect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAClE,MAAM,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,WAAW,CAAC;IACvC,wFAAwF;IACxF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA6CD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAoEvE;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAIzF"}
|