@valbuild/core 0.103.0 → 0.105.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 +2 -1
- package/dist/declarations/src/preview.d.ts +98 -0
- package/dist/declarations/src/render.d.ts +29 -91
- package/dist/declarations/src/schema/array.d.ts +22 -23
- package/dist/declarations/src/schema/boolean.d.ts +2 -2
- package/dist/declarations/src/schema/color.d.ts +2 -2
- package/dist/declarations/src/schema/date.d.ts +2 -2
- package/dist/declarations/src/schema/datetime.d.ts +2 -2
- package/dist/declarations/src/schema/file.d.ts +2 -2
- package/dist/declarations/src/schema/image.d.ts +2 -2
- package/dist/declarations/src/schema/index.d.ts +6 -6
- package/dist/declarations/src/schema/keyOf.d.ts +2 -2
- package/dist/declarations/src/schema/literal.d.ts +2 -2
- package/dist/declarations/src/schema/number.d.ts +2 -2
- package/dist/declarations/src/schema/object.d.ts +2 -2
- package/dist/declarations/src/schema/record.d.ts +19 -29
- package/dist/declarations/src/schema/richtext.d.ts +2 -2
- package/dist/declarations/src/schema/route.d.ts +2 -2
- package/dist/declarations/src/schema/string.d.ts +28 -17
- package/dist/declarations/src/schema/union.d.ts +2 -2
- package/dist/{index-2e40f2ae.cjs.dev.js → index-730a5254.cjs.dev.js} +177 -139
- package/dist/{index-267a8e9c.esm.js → index-d7cc2231.esm.js} +176 -139
- package/dist/{index-3572060f.cjs.prod.js → index-e990b6ad.cjs.prod.js} +177 -139
- package/dist/valbuild-core.cjs.dev.js +3 -2
- package/dist/valbuild-core.cjs.prod.js +3 -2
- package/dist/valbuild-core.esm.js +1 -1
- package/package.json +1 -1
- 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
|
@@ -59,7 +59,8 @@ export { type SerializedRichTextSchema, RichTextSchema, } from "./schema/richtex
|
|
|
59
59
|
export { type SerializedUnionSchema, UnionSchema, type SerializedStringUnionSchema, type SerializedObjectUnionSchema, } from "./schema/union.js";
|
|
60
60
|
export { type SerializedLiteralSchema, LiteralSchema } from "./schema/literal.js";
|
|
61
61
|
export { deserializeSchema } from "./schema/deserialize.js";
|
|
62
|
-
export { type
|
|
62
|
+
export { type PreviewItem, type RecordPreview, type ArrayPreview, type ReifiedPreview, type PreviewScope, previewScope, } from "./preview.js";
|
|
63
|
+
export { type CodeLanguage, type StringRender, CODE_LANGUAGES } from "./render.js";
|
|
63
64
|
export type { ValRouter, RouteValidationError } from "./router.js";
|
|
64
65
|
export { getSourcePathFromRoute } from "./getSourcePathFromRoute.js";
|
|
65
66
|
export declare const FATAL_ERROR_TYPES: readonly ["no-schema", "no-source", "invalid-id", "no-module", "invalid-patch"];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Schema } from "./schema/index.js";
|
|
2
|
+
import { SelectorSource } from "./selector/index.js";
|
|
3
|
+
import { ImageSource } from "./source/media.js";
|
|
4
|
+
import { ModuleFilePath, SourcePath } from "./val/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* What a container shows for ONE of its items: the user's `preview` callback
|
|
7
|
+
* returns this, and the Studio draws a row from it.
|
|
8
|
+
*
|
|
9
|
+
* NB: {@link ArrayPreview} / {@link RecordPreview} name the DATA a container
|
|
10
|
+
* previews with. The Studio also has React components called `ArrayPreview` /
|
|
11
|
+
* `RecordPreview` (the fallback rendering of an array / record field, part of
|
|
12
|
+
* the `<Type>Preview` convention in `components/Preview.tsx`). They do not
|
|
13
|
+
* collide today because no file needs both - if one ever does, alias this type
|
|
14
|
+
* at the import rather than renaming that convention.
|
|
15
|
+
*/
|
|
16
|
+
export type PreviewItem = {
|
|
17
|
+
title: string;
|
|
18
|
+
subtitle?: string | null;
|
|
19
|
+
image?: ImageSource | null;
|
|
20
|
+
};
|
|
21
|
+
export type RecordPreview = {
|
|
22
|
+
parent: "record";
|
|
23
|
+
items: [key: string, value: PreviewItem][];
|
|
24
|
+
};
|
|
25
|
+
export type ArrayPreview = {
|
|
26
|
+
parent: "array";
|
|
27
|
+
/**
|
|
28
|
+
* The previewed items, each PAIRED WITH ITS INDEX - the same
|
|
29
|
+
* `[key, value][]` shape {@link RecordPreview} uses.
|
|
30
|
+
*
|
|
31
|
+
* Not a positionally-indexed array, and the reason is
|
|
32
|
+
* {@link PreviewScope}: a preview computed for a subset of paths carries only
|
|
33
|
+
* those items, so `items[i]` would silently read the wrong row. Carrying the
|
|
34
|
+
* index makes a windowed preview impossible to misread - a consumer looks its
|
|
35
|
+
* index up rather than trusting a position - and makes the array and record
|
|
36
|
+
* shapes symmetric.
|
|
37
|
+
*/
|
|
38
|
+
items: [index: number, value: PreviewItem][];
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Main preview type.
|
|
42
|
+
*
|
|
43
|
+
* Deliberately not exported: `parent` is the discriminant, and every consumer
|
|
44
|
+
* narrows on it rather than on the union as a whole. There is no `layout` here
|
|
45
|
+
* on purpose - how a preview is laid out is the editor's business, not the
|
|
46
|
+
* schema's.
|
|
47
|
+
*/
|
|
48
|
+
type PreviewTypes = RecordPreview | ArrayPreview;
|
|
49
|
+
type WithStatus<T> = {
|
|
50
|
+
status: "error";
|
|
51
|
+
message: string;
|
|
52
|
+
} | {
|
|
53
|
+
status: "loading";
|
|
54
|
+
data?: T;
|
|
55
|
+
} | {
|
|
56
|
+
status: "success";
|
|
57
|
+
data: T;
|
|
58
|
+
};
|
|
59
|
+
export type ReifiedPreview = Record<SourcePath | ModuleFilePath, WithStatus<PreviewTypes>>;
|
|
60
|
+
/**
|
|
61
|
+
* Which paths a preview is being computed FOR.
|
|
62
|
+
*
|
|
63
|
+
* `executePreview` takes a whole module, so one request has always walked every
|
|
64
|
+
* node in it and run every `preview` closure - for `handboka`, with `preview` at
|
|
65
|
+
* two nested array levels, that is every chapter and every section to serve one
|
|
66
|
+
* visible row. A scope is what makes the walk proportional to what is being
|
|
67
|
+
* looked at instead of to the project.
|
|
68
|
+
*
|
|
69
|
+
* Two questions, because a container and its items need different answers:
|
|
70
|
+
*
|
|
71
|
+
* - {@link PreviewScope.wants} - is a preview AT this exact path wanted? A
|
|
72
|
+
* container answers `true` here when the whole of it is being shown, and its
|
|
73
|
+
* preview is then computed in full.
|
|
74
|
+
* - {@link PreviewScope.wantsUnder} - could anything at or below this path be
|
|
75
|
+
* wanted? Recursion is pruned where this is `false`, and a container whose own
|
|
76
|
+
* path is not wanted but which has wanted descendants previews a WINDOW: only
|
|
77
|
+
* the items that were asked for. That is the case a single visible row is, and
|
|
78
|
+
* it is why {@link ArrayPreview} carries indices.
|
|
79
|
+
*
|
|
80
|
+
* Absent scope means the whole module, which is what every existing caller
|
|
81
|
+
* passes and what every existing caller got.
|
|
82
|
+
*/
|
|
83
|
+
export type PreviewScope = {
|
|
84
|
+
wants(path: SourcePath | ModuleFilePath): boolean;
|
|
85
|
+
wantsUnder(path: SourcePath | ModuleFilePath): boolean;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* A scope covering exactly `paths` and their subtrees.
|
|
89
|
+
*
|
|
90
|
+
* Compares SEGMENTS rather than string prefixes. A source path's module path is
|
|
91
|
+
* a quoted, dot-joined encoding (`?p="a".1."b"`), so `startsWith` gets the
|
|
92
|
+
* ancestor test wrong wherever a key is a prefix of a sibling key or contains a
|
|
93
|
+
* dot or a quote - `"title"` against `"titles"` being the cheapest example.
|
|
94
|
+
* Segments are parsed once here, not per comparison.
|
|
95
|
+
*/
|
|
96
|
+
export declare function previewScope(paths: readonly SourcePath[]): PreviewScope;
|
|
97
|
+
export type PreviewSelector<T extends Schema<SelectorSource>> = T extends Schema<infer S> ? S : never;
|
|
98
|
+
export {};
|
|
@@ -1,98 +1,36 @@
|
|
|
1
|
-
import { Schema } from "./schema/index.js";
|
|
2
|
-
import { SelectorSource } from "./selector/index.js";
|
|
3
|
-
import { ImageSource } from "./source/media.js";
|
|
4
|
-
import { ModuleFilePath, SourcePath } from "./val/index.js";
|
|
5
|
-
export type ListRecordRender = {
|
|
6
|
-
layout: "list";
|
|
7
|
-
parent: "record";
|
|
8
|
-
items: [
|
|
9
|
-
key: string,
|
|
10
|
-
value: {
|
|
11
|
-
title: string;
|
|
12
|
-
subtitle?: string | null;
|
|
13
|
-
image?: ImageSource | null;
|
|
14
|
-
}
|
|
15
|
-
][];
|
|
16
|
-
};
|
|
17
|
-
export type ListArrayRender = {
|
|
18
|
-
layout: "list";
|
|
19
|
-
parent: "array";
|
|
20
|
-
/**
|
|
21
|
-
* The rendered items, each PAIRED WITH ITS INDEX — the same
|
|
22
|
-
* `[key, value][]` shape {@link ListRecordRender} uses.
|
|
23
|
-
*
|
|
24
|
-
* Not a positionally-indexed array, and the reason is
|
|
25
|
-
* {@link RenderScope}: a render computed for a subset of paths carries only
|
|
26
|
-
* those items, so `items[i]` would silently read the wrong row. Carrying the
|
|
27
|
-
* index makes a windowed render impossible to misread — a consumer looks its
|
|
28
|
-
* index up rather than trusting a position — and makes the array and record
|
|
29
|
-
* shapes symmetric.
|
|
30
|
-
*/
|
|
31
|
-
items: [
|
|
32
|
-
index: number,
|
|
33
|
-
value: {
|
|
34
|
-
title: string;
|
|
35
|
-
subtitle?: string | null;
|
|
36
|
-
image?: ImageSource | null;
|
|
37
|
-
}
|
|
38
|
-
][];
|
|
39
|
-
};
|
|
40
|
-
export type TextareaRender = {
|
|
41
|
-
layout: "textarea";
|
|
42
|
-
};
|
|
43
|
-
export type CodeLanguage = "typescript" | "javascript" | "javascriptreact" | "typescriptreact" | "json" | "java" | "html" | "css" | "xml" | "markdown" | "sql" | "python" | "rust" | "php" | "go" | "cpp" | "sass" | "vue" | "angular";
|
|
44
|
-
export type CodeRender = {
|
|
45
|
-
layout: "code";
|
|
46
|
-
language: CodeLanguage;
|
|
47
|
-
};
|
|
48
|
-
type RenderTypes = ListRecordRender | ListArrayRender | TextareaRender | CodeRender;
|
|
49
|
-
type WithStatus<T> = {
|
|
50
|
-
status: "error";
|
|
51
|
-
message: string;
|
|
52
|
-
} | {
|
|
53
|
-
status: "loading";
|
|
54
|
-
data?: T;
|
|
55
|
-
} | {
|
|
56
|
-
status: "success";
|
|
57
|
-
data: T;
|
|
58
|
-
};
|
|
59
|
-
export type ReifiedRender = Record<SourcePath | ModuleFilePath, WithStatus<RenderTypes>>;
|
|
60
1
|
/**
|
|
61
|
-
*
|
|
2
|
+
* A RENDER is how one field is laid out in the editor: `s.string().render({ as:
|
|
3
|
+
* "textarea" })`, `.render({ as: "code", language })`.
|
|
62
4
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* looked at instead of to the project.
|
|
5
|
+
* It is static configuration - plain data, with no closure behind it and no
|
|
6
|
+
* dependency on source - which is why it lives in the SERIALIZED schema
|
|
7
|
+
* (`SerializedStringSchema.render`) and is read straight off it where the field
|
|
8
|
+
* is drawn. There is no render pipeline, no store and no host round-trip.
|
|
68
9
|
*
|
|
69
|
-
*
|
|
10
|
+
* That "static" is an ASSUMPTION we are taking deliberately, for simplicity,
|
|
11
|
+
* not a law. A future render could plausibly want to depend on source - a
|
|
12
|
+
* layout that varies with the value, a callback of its own. If that day comes,
|
|
13
|
+
* the shape it needs back is `executePreview`'s, and the honest move is to give
|
|
14
|
+
* `render` its own execute/store pair again. It is NOT to re-merge the two:
|
|
15
|
+
* conflating them is what this file was split up to undo.
|
|
70
16
|
*
|
|
71
|
-
* -
|
|
72
|
-
*
|
|
73
|
-
* list render is then computed in full.
|
|
74
|
-
* - {@link RenderScope.wantsUnder} — could anything at or below this path be
|
|
75
|
-
* wanted? Recursion is pruned where this is `false`, and a container whose own
|
|
76
|
-
* path is not wanted but which has wanted descendants renders a WINDOW: only
|
|
77
|
-
* the items that were asked for. That is the case a single visible row is, and
|
|
78
|
-
* it is why {@link ListArrayRender} carries indices.
|
|
79
|
-
*
|
|
80
|
-
* Absent scope means the whole module, which is what every existing caller
|
|
81
|
-
* passes and what every existing caller got.
|
|
17
|
+
* The dynamic, source-dependent, demand-scoped thing - what a container shows
|
|
18
|
+
* for its items - is a PREVIEW. See `preview.ts`.
|
|
82
19
|
*/
|
|
83
|
-
export type RenderScope = {
|
|
84
|
-
wants(path: SourcePath | ModuleFilePath): boolean;
|
|
85
|
-
wantsUnder(path: SourcePath | ModuleFilePath): boolean;
|
|
86
|
-
};
|
|
87
20
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
21
|
+
* The list is the declaration and {@link CodeLanguage} is derived from it, so
|
|
22
|
+
* that a validator elsewhere (`shared`'s zod schema) can enumerate the same
|
|
23
|
+
* languages without a second copy that drifts. Same shape as `COLOR_FORMATS`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const CODE_LANGUAGES: readonly ["typescript", "javascript", "javascriptreact", "typescriptreact", "json", "java", "html", "css", "xml", "markdown", "sql", "python", "rust", "php", "go", "cpp", "sass", "vue", "angular"];
|
|
26
|
+
export type CodeLanguage = (typeof CODE_LANGUAGES)[number];
|
|
27
|
+
/**
|
|
28
|
+
* What `s.string().render(...)` takes, and what the serialized schema carries
|
|
29
|
+
* verbatim.
|
|
95
30
|
*/
|
|
96
|
-
export
|
|
97
|
-
|
|
98
|
-
|
|
31
|
+
export type StringRender = {
|
|
32
|
+
as: "textarea";
|
|
33
|
+
} | {
|
|
34
|
+
as: "code";
|
|
35
|
+
language: CodeLanguage;
|
|
36
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { PreviewItem, PreviewSelector, ReifiedPreview, PreviewScope } from "../preview.js";
|
|
3
3
|
import { SelectorSource } from "../selector/index.js";
|
|
4
|
-
import { ImageSource } from "../source/media.js";
|
|
5
4
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
6
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
7
6
|
export type SerializedArraySchema = {
|
|
@@ -9,30 +8,23 @@ export type SerializedArraySchema = {
|
|
|
9
8
|
item: SerializedSchema;
|
|
10
9
|
opt: boolean;
|
|
11
10
|
/**
|
|
12
|
-
* Set when this schema declares a `
|
|
11
|
+
* Set when this schema declares a `preview`.
|
|
13
12
|
*
|
|
14
|
-
* The
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
13
|
+
* The preview itself cannot be serialized — it is a user closure — but whether
|
|
14
|
+
* one EXISTS can be, and that is worth carrying: it lets the non-host side
|
|
15
|
+
* skip asking the host to preview a module that cannot produce one. Measured
|
|
16
|
+
* in a browser: mounting 260 fields across 141 modules spent ~2.3ms of 3.1ms
|
|
17
|
+
* calling `executePreview` on modules that returned nothing.
|
|
19
18
|
*/
|
|
20
|
-
|
|
19
|
+
preview?: true;
|
|
21
20
|
customValidate?: boolean;
|
|
22
21
|
readonly?: boolean;
|
|
23
22
|
hidden?: boolean;
|
|
24
23
|
description?: string;
|
|
25
24
|
};
|
|
26
|
-
type
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
val: RenderSelector<T>;
|
|
30
|
-
}) => {
|
|
31
|
-
title: string;
|
|
32
|
-
subtitle?: string | null;
|
|
33
|
-
image?: ImageSource | null;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
25
|
+
type ArrayPreviewInput<T extends Schema<SelectorSource>> = (input: {
|
|
26
|
+
val: PreviewSelector<T>;
|
|
27
|
+
}) => PreviewItem;
|
|
36
28
|
export declare class ArraySchema<T extends Schema<SelectorSource>, Src extends SelectorOfSchema<T>[] | null> extends Schema<Src> {
|
|
37
29
|
private readonly item;
|
|
38
30
|
private readonly opt;
|
|
@@ -40,8 +32,8 @@ export declare class ArraySchema<T extends Schema<SelectorSource>, Src extends S
|
|
|
40
32
|
private readonly isReadonly;
|
|
41
33
|
private readonly isHidden;
|
|
42
34
|
private readonly description?;
|
|
43
|
-
private readonly
|
|
44
|
-
constructor(item: T, opt?: boolean, customValidateFunctions?: ((src: Src) => false | string)[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined,
|
|
35
|
+
private readonly previewInput;
|
|
36
|
+
constructor(item: T, opt?: boolean, customValidateFunctions?: ((src: Src) => false | string)[], isReadonly?: boolean, isHidden?: boolean, description?: string | undefined, previewInput?: ArrayPreviewInput<T> | null);
|
|
45
37
|
describe(description: string | null): ArraySchema<T, Src>;
|
|
46
38
|
validate(validationFunction: (src: Src) => false | string): ArraySchema<T, Src>;
|
|
47
39
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
@@ -51,8 +43,15 @@ export declare class ArraySchema<T extends Schema<SelectorSource>, Src extends S
|
|
|
51
43
|
hidden(): ArraySchema<T, Src>;
|
|
52
44
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
53
45
|
protected executeSerialize(): SerializedArraySchema;
|
|
54
|
-
protected
|
|
55
|
-
|
|
46
|
+
protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
|
|
47
|
+
/**
|
|
48
|
+
* What the editor shows for each ITEM of this array: a title, and optionally a
|
|
49
|
+
* subtitle and an image.
|
|
50
|
+
*
|
|
51
|
+
* `select` is your own code over the item's source, so it is run on demand for
|
|
52
|
+
* the rows that are actually being looked at — see `PreviewScope`.
|
|
53
|
+
*/
|
|
54
|
+
preview(select: ArrayPreviewInput<T>): ArraySchema<T, Src>;
|
|
56
55
|
}
|
|
57
56
|
export declare const array: <S extends Schema<SelectorSource>>(schema: S) => ArraySchema<S, SelectorOfSchema<S>[]>;
|
|
58
57
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview } from "../preview.js";
|
|
3
3
|
import { SourcePath } from "../val/index.js";
|
|
4
4
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
5
5
|
export type SerializedBooleanSchema = {
|
|
@@ -26,6 +26,6 @@ export declare class BooleanSchema<Src extends boolean | null> extends Schema<Sr
|
|
|
26
26
|
hidden(): BooleanSchema<Src>;
|
|
27
27
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
28
28
|
protected executeSerialize(): SerializedSchema;
|
|
29
|
-
protected
|
|
29
|
+
protected executePreview(): ReifiedPreview;
|
|
30
30
|
}
|
|
31
31
|
export declare const boolean: () => BooleanSchema<boolean>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview } from "../preview.js";
|
|
3
3
|
import { SourcePath } from "../val/index.js";
|
|
4
4
|
import { ColorFormat } from "./colorFormat.js";
|
|
5
5
|
import { RawString } from "./string.js";
|
|
@@ -52,6 +52,6 @@ export declare class ColorSchema<Src extends string | null> extends Schema<Src>
|
|
|
52
52
|
readonly(): ColorSchema<Src>;
|
|
53
53
|
hidden(): ColorSchema<Src>;
|
|
54
54
|
protected executeSerialize(): SerializedSchema;
|
|
55
|
-
protected
|
|
55
|
+
protected executePreview(): ReifiedPreview;
|
|
56
56
|
}
|
|
57
57
|
export declare const color: (options?: ColorOptions) => ColorSchema<RawString>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview } from "../preview.js";
|
|
3
3
|
import { SourcePath } from "../val/index.js";
|
|
4
4
|
import { RawString } from "./string.js";
|
|
5
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
@@ -47,7 +47,7 @@ export declare class DateSchema<Src extends string | null> extends Schema<Src> {
|
|
|
47
47
|
hidden(): DateSchema<Src>;
|
|
48
48
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
49
49
|
protected executeSerialize(): SerializedSchema;
|
|
50
|
-
protected
|
|
50
|
+
protected executePreview(): ReifiedPreview;
|
|
51
51
|
}
|
|
52
52
|
export declare const date: (options?: Record<string, never>) => DateSchema<RawString>;
|
|
53
53
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview } from "../preview.js";
|
|
3
3
|
import { SourcePath } from "../val/index.js";
|
|
4
4
|
import { RawString } from "./string.js";
|
|
5
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
@@ -51,7 +51,7 @@ export declare class DateTimeSchema<Src extends string | null> extends Schema<Sr
|
|
|
51
51
|
hidden(): DateTimeSchema<Src>;
|
|
52
52
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
53
53
|
protected executeSerialize(): SerializedSchema;
|
|
54
|
-
protected
|
|
54
|
+
protected executePreview(): ReifiedPreview;
|
|
55
55
|
}
|
|
56
56
|
export declare const datetime: (options?: Record<string, never>) => DateTimeSchema<RawString>;
|
|
57
57
|
export {};
|
|
@@ -4,7 +4,7 @@ import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema }
|
|
|
4
4
|
import { ModulePath, SourcePath } from "../val/index.js";
|
|
5
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
6
6
|
import { ValModule } from "../index.js";
|
|
7
|
-
import {
|
|
7
|
+
import { ReifiedPreview } from "../preview.js";
|
|
8
8
|
import { FilesEntryMetadata } from "./files.js";
|
|
9
9
|
export type FileOptions = {
|
|
10
10
|
accept?: string;
|
|
@@ -45,7 +45,7 @@ export declare class FileSchema<Src extends FileSource | null> extends Schema<Sr
|
|
|
45
45
|
hidden(): FileSchema<Src>;
|
|
46
46
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
47
47
|
protected executeSerialize(): SerializedSchema;
|
|
48
|
-
protected
|
|
48
|
+
protected executePreview(): ReifiedPreview;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* A file picked from a gallery. Its mime type lives in the gallery, so the
|
|
@@ -3,7 +3,7 @@ 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 {
|
|
6
|
+
import { ReifiedPreview } from "../preview.js";
|
|
7
7
|
import { ImagesEntryMetadata } from "./images.js";
|
|
8
8
|
export type ImageOptions = {
|
|
9
9
|
ext?: ["jpg"] | ["webp"];
|
|
@@ -57,7 +57,7 @@ export declare class ImageSchema<Src extends ImageSource | null> extends Schema<
|
|
|
57
57
|
hidden(): ImageSchema<Src>;
|
|
58
58
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
59
59
|
protected executeSerialize(): SerializedSchema;
|
|
60
|
-
protected
|
|
60
|
+
protected executePreview(): ReifiedPreview;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* An image picked from a gallery. Its dimensions and mime type live in the
|
|
@@ -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 {
|
|
22
|
+
import { ReifiedPreview, PreviewScope } 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 = {
|
|
@@ -107,13 +107,13 @@ export declare abstract class Schema<Src extends SelectorSource> {
|
|
|
107
107
|
abstract hidden(): Schema<Src>;
|
|
108
108
|
protected abstract executeSerialize(): SerializedSchema;
|
|
109
109
|
/**
|
|
110
|
-
* @param scope Which paths the caller needs a
|
|
110
|
+
* @param scope Which paths the caller needs a preview for. Absent means the
|
|
111
111
|
* whole module, which is what every caller passed before scoping existed.
|
|
112
|
-
* See {@link
|
|
113
|
-
* wanted, and
|
|
114
|
-
* items are — which is the single-visible-row case.
|
|
112
|
+
* See {@link PreviewScope}: a container prunes recursion where nothing is
|
|
113
|
+
* wanted, and previews a WINDOW when its own path is not wanted but some of
|
|
114
|
+
* its items are — which is the single-visible-row case.
|
|
115
115
|
*/
|
|
116
|
-
protected abstract
|
|
116
|
+
protected abstract executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
|
|
117
117
|
/** MUTATES! since internal and perf sensitive */
|
|
118
118
|
protected appendValidationError(current: ValidationErrors, path: SourcePath, message: string, value: unknown, schemaError?: boolean): ValidationErrors;
|
|
119
119
|
/**
|
|
@@ -5,7 +5,7 @@ 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 {
|
|
8
|
+
import { ReifiedPreview } from "../preview.js";
|
|
9
9
|
export type SerializedKeyOfSchema = {
|
|
10
10
|
type: "keyOf";
|
|
11
11
|
path: SourcePath;
|
|
@@ -44,7 +44,7 @@ export declare class KeyOfSchema<Sel extends GenericSelector<SourceObject>, Src
|
|
|
44
44
|
hidden(): KeyOfSchema<Sel, Src>;
|
|
45
45
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
46
46
|
protected executeSerialize(): SerializedSchema;
|
|
47
|
-
protected
|
|
47
|
+
protected executePreview(): ReifiedPreview;
|
|
48
48
|
}
|
|
49
49
|
export declare const keyOf: <Src extends GenericSelector<SourceObject> & ValModuleBrand>(valModule: Src) => KeyOfSchema<Src, KeyOfSelector<Src>>;
|
|
50
50
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview } from "../preview.js";
|
|
3
3
|
import { SourcePath } from "../val/index.js";
|
|
4
4
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
5
5
|
export type SerializedLiteralSchema = {
|
|
@@ -28,6 +28,6 @@ export declare class LiteralSchema<Src extends string | null> extends Schema<Src
|
|
|
28
28
|
hidden(): LiteralSchema<Src>;
|
|
29
29
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
30
30
|
protected executeSerialize(): SerializedSchema;
|
|
31
|
-
protected
|
|
31
|
+
protected executePreview(): ReifiedPreview;
|
|
32
32
|
}
|
|
33
33
|
export declare const literal: <T extends string>(value: T) => LiteralSchema<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview } from "../preview.js";
|
|
3
3
|
import { SourcePath } from "../val/index.js";
|
|
4
4
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
5
5
|
type NumberOptions = {
|
|
@@ -34,7 +34,7 @@ export declare class NumberSchema<Src extends number | null> extends Schema<Src>
|
|
|
34
34
|
min(min: number): NumberSchema<Src>;
|
|
35
35
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
36
36
|
protected executeSerialize(): SerializedSchema;
|
|
37
|
-
protected
|
|
37
|
+
protected executePreview(): ReifiedPreview;
|
|
38
38
|
}
|
|
39
39
|
export declare const number: (options?: NumberOptions) => NumberSchema<number>;
|
|
40
40
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview, PreviewScope } from "../preview.js";
|
|
3
3
|
import { SelectorSource } from "../selector/index.js";
|
|
4
4
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
5
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
@@ -52,7 +52,7 @@ export declare class ObjectSchema<Props extends ObjectSchemaProps, Src extends O
|
|
|
52
52
|
hidden(): ObjectSchema<Props, Src>;
|
|
53
53
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
54
54
|
protected executeSerialize(): SerializedSchema;
|
|
55
|
-
protected
|
|
55
|
+
protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
|
|
56
56
|
}
|
|
57
57
|
export declare const object: <Props extends ObjectSchemaProps>(schema: Props) => ObjectSchema<Props, ObjectSchemaSrcOf<Props>>;
|
|
58
58
|
export {};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SelectorOfSchema, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { PreviewItem, PreviewSelector, ReifiedPreview, PreviewScope } from "../preview.js";
|
|
3
3
|
import { ValRouter } from "../router.js";
|
|
4
4
|
import { SelectorSource } from "../selector/index.js";
|
|
5
|
-
import { ImageSource } from "../source/media.js";
|
|
6
5
|
import { JsonOf, JsonSource } from "../source/json.js";
|
|
7
6
|
import { ModuleFilePath, SourcePath } from "../val/index.js";
|
|
8
7
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
@@ -18,8 +17,8 @@ export type SerializedRecordSchema = {
|
|
|
18
17
|
item: SerializedSchema;
|
|
19
18
|
key?: SerializedSchema;
|
|
20
19
|
opt: boolean;
|
|
21
|
-
/** Set when this schema declares a `
|
|
22
|
-
|
|
20
|
+
/** Set when this schema declares a `preview`. See `SerializedArraySchema`. */
|
|
21
|
+
preview?: true;
|
|
23
22
|
router?: string;
|
|
24
23
|
customValidate?: boolean;
|
|
25
24
|
mediaType?: "files" | "images";
|
|
@@ -46,17 +45,10 @@ export type SerializedRecordSchema = {
|
|
|
46
45
|
* authoring.
|
|
47
46
|
*/
|
|
48
47
|
export type JsonValuesRecordSrc<T extends Schema<SelectorSource>, K extends Schema<string>> = Record<SelectorOfSchema<K>, JsonSource<JsonOf<SelectorOfSchema<T>>> | SelectorOfSchema<T>>;
|
|
49
|
-
type
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
val: RenderSelector<T>;
|
|
54
|
-
}) => {
|
|
55
|
-
title: string;
|
|
56
|
-
subtitle?: string | null;
|
|
57
|
-
image?: ImageSource | null;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
48
|
+
type RecordPreviewInput<T extends Schema<SelectorSource>> = (input: {
|
|
49
|
+
key: string;
|
|
50
|
+
val: PreviewSelector<T>;
|
|
51
|
+
}) => PreviewItem;
|
|
60
52
|
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> {
|
|
61
53
|
private readonly item;
|
|
62
54
|
private readonly opt;
|
|
@@ -69,10 +61,10 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
|
|
|
69
61
|
private readonly description?;
|
|
70
62
|
/** When true, entry values are lazily loaded {@link JsonSource} thunks. */
|
|
71
63
|
private readonly isJsonValues;
|
|
72
|
-
private readonly
|
|
64
|
+
private readonly previewInput;
|
|
73
65
|
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,
|
|
74
66
|
/** When true, entry values are lazily loaded {@link JsonSource} thunks. */
|
|
75
|
-
isJsonValues?: boolean,
|
|
67
|
+
isJsonValues?: boolean, previewInput?: RecordPreviewInput<T> | null);
|
|
76
68
|
describe(description: string | null): RecordSchema<T, K, Src>;
|
|
77
69
|
validate(validationFunction: (src: Src) => false | string): RecordSchema<T, K, Src>;
|
|
78
70
|
protected executeValidate(path: SourcePath, src: Src): ValidationErrors;
|
|
@@ -113,18 +105,16 @@ export declare class RecordSchema<T extends Schema<SelectorSource>, K extends Sc
|
|
|
113
105
|
* defers).
|
|
114
106
|
*/
|
|
115
107
|
validateJsonEntryContent(path: SourcePath, content: SelectorSource): ValidationErrors;
|
|
116
|
-
protected
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
};
|
|
127
|
-
}): RecordSchema<T, K, Src>;
|
|
108
|
+
protected executePreview(sourcePath: SourcePath | ModuleFilePath, src: Src, scope?: PreviewScope): ReifiedPreview;
|
|
109
|
+
/**
|
|
110
|
+
* What the editor shows for each ENTRY of this record: a title, and optionally
|
|
111
|
+
* a subtitle and an image.
|
|
112
|
+
*
|
|
113
|
+
* `select` is your own code over the entry's key and source, so it is run on
|
|
114
|
+
* demand for the entries that are actually being looked at — see
|
|
115
|
+
* `PreviewScope`.
|
|
116
|
+
*/
|
|
117
|
+
preview(select: RecordPreviewInput<T>): RecordSchema<T, K, Src>;
|
|
128
118
|
}
|
|
129
119
|
export declare function record<K extends Schema<string>, S extends Schema<SelectorSource>>(key: K, schema: S): RecordSchema<S, K, Record<SelectorOfSchema<K>, SelectorOfSchema<S>>>;
|
|
130
120
|
export declare function record<S extends Schema<SelectorSource>>(schema: S): RecordSchema<S, Schema<string>, Record<string, SelectorOfSchema<S>>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CustomValidateFunction, Schema, SchemaAssertResult, SerializedSchema } from "./index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReifiedPreview } from "../preview.js";
|
|
3
3
|
import { RichTextSource, RichTextOptions, SerializedRichTextOptions } from "../source/richtext.js";
|
|
4
4
|
import { SourcePath } from "../val/index.js";
|
|
5
5
|
import { ValidationError, ValidationErrors } from "./validation/ValidationError.js";
|
|
@@ -37,7 +37,7 @@ export declare class RichTextSchema<O extends RichTextOptions, Src extends RichT
|
|
|
37
37
|
hidden(): RichTextSchema<O, Src>;
|
|
38
38
|
protected executeCustomValidateAt(path: SourcePath, src: Src): ValidationError[];
|
|
39
39
|
protected executeSerialize(): SerializedSchema;
|
|
40
|
-
protected
|
|
40
|
+
protected executePreview(): ReifiedPreview;
|
|
41
41
|
}
|
|
42
42
|
export declare const richtext: <O extends RichTextOptions>(options?: O) => RichTextSchema<O, RichTextSource<O>>;
|
|
43
43
|
export {};
|