@prismicio/types-internal 4.0.0 → 4.1.0-canary.51f7473
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 +2 -2
- package/dist/content/field.js.map +1 -1
- package/dist/content/group.d.ts +1 -2
- package/dist/content/group.d.ts.map +1 -1
- package/dist/content/group.js +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 +14 -14
- 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 +32 -20
- package/dist/content/legacy/richText.d.ts.map +1 -1
- package/dist/content/legacy/richText.js +7 -7
- 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 +66 -89
- 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 +3 -3
- package/dist/content/nestable.d.ts.map +1 -1
- package/dist/content/nestable.js +7 -13
- 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 +14 -14
- package/dist/content/richText.d.ts.map +1 -1
- package/dist/content/richText.js +10 -10
- package/dist/content/richText.js.map +1 -1
- package/dist/content/slice.d.ts +507 -5
- package/dist/content/slice.d.ts.map +1 -1
- package/dist/content/slice.js +1 -1
- package/dist/content/slice.js.map +1 -1
- package/dist/content/slices.d.ts +507 -5
- package/dist/content/slices.d.ts.map +1 -1
- package/dist/content/table.d.ts +5 -2
- package/dist/content/table.d.ts.map +1 -1
- package/dist/content/widget.js +1 -1
- package/dist/content/widget.js.map +1 -1
- package/dist/helpers/customTypeModel.d.ts +5 -5
- package/dist/helpers/customTypeModel.d.ts.map +1 -1
- package/dist/helpers/customTypeModel.js +30 -0
- package/dist/helpers/customTypeModel.js.map +1 -1
- package/dist/helpers/imageContent.d.ts +33 -0
- package/dist/helpers/imageContent.d.ts.map +1 -0
- package/dist/helpers/imageContent.js +55 -0
- package/dist/helpers/imageContent.js.map +1 -0
- package/dist/helpers/traverseContent.d.ts +4 -4
- package/dist/helpers/traverseContent.d.ts.map +1 -1
- package/dist/helpers/traverseContent.js +5 -3
- package/dist/helpers/traverseContent.js.map +1 -1
- package/dist/helpers/traverseContentWithModel.d.ts +4 -4
- package/dist/helpers/traverseContentWithModel.js +1 -1
- package/dist/helpers/withDefaultContent.d.ts +21 -0
- package/dist/helpers/withDefaultContent.d.ts.map +1 -0
- package/dist/helpers/withDefaultContent.js +120 -0
- package/dist/helpers/withDefaultContent.js.map +1 -0
- package/dist/index.d.ts +26 -24
- package/dist/index.js +6 -1
- package/dist/io-ts.d.ts +6777 -3127
- package/dist/io-ts.d.ts.map +1 -1
- package/dist/io-ts.js +17 -12
- package/dist/io-ts.js.map +1 -1
- package/dist/model/customType.d.ts +9 -3
- package/dist/model/customType.d.ts.map +1 -1
- package/dist/model/customType.js +7 -4
- package/dist/model/customType.js.map +1 -1
- package/dist/model/group.d.ts +2 -2
- package/dist/model/group.js +1 -1
- package/dist/model/group.js.map +1 -1
- package/dist/model/nestable.js +1 -1
- package/dist/model/nestable.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 +1259 -651
- package/dist/model/slice.d.ts.map +1 -1
- package/dist/model/slice.js +9 -9
- 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 +7 -4
- package/dist/model/widget.js.map +1 -1
- package/dist/zod4.d.ts +3946 -1862
- package/dist/zod4.d.ts.map +1 -1
- package/dist/zod4.js +17 -12
- package/dist/zod4.js.map +1 -1
- package/package.json +22 -12
- package/src/content/boolean.ts +0 -13
- package/src/content/codec/link.ts +12 -12
- package/src/content/field.ts +1 -15
- package/src/content/group.ts +2 -55
- 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 +32 -37
- package/src/content/link.ts +100 -89
- package/src/content/nestable.ts +4 -38
- package/src/content/richText.ts +31 -22
- package/src/content/slice.ts +1 -1
- package/src/content/widget.ts +1 -1
- package/src/helpers/customTypeModel.ts +51 -4
- package/src/helpers/imageContent.ts +84 -0
- package/src/helpers/traverseContent.ts +4 -1
- package/src/helpers/withDefaultContent.ts +180 -0
- package/src/index.ts +25 -7
- package/src/io-ts.ts +22 -10
- package/src/model/customType.ts +18 -7
- package/src/model/diff/sharedSlice.ts +2 -2
- package/src/model/diff/variation.ts +7 -7
- package/src/model/group.ts +1 -1
- package/src/model/nestable.ts +1 -1
- package/src/model/richText.ts +5 -2
- package/src/model/slice.ts +20 -23
- package/src/model/table.ts +5 -5
- package/src/model/widget.ts +14 -14
- package/src/zod4.ts +22 -10
- package/dist/model/section.d.ts +0 -11
- package/dist/model/section.d.ts.map +0 -1
- package/dist/model/section.js +0 -10
- package/dist/model/section.js.map +0 -1
- package/src/content/withDefaultValues.ts +0 -114
- package/src/model/section.ts +0 -12
|
@@ -21,7 +21,7 @@ export const LinkType = {
|
|
|
21
21
|
} as const
|
|
22
22
|
|
|
23
23
|
// Image
|
|
24
|
-
export const
|
|
24
|
+
export const FilledImageLinkLegacyValueSchema = z.object({
|
|
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.object({
|
|
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.object({
|
|
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.object({
|
|
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
|
) =>
|
|
@@ -48,14 +50,7 @@ const getHyperlinkSpanSchema = <
|
|
|
48
50
|
data,
|
|
49
51
|
})
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
type: "label"
|
|
53
|
-
start: number
|
|
54
|
-
end: number
|
|
55
|
-
data: string
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const LabelSpanSchema: z.ZodMiniType<LabelSpan> = z.object({
|
|
53
|
+
const LabelSpanSchema = z.object({
|
|
59
54
|
type: z.literal("label"),
|
|
60
55
|
start: z.number(),
|
|
61
56
|
end: z.number(),
|
|
@@ -64,14 +59,9 @@ const LabelSpanSchema: z.ZodMiniType<LabelSpan> = z.object({
|
|
|
64
59
|
z.transform((value) => (typeof value === "string" && value.length > 0 ? value : "")),
|
|
65
60
|
),
|
|
66
61
|
})
|
|
62
|
+
type LabelSpan = z.infer<typeof LabelSpanSchema>
|
|
67
63
|
|
|
68
|
-
|
|
69
|
-
type: typeof RichTextNodeType.strong | typeof RichTextNodeType.em | "list-item"
|
|
70
|
-
start: number
|
|
71
|
-
end: number
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const BasicSpanSchema: z.ZodMiniType<BasicSpan> = z.object({
|
|
64
|
+
const BasicSpanSchema = z.object({
|
|
75
65
|
type: z.union([
|
|
76
66
|
z.literal(RichTextNodeType.strong),
|
|
77
67
|
z.literal(RichTextNodeType.em),
|
|
@@ -80,18 +70,24 @@ const BasicSpanSchema: z.ZodMiniType<BasicSpan> = z.object({
|
|
|
80
70
|
start: z.number(),
|
|
81
71
|
end: z.number(),
|
|
82
72
|
})
|
|
73
|
+
type BasicSpan = z.infer<typeof BasicSpanSchema>
|
|
83
74
|
|
|
84
|
-
export type Span<TLink extends
|
|
75
|
+
export type Span<TLink extends FilledLinkLegacyValue | FilledLinkContentValue> =
|
|
85
76
|
| HyperlinkSpan<TLink>
|
|
86
77
|
| LabelSpan
|
|
87
78
|
| BasicSpan
|
|
88
79
|
|
|
89
80
|
// oxlint-disable-next-line explicit-module-boundary-types
|
|
90
81
|
export const getSpanSchema = <
|
|
91
|
-
TLinkSchema extends typeof
|
|
82
|
+
TLinkSchema extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,
|
|
92
83
|
>(
|
|
93
84
|
linkSchema: TLinkSchema,
|
|
94
|
-
) =>
|
|
85
|
+
) =>
|
|
86
|
+
z.discriminatedUnion("type", [
|
|
87
|
+
getHyperlinkSpanSchema(linkSchema),
|
|
88
|
+
LabelSpanSchema,
|
|
89
|
+
BasicSpanSchema,
|
|
90
|
+
])
|
|
95
91
|
|
|
96
92
|
// Text blocks
|
|
97
93
|
const TextBlockTypeSchema = z.union([
|
|
@@ -109,7 +105,7 @@ const TextBlockTypeSchema = z.union([
|
|
|
109
105
|
|
|
110
106
|
// oxlint-disable-next-line explicit-module-boundary-types
|
|
111
107
|
export const getTextBlockSchema = <
|
|
112
|
-
TLinkSchema extends typeof
|
|
108
|
+
TLinkSchema extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,
|
|
113
109
|
>(
|
|
114
110
|
linkSchema: TLinkSchema,
|
|
115
111
|
) =>
|
|
@@ -138,7 +134,7 @@ export const getTextBlockSchema = <
|
|
|
138
134
|
direction: z.optional(z.string()),
|
|
139
135
|
})
|
|
140
136
|
|
|
141
|
-
const TextBlockLegacySchema = getTextBlockSchema(
|
|
137
|
+
const TextBlockLegacySchema = getTextBlockSchema(FilledLinkLegacyValueSchema)
|
|
142
138
|
|
|
143
139
|
type TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>
|
|
144
140
|
|
|
@@ -146,8 +142,8 @@ type TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>
|
|
|
146
142
|
|
|
147
143
|
// oxlint-disable-next-line explicit-module-boundary-types
|
|
148
144
|
export const getImageBlockSchema = <
|
|
149
|
-
TData extends typeof
|
|
150
|
-
TLinkTo extends typeof
|
|
145
|
+
TData extends typeof ImageLegacyViewSchema | typeof ImageContentViewSchema,
|
|
146
|
+
TLinkTo extends typeof FilledLinkLegacyValueSchema | typeof FilledLinkContentValueSchema,
|
|
151
147
|
>(
|
|
152
148
|
data: TData,
|
|
153
149
|
linkTo: TLinkTo,
|
|
@@ -160,8 +156,8 @@ export const getImageBlockSchema = <
|
|
|
160
156
|
})
|
|
161
157
|
|
|
162
158
|
const ImageBlockLegacySchema = getImageBlockSchema(
|
|
163
|
-
|
|
164
|
-
|
|
159
|
+
ImageLegacyViewSchema,
|
|
160
|
+
FilledLinkLegacyValueSchema,
|
|
165
161
|
)
|
|
166
162
|
|
|
167
163
|
type ImageBlockLegacy = z.infer<typeof ImageBlockLegacySchema>
|
|
@@ -185,11 +181,10 @@ const EmbedBlockLegacySchema = getEmbedBlockSchema(EmbedLegacyLooseSchema)
|
|
|
185
181
|
type EmbedBlockLegacy = z.infer<typeof EmbedBlockLegacySchema>
|
|
186
182
|
|
|
187
183
|
// Blocks
|
|
188
|
-
export const RichTextLegacyBlockSchema: z.ZodMiniType<RichTextLegacyBlock> = z.
|
|
189
|
-
|
|
190
|
-
ImageBlockLegacySchema,
|
|
191
|
-
|
|
192
|
-
])
|
|
184
|
+
export const RichTextLegacyBlockSchema: z.ZodMiniType<RichTextLegacyBlock> = z.discriminatedUnion(
|
|
185
|
+
"type",
|
|
186
|
+
[TextBlockLegacySchema, ImageBlockLegacySchema, EmbedBlockLegacySchema],
|
|
187
|
+
)
|
|
193
188
|
|
|
194
189
|
export type RichTextLegacyBlock = TextBlockLegacy | ImageBlockLegacy | EmbedBlockLegacy
|
|
195
190
|
|
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"
|
|
@@ -16,17 +15,7 @@ import type {
|
|
|
16
15
|
TextContent,
|
|
17
16
|
TimestampContent,
|
|
18
17
|
} from "./field"
|
|
19
|
-
import {
|
|
20
|
-
ColorContentSchema,
|
|
21
|
-
DateContentSchema,
|
|
22
|
-
FieldContentType,
|
|
23
|
-
NumberContentSchema,
|
|
24
|
-
RangeContentSchema,
|
|
25
|
-
SelectContentDefaultValue,
|
|
26
|
-
SelectContentSchema,
|
|
27
|
-
TextContentSchema,
|
|
28
|
-
TimestampContentSchema,
|
|
29
|
-
} from "./field"
|
|
18
|
+
import { FieldContentType, FieldContentSchema } from "./field"
|
|
30
19
|
import type { GeoPointContent } from "./geopoint"
|
|
31
20
|
import { GeoPointContentSchema, GeoPointContentType } from "./geopoint"
|
|
32
21
|
import type { ImageContent } from "./image"
|
|
@@ -44,25 +33,19 @@ import { SeparatorContentSchema, SeparatorContentType } from "./separator"
|
|
|
44
33
|
import type { TableContent } from "./table"
|
|
45
34
|
import { TableContentSchema, TableContentType } from "./table"
|
|
46
35
|
|
|
47
|
-
export const NestableContentSchema
|
|
36
|
+
export const NestableContentSchema = z.discriminatedUnion("__TYPE__", [
|
|
48
37
|
EmptyContentSchema,
|
|
49
38
|
BooleanContentSchema,
|
|
50
|
-
ColorContentSchema,
|
|
51
|
-
DateContentSchema,
|
|
52
39
|
EmbedContentSchema,
|
|
53
40
|
GeoPointContentSchema,
|
|
54
41
|
ImageContentSchema,
|
|
55
42
|
IntegrationFieldContentSchema,
|
|
56
43
|
LinkContentSchema,
|
|
57
|
-
NumberContentSchema,
|
|
58
|
-
RangeContentSchema,
|
|
59
44
|
RepeatableContentSchema,
|
|
60
45
|
RichTextContentSchema,
|
|
61
|
-
SelectContentSchema,
|
|
62
46
|
SeparatorContentSchema,
|
|
63
47
|
TableContentSchema,
|
|
64
|
-
|
|
65
|
-
TimestampContentSchema,
|
|
48
|
+
FieldContentSchema,
|
|
66
49
|
])
|
|
67
50
|
|
|
68
51
|
export type NestableContent =
|
|
@@ -107,20 +90,3 @@ export function isNestableContent(content: {
|
|
|
107
90
|
}): content is { __TYPE__: NestableContentType } {
|
|
108
91
|
return (NestableContentTypes as string[]).includes(content.__TYPE__)
|
|
109
92
|
}
|
|
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
|
-
}
|