@prismicio/types-internal 3.11.2 → 3.12.0-alpha.1
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/CHANGELOG.md +764 -0
- package/lib/content/Document.d.ts +32 -7
- package/lib/content/Document.js +22 -8
- package/lib/content/LegacyContentCtx.d.ts +25 -3
- package/lib/content/LegacyContentCtx.js +67 -5
- package/lib/content/fields/GroupContent.d.ts +4 -2
- package/lib/content/fields/GroupContent.js +40 -17
- package/lib/content/fields/UIDContent.js +1 -0
- package/lib/content/fields/WidgetContent.d.ts +6 -0
- package/lib/content/fields/nestable/BooleanContent.js +1 -0
- package/lib/content/fields/nestable/EmbedContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/ColorContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/DateContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/NumberContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/RangeContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/SelectContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/TextContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/TimestampContent.js +1 -0
- package/lib/content/fields/nestable/GeoPointContent.js +1 -0
- package/lib/content/fields/nestable/ImageContent.js +1 -0
- package/lib/content/fields/nestable/IntegrationFieldContent.js +1 -0
- package/lib/content/fields/nestable/LinkContent.js +2 -0
- package/lib/content/fields/nestable/RepeatableContent.js +1 -0
- package/lib/content/fields/nestable/RichTextContent/index.js +1 -0
- package/lib/content/fields/nestable/SeparatorContent.js +1 -0
- package/lib/content/fields/nestable/TableContent.js +1 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +3 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +19 -5
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +5 -4
- package/lib/content/fields/slices/Slice/RepeatableContent.js +2 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +3 -0
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +26 -19
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +1 -0
- package/lib/content/fields/slices/Slice/index.d.ts +4 -0
- package/lib/content/fields/slices/SliceItem.d.ts +12 -0
- package/lib/content/fields/slices/SliceItem.js +11 -2
- package/lib/content/fields/slices/SlicesContent.d.ts +6 -0
- package/lib/content/fields/slices/SlicesContent.js +1 -0
- package/lib/customtypes/CustomType.js +6 -9
- package/lib/customtypes/Section.js +3 -8
- package/lib/customtypes/widgets/Group.js +20 -20
- package/lib/customtypes/widgets/nestable/NestableWidgetZ.d.ts +3 -0
- package/lib/customtypes/widgets/nestable/NestableWidgetZ.js +29 -0
- package/lib/customtypes/widgets/slices/CompositeSlice.js +9 -22
- package/lib/customtypes/widgets/slices/SharedSlice.js +18 -37
- package/lib/customtypes/widgets/slices/SharedSliceZ.d.ts +16 -0
- package/lib/customtypes/widgets/slices/SharedSliceZ.js +39 -0
- package/lib/customtypes/widgets/slices/SlicePrimaryWidgetZ.d.ts +3 -0
- package/lib/customtypes/widgets/slices/SlicePrimaryWidgetZ.js +6 -0
- package/lib/customtypes/widgets/slices/Slices.js +9 -16
- package/package.json +1 -1
- package/src/content/Document.ts +31 -8
- package/src/content/LegacyContentCtx.ts +72 -16
- package/src/content/fields/GroupContent.ts +58 -16
- package/src/content/fields/UIDContent.ts +1 -0
- package/src/content/fields/nestable/BooleanContent.ts +1 -0
- package/src/content/fields/nestable/EmbedContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/ColorContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/DateContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/NumberContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/RangeContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/SelectContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/TextContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/TimestampContent.ts +1 -0
- package/src/content/fields/nestable/GeoPointContent.ts +1 -0
- package/src/content/fields/nestable/ImageContent.ts +1 -0
- package/src/content/fields/nestable/IntegrationFieldContent.ts +1 -0
- package/src/content/fields/nestable/LinkContent.ts +2 -0
- package/src/content/fields/nestable/RepeatableContent.ts +4 -0
- package/src/content/fields/nestable/RichTextContent/index.ts +1 -0
- package/src/content/fields/nestable/SeparatorContent.ts +1 -0
- package/src/content/fields/nestable/TableContent.ts +1 -0
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +19 -5
- package/src/content/fields/slices/Slice/RepeatableContent.ts +7 -2
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +26 -19
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +1 -0
- package/src/content/fields/slices/SliceItem.ts +12 -3
- package/src/content/fields/slices/SlicesContent.ts +4 -1
- package/src/customtypes/CustomType.ts +6 -9
- package/src/customtypes/Section.ts +3 -9
- package/src/customtypes/widgets/Group.ts +20 -21
- package/src/customtypes/widgets/slices/CompositeSlice.ts +9 -22
- package/src/customtypes/widgets/slices/SharedSlice.ts +23 -38
- package/src/customtypes/widgets/slices/Slices.ts +9 -15
- package/lib/content/fields/RepeatableContent.d.ts +0 -162
- package/lib/content/fields/RepeatableContent.js +0 -93
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +0 -727
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +0 -80
- package/lib/customtypes/widgets/slices/SliceWidget.d.ts +0 -327
- package/lib/customtypes/widgets/slices/SliceWidget.js +0 -8
|
@@ -562,6 +562,7 @@ export const LinkContentLegacy = (ctx: LegacyContentCtx) =>
|
|
|
562
562
|
key,
|
|
563
563
|
}),
|
|
564
564
|
types: { [ctx.keyOfType]: "Link" },
|
|
565
|
+
keys: {},
|
|
565
566
|
}
|
|
566
567
|
},
|
|
567
568
|
)
|
|
@@ -627,6 +628,7 @@ export const FilledLinkContentLegacy = (ctx: LegacyContentCtx) => {
|
|
|
627
628
|
key,
|
|
628
629
|
}),
|
|
629
630
|
types: { [ctx.keyOfType]: "Link" },
|
|
631
|
+
keys: {},
|
|
630
632
|
}
|
|
631
633
|
},
|
|
632
634
|
)
|
|
@@ -88,6 +88,10 @@ export const RepeatableLegacy = (
|
|
|
88
88
|
return {
|
|
89
89
|
content: encodedItems.map((encodedItem) => encodedItem.content),
|
|
90
90
|
types: { [ctx.keyOfType]: `Repeatable.${fieldType}` },
|
|
91
|
+
keys: encodedItems.reduce<Record<string, string>>(
|
|
92
|
+
(acc, item) => ({ ...acc, ...item.keys }),
|
|
93
|
+
{},
|
|
94
|
+
),
|
|
91
95
|
}
|
|
92
96
|
},
|
|
93
97
|
)
|
|
@@ -60,7 +60,7 @@ export const CompositeSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
60
60
|
either.map((parsedSlice) => {
|
|
61
61
|
const repeat =
|
|
62
62
|
(() => {
|
|
63
|
-
const itemsCtx = getFieldCtx("repeat", ctx)
|
|
63
|
+
const itemsCtx = getFieldCtx({ fieldKey: "repeat", ctx })
|
|
64
64
|
const result = RepeatableWidgetsLegacy(itemsCtx).decode(
|
|
65
65
|
parsedSlice.repeat,
|
|
66
66
|
)
|
|
@@ -71,7 +71,11 @@ export const CompositeSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
71
71
|
const nonRepeat = Object.entries(
|
|
72
72
|
parsedSlice["non-repeat"] || {},
|
|
73
73
|
).reduce<Record<string, NestableContent>>((acc, [key, value]) => {
|
|
74
|
-
const fieldCtx = getFieldCtx(
|
|
74
|
+
const fieldCtx = getFieldCtx({
|
|
75
|
+
fieldKey: key,
|
|
76
|
+
ctx,
|
|
77
|
+
prefixes: ["non-repeat"],
|
|
78
|
+
})
|
|
75
79
|
if (!fieldCtx) return acc
|
|
76
80
|
|
|
77
81
|
const result = NestableLegacy(fieldCtx).decode(value)
|
|
@@ -94,7 +98,11 @@ export const CompositeSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
94
98
|
WithTypes<{ [key: string]: unknown }>
|
|
95
99
|
>(
|
|
96
100
|
(acc, [key, value]) => {
|
|
97
|
-
const FieldCtx = getFieldCtx(
|
|
101
|
+
const FieldCtx = getFieldCtx({
|
|
102
|
+
fieldKey: key,
|
|
103
|
+
ctx,
|
|
104
|
+
prefixes: ["non-repeat"],
|
|
105
|
+
})
|
|
98
106
|
|
|
99
107
|
const result = NestableLegacy(FieldCtx).encode(value)
|
|
100
108
|
if (!result) return acc
|
|
@@ -102,14 +110,15 @@ export const CompositeSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
102
110
|
return {
|
|
103
111
|
content: { ...acc.content, [key]: result.content },
|
|
104
112
|
types: { ...acc.types, ...result.types },
|
|
113
|
+
keys: { ...acc.keys, ...result.keys },
|
|
105
114
|
}
|
|
106
115
|
},
|
|
107
|
-
{ content: {}, types: {} },
|
|
116
|
+
{ content: {}, types: {}, keys: {} },
|
|
108
117
|
)
|
|
109
118
|
|
|
110
119
|
const repeat =
|
|
111
120
|
(() => {
|
|
112
|
-
const itemsCtx = getFieldCtx("repeat", ctx)
|
|
121
|
+
const itemsCtx = getFieldCtx({ fieldKey: "repeat", ctx })
|
|
113
122
|
const result = RepeatableWidgetsLegacy(itemsCtx).encode(s.repeat)
|
|
114
123
|
return result
|
|
115
124
|
})() || []
|
|
@@ -124,6 +133,10 @@ export const CompositeSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
124
133
|
...nonRepeat.types,
|
|
125
134
|
...repeat.reduce((acc, i) => ({ ...acc, ...i.types }), {}),
|
|
126
135
|
},
|
|
136
|
+
keys: {
|
|
137
|
+
...nonRepeat.keys,
|
|
138
|
+
...repeat.reduce((acc, i) => ({ ...acc, ...i.keys }), {}),
|
|
139
|
+
},
|
|
127
140
|
}
|
|
128
141
|
},
|
|
129
142
|
)
|
|
@@ -260,6 +273,7 @@ export function migrateCompositeSlice(
|
|
|
260
273
|
items: content.widget.repeat.map((groupItem) => {
|
|
261
274
|
return {
|
|
262
275
|
__TYPE__: "GroupItemContent",
|
|
276
|
+
key: groupItem.key,
|
|
263
277
|
value: groupItem.value.reduce<GroupItemContent["value"]>(
|
|
264
278
|
(acc, [fieldKey, fieldContent]) => {
|
|
265
279
|
if (!model.fields.items?.[fieldKey]) {
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import type { LegacyContentCtx } from "../../../LegacyContentCtx"
|
|
3
|
+
import type { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx"
|
|
4
4
|
import {
|
|
5
|
+
arrayWithIndexCodec,
|
|
5
6
|
GroupContent,
|
|
7
|
+
GroupItemContent,
|
|
6
8
|
GroupItemContentType,
|
|
7
9
|
GroupItemLegacy,
|
|
8
10
|
} from "../../GroupContent"
|
|
9
11
|
import { NestableContent } from "../../nestable"
|
|
10
12
|
|
|
11
13
|
export const RepeatableWidgetsLegacy = (ctx: LegacyContentCtx) => {
|
|
12
|
-
return
|
|
14
|
+
return arrayWithIndexCodec<GroupItemContent, WithTypes<GroupItemLegacy>>(
|
|
15
|
+
(index) => GroupItemLegacy(ctx, index),
|
|
16
|
+
)
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
const RepeatableWidget = t.tuple([
|
|
@@ -18,6 +22,7 @@ const RepeatableWidget = t.tuple([
|
|
|
18
22
|
])
|
|
19
23
|
const RepeatableWidgetsBlock = t.strict({
|
|
20
24
|
__TYPE__: t.literal(GroupItemContentType),
|
|
25
|
+
key: t.string,
|
|
21
26
|
value: t.array(RepeatableWidget),
|
|
22
27
|
})
|
|
23
28
|
|
|
@@ -68,10 +68,11 @@ export const SharedSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
68
68
|
either.map((parsedSlice) => {
|
|
69
69
|
const items =
|
|
70
70
|
(() => {
|
|
71
|
-
const itemsCtx = getFieldCtx(
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
const itemsCtx = getFieldCtx({
|
|
72
|
+
fieldKey: "items",
|
|
73
|
+
ctx,
|
|
74
|
+
prefixes: ["variations", parsedSlice.variation],
|
|
75
|
+
})
|
|
75
76
|
const result = RepeatableWidgetsLegacy(itemsCtx).decode(
|
|
76
77
|
parsedSlice.items,
|
|
77
78
|
)
|
|
@@ -82,11 +83,11 @@ export const SharedSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
82
83
|
const primary = Object.entries(parsedSlice.primary).reduce<
|
|
83
84
|
Record<string, SlicePrimaryContent>
|
|
84
85
|
>((acc, [key, value]) => {
|
|
85
|
-
const FieldCtx = getFieldCtx(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
"primary",
|
|
89
|
-
|
|
86
|
+
const FieldCtx = getFieldCtx({
|
|
87
|
+
fieldKey: key,
|
|
88
|
+
ctx,
|
|
89
|
+
prefixes: ["variations", parsedSlice.variation, "primary"],
|
|
90
|
+
})
|
|
90
91
|
|
|
91
92
|
const result = SlicePrimaryLegacy(FieldCtx).decode(value)
|
|
92
93
|
if (!result) return acc
|
|
@@ -109,11 +110,11 @@ export const SharedSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
109
110
|
WithTypes<Record<string, unknown>>
|
|
110
111
|
>(
|
|
111
112
|
(acc, [key, value]) => {
|
|
112
|
-
const FieldCtx = getFieldCtx(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
"primary",
|
|
116
|
-
|
|
113
|
+
const FieldCtx = getFieldCtx({
|
|
114
|
+
fieldKey: key,
|
|
115
|
+
ctx,
|
|
116
|
+
prefixes: ["variations", s.variation, "primary"],
|
|
117
|
+
})
|
|
117
118
|
|
|
118
119
|
const result = SlicePrimaryLegacy(FieldCtx).encode(value)
|
|
119
120
|
if (!result) return acc
|
|
@@ -121,17 +122,19 @@ export const SharedSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
121
122
|
return {
|
|
122
123
|
content: { ...acc.content, [key]: result.content },
|
|
123
124
|
types: { ...acc.types, ...result.types },
|
|
125
|
+
keys: { ...acc.keys, ...result.keys },
|
|
124
126
|
}
|
|
125
127
|
},
|
|
126
|
-
{ content: {}, types: {} },
|
|
128
|
+
{ content: {}, types: {}, keys: {} },
|
|
127
129
|
)
|
|
128
130
|
|
|
129
131
|
const items =
|
|
130
132
|
(() => {
|
|
131
|
-
const itemsCtx = getFieldCtx(
|
|
132
|
-
"
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
const itemsCtx = getFieldCtx({
|
|
134
|
+
fieldKey: "items",
|
|
135
|
+
ctx,
|
|
136
|
+
prefixes: ["variations", s.variation],
|
|
137
|
+
})
|
|
135
138
|
const result = RepeatableWidgetsLegacy(itemsCtx).encode(s.items)
|
|
136
139
|
return result
|
|
137
140
|
})() || []
|
|
@@ -147,6 +150,10 @@ export const SharedSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
147
150
|
...primary.types,
|
|
148
151
|
...items.reduce((acc, i) => ({ ...acc, ...i.types }), {}),
|
|
149
152
|
},
|
|
153
|
+
keys: {
|
|
154
|
+
...primary.keys,
|
|
155
|
+
...items.reduce((acc, i) => ({ ...acc, ...i.keys }), {}),
|
|
156
|
+
},
|
|
150
157
|
}
|
|
151
158
|
},
|
|
152
159
|
)
|
|
@@ -150,6 +150,7 @@ export function migrateSimpleSlice(
|
|
|
150
150
|
items: content.widget.value.map((groupItem) => {
|
|
151
151
|
return {
|
|
152
152
|
__TYPE__: "GroupItemContent",
|
|
153
|
+
key: groupItem.key,
|
|
153
154
|
value: groupItem.value.reduce<GroupItemContent["value"]>(
|
|
154
155
|
(acc, [fieldKey, fieldContent]) => {
|
|
155
156
|
return model.fields.items?.[fieldKey]
|
|
@@ -115,7 +115,7 @@ const itemLegacyReader = t.exact(
|
|
|
115
115
|
]),
|
|
116
116
|
)
|
|
117
117
|
|
|
118
|
-
type SliceItemLegacy = t.TypeOf<typeof itemLegacyReader>
|
|
118
|
+
export type SliceItemLegacy = t.TypeOf<typeof itemLegacyReader>
|
|
119
119
|
|
|
120
120
|
export const SlicesItemLegacy = (ctx: LegacyContentCtx) => {
|
|
121
121
|
return new t.Type<SliceItemContent, WithTypes<SliceItemLegacy>, unknown>(
|
|
@@ -134,7 +134,11 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx) => {
|
|
|
134
134
|
0,
|
|
135
135
|
stopIdx > 0 ? stopIdx : undefined,
|
|
136
136
|
)
|
|
137
|
-
const itemCtx = getFieldCtx(
|
|
137
|
+
const itemCtx = getFieldCtx({
|
|
138
|
+
fieldKey: sliceName,
|
|
139
|
+
contentKey: parsedSlice.key,
|
|
140
|
+
ctx,
|
|
141
|
+
})
|
|
138
142
|
const item = SliceLegacy(itemCtx).decode(parsedSlice.value)
|
|
139
143
|
if (!item || isLeft(item)) return t.failure(sliceItem, context)
|
|
140
144
|
|
|
@@ -148,7 +152,11 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx) => {
|
|
|
148
152
|
)
|
|
149
153
|
},
|
|
150
154
|
(sItem: SliceItemContent) => {
|
|
151
|
-
const itemCtx = getFieldCtx(
|
|
155
|
+
const itemCtx = getFieldCtx({
|
|
156
|
+
fieldKey: sItem.name,
|
|
157
|
+
contentKey: sItem.key,
|
|
158
|
+
ctx,
|
|
159
|
+
})
|
|
152
160
|
const result = SliceLegacy(itemCtx).encode(sItem.widget)
|
|
153
161
|
|
|
154
162
|
return {
|
|
@@ -158,6 +166,7 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx) => {
|
|
|
158
166
|
value: result?.content || {},
|
|
159
167
|
},
|
|
160
168
|
types: result?.types || {},
|
|
169
|
+
keys: result?.keys || {},
|
|
161
170
|
}
|
|
162
171
|
},
|
|
163
172
|
)
|
|
@@ -46,7 +46,6 @@ type SlicesLegacy = Array<unknown>
|
|
|
46
46
|
|
|
47
47
|
export const SlicesLegacy = (ctx: LegacyContentCtx) => {
|
|
48
48
|
const codec = t.array(SlicesItemLegacy(ctx))
|
|
49
|
-
|
|
50
49
|
return new t.Type<SlicesContent, WithTypes<SlicesLegacy>, unknown>(
|
|
51
50
|
"SlicesLegacy",
|
|
52
51
|
isSlicesContent,
|
|
@@ -70,6 +69,10 @@ export const SlicesLegacy = (ctx: LegacyContentCtx) => {
|
|
|
70
69
|
(acc, s) => ({ ...acc, ...s.types }),
|
|
71
70
|
{ [ctx.keyOfType]: "Slices" },
|
|
72
71
|
),
|
|
72
|
+
keys: result.reduce<Record<string, string>>(
|
|
73
|
+
(acc, s) => ({ ...acc, ...s.keys }),
|
|
74
|
+
{},
|
|
75
|
+
),
|
|
73
76
|
}
|
|
74
77
|
},
|
|
75
78
|
)
|
|
@@ -261,20 +261,17 @@ export function traverseCustomType<
|
|
|
261
261
|
}): T {
|
|
262
262
|
const { customType, onField } = args
|
|
263
263
|
|
|
264
|
-
|
|
264
|
+
const json: Record<string, typeof customType.json[string]> = {}
|
|
265
265
|
for (const [key, section] of Object.entries(customType.json)) {
|
|
266
|
-
|
|
266
|
+
json[key] = traverseSection({
|
|
267
267
|
path: [key],
|
|
268
268
|
section,
|
|
269
269
|
onField,
|
|
270
270
|
})
|
|
271
|
-
|
|
272
|
-
if (newSection !== section) {
|
|
273
|
-
if (!json) json = { ...customType.json }
|
|
274
|
-
json[key] = newSection
|
|
275
|
-
}
|
|
276
271
|
}
|
|
277
272
|
|
|
278
|
-
|
|
279
|
-
|
|
273
|
+
return {
|
|
274
|
+
...customType,
|
|
275
|
+
json,
|
|
276
|
+
}
|
|
280
277
|
}
|
|
@@ -52,7 +52,7 @@ export function traverseSection<
|
|
|
52
52
|
}): T {
|
|
53
53
|
const { path: prevPath, section: prevSection, onField } = args
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const section = { ...prevSection }
|
|
56
56
|
for (const [key, prevModel] of Object.entries(prevSection)) {
|
|
57
57
|
const path = [...prevPath, key]
|
|
58
58
|
let model
|
|
@@ -84,13 +84,7 @@ export function traverseSection<
|
|
|
84
84
|
})
|
|
85
85
|
break
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
if (model !== prevModel) {
|
|
89
|
-
if (!section) section = { ...prevSection }
|
|
90
|
-
section[key] = model
|
|
91
|
-
}
|
|
87
|
+
section[key] = model
|
|
92
88
|
}
|
|
93
|
-
|
|
94
|
-
// returns the traversed model instead of a new one if it didn't change
|
|
95
|
-
return section ?? prevSection
|
|
89
|
+
return section
|
|
96
90
|
}
|
|
@@ -58,23 +58,23 @@ export function traverseNestedGroup(args: {
|
|
|
58
58
|
|
|
59
59
|
if (!group.config?.fields) return group
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
for (const [key,
|
|
61
|
+
const fields: Record<string, NestableWidget> = {}
|
|
62
|
+
for (const [key, prevField] of Object.entries(group.config.fields)) {
|
|
63
63
|
const path = [...prevPath, key]
|
|
64
|
-
|
|
64
|
+
fields[key] = onField({
|
|
65
65
|
path,
|
|
66
66
|
key,
|
|
67
|
-
field,
|
|
67
|
+
field: prevField,
|
|
68
68
|
})
|
|
69
|
-
|
|
70
|
-
if (field !== newField) {
|
|
71
|
-
if (!fields) fields = { ...group.config.fields }
|
|
72
|
-
fields[key] = newField
|
|
73
|
-
}
|
|
74
69
|
}
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
return {
|
|
72
|
+
...group,
|
|
73
|
+
config: {
|
|
74
|
+
...group.config,
|
|
75
|
+
fields,
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export function traverseGroup(args: {
|
|
@@ -86,7 +86,7 @@ export function traverseGroup(args: {
|
|
|
86
86
|
|
|
87
87
|
if (!group.config?.fields) return group
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
const fields: Record<string, NestableWidget | NestedGroup> = {}
|
|
90
90
|
for (const [key, prevField] of Object.entries(group.config.fields)) {
|
|
91
91
|
const path = [...prevPath, key]
|
|
92
92
|
let field
|
|
@@ -102,19 +102,18 @@ export function traverseGroup(args: {
|
|
|
102
102
|
field = prevField
|
|
103
103
|
break
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
const newField = onField({
|
|
105
|
+
fields[key] = onField({
|
|
107
106
|
path,
|
|
108
107
|
key,
|
|
109
108
|
field,
|
|
110
109
|
})
|
|
111
|
-
|
|
112
|
-
if (field !== newField) {
|
|
113
|
-
if (!fields) fields = { ...group.config.fields }
|
|
114
|
-
fields[key] = newField
|
|
115
|
-
}
|
|
116
110
|
}
|
|
117
111
|
|
|
118
|
-
|
|
119
|
-
|
|
112
|
+
return {
|
|
113
|
+
...group,
|
|
114
|
+
config: {
|
|
115
|
+
...group.config,
|
|
116
|
+
fields,
|
|
117
|
+
},
|
|
118
|
+
}
|
|
120
119
|
}
|
|
@@ -46,34 +46,21 @@ export function traverseCompositeSlice(args: {
|
|
|
46
46
|
}): CompositeSlice {
|
|
47
47
|
const { path: prevPath, slice, onField } = args
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
const nonRepeat: Record<string, NestableWidget> = {}
|
|
50
50
|
for (const [key, field] of Object.entries(slice["non-repeat"] ?? {})) {
|
|
51
51
|
const path = [...prevPath, "non-repeat", key]
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (field !== newField) {
|
|
55
|
-
if (!nonRepeat) nonRepeat = { ...slice["non-repeat"] }
|
|
56
|
-
nonRepeat[key] = newField
|
|
57
|
-
}
|
|
52
|
+
nonRepeat[key] = onField({ path, key, field })
|
|
58
53
|
}
|
|
59
54
|
|
|
60
|
-
|
|
55
|
+
const repeat: Record<string, NestableWidget> = {}
|
|
61
56
|
for (const [key, field] of Object.entries(slice.repeat ?? {})) {
|
|
62
57
|
const path = [...prevPath, "repeat", key]
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (field !== newField) {
|
|
66
|
-
if (!repeat) repeat = { ...slice.repeat }
|
|
67
|
-
repeat[key] = newField
|
|
68
|
-
}
|
|
58
|
+
repeat[key] = onField({ path, key, field })
|
|
69
59
|
}
|
|
70
60
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
...(repeat && { repeat }),
|
|
77
|
-
}
|
|
78
|
-
: slice
|
|
61
|
+
return {
|
|
62
|
+
...slice,
|
|
63
|
+
...(slice["non-repeat"] && { "non-repeat": nonRepeat }),
|
|
64
|
+
...(slice.repeat && { repeat }),
|
|
65
|
+
}
|
|
79
66
|
}
|
|
@@ -79,7 +79,7 @@ export function traverseVariation(args: {
|
|
|
79
79
|
}): Variation {
|
|
80
80
|
const { path: prevPath, variation, onField } = args
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
const primary: Record<string, NestableWidget | Group> = {}
|
|
83
83
|
for (const [key, prevField] of Object.entries(variation.primary ?? {})) {
|
|
84
84
|
const path = [...prevPath, "primary", key]
|
|
85
85
|
let field
|
|
@@ -95,32 +95,20 @@ export function traverseVariation(args: {
|
|
|
95
95
|
field = prevField
|
|
96
96
|
break
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
const newField = onField({ path, key, field })
|
|
100
|
-
if (field !== newField) {
|
|
101
|
-
if (!primary) primary = { ...variation.primary }
|
|
102
|
-
primary[key] = newField
|
|
103
|
-
}
|
|
98
|
+
primary[key] = onField({ path, key, field })
|
|
104
99
|
}
|
|
105
100
|
|
|
106
|
-
|
|
107
|
-
for (const [key,
|
|
101
|
+
const items: Record<string, NestableWidget> = {}
|
|
102
|
+
for (const [key, field] of Object.entries(variation.items ?? {})) {
|
|
108
103
|
const path = [...prevPath, "items", key]
|
|
109
|
-
|
|
110
|
-
path,
|
|
111
|
-
key,
|
|
112
|
-
field: prevField,
|
|
113
|
-
})
|
|
114
|
-
if (prevField !== newField) {
|
|
115
|
-
if (!items) items = { ...variation.items }
|
|
116
|
-
items[key] = newField
|
|
117
|
-
}
|
|
104
|
+
items[key] = (onField as OnFieldFn<NestableWidget>)({ path, key, field })
|
|
118
105
|
}
|
|
119
106
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
107
|
+
return {
|
|
108
|
+
...variation,
|
|
109
|
+
...(variation.primary && { primary }),
|
|
110
|
+
...(variation.items && { items }),
|
|
111
|
+
}
|
|
124
112
|
}
|
|
125
113
|
|
|
126
114
|
export function traverseSharedSlice(args: {
|
|
@@ -130,23 +118,20 @@ export function traverseSharedSlice(args: {
|
|
|
130
118
|
}): SharedSlice {
|
|
131
119
|
const { path: prevPath, slice, onField } = args
|
|
132
120
|
|
|
133
|
-
|
|
134
|
-
for (
|
|
135
|
-
const variation = slice.variations[i]
|
|
136
|
-
if (!variation) continue
|
|
121
|
+
const variations: Variation[] = []
|
|
122
|
+
for (const variation of slice.variations) {
|
|
137
123
|
const path = [...prevPath, variation.id]
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (!variations) variations = [...slice.variations]
|
|
146
|
-
variations[i] = newVariation
|
|
147
|
-
}
|
|
124
|
+
variations.push(
|
|
125
|
+
traverseVariation({
|
|
126
|
+
path,
|
|
127
|
+
variation,
|
|
128
|
+
onField,
|
|
129
|
+
}),
|
|
130
|
+
)
|
|
148
131
|
}
|
|
149
132
|
|
|
150
|
-
|
|
151
|
-
|
|
133
|
+
return {
|
|
134
|
+
...slice,
|
|
135
|
+
variations,
|
|
136
|
+
}
|
|
152
137
|
}
|