@prismicio/types-internal 3.11.0 → 3.11.2-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/customtypes/CustomType.js +13 -11
- package/lib/customtypes/Section.js +10 -6
- package/lib/customtypes/widgets/Group.js +55 -45
- package/lib/customtypes/widgets/slices/CompositeSlice.js +26 -21
- package/lib/customtypes/widgets/slices/SharedSlice.js +60 -47
- package/lib/customtypes/widgets/slices/Slices.js +51 -47
- package/package.json +1 -1
- package/src/customtypes/CustomType.ts +13 -12
- package/src/customtypes/Section.ts +11 -6
- package/src/customtypes/widgets/Group.ts +63 -56
- package/src/customtypes/widgets/slices/CompositeSlice.ts +27 -28
- package/src/customtypes/widgets/slices/SharedSlice.ts +61 -49
- package/src/customtypes/widgets/slices/Slices.ts +55 -52
- package/lib/content/fields/nestable/RichTextContent/Block.d.ts +0 -1036
- package/lib/content/fields/nestable/RichTextContent/Block.js +0 -31
- package/lib/content/fields/nestable/RichTextContent/EmbedBlock.d.ts +0 -60
- package/lib/content/fields/nestable/RichTextContent/EmbedBlock.js +0 -53
- package/lib/content/fields/nestable/RichTextContent/ImageBlock.d.ts +0 -203
- package/lib/content/fields/nestable/RichTextContent/ImageBlock.js +0 -36
- package/lib/content/fields/nestable/RichTextContent/TableBlock.d.ts +0 -500
- package/lib/content/fields/nestable/RichTextContent/TableBlock.js +0 -21
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +0 -590
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +0 -80
|
@@ -45,33 +45,32 @@ export function traverseCompositeSlice(args: {
|
|
|
45
45
|
onField: OnFieldFn<NestableWidget>
|
|
46
46
|
}): CompositeSlice {
|
|
47
47
|
const { path: prevPath, slice, onField } = args
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)
|
|
58
|
-
const repeat =
|
|
59
|
-
slice.repeat &&
|
|
60
|
-
Object.entries(slice.repeat).reduce<Record<string, NestableWidget>>(
|
|
61
|
-
(acc, [key, field]) => {
|
|
62
|
-
const path = prevPath.concat("repeat", key)
|
|
63
|
-
acc[key] = onField({ path, key, field })
|
|
64
|
-
return acc
|
|
65
|
-
},
|
|
66
|
-
{},
|
|
67
|
-
)
|
|
68
|
-
return {
|
|
69
|
-
...slice,
|
|
70
|
-
...(nonRepeat && {
|
|
71
|
-
"non-repeat": nonRepeat,
|
|
72
|
-
}),
|
|
73
|
-
...(repeat && {
|
|
74
|
-
repeat,
|
|
75
|
-
}),
|
|
48
|
+
|
|
49
|
+
const nonRepeat: Record<string, NestableWidget> = {}
|
|
50
|
+
let nonRepeatChanged = false
|
|
51
|
+
for (const [key, field] of Object.entries(slice["non-repeat"] ?? {})) {
|
|
52
|
+
const path = [...prevPath, "non-repeat", key]
|
|
53
|
+
const newField = onField({ path, key, field })
|
|
54
|
+
|
|
55
|
+
if (!nonRepeatChanged && field !== newField) nonRepeatChanged = true
|
|
56
|
+
nonRepeat[key] = newField
|
|
76
57
|
}
|
|
58
|
+
|
|
59
|
+
const repeat: Record<string, NestableWidget> = {}
|
|
60
|
+
let repeatChanged = false
|
|
61
|
+
for (const [key, field] of Object.entries(slice.repeat ?? {})) {
|
|
62
|
+
const path = [...prevPath, "repeat", key]
|
|
63
|
+
const newField = onField({ path, key, field })
|
|
64
|
+
|
|
65
|
+
if (!repeatChanged && field !== newField) repeatChanged = true
|
|
66
|
+
repeat[key] = newField
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return nonRepeatChanged || repeatChanged
|
|
70
|
+
? {
|
|
71
|
+
...slice,
|
|
72
|
+
...(nonRepeatChanged && { "non-repeat": nonRepeat }),
|
|
73
|
+
...(repeatChanged && { repeat }),
|
|
74
|
+
}
|
|
75
|
+
: slice
|
|
77
76
|
}
|
|
@@ -78,48 +78,50 @@ export function traverseVariation(args: {
|
|
|
78
78
|
onField: OnFieldFn<NestableWidget | Group | NestedGroup>
|
|
79
79
|
}): Variation {
|
|
80
80
|
const { path: prevPath, variation, onField } = args
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
case "Group":
|
|
91
|
-
field = traverseGroup({
|
|
92
|
-
path,
|
|
93
|
-
group: prevField,
|
|
94
|
-
onField: onField as OnFieldFn<NestableWidget | NestedGroup>,
|
|
95
|
-
})
|
|
96
|
-
break
|
|
97
|
-
default:
|
|
98
|
-
field = prevField
|
|
99
|
-
break
|
|
100
|
-
}
|
|
101
|
-
acc[key] = onField({
|
|
102
|
-
path,
|
|
103
|
-
key,
|
|
104
|
-
field,
|
|
105
|
-
})
|
|
106
|
-
return acc
|
|
107
|
-
}, {}),
|
|
108
|
-
}),
|
|
109
|
-
...(variation.items && {
|
|
110
|
-
items: Object.entries(variation.items).reduce<
|
|
111
|
-
Record<string, NestableWidget>
|
|
112
|
-
>((acc, [key, field]) => {
|
|
113
|
-
const path = prevPath.concat("items", key)
|
|
114
|
-
acc[key] = (onField as OnFieldFn<NestableWidget>)({
|
|
81
|
+
|
|
82
|
+
const primary: Record<string, NestableWidget | Group> = {}
|
|
83
|
+
let primaryChanged = false
|
|
84
|
+
for (const [key, prevField] of Object.entries(variation.primary ?? {})) {
|
|
85
|
+
const path = [...prevPath, "primary", key]
|
|
86
|
+
let field
|
|
87
|
+
switch (prevField.type) {
|
|
88
|
+
case "Group":
|
|
89
|
+
field = traverseGroup({
|
|
115
90
|
path,
|
|
116
|
-
|
|
117
|
-
|
|
91
|
+
group: prevField,
|
|
92
|
+
onField: onField as OnFieldFn<NestableWidget | NestedGroup>,
|
|
118
93
|
})
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
94
|
+
break
|
|
95
|
+
default:
|
|
96
|
+
field = prevField
|
|
97
|
+
break
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const newField = onField({ path, key, field })
|
|
101
|
+
if (!primaryChanged && field !== newField) primaryChanged = true
|
|
102
|
+
primary[key] = newField
|
|
122
103
|
}
|
|
104
|
+
|
|
105
|
+
const items: Record<string, NestableWidget> = {}
|
|
106
|
+
let itemsChanged = false
|
|
107
|
+
for (const [key, prevField] of Object.entries(variation.items ?? {})) {
|
|
108
|
+
const path = [...prevPath, "items", key]
|
|
109
|
+
const newField = (onField as OnFieldFn<NestableWidget>)({
|
|
110
|
+
path,
|
|
111
|
+
key,
|
|
112
|
+
field: prevField,
|
|
113
|
+
})
|
|
114
|
+
if (!itemsChanged && prevField !== newField) itemsChanged = true
|
|
115
|
+
items[key] = newField
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return primaryChanged || itemsChanged
|
|
119
|
+
? {
|
|
120
|
+
...variation,
|
|
121
|
+
...(primaryChanged && { primary }),
|
|
122
|
+
...(itemsChanged && { items }),
|
|
123
|
+
}
|
|
124
|
+
: variation
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
export function traverseSharedSlice(args: {
|
|
@@ -128,15 +130,25 @@ export function traverseSharedSlice(args: {
|
|
|
128
130
|
onField: OnFieldFn<NestableWidget | Group | NestedGroup>
|
|
129
131
|
}): SharedSlice {
|
|
130
132
|
const { path: prevPath, slice, onField } = args
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
})
|
|
133
|
+
|
|
134
|
+
const variations: Variation[] = []
|
|
135
|
+
let changed = false
|
|
136
|
+
for (const variation of slice.variations) {
|
|
137
|
+
const path = [...prevPath, variation.id]
|
|
138
|
+
const newVariation = traverseVariation({
|
|
139
|
+
path,
|
|
140
|
+
variation,
|
|
141
|
+
onField,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
if (!changed && newVariation !== variation) changed = true
|
|
145
|
+
variations.push(newVariation)
|
|
141
146
|
}
|
|
147
|
+
|
|
148
|
+
return changed
|
|
149
|
+
? {
|
|
150
|
+
...slice,
|
|
151
|
+
variations,
|
|
152
|
+
}
|
|
153
|
+
: slice
|
|
142
154
|
}
|
|
@@ -120,60 +120,63 @@ export function traverseSlices<T extends DynamicSlices | StaticSlices>(args: {
|
|
|
120
120
|
onField: OnFieldFn<NestableWidget | Group | NestedGroup>
|
|
121
121
|
}): T {
|
|
122
122
|
const { path: prevPath, slices, onField } = args
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
slice: prevModel as SharedSlice,
|
|
143
|
-
onField,
|
|
144
|
-
})
|
|
145
|
-
else model = prevModel
|
|
146
|
-
break
|
|
147
|
-
// Group and other fields are technically possible because of legacy slices.
|
|
148
|
-
case "Group":
|
|
149
|
-
model = onField({
|
|
123
|
+
|
|
124
|
+
if (!slices.config?.choices) return slices
|
|
125
|
+
|
|
126
|
+
const choices: Record<string, typeof slices.config.choices[string]> = {}
|
|
127
|
+
let changed = false
|
|
128
|
+
for (const [key, prevModel] of Object.entries(slices.config.choices)) {
|
|
129
|
+
const path = [...prevPath, key]
|
|
130
|
+
let model
|
|
131
|
+
switch (prevModel.type) {
|
|
132
|
+
case "Slice":
|
|
133
|
+
model = traverseCompositeSlice({
|
|
134
|
+
path,
|
|
135
|
+
slice: prevModel,
|
|
136
|
+
onField: onField as OnFieldFn<NestableWidget>,
|
|
137
|
+
})
|
|
138
|
+
break
|
|
139
|
+
case "SharedSlice":
|
|
140
|
+
if ("variations" in prevModel)
|
|
141
|
+
model = traverseSharedSlice({
|
|
150
142
|
path,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
path,
|
|
154
|
-
group: prevModel,
|
|
155
|
-
onField: onField as OnFieldFn<NestableWidget>,
|
|
156
|
-
}),
|
|
143
|
+
slice: prevModel as SharedSlice,
|
|
144
|
+
onField,
|
|
157
145
|
})
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
146
|
+
else model = prevModel
|
|
147
|
+
break
|
|
148
|
+
// Group and other fields are technically possible because of legacy slices.
|
|
149
|
+
case "Group":
|
|
150
|
+
model = onField({
|
|
151
|
+
path,
|
|
152
|
+
key,
|
|
153
|
+
field: traverseNestedGroup({
|
|
161
154
|
path,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
155
|
+
group: prevModel,
|
|
156
|
+
onField: onField as OnFieldFn<NestableWidget>,
|
|
157
|
+
}),
|
|
158
|
+
})
|
|
159
|
+
break
|
|
160
|
+
default:
|
|
161
|
+
model = onField({
|
|
162
|
+
path,
|
|
163
|
+
key,
|
|
164
|
+
field: prevModel,
|
|
165
|
+
})
|
|
166
|
+
break
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!changed && model !== prevModel) changed = true
|
|
170
|
+
choices[key] = model as typeof slices.config.choices[string]
|
|
178
171
|
}
|
|
172
|
+
|
|
173
|
+
return changed
|
|
174
|
+
? {
|
|
175
|
+
...slices,
|
|
176
|
+
config: {
|
|
177
|
+
...slices.config,
|
|
178
|
+
choices,
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
: slices
|
|
179
182
|
}
|