@prismicio/types-internal 3.17.0-alpha.2 → 3.17.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.
@@ -3,7 +3,7 @@ import { WidgetKey } from "../common";
3
3
  import { type StaticWidget, StaticCustomType } from "../customtypes";
4
4
  import { WidgetContent } from "./fields";
5
5
  import { FieldOrSliceType, WithTypes } from "./LegacyContentCtx";
6
- import { ContentPath, TraverseSliceContentFn, TraverseWidgetContentFn } from "./utils";
6
+ import { ContentPath, TraverseSliceContentFn, TraverseSliceContentWithModelFn, TraverseWidgetContentFn, TraverseWidgetContentWithModelFn } from "./utils";
7
7
  export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.UnionC<[t.Type<import("./fields").GroupContent, import("./fields").GroupContent, unknown>, t.UnionC<[t.ExactC<t.TypeC<{
8
8
  type: t.StringC;
9
9
  __TYPE__: t.LiteralC<"EmptyContent">;
@@ -11800,4 +11800,14 @@ export declare function migrateDocument(document: Document, customType: StaticCu
11800
11800
  }[];
11801
11801
  };
11802
11802
  };
11803
+ export declare function traverseDocumentWithModel({ document, customType, }: {
11804
+ document: Document;
11805
+ customType: StaticCustomType | {
11806
+ customTypeId: string;
11807
+ fields: Record<string, StaticWidget>;
11808
+ };
11809
+ }): ({ transformWidget, transformSlice, }: {
11810
+ transformWidget: TraverseWidgetContentWithModelFn;
11811
+ transformSlice: TraverseSliceContentWithModelFn;
11812
+ }) => Document;
11803
11813
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.migrateDocument = exports.collectWidgets = exports.traverseDocument = exports.fillDocumentWithDefaultValues = exports.DocumentLegacy = exports.Document = void 0;
3
+ exports.traverseDocumentWithModel = exports.migrateDocument = exports.collectWidgets = exports.traverseDocument = exports.fillDocumentWithDefaultValues = exports.DocumentLegacy = exports.Document = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
6
  const Either_1 = require("fp-ts/lib/Either");
@@ -264,3 +264,101 @@ function migrateDocument(document, customType) {
264
264
  });
265
265
  }
266
266
  exports.migrateDocument = migrateDocument;
