@prismicio/types-internal 4.0.0 → 4.1.0-canary.18ae460
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 +2 -1
- 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 +25 -22
- package/dist/index.js +6 -1
- package/dist/io-ts.d.ts +1156 -727
- package/dist/io-ts.d.ts.map +1 -1
- package/dist/io-ts.js +11 -7
- package/dist/io-ts.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 +2392 -1873
- package/dist/zod4.d.ts.map +1 -1
- package/dist/zod4.js +11 -7
- 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 +44 -0
- 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 +18 -5
- package/src/io-ts.ts +14 -2
- 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 +14 -2
- package/src/content/withDefaultValues.ts +0 -114
|
@@ -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
|
-
}
|