@prismicio/types-internal 0.1.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/LICENSE +202 -0
- package/README.md +110 -0
- package/dist/customtypes/index.cjs +864 -0
- package/dist/customtypes/index.cjs.map +1 -0
- package/dist/customtypes/index.d.ts +18433 -0
- package/dist/customtypes/index.d.ts.map +1 -0
- package/dist/customtypes/index.js +864 -0
- package/dist/customtypes/index.js.map +1 -0
- package/dist/customtypes/widgets/index.cjs +735 -0
- package/dist/customtypes/widgets/index.cjs.map +1 -0
- package/dist/customtypes/widgets/index.d.ts +11697 -0
- package/dist/customtypes/widgets/index.d.ts.map +1 -0
- package/dist/customtypes/widgets/index.js +735 -0
- package/dist/customtypes/widgets/index.js.map +1 -0
- package/dist/customtypes/widgets/slices/index.cjs +671 -0
- package/dist/customtypes/widgets/slices/index.cjs.map +1 -0
- package/dist/customtypes/widgets/slices/index.d.ts +7079 -0
- package/dist/customtypes/widgets/slices/index.d.ts.map +1 -0
- package/dist/customtypes/widgets/slices/index.js +671 -0
- package/dist/customtypes/widgets/slices/index.js.map +1 -0
- package/dist/index.cjs +870 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +18455 -0
- package/dist/index.js +844 -0
- package/dist/index.js.map +1 -0
- package/package.json +84 -0
- package/src/customtypes/CustomType.ts +142 -0
- package/src/customtypes/Format.ts +4 -0
- package/src/customtypes/Section.ts +25 -0
- package/src/customtypes/index.ts +4 -0
- package/src/customtypes/widgets/Group.ts +30 -0
- package/src/customtypes/widgets/UID.ts +27 -0
- package/src/customtypes/widgets/Widget.ts +33 -0
- package/src/customtypes/widgets/WidgetTypes.ts +24 -0
- package/src/customtypes/widgets/index.ts +7 -0
- package/src/customtypes/widgets/nestable/BooleanField.ts +30 -0
- package/src/customtypes/widgets/nestable/Color.ts +26 -0
- package/src/customtypes/widgets/nestable/Date.ts +27 -0
- package/src/customtypes/widgets/nestable/Embed.ts +27 -0
- package/src/customtypes/widgets/nestable/GeoPoint.ts +25 -0
- package/src/customtypes/widgets/nestable/Image.ts +40 -0
- package/src/customtypes/widgets/nestable/IntegrationField.ts +27 -0
- package/src/customtypes/widgets/nestable/Link.ts +85 -0
- package/src/customtypes/widgets/nestable/NestableWidget.ts +39 -0
- package/src/customtypes/widgets/nestable/Number.ts +30 -0
- package/src/customtypes/widgets/nestable/Range.ts +30 -0
- package/src/customtypes/widgets/nestable/RichText.ts +160 -0
- package/src/customtypes/widgets/nestable/Select.ts +32 -0
- package/src/customtypes/widgets/nestable/Separator.ts +24 -0
- package/src/customtypes/widgets/nestable/Text.ts +27 -0
- package/src/customtypes/widgets/nestable/Timestamp.ts +27 -0
- package/src/customtypes/widgets/nestable/index.ts +15 -0
- package/src/customtypes/widgets/shared/ImageConstraint.ts +39 -0
- package/src/customtypes/widgets/shared/index.ts +1 -0
- package/src/customtypes/widgets/slices/CompositeSlice.ts +32 -0
- package/src/customtypes/widgets/slices/LegacySlice.ts +15 -0
- package/src/customtypes/widgets/slices/SharedSlice.ts +44 -0
- package/src/customtypes/widgets/slices/SharedSliceRef.ts +12 -0
- package/src/customtypes/widgets/slices/Slice.ts +7 -0
- package/src/customtypes/widgets/slices/Slices.ts +100 -0
- package/src/customtypes/widgets/slices/SlicesTypes.ts +6 -0
- package/src/customtypes/widgets/slices/index.ts +7 -0
- package/src/index.ts +1 -0
- package/src/validators/IntFromNumber.ts +24 -0
- package/src/validators/IntFromPixels.ts +31 -0
- package/src/validators/StringFromBoolean.ts +21 -0
- package/src/validators/StringFromNumber.ts +21 -0
- package/src/validators/StringOrNull.ts +3 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { StringOrNull } from '../../../validators/StringOrNull'
|
|
3
|
+
import WidgetTypes from '../WidgetTypes'
|
|
4
|
+
import ImageConstraint from '../shared/ImageConstraint'
|
|
5
|
+
|
|
6
|
+
const Thumbnail = t.exact(
|
|
7
|
+
t.intersection([
|
|
8
|
+
t.type({
|
|
9
|
+
name: t.string
|
|
10
|
+
}),
|
|
11
|
+
ImageConstraint
|
|
12
|
+
])
|
|
13
|
+
)
|
|
14
|
+
type Thumbnail = t.TypeOf<typeof Thumbnail>
|
|
15
|
+
|
|
16
|
+
const ImageConfig = t.exact(
|
|
17
|
+
t.partial({
|
|
18
|
+
label: StringOrNull,
|
|
19
|
+
placeholder: t.string,
|
|
20
|
+
constraint: ImageConstraint,
|
|
21
|
+
thumbnails: t.array(Thumbnail)
|
|
22
|
+
})
|
|
23
|
+
)
|
|
24
|
+
type ImageConfig = t.TypeOf<typeof ImageConfig>
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const Image = t.exact(
|
|
28
|
+
t.intersection([
|
|
29
|
+
t.type({
|
|
30
|
+
type: t.literal(WidgetTypes.Image)
|
|
31
|
+
}),
|
|
32
|
+
t.partial({
|
|
33
|
+
fieldset: StringOrNull,
|
|
34
|
+
config: ImageConfig
|
|
35
|
+
})
|
|
36
|
+
])
|
|
37
|
+
)
|
|
38
|
+
type Image = t.TypeOf<typeof Image>
|
|
39
|
+
|
|
40
|
+
export default Image
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { StringOrNull } from '../../../validators/StringOrNull'
|
|
3
|
+
import WidgetTypes from '../WidgetTypes'
|
|
4
|
+
|
|
5
|
+
const IntegrationFieldConfig = t.exact(
|
|
6
|
+
t.partial({
|
|
7
|
+
label: StringOrNull,
|
|
8
|
+
placeholder: t.string,
|
|
9
|
+
catalog: t.string
|
|
10
|
+
})
|
|
11
|
+
)
|
|
12
|
+
type IntegrationFieldConfig = t.TypeOf<typeof IntegrationFieldConfig>
|
|
13
|
+
|
|
14
|
+
const IntegrationField = t.exact(
|
|
15
|
+
t.intersection([
|
|
16
|
+
t.type({
|
|
17
|
+
type: t.literal(WidgetTypes.IntegrationField)
|
|
18
|
+
}),
|
|
19
|
+
t.partial({
|
|
20
|
+
fieldset: StringOrNull,
|
|
21
|
+
config: IntegrationFieldConfig
|
|
22
|
+
})
|
|
23
|
+
])
|
|
24
|
+
)
|
|
25
|
+
type IntegrationField = t.TypeOf<typeof IntegrationField>
|
|
26
|
+
|
|
27
|
+
export default IntegrationField
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { withFallback } from 'io-ts-types/lib/withFallback'
|
|
3
|
+
import { either } from 'fp-ts/lib/Either'
|
|
4
|
+
import { StringOrNull } from '../../../validators/StringOrNull'
|
|
5
|
+
import WidgetTypes from '../WidgetTypes'
|
|
6
|
+
|
|
7
|
+
const arrayString = (entries: string | string[] | {
|
|
8
|
+
[x: string]: {
|
|
9
|
+
name: string;
|
|
10
|
+
}[];
|
|
11
|
+
} | null) => {
|
|
12
|
+
if(entries instanceof Array) {
|
|
13
|
+
const isValidEntries = entries.reduce((acc, l) => acc && typeof l === 'string', true)
|
|
14
|
+
if(isValidEntries) return t.success(entries)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const plainString = (entries: string | string[] | {
|
|
19
|
+
[x: string]: {
|
|
20
|
+
name: string;
|
|
21
|
+
}[];
|
|
22
|
+
} | null) => {
|
|
23
|
+
if(typeof entries === 'string') {
|
|
24
|
+
return t.success([entries])
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const MasksArrayString = new t.Type<Array<string>, object, unknown>(
|
|
29
|
+
'MasksArrayString',
|
|
30
|
+
(u: unknown): u is any => {
|
|
31
|
+
return u instanceof Array
|
|
32
|
+
},
|
|
33
|
+
(u: unknown, context: t.Context) => {
|
|
34
|
+
return either.chain(
|
|
35
|
+
t.union([
|
|
36
|
+
t.array(t.string),
|
|
37
|
+
t.string,
|
|
38
|
+
]).validate(u, context), (masks) => {
|
|
39
|
+
return (
|
|
40
|
+
arrayString(masks) ||
|
|
41
|
+
plainString(masks) ||
|
|
42
|
+
t.failure(u, context)
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
},
|
|
47
|
+
res => res
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
const LinkConfig = t.exact(
|
|
51
|
+
t.partial({
|
|
52
|
+
label: StringOrNull,
|
|
53
|
+
useAsTitle: t.boolean,
|
|
54
|
+
placeholder: t.string,
|
|
55
|
+
select: withFallback(
|
|
56
|
+
t.union([
|
|
57
|
+
t.literal('media'),
|
|
58
|
+
t.literal('document'),
|
|
59
|
+
t.literal('web'),
|
|
60
|
+
t.null
|
|
61
|
+
]),
|
|
62
|
+
null
|
|
63
|
+
),
|
|
64
|
+
customtypes: t.array(t.string), // `customtypes` and `masks` are alternatives
|
|
65
|
+
masks: MasksArrayString,
|
|
66
|
+
tags: MasksArrayString,
|
|
67
|
+
allowTargetBlank: t.boolean
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
type LinkConfig = t.TypeOf<typeof LinkConfig>
|
|
71
|
+
|
|
72
|
+
const Link = t.exact(
|
|
73
|
+
t.intersection([
|
|
74
|
+
t.type({
|
|
75
|
+
type: t.literal(WidgetTypes.Link)
|
|
76
|
+
}),
|
|
77
|
+
t.partial({
|
|
78
|
+
fieldset: StringOrNull,
|
|
79
|
+
config: LinkConfig
|
|
80
|
+
})
|
|
81
|
+
])
|
|
82
|
+
)
|
|
83
|
+
type Link = t.TypeOf<typeof Link>
|
|
84
|
+
|
|
85
|
+
export default Link
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
|
|
3
|
+
import Color from './Color'
|
|
4
|
+
import BooleanField from './BooleanField'
|
|
5
|
+
import Date from './Date'
|
|
6
|
+
import Embed from './Embed'
|
|
7
|
+
import GeoPoint from './GeoPoint'
|
|
8
|
+
import Number from './Number'
|
|
9
|
+
import Range from './Range'
|
|
10
|
+
import RichText from './RichText'
|
|
11
|
+
import Select from './Select'
|
|
12
|
+
import Separator from './Separator'
|
|
13
|
+
import Text from './Text'
|
|
14
|
+
import Timestamp from './Timestamp'
|
|
15
|
+
import Link from './Link'
|
|
16
|
+
import Image from './Image'
|
|
17
|
+
import IntegrationField from './IntegrationField'
|
|
18
|
+
|
|
19
|
+
const NestableWidget = t.union([
|
|
20
|
+
Color,
|
|
21
|
+
BooleanField,
|
|
22
|
+
Embed,
|
|
23
|
+
GeoPoint,
|
|
24
|
+
Date,
|
|
25
|
+
Number,
|
|
26
|
+
Range,
|
|
27
|
+
RichText,
|
|
28
|
+
Select,
|
|
29
|
+
Separator,
|
|
30
|
+
Text,
|
|
31
|
+
Timestamp,
|
|
32
|
+
Link,
|
|
33
|
+
Image,
|
|
34
|
+
IntegrationField
|
|
35
|
+
])
|
|
36
|
+
|
|
37
|
+
type NestableWidget = t.TypeOf<typeof NestableWidget>
|
|
38
|
+
|
|
39
|
+
export default NestableWidget
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { StringOrNull } from '../../../validators/StringOrNull'
|
|
3
|
+
import WidgetTypes from '../WidgetTypes'
|
|
4
|
+
import { NumberFromString } from 'io-ts-types/lib/NumberFromString'
|
|
5
|
+
|
|
6
|
+
const NumberConfig = t.exact(
|
|
7
|
+
t.partial({
|
|
8
|
+
label: StringOrNull,
|
|
9
|
+
placeholder: t.string,
|
|
10
|
+
min: t.union([t.number, NumberFromString]),
|
|
11
|
+
max: t.union([t.number, NumberFromString]),
|
|
12
|
+
step: t.union([t.number, NumberFromString])
|
|
13
|
+
})
|
|
14
|
+
)
|
|
15
|
+
type NumberConfig = t.TypeOf<typeof NumberConfig>
|
|
16
|
+
|
|
17
|
+
const Number = t.exact(
|
|
18
|
+
t.intersection([
|
|
19
|
+
t.type({
|
|
20
|
+
type: t.literal(WidgetTypes.Number)
|
|
21
|
+
}),
|
|
22
|
+
t.partial({
|
|
23
|
+
fieldset: StringOrNull,
|
|
24
|
+
config: NumberConfig
|
|
25
|
+
})
|
|
26
|
+
])
|
|
27
|
+
)
|
|
28
|
+
type Number = t.TypeOf<typeof Number>
|
|
29
|
+
|
|
30
|
+
export default Number
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { StringOrNull } from '../../../validators/StringOrNull'
|
|
3
|
+
import WidgetTypes from '../WidgetTypes'
|
|
4
|
+
import { NumberFromString } from 'io-ts-types/lib/NumberFromString'
|
|
5
|
+
|
|
6
|
+
const RangeConfig = t.exact(
|
|
7
|
+
t.partial({
|
|
8
|
+
label: StringOrNull,
|
|
9
|
+
placeholder: t.string,
|
|
10
|
+
min: t.union([t.number, NumberFromString]),
|
|
11
|
+
max: t.union([t.number, NumberFromString]),
|
|
12
|
+
step: t.union([t.number, NumberFromString]),
|
|
13
|
+
})
|
|
14
|
+
)
|
|
15
|
+
type RangeConfig = t.TypeOf<typeof RangeConfig>
|
|
16
|
+
|
|
17
|
+
const Range = t.exact(
|
|
18
|
+
t.intersection([
|
|
19
|
+
t.type({
|
|
20
|
+
type: t.literal(WidgetTypes.Range)
|
|
21
|
+
}),
|
|
22
|
+
t.partial({
|
|
23
|
+
fieldset: StringOrNull,
|
|
24
|
+
config: RangeConfig
|
|
25
|
+
})
|
|
26
|
+
])
|
|
27
|
+
)
|
|
28
|
+
type Range = t.TypeOf<typeof Range>
|
|
29
|
+
|
|
30
|
+
export default Range
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { StringOrNull } from '../../../validators/StringOrNull'
|
|
3
|
+
import { either } from 'fp-ts/lib/Either'
|
|
4
|
+
import WidgetTypes from '../WidgetTypes'
|
|
5
|
+
import ImageConstraint from '../shared/ImageConstraint'
|
|
6
|
+
|
|
7
|
+
const DEFAULT_OPTION = 'paragraph'
|
|
8
|
+
const options = [
|
|
9
|
+
'heading1',
|
|
10
|
+
'heading2',
|
|
11
|
+
'heading3',
|
|
12
|
+
'heading4',
|
|
13
|
+
'heading5',
|
|
14
|
+
'heading6',
|
|
15
|
+
'paragraph',
|
|
16
|
+
'strong',
|
|
17
|
+
'em',
|
|
18
|
+
'preformatted',
|
|
19
|
+
'hyperlink',
|
|
20
|
+
'image',
|
|
21
|
+
'embed',
|
|
22
|
+
'list-item',
|
|
23
|
+
'o-list-item',
|
|
24
|
+
'rtl'
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const RichTextOptions = new t.Type<string, string, unknown>(
|
|
28
|
+
'RichTextOptions',
|
|
29
|
+
(u: unknown): u is string => typeof u === 'string',
|
|
30
|
+
(u: unknown, context: t.Context) => {
|
|
31
|
+
return either.chain(
|
|
32
|
+
t.union([
|
|
33
|
+
t.string,
|
|
34
|
+
t.null
|
|
35
|
+
]).validate(u as unknown, context), (s: string | null) => {
|
|
36
|
+
if(!s) return t.success(DEFAULT_OPTION)
|
|
37
|
+
const entries = s.split(',').map((e: string) => e.trim())
|
|
38
|
+
const filtered = entries.filter(entry => options.includes(entry))
|
|
39
|
+
if(!filtered.length) return t.success(DEFAULT_OPTION)
|
|
40
|
+
|
|
41
|
+
return t.success(filtered.join(','))
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
a => a
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
const NoLabels = (labels: string | string[] | {
|
|
50
|
+
[x: string]: {
|
|
51
|
+
name: string;
|
|
52
|
+
}[];
|
|
53
|
+
} | null) => {
|
|
54
|
+
if(!labels) return t.success([])
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const LabelsAsObject = (labels: string | string[] | {
|
|
58
|
+
[x: string]: {
|
|
59
|
+
name: string;
|
|
60
|
+
}[];
|
|
61
|
+
} | null) => {
|
|
62
|
+
if(labels instanceof Object) {
|
|
63
|
+
const labelsObj = labels as { [x: string]: { name: string }[] }
|
|
64
|
+
|
|
65
|
+
// empty labels
|
|
66
|
+
if(!Object.entries(labelsObj).length) return t.success([])
|
|
67
|
+
|
|
68
|
+
// weird case labels with empty key as parent
|
|
69
|
+
if(labelsObj['']) {
|
|
70
|
+
return t.success(labelsObj[''].map(l => l.name))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const convertedObjectToArray = Object.entries(labelsObj)
|
|
74
|
+
.reduce<ReadonlyArray<string>>((acc, [, labelsEntries]) => {
|
|
75
|
+
return acc.concat(labelsEntries.map(l => l.name))
|
|
76
|
+
}, [])
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
|
|
79
|
+
return t.success(convertedObjectToArray)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const LabelsAsArray = (labels: string | string[] | {
|
|
84
|
+
[x: string]: {
|
|
85
|
+
name: string;
|
|
86
|
+
}[];
|
|
87
|
+
} | null) => {
|
|
88
|
+
if(labels instanceof Array) {
|
|
89
|
+
const isValidLabels = labels.reduce((acc, l) => acc && typeof l === 'string', true)
|
|
90
|
+
if(isValidLabels) return t.success(labels)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const LabelsAsString = (labels: string | string[] | {
|
|
95
|
+
[x: string]: {
|
|
96
|
+
name: string;
|
|
97
|
+
}[];
|
|
98
|
+
} | null) => {
|
|
99
|
+
if(typeof labels === 'string') {
|
|
100
|
+
return t.success([labels])
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const RichTextLabels = new t.Type<Array<string>, object, unknown>(
|
|
105
|
+
'RichTextLabels',
|
|
106
|
+
(u: unknown): u is any => {
|
|
107
|
+
return u instanceof Array
|
|
108
|
+
},
|
|
109
|
+
(u: unknown, context: t.Context) => {
|
|
110
|
+
const legacyValidator = t.record(t.string, t.array(t.record(t.literal("name"), t.string)))
|
|
111
|
+
const validator = t.array(t.string)
|
|
112
|
+
|
|
113
|
+
return either.chain(
|
|
114
|
+
t.union([
|
|
115
|
+
legacyValidator,
|
|
116
|
+
validator,
|
|
117
|
+
t.string,
|
|
118
|
+
t.null,
|
|
119
|
+
]).validate(u, context), (labels) => {
|
|
120
|
+
return (
|
|
121
|
+
NoLabels(labels) ||
|
|
122
|
+
LabelsAsArray(labels) ||
|
|
123
|
+
LabelsAsObject(labels) ||
|
|
124
|
+
LabelsAsString(labels) ||
|
|
125
|
+
t.failure(u, context)
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
},
|
|
130
|
+
res => res
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
const RichTextConfig = t.exact(
|
|
134
|
+
t.partial({
|
|
135
|
+
label: StringOrNull,
|
|
136
|
+
placeholder: t.string,
|
|
137
|
+
useAsTitle: t.boolean,
|
|
138
|
+
single: RichTextOptions,
|
|
139
|
+
multi: RichTextOptions,
|
|
140
|
+
imageConstraint: ImageConstraint,
|
|
141
|
+
labels: RichTextLabels,
|
|
142
|
+
allowTargetBlank: t.boolean
|
|
143
|
+
})
|
|
144
|
+
)
|
|
145
|
+
type RichTextConfig = t.TypeOf<typeof RichTextConfig>
|
|
146
|
+
|
|
147
|
+
const RichText = t.exact(
|
|
148
|
+
t.intersection([
|
|
149
|
+
t.type({
|
|
150
|
+
type: t.literal(WidgetTypes.RichText)
|
|
151
|
+
}),
|
|
152
|
+
t.partial({
|
|
153
|
+
fieldset: StringOrNull,
|
|
154
|
+
config: RichTextConfig
|
|
155
|
+
})
|
|
156
|
+
])
|
|
157
|
+
)
|
|
158
|
+
type RichText = t.TypeOf<typeof RichText>
|
|
159
|
+
|
|
160
|
+
export default RichText
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { StringOrNull } from '../../../validators/StringOrNull'
|
|
3
|
+
import { StringFromBoolean } from '../../../validators/StringFromBoolean'
|
|
4
|
+
import WidgetTypes from '../WidgetTypes'
|
|
5
|
+
|
|
6
|
+
import { StringFromNumber } from '../../../validators/StringFromNumber'
|
|
7
|
+
|
|
8
|
+
const SelectConfig = t.exact(
|
|
9
|
+
t.partial({
|
|
10
|
+
label: StringOrNull,
|
|
11
|
+
placeholder: t.string,
|
|
12
|
+
default_value: t.string,
|
|
13
|
+
options: t.array(t.union([t.string, StringFromNumber, StringFromBoolean]))
|
|
14
|
+
})
|
|
15
|
+
)
|
|
16
|
+
type SelectConfig = t.TypeOf<typeof SelectConfig>
|
|
17
|
+
|
|
18
|
+
const Select = t.exact(
|
|
19
|
+
t.intersection([
|
|
20
|
+
t.type({
|
|
21
|
+
type: t.literal(WidgetTypes.Select)
|
|
22
|
+
}),
|
|
23
|
+
t.partial({
|
|
24
|
+
fieldset: StringOrNull,
|
|
25
|
+
config: SelectConfig
|
|
26
|
+
})
|
|
27
|
+
])
|
|
28
|
+
)
|
|
29
|
+
type Select = t.TypeOf<typeof Select>
|
|
30
|
+
|
|
31
|
+
export default Select
|
|
32
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { StringOrNull } from '../../../validators/StringOrNull'
|
|
3
|
+
import WidgetTypes from '../WidgetTypes'
|
|
4
|
+
|
|
5
|
+
const SeparatorConfig = t.exact(
|
|
6
|
+
t.partial({
|
|
7
|
+
label: StringOrNull
|
|
8
|
+
})
|
|
9
|
+
)
|
|
10
|
+
type SeparatorConfig = t.TypeOf<typeof SeparatorConfig>
|
|
11
|
+
|
|
12
|
+
const Separator = t.exact(
|
|
13
|
+
t.intersection([
|
|
14
|
+
t.type({
|
|
15
|
+
type: t.literal(WidgetTypes.Separator)
|
|
16
|
+
}),
|
|
17
|
+
t.partial({
|
|
18
|
+
config: SeparatorConfig
|
|
19
|
+
})
|
|
20
|
+
])
|
|
21
|
+
)
|
|
22
|
+
type Separator = t.TypeOf<typeof Separator>
|
|
23
|
+
|
|
24
|
+
export default Separator
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { StringOrNull } from '../../../validators/StringOrNull'
|
|
3
|
+
import WidgetTypes from '../WidgetTypes'
|
|
4
|
+
|
|
5
|
+
const TextConfig = t.exact(
|
|
6
|
+
t.partial({
|
|
7
|
+
label: StringOrNull,
|
|
8
|
+
useAsTitle: t.boolean,
|
|
9
|
+
placeholder: t.string
|
|
10
|
+
})
|
|
11
|
+
)
|
|
12
|
+
type TextConfig = t.TypeOf<typeof TextConfig>
|
|
13
|
+
|
|
14
|
+
const Text = t.exact(
|
|
15
|
+
t.intersection([
|
|
16
|
+
t.type({
|
|
17
|
+
type: t.literal(WidgetTypes.Text)
|
|
18
|
+
}),
|
|
19
|
+
t.partial({
|
|
20
|
+
fieldset: StringOrNull,
|
|
21
|
+
config: TextConfig
|
|
22
|
+
})
|
|
23
|
+
])
|
|
24
|
+
)
|
|
25
|
+
type Text = t.TypeOf<typeof Text>
|
|
26
|
+
|
|
27
|
+
export default Text
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { StringOrNull } from '../../../validators/StringOrNull'
|
|
3
|
+
import WidgetTypes from '../WidgetTypes'
|
|
4
|
+
|
|
5
|
+
const TimestampConfig = t.exact(
|
|
6
|
+
t.partial({
|
|
7
|
+
label: StringOrNull,
|
|
8
|
+
placeholder: t.string,
|
|
9
|
+
default: t.string
|
|
10
|
+
})
|
|
11
|
+
)
|
|
12
|
+
type TimestampConfig = t.TypeOf<typeof TimestampConfig>
|
|
13
|
+
|
|
14
|
+
const Timestamp = t.exact(
|
|
15
|
+
t.intersection([
|
|
16
|
+
t.type({
|
|
17
|
+
type: t.literal(WidgetTypes.Timestamp)
|
|
18
|
+
}),
|
|
19
|
+
t.partial({
|
|
20
|
+
fieldset: StringOrNull,
|
|
21
|
+
config: TimestampConfig
|
|
22
|
+
})
|
|
23
|
+
])
|
|
24
|
+
)
|
|
25
|
+
type Timestamp = t.TypeOf<typeof Timestamp>
|
|
26
|
+
|
|
27
|
+
export default Timestamp
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { default as BooleanField } from './BooleanField'
|
|
2
|
+
export { default as Color } from './Color'
|
|
3
|
+
export { default as Date } from './Date'
|
|
4
|
+
export { default as GeoPoint } from './GeoPoint'
|
|
5
|
+
export { default as Image } from './Image'
|
|
6
|
+
export { default as IntegrationField } from './IntegrationField'
|
|
7
|
+
export { default as Link } from './Link'
|
|
8
|
+
export { default as NestableWidget } from './NestableWidget'
|
|
9
|
+
export { default as Number } from './Number'
|
|
10
|
+
export { default as Range } from './Range'
|
|
11
|
+
export { default as RichText } from './RichText'
|
|
12
|
+
export { default as Select } from './Select'
|
|
13
|
+
export { default as Separator } from './Separator'
|
|
14
|
+
export { default as Text } from './Text'
|
|
15
|
+
export { default as Timestamp } from './Timestamp'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { either } from 'fp-ts/lib/Either'
|
|
3
|
+
import { IntFromString } from 'io-ts-types/lib/IntFromString'
|
|
4
|
+
|
|
5
|
+
import { IntFromNumber } from '../../../validators/IntFromNumber'
|
|
6
|
+
import { IntFromPixels } from '../../../validators/IntFromPixels'
|
|
7
|
+
|
|
8
|
+
const SideConstraint = new t.Type<number | null, any, unknown>(
|
|
9
|
+
'SideConstraints',
|
|
10
|
+
(u: unknown): u is any => {
|
|
11
|
+
return !u || typeof u === 'number'
|
|
12
|
+
},
|
|
13
|
+
(u: unknown, context: t.Context) => {
|
|
14
|
+
return either.chain(
|
|
15
|
+
t.union([
|
|
16
|
+
t.literal('auto'),
|
|
17
|
+
t.literal(''),
|
|
18
|
+
t.Int,
|
|
19
|
+
IntFromString,
|
|
20
|
+
IntFromNumber,
|
|
21
|
+
IntFromPixels,
|
|
22
|
+
t.null
|
|
23
|
+
]).validate(u, context), (constraint) => {
|
|
24
|
+
if(constraint === 'auto' || constraint === '') return t.success(null)
|
|
25
|
+
return t.success(constraint)
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
},
|
|
29
|
+
res => res
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
const ImageConstraint = t.partial({
|
|
33
|
+
width: SideConstraint,
|
|
34
|
+
height: SideConstraint
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
type ImageConstraint = t.TypeOf<typeof ImageConstraint>
|
|
38
|
+
|
|
39
|
+
export default ImageConstraint
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ImageConstraint } from './ImageConstraint'
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
|
|
3
|
+
import SlicesTypes from './SlicesTypes'
|
|
4
|
+
import NestableWidget from "../nestable/NestableWidget"
|
|
5
|
+
import { StringOrNull } from '../../../validators/StringOrNull'
|
|
6
|
+
|
|
7
|
+
const CompositeSliceConfig = t.exact(
|
|
8
|
+
t.partial({
|
|
9
|
+
label: StringOrNull
|
|
10
|
+
})
|
|
11
|
+
)
|
|
12
|
+
type CompositeSliceConfig = t.TypeOf<typeof CompositeSliceConfig>
|
|
13
|
+
|
|
14
|
+
const CompositeSlice = t.exact(
|
|
15
|
+
t.intersection([
|
|
16
|
+
t.type({
|
|
17
|
+
type: t.literal(SlicesTypes.Slice)
|
|
18
|
+
}),
|
|
19
|
+
t.partial({
|
|
20
|
+
fieldset: StringOrNull,
|
|
21
|
+
description: t.string,
|
|
22
|
+
icon: t.string,
|
|
23
|
+
display: t.string,
|
|
24
|
+
'non-repeat': t.record(t.string, NestableWidget),
|
|
25
|
+
repeat: t.record(t.string, NestableWidget),
|
|
26
|
+
config: CompositeSliceConfig
|
|
27
|
+
})
|
|
28
|
+
])
|
|
29
|
+
)
|
|
30
|
+
type CompositeSlice = t.TypeOf<typeof CompositeSlice>
|
|
31
|
+
|
|
32
|
+
export default CompositeSlice
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
|
|
3
|
+
import UID from '../UID'
|
|
4
|
+
import NestableWidget from '../nestable/NestableWidget'
|
|
5
|
+
import Group from '../Group'
|
|
6
|
+
|
|
7
|
+
const LegacySlice = t.union([
|
|
8
|
+
UID,
|
|
9
|
+
NestableWidget,
|
|
10
|
+
Group
|
|
11
|
+
])
|
|
12
|
+
|
|
13
|
+
type LegacySlice = t.TypeOf<typeof LegacySlice>
|
|
14
|
+
|
|
15
|
+
export default LegacySlice
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
import { withFallback } from 'io-ts-types/lib/withFallback'
|
|
3
|
+
import NestableWidget from '../nestable/NestableWidget'
|
|
4
|
+
import SlicesTypes from './SlicesTypes'
|
|
5
|
+
|
|
6
|
+
const IMAGE_PLACEHOLDER_URL = 'https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format'
|
|
7
|
+
|
|
8
|
+
const Variation = t.exact(
|
|
9
|
+
t.intersection([
|
|
10
|
+
t.type({
|
|
11
|
+
id: t.string,
|
|
12
|
+
name: t.string,
|
|
13
|
+
description: t.string,
|
|
14
|
+
imageUrl: withFallback(t.string, IMAGE_PLACEHOLDER_URL),
|
|
15
|
+
docURL: t.string,
|
|
16
|
+
version: t.string
|
|
17
|
+
}),
|
|
18
|
+
t.partial({
|
|
19
|
+
display: t.string,
|
|
20
|
+
primary: t.record(t.string, NestableWidget),
|
|
21
|
+
items: t.record(t.string, NestableWidget)
|
|
22
|
+
})
|
|
23
|
+
])
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
type Variation = t.TypeOf<typeof Variation>
|
|
27
|
+
|
|
28
|
+
const SharedSlice = t.exact(
|
|
29
|
+
t.intersection([
|
|
30
|
+
t.type({
|
|
31
|
+
id: t.string,
|
|
32
|
+
type: t.literal(SlicesTypes.SharedSlice),
|
|
33
|
+
name: t.string,
|
|
34
|
+
variations: t.array(Variation)
|
|
35
|
+
}),
|
|
36
|
+
t.partial({
|
|
37
|
+
description: t.string
|
|
38
|
+
})
|
|
39
|
+
])
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
type SharedSlice = t.TypeOf<typeof SharedSlice>
|
|
43
|
+
|
|
44
|
+
export default SharedSlice
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as t from 'io-ts'
|
|
2
|
+
|
|
3
|
+
import SlicesTypes from './SlicesTypes'
|
|
4
|
+
|
|
5
|
+
const SharedSliceRef = t.exact(
|
|
6
|
+
t.type({
|
|
7
|
+
type: t.literal(SlicesTypes.SharedSlice)
|
|
8
|
+
})
|
|
9
|
+
)
|
|
10
|
+
type SharedSliceRef = t.TypeOf<typeof SharedSliceRef>
|
|
11
|
+
|
|
12
|
+
export default SharedSliceRef
|