@prismicio/types-internal 2.2.0-traverse.alpha-1 → 2.2.0-traverse.alpha-3
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 +21 -4
- package/lib/_internal/utils.js +11 -0
- package/lib/content/Document.d.ts +2194 -13
- package/lib/content/Document.js +64 -36
- package/lib/content/fields/GroupContent.d.ts +6 -4
- package/lib/content/fields/GroupContent.js +13 -9
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +9 -6
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +61 -17
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +8 -6
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +26 -18
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +11 -0
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +100 -1
- package/lib/content/fields/slices/SliceItem.d.ts +15 -0
- package/lib/content/fields/slices/SliceItem.js +15 -1
- package/lib/content/fields/slices/SlicesContent.d.ts +4 -3
- package/lib/content/fields/slices/SlicesContent.js +125 -60
- package/lib/customtypes/CustomType.d.ts +8 -1
- package/lib/customtypes/CustomType.js +18 -1
- package/lib/customtypes/Section.d.ts +3 -0
- package/lib/customtypes/diff/SharedSlice.d.ts +6 -0
- package/lib/customtypes/widgets/Widget.d.ts +3 -0
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +5 -0
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +8 -0
- package/lib/customtypes/widgets/slices/SharedSlice.js +3 -0
- package/lib/customtypes/widgets/slices/Slices.d.ts +6 -0
- package/lib/import/converters/fields/nestable/Image.d.ts +3 -1
- package/lib/import/converters/fields/nestable/Image.js +18 -2
- package/lib/import/converters/fields/nestable/Nestable.js +2 -0
- package/lib/import/converters/fields/nestable/RichText.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText.js +55 -0
- package/lib/import/converters/fields/nestable/index.d.ts +1 -0
- package/lib/import/converters/fields/nestable/index.js +1 -0
- package/lib/import/validators/fields/ImportField.d.ts +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +1 -1
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +1 -1
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +1 -1
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +3 -0
- package/lib/import/validators/fields/nestable/Embed.d.ts +3 -0
- package/lib/import/validators/fields/nestable/Embed.js +3 -8
- package/lib/import/validators/fields/nestable/GeoPoint.js +2 -2
- package/lib/import/validators/fields/nestable/Image/default.d.ts +22 -0
- package/lib/import/validators/fields/nestable/Image/default.js +19 -0
- package/lib/import/validators/fields/nestable/Image/index.d.ts +19 -0
- package/lib/import/validators/fields/nestable/Image/index.js +22 -22
- package/lib/import/validators/fields/nestable/Image/merge.d.ts +23 -0
- package/lib/import/validators/fields/nestable/Image/{Decoder.js → merge.js} +18 -14
- package/lib/import/validators/fields/nestable/Image/{Validator.d.ts → validators.d.ts} +4 -2
- package/lib/import/validators/fields/nestable/Image/{Validator.js → validators.js} +7 -3
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +25 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +26 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +11 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +8 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +11 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +70 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +43 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +65 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +20 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +4 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +7 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +17 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +22 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.js +7 -0
- package/lib/import/validators/fields/nestable/Link.d.ts +21 -6
- package/lib/import/validators/fields/nestable/Link.js +8 -8
- package/lib/import/validators/fields/nestable/Nestable.d.ts +8 -1
- package/lib/import/validators/fields/nestable/Nestable.js +5 -1
- package/lib/import/validators/fields/nestable/index.d.ts +2 -1
- package/lib/import/validators/fields/nestable/index.js +4 -1
- package/package.json +1 -1
- package/src/_internal/utils.ts +63 -7
- package/src/content/Document.ts +106 -47
- package/src/content/fields/GroupContent.ts +25 -12
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +91 -22
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +42 -26
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +144 -1
- package/src/content/fields/slices/SliceItem.ts +39 -3
- package/src/content/fields/slices/SlicesContent.ts +172 -67
- package/src/customtypes/CustomType.ts +23 -1
- package/src/customtypes/widgets/slices/CompositeSlice.ts +6 -0
- package/src/customtypes/widgets/slices/SharedSlice.ts +12 -0
- package/src/import/converters/fields/nestable/Image.ts +34 -4
- package/src/import/converters/fields/nestable/Nestable.ts +3 -0
- package/src/import/converters/fields/nestable/RichText.ts +62 -0
- package/src/import/converters/fields/nestable/index.ts +1 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +1 -1
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +1 -1
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +1 -1
- package/src/import/validators/fields/nestable/Embed.ts +4 -17
- package/src/import/validators/fields/nestable/GeoPoint.ts +2 -2
- package/src/import/validators/fields/nestable/Image/default.ts +25 -0
- package/src/import/validators/fields/nestable/Image/index.ts +34 -36
- package/src/import/validators/fields/nestable/Image/{Decoder.ts → merge.ts} +23 -20
- package/src/import/validators/fields/nestable/Image/{Validator.ts → validators.ts} +9 -2
- package/src/import/validators/fields/nestable/ImportRichText/ImportBlock.ts +39 -0
- package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +41 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.ts +44 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.ts +13 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +13 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.ts +56 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/Span.ts +44 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/index.ts +4 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.ts +24 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.ts +8 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.ts +26 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/index.ts +2 -0
- package/src/import/validators/fields/nestable/ImportRichText/index.ts +2 -0
- package/src/import/validators/fields/nestable/Link.ts +18 -13
- package/src/import/validators/fields/nestable/Nestable.ts +6 -1
- package/src/import/validators/fields/nestable/index.ts +2 -1
- package/lib/import/validators/fields/nestable/Image/Decoder.d.ts +0 -26
|
@@ -3,7 +3,10 @@ import { isLeft } from "fp-ts/lib/Either"
|
|
|
3
3
|
import { pipe } from "fp-ts/lib/function"
|
|
4
4
|
import * as t from "io-ts"
|
|
5
5
|
|
|
6
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
ContentPath,
|
|
8
|
+
TraverseWidgetContentFn,
|
|
9
|
+
} from "../../_internal/utils"
|
|
7
10
|
import type { Group, NestableWidget } from "../../customtypes"
|
|
8
11
|
import {
|
|
9
12
|
FieldOrSliceType,
|
|
@@ -12,7 +15,7 @@ import {
|
|
|
12
15
|
WithTypes,
|
|
13
16
|
} from "../LegacyContentCtx"
|
|
14
17
|
import { hasContentType } from "../utils"
|
|
15
|
-
import { NestableContent, NestableLegacy } from "./nestable"
|
|
18
|
+
import { isNestableContent, NestableContent, NestableLegacy } from "./nestable"
|
|
16
19
|
|
|
17
20
|
export const GroupItemContentType = "GroupItemContent" as const
|
|
18
21
|
|
|
@@ -122,24 +125,34 @@ export type GroupContent = t.TypeOf<typeof GroupContent>
|
|
|
122
125
|
|
|
123
126
|
export function traverseGroupContent({
|
|
124
127
|
path,
|
|
128
|
+
key,
|
|
129
|
+
apiId,
|
|
125
130
|
model,
|
|
126
131
|
content,
|
|
127
132
|
}: {
|
|
128
133
|
path: ContentPath
|
|
134
|
+
key: string
|
|
135
|
+
apiId: string
|
|
129
136
|
content: GroupContent
|
|
130
137
|
model?: Group | undefined
|
|
131
138
|
}) {
|
|
132
|
-
return (transform:
|
|
139
|
+
return (transform: TraverseWidgetContentFn): GroupContent | undefined => {
|
|
133
140
|
const groupItems = traverseGroupItemsContent({
|
|
134
141
|
path,
|
|
135
142
|
model: model?.config?.fields,
|
|
136
143
|
content: content.value,
|
|
137
144
|
})(transform)
|
|
138
145
|
|
|
139
|
-
return {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
146
|
+
return transform({
|
|
147
|
+
path,
|
|
148
|
+
key,
|
|
149
|
+
apiId,
|
|
150
|
+
model,
|
|
151
|
+
content: {
|
|
152
|
+
__TYPE__: content.__TYPE__,
|
|
153
|
+
value: groupItems,
|
|
154
|
+
},
|
|
155
|
+
})
|
|
143
156
|
}
|
|
144
157
|
}
|
|
145
158
|
|
|
@@ -152,7 +165,7 @@ export function traverseGroupItemsContent({
|
|
|
152
165
|
content: Array<GroupItemContent>
|
|
153
166
|
model?: Record<string, NestableWidget> | undefined
|
|
154
167
|
}) {
|
|
155
|
-
return (transform:
|
|
168
|
+
return (transform: TraverseWidgetContentFn): Array<GroupItemContent> => {
|
|
156
169
|
return content.map((groupItem, index) => {
|
|
157
170
|
const groupItemPath = path.concat([
|
|
158
171
|
{ key: index.toString(), type: "GroupItem" },
|
|
@@ -163,16 +176,16 @@ export function traverseGroupItemsContent({
|
|
|
163
176
|
const fieldDef = model?.[fieldKey]
|
|
164
177
|
|
|
165
178
|
const transformedField = transform({
|
|
166
|
-
path: groupItemPath.concat([
|
|
167
|
-
{ key: fieldKey, type: fieldContent.__TYPE__ },
|
|
168
|
-
]),
|
|
179
|
+
path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]),
|
|
169
180
|
key: fieldKey,
|
|
170
181
|
apiId: fieldKey,
|
|
171
182
|
model: fieldDef,
|
|
172
183
|
content: fieldContent,
|
|
173
184
|
})
|
|
174
185
|
// Can happen if the transform function returns undefined to filter out a field
|
|
175
|
-
if (!transformedField
|
|
186
|
+
if (!transformedField || !isNestableContent(transformedField))
|
|
187
|
+
return acc
|
|
188
|
+
|
|
176
189
|
return acc.concat([[fieldKey, transformedField]])
|
|
177
190
|
},
|
|
178
191
|
[],
|
|
@@ -5,17 +5,29 @@ import * as t from "io-ts"
|
|
|
5
5
|
|
|
6
6
|
import type {
|
|
7
7
|
ContentPath,
|
|
8
|
-
|
|
8
|
+
TraverseSliceContentFn,
|
|
9
|
+
TraverseWidgetContentFn,
|
|
9
10
|
} from "../../../../_internal/utils"
|
|
10
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
CompositeSliceFields,
|
|
13
|
+
VariationFields,
|
|
14
|
+
} from "../../../../customtypes"
|
|
11
15
|
import {
|
|
12
16
|
getFieldCtx,
|
|
13
17
|
LegacyContentCtx,
|
|
14
18
|
WithTypes,
|
|
15
19
|
} from "../../../LegacyContentCtx"
|
|
16
20
|
import { hasContentType } from "../../../utils"
|
|
17
|
-
import { traverseGroupItemsContent } from "../../GroupContent"
|
|
18
|
-
import {
|
|
21
|
+
import { GroupItemContent, traverseGroupItemsContent } from "../../GroupContent"
|
|
22
|
+
import {
|
|
23
|
+
isNestableContent,
|
|
24
|
+
NestableContent,
|
|
25
|
+
NestableLegacy,
|
|
26
|
+
} from "../../nestable"
|
|
27
|
+
import type {
|
|
28
|
+
CompositeSliceItemContent,
|
|
29
|
+
SharedSliceItemContent,
|
|
30
|
+
} from "../SliceItem"
|
|
19
31
|
import { RepeatableWidgets, RepeatableWidgetsLegacy } from "./RepeatableContent"
|
|
20
32
|
|
|
21
33
|
export const CompositeSliceContentType = "CompositeSliceContent"
|
|
@@ -126,25 +138,34 @@ export type CompositeSliceContent = t.TypeOf<typeof CompositeSliceContent>
|
|
|
126
138
|
|
|
127
139
|
export function traverseCompositeSliceContent({
|
|
128
140
|
path,
|
|
141
|
+
sliceKey,
|
|
129
142
|
sliceName,
|
|
130
143
|
model,
|
|
131
144
|
content,
|
|
132
145
|
}: {
|
|
133
146
|
path: ContentPath
|
|
147
|
+
sliceKey: string
|
|
134
148
|
sliceName: string
|
|
135
|
-
content:
|
|
136
|
-
model?:
|
|
149
|
+
content: CompositeSliceItemContent
|
|
150
|
+
model?: VariationFields | CompositeSliceFields | undefined
|
|
137
151
|
}) {
|
|
138
|
-
return (
|
|
139
|
-
|
|
140
|
-
|
|
152
|
+
return (
|
|
153
|
+
transformWidget: TraverseWidgetContentFn,
|
|
154
|
+
transformSlice: TraverseSliceContentFn,
|
|
155
|
+
): SharedSliceItemContent | CompositeSliceItemContent | undefined => {
|
|
156
|
+
const primary = Object.entries(content.widget.nonRepeat).reduce<
|
|
157
|
+
CompositeSliceContent["nonRepeat"]
|
|
141
158
|
>((acc, [fieldKey, fieldContent]) => {
|
|
142
|
-
const fieldDef =
|
|
159
|
+
const fieldDef = (() => {
|
|
160
|
+
return model?.type === "SharedSlice"
|
|
161
|
+
? model?.fields?.primary?.[fieldKey]
|
|
162
|
+
: model?.fields?.repeat?.[fieldKey]
|
|
163
|
+
})()
|
|
143
164
|
|
|
144
|
-
const transformedField =
|
|
165
|
+
const transformedField = transformWidget({
|
|
145
166
|
path: path.concat([
|
|
146
167
|
{ key: "non-repeat", type: "primary" },
|
|
147
|
-
{ key: fieldKey, type:
|
|
168
|
+
{ key: fieldKey, type: "Widget" },
|
|
148
169
|
]),
|
|
149
170
|
key: fieldKey,
|
|
150
171
|
apiId: sliceName,
|
|
@@ -152,7 +173,7 @@ export function traverseCompositeSliceContent({
|
|
|
152
173
|
content: fieldContent,
|
|
153
174
|
})
|
|
154
175
|
// Can happen if the transform function returns undefined to filter out a field
|
|
155
|
-
if (!transformedField) return acc
|
|
176
|
+
if (!transformedField || !isNestableContent(transformedField)) return acc
|
|
156
177
|
return {
|
|
157
178
|
...acc,
|
|
158
179
|
[fieldKey]: transformedField,
|
|
@@ -161,14 +182,62 @@ export function traverseCompositeSliceContent({
|
|
|
161
182
|
|
|
162
183
|
const items = traverseGroupItemsContent({
|
|
163
184
|
path: path.concat([{ key: "repeat", type: "items" }]),
|
|
164
|
-
model:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
185
|
+
model:
|
|
186
|
+
model?.type === "SharedSlice"
|
|
187
|
+
? model?.fields.items
|
|
188
|
+
: model?.fields.repeat,
|
|
189
|
+
content: content.widget.repeat,
|
|
190
|
+
})(transformWidget)
|
|
191
|
+
|
|
192
|
+
return transformSlice({
|
|
193
|
+
key: sliceKey,
|
|
194
|
+
apiId: sliceName,
|
|
195
|
+
path,
|
|
196
|
+
model,
|
|
197
|
+
content: {
|
|
198
|
+
...content,
|
|
199
|
+
widget: {
|
|
200
|
+
__TYPE__: "CompositeSliceContent",
|
|
201
|
+
repeat: items,
|
|
202
|
+
nonRepeat: primary,
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function migrateCompositeSlice(
|
|
210
|
+
model: VariationFields,
|
|
211
|
+
content: CompositeSliceItemContent,
|
|
212
|
+
): SharedSliceItemContent {
|
|
213
|
+
return {
|
|
214
|
+
key: content.key,
|
|
215
|
+
name: model.sliceName,
|
|
216
|
+
maybeLabel: content.maybeLabel,
|
|
217
|
+
widget: {
|
|
218
|
+
__TYPE__: "SharedSliceContent",
|
|
219
|
+
variation: model.variationId,
|
|
220
|
+
primary: Object.entries(content.widget.nonRepeat).reduce(
|
|
221
|
+
(acc, [fieldKey, fieldContent]) => {
|
|
222
|
+
return model.fields.primary?.[fieldKey]
|
|
223
|
+
? { ...acc, [fieldKey]: fieldContent }
|
|
224
|
+
: acc
|
|
225
|
+
},
|
|
226
|
+
{},
|
|
227
|
+
),
|
|
228
|
+
items: content.widget.repeat.map((groupItem) => {
|
|
229
|
+
return {
|
|
230
|
+
__TYPE__: "GroupItemContent",
|
|
231
|
+
value: groupItem.value.reduce<GroupItemContent["value"]>(
|
|
232
|
+
(acc, [fieldKey, fieldContent]) => {
|
|
233
|
+
return model.fields.items?.[fieldKey]
|
|
234
|
+
? acc.concat([[fieldKey, fieldContent]])
|
|
235
|
+
: acc
|
|
236
|
+
},
|
|
237
|
+
[],
|
|
238
|
+
),
|
|
239
|
+
}
|
|
240
|
+
}, []),
|
|
241
|
+
},
|
|
173
242
|
}
|
|
174
243
|
}
|
|
@@ -6,9 +6,10 @@ import { withFallback } from "io-ts-types"
|
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
8
|
ContentPath,
|
|
9
|
-
|
|
9
|
+
TraverseSliceContentFn,
|
|
10
|
+
TraverseWidgetContentFn,
|
|
10
11
|
} from "../../../../_internal/utils"
|
|
11
|
-
import type {
|
|
12
|
+
import type { VariationFields } from "../../../../customtypes"
|
|
12
13
|
import {
|
|
13
14
|
getFieldCtx,
|
|
14
15
|
LegacyContentCtx,
|
|
@@ -16,7 +17,12 @@ import {
|
|
|
16
17
|
} from "../../../LegacyContentCtx"
|
|
17
18
|
import { hasContentType } from "../../../utils"
|
|
18
19
|
import { traverseGroupItemsContent } from "../../GroupContent"
|
|
19
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
isNestableContent,
|
|
22
|
+
NestableContent,
|
|
23
|
+
NestableLegacy,
|
|
24
|
+
} from "../../nestable"
|
|
25
|
+
import type { SharedSliceItemContent } from "../SliceItem"
|
|
20
26
|
import { RepeatableWidgets, RepeatableWidgetsLegacy } from "./RepeatableContent"
|
|
21
27
|
|
|
22
28
|
export const SharedSliceContentType = "SharedSliceContent"
|
|
@@ -137,29 +143,30 @@ export type SharedSliceContent = t.TypeOf<typeof SharedSliceContent>
|
|
|
137
143
|
|
|
138
144
|
export function traverseSharedSliceContent({
|
|
139
145
|
path,
|
|
146
|
+
sliceKey,
|
|
140
147
|
sliceName,
|
|
141
148
|
model,
|
|
142
149
|
content,
|
|
143
150
|
}: {
|
|
144
151
|
path: ContentPath
|
|
152
|
+
sliceKey: string
|
|
145
153
|
sliceName: string
|
|
146
|
-
content:
|
|
147
|
-
model?:
|
|
154
|
+
content: SharedSliceItemContent
|
|
155
|
+
model?: VariationFields | undefined
|
|
148
156
|
}) {
|
|
149
|
-
return (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
Record<string, NestableContent>
|
|
157
|
+
return (
|
|
158
|
+
transformWidget: TraverseWidgetContentFn,
|
|
159
|
+
transformSlice: TraverseSliceContentFn,
|
|
160
|
+
): SharedSliceItemContent | undefined => {
|
|
161
|
+
const primary = Object.entries(content.widget.primary).reduce<
|
|
162
|
+
SharedSliceContent["primary"]
|
|
156
163
|
>((acc, [fieldKey, fieldContent]) => {
|
|
157
|
-
const fieldDef =
|
|
164
|
+
const fieldDef = model?.fields?.primary?.[fieldKey]
|
|
158
165
|
|
|
159
|
-
const transformedField =
|
|
166
|
+
const transformedField = transformWidget({
|
|
160
167
|
path: path.concat([
|
|
161
168
|
{ key: "primary", type: "primary" },
|
|
162
|
-
{ key: fieldKey, type:
|
|
169
|
+
{ key: fieldKey, type: "Widget" },
|
|
163
170
|
]),
|
|
164
171
|
key: fieldKey,
|
|
165
172
|
apiId: sliceName,
|
|
@@ -167,7 +174,7 @@ export function traverseSharedSliceContent({
|
|
|
167
174
|
content: fieldContent,
|
|
168
175
|
})
|
|
169
176
|
// Can happen if the transform function returns undefined to filter out a field
|
|
170
|
-
if (!transformedField) return acc
|
|
177
|
+
if (!transformedField || !isNestableContent(transformedField)) return acc
|
|
171
178
|
return {
|
|
172
179
|
...acc,
|
|
173
180
|
[fieldKey]: transformedField,
|
|
@@ -176,15 +183,24 @@ export function traverseSharedSliceContent({
|
|
|
176
183
|
|
|
177
184
|
const items = traverseGroupItemsContent({
|
|
178
185
|
path: path.concat([{ key: "items", type: "items" }]),
|
|
179
|
-
model:
|
|
180
|
-
content: content.items,
|
|
181
|
-
})(
|
|
182
|
-
|
|
183
|
-
return {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
model: model?.fields.items,
|
|
187
|
+
content: content.widget.items,
|
|
188
|
+
})(transformWidget)
|
|
189
|
+
|
|
190
|
+
return transformSlice({
|
|
191
|
+
key: sliceKey,
|
|
192
|
+
apiId: sliceName,
|
|
193
|
+
path,
|
|
194
|
+
model: model,
|
|
195
|
+
content: {
|
|
196
|
+
...content,
|
|
197
|
+
widget: {
|
|
198
|
+
__TYPE__: "SharedSliceContent",
|
|
199
|
+
variation: content.widget.variation,
|
|
200
|
+
primary,
|
|
201
|
+
items,
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
})
|
|
189
205
|
}
|
|
190
206
|
}
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
+
import type {
|
|
4
|
+
ContentPath,
|
|
5
|
+
TraverseSliceContentFn,
|
|
6
|
+
TraverseWidgetContentFn,
|
|
7
|
+
} from "../../../../_internal/utils"
|
|
8
|
+
import type {
|
|
9
|
+
Group,
|
|
10
|
+
NestableWidget,
|
|
11
|
+
VariationFields,
|
|
12
|
+
} from "../../../../customtypes"
|
|
3
13
|
import type { LegacyContentCtx } from "../../../LegacyContentCtx"
|
|
4
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
GroupContent,
|
|
16
|
+
GroupItemContent,
|
|
17
|
+
GroupLegacy,
|
|
18
|
+
isGroupContent,
|
|
19
|
+
traverseGroupContent,
|
|
20
|
+
} from "../../GroupContent"
|
|
5
21
|
import {
|
|
6
22
|
isNestableContent,
|
|
7
23
|
NestableContent,
|
|
8
24
|
NestableLegacy,
|
|
9
25
|
} from "../../nestable"
|
|
26
|
+
import type {
|
|
27
|
+
SharedSliceItemContent,
|
|
28
|
+
SimpleSliceItemContent,
|
|
29
|
+
} from "../SliceItem"
|
|
10
30
|
|
|
11
31
|
export const SimpleSliceContent = t.union([NestableContent, GroupContent])
|
|
12
32
|
export type SimpleSliceContent = t.TypeOf<typeof SimpleSliceContent>
|
|
@@ -31,3 +51,126 @@ export const SimpleSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
31
51
|
},
|
|
32
52
|
}
|
|
33
53
|
}
|
|
54
|
+
|
|
55
|
+
export function traverseSimpleSliceContent({
|
|
56
|
+
path,
|
|
57
|
+
sliceKey,
|
|
58
|
+
sliceName,
|
|
59
|
+
model,
|
|
60
|
+
content,
|
|
61
|
+
}: {
|
|
62
|
+
path: ContentPath
|
|
63
|
+
sliceKey: string
|
|
64
|
+
sliceName: string
|
|
65
|
+
content: SimpleSliceItemContent
|
|
66
|
+
model?: VariationFields | Group | NestableWidget | undefined
|
|
67
|
+
}) {
|
|
68
|
+
return (
|
|
69
|
+
transformWidget: TraverseWidgetContentFn,
|
|
70
|
+
transformSlice: TraverseSliceContentFn,
|
|
71
|
+
): SharedSliceItemContent | SimpleSliceItemContent | undefined => {
|
|
72
|
+
if (isGroupContent(content.widget)) {
|
|
73
|
+
const convertedGroupWidget: GroupContent | undefined =
|
|
74
|
+
traverseGroupContent({
|
|
75
|
+
path,
|
|
76
|
+
key: content.key,
|
|
77
|
+
apiId: content.name,
|
|
78
|
+
model: (() => {
|
|
79
|
+
if (model?.type === "Group") return model
|
|
80
|
+
if (model?.type === "SharedSlice")
|
|
81
|
+
return {
|
|
82
|
+
type: "Group",
|
|
83
|
+
config: { fields: model.fields.items || {} },
|
|
84
|
+
}
|
|
85
|
+
return
|
|
86
|
+
})(),
|
|
87
|
+
content: content.widget,
|
|
88
|
+
})(transformWidget)
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
convertedGroupWidget &&
|
|
92
|
+
transformSlice({
|
|
93
|
+
key: content.key,
|
|
94
|
+
apiId: content.name,
|
|
95
|
+
path,
|
|
96
|
+
model,
|
|
97
|
+
content: {
|
|
98
|
+
...content,
|
|
99
|
+
widget: convertedGroupWidget,
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const convertedNestable: NestableContent | undefined = transformWidget({
|
|
106
|
+
key: content.key,
|
|
107
|
+
apiId: content.name,
|
|
108
|
+
path,
|
|
109
|
+
model: (() => {
|
|
110
|
+
if (model?.type === "SharedSlice")
|
|
111
|
+
return model.fields.primary?.[content.name]
|
|
112
|
+
if (model?.type !== "Group") return model
|
|
113
|
+
return
|
|
114
|
+
})(),
|
|
115
|
+
content: content.widget,
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
convertedNestable &&
|
|
120
|
+
transformSlice({
|
|
121
|
+
key: sliceKey,
|
|
122
|
+
apiId: sliceName,
|
|
123
|
+
path,
|
|
124
|
+
model,
|
|
125
|
+
content: {
|
|
126
|
+
...content,
|
|
127
|
+
widget: convertedNestable,
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function migrateSimpleSlice(
|
|
135
|
+
model: VariationFields,
|
|
136
|
+
content: SimpleSliceItemContent,
|
|
137
|
+
): SharedSliceItemContent {
|
|
138
|
+
if (content.widget.__TYPE__ === "GroupContentType") {
|
|
139
|
+
return {
|
|
140
|
+
key: content.key,
|
|
141
|
+
name: model.sliceName,
|
|
142
|
+
maybeLabel: content.maybeLabel,
|
|
143
|
+
widget: {
|
|
144
|
+
__TYPE__: "SharedSliceContent",
|
|
145
|
+
variation: model.variationId,
|
|
146
|
+
primary: {},
|
|
147
|
+
items: content.widget.value.map((groupItem) => {
|
|
148
|
+
return {
|
|
149
|
+
__TYPE__: "GroupItemContent",
|
|
150
|
+
value: groupItem.value.reduce<GroupItemContent["value"]>(
|
|
151
|
+
(acc, [fieldKey, fieldContent]) => {
|
|
152
|
+
return model.fields.items?.[fieldKey]
|
|
153
|
+
? acc.concat([[fieldKey, fieldContent]])
|
|
154
|
+
: acc
|
|
155
|
+
},
|
|
156
|
+
[],
|
|
157
|
+
),
|
|
158
|
+
}
|
|
159
|
+
}, []),
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
key: content.key,
|
|
165
|
+
name: model.sliceName,
|
|
166
|
+
maybeLabel: content.maybeLabel,
|
|
167
|
+
widget: {
|
|
168
|
+
__TYPE__: "SharedSliceContent",
|
|
169
|
+
variation: model.variationId,
|
|
170
|
+
primary: model.fields.primary?.[content.name]
|
|
171
|
+
? { [content.key]: content.widget }
|
|
172
|
+
: {},
|
|
173
|
+
items: [],
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -9,10 +9,21 @@ import {
|
|
|
9
9
|
LegacyContentCtx,
|
|
10
10
|
WithTypes,
|
|
11
11
|
} from "../../LegacyContentCtx"
|
|
12
|
+
import { isGroupContent } from "../GroupContent"
|
|
13
|
+
import { isNestableContent } from "../nestable"
|
|
12
14
|
import { SliceContent, SliceLegacy } from "./Slice"
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
import {
|
|
16
|
+
CompositeSliceContent,
|
|
17
|
+
isCompositeSliceContent,
|
|
18
|
+
} from "./Slice/CompositeSliceContent"
|
|
19
|
+
import {
|
|
20
|
+
isSharedSliceContent,
|
|
21
|
+
SharedSliceContent,
|
|
22
|
+
} from "./Slice/SharedSliceContent"
|
|
23
|
+
import {
|
|
24
|
+
isSimpleSliceContent,
|
|
25
|
+
SimpleSliceContent,
|
|
26
|
+
} from "./Slice/SimpleSliceContent"
|
|
16
27
|
|
|
17
28
|
export const SliceItemContent = t.type({
|
|
18
29
|
key: t.string,
|
|
@@ -21,6 +32,31 @@ export const SliceItemContent = t.type({
|
|
|
21
32
|
widget: SliceContent,
|
|
22
33
|
})
|
|
23
34
|
export type SliceItemContent = t.TypeOf<typeof SliceItemContent>
|
|
35
|
+
export type SharedSliceItemContent = Omit<SliceItemContent, "widget"> & {
|
|
36
|
+
widget: SharedSliceContent
|
|
37
|
+
}
|
|
38
|
+
export function isSharedSliceItemContent(
|
|
39
|
+
item: SliceItemContent,
|
|
40
|
+
): item is SharedSliceItemContent {
|
|
41
|
+
return isSharedSliceContent(item.widget)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type CompositeSliceItemContent = Omit<SliceItemContent, "widget"> & {
|
|
45
|
+
widget: CompositeSliceContent
|
|
46
|
+
}
|
|
47
|
+
export function isCompositeSliceItemContent(
|
|
48
|
+
item: SliceItemContent,
|
|
49
|
+
): item is CompositeSliceItemContent {
|
|
50
|
+
return isCompositeSliceContent(item.widget)
|
|
51
|
+
}
|
|
52
|
+
export type SimpleSliceItemContent = Omit<SliceItemContent, "widget"> & {
|
|
53
|
+
widget: SimpleSliceContent
|
|
54
|
+
}
|
|
55
|
+
export function isSimpleSliceItemContent(
|
|
56
|
+
item: SliceItemContent,
|
|
57
|
+
): item is SimpleSliceItemContent {
|
|
58
|
+
return isGroupContent(item.widget) || isNestableContent(item.widget)
|
|
59
|
+
}
|
|
24
60
|
|
|
25
61
|
const itemLegacyReader = t.exact(
|
|
26
62
|
t.intersection([
|