@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
|
@@ -21,7 +21,7 @@ export const LinkType = {
|
|
|
21
21
|
} as const
|
|
22
22
|
|
|
23
23
|
// Image
|
|
24
|
-
export const
|
|
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
|
|
39
|
+
export const EmptyImageLinkLegacyValueSchema = z.strictObject({
|
|
40
40
|
kind: z.literal(LinkKind.Image),
|
|
41
41
|
})
|
|
42
42
|
|
|
43
43
|
// File
|
|
44
|
-
export const
|
|
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
|
|
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
|
|
65
|
+
export const EmptyMediaLinkLegacyValueSchema = z.strictObject({
|
|
66
66
|
kind: z.literal(LinkKind.Media),
|
|
67
67
|
})
|
|
68
68
|
|
|
69
69
|
// Document
|
|
70
|
-
export const
|
|
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
|
|
80
|
+
export const EmptyDocumentLinkLegacyValueSchema = z.strictObject({
|
|
81
81
|
kind: z.literal(LinkKind.Document),
|
|
82
82
|
})
|
|
83
83
|
|
|
84
84
|
// External
|
|
85
|
-
export const
|
|
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
|
|
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
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
export const FilledLinkLegacyValueSchema: z.ZodMiniType<FilledLinkLegacyValue> = z.union([
|
|
113
|
+
FilledImageLinkLegacyValueSchema,
|
|
114
|
+
FilledFileLinkLegacyValueSchema,
|
|
115
|
+
FilledDocumentLinkLegacyValueSchema,
|
|
116
|
+
FilledExternalLinkLegacyValueSchema,
|
|
117
117
|
])
|
|
118
118
|
|
|
119
|
-
type
|
|
120
|
-
type
|
|
121
|
-
type
|
|
122
|
-
type
|
|
123
|
-
export type
|
|
124
|
-
|
|
|
125
|
-
|
|
|
126
|
-
|
|
|
127
|
-
|
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
|
139
|
-
type
|
|
140
|
-
type
|
|
141
|
-
type
|
|
142
|
-
type
|
|
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
|
|
145
|
-
|
|
|
146
|
-
|
|
|
147
|
-
|
|
|
148
|
-
|
|
|
149
|
-
|
|
|
144
|
+
export type EmptyLinkLegacyValue =
|
|
145
|
+
| EmptyImageLinkLegacyValue
|
|
146
|
+
| EmptyFileLinkLegacyValue
|
|
147
|
+
| EmptyMediaLinkLegacyValue
|
|
148
|
+
| EmptyDocumentLinkLegacyValue
|
|
149
|
+
| EmptyExternalLinkLegacyValue
|
|
150
150
|
| AnyLinkLegacy
|
|
151
151
|
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
const LinkLegacyValueSchema: z.ZodMiniType<LinkLegacyValue> = z.union([
|
|
153
|
+
FilledLinkLegacyValueSchema,
|
|
154
|
+
EmptyLinkLegacyValueSchema,
|
|
155
155
|
])
|
|
156
156
|
|
|
157
|
-
export type
|
|
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:
|
|
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 {
|
|
7
|
-
import type {
|
|
6
|
+
import type { ImageContentViewSchema } from "../image"
|
|
7
|
+
import type { FilledLinkContentValue, FilledLinkContentValueSchema } from "../link"
|
|
8
8
|
import { EmbedLegacyLooseSchema } from "./embed"
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import type {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
150
|
-
TLinkTo extends typeof
|
|
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
|
-
|
|
164
|
-
|
|
165
|
+
ImageLegacyViewSchema,
|
|
166
|
+
FilledLinkLegacyValueSchema,
|
|
165
167
|
)
|
|
166
168
|
|
|
167
169
|
type ImageBlockLegacy = z.infer<typeof ImageBlockLegacySchema>
|
package/src/content/link.ts
CHANGED
|
@@ -1,154 +1,165 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
EmptyDocumentLinkLegacyValueSchema,
|
|
5
|
+
EmptyImageLinkLegacyValueSchema,
|
|
6
|
+
FilledDocumentLinkLegacyValueSchema,
|
|
7
|
+
FilledFileLinkLegacyValueSchema,
|
|
8
|
+
FilledImageLinkLegacyValueSchema,
|
|
9
|
+
EmptyMediaLinkLegacyValueSchema,
|
|
10
|
+
FilledExternalLinkLegacyValueSchema,
|
|
11
|
+
EmptyExternalLinkLegacyValueSchema,
|
|
12
12
|
AnyLinkLegacySchema,
|
|
13
13
|
LinkType,
|
|
14
|
-
|
|
14
|
+
EmptyFileLinkLegacyValueSchema,
|
|
15
15
|
} from "./legacy/link"
|
|
16
16
|
|
|
17
17
|
// Image
|
|
18
|
-
const
|
|
18
|
+
const FilledImageLinkContentValueSchema = z.extend(FilledImageLinkLegacyValueSchema, {
|
|
19
19
|
__TYPE__: z.literal(LinkType.Image),
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const EmptyImageLinkContentValueSchema = z.extend(EmptyImageLinkLegacyValueSchema, {
|
|
23
23
|
__TYPE__: z.literal(LinkType.Image),
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
// File
|
|
27
|
-
const
|
|
27
|
+
const FilledFileLinkContentValueSchema = z.extend(FilledFileLinkLegacyValueSchema, {
|
|
28
28
|
__TYPE__: z.literal(LinkType.File),
|
|
29
29
|
})
|
|
30
30
|
|
|
31
|
-
const
|
|
31
|
+
const EmptyFileLinkContentValueSchema = z.extend(EmptyFileLinkLegacyValueSchema, {
|
|
32
32
|
__TYPE__: z.literal(LinkType.File),
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
// Media
|
|
36
|
-
const
|
|
36
|
+
const EmptyMediaLinkContentValueSchema = z.extend(EmptyMediaLinkLegacyValueSchema, {
|
|
37
37
|
__TYPE__: z.literal(LinkType.Media),
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
// Document
|
|
41
|
-
const
|
|
41
|
+
const FilledDocumentLinkContentValueSchema = z.extend(FilledDocumentLinkLegacyValueSchema, {
|
|
42
42
|
__TYPE__: z.literal(LinkType.Document),
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const EmptyDocumentLinkContentValueSchema = z.extend(EmptyDocumentLinkLegacyValueSchema, {
|
|
46
46
|
__TYPE__: z.literal(LinkType.Document),
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
// External
|
|
50
|
-
const
|
|
50
|
+
const FilledExternalLinkContentValueSchema = z.extend(FilledExternalLinkLegacyValueSchema, {
|
|
51
51
|
__TYPE__: z.literal(LinkType.External),
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
const
|
|
54
|
+
const EmptyExternalLinkContentValueSchema = z.extend(EmptyExternalLinkLegacyValueSchema, {
|
|
55
55
|
__TYPE__: z.literal(LinkType.External),
|
|
56
56
|
})
|
|
57
57
|
|
|
58
58
|
// Any
|
|
59
|
-
const
|
|
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
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
|
75
|
-
type
|
|
76
|
-
type
|
|
77
|
-
type
|
|
78
|
-
export type
|
|
79
|
-
|
|
|
80
|
-
|
|
|
81
|
-
|
|
|
82
|
-
|
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
|
95
|
-
type
|
|
96
|
-
type
|
|
97
|
-
type
|
|
98
|
-
type
|
|
99
|
-
type
|
|
100
|
-
export type
|
|
101
|
-
|
|
|
102
|
-
|
|
|
103
|
-
|
|
|
104
|
-
|
|
|
105
|
-
|
|
|
106
|
-
|
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
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
|
|
114
|
+
export type LinkContentValue = FilledLinkContentValue | EmptyLinkContentValue
|
|
115
115
|
|
|
116
116
|
// Content
|
|
117
117
|
export const LinkContentType = "LinkContent" as const
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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.
|
|
128
|
-
|
|
129
|
-
(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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.
|
|
141
|
-
text:
|
|
142
|
-
variant:
|
|
143
|
-
value
|
|
144
|
-
}),
|
|
147
|
+
z.transform(({ text, variant, value }) => ({
|
|
148
|
+
...(text ? { text } : {}),
|
|
149
|
+
...(variant ? { variant } : {}),
|
|
150
|
+
...value,
|
|
151
|
+
})),
|
|
145
152
|
),
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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>
|
package/src/content/nestable.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
}
|
package/src/content/richText.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
2
|
|
|
3
3
|
import { EmbedContentSchema } from "./embed"
|
|
4
|
-
import {
|
|
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 {
|
|
13
|
-
import {
|
|
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<
|
|
19
|
+
export type RichTextContentSpan = Span<FilledLinkContentValue>
|
|
17
20
|
|
|
18
21
|
export const RichTextContentSpanSchema: z.ZodMiniType<RichTextContentSpan> = getSpanSchema(
|
|
19
|
-
|
|
22
|
+
FilledLinkContentValueSchema,
|
|
20
23
|
)
|
|
21
24
|
|
|
22
25
|
// Blocks
|
|
23
|
-
const
|
|
24
|
-
type
|
|
26
|
+
const RichTextContentTextBlockSchema = getTextBlockSchema(FilledLinkContentValueSchema)
|
|
27
|
+
export type RichTextContentTextBlock = z.infer<typeof RichTextContentTextBlockSchema>
|
|
25
28
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
const RichTextContentImageBlockSchema = getImageBlockSchema(
|
|
30
|
+
ImageContentViewSchema,
|
|
31
|
+
FilledLinkContentValueSchema,
|
|
29
32
|
)
|
|
30
|
-
type
|
|
33
|
+
export type RichTextContentImageBlock = z.infer<typeof RichTextContentImageBlockSchema>
|
|
31
34
|
|
|
32
|
-
const
|
|
33
|
-
type
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
RichTextContentTextBlockSchema,
|
|
40
|
+
RichTextContentImageBlockSchema,
|
|
41
|
+
RichTextContentEmbedBlockSchema,
|
|
39
42
|
])
|
|
40
43
|
|
|
41
44
|
// Used by content/codec/richText
|
|
42
|
-
export type RichTextContentBlock =
|
|
45
|
+
export type RichTextContentBlock =
|
|
46
|
+
| RichTextContentTextBlock
|
|
47
|
+
| RichTextContentImageBlock
|
|
48
|
+
| RichTextContentEmbedBlock
|
|
43
49
|
|
|
44
50
|
export const RichTextContentType = "StructuredTextContent" as const
|
|
45
51
|
|