@prismicio/types-internal 4.0.0 → 4.1.0-canary.858108c
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/README.md +5 -5
- package/dist/content/boolean.d.ts.map +1 -1
- package/dist/content/boolean.js.map +1 -1
- package/dist/content/codec/link.js.map +1 -1
- package/dist/content/codec/nestable.js +4 -4
- package/dist/content/field.d.ts.map +1 -1
- package/dist/content/field.js +1 -1
- package/dist/content/field.js.map +1 -1
- package/dist/content/group.d.ts.map +1 -1
- package/dist/content/group.js.map +1 -1
- package/dist/content/image.d.ts +3 -1
- package/dist/content/image.d.ts.map +1 -1
- package/dist/content/image.js +3 -3
- package/dist/content/image.js.map +1 -1
- package/dist/content/legacy/boolean.d.ts +1 -0
- package/dist/content/legacy/embed.d.ts +1 -0
- package/dist/content/legacy/empty.d.ts +1 -0
- package/dist/content/legacy/field.d.ts +1 -0
- package/dist/content/legacy/geopoint.d.ts +1 -0
- package/dist/content/legacy/image.d.ts +28 -0
- package/dist/content/legacy/image.d.ts.map +1 -0
- package/dist/content/legacy/image.js +3 -3
- package/dist/content/legacy/image.js.map +1 -1
- package/dist/content/legacy/integrationField.d.ts +1 -0
- package/dist/content/legacy/link.d.ts +10 -10
- package/dist/content/legacy/link.js +23 -23
- package/dist/content/legacy/link.js.map +1 -1
- package/dist/content/legacy/nestable.d.ts +1 -0
- package/dist/content/legacy/nestable.js +1 -1
- package/dist/content/legacy/repeatable.d.ts +1 -0
- package/dist/content/legacy/richText.d.ts +9 -8
- package/dist/content/legacy/richText.d.ts.map +1 -1
- package/dist/content/legacy/richText.js +5 -5
- package/dist/content/legacy/richText.js.map +1 -1
- package/dist/content/legacy/separator.d.ts +1 -0
- package/dist/content/legacy/table.d.ts +1 -0
- package/dist/content/link.d.ts +62 -85
- package/dist/content/link.d.ts.map +1 -1
- package/dist/content/link.js +30 -27
- package/dist/content/link.js.map +1 -1
- package/dist/content/nestable.d.ts.map +1 -1
- package/dist/content/nestable.js +4 -4
- package/dist/content/nestable.js.map +1 -1
- package/dist/content/repeatable.d.ts +4 -69
- package/dist/content/repeatable.d.ts.map +1 -1
- package/dist/content/richText.d.ts +13 -13
- package/dist/content/richText.d.ts.map +1 -1
- package/dist/content/richText.js +9 -9
- package/dist/content/richText.js.map +1 -1
- package/dist/helpers/customTypeModel.d.ts +5 -5
- package/dist/helpers/customTypeModel.d.ts.map +1 -1
- package/dist/helpers/customTypeModel.js +30 -0
- package/dist/helpers/customTypeModel.js.map +1 -1
- package/dist/helpers/imageContent.d.ts +33 -0
- package/dist/helpers/imageContent.d.ts.map +1 -0
- package/dist/helpers/imageContent.js +55 -0
- package/dist/helpers/imageContent.js.map +1 -0
- package/dist/helpers/traverseContent.d.ts +4 -4
- package/dist/helpers/traverseContent.d.ts.map +1 -1
- package/dist/helpers/traverseContent.js +5 -3
- package/dist/helpers/traverseContent.js.map +1 -1
- package/dist/helpers/traverseContentWithModel.d.ts +4 -4
- package/dist/helpers/traverseContentWithModel.js +1 -1
- package/dist/helpers/withDefaultContent.d.ts +21 -0
- package/dist/helpers/withDefaultContent.d.ts.map +1 -0
- package/dist/helpers/withDefaultContent.js +120 -0
- package/dist/helpers/withDefaultContent.js.map +1 -0
- package/dist/index.d.ts +26 -24
- package/dist/index.js +6 -1
- package/dist/io-ts.d.ts +1275 -830
- package/dist/io-ts.d.ts.map +1 -1
- package/dist/io-ts.js +17 -12
- package/dist/io-ts.js.map +1 -1
- package/dist/model/customType.d.ts +9 -3
- package/dist/model/customType.d.ts.map +1 -1
- package/dist/model/customType.js +7 -4
- package/dist/model/customType.js.map +1 -1
- package/dist/model/richText.d.ts +20 -1
- package/dist/model/richText.d.ts.map +1 -1
- package/dist/model/richText.js +3 -3
- package/dist/model/richText.js.map +1 -1
- package/dist/model/slice.d.ts +1251 -643
- package/dist/model/slice.d.ts.map +1 -1
- package/dist/model/slice.js +4 -4
- package/dist/model/slice.js.map +1 -1
- package/dist/model/table.js +5 -5
- package/dist/model/table.js.map +1 -1
- package/dist/model/widget.d.ts +1 -3
- package/dist/model/widget.d.ts.map +1 -1
- package/dist/model/widget.js +5 -2
- package/dist/model/widget.js.map +1 -1
- package/dist/zod4.d.ts +2404 -1873
- package/dist/zod4.d.ts.map +1 -1
- package/dist/zod4.js +17 -12
- package/dist/zod4.js.map +1 -1
- package/package.json +19 -12
- package/src/content/boolean.ts +0 -13
- package/src/content/codec/link.ts +12 -12
- package/src/content/field.ts +0 -14
- package/src/content/group.ts +1 -54
- package/src/content/image.ts +3 -91
- package/src/content/legacy/image.ts +4 -4
- package/src/content/legacy/link.ts +46 -46
- package/src/content/legacy/richText.ts +18 -16
- package/src/content/link.ts +100 -89
- package/src/content/nestable.ts +1 -20
- package/src/content/richText.ts +23 -17
- package/src/helpers/customTypeModel.ts +51 -4
- package/src/helpers/imageContent.ts +84 -0
- package/src/helpers/traverseContent.ts +4 -1
- package/src/helpers/withDefaultContent.ts +180 -0
- package/src/index.ts +25 -7
- package/src/io-ts.ts +22 -10
- package/src/model/customType.ts +18 -7
- package/src/model/diff/sharedSlice.ts +2 -2
- package/src/model/diff/variation.ts +7 -7
- package/src/model/richText.ts +5 -2
- package/src/model/slice.ts +6 -8
- package/src/model/table.ts +5 -5
- package/src/model/widget.ts +6 -2
- package/src/zod4.ts +22 -10
- package/dist/model/section.d.ts +0 -11
- package/dist/model/section.d.ts.map +0 -1
- package/dist/model/section.js +0 -10
- package/dist/model/section.js.map +0 -1
- package/src/content/withDefaultValues.ts +0 -114
- package/src/model/section.ts +0 -12
package/src/model/table.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { RichTextModelNodeType, type RichTextModel } from "./richText"
|
|
4
4
|
|
|
5
5
|
const TableConfigSchema = z.object({
|
|
6
6
|
label: z.nullish(z.string()),
|
|
@@ -15,10 +15,10 @@ export type TableModel = z.infer<typeof TableModelSchema>
|
|
|
15
15
|
|
|
16
16
|
// TableCell configuration constant (used for cell rich text configuration)
|
|
17
17
|
export const TableCellModelNodeTypes = [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
RichTextModelNodeType.paragraph,
|
|
19
|
+
RichTextModelNodeType.strong,
|
|
20
|
+
RichTextModelNodeType.em,
|
|
21
|
+
RichTextModelNodeType.hyperlink,
|
|
22
22
|
]
|
|
23
23
|
|
|
24
24
|
export const TableCellModel: RichTextModel = {
|
package/src/model/widget.ts
CHANGED
|
@@ -46,7 +46,6 @@ export const FieldModelTypeSchema = z.enum([
|
|
|
46
46
|
"Text",
|
|
47
47
|
"Timestamp",
|
|
48
48
|
"Link",
|
|
49
|
-
"Repeatable.Link",
|
|
50
49
|
"Image",
|
|
51
50
|
"IntegrationFields",
|
|
52
51
|
"UID",
|
|
@@ -58,6 +57,11 @@ export const FieldModelTypeSchema = z.enum([
|
|
|
58
57
|
export type FieldModelType = z.infer<typeof FieldModelTypeSchema>
|
|
59
58
|
|
|
60
59
|
// Field and slice types
|
|
61
|
-
export const FieldOrSliceTypeSchema = z.union([
|
|
60
|
+
export const FieldOrSliceTypeSchema = z.union([
|
|
61
|
+
FieldModelTypeSchema,
|
|
62
|
+
SliceModelTypeSchema,
|
|
63
|
+
// Repeatable links are "meta" types like slices and shared slices
|
|
64
|
+
z.literal("Repeatable.Link"),
|
|
65
|
+
])
|
|
62
66
|
|
|
63
67
|
export type FieldOrSliceType = z.infer<typeof FieldOrSliceTypeSchema>
|
package/src/zod4.ts
CHANGED
|
@@ -24,9 +24,16 @@ import {
|
|
|
24
24
|
GroupContentSchema as rawGroupContentSchema,
|
|
25
25
|
GroupItemContentSchema as rawGroupItemContentSchema,
|
|
26
26
|
} from "./content/group"
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
ImageContentSchema as rawImageContentSchema,
|
|
29
|
+
ImageContentViewSchema as rawImageContentViewSchema,
|
|
30
|
+
} from "./content/image"
|
|
28
31
|
import { IntegrationFieldContentSchema as rawIntegrationFieldContentSchema } from "./content/integrationField"
|
|
29
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
EmptyLinkContentSchema as rawEmptyLinkContentSchema,
|
|
34
|
+
FilledLinkContentSchema as rawFilledLinkContentSchema,
|
|
35
|
+
LinkContentSchema as rawLinkContentSchema,
|
|
36
|
+
} from "./content/link"
|
|
30
37
|
import { NestableContentSchema as rawNestableContentSchema } from "./content/nestable"
|
|
31
38
|
import { RepeatableContentSchema as rawRepeatableContentSchema } from "./content/repeatable"
|
|
32
39
|
import {
|
|
@@ -56,7 +63,9 @@ import { BooleanModelSchema as rawBooleanModelSchema } from "./model/boolean"
|
|
|
56
63
|
import { ColorModelSchema as rawColorModelSchema } from "./model/color"
|
|
57
64
|
import {
|
|
58
65
|
StaticCustomTypeModelSchema as rawStaticCustomTypeModelSchema,
|
|
59
|
-
|
|
66
|
+
DynamicCustomTypeModelSchema as rawDynamicCustomTypeModelSchema,
|
|
67
|
+
StaticCustomTypeModelTabSchema as rawStaticCustomTypeModelTabSchema,
|
|
68
|
+
DynamicCustomTypeModelTabSchema as rawDynamicCustomTypeModelTabSchema,
|
|
60
69
|
} from "./model/customType"
|
|
61
70
|
import { DateModelSchema as rawDateModelSchema } from "./model/date"
|
|
62
71
|
import { EmbedModelSchema as rawEmbedModelSchema } from "./model/embed"
|
|
@@ -72,16 +81,13 @@ import { NestableModelSchema as rawNestableModelSchema } from "./model/nestable"
|
|
|
72
81
|
import { NumberModelSchema as rawNumberModelSchema } from "./model/number"
|
|
73
82
|
import { RangeModelSchema as rawRangeModelSchema } from "./model/range"
|
|
74
83
|
import { RichTextModelSchema as rawRichTextModelSchema } from "./model/richText"
|
|
75
|
-
import {
|
|
76
|
-
StaticSectionModelSchema as rawStaticSectionModelSchema,
|
|
77
|
-
DynamicSectionModelSchema as rawDynamicSectionModelSchema,
|
|
78
|
-
} from "./model/section"
|
|
79
84
|
import { SelectModelSchema as rawSelectModelSchema } from "./model/select"
|
|
80
85
|
import { SeparatorModelSchema as rawSeparatorModelSchema } from "./model/separator"
|
|
81
86
|
import {
|
|
82
87
|
LegacySliceModelSchema as rawLegacySliceModelSchema,
|
|
83
88
|
CompositeSliceModelSchema as rawCompositeSliceModelSchema,
|
|
84
89
|
SharedSliceModelSchema as rawSharedSliceModelSchema,
|
|
90
|
+
SharedSliceModelVariationSchema as rawSharedSliceModelVariationSchema,
|
|
85
91
|
SharedSliceRefModelSchema as rawSharedSliceRefModelSchema,
|
|
86
92
|
StaticSliceModelSchema as rawStaticSliceModelSchema,
|
|
87
93
|
DynamicSliceModelSchema as rawDynamicSliceModelSchema,
|
|
@@ -113,6 +119,8 @@ export const ColorContentSchema = toZod4(rawColorContentSchema)
|
|
|
113
119
|
export const DateContentSchema = toZod4(rawDateContentSchema)
|
|
114
120
|
export const EmptyContentSchema = toZod4(rawEmptyContentSchema)
|
|
115
121
|
export const GeoPointContentSchema = toZod4(rawGeoPointContentSchema)
|
|
122
|
+
export const FilledLinkContentSchema = toZod4(rawFilledLinkContentSchema)
|
|
123
|
+
export const EmptyLinkContentSchema = toZod4(rawEmptyLinkContentSchema)
|
|
116
124
|
export const LinkContentSchema = toZod4(rawLinkContentSchema)
|
|
117
125
|
export const NumberContentSchema = toZod4(rawNumberContentSchema)
|
|
118
126
|
export const RangeContentSchema = toZod4(rawRangeContentSchema)
|
|
@@ -125,6 +133,7 @@ export const FieldContentSchema = toZod4(rawFieldContentSchema)
|
|
|
125
133
|
export const UIDContentSchema = toZod4(rawUIDContentSchema)
|
|
126
134
|
export const IntegrationFieldContentSchema = toZod4(rawIntegrationFieldContentSchema)
|
|
127
135
|
export const EmbedContentSchema = toZod4(rawEmbedContentSchema)
|
|
136
|
+
export const ImageContentViewSchema = toZod4(rawImageContentViewSchema)
|
|
128
137
|
export const ImageContentSchema = toZod4(rawImageContentSchema)
|
|
129
138
|
export const RichTextContentSchema = toZod4(rawRichTextContentSchema)
|
|
130
139
|
export const RichTextContentBlockSchema = toZod4(rawRichTextContentBlockSchema)
|
|
@@ -167,6 +176,7 @@ export const TimestampModelSchema = toZod4(rawTimestampModelSchema)
|
|
|
167
176
|
export const UIDModelSchema = toZod4(rawUIDModelSchema)
|
|
168
177
|
export const GroupModelSchema = toZod4(rawGroupModelSchema)
|
|
169
178
|
export const NestedGroupModelSchema = toZod4(rawNestedGroupModelSchema)
|
|
179
|
+
export const SharedSliceModelVariationSchema = toZod4(rawSharedSliceModelVariationSchema)
|
|
170
180
|
export const SharedSliceRefModelSchema = toZod4(rawSharedSliceRefModelSchema)
|
|
171
181
|
export const CompositeSliceModelSchema = toZod4(rawCompositeSliceModelSchema)
|
|
172
182
|
export const LegacySliceModelSchema = toZod4(rawLegacySliceModelSchema)
|
|
@@ -177,10 +187,12 @@ export const DynamicSlicesModelSchema = toZod4(rawDynamicSlicesModelSchema)
|
|
|
177
187
|
export const StaticSlicesModelSchema = toZod4(rawStaticSlicesModelSchema)
|
|
178
188
|
export const StaticWidgetModelSchema = toZod4(rawStaticWidgetModelSchema)
|
|
179
189
|
export const DynamicWidgetModelSchema = toZod4(rawDynamicWidgetModelSchema)
|
|
180
|
-
export const
|
|
181
|
-
export const
|
|
190
|
+
export const StaticCustomTypeModelTabSchema = toZod4(rawStaticCustomTypeModelTabSchema)
|
|
191
|
+
export const DynamicCustomTypeModelTabSchema = toZod4(rawDynamicCustomTypeModelTabSchema)
|
|
182
192
|
export const StaticCustomTypeModelSchema = toZod4(rawStaticCustomTypeModelSchema)
|
|
183
|
-
export const
|
|
193
|
+
export const DynamicCustomTypeModelSchema = toZod4(rawDynamicCustomTypeModelSchema)
|
|
194
|
+
/** @deprecated Use DynamicCustomTypeModelSchema instead */
|
|
195
|
+
export const CustomTypeModelSchema = DynamicCustomTypeModelSchema
|
|
184
196
|
|
|
185
197
|
function toZod4<T>(type: T): T {
|
|
186
198
|
return type
|
package/dist/model/section.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { DynamicWidgetModel, StaticWidgetModel } from "./widget.js";
|
|
2
|
-
import { z } from "zod/mini";
|
|
3
|
-
|
|
4
|
-
//#region src/model/section.d.ts
|
|
5
|
-
declare const StaticSectionModelSchema: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniType<StaticWidgetModel, unknown, z.core.$ZodTypeInternals<StaticWidgetModel, unknown>>>;
|
|
6
|
-
type StaticSectionModel = z.infer<typeof StaticSectionModelSchema>;
|
|
7
|
-
declare const DynamicSectionModelSchema: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniType<DynamicWidgetModel, unknown, z.core.$ZodTypeInternals<DynamicWidgetModel, unknown>>>;
|
|
8
|
-
type DynamicSectionModel = z.infer<typeof DynamicSectionModelSchema>;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { DynamicSectionModel, StaticSectionModel };
|
|
11
|
-
//# sourceMappingURL=section.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"section.d.ts","names":[],"sources":["../../src/model/section.ts"],"mappings":";;;;cAMa,wBAAA,EAAwB,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,iBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,iBAAA;AAAA,KACzB,kBAAA,GAAqB,CAAA,CAAE,KAAA,QAAa,wBAAA;AAAA,cAGnC,yBAAA,EAAyB,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,kBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,kBAAA;AAAA,KAC1B,mBAAA,GAAsB,CAAA,CAAE,KAAA,QAAa,yBAAA"}
|
package/dist/model/section.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { WidgetKeySchema } from "../common/widgetKey.js";
|
|
2
|
-
import { DynamicWidgetModelSchema, StaticWidgetModelSchema } from "./widget.js";
|
|
3
|
-
import { z } from "zod/mini";
|
|
4
|
-
//#region src/model/section.ts
|
|
5
|
-
const StaticSectionModelSchema = z.record(WidgetKeySchema, StaticWidgetModelSchema);
|
|
6
|
-
const DynamicSectionModelSchema = z.record(WidgetKeySchema, DynamicWidgetModelSchema);
|
|
7
|
-
//#endregion
|
|
8
|
-
export { DynamicSectionModelSchema, StaticSectionModelSchema };
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=section.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"section.js","names":[],"sources":["../../src/model/section.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { WidgetKeySchema } from \"../common/widgetKey\"\nimport { DynamicWidgetModelSchema, StaticWidgetModelSchema } from \"./widget\"\n\n// StaticSection = Record<WidgetKey, StaticWidget>\nexport const StaticSectionModelSchema = z.record(WidgetKeySchema, StaticWidgetModelSchema)\nexport type StaticSectionModel = z.infer<typeof StaticSectionModelSchema>\n\n// DynamicSection = Record<WidgetKey, DynamicWidget>\nexport const DynamicSectionModelSchema = z.record(WidgetKeySchema, DynamicWidgetModelSchema)\nexport type DynamicSectionModel = z.infer<typeof DynamicSectionModelSchema>\n"],"mappings":";;;;AAMA,MAAa,2BAA2B,EAAE,OAAO,iBAAiB,wBAAwB;AAI1F,MAAa,4BAA4B,EAAE,OAAO,iBAAiB,yBAAyB"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { GroupModel, NestedGroupModel } from "../model/group"
|
|
2
|
-
import type { NestableModel } from "../model/nestable"
|
|
3
|
-
import { GroupContentType, groupContentWithDefaultValues, GroupContentSchema } from "./group"
|
|
4
|
-
import type { GroupContent } from "./group"
|
|
5
|
-
import { NestableContentDefaultValue } from "./nestable"
|
|
6
|
-
import type { NestableContent } from "./nestable"
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Applies default values to slice primary content (non-repeat zone) based on the model configuration.
|
|
10
|
-
* For each widget in the customType that has no corresponding content, this will add the default value.
|
|
11
|
-
*/
|
|
12
|
-
export function withDefaultSlicePrimaryContentValues(
|
|
13
|
-
customType: Record<string, NestableModel | NestedGroupModel>,
|
|
14
|
-
content: Partial<Record<string, NestableContent | GroupContent>>,
|
|
15
|
-
): Record<string, NestableContent | GroupContent> {
|
|
16
|
-
const updatedContent = content as Record<string, NestableContent | GroupContent>
|
|
17
|
-
|
|
18
|
-
for (const [widgetKey, widgetDef] of Object.entries(customType)) {
|
|
19
|
-
const widgetContent = content[widgetKey]
|
|
20
|
-
|
|
21
|
-
if (widgetContent === undefined) {
|
|
22
|
-
if (widgetDef.type === "Group") {
|
|
23
|
-
updatedContent[widgetKey] = groupContentWithDefaultValues(widgetDef, {
|
|
24
|
-
__TYPE__: GroupContentType,
|
|
25
|
-
value: [],
|
|
26
|
-
})
|
|
27
|
-
} else {
|
|
28
|
-
const defaultValue = NestableContentDefaultValue(widgetDef)
|
|
29
|
-
|
|
30
|
-
if (defaultValue) {
|
|
31
|
-
updatedContent[widgetKey] = defaultValue
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
continue
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const maybeGroupContent = GroupContentSchema.safeParse(widgetContent)
|
|
39
|
-
if (widgetDef.type === "Group" && maybeGroupContent.success) {
|
|
40
|
-
updatedContent[widgetKey] = groupContentWithDefaultValues(widgetDef, maybeGroupContent.data)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return updatedContent
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Applies default values to nestable content based on the model configuration.
|
|
49
|
-
* For each widget in the customType that has no corresponding content, this will add the default value.
|
|
50
|
-
*/
|
|
51
|
-
export function withDefaultNestableContentValues(
|
|
52
|
-
customType: Record<string, NestableModel>,
|
|
53
|
-
content: Record<string, NestableContent>,
|
|
54
|
-
): Record<string, NestableContent> {
|
|
55
|
-
return Object.entries(customType).reduce<Record<string, NestableContent>>(
|
|
56
|
-
(updatedContent, [widgetKey, widgetDef]) => {
|
|
57
|
-
if (content[widgetKey] === undefined) {
|
|
58
|
-
const defaultValue = NestableContentDefaultValue(widgetDef)
|
|
59
|
-
return defaultValue !== undefined
|
|
60
|
-
? {
|
|
61
|
-
...updatedContent,
|
|
62
|
-
[widgetKey]: defaultValue,
|
|
63
|
-
}
|
|
64
|
-
: updatedContent
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return updatedContent
|
|
68
|
-
},
|
|
69
|
-
content,
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Applies default values to repeatable content items (like group items or slice repeat zones).
|
|
75
|
-
* For each item, it ensures all required fields have values based on the model configuration.
|
|
76
|
-
*/
|
|
77
|
-
export function repeatableContentWithDefaultNestableContentValues<
|
|
78
|
-
T extends {
|
|
79
|
-
value: [string, GroupContent | NestableContent][]
|
|
80
|
-
},
|
|
81
|
-
>(fields: Record<string, GroupModel | NestableModel>, content: T[]): T[] {
|
|
82
|
-
const groupKeys = Object.entries(fields)
|
|
83
|
-
return content.map((contentItem) => {
|
|
84
|
-
return groupKeys.reduce((updatedContentItem, [key, fieldDef]) => {
|
|
85
|
-
const maybeContentItemValue = contentItem.value.find(([_key]) => _key === key)
|
|
86
|
-
|
|
87
|
-
if (fieldDef.type === "Group") {
|
|
88
|
-
const defaultValue = groupContentWithDefaultValues(
|
|
89
|
-
fieldDef,
|
|
90
|
-
(maybeContentItemValue?.[1] as GroupContent | undefined) ?? {
|
|
91
|
-
__TYPE__: GroupContentType,
|
|
92
|
-
value: [],
|
|
93
|
-
},
|
|
94
|
-
)
|
|
95
|
-
return {
|
|
96
|
-
...updatedContentItem,
|
|
97
|
-
value: [
|
|
98
|
-
// Since there was default content for the group, we need to remove the old one
|
|
99
|
-
...updatedContentItem.value.filter(([_key]) => _key !== key),
|
|
100
|
-
...(defaultValue ? [[key, defaultValue]] : []),
|
|
101
|
-
],
|
|
102
|
-
}
|
|
103
|
-
} else if (!maybeContentItemValue) {
|
|
104
|
-
const defaultValue = NestableContentDefaultValue(fieldDef)
|
|
105
|
-
return {
|
|
106
|
-
...updatedContentItem,
|
|
107
|
-
value: [...updatedContentItem.value, ...(defaultValue ? [[key, defaultValue]] : [])],
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return updatedContentItem
|
|
112
|
-
}, contentItem)
|
|
113
|
-
})
|
|
114
|
-
}
|
package/src/model/section.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/mini"
|
|
2
|
-
|
|
3
|
-
import { WidgetKeySchema } from "../common/widgetKey"
|
|
4
|
-
import { DynamicWidgetModelSchema, StaticWidgetModelSchema } from "./widget"
|
|
5
|
-
|
|
6
|
-
// StaticSection = Record<WidgetKey, StaticWidget>
|
|
7
|
-
export const StaticSectionModelSchema = z.record(WidgetKeySchema, StaticWidgetModelSchema)
|
|
8
|
-
export type StaticSectionModel = z.infer<typeof StaticSectionModelSchema>
|
|
9
|
-
|
|
10
|
-
// DynamicSection = Record<WidgetKey, DynamicWidget>
|
|
11
|
-
export const DynamicSectionModelSchema = z.record(WidgetKeySchema, DynamicWidgetModelSchema)
|
|
12
|
-
export type DynamicSectionModel = z.infer<typeof DynamicSectionModelSchema>
|