@byline/core 0.9.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/LICENSE +373 -0
- package/README.md +17 -0
- package/dist/@types/admin-types.d.ts +275 -0
- package/dist/@types/admin-types.d.ts.map +1 -0
- package/dist/@types/admin-types.js +18 -0
- package/dist/@types/admin-types.js.map +1 -0
- package/dist/@types/collection-types.d.ts +816 -0
- package/dist/@types/collection-types.d.ts.map +1 -0
- package/dist/@types/collection-types.js +217 -0
- package/dist/@types/collection-types.js.map +1 -0
- package/dist/@types/db-types.d.ts +463 -0
- package/dist/@types/db-types.d.ts.map +1 -0
- package/dist/@types/db-types.js +2 -0
- package/dist/@types/db-types.js.map +1 -0
- package/dist/@types/field-data-types.d.ts +147 -0
- package/dist/@types/field-data-types.d.ts.map +1 -0
- package/dist/@types/field-data-types.js +38 -0
- package/dist/@types/field-data-types.js.map +1 -0
- package/dist/@types/field-types.d.ts +579 -0
- package/dist/@types/field-types.d.ts.map +1 -0
- package/dist/@types/field-types.js +32 -0
- package/dist/@types/field-types.js.map +1 -0
- package/dist/@types/index.d.ts +18 -0
- package/dist/@types/index.d.ts.map +1 -0
- package/dist/@types/index.js +18 -0
- package/dist/@types/index.js.map +1 -0
- package/dist/@types/populate-types.d.ts +54 -0
- package/dist/@types/populate-types.d.ts.map +1 -0
- package/dist/@types/populate-types.js +9 -0
- package/dist/@types/populate-types.js.map +1 -0
- package/dist/@types/query-predicate.d.ts +74 -0
- package/dist/@types/query-predicate.d.ts.map +1 -0
- package/dist/@types/query-predicate.js +9 -0
- package/dist/@types/query-predicate.js.map +1 -0
- package/dist/@types/site-config.d.ts +212 -0
- package/dist/@types/site-config.d.ts.map +1 -0
- package/dist/@types/site-config.js +9 -0
- package/dist/@types/site-config.js.map +1 -0
- package/dist/@types/storage-types.d.ts +86 -0
- package/dist/@types/storage-types.d.ts.map +1 -0
- package/dist/@types/storage-types.js +9 -0
- package/dist/@types/storage-types.js.map +1 -0
- package/dist/@types/store-types.d.ts +134 -0
- package/dist/@types/store-types.d.ts.map +1 -0
- package/dist/@types/store-types.js +24 -0
- package/dist/@types/store-types.js.map +1 -0
- package/dist/@types/type-utils.d.ts +17 -0
- package/dist/@types/type-utils.d.ts.map +1 -0
- package/dist/@types/type-utils.js +9 -0
- package/dist/@types/type-utils.js.map +1 -0
- package/dist/auth/apply-before-read.d.ts +36 -0
- package/dist/auth/apply-before-read.d.ts.map +1 -0
- package/dist/auth/apply-before-read.js +68 -0
- package/dist/auth/apply-before-read.js.map +1 -0
- package/dist/auth/apply-before-read.test.node.d.ts +9 -0
- package/dist/auth/apply-before-read.test.node.d.ts.map +1 -0
- package/dist/auth/apply-before-read.test.node.js +144 -0
- package/dist/auth/apply-before-read.test.node.js.map +1 -0
- package/dist/auth/assert-actor-can-perform.d.ts +39 -0
- package/dist/auth/assert-actor-can-perform.d.ts.map +1 -0
- package/dist/auth/assert-actor-can-perform.js +64 -0
- package/dist/auth/assert-actor-can-perform.js.map +1 -0
- package/dist/auth/assert-actor-can-perform.test.node.d.ts +9 -0
- package/dist/auth/assert-actor-can-perform.test.node.d.ts.map +1 -0
- package/dist/auth/assert-actor-can-perform.test.node.js +119 -0
- package/dist/auth/assert-actor-can-perform.test.node.js.map +1 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +11 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/register-collection-abilities.d.ts +40 -0
- package/dist/auth/register-collection-abilities.d.ts.map +1 -0
- package/dist/auth/register-collection-abilities.js +87 -0
- package/dist/auth/register-collection-abilities.js.map +1 -0
- package/dist/auth/register-collection-abilities.test.node.d.ts +9 -0
- package/dist/auth/register-collection-abilities.test.node.d.ts.map +1 -0
- package/dist/auth/register-collection-abilities.test.node.js +124 -0
- package/dist/auth/register-collection-abilities.test.node.js.map +1 -0
- package/dist/config/config.d.ts +10 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +108 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/routes.d.ts +16 -0
- package/dist/config/routes.d.ts.map +1 -0
- package/dist/config/routes.js +26 -0
- package/dist/config/routes.js.map +1 -0
- package/dist/config/validate-admin-configs.d.ts +33 -0
- package/dist/config/validate-admin-configs.d.ts.map +1 -0
- package/dist/config/validate-admin-configs.js +250 -0
- package/dist/config/validate-admin-configs.js.map +1 -0
- package/dist/config/validate-admin-configs.test.node.d.ts +9 -0
- package/dist/config/validate-admin-configs.test.node.d.ts.map +1 -0
- package/dist/config/validate-admin-configs.test.node.js +224 -0
- package/dist/config/validate-admin-configs.test.node.js.map +1 -0
- package/dist/config/validate-collections.d.ts +33 -0
- package/dist/config/validate-collections.d.ts.map +1 -0
- package/dist/config/validate-collections.js +70 -0
- package/dist/config/validate-collections.js.map +1 -0
- package/dist/config/validate-collections.test.node.d.ts +9 -0
- package/dist/config/validate-collections.test.node.d.ts.map +1 -0
- package/dist/config/validate-collections.test.node.js +149 -0
- package/dist/config/validate-collections.test.node.js.map +1 -0
- package/dist/core.d.ts +89 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +99 -0
- package/dist/core.js.map +1 -0
- package/dist/defaults/default-values.d.ts +13 -0
- package/dist/defaults/default-values.d.ts.map +1 -0
- package/dist/defaults/default-values.js +60 -0
- package/dist/defaults/default-values.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/errors.d.ts +98 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +134 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/logger.d.ts +62 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +120 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/registry.d.ts +65 -0
- package/dist/lib/registry.d.ts.map +1 -0
- package/dist/lib/registry.js +133 -0
- package/dist/lib/registry.js.map +1 -0
- package/dist/logger/index.d.ts +3 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +3 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/patches/apply-patches.d.ts +21 -0
- package/dist/patches/apply-patches.d.ts.map +1 -0
- package/dist/patches/apply-patches.js +357 -0
- package/dist/patches/apply-patches.js.map +1 -0
- package/dist/patches/index.d.ts +3 -0
- package/dist/patches/index.d.ts.map +1 -0
- package/dist/patches/index.js +4 -0
- package/dist/patches/index.js.map +1 -0
- package/dist/patches/patch-types.d.ts +82 -0
- package/dist/patches/patch-types.d.ts.map +1 -0
- package/dist/patches/patch-types.js +3 -0
- package/dist/patches/patch-types.js.map +1 -0
- package/dist/patches/patch.test.node.d.ts +2 -0
- package/dist/patches/patch.test.node.d.ts.map +1 -0
- package/dist/patches/patch.test.node.js +193 -0
- package/dist/patches/patch.test.node.js.map +1 -0
- package/dist/query/parse-where.d.ts +100 -0
- package/dist/query/parse-where.d.ts.map +1 -0
- package/dist/query/parse-where.js +352 -0
- package/dist/query/parse-where.js.map +1 -0
- package/dist/query/parse-where.test.node.d.ts +9 -0
- package/dist/query/parse-where.test.node.d.ts.map +1 -0
- package/dist/query/parse-where.test.node.js +581 -0
- package/dist/query/parse-where.test.node.js.map +1 -0
- package/dist/schemas/zod/builder.d.ts +466 -0
- package/dist/schemas/zod/builder.d.ts.map +1 -0
- package/dist/schemas/zod/builder.js +276 -0
- package/dist/schemas/zod/builder.js.map +1 -0
- package/dist/schemas/zod/cache.d.ts +14 -0
- package/dist/schemas/zod/cache.d.ts.map +1 -0
- package/dist/schemas/zod/cache.js +40 -0
- package/dist/schemas/zod/cache.js.map +1 -0
- package/dist/schemas/zod/index.d.ts +4 -0
- package/dist/schemas/zod/index.d.ts.map +1 -0
- package/dist/schemas/zod/index.js +4 -0
- package/dist/schemas/zod/index.js.map +1 -0
- package/dist/schemas/zod/types.d.ts +13 -0
- package/dist/schemas/zod/types.d.ts.map +1 -0
- package/dist/schemas/zod/types.js +2 -0
- package/dist/schemas/zod/types.js.map +1 -0
- package/dist/services/collection-bootstrap.d.ts +46 -0
- package/dist/services/collection-bootstrap.d.ts.map +1 -0
- package/dist/services/collection-bootstrap.js +108 -0
- package/dist/services/collection-bootstrap.js.map +1 -0
- package/dist/services/collection-bootstrap.test.node.d.ts +9 -0
- package/dist/services/collection-bootstrap.test.node.d.ts.map +1 -0
- package/dist/services/collection-bootstrap.test.node.js +208 -0
- package/dist/services/collection-bootstrap.test.node.js.map +1 -0
- package/dist/services/document-lifecycle.d.ts +245 -0
- package/dist/services/document-lifecycle.d.ts.map +1 -0
- package/dist/services/document-lifecycle.js +481 -0
- package/dist/services/document-lifecycle.js.map +1 -0
- package/dist/services/document-lifecycle.test.node.d.ts +9 -0
- package/dist/services/document-lifecycle.test.node.d.ts.map +1 -0
- package/dist/services/document-lifecycle.test.node.js +781 -0
- package/dist/services/document-lifecycle.test.node.js.map +1 -0
- package/dist/services/document-read.d.ts +26 -0
- package/dist/services/document-read.d.ts.map +1 -0
- package/dist/services/document-read.js +60 -0
- package/dist/services/document-read.js.map +1 -0
- package/dist/services/field-upload.d.ts +100 -0
- package/dist/services/field-upload.d.ts.map +1 -0
- package/dist/services/field-upload.js +328 -0
- package/dist/services/field-upload.js.map +1 -0
- package/dist/services/field-upload.test.node.d.ts +9 -0
- package/dist/services/field-upload.test.node.d.ts.map +1 -0
- package/dist/services/field-upload.test.node.js +337 -0
- package/dist/services/field-upload.test.node.js.map +1 -0
- package/dist/services/index.d.ts +10 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +11 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/populate.d.ts +299 -0
- package/dist/services/populate.d.ts.map +1 -0
- package/dist/services/populate.js +484 -0
- package/dist/services/populate.js.map +1 -0
- package/dist/services/populate.test.node.d.ts +9 -0
- package/dist/services/populate.test.node.d.ts.map +1 -0
- package/dist/services/populate.test.node.js +910 -0
- package/dist/services/populate.test.node.js.map +1 -0
- package/dist/services/relation-projection.d.ts +52 -0
- package/dist/services/relation-projection.d.ts.map +1 -0
- package/dist/services/relation-projection.js +81 -0
- package/dist/services/relation-projection.js.map +1 -0
- package/dist/services/richtext-populate.d.ts +87 -0
- package/dist/services/richtext-populate.d.ts.map +1 -0
- package/dist/services/richtext-populate.js +189 -0
- package/dist/services/richtext-populate.js.map +1 -0
- package/dist/services/richtext-populate.test.node.d.ts +9 -0
- package/dist/services/richtext-populate.test.node.d.ts.map +1 -0
- package/dist/services/richtext-populate.test.node.js +197 -0
- package/dist/services/richtext-populate.test.node.js.map +1 -0
- package/dist/storage/collection-fingerprint.d.ts +21 -0
- package/dist/storage/collection-fingerprint.d.ts.map +1 -0
- package/dist/storage/collection-fingerprint.js +172 -0
- package/dist/storage/collection-fingerprint.js.map +1 -0
- package/dist/storage/collection-fingerprint.test.node.d.ts +9 -0
- package/dist/storage/collection-fingerprint.test.node.d.ts.map +1 -0
- package/dist/storage/collection-fingerprint.test.node.js +256 -0
- package/dist/storage/collection-fingerprint.test.node.js.map +1 -0
- package/dist/storage/field-store-map.d.ts +59 -0
- package/dist/storage/field-store-map.d.ts.map +1 -0
- package/dist/storage/field-store-map.js +75 -0
- package/dist/storage/field-store-map.js.map +1 -0
- package/dist/storage/field-store-map.test.node.d.ts +9 -0
- package/dist/storage/field-store-map.test.node.d.ts.map +1 -0
- package/dist/storage/field-store-map.test.node.js +117 -0
- package/dist/storage/field-store-map.test.node.js.map +1 -0
- package/dist/storage/index.d.ts +10 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +10 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/utils/normalise-dates.d.ts +15 -0
- package/dist/utils/normalise-dates.d.ts.map +1 -0
- package/dist/utils/normalise-dates.js +22 -0
- package/dist/utils/normalise-dates.js.map +1 -0
- package/dist/utils/slugify.d.ts +56 -0
- package/dist/utils/slugify.d.ts.map +1 -0
- package/dist/utils/slugify.js +91 -0
- package/dist/utils/slugify.js.map +1 -0
- package/dist/utils/slugify.test.node.d.ts +9 -0
- package/dist/utils/slugify.test.node.d.ts.map +1 -0
- package/dist/utils/slugify.test.node.js +86 -0
- package/dist/utils/slugify.test.node.js.map +1 -0
- package/dist/utils/storage-utils.d.ts +36 -0
- package/dist/utils/storage-utils.d.ts.map +1 -0
- package/dist/utils/storage-utils.js +38 -0
- package/dist/utils/storage-utils.js.map +1 -0
- package/dist/utils/utils.general.d.ts +64 -0
- package/dist/utils/utils.general.d.ts.map +1 -0
- package/dist/utils/utils.general.js +219 -0
- package/dist/utils/utils.general.js.map +1 -0
- package/dist/validation/index.d.ts +9 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +9 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/shared.d.ts +36 -0
- package/dist/validation/shared.d.ts.map +1 -0
- package/dist/validation/shared.js +42 -0
- package/dist/validation/shared.js.map +1 -0
- package/dist/workflow/index.d.ts +2 -0
- package/dist/workflow/index.d.ts.map +1 -0
- package/dist/workflow/index.js +3 -0
- package/dist/workflow/index.js.map +1 -0
- package/dist/workflow/workflow.d.ts +40 -0
- package/dist/workflow/workflow.d.ts.map +1 -0
- package/dist/workflow/workflow.js +96 -0
- package/dist/workflow/workflow.js.map +1 -0
- package/dist/workflow/workflow.test.node.d.ts +2 -0
- package/dist/workflow/workflow.test.node.d.ts.map +1 -0
- package/dist/workflow/workflow.test.node.js +198 -0
- package/dist/workflow/workflow.test.node.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Type guard to check if a StoredFileValue represents a pending (not yet uploaded) file.
|
|
10
|
+
*/
|
|
11
|
+
export function isPendingStoredFileValue(value) {
|
|
12
|
+
if (!value || typeof value !== 'object')
|
|
13
|
+
return false;
|
|
14
|
+
const v = value;
|
|
15
|
+
return v.storageProvider === 'pending';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a pending placeholder value for a file that is selected but not yet uploaded.
|
|
19
|
+
*/
|
|
20
|
+
export function createPendingStoredFileValue(file, previewUrl, dimensions) {
|
|
21
|
+
return {
|
|
22
|
+
fileId: `pending-${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
23
|
+
filename: file.name,
|
|
24
|
+
originalFilename: file.name,
|
|
25
|
+
mimeType: file.type,
|
|
26
|
+
fileSize: String(file.size),
|
|
27
|
+
storageProvider: 'pending',
|
|
28
|
+
storagePath: '',
|
|
29
|
+
storageUrl: previewUrl,
|
|
30
|
+
fileHash: null,
|
|
31
|
+
imageWidth: dimensions?.width ?? null,
|
|
32
|
+
imageHeight: dimensions?.height ?? null,
|
|
33
|
+
imageFormat: null,
|
|
34
|
+
processingStatus: 'pending',
|
|
35
|
+
thumbnailGenerated: false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=field-data-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-data-types.js","sourceRoot":"","sources":["../../src/@types/field-data-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA+MH;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IACrD,MAAM,CAAC,GAAG,KAAiC,CAAA;IAC3C,OAAO,CAAC,CAAC,eAAe,KAAK,SAAS,CAAA;AACxC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,4BAA4B,CAC1C,IAAU,EACV,UAAkB,EAClB,UAA8C;IAE9C,OAAO;QACL,MAAM,EAAE,WAAW,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QACtE,QAAQ,EAAE,IAAI,CAAC,IAAI;QACnB,gBAAgB,EAAE,IAAI,CAAC,IAAI;QAC3B,QAAQ,EAAE,IAAI,CAAC,IAAI;QACnB,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;QAC3B,eAAe,EAAE,SAAS;QAC1B,WAAW,EAAE,EAAE;QACf,UAAU,EAAE,UAAU;QACtB,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,UAAU,EAAE,KAAK,IAAI,IAAI;QACrC,WAAW,EAAE,UAAU,EAAE,MAAM,IAAI,IAAI;QACvC,WAAW,EAAE,IAAI;QACjB,gBAAgB,EAAE,SAAS;QAC3B,kBAAkB,EAAE,KAAK;KAC1B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
import type { UploadConfig } from './collection-types.js';
|
|
9
|
+
import type { MaybePromise, NonEmptyArray } from './type-utils.js';
|
|
10
|
+
/**
|
|
11
|
+
* Context passed to functions that generate default values for fields,
|
|
12
|
+
* containing the current document data, locale, and a few helper functions.
|
|
13
|
+
*/
|
|
14
|
+
export interface DefaultValueContext {
|
|
15
|
+
/**
|
|
16
|
+
* The current document data as it is being built/edited. Defaults may read
|
|
17
|
+
* other field values from here.
|
|
18
|
+
*/
|
|
19
|
+
data: Record<string, any>;
|
|
20
|
+
/**
|
|
21
|
+
* Current locale (when defaults are locale-aware).
|
|
22
|
+
*/
|
|
23
|
+
locale?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Clock access for time-based defaults.
|
|
26
|
+
*/
|
|
27
|
+
now: () => Date;
|
|
28
|
+
/**
|
|
29
|
+
* UUID generator for defaults that need stable IDs.
|
|
30
|
+
*/
|
|
31
|
+
uuid?: () => string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A function that generates a default value for a field
|
|
35
|
+
*/
|
|
36
|
+
type DefaultValueFn<T> = (ctx: DefaultValueContext) => T | Promise<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Either an actual default value, or a function that generates one
|
|
39
|
+
*/
|
|
40
|
+
export type DefaultValue<T = unknown> = T | DefaultValueFn<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Context passed to field-level hooks. Gives the hook access to the changing
|
|
43
|
+
* value, the previous value, the full document data, and the field definition.
|
|
44
|
+
*/
|
|
45
|
+
export interface FieldHookContext {
|
|
46
|
+
/**
|
|
47
|
+
* The incoming value (after the user edit).
|
|
48
|
+
*/
|
|
49
|
+
value: any;
|
|
50
|
+
/**
|
|
51
|
+
* The value before this edit.
|
|
52
|
+
*/
|
|
53
|
+
previousValue: any;
|
|
54
|
+
/**
|
|
55
|
+
* Current document data (full form state).
|
|
56
|
+
*/
|
|
57
|
+
data: Record<string, any>;
|
|
58
|
+
/**
|
|
59
|
+
* Dot-path of the field inside the document, e.g. `"content.0.richText"`.
|
|
60
|
+
*/
|
|
61
|
+
path: string;
|
|
62
|
+
/**
|
|
63
|
+
* The field definition this hook is attached to.
|
|
64
|
+
*/
|
|
65
|
+
field: Field;
|
|
66
|
+
/**
|
|
67
|
+
* `'change'` — fired on every keystroke / field edit.
|
|
68
|
+
* `'submit'` — fired once during form submit, before `validateForm()`.
|
|
69
|
+
*
|
|
70
|
+
* Hooks can use this to vary behaviour, e.g. only auto-populate a
|
|
71
|
+
* derived value at submit time while showing advisory errors on change.
|
|
72
|
+
*/
|
|
73
|
+
operation: 'change' | 'submit';
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Return type of `beforeValidate` hooks.
|
|
77
|
+
*/
|
|
78
|
+
export interface FieldBeforeValidateResult {
|
|
79
|
+
/** If set, the change is blocked and this message is shown as a field error. */
|
|
80
|
+
error?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A single `beforeValidate` hook function
|
|
84
|
+
*/
|
|
85
|
+
export type FieldBeforeValidateFn = (ctx: FieldHookContext) => MaybePromise<FieldBeforeValidateResult | void>;
|
|
86
|
+
/**
|
|
87
|
+
* Return type of `beforeChange`. Allows the hook to:
|
|
88
|
+
* - replace the value (`value`),
|
|
89
|
+
* - reject the change with a per-field error (`error`),
|
|
90
|
+
* - or do nothing (return `undefined` / `{}`).
|
|
91
|
+
*/
|
|
92
|
+
export interface FieldBeforeChangeResult {
|
|
93
|
+
/** If set, this value replaces the incoming value. */
|
|
94
|
+
value?: any;
|
|
95
|
+
/** If set, the change is blocked and this message is shown as a field error. */
|
|
96
|
+
error?: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A single beforeChange hook function.
|
|
100
|
+
*/
|
|
101
|
+
export type FieldBeforeChangeFn = (ctx: FieldHookContext) => MaybePromise<FieldBeforeChangeResult | void>;
|
|
102
|
+
/**
|
|
103
|
+
* Hooks that can be attached to any field via the `hooks` property on the
|
|
104
|
+
* field definition. Both hooks are async-capable to support debounced
|
|
105
|
+
* remote validation or similar patterns.
|
|
106
|
+
*
|
|
107
|
+
* Each hook accepts a single function or an **array** of functions that
|
|
108
|
+
* are executed in order. Execution stops at the first function that
|
|
109
|
+
* returns `{ error }` (for blocking hooks like `beforeChange`).
|
|
110
|
+
*/
|
|
111
|
+
export interface FieldHooks {
|
|
112
|
+
/**
|
|
113
|
+
* Fires **before** the built-in validation rules are evaluated.
|
|
114
|
+
*
|
|
115
|
+
* This hook is **advisory**: the value is always committed to the form
|
|
116
|
+
* store regardless of the result. Returning `{ error }` displays a
|
|
117
|
+
* per-field error (useful for live validation feedback) but does **not**
|
|
118
|
+
* block the change — the user can keep typing.
|
|
119
|
+
*/
|
|
120
|
+
beforeValidate?: FieldBeforeValidateFn | FieldBeforeValidateFn[];
|
|
121
|
+
/**
|
|
122
|
+
* Fires **after** `beforeValidate` but **before** the value is committed
|
|
123
|
+
* to the form store and a patch is emitted.
|
|
124
|
+
*
|
|
125
|
+
* Returning `{ value }` substitutes the committed value (e.g. trim, slug).
|
|
126
|
+
* Returning `{ error }` **blocks** the change — the value is not written.
|
|
127
|
+
*
|
|
128
|
+
* ⚠️ Value transformations will reset the cursor position in text inputs.
|
|
129
|
+
* Prefer `beforeValidate` for feedback that should not interfere with typing.
|
|
130
|
+
*/
|
|
131
|
+
beforeChange?: FieldBeforeChangeFn | FieldBeforeChangeFn[];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Normalise a hook slot (single function or array) into a flat array.
|
|
135
|
+
*/
|
|
136
|
+
export declare function normalizeHooks<T>(hook: T | T[] | undefined): T[];
|
|
137
|
+
export interface ValidationRule {
|
|
138
|
+
type: 'min' | 'max' | 'pattern' | 'custom' | 'email' | 'url';
|
|
139
|
+
value: any;
|
|
140
|
+
message?: string;
|
|
141
|
+
}
|
|
142
|
+
type FieldValidateFn = (value: any, data: Record<string, any>) => string | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Base properties shared by all fields
|
|
145
|
+
*/
|
|
146
|
+
interface BaseField {
|
|
147
|
+
name: string;
|
|
148
|
+
label?: string;
|
|
149
|
+
helpText?: string;
|
|
150
|
+
placeholder?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Is this field optional or required? Fields are required by default; set
|
|
153
|
+
* this to `true` to make the field optional. If the field is required, a
|
|
154
|
+
* value must be provided (possibly via a default value or hook) for the
|
|
155
|
+
* document to be considered valid.
|
|
156
|
+
*/
|
|
157
|
+
optional?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Optional field-level hooks that run on the client during editing.
|
|
160
|
+
* @see FieldHooks
|
|
161
|
+
*/
|
|
162
|
+
hooks?: FieldHooks;
|
|
163
|
+
/**
|
|
164
|
+
* Optional submit-time validator. Called by `validateForm()` for every field
|
|
165
|
+
* type — including structure fields (group, array, blocks).
|
|
166
|
+
*
|
|
167
|
+
* Receives the resolved field value (lodash `get` on the full form store, so
|
|
168
|
+
* group fields arrive as their assembled value, e.g. `[{en:true},{fr:false}]`)
|
|
169
|
+
* and the complete form data snapshot.
|
|
170
|
+
*
|
|
171
|
+
* Return a non-empty string to block submission and display the message as a
|
|
172
|
+
* field-level error. Return `undefined` (or nothing) to pass.
|
|
173
|
+
*/
|
|
174
|
+
validate?: FieldValidateFn;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Base for fields that support localization (i.e. may be configured to have
|
|
178
|
+
* separate values per locale).
|
|
179
|
+
*/
|
|
180
|
+
interface LocalizableField extends BaseField {
|
|
181
|
+
localized?: boolean;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Base for fields that do not support localization (i.e. always have a single
|
|
185
|
+
* value across all locales).
|
|
186
|
+
*/
|
|
187
|
+
interface NonlocalizableField extends BaseField {
|
|
188
|
+
localized?: false;
|
|
189
|
+
}
|
|
190
|
+
export interface GroupField extends NonlocalizableField {
|
|
191
|
+
type: 'group';
|
|
192
|
+
fields: FieldSet;
|
|
193
|
+
}
|
|
194
|
+
export interface ArrayField extends NonlocalizableField {
|
|
195
|
+
type: 'array';
|
|
196
|
+
fields: FieldSet;
|
|
197
|
+
validation?: {
|
|
198
|
+
minLength?: number;
|
|
199
|
+
maxLength?: number;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
export interface Block {
|
|
203
|
+
blockType: string;
|
|
204
|
+
fields: FieldSet;
|
|
205
|
+
label?: string;
|
|
206
|
+
helpText?: string;
|
|
207
|
+
hooks?: FieldHooks;
|
|
208
|
+
validate?: FieldValidateFn;
|
|
209
|
+
}
|
|
210
|
+
export interface BlocksField extends NonlocalizableField {
|
|
211
|
+
type: 'blocks';
|
|
212
|
+
blocks: Block[];
|
|
213
|
+
}
|
|
214
|
+
export interface TextField extends LocalizableField {
|
|
215
|
+
type: 'text';
|
|
216
|
+
defaultValue?: DefaultValue<string>;
|
|
217
|
+
validation?: {
|
|
218
|
+
minLength?: number;
|
|
219
|
+
maxLength?: number;
|
|
220
|
+
pattern?: string;
|
|
221
|
+
rules?: ValidationRule[];
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
export interface TextAreaField extends LocalizableField {
|
|
225
|
+
type: 'textArea';
|
|
226
|
+
defaultValue?: DefaultValue<string>;
|
|
227
|
+
validation?: {
|
|
228
|
+
minLength?: number;
|
|
229
|
+
maxLength?: number;
|
|
230
|
+
pattern?: string;
|
|
231
|
+
rules?: ValidationRule[];
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
export interface CheckboxField extends NonlocalizableField {
|
|
235
|
+
type: 'checkbox';
|
|
236
|
+
defaultValue?: DefaultValue<boolean>;
|
|
237
|
+
}
|
|
238
|
+
export interface BooleanField extends NonlocalizableField {
|
|
239
|
+
type: 'boolean';
|
|
240
|
+
defaultValue?: DefaultValue<boolean>;
|
|
241
|
+
}
|
|
242
|
+
export interface SelectFieldOption {
|
|
243
|
+
label: string;
|
|
244
|
+
value: string;
|
|
245
|
+
}
|
|
246
|
+
export interface SelectField<Options extends NonEmptyArray<SelectFieldOption> = NonEmptyArray<SelectFieldOption>> extends NonlocalizableField {
|
|
247
|
+
type: 'select';
|
|
248
|
+
options: Options;
|
|
249
|
+
defaultValue?: DefaultValue<Options[number]['value']>;
|
|
250
|
+
}
|
|
251
|
+
export interface RichTextField extends LocalizableField {
|
|
252
|
+
type: 'richText';
|
|
253
|
+
defaultValue?: DefaultValue<unknown>;
|
|
254
|
+
validation?: {
|
|
255
|
+
minLength?: number;
|
|
256
|
+
maxLength?: number;
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Editor-specific configuration. The shape is opaque to `@byline/core` —
|
|
260
|
+
* each editor adapter defines what it accepts. For `@byline/richtext-lexical`
|
|
261
|
+
* this is its `EditorConfig`. Per-field config takes precedence over any
|
|
262
|
+
* baked-in config supplied at registration via `lexicalEditor()`.
|
|
263
|
+
*/
|
|
264
|
+
editorConfig?: unknown;
|
|
265
|
+
/**
|
|
266
|
+
* **Write-time strategy.** When `true`, the editor's relation-bearing
|
|
267
|
+
* nodes (internal links, inline images, …) embed a small projection of
|
|
268
|
+
* the picked target's fields directly into the persisted JSON at
|
|
269
|
+
* modal-save time. Defaults to `true`.
|
|
270
|
+
*
|
|
271
|
+
* Set to `false` only when the field will be served by read-time
|
|
272
|
+
* populate (see `populateRelationsOnRead`). Without populate, public
|
|
273
|
+
* renderers see a stripped envelope (relation primary keys only) and
|
|
274
|
+
* have no title / path / image to render.
|
|
275
|
+
*
|
|
276
|
+
* Adapter-agnostic — any future editor adapter with relation-bearing
|
|
277
|
+
* nodes inherits the same lever.
|
|
278
|
+
*/
|
|
279
|
+
embedRelationsOnSave?: boolean;
|
|
280
|
+
/**
|
|
281
|
+
* **Read-time strategy.** When `true`, the framework's read pipeline
|
|
282
|
+
* walks this field's value on every read and asks the registered
|
|
283
|
+
* richtext populate function to refresh embedded relation envelopes
|
|
284
|
+
* against their source documents.
|
|
285
|
+
*
|
|
286
|
+
* Default is the inverse of `embedRelationsOnSave`:
|
|
287
|
+
* - `embedRelationsOnSave: true` → defaults to `false` (snapshot mode).
|
|
288
|
+
* - `embedRelationsOnSave: false` → defaults to `true` (storage-thin).
|
|
289
|
+
*
|
|
290
|
+
* Set both to `true` for belt-and-braces: embed at write, refresh on
|
|
291
|
+
* read. Setting both to `false` is invalid — `initBylineCore()` rejects
|
|
292
|
+
* fields where neither write-time nor read-time would render.
|
|
293
|
+
*
|
|
294
|
+
* Requires a registered `ServerConfig.fields.richText.populate` adapter
|
|
295
|
+
* when effectively `true`; otherwise `initBylineCore()` throws.
|
|
296
|
+
*/
|
|
297
|
+
populateRelationsOnRead?: boolean;
|
|
298
|
+
}
|
|
299
|
+
export interface TimeField extends NonlocalizableField {
|
|
300
|
+
type: 'time';
|
|
301
|
+
defaultValue?: DefaultValue<'00:00' | string>;
|
|
302
|
+
}
|
|
303
|
+
export interface DateField extends NonlocalizableField {
|
|
304
|
+
type: 'date';
|
|
305
|
+
defaultValue?: DefaultValue<Date>;
|
|
306
|
+
}
|
|
307
|
+
export interface DateTimeField extends NonlocalizableField {
|
|
308
|
+
type: 'datetime';
|
|
309
|
+
mode?: 'date' | 'datetime';
|
|
310
|
+
yearsInFuture?: number;
|
|
311
|
+
yearsInPast?: number;
|
|
312
|
+
defaultValue?: DefaultValue<Date>;
|
|
313
|
+
}
|
|
314
|
+
export interface FloatField extends NonlocalizableField {
|
|
315
|
+
type: 'float';
|
|
316
|
+
defaultValue?: DefaultValue<number>;
|
|
317
|
+
validation?: {
|
|
318
|
+
min?: number;
|
|
319
|
+
max?: number;
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
export interface IntegerField extends NonlocalizableField {
|
|
323
|
+
type: 'integer';
|
|
324
|
+
defaultValue?: DefaultValue<number>;
|
|
325
|
+
validation?: {
|
|
326
|
+
min?: number;
|
|
327
|
+
max?: number;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
export interface DecimalField extends NonlocalizableField {
|
|
331
|
+
type: 'decimal';
|
|
332
|
+
defaultValue?: DefaultValue<string>;
|
|
333
|
+
}
|
|
334
|
+
export interface JsonField extends LocalizableField {
|
|
335
|
+
type: 'json';
|
|
336
|
+
defaultValue?: DefaultValue<unknown>;
|
|
337
|
+
}
|
|
338
|
+
export interface ObjectField extends LocalizableField {
|
|
339
|
+
type: 'object';
|
|
340
|
+
defaultValue?: DefaultValue<Record<string, any>>;
|
|
341
|
+
}
|
|
342
|
+
export interface RelationField extends NonlocalizableField {
|
|
343
|
+
type: 'relation';
|
|
344
|
+
/**
|
|
345
|
+
* The `path` of the target collection (e.g. `'media'` or `'authors'`). The
|
|
346
|
+
* field picker will query this collection when selecting a reference.
|
|
347
|
+
*/
|
|
348
|
+
targetCollection: string;
|
|
349
|
+
/**
|
|
350
|
+
* Field name from the target collection to display in the picker and inline
|
|
351
|
+
* summary. Falls back to the first text field if omitted.
|
|
352
|
+
*/
|
|
353
|
+
displayField?: string;
|
|
354
|
+
}
|
|
355
|
+
export interface FileField extends NonlocalizableField {
|
|
356
|
+
type: 'file';
|
|
357
|
+
/**
|
|
358
|
+
* Per-field upload configuration. When set, this field is upload-capable —
|
|
359
|
+
* the auto-mounted route at `POST /admin/api/<collection-path>/upload`
|
|
360
|
+
* accepts `field=<name>` to target it. Carries MIME / size constraints,
|
|
361
|
+
* variant definitions, storage routing, and `beforeStore` / `afterStore`
|
|
362
|
+
* hooks.
|
|
363
|
+
*
|
|
364
|
+
* @see UploadConfig
|
|
365
|
+
*/
|
|
366
|
+
upload?: UploadConfig;
|
|
367
|
+
}
|
|
368
|
+
export interface ImageField extends NonlocalizableField {
|
|
369
|
+
type: 'image';
|
|
370
|
+
/**
|
|
371
|
+
* Per-field upload configuration. When set, this field is upload-capable —
|
|
372
|
+
* the auto-mounted route at `POST /admin/api/<collection-path>/upload`
|
|
373
|
+
* accepts `field=<name>` to target it. Carries MIME / size constraints,
|
|
374
|
+
* variant definitions, storage routing, and `beforeStore` / `afterStore`
|
|
375
|
+
* hooks.
|
|
376
|
+
*
|
|
377
|
+
* @see UploadConfig
|
|
378
|
+
*/
|
|
379
|
+
upload?: UploadConfig;
|
|
380
|
+
}
|
|
381
|
+
export type StructureField = GroupField | ArrayField | BlocksField;
|
|
382
|
+
export type ValueField = TextField | TextAreaField | CheckboxField | BooleanField | SelectField | RichTextField | TimeField | DateField | DateTimeField | FloatField | IntegerField | DecimalField | JsonField | ObjectField | RelationField | FileField | ImageField;
|
|
383
|
+
export type Field = StructureField | ValueField;
|
|
384
|
+
export type FieldSet = readonly Field[];
|
|
385
|
+
export type ValueFieldType = ValueField['type'];
|
|
386
|
+
export type StructureFieldType = StructureField['type'];
|
|
387
|
+
export type FieldType = Field['type'];
|
|
388
|
+
export type LocalizedField = {
|
|
389
|
+
localized: true;
|
|
390
|
+
};
|
|
391
|
+
export type OptionalField = {
|
|
392
|
+
optional: true;
|
|
393
|
+
};
|
|
394
|
+
export declare function isStructureField(field: Field): field is StructureField;
|
|
395
|
+
export declare function isArrayField(field: Field): field is ArrayField;
|
|
396
|
+
export declare function isBlocksField(field: Field): field is BlocksField;
|
|
397
|
+
export declare function isGroupField(field: Field): field is GroupField;
|
|
398
|
+
export declare function isValueField(field: Field): field is ValueField;
|
|
399
|
+
/**
|
|
400
|
+
* A framework-agnostic component type. In practice will be a React
|
|
401
|
+
* `ComponentType<P>`, but defined here without importing React so that
|
|
402
|
+
* `@byline/core` stays server-safe.
|
|
403
|
+
*/
|
|
404
|
+
export type SlotComponent<P = Record<string, unknown>> = (props: P) => any;
|
|
405
|
+
/**
|
|
406
|
+
* Base props passed to every custom slot component.
|
|
407
|
+
* Slot components also have access to form context via hooks
|
|
408
|
+
* (`useFieldValue`, `useFieldError`, `useFormContext`, etc.) since
|
|
409
|
+
* they render inside the `FormProvider`.
|
|
410
|
+
*/
|
|
411
|
+
export interface FieldSlotBaseProps {
|
|
412
|
+
/** The field definition this slot belongs to. */
|
|
413
|
+
field: Field;
|
|
414
|
+
/** Dot-path of the field in the document, e.g. `"content.0.richText"`. */
|
|
415
|
+
path: string;
|
|
416
|
+
/** Current field value (snapshot at render time). */
|
|
417
|
+
value: any;
|
|
418
|
+
/** Current field error message, if any. */
|
|
419
|
+
error?: string;
|
|
420
|
+
/** HTML `id` for the field element (useful for `htmlFor`). */
|
|
421
|
+
id: string;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Props passed to a custom **Label** slot component.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```tsx
|
|
428
|
+
* const MyLabel: SlotComponent<FieldLabelSlotProps> = ({ label, required }) => (
|
|
429
|
+
* <span>{label}{required && ' *'}</span>
|
|
430
|
+
* )
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
export interface FieldLabelSlotProps extends FieldSlotBaseProps {
|
|
434
|
+
/** The label string from the field definition. */
|
|
435
|
+
label?: string;
|
|
436
|
+
/** Whether the field is required. */
|
|
437
|
+
required?: boolean;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Props passed to a custom **HelpText** slot component.
|
|
441
|
+
*/
|
|
442
|
+
export interface FieldHelpTextSlotProps extends FieldSlotBaseProps {
|
|
443
|
+
/** The help-text string from the field definition. */
|
|
444
|
+
helpText?: string;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Props passed to a custom **Field** (input replacement) slot component.
|
|
448
|
+
*
|
|
449
|
+
* When a `Field` slot is provided it **completely replaces** the default
|
|
450
|
+
* input widget. The component must call `onChange` to commit value changes
|
|
451
|
+
* back to the form store.
|
|
452
|
+
*/
|
|
453
|
+
export interface FieldInputSlotProps extends FieldSlotBaseProps {
|
|
454
|
+
/** Call this to write a new value to the form store (runs the hook pipeline). */
|
|
455
|
+
onChange: (value: any) => void;
|
|
456
|
+
/** Default value for the field. */
|
|
457
|
+
defaultValue?: any;
|
|
458
|
+
/** Placeholder text from the field definition. */
|
|
459
|
+
placeholder?: string;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Props passed to **beforeField** / **afterField** adornment slot components.
|
|
463
|
+
*/
|
|
464
|
+
export interface FieldAdornmentSlotProps extends FieldSlotBaseProps {
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Optional UI component overrides that can be attached to any **value field**.
|
|
468
|
+
*
|
|
469
|
+
* Each slot receives typed props (see individual `*SlotProps` interfaces) and
|
|
470
|
+
* can also use form-context hooks for reactive data.
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
* ```ts
|
|
474
|
+
* {
|
|
475
|
+
* name: 'title',
|
|
476
|
+
* type: 'text',
|
|
477
|
+
* label: 'Title',
|
|
478
|
+
* components: {
|
|
479
|
+
* Label: ({ label }) => <h3>{label}</h3>,
|
|
480
|
+
* afterField: ({ value }) => (
|
|
481
|
+
* <p className="text-xs text-gray-400">{value?.length ?? 0} chars</p>
|
|
482
|
+
* ),
|
|
483
|
+
* },
|
|
484
|
+
* }
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
export interface FieldComponentSlots {
|
|
488
|
+
/**
|
|
489
|
+
* Replaces the default label. Receives `FieldLabelSlotProps`.
|
|
490
|
+
* When provided, the built-in `<Label>` is **not** rendered.
|
|
491
|
+
*/
|
|
492
|
+
Label?: SlotComponent<FieldLabelSlotProps>;
|
|
493
|
+
/**
|
|
494
|
+
* Replaces the default help text. Receives `FieldHelpTextSlotProps`.
|
|
495
|
+
* When provided, the built-in help-text string is **not** rendered.
|
|
496
|
+
*/
|
|
497
|
+
HelpText?: SlotComponent<FieldHelpTextSlotProps>;
|
|
498
|
+
/**
|
|
499
|
+
* Completely replaces the default field input. Receives `FieldInputSlotProps`.
|
|
500
|
+
* When provided the default `<Input>` (or equivalent) is **not** rendered.
|
|
501
|
+
*/
|
|
502
|
+
Field?: SlotComponent<FieldInputSlotProps>;
|
|
503
|
+
/**
|
|
504
|
+
* Rendered **before** the field input (between the label and the input).
|
|
505
|
+
* Receives `FieldAdornmentSlotProps`.
|
|
506
|
+
*/
|
|
507
|
+
beforeField?: SlotComponent<FieldAdornmentSlotProps>;
|
|
508
|
+
/**
|
|
509
|
+
* Rendered **after** the field input (between the input and any help text).
|
|
510
|
+
* Receives `FieldAdornmentSlotProps`.
|
|
511
|
+
*/
|
|
512
|
+
afterField?: SlotComponent<FieldAdornmentSlotProps>;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Props passed to a configured richtext editor component. Mirrors the
|
|
516
|
+
* arguments the field-renderer already supplies for `type: 'richText'`
|
|
517
|
+
* fields, so an adapter package can satisfy the contract by re-exporting
|
|
518
|
+
* a thin wrapper around its underlying editor.
|
|
519
|
+
*
|
|
520
|
+
* Editor packages (e.g. `@byline/richtext-lexical`) expose a component
|
|
521
|
+
* matching this shape, and the installation registers it as the
|
|
522
|
+
* site-wide default via `ClientConfig.fields.richText.editor`.
|
|
523
|
+
*/
|
|
524
|
+
export interface RichTextEditorProps {
|
|
525
|
+
/** The field definition (label / helpText / optional / hooks / validate). */
|
|
526
|
+
field: RichTextField;
|
|
527
|
+
/** Initial value to seed the editor with on first render. */
|
|
528
|
+
defaultValue?: unknown;
|
|
529
|
+
/** Commit a new value to the form store (runs the field hook pipeline). */
|
|
530
|
+
onChange: (value: unknown) => void;
|
|
531
|
+
/** Dot-path of the field in the document, e.g. `"content.0.body"`. */
|
|
532
|
+
path: string;
|
|
533
|
+
/** Stable identity for editor instances; used as a React `key`. */
|
|
534
|
+
instanceKey: string;
|
|
535
|
+
/** Active content locale; the editor may render a locale badge if set. */
|
|
536
|
+
locale?: string;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Component shape an editor package must export to be plugged in via
|
|
540
|
+
* `ClientConfig.fields.richText.editor`. Built on `SlotComponent` so the
|
|
541
|
+
* type stays React-agnostic at the `@byline/core` boundary.
|
|
542
|
+
*/
|
|
543
|
+
export type RichTextEditorComponent = SlotComponent<RichTextEditorProps>;
|
|
544
|
+
/**
|
|
545
|
+
* Context passed to the richtext populate function for one rich-text field
|
|
546
|
+
* value. Mirrors the shape consumed by the relation-field populate
|
|
547
|
+
* primitive — `readContext` is the same request-scoped context, so the
|
|
548
|
+
* visited set / read budget / `afterReadFired` machinery covers rich-text
|
|
549
|
+
* fan-out automatically and any nested reads the adapter performs.
|
|
550
|
+
*
|
|
551
|
+
* The adapter mutates `value` in place — typically by walking the editor's
|
|
552
|
+
* node tree and overwriting embedded relation envelopes. The framework
|
|
553
|
+
* holds the parent reference and reads back the mutated value when
|
|
554
|
+
* shaping the response.
|
|
555
|
+
*/
|
|
556
|
+
export interface RichTextPopulateContext {
|
|
557
|
+
/** The richText field's value (raw editor JSON, possibly stringified). */
|
|
558
|
+
value: unknown;
|
|
559
|
+
/** Field path within the document — e.g. `'body'` or `'content.0.caption'`. */
|
|
560
|
+
fieldPath: string;
|
|
561
|
+
/** Collection path the document belongs to. */
|
|
562
|
+
collectionPath: string;
|
|
563
|
+
/**
|
|
564
|
+
* Shared request-scoped `ReadContext`. Threading is mandatory — adapter
|
|
565
|
+
* implementations must pass this back into any `client.collection(...)`
|
|
566
|
+
* read they perform via `_readContext`.
|
|
567
|
+
*/
|
|
568
|
+
readContext: import('./db-types.js').ReadContext;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Server-side populate function contract. Editor adapters export an
|
|
572
|
+
* implementation; installations register one via
|
|
573
|
+
* `ServerConfig.fields.richText.populate`. Called once per rich-text
|
|
574
|
+
* leaf the framework discovers in a document, gated by each field's
|
|
575
|
+
* `populateRelationsOnRead` flag.
|
|
576
|
+
*/
|
|
577
|
+
export type RichTextPopulateFn = (ctx: RichTextPopulateContext) => Promise<void>;
|
|
578
|
+
export {};
|
|
579
|
+
//# sourceMappingURL=field-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-types.d.ts","sourceRoot":"","sources":["../../src/@types/field-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAWlE;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAEzB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,GAAG,EAAE,MAAM,IAAI,CAAA;IAEf;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,KAAK,cAAc,CAAC,CAAC,IAAI,C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;;OAGG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAA;IAChD;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAA;IAC1C;;;OAGG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC,uBAAuB,CAAC,CAAA;IACpD;;;OAGG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC,uBAAuB,CAAC,CAAA;CACpD;AAMD;;;;;;;;;GASG;AACH,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,KAAK,EAAE,aAAa,CAAA;IACpB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,2EAA2E;IAC3E,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAClC,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAA;IACZ,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAA;IACnB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG,aAAa,CAAC,mBAAmB,CAAC,CAAA;AAMxE;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,uBAAuB;IACtC,0EAA0E;IAC1E,KAAK,EAAE,OAAO,CAAA;IACd,+EAA+E;IAC/E,SAAS,EAAE,MAAM,CAAA;IACjB,+CAA+C;IAC/C,cAAc,EAAE,MAAM,CAAA;IACtB;;;;OAIG;IACH,WAAW,EAAE,OAAO,eAAe,EAAE,WAAW,CAAA;CACjD;AAED;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) Infonomic Company Limited
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Normalise a hook slot (single function or array) into a flat array.
|
|
10
|
+
*/
|
|
11
|
+
export function normalizeHooks(hook) {
|
|
12
|
+
if (!hook)
|
|
13
|
+
return [];
|
|
14
|
+
return Array.isArray(hook) ? hook : [hook];
|
|
15
|
+
}
|
|
16
|
+
// Type guards for field identification
|
|
17
|
+
export function isStructureField(field) {
|
|
18
|
+
return ['array', 'blocks', 'group'].includes(field.type);
|
|
19
|
+
}
|
|
20
|
+
export function isArrayField(field) {
|
|
21
|
+
return field.type === 'array';
|
|
22
|
+
}
|
|
23
|
+
export function isBlocksField(field) {
|
|
24
|
+
return field.type === 'blocks';
|
|
25
|
+
}
|
|
26
|
+
export function isGroupField(field) {
|
|
27
|
+
return field.type === 'group';
|
|
28
|
+
}
|
|
29
|
+
export function isValueField(field) {
|
|
30
|
+
return !isStructureField(field);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=field-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-types.js","sourceRoot":"","sources":["../../src/@types/field-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA4KH;;GAEG;AACH,MAAM,UAAU,cAAc,CAAI,IAAyB;IACzD,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IACpB,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AAC5C,CAAC;AAybD,uCAAuC;AACvC,MAAM,UAAU,gBAAgB,CAAC,KAAY;IAC3C,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAC1D,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAY;IACvC,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,CAAA;AAC/B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAY;IACxC,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAA;AAChC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAY;IACvC,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,CAAA;AAC/B,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAY;IACvC,OAAO,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;AACjC,CAAC"}
|