@lacecms/content 0.1.0-alpha.4 → 0.1.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +378 -38
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +815 -57
- package/dist/index.js.map +1 -1
- package/dist/schema-path.d.ts +8 -0
- package/dist/schema-path.d.ts.map +1 -0
- package/dist/schema-path.js +34 -0
- package/dist/schema-path.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,21 +8,31 @@ export interface JsonObject {
|
|
|
8
8
|
readonly [key: string]: JsonValue;
|
|
9
9
|
}
|
|
10
10
|
/** Field kinds available in the first Lace content-model DSL. */
|
|
11
|
-
export type FieldType = "boolean" | "date" | "datetime" | "media" | "number" | "richText" | "select" | "text" | "textarea" | "url";
|
|
11
|
+
export type FieldType = "boolean" | "date" | "datetime" | "media" | "group" | "list" | "number" | "richText" | "select" | "text" | "textarea" | "url";
|
|
12
12
|
/** Options common to every field builder. */
|
|
13
13
|
export interface CommonFieldOptions<Value> {
|
|
14
14
|
readonly defaultValue?: Value;
|
|
15
15
|
readonly description?: string;
|
|
16
16
|
readonly label?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Temporary synchronization hint naming the field's former key in a content
|
|
19
|
+
* model. Configuration moves it out of the field definition; block fields
|
|
20
|
+
* reject it.
|
|
21
|
+
*/
|
|
22
|
+
readonly renamedFrom?: string;
|
|
17
23
|
readonly required?: boolean;
|
|
18
24
|
}
|
|
25
|
+
/** A prompt on controls with an editable empty text surface. */
|
|
26
|
+
export interface PlaceholderFieldOptions<Value> extends CommonFieldOptions<Value> {
|
|
27
|
+
readonly placeholder?: string;
|
|
28
|
+
}
|
|
19
29
|
/** String-length constraints supported by text and textarea fields. */
|
|
20
|
-
export interface StringFieldOptions extends
|
|
30
|
+
export interface StringFieldOptions extends PlaceholderFieldOptions<string> {
|
|
21
31
|
readonly maxLength?: number;
|
|
22
32
|
readonly minLength?: number;
|
|
23
33
|
}
|
|
24
34
|
/** Numeric bounds supported by number fields. */
|
|
25
|
-
export interface NumberFieldOptions extends
|
|
35
|
+
export interface NumberFieldOptions extends PlaceholderFieldOptions<number> {
|
|
26
36
|
readonly max?: number;
|
|
27
37
|
readonly min?: number;
|
|
28
38
|
}
|
|
@@ -31,10 +41,10 @@ export type BooleanFieldOptions = CommonFieldOptions<boolean>;
|
|
|
31
41
|
/** Options supported by date, datetime, URL, and media fields. */
|
|
32
42
|
export type StringValueFieldOptions = CommonFieldOptions<string>;
|
|
33
43
|
/** Options supported by a safe Tiptap rich-text field. */
|
|
34
|
-
export interface RichTextFieldOptions extends
|
|
44
|
+
export interface RichTextFieldOptions extends PlaceholderFieldOptions<SafeRichTextDocument> {
|
|
35
45
|
}
|
|
36
46
|
/** Options supported by select fields. */
|
|
37
|
-
export interface SelectFieldOptions<Choices extends readonly string[]> extends
|
|
47
|
+
export interface SelectFieldOptions<Choices extends readonly string[]> extends PlaceholderFieldOptions<NoInfer<Choices[number]>> {
|
|
38
48
|
readonly options: Choices;
|
|
39
49
|
}
|
|
40
50
|
type RequiredFrom<Options> = "required" extends keyof Options ? Options extends {
|
|
@@ -50,7 +60,7 @@ type PropertyFrom<Options, Key extends string> = Key extends keyof Options ? Opt
|
|
|
50
60
|
readonly [Name in Key]?: Value;
|
|
51
61
|
} : {} : {};
|
|
52
62
|
type DefaultFrom<Options> = PropertyFrom<Options, "defaultValue">;
|
|
53
|
-
type LabelAndDescriptionFrom<Options> = PropertyFrom<Options, "label"> & PropertyFrom<Options, "description">;
|
|
63
|
+
type LabelAndDescriptionFrom<Options> = PropertyFrom<Options, "label"> & PropertyFrom<Options, "description"> & PropertyFrom<Options, "placeholder">;
|
|
54
64
|
type CommonDefinition<Type extends FieldType, Options> = {
|
|
55
65
|
readonly required: RequiredFrom<Options>;
|
|
56
66
|
readonly type: Type;
|
|
@@ -72,15 +82,72 @@ export type DateFieldDefinition<Options extends StringValueFieldOptions = String
|
|
|
72
82
|
/** A datetime-field descriptor. */
|
|
73
83
|
export type DatetimeFieldDefinition<Options extends StringValueFieldOptions = StringValueFieldOptions> = CommonDefinition<"datetime", Options>;
|
|
74
84
|
/** A URL-field descriptor. */
|
|
75
|
-
export type UrlFieldDefinition<Options extends
|
|
85
|
+
export type UrlFieldDefinition<Options extends PlaceholderFieldOptions<string> = PlaceholderFieldOptions<string>> = CommonDefinition<"url", Options>;
|
|
76
86
|
/** A media-field descriptor that stores a media identifier. */
|
|
77
87
|
export type MediaFieldDefinition<Options extends StringValueFieldOptions = StringValueFieldOptions> = CommonDefinition<"media", Options>;
|
|
78
88
|
/** A select-field descriptor. */
|
|
79
89
|
export type SelectFieldDefinition<Choices extends readonly string[] = readonly string[], Options extends SelectFieldOptions<Choices> = SelectFieldOptions<Choices>> = CommonDefinition<"select", Options> & {
|
|
80
90
|
readonly options: Choices;
|
|
81
91
|
};
|
|
92
|
+
/** Ordered presentation of immediate sibling fields; never content data. */
|
|
93
|
+
export interface FormLayout<Key extends string = string> {
|
|
94
|
+
readonly mode: "sections" | "tabs";
|
|
95
|
+
readonly groups: readonly {
|
|
96
|
+
readonly key: string;
|
|
97
|
+
readonly label: string;
|
|
98
|
+
readonly description?: string;
|
|
99
|
+
readonly fields: readonly Key[];
|
|
100
|
+
}[];
|
|
101
|
+
}
|
|
102
|
+
/** Validates, detaches and freezes optional sibling layout metadata. */
|
|
103
|
+
export declare function normalizeFormLayout<Key extends string>(value: unknown, fields: Readonly<Record<Key, unknown>>, path?: string): FormLayout<Key> | undefined;
|
|
104
|
+
/** Sibling field order used by rendering and validation summaries. */
|
|
105
|
+
export declare function formFieldKeys(fields: Readonly<Record<string, unknown>>, layout?: FormLayout): readonly string[];
|
|
106
|
+
/** A finite group of named child descriptors. */
|
|
107
|
+
export interface GroupFieldDefinition {
|
|
108
|
+
readonly layout?: FormLayout;
|
|
109
|
+
readonly type: "group";
|
|
110
|
+
readonly fields: ModelFieldDefinitions;
|
|
111
|
+
readonly required: boolean;
|
|
112
|
+
readonly label?: string;
|
|
113
|
+
readonly description?: string;
|
|
114
|
+
readonly defaultValue?: JsonObject;
|
|
115
|
+
}
|
|
116
|
+
/** A list item cannot itself be a list. */
|
|
117
|
+
export type ListItemDefinition = Exclude<FieldDefinition, ListFieldDefinition>;
|
|
118
|
+
/** A homogeneous ordered list; omitted bounds mean 0 and 100. */
|
|
119
|
+
export interface ListFieldDefinition {
|
|
120
|
+
readonly type: "list";
|
|
121
|
+
readonly item: ListItemDefinition;
|
|
122
|
+
readonly required: boolean;
|
|
123
|
+
readonly label?: string;
|
|
124
|
+
readonly description?: string;
|
|
125
|
+
readonly defaultValue?: readonly JsonValue[];
|
|
126
|
+
readonly minItems?: number;
|
|
127
|
+
readonly maxItems?: number;
|
|
128
|
+
/** Immediate text/textarea/select/URL child used for an item summary. */
|
|
129
|
+
readonly itemLabel?: string;
|
|
130
|
+
}
|
|
131
|
+
/** A draft starting value can omit required group descendants. */
|
|
132
|
+
export type DraftFieldValue<Definition extends FieldDefinition> = Definition extends {
|
|
133
|
+
readonly type: "group";
|
|
134
|
+
readonly fields: infer Fields extends ModelFieldDefinitions;
|
|
135
|
+
} ? string extends keyof Fields ? JsonObject : {
|
|
136
|
+
readonly [Key in keyof Fields]?: DraftFieldValue<Fields[Key]>;
|
|
137
|
+
} : Definition extends {
|
|
138
|
+
readonly type: "list";
|
|
139
|
+
readonly item: infer Item extends ListItemDefinition;
|
|
140
|
+
} ? readonly DraftFieldValue<Item>[] : FieldValue<Definition>;
|
|
141
|
+
/** Maximum containers along a descriptor branch. */
|
|
142
|
+
export declare const MAX_FIELD_CONTAINER_DEPTH = 6;
|
|
143
|
+
/** Maximum directly nested groups. */
|
|
144
|
+
export declare const MAX_CONSECUTIVE_GROUPS = 2;
|
|
145
|
+
/** Maximum items in any one list. */
|
|
146
|
+
export declare const MAX_LIST_ITEMS = 100;
|
|
147
|
+
/** Maximum sum of list lengths in a snapshot. */
|
|
148
|
+
export declare const MAX_SNAPSHOT_LIST_ITEMS = 500;
|
|
82
149
|
/** The discriminated union of all currently supported field descriptors. */
|
|
83
|
-
export type FieldDefinition = BooleanFieldDefinition | DateFieldDefinition | DatetimeFieldDefinition | MediaFieldDefinition | NumberFieldDefinition | RichTextFieldDefinition | SelectFieldDefinition | TextareaFieldDefinition | TextFieldDefinition | UrlFieldDefinition;
|
|
150
|
+
export type FieldDefinition = GroupFieldDefinition | ListFieldDefinition | BooleanFieldDefinition | DateFieldDefinition | DatetimeFieldDefinition | MediaFieldDefinition | NumberFieldDefinition | RichTextFieldDefinition | SelectFieldDefinition | TextareaFieldDefinition | TextFieldDefinition | UrlFieldDefinition;
|
|
84
151
|
/** The submitted value type associated with a field descriptor. */
|
|
85
152
|
export type FieldValue<Definition extends FieldDefinition> = Definition extends {
|
|
86
153
|
readonly type: "boolean";
|
|
@@ -92,7 +159,13 @@ export type FieldValue<Definition extends FieldDefinition> = Definition extends
|
|
|
92
159
|
readonly type: "select";
|
|
93
160
|
} ? Definition extends {
|
|
94
161
|
readonly options: readonly (infer Choice)[];
|
|
95
|
-
} ? Choice : never :
|
|
162
|
+
} ? Choice : never : Definition extends {
|
|
163
|
+
readonly type: "group";
|
|
164
|
+
readonly fields: infer Fields extends ModelFieldDefinitions;
|
|
165
|
+
} ? string extends keyof Fields ? JsonObject : BlockDataValues<Fields> : Definition extends {
|
|
166
|
+
readonly type: "list";
|
|
167
|
+
readonly item: infer Item extends ListItemDefinition;
|
|
168
|
+
} ? readonly FieldValue<Item>[] : string;
|
|
96
169
|
/** Whether a descriptor makes a model property required through `required` or a default. */
|
|
97
170
|
export type FieldIsRequired<Definition extends FieldDefinition> = Definition extends {
|
|
98
171
|
readonly defaultValue: unknown;
|
|
@@ -107,6 +180,23 @@ export declare class FieldConfigurationError extends Error {
|
|
|
107
180
|
}
|
|
108
181
|
/** Builders for portable Lace field descriptors. */
|
|
109
182
|
export declare const field: {
|
|
183
|
+
/** Define named child fields stored as one plain object. */
|
|
184
|
+
readonly group: <const Options extends {
|
|
185
|
+
readonly fields: ModelFieldDefinitions;
|
|
186
|
+
}>(options: Options & CommonFieldOptions<NoInfer<{ readonly [Key in keyof Options["fields"]]?: DraftFieldValue<Options["fields"][Key]>; }>> & {
|
|
187
|
+
readonly layout?: FormLayout<keyof Options["fields"] & string>;
|
|
188
|
+
}) => CommonDefinition<"group", Options> & PropertyFrom<Options, "layout"> & {
|
|
189
|
+
readonly fields: Options["fields"];
|
|
190
|
+
};
|
|
191
|
+
/** Define an ordered array of scalar or group values. */
|
|
192
|
+
readonly list: <const Options extends {
|
|
193
|
+
readonly item: ListItemDefinition;
|
|
194
|
+
readonly minItems?: number;
|
|
195
|
+
readonly maxItems?: number;
|
|
196
|
+
readonly itemLabel?: string;
|
|
197
|
+
}>(options: Options & CommonFieldOptions<NoInfer<readonly DraftFieldValue<Options["item"]>[]>>) => CommonDefinition<"list", Options> & {
|
|
198
|
+
readonly item: Options["item"];
|
|
199
|
+
} & PropertyFrom<Options, "minItems"> & PropertyFrom<Options, "maxItems"> & PropertyFrom<Options, "itemLabel">;
|
|
110
200
|
/** Define a single-line text field. */
|
|
111
201
|
readonly text: <const Options extends StringFieldOptions = StringFieldOptions>(options?: Options) => TextFieldDefinition<Options>;
|
|
112
202
|
/** Define a multiline text field. */
|
|
@@ -126,7 +216,7 @@ export declare const field: {
|
|
|
126
216
|
readonly options: readonly [string, ...string[]];
|
|
127
217
|
}>(options: Options & SelectFieldOptions<Options["options"]>) => SelectFieldDefinition<Options["options"], Options & SelectFieldOptions<Options["options"]>>;
|
|
128
218
|
/** Define a URL string field; URL protocol validation is added in Session 2B. */
|
|
129
|
-
readonly url: <const Options extends
|
|
219
|
+
readonly url: <const Options extends PlaceholderFieldOptions<string> = PlaceholderFieldOptions<string>>(options?: Options) => UrlFieldDefinition<Options>;
|
|
130
220
|
/** Define a field holding a media identifier. */
|
|
131
221
|
readonly media: <const Options extends StringValueFieldOptions = StringValueFieldOptions>(options?: Options) => MediaFieldDefinition<Options>;
|
|
132
222
|
};
|
|
@@ -135,18 +225,28 @@ export declare const field: {
|
|
|
135
225
|
* representation. Runtime schemas and callbacks are deliberately absent.
|
|
136
226
|
*/
|
|
137
227
|
export declare function toFieldMetadata(definition: FieldDefinition): FieldMetadata;
|
|
228
|
+
/** Validates and detaches a descriptor, including forged JSON/configuration input. */
|
|
229
|
+
export declare function normalizeFieldDefinition(value: unknown): FieldDefinition;
|
|
138
230
|
/** A mark permitted in Lace rich-text documents. */
|
|
139
231
|
export type SafeRichTextMark = {
|
|
140
232
|
readonly type: "bold" | "code" | "italic" | "strike";
|
|
141
233
|
} | {
|
|
142
234
|
readonly attrs: {
|
|
143
235
|
readonly href: string;
|
|
236
|
+
readonly target?: "_blank";
|
|
237
|
+
readonly rel?: "nofollow";
|
|
144
238
|
};
|
|
145
239
|
readonly type: "link";
|
|
146
240
|
};
|
|
147
241
|
/** A node permitted in Lace rich-text documents. */
|
|
148
242
|
export type SafeRichTextNode = {
|
|
149
|
-
readonly type: "hardBreak";
|
|
243
|
+
readonly type: "hardBreak" | "horizontalRule";
|
|
244
|
+
} | {
|
|
245
|
+
readonly content?: readonly {
|
|
246
|
+
readonly text: string;
|
|
247
|
+
readonly type: "text";
|
|
248
|
+
}[];
|
|
249
|
+
readonly type: "codeBlock";
|
|
150
250
|
} | {
|
|
151
251
|
readonly marks?: readonly SafeRichTextMark[];
|
|
152
252
|
readonly text: string;
|
|
@@ -156,7 +256,7 @@ export type SafeRichTextNode = {
|
|
|
156
256
|
readonly type: "paragraph";
|
|
157
257
|
} | {
|
|
158
258
|
readonly attrs: {
|
|
159
|
-
readonly level: 1 | 2 | 3;
|
|
259
|
+
readonly level: 1 | 2 | 3 | 4;
|
|
160
260
|
};
|
|
161
261
|
readonly content?: readonly SafeRichTextNode[];
|
|
162
262
|
readonly type: "heading";
|
|
@@ -202,28 +302,95 @@ export type FieldDefinitionVisitor<Result> = {
|
|
|
202
302
|
export declare function visitFieldDefinition<Result>(definition: FieldDefinition, visitor: FieldDefinitionVisitor<Result>): Result;
|
|
203
303
|
/** A Valibot runtime schema compiled from a field definition. */
|
|
204
304
|
export type CompiledFieldSchema<Definition extends FieldDefinition> = v.BaseSchema<unknown, FieldValue<Definition>, v.BaseIssue<unknown>>;
|
|
205
|
-
/** Compiles a field definition
|
|
206
|
-
export declare function compileFieldSchema<Definition extends FieldDefinition>(definition: Definition): CompiledFieldSchema<Definition>;
|
|
207
|
-
/** Validates
|
|
208
|
-
export declare function validateFieldValue<Definition extends FieldDefinition>(definition: Definition, value: unknown, path?: readonly ValidationPathSegment[]): FieldValue<Definition>;
|
|
305
|
+
/** Compiles a field definition with the same normalization as aggregate validation. */
|
|
306
|
+
export declare function compileFieldSchema<Definition extends FieldDefinition>(definition: Definition, mode?: ContentValidationMode): CompiledFieldSchema<Definition>;
|
|
307
|
+
/** Validates and normalizes one present value; absence is handled by its field map. */
|
|
308
|
+
export declare function validateFieldValue<Definition extends FieldDefinition>(definition: Definition, value: unknown, path?: readonly ValidationPathSegment[], mode?: ContentValidationMode): FieldValue<Definition>;
|
|
209
309
|
/** A model field map accepted by the draft and publish validators. */
|
|
210
310
|
export type ModelFieldDefinitions = Readonly<Record<string, FieldDefinition>>;
|
|
211
|
-
/**
|
|
212
|
-
export type ModelFieldValues =
|
|
311
|
+
/** Portable normalized values, including incomplete draft groups. */
|
|
312
|
+
export type ModelFieldValues = JsonObject;
|
|
213
313
|
/** The validation state of a content snapshot. */
|
|
214
314
|
export type ContentValidationMode = "draft" | "publish";
|
|
215
315
|
/** Validates field data for either an incomplete draft or a publish candidate. */
|
|
216
316
|
export declare function validateModelFields(definitions: ModelFieldDefinitions, value: unknown, mode: ContentValidationMode, path?: readonly ValidationPathSegment[]): ModelFieldValues;
|
|
317
|
+
/** Checks already normalized model/block values against one snapshot-wide budget. */
|
|
318
|
+
export declare function validateSnapshotListBudget(fields: ModelFieldDefinitions, values: JsonObject, blocks: readonly {
|
|
319
|
+
readonly fields: ModelFieldDefinitions;
|
|
320
|
+
readonly data: JsonObject;
|
|
321
|
+
readonly path: readonly ValidationPathSegment[];
|
|
322
|
+
}[]): void;
|
|
323
|
+
/** A declared media leaf with a typed relative path. */
|
|
324
|
+
export interface FieldMediaReference {
|
|
325
|
+
readonly mediaId: string;
|
|
326
|
+
readonly path: readonly ValidationPathSegment[];
|
|
327
|
+
}
|
|
328
|
+
/** Finds declared media leaves only; ordinary strings never become references. */
|
|
329
|
+
export declare function collectFieldMedia(definitions: ModelFieldDefinitions, values: JsonObject): readonly FieldMediaReference[];
|
|
330
|
+
/**
|
|
331
|
+
* Removes one media item from declared media leaves: a matching media value is
|
|
332
|
+
* dropped from its object, and a matching element of a list of media is removed
|
|
333
|
+
* from the list. Every other value is kept; the input is returned unchanged when
|
|
334
|
+
* nothing matches.
|
|
335
|
+
*/
|
|
336
|
+
export declare function detachFieldMedia(definitions: ModelFieldDefinitions, values: JsonObject, mediaId: string): JsonObject;
|
|
337
|
+
/** Keeps legacy scalar keys; nested locations are relative JSON Pointers. */
|
|
338
|
+
export declare function encodeFieldPath(path: readonly ValidationPathSegment[]): string;
|
|
339
|
+
/** Reads a stored reference path; numeric tokens are list indices under the field-key grammar. */
|
|
340
|
+
export declare function decodeFieldPath(path: string): readonly ValidationPathSegment[];
|
|
341
|
+
/** Maximum length of a block anchor. */
|
|
342
|
+
export declare const MAX_BLOCK_ANCHOR_LENGTH = 64;
|
|
343
|
+
/** Maximum length of a normalized block class name. */
|
|
344
|
+
export declare const MAX_BLOCK_CLASS_NAME_LENGTH = 256;
|
|
345
|
+
/** Maximum number of class tokens in a block class name. */
|
|
346
|
+
export declare const MAX_BLOCK_CLASS_TOKENS = 16;
|
|
347
|
+
/** Maximum length of one block class token. */
|
|
348
|
+
export declare const MAX_BLOCK_CLASS_TOKEN_LENGTH = 64;
|
|
349
|
+
/** Whether a value is a block anchor: a lowercase letter, then lowercase letters, digits and hyphens. */
|
|
350
|
+
export declare function isBlockAnchor(value: unknown): value is string;
|
|
351
|
+
/**
|
|
352
|
+
* Normalizes a block class name: whitespace-separated class tokens, repeats
|
|
353
|
+
* dropped, joined with single spaces. Returns `undefined` for a non-string,
|
|
354
|
+
* blank or invalid value.
|
|
355
|
+
*/
|
|
356
|
+
export declare function normalizeBlockClassName(value: unknown): string | undefined;
|
|
217
357
|
/** Thrown when a block definition or registry is not portable or internally consistent. */
|
|
218
358
|
export declare class BlockConfigurationError extends Error {
|
|
219
359
|
constructor(message: string);
|
|
220
360
|
}
|
|
361
|
+
/** The stored data and settings a block migration step receives. */
|
|
362
|
+
export interface BlockMigrationInput {
|
|
363
|
+
readonly data: JsonObject;
|
|
364
|
+
readonly settings: JsonObject;
|
|
365
|
+
}
|
|
366
|
+
/** A migration step's result; leaving out `settings` keeps the input settings. */
|
|
367
|
+
export interface BlockMigrationOutput {
|
|
368
|
+
readonly data: JsonObject;
|
|
369
|
+
readonly settings?: JsonObject;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* A pure, synchronous step that turns the stored data and settings of the
|
|
373
|
+
* previous block version into those of its target version.
|
|
374
|
+
*/
|
|
375
|
+
export type BlockMigration = (block: BlockMigrationInput) => BlockMigrationOutput;
|
|
376
|
+
/** Migrations keyed by target version; the keys form one range ending at the block version. */
|
|
377
|
+
export type BlockMigrations = Readonly<Record<number, BlockMigration>>;
|
|
378
|
+
/** Field types a block setting may use; every setting declares a default. */
|
|
379
|
+
export declare const BLOCK_SETTING_FIELD_TYPES: readonly ["boolean", "number", "select", "text"];
|
|
380
|
+
/** The settings of a block that declares none. */
|
|
381
|
+
export type NoBlockSettings = Readonly<Record<never, FieldDefinition>>;
|
|
221
382
|
/** Input accepted by the portable block-definition DSL. */
|
|
222
|
-
export interface BlockDefinitionInput<Fields extends ModelFieldDefinitions = ModelFieldDefinitions> {
|
|
383
|
+
export interface BlockDefinitionInput<Fields extends ModelFieldDefinitions = ModelFieldDefinitions, Settings extends ModelFieldDefinitions = ModelFieldDefinitions> {
|
|
223
384
|
readonly defaultValue?: unknown;
|
|
224
385
|
readonly description?: string;
|
|
225
386
|
readonly fields: Fields;
|
|
387
|
+
readonly layout?: FormLayout<keyof Fields & string>;
|
|
388
|
+
readonly settingsLayout?: FormLayout<keyof Settings & string>;
|
|
226
389
|
readonly label?: string;
|
|
390
|
+
/** Data and settings migrations from earlier versions, keyed by target version. */
|
|
391
|
+
readonly migrations?: BlockMigrations;
|
|
392
|
+
/** Presentational settings: `select`, `boolean`, `number` or `text` fields with defaults. */
|
|
393
|
+
readonly settings?: Settings;
|
|
227
394
|
readonly type: string;
|
|
228
395
|
readonly version: number;
|
|
229
396
|
}
|
|
@@ -233,21 +400,31 @@ export type BlockDataValues<Fields extends ModelFieldDefinitions> = Readonly<{
|
|
|
233
400
|
} & {
|
|
234
401
|
readonly [Key in keyof Fields as FieldIsRequired<Fields[Key]> extends true ? never : Key]?: FieldValue<Fields[Key]>;
|
|
235
402
|
}>;
|
|
403
|
+
/** The settings record of a block; every setting has a default, so every key is present. */
|
|
404
|
+
export type BlockSettingsValues<Settings extends ModelFieldDefinitions> = Readonly<{
|
|
405
|
+
[Key in keyof Settings]: FieldValue<Settings[Key]>;
|
|
406
|
+
}>;
|
|
236
407
|
/** A detached JSON-safe representation of a block definition. */
|
|
237
|
-
export interface BlockMetadata<Fields extends ModelFieldDefinitions = ModelFieldDefinitions> {
|
|
408
|
+
export interface BlockMetadata<Fields extends ModelFieldDefinitions = ModelFieldDefinitions, Settings extends ModelFieldDefinitions = ModelFieldDefinitions> {
|
|
238
409
|
readonly defaultValue?: BlockDataValues<Fields>;
|
|
239
410
|
readonly description?: string;
|
|
240
411
|
readonly fields: Fields;
|
|
412
|
+
readonly layout?: FormLayout<keyof Fields & string>;
|
|
413
|
+
readonly settingsLayout?: FormLayout<keyof Settings & string>;
|
|
241
414
|
readonly label?: string;
|
|
415
|
+
/** Declared settings; absent when the block declares none. */
|
|
416
|
+
readonly settings?: Settings;
|
|
242
417
|
readonly type: string;
|
|
243
418
|
readonly version: number;
|
|
244
419
|
}
|
|
245
420
|
/** An executable block definition retained only in the runtime projection. */
|
|
246
|
-
export interface BlockDefinition<Fields extends ModelFieldDefinitions = ModelFieldDefinitions> extends BlockMetadata<Fields> {
|
|
421
|
+
export interface BlockDefinition<Fields extends ModelFieldDefinitions = ModelFieldDefinitions, Settings extends ModelFieldDefinitions = ModelFieldDefinitions> extends BlockMetadata<Fields, Settings> {
|
|
422
|
+
/** Runtime-only migrations keyed by target version; never part of metadata. */
|
|
423
|
+
readonly migrations?: BlockMigrations;
|
|
247
424
|
readonly validate: (value: unknown, mode: ContentValidationMode) => BlockDataValues<Fields>;
|
|
248
425
|
}
|
|
249
426
|
/** Defines a versioned block using only portable field descriptors. */
|
|
250
|
-
export declare function defineBlock<const Fields extends ModelFieldDefinitions>(input: BlockDefinitionInput<Fields>): BlockDefinition<Fields>;
|
|
427
|
+
export declare function defineBlock<const Fields extends ModelFieldDefinitions, const Settings extends ModelFieldDefinitions = NoBlockSettings>(input: BlockDefinitionInput<Fields, Settings>): BlockDefinition<Fields, Settings>;
|
|
251
428
|
/** Projects a block definition into detached, JSON-safe metadata. */
|
|
252
429
|
export declare function toBlockMetadata(definition: BlockDefinition): BlockMetadata;
|
|
253
430
|
/** A registry of the current executable definition for every allowed block type. */
|
|
@@ -261,6 +438,39 @@ export declare function defineBlockRegistry(blocks: readonly BlockDefinition[]):
|
|
|
261
438
|
export declare function toBlockRegistryMetadata(registry: BlockRegistry): readonly BlockMetadata[];
|
|
262
439
|
/** Validates one block's field record, applying its whole-record default first. */
|
|
263
440
|
export declare function validateBlockData<Fields extends ModelFieldDefinitions>(definition: BlockDefinition<Fields>, value: unknown, mode: ContentValidationMode, path?: readonly ValidationPathSegment[]): BlockDataValues<Fields>;
|
|
441
|
+
/**
|
|
442
|
+
* Validates a block's settings record against its declared settings, filling
|
|
443
|
+
* every default; a block that declares none accepts only `{}`.
|
|
444
|
+
*/
|
|
445
|
+
export declare function validateBlockSettings(definition: Pick<BlockMetadata, "settings">, value: unknown, path?: readonly ValidationPathSegment[]): JsonObject;
|
|
446
|
+
/** Why stored block data could not be migrated to the current block version. */
|
|
447
|
+
export type BlockMigrationErrorCode = "invalid_result" | "migration_failed" | "missing_step" | "version_ahead";
|
|
448
|
+
/** Thrown when stored block data cannot be migrated to its definition's version. */
|
|
449
|
+
export declare class BlockMigrationError extends Error {
|
|
450
|
+
readonly code: BlockMigrationErrorCode;
|
|
451
|
+
readonly blockType: string;
|
|
452
|
+
readonly fromVersion: number;
|
|
453
|
+
readonly toVersion: number;
|
|
454
|
+
/** Target version of the failing step, for failed or invalid steps. */
|
|
455
|
+
readonly step?: number | undefined;
|
|
456
|
+
constructor(code: BlockMigrationErrorCode, blockType: string, fromVersion: number, toVersion: number, message: string,
|
|
457
|
+
/** Target version of the failing step, for failed or invalid steps. */
|
|
458
|
+
step?: number | undefined, options?: {
|
|
459
|
+
readonly cause?: unknown;
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Migrates stored block data and settings from `fromVersion` to the
|
|
464
|
+
* definition's version by composing its declared migrations in ascending
|
|
465
|
+
* order. Each step receives a detached, frozen copy. The result is not
|
|
466
|
+
* validated against the definition.
|
|
467
|
+
*/
|
|
468
|
+
export declare function migrateBlockData(definition: BlockDefinition, block: BlockMigrationInput, fromVersion: number): BlockMigrationInput;
|
|
469
|
+
/**
|
|
470
|
+
* Resolves the alt text of one media usage: a non-blank usage alt (such as the
|
|
471
|
+
* `image` block's `alt`), then a non-blank media alt, then an empty string.
|
|
472
|
+
*/
|
|
473
|
+
export declare function effectiveAltText(usageAlt: string | null | undefined, mediaAlt: string | null | undefined): string;
|
|
264
474
|
/** Starter blocks implemented exclusively through the public block and field DSL. */
|
|
265
475
|
export declare const builtInBlocks: {
|
|
266
476
|
cta: BlockDefinition<{
|
|
@@ -272,14 +482,59 @@ export declare const builtInBlocks: {
|
|
|
272
482
|
readonly required: true;
|
|
273
483
|
readonly type: "url";
|
|
274
484
|
};
|
|
275
|
-
readonly body:
|
|
485
|
+
readonly body: {
|
|
486
|
+
readonly required: false;
|
|
487
|
+
readonly type: "richText";
|
|
488
|
+
};
|
|
276
489
|
readonly heading: {
|
|
277
490
|
readonly required: true;
|
|
278
491
|
readonly type: "text";
|
|
279
492
|
};
|
|
280
|
-
}
|
|
493
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
494
|
+
gallery: BlockDefinition<{
|
|
495
|
+
readonly images: {
|
|
496
|
+
readonly required: false;
|
|
497
|
+
readonly type: "list";
|
|
498
|
+
} & {
|
|
499
|
+
readonly defaultValue: readonly [];
|
|
500
|
+
} & {
|
|
501
|
+
readonly label: "Images";
|
|
502
|
+
} & {
|
|
503
|
+
readonly item: {
|
|
504
|
+
readonly required: false;
|
|
505
|
+
readonly type: "group";
|
|
506
|
+
} & {
|
|
507
|
+
readonly fields: {
|
|
508
|
+
readonly alt: TextFieldDefinition<{
|
|
509
|
+
readonly description: "Leave empty to use the media item's alt text.";
|
|
510
|
+
readonly label: "Alt text";
|
|
511
|
+
}>;
|
|
512
|
+
readonly caption: TextFieldDefinition<{
|
|
513
|
+
readonly description: "Leave empty to use the media item's caption.";
|
|
514
|
+
readonly label: "Caption";
|
|
515
|
+
}>;
|
|
516
|
+
readonly media: MediaFieldDefinition<{
|
|
517
|
+
readonly label: "Image";
|
|
518
|
+
readonly required: true;
|
|
519
|
+
}>;
|
|
520
|
+
};
|
|
521
|
+
};
|
|
522
|
+
} & {
|
|
523
|
+
readonly minItems: 1;
|
|
524
|
+
} & {
|
|
525
|
+
readonly maxItems: 50;
|
|
526
|
+
} & {
|
|
527
|
+
readonly itemLabel: "caption";
|
|
528
|
+
};
|
|
529
|
+
readonly title: TextFieldDefinition<{
|
|
530
|
+
readonly label: "Title";
|
|
531
|
+
}>;
|
|
532
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
281
533
|
hero: BlockDefinition<{
|
|
282
|
-
readonly body:
|
|
534
|
+
readonly body: {
|
|
535
|
+
readonly required: false;
|
|
536
|
+
readonly type: "richText";
|
|
537
|
+
};
|
|
283
538
|
readonly eyebrow: {
|
|
284
539
|
readonly required: false;
|
|
285
540
|
readonly type: "text";
|
|
@@ -288,16 +543,22 @@ export declare const builtInBlocks: {
|
|
|
288
543
|
readonly required: true;
|
|
289
544
|
readonly type: "text";
|
|
290
545
|
};
|
|
291
|
-
readonly image:
|
|
546
|
+
readonly image: {
|
|
547
|
+
readonly required: false;
|
|
548
|
+
readonly type: "media";
|
|
549
|
+
};
|
|
292
550
|
readonly primaryActionLabel: {
|
|
293
551
|
readonly required: false;
|
|
294
552
|
readonly type: "text";
|
|
295
553
|
};
|
|
296
|
-
readonly primaryActionUrl:
|
|
297
|
-
|
|
554
|
+
readonly primaryActionUrl: {
|
|
555
|
+
readonly required: false;
|
|
556
|
+
readonly type: "url";
|
|
557
|
+
};
|
|
558
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
298
559
|
image: BlockDefinition<{
|
|
299
560
|
readonly alt: {
|
|
300
|
-
readonly required:
|
|
561
|
+
readonly required: false;
|
|
301
562
|
readonly type: "text";
|
|
302
563
|
};
|
|
303
564
|
readonly caption: {
|
|
@@ -308,7 +569,69 @@ export declare const builtInBlocks: {
|
|
|
308
569
|
readonly required: true;
|
|
309
570
|
readonly type: "media";
|
|
310
571
|
};
|
|
311
|
-
}
|
|
572
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
573
|
+
navigation: BlockDefinition<{
|
|
574
|
+
readonly links: {
|
|
575
|
+
readonly required: false;
|
|
576
|
+
readonly type: "list";
|
|
577
|
+
} & {
|
|
578
|
+
readonly defaultValue: readonly [];
|
|
579
|
+
} & {
|
|
580
|
+
readonly label: "Links";
|
|
581
|
+
} & {
|
|
582
|
+
readonly item: {
|
|
583
|
+
readonly required: false;
|
|
584
|
+
readonly type: "group";
|
|
585
|
+
} & {
|
|
586
|
+
readonly fields: {
|
|
587
|
+
readonly children: {
|
|
588
|
+
readonly required: false;
|
|
589
|
+
readonly type: "list";
|
|
590
|
+
} & {
|
|
591
|
+
readonly label: "Submenu links";
|
|
592
|
+
} & {
|
|
593
|
+
readonly item: {
|
|
594
|
+
readonly required: false;
|
|
595
|
+
readonly type: "group";
|
|
596
|
+
} & {
|
|
597
|
+
readonly fields: {
|
|
598
|
+
readonly label: TextFieldDefinition<{
|
|
599
|
+
readonly label: "Label";
|
|
600
|
+
readonly required: true;
|
|
601
|
+
}>;
|
|
602
|
+
readonly url: UrlFieldDefinition<{
|
|
603
|
+
readonly label: "URL";
|
|
604
|
+
readonly required: true;
|
|
605
|
+
}>;
|
|
606
|
+
};
|
|
607
|
+
};
|
|
608
|
+
} & {
|
|
609
|
+
readonly maxItems: 20;
|
|
610
|
+
} & {
|
|
611
|
+
readonly itemLabel: "label";
|
|
612
|
+
};
|
|
613
|
+
readonly label: TextFieldDefinition<{
|
|
614
|
+
readonly label: "Label";
|
|
615
|
+
readonly required: true;
|
|
616
|
+
}>;
|
|
617
|
+
readonly url: UrlFieldDefinition<{
|
|
618
|
+
readonly description: "Optional when the link has submenu links.";
|
|
619
|
+
readonly label: "URL";
|
|
620
|
+
}>;
|
|
621
|
+
};
|
|
622
|
+
};
|
|
623
|
+
} & {
|
|
624
|
+
readonly minItems: 1;
|
|
625
|
+
} & {
|
|
626
|
+
readonly maxItems: 20;
|
|
627
|
+
} & {
|
|
628
|
+
readonly itemLabel: "label";
|
|
629
|
+
};
|
|
630
|
+
readonly name: TextFieldDefinition<{
|
|
631
|
+
readonly description: "Read by screen readers, for example Main or On this page.";
|
|
632
|
+
readonly label: "Navigation name";
|
|
633
|
+
}>;
|
|
634
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
312
635
|
quote: BlockDefinition<{
|
|
313
636
|
readonly attribution: {
|
|
314
637
|
readonly required: false;
|
|
@@ -318,13 +641,13 @@ export declare const builtInBlocks: {
|
|
|
318
641
|
readonly required: true;
|
|
319
642
|
readonly type: "text";
|
|
320
643
|
};
|
|
321
|
-
}
|
|
644
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
322
645
|
richText: BlockDefinition<{
|
|
323
646
|
readonly content: {
|
|
324
647
|
readonly required: true;
|
|
325
648
|
readonly type: "richText";
|
|
326
649
|
};
|
|
327
|
-
}
|
|
650
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
328
651
|
};
|
|
329
652
|
/** Maximum title length shared by draft, publish, REST, and admin validation. */
|
|
330
653
|
export declare const MAX_TITLE_LENGTH = 200;
|
|
@@ -334,8 +657,8 @@ export declare const MAX_SLUG_LENGTH = 100;
|
|
|
334
657
|
export declare const MAX_TOP_LEVEL_BLOCKS = 200;
|
|
335
658
|
/** Maximum UTF-8 bytes in fields JSON or a single block data JSON value. */
|
|
336
659
|
export declare const MAX_JSON_BYTES = 1000000;
|
|
337
|
-
/**
|
|
338
|
-
export type ContentModelKind = "collection" | "page";
|
|
660
|
+
/** Model kinds: routed singletons, routed lists, and route-less singletons. */
|
|
661
|
+
export type ContentModelKind = "collection" | "global" | "page";
|
|
339
662
|
/** A block-like value whose data can be limited before the Step 3 block registry exists. */
|
|
340
663
|
export interface EntryBlockData {
|
|
341
664
|
readonly data: JsonValue;
|
|
@@ -370,9 +693,24 @@ export interface EntryAggregateModel {
|
|
|
370
693
|
}
|
|
371
694
|
/** One ordered, typed block submitted as part of an entry aggregate. */
|
|
372
695
|
export interface EntryAggregateBlock {
|
|
696
|
+
readonly anchor?: string;
|
|
697
|
+
readonly className?: string;
|
|
373
698
|
readonly data: JsonObject;
|
|
699
|
+
readonly hidden?: boolean;
|
|
700
|
+
readonly key: string;
|
|
701
|
+
readonly schemaVersion: number;
|
|
702
|
+
readonly settings?: JsonObject;
|
|
703
|
+
readonly type: string;
|
|
704
|
+
}
|
|
705
|
+
/** A validated block: normalized data, settings with defaults, and the envelope. */
|
|
706
|
+
export interface ValidatedEntryAggregateBlock {
|
|
707
|
+
readonly anchor?: string;
|
|
708
|
+
readonly className?: string;
|
|
709
|
+
readonly data: ModelFieldValues;
|
|
710
|
+
readonly hidden: boolean;
|
|
374
711
|
readonly key: string;
|
|
375
712
|
readonly schemaVersion: number;
|
|
713
|
+
readonly settings: JsonObject;
|
|
376
714
|
readonly type: string;
|
|
377
715
|
}
|
|
378
716
|
/** A full draft or publish candidate validated against a model and its registry. */
|
|
@@ -385,9 +723,7 @@ export interface EntryAggregateInput {
|
|
|
385
723
|
}
|
|
386
724
|
/** The normalized form of a valid entry aggregate. */
|
|
387
725
|
export interface ValidatedEntryAggregate {
|
|
388
|
-
readonly blocks: readonly
|
|
389
|
-
readonly data: ModelFieldValues;
|
|
390
|
-
})[];
|
|
726
|
+
readonly blocks: readonly ValidatedEntryAggregateBlock[];
|
|
391
727
|
readonly fields: ModelFieldValues;
|
|
392
728
|
readonly kind: ContentModelKind;
|
|
393
729
|
readonly slug?: string;
|
|
@@ -395,5 +731,9 @@ export interface ValidatedEntryAggregate {
|
|
|
395
731
|
}
|
|
396
732
|
/** Validates all system, model-field, and ordered block data for one content entry. */
|
|
397
733
|
export declare function validateEntryAggregate(input: EntryAggregateInput, model: EntryAggregateModel, registry: BlockRegistry, mode: ContentValidationMode): ValidatedEntryAggregate;
|
|
398
|
-
export {};
|
|
734
|
+
export { parseSchemaPath, encodeSchemaPath, schemaFieldAt } from "./schema-path.js";
|
|
735
|
+
/** Raw UTF-16 units: the existing text/textarea length contract, without trimming. */
|
|
736
|
+
export declare function textLength(value: string): number;
|
|
737
|
+
/** Trimmed Unicode code points: the existing SEO title/description contract. */
|
|
738
|
+
export declare function seoTextLength(value: string): number;
|
|
399
739
|
//# sourceMappingURL=index.d.ts.map
|