@conloca/cms-spa 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +2 -1
  2. package/dist/spa/main.css +6 -21
  3. package/dist/ts/.build-inputs.json +38 -28
  4. package/dist/ts/components/CMSDashboard.d.ts.map +1 -1
  5. package/dist/ts/components/CMSDashboard.js +3 -1
  6. package/dist/ts/components/CMSDashboard.js.map +1 -1
  7. package/dist/ts/components/dialogs/DeleteConfirmDialog.d.ts +6 -1
  8. package/dist/ts/components/dialogs/DeleteConfirmDialog.d.ts.map +1 -1
  9. package/dist/ts/components/dialogs/DeleteConfirmDialog.js +2 -2
  10. package/dist/ts/components/dialogs/DeleteConfirmDialog.js.map +1 -1
  11. package/dist/ts/components/dialogs/MakePagesEditableDialog.d.ts +10 -0
  12. package/dist/ts/components/dialogs/MakePagesEditableDialog.d.ts.map +1 -0
  13. package/dist/ts/components/dialogs/MakePagesEditableDialog.js +35 -0
  14. package/dist/ts/components/dialogs/MakePagesEditableDialog.js.map +1 -0
  15. package/dist/ts/components/dialogs/MoveFolderDialog.d.ts +6 -1
  16. package/dist/ts/components/dialogs/MoveFolderDialog.d.ts.map +1 -1
  17. package/dist/ts/components/dialogs/MoveFolderDialog.js +3 -3
  18. package/dist/ts/components/dialogs/MoveFolderDialog.js.map +1 -1
  19. package/dist/ts/components/editor/CMSMDXEditor.d.ts.map +1 -1
  20. package/dist/ts/components/editor/CMSMDXEditor.js +9 -9
  21. package/dist/ts/components/editor/CMSMDXEditor.js.map +1 -1
  22. package/dist/ts/components/editor/DocsPreviewButton.d.ts +6 -0
  23. package/dist/ts/components/editor/DocsPreviewButton.d.ts.map +1 -0
  24. package/dist/ts/components/editor/DocsPreviewButton.js +15 -0
  25. package/dist/ts/components/editor/DocsPreviewButton.js.map +1 -0
  26. package/dist/ts/components/editor/ImagePickerDialog.js +2 -2
  27. package/dist/ts/components/editor/ImagePickerDialog.js.map +1 -1
  28. package/dist/ts/components/editor/MdxPageEditor.d.ts.map +1 -1
  29. package/dist/ts/components/editor/MdxPageEditor.js +2 -1
  30. package/dist/ts/components/editor/MdxPageEditor.js.map +1 -1
  31. package/dist/ts/components/editor/PageEditor.d.ts.map +1 -1
  32. package/dist/ts/components/editor/PageEditor.js +1 -2
  33. package/dist/ts/components/editor/PageEditor.js.map +1 -1
  34. package/dist/ts/components/editor/draft-media-config.d.ts +20 -8
  35. package/dist/ts/components/editor/draft-media-config.d.ts.map +1 -1
  36. package/dist/ts/components/editor/draft-media-config.js +124 -60
  37. package/dist/ts/components/editor/draft-media-config.js.map +1 -1
  38. package/dist/ts/components/editor/preview-availability.d.ts +2 -0
  39. package/dist/ts/components/editor/preview-availability.d.ts.map +1 -1
  40. package/dist/ts/components/editor/preview-availability.js +2 -0
  41. package/dist/ts/components/editor/preview-availability.js.map +1 -1
  42. package/dist/ts/components/editors/DataEditor.d.ts +6 -2
  43. package/dist/ts/components/editors/DataEditor.d.ts.map +1 -1
  44. package/dist/ts/components/editors/DataEditor.js +46 -19
  45. package/dist/ts/components/editors/DataEditor.js.map +1 -1
  46. package/dist/ts/components/fields/ImageField.js +2 -2
  47. package/dist/ts/components/fields/ImageField.js.map +1 -1
  48. package/dist/ts/components/media/AssetCard.d.ts.map +1 -1
  49. package/dist/ts/components/media/AssetCard.js +3 -3
  50. package/dist/ts/components/media/AssetCard.js.map +1 -1
  51. package/dist/ts/components/media/AssetDetailSidebar.d.ts.map +1 -1
  52. package/dist/ts/components/media/AssetDetailSidebar.js +6 -3
  53. package/dist/ts/components/media/AssetDetailSidebar.js.map +1 -1
  54. package/dist/ts/components/media/AssetUsageList.d.ts +13 -0
  55. package/dist/ts/components/media/AssetUsageList.d.ts.map +1 -0
  56. package/dist/ts/components/media/AssetUsageList.js +35 -0
  57. package/dist/ts/components/media/AssetUsageList.js.map +1 -0
  58. package/dist/ts/components/media/MediaLibrary.d.ts.map +1 -1
  59. package/dist/ts/components/media/MediaLibrary.js +6 -4
  60. package/dist/ts/components/media/MediaLibrary.js.map +1 -1
  61. package/dist/ts/components/media/index.d.ts +1 -0
  62. package/dist/ts/components/media/index.d.ts.map +1 -1
  63. package/dist/ts/components/media/index.js +1 -0
  64. package/dist/ts/components/media/index.js.map +1 -1
  65. package/dist/ts/components/pages/DataList.d.ts.map +1 -1
  66. package/dist/ts/components/pages/DataList.js +51 -34
  67. package/dist/ts/components/pages/DataList.js.map +1 -1
  68. package/dist/ts/components/pages/FragmentList.d.ts.map +1 -1
  69. package/dist/ts/components/pages/FragmentList.js +1 -1
  70. package/dist/ts/components/pages/FragmentList.js.map +1 -1
  71. package/dist/ts/components/pages/MediaPage.d.ts.map +1 -1
  72. package/dist/ts/components/pages/MediaPage.js +7 -5
  73. package/dist/ts/components/pages/MediaPage.js.map +1 -1
  74. package/dist/ts/components/pages/NoPagesYet.d.ts +5 -0
  75. package/dist/ts/components/pages/NoPagesYet.d.ts.map +1 -0
  76. package/dist/ts/components/pages/NoPagesYet.js +16 -0
  77. package/dist/ts/components/pages/NoPagesYet.js.map +1 -0
  78. package/dist/ts/components/pages/PageList.d.ts.map +1 -1
  79. package/dist/ts/components/pages/PageList.js +9 -4
  80. package/dist/ts/components/pages/PageList.js.map +1 -1
  81. package/dist/ts/components/sandbox/ContentSandbox.js +3 -3
  82. package/dist/ts/components/sandbox/ContentSandbox.js.map +1 -1
  83. package/dist/ts/convert-pages.d.ts +30 -0
  84. package/dist/ts/convert-pages.d.ts.map +1 -0
  85. package/dist/ts/convert-pages.js +85 -0
  86. package/dist/ts/convert-pages.js.map +1 -0
  87. package/dist/ts/editor-queries.d.ts +24 -0
  88. package/dist/ts/editor-queries.d.ts.map +1 -0
  89. package/dist/ts/editor-queries.js +37 -0
  90. package/dist/ts/editor-queries.js.map +1 -0
  91. package/dist/ts/frame/editor-frame.d.ts +2 -1
  92. package/dist/ts/frame/editor-frame.d.ts.map +1 -1
  93. package/dist/ts/frame/editor-frame.js +14 -2
  94. package/dist/ts/frame/editor-frame.js.map +1 -1
  95. package/dist/ts/frame/media-cache.d.ts +13 -2
  96. package/dist/ts/frame/media-cache.d.ts.map +1 -1
  97. package/dist/ts/frame/media-cache.js +24 -9
  98. package/dist/ts/frame/media-cache.js.map +1 -1
  99. package/dist/ts/frame/protocol.d.ts +13 -1
  100. package/dist/ts/frame/protocol.d.ts.map +1 -1
  101. package/dist/ts/frame/protocol.js +5 -0
  102. package/dist/ts/frame/protocol.js.map +1 -1
  103. package/dist/ts/hooks/index.d.ts +2 -0
  104. package/dist/ts/hooks/index.d.ts.map +1 -1
  105. package/dist/ts/hooks/index.js +1 -0
  106. package/dist/ts/hooks/index.js.map +1 -1
  107. package/dist/ts/hooks/usePageConversion.d.ts +11 -0
  108. package/dist/ts/hooks/usePageConversion.d.ts.map +1 -0
  109. package/dist/ts/hooks/usePageConversion.js +47 -0
  110. package/dist/ts/hooks/usePageConversion.js.map +1 -0
  111. package/dist/ts/hooks/useUploadFlow.d.ts.map +1 -1
  112. package/dist/ts/hooks/useUploadFlow.js +41 -7
  113. package/dist/ts/hooks/useUploadFlow.js.map +1 -1
  114. package/dist/ts/index.d.ts +3 -0
  115. package/dist/ts/index.d.ts.map +1 -1
  116. package/dist/ts/index.js +5 -0
  117. package/dist/ts/index.js.map +1 -1
  118. package/dist/ts/media/prepare-image-upload.d.ts +19 -0
  119. package/dist/ts/media/prepare-image-upload.d.ts.map +1 -0
  120. package/dist/ts/media/prepare-image-upload.js +93 -0
  121. package/dist/ts/media/prepare-image-upload.js.map +1 -0
  122. package/dist/ts/media/use-asset-serve-src.d.ts +7 -0
  123. package/dist/ts/media/use-asset-serve-src.d.ts.map +1 -0
  124. package/dist/ts/media/use-asset-serve-src.js +17 -0
  125. package/dist/ts/media/use-asset-serve-src.js.map +1 -0
  126. package/dist/ts/ui-config.d.ts +13 -3
  127. package/dist/ts/ui-config.d.ts.map +1 -1
  128. package/dist/ts/ui-config.js +14 -0
  129. package/dist/ts/ui-config.js.map +1 -1
  130. package/dist/ts/utils/asset-url.d.ts +3 -0
  131. package/dist/ts/utils/asset-url.d.ts.map +1 -1
  132. package/dist/ts/utils/asset-url.js +4 -0
  133. package/dist/ts/utils/asset-url.js.map +1 -1
  134. package/dist/ts/utils/data-entry-validation.d.ts +11 -0
  135. package/dist/ts/utils/data-entry-validation.d.ts.map +1 -0
  136. package/dist/ts/utils/data-entry-validation.js +15 -0
  137. package/dist/ts/utils/data-entry-validation.js.map +1 -0
  138. package/package.json +6 -7
  139. package/src/components/CMSDashboard.tsx +19 -14
  140. package/src/components/dialogs/DeleteConfirmDialog.tsx +14 -1
  141. package/src/components/dialogs/MakePagesEditableDialog.tsx +112 -0
  142. package/src/components/dialogs/MoveFolderDialog.tsx +9 -2
  143. package/src/components/editor/CMSMDXEditor.tsx +9 -9
  144. package/src/components/editor/DocsPreviewButton.tsx +25 -0
  145. package/src/components/editor/ImagePickerDialog.tsx +2 -2
  146. package/src/components/editor/MdxPageEditor.tsx +2 -0
  147. package/src/components/editor/PageEditor.tsx +1 -5
  148. package/src/components/editor/draft-media-config.ts +121 -65
  149. package/src/components/editor/preview-availability.ts +3 -0
  150. package/src/components/editors/DataEditor.tsx +65 -32
  151. package/src/components/fields/ImageField.tsx +2 -2
  152. package/src/components/media/AssetCard.tsx +4 -4
  153. package/src/components/media/AssetDetailSidebar.tsx +34 -21
  154. package/src/components/media/AssetUsageList.tsx +84 -0
  155. package/src/components/media/MediaLibrary.tsx +6 -4
  156. package/src/components/media/index.ts +1 -0
  157. package/src/components/pages/DataList.tsx +58 -43
  158. package/src/components/pages/FragmentList.tsx +3 -14
  159. package/src/components/pages/MediaPage.tsx +14 -5
  160. package/src/components/pages/NoPagesYet.tsx +41 -0
  161. package/src/components/pages/PageList.tsx +23 -23
  162. package/src/components/sandbox/ContentSandbox.tsx +3 -3
  163. package/src/convert-pages.ts +110 -0
  164. package/src/editor-queries.ts +49 -0
  165. package/src/frame/editor-frame.ts +14 -2
  166. package/src/frame/media-cache.ts +28 -15
  167. package/src/frame/protocol.ts +12 -1
  168. package/src/hooks/index.ts +2 -0
  169. package/src/hooks/usePageConversion.ts +55 -0
  170. package/src/hooks/useUploadFlow.ts +44 -7
  171. package/src/index.ts +5 -0
  172. package/src/media/prepare-image-upload.ts +118 -0
  173. package/src/media/use-asset-serve-src.ts +22 -0
  174. package/src/ui-config.ts +23 -3
  175. package/src/utils/asset-url.ts +6 -0
  176. package/src/utils/data-entry-validation.ts +16 -0