267
+ function traverseDocumentWithModel({ document, customType, }) {
268
+ const model = customtypes_1.StaticCustomType.is(customType)
269
+ ? simplifyCustomType(customType)
270
+ : customType;
271
+ return ({ transformWidget, transformSlice, }) => {
272
+ return Object.entries(model.fields).reduce((acc, [key, fieldModel]) => {
273
+ const content = document[key];
274
+ const path = utils_1.ContentPath.make([
275
+ { key: model.customTypeId, type: "CustomType" },
276
+ { key, type: "Widget" },
277
+ ]);
278
+ const transformedWidget = (() => {
279
+ var _a;
280
+ switch (fieldModel.type) {
281
+ case "Choice":
282
+ case "Slices": {
283
+ const slicesContent = (0, fields_1.isSlicesContent)(content)
284
+ ? content
285
+ : undefined;
286
+ return (0, fields_1.traverseSlicesWithModel)({
287
+ path,
288
+ key,
289
+ model: fieldModel,
290
+ content: slicesContent,
291
+ })({ transformWidget, transformSlice });
292
+ }
293
+ case "Group": {
294
+ const groupContent = (0, fields_1.isGroupContent)(content) ? content : undefined;
295
+ return (0, fields_1.traverseGroupContentWithModel)({
296
+ path,
297
+ key,
298
+ model: fieldModel,
299
+ content: groupContent,
300
+ })(transformWidget);
301
+ }
302
+ case "Link": {
303
+ if (((_a = fieldModel.config) === null || _a === void 0 ? void 0 : _a.repeat) === true) {
304
+ const repeatableContent = (0, fields_1.isRepeatableContent)(content)
305
+ ? content
306
+ : undefined;
307
+ return (0, fields_1.traverseRepeatableContentWithModel)({
308
+ path,
309
+ key,
310
+ model: fieldModel,
311
+ content: repeatableContent,
312
+ })(transformWidget);
313
+ }
314
+ const nestableContent = (0, fields_1.isNestableContent)(content)
315
+ ? content
316
+ : undefined;
317
+ return transformWidget({
318
+ path,
319
+ key,
320
+ apiId: key,
321
+ model: fieldModel,
322
+ content: nestableContent,
323
+ });
324
+ }
325
+ case "Table": {
326
+ const tableContent = (0, fields_1.isTableContent)(content) ? content : undefined;
327
+ return (0, fields_1.traverseTableContentWithModel)({
328
+ path,
329
+ key,
330
+ model: fieldModel,
331
+ content: tableContent,
332
+ })(transformWidget);
333
+ }
334
+ case "UID": {
335
+ return transformWidget({
336
+ path,
337
+ key,
338
+ apiId: key,
339
+ model: fieldModel,
340
+ content,
341
+ });
342
+ }
343
+ default: {
344
+ const nestableContent = (0, fields_1.isNestableContent)(content)
345
+ ? content
346
+ : undefined;
347
+ return transformWidget({
348
+ path,
349
+ key,
350
+ apiId: key,
351
+ model: fieldModel,
352
+ content: nestableContent,
353
+ });
354
+ }
355
+ }
356
+ })();
357
+ return {
358
+ ...acc,
359
+ ...(transformedWidget ? { [key]: transformedWidget } : {}),
360
+ };
361
+ }, {});
362
+ };
363
+ }
364
+ exports.traverseDocumentWithModel = traverseDocumentWithModel;
@@ -1,7 +1,7 @@
1
1
  import * as t from "io-ts";
2
- import { type Group, type NestableWidget } from "../../customtypes";
2
+ import { type Group, type NestableWidget, type NestedGroup } from "../../customtypes";
3
3
  import { LegacyContentCtx, WithTypes } from "../LegacyContentCtx";
4
- import { ContentPath, TraverseWidgetContentFn } from "../utils";
4
+ import { ContentPath, TraverseWidgetContentFn, TraverseWidgetContentWithModelFn } from "../utils";
5
5
  import { NestableContent } from "./nestable";
6
6
  export declare const GroupItemContentType: "GroupItemContent";
7
7
  export declare const GroupContentType: "GroupContentType";
@@ -39,4 +39,15 @@ export declare function traverseGroupItemsContent({ path, model, content, }: {
39
39
  content: Array<GroupItemContent>;
40
40
  model?: Record<string, Group | NestableWidget> | undefined;
41
41
  }): (transform: TraverseWidgetContentFn) => Array<GroupItemContent>;
42
+ export declare function traverseGroupContentWithModel({ path, key, model, content, }: {
43
+ path: ContentPath;
44
+ key: string;
45
+ model: Group;
46
+ content: GroupContent | undefined;
47
+ }): (transform: TraverseWidgetContentWithModelFn) => GroupContent | undefined;
48
+ export declare function traverseGroupItemsContentWithModel({ path, model, content, }: {
49
+ path: ContentPath;
50
+ model: Record<string, NestableWidget | Group | NestedGroup>;
51
+ content: Array<GroupItemContent> | undefined;
52
+ }): (transform: TraverseWidgetContentWithModelFn) => Array<GroupItemContent>;
42
53
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.groupContentWithDefaultValues = exports.GroupLegacy = exports.arrayWithIndexCodec = exports.GroupItemLegacy = exports.GroupContentDefaultValue = exports.isGroupContent = exports.GroupContent = exports.GroupItemContent = exports.GroupContentType = exports.GroupItemContentType = void 0;
3
+ exports.traverseGroupItemsContentWithModel = exports.traverseGroupContentWithModel = exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.groupContentWithDefaultValues = exports.GroupLegacy = exports.arrayWithIndexCodec = exports.GroupItemLegacy = exports.GroupContentDefaultValue = exports.isGroupContent = exports.GroupContent = exports.GroupItemContent = exports.GroupContentType = exports.GroupItemContentType = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
6
  const Either_1 = require("fp-ts/lib/Either");
