@prismicio/types-internal 0.2.10 → 0.3.1-beta.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/CustomType.d.ts +679 -679
- package/lib/customtypes/Section.d.ts +683 -683
- package/lib/customtypes/Section.js +2 -1
- package/lib/customtypes/widgets/Widget.d.ts +675 -675
- package/lib/customtypes/widgets/nestable/RichText.d.ts +18 -1
- package/lib/customtypes/widgets/nestable/RichText.js +22 -41
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +2 -2
- package/lib/customtypes/widgets/slices/CompositeSlice.js +3 -2
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +4 -4
- package/lib/customtypes/widgets/slices/SharedSlice.js +3 -2
- package/lib/customtypes/widgets/slices/Slices.d.ts +714 -714
- package/lib/documents/widgets/index.d.ts +4 -2
- package/lib/documents/widgets/index.js +8 -4
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.d.ts +57 -15
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.js +10 -9
- package/lib/documents/widgets/slices/SlicesContent.d.ts +3 -0
- package/lib/documents/widgets/slices/SlicesContent.js +4 -2
- package/package.json +1 -1
- package/src/customtypes/CustomType.ts +1 -1
- package/src/customtypes/Section.ts +3 -2
- package/src/customtypes/widgets/nestable/RichText.ts +24 -42
- package/src/customtypes/widgets/slices/CompositeSlice.ts +3 -2
- package/src/customtypes/widgets/slices/SharedSlice.ts +3 -2
- package/src/documents/widgets/index.ts +10 -2
- package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +16 -12
- package/src/documents/widgets/slices/SlicesContent.ts +9 -2
- package/lib/customtypes/Format.d.ts +0 -4
- package/lib/customtypes/Format.js +0 -8
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import { SlicesContent } from "./slices";
|
|
2
3
|
import StaticWidgetContent from "./StaticWidgetContent";
|
|
3
4
|
export * from "./EmptyContent";
|
|
4
5
|
export * from "./GroupContent";
|
|
@@ -28,7 +29,8 @@ export declare const WidgetTypes: {
|
|
|
28
29
|
readonly IntegrationFields: "IntegrationFieldsContent";
|
|
29
30
|
readonly Separator: "SeparatorContent";
|
|
30
31
|
};
|
|
31
|
-
export declare
|
|
32
|
+
export declare const WidgetKey: t.Type<string, string, unknown>;
|
|
33
|
+
export declare type WidgetKey = t.TypeOf<typeof WidgetKey>;
|
|
32
34
|
export declare type WidgetContent = SlicesContent | StaticWidgetContent;
|
|
33
35
|
export declare const Widget: {
|
|
34
36
|
fromJson(widgetKey: WidgetKey, widgetValue: unknown, widgetTypes: Map<WidgetKey, string>, widgetPositions: Map<WidgetKey, number>): import("fp-ts/lib/Option").None | import("fp-ts/lib/Option").Some<StaticWidgetContent> | import("fp-ts/lib/Option").Some<SlicesContent>;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Widget = exports.WidgetTypes = exports.StaticWidgetContent = exports.Slices = exports.Nestable = void 0;
|
|
3
|
+
exports.Widget = exports.WidgetKey = exports.WidgetTypes = exports.StaticWidgetContent = exports.Slices = exports.Nestable = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const function_1 = require("../../validators/function");
|
|
5
7
|
const EmptyContent_1 = require("./EmptyContent");
|
|
6
8
|
const GroupContent_1 = require("./GroupContent");
|
|
7
9
|
const nestable_1 = require("./nestable");
|
|
8
|
-
const
|
|
10
|
+
const slices_1 = require("./slices");
|
|
9
11
|
const StaticWidgetContent_1 = (0, tslib_1.__importDefault)(require("./StaticWidgetContent"));
|
|
10
12
|
const UIDContent_1 = require("./UIDContent");
|
|
11
13
|
(0, tslib_1.__exportStar)(require("./EmptyContent"), exports);
|
|
@@ -21,13 +23,15 @@ exports.WidgetTypes = {
|
|
|
21
23
|
Empty: EmptyContent_1.EmptyContentType,
|
|
22
24
|
UID: UIDContent_1.UIDContentType,
|
|
23
25
|
Group: GroupContent_1.GroupContentType,
|
|
24
|
-
slices:
|
|
26
|
+
slices: slices_1.SlicesContentType,
|
|
25
27
|
};
|
|
28
|
+
const widgetKeyRegex = new RegExp("^[^<>]+$");
|
|
29
|
+
exports.WidgetKey = (0, function_1.refineType)(t.string, "WidgetKey", (s) => widgetKeyRegex.test(s));
|
|
26
30
|
exports.Widget = {
|
|
27
31
|
fromJson(widgetKey, widgetValue, widgetTypes, widgetPositions) {
|
|
28
32
|
const fieldType = widgetTypes.get(widgetKey);
|
|
29
33
|
if (fieldType === "Slices") {
|
|
30
|
-
return
|
|
34
|
+
return slices_1.SlicesContent.fromJson(widgetKey, widgetValue, widgetTypes, widgetPositions);
|
|
31
35
|
}
|
|
32
36
|
else {
|
|
33
37
|
return StaticWidgetContent_1.default.fromJson([], widgetKey, widgetValue, widgetTypes, widgetPositions);
|
|
@@ -1,27 +1,70 @@
|
|
|
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
|
}>]>>;
|
|
27
|
+
export declare type Meta = t.TypeOf<typeof Meta>;
|
|
28
|
+
export declare const Span: t.ExactC<t.IntersectionC<[t.PartialC<{
|
|
29
|
+
data: t.UnknownC;
|
|
30
|
+
}>, t.TypeC<{
|
|
31
|
+
start: t.NumberC;
|
|
32
|
+
end: t.NumberC;
|
|
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
|
+
}>;
|
|
51
|
+
}>]>>;
|
|
52
|
+
export declare type Span = Meta;
|
|
9
53
|
export declare const ValidatedMetas: t.Type<({
|
|
10
54
|
data?: unknown;
|
|
11
55
|
} & {
|
|
12
56
|
start: number;
|
|
13
57
|
end: number;
|
|
14
|
-
type:
|
|
58
|
+
type: RichTextNodeType;
|
|
15
59
|
})[], ({
|
|
16
60
|
data?: unknown;
|
|
17
61
|
} & {
|
|
18
62
|
start: number;
|
|
19
63
|
end: number;
|
|
20
|
-
type:
|
|
64
|
+
type: RichTextNodeType;
|
|
21
65
|
})[], unknown>;
|
|
22
|
-
export declare const ImageBlockType = "image";
|
|
23
66
|
export declare const ImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
24
|
-
type: t.LiteralC<
|
|
67
|
+
type: t.LiteralC<RichTextNodeType.image>;
|
|
25
68
|
data: t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
26
69
|
origin: t.ExactC<t.TypeC<{
|
|
27
70
|
id: t.StringC;
|
|
@@ -115,9 +158,8 @@ export declare const ImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
115
158
|
}>]>>;
|
|
116
159
|
export declare type ImageBlock = t.TypeOf<typeof ImageBlock>;
|
|
117
160
|
export declare function checkImageBlock(block: Block): block is ImageBlock;
|
|
118
|
-
export declare const EmbedBlockType = "embed";
|
|
119
161
|
export declare const EmbedBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
120
|
-
type: t.LiteralC<
|
|
162
|
+
type: t.LiteralC<RichTextNodeType.embed>;
|
|
121
163
|
data: t.Type<import("../EmbedContent").EmbedContentO, unknown, unknown>;
|
|
122
164
|
}>, t.PartialC<{
|
|
123
165
|
label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
@@ -126,7 +168,7 @@ export declare const EmbedBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
126
168
|
export declare type EmbedBlock = t.TypeOf<typeof EmbedBlock>;
|
|
127
169
|
export declare function checkEmbedBlock(block: Block): block is EmbedBlock;
|
|
128
170
|
export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
129
|
-
type: t.Type<
|
|
171
|
+
type: t.Type<RichTextNodeType, RichTextNodeType, unknown>;
|
|
130
172
|
content: t.IntersectionC<[t.TypeC<{
|
|
131
173
|
text: t.StringC;
|
|
132
174
|
}>, t.PartialC<{
|
|
@@ -135,13 +177,13 @@ export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
135
177
|
} & {
|
|
136
178
|
start: number;
|
|
137
179
|
end: number;
|
|
138
|
-
type:
|
|
180
|
+
type: RichTextNodeType;
|
|
139
181
|
})[], ({
|
|
140
182
|
data?: unknown;
|
|
141
183
|
} & {
|
|
142
184
|
start: number;
|
|
143
185
|
end: number;
|
|
144
|
-
type:
|
|
186
|
+
type: RichTextNodeType;
|
|
145
187
|
})[], unknown>;
|
|
146
188
|
}>]>;
|
|
147
189
|
}>, t.PartialC<{
|
|
@@ -150,7 +192,7 @@ export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
150
192
|
}>]>>;
|
|
151
193
|
export declare type TextBlock = t.TypeOf<typeof TextBlock>;
|
|
152
194
|
export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
153
|
-
type: t.LiteralC<
|
|
195
|
+
type: t.LiteralC<RichTextNodeType.image>;
|
|
154
196
|
data: t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
155
197
|
origin: t.ExactC<t.TypeC<{
|
|
156
198
|
id: t.StringC;
|
|
@@ -242,13 +284,13 @@ export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
242
284
|
label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
243
285
|
direction: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
244
286
|
}>]>>, t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
245
|
-
type: t.LiteralC<
|
|
287
|
+
type: t.LiteralC<RichTextNodeType.embed>;
|
|
246
288
|
data: t.Type<import("../EmbedContent").EmbedContentO, unknown, unknown>;
|
|
247
289
|
}>, t.PartialC<{
|
|
248
290
|
label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
249
291
|
direction: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
250
292
|
}>]>>, t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
251
|
-
type: t.Type<
|
|
293
|
+
type: t.Type<RichTextNodeType, RichTextNodeType, unknown>;
|
|
252
294
|
content: t.IntersectionC<[t.TypeC<{
|
|
253
295
|
text: t.StringC;
|
|
254
296
|
}>, t.PartialC<{
|
|
@@ -257,13 +299,13 @@ export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
257
299
|
} & {
|
|
258
300
|
start: number;
|
|
259
301
|
end: number;
|
|
260
|
-
type:
|
|
302
|
+
type: RichTextNodeType;
|
|
261
303
|
})[], ({
|
|
262
304
|
data?: unknown;
|
|
263
305
|
} & {
|
|
264
306
|
start: number;
|
|
265
307
|
end: number;
|
|
266
|
-
type:
|
|
308
|
+
type: RichTextNodeType;
|
|
267
309
|
})[], unknown>;
|
|
268
310
|
}>]>;
|
|
269
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,9 +17,11 @@ 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
|
]));
|
|
23
|
+
// export alias for code clarity
|
|
24
|
+
exports.Span = exports.Meta;
|
|
22
25
|
exports.ValidatedMetas = new t.Type("ValidatedMetas", (metas) => Array.isArray(metas) && metas.every(exports.Meta.is), (metas, c) => {
|
|
23
26
|
if (Array.isArray(metas)) {
|
|
24
27
|
const res = metas
|
|
@@ -42,10 +45,9 @@ exports.ValidatedMetas = new t.Type("ValidatedMetas", (metas) => Array.isArray(m
|
|
|
42
45
|
else
|
|
43
46
|
return t.failure(metas, c);
|
|
44
47
|
}, (m) => t.array(exports.Meta).encode(m));
|
|
45
|
-
exports.ImageBlockType = "image";
|
|
46
48
|
exports.ImageBlock = t.exact(t.intersection([
|
|
47
49
|
t.type({
|
|
48
|
-
type: t.literal(
|
|
50
|
+
type: t.literal(nestable_1.RichTextNodeType.image),
|
|
49
51
|
data: t.intersection([
|
|
50
52
|
ImageContent_1.ImageContentView,
|
|
51
53
|
t.partial({
|
|
@@ -59,13 +61,12 @@ exports.ImageBlock = t.exact(t.intersection([
|
|
|
59
61
|
}),
|
|
60
62
|
]));
|
|
61
63
|
function checkImageBlock(block) {
|
|
62
|
-
return block.type ===
|
|
64
|
+
return block.type === nestable_1.RichTextNodeType.image;
|
|
63
65
|
}
|
|
64
66
|
exports.checkImageBlock = checkImageBlock;
|
|
65
|
-
exports.EmbedBlockType = "embed";
|
|
66
67
|
exports.EmbedBlock = t.exact(t.intersection([
|
|
67
68
|
t.type({
|
|
68
|
-
type: t.literal(
|
|
69
|
+
type: t.literal(nestable_1.RichTextNodeType.embed),
|
|
69
70
|
data: EmbedContent_1.EmbedContent,
|
|
70
71
|
}),
|
|
71
72
|
t.partial({
|
|
@@ -74,12 +75,12 @@ exports.EmbedBlock = t.exact(t.intersection([
|
|
|
74
75
|
}),
|
|
75
76
|
]));
|
|
76
77
|
function checkEmbedBlock(block) {
|
|
77
|
-
return block.type ===
|
|
78
|
+
return block.type === nestable_1.RichTextNodeType.embed;
|
|
78
79
|
}
|
|
79
80
|
exports.checkEmbedBlock = checkEmbedBlock;
|
|
80
81
|
exports.TextBlock = t.exact(t.intersection([
|
|
81
82
|
t.type({
|
|
82
|
-
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),
|
|
83
84
|
content: t.intersection([
|
|
84
85
|
t.type({
|
|
85
86
|
text: t.string,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as O from "fp-ts/Option";
|
|
2
|
+
import * as t from "io-ts";
|
|
2
3
|
import { SliceWidgetContent } from "./SliceWidgetContent";
|
|
3
4
|
export declare type SlicesContentItem = {
|
|
4
5
|
key: string;
|
|
@@ -11,6 +12,8 @@ export declare type SlicesContent = {
|
|
|
11
12
|
__TYPE__: typeof SlicesContentType;
|
|
12
13
|
value: SlicesContentItem[];
|
|
13
14
|
};
|
|
15
|
+
export declare const SliceKey: t.Type<string, string, unknown>;
|
|
16
|
+
export declare type SliceKey = t.TypeOf<typeof SliceKey>;
|
|
14
17
|
export declare const SlicesContent: {
|
|
15
18
|
itemsCodec: (value: unknown, codecWidget: (n: string, v: unknown) => O.Option<SliceWidgetContent>) => O.Option<SlicesContentItem>;
|
|
16
19
|
fromJson: (key: string, value: unknown, fieldTypes: Map<string, string>, fieldPositions: Map<string, number>) => O.Option<SlicesContent>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SlicesContent = exports.SlicesContentType = void 0;
|
|
3
|
+
exports.SlicesContent = exports.SliceKey = exports.SlicesContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const A = (0, tslib_1.__importStar)(require("fp-ts/Array"));
|
|
6
6
|
const function_1 = require("fp-ts/function");
|
|
@@ -9,9 +9,11 @@ const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
|
9
9
|
const function_2 = require("../../../validators/function");
|
|
10
10
|
const SliceWidgetContent_1 = require("./SliceWidgetContent");
|
|
11
11
|
exports.SlicesContentType = "SliceContentType";
|
|
12
|
+
const sliceKeyRegex = new RegExp("^[-_\\w]+\\$[-\\w]+$");
|
|
13
|
+
exports.SliceKey = (0, function_2.refineType)(t.string, "SliceKey", (s) => sliceKeyRegex.test(s));
|
|
12
14
|
const codec = t.exact(t.intersection([
|
|
13
15
|
t.type({
|
|
14
|
-
key:
|
|
16
|
+
key: exports.SliceKey,
|
|
15
17
|
value: t.unknown,
|
|
16
18
|
}),
|
|
17
19
|
t.partial({
|
package/package.json
CHANGED
|
@@ -38,7 +38,7 @@ function customTypeReader<T extends StaticSection | DynamicSection>(
|
|
|
38
38
|
id: t.string,
|
|
39
39
|
label: StringOrNull,
|
|
40
40
|
repeatable: withFallback(t.boolean, true),
|
|
41
|
-
json: t.record(t.string, codec),
|
|
41
|
+
json: t.record(t.string, codec), //tab name => tab data
|
|
42
42
|
status: withFallback(t.boolean, true),
|
|
43
43
|
}),
|
|
44
44
|
t.partial({
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { WidgetKey } from "../documents/widgets"
|
|
4
|
+
import type { SharedSlice } from "./widgets/slices"
|
|
4
5
|
import { DynamicWidget, StaticWidget, Widgets } from "./widgets/Widget"
|
|
5
6
|
|
|
6
7
|
export function sectionReader<T extends StaticWidget | DynamicWidget>(
|
|
7
8
|
codec: t.Type<T, unknown>,
|
|
8
9
|
) {
|
|
9
|
-
return t.record(
|
|
10
|
+
return t.record(WidgetKey, codec) // WidgetId -> Widget Data
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export const StaticSection = sectionReader(StaticWidget)
|
|
@@ -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,5 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
+
import { WidgetKey } from "../../../documents/widgets"
|
|
3
4
|
import { StringOrNull } from "../../../validators"
|
|
4
5
|
import NestableWidget from "../nestable/NestableWidget"
|
|
5
6
|
import SlicesTypes from "./SlicesTypes"
|
|
@@ -21,8 +22,8 @@ const CompositeSlice = t.exact(
|
|
|
21
22
|
description: t.string,
|
|
22
23
|
icon: t.string,
|
|
23
24
|
display: t.string,
|
|
24
|
-
"non-repeat": t.record(
|
|
25
|
-
repeat: t.record(
|
|
25
|
+
"non-repeat": t.record(WidgetKey, NestableWidget),
|
|
26
|
+
repeat: t.record(WidgetKey, NestableWidget),
|
|
26
27
|
config: CompositeSliceConfig,
|
|
27
28
|
}),
|
|
28
29
|
]),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
import { withFallback } from "io-ts-types/lib/withFallback"
|
|
3
3
|
|
|
4
|
+
import { WidgetKey } from "../../../documents/widgets"
|
|
4
5
|
import NestableWidget from "../nestable/NestableWidget"
|
|
5
6
|
import SlicesTypes from "./SlicesTypes"
|
|
6
7
|
|
|
@@ -19,8 +20,8 @@ export const Variation = t.exact(
|
|
|
19
20
|
}),
|
|
20
21
|
t.partial({
|
|
21
22
|
display: t.string,
|
|
22
|
-
primary: t.record(
|
|
23
|
-
items: t.record(
|
|
23
|
+
primary: t.record(WidgetKey, NestableWidget),
|
|
24
|
+
items: t.record(WidgetKey, NestableWidget),
|
|
24
25
|
}),
|
|
25
26
|
]),
|
|
26
27
|
)
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { refineType } from "../../validators/function"
|
|
1
4
|
import { EmptyContentType } from "./EmptyContent"
|
|
2
5
|
import { GroupContentType } from "./GroupContent"
|
|
3
6
|
import { NestableTypes } from "./nestable"
|
|
4
|
-
import { SlicesContent, SlicesContentType } from "./slices
|
|
7
|
+
import { SlicesContent, SlicesContentType } from "./slices"
|
|
5
8
|
import StaticWidgetContent from "./StaticWidgetContent"
|
|
6
9
|
import { UIDContentType } from "./UIDContent"
|
|
7
10
|
|
|
@@ -24,7 +27,12 @@ export const WidgetTypes = {
|
|
|
24
27
|
slices: SlicesContentType,
|
|
25
28
|
} as const
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
const widgetKeyRegex = new RegExp("^[^<>]+$")
|
|
31
|
+
export const WidgetKey = refineType(t.string, "WidgetKey", (s: string) =>
|
|
32
|
+
widgetKeyRegex.test(s),
|
|
33
|
+
)
|
|
34
|
+
export type WidgetKey = t.TypeOf<typeof WidgetKey>
|
|
35
|
+
|
|
28
36
|
export type WidgetContent = SlicesContent | StaticWidgetContent
|
|
29
37
|
|
|
30
38
|
export const Widget = {
|
|
@@ -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,12 +19,15 @@ 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
|
)
|
|
26
|
+
export type Meta = t.TypeOf<typeof Meta>
|
|
22
27
|
|
|
23
|
-
|
|
28
|
+
// export alias for code clarity
|
|
29
|
+
export const Span = Meta
|
|
30
|
+
export type Span = Meta
|
|
24
31
|
|
|
25
32
|
export const ValidatedMetas = new t.Type<Meta[], Meta[], unknown>(
|
|
26
33
|
"ValidatedMetas",
|
|
@@ -51,12 +58,10 @@ export const ValidatedMetas = new t.Type<Meta[], Meta[], unknown>(
|
|
|
51
58
|
(m) => t.array(Meta).encode(m),
|
|
52
59
|
)
|
|
53
60
|
|
|
54
|
-
export const ImageBlockType = "image"
|
|
55
|
-
|
|
56
61
|
export const ImageBlock = t.exact(
|
|
57
62
|
t.intersection([
|
|
58
63
|
t.type({
|
|
59
|
-
type: t.literal(
|
|
64
|
+
type: t.literal(RichTextNodeType.image),
|
|
60
65
|
data: t.intersection([
|
|
61
66
|
ImageContentView,
|
|
62
67
|
t.partial({
|
|
@@ -72,14 +77,13 @@ export const ImageBlock = t.exact(
|
|
|
72
77
|
)
|
|
73
78
|
export type ImageBlock = t.TypeOf<typeof ImageBlock>
|
|
74
79
|
export function checkImageBlock(block: Block): block is ImageBlock {
|
|
75
|
-
return block.type ===
|
|
80
|
+
return block.type === RichTextNodeType.image
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
export const EmbedBlockType = "embed"
|
|
79
83
|
export const EmbedBlock = t.exact(
|
|
80
84
|
t.intersection([
|
|
81
85
|
t.type({
|
|
82
|
-
type: t.literal(
|
|
86
|
+
type: t.literal(RichTextNodeType.embed),
|
|
83
87
|
data: EmbedContent,
|
|
84
88
|
}),
|
|
85
89
|
t.partial({
|
|
@@ -90,16 +94,16 @@ export const EmbedBlock = t.exact(
|
|
|
90
94
|
)
|
|
91
95
|
export type EmbedBlock = t.TypeOf<typeof EmbedBlock>
|
|
92
96
|
export function checkEmbedBlock(block: Block): block is EmbedBlock {
|
|
93
|
-
return block.type ===
|
|
97
|
+
return block.type === RichTextNodeType.embed
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
export const TextBlock = t.exact(
|
|
97
101
|
t.intersection([
|
|
98
102
|
t.type({
|
|
99
103
|
type: refineType(
|
|
100
|
-
|
|
101
|
-
`string which isn't ${
|
|
102
|
-
(s) => s !==
|
|
104
|
+
RichTextNodeTypeCodec,
|
|
105
|
+
`string which isn't ${RichTextNodeType.image} ${RichTextNodeType.embed}`,
|
|
106
|
+
(s) => s !== RichTextNodeType.image && s !== RichTextNodeType.embed,
|
|
103
107
|
),
|
|
104
108
|
content: t.intersection([
|
|
105
109
|
t.type({
|
|
@@ -3,7 +3,7 @@ import { pipe } from "fp-ts/function"
|
|
|
3
3
|
import * as O from "fp-ts/Option"
|
|
4
4
|
import * as t from "io-ts"
|
|
5
5
|
|
|
6
|
-
import { nullable } from "../../../validators/function"
|
|
6
|
+
import { nullable, refineType } from "../../../validators/function"
|
|
7
7
|
import { SliceWidgetContent } from "./SliceWidgetContent"
|
|
8
8
|
|
|
9
9
|
export type SlicesContentItem = {
|
|
@@ -18,10 +18,17 @@ export type SlicesContent = {
|
|
|
18
18
|
__TYPE__: typeof SlicesContentType
|
|
19
19
|
value: SlicesContentItem[]
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
const sliceKeyRegex = new RegExp("^[-_\\w]+\\$[-\\w]+$")
|
|
23
|
+
export const SliceKey = refineType(t.string, "SliceKey", (s: string) =>
|
|
24
|
+
sliceKeyRegex.test(s),
|
|
25
|
+
)
|
|
26
|
+
export type SliceKey = t.TypeOf<typeof SliceKey>
|
|
27
|
+
|
|
21
28
|
const codec = t.exact(
|
|
22
29
|
t.intersection([
|
|
23
30
|
t.type({
|
|
24
|
-
key:
|
|
31
|
+
key: SliceKey,
|
|
25
32
|
value: t.unknown,
|
|
26
33
|
}),
|
|
27
34
|
t.partial({
|