@prismicio/types-internal 2.5.0-alpha.2 → 2.5.0-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.
Files changed (34) hide show
  1. package/lib/content/Document.d.ts +8 -8
  2. package/lib/content/fields/GroupContent.d.ts +8 -8
  3. package/lib/content/fields/GroupContent.js +14 -32
  4. package/lib/content/fields/WidgetContent.d.ts +8 -8
  5. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +4 -4
  6. package/lib/content/fields/slices/Slice/CompositeSliceContent.js +0 -3
  7. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +3 -2
  8. package/lib/content/fields/slices/Slice/RepeatableContent.js +4 -1
  9. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +4 -4
  10. package/lib/content/fields/slices/Slice/SharedSliceContent.js +0 -2
  11. package/lib/content/fields/slices/Slice/SimpleSliceContent.js +0 -1
  12. package/lib/content/fields/slices/Slice/index.d.ts +6 -6
  13. package/lib/content/fields/slices/SliceItem.d.ts +6 -6
  14. package/lib/content/fields/slices/SlicesContent.d.ts +8 -8
  15. package/lib/customtypes/CustomType.d.ts +2042 -690
  16. package/lib/customtypes/Section.d.ts +2028 -676
  17. package/lib/customtypes/diff/SharedSlice.d.ts +678 -2
  18. package/lib/customtypes/diff/Variation.d.ts +678 -3
  19. package/lib/customtypes/widgets/Group.d.ts +996 -15
  20. package/lib/customtypes/widgets/Group.js +15 -27
  21. package/lib/customtypes/widgets/Widget.d.ts +1684 -7
  22. package/lib/customtypes/widgets/slices/LegacySlice.d.ts +168 -2
  23. package/lib/customtypes/widgets/slices/LegacySlice.js +1 -1
  24. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +670 -2
  25. package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +674 -3
  26. package/lib/customtypes/widgets/slices/Slices.d.ts +1522 -7
  27. package/package.json +1 -1
  28. package/src/content/fields/GroupContent.ts +24 -48
  29. package/src/content/fields/slices/Slice/CompositeSliceContent.ts +4 -7
  30. package/src/content/fields/slices/Slice/RepeatableContent.ts +9 -2
  31. package/src/content/fields/slices/Slice/SharedSliceContent.ts +3 -5
  32. package/src/content/fields/slices/Slice/SimpleSliceContent.ts +1 -3
  33. package/src/customtypes/widgets/Group.ts +34 -61
  34. package/src/customtypes/widgets/slices/LegacySlice.ts +2 -2
@@ -1,33 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Group = exports.GroupConfig = exports.GroupFieldType = void 0;
3
+ 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");
7
7
  const validators_1 = require("../../validators");
8
- const function_1 = require("../../validators/function");
9
8
  const NestableWidget_1 = require("./nestable/NestableWidget");
10
9
  exports.GroupFieldType = "Group";
11
- exports.GroupConfig = t.recursion("GroupConfig", () => t.exact(t.partial({
10
+ // We're obliged to use `t.Mixed` here, otherwise the factory would be
11
+ // referencing itself and TypeScript would infer its type as `any`
12
+ const createGroupConfig = (widgets) => t.exact(t.partial({
12
13
  label: validators_1.StringOrNull,
13
14
  repeat: t.boolean,
14
- fields: t.record(common_1.WidgetKey, t.union([exports.Group, NestableWidget_1.NestableWidget])),
15
- })));
16
- const MAX_GROUP_DEPTH = 1;
17
- const getGroupDepth = (group, depth = 0) => {
18
- var _a, _b;
19
- // Stop searching when we're over limit
20
- if (depth > MAX_GROUP_DEPTH)
21
- return depth;
22
- for (const key in (_a = group.config) === null || _a === void 0 ? void 0 : _a.fields) {
23
- const field = (_b = group.config) === null || _b === void 0 ? void 0 : _b.fields[key];
24
- if ((field === null || field === void 0 ? void 0 : field.type) === exports.GroupFieldType) {
25
- depth = Math.max(depth, getGroupDepth(field, depth + 1));
26
- }
27
- }
28
- return depth;
29
- };
30
- exports.Group = (0, function_1.refineType)(t.recursion("Group", () => t.exact(t.intersection([
15
+ fields: t.record(common_1.WidgetKey, widgets),
16
+ }));
17
+ // We're obliged to use `t.Mixed` here, otherwise the factory would be
18
+ // referencing itself and TypeScript would infer its type as `any`
19
+ const createGroup = (widgets) => t.exact(t.intersection([
31
20
  t.type({
32
21
  type: t.literal(exports.GroupFieldType),
33
22
  }),
@@ -35,11 +24,10 @@ exports.Group = (0, function_1.refineType)(t.recursion("Group", () => t.exact(t.
35
24
  fieldset: validators_1.StringOrNull,
36
25
  icon: t.string,
37
26
  description: t.string,
38
- config: exports.GroupConfig,
27
+ config: createGroupConfig(widgets),
39
28
  }),
40
- ]))), "Group", (g) => {
41
- if (getGroupDepth(g) > MAX_GROUP_DEPTH) {
42
- throw new Error(`Group is nested too deeply (max ${MAX_GROUP_DEPTH} level)`);
43
- }
44
- return true;
45
- });
29
+ ]));
30
+ exports.NestedGroupConfig = createGroupConfig(NestableWidget_1.NestableWidget);
31
+ exports.NestedGroup = createGroup(NestableWidget_1.NestableWidget);
32
+ exports.GroupConfig = createGroupConfig(t.union([NestableWidget_1.NestableWidget, exports.NestedGroup]));
33
+ exports.Group = createGroup(t.union([NestableWidget_1.NestableWidget, exports.NestedGroup]));