@@ -206,3 +206,102 @@ function traverseGroupItemsContent({ path, model, content, }) {
206
206
  };
207
207
  }
208
208
  exports.traverseGroupItemsContent = traverseGroupItemsContent;
209
+ function traverseGroupContentWithModel({ path, key, model, content, }) {
210
+ return (transform) => {
211
+ var _a, _b;
212
+ const groupItems = traverseGroupItemsContentWithModel({
213
+ path,
214
+ model: (_b = (_a = model.config) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : {},
215
+ content: content === null || content === void 0 ? void 0 : content.value,
216
+ })(transform);
217
+ return transform({
218
+ path,
219
+ key,
220
+ apiId: key,
221
+ model,
222
+ content: content
223
+ ? {
224
+ __TYPE__: content.__TYPE__,
225
+ value: groupItems,
226
+ }
227
+ : undefined,
228
+ });
229
+ };
230
+ }
231
+ exports.traverseGroupContentWithModel = traverseGroupContentWithModel;
232
+ function traverseGroupItemsContentWithModel({ path, model, content, }) {
233
+ return (transform) => {
234
+ if (!content)
235
+ return [];
236
+ return content.map((groupItem) => {
237
+ const groupItemPath = path.concat([
238
+ { key: groupItem.key, type: "GroupItem" },
239
+ ]);
240
+ const groupItemFields = Object.entries(model).reduce((acc, [fieldKey, fieldModel]) => {
241
+ var _a, _b;
242
+ const fieldContent = (_a = groupItem.value.find(([key]) => key === fieldKey)) === null || _a === void 0 ? void 0 : _a[1];
243
+ const fieldPath = groupItemPath.concat([
244
+ { key: fieldKey, type: "Widget" },
245
+ ]);
246
+ let transformedField;
247
+ if (fieldModel.type === "Group") {
248
+ const groupContent = (0, exports.isGroupContent)(fieldContent)
249
+ ? fieldContent
250
+ : undefined;
251
+ transformedField = traverseGroupContentWithModel({
252
+ path: fieldPath,
253
+ key: fieldKey,
254
+ model: fieldModel,
255
+ content: groupContent,
256
+ })(transform);
257
+ }
258
+ else if (fieldModel.type === "Link" &&
259
+ ((_b = fieldModel.config) === null || _b === void 0 ? void 0 : _b.repeat) === true) {
260
+ const repeatableContent = (0, nestable_1.isRepeatableContent)(fieldContent)
261
+ ? fieldContent
262
+ : undefined;
263
+ transformedField = (0, nestable_1.traverseRepeatableContentWithModel)({
264
+ path: fieldPath,
265
+ key: fieldKey,
266
+ model: fieldModel,
267
+ content: repeatableContent,
268
+ })(transform);
269
+ }
270
+ else if (fieldModel.type === "Table") {
271
+ const tableContent = (0, nestable_1.isTableContent)(fieldContent)
272
+ ? fieldContent
273
+ : undefined;
274
+ transformedField = (0, nestable_1.traverseTableContentWithModel)({
275
+ path: fieldPath,
276
+ key: fieldKey,
277
+ model: fieldModel,
278
+ content: tableContent,
279
+ })(transform);
280
+ }
281
+ else {
282
+ const nestableContent = (0, nestable_1.isNestableContent)(fieldContent)
283
+ ? fieldContent
284
+ : undefined;
285
+ transformedField = transform({
286
+ path: fieldPath,
287
+ key: fieldKey,
288
+ apiId: fieldKey,
289
+ model: fieldModel,
290
+ content: nestableContent,
291
+ });
292
+ }
293
+ if (!transformedField ||
294
+ !((0, nestable_1.isNestableContent)(transformedField) ||
295
+ (0, exports.isGroupContent)(transformedField)))
296
+ return acc;
297
+ return acc.concat([[fieldKey, transformedField]]);
298
+ }, []);
299
+ return {
300
+ __TYPE__: groupItem.__TYPE__,
301
+ key: groupItem.key,
302
+ value: groupItemFields,
303
+ };
304
+ });
305
+ };
306
+ }
307
+ exports.traverseGroupItemsContentWithModel = traverseGroupItemsContentWithModel;
@@ -31,7 +31,7 @@ const t = (0, tslib_1.__importStar)(require("io-ts"));
31
31
  const io_ts_types_1 = require("io-ts-types");
32
32
  const validators_1 = require("../../../validators");
33
33
  const function_2 = require("../../../validators/function");
34
- const utils_1 = require("../../utils");
34
+ const helpers_1 = require("../../helpers");
35
35
  // ImageLink.
36
36
  exports.ImageLinkType = "ImageLink";
37
37
  const isImageLinkKind = (input) => typeof input === "string";
@@ -52,7 +52,7 @@ const filledImageLinkLegacyCodec = t.intersection([
52
52
  date: validators_1.StringOrNull,
53
53
  })),
