@prismicio/types-internal 2.8.0 → 2.9.0-alpha.1

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 (54) hide show
  1. package/lib/_internal/utils.d.ts +3 -2
  2. package/lib/content/Document.d.ts +1369 -61
  3. package/lib/content/Document.js +11 -0
  4. package/lib/content/LegacyContentCtx.d.ts +2 -2
  5. package/lib/content/LegacyContentCtx.js +4 -1
  6. package/lib/content/fields/GroupContent.js +13 -0
  7. package/lib/content/fields/RepeatableContent.d.ts +162 -0
  8. package/lib/content/fields/RepeatableContent.js +93 -0
  9. package/lib/content/fields/WidgetContent.d.ts +1369 -61
  10. package/lib/content/fields/index.d.ts +1 -0
  11. package/lib/content/fields/index.js +1 -0
  12. package/lib/content/fields/nestable/LinkContent.d.ts +23 -0
  13. package/lib/content/fields/nestable/LinkContent.js +23 -0
  14. package/lib/content/fields/nestable/NestableContent.d.ts +218 -0
  15. package/lib/content/fields/nestable/NestableContent.js +8 -1
  16. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +66 -66
  17. package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +727 -0
  18. package/lib/content/fields/nestable/RichTextContent/TextBlock.js +80 -0
  19. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +438 -2
  20. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +74 -0
  21. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +440 -4
  22. package/lib/content/fields/slices/Slice/SharedSliceContent.js +20 -4
  23. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +219 -1
  24. package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +219 -1
  25. package/lib/content/fields/slices/Slice/index.d.ts +735 -5
  26. package/lib/content/fields/slices/SliceItem.d.ts +734 -4
  27. package/lib/content/fields/slices/SlicesContent.d.ts +1098 -8
  28. package/lib/customtypes/CustomType.d.ts +18 -0
  29. package/lib/customtypes/Section.d.ts +18 -0
  30. package/lib/customtypes/diff/SharedSlice.d.ts +8 -0
  31. package/lib/customtypes/diff/Variation.d.ts +8 -0
  32. package/lib/customtypes/widgets/Group.d.ts +6 -0
  33. package/lib/customtypes/widgets/Widget.d.ts +21 -0
  34. package/lib/customtypes/widgets/nestable/Link.d.ts +2 -0
  35. package/lib/customtypes/widgets/nestable/Link.js +5 -1
  36. package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +1 -0
  37. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +2 -0
  38. package/lib/customtypes/widgets/slices/LegacySlice.d.ts +2 -0
  39. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +8 -0
  40. package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +6 -0
  41. package/lib/customtypes/widgets/slices/SliceWidget.d.ts +327 -0
  42. package/lib/customtypes/widgets/slices/SliceWidget.js +8 -0
  43. package/lib/customtypes/widgets/slices/Slices.d.ts +28 -0
  44. package/package.json +1 -1
  45. package/src/_internal/utils.ts +3 -1
  46. package/src/content/Document.ts +12 -0
  47. package/src/content/LegacyContentCtx.ts +4 -1
  48. package/src/content/fields/GroupContent.ts +13 -0
  49. package/src/content/fields/RepeatableContent.ts +147 -0
  50. package/src/content/fields/index.ts +1 -0
  51. package/src/content/fields/nestable/LinkContent.ts +24 -0
  52. package/src/content/fields/nestable/NestableContent.ts +12 -1
  53. package/src/content/fields/slices/Slice/SharedSliceContent.ts +18 -0
  54. package/src/customtypes/widgets/nestable/Link.ts +5 -1
@@ -158,6 +158,7 @@ function traverseDocument({ document, customType, }) {
158
158
  { key, type: "Widget" },
159
159
  ]);
