@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.
Files changed (117) 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 +2 -1
  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 +25 -22
  69. package/dist/index.js +6 -1
  70. package/dist/io-ts.d.ts +1156 -727
  71. package/dist/io-ts.d.ts.map +1 -1
  72. package/dist/io-ts.js +11 -7
  73. package/dist/io-ts.js.map +1 -1
  74. package/dist/model/richText.d.ts +20 -1
  75. package/dist/model/richText.d.ts.map +1 -1
  76. package/dist/model/richText.js +3 -3
  77. package/dist/model/richText.js.map +1 -1
  78. package/dist/model/slice.d.ts +1251 -643
  79. package/dist/model/slice.d.ts.map +1 -1
  80. package/dist/model/slice.js +4 -4
  81. package/dist/model/slice.js.map +1 -1
  82. package/dist/model/table.js +5 -5
  83. package/dist/model/table.js.map +1 -1
  84. package/dist/model/widget.d.ts +1 -3
  85. package/dist/model/widget.d.ts.map +1 -1
  86. package/dist/model/widget.js +5 -2
  87. package/dist/model/widget.js.map +1 -1
  88. package/dist/zod4.d.ts +2392 -1873
  89. package/dist/zod4.d.ts.map +1 -1
  90. package/dist/zod4.js +11 -7
  91. package/dist/zod4.js.map +1 -1
  92. package/package.json +19 -12
  93. package/src/content/boolean.ts +0 -13
  94. package/src/content/codec/link.ts +12 -12
  95. package/src/content/field.ts +0 -14
  96. package/src/content/group.ts +1 -54
  97. package/src/content/image.ts +3 -91
  98. package/src/content/legacy/image.ts +4 -4
  99. package/src/content/legacy/link.ts +46 -46
  100. package/src/content/legacy/richText.ts +18 -16
  101. package/src/content/link.ts +100 -89
  102. package/src/content/nestable.ts +1 -20
  103. package/src/content/richText.ts +23 -17
  104. package/src/helpers/customTypeModel.ts +44 -0
  105. package/src/helpers/imageContent.ts +84 -0
  106. package/src/helpers/traverseContent.ts +4 -1
  107. package/src/helpers/withDefaultContent.ts +180 -0
  108. package/src/index.ts +18 -5
  109. package/src/io-ts.ts +14 -2
  110. package/src/model/diff/sharedSlice.ts +2 -2
  111. package/src/model/diff/variation.ts +7 -7
  112. package/src/model/richText.ts +5 -2
  113. package/src/model/slice.ts +6 -8
  114. package/src/model/table.ts +5 -5
  115. package/src/model/widget.ts +6 -2
  116. package/src/zod4.ts +14 -2
  117. package/src/content/withDefaultValues.ts +0 -114
@@ -21,7 +21,7 @@ export const LinkType = {
21
21
  } as const
22
22
 
23
23
  // Image
