@lacecms/content 0.1.0-alpha.3 → 0.1.0-alpha.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.
- package/dist/index.d.ts +371 -38
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +771 -58
- 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,88 @@ 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
|
+
/** Keeps legacy scalar keys; nested locations are relative JSON Pointers. */
|
|
331
|
+
export declare function encodeFieldPath(path: readonly ValidationPathSegment[]): string;
|
|
332
|
+
/** Reads a stored reference path; numeric tokens are list indices under the field-key grammar. */
|
|
333
|
+
export declare function decodeFieldPath(path: string): readonly ValidationPathSegment[];
|
|
334
|
+
/** Maximum length of a block anchor. */
|
|
335
|
+
export declare const MAX_BLOCK_ANCHOR_LENGTH = 64;
|
|
336
|
+
/** Maximum length of a normalized block class name. */
|
|
337
|
+
export declare const MAX_BLOCK_CLASS_NAME_LENGTH = 256;
|
|
338
|
+
/** Maximum number of class tokens in a block class name. */
|
|
339
|
+
export declare const MAX_BLOCK_CLASS_TOKENS = 16;
|
|
340
|
+
/** Maximum length of one block class token. */
|
|
341
|
+
export declare const MAX_BLOCK_CLASS_TOKEN_LENGTH = 64;
|
|
342
|
+
/** Whether a value is a block anchor: a lowercase letter, then lowercase letters, digits and hyphens. */
|
|
343
|
+
export declare function isBlockAnchor(value: unknown): value is string;
|
|
344
|
+
/**
|
|
345
|
+
* Normalizes a block class name: whitespace-separated class tokens, repeats
|
|
346
|
+
* dropped, joined with single spaces. Returns `undefined` for a non-string,
|
|
347
|
+
* blank or invalid value.
|
|
348
|
+
*/
|
|
349
|
+
export declare function normalizeBlockClassName(value: unknown): string | undefined;
|
|
217
350
|
/** Thrown when a block definition or registry is not portable or internally consistent. */
|
|
218
351
|
export declare class BlockConfigurationError extends Error {
|
|
219
352
|
constructor(message: string);
|
|
220
353
|
}
|
|
354
|
+
/** The stored data and settings a block migration step receives. */
|
|
355
|
+
export interface BlockMigrationInput {
|
|
356
|
+
readonly data: JsonObject;
|
|
357
|
+
readonly settings: JsonObject;
|
|
358
|
+
}
|
|
359
|
+
/** A migration step's result; leaving out `settings` keeps the input settings. */
|
|
360
|
+
export interface BlockMigrationOutput {
|
|
361
|
+
readonly data: JsonObject;
|
|
362
|
+
readonly settings?: JsonObject;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* A pure, synchronous step that turns the stored data and settings of the
|
|
366
|
+
* previous block version into those of its target version.
|
|
367
|
+
*/
|
|
368
|
+
export type BlockMigration = (block: BlockMigrationInput) => BlockMigrationOutput;
|
|
369
|
+
/** Migrations keyed by target version; the keys form one range ending at the block version. */
|
|
370
|
+
export type BlockMigrations = Readonly<Record<number, BlockMigration>>;
|
|
371
|
+
/** Field types a block setting may use; every setting declares a default. */
|
|
372
|
+
export declare const BLOCK_SETTING_FIELD_TYPES: readonly ["boolean", "number", "select", "text"];
|
|
373
|
+
/** The settings of a block that declares none. */
|
|
374
|
+
export type NoBlockSettings = Readonly<Record<never, FieldDefinition>>;
|
|
221
375
|
/** Input accepted by the portable block-definition DSL. */
|
|
222
|
-
export interface BlockDefinitionInput<Fields extends ModelFieldDefinitions = ModelFieldDefinitions> {
|
|
376
|
+
export interface BlockDefinitionInput<Fields extends ModelFieldDefinitions = ModelFieldDefinitions, Settings extends ModelFieldDefinitions = ModelFieldDefinitions> {
|
|
223
377
|
readonly defaultValue?: unknown;
|
|
224
378
|
readonly description?: string;
|
|
225
379
|
readonly fields: Fields;
|
|
380
|
+
readonly layout?: FormLayout<keyof Fields & string>;
|
|
381
|
+
readonly settingsLayout?: FormLayout<keyof Settings & string>;
|
|
226
382
|
readonly label?: string;
|
|
383
|
+
/** Data and settings migrations from earlier versions, keyed by target version. */
|
|
384
|
+
readonly migrations?: BlockMigrations;
|
|
385
|
+
/** Presentational settings: `select`, `boolean`, `number` or `text` fields with defaults. */
|
|
386
|
+
readonly settings?: Settings;
|
|
227
387
|
readonly type: string;
|
|
228
388
|
readonly version: number;
|
|
229
389
|
}
|
|
@@ -233,21 +393,31 @@ export type BlockDataValues<Fields extends ModelFieldDefinitions> = Readonly<{
|
|
|
233
393
|
} & {
|
|
234
394
|
readonly [Key in keyof Fields as FieldIsRequired<Fields[Key]> extends true ? never : Key]?: FieldValue<Fields[Key]>;
|
|
235
395
|
}>;
|
|
396
|
+
/** The settings record of a block; every setting has a default, so every key is present. */
|
|
397
|
+
export type BlockSettingsValues<Settings extends ModelFieldDefinitions> = Readonly<{
|
|
398
|
+
[Key in keyof Settings]: FieldValue<Settings[Key]>;
|
|
399
|
+
}>;
|
|
236
400
|
/** A detached JSON-safe representation of a block definition. */
|
|
237
|
-
export interface BlockMetadata<Fields extends ModelFieldDefinitions = ModelFieldDefinitions> {
|
|
401
|
+
export interface BlockMetadata<Fields extends ModelFieldDefinitions = ModelFieldDefinitions, Settings extends ModelFieldDefinitions = ModelFieldDefinitions> {
|
|
238
402
|
readonly defaultValue?: BlockDataValues<Fields>;
|
|
239
403
|
readonly description?: string;
|
|
240
404
|
readonly fields: Fields;
|
|
405
|
+
readonly layout?: FormLayout<keyof Fields & string>;
|
|
406
|
+
readonly settingsLayout?: FormLayout<keyof Settings & string>;
|
|
241
407
|
readonly label?: string;
|
|
408
|
+
/** Declared settings; absent when the block declares none. */
|
|
409
|
+
readonly settings?: Settings;
|
|
242
410
|
readonly type: string;
|
|
243
411
|
readonly version: number;
|
|
244
412
|
}
|
|
245
413
|
/** An executable block definition retained only in the runtime projection. */
|
|
246
|
-
export interface BlockDefinition<Fields extends ModelFieldDefinitions = ModelFieldDefinitions> extends BlockMetadata<Fields> {
|
|
414
|
+
export interface BlockDefinition<Fields extends ModelFieldDefinitions = ModelFieldDefinitions, Settings extends ModelFieldDefinitions = ModelFieldDefinitions> extends BlockMetadata<Fields, Settings> {
|
|
415
|
+
/** Runtime-only migrations keyed by target version; never part of metadata. */
|
|
416
|
+
readonly migrations?: BlockMigrations;
|
|
247
417
|
readonly validate: (value: unknown, mode: ContentValidationMode) => BlockDataValues<Fields>;
|
|
248
418
|
}
|
|
249
419
|
/** Defines a versioned block using only portable field descriptors. */
|
|
250
|
-
export declare function defineBlock<const Fields extends ModelFieldDefinitions>(input: BlockDefinitionInput<Fields>): BlockDefinition<Fields>;
|
|
420
|
+
export declare function defineBlock<const Fields extends ModelFieldDefinitions, const Settings extends ModelFieldDefinitions = NoBlockSettings>(input: BlockDefinitionInput<Fields, Settings>): BlockDefinition<Fields, Settings>;
|
|
251
421
|
/** Projects a block definition into detached, JSON-safe metadata. */
|
|
252
422
|
export declare function toBlockMetadata(definition: BlockDefinition): BlockMetadata;
|
|
253
423
|
/** A registry of the current executable definition for every allowed block type. */
|
|
@@ -261,6 +431,39 @@ export declare function defineBlockRegistry(blocks: readonly BlockDefinition[]):
|
|
|
261
431
|
export declare function toBlockRegistryMetadata(registry: BlockRegistry): readonly BlockMetadata[];
|
|
262
432
|
/** Validates one block's field record, applying its whole-record default first. */
|
|
263
433
|
export declare function validateBlockData<Fields extends ModelFieldDefinitions>(definition: BlockDefinition<Fields>, value: unknown, mode: ContentValidationMode, path?: readonly ValidationPathSegment[]): BlockDataValues<Fields>;
|
|
434
|
+
/**
|
|
435
|
+
* Validates a block's settings record against its declared settings, filling
|
|
436
|
+
* every default; a block that declares none accepts only `{}`.
|
|
437
|
+
*/
|
|
438
|
+
export declare function validateBlockSettings(definition: Pick<BlockMetadata, "settings">, value: unknown, path?: readonly ValidationPathSegment[]): JsonObject;
|
|
439
|
+
/** Why stored block data could not be migrated to the current block version. */
|
|
440
|
+
export type BlockMigrationErrorCode = "invalid_result" | "migration_failed" | "missing_step" | "version_ahead";
|
|
441
|
+
/** Thrown when stored block data cannot be migrated to its definition's version. */
|
|
442
|
+
export declare class BlockMigrationError extends Error {
|
|
443
|
+
readonly code: BlockMigrationErrorCode;
|
|
444
|
+
readonly blockType: string;
|
|
445
|
+
readonly fromVersion: number;
|
|
446
|
+
readonly toVersion: number;
|
|
447
|
+
/** Target version of the failing step, for failed or invalid steps. */
|
|
448
|
+
readonly step?: number | undefined;
|
|
449
|
+
constructor(code: BlockMigrationErrorCode, blockType: string, fromVersion: number, toVersion: number, message: string,
|
|
450
|
+
/** Target version of the failing step, for failed or invalid steps. */
|
|
451
|
+
step?: number | undefined, options?: {
|
|
452
|
+
readonly cause?: unknown;
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Migrates stored block data and settings from `fromVersion` to the
|
|
457
|
+
* definition's version by composing its declared migrations in ascending
|
|
458
|
+
* order. Each step receives a detached, frozen copy. The result is not
|
|
459
|
+
* validated against the definition.
|
|
460
|
+
*/
|
|
461
|
+
export declare function migrateBlockData(definition: BlockDefinition, block: BlockMigrationInput, fromVersion: number): BlockMigrationInput;
|
|
462
|
+
/**
|
|
463
|
+
* Resolves the alt text of one media usage: a non-blank usage alt (such as the
|
|
464
|
+
* `image` block's `alt`), then a non-blank media alt, then an empty string.
|
|
465
|
+
*/
|
|
466
|
+
export declare function effectiveAltText(usageAlt: string | null | undefined, mediaAlt: string | null | undefined): string;
|
|
264
467
|
/** Starter blocks implemented exclusively through the public block and field DSL. */
|
|
265
468
|
export declare const builtInBlocks: {
|
|
266
469
|
cta: BlockDefinition<{
|
|
@@ -272,14 +475,59 @@ export declare const builtInBlocks: {
|
|
|
272
475
|
readonly required: true;
|
|
273
476
|
readonly type: "url";
|
|
274
477
|
};
|
|
275
|
-
readonly body:
|
|
478
|
+
readonly body: {
|
|
479
|
+
readonly required: false;
|
|
480
|
+
readonly type: "richText";
|
|
481
|
+
};
|
|
276
482
|
readonly heading: {
|
|
277
483
|
readonly required: true;
|
|
278
484
|
readonly type: "text";
|
|
279
485
|
};
|
|
280
|
-
}
|
|
486
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
487
|
+
gallery: BlockDefinition<{
|
|
488
|
+
readonly images: {
|
|
489
|
+
readonly required: false;
|
|
490
|
+
readonly type: "list";
|
|
491
|
+
} & {
|
|
492
|
+
readonly defaultValue: readonly [];
|
|
493
|
+
} & {
|
|
494
|
+
readonly label: "Images";
|
|
495
|
+
} & {
|
|
496
|
+
readonly item: {
|
|
497
|
+
readonly required: false;
|
|
498
|
+
readonly type: "group";
|
|
499
|
+
} & {
|
|
500
|
+
readonly fields: {
|
|
501
|
+
readonly alt: TextFieldDefinition<{
|
|
502
|
+
readonly description: "Leave empty to use the media item's alt text.";
|
|
503
|
+
readonly label: "Alt text";
|
|
504
|
+
}>;
|
|
505
|
+
readonly caption: TextFieldDefinition<{
|
|
506
|
+
readonly description: "Leave empty to use the media item's caption.";
|
|
507
|
+
readonly label: "Caption";
|
|
508
|
+
}>;
|
|
509
|
+
readonly media: MediaFieldDefinition<{
|
|
510
|
+
readonly label: "Image";
|
|
511
|
+
readonly required: true;
|
|
512
|
+
}>;
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
} & {
|
|
516
|
+
readonly minItems: 1;
|
|
517
|
+
} & {
|
|
518
|
+
readonly maxItems: 50;
|
|
519
|
+
} & {
|
|
520
|
+
readonly itemLabel: "caption";
|
|
521
|
+
};
|
|
522
|
+
readonly title: TextFieldDefinition<{
|
|
523
|
+
readonly label: "Title";
|
|
524
|
+
}>;
|
|
525
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
281
526
|
hero: BlockDefinition<{
|
|
282
|
-
readonly body:
|
|
527
|
+
readonly body: {
|
|
528
|
+
readonly required: false;
|
|
529
|
+
readonly type: "richText";
|
|
530
|
+
};
|
|
283
531
|
readonly eyebrow: {
|
|
284
532
|
readonly required: false;
|
|
285
533
|
readonly type: "text";
|
|
@@ -288,16 +536,22 @@ export declare const builtInBlocks: {
|
|
|
288
536
|
readonly required: true;
|
|
289
537
|
readonly type: "text";
|
|
290
538
|
};
|
|
291
|
-
readonly image:
|
|
539
|
+
readonly image: {
|
|
540
|
+
readonly required: false;
|
|
541
|
+
readonly type: "media";
|
|
542
|
+
};
|
|
292
543
|
readonly primaryActionLabel: {
|
|
293
544
|
readonly required: false;
|
|
294
545
|
readonly type: "text";
|
|
295
546
|
};
|
|
296
|
-
readonly primaryActionUrl:
|
|
297
|
-
|
|
547
|
+
readonly primaryActionUrl: {
|
|
548
|
+
readonly required: false;
|
|
549
|
+
readonly type: "url";
|
|
550
|
+
};
|
|
551
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
298
552
|
image: BlockDefinition<{
|
|
299
553
|
readonly alt: {
|
|
300
|
-
readonly required:
|
|
554
|
+
readonly required: false;
|
|
301
555
|
readonly type: "text";
|
|
302
556
|
};
|
|
303
557
|
readonly caption: {
|
|
@@ -308,7 +562,69 @@ export declare const builtInBlocks: {
|
|
|
308
562
|
readonly required: true;
|
|
309
563
|
readonly type: "media";
|
|
310
564
|
};
|
|
311
|
-
}
|
|
565
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
566
|
+
navigation: BlockDefinition<{
|
|
567
|
+
readonly links: {
|
|
568
|
+
readonly required: false;
|
|
569
|
+
readonly type: "list";
|
|
570
|
+
} & {
|
|
571
|
+
readonly defaultValue: readonly [];
|
|
572
|
+
} & {
|
|
573
|
+
readonly label: "Links";
|
|
574
|
+
} & {
|
|
575
|
+
readonly item: {
|
|
576
|
+
readonly required: false;
|
|
577
|
+
readonly type: "group";
|
|
578
|
+
} & {
|
|
579
|
+
readonly fields: {
|
|
580
|
+
readonly children: {
|
|
581
|
+
readonly required: false;
|
|
582
|
+
readonly type: "list";
|
|
583
|
+
} & {
|
|
584
|
+
readonly label: "Submenu links";
|
|
585
|
+
} & {
|
|
586
|
+
readonly item: {
|
|
587
|
+
readonly required: false;
|
|
588
|
+
readonly type: "group";
|
|
589
|
+
} & {
|
|
590
|
+
readonly fields: {
|
|
591
|
+
readonly label: TextFieldDefinition<{
|
|
592
|
+
readonly label: "Label";
|
|
593
|
+
readonly required: true;
|
|
594
|
+
}>;
|
|
595
|
+
readonly url: UrlFieldDefinition<{
|
|
596
|
+
readonly label: "URL";
|
|
597
|
+
readonly required: true;
|
|
598
|
+
}>;
|
|
599
|
+
};
|
|
600
|
+
};
|
|
601
|
+
} & {
|
|
602
|
+
readonly maxItems: 20;
|
|
603
|
+
} & {
|
|
604
|
+
readonly itemLabel: "label";
|
|
605
|
+
};
|
|
606
|
+
readonly label: TextFieldDefinition<{
|
|
607
|
+
readonly label: "Label";
|
|
608
|
+
readonly required: true;
|
|
609
|
+
}>;
|
|
610
|
+
readonly url: UrlFieldDefinition<{
|
|
611
|
+
readonly description: "Optional when the link has submenu links.";
|
|
612
|
+
readonly label: "URL";
|
|
613
|
+
}>;
|
|
614
|
+
};
|
|
615
|
+
};
|
|
616
|
+
} & {
|
|
617
|
+
readonly minItems: 1;
|
|
618
|
+
} & {
|
|
619
|
+
readonly maxItems: 20;
|
|
620
|
+
} & {
|
|
621
|
+
readonly itemLabel: "label";
|
|
622
|
+
};
|
|
623
|
+
readonly name: TextFieldDefinition<{
|
|
624
|
+
readonly description: "Read by screen readers, for example Main or On this page.";
|
|
625
|
+
readonly label: "Navigation name";
|
|
626
|
+
}>;
|
|
627
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
312
628
|
quote: BlockDefinition<{
|
|
313
629
|
readonly attribution: {
|
|
314
630
|
readonly required: false;
|
|
@@ -318,13 +634,13 @@ export declare const builtInBlocks: {
|
|
|
318
634
|
readonly required: true;
|
|
319
635
|
readonly type: "text";
|
|
320
636
|
};
|
|
321
|
-
}
|
|
637
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
322
638
|
richText: BlockDefinition<{
|
|
323
639
|
readonly content: {
|
|
324
640
|
readonly required: true;
|
|
325
641
|
readonly type: "richText";
|
|
326
642
|
};
|
|
327
|
-
}
|
|
643
|
+
}, Readonly<Record<never, FieldDefinition>>>;
|
|
328
644
|
};
|
|
329
645
|
/** Maximum title length shared by draft, publish, REST, and admin validation. */
|
|
330
646
|
export declare const MAX_TITLE_LENGTH = 200;
|
|
@@ -334,8 +650,8 @@ export declare const MAX_SLUG_LENGTH = 100;
|
|
|
334
650
|
export declare const MAX_TOP_LEVEL_BLOCKS = 200;
|
|
335
651
|
/** Maximum UTF-8 bytes in fields JSON or a single block data JSON value. */
|
|
336
652
|
export declare const MAX_JSON_BYTES = 1000000;
|
|
337
|
-
/**
|
|
338
|
-
export type ContentModelKind = "collection" | "page";
|
|
653
|
+
/** Model kinds: routed singletons, routed lists, and route-less singletons. */
|
|
654
|
+
export type ContentModelKind = "collection" | "global" | "page";
|
|
339
655
|
/** A block-like value whose data can be limited before the Step 3 block registry exists. */
|
|
340
656
|
export interface EntryBlockData {
|
|
341
657
|
readonly data: JsonValue;
|
|
@@ -370,9 +686,24 @@ export interface EntryAggregateModel {
|
|
|
370
686
|
}
|
|
371
687
|
/** One ordered, typed block submitted as part of an entry aggregate. */
|
|
372
688
|
export interface EntryAggregateBlock {
|
|
689
|
+
readonly anchor?: string;
|
|
690
|
+
readonly className?: string;
|
|
373
691
|
readonly data: JsonObject;
|
|
692
|
+
readonly hidden?: boolean;
|
|
693
|
+
readonly key: string;
|
|
694
|
+
readonly schemaVersion: number;
|
|
695
|
+
readonly settings?: JsonObject;
|
|
696
|
+
readonly type: string;
|
|
697
|
+
}
|
|
698
|
+
/** A validated block: normalized data, settings with defaults, and the envelope. */
|
|
699
|
+
export interface ValidatedEntryAggregateBlock {
|
|
700
|
+
readonly anchor?: string;
|
|
701
|
+
readonly className?: string;
|
|
702
|
+
readonly data: ModelFieldValues;
|
|
703
|
+
readonly hidden: boolean;
|
|
374
704
|
readonly key: string;
|
|
375
705
|
readonly schemaVersion: number;
|
|
706
|
+
readonly settings: JsonObject;
|
|
376
707
|
readonly type: string;
|
|
377
708
|
}
|
|
378
709
|
/** A full draft or publish candidate validated against a model and its registry. */
|
|
@@ -385,9 +716,7 @@ export interface EntryAggregateInput {
|
|
|
385
716
|
}
|
|
386
717
|
/** The normalized form of a valid entry aggregate. */
|
|
387
718
|
export interface ValidatedEntryAggregate {
|
|
388
|
-
readonly blocks: readonly
|
|
389
|
-
readonly data: ModelFieldValues;
|
|
390
|
-
})[];
|
|
719
|
+
readonly blocks: readonly ValidatedEntryAggregateBlock[];
|
|
391
720
|
readonly fields: ModelFieldValues;
|
|
392
721
|
readonly kind: ContentModelKind;
|
|
393
722
|
readonly slug?: string;
|
|
@@ -395,5 +724,9 @@ export interface ValidatedEntryAggregate {
|
|
|
395
724
|
}
|
|
396
725
|
/** Validates all system, model-field, and ordered block data for one content entry. */
|
|
397
726
|
export declare function validateEntryAggregate(input: EntryAggregateInput, model: EntryAggregateModel, registry: BlockRegistry, mode: ContentValidationMode): ValidatedEntryAggregate;
|
|
398
|
-
export {};
|
|
727
|
+
export { parseSchemaPath, encodeSchemaPath, schemaFieldAt } from "./schema-path.js";
|
|
728
|
+
/** Raw UTF-16 units: the existing text/textarea length contract, without trimming. */
|
|
729
|
+
export declare function textLength(value: string): number;
|
|
730
|
+
/** Trimmed Unicode code points: the existing SEO title/description contract. */
|
|
731
|
+
export declare function seoTextLength(value: string): number;
|
|
399
732
|
//# sourceMappingURL=index.d.ts.map
|