@prismicio/types-internal 3.4.0-alpha.2 → 3.4.0-alpha.4

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 (55) hide show
  1. package/lib/content/Document.d.ts +3305 -3323
  2. package/lib/content/fields/RepeatableContent.d.ts +51 -123
  3. package/lib/content/fields/RepeatableContent.js +10 -14
  4. package/lib/content/fields/WidgetContent.d.ts +3046 -3064
  5. package/lib/content/fields/nestable/NestableContent.d.ts +501 -504
  6. package/lib/content/fields/nestable/NestableContent.js +0 -7
  7. package/lib/content/fields/nestable/RichTextContent/Block.d.ts +1036 -0
  8. package/lib/content/fields/nestable/RichTextContent/Block.js +31 -0
  9. package/lib/content/fields/nestable/RichTextContent/EmbedBlock.d.ts +60 -0
  10. package/lib/content/fields/nestable/RichTextContent/EmbedBlock.js +53 -0
  11. package/lib/content/fields/nestable/RichTextContent/ImageBlock.d.ts +203 -0
  12. package/lib/content/fields/nestable/RichTextContent/ImageBlock.js +36 -0
  13. package/lib/content/fields/nestable/RichTextContent/TableBlock.d.ts +500 -0
  14. package/lib/content/fields/nestable/RichTextContent/TableBlock.js +21 -0
  15. package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +590 -0
  16. package/lib/content/fields/nestable/RichTextContent/TextBlock.js +80 -0
  17. package/lib/content/fields/nestable/RichTextContent/index.d.ts +637 -9
  18. package/lib/content/fields/nestable/RichTextContent/index.js +4 -4
  19. package/lib/content/fields/nestable/TableContent.d.ts +245 -12
  20. package/lib/content/fields/nestable/TableContent.js +7 -7
  21. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +1013 -1019
  22. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +234 -235
  23. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +1013 -1019
  24. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +501 -504
  25. package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +499 -502
  26. package/lib/content/fields/slices/Slice/index.d.ts +1852 -1862
  27. package/lib/content/fields/slices/SliceItem.d.ts +1957 -1967
  28. package/lib/content/fields/slices/SlicesContent.d.ts +2619 -2634
  29. package/lib/customtypes/CustomType.d.ts +0 -108
  30. package/lib/customtypes/Section.d.ts +0 -108
  31. package/lib/customtypes/diff/SharedSlice.d.ts +0 -48
  32. package/lib/customtypes/diff/Variation.d.ts +0 -48
  33. package/lib/customtypes/widgets/Group.d.ts +0 -36
  34. package/lib/customtypes/widgets/Widget.d.ts +0 -126
  35. package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +0 -6
  36. package/lib/customtypes/widgets/nestable/NestableWidget.js +0 -2
  37. package/lib/customtypes/widgets/nestable/RichText.d.ts +2 -0
  38. package/lib/customtypes/widgets/nestable/RichText.js +2 -0
  39. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +0 -12
  40. package/lib/customtypes/widgets/slices/LegacySlice.d.ts +0 -12
  41. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +0 -48
  42. package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +0 -36
  43. package/lib/customtypes/widgets/slices/Slices.d.ts +0 -168
  44. package/package.json +1 -1
  45. package/src/content/fields/nestable/NestableContent.ts +0 -12
  46. package/src/content/fields/nestable/RichTextContent/Block.ts +35 -0
  47. package/src/content/fields/nestable/RichTextContent/EmbedBlock.ts +81 -0
  48. package/src/content/fields/nestable/RichTextContent/ImageBlock.ts +42 -0
  49. package/src/content/fields/nestable/RichTextContent/TableBlock.ts +36 -0
  50. package/src/content/fields/nestable/RichTextContent/TextBlock.ts +108 -0
  51. package/src/content/fields/nestable/RichTextContent/index.ts +2 -2
  52. package/src/content/fields/nestable/TableContent.ts +6 -6
  53. package/src/customtypes/widgets/nestable/NestableWidget.ts +0 -2
  54. package/src/customtypes/widgets/nestable/RichText.ts +2 -0
  55. package/src/content/fields/nestable/RichTextContent/Blocks.ts +0 -238
