@prismicio/types-internal 3.11.2 → 3.12.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +764 -0
  2. package/lib/content/Document.d.ts +32 -7
  3. package/lib/content/Document.js +22 -8
  4. package/lib/content/LegacyContentCtx.d.ts +25 -3
  5. package/lib/content/LegacyContentCtx.js +67 -5
  6. package/lib/content/fields/GroupContent.d.ts +4 -2
  7. package/lib/content/fields/GroupContent.js +38 -15
  8. package/lib/content/fields/UIDContent.js +1 -0
  9. package/lib/content/fields/WidgetContent.d.ts +6 -0
  10. package/lib/content/fields/nestable/BooleanContent.js +1 -0
  11. package/lib/content/fields/nestable/EmbedContent.js +1 -0
  12. package/lib/content/fields/nestable/FieldContent/ColorContent.js +1 -0
  13. package/lib/content/fields/nestable/FieldContent/DateContent.js +1 -0
  14. package/lib/content/fields/nestable/FieldContent/NumberContent.js +1 -0
  15. package/lib/content/fields/nestable/FieldContent/RangeContent.js +1 -0
  16. package/lib/content/fields/nestable/FieldContent/SelectContent.js +1 -0
  17. package/lib/content/fields/nestable/FieldContent/TextContent.js +1 -0
  18. package/lib/content/fields/nestable/FieldContent/TimestampContent.js +1 -0
  19. package/lib/content/fields/nestable/GeoPointContent.js +1 -0
  20. package/lib/content/fields/nestable/ImageContent.js +1 -0
  21. package/lib/content/fields/nestable/IntegrationFieldContent.js +1 -0
  22. package/lib/content/fields/nestable/LinkContent.js +2 -0
  23. package/lib/content/fields/nestable/RepeatableContent.js +1 -0
  24. package/lib/content/fields/nestable/RichTextContent/index.js +1 -0
  25. package/lib/content/fields/nestable/SeparatorContent.js +1 -0
  26. package/lib/content/fields/nestable/TableContent.js +1 -0
  27. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +3 -0
  28. package/lib/content/fields/slices/Slice/CompositeSliceContent.js +19 -5
  29. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +5 -4
  30. package/lib/content/fields/slices/Slice/RepeatableContent.js +2 -1
  31. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +3 -0
  32. package/lib/content/fields/slices/Slice/SharedSliceContent.js +26 -19
  33. package/lib/content/fields/slices/Slice/SimpleSliceContent.js +1 -0
  34. package/lib/content/fields/slices/Slice/index.d.ts +4 -0
  35. package/lib/content/fields/slices/SliceItem.d.ts +13 -1
  36. package/lib/content/fields/slices/SliceItem.js +14 -3
  37. package/lib/content/fields/slices/SlicesContent.d.ts +18 -12
  38. package/lib/content/fields/slices/SlicesContent.js +3 -1
  39. package/lib/customtypes/CustomType.js +6 -9
  40. package/lib/customtypes/Section.js +3 -8
  41. package/lib/customtypes/widgets/Group.js +20 -20
  42. package/lib/customtypes/widgets/nestable/NestableWidgetZ.d.ts +3 -0
  43. package/lib/customtypes/widgets/nestable/NestableWidgetZ.js +29 -0
  44. package/lib/customtypes/widgets/slices/CompositeSlice.js +9 -22
  45. package/lib/customtypes/widgets/slices/SharedSlice.js +18 -37
  46. package/lib/customtypes/widgets/slices/SharedSliceZ.d.ts +16 -0
  47. package/lib/customtypes/widgets/slices/SharedSliceZ.js +39 -0
  48. package/lib/customtypes/widgets/slices/SlicePrimaryWidgetZ.d.ts +3 -0
  49. package/lib/customtypes/widgets/slices/SlicePrimaryWidgetZ.js +6 -0
  50. package/lib/customtypes/widgets/slices/Slices.js +9 -16
  51. package/package.json +1 -1
  52. package/src/content/Document.ts +31 -8
  53. package/src/content/LegacyContentCtx.ts +72 -16
  54. package/src/content/fields/GroupContent.ts +56 -14
  55. package/src/content/fields/UIDContent.ts +1 -0
  56. package/src/content/fields/nestable/BooleanContent.ts +1 -0
  57. package/src/content/fields/nestable/EmbedContent.ts +1 -0
  58. package/src/content/fields/nestable/FieldContent/ColorContent.ts +1 -0
  59. package/src/content/fields/nestable/FieldContent/DateContent.ts +1 -0
  60. package/src/content/fields/nestable/FieldContent/NumberContent.ts +1 -0
  61. package/src/content/fields/nestable/FieldContent/RangeContent.ts +1 -0
  62. package/src/content/fields/nestable/FieldContent/SelectContent.ts +1 -0
  63. package/src/content/fields/nestable/FieldContent/TextContent.ts +1 -0
  64. package/src/content/fields/nestable/FieldContent/TimestampContent.ts +1 -0
  65. package/src/content/fields/nestable/GeoPointContent.ts +1 -0
  66. package/src/content/fields/nestable/ImageContent.ts +1 -0
  67. package/src/content/fields/nestable/IntegrationFieldContent.ts +1 -0
  68. package/src/content/fields/nestable/LinkContent.ts +2 -0
  69. package/src/content/fields/nestable/RepeatableContent.ts +4 -0
  70. package/src/content/fields/nestable/RichTextContent/index.ts +1 -0
  71. package/src/content/fields/nestable/SeparatorContent.ts +1 -0
  72. package/src/content/fields/nestable/TableContent.ts +1 -0
  73. package/src/content/fields/slices/Slice/CompositeSliceContent.ts +19 -5
  74. package/src/content/fields/slices/Slice/RepeatableContent.ts +7 -2
  75. package/src/content/fields/slices/Slice/SharedSliceContent.ts +26 -19
  76. package/src/content/fields/slices/Slice/SimpleSliceContent.ts +1 -0
  77. package/src/content/fields/slices/SliceItem.ts +15 -4
  78. package/src/content/fields/slices/SlicesContent.ts +10 -2
  79. package/src/customtypes/CustomType.ts +6 -9
  80. package/src/customtypes/Section.ts +3 -9
  81. package/src/customtypes/widgets/Group.ts +20 -21
  82. package/src/customtypes/widgets/slices/CompositeSlice.ts +9 -22
  83. package/src/customtypes/widgets/slices/SharedSlice.ts +23 -38
  84. package/src/customtypes/widgets/slices/Slices.ts +9 -15
  85. package/lib/content/fields/RepeatableContent.d.ts +0 -162
  86. package/lib/content/fields/RepeatableContent.js +0 -93
  87. package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +0 -727
  88. package/lib/content/fields/nestable/RichTextContent/TextBlock.js +0 -80
  89. package/lib/customtypes/widgets/slices/SliceWidget.d.ts +0 -327
  90. package/lib/customtypes/widgets/slices/SliceWidget.js +0 -8