54
54
  ]);
55
- const FilledImageLinkLegacy = new t.Type("FilledImageLink", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.ImageLinkType, (image) => {
55
+ const FilledImageLinkLegacy = new t.Type("FilledImageLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.ImageLinkType, (image) => {
56
56
  return (0, function_1.pipe)(filledImageLinkLegacyCodec.decode(image), fp_ts_1.either.map((parsedImage) => {
57
57
  return exports.FilledImageLinkContent.encode({
58
58
  ...parsedImage,
@@ -80,7 +80,7 @@ const imageLinkLegacyCodec = t.intersection([
80
80
  variant: t.string,
81
81
  })),
82
82
  ]);
83
- const ImageLinkLegacy = new t.Type("ImageLink", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.ImageLinkType, (image) => {
83
+ const ImageLinkLegacy = new t.Type("ImageLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.ImageLinkType, (image) => {
84
84
  return (0, function_1.pipe)(imageLinkLegacyCodec.decode(image), fp_ts_1.either.map((parsedImage) => {
85
85
  return exports.ImageLinkContent.encode({
86
86
  ...parsedImage,
@@ -112,7 +112,7 @@ const filledFileLinkLegacyCodec = t.exact(t.intersection([
112
112
  }),
113
113
  t.partial({ date: validators_1.StringOrNull }),
114
114
  ]));
115
- const FilledFileLinkLegacy = new t.Type("FilledFileLink", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.FileLinkType, (file) => {
115
+ const FilledFileLinkLegacy = new t.Type("FilledFileLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.FileLinkType, (file) => {
116
116
  return (0, function_1.pipe)(filledFileLinkLegacyCodec.decode(file), fp_ts_1.either.map((parsedFile) => {
117
117
  return exports.FilledFileLinkContent.encode({
118
118
  ...parsedFile,
@@ -140,7 +140,7 @@ const fileLinkLegacyCodec = t.intersection([
140
140
  variant: t.string,
141
141
  })),
142
142
  ]);
143
- const FileLinkLegacy = new t.Type("FileLink", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.FileLinkType, (file) => {
143
+ const FileLinkLegacy = new t.Type("FileLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.FileLinkType, (file) => {
144
144
  return (0, function_1.pipe)(fileLinkLegacyCodec.decode(file), fp_ts_1.either.map((parsedFile) => {
145
145
  return exports.FileLinkContent.encode({
146
146
  ...parsedFile,
@@ -167,7 +167,7 @@ const mediaLinkLegacyCodec = t.intersection([
167
167
  variant: t.string,
168
168
  })),
169
169
  ]);
170
- const MediaLinkLegacy = new t.Type("MediaLink", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.MediaLinkType, (mediaLink) => {
170
+ const MediaLinkLegacy = new t.Type("MediaLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.MediaLinkType, (mediaLink) => {
171
171
  return (0, function_1.pipe)(mediaLinkLegacyCodec.decode(mediaLink), fp_ts_1.either.map((parsedMediaLink) => {
172
172
  return exports.MediaLinkContent.encode({
173
173
  ...parsedMediaLink,
@@ -188,7 +188,7 @@ exports.DocumentLinkType = "DocumentLink";
188
188
  const filledDocumentLinkLegacyCodec = t.strict({
189
189
  id: validators_1.NonEmptyString,
190
190
  });
191
- const FilledDocumentLinkLegacy = new t.Type("FilledDocumentLink", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.DocumentLinkType, (doc) => {
191
+ const FilledDocumentLinkLegacy = new t.Type("FilledDocumentLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.DocumentLinkType, (doc) => {
192
192
  return (0, function_1.pipe)(filledDocumentLinkLegacyCodec.decode(doc), fp_ts_1.either.map((parsedDoc) => {
193
193
  return exports.FilledDocumentLinkContent.encode({
194
194
  ...parsedDoc,
@@ -216,7 +216,7 @@ const documentLinkLegacyCodec = t.intersection([
216
216
  variant: t.string,
217
217
  })),
218
218
  ]);
219
- const DocumentLinkLegacy = new t.Type("DocumentLink", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.DocumentLinkType, (file) => {
219
+ const DocumentLinkLegacy = new t.Type("DocumentLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.DocumentLinkType, (file) => {
220
220
  return (0, function_1.pipe)(documentLinkLegacyCodec.decode(file), fp_ts_1.either.map((parsedDoc) => {
221
221
  return exports.DocumentLinkContent.encode({
222
222
  ...parsedDoc,
@@ -246,7 +246,7 @@ const filledExternalLinkLegacyCodec = t.exact(t.intersection([
246
246
  })),
247
247
  }),
248
248
  ]));
249
- const FilledExternalLinkLegacy = new t.Type("FilledExternalLink", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.ExternalLinkType, (link) => {
249
+ const FilledExternalLinkLegacy = new t.Type("FilledExternalLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.ExternalLinkType, (link) => {
250
250
  return (0, function_1.pipe)(filledExternalLinkLegacyCodec.decode(link), fp_ts_1.either.map((parsedLink) => {
251
251
  return exports.FilledExternalLinkContent.encode({
252
252
  ...parsedLink,
@@ -274,7 +274,7 @@ const externalLinkLegacyCodec = t.intersection([
274
274
  variant: t.string,
275
275
  })),
276
276
  ]);
277
- const ExternalLinkLegacy = new t.Type("ExternalLink", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.ExternalLinkType, (file) => {
277
+ const ExternalLinkLegacy = new t.Type("ExternalLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.ExternalLinkType, (file) => {
278
278
  return (0, function_1.pipe)(externalLinkLegacyCodec.decode(file), fp_ts_1.either.map((parsedLink) => {
279
279
  return exports.ExternalLinkContent.encode({
280
280
  ...parsedLink,
@@ -301,7 +301,7 @@ const anyLinkLegacyCodec = t.exact(t.intersection([
301
301
  variant: t.string,
302
302
  }),
303
303
  ]));
304
- const AnyLinkLegacy = new t.Type("AnyLink", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.AnyLinkType, (anyLink) => {
304
+ const AnyLinkLegacy = new t.Type("AnyLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.AnyLinkType, (anyLink) => {
305
305
  return (0, function_1.pipe)(anyLinkLegacyCodec.decode(anyLink), fp_ts_1.either.map((parsedAnyLink) => {
306
306
  return exports.AnyLinkContent.encode({
307
307
  ...parsedAnyLink,
@@ -319,9 +319,9 @@ exports.AnyLinkContent = t.intersection([
319
319
  ]);
320
320
  // Link.
321
321
  exports.LinkContentType = "LinkContent";
322
- const isLinkContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.LinkContentType;
322
+ const isLinkContent = (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.LinkContentType;
323
323
  exports.isLinkContent = isLinkContent;
324
- exports.LinkLegacy = (0, utils_1.withKey)(t.union([
324
+ exports.LinkLegacy = (0, helpers_1.withKey)(t.union([
325
325
  ImageLinkLegacy,
326
326
  FileLinkLegacy,
327
327
  DocumentLinkLegacy,
@@ -354,12 +354,12 @@ exports.Link = t.union([
354
354
  exports.MediaLinkContent,
355
355
  exports.AnyLinkContent,
356
356
  ]);
357
- exports.LinkContent = (0, utils_1.withKey)(t.strict({
357
+ exports.LinkContent = (0, helpers_1.withKey)(t.strict({
358
358
  __TYPE__: t.literal(exports.LinkContentType),
359
359
  value: exports.Link,
360
360
  }));
361
361
  // FilledLink.
362
- const isFilledLinkContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.LinkContentType;
362
+ const isFilledLinkContent = (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.LinkContentType;
363
363
  exports.isFilledLinkContent = isFilledLinkContent;
364
364
  exports.FilledLinkLegacy = t.union([
365
365
  FilledImageLinkLegacy,
@@ -368,7 +368,7 @@ exports.FilledLinkLegacy = t.union([
368
368
  FilledExternalLinkLegacy,
369
369
  ]);
370
370
  const FilledLinkContentLegacy = (ctx) => {
371
- const FilledLinkLegacyWithKey = (0, utils_1.withKey)(exports.FilledLinkLegacy);
371
+ const FilledLinkLegacyWithKey = (0, helpers_1.withKey)(exports.FilledLinkLegacy);
372
372
  return new t.Type("FilledLinkLegacy", exports.isFilledLinkContent, (u) => {
373
373
  return (0, function_1.pipe)(FilledLinkLegacyWithKey.decode(u), fp_ts_1.either.map(({ key, ...value }) => exports.FilledLinkContent.encode({
374
374
  __TYPE__: "LinkContent",
@@ -393,7 +393,7 @@ exports.FilledLink = t.union([
393
393
  exports.FilledDocumentLinkContent,
394
394
  exports.FilledExternalLinkContent,
395
395
  ]);
396
- exports.FilledLinkContent = (0, utils_1.withKey)(t.strict({
396
+ exports.FilledLinkContent = (0, helpers_1.withKey)(t.strict({
397
397
  __TYPE__: t.literal(exports.LinkContentType),
398
398
  value: exports.FilledLink,
399
399
  }));
@@ -1,7 +1,7 @@
1
1
  import * as t from "io-ts";
2
2
  import type { Link, NestableWidget } from "../../../customtypes";
3
3
  import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
4
- import { ContentPath, TraverseWidgetContentFn } from "../../utils";
4
+ import { ContentPath, TraverseWidgetContentFn, TraverseWidgetContentWithModelFn } from "../../utils";
5
5
  export declare const RepeatableContent: t.ExactC<t.TypeC<{
6
6
  __TYPE__: t.LiteralC<"RepeatableContent">;
7
7
  type: t.LiteralC<"Link">;
@@ -174,3 +174,9 @@ export declare function traverseRepeatableContent({ path, key, apiId, model, con
174
174
  content: RepeatableContent;
175
175
  model?: NestableWidget | undefined;
176
176
  }): (transform: TraverseWidgetContentFn) => RepeatableContent | undefined;
177
+ export declare function traverseRepeatableContentWithModel({ path, key, model, content, }: {
178
+ path: ContentPath;
179
+ key: string;
180
+ model: NestableWidget;
181
+ content: RepeatableContent | undefined;
182
+ }): (transform: TraverseWidgetContentWithModelFn) => RepeatableContent | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent = void 0;
3
+ exports.traverseRepeatableContentWithModel = exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
6
  const Either_1 = require("fp-ts/lib/Either");
@@ -102,3 +102,45 @@ function traverseRepeatableContent({ path, key, apiId, model, content, }) {
102
102
  };
103
103
  }
104
104
  exports.traverseRepeatableContent = traverseRepeatableContent;
105
+ function traverseRepeatableContentWithModel({ path, key, model, content, }) {
106
+ return (transform) => {
107
+ var _a;
108
+ const items = (_a = content === null || content === void 0 ? void 0 : content.value.reduce((acc, fieldContent, index) => {
109
+ const itemPath = path.concat([
110
+ { key: index.toString(), type: "Widget" },
111
+ ]);
112
+ const newModel = (model === null || model === void 0 ? void 0 : model.type) === "Link" && model.config
113
+ ? {
114
+ ...model,
115
+ config: { ...model.config, repeat: false },
116
+ }
117
+ : model;
118
+ const transformedField = transform({
119
+ path: itemPath,
120
+ key: key,
121
+ apiId: key,
122
+ model: newModel,
123
+ content: fieldContent,
124
+ });
125
+ if (!transformedField)
126
+ return acc;
127
+ if (!(0, LinkContent_1.isLinkContent)(transformedField))
128
+ return acc;
129
+ return acc.concat(transformedField);
130
+ }, [])) !== null && _a !== void 0 ? _a : [];
131
+ return transform({
132
+ path,
133
+ key,
134
+ apiId: key,
135
+ model,
136
+ content: content
137
+ ? {
138
+ __TYPE__: content.__TYPE__,
139
+ type: content.type,
140
+ value: items,
141
+ }
142
+ : undefined,
143
+ });
144
+ };
145
+ }
146
+ exports.traverseRepeatableContentWithModel = traverseRepeatableContentWithModel;
@@ -1,7 +1,7 @@
1
1
  import * as t from "io-ts";
2
2
  import { type NestableWidget } from "../../../customtypes";
3
3
  import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
4
- import { ContentPath, TraverseWidgetContentFn } from "../../utils";
4
+ import type { ContentPath, TraverseWidgetContentFn, TraverseWidgetContentWithModelFn } from "../../utils";
5
5
  export declare const TableContentType = "TableContent";
6
6
  export declare const isTableContent: (u: unknown) => u is {
7
7
  __TYPE__: "TableContent";
@@ -768,3 +768,9 @@ export declare function traverseTableContent({ path, key, apiId, model, content,
768
768
  content: TableContent;
769
769
  model?: NestableWidget | undefined;
770
770
  }): (transform: TraverseWidgetContentFn) => TableContent | undefined;
771
+ export declare function traverseTableContentWithModel({ path, key, model, content, }: {
772
+ path: ContentPath;
773
+ key: string;
774
+ model: NestableWidget;
775
+ content: TableContent | undefined;
776
+ }): (transform: TraverseWidgetContentWithModelFn) => TableContent | undefined;
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverseTableContent = exports.TableLegacy = exports.TableContent = exports.isTableContent = exports.TableContentType = void 0;
3
+ exports.traverseTableContentWithModel = exports.traverseTableContent = exports.TableLegacy = exports.TableContent = exports.isTableContent = exports.TableContentType = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
6
  const function_1 = require("fp-ts/lib/function");
7
7
  const t = (0, tslib_1.__importStar)(require("io-ts"));
8
8
  const customtypes_1 = require("../../../customtypes");
9
- const utils_1 = require("../../utils");
9
+ const helpers_1 = require("../../helpers");
10
10
  const RichTextContent_1 = require("./RichTextContent");
11
11
  exports.TableContentType = "TableContent";
12
- const isTableContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.TableContentType;
12
+ const isTableContent = (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.TableContentType;
13
13
  exports.isTableContent = isTableContent;
14
- const TableCell = (0, utils_1.withKey)(t.intersection([
14
+ const TableCell = (0, helpers_1.withKey)(t.intersection([
15
15
  t.strict({
16
16
  type: t.union([t.literal("tableHeader"), t.literal("tableCell")]),
17
17
  content: RichTextContent_1.RichTextContent,
@@ -20,7 +20,7 @@ const TableCell = (0, utils_1.withKey)(t.intersection([
20
20
  columnWidth: t.number,
21
21
  })),
22
22
  ]));
23
- const TableRow = (0, utils_1.withKey)(t.strict({
23
+ const TableRow = (0, helpers_1.withKey)(t.strict({
24
24
  type: t.literal("tableRow"),
25
25
  content: t.array(TableCell),
26
26
  }));
@@ -29,7 +29,7 @@ exports.TableContent = t.strict({
29
29
  content: t.array(TableRow),
30
30
  });
31
31
  // Legacy.
32
- const TableCellLegacy = (0, utils_1.withKey)(t.intersection([
32
+ const TableCellLegacy = (0, helpers_1.withKey)(t.intersection([
33
33
  t.strict({
34
34
  type: t.union([t.literal("tableHeader"), t.literal("tableCell")]),
35
35
  content: RichTextContent_1.RichTextLegacyContent,
@@ -38,7 +38,7 @@ const TableCellLegacy = (0, utils_1.withKey)(t.intersection([
38
38
  columnWidth: t.number,
39
39
  })),
40
40
  ]));
41
- const TableRowLegacy = (0, utils_1.withKey)(t.strict({
41
+ const TableRowLegacy = (0, helpers_1.withKey)(t.strict({
42
42
  type: t.literal("tableRow"),
43
43
  content: t.array(TableCellLegacy),
44
44
  }));
@@ -119,3 +119,49 @@ function traverseTableContent({ path, key, apiId, model, content, }) {
119
119
  };
120
120
  }
121
121
  exports.traverseTableContent = traverseTableContent;
122
+ function traverseTableContentWithModel({ path, key, model, content, }) {
123
+ return (transform) => {
124
+ var _a;
125
+ const tableContent = (_a = content === null || content === void 0 ? void 0 : content.content.map((row, rowIndex) => ({
126
+ ...row,
127
+ content: row.content.map((cell, cellIndex) => {
128
+ const itemPath = path.concat([
129
+ {
130
+ key: [rowIndex.toString(), cellIndex.toString()].join(","),
131
+ type: "Widget",
132
+ },
133
+ ]);
134
+ const cellContent = transform({
135
+ path: itemPath,
136
+ key,
137
+ apiId: key,
138
+ model: customtypes_1.TableCell,
139
+ content: {
140
+ __TYPE__: cell.content.__TYPE__,
141
+ value: cell.content.value,
142
+ },
143
+ }) || {
144
+ __TYPE__: "StructuredTextContent",
145
+ value: [],
146
+ };
147
+ return {
148
+ ...cell,
149
+ content: cellContent,
150
+ };
151
+ }),
152
+ }))) !== null && _a !== void 0 ? _a : [];
153
+ return transform({
154
+ path,
155
+ key,
156
+ apiId: key,
157
+ model,
158
+ content: content
159
+ ? {
160
+ __TYPE__: content.__TYPE__,
161
+ content: tableContent,
162
+ }
163
+ : undefined,
164
+ });
165
+ };
166
+ }
167
+ exports.traverseTableContentWithModel = traverseTableContentWithModel;