@conloca/cms-spa 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/dist/spa/main.css +240 -4
- package/dist/ts/.build-inputs.json +178 -0
- package/dist/ts/App.d.ts +10 -2
- package/dist/ts/App.d.ts.map +1 -1
- package/dist/ts/App.js +20 -8
- package/dist/ts/App.js.map +1 -1
- package/dist/ts/CmsSpaApp.d.ts.map +1 -1
- package/dist/ts/CmsSpaApp.js +4 -1
- package/dist/ts/CmsSpaApp.js.map +1 -1
- package/dist/ts/components/CMSDashboard.d.ts.map +1 -1
- package/dist/ts/components/CMSDashboard.js +6 -2
- package/dist/ts/components/CMSDashboard.js.map +1 -1
- package/dist/ts/components/RouteErrorPage.d.ts +11 -0
- package/dist/ts/components/RouteErrorPage.d.ts.map +1 -0
- package/dist/ts/components/RouteErrorPage.js +44 -0
- package/dist/ts/components/RouteErrorPage.js.map +1 -0
- package/dist/ts/components/dashboard/RecentActivity.d.ts.map +1 -1
- package/dist/ts/components/dashboard/RecentActivity.js +2 -8
- package/dist/ts/components/dashboard/RecentActivity.js.map +1 -1
- package/dist/ts/components/dialogs/CreateDataDialog.js +2 -2
- package/dist/ts/components/dialogs/CreateDataDialog.js.map +1 -1
- package/dist/ts/components/dialogs/CreateFolderDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/CreateFolderDialog.js +2 -1
- package/dist/ts/components/dialogs/CreateFolderDialog.js.map +1 -1
- package/dist/ts/components/dialogs/CreatePageFlow.d.ts +13 -0
- package/dist/ts/components/dialogs/CreatePageFlow.d.ts.map +1 -0
- package/dist/ts/components/dialogs/CreatePageFlow.js +100 -0
- package/dist/ts/components/dialogs/CreatePageFlow.js.map +1 -0
- package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts +1 -1
- package/dist/ts/components/dialogs/DataPropertiesDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/DataPropertiesDialog.js +2 -2
- package/dist/ts/components/dialogs/DataPropertiesDialog.js.map +1 -1
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts +1 -1
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.js +2 -2
- package/dist/ts/components/dialogs/FragmentPropertiesDialog.js.map +1 -1
- package/dist/ts/components/dialogs/PageMetadataDialog.d.ts +2 -12
- package/dist/ts/components/dialogs/PageMetadataDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/PageMetadataDialog.js +3 -21
- package/dist/ts/components/dialogs/PageMetadataDialog.js.map +1 -1
- package/dist/ts/components/editor/CMSMDXEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/CMSMDXEditor.js +46 -55
- package/dist/ts/components/editor/CMSMDXEditor.js.map +1 -1
- package/dist/ts/components/editor/DrawerItemOverride.d.ts +2 -0
- package/dist/ts/components/editor/DrawerItemOverride.d.ts.map +1 -1
- package/dist/ts/components/editor/DrawerItemOverride.js +4 -3
- package/dist/ts/components/editor/DrawerItemOverride.js.map +1 -1
- package/dist/ts/components/editor/PageEditor.d.ts +6 -7
- package/dist/ts/components/editor/PageEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditor.js +124 -34
- package/dist/ts/components/editor/PageEditor.js.map +1 -1
- package/dist/ts/components/editor/PageEditorHeaderActions.js +1 -1
- package/dist/ts/components/editor/PageEditorHeaderActions.js.map +1 -1
- package/dist/ts/components/editor/PageEditorWrapper.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditorWrapper.js +48 -12
- package/dist/ts/components/editor/PageEditorWrapper.js.map +1 -1
- package/dist/ts/components/editor/draft-media-config.d.ts +22 -0
- package/dist/ts/components/editor/draft-media-config.d.ts.map +1 -0
- package/dist/ts/components/editor/draft-media-config.js +186 -0
- package/dist/ts/components/editor/draft-media-config.js.map +1 -0
- package/dist/ts/components/editor/preview-availability.d.ts +6 -5
- package/dist/ts/components/editor/preview-availability.d.ts.map +1 -1
- package/dist/ts/components/editor/preview-availability.js +6 -5
- package/dist/ts/components/editor/preview-availability.js.map +1 -1
- package/dist/ts/components/editors/DataEditor.d.ts +2 -2
- package/dist/ts/components/editors/DataEditor.d.ts.map +1 -1
- package/dist/ts/components/forms/HintForm.js +8 -5
- package/dist/ts/components/forms/HintForm.js.map +1 -1
- package/dist/ts/components/forms/SchemaForm.d.ts +17 -5
- package/dist/ts/components/forms/SchemaForm.d.ts.map +1 -1
- package/dist/ts/components/forms/SchemaForm.js +16 -9
- package/dist/ts/components/forms/SchemaForm.js.map +1 -1
- package/dist/ts/components/media/AssetCard.d.ts.map +1 -1
- package/dist/ts/components/media/AssetCard.js +3 -2
- package/dist/ts/components/media/AssetCard.js.map +1 -1
- package/dist/ts/components/media/AssetDetailSidebar.d.ts.map +1 -1
- package/dist/ts/components/media/AssetDetailSidebar.js +4 -2
- package/dist/ts/components/media/AssetDetailSidebar.js.map +1 -1
- package/dist/ts/components/media/FolderTreeSidebar.d.ts.map +1 -1
- package/dist/ts/components/media/FolderTreeSidebar.js +4 -1
- package/dist/ts/components/media/FolderTreeSidebar.js.map +1 -1
- package/dist/ts/components/pages/PageList.d.ts.map +1 -1
- package/dist/ts/components/pages/PageList.js +13 -99
- package/dist/ts/components/pages/PageList.js.map +1 -1
- package/dist/ts/components/sandbox/ContentSandbox.d.ts.map +1 -1
- package/dist/ts/components/sandbox/ContentSandbox.js +36 -5
- package/dist/ts/components/sandbox/ContentSandbox.js.map +1 -1
- package/dist/ts/content-form-fields.d.ts +41 -0
- package/dist/ts/content-form-fields.d.ts.map +1 -0
- package/dist/ts/content-form-fields.js +70 -0
- package/dist/ts/content-form-fields.js.map +1 -0
- package/dist/ts/content-wrapper.d.ts +65 -0
- package/dist/ts/content-wrapper.d.ts.map +1 -0
- package/dist/ts/content-wrapper.js +190 -0
- package/dist/ts/content-wrapper.js.map +1 -0
- package/dist/ts/data-schemas.d.ts +4 -3
- package/dist/ts/data-schemas.d.ts.map +1 -1
- package/dist/ts/data-schemas.js.map +1 -1
- package/dist/ts/frame/channel.d.ts +40 -0
- package/dist/ts/frame/channel.d.ts.map +1 -0
- package/dist/ts/frame/channel.js +233 -0
- package/dist/ts/frame/channel.js.map +1 -0
- package/dist/ts/frame/editor-frame.d.ts +23 -0
- package/dist/ts/frame/editor-frame.d.ts.map +1 -0
- package/dist/ts/frame/editor-frame.js +154 -0
- package/dist/ts/frame/editor-frame.js.map +1 -0
- package/dist/ts/frame/media-cache.d.ts +26 -0
- package/dist/ts/frame/media-cache.d.ts.map +1 -0
- package/dist/ts/frame/media-cache.js +123 -0
- package/dist/ts/frame/media-cache.js.map +1 -0
- package/dist/ts/frame/memory-router.d.ts +10 -0
- package/dist/ts/frame/memory-router.d.ts.map +1 -0
- package/dist/ts/frame/memory-router.js +39 -0
- package/dist/ts/frame/memory-router.js.map +1 -0
- package/dist/ts/frame/parent-hello.d.ts +11 -0
- package/dist/ts/frame/parent-hello.d.ts.map +1 -0
- package/dist/ts/frame/parent-hello.js +53 -0
- package/dist/ts/frame/parent-hello.js.map +1 -0
- package/dist/ts/frame/protocol.d.ts +201 -0
- package/dist/ts/frame/protocol.d.ts.map +1 -0
- package/dist/ts/frame/protocol.js +195 -0
- package/dist/ts/frame/protocol.js.map +1 -0
- package/dist/ts/frame/rpc-content-client.d.ts +10 -0
- package/dist/ts/frame/rpc-content-client.d.ts.map +1 -0
- package/dist/ts/frame/rpc-content-client.js +51 -0
- package/dist/ts/frame/rpc-content-client.js.map +1 -0
- package/dist/ts/frame/save-shortcut.d.ts +8 -0
- package/dist/ts/frame/save-shortcut.d.ts.map +1 -0
- package/dist/ts/frame/save-shortcut.js +26 -0
- package/dist/ts/frame/save-shortcut.js.map +1 -0
- package/dist/ts/host-schema.d.ts +73 -0
- package/dist/ts/host-schema.d.ts.map +1 -0
- package/dist/ts/host-schema.js +66 -0
- package/dist/ts/host-schema.js.map +1 -0
- package/dist/ts/host-style-probe.d.ts +32 -37
- package/dist/ts/host-style-probe.d.ts.map +1 -1
- package/dist/ts/host-style-probe.js +102 -68
- package/dist/ts/host-style-probe.js.map +1 -1
- package/dist/ts/index.d.ts +4 -2
- package/dist/ts/index.d.ts.map +1 -1
- package/dist/ts/index.js +6 -2
- package/dist/ts/index.js.map +1 -1
- package/dist/ts/main-spa.d.ts.map +1 -1
- package/dist/ts/main-spa.js +2 -1
- package/dist/ts/main-spa.js.map +1 -1
- package/dist/ts/page-schema-define.d.ts +14 -12
- package/dist/ts/page-schema-define.d.ts.map +1 -1
- package/dist/ts/page-schema-define.js +8 -5
- package/dist/ts/page-schema-define.js.map +1 -1
- package/dist/ts/prose-surface-css.d.ts +3 -5
- package/dist/ts/prose-surface-css.d.ts.map +1 -1
- package/dist/ts/prose-surface-css.js +3 -5
- package/dist/ts/prose-surface-css.js.map +1 -1
- package/dist/ts/site-styles.d.ts +4 -21
- package/dist/ts/site-styles.d.ts.map +1 -1
- package/dist/ts/site-styles.js.map +1 -1
- package/dist/ts/ui-config.d.ts +52 -1
- package/dist/ts/ui-config.d.ts.map +1 -1
- package/dist/ts/ui-config.js +4 -0
- package/dist/ts/ui-config.js.map +1 -1
- package/dist/ts/utils/asset-url.d.ts +2 -0
- package/dist/ts/utils/asset-url.d.ts.map +1 -1
- package/dist/ts/utils/asset-url.js +7 -0
- package/dist/ts/utils/asset-url.js.map +1 -1
- package/dist/ts/utils/pageMetadata.d.ts.map +1 -1
- package/dist/ts/utils/pageMetadata.js +27 -10
- package/dist/ts/utils/pageMetadata.js.map +1 -1
- package/dist/ts/utils/schema-fields.d.ts +23 -0
- package/dist/ts/utils/schema-fields.d.ts.map +1 -0
- package/dist/ts/utils/schema-fields.js +82 -0
- package/dist/ts/utils/schema-fields.js.map +1 -0
- package/package.json +56 -18
- package/src/App.tsx +35 -14
- package/src/CmsSpaApp.tsx +5 -1
- package/src/components/CMSDashboard.tsx +12 -4
- package/src/components/RouteErrorPage.tsx +75 -0
- package/src/components/dashboard/RecentActivity.tsx +3 -7
- package/src/components/dialogs/CreateDataDialog.tsx +2 -2
- package/src/components/dialogs/CreateFolderDialog.tsx +2 -1
- package/src/components/dialogs/CreatePageFlow.tsx +117 -0
- package/src/components/dialogs/DataPropertiesDialog.tsx +3 -2
- package/src/components/dialogs/FragmentPropertiesDialog.tsx +3 -2
- package/src/components/dialogs/PageMetadataDialog.tsx +5 -28
- package/src/components/editor/CMSMDXEditor.tsx +49 -69
- package/src/components/editor/DrawerItemOverride.tsx +14 -8
- package/src/components/editor/PageEditor.tsx +135 -36
- package/src/components/editor/PageEditorHeaderActions.tsx +1 -1
- package/src/components/editor/PageEditorWrapper.tsx +51 -12
- package/src/components/editor/draft-media-config.ts +197 -0
- package/src/components/editor/preview-availability.ts +6 -5
- package/src/components/editors/DataEditor.tsx +2 -2
- package/src/components/forms/HintForm.tsx +7 -5
- package/src/components/forms/SchemaForm.tsx +41 -12
- package/src/components/media/AssetCard.tsx +10 -7
- package/src/components/media/AssetDetailSidebar.tsx +6 -6
- package/src/components/media/FolderTreeSidebar.tsx +3 -1
- package/src/components/pages/PageList.tsx +17 -119
- package/src/components/sandbox/ContentSandbox.tsx +34 -5
- package/src/content-form-fields.ts +79 -0
- package/src/content-wrapper.ts +284 -0
- package/src/data-schemas.ts +4 -3
- package/src/frame/channel.ts +258 -0
- package/src/frame/editor-frame.ts +180 -0
- package/src/frame/media-cache.ts +144 -0
- package/src/frame/memory-router.ts +39 -0
- package/src/frame/parent-hello.ts +62 -0
- package/src/frame/protocol.ts +323 -0
- package/src/frame/rpc-content-client.ts +58 -0
- package/src/frame/save-shortcut.ts +25 -0
- package/src/host-schema.ts +122 -0
- package/src/host-style-probe.ts +120 -90
- package/src/index.ts +7 -2
- package/src/main-spa.tsx +2 -0
- package/src/main.css +12 -8
- package/src/page-schema-define.ts +29 -17
- package/src/prose-surface-css.ts +3 -5
- package/src/site-styles.ts +4 -22
- package/src/ui-config.ts +54 -1
- package/src/utils/asset-url.ts +8 -0
- package/src/utils/pageMetadata.ts +27 -10
- package/src/utils/schema-fields.ts +106 -0
- package/dist/ts/host-discovery.d.ts +0 -40
- package/dist/ts/host-discovery.d.ts.map +0 -1
- package/dist/ts/host-discovery.js +0 -39
- package/dist/ts/host-discovery.js.map +0 -1
- package/dist/ts/utils/zodIntrospect.d.ts +0 -19
- package/dist/ts/utils/zodIntrospect.d.ts.map +0 -1
- package/dist/ts/utils/zodIntrospect.js +0 -95
- package/dist/ts/utils/zodIntrospect.js.map +0 -1
- package/src/host-discovery.ts +0 -77
- package/src/utils/zodIntrospect.ts +0 -136
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract between the editor page and the parent frame around it: the
|
|
3
|
+
* messages on their shared port, the methods either side may call, and the
|
|
4
|
+
* parent origins the page accepts. Both sides import it from here.
|
|
5
|
+
*/
|
|
6
|
+
import type { ContentAPIClient } from '@conloca/content-api-client';
|
|
7
|
+
import type { ThemePreference } from '../theme.js';
|
|
8
|
+
import type { EditorWriteRefusal, PreviewCapability } from '../ui-config.js';
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
EDITOR_HOST_PROTOCOL,
|
|
12
|
+
EDITOR_HOST_PROTOCOLS,
|
|
13
|
+
type EditorFrameFailure,
|
|
14
|
+
type EditorHostPageData,
|
|
15
|
+
} from '@conloca/content-api-client';
|
|
16
|
+
export { CONTENT_METHOD_CLASSIFICATION } from '../write-access.js';
|
|
17
|
+
|
|
18
|
+
export interface ProtocolRange {
|
|
19
|
+
min: number;
|
|
20
|
+
max: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const HELLO_TYPE = 'conloca:hello';
|
|
24
|
+
|
|
25
|
+
/** The parent's window message; it carries exactly one port. */
|
|
26
|
+
export interface Hello {
|
|
27
|
+
type: typeof HELLO_TYPE;
|
|
28
|
+
protocols: ProtocolRange;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The page's answer to a hello, with the identity its build baked in, so the parent can compare it. */
|
|
32
|
+
export interface Accepted {
|
|
33
|
+
kind: 'accepted';
|
|
34
|
+
protocol: number;
|
|
35
|
+
repo: string | null;
|
|
36
|
+
siteId: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface Nack {
|
|
40
|
+
kind: 'nack';
|
|
41
|
+
code: 'origin-rejected' | 'unsupported-protocol';
|
|
42
|
+
/** The protocol the page speaks, sent with `unsupported-protocol`. */
|
|
43
|
+
page?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The parent's settings, sent once after `accepted`. */
|
|
47
|
+
export interface Init {
|
|
48
|
+
kind: 'init';
|
|
49
|
+
initialPath: string;
|
|
50
|
+
readOnly: EditorWriteRefusal | null;
|
|
51
|
+
previewCapability: PreviewCapability;
|
|
52
|
+
theme: ThemePreference;
|
|
53
|
+
locales?: { list: string[]; defaultLocale: string };
|
|
54
|
+
mediaEnabled: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface Ready {
|
|
58
|
+
kind: 'ready';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface Call {
|
|
62
|
+
kind: 'call';
|
|
63
|
+
id: number;
|
|
64
|
+
method: string;
|
|
65
|
+
args: unknown[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type Result =
|
|
69
|
+
| { kind: 'result'; id: number; ok: true; value: unknown }
|
|
70
|
+
| { kind: 'result'; id: number; ok: false; error: WireError };
|
|
71
|
+
|
|
72
|
+
export interface FrameEvent {
|
|
73
|
+
kind: 'event';
|
|
74
|
+
name: string;
|
|
75
|
+
payload: unknown;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type ControlMessage = Accepted | Nack | Init | Ready;
|
|
79
|
+
export type FrameMessage = ControlMessage | Call | Result | FrameEvent;
|
|
80
|
+
|
|
81
|
+
/** Codes of the errors the channel itself raises. */
|
|
82
|
+
export type RpcErrorCode = 'method_not_allowed' | 'bad_arguments' | 'rate_limited';
|
|
83
|
+
|
|
84
|
+
/** An error as it crosses the port; the receiving side rebuilds the matching class. */
|
|
85
|
+
export interface WireError {
|
|
86
|
+
/** `APIClientError`, `StaleWriteError`, `ContentWriteRefusedError`, `RpcError` or `Error`. */
|
|
87
|
+
name: string;
|
|
88
|
+
message: string;
|
|
89
|
+
/** `APIClientError.code`, or an {@link RpcErrorCode}. */
|
|
90
|
+
code?: string;
|
|
91
|
+
/** `APIClientError.details`. */
|
|
92
|
+
details?: unknown;
|
|
93
|
+
/** `StaleWriteError.data`. */
|
|
94
|
+
data?: unknown;
|
|
95
|
+
/** `ContentWriteRefusedError.method`. */
|
|
96
|
+
method?: string;
|
|
97
|
+
refusal?: { reason: string };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The argument of `media.load`. */
|
|
101
|
+
export interface MediaLoadInput {
|
|
102
|
+
route: 'serve' | 'draft';
|
|
103
|
+
/** Relative to the media root (`uploads/hero.png`): raw, never URL-encoded, no leading slash. */
|
|
104
|
+
path: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The answer to `preview.open`. */
|
|
108
|
+
export type PreviewOpenResult =
|
|
109
|
+
| { ok: true }
|
|
110
|
+
| { ok: false; reason: 'not-deployed'; message: string }
|
|
111
|
+
| { ok: false; reason: 'popup-blocked' };
|
|
112
|
+
|
|
113
|
+
/** The answer to `site.open`; a refused path rejects with `RpcError` `bad_arguments`. */
|
|
114
|
+
export type SiteOpenResult = { ok: true } | { ok: false; reason: 'popup-blocked' };
|
|
115
|
+
|
|
116
|
+
/** Each event name and its payload. */
|
|
117
|
+
export interface FrameEventPayloads {
|
|
118
|
+
'editor.dirty': { dirty: boolean };
|
|
119
|
+
'shortcut.save': null;
|
|
120
|
+
'editor.stale': null;
|
|
121
|
+
'load.failed': {
|
|
122
|
+
stage: 'site' | 'css' | 'ui';
|
|
123
|
+
/** For logs; the parent shows its own text. */
|
|
124
|
+
message: string;
|
|
125
|
+
};
|
|
126
|
+
'route.changed': { path: string; replace: boolean };
|
|
127
|
+
'route.navigate': { path: string };
|
|
128
|
+
'readOnly.changed': { readOnly: EditorWriteRefusal | null };
|
|
129
|
+
'previewCapability.changed': { previewCapability: PreviewCapability };
|
|
130
|
+
'theme.changed': { theme: ThemePreference };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Content methods the page may call; the parent refuses every other client method. */
|
|
134
|
+
export const FRAME_CONTENT_METHODS = [
|
|
135
|
+
'getContent',
|
|
136
|
+
'getLocalized',
|
|
137
|
+
'getSitePages',
|
|
138
|
+
'getFragments',
|
|
139
|
+
'getData',
|
|
140
|
+
'getDataCollections',
|
|
141
|
+
'listAllContent',
|
|
142
|
+
'getSitesConfig',
|
|
143
|
+
'getPageByPathname',
|
|
144
|
+
'getFragmentByName',
|
|
145
|
+
'getDataByName',
|
|
146
|
+
'isPathnameAvailable',
|
|
147
|
+
'isDataNameAvailable',
|
|
148
|
+
'compileMDX',
|
|
149
|
+
'createContent',
|
|
150
|
+
'updateLocalized',
|
|
151
|
+
'deleteContent',
|
|
152
|
+
'deleteLocalized',
|
|
153
|
+
'batchUpdate',
|
|
154
|
+
'movePage',
|
|
155
|
+
'listAssets',
|
|
156
|
+
'getAsset',
|
|
157
|
+
'listFolder',
|
|
158
|
+
'getFolderTree',
|
|
159
|
+
'getAssetUsage',
|
|
160
|
+
'uploadAsset',
|
|
161
|
+
'importAssetUrl',
|
|
162
|
+
'deleteAsset',
|
|
163
|
+
'createFolder',
|
|
164
|
+
'updateAssetMetadata',
|
|
165
|
+
'moveAssets',
|
|
166
|
+
] as const satisfies readonly (keyof ContentAPIClient)[];
|
|
167
|
+
|
|
168
|
+
/** Parent-side methods the page may call; `site.open` takes `{ path }`, the page pathname relative to the site base. */
|
|
169
|
+
export const FRAME_HOST_METHODS = [
|
|
170
|
+
'mediaBridge.getAssetScope',
|
|
171
|
+
'mediaBridge.getMediaIssue',
|
|
172
|
+
'media.load',
|
|
173
|
+
'preview.open',
|
|
174
|
+
'site.open',
|
|
175
|
+
] as const;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The parent calls this on the page and gets an `EditorFlushResult`. Its `message` is for logs; the parent shows its
|
|
179
|
+
* own text.
|
|
180
|
+
*/
|
|
181
|
+
export const EDITOR_FLUSH_METHOD = 'editor.flush';
|
|
182
|
+
|
|
183
|
+
export type FrameMethod = (typeof FRAME_CONTENT_METHODS)[number] | (typeof FRAME_HOST_METHODS)[number];
|
|
184
|
+
|
|
185
|
+
/** The most arguments each method takes, as the client declares them. */
|
|
186
|
+
export const FRAME_METHOD_MAX_ARGS = {
|
|
187
|
+
getContent: 1,
|
|
188
|
+
getLocalized: 2,
|
|
189
|
+
getSitePages: 2,
|
|
190
|
+
getFragments: 2,
|
|
191
|
+
getData: 2,
|
|
192
|
+
getDataCollections: 0,
|
|
193
|
+
listAllContent: 1,
|
|
194
|
+
getSitesConfig: 0,
|
|
195
|
+
getPageByPathname: 3,
|
|
196
|
+
getFragmentByName: 3,
|
|
197
|
+
getDataByName: 3,
|
|
198
|
+
isPathnameAvailable: 4,
|
|
199
|
+
isDataNameAvailable: 3,
|
|
200
|
+
compileMDX: 1,
|
|
201
|
+
createContent: 1,
|
|
202
|
+
updateLocalized: 1,
|
|
203
|
+
deleteContent: 2,
|
|
204
|
+
deleteLocalized: 1,
|
|
205
|
+
batchUpdate: 1,
|
|
206
|
+
movePage: 5,
|
|
207
|
+
listAssets: 0,
|
|
208
|
+
getAsset: 1,
|
|
209
|
+
listFolder: 1,
|
|
210
|
+
getFolderTree: 0,
|
|
211
|
+
getAssetUsage: 1,
|
|
212
|
+
uploadAsset: 1,
|
|
213
|
+
importAssetUrl: 3,
|
|
214
|
+
deleteAsset: 1,
|
|
215
|
+
createFolder: 1,
|
|
216
|
+
updateAssetMetadata: 2,
|
|
217
|
+
moveAssets: 3,
|
|
218
|
+
'mediaBridge.getAssetScope': 1,
|
|
219
|
+
'mediaBridge.getMediaIssue': 1,
|
|
220
|
+
'media.load': 1,
|
|
221
|
+
'preview.open': 1,
|
|
222
|
+
'site.open': 1,
|
|
223
|
+
} as const satisfies Readonly<Record<FrameMethod, number>>;
|
|
224
|
+
|
|
225
|
+
const FRAME_PATH_RE = /^\/[A-Za-z0-9/_.:%-]{0,512}(\?[A-Za-z0-9_.:%=&-]{0,512})?$/;
|
|
226
|
+
const DNS_LABEL_RE = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
227
|
+
|
|
228
|
+
/** Whether `path` is an editor route (`pathname + search`) the page may report or the parent may send. */
|
|
229
|
+
export function isFramePath(path: string): boolean {
|
|
230
|
+
return FRAME_PATH_RE.test(path) && !path.includes('//');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* oxlint-disable anti-slop/no-unknown-parameters -- the guards below read what arrives on the port, untyped by nature. */
|
|
234
|
+
|
|
235
|
+
export function isThemePreference(value: unknown): value is ThemePreference {
|
|
236
|
+
return value === 'light' || value === 'dark' || value === 'system';
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function isPreviewCapability(value: unknown): value is PreviewCapability {
|
|
240
|
+
return value === 'available' || value === 'unavailable' || value === 'unknown';
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function isWriteRefusal(value: unknown): value is EditorWriteRefusal {
|
|
244
|
+
return typeof value === 'object' && value !== null && 'reason' in value && typeof value.reason === 'string';
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function readLocales(value: unknown): Init['locales'] | undefined {
|
|
248
|
+
if (typeof value !== 'object' || value === null || !('list' in value) || !('defaultLocale' in value))
|
|
249
|
+
return undefined;
|
|
250
|
+
const { list, defaultLocale } = value;
|
|
251
|
+
if (!Array.isArray(list) || typeof defaultLocale !== 'string') return undefined;
|
|
252
|
+
const locales = list.filter((locale): locale is string => typeof locale === 'string');
|
|
253
|
+
return locales.length === list.length ? { list: locales, defaultLocale } : undefined;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function readInit(data: unknown): Init | undefined {
|
|
257
|
+
if (typeof data !== 'object' || data === null) return undefined;
|
|
258
|
+
if (!('initialPath' in data) || typeof data.initialPath !== 'string' || !isFramePath(data.initialPath)) {
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
if (!('readOnly' in data) || !(data.readOnly === null || isWriteRefusal(data.readOnly))) return undefined;
|
|
262
|
+
if (!('previewCapability' in data) || !isPreviewCapability(data.previewCapability)) return undefined;
|
|
263
|
+
if (!('theme' in data) || !isThemePreference(data.theme)) return undefined;
|
|
264
|
+
if (!('mediaEnabled' in data) || typeof data.mediaEnabled !== 'boolean') return undefined;
|
|
265
|
+
const init: Init = {
|
|
266
|
+
kind: 'init',
|
|
267
|
+
initialPath: data.initialPath,
|
|
268
|
+
readOnly: data.readOnly,
|
|
269
|
+
previewCapability: data.previewCapability,
|
|
270
|
+
theme: data.theme,
|
|
271
|
+
mediaEnabled: data.mediaEnabled,
|
|
272
|
+
};
|
|
273
|
+
if (!('locales' in data) || data.locales === undefined) return init;
|
|
274
|
+
const locales = readLocales(data.locales);
|
|
275
|
+
return locales ? { ...init, locales } : undefined;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Reads a control message off the port; `undefined` when `data` is not a well-formed one. */
|
|
279
|
+
export function readControlMessage(data: unknown): ControlMessage | undefined {
|
|
280
|
+
if (typeof data !== 'object' || data === null || !('kind' in data)) return undefined;
|
|
281
|
+
switch (data.kind) {
|
|
282
|
+
case 'ready':
|
|
283
|
+
return { kind: 'ready' };
|
|
284
|
+
case 'init':
|
|
285
|
+
return readInit(data);
|
|
286
|
+
case 'accepted':
|
|
287
|
+
if (!('protocol' in data) || typeof data.protocol !== 'number') return undefined;
|
|
288
|
+
if (!('repo' in data) || !(data.repo === null || typeof data.repo === 'string')) return undefined;
|
|
289
|
+
if (!('siteId' in data) || typeof data.siteId !== 'string') return undefined;
|
|
290
|
+
return { kind: 'accepted', protocol: data.protocol, repo: data.repo, siteId: data.siteId };
|
|
291
|
+
case 'nack': {
|
|
292
|
+
if (!('code' in data) || (data.code !== 'origin-rejected' && data.code !== 'unsupported-protocol'))
|
|
293
|
+
return undefined;
|
|
294
|
+
const nack: Nack = { kind: 'nack', code: data.code };
|
|
295
|
+
return 'page' in data && typeof data.page === 'number' ? { ...nack, page: data.page } : nack;
|
|
296
|
+
}
|
|
297
|
+
default:
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/* oxlint-enable anti-slop/no-unknown-parameters */
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Whether the page accepts a hello from `origin`: `https://<label>.<root>` without a port, `<label>` one DNS label
|
|
306
|
+
* that is not reserved. Under a `.localhost` root, `http:` and any port are allowed too.
|
|
307
|
+
*/
|
|
308
|
+
export function acceptsParentOrigin(origin: string, root: string, isReserved: (label: string) => boolean): boolean {
|
|
309
|
+
let url: URL;
|
|
310
|
+
try {
|
|
311
|
+
url = new URL(origin);
|
|
312
|
+
} catch {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
const local = root.endsWith('.localhost');
|
|
316
|
+
if (url.origin !== origin) return false;
|
|
317
|
+
if (url.protocol !== 'https:' && !(local && url.protocol === 'http:')) return false;
|
|
318
|
+
if (url.port !== '' && !local) return false;
|
|
319
|
+
const suffix = `.${root}`;
|
|
320
|
+
if (!url.hostname.endsWith(suffix)) return false;
|
|
321
|
+
const label = url.hostname.slice(0, -suffix.length);
|
|
322
|
+
return DNS_LABEL_RE.test(label) && !isReserved(label);
|
|
323
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ContentAPIClient } from '@conloca/content-api-client';
|
|
2
|
+
import type { FrameChannel } from './channel.js';
|
|
3
|
+
import { clearMediaCache } from './media-cache.js';
|
|
4
|
+
import { CONTENT_METHOD_CLASSIFICATION } from './protocol.js';
|
|
5
|
+
|
|
6
|
+
/** Writes after which loaded media bytes may be stale. */
|
|
7
|
+
const MEDIA_WRITES = new Set([
|
|
8
|
+
'uploadAsset',
|
|
9
|
+
'importAssetUrl',
|
|
10
|
+
'deleteAsset',
|
|
11
|
+
'createFolder',
|
|
12
|
+
'updateAssetMetadata',
|
|
13
|
+
'moveAssets',
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
/** The name/value pairs of an upload form, each File replaced by a copy held in memory. */
|
|
17
|
+
function uploadPairs(form: FormData): Promise<[string, FormDataEntryValue][]> {
|
|
18
|
+
return Promise.all(
|
|
19
|
+
[...form.entries()].map(
|
|
20
|
+
async ([name, value]): Promise<[string, FormDataEntryValue]> =>
|
|
21
|
+
typeof value === 'string'
|
|
22
|
+
? [name, value]
|
|
23
|
+
: [
|
|
24
|
+
name,
|
|
25
|
+
new File([await value.arrayBuffer()], value.name, {
|
|
26
|
+
type: value.type,
|
|
27
|
+
lastModified: value.lastModified,
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The content client of an editor frame: it holds no credentials, so every content method becomes a call the
|
|
36
|
+
* parent frame runs on its own client. All methods cross, writes and reads alike; the parent decides what it refuses.
|
|
37
|
+
*/
|
|
38
|
+
export class RpcContentClient extends ContentAPIClient {
|
|
39
|
+
constructor(channel: Pick<FrameChannel, 'call'>) {
|
|
40
|
+
super();
|
|
41
|
+
for (const method of Object.keys(CONTENT_METHOD_CLASSIFICATION)) {
|
|
42
|
+
Object.defineProperty(this, method, {
|
|
43
|
+
// oxlint-disable-next-line anti-slop/no-unknown-returns -- it replaces a typed ContentAPIClient method; callers see that method's types.
|
|
44
|
+
value: async (...args: unknown[]): Promise<unknown> => {
|
|
45
|
+
// FormData cannot be cloned onto a port; its name/value pairs can. A picked File is backed by a disk
|
|
46
|
+
// path only this frame's process may read, so each File crosses as an in-memory copy of its bytes.
|
|
47
|
+
const sent = method === 'uploadAsset' && args[0] instanceof FormData ? [await uploadPairs(args[0])] : args;
|
|
48
|
+
const result = await channel.call(method, sent);
|
|
49
|
+
if (MEDIA_WRITES.has(method)) clearMediaCache();
|
|
50
|
+
return result;
|
|
51
|
+
},
|
|
52
|
+
writable: false,
|
|
53
|
+
enumerable: false,
|
|
54
|
+
configurable: false,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { inEditorFrame } from '../ui-config.js';
|
|
3
|
+
|
|
4
|
+
/** Whether a key press is Cmd/Ctrl+S. */
|
|
5
|
+
export function isSaveCombo(event: KeyboardEvent): boolean {
|
|
6
|
+
return (event.metaKey || event.ctrlKey) && (event.key === 's' || event.key === 'S');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* In a parent frame, hands Cmd/Ctrl+S pressed inside the editing canvas to the editor's `window`, where the frame
|
|
11
|
+
* connection sends it to the parent. The canvas is its own document, so its key presses never reach `window`.
|
|
12
|
+
*/
|
|
13
|
+
export function useCanvasSaveShortcut(canvasDocument: Document | undefined): void {
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!canvasDocument || !inEditorFrame()) return undefined;
|
|
16
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
17
|
+
if (!isSaveCombo(event)) return;
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
const { key, metaKey, ctrlKey } = event;
|
|
20
|
+
window.dispatchEvent(new KeyboardEvent('keydown', { key, metaKey, ctrlKey, cancelable: true }));
|
|
21
|
+
};
|
|
22
|
+
canvasDocument.addEventListener('keydown', onKeyDown);
|
|
23
|
+
return () => canvasDocument.removeEventListener('keydown', onKeyDown);
|
|
24
|
+
}, [canvasDocument]);
|
|
25
|
+
}
|
|
@@ -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
|
+
}
|