@prismicio/types-internal 2.2.1 → 2.3.0
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/lib/content/Document.d.ts +10 -4
- package/lib/content/Document.js +45 -11
- package/lib/content/fields/GroupContent.d.ts +1 -0
- package/lib/content/fields/GroupContent.js +13 -1
- package/lib/content/fields/nestable/BooleanContent.d.ts +2 -0
- package/lib/content/fields/nestable/BooleanContent.js +11 -1
- package/lib/content/fields/nestable/FieldContent/SelectContent.d.ts +2 -0
- package/lib/content/fields/nestable/FieldContent/SelectContent.js +12 -1
- package/lib/content/fields/nestable/NestableContent.d.ts +2 -0
- package/lib/content/fields/nestable/NestableContent.js +12 -1
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +1 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +13 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +2 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +16 -1
- package/lib/content/fields/slices/SliceItem.d.ts +3 -0
- package/lib/content/fields/slices/SliceItem.js +24 -1
- package/lib/content/fields/slices/SlicesContent.d.ts +1 -0
- package/lib/content/fields/slices/SlicesContent.js +23 -1
- package/lib/content/fields/withDefaultValues.d.ts +6 -0
- package/lib/content/fields/withDefaultValues.js +38 -0
- package/lib/import/converters/Document.d.ts +4 -0
- package/lib/import/converters/Document.js +21 -0
- package/lib/import/converters/fields/Group.d.ts +4 -0
- package/lib/import/converters/fields/Group.js +14 -0
- package/lib/import/converters/fields/RepeatableZone.d.ts +317 -0
- package/lib/import/converters/fields/RepeatableZone.js +15 -0
- package/lib/import/converters/fields/RepeatableZoneItem.d.ts +11 -0
- package/lib/import/converters/fields/RepeatableZoneItem.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
- package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.js +23 -0
- package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
- package/lib/import/converters/fields/Slices/Slices.js +16 -0
- package/lib/import/converters/fields/Slices/index.d.ts +1 -0
- package/lib/import/converters/fields/Slices/index.js +4 -0
- package/lib/import/converters/fields/UID.d.ts +3 -0
- package/lib/import/converters/fields/UID.js +10 -0
- package/lib/import/converters/fields/index.d.ts +4 -0
- package/lib/import/converters/fields/index.js +7 -0
- package/lib/import/converters/fields/nestable/Boolean.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Boolean.js +12 -0
- package/lib/import/converters/fields/nestable/Color.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Color.js +13 -0
- package/lib/import/converters/fields/nestable/Date.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Date.js +15 -0
- package/lib/import/converters/fields/nestable/Embed.d.ts +4 -0
- package/lib/import/converters/fields/nestable/Embed.js +32 -0
- package/lib/import/converters/fields/nestable/GeoPoint.d.ts +3 -0
- package/lib/import/converters/fields/nestable/GeoPoint.js +15 -0
- package/lib/import/converters/fields/nestable/Image.d.ts +28 -0
- package/lib/import/converters/fields/nestable/Image.js +67 -0
- package/lib/import/converters/fields/nestable/Link.d.ts +4 -0
- package/lib/import/converters/fields/nestable/Link.js +70 -0
- package/lib/import/converters/fields/nestable/Nestable.d.ts +5 -0
- package/lib/import/converters/fields/nestable/Nestable.js +35 -0
- package/lib/import/converters/fields/nestable/Number.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Number.js +13 -0
- package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/embedBlock.js +14 -0
- package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/imageBlock.js +12 -0
- package/lib/import/converters/fields/nestable/RichText/index.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/index.js +22 -0
- package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/textBlock.js +54 -0
- package/lib/import/converters/fields/nestable/Select.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Select.js +13 -0
- package/lib/import/converters/fields/nestable/Text.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Text.js +13 -0
- package/lib/import/converters/fields/nestable/Timestamp.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Timestamp.js +13 -0
- package/lib/import/converters/fields/nestable/index.d.ts +13 -0
- package/lib/import/converters/fields/nestable/index.js +16 -0
- package/lib/import/converters/index.d.ts +2 -0
- package/lib/import/converters/index.js +5 -0
- package/lib/import/index.d.ts +2 -0
- package/lib/import/index.js +5 -0
- package/lib/import/validators/Document.d.ts +6 -0
- package/lib/import/validators/Document.js +64 -0
- package/lib/import/validators/fields/ImportContent.d.ts +5 -0
- package/lib/import/validators/fields/ImportContent.js +21 -0
- package/lib/import/validators/fields/ImportField.d.ts +141 -0
- package/lib/import/validators/fields/ImportField.js +33 -0
- package/lib/import/validators/fields/ImportGroup.d.ts +345 -0
- package/lib/import/validators/fields/ImportGroup.js +27 -0
- package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
- package/lib/import/validators/fields/ImportSlices/ImportSlices.js +30 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +16 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +61 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +7 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +342 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
- package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/index.js +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
- package/lib/import/validators/fields/RepeatableZone.d.ts +11 -0
- package/lib/import/validators/fields/RepeatableZone.js +14 -0
- package/lib/import/validators/fields/RepeatableZoneItem.d.ts +11 -0
- package/lib/import/validators/fields/RepeatableZoneItem.js +39 -0
- package/lib/import/validators/fields/UID.d.ts +6 -0
- package/lib/import/validators/fields/UID.js +15 -0
- package/lib/import/validators/fields/index.d.ts +4 -0
- package/lib/import/validators/fields/index.js +7 -0
- package/lib/import/validators/fields/nestable/Boolean.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Boolean.js +6 -0
- package/lib/import/validators/fields/nestable/Color.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Color.js +15 -0
- package/lib/import/validators/fields/nestable/Date.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Date.js +19 -0
- package/lib/import/validators/fields/nestable/Embed.d.ts +13 -0
- package/lib/import/validators/fields/nestable/Embed.js +31 -0
- package/lib/import/validators/fields/nestable/GeoPoint.d.ts +13 -0
- package/lib/import/validators/fields/nestable/GeoPoint.js +13 -0
- package/lib/import/validators/fields/nestable/Image/default.d.ts +22 -0
- package/lib/import/validators/fields/nestable/Image/default.js +19 -0
- package/lib/import/validators/fields/nestable/Image/index.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/index.js +32 -0
- package/lib/import/validators/fields/nestable/Image/merge.d.ts +23 -0
- package/lib/import/validators/fields/nestable/Image/merge.js +44 -0
- package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
- package/lib/import/validators/fields/nestable/Image/model.js +2 -0
- package/lib/import/validators/fields/nestable/Image/validators.d.ts +132 -0
- package/lib/import/validators/fields/nestable/Image/validators.js +43 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +25 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +32 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +11 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +22 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +13 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +78 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +43 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +79 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +27 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +4 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +7 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.d.ts +12 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.js +16 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +15 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +20 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.js +7 -0
- package/lib/import/validators/fields/nestable/Link.d.ts +53 -0
- package/lib/import/validators/fields/nestable/Link.js +35 -0
- package/lib/import/validators/fields/nestable/Nestable.d.ts +192 -0
- package/lib/import/validators/fields/nestable/Nestable.js +71 -0
- package/lib/import/validators/fields/nestable/Number.d.ts +17 -0
- package/lib/import/validators/fields/nestable/Number.js +17 -0
- package/lib/import/validators/fields/nestable/Select.d.ts +16 -0
- package/lib/import/validators/fields/nestable/Select.js +19 -0
- package/lib/import/validators/fields/nestable/Text.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Text.js +6 -0
- package/lib/import/validators/fields/nestable/Timestamp.d.ts +7 -0
- package/lib/import/validators/fields/nestable/Timestamp.js +19 -0
- package/lib/import/validators/fields/nestable/index.d.ts +14 -0
- package/lib/import/validators/fields/nestable/index.js +19 -0
- package/lib/import/validators/index.d.ts +2 -0
- package/lib/import/validators/index.js +5 -0
- package/package.json +1 -1
- package/src/content/Document.ts +68 -14
- package/src/content/fields/GroupContent.ts +16 -0
- package/src/content/fields/nestable/BooleanContent.ts +11 -0
- package/src/content/fields/nestable/FieldContent/SelectContent.ts +12 -1
- package/src/content/fields/nestable/NestableContent.ts +16 -0
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +25 -0
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +32 -1
- package/src/content/fields/slices/SliceItem.ts +43 -1
- package/src/content/fields/slices/SlicesContent.ts +30 -0
- package/src/content/fields/withDefaultValues.ts +48 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { NestableWidget } from "../../../../customtypes";
|
|
2
|
+
import { ImportBoolean } from "./Boolean";
|
|
3
|
+
import { ImportColor } from "./Color";
|
|
4
|
+
import { ImportDate } from "./Date";
|
|
5
|
+
import { ImportEmbed } from "./Embed";
|
|
6
|
+
import { ImportGeoPoint } from "./GeoPoint";
|
|
7
|
+
import { ImportImage } from "./Image";
|
|
8
|
+
import { ImportRichText } from "./ImportRichText";
|
|
9
|
+
import { ImportLink } from "./Link";
|
|
10
|
+
import { ImportNumber } from "./Number";
|
|
11
|
+
import { ImportSelect } from "./Select";
|
|
12
|
+
import { ImportText } from "./Text";
|
|
13
|
+
import { ImportTimestamp } from "./Timestamp";
|
|
14
|
+
export declare type ImportNestable = ImportBoolean | ImportColor | ImportNumber | ImportSelect | ImportText | ImportDate | ImportTimestamp | ImportEmbed | ImportLink | ImportGeoPoint | ImportImage | ImportRichText;
|
|
15
|
+
export declare const ImportNestable: {
|
|
16
|
+
is(u: unknown): u is ImportNestable;
|
|
17
|
+
decode: (field: NestableWidget) => (content: unknown) => {
|
|
18
|
+
codec: import("io-ts").Type<{
|
|
19
|
+
type: "Boolean";
|
|
20
|
+
value: boolean | null;
|
|
21
|
+
}, boolean | undefined, unknown> | import("io-ts").Type<{
|
|
22
|
+
type: "Color";
|
|
23
|
+
value: `#${string}` | null;
|
|
24
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
25
|
+
type: "Date";
|
|
26
|
+
value: Date | null;
|
|
27
|
+
}, Date | undefined, unknown> | import("io-ts").Type<{
|
|
28
|
+
type: "Embed";
|
|
29
|
+
value: {
|
|
30
|
+
embed_url: string;
|
|
31
|
+
} | null;
|
|
32
|
+
}, {
|
|
33
|
+
embed_url: string;
|
|
34
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
35
|
+
type: "GeoPoint";
|
|
36
|
+
value: {
|
|
37
|
+
latitude: number;
|
|
38
|
+
longitude: number;
|
|
39
|
+
} | null;
|
|
40
|
+
}, {
|
|
41
|
+
latitude: number;
|
|
42
|
+
longitude: number;
|
|
43
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
44
|
+
type: "Image";
|
|
45
|
+
value: import("./Image").ImageFieldWithThumbnails | null;
|
|
46
|
+
}, import("./Image").ImageFieldWithThumbnails | undefined, unknown> | import("io-ts").Type<{
|
|
47
|
+
type: "Link";
|
|
48
|
+
value: ({
|
|
49
|
+
link_type: "Web";
|
|
50
|
+
url: string;
|
|
51
|
+
} & {
|
|
52
|
+
target?: string;
|
|
53
|
+
}) | {
|
|
54
|
+
link_type: "Document";
|
|
55
|
+
id: string;
|
|
56
|
+
} | {
|
|
57
|
+
link_type: "Media";
|
|
58
|
+
id: string;
|
|
59
|
+
} | null;
|
|
60
|
+
}, {
|
|
61
|
+
link_type: "Document" | "Web" | "Media";
|
|
62
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
63
|
+
type: "StructuredText";
|
|
64
|
+
value: import("./ImportRichText").ImportBlock[] | null;
|
|
65
|
+
}, import("./ImportRichText").ImportBlock[] | undefined, unknown> | import("io-ts").Type<{
|
|
66
|
+
type: "Number";
|
|
67
|
+
value: number | null;
|
|
68
|
+
}, number | undefined, unknown> | import("io-ts").Type<{
|
|
69
|
+
type: "Select";
|
|
70
|
+
value: string | null;
|
|
71
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
72
|
+
type: "Text";
|
|
73
|
+
value: string | null;
|
|
74
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
75
|
+
type: "Timestamp";
|
|
76
|
+
value: Date | null;
|
|
77
|
+
}, Date | undefined, unknown>;
|
|
78
|
+
result: import("fp-ts/lib/Either").Left<import("io-ts").Errors> | import("fp-ts/lib/Either").Right<{
|
|
79
|
+
type: "Timestamp";
|
|
80
|
+
value: Date | null;
|
|
81
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
82
|
+
type: "Text";
|
|
83
|
+
value: string | null;
|
|
84
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
85
|
+
type: "Select";
|
|
86
|
+
value: string | null;
|
|
87
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
88
|
+
type: "Number";
|
|
89
|
+
value: number | null;
|
|
90
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
91
|
+
type: "StructuredText";
|
|
92
|
+
value: import("./ImportRichText").ImportBlock[] | null;
|
|
93
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
94
|
+
type: "Link";
|
|
95
|
+
value: ({
|
|
96
|
+
link_type: "Web";
|
|
97
|
+
url: string;
|
|
98
|
+
} & {
|
|
99
|
+
target?: string;
|
|
100
|
+
}) | {
|
|
101
|
+
link_type: "Document";
|
|
102
|
+
id: string;
|
|
103
|
+
} | {
|
|
104
|
+
link_type: "Media";
|
|
105
|
+
id: string;
|
|
106
|
+
} | null;
|
|
107
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
108
|
+
type: "Image";
|
|
109
|
+
value: import("./Image").ImageFieldWithThumbnails | null;
|
|
110
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
111
|
+
type: "GeoPoint";
|
|
112
|
+
value: {
|
|
113
|
+
latitude: number;
|
|
114
|
+
longitude: number;
|
|
115
|
+
} | null;
|
|
116
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
117
|
+
type: "Embed";
|
|
118
|
+
value: {
|
|
119
|
+
embed_url: string;
|
|
120
|
+
} | null;
|
|
121
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
122
|
+
type: "Date";
|
|
123
|
+
value: Date | null;
|
|
124
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
125
|
+
type: "Color";
|
|
126
|
+
value: `#${string}` | null;
|
|
127
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
128
|
+
type: "Boolean";
|
|
129
|
+
value: boolean | null;
|
|
130
|
+
}>;
|
|
131
|
+
};
|
|
132
|
+
getCodec: (field: NestableWidget) => import("io-ts").Type<{
|
|
133
|
+
type: "Boolean";
|
|
134
|
+
value: boolean | null;
|
|
135
|
+
}, boolean | undefined, unknown> | import("io-ts").Type<{
|
|
136
|
+
type: "Color";
|
|
137
|
+
value: `#${string}` | null;
|
|
138
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
139
|
+
type: "Date";
|
|
140
|
+
value: Date | null;
|
|
141
|
+
}, Date | undefined, unknown> | import("io-ts").Type<{
|
|
142
|
+
type: "Embed";
|
|
143
|
+
value: {
|
|
144
|
+
embed_url: string;
|
|
145
|
+
} | null;
|
|
146
|
+
}, {
|
|
147
|
+
embed_url: string;
|
|
148
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
149
|
+
type: "GeoPoint";
|
|
150
|
+
value: {
|
|
151
|
+
latitude: number;
|
|
152
|
+
longitude: number;
|
|
153
|
+
} | null;
|
|
154
|
+
}, {
|
|
155
|
+
latitude: number;
|
|
156
|
+
longitude: number;
|
|
157
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
158
|
+
type: "Image";
|
|
159
|
+
value: import("./Image").ImageFieldWithThumbnails | null;
|
|
160
|
+
}, import("./Image").ImageFieldWithThumbnails | undefined, unknown> | import("io-ts").Type<{
|
|
161
|
+
type: "Link";
|
|
162
|
+
value: ({
|
|
163
|
+
link_type: "Web";
|
|
164
|
+
url: string;
|
|
165
|
+
} & {
|
|
166
|
+
target?: string;
|
|
167
|
+
}) | {
|
|
168
|
+
link_type: "Document";
|
|
169
|
+
id: string;
|
|
170
|
+
} | {
|
|
171
|
+
link_type: "Media";
|
|
172
|
+
id: string;
|
|
173
|
+
} | null;
|
|
174
|
+
}, {
|
|
175
|
+
link_type: "Document" | "Web" | "Media";
|
|
176
|
+
} | undefined, unknown> | import("io-ts").Type<{
|
|
177
|
+
type: "StructuredText";
|
|
178
|
+
value: import("./ImportRichText").ImportBlock[] | null;
|
|
179
|
+
}, import("./ImportRichText").ImportBlock[] | undefined, unknown> | import("io-ts").Type<{
|
|
180
|
+
type: "Number";
|
|
181
|
+
value: number | null;
|
|
182
|
+
}, number | undefined, unknown> | import("io-ts").Type<{
|
|
183
|
+
type: "Select";
|
|
184
|
+
value: string | null;
|
|
185
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
186
|
+
type: "Text";
|
|
187
|
+
value: string | null;
|
|
188
|
+
}, string | undefined, unknown> | import("io-ts").Type<{
|
|
189
|
+
type: "Timestamp";
|
|
190
|
+
value: Date | null;
|
|
191
|
+
}, Date | undefined, unknown>;
|
|
192
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportNestable = void 0;
|
|
4
|
+
const Boolean_1 = require("./Boolean");
|
|
5
|
+
const Color_1 = require("./Color");
|
|
6
|
+
const Date_1 = require("./Date");
|
|
7
|
+
const Embed_1 = require("./Embed");
|
|
8
|
+
const GeoPoint_1 = require("./GeoPoint");
|
|
9
|
+
const Image_1 = require("./Image");
|
|
10
|
+
const ImportRichText_1 = require("./ImportRichText");
|
|
11
|
+
const Link_1 = require("./Link");
|
|
12
|
+
const Number_1 = require("./Number");
|
|
13
|
+
const Select_1 = require("./Select");
|
|
14
|
+
const Text_1 = require("./Text");
|
|
15
|
+
const Timestamp_1 = require("./Timestamp");
|
|
16
|
+
const getCodecOrThrow = (field) => {
|
|
17
|
+
switch (field.type) {
|
|
18
|
+
case "Boolean":
|
|
19
|
+
return Boolean_1.ImportBoolean;
|
|
20
|
+
case "Color":
|
|
21
|
+
return Color_1.ImportColor;
|
|
22
|
+
case "Number":
|
|
23
|
+
return (0, Number_1.ImportNumber)(field);
|
|
24
|
+
case "Select":
|
|
25
|
+
return (0, Select_1.ImportSelect)(field);
|
|
26
|
+
case "Text":
|
|
27
|
+
return Text_1.ImportText;
|
|
28
|
+
case "Date":
|
|
29
|
+
return Date_1.ImportDate;
|
|
30
|
+
case "Timestamp":
|
|
31
|
+
return Timestamp_1.ImportTimestamp;
|
|
32
|
+
case "Embed":
|
|
33
|
+
return Embed_1.ImportEmbed;
|
|
34
|
+
case "Link":
|
|
35
|
+
return Link_1.ImportLink;
|
|
36
|
+
case "Image":
|
|
37
|
+
return (0, Image_1.ImportImage)(field);
|
|
38
|
+
case "GeoPoint":
|
|
39
|
+
return GeoPoint_1.ImportGeoPoint;
|
|
40
|
+
case "StructuredText":
|
|
41
|
+
return (0, ImportRichText_1.ImportRichText)(field);
|
|
42
|
+
default:
|
|
43
|
+
throw new Error(`Unsupported type of nestable field ${field.type}`);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.ImportNestable = {
|
|
47
|
+
is(u) {
|
|
48
|
+
return (Boolean_1.ImportBoolean.is(u) ||
|
|
49
|
+
Color_1.ImportColor.is(u) ||
|
|
50
|
+
(0, Number_1.ImportNumber)().is(u) ||
|
|
51
|
+
(0, Select_1.ImportSelect)().is(u) ||
|
|
52
|
+
Text_1.ImportText.is(u) ||
|
|
53
|
+
Date_1.ImportDate.is(u) ||
|
|
54
|
+
Timestamp_1.ImportTimestamp.is(u) ||
|
|
55
|
+
Embed_1.ImportEmbed.is(u) ||
|
|
56
|
+
Link_1.ImportLink.is(u) ||
|
|
57
|
+
GeoPoint_1.ImportGeoPoint.is(u) ||
|
|
58
|
+
(0, Image_1.ImportImage)().is(u) ||
|
|
59
|
+
(0, ImportRichText_1.ImportRichText)().is(u));
|
|
60
|
+
},
|
|
61
|
+
decode: (field) => {
|
|
62
|
+
return (content) => {
|
|
63
|
+
const codec = getCodecOrThrow(field);
|
|
64
|
+
return {
|
|
65
|
+
codec,
|
|
66
|
+
result: codec.decode(content),
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
getCodec: getCodecOrThrow,
|
|
71
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const ImportNumber: (field?: ({
|
|
3
|
+
type: "Number";
|
|
4
|
+
} & {
|
|
5
|
+
fieldset?: string | null | undefined;
|
|
6
|
+
config?: {
|
|
7
|
+
label?: string | null | undefined;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
min?: number;
|
|
10
|
+
max?: number;
|
|
11
|
+
step?: number;
|
|
12
|
+
};
|
|
13
|
+
}) | undefined) => t.Type<{
|
|
14
|
+
type: "Number";
|
|
15
|
+
value: number | null;
|
|
16
|
+
}, number | undefined, unknown>;
|
|
17
|
+
export declare type ImportNumber = t.TypeOf<ReturnType<typeof ImportNumber>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportNumber = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const validators_1 = require("../../../../validators");
|
|
7
|
+
const ImportContent_1 = require("../ImportContent");
|
|
8
|
+
const numberValue = (config) => validators_1.Number.pipe(new t.Type("ImportNumberValue", (u) => validators_1.Number.is(u), (n, c) => {
|
|
9
|
+
const min = config === null || config === void 0 ? void 0 : config.min;
|
|
10
|
+
const max = config === null || config === void 0 ? void 0 : config.max;
|
|
11
|
+
if ((min !== undefined && n < min) || (max !== undefined && n > max)) {
|
|
12
|
+
return t.failure(n, c, `The value must be between [${min !== undefined ? min : ""}, ${max !== undefined ? max : ""}]`);
|
|
13
|
+
}
|
|
14
|
+
return t.success(n);
|
|
15
|
+
}, t.identity));
|
|
16
|
+
const ImportNumber = (field) => (0, ImportContent_1.ImportContent)("Number", (0, validators_1.NullOrElse)(numberValue(field === null || field === void 0 ? void 0 : field.config)));
|
|
17
|
+
exports.ImportNumber = ImportNumber;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const ImportSelect: (field?: ({
|
|
3
|
+
type: "Select";
|
|
4
|
+
} & {
|
|
5
|
+
fieldset?: string | null | undefined;
|
|
6
|
+
config?: {
|
|
7
|
+
label?: string | null | undefined;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
default_value?: string;
|
|
10
|
+
options?: readonly string[];
|
|
11
|
+
};
|
|
12
|
+
}) | undefined) => t.Type<{
|
|
13
|
+
type: "Select";
|
|
14
|
+
value: string | null;
|
|
15
|
+
}, string | undefined, unknown>;
|
|
16
|
+
export declare type ImportSelect = t.TypeOf<ReturnType<typeof ImportSelect>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportSelect = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const validators_1 = require("../../../../validators");
|
|
7
|
+
const ImportContent_1 = require("../ImportContent");
|
|
8
|
+
const selectValue = (config) => validators_1.String.pipe(new t.Type("ImportSelectValue", (u) => validators_1.String.is(u), (s, c) => {
|
|
9
|
+
var _a;
|
|
10
|
+
if (!(config === null || config === void 0 ? void 0 : config.options)) {
|
|
11
|
+
return t.failure(s, c, "The value must be defined in the custom type's configuration of the field");
|
|
12
|
+
}
|
|
13
|
+
if (!config.options.includes(s)) {
|
|
14
|
+
return t.failure(s, c, `The value must be one of these: ${(_a = config.options) === null || _a === void 0 ? void 0 : _a.join(",")}`);
|
|
15
|
+
}
|
|
16
|
+
return t.success(s);
|
|
17
|
+
}, t.identity));
|
|
18
|
+
const ImportSelect = (field) => (0, ImportContent_1.ImportContent)("Select", (0, validators_1.NullOrElse)(selectValue(field === null || field === void 0 ? void 0 : field.config)));
|
|
19
|
+
exports.ImportSelect = ImportSelect;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportText = void 0;
|
|
4
|
+
const validators_1 = require("../../../../validators");
|
|
5
|
+
const ImportContent_1 = require("../ImportContent");
|
|
6
|
+
exports.ImportText = (0, ImportContent_1.ImportContent)("Text", (0, validators_1.NullOrElse)(validators_1.String));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const TIMESTAMP_INPUT_REGEX: RegExp;
|
|
3
|
+
export declare const ImportTimestamp: t.Type<{
|
|
4
|
+
type: "Timestamp";
|
|
5
|
+
value: Date | null;
|
|
6
|
+
}, Date | undefined, unknown>;
|
|
7
|
+
export declare type ImportTimestamp = t.TypeOf<typeof ImportTimestamp>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportTimestamp = exports.TIMESTAMP_INPUT_REGEX = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Either_1 = require("fp-ts/Either");
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const validators_1 = require("../../../../validators");
|
|
9
|
+
const ImportContent_1 = require("../ImportContent");
|
|
10
|
+
exports.TIMESTAMP_INPUT_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:(?:[+-]{1}\d{2}:?\d{2})|Z)$/;
|
|
11
|
+
const timestampValue = new t.Type("ImportTimestampValue", (u) => u instanceof Date, (u, c) => (0, function_1.pipe)(validators_1.String.validate(u, c), (0, Either_1.chain)((s) => {
|
|
12
|
+
const date = new Date(s);
|
|
13
|
+
const isInvalidDate = isNaN(date.getTime());
|
|
14
|
+
if (isInvalidDate || !exports.TIMESTAMP_INPUT_REGEX.test(s)) {
|
|
15
|
+
return t.failure(u, c, "The value must be a DateTime in the format YYYY-MM-DDTHH:MM:SS+0000");
|
|
16
|
+
}
|
|
17
|
+
return t.success(date);
|
|
18
|
+
})), t.identity);
|
|
19
|
+
exports.ImportTimestamp = (0, ImportContent_1.ImportContent)("Timestamp", (0, validators_1.NullOrElse)(timestampValue));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./Boolean";
|
|
2
|
+
export * from "./Color";
|
|
3
|
+
export * from "./Date";
|
|
4
|
+
export { ImportEmbed } from "./Embed";
|
|
5
|
+
export * from "./GeoPoint";
|
|
6
|
+
export * from "./Image";
|
|
7
|
+
export * from "./Image/index";
|
|
8
|
+
export * from "./ImportRichText";
|
|
9
|
+
export * from "./Link";
|
|
10
|
+
export * from "./Nestable";
|
|
11
|
+
export * from "./Number";
|
|
12
|
+
export * from "./Select";
|
|
13
|
+
export * from "./Text";
|
|
14
|
+
export * from "./Timestamp";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportEmbed = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./Boolean"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./Color"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./Date"), exports);
|
|
8
|
+
var Embed_1 = require("./Embed");
|
|
9
|
+
Object.defineProperty(exports, "ImportEmbed", { enumerable: true, get: function () { return Embed_1.ImportEmbed; } });
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./GeoPoint"), exports);
|
|
11
|
+
(0, tslib_1.__exportStar)(require("./Image"), exports);
|
|
12
|
+
(0, tslib_1.__exportStar)(require("./Image/index"), exports);
|
|
13
|
+
(0, tslib_1.__exportStar)(require("./ImportRichText"), exports);
|
|
14
|
+
(0, tslib_1.__exportStar)(require("./Link"), exports);
|
|
15
|
+
(0, tslib_1.__exportStar)(require("./Nestable"), exports);
|
|
16
|
+
(0, tslib_1.__exportStar)(require("./Number"), exports);
|
|
17
|
+
(0, tslib_1.__exportStar)(require("./Select"), exports);
|
|
18
|
+
(0, tslib_1.__exportStar)(require("./Text"), exports);
|
|
19
|
+
(0, tslib_1.__exportStar)(require("./Timestamp"), exports);
|
package/package.json
CHANGED
package/src/content/Document.ts
CHANGED
|
@@ -13,10 +13,16 @@ import {
|
|
|
13
13
|
type StaticWidget,
|
|
14
14
|
collectSharedSlices,
|
|
15
15
|
flattenSections,
|
|
16
|
+
NestableWidget,
|
|
16
17
|
StaticCustomType,
|
|
17
18
|
} from "../customtypes"
|
|
18
19
|
import {
|
|
20
|
+
groupContentWithDefaultValues,
|
|
21
|
+
isGroupContent,
|
|
22
|
+
isSlicesContent,
|
|
19
23
|
migrateSliceItem,
|
|
24
|
+
NestableContentDefaultValue,
|
|
25
|
+
slicesContentWithDefaultValues,
|
|
20
26
|
traverseGroupContent,
|
|
21
27
|
traverseSlices,
|
|
22
28
|
WidgetContent,
|
|
@@ -157,12 +163,70 @@ export const DocumentLegacy = {
|
|
|
157
163
|
encode: encodeToLegacyDocument,
|
|
158
164
|
}
|
|
159
165
|
|
|
166
|
+
function simplifyCustomType(customType: StaticCustomType): {
|
|
167
|
+
customTypeId: string
|
|
168
|
+
fields: Record<string, StaticWidget>
|
|
169
|
+
} {
|
|
170
|
+
return {
|
|
171
|
+
customTypeId: customType?.id,
|
|
172
|
+
fields: Object.fromEntries(flattenSections(customType)),
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function fillDocumentWithDefaultValues(
|
|
177
|
+
customType:
|
|
178
|
+
| StaticCustomType
|
|
179
|
+
| {
|
|
180
|
+
customTypeId: string
|
|
181
|
+
fields: Record<string, StaticWidget>
|
|
182
|
+
},
|
|
183
|
+
document: Document,
|
|
184
|
+
): Document {
|
|
185
|
+
const { fields } =
|
|
186
|
+
customType && StaticCustomType.is(customType)
|
|
187
|
+
? simplifyCustomType(customType)
|
|
188
|
+
: customType
|
|
189
|
+
|
|
190
|
+
return Object.entries(fields).reduce<Document>(
|
|
191
|
+
(updatedDocument, [fieldKey, fieldDef]) => {
|
|
192
|
+
const fieldContent = document[fieldKey]
|
|
193
|
+
|
|
194
|
+
const updatedField = (() => {
|
|
195
|
+
switch (fieldDef.type) {
|
|
196
|
+
case "Group":
|
|
197
|
+
return isGroupContent(fieldContent)
|
|
198
|
+
? groupContentWithDefaultValues(fieldDef, fieldContent)
|
|
199
|
+
: fieldContent
|
|
200
|
+
case "Choice":
|
|
201
|
+
case "Slices":
|
|
202
|
+
return isSlicesContent(fieldContent)
|
|
203
|
+
? slicesContentWithDefaultValues(fieldDef, fieldContent)
|
|
204
|
+
: fieldContent
|
|
205
|
+
default:
|
|
206
|
+
return fieldContent === undefined && NestableWidget.is(fieldDef)
|
|
207
|
+
? NestableContentDefaultValue(fieldDef)
|
|
208
|
+
: fieldContent
|
|
209
|
+
}
|
|
210
|
+
})()
|
|
211
|
+
|
|
212
|
+
return updatedField
|
|
213
|
+
? {
|
|
214
|
+
...updatedDocument,
|
|
215
|
+
[fieldKey]: updatedField,
|
|
216
|
+
}
|
|
217
|
+
: updatedDocument
|
|
218
|
+
},
|
|
219
|
+
document,
|
|
220
|
+
)
|
|
221
|
+
}
|
|
160
222
|
/**
|
|
161
|
-
*
|
|
162
|
-
*
|
|
223
|
+
* @param model: Can be optional if we simply want to loop through the content
|
|
224
|
+
* without any consideration for the attached model
|
|
163
225
|
* @param document: The content we actually want to iterate on in an immutable fashion
|
|
164
|
-
* @param transform: A user function that provides a way to transform any kind
|
|
165
|
-
*
|
|
226
|
+
* @param transform: A user function that provides a way to transform any kind
|
|
227
|
+
* of content wherever it is in a structured Prismic object content.
|
|
228
|
+
* @returns A transformed document with the user's transformation applied with
|
|
229
|
+
* the transform function
|
|
166
230
|
*/
|
|
167
231
|
export function traverseDocument({
|
|
168
232
|
document,
|
|
@@ -247,16 +311,6 @@ export function traverseDocument({
|
|
|
247
311
|
}
|
|
248
312
|
}
|
|
249
313
|
|
|
250
|
-
function simplifyCustomType(customType: StaticCustomType): {
|
|
251
|
-
customTypeId: string
|
|
252
|
-
fields: Record<string, StaticWidget>
|
|
253
|
-
} {
|
|
254
|
-
return {
|
|
255
|
-
customTypeId: customType?.id,
|
|
256
|
-
fields: Object.fromEntries(flattenSections(customType)),
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
314
|
// /**
|
|
261
315
|
// * The goal is to be able to collect all widgets or slices of a given type at any level of nesting inside a prismic content
|
|
262
316
|
// *
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
} from "../LegacyContentCtx"
|
|
17
17
|
import { hasContentType } from "../utils"
|
|
18
18
|
import { isNestableContent, NestableContent, NestableLegacy } from "./nestable"
|
|
19
|
+
import { repeatableContentWithDefaultNestableContentValues } from "./withDefaultValues"
|
|
19
20
|
|
|
20
21
|
export const GroupItemContentType = "GroupItemContent" as const
|
|
21
22
|
|
|
@@ -123,6 +124,21 @@ export const GroupContent = t.strict({
|
|
|
123
124
|
})
|
|
124
125
|
export type GroupContent = t.TypeOf<typeof GroupContent>
|
|
125
126
|
|
|
127
|
+
export function groupContentWithDefaultValues(
|
|
128
|
+
customType: Group,
|
|
129
|
+
content: GroupContent,
|
|
130
|
+
): GroupContent {
|
|
131
|
+
const fields = customType.config?.fields
|
|
132
|
+
if (!fields) return content
|
|
133
|
+
return {
|
|
134
|
+
...content,
|
|
135
|
+
value: repeatableContentWithDefaultNestableContentValues(
|
|
136
|
+
fields,
|
|
137
|
+
content.value,
|
|
138
|
+
),
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
126
142
|
export function traverseGroupContent({
|
|
127
143
|
path,
|
|
128
144
|
key,
|
|
@@ -2,6 +2,7 @@ import { either } from "fp-ts"
|
|
|
2
2
|
import { pipe } from "fp-ts/lib/function"
|
|
3
3
|
import * as t from "io-ts"
|
|
4
4
|
|
|
5
|
+
import type { BooleanField } from "../../../customtypes"
|
|
5
6
|
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
|
|
6
7
|
import { hasContentType } from "../../utils"
|
|
7
8
|
|
|
@@ -38,3 +39,13 @@ export const BooleanContent = t.strict({
|
|
|
38
39
|
})
|
|
39
40
|
|
|
40
41
|
export type BooleanContent = t.TypeOf<typeof BooleanContent>
|
|
42
|
+
|
|
43
|
+
export const BooleanContentDefaultValue = (
|
|
44
|
+
field: BooleanField,
|
|
45
|
+
): BooleanContent | undefined =>
|
|
46
|
+
field.config?.default_value !== undefined
|
|
47
|
+
? {
|
|
48
|
+
__TYPE__: BooleanContentType,
|
|
49
|
+
value: field.config.default_value || false,
|
|
50
|
+
}
|
|
51
|
+
: undefined
|
|
@@ -2,7 +2,7 @@ import { either } from "fp-ts"
|
|
|
2
2
|
import { pipe } from "fp-ts/lib/function"
|
|
3
3
|
import * as t from "io-ts"
|
|
4
4
|
|
|
5
|
-
import { SelectFieldType } from "../../../../customtypes/widgets"
|
|
5
|
+
import { Select, SelectFieldType } from "../../../../customtypes/widgets"
|
|
6
6
|
import TrimmedString from "../../../../validators/TrimmedString"
|
|
7
7
|
import type { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx"
|
|
8
8
|
import { hasContentType, hasFieldContentType } from "../../../utils"
|
|
@@ -46,3 +46,14 @@ export const SelectContent = t.strict({
|
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
export type SelectContent = t.TypeOf<typeof SelectContent>
|
|
49
|
+
|
|
50
|
+
export const SelectContentDefaultValue = (
|
|
51
|
+
field: Select,
|
|
52
|
+
): SelectContent | undefined =>
|
|
53
|
+
field.config?.default_value
|
|
54
|
+
? {
|
|
55
|
+
__TYPE__: FieldContentType,
|
|
56
|
+
type: SelectFieldType,
|
|
57
|
+
value: field.config.default_value || "",
|
|
58
|
+
}
|
|
59
|
+
: undefined
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { isRight } from "fp-ts/lib/Either"
|
|
2
2
|
import * as t from "io-ts"
|
|
3
3
|
|
|
4
|
+
import type { NestableWidget } from "../../../customtypes"
|
|
4
5
|
import type { LegacyContentCtx } from "../../LegacyContentCtx"
|
|
5
6
|
import { EmptyContent, EmptyLegacy, isEmptyContent } from "../EmptyContent"
|
|
6
7
|
import {
|
|
7
8
|
BooleanContent,
|
|
9
|
+
BooleanContentDefaultValue,
|
|
8
10
|
BooleanContentType,
|
|
9
11
|
BooleanLegacy,
|
|
10
12
|
isBooleanContent,
|
|
@@ -32,6 +34,7 @@ import {
|
|
|
32
34
|
RangeContent,
|
|
33
35
|
RangeLegacy,
|
|
34
36
|
SelectContent,
|
|
37
|
+
SelectContentDefaultValue,
|
|
35
38
|
SelectLegacy,
|
|
36
39
|
TextContent,
|
|
37
40
|
TextLegacy,
|
|
@@ -97,6 +100,19 @@ export const NestableContent = t.union([
|
|
|
97
100
|
export type NestableContent = t.TypeOf<typeof NestableContent>
|
|
98
101
|
export type NestableContentType = NestableContent["__TYPE__"]
|
|
99
102
|
|
|
103
|
+
export const NestableContentDefaultValue = (
|
|
104
|
+
widgetDef: NestableWidget,
|
|
105
|
+
): NestableContent | undefined => {
|
|
106
|
+
switch (widgetDef.type) {
|
|
107
|
+
case "Boolean":
|
|
108
|
+
return BooleanContentDefaultValue(widgetDef)
|
|
109
|
+
case "Select":
|
|
110
|
+
return SelectContentDefaultValue(widgetDef)
|
|
111
|
+
default:
|
|
112
|
+
return undefined
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
100
116
|
export const isNestableContent = (u: unknown): u is NestableContent =>
|
|
101
117
|
isTextContent(u) ||
|
|
102
118
|
isColorContent(u) ||
|