@prismicio/types-internal 3.10.2-alpha.2 → 3.10.2-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/content/Document.js +23 -34
- package/lib/customtypes/CustomType.js +13 -26
- package/lib/customtypes/Section.js +37 -44
- package/lib/customtypes/widgets/Group.js +65 -103
- package/lib/customtypes/widgets/slices/SharedSlice.js +47 -98
- package/package.json +1 -1
- package/src/content/Document.ts +31 -41
- package/src/customtypes/CustomType.ts +13 -30
- package/src/customtypes/Section.ts +39 -46
- package/src/customtypes/widgets/Group.ts +72 -111
- package/src/customtypes/widgets/slices/SharedSlice.ts +51 -108
package/lib/content/Document.js
CHANGED
|
@@ -107,43 +107,32 @@ function fillDocumentWithDefaultValues(customType, document) {
|
|
|
107
107
|
const { fields } = customType && customtypes_1.StaticCustomType.is(customType)
|
|
108
108
|
? simplifyCustomType(customType)
|
|
109
109
|
: customType;
|
|
110
|
-
|
|
111
|
-
const result = { ...document };
|
|
112
|
-
// Process fields from the custom type
|
|
113
|
-
const fieldKeys = Object.keys(fields);
|
|
114
|
-
for (let i = 0; i < fieldKeys.length; i++) {
|
|
115
|
-
const fieldKey = fieldKeys[i];
|
|
116
|
-
if (!fieldKey)
|
|
117
|
-
continue;
|
|
118
|
-
const fieldDef = fields[fieldKey];
|
|
119
|
-
if (!fieldDef)
|
|
120
|
-
continue;
|
|
110
|
+
return Object.entries(fields).reduce((updatedDocument, [fieldKey, fieldDef]) => {
|
|
121
111
|
const fieldContent = document[fieldKey];
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
default:
|
|
136
|
-
updatedField =
|
|
137
|
-
fieldContent === undefined && customtypes_1.NestableWidget.is(fieldDef)
|
|
112
|
+
const updatedField = (() => {
|
|
113
|
+
switch (fieldDef.type) {
|
|
114
|
+
case "Group":
|
|
115
|
+
return (0, fields_1.isGroupContent)(fieldContent)
|
|
116
|
+
? (0, fields_1.groupContentWithDefaultValues)(fieldDef, fieldContent)
|
|
117
|
+
: fieldContent;
|
|
118
|
+
case "Choice":
|
|
119
|
+
case "Slices":
|
|
120
|
+
return (0, fields_1.isSlicesContent)(fieldContent)
|
|
121
|
+
? (0, fields_1.slicesContentWithDefaultValues)(fieldDef, fieldContent)
|
|
122
|
+
: fieldContent;
|
|
123
|
+
default:
|
|
124
|
+
return fieldContent === undefined && customtypes_1.NestableWidget.is(fieldDef)
|
|
138
125
|
? (0, fields_1.NestableContentDefaultValue)(fieldDef)
|
|
139
126
|
: fieldContent;
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
return updatedField
|
|
130
|
+
? {
|
|
131
|
+
...updatedDocument,
|
|
132
|
+
[fieldKey]: updatedField,
|
|
133
|
+
}
|
|
134
|
+
: updatedDocument;
|
|
135
|
+
}, document);
|
|
147
136
|
}
|
|
148
137
|
exports.fillDocumentWithDefaultValues = fillDocumentWithDefaultValues;
|
|
149
138
|
/**
|
|
@@ -165,34 +165,21 @@ function collectSharedSlices(customType) {
|
|
|
165
165
|
exports.collectSharedSlices = collectSharedSlices;
|
|
166
166
|
function traverseCustomType(args) {
|
|
167
167
|
const { customType, onField } = args;
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
// Copy all properties directly
|
|
171
|
-
result.id = customType.id;
|
|
172
|
-
result.label = customType.label;
|
|
173
|
-
result.repeatable = customType.repeatable;
|
|
174
|
-
result.status = customType.status;
|
|
175
|
-
// Copy optional properties
|
|
176
|
-
if (customType.format !== undefined)
|
|
177
|
-
result.format = customType.format;
|
|
178
|
-
// Process JSON sections
|
|
179
|
-
const newJson = Object.create(null);
|
|
168
|
+
const result = { ...customType };
|
|
169
|
+
const newJson = {};
|
|
180
170
|
const keys = Object.keys(customType.json);
|
|
181
|
-
|
|
182
|
-
for (let i = 0; i < keyCount; i++) {
|
|
171
|
+
for (let i = 0; i < keys.length; i++) {
|
|
183
172
|
const key = keys[i];
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
onField,
|
|
195
|
-
});
|
|
173
|
+
if (key) {
|
|
174
|
+
const section = customType.json[key];
|
|
175
|
+
if (section) {
|
|
176
|
+
newJson[key] = (0, Section_1.traverseSection)({
|
|
177
|
+
path: [key],
|
|
178
|
+
section,
|
|
179
|
+
onField,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
196
183
|
}
|
|
197
184
|
result.json = newJson;
|
|
198
185
|
return result;
|
|
@@ -22,53 +22,46 @@ exports.Sections = {
|
|
|
22
22
|
};
|
|
23
23
|
function traverseSection(args) {
|
|
24
24
|
const { path: prevPath, section, onField } = args;
|
|
25
|
-
const result =
|
|
25
|
+
const result = {};
|
|
26
26
|
const keys = Object.keys(section);
|
|
27
|
-
|
|
28
|
-
for (let i = 0; i < keyCount; i++) {
|
|
27
|
+
for (let i = 0; i < keys.length; i++) {
|
|
29
28
|
const key = keys[i];
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
if (key) {
|
|
30
|
+
const prevModel = section[key];
|
|
31
|
+
if (prevModel) {
|
|
32
|
+
const path = [...prevPath, key];
|
|
33
|
+
let model;
|
|
34
|
+
switch (prevModel.type) {
|
|
35
|
+
case "Choice":
|
|
36
|
+
case "Slices":
|
|
37
|
+
model = (0, widgets_1.traverseSlices)({
|
|
38
|
+
path,
|
|
39
|
+
slices: prevModel,
|
|
40
|
+
onField: onField,
|
|
41
|
+
});
|
|
42
|
+
break;
|
|
43
|
+
case "Group":
|
|
44
|
+
model = onField({
|
|
45
|
+
path,
|
|
46
|
+
key,
|
|
47
|
+
field: (0, widgets_1.traverseGroup)({
|
|
48
|
+
path,
|
|
49
|
+
group: prevModel,
|
|
50
|
+
onField: onField,
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
break;
|
|
54
|
+
default:
|
|
55
|
+
model = onField({
|
|
56
|
+
path,
|
|
57
|
+
key,
|
|
58
|
+
field: prevModel,
|
|
59
|
+
});
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
result[key] = model;
|
|
63
|
+
}
|
|
40
64
|
}
|
|
41
|
-
newPath[pathLength] = key;
|
|
42
|
-
let model;
|
|
43
|
-
switch (prevModel.type) {
|
|
44
|
-
case "Choice":
|
|
45
|
-
case "Slices":
|
|
46
|
-
model = (0, widgets_1.traverseSlices)({
|
|
47
|
-
path: newPath,
|
|
48
|
-
slices: prevModel,
|
|
49
|
-
onField: onField,
|
|
50
|
-
});
|
|
51
|
-
break;
|
|
52
|
-
case "Group":
|
|
53
|
-
model = onField({
|
|
54
|
-
path: newPath,
|
|
55
|
-
key,
|
|
56
|
-
field: (0, widgets_1.traverseGroup)({
|
|
57
|
-
path: newPath,
|
|
58
|
-
group: prevModel,
|
|
59
|
-
onField: onField,
|
|
60
|
-
}),
|
|
61
|
-
});
|
|
62
|
-
break;
|
|
63
|
-
default:
|
|
64
|
-
model = onField({
|
|
65
|
-
path: newPath,
|
|
66
|
-
key,
|
|
67
|
-
field: prevModel,
|
|
68
|
-
});
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
result[key] = model;
|
|
72
65
|
}
|
|
73
66
|
return result;
|
|
74
67
|
}
|
|
@@ -34,119 +34,81 @@ 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
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
config.repeat = group.config.repeat;
|
|
57
|
-
// Process fields
|
|
58
|
-
const fields = Object.create(null);
|
|
59
|
-
const fieldEntries = group.config.fields;
|
|
60
|
-
const keys = Object.keys(fieldEntries);
|
|
61
|
-
const keyCount = keys.length;
|
|
62
|
-
for (let i = 0; i < keyCount; i++) {
|
|
63
|
-
const key = keys[i];
|
|
64
|
-
if (!key)
|
|
65
|
-
continue;
|
|
66
|
-
const model = fieldEntries[key];
|
|
67
|
-
if (!model)
|
|
68
|
-
continue;
|
|
69
|
-
// Create new path array directly
|
|
70
|
-
const pathLength = prevPath.length;
|
|
71
|
-
const newPath = new Array(pathLength + 1);
|
|
72
|
-
for (let j = 0; j < pathLength; j++) {
|
|
73
|
-
newPath[j] = prevPath[j];
|
|
37
|
+
let fields = undefined;
|
|
38
|
+
if ((_a = group.config) === null || _a === void 0 ? void 0 : _a.fields) {
|
|
39
|
+
fields = {};
|
|
40
|
+
const fieldEntries = group.config.fields;
|
|
41
|
+
const keys = Object.keys(fieldEntries);
|
|
42
|
+
for (let i = 0; i < keys.length; i++) {
|
|
43
|
+
const key = keys[i];
|
|
44
|
+
if (key) {
|
|
45
|
+
const model = fieldEntries[key];
|
|
46
|
+
if (model) {
|
|
47
|
+
// Create new path array instead of using concat
|
|
48
|
+
const newPath = [...prevPath, key];
|
|
49
|
+
fields[key] = onField({
|
|
50
|
+
path: newPath,
|
|
51
|
+
key,
|
|
52
|
+
field: model,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
74
56
|
}
|
|
75
|
-
newPath[pathLength] = key;
|
|
76
|
-
fields[key] = onField({
|
|
77
|
-
path: newPath,
|
|
78
|
-
key,
|
|
79
|
-
field: model,
|
|
80
|
-
});
|
|
81
57
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
58
|
+
return {
|
|
59
|
+
...group,
|
|
60
|
+
...(group.config && {
|
|
61
|
+
config: {
|
|
62
|
+
...group.config,
|
|
63
|
+
...(fields && { fields }),
|
|
64
|
+
},
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
85
67
|
}
|
|
86
68
|
exports.traverseNestedGroup = traverseNestedGroup;
|
|
87
69
|
function traverseGroup(args) {
|
|
88
70
|
var _a;
|
|
89
71
|
const { path: prevPath, group, onField } = args;
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
for (let i = 0; i < keyCount; i++) {
|
|
116
|
-
const key = keys[i];
|
|
117
|
-
if (!key)
|
|
118
|
-
continue;
|
|
119
|
-
const prevField = fieldEntries[key];
|
|
120
|
-
if (!prevField)
|
|
121
|
-
continue;
|
|
122
|
-
// Create new path array directly
|
|
123
|
-
const pathLength = prevPath.length;
|
|
124
|
-
const newPath = new Array(pathLength + 1);
|
|
125
|
-
for (let j = 0; j < pathLength; j++) {
|
|
126
|
-
newPath[j] = prevPath[j];
|
|
127
|
-
}
|
|
128
|
-
newPath[pathLength] = key;
|
|
129
|
-
let field;
|
|
130
|
-
switch (prevField.type) {
|
|
131
|
-
case "Group":
|
|
132
|
-
field = traverseNestedGroup({
|
|
72
|
+
let fields = undefined;
|
|
73
|
+
if ((_a = group.config) === null || _a === void 0 ? void 0 : _a.fields) {
|
|
74
|
+
fields = {};
|
|
75
|
+
const fieldEntries = group.config.fields;
|
|
76
|
+
const keys = Object.keys(fieldEntries);
|
|
77
|
+
for (let i = 0; i < keys.length; i++) {
|
|
78
|
+
const key = keys[i];
|
|
79
|
+
if (key) {
|
|
80
|
+
const prevField = fieldEntries[key];
|
|
81
|
+
// Create new path array instead of using concat
|
|
82
|
+
const newPath = [...prevPath, key];
|
|
83
|
+
let field;
|
|
84
|
+
switch (prevField.type) {
|
|
85
|
+
case "Group":
|
|
86
|
+
field = traverseNestedGroup({
|
|
87
|
+
path: newPath,
|
|
88
|
+
group: prevField,
|
|
89
|
+
onField: onField,
|
|
90
|
+
});
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
field = prevField;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
fields[key] = onField({
|
|
133
97
|
path: newPath,
|
|
134
|
-
|
|
135
|
-
|
|
98
|
+
key,
|
|
99
|
+
field,
|
|
136
100
|
});
|
|
137
|
-
|
|
138
|
-
default:
|
|
139
|
-
field = prevField;
|
|
140
|
-
break;
|
|
101
|
+
}
|
|
141
102
|
}
|
|
142
|
-
fields[key] = onField({
|
|
143
|
-
path: newPath,
|
|
144
|
-
key,
|
|
145
|
-
field,
|
|
146
|
-
});
|
|
147
103
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
104
|
+
return {
|
|
105
|
+
...group,
|
|
106
|
+
...(group.config && {
|
|
107
|
+
config: {
|
|
108
|
+
...group.config,
|
|
109
|
+
...(fields && { fields }),
|
|
110
|
+
},
|
|
111
|
+
}),
|
|
112
|
+
};
|
|
151
113
|
}
|
|
152
114
|
exports.traverseGroup = traverseGroup;
|
|
@@ -49,88 +49,55 @@ function isDynamicSharedSlice(slice) {
|
|
|
49
49
|
exports.isDynamicSharedSlice = isDynamicSharedSlice;
|
|
50
50
|
function traverseVariation(args) {
|
|
51
51
|
const { path: prevPath, variation, onField } = args;
|
|
52
|
-
|
|
53
|
-
if (!variation.primary && !variation.items) {
|
|
54
|
-
return variation;
|
|
55
|
-
}
|
|
56
|
-
// Create result object directly
|
|
57
|
-
const result = Object.create(null);
|
|
58
|
-
// Copy all basic properties
|
|
59
|
-
result.id = variation.id;
|
|
60
|
-
result.name = variation.name;
|
|
61
|
-
result.description = variation.description;
|
|
62
|
-
result.imageUrl = variation.imageUrl;
|
|
63
|
-
result.docURL = variation.docURL;
|
|
64
|
-
result.version = variation.version;
|
|
65
|
-
// Copy optional properties if they exist
|
|
66
|
-
if (variation.display !== undefined)
|
|
67
|
-
result.display = variation.display;
|
|
68
|
-
// Process primary fields if they exist
|
|
52
|
+
const result = { ...variation };
|
|
69
53
|
if (variation.primary) {
|
|
70
|
-
const primary =
|
|
54
|
+
const primary = {};
|
|
71
55
|
const keys = Object.keys(variation.primary);
|
|
72
|
-
|
|
73
|
-
for (let i = 0; i < keyCount; i++) {
|
|
56
|
+
for (let i = 0; i < keys.length; i++) {
|
|
74
57
|
const key = keys[i];
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
58
|
+
if (key) {
|
|
59
|
+
const prevField = variation.primary[key];
|
|
60
|
+
if (prevField) {
|
|
61
|
+
const path = [...prevPath, "primary", key];
|
|
62
|
+
let field;
|
|
63
|
+
switch (prevField.type) {
|
|
64
|
+
case "Group":
|
|
65
|
+
field = (0, Group_1.traverseGroup)({
|
|
66
|
+
path,
|
|
67
|
+
group: prevField,
|
|
68
|
+
onField: onField,
|
|
69
|
+
});
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
field = prevField;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
primary[key] = onField({
|
|
76
|
+
path,
|
|
77
|
+
key,
|
|
78
|
+
field,
|
|
95
79
|
});
|
|
96
|
-
|
|
97
|
-
default:
|
|
98
|
-
field = prevField;
|
|
99
|
-
break;
|
|
80
|
+
}
|
|
100
81
|
}
|
|
101
|
-
primary[key] = onField({
|
|
102
|
-
path: newPath,
|
|
103
|
-
key,
|
|
104
|
-
field,
|
|
105
|
-
});
|
|
106
82
|
}
|
|
107
83
|
result.primary = primary;
|
|
108
84
|
}
|
|
109
|
-
// Process items fields if they exist
|
|
110
85
|
if (variation.items) {
|
|
111
|
-
const items =
|
|
86
|
+
const items = {};
|
|
112
87
|
const keys = Object.keys(variation.items);
|
|
113
|
-
|
|
114
|
-
for (let i = 0; i < keyCount; i++) {
|
|
88
|
+
for (let i = 0; i < keys.length; i++) {
|
|
115
89
|
const key = keys[i];
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
90
|
+
if (key) {
|
|
91
|
+
const field = variation.items[key];
|
|
92
|
+
if (field) {
|
|
93
|
+
const path = [...prevPath, "items", key];
|
|
94
|
+
items[key] = onField({
|
|
95
|
+
path,
|
|
96
|
+
key,
|
|
97
|
+
field,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
126
100
|
}
|
|
127
|
-
newPath[pathLength] = "items";
|
|
128
|
-
newPath[pathLength + 1] = key;
|
|
129
|
-
items[key] = onField({
|
|
130
|
-
path: newPath,
|
|
131
|
-
key,
|
|
132
|
-
field,
|
|
133
|
-
});
|
|
134
101
|
}
|
|
135
102
|
result.items = items;
|
|
136
103
|
}
|
|
@@ -139,36 +106,18 @@ function traverseVariation(args) {
|
|
|
139
106
|
exports.traverseVariation = traverseVariation;
|
|
140
107
|
function traverseSharedSlice(args) {
|
|
141
108
|
const { path: prevPath, slice, onField } = args;
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
result.id = slice.id;
|
|
146
|
-
result.type = slice.type;
|
|
147
|
-
result.name = slice.name;
|
|
148
|
-
// Copy optional properties
|
|
149
|
-
if (slice.description !== undefined)
|
|
150
|
-
result.description = slice.description;
|
|
151
|
-
if (slice.legacyPaths !== undefined)
|
|
152
|
-
result.legacyPaths = slice.legacyPaths;
|
|
153
|
-
// Process variations
|
|
154
|
-
const variationCount = slice.variations.length;
|
|
155
|
-
const variations = new Array(variationCount);
|
|
156
|
-
for (let i = 0; i < variationCount; i++) {
|
|
109
|
+
const result = { ...slice };
|
|
110
|
+
const variations = [];
|
|
111
|
+
for (let i = 0; i < slice.variations.length; i++) {
|
|
157
112
|
const variation = slice.variations[i];
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
113
|
+
if (variation) {
|
|
114
|
+
const path = [...prevPath, variation.id];
|
|
115
|
+
variations.push(traverseVariation({
|
|
116
|
+
path,
|
|
117
|
+
variation,
|
|
118
|
+
onField,
|
|
119
|
+
}));
|
|
165
120
|
}
|
|
166
|
-
newPath[pathLength] = variation.id;
|
|
167
|
-
variations[i] = traverseVariation({
|
|
168
|
-
path: newPath,
|
|
169
|
-
variation,
|
|
170
|
-
onField,
|
|
171
|
-
});
|
|
172
121
|
}
|
|
173
122
|
result.variations = variations;
|
|
174
123
|
return result;
|
package/package.json
CHANGED
package/src/content/Document.ts
CHANGED
|
@@ -195,47 +195,37 @@ export function fillDocumentWithDefaultValues(
|
|
|
195
195
|
? simplifyCustomType(customType)
|
|
196
196
|
: customType
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
: fieldContent
|
|
230
|
-
break
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (updatedField) {
|
|
234
|
-
result[fieldKey] = updatedField
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return result
|
|
198
|
+
return Object.entries(fields).reduce<Document>(
|
|
199
|
+
(updatedDocument, [fieldKey, fieldDef]) => {
|
|
200
|
+
const fieldContent = document[fieldKey]
|
|
201
|
+
|
|
202
|
+
const updatedField = (() => {
|
|
203
|
+
switch (fieldDef.type) {
|
|
204
|
+
case "Group":
|
|
205
|
+
return isGroupContent(fieldContent)
|
|
206
|
+
? groupContentWithDefaultValues(fieldDef, fieldContent)
|
|
207
|
+
: fieldContent
|
|
208
|
+
case "Choice":
|
|
209
|
+
case "Slices":
|
|
210
|
+
return isSlicesContent(fieldContent)
|
|
211
|
+
? slicesContentWithDefaultValues(fieldDef, fieldContent)
|
|
212
|
+
: fieldContent
|
|
213
|
+
default:
|
|
214
|
+
return fieldContent === undefined && NestableWidget.is(fieldDef)
|
|
215
|
+
? NestableContentDefaultValue(fieldDef)
|
|
216
|
+
: fieldContent
|
|
217
|
+
}
|
|
218
|
+
})()
|
|
219
|
+
|
|
220
|
+
return updatedField
|
|
221
|
+
? {
|
|
222
|
+
...updatedDocument,
|
|
223
|
+
[fieldKey]: updatedField,
|
|
224
|
+
}
|
|
225
|
+
: updatedDocument
|
|
226
|
+
},
|
|
227
|
+
document,
|
|
228
|
+
)
|
|
239
229
|
}
|
|
240
230
|
/**
|
|
241
231
|
* @param model: Can be optional if we simply want to loop through the content
|
|
@@ -260,39 +260,22 @@ export function traverseCustomType<
|
|
|
260
260
|
onField: OnFieldFn<UID | NestableWidget | Group | NestedGroup>
|
|
261
261
|
}): T {
|
|
262
262
|
const { customType, onField } = args
|
|
263
|
+
const result = { ...customType } as T
|
|
264
|
+
const newJson: Record<string, typeof customType.json[string]> = {}
|
|
263
265
|
|
|
264
|
-
// Create a new result object directly
|
|
265
|
-
const result = Object.create(null) as T
|
|
266
|
-
|
|
267
|
-
// Copy all properties directly
|
|
268
|
-
result.id = customType.id
|
|
269
|
-
result.label = customType.label
|
|
270
|
-
result.repeatable = customType.repeatable
|
|
271
|
-
result.status = customType.status
|
|
272
|
-
|
|
273
|
-
// Copy optional properties
|
|
274
|
-
if (customType.format !== undefined) result.format = customType.format
|
|
275
|
-
|
|
276
|
-
// Process JSON sections
|
|
277
|
-
const newJson = Object.create(null)
|
|
278
266
|
const keys = Object.keys(customType.json)
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
for (let i = 0; i < keyCount; i++) {
|
|
267
|
+
for (let i = 0; i < keys.length; i++) {
|
|
282
268
|
const key = keys[i]
|
|
283
|
-
if (
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
section,
|
|
294
|
-
onField,
|
|
295
|
-
})
|
|
269
|
+
if (key) {
|
|
270
|
+
const section = customType.json[key]
|
|
271
|
+
if (section) {
|
|
272
|
+
newJson[key] = traverseSection({
|
|
273
|
+
path: [key],
|
|
274
|
+
section,
|
|
275
|
+
onField,
|
|
276
|
+
})
|
|
277
|
+
}
|
|
278
|
+
}
|
|
296
279
|
}
|
|
297
280
|
|
|
298
281
|
result.json = newJson
|
|
@@ -51,58 +51,51 @@ export function traverseSection<
|
|
|
51
51
|
onField: OnFieldFn<UID | NestableWidget | Group | NestedGroup>
|
|
52
52
|
}): T {
|
|
53
53
|
const { path: prevPath, section, onField } = args
|
|
54
|
-
const result =
|
|
54
|
+
const result = {} as T
|
|
55
55
|
|
|
56
56
|
const keys = Object.keys(section)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
for (let i = 0; i < keyCount; i++) {
|
|
57
|
+
for (let i = 0; i < keys.length; i++) {
|
|
60
58
|
const key = keys[i]
|
|
61
|
-
if (
|
|
59
|
+
if (key) {
|
|
60
|
+
const prevModel = section[key]
|
|
61
|
+
if (prevModel) {
|
|
62
|
+
const path = [...prevPath, key]
|
|
63
|
+
let model
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
switch (prevModel.type) {
|
|
66
|
+
case "Choice":
|
|
67
|
+
case "Slices":
|
|
68
|
+
model = traverseSlices({
|
|
69
|
+
path,
|
|
70
|
+
slices: prevModel,
|
|
71
|
+
onField: onField as OnFieldFn<
|
|
72
|
+
NestableWidget | Group | NestedGroup
|
|
73
|
+
>,
|
|
74
|
+
})
|
|
75
|
+
break
|
|
76
|
+
case "Group":
|
|
77
|
+
model = onField({
|
|
78
|
+
path,
|
|
79
|
+
key,
|
|
80
|
+
field: traverseGroup({
|
|
81
|
+
path,
|
|
82
|
+
group: prevModel,
|
|
83
|
+
onField: onField as OnFieldFn<NestableWidget | NestedGroup>,
|
|
84
|
+
}),
|
|
85
|
+
})
|
|
86
|
+
break
|
|
87
|
+
default:
|
|
88
|
+
model = onField({
|
|
89
|
+
path,
|
|
90
|
+
key,
|
|
91
|
+
field: prevModel,
|
|
92
|
+
})
|
|
93
|
+
break
|
|
94
|
+
}
|
|
65
95
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const newPath = new Array(pathLength + 1)
|
|
69
|
-
for (let j = 0; j < pathLength; j++) {
|
|
70
|
-
newPath[j] = prevPath[j]
|
|
96
|
+
result[key] = model as any
|
|
97
|
+
}
|
|
71
98
|
}
|
|
72
|
-
newPath[pathLength] = key
|
|
73
|
-
|
|
74
|
-
let model
|
|
75
|
-
|
|
76
|
-
switch (prevModel.type) {
|
|
77
|
-
case "Choice":
|
|
78
|
-
case "Slices":
|
|
79
|
-
model = traverseSlices({
|
|
80
|
-
path: newPath,
|
|
81
|
-
slices: prevModel,
|
|
82
|
-
onField: onField as OnFieldFn<NestableWidget | Group | NestedGroup>,
|
|
83
|
-
})
|
|
84
|
-
break
|
|
85
|
-
case "Group":
|
|
86
|
-
model = onField({
|
|
87
|
-
path: newPath,
|
|
88
|
-
key,
|
|
89
|
-
field: traverseGroup({
|
|
90
|
-
path: newPath,
|
|
91
|
-
group: prevModel,
|
|
92
|
-
onField: onField as OnFieldFn<NestableWidget | NestedGroup>,
|
|
93
|
-
}),
|
|
94
|
-
})
|
|
95
|
-
break
|
|
96
|
-
default:
|
|
97
|
-
model = onField({
|
|
98
|
-
path: newPath,
|
|
99
|
-
key,
|
|
100
|
-
field: prevModel,
|
|
101
|
-
})
|
|
102
|
-
break
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
result[key] = model
|
|
106
99
|
}
|
|
107
100
|
|
|
108
101
|
return result
|
|
@@ -55,58 +55,39 @@ export function traverseNestedGroup(args: {
|
|
|
55
55
|
onField: OnFieldFn<NestableWidget>
|
|
56
56
|
}): NestedGroup {
|
|
57
57
|
const { path: prevPath, group, onField } = args
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const fields = Object.create(null)
|
|
80
|
-
const fieldEntries = group.config.fields
|
|
81
|
-
const keys = Object.keys(fieldEntries)
|
|
82
|
-
const keyCount = keys.length
|
|
83
|
-
|
|
84
|
-
for (let i = 0; i < keyCount; i++) {
|
|
85
|
-
const key = keys[i]
|
|
86
|
-
if (!key) continue
|
|
87
|
-
|
|
88
|
-
const model = fieldEntries[key]
|
|
89
|
-
if (!model) continue
|
|
90
|
-
|
|
91
|
-
// Create new path array directly
|
|
92
|
-
const pathLength = prevPath.length
|
|
93
|
-
const newPath = new Array(pathLength + 1)
|
|
94
|
-
for (let j = 0; j < pathLength; j++) {
|
|
95
|
-
newPath[j] = prevPath[j]
|
|
58
|
+
let fields: Record<string, NestableWidget> | undefined = undefined
|
|
59
|
+
|
|
60
|
+
if (group.config?.fields) {
|
|
61
|
+
fields = {}
|
|
62
|
+
const fieldEntries = group.config.fields
|
|
63
|
+
const keys = Object.keys(fieldEntries)
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < keys.length; i++) {
|
|
66
|
+
const key = keys[i]
|
|
67
|
+
if (key) {
|
|
68
|
+
const model = fieldEntries[key]
|
|
69
|
+
if (model) {
|
|
70
|
+
// Create new path array instead of using concat
|
|
71
|
+
const newPath = [...prevPath, key]
|
|
72
|
+
fields[key] = onField({
|
|
73
|
+
path: newPath,
|
|
74
|
+
key,
|
|
75
|
+
field: model,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
}
|
|
96
79
|
}
|
|
97
|
-
newPath[pathLength] = key
|
|
98
|
-
|
|
99
|
-
fields[key] = onField({
|
|
100
|
-
path: newPath,
|
|
101
|
-
key,
|
|
102
|
-
field: model,
|
|
103
|
-
})
|
|
104
80
|
}
|
|
105
81
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
82
|
+
return {
|
|
83
|
+
...group,
|
|
84
|
+
...(group.config && {
|
|
85
|
+
config: {
|
|
86
|
+
...group.config,
|
|
87
|
+
...(fields && { fields }),
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
}
|
|
110
91
|
}
|
|
111
92
|
|
|
112
93
|
export function traverseGroup(args: {
|
|
@@ -115,71 +96,51 @@ export function traverseGroup(args: {
|
|
|
115
96
|
onField: OnFieldFn<NestableWidget | NestedGroup>
|
|
116
97
|
}): Group {
|
|
117
98
|
const { path: prevPath, group, onField } = args
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const prevField = fieldEntries[key]
|
|
149
|
-
if (!prevField) continue
|
|
150
|
-
|
|
151
|
-
// Create new path array directly
|
|
152
|
-
const pathLength = prevPath.length
|
|
153
|
-
const newPath = new Array(pathLength + 1)
|
|
154
|
-
for (let j = 0; j < pathLength; j++) {
|
|
155
|
-
newPath[j] = prevPath[j]
|
|
156
|
-
}
|
|
157
|
-
newPath[pathLength] = key
|
|
158
|
-
|
|
159
|
-
let field
|
|
160
|
-
|
|
161
|
-
switch (prevField.type) {
|
|
162
|
-
case "Group":
|
|
163
|
-
field = traverseNestedGroup({
|
|
99
|
+
let fields: Record<string, NestableWidget | NestedGroup> | undefined =
|
|
100
|
+
undefined
|
|
101
|
+
|
|
102
|
+
if (group.config?.fields) {
|
|
103
|
+
fields = {}
|
|
104
|
+
const fieldEntries = group.config.fields
|
|
105
|
+
const keys = Object.keys(fieldEntries)
|
|
106
|
+
|
|
107
|
+
for (let i = 0; i < keys.length; i++) {
|
|
108
|
+
const key = keys[i]
|
|
109
|
+
if (key) {
|
|
110
|
+
const prevField = fieldEntries[key] as NestableWidget | NestedGroup
|
|
111
|
+
// Create new path array instead of using concat
|
|
112
|
+
const newPath = [...prevPath, key] as ReadonlyArray<string>
|
|
113
|
+
let field
|
|
114
|
+
|
|
115
|
+
switch (prevField.type) {
|
|
116
|
+
case "Group":
|
|
117
|
+
field = traverseNestedGroup({
|
|
118
|
+
path: newPath,
|
|
119
|
+
group: prevField,
|
|
120
|
+
onField: onField as OnFieldFn<NestableWidget>,
|
|
121
|
+
})
|
|
122
|
+
break
|
|
123
|
+
default:
|
|
124
|
+
field = prevField
|
|
125
|
+
break
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
fields[key] = onField({
|
|
164
129
|
path: newPath,
|
|
165
|
-
|
|
166
|
-
|
|
130
|
+
key,
|
|
131
|
+
field,
|
|
167
132
|
})
|
|
168
|
-
|
|
169
|
-
default:
|
|
170
|
-
field = prevField
|
|
171
|
-
break
|
|
133
|
+
}
|
|
172
134
|
}
|
|
173
|
-
|
|
174
|
-
fields[key] = onField({
|
|
175
|
-
path: newPath,
|
|
176
|
-
key,
|
|
177
|
-
field,
|
|
178
|
-
})
|
|
179
135
|
}
|
|
180
136
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
137
|
+
return {
|
|
138
|
+
...group,
|
|
139
|
+
...(group.config && {
|
|
140
|
+
config: {
|
|
141
|
+
...group.config,
|
|
142
|
+
...(fields && { fields }),
|
|
143
|
+
},
|
|
144
|
+
}),
|
|
145
|
+
}
|
|
185
146
|
}
|
|
@@ -78,100 +78,62 @@ export function traverseVariation(args: {
|
|
|
78
78
|
onField: OnFieldFn<NestableWidget | Group | NestedGroup>
|
|
79
79
|
}): Variation {
|
|
80
80
|
const { path: prevPath, variation, onField } = args
|
|
81
|
+
const result = { ...variation }
|
|
81
82
|
|
|
82
|
-
// If no primary or items, return the variation as is
|
|
83
|
-
if (!variation.primary && !variation.items) {
|
|
84
|
-
return variation
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Create result object directly
|
|
88
|
-
const result = Object.create(null)
|
|
89
|
-
|
|
90
|
-
// Copy all basic properties
|
|
91
|
-
result.id = variation.id
|
|
92
|
-
result.name = variation.name
|
|
93
|
-
result.description = variation.description
|
|
94
|
-
result.imageUrl = variation.imageUrl
|
|
95
|
-
result.docURL = variation.docURL
|
|
96
|
-
result.version = variation.version
|
|
97
|
-
|
|
98
|
-
// Copy optional properties if they exist
|
|
99
|
-
if (variation.display !== undefined) result.display = variation.display
|
|
100
|
-
|
|
101
|
-
// Process primary fields if they exist
|
|
102
83
|
if (variation.primary) {
|
|
103
|
-
const primary =
|
|
84
|
+
const primary: Record<string, NestableWidget | Group> = {}
|
|
104
85
|
const keys = Object.keys(variation.primary)
|
|
105
|
-
const keyCount = keys.length
|
|
106
86
|
|
|
107
|
-
for (let i = 0; i <
|
|
87
|
+
for (let i = 0; i < keys.length; i++) {
|
|
108
88
|
const key = keys[i]
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
89
|
+
if (key) {
|
|
90
|
+
const prevField = variation.primary[key]
|
|
91
|
+
if (prevField) {
|
|
92
|
+
const path = [...prevPath, "primary", key]
|
|
93
|
+
let field
|
|
94
|
+
|
|
95
|
+
switch (prevField.type) {
|
|
96
|
+
case "Group":
|
|
97
|
+
field = traverseGroup({
|
|
98
|
+
path,
|
|
99
|
+
group: prevField,
|
|
100
|
+
onField: onField as OnFieldFn<NestableWidget | NestedGroup>,
|
|
101
|
+
})
|
|
102
|
+
break
|
|
103
|
+
default:
|
|
104
|
+
field = prevField
|
|
105
|
+
break
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
primary[key] = onField({
|
|
109
|
+
path,
|
|
110
|
+
key,
|
|
111
|
+
field,
|
|
131
112
|
})
|
|
132
|
-
|
|
133
|
-
default:
|
|
134
|
-
field = prevField
|
|
135
|
-
break
|
|
113
|
+
}
|
|
136
114
|
}
|
|
137
|
-
|
|
138
|
-
primary[key] = onField({
|
|
139
|
-
path: newPath,
|
|
140
|
-
key,
|
|
141
|
-
field,
|
|
142
|
-
})
|
|
143
115
|
}
|
|
144
116
|
|
|
145
117
|
result.primary = primary
|
|
146
118
|
}
|
|
147
119
|
|
|
148
|
-
// Process items fields if they exist
|
|
149
120
|
if (variation.items) {
|
|
150
|
-
const items =
|
|
121
|
+
const items: Record<string, NestableWidget> = {}
|
|
151
122
|
const keys = Object.keys(variation.items)
|
|
152
|
-
const keyCount = keys.length
|
|
153
123
|
|
|
154
|
-
for (let i = 0; i <
|
|
124
|
+
for (let i = 0; i < keys.length; i++) {
|
|
155
125
|
const key = keys[i]
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
126
|
+
if (key) {
|
|
127
|
+
const field = variation.items[key]
|
|
128
|
+
if (field) {
|
|
129
|
+
const path = [...prevPath, "items", key]
|
|
130
|
+
items[key] = (onField as OnFieldFn<NestableWidget>)({
|
|
131
|
+
path,
|
|
132
|
+
key,
|
|
133
|
+
field,
|
|
134
|
+
})
|
|
135
|
+
}
|
|
166
136
|
}
|
|
167
|
-
newPath[pathLength] = "items"
|
|
168
|
-
newPath[pathLength + 1] = key
|
|
169
|
-
|
|
170
|
-
items[key] = (onField as OnFieldFn<NestableWidget>)({
|
|
171
|
-
path: newPath,
|
|
172
|
-
key,
|
|
173
|
-
field,
|
|
174
|
-
})
|
|
175
137
|
}
|
|
176
138
|
|
|
177
139
|
result.items = items
|
|
@@ -186,40 +148,21 @@ export function traverseSharedSlice(args: {
|
|
|
186
148
|
onField: OnFieldFn<NestableWidget | Group | NestedGroup>
|
|
187
149
|
}): SharedSlice {
|
|
188
150
|
const { path: prevPath, slice, onField } = args
|
|
151
|
+
const result = { ...slice }
|
|
152
|
+
const variations: Variation[] = []
|
|
189
153
|
|
|
190
|
-
|
|
191
|
-
const result = Object.create(null)
|
|
192
|
-
|
|
193
|
-
// Copy all base properties
|
|
194
|
-
result.id = slice.id
|
|
195
|
-
result.type = slice.type
|
|
196
|
-
result.name = slice.name
|
|
197
|
-
|
|
198
|
-
// Copy optional properties
|
|
199
|
-
if (slice.description !== undefined) result.description = slice.description
|
|
200
|
-
if (slice.legacyPaths !== undefined) result.legacyPaths = slice.legacyPaths
|
|
201
|
-
|
|
202
|
-
// Process variations
|
|
203
|
-
const variationCount = slice.variations.length
|
|
204
|
-
const variations = new Array(variationCount)
|
|
205
|
-
|
|
206
|
-
for (let i = 0; i < variationCount; i++) {
|
|
154
|
+
for (let i = 0; i < slice.variations.length; i++) {
|
|
207
155
|
const variation = slice.variations[i]
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
156
|
+
if (variation) {
|
|
157
|
+
const path = [...prevPath, variation.id]
|
|
158
|
+
variations.push(
|
|
159
|
+
traverseVariation({
|
|
160
|
+
path,
|
|
161
|
+
variation,
|
|
162
|
+
onField,
|
|
163
|
+
}),
|
|
164
|
+
)
|
|
215
165
|
}
|
|
216
|
-
newPath[pathLength] = variation.id
|
|
217
|
-
|
|
218
|
-
variations[i] = traverseVariation({
|
|
219
|
-
path: newPath,
|
|
220
|
-
variation,
|
|
221
|
-
onField,
|
|
222
|
-
})
|
|
223
166
|
}
|
|
224
167
|
|
|
225
168
|
result.variations = variations as ReadonlyArray<Variation>
|