@prismicio/types-internal 4.0.0-pr.6.38cb7de → 4.0.0-pr.6.6ce647d
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/dist/content/legacy/group.d.ts.map +1 -1
- package/dist/content/legacy/group.js.map +1 -1
- package/dist/content/legacy/nestable.js.map +1 -1
- package/dist/content/legacy/repeatable.js +2 -8
- package/dist/content/legacy/repeatable.js.map +1 -1
- package/dist/content/legacy/slice.js +2 -3
- package/dist/content/legacy/slice.js.map +1 -1
- package/dist/content/nestable.js +1 -0
- package/dist/content/nestable.js.map +1 -1
- package/dist/helpers/contentPath.js +1 -1
- package/dist/helpers/customTypeModel.js +1 -1
- package/dist/helpers/documentContent.d.ts +2 -1
- package/dist/helpers/documentContent.d.ts.map +1 -1
- package/dist/helpers/documentContent.js +14 -1
- package/dist/helpers/documentContent.js.map +1 -1
- package/dist/helpers/sliceContent.d.ts +12 -0
- package/dist/helpers/sliceContent.d.ts.map +1 -0
- package/dist/helpers/sliceContent.js +60 -0
- package/dist/helpers/sliceContent.js.map +1 -0
- package/dist/helpers/traverseContent.d.ts +5 -5
- package/dist/helpers/traverseContent.d.ts.map +1 -1
- package/dist/helpers/traverseContent.js +50 -18
- package/dist/helpers/traverseContent.js.map +1 -1
- package/dist/helpers/traverseContentWithModel.d.ts +4 -4
- package/dist/helpers/traverseContentWithModel.d.ts.map +1 -1
- package/dist/helpers/traverseContentWithModel.js +60 -34
- package/dist/helpers/traverseContentWithModel.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/io-ts.d.ts +1 -69
- package/dist/io-ts.d.ts.map +1 -1
- package/dist/model/table.d.ts.map +1 -1
- package/dist/model/table.js.map +1 -1
- package/dist/model/widget.d.ts +8 -8
- package/package.json +1 -1
- package/src/content/legacy/group.ts +2 -0
- package/src/content/legacy/nestable.ts +1 -1
- package/src/content/legacy/repeatable.ts +3 -16
- package/src/content/legacy/slice.ts +6 -5
- package/src/content/nestable.ts +2 -0
- package/src/helpers/documentContent.ts +32 -1
- package/src/helpers/sliceContent.ts +86 -0
- package/src/helpers/traverseContent.ts +89 -27
- package/src/helpers/traverseContentWithModel.ts +69 -42
- package/src/index.ts +1 -0
- package/src/model/table.ts +2 -1
|
@@ -5,10 +5,15 @@ import { defaultCtx } from "../content/codec/legacyContentCtx"
|
|
|
5
5
|
import type { DocumentContent } from "../content/document"
|
|
6
6
|
import type { DocumentLegacy } from "../content/legacy/document"
|
|
7
7
|
import { DocumentLegacySchema } from "../content/legacy/document"
|
|
8
|
+
import { isNestableContent } from "../content/nestable"
|
|
9
|
+
import type { CompositeSliceItemContent, LegacySliceItemContent } from "../content/slices"
|
|
8
10
|
import type { WidgetContent } from "../content/widget"
|
|
11
|
+
import type { StaticCustomTypeModel } from "../model/customType"
|
|
9
12
|
import type { FieldOrSliceType } from "../model/widget"
|
|
10
13
|
import { FieldOrSliceTypeSchema } from "../model/widget"
|
|
11
14
|
import * as contentPath from "./contentPath"
|
|
15
|
+
import * as customTypeModel from "./customTypeModel"
|
|
16
|
+
import * as sliceContent from "./sliceContent"
|
|
12
17
|
import { traverseDocumentContent } from "./traverseContent"
|
|
13
18
|
|
|
14
19
|
export function collectWidgets<TWidgetContent extends WidgetContent>(
|
|
@@ -37,7 +42,10 @@ export function collectWidgets<TWidgetContent extends WidgetContent>(
|
|
|
37
42
|
return collected
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
export function fromLegacy(
|
|
45
|
+
export function fromLegacy(
|
|
46
|
+
legacy: DocumentLegacy,
|
|
47
|
+
model: StaticCustomTypeModel,
|
|
48
|
+
): DocumentContent | undefined {
|
|
41
49
|
const parsed = DocumentLegacySchema.safeParse(legacy)
|
|
42
50
|
if (!parsed.success) {
|
|
43
51
|
return
|
|
@@ -67,6 +75,29 @@ export function fromLegacy(legacy: DocumentLegacy): DocumentContent | undefined
|
|
|
67
75
|
return
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
const needsMigration = Object.values(customTypeModel.collectSharedSlices(model)).some((slice) =>
|
|
79
|
+
Boolean(slice.legacyPaths),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if (needsMigration) {
|
|
83
|
+
return traverseDocumentContent(result.data, {
|
|
84
|
+
model,
|
|
85
|
+
transformSlice: ({ content, model }) => {
|
|
86
|
+
if (model?.type === "SharedSlice") {
|
|
87
|
+
if (content.widget.__TYPE__ === "CompositeSliceContent") {
|
|
88
|
+
return sliceContent.compositeToShared(content as CompositeSliceItemContent, model)
|
|
89
|
+
} else if (
|
|
90
|
+
content.widget.__TYPE__ === "GroupContentType" ||
|
|
91
|
+
isNestableContent(content.widget)
|
|
92
|
+
) {
|
|
93
|
+
return sliceContent.legacyToShared(content as LegacySliceItemContent, model)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return content
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
70
101
|
return result.data
|
|
71
102
|
}
|
|
72
103
|
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { GroupItemContent } from "../content/group"
|
|
2
|
+
import type { SharedSliceContent } from "../content/slice"
|
|
3
|
+
import type {
|
|
4
|
+
CompositeSliceItemContent,
|
|
5
|
+
LegacySliceItemContent,
|
|
6
|
+
SharedSliceItemContent,
|
|
7
|
+
} from "../content/slices"
|
|
8
|
+
import type { SharedSliceVariationContentModel } from "../model/slice"
|
|
9
|
+
|
|
10
|
+
export const legacyToShared = (
|
|
11
|
+
content: LegacySliceItemContent,
|
|
12
|
+
model: SharedSliceVariationContentModel,
|
|
13
|
+
): SharedSliceItemContent => {
|
|
14
|
+
const sliceUUID = content.key.split("$")[1]
|
|
15
|
+
|
|
16
|
+
const primary: SharedSliceContent["primary"] = {}
|
|
17
|
+
const items: SharedSliceContent["items"] = []
|
|
18
|
+
if (content.widget.__TYPE__ === "GroupContentType") {
|
|
19
|
+
// Group content
|
|
20
|
+
for (const item of content.widget.value) {
|
|
21
|
+
const value: GroupItemContent["value"] = []
|
|
22
|
+
|
|
23
|
+
for (const [key, nestable] of item.value) {
|
|
24
|
+
if (model.fields.items?.[key]) {
|
|
25
|
+
value.push([key, nestable])
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
items.push({ ...item, value })
|
|
30
|
+
}
|
|
31
|
+
} else if (model.fields.primary?.[content.name]) {
|
|
32
|
+
// Nestable content
|
|
33
|
+
primary[content.name] = content.widget
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
key: `${model.sliceName}$${sliceUUID}`,
|
|
38
|
+
name: model.sliceName,
|
|
39
|
+
maybeLabel: content.maybeLabel,
|
|
40
|
+
widget: {
|
|
41
|
+
__TYPE__: "SharedSliceContent",
|
|
42
|
+
variation: model.variationID,
|
|
43
|
+
primary,
|
|
44
|
+
items,
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const compositeToShared = (
|
|
50
|
+
content: CompositeSliceItemContent,
|
|
51
|
+
model: SharedSliceVariationContentModel,
|
|
52
|
+
): SharedSliceItemContent => {
|
|
53
|
+
const sliceUUID = content.key.split("$")[1]
|
|
54
|
+
|
|
55
|
+
const primary: SharedSliceContent["primary"] = {}
|
|
56
|
+
for (const [key, value] of Object.entries(content.widget.nonRepeat)) {
|
|
57
|
+
if (model.fields.primary?.[key]) {
|
|
58
|
+
primary[key] = value
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const items: SharedSliceContent["items"] = []
|
|
63
|
+
for (const item of content.widget.repeat) {
|
|
64
|
+
const value: GroupItemContent["value"] = []
|
|
65
|
+
|
|
66
|
+
for (const [key, nestable] of item.value) {
|
|
67
|
+
if (model.fields.items?.[key]) {
|
|
68
|
+
value.push([key, nestable])
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
items.push({ ...item, value })
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
key: `${model.sliceName}$${sliceUUID}`,
|
|
77
|
+
name: model.sliceName,
|
|
78
|
+
maybeLabel: content.maybeLabel,
|
|
79
|
+
widget: {
|
|
80
|
+
__TYPE__: "SharedSliceContent",
|
|
81
|
+
variation: model.variationID,
|
|
82
|
+
primary,
|
|
83
|
+
items,
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -24,6 +24,7 @@ import type { NestableModel } from "../model/nestable"
|
|
|
24
24
|
import type {
|
|
25
25
|
CompositeSliceModel,
|
|
26
26
|
LegacySliceModel,
|
|
27
|
+
SharedSliceModel,
|
|
27
28
|
SharedSliceVariationContentModel,
|
|
28
29
|
SliceContentModel,
|
|
29
30
|
} from "../model/slice"
|
|
@@ -89,27 +90,67 @@ export function traverseSlicesContent(
|
|
|
89
90
|
for (const sliceItemContent of content.value) {
|
|
90
91
|
const sliceModel = config.model?.config?.choices?.[sliceItemContent.name]
|
|
91
92
|
|
|
92
|
-
let
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
let sliceContentModel: SliceContentModel | undefined
|
|
94
|
+
|
|
95
|
+
// Happy path, content and model are both shared slices
|
|
96
|
+
if (
|
|
97
|
+
sliceItemContent.widget.__TYPE__ === SharedSliceContentType &&
|
|
98
|
+
sliceModel?.type === "SharedSlice"
|
|
99
|
+
) {
|
|
100
|
+
const variationID = sliceItemContent.widget.variation
|
|
101
|
+
const variationModel = sliceModel.variations.find((variation) => variation.id === variationID)
|
|
102
|
+
if (variationModel) {
|
|
103
|
+
sliceContentModel = {
|
|
104
|
+
type: "SharedSlice",
|
|
105
|
+
sliceName: sliceModel.id,
|
|
106
|
+
variationID: variationModel.id,
|
|
107
|
+
fields: {
|
|
108
|
+
primary: variationModel.primary || {},
|
|
109
|
+
items: variationModel.items || {},
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Migrated path, content is composite or legacy, model is shared slice
|
|
116
|
+
if (!sliceContentModel) {
|
|
117
|
+
const legacyPath = contentPath.append(contentPath.serialize(path), sliceItemContent.name)
|
|
118
|
+
|
|
119
|
+
// Find the migrated slice model who's legacy path matches the content path
|
|
120
|
+
const migratedSliceModel = Object.values(config.model?.config?.choices || {}).find(
|
|
121
|
+
(model): model is SharedSliceModel => {
|
|
122
|
+
return model.type === "SharedSlice" && Boolean(model.legacyPaths?.[legacyPath])
|
|
123
|
+
},
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
if (migratedSliceModel) {
|
|
127
|
+
// Find the variation that matches the legacy path
|
|
128
|
+
const variation = migratedSliceModel.variations.find((variation) => {
|
|
129
|
+
return variation.id === migratedSliceModel.legacyPaths?.[legacyPath]
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
if (variation) {
|
|
133
|
+
sliceContentModel = {
|
|
102
134
|
type: "SharedSlice",
|
|
103
|
-
sliceName:
|
|
104
|
-
variationID,
|
|
135
|
+
sliceName: migratedSliceModel.id,
|
|
136
|
+
variationID: variation.id,
|
|
105
137
|
fields: {
|
|
106
|
-
primary:
|
|
107
|
-
items:
|
|
138
|
+
primary: variation.primary || {},
|
|
139
|
+
items: variation.items || {},
|
|
108
140
|
},
|
|
109
141
|
}
|
|
110
142
|
}
|
|
111
143
|
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Non-migrated path, content and model are composite or legacy
|
|
147
|
+
if (!sliceContentModel && sliceModel && sliceModel.type !== "SharedSlice") {
|
|
148
|
+
sliceContentModel = sliceModel
|
|
149
|
+
}
|
|
112
150
|
|
|
151
|
+
let traversedSliceItemContent: SliceItemContent | undefined
|
|
152
|
+
if (sliceItemContent.widget.__TYPE__ === SharedSliceContentType) {
|
|
153
|
+
const model = sliceContentModel?.type === "SharedSlice" ? sliceContentModel : undefined
|
|
113
154
|
traversedSliceItemContent = traverseSharedSliceContent(
|
|
114
155
|
path.concat({ key: sliceItemContent.key, type: "SharedSlice" }),
|
|
115
156
|
sliceItemContent.key,
|
|
@@ -118,7 +159,10 @@ export function traverseSlicesContent(
|
|
|
118
159
|
{ model, transformWidget, transformSlice },
|
|
119
160
|
)
|
|
120
161
|
} else if (sliceItemContent.widget.__TYPE__ === CompositeSliceContentType) {
|
|
121
|
-
const model =
|
|
162
|
+
const model =
|
|
163
|
+
sliceContentModel?.type === "Slice" || sliceContentModel?.type === "SharedSlice"
|
|
164
|
+
? sliceContentModel
|
|
165
|
+
: undefined
|
|
122
166
|
traversedSliceItemContent = traverseCompositeSliceContent(
|
|
123
167
|
path.concat({ key: sliceItemContent.key, type: "Slice" }),
|
|
124
168
|
sliceItemContent.key,
|
|
@@ -127,8 +171,7 @@ export function traverseSlicesContent(
|
|
|
127
171
|
{ model, transformWidget, transformSlice },
|
|
128
172
|
)
|
|
129
173
|
} else {
|
|
130
|
-
const model =
|
|
131
|
-
sliceModel?.type !== "SharedSlice" && sliceModel?.type !== "Slice" ? sliceModel : undefined
|
|
174
|
+
const model = sliceContentModel?.type !== "Slice" ? sliceContentModel : undefined
|
|
132
175
|
traversedSliceItemContent = traverseLegacySliceContent(
|
|
133
176
|
path.concat({ key: sliceItemContent.key, type: "LegacySlice" }),
|
|
134
177
|
sliceItemContent.key,
|
|
@@ -207,7 +250,7 @@ export function traverseSharedSliceContent(
|
|
|
207
250
|
}
|
|
208
251
|
|
|
209
252
|
type TraverseCompositeSliceContentConfig = {
|
|
210
|
-
model?: CompositeSliceModel
|
|
253
|
+
model?: CompositeSliceModel | SharedSliceVariationContentModel
|
|
211
254
|
transformWidget?: TraverseWidgetContentFunction
|
|
212
255
|
transformSlice?: TraverseSliceContentFunction
|
|
213
256
|
}
|
|
@@ -218,20 +261,22 @@ export function traverseCompositeSliceContent(
|
|
|
218
261
|
apiID: string,
|
|
219
262
|
content: CompositeSliceItemContent,
|
|
220
263
|
config: TraverseCompositeSliceContentConfig,
|
|
221
|
-
): CompositeSliceItemContent | undefined {
|
|
264
|
+
): CompositeSliceItemContent | SharedSliceItemContent | undefined {
|
|
222
265
|
const { transformWidget = (args) => args.content, transformSlice = (args) => args.content } =
|
|
223
266
|
config
|
|
224
267
|
|
|
268
|
+
const primaryModel =
|
|
269
|
+
config.model?.type === "SharedSlice"
|
|
270
|
+
? config.model?.fields.primary
|
|
271
|
+
: config.model?.["non-repeat"]
|
|
225
272
|
const traversedPrimary: CompositeSliceContent["nonRepeat"] = {}
|
|
226
273
|
for (const [key, fieldContent] of Object.entries(content.widget.nonRepeat)) {
|
|
227
|
-
const model = config.model?.["non-repeat"]?.[key]
|
|
228
|
-
|
|
229
274
|
const traversedContent = traverseWidgetContent(
|
|
230
275
|
path.concat({ key: "non-repeat", type: "primary" }, { key, type: "Widget" }),
|
|
231
276
|
key,
|
|
232
277
|
apiID,
|
|
233
278
|
fieldContent,
|
|
234
|
-
{ model, transformWidget },
|
|
279
|
+
{ model: primaryModel?.[key], transformWidget },
|
|
235
280
|
)
|
|
236
281
|
|
|
237
282
|
if (traversedContent && isNestableContent(traversedContent)) {
|
|
@@ -239,10 +284,12 @@ export function traverseCompositeSliceContent(
|
|
|
239
284
|
}
|
|
240
285
|
}
|
|
241
286
|
|
|
287
|
+
const itemsModel =
|
|
288
|
+
config.model?.type === "SharedSlice" ? config.model?.fields.items : config.model?.repeat
|
|
242
289
|
const traversedItems = traverseGroupItemsContent(
|
|
243
290
|
path.concat({ key: "repeat", type: "items" }),
|
|
244
291
|
content.widget.repeat,
|
|
245
|
-
{ model:
|
|
292
|
+
{ model: itemsModel, transformWidget },
|
|
246
293
|
)
|
|
247
294
|
|
|
248
295
|
return transformSlice({
|
|
@@ -258,7 +305,7 @@ export function traverseCompositeSliceContent(
|
|
|
258
305
|
}
|
|
259
306
|
|
|
260
307
|
type TraverseLegacySliceContentConfig = {
|
|
261
|
-
model?: LegacySliceModel
|
|
308
|
+
model?: LegacySliceModel | SharedSliceVariationContentModel
|
|
262
309
|
transformWidget?: TraverseWidgetContentFunction
|
|
263
310
|
transformSlice?: TraverseSliceContentFunction
|
|
264
311
|
}
|
|
@@ -269,15 +316,30 @@ export function traverseLegacySliceContent(
|
|
|
269
316
|
apiID: string,
|
|
270
317
|
content: LegacySliceItemContent,
|
|
271
318
|
config: TraverseLegacySliceContentConfig,
|
|
272
|
-
): LegacySliceItemContent | undefined {
|
|
319
|
+
): LegacySliceItemContent | SharedSliceItemContent | undefined {
|
|
273
320
|
const {
|
|
274
321
|
model,
|
|
275
322
|
transformWidget = (args) => args.content,
|
|
276
323
|
transformSlice = (args) => args.content,
|
|
277
324
|
} = config
|
|
278
325
|
|
|
326
|
+
let legacySliceModel: LegacySliceModel | undefined
|
|
327
|
+
if (content.widget.__TYPE__ === "GroupContentType") {
|
|
328
|
+
if (model?.type === "Group") {
|
|
329
|
+
legacySliceModel = model
|
|
330
|
+
} else if (model?.type === "SharedSlice") {
|
|
331
|
+
legacySliceModel = { type: "Group", config: { fields: model.fields.items } }
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
if (model?.type === "SharedSlice") {
|
|
335
|
+
legacySliceModel = model.fields.primary?.[content.name]
|
|
336
|
+
} else if (model?.type !== "Group") {
|
|
337
|
+
legacySliceModel = model
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
279
341
|
const traversedContent = traverseWidgetContent(path, key, apiID, content.widget, {
|
|
280
|
-
model,
|
|
342
|
+
model: legacySliceModel,
|
|
281
343
|
transformWidget,
|
|
282
344
|
transformSlice,
|
|
283
345
|
})
|
|
@@ -467,7 +529,7 @@ export type TraverseSliceContentFunction = <TContent extends SliceItemContent>(a
|
|
|
467
529
|
apiID: string
|
|
468
530
|
content: TContent
|
|
469
531
|
model?: SliceContentModel
|
|
470
|
-
}) => TContent | undefined
|
|
532
|
+
}) => TContent | SharedSliceItemContent | undefined
|
|
471
533
|
|
|
472
534
|
export type TraverseWidgetContentFunction<
|
|
473
535
|
TContentTransformMode extends "preserve" | "widen" = "preserve",
|
|
@@ -96,49 +96,70 @@ export function traverseSlicesContentWithModel(
|
|
|
96
96
|
|
|
97
97
|
const traversed: SlicesContent["value"] = []
|
|
98
98
|
for (const sliceItemContent of content.value) {
|
|
99
|
-
const
|
|
99
|
+
const sliceModel = config.model.config?.choices?.[sliceItemContent.name]
|
|
100
100
|
|
|
101
101
|
let traversedSliceItemContent: SliceItemContent | undefined
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
102
|
+
if (sliceModel?.type === "SharedSlice") {
|
|
103
|
+
if (sliceItemContent.widget.__TYPE__ === SharedSliceContentType) {
|
|
104
|
+
// Happy path, content and model are both shared slices
|
|
105
|
+
const variationID = sliceItemContent.widget.variation
|
|
106
|
+
const variationModel = sliceModel.variations.find(
|
|
107
|
+
(variation) => variation.id === variationID,
|
|
108
|
+
)
|
|
109
|
+
if (variationModel) {
|
|
110
|
+
const model: SharedSliceVariationContentModel = {
|
|
111
|
+
type: "SharedSlice",
|
|
112
|
+
sliceName: sliceModel.id,
|
|
113
|
+
variationID: variationModel.id,
|
|
114
|
+
fields: {
|
|
115
|
+
primary: variationModel.primary || {},
|
|
116
|
+
items: variationModel.items || {},
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
traversedSliceItemContent = traverseSharedSliceContentWithModel(
|
|
121
|
+
path.concat({ key: sliceItemContent.key, type: "SharedSlice" }),
|
|
122
|
+
sliceItemContent.key,
|
|
123
|
+
sliceItemContent.name,
|
|
124
|
+
sliceItemContent as SharedSliceItemContent,
|
|
125
|
+
{ model, transformWidget, transformSlice },
|
|
126
|
+
)
|
|
117
127
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
128
|
+
} else if (sliceItemContent.widget.__TYPE__ === CompositeSliceContentType) {
|
|
129
|
+
// Migrated path, content is composite, model is shared slice
|
|
130
|
+
const variationModel = sliceModel.variations[0]
|
|
131
|
+
if (variationModel) {
|
|
132
|
+
const model: SharedSliceVariationContentModel = {
|
|
133
|
+
type: "SharedSlice",
|
|
134
|
+
sliceName: sliceModel.id,
|
|
135
|
+
variationID: variationModel.id,
|
|
136
|
+
fields: {
|
|
137
|
+
primary: variationModel.primary || {},
|
|
138
|
+
items: variationModel.items || {},
|
|
139
|
+
},
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
traversedSliceItemContent = traverseCompositeSliceContentWithModel(
|
|
143
|
+
path.concat({ key: sliceItemContent.key, type: "Slice" }),
|
|
144
|
+
sliceItemContent.key,
|
|
145
|
+
sliceItemContent.name,
|
|
146
|
+
sliceItemContent as CompositeSliceItemContent,
|
|
147
|
+
{ model, transformWidget, transformSlice },
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} else if (sliceModel?.type === "Slice") {
|
|
152
|
+
if (sliceItemContent.widget.__TYPE__ === CompositeSliceContentType) {
|
|
153
|
+
traversedSliceItemContent = traverseCompositeSliceContentWithModel(
|
|
154
|
+
path.concat({ key: sliceItemContent.key, type: "Slice" }),
|
|
121
155
|
sliceItemContent.key,
|
|
122
156
|
sliceItemContent.name,
|
|
123
|
-
sliceItemContent as
|
|
124
|
-
{ model:
|
|
157
|
+
sliceItemContent as CompositeSliceItemContent,
|
|
158
|
+
{ model: sliceModel, transformWidget, transformSlice },
|
|
125
159
|
)
|
|
126
160
|
}
|
|
127
161
|
} else if (
|
|
128
|
-
|
|
129
|
-
sliceItemContent.widget.__TYPE__ === CompositeSliceContentType
|
|
130
|
-
) {
|
|
131
|
-
traversedSliceItemContent = traverseCompositeSliceContentWithModel(
|
|
132
|
-
path.concat({ key: sliceItemContent.key, type: "Slice" }),
|
|
133
|
-
sliceItemContent.key,
|
|
134
|
-
sliceItemContent.name,
|
|
135
|
-
sliceItemContent as CompositeSliceItemContent,
|
|
136
|
-
{ model, transformWidget, transformSlice },
|
|
137
|
-
)
|
|
138
|
-
} else if (
|
|
139
|
-
model &&
|
|
140
|
-
model?.type !== "SharedSlice" &&
|
|
141
|
-
model?.type !== "Slice" &&
|
|
162
|
+
sliceModel &&
|
|
142
163
|
sliceItemContent.widget.__TYPE__ !== SharedSliceContentType &&
|
|
143
164
|
sliceItemContent.widget.__TYPE__ !== CompositeSliceContentType
|
|
144
165
|
) {
|
|
@@ -147,7 +168,7 @@ export function traverseSlicesContentWithModel(
|
|
|
147
168
|
sliceItemContent.key,
|
|
148
169
|
sliceItemContent.name,
|
|
149
170
|
sliceItemContent as LegacySliceItemContent,
|
|
150
|
-
{ model, transformWidget, transformSlice },
|
|
171
|
+
{ model: sliceModel, transformWidget, transformSlice },
|
|
151
172
|
)
|
|
152
173
|
}
|
|
153
174
|
|
|
@@ -222,7 +243,7 @@ export function traverseSharedSliceContentWithModel(
|
|
|
222
243
|
}
|
|
223
244
|
|
|
224
245
|
type TraverseCompositeSliceContentWithModelConfig = {
|
|
225
|
-
model: CompositeSliceModel
|
|
246
|
+
model: CompositeSliceModel | SharedSliceVariationContentModel
|
|
226
247
|
transformWidget?: TraverseWidgetContentWithModelFunction
|
|
227
248
|
transformSlice?: TraverseSliceContentWithModelFunction
|
|
228
249
|
}
|
|
@@ -233,7 +254,7 @@ export function traverseCompositeSliceContentWithModel(
|
|
|
233
254
|
apiID: string,
|
|
234
255
|
content: CompositeSliceItemContent | undefined,
|
|
235
256
|
config: TraverseCompositeSliceContentWithModelConfig,
|
|
236
|
-
): CompositeSliceItemContent | undefined {
|
|
257
|
+
): CompositeSliceItemContent | SharedSliceItemContent | undefined {
|
|
237
258
|
if (!content) {
|
|
238
259
|
return
|
|
239
260
|
}
|
|
@@ -241,8 +262,12 @@ export function traverseCompositeSliceContentWithModel(
|
|
|
241
262
|
const { transformWidget = (args) => args.content, transformSlice = (args) => args.content } =
|
|
242
263
|
config
|
|
243
264
|
|
|
265
|
+
const primaryModel =
|
|
266
|
+
config.model?.type === "SharedSlice"
|
|
267
|
+
? config.model?.fields.primary
|
|
268
|
+
: config.model?.["non-repeat"]
|
|
244
269
|
const traversedPrimary: CompositeSliceContent["nonRepeat"] = {}
|
|
245
|
-
for (const [key, model] of Object.entries(
|
|
270
|
+
for (const [key, model] of Object.entries(primaryModel ?? {})) {
|
|
246
271
|
const traversedContent = traverseWidgetContentWithModel(
|
|
247
272
|
path.concat({ key: "non-repeat", type: "primary" }, { key, type: "Widget" }),
|
|
248
273
|
key,
|
|
@@ -256,10 +281,12 @@ export function traverseCompositeSliceContentWithModel(
|
|
|
256
281
|
}
|
|
257
282
|
}
|
|
258
283
|
|
|
284
|
+
const itemsModel =
|
|
285
|
+
config.model?.type === "SharedSlice" ? config.model?.fields.items : config.model?.repeat
|
|
259
286
|
const traversedItems = traverseGroupItemsContentWithModel(
|
|
260
287
|
path.concat({ key: "repeat", type: "items" }),
|
|
261
288
|
content.widget.repeat,
|
|
262
|
-
{ model:
|
|
289
|
+
{ model: itemsModel ?? {}, transformWidget },
|
|
263
290
|
)
|
|
264
291
|
|
|
265
292
|
return transformSlice({
|
|
@@ -286,7 +313,7 @@ export function traverseLegacySliceContentWithModel(
|
|
|
286
313
|
apiID: string,
|
|
287
314
|
content: LegacySliceItemContent | undefined,
|
|
288
315
|
config: TraverseLegacySliceContentWithModelConfig,
|
|
289
|
-
): LegacySliceItemContent | undefined {
|
|
316
|
+
): LegacySliceItemContent | SharedSliceItemContent | undefined {
|
|
290
317
|
if (!content) {
|
|
291
318
|
return
|
|
292
319
|
}
|
|
@@ -520,7 +547,7 @@ export type TraverseSliceContentWithModelFunction = <TContent extends SliceItemC
|
|
|
520
547
|
apiID: string
|
|
521
548
|
content?: TContent
|
|
522
549
|
model: SliceContentModel
|
|
523
|
-
}) => TContent | undefined
|
|
550
|
+
}) => TContent | SharedSliceItemContent | undefined
|
|
524
551
|
|
|
525
552
|
export type TraverseWidgetContentWithModelFunction<
|
|
526
553
|
TContentTransformMode extends "preserve" | "widen" = "preserve",
|
package/src/index.ts
CHANGED
|
@@ -90,6 +90,7 @@ export { LegacyContentCtx, getFieldCtx, defaultCtx } from "./content/codec/legac
|
|
|
90
90
|
export * as contentPath from "./helpers/contentPath"
|
|
91
91
|
export * as customTypeModel from "./helpers/customTypeModel"
|
|
92
92
|
export * as documentContent from "./helpers/documentContent"
|
|
93
|
+
export * as sliceContent from "./helpers/sliceContent"
|
|
93
94
|
export {
|
|
94
95
|
traverseDocumentContent,
|
|
95
96
|
traverseSlicesContent,
|
package/src/model/table.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
|
+
|
|
2
3
|
import { RichTextNodeType, type RichTextModel } from "./richText"
|
|
3
4
|
|
|
4
5
|
const TableConfigSchema = z.object({
|
|
@@ -17,7 +18,7 @@ export const TableCellModelNodeTypes = [
|
|
|
17
18
|
RichTextNodeType.paragraph,
|
|
18
19
|
RichTextNodeType.strong,
|
|
19
20
|
RichTextNodeType.em,
|
|
20
|
-
RichTextNodeType.hyperlink
|
|
21
|
+
RichTextNodeType.hyperlink,
|
|
21
22
|
]
|
|
22
23
|
|
|
23
24
|
export const TableCellModel: RichTextModel = {
|