@valbuild/core 0.18.0 → 0.20.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 -1
- package/dist/declarations/src/initSchema.d.ts +2 -2
- package/dist/declarations/src/patch/deref.d.ts +2 -1
- package/dist/declarations/src/patch/operation.d.ts +8 -0
- package/dist/declarations/src/schema/richtext.d.ts +7 -6
- package/dist/declarations/src/schema/string.d.ts +6 -3
- package/dist/declarations/src/selector/future/index.d.ts +3 -3
- package/dist/declarations/src/selector/index.d.ts +3 -3
- package/dist/declarations/src/source/future/remote.d.ts +2 -2
- package/dist/declarations/src/source/index.d.ts +3 -3
- package/dist/declarations/src/source/richtext.d.ts +70 -54
- package/dist/{index-4abf3a1f.esm.js → index-5d1ab97c.esm.js} +1 -1
- package/dist/{index-a9235737.esm.js → index-bccf1907.esm.js} +1 -1
- package/dist/{ops-a2a295f8.esm.js → ops-22b624eb.esm.js} +107 -35
- package/dist/{ops-f3015423.cjs.dev.js → ops-b0a33248.cjs.dev.js} +106 -33
- package/dist/{ops-0d09f8ee.cjs.prod.js → ops-def81fc3.cjs.prod.js} +106 -33
- package/dist/valbuild-core.cjs.dev.js +202 -104
- package/dist/valbuild-core.cjs.prod.js +202 -104
- package/dist/valbuild-core.esm.js +184 -106
- package/expr/dist/valbuild-core-expr.esm.js +2 -2
- package/package.json +4 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +6 -1
- package/patch/dist/valbuild-core-patch.cjs.prod.js +6 -1
- package/patch/dist/valbuild-core-patch.esm.js +8 -3
- package/src/getSha256.ts +8 -0
- package/src/index.ts +21 -5
- package/src/module.ts +33 -2
- package/src/patch/deref.ts +14 -1
- package/src/patch/operation.ts +10 -0
- package/src/patch/parse.ts +1 -0
- package/src/patch/patch.ts +3 -0
- package/src/schema/richtext.ts +19 -73
- package/src/schema/string.ts +14 -4
- package/src/schema/validation.test.ts +2 -2
- package/src/selector/future/index.ts +8 -4
- package/src/selector/index.ts +4 -4
- package/src/source/future/remote.ts +2 -2
- package/src/source/index.ts +2 -2
- package/src/source/richtext.test.ts +178 -0
- package/src/source/richtext.ts +295 -89
- package/tsconfig.json +2 -1
@@ -4,7 +4,7 @@ export { Schema, type SerializedSchema } from "./schema/index.js";
|
|
4
4
|
export type { ValModule, SerializedModule } from "./module.js";
|
5
5
|
export type { SourceObject, SourcePrimitive, Source } from "./source/index.js";
|
6
6
|
export type { FileSource } from "./source/file.js";
|
7
|
-
export type {
|
7
|
+
export type { AnyRichTextOptions, Bold, Classes, HeadingNode, ImageNode, Italic, LineThrough, ListItemNode, OrderedListNode, ParagraphNode, RichText, RichTextNode, RichTextOptions, RichTextSource, RichTextSourceNode, RootNode, SourceNode, SpanNode, UnorderedListNode, } from "./source/richtext.js";
|
8
8
|
export { type Val, type SerializedVal, type ModuleId, type ModulePath, type SourcePath, type JsonOfSource, } from "./val/index.js";
|
9
9
|
export type { Json, JsonPrimitive } from "./Json.js";
|
10
10
|
export type { ValidationErrors, ValidationError, } from "./schema/validation/ValidationError.js";
|
@@ -21,6 +21,7 @@ import { createValPathOfItem } from "./selector/SelectorProxy.js";
|
|
21
21
|
import { getVal } from "./future/fetchVal.js";
|
22
22
|
import { Json } from "./Json.js";
|
23
23
|
import { SerializedSchema } from "./schema/index.js";
|
24
|
+
import { convertRichTextSource } from "./source/richtext.js";
|
24
25
|
export { ValApi } from "./ValApi.js";
|
25
26
|
export type ApiTreeResponse = {
|
26
27
|
git: {
|
@@ -42,6 +43,7 @@ declare const Internal: {
|
|
42
43
|
url: string;
|
43
44
|
metadata?: import("./schema/image.js").ImageMetadata;
|
44
45
|
};
|
46
|
+
convertRichTextSource: typeof convertRichTextSource;
|
45
47
|
getSchema: typeof getSchema;
|
46
48
|
getValPath: typeof getValPath;
|
47
49
|
getVal: typeof getVal;
|
@@ -50,6 +52,7 @@ declare const Internal: {
|
|
50
52
|
splitModuleIdAndModulePath: typeof splitModuleIdAndModulePath;
|
51
53
|
isVal: typeof isVal;
|
52
54
|
createValPathOfItem: typeof createValPathOfItem;
|
55
|
+
getSHA256Hash: (bits: Uint8Array) => Promise<string>;
|
53
56
|
createPatchJSONPath: (modulePath: ModulePath) => string;
|
54
57
|
/**
|
55
58
|
* Enables draft mode: updates all Val modules with patches
|
@@ -26,7 +26,7 @@ export declare function initSchema(): {
|
|
26
26
|
string: <T extends string>(options?: {
|
27
27
|
maxLength?: number | undefined;
|
28
28
|
minLength?: number | undefined;
|
29
|
-
} | undefined) => import("./schema/
|
29
|
+
} | undefined) => import("./schema/string.js").StringSchema<T>;
|
30
30
|
boolean: () => import("./schema/index.js").Schema<boolean>;
|
31
31
|
array: <S extends import("./schema/index.js").Schema<import("./selector/index.js").SelectorSource>>(schema: S) => import("./schema/index.js").Schema<import("./schema/index.js").SchemaTypeOf<S>[]>;
|
32
32
|
object: <Props extends {
|
@@ -47,7 +47,7 @@ export declare function initSchema(): {
|
|
47
47
|
val?: undefined;
|
48
48
|
valPath?: undefined;
|
49
49
|
} & { [k in Key]: string; }>[]>(key: Key, ...objects: T_1) => import("./schema/index.js").Schema<T_1 extends import("./schema/index.js").Schema<infer S_1 extends import("./selector/index.js").SelectorSource>[] ? S_1 extends import("./selector/index.js").SelectorSource ? S_1 : never : never>;
|
50
|
-
richtext: () => import("./schema/index.js").Schema<import("./index.js").RichTextSource
|
50
|
+
richtext: <O extends import("./index.js").RichTextOptions>(options?: O | undefined) => import("./schema/index.js").Schema<import("./index.js").RichTextSource<O>>;
|
51
51
|
image: (options?: import("./schema/image.js").ImageOptions | undefined) => import("./schema/index.js").Schema<import("./index.js").FileSource<import("./schema/image.js").ImageMetadata>>;
|
52
52
|
literal: <T_2 extends string>(value: T_2) => import("./schema/index.js").Schema<T_2>;
|
53
53
|
keyOf: <Src extends import("./selector/index.js").GenericSelector<import("./source/index.js").SourceObject | import("./source/index.js").SourceArray, undefined> & import("./module.js").ValModuleBrand>(valModule: Src) => import("./schema/index.js").Schema<Src extends import("./selector/index.js").GenericSelector<infer S_2 extends import("./source/index.js").Source, undefined> ? S_2 extends readonly any[] ? number : S_2 extends import("./source/index.js").SourceObject ? keyof S_2 : S_2 extends Record<string, any> ? string : never : never>;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { result } from "../fp/index.js";
|
2
2
|
import { Ops, PatchError } from "./ops.js";
|
3
3
|
import { Patch } from "./patch.js";
|
4
|
+
import { Operation } from "./operation.js";
|
4
5
|
export type DerefPatchResult = {
|
5
6
|
dereferencedPatch: Patch;
|
6
7
|
fileUpdates: {
|
@@ -10,4 +11,4 @@ export type DerefPatchResult = {
|
|
10
11
|
[ref: string]: Patch;
|
11
12
|
};
|
12
13
|
};
|
13
|
-
export declare function derefPatch<D, E>(patch:
|
14
|
+
export declare function derefPatch<D, E>(patch: Operation[], document: D, ops: Ops<D, E>): result.Result<DerefPatchResult, E | PatchError>;
|
@@ -26,6 +26,10 @@ export type OperationJSON = {
|
|
26
26
|
op: "test";
|
27
27
|
path: string;
|
28
28
|
value: JSONValue;
|
29
|
+
} | {
|
30
|
+
op: "file";
|
31
|
+
path: string;
|
32
|
+
value: JSONValue;
|
29
33
|
};
|
30
34
|
/**
|
31
35
|
* Parsed form of JSON patch operation.
|
@@ -56,4 +60,8 @@ export type Operation = {
|
|
56
60
|
op: "test";
|
57
61
|
path: string[];
|
58
62
|
value: JSONValue;
|
63
|
+
} | {
|
64
|
+
op: "file";
|
65
|
+
path: string[];
|
66
|
+
value: JSONValue;
|
59
67
|
};
|
@@ -1,17 +1,18 @@
|
|
1
1
|
import { Schema, SerializedSchema } from "./index.js";
|
2
|
-
import { RichTextSource } from "../source/richtext.js";
|
2
|
+
import { RichTextSource, RichTextOptions } from "../source/richtext.js";
|
3
3
|
import { SourcePath } from "../val/index.js";
|
4
4
|
import { ValidationErrors } from "./validation/ValidationError.js";
|
5
|
-
export type SerializedRichTextSchema = {
|
5
|
+
export type SerializedRichTextSchema = RichTextOptions & {
|
6
6
|
type: "richtext";
|
7
7
|
opt: boolean;
|
8
8
|
};
|
9
|
-
export declare class RichTextSchema<Src extends RichTextSource | null> extends Schema<Src> {
|
9
|
+
export declare class RichTextSchema<O extends RichTextOptions, Src extends RichTextSource<O> | null> extends Schema<Src> {
|
10
|
+
readonly options: O;
|
10
11
|
readonly opt: boolean;
|
12
|
+
constructor(options: O, opt?: boolean);
|
11
13
|
validate(path: SourcePath, src: Src): ValidationErrors;
|
12
14
|
assert(src: Src): boolean;
|
13
|
-
optional(): Schema<RichTextSource | null>;
|
15
|
+
optional(): Schema<RichTextSource<O> | null>;
|
14
16
|
serialize(): SerializedSchema;
|
15
|
-
constructor(opt?: boolean);
|
16
17
|
}
|
17
|
-
export declare const richtext: () => Schema<RichTextSource
|
18
|
+
export declare const richtext: <O extends RichTextOptions>(options?: O | undefined) => Schema<RichTextSource<O>>;
|
@@ -9,15 +9,18 @@ export type SerializedStringSchema = {
|
|
9
9
|
type: "string";
|
10
10
|
options?: StringOptions;
|
11
11
|
opt: boolean;
|
12
|
+
raw: boolean;
|
12
13
|
};
|
13
14
|
export declare class StringSchema<Src extends string | null> extends Schema<Src> {
|
14
15
|
readonly options?: StringOptions | undefined;
|
15
16
|
readonly opt: boolean;
|
16
|
-
|
17
|
+
private readonly isRaw;
|
18
|
+
constructor(options?: StringOptions | undefined, opt?: boolean, isRaw?: boolean);
|
17
19
|
validate(path: SourcePath, src: Src): ValidationErrors;
|
18
20
|
assert(src: Src): boolean;
|
19
|
-
optional():
|
21
|
+
optional(): StringSchema<Src | null>;
|
22
|
+
raw(): StringSchema<Src>;
|
20
23
|
serialize(): SerializedSchema;
|
21
24
|
}
|
22
|
-
export declare const string: <T extends string>(options?: StringOptions) =>
|
25
|
+
export declare const string: <T extends string>(options?: StringOptions) => StringSchema<T>;
|
23
26
|
export {};
|
@@ -15,7 +15,7 @@ import { A } from "ts-toolbelt";
|
|
15
15
|
import { I18nSource, I18nCompatibleSource } from "../../source/future/i18n.js";
|
16
16
|
import { RemoteCompatibleSource, RemoteSource } from "../../source/future/remote.js";
|
17
17
|
import { FileSource } from "../../source/file.js";
|
18
|
-
import { RichText, RichTextSource } from "../../source/richtext.js";
|
18
|
+
import { AnyRichTextOptions, RichText, RichTextSource } from "../../source/richtext.js";
|
19
19
|
/**
|
20
20
|
* Selectors can be used to select parts of a Val module.
|
21
21
|
* Unlike queries, joins, aggregates etc is and will not be supported.
|
@@ -37,10 +37,10 @@ import { RichText, RichTextSource } from "../../source/richtext.js";
|
|
37
37
|
* }));
|
38
38
|
*
|
39
39
|
*/
|
40
|
-
export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends I18nSource<infer L, infer S> ? I18nSelector<L, S> : T extends RemoteSource<infer S> ? S extends RemoteCompatibleSource ? RemoteSelector<S> : GenericSelector<Source, "Could not determine remote source"> : T extends FileSource ? FileSelector : T extends RichTextSource ? RichText : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
|
40
|
+
export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends I18nSource<infer L, infer S> ? I18nSelector<L, S> : T extends RemoteSource<infer S> ? S extends RemoteCompatibleSource ? RemoteSelector<S> : GenericSelector<Source, "Could not determine remote source"> : T extends FileSource ? FileSelector : T extends RichTextSource<infer O> ? RichText<O> : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
|
41
41
|
export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
|
42
42
|
[key: string]: SelectorSource;
|
43
|
-
} | I18nSource<readonly string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource | GenericSelector<Source>;
|
43
|
+
} | I18nSource<readonly string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource<AnyRichTextOptions> | GenericSelector<Source>;
|
44
44
|
/**
|
45
45
|
* @internal
|
46
46
|
*/
|
@@ -10,11 +10,11 @@ import { Source, SourceArray, SourceObject, SourcePrimitive } from "../source/in
|
|
10
10
|
import { Schema } from "../schema/index.js";
|
11
11
|
import type { A } from "ts-toolbelt";
|
12
12
|
import { FileSource } from "../source/file.js";
|
13
|
-
import { RichText, RichTextSource } from "../source/richtext.js";
|
14
|
-
export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends FileSource ? FileSelector : T extends RichTextSource ? RichText : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
|
13
|
+
import { RichText, RichTextOptions, RichTextSource } from "../source/richtext.js";
|
14
|
+
export type Selector<T extends Source> = Source extends T ? GenericSelector<T> : T extends FileSource ? FileSelector : T extends RichTextSource<infer O> ? RichText<O> : T extends SourceObject ? ObjectSelector<T> : T extends SourceArray ? ArraySelector<T> : T extends string ? StringSelector<T> : T extends number ? NumberSelector<T> : T extends boolean ? BooleanSelector<T> : T extends null ? PrimitiveSelector<null> : never;
|
15
15
|
export type SelectorSource = SourcePrimitive | undefined | readonly SelectorSource[] | {
|
16
16
|
[key: string]: SelectorSource;
|
17
|
-
} | FileSource | RichTextSource | GenericSelector<Source>;
|
17
|
+
} | FileSource | RichTextSource<RichTextOptions> | GenericSelector<Source>;
|
18
18
|
/**
|
19
19
|
* @internal
|
20
20
|
*/
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { SourcePrimitive, VAL_EXTENSION, PhantomType } from "../index.js";
|
2
2
|
import { FileSource } from "../file.js";
|
3
3
|
import { I18nCompatibleSource, I18nSource } from "./i18n.js";
|
4
|
-
import { RichTextSource } from "../richtext.js";
|
4
|
+
import { AnyRichTextOptions, RichTextSource } from "../richtext.js";
|
5
5
|
/**
|
6
6
|
* Remote sources cannot include other remote sources.
|
7
7
|
*/
|
8
|
-
export type RemoteCompatibleSource = SourcePrimitive | RemoteObject | RemoteArray | RichTextSource | FileSource | I18nSource<string[], I18nCompatibleSource>;
|
8
|
+
export type RemoteCompatibleSource = SourcePrimitive | RemoteObject | RemoteArray | RichTextSource<AnyRichTextOptions> | FileSource | I18nSource<string[], I18nCompatibleSource>;
|
9
9
|
export type RemoteObject = {
|
10
10
|
[key in string]: RemoteCompatibleSource;
|
11
11
|
};
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { FileSource } from "./file.js";
|
2
2
|
import { I18nSource, I18nCompatibleSource } from "./future/i18n.js";
|
3
3
|
import { RemoteSource, RemoteCompatibleSource } from "./future/remote.js";
|
4
|
-
import { RichTextSource } from "./richtext.js";
|
5
|
-
export type Source = SourcePrimitive | SourceObject | SourceArray | I18nSource<string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource
|
4
|
+
import { RichTextOptions, RichTextSource } from "./richtext.js";
|
5
|
+
export type Source = SourcePrimitive | SourceObject | SourceArray | I18nSource<string[], I18nCompatibleSource> | RemoteSource<RemoteCompatibleSource> | FileSource | RichTextSource<RichTextOptions>;
|
6
6
|
export type SourceObject = {
|
7
7
|
[key in string]: Source;
|
8
8
|
} & {
|
@@ -17,7 +17,7 @@ export type SourceObject = {
|
|
17
17
|
export type SourceArray = readonly Source[];
|
18
18
|
export type SourcePrimitive = string | number | boolean | null;
|
19
19
|
export declare const VAL_EXTENSION: "_type";
|
20
|
-
export declare function getValExtension(source: Source): false | "" | 0 | "
|
20
|
+
export declare function getValExtension(source: Source): false | "" | 0 | "remote" | "file" | "richtext" | "i18n" | null | undefined;
|
21
21
|
/**
|
22
22
|
* A phantom type parameter is one that doesn't show up at runtime, but is checked statically (and only) at compile time.
|
23
23
|
*
|
@@ -1,63 +1,79 @@
|
|
1
|
+
import { FileSource } from "./file.js";
|
1
2
|
import { VAL_EXTENSION } from "./index.js";
|
2
|
-
|
3
|
-
|
4
|
-
|
3
|
+
export type RichTextOptions = {
|
4
|
+
headings?: ("h1" | "h2" | "h3" | "h4" | "h5" | "h6")[];
|
5
|
+
img?: boolean;
|
6
|
+
ul?: boolean;
|
7
|
+
ol?: boolean;
|
8
|
+
lineThrough?: boolean;
|
9
|
+
bold?: boolean;
|
10
|
+
italic?: boolean;
|
5
11
|
};
|
6
|
-
type
|
7
|
-
|
8
|
-
|
9
|
-
indent?: number;
|
12
|
+
export type ParagraphNode<O extends RichTextOptions> = {
|
13
|
+
tag: "p";
|
14
|
+
children: (string | SpanNode<O> | ImageNode<O>)[];
|
10
15
|
};
|
11
|
-
type
|
12
|
-
type
|
13
|
-
export type
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
text: string;
|
20
|
-
direction?: DirectionType;
|
21
|
-
indent?: number;
|
16
|
+
export type LineThrough<O extends RichTextOptions> = O["lineThrough"] extends true ? "line-through" : never;
|
17
|
+
export type Italic<O extends RichTextOptions> = O["italic"] extends true ? "italic" : never;
|
18
|
+
export type Bold<O extends RichTextOptions> = O["bold"] extends true ? "bold" : never;
|
19
|
+
export type Classes<O extends RichTextOptions> = LineThrough<O> | Italic<O> | Bold<O>;
|
20
|
+
export type SpanNode<O extends RichTextOptions> = {
|
21
|
+
tag: "span";
|
22
|
+
classes: Classes<O>[];
|
23
|
+
children: [string | SpanNode<O>];
|
22
24
|
};
|
23
|
-
export type
|
24
|
-
|
25
|
-
|
25
|
+
export type ImageNode<O extends RichTextOptions> = O["img"] extends true ? {
|
26
|
+
tag: "img";
|
27
|
+
src: string;
|
28
|
+
height?: number;
|
29
|
+
width?: number;
|
30
|
+
} : never;
|
31
|
+
export type ListItemNode<O extends RichTextOptions> = {
|
32
|
+
tag: "li";
|
33
|
+
children: (string | SpanNode<O> | ImageNode<O> | UnorderedListNode<O> | OrderedListNode<O>)[];
|
26
34
|
};
|
27
|
-
export type
|
28
|
-
|
29
|
-
|
30
|
-
|
35
|
+
export type UnorderedListNode<O extends RichTextOptions> = O["ul"] extends true ? {
|
36
|
+
tag: "ul";
|
37
|
+
dir?: "ltr" | "rtl";
|
38
|
+
children: ListItemNode<O>[];
|
39
|
+
} : never;
|
40
|
+
export type OrderedListNode<O extends RichTextOptions> = O["ol"] extends true ? {
|
41
|
+
tag: "ol";
|
42
|
+
dir?: "ltr" | "rtl";
|
43
|
+
children: ListItemNode<O>[];
|
44
|
+
} : never;
|
45
|
+
export type HeadingNode<O extends RichTextOptions> = O["headings"] extends any[] ? {
|
46
|
+
tag: O["headings"][number];
|
47
|
+
children: (string | SpanNode<O>)[];
|
48
|
+
} : never;
|
49
|
+
type ImageSource = FileSource<{
|
50
|
+
width: number;
|
51
|
+
height: number;
|
52
|
+
sha256: string;
|
53
|
+
}>;
|
54
|
+
export type SourceNode<O extends RichTextOptions> = O["img"] extends true ? ImageSource : never;
|
55
|
+
export type AnyRichTextOptions = {
|
56
|
+
headings: ("h1" | "h2" | "h3" | "h4" | "h5" | "h6")[];
|
57
|
+
img: true;
|
58
|
+
ul: true;
|
59
|
+
ol: true;
|
60
|
+
lineThrough: true;
|
61
|
+
bold: true;
|
62
|
+
italic: true;
|
31
63
|
};
|
32
|
-
export type
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
64
|
+
export type RichTextSourceNode<O extends RichTextOptions> = Exclude<RichTextNode<O>, {
|
65
|
+
tag: "img";
|
66
|
+
}> | ParagraphNode<O> | ListItemNode<O> | ImageNode<O> | SourceNode<O>;
|
67
|
+
export type RichTextSource<O extends RichTextOptions> = {
|
68
|
+
[VAL_EXTENSION]: "richtext";
|
69
|
+
children: (HeadingNode<O> | ParagraphNode<O> | UnorderedListNode<O> | OrderedListNode<O> | SourceNode<O>)[];
|
37
70
|
};
|
38
|
-
export type
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
start?: number;
|
71
|
+
export type RichTextNode<O extends RichTextOptions> = string | HeadingNode<O> | ParagraphNode<O> | UnorderedListNode<O> | OrderedListNode<O> | ListItemNode<O> | SpanNode<O> | ImageNode<O>;
|
72
|
+
export type RootNode<O extends RichTextOptions> = HeadingNode<O> | ParagraphNode<O> | UnorderedListNode<O> | OrderedListNode<O> | ImageNode<O>;
|
73
|
+
export type RichText<O extends RichTextOptions> = {
|
74
|
+
[VAL_EXTENSION]: "richtext";
|
75
|
+
children: RootNode<O>[];
|
44
76
|
};
|
45
|
-
|
46
|
-
export
|
47
|
-
children: (HeadingNode<HT> | ParagraphNode<VN> | ListNode<VN>)[];
|
48
|
-
type?: "root";
|
49
|
-
format?: FormatType;
|
50
|
-
direction?: DirectionType;
|
51
|
-
indent?: number;
|
52
|
-
};
|
53
|
-
declare const brand: unique symbol;
|
54
|
-
export type RichText<HT extends HeadingTags = HeadingTags, VN extends TextNode = TextNode> = RootNode<HT, VN> & {
|
55
|
-
[brand]: "richtext";
|
56
|
-
valPath: SourcePath;
|
57
|
-
};
|
58
|
-
export type RichTextSource = RichText & {
|
59
|
-
readonly [VAL_EXTENSION]: "richtext";
|
60
|
-
};
|
61
|
-
export declare function richtext(data: RootNode<HeadingTags, TextNode> | string): RichTextSource;
|
62
|
-
export declare function isRichText(obj: unknown): obj is RichTextSource;
|
77
|
+
export declare function convertRichTextSource<O extends RichTextOptions>(src: RichTextSource<O>): RichText<O>;
|
78
|
+
export declare function richtext<O extends RichTextOptions, Nodes extends never | ImageSource>(templateStrings: TemplateStringsArray, ...expr: Nodes[]): RichTextSource<O>;
|
63
79
|
export {};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { j as _objectSpread2, k as _slicedToArray, c as _createClass, b as _classCallCheck, r as Sym, C as Call, s as StringLiteral, t as StringTemplate, e as _typeof, n as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, f as convertFileSource, d as _defineProperty, S as Schema, E as Expr, u as _toConsumableArray, N as NilSym } from './index-bccf1907.esm.js';
|
2
2
|
import { i as isErr, e as err, o as ok, a as isOk } from './result-b96df128.esm.js';
|
3
3
|
|
4
4
|
var WHITE_SPACE = ["\n", "\r", "\t", " "];
|
@@ -547,4 +547,4 @@ function getValPath(valOrSelector) {
|
|
547
547
|
return valOrSelector[Path];
|
548
548
|
}
|
549
549
|
|
550
|
-
export { Call as C, Expr as E, FILE_REF_PROP as F, GetSchema as G, ImageSchema as I, NilSym as N, Path as P, Schema as S, VAL_EXTENSION as V, _inherits as _, _createSuper as a, _classCallCheck as b, _createClass as c, _defineProperty as d, _typeof as e,
|
550
|
+
export { Call as C, Expr as E, FILE_REF_PROP as F, GetSchema as G, ImageSchema as I, NilSym as N, Path as P, Schema as S, VAL_EXTENSION as V, _inherits as _, _createSuper as a, _classCallCheck as b, _createClass as c, _defineProperty as d, _typeof as e, convertFileSource as f, getValPath as g, file as h, image as i, _objectSpread2 as j, _slicedToArray as k, isFile as l, GetSource as m, isSerializedVal as n, getSchema as o, isVal as p, GenericSelector as q, Sym as r, StringLiteral as s, StringTemplate as t, _toConsumableArray as u };
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { e as _typeof,
|
1
|
+
import { e as _typeof, n as isSerializedVal, F as FILE_REF_PROP, V as VAL_EXTENSION, f as convertFileSource, d as _defineProperty, m as GetSource, P as Path, G as GetSchema, S as Schema, E as Expr, _ as _inherits, a as _createSuper, b as _classCallCheck, c as _createClass, k as _slicedToArray, j as _objectSpread2, u as _toConsumableArray, I as ImageSchema } from './index-bccf1907.esm.js';
|
2
2
|
import { _ as _createForOfIteratorHelper } from './result-b96df128.esm.js';
|
3
3
|
|
4
4
|
function hasOwn(obj, prop) {
|
@@ -380,75 +380,132 @@ var union = function union(key) {
|
|
380
380
|
var RichTextSchema = /*#__PURE__*/function (_Schema) {
|
381
381
|
_inherits(RichTextSchema, _Schema);
|
382
382
|
var _super = _createSuper(RichTextSchema);
|
383
|
-
function RichTextSchema() {
|
383
|
+
function RichTextSchema(options) {
|
384
384
|
var _this;
|
385
|
-
var opt = arguments.length >
|
385
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
386
386
|
_classCallCheck(this, RichTextSchema);
|
387
387
|
_this = _super.call(this);
|
388
|
+
_this.options = options;
|
388
389
|
_this.opt = opt;
|
389
390
|
return _this;
|
390
391
|
}
|
391
392
|
_createClass(RichTextSchema, [{
|
392
393
|
key: "validate",
|
393
394
|
value: function validate(path, src) {
|
395
|
+
return false; //TODO
|
396
|
+
}
|
397
|
+
}, {
|
398
|
+
key: "assert",
|
399
|
+
value: function assert(src) {
|
400
|
+
return true; // TODO
|
401
|
+
}
|
402
|
+
}, {
|
403
|
+
key: "optional",
|
404
|
+
value: function optional() {
|
405
|
+
return new RichTextSchema(this.options, true);
|
406
|
+
}
|
407
|
+
}, {
|
408
|
+
key: "serialize",
|
409
|
+
value: function serialize() {
|
410
|
+
return {
|
411
|
+
type: "richtext",
|
412
|
+
opt: this.opt
|
413
|
+
};
|
414
|
+
}
|
415
|
+
}]);
|
416
|
+
return RichTextSchema;
|
417
|
+
}(Schema);
|
418
|
+
var richtext = function richtext(options) {
|
419
|
+
return new RichTextSchema(options !== null && options !== void 0 ? options : {});
|
420
|
+
};
|
421
|
+
|
422
|
+
var RecordSchema = /*#__PURE__*/function (_Schema) {
|
423
|
+
_inherits(RecordSchema, _Schema);
|
424
|
+
var _super = _createSuper(RecordSchema);
|
425
|
+
function RecordSchema(item) {
|
426
|
+
var _this;
|
427
|
+
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
428
|
+
_classCallCheck(this, RecordSchema);
|
429
|
+
_this = _super.call(this);
|
430
|
+
_this.item = item;
|
431
|
+
_this.opt = opt;
|
432
|
+
return _this;
|
433
|
+
}
|
434
|
+
_createClass(RecordSchema, [{
|
435
|
+
key: "validate",
|
436
|
+
value: function validate(path, src) {
|
437
|
+
var _this2 = this;
|
438
|
+
var error = false;
|
394
439
|
if (this.opt && (src === null || src === undefined)) {
|
395
440
|
return false;
|
396
441
|
}
|
397
|
-
if (src
|
398
|
-
return _defineProperty({}, path, [{
|
399
|
-
message: "Expected non-nullable got '".concat(src, "'")
|
400
|
-
}]);
|
401
|
-
}
|
402
|
-
if (_typeof(src) !== "object" && !Array.isArray(src)) {
|
403
|
-
return _defineProperty({}, path, [{
|
404
|
-
message: "Expected 'object' (that is not of an array) or 'string', got '".concat(_typeof(src), "'"),
|
405
|
-
value: src
|
406
|
-
}]);
|
407
|
-
}
|
408
|
-
if (src[VAL_EXTENSION] !== "richtext") {
|
409
|
-
return _defineProperty({}, path, [{
|
410
|
-
message: "Expected _type key with value 'richtext' got '".concat(src[VAL_EXTENSION], "'"),
|
411
|
-
value: src
|
412
|
-
}]);
|
413
|
-
}
|
414
|
-
if (src.type !== "root") {
|
442
|
+
if (_typeof(src) !== "object") {
|
415
443
|
return _defineProperty({}, path, [{
|
416
|
-
message: "Expected
|
417
|
-
value: src
|
444
|
+
message: "Expected 'object', got '".concat(_typeof(src), "'")
|
418
445
|
}]);
|
419
446
|
}
|
420
|
-
if (
|
447
|
+
if (Array.isArray(src)) {
|
421
448
|
return _defineProperty({}, path, [{
|
422
|
-
message: "Expected
|
423
|
-
value: src
|
449
|
+
message: "Expected 'object', got 'array'"
|
424
450
|
}]);
|
425
451
|
}
|
426
|
-
|
452
|
+
Object.entries(src).forEach(function (_ref3) {
|
453
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
454
|
+
key = _ref4[0],
|
455
|
+
elem = _ref4[1];
|
456
|
+
var subPath = createValPathOfItem(path, key);
|
457
|
+
if (!subPath) {
|
458
|
+
error = _this2.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(elem),
|
459
|
+
// Should! never happen
|
460
|
+
src);
|
461
|
+
} else {
|
462
|
+
var subError = _this2.item.validate(subPath, elem);
|
463
|
+
if (subError && error) {
|
464
|
+
error = _objectSpread2(_objectSpread2({}, subError), error);
|
465
|
+
} else if (subError) {
|
466
|
+
error = subError;
|
467
|
+
}
|
468
|
+
}
|
469
|
+
});
|
470
|
+
return error;
|
427
471
|
}
|
428
472
|
}, {
|
429
473
|
key: "assert",
|
430
474
|
value: function assert(src) {
|
431
|
-
|
432
|
-
|
475
|
+
if (this.opt && (src === null || src === undefined)) {
|
476
|
+
return true;
|
477
|
+
}
|
478
|
+
if (!src) {
|
479
|
+
return false;
|
480
|
+
}
|
481
|
+
for (var _i = 0, _Object$entries = Object.entries(src); _i < _Object$entries.length; _i++) {
|
482
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
483
|
+
_item = _Object$entries$_i[1];
|
484
|
+
if (!this.item.assert(_item)) {
|
485
|
+
return false;
|
486
|
+
}
|
487
|
+
}
|
488
|
+
return _typeof(src) === "object" && !Array.isArray(src);
|
433
489
|
}
|
434
490
|
}, {
|
435
491
|
key: "optional",
|
436
492
|
value: function optional() {
|
437
|
-
return new
|
493
|
+
return new RecordSchema(this.item, true);
|
438
494
|
}
|
439
495
|
}, {
|
440
496
|
key: "serialize",
|
441
497
|
value: function serialize() {
|
442
498
|
return {
|
443
|
-
type: "
|
499
|
+
type: "record",
|
500
|
+
item: this.item.serialize(),
|
444
501
|
opt: this.opt
|
445
502
|
};
|
446
503
|
}
|
447
504
|
}]);
|
448
|
-
return
|
505
|
+
return RecordSchema;
|
449
506
|
}(Schema);
|
450
|
-
var
|
451
|
-
return new
|
507
|
+
var record = function record(schema) {
|
508
|
+
return new RecordSchema(schema);
|
452
509
|
};
|
453
510
|
|
454
511
|
function content(
|
@@ -475,6 +532,9 @@ function splitModuleIdAndModulePath(path) {
|
|
475
532
|
function isObjectSchema(schema) {
|
476
533
|
return schema instanceof ObjectSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "object";
|
477
534
|
}
|
535
|
+
function isRecordSchema(schema) {
|
536
|
+
return schema instanceof RecordSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "record";
|
537
|
+
}
|
478
538
|
function isArraySchema(schema) {
|
479
539
|
return schema instanceof ArraySchema || _typeof(schema) === "object" && "type" in schema && schema.type === "array";
|
480
540
|
}
|
@@ -533,6 +593,18 @@ function resolvePath(path, valModule, schema) {
|
|
533
593
|
}
|
534
594
|
resolvedSource = resolvedSource[part];
|
535
595
|
resolvedSchema = resolvedSchema.item;
|
596
|
+
} else if (isRecordSchema(resolvedSchema)) {
|
597
|
+
if (typeof part !== "string") {
|
598
|
+
throw Error("Invalid path: record schema ".concat(resolvedSchema, " must have path: ").concat(part, " as string"));
|
599
|
+
}
|
600
|
+
if (_typeof(resolvedSource) !== "object" && !Array.isArray(resolvedSource)) {
|
601
|
+
throw Error("Schema type error: expected source to be type of record, but got ".concat(_typeof(resolvedSource)));
|
602
|
+
}
|
603
|
+
if (!resolvedSource[part]) {
|
604
|
+
throw Error("Invalid path: record source did not have key ".concat(part, " from path: ").concat(path));
|
605
|
+
}
|
606
|
+
resolvedSource = resolvedSource[part];
|
607
|
+
resolvedSchema = resolvedSchema.item;
|
536
608
|
} else if (isObjectSchema(resolvedSchema)) {
|
537
609
|
if (_typeof(resolvedSource) !== "object") {
|
538
610
|
throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
|
@@ -668,4 +740,4 @@ var PatchError = /*#__PURE__*/_createClass(function PatchError(message) {
|
|
668
740
|
* NOTE: MAY mutate the input document.
|
669
741
|
*/
|
670
742
|
|
671
|
-
export { PatchError as P, array as a,
|
743
|
+
export { PatchError as P, array as a, record as b, content as c, createValPathOfItem as d, resolvePath as e, getSource as g, isSelector as i, newSelectorProxy as n, object as o, richtext as r, splitModuleIdAndModulePath as s, union as u };
|