@@ -0,0 +1,108 @@
1
+ import { isLeft } from "fp-ts/lib/Either"
2
+ import * as t from "io-ts"
3
+ import { withFallback } from "io-ts-types"
4
+
5
+ import {
6
+ RichTextNodeType,
7
+ RichTextNodeTypeCodec,
8
+ } from "../../../../customtypes/widgets/nestable"
9
+ import { refineType } from "../../../../validators/function"
10
+ import { FilledLink, FilledLinkLegacy } from "../LinkContent"
11
+
12
+ const linkSpan = (linkCodec: typeof FilledLink | typeof FilledLinkLegacy) =>
13
+ t.strict({
14
+ data: linkCodec,
15
+ start: t.number,
16
+ end: t.number,
17
+ type: t.literal(RichTextNodeType.hyperlink),
18
+ })
19
+
20
+ const labelSpan = t.strict({
21
+ data: withFallback(t.string, ""),
22
+ start: t.number,
23
+ end: t.number,
24
+ type: t.literal("label"),
25
+ })
26
+
27
+ const basicSpan = t.strict({
28
+ start: t.number,
29
+ end: t.number,
30
+ type: t.keyof({
31
+ [RichTextNodeType.strong]: null,
32
+ [RichTextNodeType.em]: null,
33
+ "list-item": null, // legacy case that should not happen, we shouldn't support this in new page builder or migration API
34
+ }),
35
+ })
36
+
37
+ export const Span = t.union([linkSpan(FilledLink), labelSpan, basicSpan])
38
+ export type Span = t.TypeOf<typeof Span>
39
+
40
+ export const SpanLegacy = t.union([
41
+ linkSpan(FilledLinkLegacy),
42
+ labelSpan,
43
+ basicSpan,
44
+ ])
45
+ export type SpanLegacy = t.TypeOf<typeof SpanLegacy>
46
+
47
+ export const ValidatedSpans = <C extends typeof Span | typeof SpanLegacy>(
48
+ spanCodec: C,
49
+ ) => {
50
+ type S = t.TypeOf<C>
51
+
52
+ return new t.Type<S[], S[], unknown>(
53
+ "ValidatedSpans",
54
+ (spans): spans is S[] => Array.isArray(spans) && spans.every(spanCodec.is),
55
+ (spans: unknown, c) => {
56
+ if (Array.isArray(spans)) {
57
+ const res = spans
58
+ .reduce<Array<S>>((acc, maybeSpan) => {
59
+ const decodedSpan = spanCodec.decode(maybeSpan)
60
+ if (isLeft(decodedSpan)) return acc
61
+ return [...acc, decodedSpan.right]
62
+ }, [])
63
+ .sort((m1: S, m2: S) => m1.start - m2.start)
64
+ return t.success(res)
65
+ } else return t.failure(spans, c)
66
+ },
67
+ (m) => {
68
+ return m.reduce<Array<S>>((acc, meta) => {
69
+ const encoded = spanCodec.encode(meta) as S
70
+ return [...acc, encoded]
71
+ }, [])
72
+ },
73
+ )
74
+ }
75
+
76
+ const TextBlockCodec = <C extends typeof Span | typeof SpanLegacy>(
77
+ spanCodec: C,
78
+ ) =>
79
+ t.exact(
80
+ t.intersection([
81
+ t.type({
82
+ type: refineType(
83
+ RichTextNodeTypeCodec,
84
+ `string which isn't ${RichTextNodeType.image} ${RichTextNodeType.embed}`,
85
+ (s) => s !== RichTextNodeType.image && s !== RichTextNodeType.embed,
86
+ ),
87
+ content: t.intersection([
88
+ t.type({
89
+ text: t.string,
90
+ }),
91
+ t.partial({
92
+ spans: ValidatedSpans(spanCodec),
93
+ }),
94
+ ]),
95
+ }),
96
+ t.partial({
97
+ label: t.string,
98
+ direction: t.string,
99
+ }),
100
+ ]),
101
+ )
102
+
103
+ /* These Text block will decode codec A and encode from codec B to A */
104
+ export const TextBlock = TextBlockCodec(Span)
105
+ export type TextBlock = t.TypeOf<typeof TextBlock>
106
+
107
+ export const TextBlockLegacy = TextBlockCodec(SpanLegacy)
108
+ export type TextBlockLegacy = t.TypeOf<typeof TextBlockLegacy>
@@ -4,7 +4,7 @@ import * as t from "io-ts"
4
4
 
