@prismicio/types-internal 0.2.11 → 0.3.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/lib/customtypes/widgets/nestable/RichText.d.ts +18 -1
- package/lib/customtypes/widgets/nestable/RichText.js +22 -41
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.d.ts +49 -16
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.js +8 -9
- package/package.json +1 -1
- package/src/customtypes/widgets/nestable/RichText.ts +24 -42
- package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +12 -11
|
@@ -19,7 +19,24 @@ export declare enum RichTextNodeType {
|
|
|
19
19
|
orderedList = "o-list-item",
|
|
20
20
|
rtl = "rtl"
|
|
21
21
|
}
|
|
22
|
-
export declare
|
|
22
|
+
export declare const RichTextNodeTypeCodec: t.KeyofC<{
|
|
23
|
+
heading1: null;
|
|
24
|
+
heading2: null;
|
|
25
|
+
heading3: null;
|
|
26
|
+
heading4: null;
|
|
27
|
+
heading5: null;
|
|
28
|
+
heading6: null;
|
|
29
|
+
paragraph: null;
|
|
30
|
+
strong: null;
|
|
31
|
+
em: null;
|
|
32
|
+
preformatted: null;
|
|
33
|
+
hyperlink: null;
|
|
34
|
+
image: null;
|
|
35
|
+
embed: null;
|
|
36
|
+
"list-item": null;
|
|
37
|
+
"o-list-item": null;
|
|
38
|
+
rtl: null;
|
|
39
|
+
}>;
|
|
23
40
|
export declare const RichTextConfig: t.ExactC<t.PartialC<{
|
|
24
41
|
label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
25
42
|
placeholder: t.StringC;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RichText = exports.RichTextConfig = exports.
|
|
3
|
+
exports.RichText = exports.RichTextConfig = exports.RichTextNodeTypeCodec = exports.RichTextNodeType = exports.DEFAULT_OPTION = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const Either_1 = require("fp-ts/lib/Either");
|
|
6
6
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
@@ -27,51 +27,32 @@ var RichTextNodeType;
|
|
|
27
27
|
RichTextNodeType["orderedList"] = "o-list-item";
|
|
28
28
|
RichTextNodeType["rtl"] = "rtl";
|
|
29
29
|
})(RichTextNodeType = exports.RichTextNodeType || (exports.RichTextNodeType = {}));
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
case RichTextNodeType.em:
|
|
49
|
-
return RichTextNodeType.em;
|
|
50
|
-
case RichTextNodeType.preformatted:
|
|
51
|
-
return RichTextNodeType.preformatted;
|
|
52
|
-
case RichTextNodeType.hyperlink:
|
|
53
|
-
return RichTextNodeType.hyperlink;
|
|
54
|
-
case RichTextNodeType.image:
|
|
55
|
-
return RichTextNodeType.image;
|
|
56
|
-
case RichTextNodeType.embed:
|
|
57
|
-
return RichTextNodeType.embed;
|
|
58
|
-
case RichTextNodeType.list:
|
|
59
|
-
return RichTextNodeType.list;
|
|
60
|
-
case RichTextNodeType.orderedList:
|
|
61
|
-
return RichTextNodeType.orderedList;
|
|
62
|
-
case RichTextNodeType.rtl:
|
|
63
|
-
return RichTextNodeType.rtl;
|
|
64
|
-
default:
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.parseRichTextNodeType = parseRichTextNodeType;
|
|
30
|
+
exports.RichTextNodeTypeCodec = t.keyof({
|
|
31
|
+
[RichTextNodeType.heading1]: null,
|
|
32
|
+
[RichTextNodeType.heading2]: null,
|
|
33
|
+
[RichTextNodeType.heading3]: null,
|
|
34
|
+
[RichTextNodeType.heading4]: null,
|
|
35
|
+
[RichTextNodeType.heading5]: null,
|
|
36
|
+
[RichTextNodeType.heading6]: null,
|
|
37
|
+
[RichTextNodeType.paragraph]: null,
|
|
38
|
+
[RichTextNodeType.strong]: null,
|
|
39
|
+
[RichTextNodeType.em]: null,
|
|
40
|
+
[RichTextNodeType.preformatted]: null,
|
|
41
|
+
[RichTextNodeType.hyperlink]: null,
|
|
42
|
+
[RichTextNodeType.image]: null,
|
|
43
|
+
[RichTextNodeType.embed]: null,
|
|
44
|
+
[RichTextNodeType.list]: null,
|
|
45
|
+
[RichTextNodeType.orderedList]: null,
|
|
46
|
+
[RichTextNodeType.rtl]: null,
|
|
47
|
+
});
|
|
69
48
|
const RichTextOptions = new t.Type("RichTextOptions", (u) => typeof u === "string", (u, context) => {
|
|
70
49
|
return Either_1.either.chain(t.union([t.string, t.null]).validate(u, context), (s) => {
|
|
71
50
|
if (!s)
|
|
72
51
|
return t.success(exports.DEFAULT_OPTION);
|
|
73
52
|
const entries = s.split(",").map((e) => e.trim());
|
|
74
|
-
const filtered = entries.filter((entry) =>
|
|
53
|
+
const filtered = entries.filter((entry) => {
|
|
54
|
+
return (0, Either_1.getOrElseW)(() => undefined)(exports.RichTextNodeTypeCodec.decode(entry));
|
|
55
|
+
});
|
|
75
56
|
if (!filtered.length)
|
|
76
57
|
return t.success(exports.DEFAULT_OPTION);
|
|
77
58
|
return t.success(filtered.join(","));
|
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import { RichTextNodeType } from "../../../../customtypes/widgets/nestable";
|
|
2
3
|
export declare const Meta: t.ExactC<t.IntersectionC<[t.PartialC<{
|
|
3
4
|
data: t.UnknownC;
|
|
4
5
|
}>, t.TypeC<{
|
|
5
6
|
start: t.NumberC;
|
|
6
7
|
end: t.NumberC;
|
|
7
|
-
type: t.
|
|
8
|
+
type: t.KeyofC<{
|
|
9
|
+
heading1: null;
|
|
10
|
+
heading2: null;
|
|
11
|
+
heading3: null;
|
|
12
|
+
heading4: null;
|
|
13
|
+
heading5: null;
|
|
14
|
+
heading6: null;
|
|
15
|
+
paragraph: null;
|
|
16
|
+
strong: null;
|
|
17
|
+
em: null;
|
|
18
|
+
preformatted: null;
|
|
19
|
+
hyperlink: null;
|
|
20
|
+
image: null;
|
|
21
|
+
embed: null;
|
|
22
|
+
"list-item": null;
|
|
23
|
+
"o-list-item": null;
|
|
24
|
+
rtl: null;
|
|
25
|
+
}>;
|
|
8
26
|
}>]>>;
|
|
9
27
|
export declare type Meta = t.TypeOf<typeof Meta>;
|
|
10
28
|
export declare const Span: t.ExactC<t.IntersectionC<[t.PartialC<{
|
|
@@ -12,7 +30,24 @@ export declare const Span: t.ExactC<t.IntersectionC<[t.PartialC<{
|
|
|
12
30
|
}>, t.TypeC<{
|
|
13
31
|
start: t.NumberC;
|
|
14
32
|
end: t.NumberC;
|
|
15
|
-
type: t.
|
|
33
|
+
type: t.KeyofC<{
|
|
34
|
+
heading1: null;
|
|
35
|
+
heading2: null;
|
|
36
|
+
heading3: null;
|
|
37
|
+
heading4: null;
|
|
38
|
+
heading5: null;
|
|
39
|
+
heading6: null;
|
|
40
|
+
paragraph: null;
|
|
41
|
+
strong: null;
|
|
42
|
+
em: null;
|
|
43
|
+
preformatted: null;
|
|
44
|
+
hyperlink: null;
|
|
45
|
+
image: null;
|
|
46
|
+
embed: null;
|
|
47
|
+
"list-item": null;
|
|
48
|
+
"o-list-item": null;
|
|
49
|
+
rtl: null;
|
|
50
|
+
}>;
|
|
16
51
|
}>]>>;
|
|
17
52
|
export declare type Span = Meta;
|
|
18
53
|
export declare const ValidatedMetas: t.Type<({
|
|
@@ -20,17 +55,16 @@ export declare const ValidatedMetas: t.Type<({
|
|
|
20
55
|
} & {
|
|
21
56
|
start: number;
|
|
22
57
|
end: number;
|
|
23
|
-
type:
|
|
58
|
+
type: RichTextNodeType;
|
|
24
59
|
})[], ({
|
|
25
60
|
data?: unknown;
|
|
26
61
|
} & {
|
|
27
62
|
start: number;
|
|
28
63
|
end: number;
|
|
29
|
-
type:
|
|
64
|
+
type: RichTextNodeType;
|
|
30
65
|
})[], unknown>;
|
|
31
|
-
export declare const ImageBlockType = "image";
|
|
32
66
|
export declare const ImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
33
|
-
type: t.LiteralC<
|
|
67
|
+
type: t.LiteralC<RichTextNodeType.image>;
|
|
34
68
|
data: t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
35
69
|
origin: t.ExactC<t.TypeC<{
|
|
36
70
|
id: t.StringC;
|
|
@@ -124,9 +158,8 @@ export declare const ImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
124
158
|
}>]>>;
|
|
125
159
|
export declare type ImageBlock = t.TypeOf<typeof ImageBlock>;
|
|
126
160
|
export declare function checkImageBlock(block: Block): block is ImageBlock;
|
|
127
|
-
export declare const EmbedBlockType = "embed";
|
|
128
161
|
export declare const EmbedBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
129
|
-
type: t.LiteralC<
|
|
162
|
+
type: t.LiteralC<RichTextNodeType.embed>;
|
|
130
163
|
data: t.Type<import("../EmbedContent").EmbedContentO, unknown, unknown>;
|
|
131
164
|
}>, t.PartialC<{
|
|
132
165
|
label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
@@ -135,7 +168,7 @@ export declare const EmbedBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
135
168
|
export declare type EmbedBlock = t.TypeOf<typeof EmbedBlock>;
|
|
136
169
|
export declare function checkEmbedBlock(block: Block): block is EmbedBlock;
|
|
137
170
|
export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
138
|
-
type: t.Type<
|
|
171
|
+
type: t.Type<RichTextNodeType, RichTextNodeType, unknown>;
|
|
139
172
|
content: t.IntersectionC<[t.TypeC<{
|
|
140
173
|
text: t.StringC;
|
|
141
174
|
}>, t.PartialC<{
|
|
@@ -144,13 +177,13 @@ export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
144
177
|
} & {
|
|
145
178
|
start: number;
|
|
146
179
|
end: number;
|
|
147
|
-
type:
|
|
180
|
+
type: RichTextNodeType;
|
|
148
181
|
})[], ({
|
|
149
182
|
data?: unknown;
|
|
150
183
|
} & {
|
|
151
184
|
start: number;
|
|
152
185
|
end: number;
|
|
153
|
-
type:
|
|
186
|
+
type: RichTextNodeType;
|
|
154
187
|
})[], unknown>;
|
|
155
188
|
}>]>;
|
|
156
189
|
}>, t.PartialC<{
|
|
@@ -159,7 +192,7 @@ export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
159
192
|
}>]>>;
|
|
160
193
|
export declare type TextBlock = t.TypeOf<typeof TextBlock>;
|
|
161
194
|
export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
162
|
-
type: t.LiteralC<
|
|
195
|
+
type: t.LiteralC<RichTextNodeType.image>;
|
|
163
196
|
data: t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
164
197
|
origin: t.ExactC<t.TypeC<{
|
|
165
198
|
id: t.StringC;
|
|
@@ -251,13 +284,13 @@ export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
251
284
|
label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
252
285
|
direction: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
253
286
|
}>]>>, t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
254
|
-
type: t.LiteralC<
|
|
287
|
+
type: t.LiteralC<RichTextNodeType.embed>;
|
|
255
288
|
data: t.Type<import("../EmbedContent").EmbedContentO, unknown, unknown>;
|
|
256
289
|
}>, t.PartialC<{
|
|
257
290
|
label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
258
291
|
direction: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
259
292
|
}>]>>, t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
260
|
-
type: t.Type<
|
|
293
|
+
type: t.Type<RichTextNodeType, RichTextNodeType, unknown>;
|
|
261
294
|
content: t.IntersectionC<[t.TypeC<{
|
|
262
295
|
text: t.StringC;
|
|
263
296
|
}>, t.PartialC<{
|
|
@@ -266,13 +299,13 @@ export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
266
299
|
} & {
|
|
267
300
|
start: number;
|
|
268
301
|
end: number;
|
|
269
|
-
type:
|
|
302
|
+
type: RichTextNodeType;
|
|
270
303
|
})[], ({
|
|
271
304
|
data?: unknown;
|
|
272
305
|
} & {
|
|
273
306
|
start: number;
|
|
274
307
|
end: number;
|
|
275
|
-
type:
|
|
308
|
+
type: RichTextNodeType;
|
|
276
309
|
})[], unknown>;
|
|
277
310
|
}>]>;
|
|
278
311
|
}>, t.PartialC<{
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Block = exports.TextBlock = exports.checkEmbedBlock = exports.EmbedBlock = exports.
|
|
3
|
+
exports.Block = exports.TextBlock = exports.checkEmbedBlock = exports.EmbedBlock = exports.checkImageBlock = exports.ImageBlock = exports.ValidatedMetas = exports.Span = exports.Meta = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const E = (0, tslib_1.__importStar)(require("fp-ts/lib/Either"));
|
|
6
6
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
const nestable_1 = require("../../../../customtypes/widgets/nestable");
|
|
7
8
|
const validators_1 = require("../../../../validators");
|
|
8
9
|
const function_1 = require("../../../../validators/function");
|
|
9
10
|
const EmbedContent_1 = require("../EmbedContent");
|
|
@@ -16,7 +17,7 @@ exports.Meta = t.exact(t.intersection([
|
|
|
16
17
|
t.type({
|
|
17
18
|
start: t.number,
|
|
18
19
|
end: t.number,
|
|
19
|
-
type:
|
|
20
|
+
type: nestable_1.RichTextNodeTypeCodec,
|
|
20
21
|
}),
|
|
21
22
|
]));
|
|
22
23
|
// export alias for code clarity
|
|
@@ -44,10 +45,9 @@ exports.ValidatedMetas = new t.Type("ValidatedMetas", (metas) => Array.isArray(m
|
|
|
44
45
|
else
|
|
45
46
|
return t.failure(metas, c);
|
|
46
47
|
}, (m) => t.array(exports.Meta).encode(m));
|
|
47
|
-
exports.ImageBlockType = "image";
|
|
48
48
|
exports.ImageBlock = t.exact(t.intersection([
|
|
49
49
|
t.type({
|
|
50
|
-
type: t.literal(
|
|
50
|
+
type: t.literal(nestable_1.RichTextNodeType.image),
|
|
51
51
|
data: t.intersection([
|
|
52
52
|
ImageContent_1.ImageContentView,
|
|
53
53
|
t.partial({
|
|
@@ -61,13 +61,12 @@ exports.ImageBlock = t.exact(t.intersection([
|
|
|
61
61
|
}),
|
|
62
62
|
]));
|
|
63
63
|
function checkImageBlock(block) {
|
|
64
|
-
return block.type ===
|
|
64
|
+
return block.type === nestable_1.RichTextNodeType.image;
|
|
65
65
|
}
|
|
66
66
|
exports.checkImageBlock = checkImageBlock;
|
|
67
|
-
exports.EmbedBlockType = "embed";
|
|
68
67
|
exports.EmbedBlock = t.exact(t.intersection([
|
|
69
68
|
t.type({
|
|
70
|
-
type: t.literal(
|
|
69
|
+
type: t.literal(nestable_1.RichTextNodeType.embed),
|
|
71
70
|
data: EmbedContent_1.EmbedContent,
|
|
72
71
|
}),
|
|
73
72
|
t.partial({
|
|
@@ -76,12 +75,12 @@ exports.EmbedBlock = t.exact(t.intersection([
|
|
|
76
75
|
}),
|
|
77
76
|
]));
|
|
78
77
|
function checkEmbedBlock(block) {
|
|
79
|
-
return block.type ===
|
|
78
|
+
return block.type === nestable_1.RichTextNodeType.embed;
|
|
80
79
|
}
|
|
81
80
|
exports.checkEmbedBlock = checkEmbedBlock;
|
|
82
81
|
exports.TextBlock = t.exact(t.intersection([
|
|
83
82
|
t.type({
|
|
84
|
-
type: (0, function_1.refineType)(
|
|
83
|
+
type: (0, function_1.refineType)(nestable_1.RichTextNodeTypeCodec, `string which isn't ${nestable_1.RichTextNodeType.image} ${nestable_1.RichTextNodeType.embed}`, (s) => s !== nestable_1.RichTextNodeType.image && s !== nestable_1.RichTextNodeType.embed),
|
|
85
84
|
content: t.intersection([
|
|
86
85
|
t.type({
|
|
87
86
|
text: t.string,
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { either } from "fp-ts/lib/Either"
|
|
1
|
+
import { either, getOrElseW } from "fp-ts/lib/Either"
|
|
2
2
|
import * as t from "io-ts"
|
|
3
3
|
|
|
4
4
|
import { StringOrNull } from "../../../validators"
|
|
@@ -26,46 +26,24 @@ export enum RichTextNodeType {
|
|
|
26
26
|
rtl = "rtl",
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
case RichTextNodeType.strong:
|
|
48
|
-
return RichTextNodeType.strong
|
|
49
|
-
case RichTextNodeType.em:
|
|
50
|
-
return RichTextNodeType.em
|
|
51
|
-
case RichTextNodeType.preformatted:
|
|
52
|
-
return RichTextNodeType.preformatted
|
|
53
|
-
case RichTextNodeType.hyperlink:
|
|
54
|
-
return RichTextNodeType.hyperlink
|
|
55
|
-
case RichTextNodeType.image:
|
|
56
|
-
return RichTextNodeType.image
|
|
57
|
-
case RichTextNodeType.embed:
|
|
58
|
-
return RichTextNodeType.embed
|
|
59
|
-
case RichTextNodeType.list:
|
|
60
|
-
return RichTextNodeType.list
|
|
61
|
-
case RichTextNodeType.orderedList:
|
|
62
|
-
return RichTextNodeType.orderedList
|
|
63
|
-
case RichTextNodeType.rtl:
|
|
64
|
-
return RichTextNodeType.rtl
|
|
65
|
-
default:
|
|
66
|
-
return
|
|
67
|
-
}
|
|
68
|
-
}
|
|
29
|
+
export const RichTextNodeTypeCodec = t.keyof({
|
|
30
|
+
[RichTextNodeType.heading1]: null,
|
|
31
|
+
[RichTextNodeType.heading2]: null,
|
|
32
|
+
[RichTextNodeType.heading3]: null,
|
|
33
|
+
[RichTextNodeType.heading4]: null,
|
|
34
|
+
[RichTextNodeType.heading5]: null,
|
|
35
|
+
[RichTextNodeType.heading6]: null,
|
|
36
|
+
[RichTextNodeType.paragraph]: null,
|
|
37
|
+
[RichTextNodeType.strong]: null,
|
|
38
|
+
[RichTextNodeType.em]: null,
|
|
39
|
+
[RichTextNodeType.preformatted]: null,
|
|
40
|
+
[RichTextNodeType.hyperlink]: null,
|
|
41
|
+
[RichTextNodeType.image]: null,
|
|
42
|
+
[RichTextNodeType.embed]: null,
|
|
43
|
+
[RichTextNodeType.list]: null,
|
|
44
|
+
[RichTextNodeType.orderedList]: null,
|
|
45
|
+
[RichTextNodeType.rtl]: null,
|
|
46
|
+
})
|
|
69
47
|
|
|
70
48
|
const RichTextOptions = new t.Type<string, string, unknown>(
|
|
71
49
|
"RichTextOptions",
|
|
@@ -76,7 +54,11 @@ const RichTextOptions = new t.Type<string, string, unknown>(
|
|
|
76
54
|
(s: string | null) => {
|
|
77
55
|
if (!s) return t.success(DEFAULT_OPTION)
|
|
78
56
|
const entries = s.split(",").map((e: string) => e.trim())
|
|
79
|
-
const filtered = entries.filter((entry) =>
|
|
57
|
+
const filtered = entries.filter((entry) => {
|
|
58
|
+
return getOrElseW(() => undefined)(
|
|
59
|
+
RichTextNodeTypeCodec.decode(entry),
|
|
60
|
+
)
|
|
61
|
+
})
|
|
80
62
|
if (!filtered.length) return t.success(DEFAULT_OPTION)
|
|
81
63
|
|
|
82
64
|
return t.success(filtered.join(","))
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as E from "fp-ts/lib/Either"
|
|
2
2
|
import * as t from "io-ts"
|
|
3
3
|
|
|
4
|
+
import {
|
|
5
|
+
RichTextNodeType,
|
|
6
|
+
RichTextNodeTypeCodec,
|
|
7
|
+
} from "../../../../customtypes/widgets/nestable"
|
|
4
8
|
import { StringOrNull } from "../../../../validators"
|
|
5
9
|
import { nullable, refineType } from "../../../../validators/function"
|
|
6
10
|
import { EmbedContent } from "../EmbedContent"
|
|
@@ -15,7 +19,7 @@ export const Meta = t.exact(
|
|
|
15
19
|
t.type({
|
|
16
20
|
start: t.number,
|
|
17
21
|
end: t.number,
|
|
18
|
-
type:
|
|
22
|
+
type: RichTextNodeTypeCodec,
|
|
19
23
|
}),
|
|
20
24
|
]),
|
|
21
25
|
)
|
|
@@ -54,12 +58,10 @@ export const ValidatedMetas = new t.Type<Meta[], Meta[], unknown>(
|
|
|
54
58
|
(m) => t.array(Meta).encode(m),
|
|
55
59
|
)
|
|
56
60
|
|
|
57
|
-
export const ImageBlockType = "image"
|
|
58
|
-
|
|
59
61
|
export const ImageBlock = t.exact(
|
|
60
62
|
t.intersection([
|
|
61
63
|
t.type({
|
|
62
|
-
type: t.literal(
|
|
64
|
+
type: t.literal(RichTextNodeType.image),
|
|
63
65
|
data: t.intersection([
|
|
64
66
|
ImageContentView,
|
|
65
67
|
t.partial({
|
|
@@ -75,14 +77,13 @@ export const ImageBlock = t.exact(
|
|
|
75
77
|
)
|
|
76
78
|
export type ImageBlock = t.TypeOf<typeof ImageBlock>
|
|
77
79
|
export function checkImageBlock(block: Block): block is ImageBlock {
|
|
78
|
-
return block.type ===
|
|
80
|
+
return block.type === RichTextNodeType.image
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
export const EmbedBlockType = "embed"
|
|
82
83
|
export const EmbedBlock = t.exact(
|
|
83
84
|
t.intersection([
|
|
84
85
|
t.type({
|
|
85
|
-
type: t.literal(
|
|
86
|
+
type: t.literal(RichTextNodeType.embed),
|
|
86
87
|
data: EmbedContent,
|
|
87
88
|
}),
|
|
88
89
|
t.partial({
|
|
@@ -93,16 +94,16 @@ export const EmbedBlock = t.exact(
|
|
|
93
94
|
)
|
|
94
95
|
export type EmbedBlock = t.TypeOf<typeof EmbedBlock>
|
|
95
96
|
export function checkEmbedBlock(block: Block): block is EmbedBlock {
|
|
96
|
-
return block.type ===
|
|
97
|
+
return block.type === RichTextNodeType.embed
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
export const TextBlock = t.exact(
|
|
100
101
|
t.intersection([
|
|
101
102
|
t.type({
|
|
102
103
|
type: refineType(
|
|
103
|
-
|
|
104
|
-
`string which isn't ${
|
|
105
|
-
(s) => s !==
|
|
104
|
+
RichTextNodeTypeCodec,
|
|
105
|
+
`string which isn't ${RichTextNodeType.image} ${RichTextNodeType.embed}`,
|
|
106
|
+
(s) => s !== RichTextNodeType.image && s !== RichTextNodeType.embed,
|
|
106
107
|
),
|
|
107
108
|
content: t.intersection([
|
|
108
109
|
t.type({
|