@@ -0,0 +1,118 @@
1
+ import {
2
+ DEFAULT_ACCEPTED_FORMATS,
3
+ IMAGE_EXTENSION_MIME,
4
+ JPEG_FALLBACK_QUALITY,
5
+ MAX_IMAGE_EDGE,
6
+ tooLargeRefusal,
7
+ unreadableImageRefusal,
8
+ unsupportedTypeRefusal,
9
+ VIDEO_EXTENSIONS,
10
+ videoRefusal,
11
+ WEBP_QUALITY,
12
+ } from '@conloca/content-api-client';
13
+
14
+ /**
15
+ * The browser's half of the upload rules: a photo over 2560 px is shrunk, upright, and a file the site will not
16
+ * store is refused before any byte is sent. The editor runs it, and the editor's parent page runs it again for
17
+ * editor bundles built before it existed.
18
+ */
19
+
20
+ type OutputType = 'image/webp' | 'image/jpeg' | 'image/png';
21
+
22
+ const OUTPUT_EXTENSION = { 'image/webp': 'webp', 'image/jpeg': 'jpg', 'image/png': 'png' } satisfies Record<
23
+ OutputType,
24
+ string
25
+ >;
26
+
27
+ /** Formats a canvas decodes and re-encodes; GIF, SVG and ICO are sent as they are. */
28
+ const SHRINKABLE: ReadonlySet<string> = new Set(['image/jpeg', 'image/png', 'image/webp', 'image/avif']);
29
+
30
+ /** The size that fits `width`×`height` within `maxEdge` on its long edge, or `null` when it already fits. */
31
+ export function fitWithin(width: number, height: number, maxEdge: number): { width: number; height: number } | null {
32
+ const longEdge = Math.max(width, height);
33
+ if (longEdge <= maxEdge) return null;
34
+ const scale = maxEdge / longEdge;
35
+ return { width: Math.max(1, Math.round(width * scale)), height: Math.max(1, Math.round(height * scale)) };
36
+ }
37
+
38
+ /** `name` with its extension replaced by the one `outputType` is stored under. */
39
+ export function processedName(name: string, outputType: OutputType): string {
40
+ const dot = name.lastIndexOf('.');
41
+ return `${dot > 0 ? name.slice(0, dot) : name}.${OUTPUT_EXTENSION[outputType]}`;
42
+ }
43
+
44
+ function extensionOf(name: string): string {
45
+ const dot = name.lastIndexOf('.');
46
+ return dot < 0 ? '' : name.slice(dot + 1).toLowerCase();
47
+ }
48
+
49
+ /** The file to upload in place of `file`, shrunk when it is a photo over the edge; throws the refusal sentence. */
50
+ export async function prepareImageUpload(file: File, maxBytes: number): Promise<File> {
51
+ const extension = extensionOf(file.name);
52
+ if (VIDEO_EXTENSIONS.has(extension) || file.type.startsWith('video/')) throw new Error(videoRefusal(file.name));
53
+ const type = IMAGE_EXTENSION_MIME[extension];
54
+ if (type === undefined) throw new Error(unsupportedTypeRefusal(file.name, DEFAULT_ACCEPTED_FORMATS));
55
+ const prepared = SHRINKABLE.has(type) ? await shrink(file, type) : file;
56
+ if (prepared.size > maxBytes) throw new Error(tooLargeRefusal(file.name, prepared.size, maxBytes));
57
+ return prepared;
58
+ }
59
+
60
+ /** `form` with its `file` prepared by {@link prepareImageUpload}; `alt` and `folder` are kept. */
61
+ export async function prepareUploadForm(form: FormData, maxBytes: number): Promise<FormData> {
62
+ const file = form.get('file');
63
+ // The server refuses a form without a file in its own words.
64
+ if (!(file instanceof File)) return form;
65
+ const prepared = await prepareImageUpload(file, maxBytes);
66
+ const next = new FormData();
67
+ for (const [key, value] of form) next.append(key, key === 'file' ? prepared : value);
68
+ return next;
69
+ }
70
+
71
+ async function shrink(file: File, type: string): Promise<File> {
72
+ const bitmap = await decode(file);
73
+ if (!bitmap) throw new Error(unreadableImageRefusal(file.name));
74
+ try {
75
+ const size = fitWithin(bitmap.width, bitmap.height, MAX_IMAGE_EDGE);
76
+ if (!size) return file;
77
+ // Never larger than 2560×2560: inside the canvas area iOS allows.
78
+ const canvas = document.createElement('canvas');
79
+ canvas.width = size.width;
80
+ canvas.height = size.height;
81
+ const context = canvas.getContext('2d');
82
+ if (!context) throw new Error(unreadableImageRefusal(file.name));
83
+ context.imageSmoothingQuality = 'high';
84
+ context.drawImage(bitmap, 0, 0, size.width, size.height);
85
+ const encoded = await encode(canvas, type === 'image/png', file.name);
86
+ return new File([encoded.blob], processedName(file.name, encoded.type), { type: encoded.type });
87
+ } finally {
88
+ bitmap.close();
89
+ }
90
+ }
91
+
92
+ /** The decoded image, upright, or `null` when the bytes are not one the browser can read. */
93
+ async function decode(file: File): Promise<ImageBitmap | null> {
94
+ try {
95
+ return await createImageBitmap(file, { imageOrientation: 'from-image' });
96
+ } catch (error) {
97
+ // Older engines reject the options with a TypeError; they apply the EXIF orientation by default.
98
+ return error instanceof TypeError ? createImageBitmap(file).catch(() => null) : null;
99
+ }
100
+ }
101
+
102
+ async function encode(
103
+ canvas: HTMLCanvasElement,
104
+ png: boolean,
105
+ name: string,
106
+ ): Promise<{ blob: Blob; type: OutputType }> {
107
+ if (png) return { blob: await toBlob(canvas, 'image/png', undefined, name), type: 'image/png' };
108
+ const webp = await toBlob(canvas, 'image/webp', WEBP_QUALITY, name);
109
+ if (webp.type === 'image/webp') return { blob: webp, type: 'image/webp' };
110
+ // Safari cannot encode WebP and answers PNG instead.
111
+ return { blob: await toBlob(canvas, 'image/jpeg', JPEG_FALLBACK_QUALITY, name), type: 'image/jpeg' };
112
+ }
113
+
114
+ function toBlob(canvas: HTMLCanvasElement, type: OutputType, quality: number | undefined, name: string): Promise<Blob> {
115
+ return new Promise((resolve, reject) =>
116
+ canvas.toBlob((blob) => (blob ? resolve(blob) : reject(new Error(unreadableImageRefusal(name)))), type, quality),
117
+ );
118
+ }
@@ -0,0 +1,22 @@
1
+ import type { AssetEntry } from '@conloca/content-api-client';
2
+ import { mediaSourceOf } from '../components/editor/draft-media-config.js';
3
+ import { useMediaObjectUrl } from '../frame/media-cache.js';
4
+ import type { MediaLoadInput } from '../frame/protocol.js';
5
+ import { getUIConfig } from '../ui-config.js';
6
+ import { assetPath, buildAssetServeUrl } from '../utils/asset-url.js';
7
+
8
+ /**
9
+ * The `src` of an asset thumbnail: with a loader, an object URL of the bytes its link names (an image in the site's
10
+ * folder loads from there, anything else from its upload address); without one, the serve URL.
11
+ */
12
+ export function useAssetServeSrc(
13
+ assetsBasePath: string,
14
+ asset: Pick<AssetEntry, 'folder' | 'filename' | 'ref'>,
15
+ ): string | undefined {
16
+ const source: MediaLoadInput = (asset.ref === undefined ? undefined : mediaSourceOf(asset.ref)) ?? {
17
+ route: 'serve',
18
+ path: assetPath(asset.folder, asset.filename),
19
+ };
20
+ const loaded = useMediaObjectUrl(source.route, source.path);
21
+ return getUIConfig().loadMedia ? loaded : buildAssetServeUrl(assetsBasePath, asset.folder, asset.filename);
22
+ }
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 { PageConversionFacts } from './convert-pages.js';
4
5
  import type { MediaLoadInput, PreviewOpenResult } from './frame/protocol.js';
