@prismicio/types-internal 4.0.0-pr.6.bf36d5e → 4.0.0-pr.6.cba77ba
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/dist/content/codec/richText.js +2 -2
- package/dist/content/codec/richText.js.map +1 -1
- package/dist/content/document.d.ts +2 -3019
- package/dist/content/document.d.ts.map +1 -1
- package/dist/content/field.d.ts +1 -30
- package/dist/content/field.d.ts.map +1 -1
- package/dist/content/field.js.map +1 -1
- package/dist/content/group.d.ts +2 -1
- package/dist/content/group.d.ts.map +1 -1
- package/dist/content/group.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/geopoint.d.ts +1 -0
- package/dist/content/legacy/group.d.ts +9 -0
- package/dist/content/legacy/group.d.ts.map +1 -0
- package/dist/content/legacy/group.js.map +1 -1
- package/dist/content/legacy/integrationField.d.ts +1 -0
- package/dist/content/legacy/link.d.ts +41 -0
- package/dist/content/legacy/link.d.ts.map +1 -0
- package/dist/content/legacy/link.js.map +1 -1
- package/dist/content/legacy/nestable.d.ts +1 -0
- package/dist/content/legacy/nestable.js.map +1 -1
- package/dist/content/legacy/repeatable.d.ts +1 -0
- package/dist/content/legacy/richText.d.ts +109 -0
- package/dist/content/legacy/richText.d.ts.map +1 -0
- package/dist/content/legacy/richText.js +3 -3
- package/dist/content/legacy/richText.js.map +1 -1
- package/dist/content/legacy/separator.d.ts +1 -0
- package/dist/content/legacy/slice.js.map +1 -1
- package/dist/content/legacy/table.d.ts +1 -0
- package/dist/content/link.d.ts +74 -99
- package/dist/content/link.d.ts.map +1 -1
- package/dist/content/link.js +2 -2
- package/dist/content/link.js.map +1 -1
- package/dist/content/nestable.d.ts +13 -749
- package/dist/content/nestable.d.ts.map +1 -1
- package/dist/content/nestable.js.map +1 -1
- package/dist/content/repeatable.d.ts +3 -98
- package/dist/content/repeatable.d.ts.map +1 -1
- package/dist/content/richText.d.ts +81 -131
- package/dist/content/richText.d.ts.map +1 -1
- package/dist/content/richText.js +5 -4
- package/dist/content/richText.js.map +1 -1
- package/dist/content/slice.d.ts +6 -4509
- package/dist/content/slice.d.ts.map +1 -1
- package/dist/content/slice.js.map +1 -1
- package/dist/content/slices.d.ts +8 -6765
- package/dist/content/slices.d.ts.map +1 -1
- package/dist/content/table.d.ts +2 -134
- package/dist/content/table.d.ts.map +1 -1
- package/dist/content/widget.d.ts +5 -3020
- package/dist/content/widget.d.ts.map +1 -1
- package/dist/content/widget.js.map +1 -1
- package/dist/helpers/customTypeModel.d.ts +1 -1
- package/dist/helpers/documentContent.d.ts +3 -9
- package/dist/helpers/documentContent.d.ts.map +1 -1
- package/dist/helpers/documentContent.js +3 -3
- package/dist/helpers/documentContent.js.map +1 -1
- package/dist/helpers/traverseContent.d.ts +10 -11
- package/dist/helpers/traverseContent.d.ts.map +1 -1
- package/dist/helpers/traverseContent.js.map +1 -1
- package/dist/helpers/traverseContentWithModel.d.ts +10 -11
- package/dist/helpers/traverseContentWithModel.d.ts.map +1 -1
- package/dist/helpers/traverseContentWithModel.js.map +1 -1
- package/dist/index.d.ts +25 -25
- package/dist/io-ts.d.ts +3380 -70926
- package/dist/io-ts.d.ts.map +1 -1
- package/dist/io-ts.js +125 -122
- package/dist/io-ts.js.map +1 -1
- package/dist/model/customType.d.ts +3 -3329
- package/dist/model/customType.d.ts.map +1 -1
- package/dist/model/group.d.ts +391 -392
- package/dist/model/group.d.ts.map +1 -1
- package/dist/model/group.js.map +1 -1
- package/dist/model/image.d.ts +4 -4
- package/dist/model/image.js.map +1 -1
- package/dist/model/link.d.ts +18 -18
- package/dist/model/link.d.ts.map +1 -1
- package/dist/model/link.js +7 -7
- package/dist/model/link.js.map +1 -1
- package/dist/model/nestable.d.ts +17 -178
- package/dist/model/nestable.d.ts.map +1 -1
- package/dist/model/nestable.js.map +1 -1
- package/dist/model/richText.d.ts +3 -7
- package/dist/model/richText.d.ts.map +1 -1
- package/dist/model/richText.js.map +1 -1
- package/dist/model/section.d.ts +3 -3329
- package/dist/model/section.d.ts.map +1 -1
- package/dist/model/select.d.ts +1 -1
- package/dist/model/select.js +1 -1
- package/dist/model/select.js.map +1 -1
- package/dist/model/slice.d.ts +861 -3800
- package/dist/model/slice.d.ts.map +1 -1
- package/dist/model/slice.js +7 -2
- package/dist/model/slice.js.map +1 -1
- package/dist/model/slices.d.ts +3 -2195
- package/dist/model/slices.d.ts.map +1 -1
- package/dist/model/widget.d.ts +6 -3331
- package/dist/model/widget.d.ts.map +1 -1
- package/dist/model/widget.js.map +1 -1
- package/dist/zod4.d.ts +1345 -34797
- package/dist/zod4.d.ts.map +1 -1
- package/dist/zod4.js +125 -122
- package/dist/zod4.js.map +1 -1
- package/package.json +3 -2
- package/src/content/codec/richText.ts +10 -6
- package/src/content/field.ts +2 -2
- package/src/content/group.ts +2 -2
- package/src/content/legacy/group.ts +6 -4
- package/src/content/legacy/link.ts +20 -7
- package/src/content/legacy/nestable.ts +13 -2
- package/src/content/legacy/richText.ts +38 -7
- package/src/content/legacy/slice.ts +2 -2
- package/src/content/legacy/widget.ts +10 -2
- package/src/content/link.ts +17 -7
- package/src/content/nestable.ts +39 -2
- package/src/content/richText.ts +33 -9
- package/src/content/slice.ts +2 -2
- package/src/content/widget.ts +6 -2
- package/src/helpers/documentContent.ts +12 -15
- package/src/helpers/traverseContent.ts +12 -19
- package/src/helpers/traverseContentWithModel.ts +10 -16
- package/src/index.ts +3 -2
- package/src/io-ts.ts +148 -140
- package/src/model/group.ts +2 -1
- package/src/model/image.ts +1 -1
- package/src/model/link.ts +39 -45
- package/src/model/nestable.ts +33 -1
- package/src/model/richText.ts +2 -2
- package/src/model/select.ts +2 -2
- package/src/model/slice.ts +21 -9
- package/src/model/widget.ts +8 -4
- package/src/zod4.ts +148 -140
|
@@ -109,16 +109,20 @@ export const AnyLinkLegacySchema = z.strictObject({
|
|
|
109
109
|
|
|
110
110
|
// All
|
|
111
111
|
|
|
112
|
-
export const FilledLinkValueLegacySchema = z.union([
|
|
112
|
+
export const FilledLinkValueLegacySchema: z.ZodMiniType<FilledLinkValueLegacy> = z.union([
|
|
113
113
|
FilledImageLinkValueLegacySchema,
|
|
114
114
|
FilledFileLinkValueLegacySchema,
|
|
115
115
|
FilledDocumentLinkValueLegacySchema,
|
|
116
116
|
FilledExternalLinkValueLegacySchema,
|
|
117
117
|
])
|
|
118
118
|
|
|
119
|
-
|
|
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 = FilledImageLinkValueLegacy | FilledFileLinkValueLegacy | FilledDocumentLinkValueLegacy | FilledExternalLinkValueLegacy
|
|
120
124
|
|
|
121
|
-
const EmptyLinkValueLegacySchema = z.union([
|
|
125
|
+
const EmptyLinkValueLegacySchema: z.ZodMiniType<EmptyLinkValueLegacy> = z.union([
|
|
122
126
|
EmptyImageLinkValueLegacySchema,
|
|
123
127
|
EmptyFileLinkValueLegacySchema,
|
|
124
128
|
EmptyMediaLinkValueLegacySchema,
|
|
@@ -127,11 +131,20 @@ const EmptyLinkValueLegacySchema = z.union([
|
|
|
127
131
|
AnyLinkLegacySchema,
|
|
128
132
|
])
|
|
129
133
|
|
|
130
|
-
|
|
134
|
+
type EmptyImageLinkValueLegacy = z.infer<typeof EmptyImageLinkValueLegacySchema>
|
|
135
|
+
type EmptyFileLinkValueLegacy = z.infer<typeof EmptyFileLinkValueLegacySchema>
|
|
136
|
+
type EmptyMediaLinkValueLegacy = z.infer<typeof EmptyMediaLinkValueLegacySchema>
|
|
137
|
+
type EmptyDocumentLinkValueLegacy = z.infer<typeof EmptyDocumentLinkValueLegacySchema>
|
|
138
|
+
type EmptyExternalLinkValueLegacy = z.infer<typeof EmptyExternalLinkValueLegacySchema>
|
|
139
|
+
type AnyLinkLegacy = z.infer<typeof AnyLinkLegacySchema>
|
|
140
|
+
export type EmptyLinkValueLegacy = EmptyImageLinkValueLegacy | EmptyFileLinkValueLegacy | EmptyMediaLinkValueLegacy | EmptyDocumentLinkValueLegacy | EmptyExternalLinkValueLegacy | AnyLinkLegacy
|
|
131
141
|
|
|
132
|
-
const LinkValueLegacySchema
|
|
142
|
+
const LinkValueLegacySchema: z.ZodMiniType<LinkValueLegacy> =
|
|
143
|
+
z.union([FilledLinkValueLegacySchema, EmptyLinkValueLegacySchema])
|
|
133
144
|
|
|
134
|
-
export type LinkValueLegacy =
|
|
145
|
+
export type LinkValueLegacy =
|
|
146
|
+
| FilledLinkValueLegacy
|
|
147
|
+
| EmptyLinkValueLegacy
|
|
135
148
|
|
|
136
149
|
// We cannot use z.extend here because we're working with unions.
|
|
137
150
|
// z.intersection wouldn't work also for the same reason.
|
|
@@ -157,7 +170,7 @@ export const LinkLegacySchema = z.pipe(
|
|
|
157
170
|
key: z.optional(z.string()),
|
|
158
171
|
text: z.optional(z.string()),
|
|
159
172
|
variant: z.optional(z.string()),
|
|
160
|
-
value: LinkValueLegacySchema,
|
|
173
|
+
value: LinkValueLegacySchema as z.ZodMiniType<LinkValueLegacy, Record<string, unknown>>,
|
|
161
174
|
}),
|
|
162
175
|
),
|
|
163
176
|
z.transform(({ key, text, variant, value }) => ({
|
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
2
|
|
|
3
|
+
import type { BooleanLegacy} from "./boolean";
|
|
3
4
|
import { BooleanLegacySchema } from "./boolean"
|
|
5
|
+
import type { EmbedLegacy} from "./embed";
|
|
4
6
|
import { EmbedLegacyLooseSchema } from "./embed"
|
|
7
|
+
import type { EmptyLegacy} from "./empty";
|
|
5
8
|
import { EmptyLegacySchema } from "./empty"
|
|
6
9
|
import { StringLegacySchema } from "./field"
|
|
10
|
+
import type { GeoPointLegacy} from "./geopoint";
|
|
7
11
|
import { GeoPointLegacySchema } from "./geopoint"
|
|
12
|
+
import type { ImageLegacy} from "./image";
|
|
8
13
|
import { ImageLegacySchema } from "./image"
|
|
14
|
+
import type { IntegrationFieldLegacy} from "./integrationField";
|
|
9
15
|
import { IntegrationFieldLegacySchema } from "./integrationField"
|
|
16
|
+
import type { LinkLegacy} from "./link";
|
|
10
17
|
import { LinkLegacySchema } from "./link"
|
|
18
|
+
import type { RepeatableLegacy} from "./repeatable";
|
|
11
19
|
import { RepeatableLegacySchema } from "./repeatable"
|
|
20
|
+
import type { RichTextLegacy} from "./richText";
|
|
12
21
|
import { RichTextLegacySchema } from "./richText"
|
|
22
|
+
import type { SeparatorLegacy} from "./separator";
|
|
13
23
|
import { SeparatorLegacySchema } from "./separator"
|
|
24
|
+
import type { TableLegacy} from "./table";
|
|
14
25
|
import { TableLegacySchema } from "./table"
|
|
15
26
|
|
|
16
|
-
export const NestableLegacySchema = z.union([
|
|
27
|
+
export const NestableLegacySchema: z.ZodMiniType<NestableLegacy> = z.union([
|
|
17
28
|
EmptyLegacySchema,
|
|
18
29
|
BooleanLegacySchema,
|
|
19
30
|
EmbedLegacyLooseSchema,
|
|
@@ -28,4 +39,4 @@ export const NestableLegacySchema = z.union([
|
|
|
28
39
|
TableLegacySchema,
|
|
29
40
|
])
|
|
30
41
|
|
|
31
|
-
export type NestableLegacy =
|
|
42
|
+
export type NestableLegacy = EmptyLegacy | BooleanLegacy | EmbedLegacy | GeoPointLegacy | ImageLegacy | IntegrationFieldLegacy | LinkLegacy | RepeatableLegacy | RichTextLegacy | SeparatorLegacy | TableLegacy
|
|
@@ -4,10 +4,11 @@ import { z } from "zod/mini"
|
|
|
4
4
|
// avoid runtime circular dependencies!
|
|
5
5
|
import type { EmbedContentSchema } from "../embed"
|
|
6
6
|
import type { ImageViewContentSchema } from "../image"
|
|
7
|
-
import type { FilledLinkValueContentSchema } from "../link"
|
|
7
|
+
import type { FilledLinkValueContent, FilledLinkValueContentSchema } from "../link"
|
|
8
8
|
import { EmbedLegacyLooseSchema } from "./embed"
|
|
9
9
|
import { ImageViewLegacySchema } from "./image"
|
|
10
10
|
import { FilledLinkValueLegacySchema } from "./link"
|
|
11
|
+
import type { FilledLinkValueLegacy } from "./link"
|
|
11
12
|
|
|
12
13
|
export const RichTextNodeType = {
|
|
13
14
|
paragraph: "paragraph",
|
|
@@ -28,6 +29,13 @@ export const RichTextNodeType = {
|
|
|
28
29
|
} as const
|
|
29
30
|
|
|
30
31
|
// Spans
|
|
32
|
+
type HyperlinkSpan<TData extends FilledLinkValueLegacy | FilledLinkValueContent> = {
|
|
33
|
+
type: typeof RichTextNodeType.hyperlink
|
|
34
|
+
start: number
|
|
35
|
+
end: number
|
|
36
|
+
data: TData
|
|
37
|
+
}
|
|
38
|
+
|
|
31
39
|
const getHyperlinkSpanSchema = <
|
|
32
40
|
TData extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
|
|
33
41
|
>(
|
|
@@ -40,7 +48,14 @@ const getHyperlinkSpanSchema = <
|
|
|
40
48
|
data,
|
|
41
49
|
})
|
|
42
50
|
|
|
43
|
-
|
|
51
|
+
type LabelSpan = {
|
|
52
|
+
type: "label"
|
|
53
|
+
start: number
|
|
54
|
+
end: number
|
|
55
|
+
data: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const LabelSpanSchema: z.ZodMiniType<LabelSpan> = z.object({
|
|
44
59
|
type: z.literal("label"),
|
|
45
60
|
start: z.number(),
|
|
46
61
|
end: z.number(),
|
|
@@ -50,7 +65,13 @@ const LabelSpanSchema = z.object({
|
|
|
50
65
|
),
|
|
51
66
|
})
|
|
52
67
|
|
|
53
|
-
|
|
68
|
+
type BasicSpan = {
|
|
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({
|
|
54
75
|
type: z.union([
|
|
55
76
|
z.literal(RichTextNodeType.strong),
|
|
56
77
|
z.literal(RichTextNodeType.em),
|
|
@@ -60,7 +81,11 @@ const BasicSpanSchema = z.object({
|
|
|
60
81
|
end: z.number(),
|
|
61
82
|
})
|
|
62
83
|
|
|
63
|
-
|
|
84
|
+
export type Span<TLink extends FilledLinkValueLegacy | FilledLinkValueContent> =
|
|
85
|
+
HyperlinkSpan<TLink> | LabelSpan | BasicSpan
|
|
86
|
+
|
|
87
|
+
// oxlint-disable-next-line explicit-module-boundary-types
|
|
88
|
+
export const getSpanSchema = <
|
|
64
89
|
TLinkSchema extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
|
|
65
90
|
>(
|
|
66
91
|
linkSchema: TLinkSchema,
|
|
@@ -113,6 +138,8 @@ export const getTextBlockSchema = <
|
|
|
113
138
|
|
|
114
139
|
const TextBlockLegacySchema = getTextBlockSchema(FilledLinkValueLegacySchema)
|
|
115
140
|
|
|
141
|
+
type TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>
|
|
142
|
+
|
|
116
143
|
// Image block
|
|
117
144
|
|
|
118
145
|
// oxlint-disable-next-line explicit-module-boundary-types
|
|
@@ -135,6 +162,8 @@ const ImageBlockLegacySchema = getImageBlockSchema(
|
|
|
135
162
|
FilledLinkValueLegacySchema,
|
|
136
163
|
)
|
|
137
164
|
|
|
165
|
+
type ImageBlockLegacy = z.infer<typeof ImageBlockLegacySchema>
|
|
166
|
+
|
|
138
167
|
// Embed block
|
|
139
168
|
// oxlint-disable-next-line explicit-module-boundary-types
|
|
140
169
|
export const getEmbedBlockSchema = <
|
|
@@ -151,15 +180,17 @@ export const getEmbedBlockSchema = <
|
|
|
151
180
|
|
|
152
181
|
const EmbedBlockLegacySchema = getEmbedBlockSchema(EmbedLegacyLooseSchema)
|
|
153
182
|
|
|
183
|
+
type EmbedBlockLegacy = z.infer<typeof EmbedBlockLegacySchema>
|
|
184
|
+
|
|
154
185
|
// Blocks
|
|
155
|
-
export const
|
|
186
|
+
export const RichTextLegacyBlockSchema: z.ZodMiniType<RichTextLegacyBlock> = z.union([
|
|
156
187
|
TextBlockLegacySchema,
|
|
157
188
|
ImageBlockLegacySchema,
|
|
158
189
|
EmbedBlockLegacySchema,
|
|
159
190
|
])
|
|
160
191
|
|
|
161
|
-
export type
|
|
192
|
+
export type RichTextLegacyBlock = TextBlockLegacy | ImageBlockLegacy | EmbedBlockLegacy
|
|
162
193
|
|
|
163
|
-
export const RichTextLegacySchema = z.array(
|
|
194
|
+
export const RichTextLegacySchema = z.array(RichTextLegacyBlockSchema)
|
|
164
195
|
|
|
165
196
|
export type RichTextLegacy = z.infer<typeof RichTextLegacySchema>
|
|
@@ -28,10 +28,10 @@ export const SharedSliceLegacySchema = z.object({
|
|
|
28
28
|
export type SharedSliceLegacy = z.infer<typeof SharedSliceLegacySchema>
|
|
29
29
|
|
|
30
30
|
// All
|
|
31
|
-
export const SliceLegacySchema = z.union([
|
|
31
|
+
export const SliceLegacySchema: z.ZodMiniType<SliceLegacy> = z.union([
|
|
32
32
|
LegacySliceLegacySchema,
|
|
33
33
|
CompositeSliceLegacySchema,
|
|
34
34
|
SharedSliceLegacySchema,
|
|
35
35
|
])
|
|
36
36
|
|
|
37
|
-
export type SliceLegacy =
|
|
37
|
+
export type SliceLegacy = LegacySliceLegacy | CompositeSliceLegacy | SharedSliceLegacy
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
2
|
|
|
3
|
+
import type { GroupLegacy} from "./group";
|
|
3
4
|
import { GroupLegacySchema } from "./group"
|
|
5
|
+
import type { NestableLegacy} from "./nestable";
|
|
4
6
|
import { NestableLegacySchema } from "./nestable"
|
|
7
|
+
import type { SlicesLegacy} from "./slices";
|
|
5
8
|
import { SlicesLegacySchema } from "./slices"
|
|
9
|
+
import type { UIDLegacy} from "./uid";
|
|
6
10
|
import { UIDLegacySchema } from "./uid"
|
|
7
11
|
|
|
8
|
-
export const WidgetLegacySchema = z.union([
|
|
12
|
+
export const WidgetLegacySchema: z.ZodMiniType<WidgetLegacy> = z.union([
|
|
9
13
|
UIDLegacySchema,
|
|
10
14
|
GroupLegacySchema,
|
|
11
15
|
SlicesLegacySchema,
|
|
12
16
|
NestableLegacySchema,
|
|
13
17
|
])
|
|
14
18
|
|
|
15
|
-
export type WidgetLegacy =
|
|
19
|
+
export type WidgetLegacy =
|
|
20
|
+
| UIDLegacy
|
|
21
|
+
| GroupLegacy
|
|
22
|
+
| SlicesLegacy
|
|
23
|
+
| NestableLegacy
|
package/src/content/link.ts
CHANGED
|
@@ -63,7 +63,7 @@ const AnyLinkValueContentSchema = z.extend(AnyLinkLegacySchema, {
|
|
|
63
63
|
// All
|
|
64
64
|
|
|
65
65
|
// Used by content/richText
|
|
66
|
-
export const FilledLinkValueContentSchema = z.union([
|
|
66
|
+
export const FilledLinkValueContentSchema: z.ZodMiniType<FilledLinkValueContent> = z.union([
|
|
67
67
|
FilledImageLinkValueContentSchema,
|
|
68
68
|
FilledFileLinkValueContentSchema,
|
|
69
69
|
FilledDocumentLinkValueContentSchema,
|
|
@@ -71,9 +71,13 @@ export const FilledLinkValueContentSchema = z.union([
|
|
|
71
71
|
])
|
|
72
72
|
|
|
73
73
|
// Used by content/legacy/link
|
|
74
|
-
|
|
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 = FilledImageLinkValueContent | FilledFileLinkValueContent | FilledDocumentLinkValueContent | FilledExternalLinkValueContent
|
|
75
79
|
|
|
76
|
-
const EmptyLinkValueContentSchema = z.union([
|
|
80
|
+
const EmptyLinkValueContentSchema: z.ZodMiniType<EmptyLinkValueContent> = z.union([
|
|
77
81
|
EmptyImageLinkValueContentSchema,
|
|
78
82
|
EmptyFileLinkValueContentSchema,
|
|
79
83
|
EmptyMediaLinkValueContentSchema,
|
|
@@ -83,12 +87,18 @@ const EmptyLinkValueContentSchema = z.union([
|
|
|
83
87
|
])
|
|
84
88
|
|
|
85
89
|
// Used by content/codec/link
|
|
86
|
-
|
|
90
|
+
type EmptyImageLinkValueContent = z.infer<typeof EmptyImageLinkValueContentSchema>
|
|
91
|
+
type EmptyFileLinkValueContent = z.infer<typeof EmptyFileLinkValueContentSchema>
|
|
92
|
+
type EmptyMediaLinkValueContent = z.infer<typeof EmptyMediaLinkValueContentSchema>
|
|
93
|
+
type EmptyDocumentLinkValueContent = z.infer<typeof EmptyDocumentLinkValueContentSchema>
|
|
94
|
+
type EmptyExternalLinkValueContent = z.infer<typeof EmptyExternalLinkValueContentSchema>
|
|
95
|
+
type AnyLinkValueContent = z.infer<typeof AnyLinkValueContentSchema>
|
|
96
|
+
export type EmptyLinkValueContent = EmptyImageLinkValueContent | EmptyFileLinkValueContent | EmptyMediaLinkValueContent | EmptyDocumentLinkValueContent | EmptyExternalLinkValueContent | AnyLinkValueContent
|
|
87
97
|
|
|
88
|
-
const LinkValueContentSchema = z.union([FilledLinkValueContentSchema, EmptyLinkValueContentSchema])
|
|
98
|
+
const LinkValueContentSchema: z.ZodMiniType<LinkValueContent> = z.union([FilledLinkValueContentSchema, EmptyLinkValueContentSchema])
|
|
89
99
|
|
|
90
100
|
// Used by content/codec/link
|
|
91
|
-
export type LinkValueContent =
|
|
101
|
+
export type LinkValueContent = FilledLinkValueContent | EmptyLinkValueContent
|
|
92
102
|
|
|
93
103
|
// Content
|
|
94
104
|
export const LinkContentType = "LinkContent" as const
|
|
@@ -117,7 +127,7 @@ export const LinkContentSchema = z.object({
|
|
|
117
127
|
z.object({
|
|
118
128
|
text: z.optional(z.string()),
|
|
119
129
|
variant: z.optional(z.string()),
|
|
120
|
-
value: z.
|
|
130
|
+
value: LinkValueContentSchema as z.ZodMiniType<LinkValueContent, Record<string, unknown>>,
|
|
121
131
|
}),
|
|
122
132
|
),
|
|
123
133
|
z.transform(({ text, variant, value }) => ({
|
package/src/content/nestable.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
2
|
|
|
3
3
|
import type { NestableModel } from "../model/nestable"
|
|
4
|
+
import type { BooleanContent} from "./boolean";
|
|
4
5
|
import { BooleanContentDefaultValue, BooleanContentSchema, BooleanContentType } from "./boolean"
|
|
6
|
+
import type { EmbedContent} from "./embed";
|
|
5
7
|
import { EmbedContentSchema, EmbedContentType } from "./embed"
|
|
8
|
+
import type { EmptyContent} from "./empty";
|
|
6
9
|
import { EmptyContentSchema, EmptyContentType } from "./empty"
|
|
10
|
+
import type {
|
|
11
|
+
ColorContent,
|
|
12
|
+
DateContent,
|
|
13
|
+
NumberContent,
|
|
14
|
+
RangeContent,
|
|
15
|
+
SelectContent,
|
|
16
|
+
TextContent,
|
|
17
|
+
TimestampContent} from "./field";
|
|
7
18
|
import {
|
|
8
19
|
ColorContentSchema,
|
|
9
20
|
DateContentSchema,
|
|
@@ -15,16 +26,24 @@ import {
|
|
|
15
26
|
TextContentSchema,
|
|
16
27
|
TimestampContentSchema,
|
|
17
28
|
} from "./field"
|
|
29
|
+
import type { GeoPointContent} from "./geopoint";
|
|
18
30
|
import { GeoPointContentSchema, GeoPointContentType } from "./geopoint"
|
|
31
|
+
import type { ImageContent} from "./image";
|
|
19
32
|
import { ImageContentSchema, ImageContentType } from "./image"
|
|
33
|
+
import type { IntegrationFieldContent} from "./integrationField";
|
|
20
34
|
import { IntegrationFieldContentSchema, IntegrationFieldContentType } from "./integrationField"
|
|
35
|
+
import type { LinkContent} from "./link";
|
|
21
36
|
import { LinkContentSchema, LinkContentType } from "./link"
|
|
37
|
+
import type { RepeatableContent} from "./repeatable";
|
|
22
38
|
import { RepeatableContentSchema, RepeatableContentType } from "./repeatable"
|
|
39
|
+
import type { RichTextContent} from "./richText";
|
|
23
40
|
import { RichTextContentSchema, RichTextContentType } from "./richText"
|
|
41
|
+
import type { SeparatorContent} from "./separator";
|
|
24
42
|
import { SeparatorContentSchema, SeparatorContentType } from "./separator"
|
|
43
|
+
import type { TableContent} from "./table";
|
|
25
44
|
import { TableContentSchema, TableContentType } from "./table"
|
|
26
45
|
|
|
27
|
-
export const NestableContentSchema = z.union([
|
|
46
|
+
export const NestableContentSchema: z.ZodMiniType<NestableContent> = z.union([
|
|
28
47
|
EmptyContentSchema,
|
|
29
48
|
BooleanContentSchema,
|
|
30
49
|
ColorContentSchema,
|
|
@@ -45,7 +64,25 @@ export const NestableContentSchema = z.union([
|
|
|
45
64
|
TimestampContentSchema,
|
|
46
65
|
])
|
|
47
66
|
|
|
48
|
-
export type NestableContent =
|
|
67
|
+
export type NestableContent =
|
|
68
|
+
EmptyContent |
|
|
69
|
+
BooleanContent |
|
|
70
|
+
ColorContent |
|
|
71
|
+
DateContent |
|
|
72
|
+
EmbedContent |
|
|
73
|
+
GeoPointContent |
|
|
74
|
+
ImageContent |
|
|
75
|
+
IntegrationFieldContent |
|
|
76
|
+
LinkContent |
|
|
77
|
+
NumberContent |
|
|
78
|
+
RangeContent |
|
|
79
|
+
RepeatableContent |
|
|
80
|
+
RichTextContent |
|
|
81
|
+
SelectContent |
|
|
82
|
+
SeparatorContent |
|
|
83
|
+
TableContent |
|
|
84
|
+
TextContent |
|
|
85
|
+
TimestampContent
|
|
49
86
|
|
|
50
87
|
const NestableContentTypes = [
|
|
51
88
|
EmptyContentType,
|
package/src/content/richText.ts
CHANGED
|
@@ -2,31 +2,55 @@ import { z } from "zod/mini"
|
|
|
2
2
|
|
|
3
3
|
import { EmbedContentSchema } from "./embed"
|
|
4
4
|
import { ImageViewContentSchema } from "./image"
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
getEmbedBlockSchema,
|
|
7
|
+
getImageBlockSchema,
|
|
8
|
+
getSpanSchema,
|
|
9
|
+
getTextBlockSchema,
|
|
10
|
+
} from "./legacy/richText"
|
|
11
|
+
import type { Span } from "./legacy/richText"
|
|
12
|
+
import type { FilledLinkValueContent } from "./link"
|
|
6
13
|
import { FilledLinkValueContentSchema } from "./link"
|
|
7
14
|
|
|
15
|
+
// Spans
|
|
16
|
+
export type RichTextContentSpan = Span<FilledLinkValueContent>
|
|
17
|
+
|
|
18
|
+
export const RichTextContentSpanSchema: z.ZodMiniType<RichTextContentSpan> =
|
|
19
|
+
getSpanSchema(FilledLinkValueContentSchema)
|
|
20
|
+
|
|
21
|
+
// Blocks
|
|
8
22
|
const TextBlockValueSchema = getTextBlockSchema(FilledLinkValueContentSchema)
|
|
23
|
+
type TextBlockValue = z.infer<typeof TextBlockValueSchema>
|
|
24
|
+
|
|
9
25
|
const ImageBlockValueSchema = getImageBlockSchema(
|
|
10
26
|
ImageViewContentSchema,
|
|
11
27
|
FilledLinkValueContentSchema,
|
|
12
28
|
)
|
|
29
|
+
type ImageBlockValue = z.infer<typeof ImageBlockValueSchema>
|
|
30
|
+
|
|
13
31
|
const EmbedBlockValueSchema = getEmbedBlockSchema(EmbedContentSchema)
|
|
32
|
+
type EmbedBlockValue = z.infer<typeof EmbedBlockValueSchema>
|
|
14
33
|
|
|
15
|
-
|
|
16
|
-
const BlockValueSchema = z.union([
|
|
34
|
+
export const RichTextContentBlockSchema: z.ZodMiniType<RichTextContentBlock> = z.union([
|
|
17
35
|
TextBlockValueSchema,
|
|
18
36
|
ImageBlockValueSchema,
|
|
19
37
|
EmbedBlockValueSchema,
|
|
20
38
|
])
|
|
21
39
|
|
|
22
|
-
// Used by content/richText
|
|
23
|
-
export type
|
|
40
|
+
// Used by content/codec/richText
|
|
41
|
+
export type RichTextContentBlock =
|
|
42
|
+
| TextBlockValue
|
|
43
|
+
| ImageBlockValue
|
|
44
|
+
| EmbedBlockValue
|
|
24
45
|
|
|
25
46
|
export const RichTextContentType = "StructuredTextContent" as const
|
|
26
47
|
|
|
27
|
-
export
|
|
48
|
+
export type RichTextContent = {
|
|
49
|
+
__TYPE__: typeof RichTextContentType
|
|
50
|
+
value: RichTextContentBlock[]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const RichTextContentSchema: z.ZodMiniType<RichTextContent> = z.object({
|
|
28
54
|
__TYPE__: z.literal(RichTextContentType),
|
|
29
|
-
value: z.array(
|
|
55
|
+
value: z.array(RichTextContentBlockSchema),
|
|
30
56
|
})
|
|
31
|
-
|
|
32
|
-
export type RichTextContent = z.infer<typeof RichTextContentSchema>
|
package/src/content/slice.ts
CHANGED
|
@@ -32,10 +32,10 @@ export const SharedSliceContentSchema = z.object({
|
|
|
32
32
|
export type SharedSliceContent = z.infer<typeof SharedSliceContentSchema>
|
|
33
33
|
|
|
34
34
|
// All
|
|
35
|
-
export const SliceContentSchema = z.union([
|
|
35
|
+
export const SliceContentSchema: z.ZodMiniType<SliceContent> = z.union([
|
|
36
36
|
LegacySliceContentSchema,
|
|
37
37
|
CompositeSliceContentSchema,
|
|
38
38
|
SharedSliceContentSchema,
|
|
39
39
|
])
|
|
40
40
|
|
|
41
|
-
export type SliceContent =
|
|
41
|
+
export type SliceContent = LegacySliceContent | CompositeSliceContent | SharedSliceContent
|
package/src/content/widget.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
2
|
|
|
3
|
+
import type { GroupContent} from "./group";
|
|
3
4
|
import { GroupContentSchema } from "./group"
|
|
5
|
+
import type { NestableContent} from "./nestable";
|
|
4
6
|
import { NestableContentSchema } from "./nestable"
|
|
7
|
+
import type { SlicesContent} from "./slices";
|
|
5
8
|
import { SlicesContentSchema } from "./slices"
|
|
9
|
+
import type { UIDContent} from "./uid";
|
|
6
10
|
import { UIDContentSchema } from "./uid"
|
|
7
11
|
|
|
8
|
-
export const WidgetContentSchema = z.union([
|
|
12
|
+
export const WidgetContentSchema: z.ZodMiniType<WidgetContent> = z.union([
|
|
9
13
|
GroupContentSchema,
|
|
10
14
|
NestableContentSchema,
|
|
11
15
|
UIDContentSchema,
|
|
12
16
|
SlicesContentSchema,
|
|
13
17
|
])
|
|
14
18
|
|
|
15
|
-
export type WidgetContent =
|
|
19
|
+
export type WidgetContent = GroupContent | NestableContent | UIDContent | SlicesContent
|
|
16
20
|
|
|
17
21
|
export type ContentType = WidgetContent["__TYPE__"]
|
|
@@ -13,27 +13,24 @@ import { traverseDocumentContent } from "./traverseContent"
|
|
|
13
13
|
|
|
14
14
|
export function collectWidgets<TWidgetContent extends WidgetContent>(
|
|
15
15
|
document: DocumentContent,
|
|
16
|
-
test: (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
apiID: string
|
|
25
|
-
content: TWidgetContent
|
|
26
|
-
},
|
|
16
|
+
test: (
|
|
17
|
+
content: WidgetContent,
|
|
18
|
+
args: {
|
|
19
|
+
path: contentPath.Path
|
|
20
|
+
key: string
|
|
21
|
+
apiID: string
|
|
22
|
+
},
|
|
23
|
+
) => content is TWidgetContent,
|
|
27
24
|
): Record<string, TWidgetContent> {
|
|
28
25
|
const collected: Record<string, TWidgetContent> = {}
|
|
29
26
|
|
|
30
27
|
traverseDocumentContent(document, {
|
|
31
|
-
transformWidget: (args) => {
|
|
32
|
-
if (test(args)) {
|
|
33
|
-
collected[contentPath.serialize(args.path)] =
|
|
28
|
+
transformWidget: ({ content, ...args }) => {
|
|
29
|
+
if (test(content, args)) {
|
|
30
|
+
collected[contentPath.serialize(args.path)] = content
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
return
|
|
33
|
+
return content
|
|
37
34
|
},
|
|
38
35
|
})
|
|
39
36
|
|
|
@@ -24,7 +24,8 @@ import type { NestableModel } from "../model/nestable"
|
|
|
24
24
|
import type {
|
|
25
25
|
CompositeSliceModel,
|
|
26
26
|
LegacySliceModel,
|
|
27
|
-
|
|
27
|
+
SharedSliceVariationContentModel,
|
|
28
|
+
SliceContentModel,
|
|
28
29
|
} from "../model/slice"
|
|
29
30
|
import type { StaticSlicesModel } from "../model/slices"
|
|
30
31
|
import { TableCellModel } from "../model/table"
|
|
@@ -81,10 +82,8 @@ export function traverseSlicesContent(
|
|
|
81
82
|
content: SlicesContent,
|
|
82
83
|
config: TraverseSlicesContentConfig,
|
|
83
84
|
): SlicesContent | undefined {
|
|
84
|
-
const {
|
|
85
|
-
|
|
86
|
-
transformSlice = (args) => args.content
|
|
87
|
-
} = config
|
|
85
|
+
const { transformWidget = (args) => args.content, transformSlice = (args) => args.content } =
|
|
86
|
+
config
|
|
88
87
|
|
|
89
88
|
const traversed: SlicesContent["value"] = []
|
|
90
89
|
for (const sliceItemContent of content.value) {
|
|
@@ -92,7 +91,7 @@ export function traverseSlicesContent(
|
|
|
92
91
|
|
|
93
92
|
let traversedSliceItemContent: SliceItemContent | undefined
|
|
94
93
|
if (sliceItemContent.widget.__TYPE__ === SharedSliceContentType) {
|
|
95
|
-
let model:
|
|
94
|
+
let model: SharedSliceVariationContentModel | undefined
|
|
96
95
|
if (sliceModel?.type === "SharedSlice") {
|
|
97
96
|
const variationID = sliceItemContent.widget.variation
|
|
98
97
|
const variationModel = sliceModel.variations.find(
|
|
@@ -154,7 +153,7 @@ export function traverseSlicesContent(
|
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
type TraverseSharedSliceContentConfig = {
|
|
157
|
-
model?:
|
|
156
|
+
model?: SharedSliceVariationContentModel
|
|
158
157
|
transformWidget?: TraverseWidgetContentFunction
|
|
159
158
|
transformSlice?: TraverseSliceContentFunction
|
|
160
159
|
}
|
|
@@ -166,10 +165,8 @@ export function traverseSharedSliceContent(
|
|
|
166
165
|
content: SharedSliceItemContent,
|
|
167
166
|
config: TraverseSharedSliceContentConfig,
|
|
168
167
|
): SharedSliceItemContent | undefined {
|
|
169
|
-
const {
|
|
170
|
-
|
|
171
|
-
transformSlice = (args) => args.content
|
|
172
|
-
} = config
|
|
168
|
+
const { transformWidget = (args) => args.content, transformSlice = (args) => args.content } =
|
|
169
|
+
config
|
|
173
170
|
|
|
174
171
|
const traversedPrimary: SharedSliceContent["primary"] = {}
|
|
175
172
|
for (const [key, fieldContent] of Object.entries(content.widget.primary)) {
|
|
@@ -222,10 +219,8 @@ export function traverseCompositeSliceContent(
|
|
|
222
219
|
content: CompositeSliceItemContent,
|
|
223
220
|
config: TraverseCompositeSliceContentConfig,
|
|
224
221
|
): CompositeSliceItemContent | undefined {
|
|
225
|
-
const {
|
|
226
|
-
|
|
227
|
-
transformSlice = (args) => args.content
|
|
228
|
-
} = config
|
|
222
|
+
const { transformWidget = (args) => args.content, transformSlice = (args) => args.content } =
|
|
223
|
+
config
|
|
229
224
|
|
|
230
225
|
const traversedPrimary: CompositeSliceContent["nonRepeat"] = {}
|
|
231
226
|
for (const [key, fieldContent] of Object.entries(content.widget.nonRepeat)) {
|
|
@@ -278,7 +273,7 @@ export function traverseLegacySliceContent(
|
|
|
278
273
|
const {
|
|
279
274
|
model,
|
|
280
275
|
transformWidget = (args) => args.content,
|
|
281
|
-
transformSlice = (args) => args.content
|
|
276
|
+
transformSlice = (args) => args.content,
|
|
282
277
|
} = config
|
|
283
278
|
|
|
284
279
|
const traversedContent = traverseWidgetContent(path, key, apiID, content.widget, {
|
|
@@ -471,7 +466,7 @@ export type TraverseSliceContentFunction = <TContent extends SliceItemContent>(a
|
|
|
471
466
|
key: string
|
|
472
467
|
apiID: string
|
|
473
468
|
content: TContent
|
|
474
|
-
model?:
|
|
469
|
+
model?: SliceContentModel
|
|
475
470
|
}) => TContent | undefined
|
|
476
471
|
|
|
477
472
|
export type TraverseWidgetContentFunction<
|
|
@@ -485,8 +480,6 @@ export type TraverseWidgetContentFunction<
|
|
|
485
480
|
}) => (TContentTransformMode extends "preserve" ? TContent : WidgetContent) | undefined
|
|
486
481
|
|
|
487
482
|
// Internals
|
|
488
|
-
type SliceModel = SharedSliceVariationModel | CompositeSliceModel | LegacySliceModel
|
|
489
|
-
|
|
490
483
|
type TraverseWidgetContentConfig = {
|
|
491
484
|
model?: StaticWidgetModel
|
|
492
485
|
transformWidget?: TraverseWidgetContentFunction
|