@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.
Files changed (127) hide show
  1. package/README.md +5 -5
  2. package/dist/content/boolean.d.ts.map +1 -1
  3. package/dist/content/boolean.js.map +1 -1
  4. package/dist/content/codec/link.js.map +1 -1
  5. package/dist/content/codec/nestable.js +4 -4
  6. package/dist/content/field.d.ts.map +1 -1
  7. package/dist/content/field.js +1 -1
  8. package/dist/content/field.js.map +1 -1
  9. package/dist/content/group.d.ts.map +1 -1
  10. package/dist/content/group.js.map +1 -1
  11. package/dist/content/image.d.ts +3 -1
  12. package/dist/content/image.d.ts.map +1 -1
  13. package/dist/content/image.js +3 -3
  14. package/dist/content/image.js.map +1 -1
  15. package/dist/content/legacy/boolean.d.ts +1 -0
  16. package/dist/content/legacy/embed.d.ts +1 -0
  17. package/dist/content/legacy/empty.d.ts +1 -0
  18. package/dist/content/legacy/field.d.ts +1 -0
  19. package/dist/content/legacy/geopoint.d.ts +1 -0
  20. package/dist/content/legacy/image.d.ts +28 -0
  21. package/dist/content/legacy/image.d.ts.map +1 -0
  22. package/dist/content/legacy/image.js +3 -3
  23. package/dist/content/legacy/image.js.map +1 -1
  24. package/dist/content/legacy/integrationField.d.ts +1 -0
  25. package/dist/content/legacy/link.d.ts +10 -10
  26. package/dist/content/legacy/link.js +23 -23
  27. package/dist/content/legacy/link.js.map +1 -1
  28. package/dist/content/legacy/nestable.d.ts +1 -0
  29. package/dist/content/legacy/nestable.js +1 -1
  30. package/dist/content/legacy/repeatable.d.ts +1 -0
  31. package/dist/content/legacy/richText.d.ts +9 -8
  32. package/dist/content/legacy/richText.d.ts.map +1 -1
  33. package/dist/content/legacy/richText.js +5 -5
  34. package/dist/content/legacy/richText.js.map +1 -1
  35. package/dist/content/legacy/separator.d.ts +1 -0
  36. package/dist/content/legacy/table.d.ts +1 -0
  37. package/dist/content/link.d.ts +62 -85
  38. package/dist/content/link.d.ts.map +1 -1
  39. package/dist/content/link.js +30 -27
  40. package/dist/content/link.js.map +1 -1
  41. package/dist/content/nestable.d.ts.map +1 -1
  42. package/dist/content/nestable.js +4 -4
  43. package/dist/content/nestable.js.map +1 -1
  44. package/dist/content/repeatable.d.ts +4 -69
  45. package/dist/content/repeatable.d.ts.map +1 -1
  46. package/dist/content/richText.d.ts +13 -13
  47. package/dist/content/richText.d.ts.map +1 -1
  48. package/dist/content/richText.js +9 -9
  49. package/dist/content/richText.js.map +1 -1
  50. package/dist/helpers/customTypeModel.d.ts +5 -5
  51. package/dist/helpers/customTypeModel.d.ts.map +1 -1
  52. package/dist/helpers/customTypeModel.js +30 -0
  53. package/dist/helpers/customTypeModel.js.map +1 -1
  54. package/dist/helpers/imageContent.d.ts +33 -0
  55. package/dist/helpers/imageContent.d.ts.map +1 -0
  56. package/dist/helpers/imageContent.js +55 -0
  57. package/dist/helpers/imageContent.js.map +1 -0
  58. package/dist/helpers/traverseContent.d.ts +4 -4
  59. package/dist/helpers/traverseContent.d.ts.map +1 -1
  60. package/dist/helpers/traverseContent.js +5 -3
  61. package/dist/helpers/traverseContent.js.map +1 -1
  62. package/dist/helpers/traverseContentWithModel.d.ts +4 -4
  63. package/dist/helpers/traverseContentWithModel.js +1 -1
  64. package/dist/helpers/withDefaultContent.d.ts +21 -0
  65. package/dist/helpers/withDefaultContent.d.ts.map +1 -0
  66. package/dist/helpers/withDefaultContent.js +120 -0
  67. package/dist/helpers/withDefaultContent.js.map +1 -0
  68. package/dist/index.d.ts +26 -24
  69. package/dist/index.js +6 -1
  70. package/dist/io-ts.d.ts +1275 -830
  71. package/dist/io-ts.d.ts.map +1 -1
  72. package/dist/io-ts.js +17 -12
  73. package/dist/io-ts.js.map +1 -1
  74. package/dist/model/customType.d.ts +9 -3
  75. package/dist/model/customType.d.ts.map +1 -1
  76. package/dist/model/customType.js +7 -4
  77. package/dist/model/customType.js.map +1 -1
  78. package/dist/model/richText.d.ts +20 -1
  79. package/dist/model/richText.d.ts.map +1 -1
  80. package/dist/model/richText.js +3 -3
  81. package/dist/model/richText.js.map +1 -1
  82. package/dist/model/slice.d.ts +1251 -643
  83. package/dist/model/slice.d.ts.map +1 -1
  84. package/dist/model/slice.js +4 -4
  85. package/dist/model/slice.js.map +1 -1
  86. package/dist/model/table.js +5 -5
  87. package/dist/model/table.js.map +1 -1
  88. package/dist/model/widget.d.ts +1 -3
  89. package/dist/model/widget.d.ts.map +1 -1
  90. package/dist/model/widget.js +5 -2
  91. package/dist/model/widget.js.map +1 -1
  92. package/dist/zod4.d.ts +2404 -1873
  93. package/dist/zod4.d.ts.map +1 -1
  94. package/dist/zod4.js +17 -12
  95. package/dist/zod4.js.map +1 -1
  96. package/package.json +19 -12
  97. package/src/content/boolean.ts +0 -13
  98. package/src/content/codec/link.ts +12 -12
  99. package/src/content/field.ts +0 -14
  100. package/src/content/group.ts +1 -54
  101. package/src/content/image.ts +3 -91
  102. package/src/content/legacy/image.ts +4 -4
  103. package/src/content/legacy/link.ts +46 -46
  104. package/src/content/legacy/richText.ts +18 -16
  105. package/src/content/link.ts +100 -89
  106. package/src/content/nestable.ts +1 -20
  107. package/src/content/richText.ts +23 -17
  108. package/src/helpers/customTypeModel.ts +51 -4
  109. package/src/helpers/imageContent.ts +84 -0
  110. package/src/helpers/traverseContent.ts +4 -1
  111. package/src/helpers/withDefaultContent.ts +180 -0
  112. package/src/index.ts +25 -7
  113. package/src/io-ts.ts +22 -10
  114. package/src/model/customType.ts +18 -7
  115. package/src/model/diff/sharedSlice.ts +2 -2
  116. package/src/model/diff/variation.ts +7 -7
  117. package/src/model/richText.ts +5 -2
  118. package/src/model/slice.ts +6 -8
  119. package/src/model/table.ts +5 -5
  120. package/src/model/widget.ts +6 -2
  121. package/src/zod4.ts +22 -10
  122. package/dist/model/section.d.ts +0 -11
  123. package/dist/model/section.d.ts.map +0 -1
  124. package/dist/model/section.js +0 -10
  125. package/dist/model/section.js.map +0 -1
  126. package/src/content/withDefaultValues.ts +0 -114
  127. package/src/model/section.ts +0 -12
