@prismicio/types-internal 2.4.0-alpha.0 → 2.4.0-alpha.2
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/content/Document.d.ts +6811 -12595
- package/lib/content/fields/GroupContent.d.ts +345 -1602
- package/lib/content/fields/WidgetContent.d.ts +6556 -12340
- package/lib/content/fields/nestable/ImageContent.d.ts +0 -723
- package/lib/content/fields/nestable/ImageContent.js +0 -2
- package/lib/content/fields/nestable/NestableContent.d.ts +209 -932
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +507 -370
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +73 -6
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +186 -491
- package/lib/content/fields/nestable/RichTextContent/index.js +0 -1
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +531 -1977
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +104 -638
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +531 -1977
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +711 -2157
- package/lib/content/fields/slices/Slice/index.d.ts +1962 -5166
- package/lib/content/fields/slices/SliceItem.d.ts +928 -4132
- package/lib/content/fields/slices/SlicesContent.d.ts +2426 -6764
- package/lib/customtypes/CustomType.d.ts +328 -14
- package/lib/customtypes/Section.d.ts +328 -14
- package/lib/customtypes/diff/SharedSlice.d.ts +656 -4
- package/lib/customtypes/diff/Variation.d.ts +659 -5
- package/lib/customtypes/diff/Variation.js +3 -1
- package/lib/customtypes/widgets/Group.d.ts +0 -2
- package/lib/customtypes/widgets/Widget.d.ts +328 -16
- package/lib/customtypes/widgets/nestable/Image.d.ts +0 -2
- package/lib/customtypes/widgets/nestable/Image.js +0 -1
- package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +0 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +0 -2
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +0 -2
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +648 -4
- package/lib/customtypes/widgets/slices/SharedSlice.js +2 -0
- package/lib/customtypes/widgets/slices/SliceWidget.d.ts +327 -0
- package/lib/customtypes/widgets/slices/SliceWidget.js +8 -0
- package/lib/customtypes/widgets/slices/Slices.d.ts +656 -24
- package/lib/customtypes/widgets/slices/index.d.ts +1 -0
- package/lib/customtypes/widgets/slices/index.js +1 -0
- package/package.json +1 -1
- package/src/content/fields/nestable/ImageContent.ts +0 -2
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +101 -3
- package/src/content/fields/nestable/RichTextContent/index.ts +0 -1
- package/src/customtypes/diff/Variation.ts +10 -6
- package/src/customtypes/widgets/nestable/Image.ts +0 -1
- package/src/customtypes/widgets/slices/SharedSlice.ts +2 -0
- package/src/customtypes/widgets/slices/SliceWidget.ts +9 -0
- package/src/customtypes/widgets/slices/index.ts +1 -0
- package/src/content/fields/nestable/RichTextContent/TextBlock.ts +0 -118
|
@@ -1,17 +1,64 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Block = exports.BlockLegacy = exports.checkEmbedBlock = exports.EmbedBlock = exports.checkImageBlock = exports.ImageBlock = void 0;
|
|
3
|
+
exports.Block = exports.BlockLegacy = exports.TextBlock = exports.checkEmbedBlock = exports.EmbedBlock = exports.checkImageBlock = exports.ImageBlock = exports.ValidatedSpans = exports.SpanLegacy = exports.Span = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
6
7
|
const function_1 = require("fp-ts/lib/function");
|
|
7
8
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
9
|
+
const io_ts_types_1 = require("io-ts-types");
|
|
8
10
|
const nestable_1 = require("../../../../customtypes/widgets/nestable");
|
|
9
11
|
const validators_1 = require("../../../../validators");
|
|
10
12
|
const function_2 = require("../../../../validators/function");
|
|
11
13
|
const EmbedContent_1 = require("../EmbedContent");
|
|
12
14
|
const ImageContent_1 = require("../ImageContent");
|
|
13
15
|
const LinkContent_1 = require("../LinkContent");
|
|
14
|
-
const
|
|
16
|
+
const linkSpan = (linkCodec) => t.strict({
|
|
17
|
+
data: linkCodec,
|
|
18
|
+
start: t.number,
|
|
19
|
+
end: t.number,
|
|
20
|
+
type: t.literal(nestable_1.RichTextNodeType.hyperlink),
|
|
21
|
+
});
|
|
22
|
+
const labelSpan = t.strict({
|
|
23
|
+
data: (0, io_ts_types_1.withFallback)(t.string, ""),
|
|
24
|
+
start: t.number,
|
|
25
|
+
end: t.number,
|
|
26
|
+
type: t.literal("label"),
|
|
27
|
+
});
|
|
28
|
+
const basicSpan = t.strict({
|
|
29
|
+
start: t.number,
|
|
30
|
+
end: t.number,
|
|
31
|
+
type: t.keyof({
|
|
32
|
+
[nestable_1.RichTextNodeType.strong]: null,
|
|
33
|
+
[nestable_1.RichTextNodeType.em]: null,
|
|
34
|
+
"list-item": null, // legacy case that should not happen, we shouldn't support this in new page builder or migration API
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
exports.Span = t.union([linkSpan(LinkContent_1.Link), labelSpan, basicSpan]);
|
|
38
|
+
exports.SpanLegacy = t.union([linkSpan(LinkContent_1.LinkLegacy), labelSpan, basicSpan]);
|
|
39
|
+
const ValidatedSpans = (spanCodec) => {
|
|
40
|
+
return new t.Type("ValidatedSpans", (spans) => Array.isArray(spans) && spans.every(spanCodec.is), (spans, c) => {
|
|
41
|
+
if (Array.isArray(spans)) {
|
|
42
|
+
const res = spans
|
|
43
|
+
.reduce((acc, maybeSpan) => {
|
|
44
|
+
const decodedSpan = spanCodec.decode(maybeSpan);
|
|
45
|
+
if ((0, Either_1.isLeft)(decodedSpan))
|
|
46
|
+
return acc;
|
|
47
|
+
return [...acc, decodedSpan.right];
|
|
48
|
+
}, [])
|
|
49
|
+
.sort((m1, m2) => m1.start - m2.start);
|
|
50
|
+
return t.success(res);
|
|
51
|
+
}
|
|
52
|
+
else
|
|
53
|
+
return t.failure(spans, c);
|
|
54
|
+
}, (m) => {
|
|
55
|
+
return m.reduce((acc, meta) => {
|
|
56
|
+
const encoded = spanCodec.encode(meta);
|
|
57
|
+
return [...acc, encoded];
|
|
58
|
+
}, []);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
exports.ValidatedSpans = ValidatedSpans;
|
|
15
62
|
const ImageBlockCodec = (linkCodec) => t.exact(t.intersection([
|
|
16
63
|
t.type({
|
|
17
64
|
type: t.literal(nestable_1.RichTextNodeType.image),
|
|
@@ -76,19 +123,39 @@ function checkEmbedBlock(block) {
|
|
|
76
123
|
return block.type === nestable_1.RichTextNodeType.embed;
|
|
77
124
|
}
|
|
78
125
|
exports.checkEmbedBlock = checkEmbedBlock;
|
|
126
|
+
const TextBlockCodec = (spanCodec) => t.exact(t.intersection([
|
|
127
|
+
t.type({
|
|
128
|
+
type: (0, function_2.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),
|
|
129
|
+
content: t.intersection([
|
|
130
|
+
t.type({
|
|
131
|
+
text: t.string,
|
|
132
|
+
}),
|
|
133
|
+
t.partial({
|
|
134
|
+
spans: (0, exports.ValidatedSpans)(spanCodec),
|
|
135
|
+
}),
|
|
136
|
+
]),
|
|
137
|
+
}),
|
|
138
|
+
t.partial({
|
|
139
|
+
label: t.string,
|
|
140
|
+
direction: t.string,
|
|
141
|
+
}),
|
|
142
|
+
]));
|
|
143
|
+
/* These Text block will decode codec A and encode from codec B to A */
|
|
144
|
+
exports.TextBlock = TextBlockCodec(exports.Span);
|
|
145
|
+
const TextBlockLegacy = TextBlockCodec(exports.SpanLegacy);
|
|
79
146
|
const legacyBlockCodec = t.union([
|
|
80
147
|
EmbedBlockLegacy,
|
|
81
148
|
ImageBlockLegacy,
|
|
82
|
-
|
|
149
|
+
TextBlockLegacy,
|
|
83
150
|
]);
|
|
84
|
-
exports.BlockLegacy = new t.Type("BlockLegacy", (u) => EmbedBlockLegacy.is(u) || ImageBlockLegacy.is(u) ||
|
|
151
|
+
exports.BlockLegacy = new t.Type("BlockLegacy", (u) => EmbedBlockLegacy.is(u) || ImageBlockLegacy.is(u) || TextBlockLegacy.is(u), (legacyBlock) => legacyBlockCodec.decode(legacyBlock), (block) => {
|
|
85
152
|
return (() => {
|
|
86
153
|
if (exports.ImageBlock.is(block))
|
|
87
154
|
return ImageBlockLegacy.encode(block);
|
|
88
155
|
else if (exports.EmbedBlock.is(block))
|
|
89
156
|
return EmbedBlockLegacy.encode(block);
|
|
90
157
|
else
|
|
91
|
-
return
|
|
158
|
+
return TextBlockLegacy.encode(block);
|
|
92
159
|
})();
|
|
93
160
|
});
|
|
94
|
-
exports.Block = t.union([exports.ImageBlock, exports.EmbedBlock,
|
|
161
|
+
exports.Block = t.union([exports.ImageBlock, exports.EmbedBlock, exports.TextBlock]);
|