@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GroupModel } from "../group"
|
|
2
2
|
import { GroupFieldType } from "../group"
|
|
3
3
|
import type { NestableModel } from "../nestable"
|
|
4
|
-
import type {
|
|
4
|
+
import type { SharedSliceModelVariation } from "../slice"
|
|
5
5
|
import { type DiffChange, DiffOperation } from "./changes"
|
|
6
6
|
import { isNotEmpty, zipObjects } from "./utils"
|
|
7
7
|
import type {
|
|
@@ -10,9 +10,9 @@ import type {
|
|
|
10
10
|
SlicePrimaryWidgetDiff,
|
|
11
11
|
} from "./widgets"
|
|
12
12
|
|
|
13
|
-
export type VariationMetadata = Omit<
|
|
13
|
+
export type VariationMetadata = Omit<SharedSliceModelVariation, "primary" | "items">
|
|
14
14
|
export type VariationDiff = DiffChange<
|
|
15
|
-
|
|
15
|
+
SharedSliceModelVariation,
|
|
16
16
|
Partial<VariationMetadata> & {
|
|
17
17
|
primary?: Record<string, SlicePrimaryWidgetDiff>
|
|
18
18
|
items?: Record<string, NestableWidgetDiff>
|
|
@@ -20,8 +20,8 @@ export type VariationDiff = DiffChange<
|
|
|
20
20
|
>
|
|
21
21
|
|
|
22
22
|
function compareVariationMeta(
|
|
23
|
-
variationA?:
|
|
24
|
-
variationB?:
|
|
23
|
+
variationA?: SharedSliceModelVariation,
|
|
24
|
+
variationB?: SharedSliceModelVariation,
|
|
25
25
|
): Partial<VariationMetadata> {
|
|
26
26
|
const zippedVariations = zipObjects(variationA, variationB)
|
|
27
27
|
|
|
@@ -119,8 +119,8 @@ function compareWidgets<TWidget extends NestableModel | GroupModel>(
|
|
|
119
119
|
|
|
120
120
|
export const VariationComparator = {
|
|
121
121
|
compare(
|
|
122
|
-
variationA?:
|
|
123
|
-
variationB?:
|
|
122
|
+
variationA?: SharedSliceModelVariation,
|
|
123
|
+
variationB?: SharedSliceModelVariation,
|
|
124
124
|
): VariationDiff | undefined {
|
|
125
125
|
if (variationA && !variationB)
|
|
126
126
|
return {
|
package/src/model/group.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type NestedGroupModel = z.infer<typeof NestedGroupModelSchema>
|
|
|
31
31
|
|
|
32
32
|
// Group - allows Nestable | NestedGroup in fields (max 2 levels of nesting)
|
|
33
33
|
export const GroupModelSchema = createGroupSchema(
|
|
34
|
-
z.
|
|
34
|
+
z.discriminatedUnion("type", [NestableModelSchema, NestedGroupModelSchema]) as z.ZodMiniType<
|
|
35
35
|
NestableModel | NestedGroupModel
|
|
36
36
|
>,
|
|
37
37
|
)
|
package/src/model/nestable.ts
CHANGED
|
@@ -33,7 +33,7 @@ import { TextModelSchema } from "./text"
|
|
|
33
33
|
import type { TimestampModel } from "./timestamp"
|
|
34
34
|
import { TimestampModelSchema } from "./timestamp"
|
|
35
35
|
|
|
36
|
-
export const NestableModelSchema = z.
|
|
36
|
+
export const NestableModelSchema = z.discriminatedUnion("type", [
|
|
37
37
|
BooleanModelSchema,
|
|
38
38
|
ColorModelSchema,
|
|
39
39
|
DateModelSchema,
|
package/src/model/richText.ts
CHANGED
|
@@ -6,7 +6,7 @@ export const RichTextFieldType = "StructuredText"
|
|
|
6
6
|
|
|
7
7
|
export const DEFAULT_OPTION = "paragraph"
|
|
8
8
|
|
|
9
|
-
export const
|
|
9
|
+
export const RichTextModelNodeType = {
|
|
10
10
|
heading1: "heading1",
|
|
11
11
|
heading2: "heading2",
|
|
12
12
|
heading3: "heading3",
|
|
@@ -25,7 +25,10 @@ export const RichTextNodeType = {
|
|
|
25
25
|
rtl: "rtl",
|
|
26
26
|
} as const
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
export type RichTextModelNodeTypes =
|
|
29
|
+
(typeof RichTextModelNodeType)[keyof typeof RichTextModelNodeType]
|
|
30
|
+
|
|
31
|
+
const VALID_NODE_TYPES = Object.values(RichTextModelNodeType)
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
34
|
* RichTextOptions parses comma-separated node types, filters invalid ones,
|
package/src/model/slice.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
2
|
|
|
3
3
|
import { WidgetKeySchema } from "../common/widgetKey"
|
|
4
|
-
import type { NestedGroupModel } from "./group"
|
|
4
|
+
import type { GroupModel, NestedGroupModel } from "./group"
|
|
5
5
|
import { GroupModelSchema, NestedGroupModelSchema } from "./group"
|
|
6
6
|
import type { NestableModel } from "./nestable"
|
|
7
7
|
import { NestableModelSchema } from "./nestable"
|
|
8
8
|
|
|
9
9
|
// Simple (before 2020)
|
|
10
|
-
export const LegacySliceModelSchema
|
|
10
|
+
export const LegacySliceModelSchema = z.discriminatedUnion("type", [
|
|
11
11
|
NestableModelSchema,
|
|
12
12
|
NestedGroupModelSchema,
|
|
13
13
|
])
|
|
@@ -40,7 +40,7 @@ export const SharedSliceType = "SharedSlice" as const
|
|
|
40
40
|
const IMAGE_PLACEHOLDER_URL =
|
|
41
41
|
"https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format"
|
|
42
42
|
|
|
43
|
-
export const
|
|
43
|
+
export const SharedSliceModelVariationSchema = z.object({
|
|
44
44
|
id: z.string(),
|
|
45
45
|
name: z.string(),
|
|
46
46
|
description: z.string(),
|
|
@@ -51,21 +51,21 @@ export const SharedSliceVariationSchema = z.object({
|
|
|
51
51
|
primary: z.optional(
|
|
52
52
|
z.record(
|
|
53
53
|
z.string(),
|
|
54
|
-
z.
|
|
55
|
-
NestableModel |
|
|
54
|
+
z.discriminatedUnion("type", [NestableModelSchema, GroupModelSchema]) as z.ZodMiniType<
|
|
55
|
+
NestableModel | GroupModel
|
|
56
56
|
>,
|
|
57
57
|
),
|
|
58
58
|
),
|
|
59
59
|
items: z.optional(z.record(z.string(), NestableModelSchema)),
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
-
export type
|
|
62
|
+
export type SharedSliceModelVariation = z.infer<typeof SharedSliceModelVariationSchema>
|
|
63
63
|
|
|
64
64
|
export const SharedSliceModelSchema = z.object({
|
|
65
65
|
id: z.string(),
|
|
66
66
|
type: z.literal(SharedSliceType),
|
|
67
67
|
name: z.string(),
|
|
68
|
-
variations: z.array(
|
|
68
|
+
variations: z.array(SharedSliceModelVariationSchema),
|
|
69
69
|
description: z.optional(z.string()),
|
|
70
70
|
legacyPaths: z.optional(z.record(z.string(), z.string())),
|
|
71
71
|
})
|
|
@@ -84,7 +84,7 @@ export const SharedSliceVariationContentModelSchema = z.object({
|
|
|
84
84
|
type: z.literal(SharedSliceType),
|
|
85
85
|
sliceName: z.string(),
|
|
86
86
|
variationID: z.string(),
|
|
87
|
-
fields: z.pick(
|
|
87
|
+
fields: z.pick(SharedSliceModelVariationSchema, { primary: true, items: true }),
|
|
88
88
|
})
|
|
89
89
|
|
|
90
90
|
export type SharedSliceVariationContentModel = z.infer<
|
|
@@ -94,30 +94,27 @@ export type SharedSliceVariationContentModel = z.infer<
|
|
|
94
94
|
// All
|
|
95
95
|
|
|
96
96
|
// Used when slices reference SharedSlice by ref (not full definition)
|
|
97
|
-
export const DynamicSliceModelSchema: z.ZodMiniType<DynamicSliceModel> = z.
|
|
98
|
-
|
|
99
|
-
LegacySliceModelSchema,
|
|
100
|
-
|
|
101
|
-
])
|
|
97
|
+
export const DynamicSliceModelSchema: z.ZodMiniType<DynamicSliceModel> = z.discriminatedUnion(
|
|
98
|
+
"type",
|
|
99
|
+
[CompositeSliceModelSchema, LegacySliceModelSchema, SharedSliceRefModelSchema],
|
|
100
|
+
)
|
|
102
101
|
|
|
103
102
|
export type DynamicSliceModel = CompositeSliceModel | LegacySliceModel | SharedSliceRefModel
|
|
104
103
|
|
|
105
104
|
// Used when slices include full SharedSlice definition
|
|
106
|
-
export const StaticSliceModelSchema: z.ZodMiniType<StaticSliceModel> = z.
|
|
107
|
-
|
|
108
|
-
LegacySliceModelSchema,
|
|
109
|
-
|
|
110
|
-
])
|
|
105
|
+
export const StaticSliceModelSchema: z.ZodMiniType<StaticSliceModel> = z.discriminatedUnion(
|
|
106
|
+
"type",
|
|
107
|
+
[CompositeSliceModelSchema, LegacySliceModelSchema, SharedSliceModelSchema],
|
|
108
|
+
)
|
|
111
109
|
|
|
112
110
|
export type StaticSliceModel = CompositeSliceModel | LegacySliceModel | SharedSliceModel
|
|
113
111
|
|
|
114
112
|
// Used to represent a slice content model as shared slice variations
|
|
115
113
|
// can only be of a given shared slice variation type.
|
|
116
|
-
export const SliceContentModelSchema: z.ZodMiniType<SliceContentModel> = z.
|
|
117
|
-
|
|
118
|
-
LegacySliceModelSchema,
|
|
119
|
-
|
|
120
|
-
])
|
|
114
|
+
export const SliceContentModelSchema: z.ZodMiniType<SliceContentModel> = z.discriminatedUnion(
|
|
115
|
+
"type",
|
|
116
|
+
[CompositeSliceModelSchema, LegacySliceModelSchema, SharedSliceVariationContentModelSchema],
|
|
117
|
+
)
|
|
121
118
|
|
|
122
119
|
export type SliceContentModel =
|
|
123
120
|
| CompositeSliceModel
|
package/src/model/table.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod/mini"
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { RichTextModelNodeType, type RichTextModel } from "./richText"
|
|
4
4
|
|
|
5
5
|
const TableConfigSchema = z.object({
|
|
6
6
|
label: z.nullish(z.string()),
|
|
@@ -15,10 +15,10 @@ export type TableModel = z.infer<typeof TableModelSchema>
|
|
|
15
15
|
|
|
16
16
|
// TableCell configuration constant (used for cell rich text configuration)
|
|
17
17
|
export const TableCellModelNodeTypes = [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
RichTextModelNodeType.paragraph,
|
|
19
|
+
RichTextModelNodeType.strong,
|
|
20
|
+
RichTextModelNodeType.em,
|
|
21
|
+
RichTextModelNodeType.hyperlink,
|
|
22
22
|
]
|
|
23
23
|
|
|
24
24
|
export const TableCellModel: RichTextModel = {
|
package/src/model/widget.ts
CHANGED
|
@@ -11,22 +11,18 @@ import type { UIDModel } from "./uid"
|
|
|
11
11
|
import { UIDModelSchema } from "./uid"
|
|
12
12
|
|
|
13
13
|
// StaticWidget = UID | Nestable | Group | StaticSlices
|
|
14
|
-
export const StaticWidgetModelSchema: z.ZodMiniType<StaticWidgetModel> = z.
|
|
15
|
-
|
|
16
|
-
NestableModelSchema,
|
|
17
|
-
|
|
18
|
-
StaticSlicesModelSchema,
|
|
19
|
-
])
|
|
14
|
+
export const StaticWidgetModelSchema: z.ZodMiniType<StaticWidgetModel> = z.discriminatedUnion(
|
|
15
|
+
"type",
|
|
16
|
+
[UIDModelSchema, NestableModelSchema, GroupModelSchema, StaticSlicesModelSchema],
|
|
17
|
+
)
|
|
20
18
|
|
|
21
19
|
export type StaticWidgetModel = UIDModel | NestableModel | GroupModel | StaticSlicesModel
|
|
22
20
|
|
|
23
21
|
// DynamicWidget = UID | Nestable | Group | DynamicSlices
|
|
24
|
-
export const DynamicWidgetModelSchema: z.ZodMiniType<DynamicWidgetModel> = z.
|
|
25
|
-
|
|
26
|
-
NestableModelSchema,
|
|
27
|
-
|
|
28
|
-
DynamicSlicesModelSchema,
|
|
29
|
-
])
|
|
22
|
+
export const DynamicWidgetModelSchema: z.ZodMiniType<DynamicWidgetModel> = z.discriminatedUnion(
|
|
23
|
+
"type",
|
|
24
|
+
[UIDModelSchema, NestableModelSchema, GroupModelSchema, DynamicSlicesModelSchema],
|
|
25
|
+
)
|
|
30
26
|
|
|
31
27
|
export type DynamicWidgetModel = UIDModel | NestableModel | GroupModel | DynamicSlicesModel
|
|
32
28
|
|
|
@@ -46,7 +42,6 @@ export const FieldModelTypeSchema = z.enum([
|
|
|
46
42
|
"Text",
|
|
47
43
|
"Timestamp",
|
|
48
44
|
"Link",
|
|
49
|
-
"Repeatable.Link",
|
|
50
45
|
"Image",
|
|
51
46
|
"IntegrationFields",
|
|
52
47
|
"UID",
|
|
@@ -58,6 +53,11 @@ export const FieldModelTypeSchema = z.enum([
|
|
|
58
53
|
export type FieldModelType = z.infer<typeof FieldModelTypeSchema>
|
|
59
54
|
|
|
60
55
|
// Field and slice types
|
|
61
|
-
export const FieldOrSliceTypeSchema = z.union([
|
|
56
|
+
export const FieldOrSliceTypeSchema = z.union([
|
|
57
|
+
FieldModelTypeSchema,
|
|
58
|
+
SliceModelTypeSchema,
|
|
59
|
+
// Repeatable links are "meta" types like slices and shared slices
|
|
60
|
+
z.literal("Repeatable.Link"),
|
|
61
|
+
])
|
|
62
62
|
|
|
63
63
|
export type FieldOrSliceType = z.infer<typeof FieldOrSliceTypeSchema>
|
package/src/zod4.ts
CHANGED
|
@@ -24,9 +24,16 @@ import {
|
|
|
24
24
|
GroupContentSchema as rawGroupContentSchema,
|
|
25
25
|
GroupItemContentSchema as rawGroupItemContentSchema,
|
|
26
26
|
} from "./content/group"
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
ImageContentSchema as rawImageContentSchema,
|
|
29
|
+
ImageContentViewSchema as rawImageContentViewSchema,
|
|
30
|
+
} from "./content/image"
|
|
28
31
|
import { IntegrationFieldContentSchema as rawIntegrationFieldContentSchema } from "./content/integrationField"
|
|
29
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
EmptyLinkContentSchema as rawEmptyLinkContentSchema,
|
|
34
|
+
FilledLinkContentSchema as rawFilledLinkContentSchema,
|
|
35
|
+
LinkContentSchema as rawLinkContentSchema,
|
|
36
|
+
} from "./content/link"
|
|
30
37
|
import { NestableContentSchema as rawNestableContentSchema } from "./content/nestable"
|
|
31
38
|
import { RepeatableContentSchema as rawRepeatableContentSchema } from "./content/repeatable"
|
|
32
39
|
import {
|
|
@@ -56,7 +63,9 @@ import { BooleanModelSchema as rawBooleanModelSchema } from "./model/boolean"
|
|
|
56
63
|
import { ColorModelSchema as rawColorModelSchema } from "./model/color"
|
|
57
64
|
import {
|
|
58
65
|
StaticCustomTypeModelSchema as rawStaticCustomTypeModelSchema,
|
|
59
|
-
|
|
66
|
+
DynamicCustomTypeModelSchema as rawDynamicCustomTypeModelSchema,
|
|
67
|
+
StaticCustomTypeModelTabSchema as rawStaticCustomTypeModelTabSchema,
|
|
68
|
+
DynamicCustomTypeModelTabSchema as rawDynamicCustomTypeModelTabSchema,
|
|
60
69
|
} from "./model/customType"
|
|
61
70
|
import { DateModelSchema as rawDateModelSchema } from "./model/date"
|
|
62
71
|
import { EmbedModelSchema as rawEmbedModelSchema } from "./model/embed"
|
|
@@ -72,16 +81,13 @@ import { NestableModelSchema as rawNestableModelSchema } from "./model/nestable"
|
|
|
72
81
|
import { NumberModelSchema as rawNumberModelSchema } from "./model/number"
|
|
73
82
|
import { RangeModelSchema as rawRangeModelSchema } from "./model/range"
|
|
74
83
|
import { RichTextModelSchema as rawRichTextModelSchema } from "./model/richText"
|
|
75
|
-
import {
|
|
76
|
-
StaticSectionModelSchema as rawStaticSectionModelSchema,
|
|
77
|
-
DynamicSectionModelSchema as rawDynamicSectionModelSchema,
|
|
78
|
-
} from "./model/section"
|
|
79
84
|
import { SelectModelSchema as rawSelectModelSchema } from "./model/select"
|
|
80
85
|
import { SeparatorModelSchema as rawSeparatorModelSchema } from "./model/separator"
|
|
81
86
|
import {
|
|
82
87
|
LegacySliceModelSchema as rawLegacySliceModelSchema,
|
|
83
88
|
CompositeSliceModelSchema as rawCompositeSliceModelSchema,
|
|
84
89
|
SharedSliceModelSchema as rawSharedSliceModelSchema,
|
|
90
|
+
SharedSliceModelVariationSchema as rawSharedSliceModelVariationSchema,
|
|
85
91
|
SharedSliceRefModelSchema as rawSharedSliceRefModelSchema,
|
|
86
92
|
StaticSliceModelSchema as rawStaticSliceModelSchema,
|
|
87
93
|
DynamicSliceModelSchema as rawDynamicSliceModelSchema,
|
|
@@ -113,6 +119,8 @@ export const ColorContentSchema = toZod4(rawColorContentSchema)
|
|
|
113
119
|
export const DateContentSchema = toZod4(rawDateContentSchema)
|
|
114
120
|
export const EmptyContentSchema = toZod4(rawEmptyContentSchema)
|
|
115
121
|
export const GeoPointContentSchema = toZod4(rawGeoPointContentSchema)
|
|
122
|
+
export const FilledLinkContentSchema = toZod4(rawFilledLinkContentSchema)
|
|
123
|
+
export const EmptyLinkContentSchema = toZod4(rawEmptyLinkContentSchema)
|
|
116
124
|
export const LinkContentSchema = toZod4(rawLinkContentSchema)
|
|
117
125
|
export const NumberContentSchema = toZod4(rawNumberContentSchema)
|
|
118
126
|
export const RangeContentSchema = toZod4(rawRangeContentSchema)
|
|
@@ -125,6 +133,7 @@ export const FieldContentSchema = toZod4(rawFieldContentSchema)
|
|
|
125
133
|
export const UIDContentSchema = toZod4(rawUIDContentSchema)
|
|
126
134
|
export const IntegrationFieldContentSchema = toZod4(rawIntegrationFieldContentSchema)
|
|
127
135
|
export const EmbedContentSchema = toZod4(rawEmbedContentSchema)
|
|
136
|
+
export const ImageContentViewSchema = toZod4(rawImageContentViewSchema)
|
|
128
137
|
export const ImageContentSchema = toZod4(rawImageContentSchema)
|
|
129
138
|
export const RichTextContentSchema = toZod4(rawRichTextContentSchema)
|
|
130
139
|
export const RichTextContentBlockSchema = toZod4(rawRichTextContentBlockSchema)
|
|
@@ -167,6 +176,7 @@ export const TimestampModelSchema = toZod4(rawTimestampModelSchema)
|
|
|
167
176
|
export const UIDModelSchema = toZod4(rawUIDModelSchema)
|
|
168
177
|
export const GroupModelSchema = toZod4(rawGroupModelSchema)
|
|
169
178
|
export const NestedGroupModelSchema = toZod4(rawNestedGroupModelSchema)
|
|
179
|
+
export const SharedSliceModelVariationSchema = toZod4(rawSharedSliceModelVariationSchema)
|
|
170
180
|
export const SharedSliceRefModelSchema = toZod4(rawSharedSliceRefModelSchema)
|
|
171
181
|
export const CompositeSliceModelSchema = toZod4(rawCompositeSliceModelSchema)
|
|
172
182
|
export const LegacySliceModelSchema = toZod4(rawLegacySliceModelSchema)
|
|
@@ -177,10 +187,12 @@ export const DynamicSlicesModelSchema = toZod4(rawDynamicSlicesModelSchema)
|
|
|
177
187
|
export const StaticSlicesModelSchema = toZod4(rawStaticSlicesModelSchema)
|
|
178
188
|
export const StaticWidgetModelSchema = toZod4(rawStaticWidgetModelSchema)
|
|
179
189
|
export const DynamicWidgetModelSchema = toZod4(rawDynamicWidgetModelSchema)
|
|
180
|
-
export const
|
|
181
|
-
export const
|
|
190
|
+
export const StaticCustomTypeModelTabSchema = toZod4(rawStaticCustomTypeModelTabSchema)
|
|
191
|
+
export const DynamicCustomTypeModelTabSchema = toZod4(rawDynamicCustomTypeModelTabSchema)
|
|
182
192
|
export const StaticCustomTypeModelSchema = toZod4(rawStaticCustomTypeModelSchema)
|
|
183
|
-
export const
|
|
193
|
+
export const DynamicCustomTypeModelSchema = toZod4(rawDynamicCustomTypeModelSchema)
|
|
194
|
+
/** @deprecated Use DynamicCustomTypeModelSchema instead */
|
|
195
|
+
export const CustomTypeModelSchema = DynamicCustomTypeModelSchema
|
|
184
196
|
|
|
185
197
|
function toZod4<T>(type: T): T {
|
|
186
198
|
return type
|
package/dist/model/section.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { DynamicWidgetModel, StaticWidgetModel } from "./widget.js";
|
|
2
|
-
import { z } from "zod/mini";
|
|
3
|
-
|
|
4
|
-
//#region src/model/section.d.ts
|
|
5
|
-
declare const StaticSectionModelSchema: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniType<StaticWidgetModel, unknown, z.core.$ZodTypeInternals<StaticWidgetModel, unknown>>>;
|
|
6
|
-
type StaticSectionModel = z.infer<typeof StaticSectionModelSchema>;
|
|
7
|
-
declare const DynamicSectionModelSchema: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniType<DynamicWidgetModel, unknown, z.core.$ZodTypeInternals<DynamicWidgetModel, unknown>>>;
|
|
8
|
-
type DynamicSectionModel = z.infer<typeof DynamicSectionModelSchema>;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { DynamicSectionModel, StaticSectionModel };
|
|
11
|
-
//# sourceMappingURL=section.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"section.d.ts","names":[],"sources":["../../src/model/section.ts"],"mappings":";;;;cAMa,wBAAA,EAAwB,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,iBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,iBAAA;AAAA,KACzB,kBAAA,GAAqB,CAAA,CAAE,KAAA,QAAa,wBAAA;AAAA,cAGnC,yBAAA,EAAyB,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,aAAA,UAAA,CAAA,CAAA,WAAA,CAAA,kBAAA,WAAA,CAAA,CAAA,IAAA,CAAA,iBAAA,CAAA,kBAAA;AAAA,KAC1B,mBAAA,GAAsB,CAAA,CAAE,KAAA,QAAa,yBAAA"}
|
package/dist/model/section.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { WidgetKeySchema } from "../common/widgetKey.js";
|
|
2
|
-
import { DynamicWidgetModelSchema, StaticWidgetModelSchema } from "./widget.js";
|
|
3
|
-
import { z } from "zod/mini";
|
|
4
|
-
//#region src/model/section.ts
|
|
5
|
-
const StaticSectionModelSchema = z.record(WidgetKeySchema, StaticWidgetModelSchema);
|
|
6
|
-
const DynamicSectionModelSchema = z.record(WidgetKeySchema, DynamicWidgetModelSchema);
|
|
7
|
-
//#endregion
|
|
8
|
-
export { DynamicSectionModelSchema, StaticSectionModelSchema };
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=section.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"section.js","names":[],"sources":["../../src/model/section.ts"],"sourcesContent":["import { z } from \"zod/mini\"\n\nimport { WidgetKeySchema } from \"../common/widgetKey\"\nimport { DynamicWidgetModelSchema, StaticWidgetModelSchema } from \"./widget\"\n\n// StaticSection = Record<WidgetKey, StaticWidget>\nexport const StaticSectionModelSchema = z.record(WidgetKeySchema, StaticWidgetModelSchema)\nexport type StaticSectionModel = z.infer<typeof StaticSectionModelSchema>\n\n// DynamicSection = Record<WidgetKey, DynamicWidget>\nexport const DynamicSectionModelSchema = z.record(WidgetKeySchema, DynamicWidgetModelSchema)\nexport type DynamicSectionModel = z.infer<typeof DynamicSectionModelSchema>\n"],"mappings":";;;;AAMA,MAAa,2BAA2B,EAAE,OAAO,iBAAiB,wBAAwB;AAI1F,MAAa,4BAA4B,EAAE,OAAO,iBAAiB,yBAAyB"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { GroupModel, NestedGroupModel } from "../model/group"
|
|
2
|
-
import type { NestableModel } from "../model/nestable"
|
|
3
|
-
import { GroupContentType, groupContentWithDefaultValues, GroupContentSchema } from "./group"
|
|
4
|
-
import type { GroupContent } from "./group"
|
|
5
|
-
import { NestableContentDefaultValue } from "./nestable"
|
|
6
|
-
import type { NestableContent } from "./nestable"
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Applies default values to slice primary content (non-repeat zone) based on the model configuration.
|
|
10
|
-
* For each widget in the customType that has no corresponding content, this will add the default value.
|
|
11
|
-
*/
|
|
12
|
-
export function withDefaultSlicePrimaryContentValues(
|
|
13
|
-
customType: Record<string, NestableModel | NestedGroupModel>,
|
|
14
|
-
content: Partial<Record<string, NestableContent | GroupContent>>,
|
|
15
|
-
): Record<string, NestableContent | GroupContent> {
|
|
16
|
-
const updatedContent = content as Record<string, NestableContent | GroupContent>
|
|
17
|
-
|
|
18
|
-
for (const [widgetKey, widgetDef] of Object.entries(customType)) {
|
|
19
|
-
const widgetContent = content[widgetKey]
|
|
20
|
-
|
|
21
|
-
if (widgetContent === undefined) {
|
|
22
|
-
if (widgetDef.type === "Group") {
|
|
23
|
-
updatedContent[widgetKey] = groupContentWithDefaultValues(widgetDef, {
|
|
24
|
-
__TYPE__: GroupContentType,
|
|
25
|
-
value: [],
|
|
26
|
-
})
|
|
27
|
-
} else {
|
|
28
|
-
const defaultValue = NestableContentDefaultValue(widgetDef)
|
|
29
|
-
|
|
30
|
-
if (defaultValue) {
|
|
31
|
-
updatedContent[widgetKey] = defaultValue
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
continue
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const maybeGroupContent = GroupContentSchema.safeParse(widgetContent)
|
|
39
|
-
if (widgetDef.type === "Group" && maybeGroupContent.success) {
|
|
40
|
-
updatedContent[widgetKey] = groupContentWithDefaultValues(widgetDef, maybeGroupContent.data)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return updatedContent
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Applies default values to nestable content based on the model configuration.
|
|
49
|
-
* For each widget in the customType that has no corresponding content, this will add the default value.
|
|
50
|
-
*/
|
|
51
|
-
export function withDefaultNestableContentValues(
|
|
52
|
-
customType: Record<string, NestableModel>,
|
|
53
|
-
content: Record<string, NestableContent>,
|
|
54
|
-
): Record<string, NestableContent> {
|
|
55
|
-
return Object.entries(customType).reduce<Record<string, NestableContent>>(
|
|
56
|
-
(updatedContent, [widgetKey, widgetDef]) => {
|
|
57
|
-
if (content[widgetKey] === undefined) {
|
|
58
|
-
const defaultValue = NestableContentDefaultValue(widgetDef)
|
|
59
|
-
return defaultValue !== undefined
|
|
60
|
-
? {
|
|
61
|
-
...updatedContent,
|
|
62
|
-
[widgetKey]: defaultValue,
|
|
63
|
-
}
|
|
64
|
-
: updatedContent
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return updatedContent
|
|
68
|
-
},
|
|
69
|
-
content,
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Applies default values to repeatable content items (like group items or slice repeat zones).
|
|
75
|
-
* For each item, it ensures all required fields have values based on the model configuration.
|
|
76
|
-
*/
|
|
77
|
-
export function repeatableContentWithDefaultNestableContentValues<
|
|
78
|
-
T extends {
|
|
79
|
-
value: [string, GroupContent | NestableContent][]
|
|
80
|
-
},
|
|
81
|
-
>(fields: Record<string, GroupModel | NestableModel>, content: T[]): T[] {
|
|
82
|
-
const groupKeys = Object.entries(fields)
|
|
83
|
-
return content.map((contentItem) => {
|
|
84
|
-
return groupKeys.reduce((updatedContentItem, [key, fieldDef]) => {
|
|
85
|
-
const maybeContentItemValue = contentItem.value.find(([_key]) => _key === key)
|
|
86
|
-
|
|
87
|
-
if (fieldDef.type === "Group") {
|
|
88
|
-
const defaultValue = groupContentWithDefaultValues(
|
|
89
|
-
fieldDef,
|
|
90
|
-
(maybeContentItemValue?.[1] as GroupContent | undefined) ?? {
|
|
91
|
-
__TYPE__: GroupContentType,
|
|
92
|
-
value: [],
|
|
93
|
-
},
|
|
94
|
-
)
|
|
95
|
-
return {
|
|
96
|
-
...updatedContentItem,
|
|
97
|
-
value: [
|
|
98
|
-
// Since there was default content for the group, we need to remove the old one
|
|
99
|
-
...updatedContentItem.value.filter(([_key]) => _key !== key),
|
|
100
|
-
...(defaultValue ? [[key, defaultValue]] : []),
|
|
101
|
-
],
|
|
102
|
-
}
|
|
103
|
-
} else if (!maybeContentItemValue) {
|
|
104
|
-
const defaultValue = NestableContentDefaultValue(fieldDef)
|
|
105
|
-
return {
|
|
106
|
-
...updatedContentItem,
|
|
107
|
-
value: [...updatedContentItem.value, ...(defaultValue ? [[key, defaultValue]] : [])],
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return updatedContentItem
|
|
112
|
-
}, contentItem)
|
|
113
|
-
})
|
|
114
|
-
}
|
package/src/model/section.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/mini"
|
|
2
|
-
|
|
3
|
-
import { WidgetKeySchema } from "../common/widgetKey"
|
|
4
|
-
import { DynamicWidgetModelSchema, StaticWidgetModelSchema } from "./widget"
|
|
5
|
-
|
|
6
|
-
// StaticSection = Record<WidgetKey, StaticWidget>
|
|
7
|
-
export const StaticSectionModelSchema = z.record(WidgetKeySchema, StaticWidgetModelSchema)
|
|
8
|
-
export type StaticSectionModel = z.infer<typeof StaticSectionModelSchema>
|
|
9
|
-
|
|
10
|
-
// DynamicSection = Record<WidgetKey, DynamicWidget>
|
|
11
|
-
export const DynamicSectionModelSchema = z.record(WidgetKeySchema, DynamicWidgetModelSchema)
|
|
12
|
-
export type DynamicSectionModel = z.infer<typeof DynamicSectionModelSchema>
|