@@ -1,9 +1,12 @@
1
- import type { CustomTypeModel, StaticCustomTypeModel } from "../model/customType"
2
- import type { StaticSectionModel } from "../model/section"
1
+ import type {
2
+ DynamicCustomTypeModel,
3
+ StaticCustomTypeModel,
4
+ StaticCustomTypeModelTab,
5
+ } from "../model/customType"
3
6
  import type { SharedSliceModel, StaticSliceModel } from "../model/slice"
4
7
 
5
8
  export function toStatic(
6
- customType: CustomTypeModel,
9
+ customType: DynamicCustomTypeModel,
7
10
  sharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,
8
11
  ): StaticCustomTypeModel {
9
12
  const json: StaticCustomTypeModel["json"] = {}
@@ -45,7 +48,7 @@ export function toStatic(
45
48
  return { ...customType, json }
46
49
  }
47
50
 
48
- export function flatten(customType: StaticCustomTypeModel): StaticSectionModel {
51
+ export function flatten(customType: StaticCustomTypeModel): StaticCustomTypeModelTab {
49
52
  return Object.values(customType.json).reduce((acc, fields) => ({ ...acc, ...fields }), {})
50
53
  }
51
54
 
@@ -67,3 +70,47 @@ export function collectSharedSlices(
67
70
 
68
71
  return sharedSlices
69
72
  }
73
+
74
+ export function filterMissingSharedSlices<
75
+ TCustomType extends StaticCustomTypeModel | DynamicCustomTypeModel,
76
+ >(
77
+ customType: TCustomType,
78
+ sharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,
79
+ ): TCustomType {
80
+ const json: TCustomType["json"] = {}
81
+
82
+ const sharedSlicesMap =
83
+ sharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))
84
+
85
+ for (const [tabKey, tab] of Object.entries(customType.json)) {
86
+ const tabJSON: typeof tab = {}
87
+ for (const [key, widget] of Object.entries(tab)) {
88
+ switch (widget.type) {
89
+ case "Slices":
90
+ case "Choice":
91
+ const choices: Required<typeof widget>["config"]["choices"] = {}
92
+ for (const [id, model] of Object.entries(widget.config?.choices || {})) {
93
+ if (model.type === "SharedSlice") {
94
+ if (sharedSlicesMap.get(id)) {
95
+ choices[id] = model
96
+ }
97
+ } else {
98
+ choices[id] = model
99
+ }
100
+ }
101
+
102
+ tabJSON[key] = {
103
+ ...widget,
104
+ config: { ...widget.config, choices },
105
+ }
106
+ break
107
+ default:
108
+ tabJSON[key] = widget
109
+ }
110
+ }
111
+
112
+ json[tabKey] = tabJSON
113
+ }
114
+
115
+ return { ...customType, json }
116
+ }
@@ -0,0 +1,84 @@
1
+ import type { ImageContent, ImageContentView } from "../content/image"
2
+
3
+ export interface CroppedImage {
4
+ zoom: number
5
+ /** X coordinate of the crop rect on the original image */
6
+ x: number
7
+ /** Y coordinate of the crop rect on the original image */
8
+ y: number
9
+
10
+ /** The width of the crop rect over the original image */
11
+ cropWidth: number
12
+ /** The height of the crop rect over the original image */
13
+ cropHeight: number
14
+
15
+ /** Final (user defined via W input) width of the image */
16
+ width: number
17
+ /** Final (user defined via H input) height of the image */
18
+ height: number
19
+ }
20
+
21
+ export function buildCropURL(args: {
22
+ origin: ImageContent["origin"]
23
+ croppedImage: CroppedImage
24
+ }): string {
25
+ const { origin, croppedImage } = args
26
+ const { x, y, width, height, cropHeight, cropWidth } = croppedImage
27
+
28
+ const url = new URL(origin.url)
29
+
30
+ const hasResize = origin.height !== height || origin.width !== width
31
+
32
+ const hasCrop = x !== 0 || y !== 0 || cropHeight !== origin.height || cropWidth !== origin.width
33
+
34
+ if (hasCrop) {
35
+ const crop = [x, y, cropWidth, cropHeight].map(Math.round).join(",")
36
+
37
+ url.searchParams.set("rect", crop)
38
+ url.searchParams.set("w", width.toString())
39
+ url.searchParams.set("h", height.toString())
40
+ }
41
+
42
+ if (hasResize) {
43
+ url.searchParams.set("w", width.toString())
44
+ url.searchParams.set("h", height.toString())
45
+ }
46
+
47
+ return url.toString()
48
+ }
49
+
50
+ export function getCroppedImage({ contentView }: { contentView: ImageContentView }): CroppedImage {
51
+ const {
52
+ edit: {
53
+ crop: { x, y },
54
+ zoom,
55
+ },
56
+ width,
57
+ height,
58
+ origin: { width: originWidth, height: originHeight },
59
+ } = contentView
60
+
61
+ let cropWidth
62
+ let cropHeight
63
+ const originAspect = originWidth / originHeight
64
+ const cropAspect = width / height
65
+ if (cropAspect >= originAspect) {
66
+ // crop and origin image would be the same width if zoom was equal to 1
67
+ cropWidth = originWidth / zoom
68
+ cropHeight = cropWidth / cropAspect
69
+ } else {
70
+ // crop and origin image would be the same height if zoom was equal to 1
71
+ cropHeight = originHeight / zoom
72
+ cropWidth = cropHeight * cropAspect
73
+ }
74
+
75
+ return {
76
+ x,
77
+ y,
78
+ width,
79
+ height,
80
+ zoom,
81
+ cropWidth,
82
+ cropHeight,
83
+ }
84
+ }
@@ -332,7 +332,10 @@ export function traverseLegacySliceContent(
332
332
  }
