@prismicio/types-internal 2.9.0-alpha.3 → 3.0.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 +2 -3
- package/lib/content/Document.d.ts +212 -1520
- package/lib/content/Document.js +0 -11
- package/lib/content/LegacyContentCtx.d.ts +2 -2
- package/lib/content/LegacyContentCtx.js +1 -4
- package/lib/content/fields/GroupContent.js +0 -13
- package/lib/content/fields/WidgetContent.d.ts +186 -1494
- package/lib/content/fields/index.d.ts +0 -1
- package/lib/content/fields/index.js +0 -1
- package/lib/content/fields/nestable/LinkContent.d.ts +32 -32
- package/lib/content/fields/nestable/LinkContent.js +10 -2
- package/lib/content/fields/nestable/NestableContent.d.ts +22 -240
- package/lib/content/fields/nestable/NestableContent.js +1 -8
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +106 -106
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +20 -20
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +46 -482
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +10 -84
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +48 -484
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +4 -20
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +23 -241
- package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +23 -241
- package/lib/content/fields/slices/Slice/index.d.ts +85 -815
- package/lib/content/fields/slices/SliceItem.d.ts +84 -814
- package/lib/content/fields/slices/SlicesContent.d.ts +118 -1208
- package/lib/customtypes/CustomType.d.ts +0 -18
- package/lib/customtypes/Section.d.ts +0 -18
- package/lib/customtypes/diff/SharedSlice.d.ts +0 -8
- package/lib/customtypes/diff/Variation.d.ts +0 -8
- package/lib/customtypes/widgets/Group.d.ts +0 -6
- package/lib/customtypes/widgets/Widget.d.ts +0 -21
- package/lib/customtypes/widgets/nestable/Link.d.ts +0 -10
- package/lib/customtypes/widgets/nestable/Link.js +0 -5
- package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +0 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +0 -2
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +0 -2
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +0 -8
- package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +0 -6
- package/lib/customtypes/widgets/slices/Slices.d.ts +0 -28
- package/package.json +1 -1
- package/src/_internal/utils.ts +1 -3
- package/src/content/Document.ts +0 -12
- package/src/content/LegacyContentCtx.ts +1 -4
- package/src/content/fields/GroupContent.ts +0 -13
- package/src/content/fields/index.ts +0 -1
- package/src/content/fields/nestable/LinkContent.ts +26 -2
- package/src/content/fields/nestable/NestableContent.ts +1 -12
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +0 -18
- package/src/customtypes/widgets/nestable/Link.ts +0 -6
- package/src/content/fields/RepeatableContent.ts +0 -147
|
@@ -1,147 +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
|
-
|
|
6
|
-
import type {
|
|
7
|
-
ContentPath,
|
|
8
|
-
TraverseWidgetContentFn,
|
|
9
|
-
} from "../../_internal/utils"
|
|
10
|
-
import type { Link, NestableWidget } from "../../customtypes"
|
|
11
|
-
import type { LegacyContentCtx, WithTypes } from "../LegacyContentCtx"
|
|
12
|
-
import {
|
|
13
|
-
isLinkContent,
|
|
14
|
-
LinkContent,
|
|
15
|
-
LinkContentLegacy,
|
|
16
|
-
LinkContentType,
|
|
17
|
-
} from "./nestable"
|
|
18
|
-
|
|
19
|
-
export const RepeatableContent = t.strict({
|
|
20
|
-
__TYPE__: t.literal("RepeatableContent"),
|
|
21
|
-
type: t.literal("Link"),
|
|
22
|
-
value: t.array(LinkContent),
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
export type RepeatableContent = t.TypeOf<typeof RepeatableContent>
|
|
26
|
-
|
|
27
|
-
export const isRepeatableContent = RepeatableContent.is
|
|
28
|
-
|
|
29
|
-
export const RepeatableLegacy = (
|
|
30
|
-
ctx: LegacyContentCtx,
|
|
31
|
-
fieldType: "Link",
|
|
32
|
-
): t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown> => {
|
|
33
|
-
return new t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>(
|
|
34
|
-
"RepeatableLegacy",
|
|
35
|
-
isRepeatableContent,
|
|
36
|
-
(items) => {
|
|
37
|
-
const parsed = pipe(
|
|
38
|
-
t.array(t.unknown).decode(items),
|
|
39
|
-
either.map((items) => {
|
|
40
|
-
const parsedItems = items.reduce<Array<LinkContent>>((acc, item) => {
|
|
41
|
-
let result
|
|
42
|
-
|
|
43
|
-
switch (fieldType) {
|
|
44
|
-
case "Link":
|
|
45
|
-
result = LinkContentLegacy(ctx).decode(item)
|
|
46
|
-
break
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!result) return acc
|
|
50
|
-
if (isLeft(result)) return acc
|
|
51
|
-
|
|
52
|
-
return [...acc, result.right]
|
|
53
|
-
}, [])
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
value: parsedItems,
|
|
57
|
-
type: fieldType,
|
|
58
|
-
__TYPE__: "RepeatableContent" as const,
|
|
59
|
-
}
|
|
60
|
-
}),
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
return parsed
|
|
64
|
-
},
|
|
65
|
-
(r: RepeatableContent) => {
|
|
66
|
-
const res = t.array(LinkContent).encode(r.value)
|
|
67
|
-
const encodedItems = res.reduce<Array<WithTypes<unknown>>>(
|
|
68
|
-
(acc, item) => {
|
|
69
|
-
let encoded
|
|
70
|
-
|
|
71
|
-
switch (item.__TYPE__) {
|
|
72
|
-
case LinkContentType:
|
|
73
|
-
encoded = LinkContentLegacy(ctx).encode(item)
|
|
74
|
-
break
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (!encoded) return acc
|
|
78
|
-
|
|
79
|
-
return [...acc, encoded]
|
|
80
|
-
},
|
|
81
|
-
[],
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
content: encodedItems.map((encodedItem) => encodedItem.content),
|
|
86
|
-
types: { [ctx.keyOfType]: `Repeatable.${fieldType}` },
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export type RepeatableCustomType = Link
|
|
93
|
-
|
|
94
|
-
export function traverseRepeatableContent({
|
|
95
|
-
path,
|
|
96
|
-
key,
|
|
97
|
-
apiId,
|
|
98
|
-
model,
|
|
99
|
-
content,
|
|
100
|
-
}: {
|
|
101
|
-
path: ContentPath
|
|
102
|
-
key: string
|
|
103
|
-
apiId: string
|
|
104
|
-
content: RepeatableContent
|
|
105
|
-
model?: NestableWidget | undefined
|
|
106
|
-
}) {
|
|
107
|
-
return (
|
|
108
|
-
transform: TraverseWidgetContentFn,
|
|
109
|
-
): RepeatableContent | undefined => {
|
|
110
|
-
const items = content.value.reduce<Array<LinkContent>>(
|
|
111
|
-
(acc, fieldContent, index) => {
|
|
112
|
-
const itemPath = path.concat([
|
|
113
|
-
{ key: index.toString(), type: "Widget" },
|
|
114
|
-
])
|
|
115
|
-
|
|
116
|
-
const transformedField = transform({
|
|
117
|
-
path: itemPath,
|
|
118
|
-
key: key,
|
|
119
|
-
apiId: apiId,
|
|
120
|
-
model: model,
|
|
121
|
-
content: fieldContent,
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
// Can happen if the transform function returns undefined to filter out a field
|
|
125
|
-
if (!transformedField) return acc
|
|
126
|
-
|
|
127
|
-
// If the transformed field is not a link content, we don't include it
|
|
128
|
-
if (!isLinkContent(transformedField)) return acc
|
|
129
|
-
|
|
130
|
-
return acc.concat(transformedField)
|
|
131
|
-
},
|
|
132
|
-
[],
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
return transform({
|
|
136
|
-
path,
|
|
137
|
-
key,
|
|
138
|
-
apiId,
|
|
139
|
-
model,
|
|
140
|
-
content: {
|
|
141
|
-
__TYPE__: content.__TYPE__,
|
|
142
|
-
type: content.type,
|
|
143
|
-
value: items,
|
|
144
|
-
},
|
|
145
|
-
})
|
|
146
|
-
}
|
|
147
|
-
}
|