160
160
  const transformedWidget = (() => {
161
+ var _a;
161
162
  switch (content.__TYPE__) {
162
163
  case "SliceContentType":
163
164
  return (0, fields_1.traverseSlices)({
@@ -176,6 +177,16 @@ function traverseDocument({ document, customType, }) {
176
177
  model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Group" ? fieldModel : undefined,
177
178
  content,
178
179
  })(transformWidget);
180
+ case "RepeatableContent":
181
+ return (0, fields_1.traverseRepeatableContent)({
182
+ path,
183
+ key,
184
+ apiId: key,
185
+ model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Link" && ((_a = fieldModel.config) === null || _a === void 0 ? void 0 : _a.repeat)
186
+ ? fieldModel
187
+ : undefined,
188
+ content,
189
+ })(transformWidget);
179
190
  default:
180
191
  return transformWidget({
181
192
  path,
@@ -1,5 +1,5 @@
1
1
  import * as t from "io-ts";
2
- export declare const FieldOrSliceType: t.UnionC<[t.KeyofC<{
2
+ export declare const FieldOrSliceType: t.UnionC<[t.UnionC<[t.KeyofC<{
3
3
  Color: null;
4
4
  Boolean: null;
5
5
  Number: null;
@@ -22,7 +22,7 @@ export declare const FieldOrSliceType: t.UnionC<[t.KeyofC<{
22
22
  }>, t.KeyofC<{
23
23
  Slice: null;
24
24
  SharedSlice: null;
25
- }>]>;
25
+ }>]>, t.LiteralC<"Repeatable.Link">]>;
26
26
  export declare type FieldOrSliceType = t.TypeOf<typeof FieldOrSliceType>;
27
27
  export declare class LegacyContentCtx {
28
28
  fieldKey: string;
@@ -4,7 +4,10 @@ exports.defaultCtx = exports.getFieldCtx = exports.LegacyContentCtx = exports.Fi
4
4
  const tslib_1 = require("tslib");
5
5
  const t = (0, tslib_1.__importStar)(require("io-ts"));
6
6
  const widgets_1 = require("../customtypes/widgets");
7
- exports.FieldOrSliceType = t.union([widgets_1.FieldType, widgets_1.SlicesTypes]);
7
+ exports.FieldOrSliceType = t.union([
8
+ t.union([widgets_1.FieldType, widgets_1.SlicesTypes]),
9
+ t.literal("Repeatable.Link"),
10
+ ]);
8
11
  class LegacyContentCtx {
9
12
  constructor(fieldKey, fieldPath, allTypes) {
10
13
  Object.defineProperty(this, "fieldKey", {
@@ -10,6 +10,7 @@ const customtypes_1 = require("../../customtypes");
10
10
  const LegacyContentCtx_1 = require("../LegacyContentCtx");
11
11
  const utils_1 = require("../utils");
12
12
  const nestable_1 = require("./nestable");
13
+ const RepeatableContent_1 = require("./RepeatableContent");
13
14
  const withDefaultValues_1 = require("./withDefaultValues");
14
15
  exports.GroupItemContentType = "GroupItemContent";
15
16
  exports.GroupContentType = "GroupContentType";
@@ -129,6 +130,7 @@ function traverseGroupItemsContent({ path, model, content, }) {
129
130
  { key: index.toString(), type: "GroupItem" },
130
131
  ]);
131
132
  const groupItemFields = groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
133
+ var _a;
132
134
  const fieldDef = model === null || model === void 0 ? void 0 : model[fieldKey];
133
135
  let transformedField;
134
136
  if ((!fieldDef || (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === customtypes_1.GroupFieldType) &&
@@ -141,6 +143,17 @@ function traverseGroupItemsContent({ path, model, content, }) {
141
143
  content: fieldContent,
142
144
  })(transform);
143
145
  }
146
+ else if ((!fieldDef ||
147
+ ((fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === "Link" && ((_a = fieldDef.config) === null || _a === void 0 ? void 0 : _a.repeat))) &&
148
+ fieldContent.__TYPE__ === "RepeatableContent") {
149
+ transformedField = (0, RepeatableContent_1.traverseRepeatableContent)({
150
+ path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]),
151
+ key: fieldKey,
152
+ apiId: fieldKey,
153
+ model: fieldDef,
154
+ content: fieldContent,
155
+ })(transform);
156
+ }
144
157
  else {
145
158
  transformedField = transform({
146
159
  path: groupItemPath.concat([{ key: fieldKey, type: "Widget" }]),
@@ -0,0 +1,162 @@
1
+ import * as t from "io-ts";
2
+ import type { ContentPath, TraverseWidgetContentFn } from "../../_internal/utils";
3
+ import type { Link, NestableWidget } from "../../customtypes";
4
+ import type { LegacyContentCtx, WithTypes } from "../LegacyContentCtx";
5
+ export declare const RepeatableContent: t.ExactC<t.TypeC<{
6
+ __TYPE__: t.LiteralC<"RepeatableContent">;
7
+ type: t.LiteralC<"Link">;
8
+ value: t.ArrayC<t.ExactC<t.TypeC<{
9
+ __TYPE__: t.LiteralC<"LinkContent">;
10
+ value: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
11
+ __TYPE__: t.LiteralC<"ImageLink">;
12
+ }>>, t.UnionC<[t.IntersectionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
13
+ kind: t.StringC;
14
+ id: t.StringC;
15
+ url: t.StringC;
16
+ height: t.StringC;
17
+ width: t.StringC;
18
+ size: t.StringC;
19
+ name: t.StringC;
20
+ }>>, t.ExactC<t.PartialC<{
21
+ date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
22
+ }>>]>, t.ExactC<t.PartialC<{
23
+ text: t.StringC;
24
+ }>>]>, t.ExactC<t.TypeC<{
25
+ kind: t.LiteralC<"image">;
26
+ text: t.StringC;
27
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
28
+ __TYPE__: t.LiteralC<"FileLink">;
29
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
30
+ kind: t.StringC;
31
+ id: t.StringC;
32
+ url: t.StringC;
33
+ name: t.StringC;
34
+ size: t.StringC;
35
+ }>, t.PartialC<{
36
+ date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
37
+ }>]>>, t.ExactC<t.PartialC<{
38
+ text: t.StringC;
39
+ }>>]>, t.ExactC<t.TypeC<{
40
+ kind: t.LiteralC<"file">;
41
+ text: t.StringC;
42
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
43
+ __TYPE__: t.LiteralC<"DocumentLink">;
44
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
45
+ id: t.Type<string, string, unknown>;
46
+ }>>, t.ExactC<t.PartialC<{
47
+ text: t.StringC;
48
+ }>>]>, t.ExactC<t.TypeC<{
49
+ kind: t.LiteralC<"document">;
50
+ text: t.StringC;
51
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
52
+ __TYPE__: t.LiteralC<"ExternalLink">;
53
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
54
+ url: t.StringC;
55
+ }>, t.PartialC<{
56
+ kind: t.LiteralC<"web">;
57
+ target: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
58
+ preview: t.UnionC<[t.Type<{
59
+ title?: string;
60
+ }, {
61
+ title?: string;
62
+ }, unknown>, t.NullC, t.UndefinedC]>;
63
+ }>]>>, t.ExactC<t.PartialC<{
64
+ text: t.StringC;
65
+ }>>]>, t.ExactC<t.TypeC<{
66
+ kind: t.LiteralC<"web">;
67
+ text: t.StringC;
68
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
69
+ __TYPE__: t.LiteralC<"MediaLink">;
70
+ }>>, t.ExactC<t.TypeC<{
71
+ kind: t.LiteralC<"media">;
72
+ text: t.StringC;
73
+ }>>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
74
+ __TYPE__: t.LiteralC<"AnyLink">;
75
+ }>>, t.ExactC<t.TypeC<{
76
+ text: t.StringC;
77
+ }>>]>]>;
78
+ }>>>;
79
+ }>>;
80
+ export declare type RepeatableContent = t.TypeOf<typeof RepeatableContent>;
81
+ export declare const isRepeatableContent: t.Is<{
82
+ __TYPE__: "RepeatableContent";
83
+ type: "Link";
84
+ value: {
85
+ __TYPE__: "LinkContent";
86
+ value: ({
87
+ __TYPE__: "ImageLink";
88
+ } & (({
89
+ kind: string;
90
+ id: string;
91
+ url: string;
92
+ height: string;
93
+ width: string;
94
+ size: string;
95
+ name: string;
96
+ } & {
97
+ date?: string | null | undefined;
98
+ } & {
99
+ text?: string;
100
+ }) | {
101
+ kind: "image";
102
+ text: string;
103
+ })) | ({
104
+ __TYPE__: "FileLink";
105
+ } & (({
106
+ kind: string;
107
+ id: string;
108
+ url: string;
109
+ name: string;
110
+ size: string;
111
+ } & {
112
+ date?: string | null | undefined;
113
+ } & {
114
+ text?: string;
115
+ }) | {
116
+ kind: "file";
117
+ text: string;
118
+ })) | ({
119
+ __TYPE__: "MediaLink";
120
+ } & {
121
+ kind: "media";
122
+ text: string;
123
+ }) | ({
124
+ __TYPE__: "DocumentLink";
125
+ } & (({
126
+ id: string;
127
+ } & {
128
+ text?: string;
129
+ }) | {
130
+ kind: "document";
131
+ text: string;
132
+ })) | ({
133
+ __TYPE__: "ExternalLink";
134
+ } & (({
135
+ url: string;
136
+ } & {
137
+ kind?: "web";
138
+ target?: string | null | undefined;
139
+ preview?: {
140
+ title?: string;
141
+ } | null | undefined;
142
+ } & {
143
+ text?: string;
144
+ }) | {
145
+ kind: "web";
146
+ text: string;
147
+ })) | ({
148
+ __TYPE__: "AnyLink";
149
+ } & {
150
+ text: string;
151
+ });
152
+ }[];
153
+ }>;
154
+ export declare const RepeatableLegacy: (ctx: LegacyContentCtx, fieldType: "Link") => t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>;
155
+ export declare type RepeatableCustomType = Link;
156
+ export declare function traverseRepeatableContent({ path, key, apiId, model, content, }: {
157
+ path: ContentPath;
158
+ key: string;
159
+ apiId: string;
160
+ content: RepeatableContent;
161
+ model?: NestableWidget | undefined;
162
+ }): (transform: TraverseWidgetContentFn) => RepeatableContent | undefined;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fp_ts_1 = require("fp-ts");
6
+ const Either_1 = require("fp-ts/lib/Either");
7
+ const function_1 = require("fp-ts/lib/function");
8
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
9
+ const nestable_1 = require("./nestable");
10
+ exports.RepeatableContent = t.strict({
11
+ __TYPE__: t.literal("RepeatableContent"),
12
+ type: t.literal("Link"),
13
+ value: t.array(nestable_1.LinkContent),
14
+ });
15
+ exports.isRepeatableContent = exports.RepeatableContent.is;
16
+ const RepeatableLegacy = (ctx, fieldType) => {
17
+ return new t.Type("RepeatableLegacy", exports.isRepeatableContent, (items) => {
18
+ const parsed = (0, function_1.pipe)(t.array(t.unknown).decode(items), fp_ts_1.either.map((items) => {
19
+ const parsedItems = items.reduce((acc, item) => {
20
+ let result;
21
+ switch (fieldType) {
22
+ case "Link":
23
+ result = (0, nestable_1.LinkContentLegacy)(ctx).decode(item);
24
+ break;
25
+ }
26
+ if (!result)
27
+ return acc;
28
+ if ((0, Either_1.isLeft)(result))
29
+ return acc;
30
+ return [...acc, result.right];
31
+ }, []);
32
+ return {
33
+ value: parsedItems,
34
+ type: fieldType,
35
+ __TYPE__: "RepeatableContent",
36
+ };
37
+ }));
38
+ return parsed;
39
+ }, (r) => {
40
+ const res = t.array(nestable_1.LinkContent).encode(r.value);
41
+ const encodedItems = res.reduce((acc, item) => {
42
+ let encoded;
43
+ switch (item.__TYPE__) {
44
+ case nestable_1.LinkContentType:
45
+ encoded = (0, nestable_1.LinkContentLegacy)(ctx).encode(item);
46
+ break;
47
+ }
48
+ if (!encoded)
49
+ return acc;
50
+ return [...acc, encoded];
51
+ }, []);
52
+ return {
53
+ content: encodedItems.map((encodedItem) => encodedItem.content),
54
+ types: { [ctx.keyOfType]: `Repeatable.${fieldType}` },
55
+ };
56
+ });
57
+ };
58
+ exports.RepeatableLegacy = RepeatableLegacy;
59
+ function traverseRepeatableContent({ path, key, apiId, model, content, }) {
60
+ return (transform) => {
61
+ const items = content.value.reduce((acc, fieldContent, index) => {
62
+ const itemPath = path.concat([
63
+ { key: index.toString(), type: "Widget" },
64
+ ]);
65
+ const transformedField = transform({
66
+ path: itemPath,
67
+ key: key,
68
+ apiId: apiId,
69
+ model: model,
70
+ content: fieldContent,
71
+ });
72
+ // Can happen if the transform function returns undefined to filter out a field
73
+ if (!transformedField)
74
+ return acc;
75
+ // If the transformed field is not a link content, we don't include it
76
+ if (!(0, nestable_1.isLinkContent)(transformedField))
77
+ return acc;
78
+ return acc.concat(transformedField);
79
+ }, []);
80
+ return transform({
81
+ path,
82
+ key,
83
+ apiId,
84
+ model,
85
+ content: {
86
+ __TYPE__: content.__TYPE__,
87
+ type: content.type,
88
+ value: items,
89
+ },
90
+ });
91
+ };
92
+ }
93
+ exports.traverseRepeatableContent = traverseRepeatableContent;