@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
|
@@ -165,16 +165,18 @@ function collectSharedSlices(customType) {
|
|
|
165
165
|
exports.collectSharedSlices = collectSharedSlices;
|
|
166
166
|
function traverseCustomType(args) {
|
|
167
167
|
const { customType, onField } = args;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
168
|
+
const json = {};
|
|
169
|
+
let changed = false;
|
|
170
|
+
for (const [key, section] of Object.entries(customType.json)) {
|
|
171
|
+
const newSection = (0, Section_1.traverseSection)({
|
|
172
|
+
path: [key],
|
|
173
|
+
section,
|
|
174
|
+
onField,
|
|
175
|
+
});
|
|
176
|
+
if (!changed && newSection !== section)
|
|
177
|
+
changed = true;
|
|
178
|
+
json[key] = newSection;
|
|
179
|
+
}
|
|
180
|
+
return changed ? { ...customType, json } : customType;
|
|
179
181
|
}
|
|
180
182
|
exports.traverseCustomType = traverseCustomType;
|
|
@@ -21,9 +21,11 @@ exports.Sections = {
|
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
23
|
function traverseSection(args) {
|
|
24
|
-
const { path: prevPath, section, onField } = args;
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const { path: prevPath, section: prevSection, onField } = args;
|
|
25
|
+
const section = {};
|
|
26
|
+
let changed = false;
|
|
27
|
+
for (const [key, prevModel] of Object.entries(prevSection)) {
|
|
28
|
+
const path = [...prevPath, key];
|
|
27
29
|
let model;
|
|
28
30
|
switch (prevModel.type) {
|
|
29
31
|
case "Choice":
|
|
@@ -53,8 +55,10 @@ function traverseSection(args) {
|
|
|
53
55
|
});
|
|
54
56
|
break;
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
if (!changed && model !== prevModel)
|
|
59
|
+
changed = true;
|
|
60
|
+
section[key] = model;
|
|
61
|
+
}
|
|
62
|
+
return changed ? section : prevSection;
|
|
59
63
|
}
|
|
60
64
|
exports.traverseSection = traverseSection;
|
|
@@ -34,61 +34,71 @@ exports.Group = createGroup(t.union([NestableWidget_1.NestableWidget, exports.Ne
|
|
|
34
34
|
function traverseNestedGroup(args) {
|
|
35
35
|
var _a;
|
|
36
36
|
const { path: prevPath, group, onField } = args;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
if (!((_a = group.config) === null || _a === void 0 ? void 0 : _a.fields))
|
|
38
|
+
return group;
|
|
39
|
+
const fields = {};
|
|
40
|
+
let changed = false;
|
|
41
|
+
for (const [key, field] of Object.entries(group.config.fields)) {
|
|
42
|
+
const path = [...prevPath, key];
|
|
43
|
+
const newField = onField({
|
|
44
|
+
path,
|
|
45
|
+
key,
|
|
46
|
+
field,
|
|
47
|
+
});
|
|
48
|
+
if (!changed && field !== newField)
|
|
49
|
+
changed = true;
|
|
50
|
+
fields[key] = newField;
|
|
51
|
+
}
|
|
52
|
+
return changed
|
|
53
|
+
? {
|
|
54
|
+
...group,
|
|
50
55
|
config: {
|
|
51
56
|
...group.config,
|
|
52
|
-
|
|
57
|
+
fields,
|
|
53
58
|
},
|
|
54
|
-
}
|
|
55
|
-
|
|
59
|
+
}
|
|
60
|
+
: group;
|
|
56
61
|
}
|
|
57
62
|
exports.traverseNestedGroup = traverseNestedGroup;
|
|
58
63
|
function traverseGroup(args) {
|
|
59
64
|
var _a;
|
|
60
65
|
const { path: prevPath, group, onField } = args;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
66
|
+
if (!((_a = group.config) === null || _a === void 0 ? void 0 : _a.fields))
|
|
67
|
+
return group;
|
|
68
|
+
const fields = {};
|
|
69
|
+
let changed = false;
|
|
70
|
+
for (const [key, prevField] of Object.entries(group.config.fields)) {
|
|
71
|
+
const path = [...prevPath, key];
|
|
72
|
+
let field;
|
|
73
|
+
switch (prevField.type) {
|
|
74
|
+
case "Group":
|
|
75
|
+
field = traverseNestedGroup({
|
|
76
|
+
path,
|
|
77
|
+
group: prevField,
|
|
78
|
+
onField: onField,
|
|
79
|
+
});
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
field = prevField;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
const newField = onField({
|
|
86
|
+
path,
|
|
87
|
+
key,
|
|
88
|
+
field,
|
|
89
|
+
});
|
|
90
|
+
if (!changed && field !== newField)
|
|
91
|
+
changed = true;
|
|
92
|
+
fields[key] = newField;
|
|
93
|
+
}
|
|
94
|
+
return changed
|
|
95
|
+
? {
|
|
96
|
+
...group,
|
|
87
97
|
config: {
|
|
88
98
|
...group.config,
|
|
89
|
-
|
|
99
|
+
fields,
|
|
90
100
|
},
|
|
91
|
-
}
|
|
92
|
-
|
|
101
|
+
}
|
|
102
|
+
: group;
|
|
93
103
|
}
|
|
94
104
|
exports.traverseGroup = traverseGroup;
|
|
@@ -29,27 +29,32 @@ function isCompositeSlice(slice) {
|
|
|
29
29
|
}
|
|
30
30
|
exports.isCompositeSlice = isCompositeSlice;
|
|
31
31
|
function traverseCompositeSlice(args) {
|
|
32
|
+
var _a, _b;
|
|
32
33
|
const { path: prevPath, slice, onField } = args;
|
|
33
|
-
const nonRepeat =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
const nonRepeat = {};
|
|
35
|
+
let nonRepeatChanged = false;
|
|
36
|
+
for (const [key, field] of Object.entries((_a = slice["non-repeat"]) !== null && _a !== void 0 ? _a : {})) {
|
|
37
|
+
const path = [...prevPath, "non-repeat", key];
|
|
38
|
+
const newField = onField({ path, key, field });
|
|
39
|
+
if (!nonRepeatChanged && field !== newField)
|
|
40
|
+
nonRepeatChanged = true;
|
|
41
|
+
nonRepeat[key] = newField;
|
|
42
|
+
}
|
|
43
|
+
const repeat = {};
|
|
44
|
+
let repeatChanged = false;
|
|
45
|
+
for (const [key, field] of Object.entries((_b = slice.repeat) !== null && _b !== void 0 ? _b : {})) {
|
|
46
|
+
const path = [...prevPath, "repeat", key];
|
|
47
|
+
const newField = onField({ path, key, field });
|
|
48
|
+
if (!repeatChanged && field !== newField)
|
|
49
|
+
repeatChanged = true;
|
|
50
|
+
repeat[key] = newField;
|
|
51
|
+
}
|
|
52
|
+
return nonRepeatChanged || repeatChanged
|
|
53
|
+
? {
|
|
54
|
+
...slice,
|
|
55
|
+
...(nonRepeatChanged && { "non-repeat": nonRepeat }),
|
|
56
|
+
...(repeatChanged && { repeat }),
|
|
57
|
+
}
|
|
58
|
+
: slice;
|
|
54
59
|
}
|
|
55
60
|
exports.traverseCompositeSlice = traverseCompositeSlice;
|
|
@@ -48,59 +48,72 @@ function isDynamicSharedSlice(slice) {
|
|
|
48
48
|
}
|
|
49
49
|
exports.isDynamicSharedSlice = isDynamicSharedSlice;
|
|
50
50
|
function traverseVariation(args) {
|
|
51
|
+
var _a, _b;
|
|
51
52
|
const { path: prevPath, variation, onField } = args;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
field = (0, Group_1.traverseGroup)({
|
|
61
|
-
path,
|
|
62
|
-
group: prevField,
|
|
63
|
-
onField: onField,
|
|
64
|
-
});
|
|
65
|
-
break;
|
|
66
|
-
default:
|
|
67
|
-
field = prevField;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
acc[key] = onField({
|
|
53
|
+
const primary = {};
|
|
54
|
+
let primaryChanged = false;
|
|
55
|
+
for (const [key, prevField] of Object.entries((_a = variation.primary) !== null && _a !== void 0 ? _a : {})) {
|
|
56
|
+
const path = [...prevPath, "primary", key];
|
|
57
|
+
let field;
|
|
58
|
+
switch (prevField.type) {
|
|
59
|
+
case "Group":
|
|
60
|
+
field = (0, Group_1.traverseGroup)({
|
|
71
61
|
path,
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
group: prevField,
|
|
63
|
+
onField: onField,
|
|
74
64
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
field = prevField;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
const newField = onField({ path, key, field });
|
|
71
|
+
if (!primaryChanged && field !== newField)
|
|
72
|
+
primaryChanged = true;
|
|
73
|
+
primary[key] = newField;
|
|
74
|
+
}
|
|
75
|
+
const items = {};
|
|
76
|
+
let itemsChanged = false;
|
|
77
|
+
for (const [key, prevField] of Object.entries((_b = variation.items) !== null && _b !== void 0 ? _b : {})) {
|
|
78
|
+
const path = [...prevPath, "items", key];
|
|
79
|
+
const newField = onField({
|
|
80
|
+
path,
|
|
81
|
+
key,
|
|
82
|
+
field: prevField,
|
|
83
|
+
});
|
|
84
|
+
if (!itemsChanged && prevField !== newField)
|
|
85
|
+
itemsChanged = true;
|
|
86
|
+
items[key] = newField;
|
|
87
|
+
}
|
|
88
|
+
return primaryChanged || itemsChanged
|
|
89
|
+
? {
|
|
90
|
+
...variation,
|
|
91
|
+
...(primaryChanged && { primary }),
|
|
92
|
+
...(itemsChanged && { items }),
|
|
93
|
+
}
|
|
94
|
+
: variation;
|
|
90
95
|
}
|
|
91
96
|
exports.traverseVariation = traverseVariation;
|
|
92
97
|
function traverseSharedSlice(args) {
|
|
93
98
|
const { path: prevPath, slice, onField } = args;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
const variations = [];
|
|
100
|
+
let changed = false;
|
|
101
|
+
for (const variation of slice.variations) {
|
|
102
|
+
const path = [...prevPath, variation.id];
|
|
103
|
+
const newVariation = traverseVariation({
|
|
104
|
+
path,
|
|
105
|
+
variation,
|
|
106
|
+
onField,
|
|
107
|
+
});
|
|
108
|
+
if (!changed && newVariation !== variation)
|
|
109
|
+
changed = true;
|
|
110
|
+
variations.push(newVariation);
|
|
111
|
+
}
|
|
112
|
+
return changed
|
|
113
|
+
? {
|
|
114
|
+
...slice,
|
|
115
|
+
variations,
|
|
116
|
+
}
|
|
117
|
+
: slice;
|
|
105
118
|
}
|
|
106
119
|
exports.traverseSharedSlice = traverseSharedSlice;
|
|
@@ -82,59 +82,63 @@ exports.Slices = {
|
|
|
82
82
|
function traverseSlices(args) {
|
|
83
83
|
var _a;
|
|
84
84
|
const { path: prevPath, slices, onField } = args;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
if (!((_a = slices.config) === null || _a === void 0 ? void 0 : _a.choices))
|
|
86
|
+
return slices;
|
|
87
|
+
const choices = {};
|
|
88
|
+
let changed = false;
|
|
89
|
+
for (const [key, prevModel] of Object.entries(slices.config.choices)) {
|
|
90
|
+
const path = [...prevPath, key];
|
|
91
|
+
let model;
|
|
92
|
+
switch (prevModel.type) {
|
|
93
|
+
case "Slice":
|
|
94
|
+
model = (0, CompositeSlice_1.traverseCompositeSlice)({
|
|
95
|
+
path,
|
|
96
|
+
slice: prevModel,
|
|
97
|
+
onField: onField,
|
|
98
|
+
});
|
|
99
|
+
break;
|
|
100
|
+
case "SharedSlice":
|
|
101
|
+
if ("variations" in prevModel)
|
|
102
|
+
model = (0, SharedSlice_1.traverseSharedSlice)({
|
|
92
103
|
path,
|
|
93
104
|
slice: prevModel,
|
|
94
|
-
onField
|
|
95
|
-
});
|
|
96
|
-
break;
|
|
97
|
-
case "SharedSlice":
|
|
98
|
-
if ("variations" in prevModel)
|
|
99
|
-
model = (0, SharedSlice_1.traverseSharedSlice)({
|
|
100
|
-
path,
|
|
101
|
-
slice: prevModel,
|
|
102
|
-
onField,
|
|
103
|
-
});
|
|
104
|
-
else
|
|
105
|
-
model = prevModel;
|
|
106
|
-
break;
|
|
107
|
-
// Group and other fields are technically possible because of legacy slices.
|
|
108
|
-
case "Group":
|
|
109
|
-
model = onField({
|
|
110
|
-
path,
|
|
111
|
-
key,
|
|
112
|
-
field: (0, Group_1.traverseNestedGroup)({
|
|
113
|
-
path,
|
|
114
|
-
group: prevModel,
|
|
115
|
-
onField: onField,
|
|
116
|
-
}),
|
|
105
|
+
onField,
|
|
117
106
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
107
|
+
else
|
|
108
|
+
model = prevModel;
|
|
109
|
+
break;
|
|
110
|
+
// Group and other fields are technically possible because of legacy slices.
|
|
111
|
+
case "Group":
|
|
112
|
+
model = onField({
|
|
113
|
+
path,
|
|
114
|
+
key,
|
|
115
|
+
field: (0, Group_1.traverseNestedGroup)({
|
|
121
116
|
path,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
group: prevModel,
|
|
118
|
+
onField: onField,
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
model = onField({
|
|
124
|
+
path,
|
|
125
|
+
key,
|
|
126
|
+
field: prevModel,
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
if (!changed && model !== prevModel)
|
|
131
|
+
changed = true;
|
|
132
|
+
choices[key] = model;
|
|
133
|
+
}
|
|
134
|
+
return changed
|
|
135
|
+
? {
|
|
136
|
+
...slices,
|
|
133
137
|
config: {
|
|
134
138
|
...slices.config,
|
|
135
|
-
|
|
139
|
+
choices,
|
|
136
140
|
},
|
|
137
|
-
}
|
|
138
|
-
|
|
141
|
+
}
|
|
142
|
+
: slices;
|
|
139
143
|
}
|
|
140
144
|
exports.traverseSlices = traverseSlices;
|
package/package.json
CHANGED
|
@@ -260,17 +260,18 @@ export function traverseCustomType<
|
|
|
260
260
|
onField: OnFieldFn<UID | NestableWidget | Group | NestedGroup>
|
|
261
261
|
}): T {
|
|
262
262
|
const { customType, onField } = args
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}, {}),
|
|
263
|
+
|
|
264
|
+
const json: Record<string, typeof customType.json[string]> = {}
|
|
265
|
+
let changed = false
|
|
266
|
+
for (const [key, section] of Object.entries(customType.json)) {
|
|
267
|
+
const newSection = traverseSection({
|
|
268
|
+
path: [key],
|
|
269
|
+
section,
|
|
270
|
+
onField,
|
|
271
|
+
})
|
|
272
|
+
if (!changed && newSection !== section) changed = true
|
|
273
|
+
json[key] = newSection
|
|
275
274
|
}
|
|
275
|
+
|
|
276
|
+
return changed ? { ...customType, json } : customType
|
|
276
277
|
}
|
|
@@ -50,9 +50,12 @@ export function traverseSection<
|
|
|
50
50
|
section: T
|
|
51
51
|
onField: OnFieldFn<UID | NestableWidget | Group | NestedGroup>
|
|
52
52
|
}): T {
|
|
53
|
-
const { path: prevPath, section, onField } = args
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const { path: prevPath, section: prevSection, onField } = args
|
|
54
|
+
|
|
55
|
+
const section: T = {} as T
|
|
56
|
+
let changed = false
|
|
57
|
+
for (const [key, prevModel] of Object.entries(prevSection)) {
|
|
58
|
+
const path = [...prevPath, key]
|
|
56
59
|
let model
|
|
57
60
|
switch (prevModel.type) {
|
|
58
61
|
case "Choice":
|
|
@@ -82,7 +85,9 @@ export function traverseSection<
|
|
|
82
85
|
})
|
|
83
86
|
break
|
|
84
87
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
+
if (!changed && model !== prevModel) changed = true
|
|
89
|
+
section[key] = model
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return changed ? section : prevSection
|
|
88
93
|
}
|
|
@@ -55,29 +55,32 @@ export function traverseNestedGroup(args: {
|
|
|
55
55
|
onField: OnFieldFn<NestableWidget>
|
|
56
56
|
}): NestedGroup {
|
|
57
57
|
const { path: prevPath, group, onField } = args
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
...group,
|
|
74
|
-
...(group.config && {
|
|
75
|
-
config: {
|
|
76
|
-
...group.config,
|
|
77
|
-
...(fields && { fields }),
|
|
78
|
-
},
|
|
79
|
-
}),
|
|
58
|
+
|
|
59
|
+
if (!group.config?.fields) return group
|
|
60
|
+
|
|
61
|
+
const fields: Record<string, NestableWidget> = {}
|
|
62
|
+
let changed = false
|
|
63
|
+
for (const [key, field] of Object.entries(group.config.fields)) {
|
|
64
|
+
const path = [...prevPath, key]
|
|
65
|
+
const newField = onField({
|
|
66
|
+
path,
|
|
67
|
+
key,
|
|
68
|
+
field,
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
if (!changed && field !== newField) changed = true
|
|
72
|
+
fields[key] = newField
|
|
80
73
|
}
|
|
74
|
+
|
|
75
|
+
return changed
|
|
76
|
+
? {
|
|
77
|
+
...group,
|
|
78
|
+
config: {
|
|
79
|
+
...group.config,
|
|
80
|
+
fields,
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
: group
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
export function traverseGroup(args: {
|
|
@@ -86,39 +89,43 @@ export function traverseGroup(args: {
|
|
|
86
89
|
onField: OnFieldFn<NestableWidget | NestedGroup>
|
|
87
90
|
}): Group {
|
|
88
91
|
const { path: prevPath, group, onField } = args
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
...(group.config && {
|
|
118
|
-
config: {
|
|
119
|
-
...group.config,
|
|
120
|
-
...(fields && { fields }),
|
|
121
|
-
},
|
|
122
|
-
}),
|
|
92
|
+
|
|
93
|
+
if (!group.config?.fields) return group
|
|
94
|
+
|
|
95
|
+
const fields: Record<string, NestableWidget | NestedGroup> = {}
|
|
96
|
+
let changed = false
|
|
97
|
+
for (const [key, prevField] of Object.entries(group.config.fields)) {
|
|
98
|
+
const path = [...prevPath, key]
|
|
99
|
+
let field
|
|
100
|
+
switch (prevField.type) {
|
|
101
|
+
case "Group":
|
|
102
|
+
field = traverseNestedGroup({
|
|
103
|
+
path,
|
|
104
|
+
group: prevField,
|
|
105
|
+
onField: onField as OnFieldFn<NestableWidget>,
|
|
106
|
+
})
|
|
107
|
+
break
|
|
108
|
+
default:
|
|
109
|
+
field = prevField
|
|
110
|
+
break
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const newField = onField({
|
|
114
|
+
path,
|
|
115
|
+
key,
|
|
116
|
+
field,
|
|
117
|
+
})
|
|
118
|
+
if (!changed && field !== newField) changed = true
|
|
119
|
+
fields[key] = newField
|
|
123
120
|
}
|
|
121
|
+
|
|
122
|
+
return changed
|
|
123
|
+
? {
|
|
124
|
+
...group,
|
|
125
|
+
config: {
|
|
126
|
+
...group.config,
|
|
127
|
+
fields,
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
: group
|
|
124
131
|
}
|