5
6
  import type { MediaBridge } from './media/types.js';
6
7
 
@@ -137,8 +138,6 @@ export interface UIConfig {
137
138
  * literal default.
138
139
  */
139
140
  assetsBasePath?: string;
140
- /** Draft-image render base; render URLs must never replace canonical saved asset refs. */
141
- draftAssetsBasePath?: string;
142
141
  /**
143
142
  * Base the STORED asset reference is built on (`buildAssetRef(folder,
144
143
  * filename)`) — the sibling of `assetsBasePath`, and deliberately a
@@ -208,7 +207,9 @@ export interface UIConfig {
208
207
  editorCss?: string;
209
208
  /**
210
209
  * 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.
210
+ * URLs to `<img>`; they show object URLs of the loaded bytes. Draft addresses
211
+ * (`/api/v1/assets/serve/<path>`) load through it from `serve` and show a
212
+ * transparent placeholder until their bytes arrive.
212
213
  */
213
214
  loadMedia?: (input: MediaLoadInput) => Promise<Blob>;
214
215
  /**
@@ -217,6 +218,11 @@ export interface UIConfig {
217
218
  * dev-server endpoints do not exist.
218
219
  */
219
220
  memoryRouter?: MemoryRouterConfig;
221
+ /**
222
+ * Set by the workspace editor around the framed editor or by the local
223
+ * integration; absent means the editor does not offer page conversion.
224
+ */
225
+ pageConversion?: PageConversionFacts;
220
226
  }