24
- export const FilledImageLinkValueLegacySchema = z.strictObject({
24
+ export const FilledImageLinkLegacyValueSchema = z.strictObject({
25
25
  // `kind` was normalized to the literal (legacy behavior)
26
26
  kind: z.pipe(
27
27
  z.string(),
@@ -36,12 +36,12 @@ export const FilledImageLinkValueLegacySchema = z.strictObject({
36
36
  date: z.nullish(z.string()),
37
37
  })
38
38
 
39
- export const EmptyImageLinkValueLegacySchema = z.strictObject({
39
+ export const EmptyImageLinkLegacyValueSchema = z.strictObject({
40
40
  kind: z.literal(LinkKind.Image),
41
41
  })
42
42
 
43
43
  // File
44
- export const FilledFileLinkValueLegacySchema = z.strictObject({
44
+ export const FilledFileLinkLegacyValueSchema = z.strictObject({
45
45
  // `kind` was normalized to the literal (legacy behavior)
46
46
  kind: z.pipe(
47
47
  z.string(),
@@ -54,7 +54,7 @@ export const FilledFileLinkValueLegacySchema = z.strictObject({
54
54
  date: z.nullish(z.string()),
55
55
  })
56
56
 
57
- export const EmptyFileLinkValueLegacySchema = z.strictObject({
57
+ export const EmptyFileLinkLegacyValueSchema = z.strictObject({
58
58
  kind: z.literal(LinkKind.File),
59
59
  })
60
60
 
@@ -62,12 +62,12 @@ export const EmptyFileLinkValueLegacySchema = z.strictObject({
62
62
 
63
63
  // Media link only represent the empty state as they turn into
64
64
  // file or image links when they filled.
65
- export const EmptyMediaLinkValueLegacySchema = z.strictObject({
65
+ export const EmptyMediaLinkLegacyValueSchema = z.strictObject({
66
66
  kind: z.literal(LinkKind.Media),
67
67
  })
68
68
 
69
69
  // Document
70
- export const FilledDocumentLinkValueLegacySchema = z.strictObject({
70
+ export const FilledDocumentLinkLegacyValueSchema = z.strictObject({
71
71
  // `kind` is not part of the filled schema... (legacy behavior)
72
72
  // We transform it to the literal for consistency.
73
73
  kind: z.pipe(
@@ -77,12 +77,12 @@ export const FilledDocumentLinkValueLegacySchema = z.strictObject({
77
77
  id: NonEmptyStringSchema,
78
78
  })
79
79
 
80
- export const EmptyDocumentLinkValueLegacySchema = z.strictObject({
80
+ export const EmptyDocumentLinkLegacyValueSchema = z.strictObject({
81
81
  kind: z.literal(LinkKind.Document),
82
82
  })
83
83
 
84
84
  // External
85
- export const FilledExternalLinkValueLegacySchema = z.strictObject({
85
+ export const FilledExternalLinkLegacyValueSchema = z.strictObject({
86
86
  // It's odd that `kind` is optional here... (legacy behavior)
87
87
  // We transform it to the literal for consistency.
88
88
  kind: z.pipe(
@@ -98,7 +98,7 @@ export const FilledExternalLinkValueLegacySchema = z.strictObject({
98
98
  ),
99
99
  })
100
100
 
101
- export const EmptyExternalLinkValueLegacySchema = z.strictObject({
101
+ export const EmptyExternalLinkLegacyValueSchema = z.strictObject({
102
102
  kind: z.literal(LinkKind.External),
103
103
  })
104
104
 
@@ -109,52 +109,52 @@ export const AnyLinkLegacySchema = z.strictObject({
109
109
 
110
110
  // All
111
111
 
112
- export const FilledLinkValueLegacySchema: z.ZodMiniType<FilledLinkValueLegacy> = z.union([
113
- FilledImageLinkValueLegacySchema,
114
- FilledFileLinkValueLegacySchema,
115
- FilledDocumentLinkValueLegacySchema,
116
- FilledExternalLinkValueLegacySchema,
112
+ export const FilledLinkLegacyValueSchema: z.ZodMiniType<FilledLinkLegacyValue> = z.union([
113
+ FilledImageLinkLegacyValueSchema,
114
+ FilledFileLinkLegacyValueSchema,
115
+ FilledDocumentLinkLegacyValueSchema,
116
+ FilledExternalLinkLegacyValueSchema,
117
117
  ])
118
118
 
119
- type FilledImageLinkValueLegacy = z.infer<typeof FilledImageLinkValueLegacySchema>
120
- type FilledFileLinkValueLegacy = z.infer<typeof FilledFileLinkValueLegacySchema>
121
- type FilledDocumentLinkValueLegacy = z.infer<typeof FilledDocumentLinkValueLegacySchema>
122
- type FilledExternalLinkValueLegacy = z.infer<typeof FilledExternalLinkValueLegacySchema>
123
- export type FilledLinkValueLegacy =
124
- | FilledImageLinkValueLegacy
125
- | FilledFileLinkValueLegacy
126
- | FilledDocumentLinkValueLegacy
127
- | FilledExternalLinkValueLegacy
128
-
129
- const EmptyLinkValueLegacySchema: z.ZodMiniType<EmptyLinkValueLegacy> = z.union([
130
- EmptyImageLinkValueLegacySchema,
131
- EmptyFileLinkValueLegacySchema,
132
- EmptyMediaLinkValueLegacySchema,
133
- EmptyDocumentLinkValueLegacySchema,
134
- EmptyExternalLinkValueLegacySchema,
119
+ type FilledImageLinkLegacyValue = z.infer<typeof FilledImageLinkLegacyValueSchema>
120
+ type FilledFileLinkLegacyValue = z.infer<typeof FilledFileLinkLegacyValueSchema>
121
+ type FilledDocumentLinkLegacyValue = z.infer<typeof FilledDocumentLinkLegacyValueSchema>
122
+ type FilledExternalLinkLegacyValue = z.infer<typeof FilledExternalLinkLegacyValueSchema>
123
+ export type FilledLinkLegacyValue =
124
+ | FilledImageLinkLegacyValue
125
+ | FilledFileLinkLegacyValue
126
+ | FilledDocumentLinkLegacyValue
127
+ | FilledExternalLinkLegacyValue
128
+
129
+ const EmptyLinkLegacyValueSchema: z.ZodMiniType<EmptyLinkLegacyValue> = z.union([
130
+ EmptyImageLinkLegacyValueSchema,
131
+ EmptyFileLinkLegacyValueSchema,
132
+ EmptyMediaLinkLegacyValueSchema,
133
+ EmptyDocumentLinkLegacyValueSchema,
134
+ EmptyExternalLinkLegacyValueSchema,
135
135
  AnyLinkLegacySchema,
136
136
  ])
137
137
 
138
- type EmptyImageLinkValueLegacy = z.infer<typeof EmptyImageLinkValueLegacySchema>
139
- type EmptyFileLinkValueLegacy = z.infer<typeof EmptyFileLinkValueLegacySchema>
140
- type EmptyMediaLinkValueLegacy = z.infer<typeof EmptyMediaLinkValueLegacySchema>
141
- type EmptyDocumentLinkValueLegacy = z.infer<typeof EmptyDocumentLinkValueLegacySchema>
142
- type EmptyExternalLinkValueLegacy = z.infer<typeof EmptyExternalLinkValueLegacySchema>
138
+ type EmptyImageLinkLegacyValue = z.infer<typeof EmptyImageLinkLegacyValueSchema>
139
+ type EmptyFileLinkLegacyValue = z.infer<typeof EmptyFileLinkLegacyValueSchema>
140
+ type EmptyMediaLinkLegacyValue = z.infer<typeof EmptyMediaLinkLegacyValueSchema>
141
+ type EmptyDocumentLinkLegacyValue = z.infer<typeof EmptyDocumentLinkLegacyValueSchema>
142
+ type EmptyExternalLinkLegacyValue = z.infer<typeof EmptyExternalLinkLegacyValueSchema>
143
143
  type AnyLinkLegacy = z.infer<typeof AnyLinkLegacySchema>
144
- export type EmptyLinkValueLegacy =
145
- | EmptyImageLinkValueLegacy
146
- | EmptyFileLinkValueLegacy
147
- | EmptyMediaLinkValueLegacy
148
- | EmptyDocumentLinkValueLegacy
149
- | EmptyExternalLinkValueLegacy
144
+ export type EmptyLinkLegacyValue =
145
+ | EmptyImageLinkLegacyValue
146
+ | EmptyFileLinkLegacyValue
147
+ | EmptyMediaLinkLegacyValue
148
+ | EmptyDocumentLinkLegacyValue
149
+ | EmptyExternalLinkLegacyValue
150
150
  | AnyLinkLegacy
151
151
 
152
- const LinkValueLegacySchema: z.ZodMiniType<LinkValueLegacy> = z.union([
153
- FilledLinkValueLegacySchema,
154
- EmptyLinkValueLegacySchema,
152
+ const LinkLegacyValueSchema: z.ZodMiniType<LinkLegacyValue> = z.union([
153
+ FilledLinkLegacyValueSchema,
154
+ EmptyLinkLegacyValueSchema,
155
155
  ])
156
156
 
157
- export type LinkValueLegacy = FilledLinkValueLegacy | EmptyLinkValueLegacy
157
+ export type LinkLegacyValue = FilledLinkLegacyValue | EmptyLinkLegacyValue
158
158
 
159
159
  // We cannot use z.extend here because we're working with unions.
160
160
  // z.intersection wouldn't work also for the same reason.
@@ -180,7 +180,7 @@ export const LinkLegacySchema = z.pipe(
180
180
  key: z.optional(z.string()),
181
181
  text: z.optional(z.string()),
182
182
  variant: z.optional(z.string()),
183
- value: LinkValueLegacySchema as z.ZodMiniType<LinkValueLegacy, Record<string, unknown>>,
183
+ value: LinkLegacyValueSchema as z.ZodMiniType<LinkLegacyValue, Record<string, unknown>>,
184
184
  }),
185
185
  ),
186
186
  z.transform(({ key, text, variant, value }) => ({
@@ -3,21 +3,21 @@ import { z } from "zod/mini"
3
3
  // It's important to only import the types here to
4
4
  // avoid runtime circular dependencies!
5
5
  import type { EmbedContentSchema } from "../embed"
6
- import type { ImageViewContentSchema } from "../image"
7
- import type { FilledLinkValueContent, FilledLinkValueContentSchema } from "../link"
6
+ import type { ImageContentViewSchema } from "../image"
7
+ import type { FilledLinkContentValue, FilledLinkContentValueSchema } from "../link"
8
8
  import { EmbedLegacyLooseSchema } from "./embed"
9
- import { ImageViewLegacySchema } from "./image"
10
- import { FilledLinkValueLegacySchema } from "./link"
11
- import type { FilledLinkValueLegacy } from "./link"
9
+ import { ImageLegacyViewSchema } from "./image"
10
+ import { FilledLinkLegacyValueSchema } from "./link"
11
+ import type { FilledLinkLegacyValue } from "./link"
12
12
 
13
13
  export const RichTextNodeType = {
14
- paragraph: "paragraph",
15
14
  heading1: "heading1",
16
15
  heading2: "heading2",
17
16
  heading3: "heading3",
18
17
  heading4: "heading4",
19
18
  heading5: "heading5",
20
19
  heading6: "heading6",
20
+ paragraph: "paragraph",
21
21
  preformatted: "preformatted",
22
22
  oListItem: "o-list-item",
23
23
  listItem: "list-item",
@@ -28,8 +28,10 @@ export const RichTextNodeType = {
28
28
  em: "em",
29
29
  } as const
30
30
 
31
+ export type RichTextNodeTypes = (typeof RichTextNodeType)[keyof typeof RichTextNodeType]
32
+
31
33
  // Spans
32
- type HyperlinkSpan<TData extends FilledLinkValueLegacy | FilledLinkValueContent> = {
34
+ type HyperlinkSpan<TData extends FilledLinkLegacyValue | FilledLinkContentValue> = {
33
35
  type: typeof RichTextNodeType.hyperlink
34
36
  start: number
35
37
  end: number
@@ -37,7 +39,7 @@ type HyperlinkSpan<TData extends FilledLinkValueLegacy | FilledLinkValueContent>
37
39
  }
38
40
 
39
41
  const getHyperlinkSpanSchema = <
40
- TData extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
42
+ TData extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,
41
43
  >(
42
44
  data: TData,
43
45
  ) =>
@@ -81,14 +83,14 @@ const BasicSpanSchema: z.ZodMiniType<BasicSpan> = z.object({
81
83
  end: z.number(),
82
84
  })
83
85
 
84
- export type Span<TLink extends FilledLinkValueLegacy | FilledLinkValueContent> =
86
+ export type Span<TLink extends FilledLinkLegacyValue | FilledLinkContentValue> =
85
87
  | HyperlinkSpan<TLink>
86
88
  | LabelSpan
87
89
  | BasicSpan
88
90
 
89
91
  // oxlint-disable-next-line explicit-module-boundary-types
90
92
  export const getSpanSchema = <
91
- TLinkSchema extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
93
+ TLinkSchema extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,
92
94
  >(
93
95
  linkSchema: TLinkSchema,
94
96
  ) => z.union([getHyperlinkSpanSchema(linkSchema), LabelSpanSchema, BasicSpanSchema])
@@ -109,7 +111,7 @@ const TextBlockTypeSchema = z.union([
109
111
 
110
112
  // oxlint-disable-next-line explicit-module-boundary-types
111
113
  export const getTextBlockSchema = <
112
- TLinkSchema extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
114
+ TLinkSchema extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,
113
115
  >(
114
116
  linkSchema: TLinkSchema,
115
117
  ) =>
@@ -138,7 +140,7 @@ export const getTextBlockSchema = <
138
140
  direction: z.optional(z.string()),
139
141
  })
140
142
 
141
- const TextBlockLegacySchema = getTextBlockSchema(FilledLinkValueLegacySchema)
143
+ const TextBlockLegacySchema = getTextBlockSchema(FilledLinkLegacyValueSchema)
142
144
 
143
145
  type TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>
144
146
 
@@ -146,8 +148,8 @@ type TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>
146
148
 
147
149
  // oxlint-disable-next-line explicit-module-boundary-types
148
150
  export const getImageBlockSchema = <
149
- TData extends typeof ImageViewLegacySchema | typeof ImageViewContentSchema,
150
- TLinkTo extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
151
+ TData extends typeof ImageLegacyViewSchema | typeof ImageContentViewSchema,
152
+ TLinkTo extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,
151
153
  >(
152
154
  data: TData,
153
155
  linkTo: TLinkTo,
@@ -160,8 +162,8 @@ export const getImageBlockSchema = <
160
162
  })
161
163
 
162
164
  const ImageBlockLegacySchema = getImageBlockSchema(
163
- ImageViewLegacySchema,
164
- FilledLinkValueLegacySchema,
165
+ ImageLegacyViewSchema,
166
+ FilledLinkLegacyValueSchema,
165
167
  )
166
168
 
167
169
  type ImageBlockLegacy = z.infer<typeof ImageBlockLegacySchema>
@@ -1,154 +1,165 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
3
  import {
4
- EmptyDocumentLinkValueLegacySchema,
5
- EmptyImageLinkValueLegacySchema,
6
- FilledDocumentLinkValueLegacySchema,
7
- FilledFileLinkValueLegacySchema,
8
- FilledImageLinkValueLegacySchema,
9
- EmptyMediaLinkValueLegacySchema,
10
- FilledExternalLinkValueLegacySchema,
11
- EmptyExternalLinkValueLegacySchema,
4
+ EmptyDocumentLinkLegacyValueSchema,
5
+ EmptyImageLinkLegacyValueSchema,
6
+ FilledDocumentLinkLegacyValueSchema,
7
+ FilledFileLinkLegacyValueSchema,
8
+ FilledImageLinkLegacyValueSchema,
9
+ EmptyMediaLinkLegacyValueSchema,
10
+ FilledExternalLinkLegacyValueSchema,
11
+ EmptyExternalLinkLegacyValueSchema,
12
12
  AnyLinkLegacySchema,
13
13
  LinkType,
14
- EmptyFileLinkValueLegacySchema,
14
+ EmptyFileLinkLegacyValueSchema,
15
15
  } from "./legacy/link"
16
16
 
17
17
  // Image
18
- const FilledImageLinkValueContentSchema = z.extend(FilledImageLinkValueLegacySchema, {
18
+ const FilledImageLinkContentValueSchema = z.extend(FilledImageLinkLegacyValueSchema, {
19
19
  __TYPE__: z.literal(LinkType.Image),
20
20
  })
21
21
 
22
- const EmptyImageLinkValueContentSchema = z.extend(EmptyImageLinkValueLegacySchema, {
22
+ const EmptyImageLinkContentValueSchema = z.extend(EmptyImageLinkLegacyValueSchema, {
23
23
  __TYPE__: z.literal(LinkType.Image),
24
24
  })
25
25
 
26
26
  // File
27
- const FilledFileLinkValueContentSchema = z.extend(FilledFileLinkValueLegacySchema, {
27
+ const FilledFileLinkContentValueSchema = z.extend(FilledFileLinkLegacyValueSchema, {
28
28
  __TYPE__: z.literal(LinkType.File),
29
29
  })
30
30
 
31
- const EmptyFileLinkValueContentSchema = z.extend(EmptyFileLinkValueLegacySchema, {
31
+ const EmptyFileLinkContentValueSchema = z.extend(EmptyFileLinkLegacyValueSchema, {
32
32
  __TYPE__: z.literal(LinkType.File),
33
33
  })
34
34
 
35
35
  // Media
36
- const EmptyMediaLinkValueContentSchema = z.extend(EmptyMediaLinkValueLegacySchema, {
36
+ const EmptyMediaLinkContentValueSchema = z.extend(EmptyMediaLinkLegacyValueSchema, {
37
37
  __TYPE__: z.literal(LinkType.Media),
38
38
  })
39
39
 
40
40
  // Document
41
- const FilledDocumentLinkValueContentSchema = z.extend(FilledDocumentLinkValueLegacySchema, {
41
+ const FilledDocumentLinkContentValueSchema = z.extend(FilledDocumentLinkLegacyValueSchema, {
42
42
  __TYPE__: z.literal(LinkType.Document),
43
43
  })
44
44
 
45
- const EmptyDocumentLinkValueContentSchema = z.extend(EmptyDocumentLinkValueLegacySchema, {
45
+ const EmptyDocumentLinkContentValueSchema = z.extend(EmptyDocumentLinkLegacyValueSchema, {
46
46
  __TYPE__: z.literal(LinkType.Document),
47
47
  })
48
48
 
49
49
  // External
50
- const FilledExternalLinkValueContentSchema = z.extend(FilledExternalLinkValueLegacySchema, {
50
+ const FilledExternalLinkContentValueSchema = z.extend(FilledExternalLinkLegacyValueSchema, {
51
51
  __TYPE__: z.literal(LinkType.External),
52
52
  })
53
53
 
54
- const EmptyExternalLinkValueContentSchema = z.extend(EmptyExternalLinkValueLegacySchema, {
54
+ const EmptyExternalLinkContentValueSchema = z.extend(EmptyExternalLinkLegacyValueSchema, {
55
55
  __TYPE__: z.literal(LinkType.External),
56
56
  })
57
57
 
58
58
  // Any
59
- const AnyLinkValueContentSchema = z.extend(AnyLinkLegacySchema, {
59
+ const AnyLinkContentValueSchema = z.extend(AnyLinkLegacySchema, {
60
60
  __TYPE__: z.literal(LinkType.Any),
61
61
  })
62
62
 
63
63
  // All
64
64
 
65
65
  // Used by content/richText
66
- export const FilledLinkValueContentSchema: z.ZodMiniType<FilledLinkValueContent> = z.union([
67
- FilledImageLinkValueContentSchema,
68
- FilledFileLinkValueContentSchema,
69
- FilledDocumentLinkValueContentSchema,
70
- FilledExternalLinkValueContentSchema,
66
+ export const FilledLinkContentValueSchema: z.ZodMiniType<FilledLinkContentValue> = z.union([
67
+ FilledImageLinkContentValueSchema,
68
+ FilledFileLinkContentValueSchema,
69
+ FilledDocumentLinkContentValueSchema,
70
+ FilledExternalLinkContentValueSchema,
71
71
  ])
72
72
 
73
73
  // Used by content/legacy/link
74
- type FilledImageLinkValueContent = z.infer<typeof FilledImageLinkValueContentSchema>
75
- type FilledFileLinkValueContent = z.infer<typeof FilledFileLinkValueContentSchema>
76
- type FilledDocumentLinkValueContent = z.infer<typeof FilledDocumentLinkValueContentSchema>
77
- type FilledExternalLinkValueContent = z.infer<typeof FilledExternalLinkValueContentSchema>
78
- export type FilledLinkValueContent =
79
- | FilledImageLinkValueContent
80
- | FilledFileLinkValueContent
81
- | FilledDocumentLinkValueContent
82
- | FilledExternalLinkValueContent
83
-
84
- const EmptyLinkValueContentSchema: z.ZodMiniType<EmptyLinkValueContent> = z.union([
85
- EmptyImageLinkValueContentSchema,
86
- EmptyFileLinkValueContentSchema,
87
- EmptyMediaLinkValueContentSchema,
88
- EmptyDocumentLinkValueContentSchema,
89
- EmptyExternalLinkValueContentSchema,
90
- AnyLinkValueContentSchema,
74
+ type FilledImageLinkContentValue = z.infer<typeof FilledImageLinkContentValueSchema>
75
+ type FilledFileLinkContentValue = z.infer<typeof FilledFileLinkContentValueSchema>
76
+ type FilledDocumentLinkContentValue = z.infer<typeof FilledDocumentLinkContentValueSchema>
77
+ type FilledExternalLinkContentValue = z.infer<typeof FilledExternalLinkContentValueSchema>
78
+ export type FilledLinkContentValue =
79
+ | FilledImageLinkContentValue
80
+ | FilledFileLinkContentValue
81
+ | FilledDocumentLinkContentValue
82
+ | FilledExternalLinkContentValue
83
+
84
+ const EmptyLinkContentValueSchema: z.ZodMiniType<EmptyLinkContentValue> = z.union([
85
+ EmptyImageLinkContentValueSchema,
86
+ EmptyFileLinkContentValueSchema,
87
+ EmptyMediaLinkContentValueSchema,
88
+ EmptyDocumentLinkContentValueSchema,
89
+ EmptyExternalLinkContentValueSchema,
90
+ AnyLinkContentValueSchema,
91
91
  ])
92
92
 
93
93
  // Used by content/codec/link
94
- type EmptyImageLinkValueContent = z.infer<typeof EmptyImageLinkValueContentSchema>
95
- type EmptyFileLinkValueContent = z.infer<typeof EmptyFileLinkValueContentSchema>
96
- type EmptyMediaLinkValueContent = z.infer<typeof EmptyMediaLinkValueContentSchema>
97
- type EmptyDocumentLinkValueContent = z.infer<typeof EmptyDocumentLinkValueContentSchema>
98
- type EmptyExternalLinkValueContent = z.infer<typeof EmptyExternalLinkValueContentSchema>
99
- type AnyLinkValueContent = z.infer<typeof AnyLinkValueContentSchema>
100
- export type EmptyLinkValueContent =
101
- | EmptyImageLinkValueContent
102
- | EmptyFileLinkValueContent
103
- | EmptyMediaLinkValueContent
104
- | EmptyDocumentLinkValueContent
105
- | EmptyExternalLinkValueContent
106
- | AnyLinkValueContent
107
-
108
- const LinkValueContentSchema: z.ZodMiniType<LinkValueContent> = z.union([
109
- FilledLinkValueContentSchema,
110
- EmptyLinkValueContentSchema,
94
+ type EmptyImageLinkContentValue = z.infer<typeof EmptyImageLinkContentValueSchema>
95
+ type EmptyFileLinkContentValue = z.infer<typeof EmptyFileLinkContentValueSchema>
96
+ type EmptyMediaLinkContentValue = z.infer<typeof EmptyMediaLinkContentValueSchema>
97
+ type EmptyDocumentLinkContentValue = z.infer<typeof EmptyDocumentLinkContentValueSchema>
98
+ type EmptyExternalLinkContentValue = z.infer<typeof EmptyExternalLinkContentValueSchema>
99
+ type AnyLinkContentValue = z.infer<typeof AnyLinkContentValueSchema>
100
+ export type EmptyLinkContentValue =
101
+ | EmptyImageLinkContentValue
102
+ | EmptyFileLinkContentValue
103
+ | EmptyMediaLinkContentValue
104
+ | EmptyDocumentLinkContentValue
105
+ | EmptyExternalLinkContentValue
106
+ | AnyLinkContentValue
107
+
108
+ const LinkContentValueSchema: z.ZodMiniType<LinkContentValue> = z.union([
109
+ FilledLinkContentValueSchema,
110
+ EmptyLinkContentValueSchema,
111
111
  ])
112
112
 
113
113
  // Used by content/codec/link
114
- export type LinkValueContent = FilledLinkValueContent | EmptyLinkValueContent
114
+ export type LinkContentValue = FilledLinkContentValue | EmptyLinkContentValue
115
115
 
116
116
  // Content
117
117
  export const LinkContentType = "LinkContent" as const
118
118
 
119
- export const LinkContentSchema = z.object({
120
- __TYPE__: z.literal(LinkContentType),
121
- key: z.transform((value) => z.uuidv4().safeParse(value).data || crypto.randomUUID()),
122
- // We cannot use z.extend here because we're working with unions.
123
- // z.intersection wouldn't work also for the same reason.
124
- value: z.pipe(
125
- z.pipe(
119
+ const getLinkContentSchema = <TValue extends LinkContentValue>(value: z.ZodMiniType<TValue>) =>
120
+ z.object({
121
+ __TYPE__: z.literal(LinkContentType),
122
+ key: z.transform((value) => z.uuidv4().safeParse(value).data || crypto.randomUUID()),
123
+ // We cannot use z.extend here because we're working with unions.
124
+ // z.intersection wouldn't work also for the same reason.
125
+ value: z.pipe(
126
126
  z.pipe(
127
- z.record(z.string(), z.unknown()),
128
- z.transform(
129
- ({
130
- text,
131
- variant,
132
- ...value
133
- }): {
134
- text?: unknown
135
- variant?: unknown
136
- value: Record<string, unknown>
137
- } => ({ text, variant, value }),
127
+ z.pipe(
128
+ z.record(z.string(), z.unknown()),
129
+ z.transform(
130
+ ({
131
+ text,
132
+ variant,
133
+ ...value
134
+ }): {
135
+ text?: unknown
136
+ variant?: unknown
137
+ value: Record<string, unknown>
138
+ } => ({ text, variant, value }),
139
+ ),
138
140
  ),
141
+ z.object({
142
+ text: z.optional(z.string()),
143
+ variant: z.optional(z.string()),
144
+ value: value as z.ZodMiniType<TValue, Record<string, unknown>>,
145
+ }),
139
146
  ),
140
- z.object({
141
- text: z.optional(z.string()),
142
- variant: z.optional(z.string()),
143
- value: LinkValueContentSchema as z.ZodMiniType<LinkValueContent, Record<string, unknown>>,
144
- }),
147
+ z.transform(({ text, variant, value }) => ({
148
+ ...(text ? { text } : {}),
149
+ ...(variant ? { variant } : {}),
150
+ ...value,
151
+ })),
145
152
  ),
146
- z.transform(({ text, variant, value }) => ({
147
- ...(text ? { text } : {}),
148
- ...(variant ? { variant } : {}),
149
- ...value,
150
- })),
151
- ),
152
- })
153
+ })
154
+
155
+ export const FilledLinkContentSchema = getLinkContentSchema(FilledLinkContentValueSchema)
156
+
157
+ export type FilledLinkContent = z.infer<typeof FilledLinkContentSchema>
158
+
159
+ export const EmptyLinkContentSchema = getLinkContentSchema(EmptyLinkContentValueSchema)
160
+
161
+ export type EmptyLinkContent = z.infer<typeof EmptyLinkContentSchema>
162
+
163
+ export const LinkContentSchema = getLinkContentSchema(LinkContentValueSchema)
153
164
 
154
165
  export type LinkContent = z.infer<typeof LinkContentSchema>
@@ -1,8 +1,7 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
- import type { NestableModel } from "../model/nestable"
4
3
  import type { BooleanContent } from "./boolean"
5
- import { BooleanContentDefaultValue, BooleanContentSchema, BooleanContentType } from "./boolean"
4
+ import { BooleanContentSchema, BooleanContentType } from "./boolean"
6
5
  import type { EmbedContent } from "./embed"
7
6
  import { EmbedContentSchema, EmbedContentType } from "./embed"
8
7
  import type { EmptyContent } from "./empty"
@@ -22,7 +21,6 @@ import {
22
21
  FieldContentType,
23
22
  NumberContentSchema,
24
23
  RangeContentSchema,
25
- SelectContentDefaultValue,
26
24
  SelectContentSchema,
27
25
  TextContentSchema,
28
26
  TimestampContentSchema,
@@ -107,20 +105,3 @@ export function isNestableContent(content: {
107
105
  }): content is { __TYPE__: NestableContentType } {
108
106
  return (NestableContentTypes as string[]).includes(content.__TYPE__)
109
107
  }
110
-
111
- /**
112
- * Returns the default value for a nestable widget based on its configuration.
113
- * Currently only Boolean and Select fields have default values.
114
- */
115
- export const NestableContentDefaultValue = (
116
- widgetDef: NestableModel,
117
- ): NestableContent | undefined => {
118
- switch (widgetDef.type) {
119
- case "Boolean":
120
- return BooleanContentDefaultValue(widgetDef)
121
- case "Select":
122
- return SelectContentDefaultValue(widgetDef)
123
- default:
124
- return undefined
125
- }
126
- }
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
3
  import { EmbedContentSchema } from "./embed"
4
- import { ImageViewContentSchema } from "./image"
4
+ import { ImageContentViewSchema } from "./image"
5
5
  import {
6
6
  getEmbedBlockSchema,
7
7
  getImageBlockSchema,
@@ -9,37 +9,43 @@ import {
9
9
  getTextBlockSchema,
10
10
  } from "./legacy/richText"
11
11
  import type { Span } from "./legacy/richText"
12
- import type { FilledLinkValueContent } from "./link"
13
- import { FilledLinkValueContentSchema } from "./link"
12
+ import type { FilledLinkContentValue } from "./link"
13
+ import { FilledLinkContentValueSchema } from "./link"
14
+
15
+ export { RichTextNodeType } from "./legacy/richText"
16
+ export type { RichTextNodeTypes } from "./legacy/richText"
14
17
 
15
18
  // Spans
16
- export type RichTextContentSpan = Span<FilledLinkValueContent>
19
+ export type RichTextContentSpan = Span<FilledLinkContentValue>
17
20
 
18
21
  export const RichTextContentSpanSchema: z.ZodMiniType<RichTextContentSpan> = getSpanSchema(
19
- FilledLinkValueContentSchema,
22
+ FilledLinkContentValueSchema,
20
23
  )
21
24
 
22
25
  // Blocks
23
- const TextBlockValueSchema = getTextBlockSchema(FilledLinkValueContentSchema)
24
- type TextBlockValue = z.infer<typeof TextBlockValueSchema>
26
+ const RichTextContentTextBlockSchema = getTextBlockSchema(FilledLinkContentValueSchema)
27
+ export type RichTextContentTextBlock = z.infer<typeof RichTextContentTextBlockSchema>
25
28
 
26
- const ImageBlockValueSchema = getImageBlockSchema(
27
- ImageViewContentSchema,
28
- FilledLinkValueContentSchema,
29
+ const RichTextContentImageBlockSchema = getImageBlockSchema(
30
+ ImageContentViewSchema,
31
+ FilledLinkContentValueSchema,
29
32
  )
30
- type ImageBlockValue = z.infer<typeof ImageBlockValueSchema>
33
+ export type RichTextContentImageBlock = z.infer<typeof RichTextContentImageBlockSchema>
31
34
 
32
- const EmbedBlockValueSchema = getEmbedBlockSchema(EmbedContentSchema)
33
- type EmbedBlockValue = z.infer<typeof EmbedBlockValueSchema>
35
+ const RichTextContentEmbedBlockSchema = getEmbedBlockSchema(EmbedContentSchema)
36
+ export type RichTextContentEmbedBlock = z.infer<typeof RichTextContentEmbedBlockSchema>
34
37
 
35
38
  export const RichTextContentBlockSchema: z.ZodMiniType<RichTextContentBlock> = z.union([
36
- TextBlockValueSchema,
37
- ImageBlockValueSchema,
38
- EmbedBlockValueSchema,
39
+ RichTextContentTextBlockSchema,
40
+ RichTextContentImageBlockSchema,
41
+ RichTextContentEmbedBlockSchema,
39
42
  ])
40
43
 
41
44
  // Used by content/codec/richText
42
- export type RichTextContentBlock = TextBlockValue | ImageBlockValue | EmbedBlockValue
45
+ export type RichTextContentBlock =
46
+ | RichTextContentTextBlock
47
+ | RichTextContentImageBlock
48
+ | RichTextContentEmbedBlock
43
49
 
44
50
  export const RichTextContentType = "StructuredTextContent" as const
45
51