@prismicio/types-internal 2.9.0-alpha.0 → 2.9.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 +19 -19
- package/lib/content/Document.js +11 -0
- package/lib/content/LegacyContentCtx.d.ts +2 -17
- package/lib/content/LegacyContentCtx.js +4 -1
- package/lib/content/fields/GroupContent.js +13 -0
- package/lib/content/fields/RepeatableContent.d.ts +4 -78
- package/lib/content/fields/RepeatableContent.js +10 -14
- package/lib/content/fields/WidgetContent.d.ts +18 -18
- package/lib/content/fields/index.d.ts +1 -0
- package/lib/content/fields/index.js +1 -0
- package/lib/content/fields/nestable/NestableContent.d.ts +6 -6
- package/lib/content/fields/nestable/NestableContent.js +5 -17
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +727 -0
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +80 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +6 -6
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +1 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +6 -6
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +20 -4
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +5 -5
- package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +5 -5
- package/lib/content/fields/slices/Slice/index.d.ts +10 -10
- package/lib/content/fields/slices/SliceItem.d.ts +10 -10
- package/lib/content/fields/slices/SlicesContent.d.ts +15 -15
- package/lib/customtypes/widgets/Widget.d.ts +0 -15
- package/lib/customtypes/widgets/Widget.js +0 -15
- package/lib/customtypes/widgets/nestable/Link.d.ts +8 -0
- package/lib/customtypes/widgets/nestable/Link.js +6 -5
- package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +1 -2
- package/lib/customtypes/widgets/nestable/NestableWidget.js +1 -18
- package/lib/customtypes/widgets/slices/SliceWidget.d.ts +327 -0
- package/lib/customtypes/widgets/slices/SliceWidget.js +8 -0
- package/package.json +1 -1
- package/src/content/Document.ts +12 -0
- package/src/content/LegacyContentCtx.ts +4 -1
- package/src/content/fields/GroupContent.ts +13 -0
- package/src/content/fields/RepeatableContent.ts +29 -38
- package/src/content/fields/index.ts +1 -0
- package/src/content/fields/nestable/NestableContent.ts +6 -20
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +18 -0
- package/src/customtypes/widgets/Widget.ts +0 -15
- package/src/customtypes/widgets/nestable/Link.ts +7 -5
- package/src/customtypes/widgets/nestable/NestableWidget.ts +16 -34
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
} from "../LegacyContentCtx"
|
|
21
21
|
import { hasContentType } from "../utils"
|
|
22
22
|
import { isNestableContent, NestableContent, NestableLegacy } from "./nestable"
|
|
23
|
+
import { traverseRepeatableContent } from "./RepeatableContent"
|
|
23
24
|
import { repeatableContentWithDefaultNestableContentValues } from "./withDefaultValues"
|
|
24
25
|
|
|
25
26
|
export const GroupItemContentType = "GroupItemContent" as const
|
|
@@ -235,6 +236,18 @@ export function traverseGroupItemsContent({
|
|
|
235
236
|
model: fieldDef,
|
|
236
237
|
content: fieldContent,
|
|
237
238
|
})(transform)
|
|
239
|
+
} else if (
|
|
240
|
+
(!fieldDef ||
|
|
241
|
+
(fieldDef?.type === "Link" && fieldDef.config?.repeat)) &&
|
|
242
|
+
fieldContent.__TYPE__ === "RepeatableContent"
|
|
243
|
+
) {
|
|
244
|
+
transformedField = traverseRepeatableContent({
|
|
245
|
+
path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]),
|
|
246
|
+
key: fieldKey,
|
|
247
|
+
apiId: fieldKey,
|
|
248
|
+
model: fieldDef,
|
|
249
|
+
content: fieldContent,
|
|
250
|
+
})(transform)
|
|
238
251
|
} else {
|
|
239
252
|
transformedField = transform({
|
|
240
253
|
path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]),
|
|
@@ -7,25 +7,19 @@ import type {
|
|
|
7
7
|
ContentPath,
|
|
8
8
|
TraverseWidgetContentFn,
|
|
9
9
|
} from "../../_internal/utils"
|
|
10
|
-
import {
|
|
11
|
-
type Link,
|
|
12
|
-
NestableFieldTypes,
|
|
13
|
-
NestableWidget,
|
|
14
|
-
} from "../../customtypes"
|
|
10
|
+
import type { Link, NestableWidget } from "../../customtypes"
|
|
15
11
|
import type { LegacyContentCtx, WithTypes } from "../LegacyContentCtx"
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export type RepeatableItemContent = t.TypeOf<typeof RepeatableItemContent>
|
|
12
|
+
import {
|
|
13
|
+
isLinkContent,
|
|
14
|
+
LinkContent,
|
|
15
|
+
LinkContentLegacy,
|
|
16
|
+
LinkContentType,
|
|
17
|
+
} from "./nestable"
|
|
23
18
|
|
|
24
19
|
export const RepeatableContent = t.strict({
|
|
25
|
-
__TYPE__: t.literal(
|
|
26
|
-
type:
|
|
27
|
-
|
|
28
|
-
value: t.array(RepeatableItemContent),
|
|
20
|
+
__TYPE__: t.literal("RepeatableContent"),
|
|
21
|
+
type: t.literal("Link"),
|
|
22
|
+
value: t.array(LinkContent),
|
|
29
23
|
})
|
|
30
24
|
|
|
31
25
|
export type RepeatableContent = t.TypeOf<typeof RepeatableContent>
|
|
@@ -34,40 +28,34 @@ export const isRepeatableContent = RepeatableContent.is
|
|
|
34
28
|
|
|
35
29
|
export const RepeatableLegacy = (
|
|
36
30
|
ctx: LegacyContentCtx,
|
|
37
|
-
fieldType:
|
|
31
|
+
fieldType: "Link",
|
|
38
32
|
): t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown> => {
|
|
39
|
-
const codecDecode = t.array(t.unknown)
|
|
40
|
-
const codecEncode = t.array(RepeatableItemContent)
|
|
41
|
-
|
|
42
33
|
return new t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>(
|
|
43
34
|
"RepeatableLegacy",
|
|
44
35
|
isRepeatableContent,
|
|
45
36
|
(items) => {
|
|
46
37
|
const parsed = pipe(
|
|
47
|
-
|
|
38
|
+
t.array(t.unknown).decode(items),
|
|
48
39
|
either.map((items) => {
|
|
49
|
-
const parsedItems = items.reduce<Array<
|
|
50
|
-
|
|
51
|
-
let result
|
|
40
|
+
const parsedItems = items.reduce<Array<LinkContent>>((acc, item) => {
|
|
41
|
+
let result
|
|
52
42
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
switch (fieldType) {
|
|
44
|
+
case "Link":
|
|
45
|
+
result = LinkContentLegacy(ctx).decode(item)
|
|
46
|
+
break
|
|
47
|
+
}
|
|
58
48
|
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
if (!result) return acc
|
|
50
|
+
if (isLeft(result)) return acc
|
|
61
51
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
[],
|
|
65
|
-
)
|
|
52
|
+
return [...acc, result.right]
|
|
53
|
+
}, [])
|
|
66
54
|
|
|
67
55
|
return {
|
|
68
56
|
value: parsedItems,
|
|
69
57
|
type: fieldType,
|
|
70
|
-
__TYPE__:
|
|
58
|
+
__TYPE__: "RepeatableContent" as const,
|
|
71
59
|
}
|
|
72
60
|
}),
|
|
73
61
|
)
|
|
@@ -75,7 +63,7 @@ export const RepeatableLegacy = (
|
|
|
75
63
|
return parsed
|
|
76
64
|
},
|
|
77
65
|
(r: RepeatableContent) => {
|
|
78
|
-
const res =
|
|
66
|
+
const res = t.array(LinkContent).encode(r.value)
|
|
79
67
|
const encodedItems = res.reduce<Array<WithTypes<unknown>>>(
|
|
80
68
|
(acc, item) => {
|
|
81
69
|
let encoded
|
|
@@ -119,7 +107,7 @@ export function traverseRepeatableContent({
|
|
|
119
107
|
return (
|
|
120
108
|
transform: TraverseWidgetContentFn,
|
|
121
109
|
): RepeatableContent | undefined => {
|
|
122
|
-
const items = content.value.reduce<Array<
|
|
110
|
+
const items = content.value.reduce<Array<LinkContent>>(
|
|
123
111
|
(acc, fieldContent, index) => {
|
|
124
112
|
const itemPath = path.concat([
|
|
125
113
|
{ key: index.toString(), type: "Widget" },
|
|
@@ -136,6 +124,9 @@ export function traverseRepeatableContent({
|
|
|
136
124
|
// Can happen if the transform function returns undefined to filter out a field
|
|
137
125
|
if (!transformedField) return acc
|
|
138
126
|
|
|
127
|
+
// If the transformed field is not a link content, we don't include it
|
|
128
|
+
if (!isLinkContent(transformedField)) return acc
|
|
129
|
+
|
|
139
130
|
return acc.concat(transformedField)
|
|
140
131
|
},
|
|
141
132
|
[],
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { isRight } from "fp-ts/lib/Either"
|
|
2
2
|
import * as t from "io-ts"
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import type { NestableWidget } from "../../../customtypes"
|
|
5
5
|
import type { LegacyContentCtx } from "../../LegacyContentCtx"
|
|
6
6
|
import { EmptyContent, EmptyLegacy, isEmptyContent } from "../EmptyContent"
|
|
7
7
|
import {
|
|
8
8
|
isRepeatableContent,
|
|
9
9
|
RepeatableContent,
|
|
10
|
-
RepeatableContentType,
|
|
11
10
|
RepeatableLegacy,
|
|
12
11
|
} from "../RepeatableContent"
|
|
13
12
|
import {
|
|
@@ -147,13 +146,8 @@ export const NestableLegacy = (ctx: LegacyContentCtx) => {
|
|
|
147
146
|
const nullValue = EmptyLegacy(ctx.fieldType).decode(value)
|
|
148
147
|
if (isRight(nullValue)) return nullValue
|
|
149
148
|
|
|
150
|
-
const fieldTypeSplit = ctx?.fieldType?.split(".")
|
|
151
|
-
const fieldType = fieldTypeSplit?.[1] ?? ctx.fieldType
|
|
152
|
-
|
|
153
|
-
if (!NestableFieldTypes.is(fieldType)) return
|
|
154
|
-
|
|
155
149
|
const codec = (() => {
|
|
156
|
-
switch (fieldType) {
|
|
150
|
+
switch (ctx.fieldType) {
|
|
157
151
|
case "Text":
|
|
158
152
|
return TextLegacy(ctx)
|
|
159
153
|
case "Color":
|
|
@@ -184,6 +178,8 @@ export const NestableLegacy = (ctx: LegacyContentCtx) => {
|
|
|
184
178
|
return LinkContentLegacy(ctx)
|
|
185
179
|
case "Separator":
|
|
186
180
|
return SeparatorLegacy(ctx)
|
|
181
|
+
case "Repeatable.Link":
|
|
182
|
+
return RepeatableLegacy(ctx, "Link")
|
|
187
183
|
default:
|
|
188
184
|
return
|
|
189
185
|
}
|
|
@@ -191,21 +187,9 @@ export const NestableLegacy = (ctx: LegacyContentCtx) => {
|
|
|
191
187
|
|
|
192
188
|
if (!codec) return
|
|
193
189
|
|
|
194
|
-
// We check if the Nestable Content is repeated. If so, we decode each
|
|
195
|
-
// item in the array using the specific codec for the repeated content.
|
|
196
|
-
if (fieldTypeSplit?.[0] === "Repeatable") {
|
|
197
|
-
return RepeatableLegacy(ctx, fieldType).decode(value)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
190
|
return codec.decode(value)
|
|
201
191
|
},
|
|
202
192
|
encode(value: NestableContent) {
|
|
203
|
-
// We check if the Nestable Content is repeated. If so, we decode each
|
|
204
|
-
// item in the array using the specific codec for the repeated content.
|
|
205
|
-
if (value.__TYPE__ === RepeatableContentType) {
|
|
206
|
-
return RepeatableLegacy(ctx, value.type).encode(value)
|
|
207
|
-
}
|
|
208
|
-
|
|
209
193
|
switch (value.__TYPE__) {
|
|
210
194
|
case FieldContentType: {
|
|
211
195
|
if (value.type === "Text") return TextLegacy(ctx).encode(value)
|
|
@@ -234,6 +218,8 @@ export const NestableLegacy = (ctx: LegacyContentCtx) => {
|
|
|
234
218
|
return LinkContentLegacy(ctx).encode(value)
|
|
235
219
|
case SeparatorContentType:
|
|
236
220
|
return SeparatorLegacy(ctx).encode(value)
|
|
221
|
+
case "RepeatableContent":
|
|
222
|
+
return RepeatableLegacy(ctx, value.type).encode(value)
|
|
237
223
|
|
|
238
224
|
default:
|
|
239
225
|
return
|
|
@@ -26,6 +26,10 @@ import {
|
|
|
26
26
|
traverseGroupItemsContent,
|
|
27
27
|
} from "../../GroupContent"
|
|
28
28
|
import { isNestableContent } from "../../nestable"
|
|
29
|
+
import {
|
|
30
|
+
isRepeatableContent,
|
|
31
|
+
traverseRepeatableContent,
|
|
32
|
+
} from "../../RepeatableContent"
|
|
29
33
|
import {
|
|
30
34
|
repeatableContentWithDefaultNestableContentValues,
|
|
31
35
|
withDefaultSlicePrimaryContentValues,
|
|
@@ -215,6 +219,20 @@ export function traverseSharedSliceContent({
|
|
|
215
219
|
content: fieldContent,
|
|
216
220
|
model: fieldDef?.type === GroupFieldType ? fieldDef : undefined,
|
|
217
221
|
})(transformWidget)
|
|
222
|
+
} else if (isRepeatableContent(fieldContent)) {
|
|
223
|
+
return traverseRepeatableContent({
|
|
224
|
+
path: path.concat([
|
|
225
|
+
{ key: "primary", type: "primary" },
|
|
226
|
+
{ key: fieldKey, type: "Widget" },
|
|
227
|
+
]),
|
|
228
|
+
key: fieldKey,
|
|
229
|
+
apiId: fieldKey,
|
|
230
|
+
content: fieldContent,
|
|
231
|
+
model:
|
|
232
|
+
fieldDef?.type === "Link" && fieldDef.config?.repeat
|
|
233
|
+
? fieldDef
|
|
234
|
+
: undefined,
|
|
235
|
+
})(transformWidget)
|
|
218
236
|
} else if (isNestableContent(fieldContent)) {
|
|
219
237
|
return transformWidget({
|
|
220
238
|
path: path.concat([
|
|
@@ -61,21 +61,6 @@ export const FieldType = t.keyof({
|
|
|
61
61
|
[GroupFieldType]: null,
|
|
62
62
|
[SlicesFieldType]: null,
|
|
63
63
|
[LegacySlicesFieldType]: null,
|
|
64
|
-
[`Repeatable.Color`]: null,
|
|
65
|
-
[`Repeatable.Boolean`]: null,
|
|
66
|
-
[`Repeatable.Number`]: null,
|
|
67
|
-
[`Repeatable.Embed`]: null,
|
|
68
|
-
[`Repeatable.GeoPoint`]: null,
|
|
69
|
-
[`Repeatable.Date`]: null,
|
|
70
|
-
[`Repeatable.Range`]: null,
|
|
71
|
-
[`Repeatable.StructuredText`]: null,
|
|
72
|
-
[`Repeatable.Select`]: null,
|
|
73
|
-
[`Repeatable.Separator`]: null,
|
|
74
|
-
[`Repeatable.Text`]: null,
|
|
75
|
-
[`Repeatable.Timestamp`]: null,
|
|
76
|
-
[`Repeatable.Link`]: null,
|
|
77
|
-
[`Repeatable.Image`]: null,
|
|
78
|
-
[`Repeatable.IntegrationFields`]: null,
|
|
79
64
|
})
|
|
80
65
|
|
|
81
66
|
export type FieldType = t.TypeOf<typeof FieldType>
|
|
@@ -79,7 +79,12 @@ export const LinkConfig = t.exact(
|
|
|
79
79
|
tags: MasksArrayString,
|
|
80
80
|
allowTargetBlank: t.boolean,
|
|
81
81
|
allowText: t.boolean,
|
|
82
|
-
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* `repeat` property is used to allow multiple links to be added.
|
|
85
|
+
* `undefined` means that the field is not repeatable (hence repeat = false).
|
|
86
|
+
*/
|
|
87
|
+
repeat: t.boolean,
|
|
83
88
|
}),
|
|
84
89
|
)
|
|
85
90
|
export type LinkConfig = t.TypeOf<typeof LinkConfig>
|
|
@@ -91,10 +96,7 @@ export const Link = t.exact(
|
|
|
91
96
|
}),
|
|
92
97
|
t.partial({
|
|
93
98
|
fieldset: StringOrNull,
|
|
94
|
-
config:
|
|
95
|
-
select: null,
|
|
96
|
-
repeat: false,
|
|
97
|
-
}),
|
|
99
|
+
config: LinkConfig,
|
|
98
100
|
}),
|
|
99
101
|
]),
|
|
100
102
|
)
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import { BooleanField
|
|
4
|
-
import { Color
|
|
5
|
-
import { Date
|
|
6
|
-
import { Embed
|
|
7
|
-
import { GeoPoint
|
|
8
|
-
import { Image
|
|
9
|
-
import { IntegrationField
|
|
10
|
-
import { Link
|
|
11
|
-
import { Number
|
|
12
|
-
import { Range
|
|
13
|
-
import { RichText
|
|
14
|
-
import { Select
|
|
15
|
-
import { Separator
|
|
16
|
-
import { Text
|
|
17
|
-
import { Timestamp
|
|
3
|
+
import { BooleanField } from "./BooleanField"
|
|
4
|
+
import { Color } from "./Color"
|
|
5
|
+
import { Date } from "./Date"
|
|
6
|
+
import { Embed } from "./Embed"
|
|
7
|
+
import { GeoPoint } from "./GeoPoint"
|
|
8
|
+
import { Image } from "./Image"
|
|
9
|
+
import { IntegrationField } from "./IntegrationField"
|
|
10
|
+
import { Link } from "./Link"
|
|
11
|
+
import { Number } from "./Number"
|
|
12
|
+
import { Range } from "./Range"
|
|
13
|
+
import { RichText } from "./RichText"
|
|
14
|
+
import { Select } from "./Select"
|
|
15
|
+
import { Separator } from "./Separator"
|
|
16
|
+
import { Text } from "./Text"
|
|
17
|
+
import { Timestamp } from "./Timestamp"
|
|
18
18
|
|
|
19
19
|
export const NestableWidget = t.union([
|
|
20
20
|
Color,
|
|
@@ -35,22 +35,4 @@ export const NestableWidget = t.union([
|
|
|
35
35
|
])
|
|
36
36
|
|
|
37
37
|
export type NestableWidget = t.TypeOf<typeof NestableWidget>
|
|
38
|
-
|
|
39
|
-
export const NestableFieldTypes = t.union([
|
|
40
|
-
t.literal(ColorFieldType),
|
|
41
|
-
t.literal(BooleanFieldType),
|
|
42
|
-
t.literal(EmbedFieldType),
|
|
43
|
-
t.literal(GeoPointFieldType),
|
|
44
|
-
t.literal(DateFieldType),
|
|
45
|
-
t.literal(NumberFieldType),
|
|
46
|
-
t.literal(RangeFieldType),
|
|
47
|
-
t.literal(RichTextFieldType),
|
|
48
|
-
t.literal(SelectFieldType),
|
|
49
|
-
t.literal(SeparatorFieldType),
|
|
50
|
-
t.literal(TextFieldType),
|
|
51
|
-
t.literal(TimestampFieldType),
|
|
52
|
-
t.literal(LinkFieldType),
|
|
53
|
-
t.literal(ImageFieldType),
|
|
54
|
-
t.literal(IntegrationFieldType),
|
|
55
|
-
])
|
|
56
|
-
export type NestableFieldTypes = t.TypeOf<typeof NestableFieldTypes>
|
|
38
|
+
export type NestableFieldTypes = NestableWidget["type"]
|