@prismicio/types-internal 0.2.9 → 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/GroupContent.js +3 -2
- package/lib/documents/widgets/UIDContent.js +1 -1
- package/lib/documents/widgets/nestable/BooleanContent.js +1 -1
- package/lib/documents/widgets/nestable/IntegrationFieldsContent.js +1 -1
- package/lib/documents/widgets/nestable/Link/LinkContent.js +2 -1
- 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/nestable/StructuredTextContent/index.js +1 -1
- package/lib/documents/widgets/slices/CompositeSliceContent.js +5 -3
- package/lib/documents/widgets/slices/SharedSliceContent.js +3 -2
- package/lib/documents/widgets/slices/SlicesContent.js +2 -1
- package/package.json +1 -1
- package/src/customtypes/widgets/nestable/RichText.ts +24 -42
- package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +16 -12
|
@@ -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(","));
|
|
@@ -14,8 +14,9 @@ exports.GroupContent = Object.freeze({
|
|
|
14
14
|
return jsItems.map((jsItem) => {
|
|
15
15
|
if (typeof jsItem === "object" && jsItem !== null) {
|
|
16
16
|
const sorted = Object.entries(jsItem).sort(([k1], [k2]) => {
|
|
17
|
-
|
|
18
|
-
const
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const p1 = (_a = fieldPositions.get(`${prefixedKey}.${k1}`)) !== null && _a !== void 0 ? _a : 10000;
|
|
19
|
+
const p2 = (_b = fieldPositions.get(`${prefixedKey}.${k2}`)) !== null && _b !== void 0 ? _b : 10000;
|
|
19
20
|
return p1 - p2;
|
|
20
21
|
});
|
|
21
22
|
const w = sorted.map(([k, v]) => {
|
|
@@ -5,6 +5,6 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const Either_1 = require("fp-ts/Either");
|
|
6
6
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
7
|
exports.UIDContentType = "UIDContent";
|
|
8
|
-
exports.UIDContent = new t.Type("UIDContent", (u) => u
|
|
8
|
+
exports.UIDContent = new t.Type("UIDContent", (u) => { var _a; return ((_a = u) === null || _a === void 0 ? void 0 : _a.__TYPE__) === exports.UIDContentType; }, (u, c) => Either_1.Chain.chain(t.string.validate(u, c), (u) => {
|
|
9
9
|
return t.success({ value: u, __TYPE__: "UIDContent" });
|
|
10
10
|
}), (uidContent) => uidContent.value);
|
|
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const Either_1 = require("fp-ts/Either");
|
|
6
6
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
7
|
exports.BooleanContentType = "BooleanContent";
|
|
8
|
-
const BooleanContent = new t.Type("BooleanContent", (u) => u
|
|
8
|
+
const BooleanContent = new t.Type("BooleanContent", (u) => { var _a; return ((_a = u) === null || _a === void 0 ? void 0 : _a.__TYPE__) === exports.BooleanContentType; }, (u, c) => Either_1.Chain.chain(t.boolean.validate(u, c), (u) => {
|
|
9
9
|
return t.success({ value: u, __TYPE__: exports.BooleanContentType });
|
|
10
10
|
}), (booleanContent) => t.boolean.encode(booleanContent.value));
|
|
11
11
|
exports.default = BooleanContent;
|
|
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const Either_1 = require("fp-ts/Either");
|
|
6
6
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
7
|
exports.IntegrationFieldsContentType = "IntegrationFieldsContent";
|
|
8
|
-
const IntegrationFieldsContent = new t.Type("IntegrationFieldsContent", (u) => u
|
|
8
|
+
const IntegrationFieldsContent = new t.Type("IntegrationFieldsContent", (u) => { var _a; return ((_a = u) === null || _a === void 0 ? void 0 : _a.__TYPE__) === exports.IntegrationFieldsContentType; }, (u, c) => Either_1.Chain.chain(t.string.validate(u, c), (u) => {
|
|
9
9
|
return t.success({
|
|
10
10
|
value: u,
|
|
11
11
|
__TYPE__: exports.IntegrationFieldsContentType,
|
|
@@ -7,7 +7,8 @@ const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
|
7
7
|
const index_1 = require("./index");
|
|
8
8
|
exports.LinkContentType = "LinkContent";
|
|
9
9
|
exports.LinkContent = new t.Type("LinkContent", (u) => {
|
|
10
|
-
|
|
10
|
+
var _a;
|
|
11
|
+
return index_1.Link.is((_a = u) === null || _a === void 0 ? void 0 : _a.value);
|
|
11
12
|
}, (u, c) => Either_1.Chain.chain(index_1.Link.validate(u, c), (u) => {
|
|
12
13
|
return t.success({ value: u, __TYPE__: exports.LinkContentType });
|
|
13
14
|
}), (linkContent) => index_1.Link.encode(linkContent.value));
|
|
@@ -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,
|
|
@@ -6,7 +6,7 @@ const Either_1 = require("fp-ts/Either");
|
|
|
6
6
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
7
|
const Block_1 = require("./Block");
|
|
8
8
|
exports.StructuredTextContentType = "StructuredTextContent";
|
|
9
|
-
exports.StructuredTextContent = new t.Type(exports.StructuredTextContentType, (u) => u
|
|
9
|
+
exports.StructuredTextContent = new t.Type(exports.StructuredTextContentType, (u) => { var _a; return ((_a = u) === null || _a === void 0 ? void 0 : _a.__TYPE__) === exports.StructuredTextContentType; }, (u, c) => Either_1.Chain.chain(t.array(Block_1.Block).validate(u, c), (u) => {
|
|
10
10
|
return t.success({ value: u, __TYPE__: exports.StructuredTextContentType });
|
|
11
11
|
}), () => {
|
|
12
12
|
throw new Error("NotImplementedError: Not relevant method");
|
|
@@ -13,17 +13,19 @@ const codec = t.exact(t.partial({
|
|
|
13
13
|
}));
|
|
14
14
|
exports.CompositeSliceContent = {
|
|
15
15
|
fromJson: (prefixes, key, value, fieldTypes, fieldPositions) => {
|
|
16
|
+
var _a;
|
|
16
17
|
const prefixedRepeatKey = Array.of(prefixes, [key, "repeat"])
|
|
17
18
|
.flat()
|
|
18
19
|
.join(".");
|
|
19
20
|
const decodedValue = codec.decode(value);
|
|
20
21
|
if ((0, Either_1.isRight)(decodedValue)) {
|
|
21
22
|
const repeatObj = decodedValue.right.repeat;
|
|
22
|
-
const nonRepeatObj = decodedValue.right["non-repeat"]
|
|
23
|
+
const nonRepeatObj = (_a = decodedValue.right["non-repeat"]) !== null && _a !== void 0 ? _a : {};
|
|
23
24
|
const groupItemsContentsRepeat = index_1.GroupContent.itemsContentsFromJson(prefixedRepeatKey, repeatObj, fieldTypes, fieldPositions);
|
|
24
25
|
const sortedFields = Object.entries(nonRepeatObj).sort(([k1], [k2]) => {
|
|
25
|
-
|
|
26
|
-
const
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const p1 = (_a = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k1}`)) !== null && _a !== void 0 ? _a : 10000;
|
|
28
|
+
const p2 = (_b = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k2}`)) !== null && _b !== void 0 ? _b : 10000;
|
|
27
29
|
return p1 - p2;
|
|
28
30
|
});
|
|
29
31
|
const nonRepeat = sortedFields.reduce((acc, [k, v]) => {
|
|
@@ -26,8 +26,9 @@ exports.SharedSliceContent = {
|
|
|
26
26
|
.join(".");
|
|
27
27
|
const groupItemsContents = index_1.GroupContent.itemsContentsFromJson(prefixedItemsKey, v.items, fieldTypes, fieldPositions);
|
|
28
28
|
const sortedFields = Object.entries(v.primary).sort(([k1], [k2]) => {
|
|
29
|
-
|
|
30
|
-
const
|
|
29
|
+
var _a, _b;
|
|
30
|
+
const p1 = (_a = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k1}`)) !== null && _a !== void 0 ? _a : 10000;
|
|
31
|
+
const p2 = (_b = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k2}`)) !== null && _b !== void 0 ? _b : 10000;
|
|
31
32
|
return p1 - p2;
|
|
32
33
|
});
|
|
33
34
|
const primary = sortedFields.reduce((acc, [k, w]) => {
|
|
@@ -25,10 +25,11 @@ exports.SlicesContent = {
|
|
|
25
25
|
const name = r.key.substring(0, stopIdx > 0 ? stopIdx : undefined);
|
|
26
26
|
const maybeWidget = codecWidget(name, r.value);
|
|
27
27
|
return O.map((widget) => {
|
|
28
|
+
var _a;
|
|
28
29
|
return {
|
|
29
30
|
key: r.key,
|
|
30
31
|
name,
|
|
31
|
-
maybeLabel: r.label
|
|
32
|
+
maybeLabel: (_a = r.label) !== null && _a !== void 0 ? _a : undefined,
|
|
32
33
|
widget: widget,
|
|
33
34
|
};
|
|
34
35
|
})(maybeWidget);
|
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,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({
|