@prismicio/types-internal 4.0.0-pr.6.eb53f11 → 4.0.0-pr.7.9dec8db
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/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/field.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/repeatable.js +2 -8
- package/dist/content/legacy/repeatable.js.map +1 -1
- 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.map +1 -1
- package/dist/content/legacy/separator.d.ts +1 -0
- package/dist/content/legacy/slice.js +2 -3
- 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 +1 -0
- 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 +20 -248
- package/dist/content/richText.d.ts.map +1 -1
- 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/contentPath.js +1 -1
- package/dist/helpers/customTypeModel.d.ts +3 -2
- package/dist/helpers/customTypeModel.d.ts.map +1 -1
- package/dist/helpers/customTypeModel.js +31 -1
- package/dist/helpers/customTypeModel.js.map +1 -1
- package/dist/helpers/documentContent.d.ts +3 -2
- package/dist/helpers/documentContent.d.ts.map +1 -1
- package/dist/helpers/documentContent.js +14 -1
- package/dist/helpers/documentContent.js.map +1 -1
- package/dist/helpers/sliceContent.d.ts +12 -0
- package/dist/helpers/sliceContent.d.ts.map +1 -0
- package/dist/helpers/sliceContent.js +60 -0
- package/dist/helpers/sliceContent.js.map +1 -0
- package/dist/helpers/traverseContent.d.ts +15 -16
- package/dist/helpers/traverseContent.d.ts.map +1 -1
- package/dist/helpers/traverseContent.js +51 -19
- package/dist/helpers/traverseContent.js.map +1 -1
- package/dist/helpers/traverseContentWithModel.d.ts +14 -15
- package/dist/helpers/traverseContentWithModel.d.ts.map +1 -1
- package/dist/helpers/traverseContentWithModel.js +61 -35
- package/dist/helpers/traverseContentWithModel.js.map +1 -1
- package/dist/index.d.ts +25 -24
- package/dist/index.js +3 -1
- package/dist/io-ts.d.ts +3048 -71012
- package/dist/io-ts.d.ts.map +1 -1
- package/dist/io-ts.js +125 -124
- 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 +375 -376
- 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 +2 -2
- 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 +3 -3
- 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 +4 -3
- 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 +781 -3720
- 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/table.d.ts +2 -1
- package/dist/model/table.d.ts.map +1 -1
- package/dist/model/table.js +9 -7
- package/dist/model/table.js.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 +1332 -34960
- package/dist/zod4.d.ts.map +1 -1
- package/dist/zod4.js +125 -124
- package/dist/zod4.js.map +1 -1
- package/package.json +3 -2
- package/src/content/field.ts +9 -2
- package/src/content/group.ts +5 -2
- package/src/content/legacy/group.ts +12 -4
- package/src/content/legacy/link.ts +32 -9
- package/src/content/legacy/nestable.ts +26 -2
- package/src/content/legacy/repeatable.ts +3 -16
- package/src/content/legacy/richText.ts +37 -5
- package/src/content/legacy/slice.ts +8 -7
- package/src/content/legacy/widget.ts +6 -2
- package/src/content/link.ts +32 -9
- package/src/content/nestable.ts +42 -2
- package/src/content/richText.ts +19 -7
- package/src/content/slice.ts +2 -2
- package/src/content/widget.ts +6 -2
- package/src/helpers/customTypeModel.ts +44 -0
- package/src/helpers/documentContent.ts +32 -1
- package/src/helpers/sliceContent.ts +86 -0
- package/src/helpers/traverseContent.ts +93 -32
- package/src/helpers/traverseContentWithModel.ts +73 -48
- package/src/index.ts +4 -1
- package/src/io-ts.ts +164 -144
- package/src/model/group.ts +4 -1
- package/src/model/image.ts +1 -1
- package/src/model/link.ts +1 -1
- 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 +36 -9
- package/src/model/table.ts +11 -2
- package/src/model/widget.ts +8 -4
- package/src/zod4.ts +164 -144
|
@@ -1,19 +1,31 @@
|
|
|
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"
|
|
9
|
+
import type { StringLegacy } from "./field"
|
|
6
10
|
import { StringLegacySchema } from "./field"
|
|
11
|
+
import type { GeoPointLegacy } from "./geopoint"
|
|
7
12
|
import { GeoPointLegacySchema } from "./geopoint"
|
|
13
|
+
import type { ImageLegacy } from "./image"
|
|
8
14
|
import { ImageLegacySchema } from "./image"
|
|
15
|
+
import type { IntegrationFieldLegacy } from "./integrationField"
|
|
9
16
|
import { IntegrationFieldLegacySchema } from "./integrationField"
|
|
17
|
+
import type { LinkLegacy } from "./link"
|
|
10
18
|
import { LinkLegacySchema } from "./link"
|
|
19
|
+
import type { RepeatableLegacy } from "./repeatable"
|
|
11
20
|
import { RepeatableLegacySchema } from "./repeatable"
|
|
21
|
+
import type { RichTextLegacy } from "./richText"
|
|
12
22
|
import { RichTextLegacySchema } from "./richText"
|
|
23
|
+
import type { SeparatorLegacy } from "./separator"
|
|
13
24
|
import { SeparatorLegacySchema } from "./separator"
|
|
25
|
+
import type { TableLegacy } from "./table"
|
|
14
26
|
import { TableLegacySchema } from "./table"
|
|
15
27
|
|
|
16
|
-
export const NestableLegacySchema = z.union([
|
|
28
|
+
export const NestableLegacySchema: z.ZodMiniType<NestableLegacy> = z.union([
|
|
17
29
|
EmptyLegacySchema,
|
|
18
30
|
BooleanLegacySchema,
|
|
19
31
|
EmbedLegacyLooseSchema,
|
|
@@ -28,4 +40,16 @@ export const NestableLegacySchema = z.union([
|
|
|
28
40
|
TableLegacySchema,
|
|
29
41
|
])
|
|
30
42
|
|
|
31
|
-
export type NestableLegacy =
|
|
43
|
+
export type NestableLegacy =
|
|
44
|
+
| EmptyLegacy
|
|
45
|
+
| BooleanLegacy
|
|
46
|
+
| EmbedLegacy
|
|
47
|
+
| StringLegacy
|
|
48
|
+
| GeoPointLegacy
|
|
49
|
+
| ImageLegacy
|
|
50
|
+
| IntegrationFieldLegacy
|
|
51
|
+
| LinkLegacy
|
|
52
|
+
| RepeatableLegacy
|
|
53
|
+
| RichTextLegacy
|
|
54
|
+
| SeparatorLegacy
|
|
55
|
+
| TableLegacy
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
z.array(z.unknown()),
|
|
7
|
-
z.transform((value) =>
|
|
8
|
-
value.flatMap((item) => {
|
|
9
|
-
try {
|
|
10
|
-
return [LinkLegacySchema.parse(item)]
|
|
11
|
-
} catch {
|
|
12
|
-
return []
|
|
13
|
-
}
|
|
14
|
-
}),
|
|
15
|
-
),
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
export const RepeatableLegacySchema = RepeatableLinkLegacySchema
|
|
3
|
+
// Keep the legacy schema non-lossy; item-level link decoding lives in
|
|
4
|
+
// `codec/repeatable.ts`, where the field model is available.
|
|
5
|
+
export const RepeatableLegacySchema = z.array(z.unknown())
|
|
19
6
|
|
|
20
7
|
export type RepeatableLegacy = z.infer<typeof RepeatableLegacySchema>
|
|
@@ -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,6 +81,11 @@ const BasicSpanSchema = z.object({
|
|
|
60
81
|
end: z.number(),
|
|
61
82
|
})
|
|
62
83
|
|
|
84
|
+
export type Span<TLink extends FilledLinkValueLegacy | FilledLinkValueContent> =
|
|
85
|
+
| HyperlinkSpan<TLink>
|
|
86
|
+
| LabelSpan
|
|
87
|
+
| BasicSpan
|
|
88
|
+
|
|
63
89
|
// oxlint-disable-next-line explicit-module-boundary-types
|
|
64
90
|
export const getSpanSchema = <
|
|
65
91
|
TLinkSchema extends typeof FilledLinkValueLegacySchema | typeof FilledLinkValueContentSchema,
|
|
@@ -114,6 +140,8 @@ export const getTextBlockSchema = <
|
|
|
114
140
|
|
|
115
141
|
const TextBlockLegacySchema = getTextBlockSchema(FilledLinkValueLegacySchema)
|
|
116
142
|
|
|
143
|
+
type TextBlockLegacy = z.infer<typeof TextBlockLegacySchema>
|
|
144
|
+
|
|
117
145
|
// Image block
|
|
118
146
|
|
|
119
147
|
// oxlint-disable-next-line explicit-module-boundary-types
|
|
@@ -136,6 +164,8 @@ const ImageBlockLegacySchema = getImageBlockSchema(
|
|
|
136
164
|
FilledLinkValueLegacySchema,
|
|
137
165
|
)
|
|
138
166
|
|
|
167
|
+
type ImageBlockLegacy = z.infer<typeof ImageBlockLegacySchema>
|
|
168
|
+
|
|
139
169
|
// Embed block
|
|
140
170
|
// oxlint-disable-next-line explicit-module-boundary-types
|
|
141
171
|
export const getEmbedBlockSchema = <
|
|
@@ -152,14 +182,16 @@ export const getEmbedBlockSchema = <
|
|
|
152
182
|
|
|
153
183
|
const EmbedBlockLegacySchema = getEmbedBlockSchema(EmbedLegacyLooseSchema)
|
|
154
184
|
|
|
185
|
+
type EmbedBlockLegacy = z.infer<typeof EmbedBlockLegacySchema>
|
|
186
|
+
|
|
155
187
|
// Blocks
|
|
156
|
-
export const RichTextLegacyBlockSchema = z.union([
|
|
188
|
+
export const RichTextLegacyBlockSchema: z.ZodMiniType<RichTextLegacyBlock> = z.union([
|
|
157
189
|
TextBlockLegacySchema,
|
|
158
190
|
ImageBlockLegacySchema,
|
|
159
191
|
EmbedBlockLegacySchema,
|
|
160
192
|
])
|
|
161
193
|
|
|
162
|
-
export type RichTextLegacyBlock =
|
|
194
|
+
export type RichTextLegacyBlock = TextBlockLegacy | ImageBlockLegacy | EmbedBlockLegacy
|
|
163
195
|
|
|
164
196
|
export const RichTextLegacySchema = z.array(RichTextLegacyBlockSchema)
|
|
165
197
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
2
|
|
|
3
3
|
import { GroupItemLegacySchema, NestableAndGroupLegacySchema } from "./group"
|
|
4
|
-
import { NestableLegacySchema } from "./nestable"
|
|
5
4
|
|
|
6
5
|
// Legacy (before 2020)
|
|
7
6
|
export const LegacySliceLegacySchema = NestableAndGroupLegacySchema
|
|
@@ -9,29 +8,31 @@ export const LegacySliceLegacySchema = NestableAndGroupLegacySchema
|
|
|
9
8
|
export type LegacySliceLegacy = z.infer<typeof LegacySliceLegacySchema>
|
|
10
9
|
|
|
11
10
|
// Composite (2020 to 2021)
|
|
11
|
+
// Keep non-repeat values raw here: array-shaped legacy payloads are ambiguous until
|
|
12
|
+
// `codec/slice.ts` resolves the field model and picks the right decoder.
|
|
12
13
|
export const CompositeSliceLegacySchema = z.object({
|
|
13
|
-
"non-repeat": z.optional(z.record(z.string(),
|
|
14
|
+
"non-repeat": z.optional(z.record(z.string(), z.unknown())),
|
|
14
15
|
repeat: z.optional(z.array(GroupItemLegacySchema)),
|
|
15
16
|
})
|
|
16
17
|
|
|
17
18
|
export type CompositeSliceLegacy = z.infer<typeof CompositeSliceLegacySchema>
|
|
18
19
|
|
|
19
20
|
// Shared (2021 to present)
|
|
21
|
+
// Keep primary values raw here: array-shaped legacy payloads are ambiguous until
|
|
22
|
+
// `codec/slice.ts` resolves the field model and picks the right decoder.
|
|
20
23
|
export const SharedSliceLegacySchema = z.object({
|
|
21
24
|
variation: z.string(),
|
|
22
|
-
primary: z.transform(
|
|
23
|
-
(value) => z.record(z.string(), NestableAndGroupLegacySchema).safeParse(value).data || {},
|
|
24
|
-
),
|
|
25
|
+
primary: z.transform((value) => z.record(z.string(), z.unknown()).safeParse(value).data || {}),
|
|
25
26
|
items: z.transform((value) => z.array(GroupItemLegacySchema).safeParse(value).data || []),
|
|
26
27
|
})
|
|
27
28
|
|
|
28
29
|
export type SharedSliceLegacy = z.infer<typeof SharedSliceLegacySchema>
|
|
29
30
|
|
|
30
31
|
// All
|
|
31
|
-
export const SliceLegacySchema = z.union([
|
|
32
|
+
export const SliceLegacySchema: z.ZodMiniType<SliceLegacy> = z.union([
|
|
32
33
|
LegacySliceLegacySchema,
|
|
33
34
|
CompositeSliceLegacySchema,
|
|
34
35
|
SharedSliceLegacySchema,
|
|
35
36
|
])
|
|
36
37
|
|
|
37
|
-
export type SliceLegacy =
|
|
38
|
+
export type SliceLegacy = LegacySliceLegacy | CompositeSliceLegacy | SharedSliceLegacy
|
|
@@ -1,15 +1,19 @@
|
|
|
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 = UIDLegacy | GroupLegacy | SlicesLegacy | 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,17 @@ export const FilledLinkValueContentSchema = z.union([
|
|
|
71
71
|
])
|
|
72
72
|
|
|
73
73
|
// Used by content/legacy/link
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
type FilledImageLinkValueContent = z.infer<typeof FilledImageLinkValueContentSchema>
|
|
75
|
+
type FilledFileLinkValueContent = z.infer<typeof FilledFileLinkValueContentSchema>
|
|
76
|
+
type FilledDocumentLinkValueContent = z.infer<typeof FilledDocumentLinkValueContentSchema>
|
|
77
|
+
type FilledExternalLinkValueContent = z.infer<typeof FilledExternalLinkValueContentSchema>
|
|
78
|
+
export type FilledLinkValueContent =
|
|
79
|
+
| FilledImageLinkValueContent
|
|
80
|
+
| FilledFileLinkValueContent
|
|
81
|
+
| FilledDocumentLinkValueContent
|
|
82
|
+
| FilledExternalLinkValueContent
|
|
83
|
+
|
|
84
|
+
const EmptyLinkValueContentSchema: z.ZodMiniType<EmptyLinkValueContent> = z.union([
|
|
77
85
|
EmptyImageLinkValueContentSchema,
|
|
78
86
|
EmptyFileLinkValueContentSchema,
|
|
79
87
|
EmptyMediaLinkValueContentSchema,
|
|
@@ -83,12 +91,27 @@ const EmptyLinkValueContentSchema = z.union([
|
|
|
83
91
|
])
|
|
84
92
|
|
|
85
93
|
// Used by content/codec/link
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
type EmptyImageLinkValueContent = z.infer<typeof EmptyImageLinkValueContentSchema>
|
|
95
|
+
type EmptyFileLinkValueContent = z.infer<typeof EmptyFileLinkValueContentSchema>
|
|
96
|
+
type EmptyMediaLinkValueContent = z.infer<typeof EmptyMediaLinkValueContentSchema>
|
|
97
|
+
type EmptyDocumentLinkValueContent = z.infer<typeof EmptyDocumentLinkValueContentSchema>
|
|
98
|
+
type EmptyExternalLinkValueContent = z.infer<typeof EmptyExternalLinkValueContentSchema>
|
|
99
|
+
type AnyLinkValueContent = z.infer<typeof AnyLinkValueContentSchema>
|
|
100
|
+
export type EmptyLinkValueContent =
|
|
101
|
+
| EmptyImageLinkValueContent
|
|
102
|
+
| EmptyFileLinkValueContent
|
|
103
|
+
| EmptyMediaLinkValueContent
|
|
104
|
+
| EmptyDocumentLinkValueContent
|
|
105
|
+
| EmptyExternalLinkValueContent
|
|
106
|
+
| AnyLinkValueContent
|
|
107
|
+
|
|
108
|
+
const LinkValueContentSchema: z.ZodMiniType<LinkValueContent> = z.union([
|
|
109
|
+
FilledLinkValueContentSchema,
|
|
110
|
+
EmptyLinkValueContentSchema,
|
|
111
|
+
])
|
|
89
112
|
|
|
90
113
|
// Used by content/codec/link
|
|
91
|
-
export type LinkValueContent =
|
|
114
|
+
export type LinkValueContent = FilledLinkValueContent | EmptyLinkValueContent
|
|
92
115
|
|
|
93
116
|
// Content
|
|
94
117
|
export const LinkContentType = "LinkContent" as const
|
|
@@ -117,7 +140,7 @@ export const LinkContentSchema = z.object({
|
|
|
117
140
|
z.object({
|
|
118
141
|
text: z.optional(z.string()),
|
|
119
142
|
variant: z.optional(z.string()),
|
|
120
|
-
value: z.
|
|
143
|
+
value: LinkValueContentSchema as z.ZodMiniType<LinkValueContent, Record<string, unknown>>,
|
|
121
144
|
}),
|
|
122
145
|
),
|
|
123
146
|
z.transform(({ text, variant, value }) => ({
|
package/src/content/nestable.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
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,
|
|
18
|
+
} from "./field"
|
|
7
19
|
import {
|
|
8
20
|
ColorContentSchema,
|
|
9
21
|
DateContentSchema,
|
|
@@ -15,16 +27,24 @@ import {
|
|
|
15
27
|
TextContentSchema,
|
|
16
28
|
TimestampContentSchema,
|
|
17
29
|
} from "./field"
|
|
30
|
+
import type { GeoPointContent } from "./geopoint"
|
|
18
31
|
import { GeoPointContentSchema, GeoPointContentType } from "./geopoint"
|
|
32
|
+
import type { ImageContent } from "./image"
|
|
19
33
|
import { ImageContentSchema, ImageContentType } from "./image"
|
|
34
|
+
import type { IntegrationFieldContent } from "./integrationField"
|
|
20
35
|
import { IntegrationFieldContentSchema, IntegrationFieldContentType } from "./integrationField"
|
|
36
|
+
import type { LinkContent } from "./link"
|
|
21
37
|
import { LinkContentSchema, LinkContentType } from "./link"
|
|
38
|
+
import type { RepeatableContent } from "./repeatable"
|
|
22
39
|
import { RepeatableContentSchema, RepeatableContentType } from "./repeatable"
|
|
40
|
+
import type { RichTextContent } from "./richText"
|
|
23
41
|
import { RichTextContentSchema, RichTextContentType } from "./richText"
|
|
42
|
+
import type { SeparatorContent } from "./separator"
|
|
24
43
|
import { SeparatorContentSchema, SeparatorContentType } from "./separator"
|
|
44
|
+
import type { TableContent } from "./table"
|
|
25
45
|
import { TableContentSchema, TableContentType } from "./table"
|
|
26
46
|
|
|
27
|
-
export const NestableContentSchema = z.union([
|
|
47
|
+
export const NestableContentSchema: z.ZodMiniType<NestableContent> = z.union([
|
|
28
48
|
EmptyContentSchema,
|
|
29
49
|
BooleanContentSchema,
|
|
30
50
|
ColorContentSchema,
|
|
@@ -45,7 +65,25 @@ export const NestableContentSchema = z.union([
|
|
|
45
65
|
TimestampContentSchema,
|
|
46
66
|
])
|
|
47
67
|
|
|
48
|
-
export type NestableContent =
|
|
68
|
+
export type NestableContent =
|
|
69
|
+
| EmptyContent
|
|
70
|
+
| BooleanContent
|
|
71
|
+
| ColorContent
|
|
72
|
+
| DateContent
|
|
73
|
+
| EmbedContent
|
|
74
|
+
| GeoPointContent
|
|
75
|
+
| ImageContent
|
|
76
|
+
| IntegrationFieldContent
|
|
77
|
+
| LinkContent
|
|
78
|
+
| NumberContent
|
|
79
|
+
| RangeContent
|
|
80
|
+
| RepeatableContent
|
|
81
|
+
| RichTextContent
|
|
82
|
+
| SelectContent
|
|
83
|
+
| SeparatorContent
|
|
84
|
+
| TableContent
|
|
85
|
+
| TextContent
|
|
86
|
+
| TimestampContent
|
|
49
87
|
|
|
50
88
|
const NestableContentTypes = [
|
|
51
89
|
EmptyContentType,
|
|
@@ -62,6 +100,8 @@ const NestableContentTypes = [
|
|
|
62
100
|
TableContentType,
|
|
63
101
|
]
|
|
64
102
|
type NestableContentType = (typeof NestableContentTypes)[number]
|
|
103
|
+
|
|
104
|
+
/** @internal */
|
|
65
105
|
export function isNestableContent(content: {
|
|
66
106
|
__TYPE__: string
|
|
67
107
|
}): content is { __TYPE__: NestableContentType } {
|
package/src/content/richText.ts
CHANGED
|
@@ -8,35 +8,47 @@ import {
|
|
|
8
8
|
getSpanSchema,
|
|
9
9
|
getTextBlockSchema,
|
|
10
10
|
} from "./legacy/richText"
|
|
11
|
+
import type { Span } from "./legacy/richText"
|
|
12
|
+
import type { FilledLinkValueContent } from "./link"
|
|
11
13
|
import { FilledLinkValueContentSchema } from "./link"
|
|
12
14
|
|
|
13
15
|
// Spans
|
|
14
|
-
export
|
|
16
|
+
export type RichTextContentSpan = Span<FilledLinkValueContent>
|
|
15
17
|
|
|
16
|
-
export
|
|
18
|
+
export const RichTextContentSpanSchema: z.ZodMiniType<RichTextContentSpan> = getSpanSchema(
|
|
19
|
+
FilledLinkValueContentSchema,
|
|
20
|
+
)
|
|
17
21
|
|
|
18
22
|
// Blocks
|
|
19
23
|
const TextBlockValueSchema = getTextBlockSchema(FilledLinkValueContentSchema)
|
|
24
|
+
type TextBlockValue = z.infer<typeof TextBlockValueSchema>
|
|
25
|
+
|
|
20
26
|
const ImageBlockValueSchema = getImageBlockSchema(
|
|
21
27
|
ImageViewContentSchema,
|
|
22
28
|
FilledLinkValueContentSchema,
|
|
23
29
|
)
|
|
30
|
+
type ImageBlockValue = z.infer<typeof ImageBlockValueSchema>
|
|
31
|
+
|
|
24
32
|
const EmbedBlockValueSchema = getEmbedBlockSchema(EmbedContentSchema)
|
|
33
|
+
type EmbedBlockValue = z.infer<typeof EmbedBlockValueSchema>
|
|
25
34
|
|
|
26
|
-
export const RichTextContentBlockSchema = z.union([
|
|
35
|
+
export const RichTextContentBlockSchema: z.ZodMiniType<RichTextContentBlock> = z.union([
|
|
27
36
|
TextBlockValueSchema,
|
|
28
37
|
ImageBlockValueSchema,
|
|
29
38
|
EmbedBlockValueSchema,
|
|
30
39
|
])
|
|
31
40
|
|
|
32
41
|
// Used by content/codec/richText
|
|
33
|
-
export type RichTextContentBlock =
|
|
42
|
+
export type RichTextContentBlock = TextBlockValue | ImageBlockValue | EmbedBlockValue
|
|
34
43
|
|
|
35
44
|
export const RichTextContentType = "StructuredTextContent" as const
|
|
36
45
|
|
|
37
|
-
export
|
|
46
|
+
export type RichTextContent = {
|
|
47
|
+
__TYPE__: typeof RichTextContentType
|
|
48
|
+
value: RichTextContentBlock[]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const RichTextContentSchema: z.ZodMiniType<RichTextContent> = z.object({
|
|
38
52
|
__TYPE__: z.literal(RichTextContentType),
|
|
39
53
|
value: z.array(RichTextContentBlockSchema),
|
|
40
54
|
})
|
|
41
|
-
|
|
42
|
-
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__"]
|
|
@@ -67,3 +67,47 @@ export function collectSharedSlices(
|
|
|
67
67
|
|
|
68
68
|
return sharedSlices
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
export function filterMissingSharedSlices<
|
|
72
|
+
TCustomType extends StaticCustomTypeModel | CustomTypeModel,
|
|
73
|
+
>(
|
|
74
|
+
customType: TCustomType,
|
|
75
|
+
sharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,
|
|
76
|
+
): TCustomType {
|
|
77
|
+
const json: TCustomType["json"] = {}
|
|
78
|
+
|
|
79
|
+
const sharedSlicesMap =
|
|
80
|
+
sharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))
|
|
81
|
+
|
|
82
|
+
for (const [tabKey, tab] of Object.entries(customType.json)) {
|
|
83
|
+
const tabJSON: typeof tab = {}
|
|
84
|
+
for (const [key, widget] of Object.entries(tab)) {
|
|
85
|
+
switch (widget.type) {
|
|
86
|
+
case "Slices":
|
|
87
|
+
case "Choice":
|
|
88
|
+
const choices: Required<typeof widget>["config"]["choices"] = {}
|
|
89
|
+
for (const [id, model] of Object.entries(widget.config?.choices || {})) {
|
|
90
|
+
if (model.type === "SharedSlice") {
|
|
91
|
+
if (sharedSlicesMap.get(id)) {
|
|
92
|
+
choices[id] = model
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
choices[id] = model
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
tabJSON[key] = {
|
|
100
|
+
...widget,
|
|
101
|
+
config: { ...widget.config, choices },
|
|
102
|
+
}
|
|
103
|
+
break
|
|
104
|
+
default:
|
|
105
|
+
tabJSON[key] = widget
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
json[tabKey] = tabJSON
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return { ...customType, json }
|
|
113
|
+
}
|
|
@@ -5,10 +5,15 @@ import { defaultCtx } from "../content/codec/legacyContentCtx"
|
|
|
5
5
|
import type { DocumentContent } from "../content/document"
|
|
6
6
|
import type { DocumentLegacy } from "../content/legacy/document"
|
|
7
7
|
import { DocumentLegacySchema } from "../content/legacy/document"
|
|
8
|
+
import { isNestableContent } from "../content/nestable"
|
|
9
|
+
import type { CompositeSliceItemContent, LegacySliceItemContent } from "../content/slices"
|
|
8
10
|
import type { WidgetContent } from "../content/widget"
|
|
11
|
+
import type { StaticCustomTypeModel } from "../model/customType"
|
|
9
12
|
import type { FieldOrSliceType } from "../model/widget"
|
|
10
13
|
import { FieldOrSliceTypeSchema } from "../model/widget"
|
|
11
14
|
import * as contentPath from "./contentPath"
|
|
15
|
+
import * as customTypeModel from "./customTypeModel"
|
|
16
|
+
import * as sliceContent from "./sliceContent"
|
|
12
17
|
import { traverseDocumentContent } from "./traverseContent"
|
|
13
18
|
|
|
14
19
|
export function collectWidgets<TWidgetContent extends WidgetContent>(
|
|
@@ -37,7 +42,10 @@ export function collectWidgets<TWidgetContent extends WidgetContent>(
|
|
|
37
42
|
return collected
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
export function fromLegacy(
|
|
45
|
+
export function fromLegacy(
|
|
46
|
+
legacy: DocumentLegacy,
|
|
47
|
+
model: StaticCustomTypeModel,
|
|
48
|
+
): DocumentContent | undefined {
|
|
41
49
|
const parsed = DocumentLegacySchema.safeParse(legacy)
|
|
42
50
|
if (!parsed.success) {
|
|
43
51
|
return
|
|
@@ -67,6 +75,29 @@ export function fromLegacy(legacy: DocumentLegacy): DocumentContent | undefined
|
|
|
67
75
|
return
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
const needsMigration = Object.values(customTypeModel.collectSharedSlices(model)).some((slice) =>
|
|
79
|
+
Boolean(slice.legacyPaths),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if (needsMigration) {
|
|
83
|
+
return traverseDocumentContent(result.data, {
|
|
84
|
+
model,
|
|
85
|
+
transformSlice: ({ content, model }) => {
|
|
86
|
+
if (model?.type === "SharedSlice") {
|
|
87
|
+
if (content.widget.__TYPE__ === "CompositeSliceContent") {
|
|
88
|
+
return sliceContent.compositeToShared(content as CompositeSliceItemContent, model)
|
|
89
|
+
} else if (
|
|
90
|
+
content.widget.__TYPE__ === "GroupContentType" ||
|
|
91
|
+
isNestableContent(content.widget)
|
|
92
|
+
) {
|
|
93
|
+
return sliceContent.legacyToShared(content as LegacySliceItemContent, model)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return content
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
70
101
|
return result.data
|
|
71
102
|
}
|
|
72
103
|
|