@@ -52,7 +52,7 @@ export function traverseSection<
52
52
  }): T {
53
53
  const { path: prevPath, section: prevSection, onField } = args
54
54
 
55
- let section: T | undefined
55
+ const section = { ...prevSection }
56
56
  for (const [key, prevModel] of Object.entries(prevSection)) {
57
57
  const path = [...prevPath, key]
58
58
  let model
@@ -84,13 +84,7 @@ export function traverseSection<
84
84
  })
85
85
  break
86
86
  }
87
-
88
- if (model !== prevModel) {
89
- if (!section) section = { ...prevSection }
90
- section[key] = model
91
- }
87
+ section[key] = model
92
88
  }
93
-
94
- // returns the traversed model instead of a new one if it didn't change
95
- return section ?? prevSection
89
+ return section
96
90
  }
@@ -58,23 +58,23 @@ export function traverseNestedGroup(args: {
58
58
 
59
59
  if (!group.config?.fields) return group
60
60
 
61
- let fields: Record<string, NestableWidget> | undefined
62
- for (const [key, field] of Object.entries(group.config.fields)) {
61
+ const fields: Record<string, NestableWidget> = {}
62
+ for (const [key, prevField] of Object.entries(group.config.fields)) {
63
63
  const path = [...prevPath, key]
64
- const newField = onField({
64
+ fields[key] = onField({
65
65
  path,
66
66
  key,
67
- field,
67
+ field: prevField,
68
68
  })
69
-
70
- if (field !== newField) {
71
- if (!fields) fields = { ...group.config.fields }
72
- fields[key] = newField
73
- }
74
69
  }
75
70
 
76
- // returns the traversed model instead of a new one if it didn't change
77
- return fields ? { ...group, config: { ...group.config, fields } } : group
71
+ return {
72
+ ...group,
73
+ config: {
74
+ ...group.config,
75
+ fields,
76
+ },
77
+ }
78
78
  }
79
79
 
80
80
  export function traverseGroup(args: {
@@ -86,7 +86,7 @@ export function traverseGroup(args: {
86
86
 
87
87
  if (!group.config?.fields) return group
88
88
 
89
- let fields: Record<string, NestableWidget | NestedGroup> | undefined
89
+ const fields: Record<string, NestableWidget | NestedGroup> = {}
90
90
  for (const [key, prevField] of Object.entries(group.config.fields)) {
91
91
  const path = [...prevPath, key]
92
92
  let field
@@ -102,19 +102,18 @@ export function traverseGroup(args: {
102
102
  field = prevField
103
103
  break
104
104
  }
105
-
106
- const newField = onField({
105
+ fields[key] = onField({
107
106
  path,
108
107
  key,
109
108
  field,
110
109
  })
111
-
112
- if (field !== newField) {
113
- if (!fields) fields = { ...group.config.fields }
114
- fields[key] = newField
115
- }
116
110
  }
117
111
 
118
- // returns the traversed model instead of a new one if it didn't change
119
- return fields ? { ...group, config: { ...group.config, fields } } : group
112
+ return {
113
+ ...group,
114
+ config: {
115
+ ...group.config,
116
+ fields,
117
+ },
118
+ }
120
119
  }
@@ -46,34 +46,21 @@ export function traverseCompositeSlice(args: {
46
46
  }): CompositeSlice {
47
47
  const { path: prevPath, slice, onField } = args
48
48
 
49
- let nonRepeat: Record<string, NestableWidget> | undefined
49
+ const nonRepeat: Record<string, NestableWidget> = {}
50
50
  for (const [key, field] of Object.entries(slice["non-repeat"] ?? {})) {
51
51
  const path = [...prevPath, "non-repeat", key]
52
- const newField = onField({ path, key, field })
53
-
54
- if (field !== newField) {
55
- if (!nonRepeat) nonRepeat = { ...slice["non-repeat"] }
56
- nonRepeat[key] = newField
57
- }
52
+ nonRepeat[key] = onField({ path, key, field })
58
53
  }
59
54
 
60
- let repeat: Record<string, NestableWidget> | undefined
55
+ const repeat: Record<string, NestableWidget> = {}
61
56
  for (const [key, field] of Object.entries(slice.repeat ?? {})) {
62
57
  const path = [...prevPath, "repeat", key]
63
- const newField = onField({ path, key, field })
64
-
65
- if (field !== newField) {
66
- if (!repeat) repeat = { ...slice.repeat }
67
- repeat[key] = newField
68
- }
58
+ repeat[key] = onField({ path, key, field })
69
59
  }
70
60
 
71
- // returns the traversed model instead of a new one if it didn't change
72
- return repeat || nonRepeat
73
- ? {
74
- ...slice,
75
- ...(nonRepeat && { "non-repeat": nonRepeat }),
76
- ...(repeat && { repeat }),
77
- }
78
- : slice
61
+ return {
62
+ ...slice,
63
+ ...(slice["non-repeat"] && { "non-repeat": nonRepeat }),
64
+ ...(slice.repeat && { repeat }),
65
+ }
79
66
  }
@@ -79,7 +79,7 @@ export function traverseVariation(args: {
79
79
  }): Variation {
80
80
  const { path: prevPath, variation, onField } = args
81
81
 
82
- let primary: Record<string, NestableWidget | Group> | undefined
82
+ const primary: Record<string, NestableWidget | Group> = {}
83
83
  for (const [key, prevField] of Object.entries(variation.primary ?? {})) {
84
84
  const path = [...prevPath, "primary", key]
85
85
  let field
@@ -95,32 +95,20 @@ export function traverseVariation(args: {
95
95
  field = prevField
96
96
  break
97
97
  }
98
-
99
- const newField = onField({ path, key, field })
100
- if (field !== newField) {
101
- if (!primary) primary = { ...variation.primary }
102
- primary[key] = newField
103
- }
98
+ primary[key] = onField({ path, key, field })
104
99
  }
105
100
 
106
- let items: Record<string, NestableWidget> | undefined
107
- for (const [key, prevField] of Object.entries(variation.items ?? {})) {
101
+ const items: Record<string, NestableWidget> = {}
102
+ for (const [key, field] of Object.entries(variation.items ?? {})) {
108
103
  const path = [...prevPath, "items", key]
109
- const newField = (onField as OnFieldFn<NestableWidget>)({
110
- path,
111
- key,
112
- field: prevField,
113
- })
114
- if (prevField !== newField) {
115
- if (!items) items = { ...variation.items }
116
- items[key] = newField
117
- }
104
+ items[key] = (onField as OnFieldFn<NestableWidget>)({ path, key, field })
118
105
  }
119
106
 
120
- // returns the traversed model instead of a new one if it didn't change
121
- return primary || items
122
- ? { ...variation, ...(primary && { primary }), ...(items && { items }) }
123
- : variation
107
+ return {
108
+ ...variation,
109
+ ...(variation.primary && { primary }),
110
+ ...(variation.items && { items }),
111
+ }
124
112
  }
125
113
 
126
114
  export function traverseSharedSlice(args: {
@@ -130,23 +118,20 @@ export function traverseSharedSlice(args: {
130
118
  }): SharedSlice {
131
119
  const { path: prevPath, slice, onField } = args
132
120
 
133
- let variations: Variation[] | undefined
134
- for (let i = 0; i < slice.variations.length; i++) {
135
- const variation = slice.variations[i]
136
- if (!variation) continue
121
+ const variations: Variation[] = []
122
+ for (const variation of slice.variations) {
137
123
  const path = [...prevPath, variation.id]
138
- const newVariation = traverseVariation({
139
- path,
140
- variation,
141
- onField,
142
- })
143
-
144
- if (newVariation !== variation) {
145
- if (!variations) variations = [...slice.variations]
146
- variations[i] = newVariation
147
- }
124
+ variations.push(
125
+ traverseVariation({
126
+ path,
127
+ variation,
128
+ onField,
129
+ }),
130
+ )
148
131
  }
149
132
 
150
- // returns the traversed model instead of a new one if it didn't change
151
- return variations ? { ...slice, variations } : slice
133
+ return {
134
+ ...slice,
135
+ variations,
136
+ }
152
137
  }
@@ -123,7 +123,7 @@ export function traverseSlices<T extends DynamicSlices | StaticSlices>(args: {
123
123
 
124
124
  if (!slices.config?.choices) return slices
125
125
 
126
- let choices: Record<string, typeof slices.config.choices[string]> | undefined
126
+ const choices: Record<string, typeof slices.config.choices[string]> = {}
127
127
  for (const [key, prevModel] of Object.entries(slices.config.choices)) {
128
128
  const path = [...prevPath, key]
129
129
  let model
@@ -165,20 +165,14 @@ export function traverseSlices<T extends DynamicSlices | StaticSlices>(args: {
165
165
  break
166
166
  }
167
167
 
168
- if (model !== prevModel) {
169
- if (!choices) choices = { ...slices.config.choices }
170
- choices[key] = model as typeof slices.config.choices[string]
171
- }
168
+ choices[key] = model as typeof slices.config.choices[string]
172
169
  }
173
170
 
174
- // returns the traversed model instead of a new one if it didn't change
175
- return choices
176
- ? {
177
- ...slices,
178
- config: {
179
- ...slices.config,
180
- choices,
181
- },
182
- }
183
- : slices
171
+ return {
172
+ ...slices,
173
+ config: {
174
+ ...slices.config,
175
+ choices,
176
+ },
177
+ }
184
178
  }
@@ -1,162 +0,0 @@
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;
@@ -1,93 +0,0 @@
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;