@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
package/src/ui-config.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* oxlint-disable no-underscore-dangle -- __UI_CONFIG__ is the existing browser-global compatibility contract read by embedded hosts. */
|
|
2
2
|
import type { ContentAPIClient, EditorDataBindings } from '@conloca/content-api-client';
|
|
3
3
|
import type { QueryClientConfig } from '@tanstack/react-query';
|
|
4
|
+
import type { MediaLoadInput, PreviewOpenResult } from './frame/protocol.js';
|
|
4
5
|
import type { MediaBridge } from './media/types.js';
|
|
5
6
|
|
|
6
7
|
export interface TemplateConfig {
|
|
@@ -136,6 +137,8 @@ export interface UIConfig {
|
|
|
136
137
|
* literal default.
|
|
137
138
|
*/
|
|
138
139
|
assetsBasePath?: string;
|
|
140
|
+
/** Draft-image render base; render URLs must never replace canonical saved asset refs. */
|
|
141
|
+
draftAssetsBasePath?: string;
|
|
139
142
|
/**
|
|
140
143
|
* Base the STORED asset reference is built on (`buildAssetRef(folder,
|
|
141
144
|
* filename)`) — the sibling of `assetsBasePath`, and deliberately a
|
|
@@ -159,7 +162,20 @@ export interface UIConfig {
|
|
|
159
162
|
* about that site — not a failure of the call. The two must
|
|
160
163
|
* stay distinguishable: one is the site's setup, the other is a fault.
|
|
161
164
|
*/
|
|
162
|
-
openPreview?: (input: { path: string }) => Promise<OpenPreviewResult>;
|
|
165
|
+
openPreview?: (input: { path: string }) => Promise<OpenPreviewResult | PreviewOpenResult>;
|
|
166
|
+
/**
|
|
167
|
+
* Who opens the preview tab. Default `'editor'`. With `'parent'` the parent
|
|
168
|
+
* frame opens the tab during the click, so the editor opens none and only
|
|
169
|
+
* asks through `openPreview`.
|
|
170
|
+
*/
|
|
171
|
+
previewTab?: 'editor' | 'parent';
|
|
172
|
+
/**
|
|
173
|
+
* Opens the published page at `path` from outside the editor frame, so the
|
|
174
|
+
* tab is not born inside a sandboxed frame. Without it the editor keeps
|
|
175
|
+
* `window.open`. Whoever opens the tab explains a blocked popup, so the
|
|
176
|
+
* editor only waits for the request to settle.
|
|
177
|
+
*/
|
|
178
|
+
openSiteUrl?: (input: { path: string }) => Promise<void>;
|
|
163
179
|
/**
|
|
164
180
|
* Whether the site actually serves draft preview.
|
|
165
181
|
* `'unknown'` (the default) means not established yet and the editor leaves
|
|
@@ -179,6 +195,43 @@ export interface UIConfig {
|
|
|
179
195
|
* is refused with {@link EditorWriteRefusal.reason}.
|
|
180
196
|
*/
|
|
181
197
|
readOnly?: EditorWriteRefusal;
|
|
198
|
+
/**
|
|
199
|
+
* Path the MDX sandbox frame loads from. An editor page that ships its own
|
|
200
|
+
* static copy of the frame sets it; default `SANDBOX_FRAME_PATH`.
|
|
201
|
+
*/
|
|
202
|
+
sandboxFramePath?: string;
|
|
203
|
+
/**
|
|
204
|
+
* The site's `editorCSS` text, appended after the MDX canvas styles so it
|
|
205
|
+
* wins. An editor page that loads it at run time sets it; otherwise the
|
|
206
|
+
* build's copy applies.
|
|
207
|
+
*/
|
|
208
|
+
editorCss?: string;
|
|
209
|
+
/**
|
|
210
|
+
* Loads the bytes of a media file. When set, media surfaces never hand media
|
|
211
|
+
* URLs to `<img>`; they show object URLs of the loaded bytes.
|
|
212
|
+
*/
|
|
213
|
+
loadMedia?: (input: MediaLoadInput) => Promise<Blob>;
|
|
214
|
+
/**
|
|
215
|
+
* Set by a parent frame: the editor routes in memory and reports each route
|
|
216
|
+
* to it. It also marks the editor as running in a parent frame, where the
|
|
217
|
+
* dev-server endpoints do not exist.
|
|
218
|
+
*/
|
|
219
|
+
memoryRouter?: MemoryRouterConfig;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** How the editor routes when a parent frame owns the address bar. */
|
|
223
|
+
export interface MemoryRouterConfig {
|
|
224
|
+
/** The editor route to open first, `pathname + search`. */
|
|
225
|
+
initialPath: string;
|
|
226
|
+
/** Called with each route the editor commits, `pathname + search`. */
|
|
227
|
+
onNavigate(path: string, replace: boolean): void;
|
|
228
|
+
/** Listens for routes the parent asks for; returns the function that stops listening. */
|
|
229
|
+
subscribe(navigate: (path: string) => void): () => void;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Whether the editor runs inside a parent frame (see `UIConfig.memoryRouter`). */
|
|
233
|
+
export function inEditorFrame(config: UIConfig = getUIConfig()): boolean {
|
|
234
|
+
return config.memoryRouter !== undefined;
|
|
182
235
|
}
|
|
183
236
|
|
|
184
237
|
const defaultConfig: UIConfig = {
|
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,40 +0,0 @@
|
|
|
1
|
-
import type { HostWrappers } from './site-styles.js';
|
|
2
|
-
/**
|
|
3
|
-
* Registered style-discovery results, written by a host app that embeds the
|
|
4
|
-
* editor and read by the MDX editor.
|
|
5
|
-
*
|
|
6
|
-
* The astro-cms dev server discovers the same facts at runtime
|
|
7
|
-
* (`/api/styles`, `/api/content-wrapper`, the computed-style probe); those
|
|
8
|
-
* mechanisms need a Vite graph and a same-origin page, which an editor served
|
|
9
|
-
* from another origin does not have. A host app that learns the same facts
|
|
10
|
-
* some other way writes them into this registry — the editor's consumption
|
|
11
|
-
* chain then treats them as the same tier, one layer below live discovery.
|
|
12
|
-
*
|
|
13
|
-
* astro-cms never writes this, so the chain simply skips it there.
|
|
14
|
-
*/
|
|
15
|
-
export interface HostDiscovery {
|
|
16
|
-
/** The discovery route's collected CSS. */
|
|
17
|
-
routeCss?: string;
|
|
18
|
-
/** The discovery route's content-wrapper shape, same contract as the endpoint's. */
|
|
19
|
-
wrappers?: HostWrappers;
|
|
20
|
-
}
|
|
21
|
-
interface DiscoveryState {
|
|
22
|
-
value: HostDiscovery;
|
|
23
|
-
subscribers: Set<(value: HostDiscovery) => void>;
|
|
24
|
-
}
|
|
25
|
-
declare global {
|
|
26
|
-
interface Window {
|
|
27
|
-
__HOST_DISCOVERY_STATE__?: DiscoveryState;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Replace the registered discovery wholesale. Wholesale on purpose: the
|
|
32
|
-
* registry is process-global, so a switch to another site that carried only
|
|
33
|
-
* SOME fields forward would leak the previous site's wrapper or CSS into the new
|
|
34
|
-
* one — the same clear-semantics `setSiteStyles([])` has.
|
|
35
|
-
*/
|
|
36
|
-
export declare function setHostDiscovery(value: HostDiscovery): void;
|
|
37
|
-
export declare function getHostDiscovery(): HostDiscovery;
|
|
38
|
-
export declare function useHostDiscovery(): HostDiscovery;
|
|
39
|
-
export {};
|
|
40
|
-
//# sourceMappingURL=host-discovery.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"host-discovery.d.ts","sourceRoot":"","sources":["../../src/host-discovery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAED,UAAU,cAAc;IACtB,KAAK,EAAE,aAAa,CAAC;IACrB,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC,CAAC;CAClD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,wBAAwB,CAAC,EAAE,cAAc,CAAC;KAC3C;CACF;AAYD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAM3D;AAED,wBAAgB,gBAAgB,IAAI,aAAa,CAEhD;AAED,wBAAgB,gBAAgB,IAAI,aAAa,CAahD"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
const getState = () => {
|
|
3
|
-
if (typeof window !== 'undefined') {
|
|
4
|
-
if (!window.__HOST_DISCOVERY_STATE__) {
|
|
5
|
-
window.__HOST_DISCOVERY_STATE__ = { value: {}, subscribers: new Set() };
|
|
6
|
-
}
|
|
7
|
-
return window.__HOST_DISCOVERY_STATE__;
|
|
8
|
-
}
|
|
9
|
-
return { value: {}, subscribers: new Set() };
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Replace the registered discovery wholesale. Wholesale on purpose: the
|
|
13
|
-
* registry is process-global, so a switch to another site that carried only
|
|
14
|
-
* SOME fields forward would leak the previous site's wrapper or CSS into the new
|
|
15
|
-
* one — the same clear-semantics `setSiteStyles([])` has.
|
|
16
|
-
*/
|
|
17
|
-
export function setHostDiscovery(value) {
|
|
18
|
-
const state = getState();
|
|
19
|
-
state.value = value;
|
|
20
|
-
state.subscribers.forEach((fn) => {
|
|
21
|
-
fn(value);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
export function getHostDiscovery() {
|
|
25
|
-
return getState().value;
|
|
26
|
-
}
|
|
27
|
-
export function useHostDiscovery() {
|
|
28
|
-
const [value, setValue] = useState(() => getState().value);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
const state = getState();
|
|
31
|
-
setValue((current) => (state.value === current ? current : state.value));
|
|
32
|
-
state.subscribers.add(setValue);
|
|
33
|
-
return () => {
|
|
34
|
-
state.subscribers.delete(setValue);
|
|
35
|
-
};
|
|
36
|
-
}, []);
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=host-discovery.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"host-discovery.js","sourceRoot":"","sources":["../../src/host-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAmC5C,MAAM,QAAQ,GAAG,GAAmB,EAAE;IACpC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,wBAAwB,EAAE,CAAC;YACrC,MAAM,CAAC,wBAAwB,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;QAC1E,CAAC;QACD,OAAO,MAAM,CAAC,wBAAwB,CAAC;IACzC,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;AAC/C,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAoB;IACnD,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IACzB,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QAC/B,EAAE,CAAC,KAAK,CAAC,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,OAAO,QAAQ,EAAE,CAAC,KAAK,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC;IAE3D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;QACzB,QAAQ,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACzE,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAChC,OAAO,GAAG,EAAE;YACV,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -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"}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
function definition(schema) {
|
|
2
|
-
return schema._def ?? schema._zod?.def;
|
|
3
|
-
}
|
|
4
|
-
function getZodTypeName(def) {
|
|
5
|
-
if (typeof def.typeName === 'string')
|
|
6
|
-
return def.typeName;
|
|
7
|
-
return typeof def.type === 'string' ? def.type : '';
|
|
8
|
-
}
|
|
9
|
-
function readStringCheck(def) {
|
|
10
|
-
const format = def.check === 'string_format' ? def.format : def.kind;
|
|
11
|
-
if (format === 'url' || format === 'email')
|
|
12
|
-
return { format };
|
|
13
|
-
if (def.check === 'max_length' && typeof def.maximum === 'number')
|
|
14
|
-
return { maxLength: def.maximum };
|
|
15
|
-
if (def.kind === 'max' && typeof def.value === 'number')
|
|
16
|
-
return { maxLength: def.value };
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Introspects the subset of Zod 3/4 internals required to render form hints.
|
|
21
|
-
* The single assertion is the compatibility boundary; every field read after
|
|
22
|
-
* it is represented explicitly by ZodCompat/ZodDef.
|
|
23
|
-
*/
|
|
24
|
-
export function getZodFieldInfo(field) {
|
|
25
|
-
// SAFETY: both supported Zod generations expose either _def or _zod.def;
|
|
26
|
-
// ZodCompat contains only optional fields read by this compatibility adapter.
|
|
27
|
-
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- documented third-party compatibility boundary
|
|
28
|
-
let current = field;
|
|
29
|
-
let isOptional = false;
|
|
30
|
-
let isNullable = false;
|
|
31
|
-
let helpText;
|
|
32
|
-
while (true) {
|
|
33
|
-
helpText ??= current.description;
|
|
34
|
-
const def = definition(current);
|
|
35
|
-
if (!def)
|
|
36
|
-
break;
|
|
37
|
-
const typeName = getZodTypeName(def);
|
|
38
|
-
if (typeName === 'ZodOptional' || typeName === 'optional') {
|
|
39
|
-
isOptional = true;
|
|
40
|
-
}
|
|
41
|
-
else if (typeName === 'ZodNullable' || typeName === 'nullable') {
|
|
42
|
-
isNullable = true;
|
|
43
|
-
}
|
|
44
|
-
else if (typeName !== 'ZodDefault' && typeName !== 'default') {
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
if (!def.innerType)
|
|
48
|
-
break;
|
|
49
|
-
current = def.innerType;
|
|
50
|
-
}
|
|
51
|
-
const def = definition(current);
|
|
52
|
-
const typeName = def ? getZodTypeName(def) : '';
|
|
53
|
-
if (typeName === 'ZodEnum' || typeName === 'enum') {
|
|
54
|
-
const enumValues = Array.isArray(def?.values)
|
|
55
|
-
? def.values.filter((value) => typeof value === 'string')
|
|
56
|
-
: (current.options ?? []);
|
|
57
|
-
return { type: 'enum', enumValues, description: helpText, isOptional, isNullable };
|
|
58
|
-
}
|
|
59
|
-
if (typeName === 'ZodNativeEnum' || typeName === 'nativeEnum') {
|
|
60
|
-
const values = def?.values;
|
|
61
|
-
const enumValues = values && !Array.isArray(values)
|
|
62
|
-
? Object.values(values).filter((value) => typeof value === 'string')
|
|
63
|
-
: [];
|
|
64
|
-
return { type: 'enum', enumValues, description: helpText, isOptional, isNullable };
|
|
65
|
-
}
|
|
66
|
-
if (typeName === 'ZodDate' || typeName === 'date') {
|
|
67
|
-
return { type: 'date', format: 'date-time', description: helpText, isOptional, isNullable };
|
|
68
|
-
}
|
|
69
|
-
if (typeName === 'ZodBoolean' || typeName === 'boolean') {
|
|
70
|
-
return { type: 'boolean', description: helpText, isOptional, isNullable };
|
|
71
|
-
}
|
|
72
|
-
if (typeName === 'ZodNumber' || typeName === 'number') {
|
|
73
|
-
return { type: 'number', description: helpText, isOptional, isNullable };
|
|
74
|
-
}
|
|
75
|
-
if (typeName === 'ZodArray' || typeName === 'array') {
|
|
76
|
-
return { type: 'array', description: helpText, isOptional, isNullable };
|
|
77
|
-
}
|
|
78
|
-
if (typeName === 'ZodString' || typeName === 'string') {
|
|
79
|
-
const checks = def?.checks ?? [];
|
|
80
|
-
const constraints = [def, ...checks.map((check) => check._zod?.def ?? check)]
|
|
81
|
-
.filter((check) => check !== undefined)
|
|
82
|
-
.map(readStringCheck);
|
|
83
|
-
const format = constraints.find((constraint) => constraint.format)?.format;
|
|
84
|
-
const maxLength = constraints.find((constraint) => constraint.maxLength !== undefined)?.maxLength;
|
|
85
|
-
return { type: 'string', format, description: helpText, isOptional, isNullable, maxLength };
|
|
86
|
-
}
|
|
87
|
-
return { type: 'string', description: helpText, isOptional, isNullable };
|
|
88
|
-
}
|
|
89
|
-
export function getZodShape(schema) {
|
|
90
|
-
const result = {};
|
|
91
|
-
for (const [key, field] of Object.entries(schema.shape))
|
|
92
|
-
result[key] = getZodFieldInfo(field);
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=zodIntrospect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"zodIntrospect.js","sourceRoot":"","sources":["../../../src/utils/zodIntrospect.ts"],"names":[],"mappings":"AAuCA,SAAS,UAAU,CAAC,MAAiB;IACnC,OAAO,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC;AACzC,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IACjC,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC,QAAQ,CAAC;IAC1D,OAAO,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;AACtD,CAAC;AAED,SAAS,eAAe,CAAC,GAAW;IAClC,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;IACrE,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,OAAO;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAC9D,IAAI,GAAG,CAAC,KAAK,KAAK,YAAY,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ;QAAE,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;IACrG,IAAI,GAAG,CAAC,IAAI,KAAK,KAAK,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;IACzF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C;IAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,MAAM,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAC9F,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/src/host-discovery.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import type { HostWrappers } from './site-styles.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Registered style-discovery results, written by a host app that embeds the
|
|
6
|
-
* editor and read by the MDX editor.
|
|
7
|
-
*
|
|
8
|
-
* The astro-cms dev server discovers the same facts at runtime
|
|
9
|
-
* (`/api/styles`, `/api/content-wrapper`, the computed-style probe); those
|
|
10
|
-
* mechanisms need a Vite graph and a same-origin page, which an editor served
|
|
11
|
-
* from another origin does not have. A host app that learns the same facts
|
|
12
|
-
* some other way writes them into this registry — the editor's consumption
|
|
13
|
-
* chain then treats them as the same tier, one layer below live discovery.
|
|
14
|
-
*
|
|
15
|
-
* astro-cms never writes this, so the chain simply skips it there.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
export interface HostDiscovery {
|
|
19
|
-
/** The discovery route's collected CSS. */
|
|
20
|
-
routeCss?: string;
|
|
21
|
-
/** The discovery route's content-wrapper shape, same contract as the endpoint's. */
|
|
22
|
-
wrappers?: HostWrappers;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface DiscoveryState {
|
|
26
|
-
value: HostDiscovery;
|
|
27
|
-
subscribers: Set<(value: HostDiscovery) => void>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
declare global {
|
|
31
|
-
interface Window {
|
|
32
|
-
__HOST_DISCOVERY_STATE__?: DiscoveryState;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const getState = (): DiscoveryState => {
|
|
37
|
-
if (typeof window !== 'undefined') {
|
|
38
|
-
if (!window.__HOST_DISCOVERY_STATE__) {
|
|
39
|
-
window.__HOST_DISCOVERY_STATE__ = { value: {}, subscribers: new Set() };
|
|
40
|
-
}
|
|
41
|
-
return window.__HOST_DISCOVERY_STATE__;
|
|
42
|
-
}
|
|
43
|
-
return { value: {}, subscribers: new Set() };
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Replace the registered discovery wholesale. Wholesale on purpose: the
|
|
48
|
-
* registry is process-global, so a switch to another site that carried only
|
|
49
|
-
* SOME fields forward would leak the previous site's wrapper or CSS into the new
|
|
50
|
-
* one — the same clear-semantics `setSiteStyles([])` has.
|
|
51
|
-
*/
|
|
52
|
-
export function setHostDiscovery(value: HostDiscovery): void {
|
|
53
|
-
const state = getState();
|
|
54
|
-
state.value = value;
|
|
55
|
-
state.subscribers.forEach((fn) => {
|
|
56
|
-
fn(value);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function getHostDiscovery(): HostDiscovery {
|
|
61
|
-
return getState().value;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function useHostDiscovery(): HostDiscovery {
|
|
65
|
-
const [value, setValue] = useState(() => getState().value);
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
const state = getState();
|
|
69
|
-
setValue((current) => (state.value === current ? current : state.value));
|
|
70
|
-
state.subscribers.add(setValue);
|
|
71
|
-
return () => {
|
|
72
|
-
state.subscribers.delete(setValue);
|
|
73
|
-
};
|
|
74
|
-
}, []);
|
|
75
|
-
|
|
76
|
-
return value;
|
|
77
|
-
}
|