@prismicio/types-internal 2.8.0 → 2.9.0-alpha.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/_internal/utils.d.ts +3 -2
- package/lib/content/Document.d.ts +1369 -61
- package/lib/content/LegacyContentCtx.d.ts +15 -0
- package/lib/content/fields/RepeatableContent.d.ts +236 -0
- package/lib/content/fields/RepeatableContent.js +97 -0
- package/lib/content/fields/WidgetContent.d.ts +1369 -61
- package/lib/content/fields/nestable/LinkContent.d.ts +23 -0
- package/lib/content/fields/nestable/LinkContent.js +23 -0
- package/lib/content/fields/nestable/NestableContent.d.ts +220 -2
- package/lib/content/fields/nestable/NestableContent.js +21 -2
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +66 -66
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +438 -2
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +74 -0
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +440 -4
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +220 -2
- package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +221 -3
- package/lib/content/fields/slices/Slice/index.d.ts +735 -5
- package/lib/content/fields/slices/SliceItem.d.ts +734 -4
- package/lib/content/fields/slices/SlicesContent.d.ts +1098 -8
- package/lib/customtypes/CustomType.d.ts +18 -0
- package/lib/customtypes/Section.d.ts +18 -0
- package/lib/customtypes/diff/SharedSlice.d.ts +8 -0
- package/lib/customtypes/diff/Variation.d.ts +8 -0
- package/lib/customtypes/widgets/Group.d.ts +6 -0
- package/lib/customtypes/widgets/Widget.d.ts +36 -0
- package/lib/customtypes/widgets/Widget.js +15 -0
- package/lib/customtypes/widgets/nestable/Link.d.ts +2 -0
- package/lib/customtypes/widgets/nestable/Link.js +5 -1
- package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +3 -1
- package/lib/customtypes/widgets/nestable/NestableWidget.js +18 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +2 -0
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +2 -0
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +8 -0
- package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +6 -0
- package/lib/customtypes/widgets/slices/Slices.d.ts +28 -0
- package/package.json +1 -1
- package/src/_internal/utils.ts +3 -1
- package/src/content/fields/RepeatableContent.ts +156 -0
- package/src/content/fields/nestable/LinkContent.ts +24 -0
- package/src/content/fields/nestable/NestableContent.ts +28 -3
- package/src/customtypes/widgets/Widget.ts +15 -0
- package/src/customtypes/widgets/nestable/Link.ts +5 -1
- package/src/customtypes/widgets/nestable/NestableWidget.ts +34 -16
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { isRight } from "fp-ts/lib/Either"
|
|
2
2
|
import * as t from "io-ts"
|
|
3
3
|
|
|
4
|
-
import type
|
|
4
|
+
import { type NestableWidget, NestableFieldTypes } from "../../../customtypes"
|
|
5
5
|
import type { LegacyContentCtx } from "../../LegacyContentCtx"
|
|
6
6
|
import { EmptyContent, EmptyLegacy, isEmptyContent } from "../EmptyContent"
|
|
7
|
+
import {
|
|
8
|
+
isRepeatableContent,
|
|
9
|
+
RepeatableContent,
|
|
10
|
+
RepeatableContentType,
|
|
11
|
+
RepeatableLegacy,
|
|
12
|
+
} from "../RepeatableContent"
|
|
7
13
|
import {
|
|
8
14
|
BooleanContent,
|
|
9
15
|
BooleanContentDefaultValue,
|
|
@@ -96,6 +102,7 @@ export const NestableContent = t.union([
|
|
|
96
102
|
LinkContent,
|
|
97
103
|
RichTextContent,
|
|
98
104
|
SeparatorContent,
|
|
105
|
+
RepeatableContent,
|
|
99
106
|
])
|
|
100
107
|
export type NestableContent = t.TypeOf<typeof NestableContent>
|
|
101
108
|
export type NestableContentType = NestableContent["__TYPE__"]
|
|
@@ -129,7 +136,8 @@ export const isNestableContent = (u: unknown): u is NestableContent =>
|
|
|
129
136
|
isIntegrationFieldContent(u) ||
|
|
130
137
|
isLinkContent(u) ||
|
|
131
138
|
isSeparatorContent(u) ||
|
|
132
|
-
isEmptyContent(u)
|
|
139
|
+
isEmptyContent(u) ||
|
|
140
|
+
isRepeatableContent(u)
|
|
133
141
|
|
|
134
142
|
export const NestableLegacy = (ctx: LegacyContentCtx) => {
|
|
135
143
|
return {
|
|
@@ -139,8 +147,13 @@ export const NestableLegacy = (ctx: LegacyContentCtx) => {
|
|
|
139
147
|
const nullValue = EmptyLegacy(ctx.fieldType).decode(value)
|
|
140
148
|
if (isRight(nullValue)) return nullValue
|
|
141
149
|
|
|
150
|
+
const fieldTypeSplit = ctx?.fieldType?.split(".")
|
|
151
|
+
const fieldType = fieldTypeSplit?.[1] ?? ctx.fieldType
|
|
152
|
+
|
|
153
|
+
if (!NestableFieldTypes.is(fieldType)) return
|
|
154
|
+
|
|
142
155
|
const codec = (() => {
|
|
143
|
-
switch (
|
|
156
|
+
switch (fieldType) {
|
|
144
157
|
case "Text":
|
|
145
158
|
return TextLegacy(ctx)
|
|
146
159
|
case "Color":
|
|
@@ -178,9 +191,21 @@ export const NestableLegacy = (ctx: LegacyContentCtx) => {
|
|
|
178
191
|
|
|
179
192
|
if (!codec) return
|
|
180
193
|
|
|
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
|
+
|
|
181
200
|
return codec.decode(value)
|
|
182
201
|
},
|
|
183
202
|
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
|
+
|
|
184
209
|
switch (value.__TYPE__) {
|
|
185
210
|
case FieldContentType: {
|
|
186
211
|
if (value.type === "Text") return TextLegacy(ctx).encode(value)
|
|
@@ -61,6 +61,21 @@ 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,
|
|
64
79
|
})
|
|
65
80
|
|
|
66
81
|
export type FieldType = t.TypeOf<typeof FieldType>
|
|
@@ -79,6 +79,7 @@ export const LinkConfig = t.exact(
|
|
|
79
79
|
tags: MasksArrayString,
|
|
80
80
|
allowTargetBlank: t.boolean,
|
|
81
81
|
allowText: t.boolean,
|
|
82
|
+
repeat: withFallback(t.boolean, false),
|
|
82
83
|
}),
|
|
83
84
|
)
|
|
84
85
|
export type LinkConfig = t.TypeOf<typeof LinkConfig>
|
|
@@ -90,7 +91,10 @@ export const Link = t.exact(
|
|
|
90
91
|
}),
|
|
91
92
|
t.partial({
|
|
92
93
|
fieldset: StringOrNull,
|
|
93
|
-
config: LinkConfig,
|
|
94
|
+
config: withFallback(LinkConfig, {
|
|
95
|
+
select: null,
|
|
96
|
+
repeat: false,
|
|
97
|
+
}),
|
|
94
98
|
}),
|
|
95
99
|
]),
|
|
96
100
|
)
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
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"
|
|
3
|
+
import { BooleanField, BooleanFieldType } from "./BooleanField"
|
|
4
|
+
import { Color, ColorFieldType } from "./Color"
|
|
5
|
+
import { Date, DateFieldType } from "./Date"
|
|
6
|
+
import { Embed, EmbedFieldType } from "./Embed"
|
|
7
|
+
import { GeoPoint, GeoPointFieldType } from "./GeoPoint"
|
|
8
|
+
import { Image, ImageFieldType } from "./Image"
|
|
9
|
+
import { IntegrationField, IntegrationFieldType } from "./IntegrationField"
|
|
10
|
+
import { Link, LinkFieldType } from "./Link"
|
|
11
|
+
import { Number, NumberFieldType } from "./Number"
|
|
12
|
+
import { Range, RangeFieldType } from "./Range"
|
|
13
|
+
import { RichText, RichTextFieldType } from "./RichText"
|
|
14
|
+
import { Select, SelectFieldType } from "./Select"
|
|
15
|
+
import { Separator, SeparatorFieldType } from "./Separator"
|
|
16
|
+
import { Text, TextFieldType } from "./Text"
|
|
17
|
+
import { Timestamp, TimestampFieldType } from "./Timestamp"
|
|
18
18
|
|
|
19
19
|
export const NestableWidget = t.union([
|
|
20
20
|
Color,
|
|
@@ -35,4 +35,22 @@ export const NestableWidget = t.union([
|
|
|
35
35
|
])
|
|
36
36
|
|
|
37
37
|
export type NestableWidget = t.TypeOf<typeof NestableWidget>
|
|
38
|
-
|
|
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>
|