221
227
 
222
228
  /** How the editor routes when a parent frame owns the address bar. */
@@ -257,6 +263,9 @@ declare global {
257
263
 
258
264
  let config: UIConfig = { ...defaultConfig };
259
265
 
266
+ /** Fired on window when a parent frame changes `readOnly` or `pageConversion` after `configureUI`. */
267
+ export const EDITOR_CONFIG_CHANGED_EVENT = 'conloca:editor-config-changed';
268
+
260
269
  export function configureUI(options: Partial<UIConfig>) {
261
270
  // `readOnly` survives a reinstall unless the caller states a new answer.
262
271
  //
@@ -294,6 +303,17 @@ export function setEditorReadOnly(readOnly: EditorWriteRefusal | null) {
294
303
  // The runtime mirror `getUIConfig` reads from.
295
304
  const runtimeConfig = window.__UI_CONFIG__;
296
305
  if (runtimeConfig) runtimeConfig.readOnly = next;
306
+ window.dispatchEvent(new Event(EDITOR_CONFIG_CHANGED_EVENT));
307
+ }
308
+
309
+ /** Install (or clear, with `null`) the page conversion facts after `configureUI`, like {@link setEditorReadOnly}. */
310
+ export function setPageConversion(facts: PageConversionFacts | null) {
311
+ const next = facts ?? undefined;
312
+ config.pageConversion = next;
313
+ if (typeof window === 'undefined') return;
314
+ const runtimeConfig = window.__UI_CONFIG__;
315
+ if (runtimeConfig) runtimeConfig.pageConversion = next;
316
+ window.dispatchEvent(new Event(EDITOR_CONFIG_CHANGED_EVENT));
297
317
  }
298
318
 
299
319
  /**
@@ -1,3 +1,4 @@
1
+ import type { AssetEntry } from '@conloca/content-api-client';
1
2
  import { getUIConfig } from '../ui-config.js';
2
3
 
3
4
  /** An asset path relative to the media root; this is the identity accepted by asset routes. */
@@ -28,3 +29,8 @@ export function buildAssetServeUrl(basePath: string, folder: string | undefined,
28
29
  export function buildAssetRef(folder: string | undefined, filename: string): string {
29
30
  return buildAssetServeUrl(getUIConfig().assetRefBase ?? '/assets', folder, filename);
30
31
  }
32
+
33
+ /** The link a pick of `asset` stores: the one the server gave it, else the site link `buildAssetRef` builds. */
34
+ export function assetRefOf(asset: Pick<AssetEntry, 'folder' | 'filename' | 'ref'>): string {
35
+ return asset.ref ?? buildAssetRef(asset.folder, asset.filename);
36
+ }
@@ -0,0 +1,16 @@
1
+ import type { DataCollectionEntry } from '@conloca/content-api-client';
2
+ import type { HostSchema } from '../host-schema.js';
3
+
4
+ /**
5
+ * Why the build would reject `values` as a data entry of `schema`, or null when it accepts them.
6
+ *
7
+ * Only the verdict is read: a pruning validator (`typia.plain.createValidatePrune`) drops undeclared
8
+ * keys from what it validates, so it gets a copy and the caller stores `values` as they are, keys
9
+ * written outside the form included.
10
+ */
11
+ export function validateEntryData(schema: HostSchema, values: DataCollectionEntry['data']): string | null {
12
+ const result = schema.validate(structuredClone(values));
13
+ if (result.success) return null;
14
+ const fields = result.errors.map((error) => `${error.path.replace(/^\$input\./, '')} (expected ${error.expected})`);
15
+ return `Fix these fields before saving: ${fields.join(', ')}`;
16
+ }