@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.
Files changed (46) hide show
  1. package/lib/content/Document.d.ts +6811 -12595
  2. package/lib/content/fields/GroupContent.d.ts +345 -1602
  3. package/lib/content/fields/WidgetContent.d.ts +6556 -12340
  4. package/lib/content/fields/nestable/ImageContent.d.ts +0 -723
  5. package/lib/content/fields/nestable/ImageContent.js +0 -2
  6. package/lib/content/fields/nestable/NestableContent.d.ts +209 -932
  7. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +507 -370
  8. package/lib/content/fields/nestable/RichTextContent/Blocks.js +73 -6
  9. package/lib/content/fields/nestable/RichTextContent/index.d.ts +186 -491
  10. package/lib/content/fields/nestable/RichTextContent/index.js +0 -1
  11. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +531 -1977
  12. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +104 -638
  13. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +531 -1977
  14. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +711 -2157
  15. package/lib/content/fields/slices/Slice/index.d.ts +1962 -5166
  16. package/lib/content/fields/slices/SliceItem.d.ts +928 -4132
  17. package/lib/content/fields/slices/SlicesContent.d.ts +2426 -6764
  18. package/lib/customtypes/CustomType.d.ts +328 -14
  19. package/lib/customtypes/Section.d.ts +328 -14
  20. package/lib/customtypes/diff/SharedSlice.d.ts +656 -4
  21. package/lib/customtypes/diff/Variation.d.ts +659 -5
  22. package/lib/customtypes/diff/Variation.js +3 -1
  23. package/lib/customtypes/widgets/Group.d.ts +0 -2
  24. package/lib/customtypes/widgets/Widget.d.ts +328 -16
  25. package/lib/customtypes/widgets/nestable/Image.d.ts +0 -2
  26. package/lib/customtypes/widgets/nestable/Image.js +0 -1
  27. package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +0 -1
  28. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +0 -2
  29. package/lib/customtypes/widgets/slices/LegacySlice.d.ts +0 -2
  30. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +648 -4
  31. package/lib/customtypes/widgets/slices/SharedSlice.js +2 -0
  32. package/lib/customtypes/widgets/slices/SliceWidget.d.ts +327 -0
  33. package/lib/customtypes/widgets/slices/SliceWidget.js +8 -0
  34. package/lib/customtypes/widgets/slices/Slices.d.ts +656 -24
  35. package/lib/customtypes/widgets/slices/index.d.ts +1 -0
  36. package/lib/customtypes/widgets/slices/index.js +1 -0
  37. package/package.json +1 -1
  38. package/src/content/fields/nestable/ImageContent.ts +0 -2
  39. package/src/content/fields/nestable/RichTextContent/Blocks.ts +101 -3
  40. package/src/content/fields/nestable/RichTextContent/index.ts +0 -1
  41. package/src/customtypes/diff/Variation.ts +10 -6
  42. package/src/customtypes/widgets/nestable/Image.ts +0 -1
  43. package/src/customtypes/widgets/slices/SharedSlice.ts +2 -0
  44. package/src/customtypes/widgets/slices/SliceWidget.ts +9 -0
  45. package/src/customtypes/widgets/slices/index.ts +1 -0
  46. 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 TextBlock_1 = require("./TextBlock");
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
- TextBlock_1.TextBlockLegacy,
149
+ TextBlockLegacy,
83
150
  ]);
84
- exports.BlockLegacy = new t.Type("BlockLegacy", (u) => EmbedBlockLegacy.is(u) || ImageBlockLegacy.is(u) || TextBlock_1.TextBlockLegacy.is(u), (legacyBlock) => legacyBlockCodec.decode(legacyBlock), (block) => {
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 TextBlock_1.TextBlockLegacy.encode(block);
158
+ return TextBlockLegacy.encode(block);
92
159
  })();
93
160
  });
94
- exports.Block = t.union([exports.ImageBlock, exports.EmbedBlock, TextBlock_1.TextBlock]);
161
+ exports.Block = t.union([exports.ImageBlock, exports.EmbedBlock, exports.TextBlock]);