@prismicio/types-internal 3.4.0-alpha.8 → 3.5.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/content/Document.d.ts +433 -325
- package/lib/content/Document.js +8 -0
- package/lib/content/fields/GroupContent.d.ts +1 -1
- package/lib/content/fields/GroupContent.js +12 -1
- package/lib/content/fields/RepeatableContent.d.ts +123 -51
- package/lib/content/fields/RepeatableContent.js +14 -10
- package/lib/content/fields/WidgetContent.d.ts +432 -324
- package/lib/content/fields/nestable/NestableContent.d.ts +72 -54
- package/lib/content/fields/nestable/NestableContent.js +7 -0
- package/lib/content/fields/nestable/RepeatableContent.d.ts +2 -2
- package/lib/content/fields/nestable/RepeatableContent.js +5 -2
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +112 -0
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +5 -5
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +9 -641
- package/lib/content/fields/nestable/RichTextContent/index.js +4 -8
- package/lib/content/fields/nestable/TableContent.d.ts +536 -618
- package/lib/content/fields/nestable/TableContent.js +101 -15
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +144 -108
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +24 -18
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +144 -108
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +12 -0
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +72 -54
- package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +72 -54
- package/lib/content/fields/slices/Slice/index.d.ts +240 -180
- package/lib/content/fields/slices/SliceItem.d.ts +240 -180
- package/lib/content/fields/slices/SlicesContent.d.ts +360 -270
- package/lib/customtypes/CustomType.d.ts +108 -0
- package/lib/customtypes/Section.d.ts +108 -0
- package/lib/customtypes/diff/SharedSlice.d.ts +48 -0
- package/lib/customtypes/diff/Variation.d.ts +48 -0
- package/lib/customtypes/widgets/Group.d.ts +36 -0
- package/lib/customtypes/widgets/Widget.d.ts +126 -0
- package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +6 -0
- package/lib/customtypes/widgets/nestable/NestableWidget.js +2 -0
- package/lib/customtypes/widgets/nestable/RichText.d.ts +0 -2
- package/lib/customtypes/widgets/nestable/RichText.js +0 -2
- package/lib/customtypes/widgets/nestable/Table.d.ts +6 -0
- package/lib/customtypes/widgets/nestable/Table.js +13 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +12 -0
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +12 -0
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +48 -0
- package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +36 -0
- package/lib/customtypes/widgets/slices/Slices.d.ts +168 -0
- package/package.json +1 -1
- package/src/content/Document.ts +9 -0
- package/src/content/fields/GroupContent.ts +15 -1
- package/src/content/fields/nestable/NestableContent.ts +12 -0
- package/src/content/fields/nestable/RepeatableContent.ts +6 -2
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +238 -0
- package/src/content/fields/nestable/RichTextContent/index.ts +3 -7
- package/src/content/fields/nestable/TableContent.ts +131 -14
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +13 -0
- package/src/customtypes/widgets/nestable/NestableWidget.ts +2 -0
- package/src/customtypes/widgets/nestable/RichText.ts +0 -2
- package/src/customtypes/widgets/nestable/Table.ts +13 -0
- package/lib/content/fields/nestable/RichTextContent/Block.d.ts +0 -1036
- package/lib/content/fields/nestable/RichTextContent/Block.js +0 -31
- package/lib/content/fields/nestable/RichTextContent/EmbedBlock.d.ts +0 -60
- package/lib/content/fields/nestable/RichTextContent/EmbedBlock.js +0 -53
- package/lib/content/fields/nestable/RichTextContent/ImageBlock.d.ts +0 -203
- package/lib/content/fields/nestable/RichTextContent/ImageBlock.js +0 -36
- package/lib/content/fields/nestable/RichTextContent/TableBlock.d.ts +0 -500
- package/lib/content/fields/nestable/RichTextContent/TableBlock.js +0 -21
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +0 -590
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +0 -80
- package/src/content/fields/nestable/RichTextContent/Block.ts +0 -35
- package/src/content/fields/nestable/RichTextContent/EmbedBlock.ts +0 -81
- package/src/content/fields/nestable/RichTextContent/ImageBlock.ts +0 -42
- package/src/content/fields/nestable/RichTextContent/TableBlock.ts +0 -36
- package/src/content/fields/nestable/RichTextContent/TextBlock.ts +0 -108
|
@@ -0,0 +1,238 @@
|
|
|
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
|
+
export const TextBlockLegacy = TextBlockCodec(SpanLegacy)
|
|
215
|
+
export 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>
|
|
@@ -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 "./
|
|
7
|
+
import { Block, BlockLegacy } from "./Blocks"
|
|
8
8
|
|
|
9
9
|
export const RichTextContentType = "StructuredTextContent"
|
|
10
10
|
export const isRichTextContent = (u: unknown): u is RichTextContent =>
|
|
@@ -19,6 +19,8 @@ export const RichTextContent = t.strict({
|
|
|
19
19
|
})
|
|
20
20
|
export type RichTextContent = t.TypeOf<typeof RichTextContent>
|
|
21
21
|
|
|
22
|
+
export * from "./Blocks"
|
|
23
|
+
|
|
22
24
|
export const RichTextLegacy = (ctx: LegacyContentCtx) =>
|
|
23
25
|
new t.Type<RichTextContent, WithTypes<RichTextLegacy>, unknown>(
|
|
24
26
|
"RichTextLegacy",
|
|
@@ -37,9 +39,3 @@ export const RichTextLegacy = (ctx: LegacyContentCtx) =>
|
|
|
37
39
|
}
|
|
38
40
|
},
|
|
39
41
|
)
|
|
40
|
-
|
|
41
|
-
export * from "./Block"
|
|
42
|
-
export * from "./EmbedBlock"
|
|
43
|
-
export * from "./ImageBlock"
|
|
44
|
-
export * from "./TableBlock"
|
|
45
|
-
export * from "./TextBlock"
|
|
@@ -2,16 +2,38 @@ import { either } from "fp-ts"
|
|
|
2
2
|
import { pipe } from "fp-ts/lib/function"
|
|
3
3
|
import * as t from "io-ts"
|
|
4
4
|
|
|
5
|
+
import type {
|
|
6
|
+
ContentPath,
|
|
7
|
+
TraverseWidgetContentFn,
|
|
8
|
+
} from "../../../_internal/utils"
|
|
9
|
+
import { type NestableWidget, TableCell } from "../../../customtypes"
|
|
5
10
|
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
|
|
6
11
|
import { hasContentType } from "../../utils"
|
|
7
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
RichTextContentType,
|
|
14
|
+
TextBlock,
|
|
15
|
+
TextBlockLegacy,
|
|
16
|
+
} from "./RichTextContent"
|
|
8
17
|
|
|
9
18
|
export const TableContentType = "TableContent"
|
|
10
19
|
|
|
11
20
|
export const isTableContent = (u: unknown): u is TableContent =>
|
|
12
21
|
hasContentType(u) && u.__TYPE__ === TableContentType
|
|
13
22
|
|
|
14
|
-
const
|
|
23
|
+
const TableCellLegacy = t.array(TextBlockLegacy)
|
|
24
|
+
type TableCellLegacy = t.TypeOf<typeof TableCellLegacy>
|
|
25
|
+
|
|
26
|
+
export const TableCellContent = t.strict({
|
|
27
|
+
__TYPE__: t.literal(RichTextContentType),
|
|
28
|
+
value: t.array(TextBlock),
|
|
29
|
+
})
|
|
30
|
+
export type TableCellContent = t.TypeOf<typeof TableCellContent>
|
|
31
|
+
|
|
32
|
+
const TableDataCellLegacy = t.strict({
|
|
33
|
+
type: t.literal("tableCell"),
|
|
34
|
+
content: TableCellLegacy,
|
|
35
|
+
})
|
|
36
|
+
type TableDataCellLegacy = t.TypeOf<typeof TableDataCellLegacy>
|
|
15
37
|
|
|
16
38
|
export const TableDataCell = t.strict({
|
|
17
39
|
type: t.literal("tableCell"),
|
|
@@ -25,17 +47,28 @@ export const TableHeaderCell = t.strict({
|
|
|
25
47
|
})
|
|
26
48
|
export type TableHeaderCell = t.TypeOf<typeof TableHeaderCell>
|
|
27
49
|
|
|
50
|
+
const TableHeaderCellLegacy = t.strict({
|
|
51
|
+
type: t.literal("tableHeader"),
|
|
52
|
+
content: TableCellLegacy,
|
|
53
|
+
})
|
|
54
|
+
type TableHeaderCellLegacy = t.TypeOf<typeof TableHeaderCellLegacy>
|
|
55
|
+
|
|
28
56
|
export const TableRow = t.strict({
|
|
29
57
|
type: t.literal("tableRow"),
|
|
30
58
|
content: t.array(t.union([TableHeaderCell, TableDataCell])),
|
|
31
59
|
})
|
|
32
60
|
export type TableRow = t.TypeOf<typeof TableRow>
|
|
33
61
|
|
|
34
|
-
|
|
35
|
-
|
|
62
|
+
const TableRowLegacy = t.strict({
|
|
63
|
+
type: t.literal("tableRow"),
|
|
64
|
+
content: t.array(t.union([TableHeaderCellLegacy, TableDataCellLegacy])),
|
|
36
65
|
})
|
|
66
|
+
type TableRowLegacy = t.TypeOf<typeof TableRowLegacy>
|
|
37
67
|
|
|
38
|
-
|
|
68
|
+
const legacyReader = t.strict({
|
|
69
|
+
content: t.array(TableRowLegacy),
|
|
70
|
+
})
|
|
71
|
+
type TableLegacy = t.TypeOf<typeof legacyReader>
|
|
39
72
|
|
|
40
73
|
export const TableLegacy = (ctx: LegacyContentCtx) =>
|
|
41
74
|
new t.Type<TableContent, WithTypes<TableLegacy>, unknown>(
|
|
@@ -43,25 +76,109 @@ export const TableLegacy = (ctx: LegacyContentCtx) =>
|
|
|
43
76
|
isTableContent,
|
|
44
77
|
(u) => {
|
|
45
78
|
return pipe(
|
|
46
|
-
|
|
79
|
+
legacyReader.decode(u),
|
|
47
80
|
either.map((t) =>
|
|
48
|
-
TableContent.encode({
|
|
81
|
+
TableContent.encode({
|
|
82
|
+
content: t.content.map((row) => {
|
|
83
|
+
return {
|
|
84
|
+
...row,
|
|
85
|
+
content: row.content.map((cell) => {
|
|
86
|
+
return {
|
|
87
|
+
...cell,
|
|
88
|
+
content: {
|
|
89
|
+
__TYPE__: RichTextContentType,
|
|
90
|
+
value: cell.content,
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
}),
|
|
94
|
+
}
|
|
95
|
+
}),
|
|
96
|
+
__TYPE__: TableContentType,
|
|
97
|
+
}),
|
|
49
98
|
),
|
|
50
99
|
)
|
|
51
100
|
},
|
|
52
101
|
|
|
53
102
|
(t: TableContent) => {
|
|
54
103
|
return {
|
|
55
|
-
content:
|
|
104
|
+
content: legacyReader.encode({
|
|
105
|
+
content: t.content.map((row) => {
|
|
106
|
+
return {
|
|
107
|
+
...row,
|
|
108
|
+
content: row.content.map((cell) => {
|
|
109
|
+
return {
|
|
110
|
+
...cell,
|
|
111
|
+
content: cell.content.value,
|
|
112
|
+
}
|
|
113
|
+
}),
|
|
114
|
+
}
|
|
115
|
+
}),
|
|
116
|
+
}),
|
|
56
117
|
types: { [ctx.keyOfType]: "Table" },
|
|
57
118
|
}
|
|
58
119
|
},
|
|
59
120
|
)
|
|
60
121
|
|
|
61
|
-
export const TableContent = t.
|
|
62
|
-
|
|
63
|
-
t.
|
|
64
|
-
|
|
65
|
-
}),
|
|
66
|
-
])
|
|
122
|
+
export const TableContent = t.strict({
|
|
123
|
+
__TYPE__: t.literal(TableContentType),
|
|
124
|
+
content: t.array(TableRow),
|
|
125
|
+
})
|
|
67
126
|
export type TableContent = t.TypeOf<typeof TableContent>
|
|
127
|
+
|
|
128
|
+
export function traverseTableContent({
|
|
129
|
+
path,
|
|
130
|
+
key,
|
|
131
|
+
apiId,
|
|
132
|
+
model,
|
|
133
|
+
content,
|
|
134
|
+
}: {
|
|
135
|
+
path: ContentPath
|
|
136
|
+
key: string
|
|
137
|
+
apiId: string
|
|
138
|
+
content: TableContent
|
|
139
|
+
model?: NestableWidget | undefined
|
|
140
|
+
}) {
|
|
141
|
+
return (transform: TraverseWidgetContentFn): TableContent | undefined => {
|
|
142
|
+
const tableContent = content.content.map((row, rowIndex) => ({
|
|
143
|
+
...row,
|
|
144
|
+
content: row.content.map((cell, cellIndex) => {
|
|
145
|
+
const itemPath = path.concat([
|
|
146
|
+
{
|
|
147
|
+
key: [rowIndex.toString(), cellIndex.toString()].join(","),
|
|
148
|
+
type: "Widget",
|
|
149
|
+
},
|
|
150
|
+
])
|
|
151
|
+
|
|
152
|
+
const cellContent = transform({
|
|
153
|
+
path: itemPath,
|
|
154
|
+
key,
|
|
155
|
+
apiId,
|
|
156
|
+
model: TableCell, // Table cell content config is fixed.
|
|
157
|
+
content: {
|
|
158
|
+
__TYPE__: cell.content.__TYPE__,
|
|
159
|
+
value: cell.content.value,
|
|
160
|
+
},
|
|
161
|
+
}) || {
|
|
162
|
+
__TYPE__: RichTextContentType,
|
|
163
|
+
value: [],
|
|
164
|
+
} // Return an empty table cell if the transform function filters out rich text (returns undefined)
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
...cell,
|
|
168
|
+
content: cellContent,
|
|
169
|
+
}
|
|
170
|
+
}),
|
|
171
|
+
}))
|
|
172
|
+
|
|
173
|
+
return transform({
|
|
174
|
+
path,
|
|
175
|
+
key,
|
|
176
|
+
apiId,
|
|
177
|
+
model,
|
|
178
|
+
content: {
|
|
179
|
+
__TYPE__: content.__TYPE__,
|
|
180
|
+
content: tableContent,
|
|
181
|
+
},
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -28,7 +28,9 @@ import {
|
|
|
28
28
|
import {
|
|
29
29
|
isNestableContent,
|
|
30
30
|
isRepeatableContent,
|
|
31
|
+
isTableContent,
|
|
31
32
|
traverseRepeatableContent,
|
|
33
|
+
traverseTableContent,
|
|
32
34
|
} from "../../nestable"
|
|
33
35
|
import {
|
|
34
36
|
repeatableContentWithDefaultNestableContentValues,
|
|
@@ -230,6 +232,17 @@ export function traverseSharedSliceContent({
|
|
|
230
232
|
content: fieldContent,
|
|
231
233
|
model: fieldDef?.type === "Link" ? fieldDef : undefined,
|
|
232
234
|
})(transformWidget)
|
|
235
|
+
} else if (isTableContent(fieldContent)) {
|
|
236
|
+
return traverseTableContent({
|
|
237
|
+
path: path.concat([
|
|
238
|
+
{ key: "primary", type: "primary" },
|
|
239
|
+
{ key: fieldKey, type: "Widget" },
|
|
240
|
+
]),
|
|
241
|
+
key: fieldKey,
|
|
242
|
+
apiId: fieldKey,
|
|
243
|
+
content: fieldContent,
|
|
244
|
+
model: fieldDef?.type === "Table" ? fieldDef : undefined,
|
|
245
|
+
})(transformWidget)
|
|
233
246
|
} else if (isNestableContent(fieldContent)) {
|
|
234
247
|
return transformWidget({
|
|
235
248
|
path: path.concat([
|
|
@@ -13,6 +13,7 @@ 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"
|
|
16
17
|
import { Text } from "./Text"
|
|
17
18
|
import { Timestamp } from "./Timestamp"
|
|
18
19
|
|
|
@@ -27,6 +28,7 @@ export const NestableWidget = t.union([
|
|
|
27
28
|
RichText,
|
|
28
29
|
Select,
|
|
29
30
|
Separator,
|
|
31
|
+
Table,
|
|
30
32
|
Text,
|
|
31
33
|
Timestamp,
|
|
32
34
|
Link,
|
|
@@ -29,7 +29,6 @@ export const RichTextNodeType = {
|
|
|
29
29
|
list: "list-item",
|
|
30
30
|
orderedList: "o-list-item",
|
|
31
31
|
rtl: "rtl",
|
|
32
|
-
table: "table",
|
|
33
32
|
} as const
|
|
34
33
|
|
|
35
34
|
export const RichTextNodeTypeCodec = t.keyof({
|
|
@@ -49,7 +48,6 @@ export const RichTextNodeTypeCodec = t.keyof({
|
|
|
49
48
|
[RichTextNodeType.list]: null,
|
|
50
49
|
[RichTextNodeType.orderedList]: null,
|
|
51
50
|
[RichTextNodeType.rtl]: null,
|
|
52
|
-
[RichTextNodeType.table]: null,
|
|
53
51
|
})
|
|
54
52
|
|
|
55
53
|
const RichTextOptions = new t.Type<string, string, unknown>(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
3
|
import { StringOrNull } from "../../../validators"
|
|
4
|
+
import { RichTextNodeType } from "./RichText"
|
|
4
5
|
|
|
5
6
|
export const TableFieldType = "Table"
|
|
6
7
|
|
|
@@ -23,3 +24,15 @@ export const Table = t.exact(
|
|
|
23
24
|
]),
|
|
24
25
|
)
|
|
25
26
|
export type Table = t.TypeOf<typeof Table>
|
|
27
|
+
|
|
28
|
+
export const TableCell = {
|
|
29
|
+
type: "StructuredText" as const,
|
|
30
|
+
config: {
|
|
31
|
+
multi: [
|
|
32
|
+
RichTextNodeType.paragraph,
|
|
33
|
+
RichTextNodeType.strong,
|
|
34
|
+
RichTextNodeType.em,
|
|
35
|
+
RichTextNodeType.hyperlink,
|
|
36
|
+
].join(","),
|
|
37
|
+
},
|
|
38
|
+
}
|