5
5
  import type { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx"
6
6
  import { hasContentType } from "../../../utils"
7
- import { Block, BlockLegacy } from "./Blocks"
7
+ import { Block, BlockLegacy } from "./Block"
8
8
 
9
9
  export const RichTextContentType = "StructuredTextContent"
10
10
  export const isRichTextContent = (u: unknown): u is RichTextContent =>
@@ -19,7 +19,7 @@ export const RichTextContent = t.strict({
19
19
  })
20
20
  export type RichTextContent = t.TypeOf<typeof RichTextContent>
21
21
 
22
- export * from "./Blocks"
22
+ export * from "./Block"
23
23
 
24
24
  export const RichTextLegacy = (ctx: LegacyContentCtx) =>
25
25
  new t.Type<RichTextContent, WithTypes<RichTextLegacy>, unknown>(
@@ -4,7 +4,7 @@ import * as t from "io-ts"
4
4
 
5
5
  import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
6
6
  import { hasContentType } from "../../utils"
7
- import { TextBlock } from "./RichTextContent"
7
+ import { TextBlock } from "./RichTextContent/TextBlock"
8
8
 
9
9
  export const TableContentType = "TableContent"
10
10
 
@@ -30,11 +30,11 @@ export const TableRow = t.strict({
30
30
  content: t.array(t.union([TableHeaderCell, TableDataCell])),
31
31
  })
32
32
 
33
- const legacyReader = t.strict({
33
+ export const tableContentLegacyCodec = t.strict({
34
34
  content: t.array(TableRow),
35
35
  })
36
36
 
37
- type TableLegacy = t.TypeOf<typeof legacyReader>
37
+ export type TableLegacy = t.TypeOf<typeof tableContentLegacyCodec>
38
38
 
39
39
  export const TableLegacy = (ctx: LegacyContentCtx) =>
40
40
  new t.Type<TableContent, WithTypes<TableLegacy>, unknown>(
@@ -42,7 +42,7 @@ export const TableLegacy = (ctx: LegacyContentCtx) =>
42
42
  isTableContent,
43
43
  (u) => {
44
44
  return pipe(
45
- legacyReader.decode(u),
45
+ tableContentLegacyCodec.decode(u),
46
46
  either.map((t) =>
47
47
  TableContent.encode({ ...t, __TYPE__: TableContentType }),
48
48
  ),
@@ -51,14 +51,14 @@ export const TableLegacy = (ctx: LegacyContentCtx) =>
51
51
 
52
52
  (t: TableContent) => {
53
53
  return {
54
- content: legacyReader.encode(t),
54
+ content: tableContentLegacyCodec.encode(t),
55
55
  types: { [ctx.keyOfType]: "Table" },
56
56
  }
57
57
  },
58
58
  )
59
59
 
60
60
  export const TableContent = t.intersection([
61
- legacyReader,
61
+ tableContentLegacyCodec,
62
62
  t.strict({
63
63
  __TYPE__: t.literal(TableContentType),
64
64
  }),
@@ -13,7 +13,6 @@ import { Range } from "./Range"
13
13
  import { RichText } from "./RichText"
14
14
  import { Select } from "./Select"
15
15
  import { Separator } from "./Separator"
16
- import { Table } from "./Table"
17
16
  import { Text } from "./Text"
18
17
  import { Timestamp } from "./Timestamp"
19
18
 
@@ -28,7 +27,6 @@ export const NestableWidget = t.union([
28
27
  RichText,
29
28
  Select,
30
29
  Separator,
31
- Table,
32
30
  Text,
33
31
  Timestamp,
34
32
  Link,
@@ -29,6 +29,7 @@ export const RichTextNodeType = {
29
29
  list: "list-item",
30
30
  orderedList: "o-list-item",
31
31
  rtl: "rtl",
32
+ table: "table",
32
33
  } as const
33
34
 
34
35
  export const RichTextNodeTypeCodec = t.keyof({
@@ -48,6 +49,7 @@ export const RichTextNodeTypeCodec = t.keyof({
48
49
  [RichTextNodeType.list]: null,
49
50
  [RichTextNodeType.orderedList]: null,
50
51
  [RichTextNodeType.rtl]: null,
52
+ [RichTextNodeType.table]: null,
51
53
  })
52
54
 
53
55
  const RichTextOptions = new t.Type<string, string, unknown>(
@@ -1,238 +0,0 @@
1
- import { either } from "fp-ts"
2
- import { isLeft } from "fp-ts/lib/Either"
3
- import { pipe } from "fp-ts/lib/function"
4
- import * as t from "io-ts"
5
- import { withFallback } from "io-ts-types"
6
-
7
- import {
8
- RichTextNodeType,
9
- RichTextNodeTypeCodec,
10
- } from "../../../../customtypes/widgets/nestable"
11
- import { StringOrNull } from "../../../../validators"
12
- import { nullable, refineType } from "../../../../validators/function"
13
- import {
14
- EmbedContent,
15
- EmbedContentLegacy,
16
- EmbedContentType,
17
- EmbedLegacy,
18
- } from "../EmbedContent"
19
- import { ImageContentView } from "../ImageContent"
20
- import { FilledLink, FilledLinkLegacy } from "../LinkContent"
21
-
22
- const linkSpan = (linkCodec: typeof FilledLink | typeof FilledLinkLegacy) =>
23
- t.strict({
24
- data: linkCodec,
25
- start: t.number,
26
- end: t.number,
27
- type: t.literal(RichTextNodeType.hyperlink),
28
- })
29
-
30
- const labelSpan = t.strict({
31
- data: withFallback(t.string, ""),
32
- start: t.number,
33
- end: t.number,
34
- type: t.literal("label"),
35
- })
36
-
37
- const basicSpan = t.strict({
38
- start: t.number,
39
- end: t.number,
40
- type: t.keyof({
41
- [RichTextNodeType.strong]: null,
42
- [RichTextNodeType.em]: null,
43
- "list-item": null, // legacy case that should not happen, we shouldn't support this in new page builder or migration API
44
- }),
45
- })
46
-
47
- export const Span = t.union([linkSpan(FilledLink), labelSpan, basicSpan])
48
- export type Span = t.TypeOf<typeof Span>
49
-
50
- export const SpanLegacy = t.union([
51
- linkSpan(FilledLinkLegacy),
52
- labelSpan,
53
- basicSpan,
54
- ])
55
- export type SpanLegacy = t.TypeOf<typeof SpanLegacy>
56
-
57
- export const ValidatedSpans = <C extends typeof Span | typeof SpanLegacy>(
58
- spanCodec: C,
59
- ) => {
60
- type S = t.TypeOf<C>
61
-
62
- return new t.Type<S[], S[], unknown>(
63
- "ValidatedSpans",
64
- (spans): spans is S[] => Array.isArray(spans) && spans.every(spanCodec.is),
65
- (spans: unknown, c) => {
66
- if (Array.isArray(spans)) {
67
- const res = spans
68
- .reduce<Array<S>>((acc, maybeSpan) => {
69
- const decodedSpan = spanCodec.decode(maybeSpan)
70
- if (isLeft(decodedSpan)) return acc
71
- return [...acc, decodedSpan.right]
72
- }, [])
73
- .sort((m1: S, m2: S) => m1.start - m2.start)
74
- return t.success(res)
75
- } else return t.failure(spans, c)
76
- },
77
- (m) => {
78
- return m.reduce<Array<S>>((acc, meta) => {
79
- const encoded = <S>spanCodec.encode(meta)
80
- return [...acc, encoded]
81
- }, [])
82
- },
83
- )
84
- }
85
-
86
- // We allow any codec here and let TypeScript infer the resulting codec.
87
- // Typing it more precisely creates conflicts.
88
- //
89
- // Using `t.Mixed` rather than `t.Type<A, O>` causes `data.linkTo` to be
90
- // typed as `any`. It seems to be an issue with the `nullable` helper.
91
- const ImageBlockCodec = <A, O>(linkCodec: t.Type<A, O>) =>
92
- t.exact(
93
- t.intersection([
94
- t.type({
95
- type: t.literal(RichTextNodeType.image),
96
- data: t.intersection([
97
- ImageContentView,
98
- t.partial({
99
- linkTo: nullable(linkCodec),
100
- }),
101
- ]),
102
- }),
103
- t.partial({
104
- label: StringOrNull,
105
- direction: StringOrNull,
106
- }),
107
- ]),
108
- )
109
-
110
- export const ImageBlock = ImageBlockCodec(FilledLink)
111
- export type ImageBlock = t.TypeOf<typeof ImageBlock>
112
-
113
- const ImageBlockLegacy = ImageBlockCodec(FilledLinkLegacy)
114
- type ImageBlockLegacy = t.TypeOf<typeof ImageBlockLegacy>
115
-
116
- export function checkImageBlock(block: Block): block is ImageBlock {
117
- return block.type === RichTextNodeType.image
118
- }
119
-
120
- const embedBlockLegacyCodec = t.exact(
121
- t.intersection([
122
- t.type({
123
- type: t.literal(RichTextNodeType.embed),
124
- data: t.unknown,
125
- }),
126
- t.partial({
127
- label: StringOrNull,
128
- direction: StringOrNull,
129
- }),
130
- ]),
131
- )
132
-
133
- type EmbedBlockLegacy = t.TypeOf<typeof embedBlockLegacyCodec>
134
-
135
- const EmbedBlockLegacy = new t.Type<EmbedBlock, EmbedBlockLegacy, unknown>(
136
- "EmbedBlockLegacy",
137
- (u): u is EmbedBlock => (u as EmbedBlock).type === "embed",
138
- (block) =>
139
- pipe(
140
- embedBlockLegacyCodec.decode(block),
141
- either.chain((decodedBlock) => {
142
- return either.map<EmbedLegacy, [EmbedBlockLegacy, EmbedLegacy]>(
143
- (decodedData: EmbedLegacy) => {
144
- return [decodedBlock, decodedData]
145
- },
146
- )(EmbedContentLegacy.decode(decodedBlock.data))
147
- }),
148
- either.map(([block, parsedData]) => {
149
- return EmbedBlock.encode({
150
- ...block,
151
- data: {
152
- ...parsedData,
153
- __TYPE__: EmbedContentType,
154
- all: block.data,
155
- },
156
- })
157
- }),
158
- ),
159
- (embedBlock: EmbedBlock): EmbedBlockLegacy => {
160
- return {
161
- ...embedBlockLegacyCodec.encode(embedBlock),
162
- data: EmbedContentLegacy.encode(embedBlock.data),
163
- }
164
- },
165
- )
166
- export const EmbedBlock = t.exact(
167
- t.intersection([
168
- t.type({
169
- type: t.literal(RichTextNodeType.embed),
170
- data: EmbedContent,
171
- }),
172
- t.partial({
173
- label: StringOrNull,
174
- direction: StringOrNull,
175
- }),
176
- ]),
177
- )
178
- export type EmbedBlock = t.TypeOf<typeof EmbedBlock>
179
- export function checkEmbedBlock(block: Block): block is EmbedBlock {
180
- return block.type === RichTextNodeType.embed
181
- }
182
-
183
- const TextBlockCodec = <C extends typeof Span | typeof SpanLegacy>(
184
- spanCodec: C,
185
- ) =>
186
- t.exact(
187
- t.intersection([
188
- t.type({
189
- type: refineType(
190
- RichTextNodeTypeCodec,
191
- `string which isn't ${RichTextNodeType.image} ${RichTextNodeType.embed}`,
192
- (s) => s !== RichTextNodeType.image && s !== RichTextNodeType.embed,
193
- ),
194
- content: t.intersection([
195
- t.type({
196
- text: t.string,
197
- }),
198
- t.partial({
199
- spans: ValidatedSpans(spanCodec),
200
- }),
201
- ]),
202
- }),
203
- t.partial({
204
- label: t.string,
205
- direction: t.string,
206
- }),
207
- ]),
208
- )
209
-
210
- /* These Text block will decode codec A and encode from codec B to A */
211
- export const TextBlock = TextBlockCodec(Span)
212
- export type TextBlock = t.TypeOf<typeof TextBlock>
213
-
214
- const TextBlockLegacy = TextBlockCodec(SpanLegacy)
215
- type TextBlockLegacy = t.TypeOf<typeof TextBlockLegacy>
216
-
217
- const legacyBlockCodec = t.union([
218
- EmbedBlockLegacy,
219
- ImageBlockLegacy,
220
- TextBlockLegacy,
221
- ])
222
- type BlockLegacy = t.TypeOf<typeof legacyBlockCodec>
223
-
224
- export const BlockLegacy = new t.Type<Block, BlockLegacy, unknown>(
225
- "BlockLegacy",
226
- (u): u is Block =>
227
- EmbedBlockLegacy.is(u) || ImageBlockLegacy.is(u) || TextBlockLegacy.is(u),
228
- (legacyBlock) => legacyBlockCodec.decode(legacyBlock),
229
- (block: Block) => {
230
- return (() => {
231
- if (ImageBlock.is(block)) return ImageBlockLegacy.encode(block)
232
- else if (EmbedBlock.is(block)) return EmbedBlockLegacy.encode(block)
233
- else return TextBlockLegacy.encode(block)
234
- })() as BlockLegacy
235
- },
236
- )
237
- export const Block = t.union([ImageBlock, EmbedBlock, TextBlock])
238
- export type Block = t.TypeOf<typeof Block>