@prismicio/types-internal 3.9.0 → 3.10.0-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/_internal/utils.d.ts +6 -1
- package/lib/content/Document.d.ts +1 -1
- package/lib/content/fields/RepeatableContent.d.ts +123 -51
- package/lib/content/fields/RepeatableContent.js +14 -10
- package/lib/customtypes/CustomType.d.ts +24 -18
- package/lib/customtypes/CustomType.js +16 -1
- package/lib/customtypes/Section.d.ts +25 -18
- package/lib/customtypes/Section.js +56 -1
- package/lib/customtypes/widgets/Group.d.ts +12 -0
- package/lib/customtypes/widgets/Group.js +77 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +7 -0
- package/lib/customtypes/widgets/slices/CompositeSlice.js +26 -1
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +13 -0
- package/lib/customtypes/widgets/slices/SharedSlice.js +74 -1
- package/lib/customtypes/widgets/slices/Slices.d.ts +8 -0
- package/lib/customtypes/widgets/slices/Slices.js +75 -1
- package/package.json +1 -1
- package/src/_internal/utils.ts +4 -0
- package/src/customtypes/CustomType.ts +30 -1
- package/src/customtypes/Section.ts +69 -0
- package/src/customtypes/widgets/Group.ts +90 -0
- package/src/customtypes/widgets/slices/CompositeSlice.ts +38 -0
- package/src/customtypes/widgets/slices/SharedSlice.ts +86 -0
- package/src/customtypes/widgets/slices/Slices.ts +83 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Group = exports.GroupConfig = exports.NestedGroup = exports.NestedGroupConfig = exports.GroupFieldType = void 0;
|
|
3
|
+
exports.traverseGroup = exports.traverseNestedGroup = exports.Group = exports.GroupConfig = exports.NestedGroup = exports.NestedGroupConfig = exports.GroupFieldType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const common_1 = require("../../common");
|
|
@@ -31,3 +31,79 @@ exports.NestedGroupConfig = createGroupConfig(NestableWidget_1.NestableWidget);
|
|
|
31
31
|
exports.NestedGroup = createGroup(NestableWidget_1.NestableWidget);
|
|
32
32
|
exports.GroupConfig = createGroupConfig(t.union([NestableWidget_1.NestableWidget, exports.NestedGroup]));
|
|
33
33
|
exports.Group = createGroup(t.union([NestableWidget_1.NestableWidget, exports.NestedGroup]));
|
|
34
|
+
function traverseNestedGroup(args) {
|
|
35
|
+
var _a;
|
|
36
|
+
const { path: prevPath, group, onField } = args;
|
|
37
|
+
const fields = ((_a = group.config) === null || _a === void 0 ? void 0 : _a.fields) &&
|
|
38
|
+
Object.entries(group.config.fields).reduce((acc, [key, model]) => {
|
|
39
|
+
const path = prevPath.concat(key);
|
|
40
|
+
acc[key] = onField({
|
|
41
|
+
path,
|
|
42
|
+
key,
|
|
43
|
+
field: model,
|
|
44
|
+
});
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
47
|
+
return {
|
|
48
|
+
...group,
|
|
49
|
+
...(group.config && {
|
|
50
|
+
config: {
|
|
51
|
+
...group.config,
|
|
52
|
+
...(fields && { fields }),
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.traverseNestedGroup = traverseNestedGroup;
|
|
58
|
+
function traverseGroup(args) {
|
|
59
|
+
var _a;
|
|
60
|
+
const { path: prevPath, group, onField } = args;
|
|
61
|
+
const fields = ((_a = group.config) === null || _a === void 0 ? void 0 : _a.fields) &&
|
|
62
|
+
Object.entries(group.config.fields).reduce((acc, [key, prevField]) => {
|
|
63
|
+
const path = prevPath.concat(key);
|
|
64
|
+
let field;
|
|
65
|
+
switch (prevField.type) {
|
|
66
|
+
case "Group":
|
|
67
|
+
field = traverseNestedGroup({
|
|
68
|
+
path,
|
|
69
|
+
group: prevField,
|
|
70
|
+
onField: onField,
|
|
71
|
+
});
|
|
72
|
+
break;
|
|
73
|
+
case "Boolean":
|
|
74
|
+
case "Color":
|
|
75
|
+
case "Date":
|
|
76
|
+
case "Embed":
|
|
77
|
+
case "GeoPoint":
|
|
78
|
+
case "Image":
|
|
79
|
+
case "IntegrationFields":
|
|
80
|
+
case "Link":
|
|
81
|
+
case "Number":
|
|
82
|
+
case "Range":
|
|
83
|
+
case "Select":
|
|
84
|
+
case "Separator":
|
|
85
|
+
case "StructuredText":
|
|
86
|
+
case "Table":
|
|
87
|
+
case "Text":
|
|
88
|
+
case "Timestamp":
|
|
89
|
+
field = prevField;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
acc[key] = onField({
|
|
93
|
+
path,
|
|
94
|
+
key,
|
|
95
|
+
field,
|
|
96
|
+
});
|
|
97
|
+
return acc;
|
|
98
|
+
}, {});
|
|
99
|
+
return {
|
|
100
|
+
...group,
|
|
101
|
+
...(group.config && {
|
|
102
|
+
config: {
|
|
103
|
+
...group.config,
|
|
104
|
+
...(fields && { fields }),
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
exports.traverseGroup = traverseGroup;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { OnFieldFn } from "../../../_internal/utils";
|
|
3
|
+
import { NestableWidget } from "../nestable/NestableWidget";
|
|
2
4
|
import type { DynamicSlice, StaticSlice } from "./Slice";
|
|
3
5
|
export declare const CompositeSliceType = "Slice";
|
|
4
6
|
export declare const CompositeSliceConfig: t.ExactC<t.PartialC<{
|
|
@@ -394,3 +396,8 @@ export declare const CompositeSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
394
396
|
}>]>>;
|
|
395
397
|
export declare type CompositeSlice = t.TypeOf<typeof CompositeSlice>;
|
|
396
398
|
export declare function isCompositeSlice(slice: DynamicSlice | StaticSlice): slice is CompositeSlice;
|
|
399
|
+
export declare function traverseCompositeSlice(args: {
|
|
400
|
+
path: ReadonlyArray<string>;
|
|
401
|
+
slice: CompositeSlice;
|
|
402
|
+
onField: OnFieldFn<NestableWidget>;
|
|
403
|
+
}): CompositeSlice;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCompositeSlice = exports.CompositeSlice = exports.CompositeSliceConfig = exports.CompositeSliceType = void 0;
|
|
3
|
+
exports.traverseCompositeSlice = exports.isCompositeSlice = exports.CompositeSlice = exports.CompositeSliceConfig = exports.CompositeSliceType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const common_1 = require("../../../common");
|
|
@@ -28,3 +28,28 @@ function isCompositeSlice(slice) {
|
|
|
28
28
|
return slice.type === "Slice";
|
|
29
29
|
}
|
|
30
30
|
exports.isCompositeSlice = isCompositeSlice;
|
|
31
|
+
function traverseCompositeSlice(args) {
|
|
32
|
+
const { path: prevPath, slice, onField } = args;
|
|
33
|
+
const nonRepeat = slice["non-repeat"] &&
|
|
34
|
+
Object.entries(slice["non-repeat"]).reduce((acc, [key, field]) => {
|
|
35
|
+
const path = prevPath.concat("non-repeat", key);
|
|
36
|
+
acc[key] = onField({ path, key, field });
|
|
37
|
+
return acc;
|
|
38
|
+
}, {});
|
|
39
|
+
const repeat = slice.repeat &&
|
|
40
|
+
Object.entries(slice.repeat).reduce((acc, [key, field]) => {
|
|
41
|
+
const path = prevPath.concat("repeat", key);
|
|
42
|
+
acc[key] = onField({ path, key, field });
|
|
43
|
+
return acc;
|
|
44
|
+
}, {});
|
|
45
|
+
return {
|
|
46
|
+
...slice,
|
|
47
|
+
...(nonRepeat && {
|
|
48
|
+
"non-repeat": nonRepeat,
|
|
49
|
+
}),
|
|
50
|
+
...(repeat && {
|
|
51
|
+
repeat,
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.traverseCompositeSlice = traverseCompositeSlice;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { OnFieldFn } from "../../../_internal/utils";
|
|
3
|
+
import { Group, NestedGroup } from "../Group";
|
|
4
|
+
import { NestableWidget } from "../nestable/NestableWidget";
|
|
2
5
|
import type { SharedSliceRef } from "./SharedSliceRef";
|
|
3
6
|
import type { DynamicSlice, StaticSlice } from "./Slice";
|
|
4
7
|
export declare const Variation: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
@@ -1584,3 +1587,13 @@ export declare const SharedSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
1584
1587
|
export declare type SharedSlice = t.TypeOf<typeof SharedSlice>;
|
|
1585
1588
|
export declare function isStaticSharedSlice(slice: StaticSlice): slice is SharedSlice;
|
|
1586
1589
|
export declare function isDynamicSharedSlice(slice: DynamicSlice): slice is SharedSliceRef;
|
|
1590
|
+
export declare function traverseVariation(args: {
|
|
1591
|
+
path: ReadonlyArray<string>;
|
|
1592
|
+
variation: Variation;
|
|
1593
|
+
onField: OnFieldFn<NestableWidget | Group | NestedGroup>;
|
|
1594
|
+
}): Variation;
|
|
1595
|
+
export declare function traverseSharedSlice(args: {
|
|
1596
|
+
path: ReadonlyArray<string>;
|
|
1597
|
+
slice: SharedSlice;
|
|
1598
|
+
onField: OnFieldFn<NestableWidget | Group | NestedGroup>;
|
|
1599
|
+
}): SharedSlice;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDynamicSharedSlice = exports.isStaticSharedSlice = exports.SharedSlice = exports.SharedSliceType = exports.Variation = void 0;
|
|
3
|
+
exports.traverseSharedSlice = exports.traverseVariation = exports.isDynamicSharedSlice = exports.isStaticSharedSlice = exports.SharedSlice = exports.SharedSliceType = exports.Variation = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const withFallback_1 = require("io-ts-types/lib/withFallback");
|
|
7
7
|
const common_1 = require("../../../common");
|
|
8
|
+
const Group_1 = require("../Group");
|
|
8
9
|
const NestableWidget_1 = require("../nestable/NestableWidget");
|
|
9
10
|
const SlicePrimaryWidget_1 = require("./SlicePrimaryWidget");
|
|
10
11
|
const IMAGE_PLACEHOLDER_URL = "https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format";
|
|
@@ -46,3 +47,75 @@ function isDynamicSharedSlice(slice) {
|
|
|
46
47
|
return slice.type === "SharedSlice";
|
|
47
48
|
}
|
|
48
49
|
exports.isDynamicSharedSlice = isDynamicSharedSlice;
|
|
50
|
+
function traverseVariation(args) {
|
|
51
|
+
const { path: prevPath, variation, onField } = args;
|
|
52
|
+
return {
|
|
53
|
+
...variation,
|
|
54
|
+
...(variation.primary && {
|
|
55
|
+
primary: Object.entries(variation.primary).reduce((acc, [key, prevField]) => {
|
|
56
|
+
const path = prevPath.concat("primary", key);
|
|
57
|
+
let field;
|
|
58
|
+
switch (prevField.type) {
|
|
59
|
+
case "Group":
|
|
60
|
+
field = (0, Group_1.traverseGroup)({
|
|
61
|
+
path,
|
|
62
|
+
group: prevField,
|
|
63
|
+
onField: onField,
|
|
64
|
+
});
|
|
65
|
+
break;
|
|
66
|
+
case "Boolean":
|
|
67
|
+
case "Color":
|
|
68
|
+
case "Date":
|
|
69
|
+
case "Embed":
|
|
70
|
+
case "GeoPoint":
|
|
71
|
+
case "Image":
|
|
72
|
+
case "IntegrationFields":
|
|
73
|
+
case "Link":
|
|
74
|
+
case "Number":
|
|
75
|
+
case "Range":
|
|
76
|
+
case "Select":
|
|
77
|
+
case "Separator":
|
|
78
|
+
case "StructuredText":
|
|
79
|
+
case "Table":
|
|
80
|
+
case "Text":
|
|
81
|
+
case "Timestamp":
|
|
82
|
+
field = prevField;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
acc[key] = onField({
|
|
86
|
+
path,
|
|
87
|
+
key,
|
|
88
|
+
field,
|
|
89
|
+
});
|
|
90
|
+
return acc;
|
|
91
|
+
}, {}),
|
|
92
|
+
}),
|
|
93
|
+
...(variation.items && {
|
|
94
|
+
items: Object.entries(variation.items).reduce((acc, [key, field]) => {
|
|
95
|
+
const path = prevPath.concat("items", key);
|
|
96
|
+
acc[key] = onField({
|
|
97
|
+
path,
|
|
98
|
+
key,
|
|
99
|
+
field,
|
|
100
|
+
});
|
|
101
|
+
return acc;
|
|
102
|
+
}, {}),
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
exports.traverseVariation = traverseVariation;
|
|
107
|
+
function traverseSharedSlice(args) {
|
|
108
|
+
const { path: prevPath, slice, onField } = args;
|
|
109
|
+
return {
|
|
110
|
+
...slice,
|
|
111
|
+
variations: slice.variations.map((variation) => {
|
|
112
|
+
const path = prevPath.concat(variation.id);
|
|
113
|
+
return traverseVariation({
|
|
114
|
+
path,
|
|
115
|
+
variation,
|
|
116
|
+
onField,
|
|
117
|
+
});
|
|
118
|
+
}),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
exports.traverseSharedSlice = traverseSharedSlice;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { OnFieldFn } from "../../../_internal/utils";
|
|
3
|
+
import { Group, NestedGroup } from "../Group";
|
|
4
|
+
import type { NestableWidget } from "../nestable";
|
|
2
5
|
import { SharedSlice } from "./SharedSlice";
|
|
3
6
|
import { SharedSliceRef } from "./SharedSliceRef";
|
|
4
7
|
export declare const LegacySlicesFieldType = "Choice";
|
|
@@ -5387,3 +5390,8 @@ export declare type DynamicSlices = t.TypeOf<typeof DynamicSlices>;
|
|
|
5387
5390
|
export declare const Slices: {
|
|
5388
5391
|
toStatic(slices: DynamicSlices, sharedSlices: Map<string, SharedSlice>): StaticSlices;
|
|
5389
5392
|
};
|
|
5393
|
+
export declare function traverseSlices<T extends DynamicSlices | StaticSlices>(args: {
|
|
5394
|
+
path: ReadonlyArray<string>;
|
|
5395
|
+
slices: T;
|
|
5396
|
+
onField: OnFieldFn<NestableWidget | Group | NestedGroup>;
|
|
5397
|
+
}): T;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Slices = exports.DynamicSlices = exports.StaticSlices = exports.slicesReader = exports.DynamicSlicesConfig = exports.StaticSlicesConfig = exports.slicesConfigReader = exports.SlicesLabels = exports.SlicesFieldType = exports.LegacySlicesFieldType = void 0;
|
|
3
|
+
exports.traverseSlices = exports.Slices = exports.DynamicSlices = exports.StaticSlices = exports.slicesReader = exports.DynamicSlicesConfig = exports.StaticSlicesConfig = exports.slicesConfigReader = exports.SlicesLabels = exports.SlicesFieldType = exports.LegacySlicesFieldType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const common_1 = require("../../../common");
|
|
7
7
|
const validators_1 = require("../../../validators");
|
|
8
|
+
const Group_1 = require("../Group");
|
|
8
9
|
const CompositeSlice_1 = require("./CompositeSlice");
|
|
9
10
|
const LegacySlice_1 = require("./LegacySlice");
|
|
10
11
|
const SharedSlice_1 = require("./SharedSlice");
|
|
@@ -78,3 +79,76 @@ exports.Slices = {
|
|
|
78
79
|
}
|
|
79
80
|
},
|
|
80
81
|
};
|
|
82
|
+
function traverseSlices(args) {
|
|
83
|
+
var _a;
|
|
84
|
+
const { path: prevPath, slices, onField } = args;
|
|
85
|
+
const choices = ((_a = slices.config) === null || _a === void 0 ? void 0 : _a.choices) &&
|
|
86
|
+
Object.entries(slices.config.choices).reduce((acc, [key, prevModel]) => {
|
|
87
|
+
const path = prevPath.concat(key);
|
|
88
|
+
let model;
|
|
89
|
+
switch (prevModel.type) {
|
|
90
|
+
case "Slice":
|
|
91
|
+
model = (0, CompositeSlice_1.traverseCompositeSlice)({
|
|
92
|
+
path,
|
|
93
|
+
slice: prevModel,
|
|
94
|
+
onField: 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
|
+
case "Group":
|
|
108
|
+
model = onField({
|
|
109
|
+
path,
|
|
110
|
+
key,
|
|
111
|
+
field: (0, Group_1.traverseNestedGroup)({
|
|
112
|
+
path,
|
|
113
|
+
group: prevModel,
|
|
114
|
+
onField: onField,
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
117
|
+
break;
|
|
118
|
+
case "Boolean":
|
|
119
|
+
case "Color":
|
|
120
|
+
case "Date":
|
|
121
|
+
case "Embed":
|
|
122
|
+
case "GeoPoint":
|
|
123
|
+
case "Image":
|
|
124
|
+
case "IntegrationFields":
|
|
125
|
+
case "Link":
|
|
126
|
+
case "Number":
|
|
127
|
+
case "Range":
|
|
128
|
+
case "Select":
|
|
129
|
+
case "Separator":
|
|
130
|
+
case "StructuredText":
|
|
131
|
+
case "Table":
|
|
132
|
+
case "Text":
|
|
133
|
+
case "Timestamp":
|
|
134
|
+
model = onField({
|
|
135
|
+
path,
|
|
136
|
+
key,
|
|
137
|
+
field: prevModel,
|
|
138
|
+
});
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
acc[key] = model;
|
|
142
|
+
return acc;
|
|
143
|
+
}, {});
|
|
144
|
+
return {
|
|
145
|
+
...slices,
|
|
146
|
+
...(slices.config && {
|
|
147
|
+
config: {
|
|
148
|
+
...slices.config,
|
|
149
|
+
...(choices && { choices }),
|
|
150
|
+
},
|
|
151
|
+
}),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
exports.traverseSlices = traverseSlices;
|
package/package.json
CHANGED
package/src/_internal/utils.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
CompositeSlice,
|
|
9
9
|
Group,
|
|
10
10
|
NestableWidget,
|
|
11
|
+
NestedGroup,
|
|
11
12
|
StaticSlices,
|
|
12
13
|
UID,
|
|
13
14
|
VariationFields,
|
|
@@ -91,3 +92,6 @@ export type SliceModel =
|
|
|
91
92
|
| NestableWidget
|
|
92
93
|
| CompositeSlice
|
|
93
94
|
| Group
|
|
95
|
+
|
|
96
|
+
export type OnFieldFn<T extends UID | NestableWidget | Group | NestedGroup> =
|
|
97
|
+
(args: { path: ReadonlyArray<string>; key: string; field: T }) => T
|
|
@@ -2,8 +2,15 @@ import { Either, left, right } from "fp-ts/lib/Either"
|
|
|
2
2
|
import * as t from "io-ts"
|
|
3
3
|
import { withFallback } from "io-ts-types/lib/withFallback"
|
|
4
4
|
|
|
5
|
+
import type { OnFieldFn } from "../_internal/utils"
|
|
5
6
|
import { StringOrNull } from "../validators"
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
DynamicSection,
|
|
9
|
+
Sections,
|
|
10
|
+
StaticSection,
|
|
11
|
+
traverseSection,
|
|
12
|
+
} from "./Section"
|
|
13
|
+
import type { Group, NestableWidget, NestedGroup, UID } from "./widgets"
|
|
7
14
|
import type { SharedSlice } from "./widgets/slices/SharedSlice"
|
|
8
15
|
import type { DynamicSlice } from "./widgets/slices/Slice"
|
|
9
16
|
import type { DynamicSlices } from "./widgets/slices/Slices"
|
|
@@ -245,3 +252,25 @@ export function collectSharedSlices(customType: {
|
|
|
245
252
|
return acc
|
|
246
253
|
}, {})
|
|
247
254
|
}
|
|
255
|
+
|
|
256
|
+
export function traverseCustomType<
|
|
257
|
+
T extends CustomType | StaticCustomType,
|
|
258
|
+
>(args: {
|
|
259
|
+
customType: T
|
|
260
|
+
onField: OnFieldFn<UID | NestableWidget | Group | NestedGroup>
|
|
261
|
+
}): T {
|
|
262
|
+
const { customType, onField } = args
|
|
263
|
+
return {
|
|
264
|
+
...customType,
|
|
265
|
+
json: Object.entries(customType.json).reduce<
|
|
266
|
+
Record<string, typeof customType.json[string]>
|
|
267
|
+
>((acc, [key, section]) => {
|
|
268
|
+
acc[key] = traverseSection({
|
|
269
|
+
path: [key],
|
|
270
|
+
section,
|
|
271
|
+
onField,
|
|
272
|
+
})
|
|
273
|
+
return acc
|
|
274
|
+
}, {}),
|
|
275
|
+
}
|
|
276
|
+
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
+
import type { OnFieldFn } from "../_internal/utils"
|
|
3
4
|
import { WidgetKey } from "../common"
|
|
5
|
+
import {
|
|
6
|
+
Group,
|
|
7
|
+
NestableWidget,
|
|
8
|
+
NestedGroup,
|
|
9
|
+
traverseGroup,
|
|
10
|
+
traverseSlices,
|
|
11
|
+
UID,
|
|
12
|
+
} from "./widgets"
|
|
4
13
|
import type { SharedSlice } from "./widgets/slices"
|
|
5
14
|
import { DynamicWidget, StaticWidget, Widgets } from "./widgets/Widget"
|
|
6
15
|
|
|
@@ -33,3 +42,63 @@ export const Sections = {
|
|
|
33
42
|
return section as StaticSection
|
|
34
43
|
},
|
|
35
44
|
}
|
|
45
|
+
|
|
46
|
+
export function traverseSection<
|
|
47
|
+
T extends DynamicSection | StaticSection,
|
|
48
|
+
>(args: {
|
|
49
|
+
path: ReadonlyArray<string>
|
|
50
|
+
section: T
|
|
51
|
+
onField: OnFieldFn<UID | NestableWidget | Group | NestedGroup>
|
|
52
|
+
}): T {
|
|
53
|
+
const { path: prevPath, section, onField } = args
|
|
54
|
+
return Object.entries(section).reduce((acc, [key, prevModel]) => {
|
|
55
|
+
const path = prevPath.concat(key)
|
|
56
|
+
let model
|
|
57
|
+
switch (prevModel.type) {
|
|
58
|
+
case "Choice":
|
|
59
|
+
case "Slices":
|
|
60
|
+
model = traverseSlices({
|
|
61
|
+
path,
|
|
62
|
+
slices: prevModel,
|
|
63
|
+
onField: onField as OnFieldFn<NestableWidget | Group | NestedGroup>,
|
|
64
|
+
})
|
|
65
|
+
break
|
|
66
|
+
case "Group":
|
|
67
|
+
model = onField({
|
|
68
|
+
path,
|
|
69
|
+
key,
|
|
70
|
+
field: traverseGroup({
|
|
71
|
+
path,
|
|
72
|
+
group: prevModel,
|
|
73
|
+
onField: onField as OnFieldFn<NestableWidget | NestedGroup>,
|
|
74
|
+
}),
|
|
75
|
+
})
|
|
76
|
+
break
|
|
77
|
+
case "Boolean":
|
|
78
|
+
case "Color":
|
|
79
|
+
case "Date":
|
|
80
|
+
case "Embed":
|
|
81
|
+
case "GeoPoint":
|
|
82
|
+
case "Image":
|
|
83
|
+
case "IntegrationFields":
|
|
84
|
+
case "Link":
|
|
85
|
+
case "Number":
|
|
86
|
+
case "Range":
|
|
87
|
+
case "Select":
|
|
88
|
+
case "Separator":
|
|
89
|
+
case "StructuredText":
|
|
90
|
+
case "Table":
|
|
91
|
+
case "Text":
|
|
92
|
+
case "Timestamp":
|
|
93
|
+
case "UID":
|
|
94
|
+
model = onField({
|
|
95
|
+
path,
|
|
96
|
+
key,
|
|
97
|
+
field: prevModel,
|
|
98
|
+
})
|
|
99
|
+
break
|
|
100
|
+
}
|
|
101
|
+
acc[key] = model
|
|
102
|
+
return acc
|
|
103
|
+
}, {} as T)
|
|
104
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
+
import type { OnFieldFn } from "../../_internal/utils"
|
|
3
4
|
import { WidgetKey } from "../../common"
|
|
4
5
|
import { StringOrNull } from "../../validators"
|
|
5
6
|
import { NestableWidget } from "./nestable/NestableWidget"
|
|
@@ -47,3 +48,92 @@ export type GroupConfig = t.TypeOf<typeof GroupConfig>
|
|
|
47
48
|
|
|
48
49
|
export const Group = createGroup(t.union([NestableWidget, NestedGroup]))
|
|
49
50
|
export type Group = t.TypeOf<typeof Group>
|
|
51
|
+
|
|
52
|
+
export function traverseNestedGroup(args: {
|
|
53
|
+
path: ReadonlyArray<string>
|
|
54
|
+
group: NestedGroup
|
|
55
|
+
onField: OnFieldFn<NestableWidget>
|
|
56
|
+
}): NestedGroup {
|
|
57
|
+
const { path: prevPath, group, onField } = args
|
|
58
|
+
const fields =
|
|
59
|
+
group.config?.fields &&
|
|
60
|
+
Object.entries(group.config.fields).reduce<Record<string, NestableWidget>>(
|
|
61
|
+
(acc, [key, model]) => {
|
|
62
|
+
const path = prevPath.concat(key)
|
|
63
|
+
acc[key] = onField({
|
|
64
|
+
path,
|
|
65
|
+
key,
|
|
66
|
+
field: model,
|
|
67
|
+
})
|
|
68
|
+
return acc
|
|
69
|
+
},
|
|
70
|
+
{},
|
|
71
|
+
)
|
|
72
|
+
return {
|
|
73
|
+
...group,
|
|
74
|
+
...(group.config && {
|
|
75
|
+
config: {
|
|
76
|
+
...group.config,
|
|
77
|
+
...(fields && { fields }),
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function traverseGroup(args: {
|
|
84
|
+
path: ReadonlyArray<string>
|
|
85
|
+
group: Group
|
|
86
|
+
onField: OnFieldFn<NestableWidget | NestedGroup>
|
|
87
|
+
}): Group {
|
|
88
|
+
const { path: prevPath, group, onField } = args
|
|
89
|
+
const fields =
|
|
90
|
+
group.config?.fields &&
|
|
91
|
+
Object.entries(group.config.fields).reduce<
|
|
92
|
+
Record<string, NestableWidget | NestedGroup>
|
|
93
|
+
>((acc, [key, prevField]) => {
|
|
94
|
+
const path = prevPath.concat(key)
|
|
95
|
+
let field
|
|
96
|
+
switch (prevField.type) {
|
|
97
|
+
case "Group":
|
|
98
|
+
field = traverseNestedGroup({
|
|
99
|
+
path,
|
|
100
|
+
group: prevField,
|
|
101
|
+
onField: onField as OnFieldFn<NestableWidget>,
|
|
102
|
+
})
|
|
103
|
+
break
|
|
104
|
+
case "Boolean":
|
|
105
|
+
case "Color":
|
|
106
|
+
case "Date":
|
|
107
|
+
case "Embed":
|
|
108
|
+
case "GeoPoint":
|
|
109
|
+
case "Image":
|
|
110
|
+
case "IntegrationFields":
|
|
111
|
+
case "Link":
|
|
112
|
+
case "Number":
|
|
113
|
+
case "Range":
|
|
114
|
+
case "Select":
|
|
115
|
+
case "Separator":
|
|
116
|
+
case "StructuredText":
|
|
117
|
+
case "Table":
|
|
118
|
+
case "Text":
|
|
119
|
+
case "Timestamp":
|
|
120
|
+
field = prevField
|
|
121
|
+
break
|
|
122
|
+
}
|
|
123
|
+
acc[key] = onField({
|
|
124
|
+
path,
|
|
125
|
+
key,
|
|
126
|
+
field,
|
|
127
|
+
})
|
|
128
|
+
return acc
|
|
129
|
+
}, {})
|
|
130
|
+
return {
|
|
131
|
+
...group,
|
|
132
|
+
...(group.config && {
|
|
133
|
+
config: {
|
|
134
|
+
...group.config,
|
|
135
|
+
...(fields && { fields }),
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
+
import type { OnFieldFn } from "../../../_internal/utils"
|
|
3
4
|
import { WidgetKey } from "../../../common"
|
|
4
5
|
import { StringOrNull } from "../../../validators"
|
|
5
6
|
import { NestableWidget } from "../nestable/NestableWidget"
|
|
@@ -37,3 +38,40 @@ export function isCompositeSlice(
|
|
|
37
38
|
): slice is CompositeSlice {
|
|
38
39
|
return slice.type === "Slice"
|
|
39
40
|
}
|
|
41
|
+
|
|
42
|
+
export function traverseCompositeSlice(args: {
|
|
43
|
+
path: ReadonlyArray<string>
|
|
44
|
+
slice: CompositeSlice
|
|
45
|
+
onField: OnFieldFn<NestableWidget>
|
|
46
|
+
}): CompositeSlice {
|
|
47
|
+
const { path: prevPath, slice, onField } = args
|
|
48
|
+
const nonRepeat =
|
|
49
|
+
slice["non-repeat"] &&
|
|
50
|
+
Object.entries(slice["non-repeat"]).reduce<Record<string, NestableWidget>>(
|
|
51
|
+
(acc, [key, field]) => {
|
|
52
|
+
const path = prevPath.concat("non-repeat", key)
|
|
53
|
+
acc[key] = onField({ path, key, field })
|
|
54
|
+
return acc
|
|
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
|
+
}),
|
|
76
|
+
}
|
|
77
|
+
}
|