333
333
  } else {
334
334
  if (model?.type === "SharedSlice") {
335
- legacySliceModel = model.fields.primary?.[content.name]
335
+ const primaryModel = model.fields.primary?.[content.name]
336
+ if (primaryModel?.type !== "Group") {
337
+ legacySliceModel = primaryModel
338
+ }
336
339
  } else if (model?.type !== "Group") {
337
340
  legacySliceModel = model
338
341
  }
@@ -0,0 +1,180 @@
1
+ import { BooleanContentType } from "../content/boolean"
2
+ import type { DocumentContent } from "../content/document"
3
+ import { FieldContentType, SelectFieldType } from "../content/field"
4
+ import type { GroupContent, GroupItemContent } from "../content/group"
5
+ import { GroupContentType } from "../content/group"
6
+ import type { SliceContent } from "../content/slice"
7
+ import { CompositeSliceContentType, SharedSliceContentType } from "../content/slice"
8
+ import type { SlicesContent } from "../content/slices"
9
+ import { SlicesContentType } from "../content/slices"
10
+ import type { WidgetContent } from "../content/widget"
11
+ import type { StaticCustomTypeModel } from "../model/customType"
12
+ import type { GroupModel } from "../model/group"
13
+ import type { NestableModel } from "../model/nestable"
14
+ import type { StaticSliceModel } from "../model/slice"
15
+ import type { StaticWidgetModel } from "../model/widget"
16
+ import * as customTypeModel from "./customTypeModel"
17
+
18
+ export function document(content: DocumentContent, model: StaticCustomTypeModel): DocumentContent {
19
+ return record(content, customTypeModel.flatten(model))
20
+ }
21
+
22
+ export function slice(content: SliceContent, model: StaticSliceModel | undefined): SliceContent {
23
+ if (!model) {
24
+ return content
25
+ }
26
+
27
+ if (model.type === "SharedSlice") {
28
+ if (content.__TYPE__ !== SharedSliceContentType) {
29
+ return content
30
+ }
31
+
32
+ const variation = model.variations.find((variation) => variation.id === content.variation)
33
+ if (!variation) {
34
+ return content
35
+ }
36
+
37
+ return {
38
+ ...content,
39
+ primary: record(content.primary, variation?.primary),
40
+ items: items(content.items, variation?.items),
41
+ }
42
+ }
43
+
44
+ if (model.type === "Slice") {
45
+ if (content.__TYPE__ !== CompositeSliceContentType) {
46
+ return content
47
+ }
48
+
49
+ return {
50
+ ...content,
51
+ nonRepeat: record(content.nonRepeat, model["non-repeat"]),
52
+ repeat: items(content.repeat, model.repeat),
53
+ }
54
+ }
55
+
56
+ if (
57
+ content.__TYPE__ === SharedSliceContentType ||
58
+ content.__TYPE__ === CompositeSliceContentType
59
+ ) {
60
+ return content
61
+ }
62
+
63
+ return widget(content, model)
64
+ }
65
+
66
+ export function widget<TContent extends WidgetContent | undefined>(
67
+ content: TContent,
68
+ model: StaticWidgetModel | undefined,
69
+ ): TContent {
70
+ if (!model) {
71
+ return content
72
+ }
73
+
74
+ if (
75
+ (model.type === "Slices" || model.type === "Choice") &&
76
+ content?.__TYPE__ === SlicesContentType
77
+ ) {
78
+ if (!model.config?.choices) return content
79
+
80
+ const value: SlicesContent["value"] = []
81
+ for (const sliceItem of content.value) {
82
+ value.push({
83
+ ...sliceItem,
84
+ widget: slice(sliceItem.widget, model.config.choices[sliceItem.name]),
85
+ })
86
+ }
87
+
88
+ return { ...content, value }
89
+ }
90
+
91
+ if (model.type === "Group") {
92
+ if (content?.__TYPE__ !== GroupContentType) {
93
+ return <TContent>{
94
+ __TYPE__: GroupContentType,
95
+ value: items([], model.config?.fields),
96
+ }
97
+ }
98
+
99
+ return { ...content, value: items(content.value, model.config?.fields) }
100
+ }
101
+
102
+ if (model.type === "Boolean" && !content) {
103
+ if (model.config?.default_value === undefined) {
104
+ return <TContent>undefined
105
+ }
106
+
107
+ return <TContent>{
108
+ __TYPE__: BooleanContentType,
109
+ value: model.config.default_value,
110
+ }
111
+ }
112
+
113
+ if (model.type === "Select" && !content) {
114
+ if (!model.config?.default_value) {
115
+ return <TContent>undefined
116
+ }
117
+
118
+ return <TContent>{
119
+ __TYPE__: FieldContentType,
120
+ type: SelectFieldType,
121
+ value: model.config.default_value,
122
+ }
123
+ }
124
+
125
+ return content
126
+ }
127
+
128
+ export function items(
129
+ items: GroupContent["value"],
130
+ fields: Record<string, GroupModel | NestableModel> | undefined,
131
+ ): GroupContent["value"] {
132
+ if (!fields) {
133
+ return items
134
+ }
135
+
136
+ const itemsWithDefaults: GroupContent["value"] = []
137
+ for (const item of items) {
138
+ const itemValue: GroupItemContent["value"] = []
139
+
140
+ const missingFields = { ...fields }
141
+ for (const [key, value] of item.value) {
142
+ delete missingFields[key]
143
+ itemValue.push([key, widget(value, fields[key])])
144
+ }
145
+ for (const [key, field] of Object.entries(missingFields)) {
146
+ const content = widget(undefined, field)
147
+ if (content) {
148
+ itemValue.push([key, content])
149
+ }
150
+ }
151
+
152
+ itemsWithDefaults.push({ ...item, value: itemValue })
153
+ }
154
+
155
+ return itemsWithDefaults
156
+ }
157
+
158
+ function record<TContent extends WidgetContent>(
159
+ record: Record<string, TContent>,
160
+ fields: Record<string, StaticWidgetModel> | undefined,
161
+ ): Record<string, TContent> {
162
+ if (!fields) {
163
+ return record
164
+ }
165
+
166
+ const missingFields = { ...fields }
167
+ const recordWithDefaults: Record<string, TContent> = {}
168
+ for (const [key, value] of Object.entries(record)) {
169
+ delete missingFields[key]
170
+ recordWithDefaults[key] = widget(value, fields[key])
171
+ }
172
+ for (const [key, field] of Object.entries(missingFields)) {
173
+ const content = widget(undefined, field)
174
+ if (content) {
175
+ recordWithDefaults[key] = content
176
+ }
177
+ }
178
+
179
+ return recordWithDefaults
180
+ }
package/src/index.ts CHANGED
@@ -22,12 +22,21 @@ export type {
22
22
  } from "./content/field"
23
23
  export type { GeoPointContent } from "./content/geopoint"
24
24
  export type { GroupContent, GroupItemContent } from "./content/group"
25
- export type { ImageContent } from "./content/image"
25
+ export type { ImageContent, ImageContentView } from "./content/image"
26
26
  export type { IntegrationFieldContent } from "./content/integrationField"
27
- export type { LinkContent } from "./content/link"
27
+ export type { EmptyLinkContent, FilledLinkContent, LinkContent } from "./content/link"
28
28
  export type { NestableContent } from "./content/nestable"
29
29
  export type { RepeatableContent } from "./content/repeatable"
30
- export type { RichTextContent, RichTextContentBlock, RichTextContentSpan } from "./content/richText"
30
+ export type {
31
+ RichTextContent,
32
+ RichTextContentBlock,
33
+ RichTextContentTextBlock,
34
+ RichTextContentImageBlock,
35
+ RichTextContentEmbedBlock,
36
+ RichTextContentSpan,
37
+ RichTextNodeTypes,
38
+ } from "./content/richText"
39
+ export { RichTextNodeType } from "./content/richText"
31
40
  export type { SeparatorContent } from "./content/separator"
32
41
  export type {
33
42
  LegacySliceContent,
@@ -49,7 +58,13 @@ export type { WidgetContent } from "./content/widget"
49
58
  // Model
50
59
  export type { BooleanModel } from "./model/boolean"
51
60
  export type { ColorModel } from "./model/color"
52
- export type { StaticCustomTypeModel, CustomTypeModel } from "./model/customType"
61
+ export type {
62
+ StaticCustomTypeModel,
63
+ DynamicCustomTypeModel,
64
+ CustomTypeModel,
65
+ StaticCustomTypeModelTab,
66
+ DynamicCustomTypeModelTab,
67
+ } from "./model/customType"
53
68
  export type { DateModel } from "./model/date"
54
69
  export type { EmbedModel } from "./model/embed"
55
70
  export type { GeoPointModel } from "./model/geopoint"
@@ -60,8 +75,8 @@ export type { LinkModel } from "./model/link"
60
75
  export type { NestableModel } from "./model/nestable"
61
76
  export type { NumberModel } from "./model/number"
62
77
  export type { RangeModel } from "./model/range"
63
- export type { RichTextModel } from "./model/richText"
64
- export type { StaticSectionModel, DynamicSectionModel } from "./model/section"
78
+ export type { RichTextModel, RichTextModelNodeTypes } from "./model/richText"
79
+ export { RichTextModelNodeType } from "./model/richText"
65
80
  export type { SelectModel } from "./model/select"
66
81
  export type { SeparatorModel } from "./model/separator"
67
82
  export type {
@@ -69,7 +84,8 @@ export type {
69
84
  CompositeSliceModel,
70
85
  SharedSliceModel,
71
86
  SharedSliceRefModel,
72
- SharedSliceVariationContentModel as SharedSliceVariationModel,
87
+ SharedSliceModelVariation,
88
+ SharedSliceVariationContentModel,
73
89
  StaticSliceModel,
74
90
  DynamicSliceModel,
75
91
  SliceContentModel,
@@ -91,6 +107,8 @@ export * as contentPath from "./helpers/contentPath"
91
107
  export * as customTypeModel from "./helpers/customTypeModel"
92
108
  export * as documentContent from "./helpers/documentContent"
93
109
  export * as sliceContent from "./helpers/sliceContent"
110
+ export * as withDefaultContent from "./helpers/withDefaultContent"
111
+ export * as imageContent from "./helpers/imageContent"
94
112
  export {
95
113
  traverseDocumentContent,
96
114
  traverseSlicesContent,
package/src/io-ts.ts CHANGED
@@ -60,9 +60,16 @@ import {
60
60
  GroupContentSchema as rawGroupContentSchema,
61
61
  GroupItemContentSchema as rawGroupItemContentSchema,
62
62
  } from "./content/group"
63
- import { ImageContentSchema as rawImageContentSchema } from "./content/image"
63
+ import {
64
+ ImageContentSchema as rawImageContentSchema,
65
+ ImageContentViewSchema as rawImageContentViewSchema,
66
+ } from "./content/image"
64
67
  import { IntegrationFieldContentSchema as rawIntegrationFieldContentSchema } from "./content/integrationField"
65
- import { LinkContentSchema as rawLinkContentSchema } from "./content/link"
68
+ import {
69
+ EmptyLinkContentSchema as rawEmptyLinkContentSchema,
70
+ FilledLinkContentSchema as rawFilledLinkContentSchema,
71
+ LinkContentSchema as rawLinkContentSchema,
72
+ } from "./content/link"
66
73
  import { NestableContentSchema as rawNestableContentSchema } from "./content/nestable"
67
74
  import { RepeatableContentSchema as rawRepeatableContentSchema } from "./content/repeatable"
68
75
  import {
@@ -92,7 +99,9 @@ import { BooleanModelSchema as rawBooleanModelSchema } from "./model/boolean"
92
99
  import { ColorModelSchema as rawColorModelSchema } from "./model/color"
93
100
  import {
94
101
  StaticCustomTypeModelSchema as rawStaticCustomTypeModelSchema,
95
- CustomTypeModelSchema as rawCustomTypeModelSchema,
102
+ DynamicCustomTypeModelSchema as rawDynamicCustomTypeModelSchema,
103
+ StaticCustomTypeModelTabSchema as rawStaticCustomTypeModelTabSchema,
104
+ DynamicCustomTypeModelTabSchema as rawDynamicCustomTypeModelTabSchema,
96
105
  } from "./model/customType"
97
106
  import { DateModelSchema as rawDateModelSchema } from "./model/date"
98
107
  import { EmbedModelSchema as rawEmbedModelSchema } from "./model/embed"
@@ -108,16 +117,13 @@ import { NestableModelSchema as rawNestableModelSchema } from "./model/nestable"
108
117
  import { NumberModelSchema as rawNumberModelSchema } from "./model/number"
109
118
  import { RangeModelSchema as rawRangeModelSchema } from "./model/range"
110
119
  import { RichTextModelSchema as rawRichTextModelSchema } from "./model/richText"
111
- import {
112
- StaticSectionModelSchema as rawStaticSectionModelSchema,
113
- DynamicSectionModelSchema as rawDynamicSectionModelSchema,
114
- } from "./model/section"
115
120
  import { SelectModelSchema as rawSelectModelSchema } from "./model/select"
116
121
  import { SeparatorModelSchema as rawSeparatorModelSchema } from "./model/separator"
117
122
  import {
118
123
  LegacySliceModelSchema as rawLegacySliceModelSchema,
119
124
  CompositeSliceModelSchema as rawCompositeSliceModelSchema,
120
125
  SharedSliceModelSchema as rawSharedSliceModelSchema,
126
+ SharedSliceModelVariationSchema as rawSharedSliceModelVariationSchema,
121
127
  SharedSliceRefModelSchema as rawSharedSliceRefModelSchema,
122
128
  StaticSliceModelSchema as rawStaticSliceModelSchema,
123
129
  DynamicSliceModelSchema as rawDynamicSliceModelSchema,
@@ -149,6 +155,8 @@ export const ColorContentSchema = toIOTS(rawColorContentSchema)
149
155
  export const DateContentSchema = toIOTS(rawDateContentSchema)
150
156
  export const EmptyContentSchema = toIOTS(rawEmptyContentSchema)
151
157
  export const GeoPointContentSchema = toIOTS(rawGeoPointContentSchema)
158
+ export const FilledLinkContentSchema = toIOTS(rawFilledLinkContentSchema)
159
+ export const EmptyLinkContentSchema = toIOTS(rawEmptyLinkContentSchema)
152
160
  export const LinkContentSchema = toIOTS(rawLinkContentSchema)
153
161
  export const NumberContentSchema = toIOTS(rawNumberContentSchema)
154
162
  export const RangeContentSchema = toIOTS(rawRangeContentSchema)
@@ -161,6 +169,7 @@ export const FieldContentSchema = toIOTS(rawFieldContentSchema)
161
169
  export const UIDContentSchema = toIOTS(rawUIDContentSchema)
162
170
  export const IntegrationFieldContentSchema = toIOTS(rawIntegrationFieldContentSchema)
163
171
  export const EmbedContentSchema = toIOTS(rawEmbedContentSchema)
172
+ export const ImageContentViewSchema = toIOTS(rawImageContentViewSchema)
164
173
  export const ImageContentSchema = toIOTS(rawImageContentSchema)
165
174
  export const RichTextContentSchema = toIOTS(rawRichTextContentSchema)
166
175
  export const RichTextContentBlockSchema = toIOTS(rawRichTextContentBlockSchema)
@@ -235,6 +244,7 @@ export const TimestampModelSchema = toIOTS(rawTimestampModelSchema)
235
244
  export const UIDModelSchema = toIOTS(rawUIDModelSchema)
236
245
  export const GroupModelSchema = toIOTS(rawGroupModelSchema)
237
246
  export const NestedGroupModelSchema = toIOTS(rawNestedGroupModelSchema)
247
+ export const SharedSliceModelVariationSchema = toIOTS(rawSharedSliceModelVariationSchema)
238
248
  export const SharedSliceRefModelSchema = toIOTS(rawSharedSliceRefModelSchema)
239
249
  export const CompositeSliceModelSchema = toIOTS(rawCompositeSliceModelSchema)
240
250
  export const LegacySliceModelSchema = toIOTS(rawLegacySliceModelSchema)
@@ -245,10 +255,12 @@ export const DynamicSlicesModelSchema = toIOTS(rawDynamicSlicesModelSchema)
245
255
  export const StaticSlicesModelSchema = toIOTS(rawStaticSlicesModelSchema)
246
256
  export const StaticWidgetModelSchema = toIOTS(rawStaticWidgetModelSchema)
247
257
  export const DynamicWidgetModelSchema = toIOTS(rawDynamicWidgetModelSchema)
248
- export const StaticSectionModelSchema = toIOTS(rawStaticSectionModelSchema)
249
- export const DynamicSectionModelSchema = toIOTS(rawDynamicSectionModelSchema)
258
+ export const StaticCustomTypeModelTabSchema = toIOTS(rawStaticCustomTypeModelTabSchema)
259
+ export const DynamicCustomTypeModelTabSchema = toIOTS(rawDynamicCustomTypeModelTabSchema)
250
260
  export const StaticCustomTypeModelSchema = toIOTS(rawStaticCustomTypeModelSchema)
251
- export const CustomTypeModelSchema = toIOTS(rawCustomTypeModelSchema)
261
+ export const DynamicCustomTypeModelSchema = toIOTS(rawDynamicCustomTypeModelSchema)
262
+ /** @deprecated Use DynamicCustomTypeModelSchema instead */
263
+ export const CustomTypeModelSchema = DynamicCustomTypeModelSchema
252
264
 
253
265
  function toIOTS<T>(type: ZodMiniType<T>): t.Type<T> {
254
266
  return new t.Type<T>(
@@ -1,8 +1,16 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
- import { DynamicSectionModelSchema, StaticSectionModelSchema } from "./section"
3
+ import { WidgetKeySchema } from "../common/widgetKey"
4
+ import { DynamicWidgetModelSchema, StaticWidgetModelSchema } from "./widget"
4
5
 
5
- // CustomTypeFormat - "page" | "custom"
6
+ // Tab
7
+ export const StaticCustomTypeModelTabSchema = z.record(WidgetKeySchema, StaticWidgetModelSchema)
8
+ export type StaticCustomTypeModelTab = z.infer<typeof StaticCustomTypeModelTabSchema>
9
+
10
+ export const DynamicCustomTypeModelTabSchema = z.record(WidgetKeySchema, DynamicWidgetModelSchema)
11
+ export type DynamicCustomTypeModelTab = z.infer<typeof DynamicCustomTypeModelTabSchema>
12
+
13
+ // Custom types
6
14
  export const CustomTypeFormatSchema = z.enum(["page", "custom"])
7
15
  export type CustomTypeFormat = z.infer<typeof CustomTypeFormatSchema>
8
16
 
@@ -17,10 +25,13 @@ const createCustomTypeSchema = <T extends z.ZodMiniType>(sectionSchema: T) =>
17
25
  format: z._default(CustomTypeFormatSchema, "custom"),
18
26
  })
19
27
 
20
- // StaticCustomType - uses StaticSection (with full SharedSlice definitions)
21
- export const StaticCustomTypeModelSchema = createCustomTypeSchema(StaticSectionModelSchema)
28
+ export const StaticCustomTypeModelSchema = createCustomTypeSchema(StaticCustomTypeModelTabSchema)
22
29
  export type StaticCustomTypeModel = z.infer<typeof StaticCustomTypeModelSchema>
23
30
 
24
- // CustomType (dynamic) - uses DynamicSection (with SharedSliceRef references)
25
- export const CustomTypeModelSchema = createCustomTypeSchema(DynamicSectionModelSchema)
26
- export type CustomTypeModel = z.infer<typeof CustomTypeModelSchema>
31
+ export const DynamicCustomTypeModelSchema = createCustomTypeSchema(DynamicCustomTypeModelTabSchema)
32
+ export type DynamicCustomTypeModel = z.infer<typeof DynamicCustomTypeModelSchema>
33
+
34
+ /** @deprecated Use DynamicCustomTypeModelSchema instead */
35
+ export const CustomTypeModelSchema = DynamicCustomTypeModelSchema
36
+ /** @deprecated Use DynamicCustomTypeModel instead */
37
+ export type CustomTypeModel = DynamicCustomTypeModel
@@ -1,4 +1,4 @@
1
- import type { SharedSliceModel, SharedSliceVariation } from "../slice"
1
+ import type { SharedSliceModel, SharedSliceModelVariation } from "../slice"
2
2
  import { type DiffChange, DiffOperation } from "./changes"
3
3
  import { isNotEmpty, toRecord, zipObjects } from "./utils"
4
4
  import { type VariationDiff, VariationComparator } from "./variation"
@@ -41,7 +41,7 @@ export const SliceComparator = {
41
41
 
42
42
  const diffMeta = compareSliceMeta(sliceA, sliceB)
43
43
 
44
- const zippedSlices = zipObjects<SharedSliceVariation>(
44
+ const zippedSlices = zipObjects<SharedSliceModelVariation>(
45
45
  sliceA && toRecord(sliceA.variations, (v) => v.id),
46
46
  sliceB && toRecord(sliceB.variations, (v) => v.id),
47
47
  )
@@ -1,7 +1,7 @@
1
1
  import type { GroupModel } from "../group"
2
2
  import { GroupFieldType } from "../group"
3
3
  import type { NestableModel } from "../nestable"
4
- import type { SharedSliceVariation } from "../slice"
4
+ import type { SharedSliceModelVariation } from "../slice"
5
5
  import { type DiffChange, DiffOperation } from "./changes"
6
6
  import { isNotEmpty, zipObjects } from "./utils"
7
7
  import type {
@@ -10,9 +10,9 @@ import type {
10
10
  SlicePrimaryWidgetDiff,
11
11
  } from "./widgets"
12
12
 
13
- export type VariationMetadata = Omit<SharedSliceVariation, "primary" | "items">
13
+ export type VariationMetadata = Omit<SharedSliceModelVariation, "primary" | "items">
14
14
  export type VariationDiff = DiffChange<
15
- SharedSliceVariation,
15
+ SharedSliceModelVariation,
16
16
  Partial<VariationMetadata> & {
17
17
  primary?: Record<string, SlicePrimaryWidgetDiff>
18
18
  items?: Record<string, NestableWidgetDiff>
@@ -20,8 +20,8 @@ export type VariationDiff = DiffChange<
20
20
  >
21
21
 
22
22
  function compareVariationMeta(
23
- variationA?: SharedSliceVariation,
24
- variationB?: SharedSliceVariation,
23
+ variationA?: SharedSliceModelVariation,
24
+ variationB?: SharedSliceModelVariation,
25
25
  ): Partial<VariationMetadata> {
26
26
  const zippedVariations = zipObjects(variationA, variationB)
27
27
 
@@ -119,8 +119,8 @@ function compareWidgets<TWidget extends NestableModel | GroupModel>(
119
119
 
120
120
  export const VariationComparator = {
121
121
  compare(
122
- variationA?: SharedSliceVariation,
123
- variationB?: SharedSliceVariation,
122
+ variationA?: SharedSliceModelVariation,
123
+ variationB?: SharedSliceModelVariation,
124
124
  ): VariationDiff | undefined {
125
125
  if (variationA && !variationB)
126
126
  return {
@@ -6,7 +6,7 @@ export const RichTextFieldType = "StructuredText"
6
6
 
7
7
  export const DEFAULT_OPTION = "paragraph"
8
8
 
9
- export const RichTextNodeType = {
9
+ export const RichTextModelNodeType = {
10
10
  heading1: "heading1",
11
11
  heading2: "heading2",
12
12
  heading3: "heading3",
@@ -25,7 +25,10 @@ export const RichTextNodeType = {
25
25
  rtl: "rtl",
26
26
  } as const
27
27
 
28
- const VALID_NODE_TYPES = Object.values(RichTextNodeType)
28
+ export type RichTextModelNodeTypes =
29
+ (typeof RichTextModelNodeType)[keyof typeof RichTextModelNodeType]
30
+
31
+ const VALID_NODE_TYPES = Object.values(RichTextModelNodeType)
29
32
 
30
33
  /**
31
34
  * RichTextOptions parses comma-separated node types, filters invalid ones,
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
3
  import { WidgetKeySchema } from "../common/widgetKey"
4
- import type { NestedGroupModel } from "./group"
4
+ import type { GroupModel, NestedGroupModel } from "./group"
5
5
  import { GroupModelSchema, NestedGroupModelSchema } from "./group"
6
6
  import type { NestableModel } from "./nestable"
7
7
  import { NestableModelSchema } from "./nestable"
@@ -40,7 +40,7 @@ export const SharedSliceType = "SharedSlice" as const
40
40
  const IMAGE_PLACEHOLDER_URL =
41
41
  "https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format"
42
42
 
43
- export const SharedSliceVariationSchema = z.object({
43
+ export const SharedSliceModelVariationSchema = z.object({
44
44
  id: z.string(),
45
45
  name: z.string(),
46
46
  description: z.string(),
@@ -51,21 +51,19 @@ export const SharedSliceVariationSchema = z.object({
51
51
  primary: z.optional(
52
52
  z.record(
53
53
  z.string(),
54
- z.union([NestableModelSchema, GroupModelSchema]) as z.ZodMiniType<
55
- NestableModel | NestedGroupModel
56
- >,
54
+ z.union([NestableModelSchema, GroupModelSchema]) as z.ZodMiniType<NestableModel | GroupModel>,
57
55
  ),
58
56
  ),
59
57
  items: z.optional(z.record(z.string(), NestableModelSchema)),
60
58
  })
61
59
 
62
- export type SharedSliceVariation = z.infer<typeof SharedSliceVariationSchema>
60
+ export type SharedSliceModelVariation = z.infer<typeof SharedSliceModelVariationSchema>
63
61
 
64
62
  export const SharedSliceModelSchema = z.object({
65
63
  id: z.string(),
66
64
  type: z.literal(SharedSliceType),
67
65
  name: z.string(),
68
- variations: z.array(SharedSliceVariationSchema),
66
+ variations: z.array(SharedSliceModelVariationSchema),
69
67
  description: z.optional(z.string()),
70
68
  legacyPaths: z.optional(z.record(z.string(), z.string())),
71
69
  })
@@ -84,7 +82,7 @@ export const SharedSliceVariationContentModelSchema = z.object({
84
82
  type: z.literal(SharedSliceType),
85
83
  sliceName: z.string(),
86
84
  variationID: z.string(),
87
- fields: z.pick(SharedSliceVariationSchema, { primary: true, items: true }),
85
+ fields: z.pick(SharedSliceModelVariationSchema, { primary: true, items: true }),
88
86
  })
89
87
 
90
88
  export type SharedSliceVariationContentModel = z.infer<