@valbuild/core 0.106.0 → 0.110.0
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/declarations/src/index.d.ts +4 -4
- package/dist/declarations/src/initSchema.d.ts +20 -20
- package/dist/declarations/src/preview.d.ts +40 -2
- package/dist/declarations/src/render.d.ts +64 -9
- package/dist/declarations/src/schema/array.d.ts +24 -12
- package/dist/declarations/src/schema/boolean.d.ts +25 -2
- package/dist/declarations/src/schema/color.d.ts +25 -2
- package/dist/declarations/src/schema/date.d.ts +25 -2
- package/dist/declarations/src/schema/datetime.d.ts +25 -2
- package/dist/declarations/src/schema/file.d.ts +25 -2
- package/dist/declarations/src/schema/image.d.ts +61 -5
- package/dist/declarations/src/schema/images.d.ts +8 -0
- package/dist/declarations/src/schema/index.d.ts +19 -1
- package/dist/declarations/src/schema/keyOf.d.ts +25 -2
- package/dist/declarations/src/schema/literal.d.ts +25 -2
- package/dist/declarations/src/schema/number.d.ts +25 -2
- package/dist/declarations/src/schema/object.d.ts +25 -2
- package/dist/declarations/src/schema/record.d.ts +29 -13
- package/dist/declarations/src/schema/richtext.d.ts +25 -2
- package/dist/declarations/src/schema/route.d.ts +25 -2
- package/dist/declarations/src/schema/string.d.ts +13 -2
- package/dist/declarations/src/schema/union.d.ts +32 -2
- package/dist/{index-2cef45cc.cjs.dev.js → index-409a38c3.cjs.dev.js} +1072 -192
- package/dist/{index-eaee0a0b.cjs.prod.js → index-62ef4533.cjs.prod.js} +1072 -192
- package/dist/{index-193f19b4.esm.js → index-6652ab3c.esm.js} +1072 -193
- package/dist/valbuild-core.cjs.dev.js +2 -1
- package/dist/valbuild-core.cjs.prod.js +2 -1
- package/dist/valbuild-core.esm.js +1 -1
- package/package.json +2 -2
- package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
- package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
- package/patch/dist/valbuild-core-patch.esm.js +2 -2
|
@@ -3,16 +3,54 @@ import { GalleryImageSource, ImageSource } from "../source/media.js";
|
|
|
3
3
|
import { ModulePath, SourcePath } from "../val/index.js";
|
|
4
4
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
5
5
|
import { ValModule } from "../index.js";
|
|
6
|
-
import { ReifiedPreview } from "../preview.js";
|
|
6
|
+
import { ItemPreviewInput, PreviewItem, ReifiedPreview } from "../preview.js";
|
|
7
|
+
import { FieldRender } from "../render.js";
|
|
7
8
|
import { ImagesEntryMetadata } from "./images.js";
|
|
9
|
+
/**
|
|
10
|
+
* How an uploaded image is re-encoded in the browser, before it is uploaded.
|
|
11
|
+
*
|
|
12
|
+
* Off unless a schema asks for it. When it is on, the image is converted to
|
|
13
|
+
* `type` and scaled down to fit `maxWidth` x `maxHeight` - unless the result
|
|
14
|
+
* would be BIGGER than the original and no downscale was needed, in which case
|
|
15
|
+
* the original bytes are kept. See `architecture/media.md`.
|
|
16
|
+
*
|
|
17
|
+
* `type` is required so that adding a format later is additive: a schema
|
|
18
|
+
* written today keeps saying exactly which format it asked for.
|
|
19
|
+
*/
|
|
20
|
+
export type ImageEncodeOptions = {
|
|
21
|
+
type: "webp";
|
|
22
|
+
/** Passed to `canvas.toBlob`. Between 0 and 1. @default 0.8 */
|
|
23
|
+
quality?: number;
|
|
24
|
+
/** @default 2560 */
|
|
25
|
+
maxWidth?: number;
|
|
26
|
+
/** @default 2560 */
|
|
27
|
+
maxHeight?: number;
|
|
28
|
+
};
|
|
29
|
+
/** `false` (or absent) uploads the bytes exactly as the editor picked them. */
|
|
30
|
+
export type ImageEncodeOption = false | ImageEncodeOptions;
|
|
31
|
+
/**
|
|
32
|
+
* What a GALLERY-BACKED field may say for itself.
|
|
33
|
+
*
|
|
34
|
+
* Not `ImageOptions`: `directory` and `accept` belong to the gallery, and a
|
|
35
|
+
* field repeating them is how two copies of one fact get to disagree. `encode`
|
|
36
|
+
* is different — it describes what happens to the bytes on their way IN, so a
|
|
37
|
+
* field that wants the original where its gallery re-encodes has to be able to
|
|
38
|
+
* say `encode: false`, and there is nowhere else to say it.
|
|
39
|
+
*/
|
|
40
|
+
export type GalleryImageOptions = {
|
|
41
|
+
encode?: ImageEncodeOption;
|
|
42
|
+
};
|
|
8
43
|
export type ImageOptions = {
|
|
9
|
-
ext?: ["jpg"] | ["webp"];
|
|
10
44
|
directory?: string;
|
|
11
|
-
prefix?: string;
|
|
12
45
|
accept?: string;
|
|
46
|
+
encode?: ImageEncodeOption;
|
|
13
47
|
};
|
|
14
48
|
export type SerializedImageSchema = {
|
|
15
49
|
type: "image";
|
|
50
|
+
/** Static layout config, carried whole in the serialized schema — see `render.ts`. */
|
|
51
|
+
render?: FieldRender;
|
|
52
|
+
/** Set when this schema declares a `preview`. The closure itself cannot serialize. */
|
|
53
|
+
preview?: true;
|
|
16
54
|
options?: ImageOptions;
|
|
17
55
|
opt: boolean;
|
|
18
56
|
remote?: boolean;
|
|
@@ -41,7 +79,9 @@ export declare class ImageSchema<Src extends ImageSource | null> extends Schema<
|
|
|
41
79
|
private readonly isReadonly;
|
|
42
80
|
private readonly isHidden;
|
|
43
81
|
private readonly description?;
|
|
44
|
-
|
|
82
|
+
private readonly renderInput;
|
|
83
|
+
private readonly previewInput;
|
|
84
|
+
constructor(options?: ImageOptions | undefined, opt?: boolean, isRemote?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], moduleMetadata?: Record<ModulePath, Record<string, ImagesEntryMetadata>>, isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, renderInput?: FieldRender | null, previewInput?: ItemPreviewInput<Src> | null);
|
|
45
85
|
describe(description: string | null): ImageSchema<Src>;
|
|
46
86
|
remote(): ImageSchema<Src>;
|
|
47
87
|
validate(validationFunction: CustomValidateFunction<Src>): ImageSchema<Src>;
|
|
@@ -56,6 +96,22 @@ export declare class ImageSchema<Src extends ImageSource | null> extends Schema<
|
|
|
56
96
|
readonly(): ImageSchema<Src>;
|
|
57
97
|
hidden(): ImageSchema<Src>;
|
|
58
98
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
99
|
+
/**
|
|
100
|
+
* How this field is laid out in the editor when it is the item of an array
|
|
101
|
+
* or record: `{ as: "inline" }` renders the field itself inside each row,
|
|
102
|
+
* instead of a preview row that navigates to it.
|
|
103
|
+
*
|
|
104
|
+
* Static configuration, not a callback — see `render.ts`.
|
|
105
|
+
*/
|
|
106
|
+
render(input: FieldRender): ImageSchema<Src>;
|
|
107
|
+
/**
|
|
108
|
+
* How this VALUE is shown where a preview of it is needed — a row in a
|
|
109
|
+
* sortable list, a reference dropdown, a search hit. Never how the field
|
|
110
|
+
* itself is edited (that is `render`). See `preview.ts`.
|
|
111
|
+
*/
|
|
112
|
+
preview(select: ItemPreviewInput<Src>): ImageSchema<Src>;
|
|
113
|
+
protected executePreviewItem(src: NonNullable<Src>): PreviewItem | null;
|
|
114
|
+
protected declaresItemPreview(): boolean;
|
|
59
115
|
protected executeSerialize(): SerializedSchema;
|
|
60
116
|
protected executePreview(): ReifiedPreview;
|
|
61
117
|
}
|
|
@@ -63,6 +119,6 @@ export declare class ImageSchema<Src extends ImageSource | null> extends Schema<
|
|
|
63
119
|
* An image picked from a gallery. Its dimensions and mime type live in the
|
|
64
120
|
* gallery, so the field carries only what a person typed.
|
|
65
121
|
*/
|
|
66
|
-
export declare function image(galleryModule: ValModule<Record<string, ImagesEntryMetadata
|
|
122
|
+
export declare function image(galleryModule: ValModule<Record<string, ImagesEntryMetadata>>, galleryOptions?: GalleryImageOptions): ImageSchema<GalleryImageSource>;
|
|
67
123
|
/** An image of its own, carrying its own dimensions and mime type. */
|
|
68
124
|
export declare function image(options?: ImageOptions): ImageSchema<ImageSource>;
|
|
@@ -4,6 +4,7 @@ import { RecordSchema } from "./record.js";
|
|
|
4
4
|
import { ObjectSchema } from "./object.js";
|
|
5
5
|
import { StringSchema } from "./string.js";
|
|
6
6
|
import { NumberSchema } from "./number.js";
|
|
7
|
+
import type { ImageEncodeOption } from "./image.js";
|
|
7
8
|
/**
|
|
8
9
|
* Alt schema type - can be a string, nullable string, or a record of locale to string
|
|
9
10
|
*/
|
|
@@ -39,6 +40,13 @@ export type ImagesOptions<Accept extends `image/${string}`> = {
|
|
|
39
40
|
* @default false
|
|
40
41
|
*/
|
|
41
42
|
remote?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Re-encode uploads in the browser before they are uploaded.
|
|
45
|
+
*
|
|
46
|
+
* Off unless set. A field backed by this gallery (`s.image(galleryVal)`)
|
|
47
|
+
* inherits it, the same way it inherits `accept` and `directory`.
|
|
48
|
+
*/
|
|
49
|
+
encode?: ImageEncodeOption;
|
|
42
50
|
};
|
|
43
51
|
/**
|
|
44
52
|
* Metadata for an image entry in the images record
|
|
@@ -19,7 +19,7 @@ import { SerializedRouteSchema } from "./route.js";
|
|
|
19
19
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
20
20
|
import { FileSource } from "../source/media.js";
|
|
21
21
|
import { GenericRichTextSourceNode, RichTextSource } from "../source/richtext.js";
|
|
22
|
-
import { ReifiedPreview, PreviewScope } from "../preview.js";
|
|
22
|
+
import { ReifiedPreview, PreviewScope, PreviewItem } from "../preview.js";
|
|
23
23
|
export type SerializedSchema = SerializedStringSchema | SerializedLiteralSchema | SerializedBooleanSchema | SerializedNumberSchema | SerializedObjectSchema | SerializedArraySchema | SerializedUnionSchema | SerializedRichTextSchema | SerializedRecordSchema | SerializedKeyOfSchema | SerializedFileSchema | SerializedDateSchema | SerializedDateTimeSchema | SerializedColorSchema | SerializedRouteSchema | SerializedImageSchema;
|
|
24
24
|
type Primitives = number | string | boolean | null | FileSource;
|
|
25
25
|
export type AssertError = {
|
|
@@ -114,6 +114,24 @@ export declare abstract class Schema<Src extends SelectorSource> {
|
|
|
114
114
|
* its items are — which is the single-visible-row case.
|
|
115
115
|
*/
|
|
116
116
|
protected abstract executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
|
|
117
|
+
/**
|
|
118
|
+
* This value AS A PREVIEW — what a container's row, a reference dropdown or
|
|
119
|
+
* a search hit shows for it. Runs the schema's own `preview` closure;
|
|
120
|
+
* `null` when none is declared (the consumer falls back to a generic
|
|
121
|
+
* preview). A union dispatches to the matching member's closure.
|
|
122
|
+
*
|
|
123
|
+
* Containers call this on their ITEM schema per item — that is how
|
|
124
|
+
* `executePreview` reifies an {@link ArrayPreview} / {@link RecordPreview}
|
|
125
|
+
* from item-level declarations.
|
|
126
|
+
*/
|
|
127
|
+
protected executePreviewItem(src: NonNullable<Src>): PreviewItem | null;
|
|
128
|
+
/**
|
|
129
|
+
* Could {@link executePreviewItem} ever answer? A container reifies a rows
|
|
130
|
+
* preview only when its item schema says yes — asked here rather than by
|
|
131
|
+
* running the closure, so an EMPTY list still previews as an empty list
|
|
132
|
+
* instead of not at all.
|
|
133
|
+
*/
|
|
134
|
+
protected declaresItemPreview(): boolean;
|
|
117
135
|
/** MUTATES! since internal and perf sensitive */
|
|
118
136
|
protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value: unknown, schemaError?: boolean): ValidationErrors;
|
|
119
137
|
/**
|
|
@@ -5,9 +5,14 @@ import { Source, SourceObject } from "../source/index.js";
|
|
|
5
5
|
import { SourcePath } from "../val/index.js";
|
|
6
6
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
7
7
|
import { RawString } from "./string.js";
|
|
8
|
-
import { ReifiedPreview } from "../preview.js";
|
|
8
|
+
import { ItemPreviewInput, PreviewItem, ReifiedPreview } from "../preview.js";
|
|
9
|
+
import { FieldRender } from "../render.js";
|
|
9
10
|
export type SerializedKeyOfSchema = {
|
|
10
11
|
type: "keyOf";
|
|
12
|
+
/** Static layout config, carried whole in the serialized schema — see `render.ts`. */
|
|
13
|
+
render?: FieldRender;
|
|
14
|
+
/** Set when this schema declares a `preview`. The closure itself cannot serialize. */
|
|
15
|
+
preview?: true;
|
|
11
16
|
path: SourcePath;
|
|
12
17
|
schema?: SerializedRefSchema | undefined;
|
|
13
18
|
opt: boolean;
|
|
@@ -34,7 +39,9 @@ export declare class KeyOfSchema<Sel extends GenericSelector<SourceObject>, Src
|
|
|
34
39
|
private readonly isReadonly;
|
|
35
40
|
private readonly isHidden;
|
|
36
41
|
private readonly description?;
|
|
37
|
-
|
|
42
|
+
private readonly renderInput;
|
|
43
|
+
private readonly previewInput;
|
|
44
|
+
constructor(schema?: SerializedRefSchema | undefined, sourcePath?: SourcePath | undefined, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, renderInput?: FieldRender | null, previewInput?: ItemPreviewInput<Src> | null);
|
|
38
45
|
describe(description: string | null): KeyOfSchema<Sel, Src>;
|
|
39
46
|
validate(validationFunction: (src: Src) => false | string): KeyOfSchema<Sel, Src>;
|
|
40
47
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
@@ -43,6 +50,22 @@ export declare class KeyOfSchema<Sel extends GenericSelector<SourceObject>, Src
|
|
|
43
50
|
readonly(): KeyOfSchema<Sel, Src>;
|
|
44
51
|
hidden(): KeyOfSchema<Sel, Src>;
|
|
45
52
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
53
|
+
/**
|
|
54
|
+
* How this field is laid out in the editor when it is the item of an array
|
|
55
|
+
* or record: `{ as: "inline" }` renders the field itself inside each row,
|
|
56
|
+
* instead of a preview row that navigates to it.
|
|
57
|
+
*
|
|
58
|
+
* Static configuration, not a callback — see `render.ts`.
|
|
59
|
+
*/
|
|
60
|
+
render(input: FieldRender): KeyOfSchema<Sel, Src>;
|
|
61
|
+
/**
|
|
62
|
+
* How this VALUE is shown where a preview of it is needed — a row in a
|
|
63
|
+
* sortable list, a reference dropdown, a search hit. Never how the field
|
|
64
|
+
* itself is edited (that is `render`). See `preview.ts`.
|
|
65
|
+
*/
|
|
66
|
+
preview(select: ItemPreviewInput<Src>): KeyOfSchema<Sel, Src>;
|
|
67
|
+
protected executePreviewItem(src: NonNullable<Src>): PreviewItem | null;
|
|
68
|
+
protected declaresItemPreview(): boolean;
|
|
46
69
|
protected executeSerialize(): SerializedSchema;
|
|
47
70
|
protected executePreview(): ReifiedPreview;
|
|
48
71
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import { ReifiedPreview } from "../preview.js";
|
|
2
|
+
import { ItemPreviewInput, PreviewItem, ReifiedPreview } from "../preview.js";
|
|
3
|
+
import { FieldRender } from "../render.js";
|
|
3
4
|
import { SourcePath } from "../val/index.js";
|
|
4
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
5
6
|
export type SerializedLiteralSchema = {
|
|
6
7
|
type: "literal";
|
|
8
|
+
/** Static layout config, carried whole in the serialized schema — see `render.ts`. */
|
|
9
|
+
render?: FieldRender;
|
|
10
|
+
/** Set when this schema declares a `preview`. The closure itself cannot serialize. */
|
|
11
|
+
preview?: true;
|
|
7
12
|
value: string;
|
|
8
13
|
opt: boolean;
|
|
9
14
|
customValidate?: boolean;
|
|
@@ -18,7 +23,9 @@ export declare class LiteralSchema<Src extends string | null> extends Schema<Src
|
|
|
18
23
|
private readonly isReadonly;
|
|
19
24
|
private readonly isHidden;
|
|
20
25
|
private readonly description?;
|
|
21
|
-
|
|
26
|
+
private readonly renderInput;
|
|
27
|
+
private readonly previewInput;
|
|
28
|
+
constructor(value: string, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, renderInput?: FieldRender | null, previewInput?: ItemPreviewInput<Src> | null);
|
|
22
29
|
describe(description: string | null): LiteralSchema<Src>;
|
|
23
30
|
validate(validationFunction: (src: Src) => false | string): LiteralSchema<Src>;
|
|
24
31
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
@@ -27,6 +34,22 @@ export declare class LiteralSchema<Src extends string | null> extends Schema<Src
|
|
|
27
34
|
readonly(): LiteralSchema<Src>;
|
|
28
35
|
hidden(): LiteralSchema<Src>;
|
|
29
36
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
37
|
+
/**
|
|
38
|
+
* How this field is laid out in the editor when it is the item of an array
|
|
39
|
+
* or record: `{ as: "inline" }` renders the field itself inside each row,
|
|
40
|
+
* instead of a preview row that navigates to it.
|
|
41
|
+
*
|
|
42
|
+
* Static configuration, not a callback — see `render.ts`.
|
|
43
|
+
*/
|
|
44
|
+
render(input: FieldRender): LiteralSchema<Src>;
|
|
45
|
+
/**
|
|
46
|
+
* How this VALUE is shown where a preview of it is needed — a row in a
|
|
47
|
+
* sortable list, a reference dropdown, a search hit. Never how the field
|
|
48
|
+
* itself is edited (that is `render`). See `preview.ts`.
|
|
49
|
+
*/
|
|
50
|
+
preview(select: ItemPreviewInput<Src>): LiteralSchema<Src>;
|
|
51
|
+
protected executePreviewItem(src: NonNullable<Src>): PreviewItem | null;
|
|
52
|
+
protected declaresItemPreview(): boolean;
|
|
30
53
|
protected executeSerialize(): SerializedSchema;
|
|
31
54
|
protected executePreview(): ReifiedPreview;
|
|
32
55
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import { ReifiedPreview } from "../preview.js";
|
|
2
|
+
import { ItemPreviewInput, PreviewItem, ReifiedPreview } from "../preview.js";
|
|
3
|
+
import { FieldRender } from "../render.js";
|
|
3
4
|
import { SourcePath } from "../val/index.js";
|
|
4
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
5
6
|
type NumberOptions = {
|
|
@@ -8,6 +9,10 @@ type NumberOptions = {
|
|
|
8
9
|
};
|
|
9
10
|
export type SerializedNumberSchema = {
|
|
10
11
|
type: "number";
|
|
12
|
+
/** Static layout config, carried whole in the serialized schema — see `render.ts`. */
|
|
13
|
+
render?: FieldRender;
|
|
14
|
+
/** Set when this schema declares a `preview`. The closure itself cannot serialize. */
|
|
15
|
+
preview?: true;
|
|
11
16
|
options?: NumberOptions;
|
|
12
17
|
opt: boolean;
|
|
13
18
|
customValidate?: boolean;
|
|
@@ -22,7 +27,9 @@ export declare class NumberSchema<Src extends number | null> extends Schema<Src>
|
|
|
22
27
|
private readonly isReadonly;
|
|
23
28
|
private readonly isHidden;
|
|
24
29
|
private readonly description?;
|
|
25
|
-
|
|
30
|
+
private readonly renderInput;
|
|
31
|
+
private readonly previewInput;
|
|
32
|
+
constructor(options?: NumberOptions | undefined, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, renderInput?: FieldRender | null, previewInput?: ItemPreviewInput<Src> | null);
|
|
26
33
|
describe(description: string | null): NumberSchema<Src>;
|
|
27
34
|
validate(validationFunction: (src: Src) => false | string): NumberSchema<Src>;
|
|
28
35
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
@@ -33,6 +40,22 @@ export declare class NumberSchema<Src extends number | null> extends Schema<Src>
|
|
|
33
40
|
max(max: number): NumberSchema<Src>;
|
|
34
41
|
min(min: number): NumberSchema<Src>;
|
|
35
42
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
43
|
+
/**
|
|
44
|
+
* How this field is laid out in the editor when it is the item of an array
|
|
45
|
+
* or record: `{ as: "inline" }` renders the field itself inside each row,
|
|
46
|
+
* instead of a preview row that navigates to it.
|
|
47
|
+
*
|
|
48
|
+
* Static configuration, not a callback — see `render.ts`.
|
|
49
|
+
*/
|
|
50
|
+
render(input: FieldRender): NumberSchema<Src>;
|
|
51
|
+
/**
|
|
52
|
+
* How this VALUE is shown where a preview of it is needed — a row in a
|
|
53
|
+
* sortable list, a reference dropdown, a search hit. Never how the field
|
|
54
|
+
* itself is edited (that is `render`). See `preview.ts`.
|
|
55
|
+
*/
|
|
56
|
+
preview(select: ItemPreviewInput<Src>): NumberSchema<Src>;
|
|
57
|
+
protected executePreviewItem(src: NonNullable<Src>): PreviewItem | null;
|
|
58
|
+
protected declaresItemPreview(): boolean;
|
|
36
59
|
protected executeSerialize(): SerializedSchema;
|
|
37
60
|
protected executePreview(): ReifiedPreview;
|
|
38
61
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
|
|
2
|
-
import { ReifiedPreview, PreviewScope } from "../preview.js";
|
|
2
|
+
import { ItemPreviewInput, PreviewItem, ReifiedPreview, PreviewScope } from "../preview.js";
|
|
3
|
+
import { FieldRender } from "../render.js";
|
|
3
4
|
import { SelectorSource } from "../selector/index.js";
|
|
4
5
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
5
6
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
6
7
|
export type SerializedObjectSchema = {
|
|
7
8
|
type: "object";
|
|
9
|
+
/** Static layout config, carried whole in the serialized schema — see `render.ts`. */
|
|
10
|
+
render?: FieldRender;
|
|
11
|
+
/** Set when this schema declares a `preview`. The closure itself cannot serialize. */
|
|
12
|
+
preview?: true;
|
|
8
13
|
items: Record<string, SerializedSchema>;
|
|
9
14
|
opt: boolean;
|
|
10
15
|
customValidate?: boolean;
|
|
@@ -42,7 +47,9 @@ export declare class ObjectSchema<Props extends ObjectSchemaProps, Src extends O
|
|
|
42
47
|
private readonly isReadonly;
|
|
43
48
|
private readonly isHidden;
|
|
44
49
|
private readonly description?;
|
|
45
|
-
|
|
50
|
+
private readonly renderInput;
|
|
51
|
+
private readonly previewInput;
|
|
52
|
+
constructor(items: Props, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, renderInput?: FieldRender | null, previewInput?: ItemPreviewInput<Src> | null);
|
|
46
53
|
describe(description: string | null): ObjectSchema<Props, Src>;
|
|
47
54
|
validate(validationFunction: (src: Src) => false | string): ObjectSchema<Props, Src>;
|
|
48
55
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
@@ -51,6 +58,22 @@ export declare class ObjectSchema<Props extends ObjectSchemaProps, Src extends O
|
|
|
51
58
|
readonly(): ObjectSchema<Props, Src>;
|
|
52
59
|
hidden(): ObjectSchema<Props, Src>;
|
|
53
60
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
61
|
+
/**
|
|
62
|
+
* How this field is laid out in the editor when it is the item of an array
|
|
63
|
+
* or record: `{ as: "inline" }` renders the field itself inside each row,
|
|
64
|
+
* instead of a preview row that navigates to it.
|
|
65
|
+
*
|
|
66
|
+
* Static configuration, not a callback — see `render.ts`.
|
|
67
|
+
*/
|
|
68
|
+
render(input: FieldRender): ObjectSchema<Props, Src>;
|
|
69
|
+
/**
|
|
70
|
+
* How this VALUE is shown where a preview of it is needed — a row in a
|
|
71
|
+
* sortable list, a reference dropdown, a search hit. Never how the field
|
|
72
|
+
* itself is edited (that is `render`). See `preview.ts`.
|
|
73
|
+
*/
|
|
74
|
+
preview(select: ItemPreviewInput<Src>): ObjectSchema<Props, Src>;
|
|
75
|
+
protected executePreviewItem(src: NonNullable<Src>): PreviewItem | null;
|
|
76
|
+
protected declaresItemPreview(): boolean;
|
|
54
77
|
protected executeSerialize(): SerializedSchema;
|
|
55
78
|
protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
|
|
56
79
|
}
|
|
@@ -1,30 +1,41 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ItemPreviewInput, PreviewItem, ReifiedPreview, PreviewScope } from "../preview.js";
|
|
3
|
+
import { FieldRender } from "../render.js";
|
|
3
4
|
import { ValRouter } from "../router.js";
|
|
4
5
|
import { SelectorSource } from "../selector/index.js";
|
|
5
6
|
import { JsonOf, JsonSource } from "../source/json.js";
|
|
6
7
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
7
8
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
9
|
+
import type { ImageEncodeOption } from "./image.js";
|
|
8
10
|
type MediaOptions = {
|
|
9
11
|
type: "files" | "images";
|
|
10
12
|
accept: string;
|
|
11
13
|
directory: string;
|
|
12
14
|
remote: boolean;
|
|
13
15
|
altSchema?: Schema<SelectorSource>;
|
|
16
|
+
/** Images only: how uploads are re-encoded in the browser. See `image.ts`. */
|
|
17
|
+
encode?: ImageEncodeOption;
|
|
14
18
|
};
|
|
15
19
|
export type SerializedRecordSchema = {
|
|
16
20
|
type: "record";
|
|
17
21
|
item: SerializedSchema;
|
|
18
22
|
key?: SerializedSchema;
|
|
19
23
|
opt: boolean;
|
|
20
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Set when this schema declares a `preview` — of the RECORD ITSELF as a
|
|
26
|
+
* value. Whether its ENTRIES preview is carried by the item's serialized
|
|
27
|
+
* schema. See `SerializedArraySchema`.
|
|
28
|
+
*/
|
|
21
29
|
preview?: true;
|
|
30
|
+
/** Static layout config, carried whole in the serialized schema — see `render.ts`. */
|
|
31
|
+
render?: FieldRender;
|
|
22
32
|
router?: string;
|
|
23
33
|
customValidate?: boolean;
|
|
24
34
|
mediaType?: "files" | "images";
|
|
25
35
|
accept?: string;
|
|
26
36
|
directory?: string;
|
|
27
37
|
remote?: boolean;
|
|
38
|
+
encode?: ImageEncodeOption;
|
|
28
39
|
alt?: SerializedSchema;
|
|
29
40
|
jsonValues?: boolean;
|
|
30
41
|
readonly?: boolean;
|
|
@@ -45,10 +56,6 @@ export type SerializedRecordSchema = {
|
|
|
45
56
|
* authoring.
|
|
46
57
|
*/
|
|
47
58
|
export type JsonValuesRecordSrc<T extends Schema<SelectorSource>, K extends Schema<string>> = Record<SelectorOfSchema<K>, JsonSource<JsonOf<SelectorOfSchema<T>>> | SelectorOfSchema<T>>;
|
|
48
|
-
type RecordPreviewInput<T extends Schema<SelectorSource>> = (input: {
|
|
49
|
-
key: string;
|
|
50
|
-
val: PreviewSelector<T>;
|
|
51
|
-
}) => PreviewItem;
|
|
52
59
|
export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Schema<string>, Src extends Record<SelectorOfSchema<K>, SelectorOfSchema<T>> | JsonValuesRecordSrc<T, K> | null> extends Schema<Src> {
|
|
53
60
|
private readonly item;
|
|
54
61
|
private readonly opt;
|
|
@@ -62,9 +69,10 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
|
|
|
62
69
|
/** When true, entry values are lazily loaded {@link JsonSource} thunks. */
|
|
63
70
|
private readonly isJsonValues;
|
|
64
71
|
private readonly previewInput;
|
|
72
|
+
private readonly renderInput;
|
|
65
73
|
constructor(item: T, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], currentRouter?: ValRouter | null, keySchema?: Schema<string> | null, mediaOptions?: MediaOptions | undefined, isReadonly?: boolean, isHidden?: boolean, description?: string | undefined,
|
|
66
74
|
/** When true, entry values are lazily loaded {@link JsonSource} thunks. */
|
|
67
|
-
isJsonValues?: boolean, previewInput?:
|
|
75
|
+
isJsonValues?: boolean, previewInput?: ItemPreviewInput<Src> | null, renderInput?: FieldRender | null);
|
|
68
76
|
describe(description: string | null): RecordSchema<T, K, Src>;
|
|
69
77
|
validate(validationFunction: (src: Src) => false | string): RecordSchema<T, K, Src>;
|
|
70
78
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
@@ -106,15 +114,23 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
|
|
|
106
114
|
*/
|
|
107
115
|
validateJsonEntryContent(path: SourcePath, content: SelectorSource): ValidationErrors;
|
|
108
116
|
protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
|
|
117
|
+
protected executePreviewItem(src: NonNullable<Src>): PreviewItem | null;
|
|
118
|
+
protected declaresItemPreview(): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* How this RECORD ITSELF is shown where a preview of it is needed — when it
|
|
121
|
+
* is the item of another container, in search, in references. What its
|
|
122
|
+
* entries show is the ITEM schema's `preview`, not this. Never how the field
|
|
123
|
+
* is edited (that is `render`). See `preview.ts`.
|
|
124
|
+
*/
|
|
125
|
+
preview(select: ItemPreviewInput<Src>): RecordSchema<T, K, Src>;
|
|
109
126
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
127
|
+
* How this field is laid out in the editor when it is the item of an array
|
|
128
|
+
* or record: `{ as: "inline" }` renders the field itself inside each row,
|
|
129
|
+
* instead of a preview row that navigates to it.
|
|
112
130
|
*
|
|
113
|
-
*
|
|
114
|
-
* demand for the entries that are actually being looked at — see
|
|
115
|
-
* `PreviewScope`.
|
|
131
|
+
* Static configuration, not a callback — see `render.ts`.
|
|
116
132
|
*/
|
|
117
|
-
|
|
133
|
+
render(input: FieldRender): RecordSchema<T, K, Src>;
|
|
118
134
|
}
|
|
119
135
|
export declare function record<K extends Schema<string>, S extends Schema<SelectorSource>>(key: K, schema: S): RecordSchema<S, K, Record<SelectorOfSchema<K>, SelectorOfSchema<S>>>;
|
|
120
136
|
export declare function record<S extends Schema<SelectorSource>>(schema: S): RecordSchema<S, Schema<string>, Record<string, SelectorOfSchema<S>>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import { ReifiedPreview } from "../preview.js";
|
|
2
|
+
import { ItemPreviewInput, PreviewItem, ReifiedPreview } from "../preview.js";
|
|
3
|
+
import { FieldRender } from "../render.js";
|
|
3
4
|
import { RichTextSource, RichTextOptions, SerializedRichTextOptions } from "../source/richtext.js";
|
|
4
5
|
import { SourcePath } from "../val/index.js";
|
|
5
6
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
@@ -9,6 +10,10 @@ type ValidationOptions = {
|
|
|
9
10
|
};
|
|
10
11
|
export type SerializedRichTextSchema = {
|
|
11
12
|
type: "richtext";
|
|
13
|
+
/** Static layout config, carried whole in the serialized schema — see `render.ts`. */
|
|
14
|
+
render?: FieldRender;
|
|
15
|
+
/** Set when this schema declares a `preview`. The closure itself cannot serialize. */
|
|
16
|
+
preview?: true;
|
|
12
17
|
opt: boolean;
|
|
13
18
|
options?: SerializedRichTextOptions & ValidationOptions;
|
|
14
19
|
customValidate?: boolean;
|
|
@@ -23,7 +28,9 @@ export declare class RichTextSchema<O extends RichTextOptions, Src extends RichT
|
|
|
23
28
|
private readonly isReadonly;
|
|
24
29
|
private readonly isHidden;
|
|
25
30
|
private readonly description?;
|
|
26
|
-
|
|
31
|
+
private readonly renderInput;
|
|
32
|
+
private readonly previewInput;
|
|
33
|
+
constructor(options: O & ValidationOptions, opt?: boolean, customValidateFunctions?: CustomValidateFunction<Src>[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, renderInput?: FieldRender | null, previewInput?: ItemPreviewInput<Src> | null);
|
|
27
34
|
describe(description: string | null): RichTextSchema<O, Src>;
|
|
28
35
|
maxLength(max: number): RichTextSchema<O, Src>;
|
|
29
36
|
minLength(min: number): RichTextSchema<O, Src>;
|
|
@@ -36,6 +43,22 @@ export declare class RichTextSchema<O extends RichTextOptions, Src extends RichT
|
|
|
36
43
|
readonly(): RichTextSchema<O, Src>;
|
|
37
44
|
hidden(): RichTextSchema<O, Src>;
|
|
38
45
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
46
|
+
/**
|
|
47
|
+
* How this field is laid out in the editor when it is the item of an array
|
|
48
|
+
* or record: `{ as: "inline" }` renders the field itself inside each row,
|
|
49
|
+
* instead of a preview row that navigates to it.
|
|
50
|
+
*
|
|
51
|
+
* Static configuration, not a callback — see `render.ts`.
|
|
52
|
+
*/
|
|
53
|
+
render(input: FieldRender): RichTextSchema<O, Src>;
|
|
54
|
+
/**
|
|
55
|
+
* How this VALUE is shown where a preview of it is needed — a row in a
|
|
56
|
+
* sortable list, a reference dropdown, a search hit. Never how the field
|
|
57
|
+
* itself is edited (that is `render`). See `preview.ts`.
|
|
58
|
+
*/
|
|
59
|
+
preview(select: ItemPreviewInput<Src>): RichTextSchema<O, Src>;
|
|
60
|
+
protected executePreviewItem(src: NonNullable<Src>): PreviewItem | null;
|
|
61
|
+
protected declaresItemPreview(): boolean;
|
|
39
62
|
protected executeSerialize(): SerializedSchema;
|
|
40
63
|
protected executePreview(): ReifiedPreview;
|
|
41
64
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
2
|
import { SourcePath } from "../val/index.js";
|
|
3
|
-
import { ReifiedPreview } from "../preview.js";
|
|
3
|
+
import { ItemPreviewInput, PreviewItem, ReifiedPreview } from "../preview.js";
|
|
4
|
+
import { FieldRender } from "../render.js";
|
|
4
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
5
6
|
type RouteOptions = {
|
|
6
7
|
include?: RegExp;
|
|
@@ -8,6 +9,10 @@ type RouteOptions = {
|
|
|
8
9
|
};
|
|
9
10
|
export type SerializedRouteSchema = {
|
|
10
11
|
type: "route";
|
|
12
|
+
/** Static layout config, carried whole in the serialized schema — see `render.ts`. */
|
|
13
|
+
render?: FieldRender;
|
|
14
|
+
/** Set when this schema declares a `preview`. The closure itself cannot serialize. */
|
|
15
|
+
preview?: true;
|
|
11
16
|
options?: {
|
|
12
17
|
include?: {
|
|
13
18
|
source: string;
|
|
@@ -32,7 +37,9 @@ export declare class RouteSchema<Src extends string | null> extends Schema<Src>
|
|
|
32
37
|
private readonly isReadonly;
|
|
33
38
|
private readonly isHidden;
|
|
34
39
|
private readonly description?;
|
|
35
|
-
|
|
40
|
+
private readonly renderInput;
|
|
41
|
+
private readonly previewInput;
|
|
42
|
+
constructor(options?: RouteOptions | undefined, opt?: boolean, customValidateFunctions?: ((src: Src) => false | string)[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, renderInput?: FieldRender | null, previewInput?: ItemPreviewInput<Src> | null);
|
|
36
43
|
describe(description: string | null): RouteSchema<Src>;
|
|
37
44
|
/**
|
|
38
45
|
* Specify a pattern for which routes are allowed.
|
|
@@ -67,6 +74,22 @@ export declare class RouteSchema<Src extends string | null> extends Schema<Src>
|
|
|
67
74
|
readonly(): RouteSchema<Src>;
|
|
68
75
|
hidden(): RouteSchema<Src>;
|
|
69
76
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
77
|
+
/**
|
|
78
|
+
* How this field is laid out in the editor when it is the item of an array
|
|
79
|
+
* or record: `{ as: "inline" }` renders the field itself inside each row,
|
|
80
|
+
* instead of a preview row that navigates to it.
|
|
81
|
+
*
|
|
82
|
+
* Static configuration, not a callback — see `render.ts`.
|
|
83
|
+
*/
|
|
84
|
+
render(input: FieldRender): RouteSchema<Src>;
|
|
85
|
+
/**
|
|
86
|
+
* How this VALUE is shown where a preview of it is needed — a row in a
|
|
87
|
+
* sortable list, a reference dropdown, a search hit. Never how the field
|
|
88
|
+
* itself is edited (that is `render`). See `preview.ts`.
|
|
89
|
+
*/
|
|
90
|
+
preview(select: ItemPreviewInput<Src>): RouteSchema<Src>;
|
|
91
|
+
protected executePreviewItem(src: NonNullable<Src>): PreviewItem | null;
|
|
92
|
+
protected declaresItemPreview(): boolean;
|
|
70
93
|
protected executeSerialize(): SerializedSchema;
|
|
71
94
|
protected executePreview(): ReifiedPreview;
|
|
72
95
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import { ReifiedPreview } from "../preview.js";
|
|
2
|
+
import { ItemPreviewInput, PreviewItem, ReifiedPreview } from "../preview.js";
|
|
3
3
|
import { StringRender } from "../render.js";
|
|
4
4
|
import { SourcePath } from "../val/index.js";
|
|
5
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
@@ -21,6 +21,8 @@ export type SerializedStringSchema = {
|
|
|
21
21
|
* buys, and what to do if a render ever needs to stop being static.
|
|
22
22
|
*/
|
|
23
23
|
render?: StringRender;
|
|
24
|
+
/** Set when this schema declares a `preview`. The closure itself cannot serialize. */
|
|
25
|
+
preview?: true;
|
|
24
26
|
options?: {
|
|
25
27
|
maxLength?: number;
|
|
26
28
|
minLength?: number;
|
|
@@ -51,7 +53,8 @@ export declare class StringSchema<Src extends string | null> extends Schema<Src>
|
|
|
51
53
|
private readonly isReadonly;
|
|
52
54
|
private readonly isHidden;
|
|
53
55
|
private readonly description?;
|
|
54
|
-
|
|
56
|
+
private readonly previewInput;
|
|
57
|
+
constructor(options?: StringOptions | undefined, opt?: boolean, isRaw?: boolean, customValidateFunctions?: ((src: Src) => false | string)[], renderInput?: StringRender | null, isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, previewInput?: ItemPreviewInput<Src> | null);
|
|
55
58
|
describe(description: string | null): StringSchema<Src>;
|
|
56
59
|
/**
|
|
57
60
|
* @deprecated Use `minLength` instead
|
|
@@ -81,6 +84,14 @@ export declare class StringSchema<Src extends string | null> extends Schema<Src>
|
|
|
81
84
|
* shows for its items is a `preview`, which is a different thing entirely.
|
|
82
85
|
*/
|
|
83
86
|
render(input: StringRender): StringSchema<Src>;
|
|
87
|
+
/**
|
|
88
|
+
* How this VALUE is shown where a preview of it is needed — a row in a
|
|
89
|
+
* sortable list, a reference dropdown, a search hit. Never how the field
|
|
90
|
+
* itself is edited (that is `render`). See `preview.ts`.
|
|
91
|
+
*/
|
|
92
|
+
preview(select: ItemPreviewInput<Src>): StringSchema<Src>;
|
|
93
|
+
protected executePreviewItem(src: NonNullable<Src>): PreviewItem | null;
|
|
94
|
+
protected declaresItemPreview(): boolean;
|
|
84
95
|
/**
|
|
85
96
|
* Nothing: a string has no items, so there is nothing to preview. Its layout
|
|
86
97
|
* is a `render`, which travels in the serialized schema instead of through
|