@prismicio/types-internal 0.1.1 → 0.2.3
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 +13 -13
- package/{dist → lib}/customtypes/CustomType.d.ts +697 -715
- package/{dist → lib}/customtypes/CustomType.js +42 -52
- package/{dist → lib}/customtypes/Format.d.ts +0 -0
- package/{dist → lib}/customtypes/Format.js +0 -0
- package/{dist → lib}/customtypes/Section.d.ts +1035 -1062
- package/lib/customtypes/Section.js +21 -0
- package/lib/customtypes/index.d.ts +4 -0
- package/lib/customtypes/index.js +9 -0
- package/{dist → lib}/customtypes/widgets/Group.d.ts +45 -45
- package/lib/customtypes/widgets/Group.js +24 -0
- package/{dist → lib}/customtypes/widgets/UID.d.ts +4 -4
- package/lib/customtypes/widgets/UID.js +21 -0
- package/{dist → lib}/customtypes/widgets/Widget.d.ts +1036 -1063
- package/lib/customtypes/widgets/Widget.js +27 -0
- package/{dist → lib}/customtypes/widgets/WidgetTypes.d.ts +0 -0
- package/{dist → lib}/customtypes/widgets/WidgetTypes.js +0 -0
- package/lib/customtypes/widgets/index.d.ts +7 -0
- package/lib/customtypes/widgets/index.js +14 -0
- package/{dist → lib}/customtypes/widgets/nestable/BooleanField.d.ts +3 -3
- package/lib/customtypes/widgets/nestable/BooleanField.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Color.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Color.js +20 -0
- package/{dist → lib}/customtypes/widgets/nestable/Date.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Date.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Embed.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Embed.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/GeoPoint.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/GeoPoint.js +19 -0
- package/lib/customtypes/widgets/nestable/Image.d.ts +23 -0
- package/lib/customtypes/widgets/nestable/Image.js +29 -0
- package/{dist → lib}/customtypes/widgets/nestable/IntegrationField.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/IntegrationField.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Link.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Link.js +54 -0
- package/{dist → lib}/customtypes/widgets/nestable/NestableWidget.d.ts +42 -42
- package/lib/customtypes/widgets/nestable/NestableWidget.js +37 -0
- package/{dist → lib}/customtypes/widgets/nestable/Number.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Number.js +24 -0
- package/{dist → lib}/customtypes/widgets/nestable/Range.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Range.js +24 -0
- package/{dist → lib}/customtypes/widgets/nestable/RichText.d.ts +6 -6
- package/lib/customtypes/widgets/nestable/RichText.js +111 -0
- package/lib/customtypes/widgets/nestable/Select.d.ts +15 -0
- package/lib/customtypes/widgets/nestable/Select.js +22 -0
- package/{dist → lib}/customtypes/widgets/nestable/Separator.d.ts +3 -3
- package/lib/customtypes/widgets/nestable/Separator.js +18 -0
- package/{dist → lib}/customtypes/widgets/nestable/Text.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Text.js +21 -0
- package/{dist → lib}/customtypes/widgets/nestable/Timestamp.d.ts +4 -4
- package/lib/customtypes/widgets/nestable/Timestamp.js +21 -0
- package/lib/customtypes/widgets/nestable/index.d.ts +15 -0
- package/{dist → lib}/customtypes/widgets/nestable/index.js +0 -0
- package/{dist → lib}/customtypes/widgets/shared/ImageConstraint.d.ts +3 -3
- package/lib/customtypes/widgets/shared/ImageConstraint.js +31 -0
- package/lib/customtypes/widgets/shared/index.d.ts +1 -0
- package/{dist → lib}/customtypes/widgets/shared/index.js +0 -0
- package/{dist → lib}/customtypes/widgets/slices/CompositeSlice.d.ts +87 -87
- package/lib/customtypes/widgets/slices/CompositeSlice.js +25 -0
- package/{dist → lib}/customtypes/widgets/slices/LegacySlice.d.ts +86 -95
- package/lib/customtypes/widgets/slices/LegacySlice.js +8 -0
- package/{dist → lib}/customtypes/widgets/slices/SharedSlice.d.ts +84 -84
- package/lib/customtypes/widgets/slices/SharedSlice.js +35 -0
- package/{dist → lib}/customtypes/widgets/slices/SharedSliceRef.d.ts +2 -2
- package/lib/customtypes/widgets/slices/SharedSliceRef.js +9 -0
- package/lib/customtypes/widgets/slices/Slice.d.ts +6 -0
- package/{dist → lib}/customtypes/widgets/slices/Slice.js +0 -0
- package/{dist → lib}/customtypes/widgets/slices/Slices.d.ts +1550 -1604
- package/lib/customtypes/widgets/slices/Slices.js +93 -0
- package/{dist → lib}/customtypes/widgets/slices/SlicesTypes.d.ts +0 -0
- package/{dist → lib}/customtypes/widgets/slices/SlicesTypes.js +0 -0
- package/lib/customtypes/widgets/slices/index.d.ts +7 -0
- package/lib/customtypes/widgets/slices/index.js +16 -0
- package/lib/documents/DocumentData.d.ts +8 -0
- package/lib/documents/DocumentData.js +28 -0
- package/lib/documents/index.d.ts +2 -0
- package/lib/documents/index.js +7 -0
- package/lib/documents/widgets/EmptyContent.d.ts +8 -0
- package/lib/documents/widgets/EmptyContent.js +9 -0
- package/lib/documents/widgets/GroupContent.d.ts +16 -0
- package/lib/documents/widgets/GroupContent.js +59 -0
- package/lib/documents/widgets/SimpleWidgetContent.d.ts +20 -0
- package/lib/documents/widgets/SimpleWidgetContent.js +75 -0
- package/lib/documents/widgets/StaticWidgetContent.d.ts +10 -0
- package/lib/documents/widgets/StaticWidgetContent.js +26 -0
- package/lib/documents/widgets/UIDContent.d.ts +7 -0
- package/lib/documents/widgets/UIDContent.js +10 -0
- package/lib/documents/widgets/index.d.ts +35 -0
- package/lib/documents/widgets/index.js +36 -0
- package/lib/documents/widgets/nestable/BooleanContent.d.ts +8 -0
- package/lib/documents/widgets/nestable/BooleanContent.js +11 -0
- package/lib/documents/widgets/nestable/EmbedContent.d.ts +40 -0
- package/lib/documents/widgets/nestable/EmbedContent.js +36 -0
- package/lib/documents/widgets/nestable/FieldContent.d.ts +12 -0
- package/lib/documents/widgets/nestable/FieldContent.js +37 -0
- package/lib/documents/widgets/nestable/GeoPointContent.d.ts +17 -0
- package/lib/documents/widgets/nestable/GeoPointContent.js +13 -0
- package/lib/documents/widgets/nestable/ImageContent.d.ts +127 -0
- package/lib/documents/widgets/nestable/ImageContent.js +41 -0
- package/lib/documents/widgets/nestable/IntegrationFieldsContent.d.ts +8 -0
- package/lib/documents/widgets/nestable/IntegrationFieldsContent.js +16 -0
- package/lib/documents/widgets/nestable/Link/DocumentLink.d.ts +12 -0
- package/lib/documents/widgets/nestable/Link/DocumentLink.js +13 -0
- package/lib/documents/widgets/nestable/Link/ExternalLink.d.ts +24 -0
- package/lib/documents/widgets/nestable/Link/ExternalLink.js +24 -0
- package/lib/documents/widgets/nestable/Link/FileLink.d.ts +22 -0
- package/lib/documents/widgets/nestable/Link/FileLink.js +24 -0
- package/lib/documents/widgets/nestable/Link/ImageLink.d.ts +28 -0
- package/lib/documents/widgets/nestable/Link/ImageLink.js +26 -0
- package/lib/documents/widgets/nestable/Link/LinkContent.d.ts +36 -0
- package/lib/documents/widgets/nestable/Link/LinkContent.js +13 -0
- package/lib/documents/widgets/nestable/Link/index.d.ts +89 -0
- package/lib/documents/widgets/nestable/Link/index.js +35 -0
- package/lib/documents/widgets/nestable/SeparatorContent.d.ts +7 -0
- package/lib/documents/widgets/nestable/SeparatorContent.js +10 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.d.ts +274 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.js +97 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/index.d.ts +9 -0
- package/lib/documents/widgets/nestable/StructuredTextContent/index.js +14 -0
- package/lib/documents/widgets/nestable/index.d.ts +26 -0
- package/lib/documents/widgets/nestable/index.js +40 -0
- package/lib/documents/widgets/slices/CompositeSliceContent.d.ts +14 -0
- package/lib/documents/widgets/slices/CompositeSliceContent.js +50 -0
- package/lib/documents/widgets/slices/SharedSliceContent.d.ts +15 -0
- package/lib/documents/widgets/slices/SharedSliceContent.js +62 -0
- package/lib/documents/widgets/slices/SimpleSliceContent.d.ts +6 -0
- package/lib/documents/widgets/slices/SimpleSliceContent.js +6 -0
- package/lib/documents/widgets/slices/SliceWidgetContent.d.ts +8 -0
- package/lib/documents/widgets/slices/SliceWidgetContent.js +26 -0
- package/lib/documents/widgets/slices/SlicesContent.d.ts +17 -0
- package/lib/documents/widgets/slices/SlicesContent.js +51 -0
- package/lib/documents/widgets/slices/index.d.ts +5 -0
- package/lib/documents/widgets/slices/index.js +8 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +7 -0
- package/lib/validators/DateFromString.d.ts +3 -0
- package/lib/validators/DateFromString.js +10 -0
- package/lib/validators/DateFromStringOrNumber.d.ts +3 -0
- package/lib/validators/DateFromStringOrNumber.js +10 -0
- package/lib/validators/DateFromTsMs.d.ts +3 -0
- package/lib/validators/DateFromTsMs.js +10 -0
- package/lib/validators/IntFromNumber.d.ts +5 -0
- package/lib/validators/IntFromNumber.js +14 -0
- package/lib/validators/IntFromPixels.d.ts +8 -0
- package/lib/validators/IntFromPixels.js +24 -0
- package/lib/validators/NonEmptyString.d.ts +3 -0
- package/lib/validators/NonEmptyString.js +6 -0
- package/lib/validators/NonEmptyStringOrNull.d.ts +3 -0
- package/lib/validators/NonEmptyStringOrNull.js +15 -0
- package/lib/validators/NumberOrNull.d.ts +3 -0
- package/lib/validators/NumberOrNull.js +6 -0
- package/lib/validators/StringFromBoolean.d.ts +5 -0
- package/lib/validators/StringFromBoolean.js +10 -0
- package/lib/validators/StringFromNumber.d.ts +5 -0
- package/lib/validators/StringFromNumber.js +10 -0
- package/lib/validators/StringOrNull.d.ts +3 -0
- package/lib/validators/StringOrNull.js +6 -0
- package/lib/validators/function.d.ts +14 -0
- package/lib/validators/function.js +60 -0
- package/lib/validators/index.d.ts +12 -0
- package/lib/validators/index.js +27 -0
- package/package.json +30 -18
- package/src/customtypes/CustomType.ts +173 -116
- package/src/customtypes/Format.ts +3 -3
- package/src/customtypes/Section.ts +26 -13
- package/src/customtypes/index.ts +4 -4
- package/src/customtypes/widgets/Group.ts +21 -20
- package/src/customtypes/widgets/UID.ts +18 -17
- package/src/customtypes/widgets/Widget.ts +22 -23
- package/src/customtypes/widgets/WidgetTypes.ts +21 -21
- package/src/customtypes/widgets/index.ts +7 -7
- package/src/customtypes/widgets/nestable/BooleanField.ts +19 -19
- package/src/customtypes/widgets/nestable/Color.ts +17 -16
- package/src/customtypes/widgets/nestable/Date.ts +19 -18
- package/src/customtypes/widgets/nestable/Embed.ts +19 -18
- package/src/customtypes/widgets/nestable/GeoPoint.ts +17 -16
- package/src/customtypes/widgets/nestable/Image.ts +26 -26
- package/src/customtypes/widgets/nestable/IntegrationField.ts +18 -17
- package/src/customtypes/widgets/nestable/Link.ts +80 -68
- package/src/customtypes/widgets/nestable/NestableWidget.ts +32 -32
- package/src/customtypes/widgets/nestable/Number.ts +22 -21
- package/src/customtypes/widgets/nestable/Range.ts +22 -21
- package/src/customtypes/widgets/nestable/RichText.ts +164 -134
- package/src/customtypes/widgets/nestable/Select.ts +22 -21
- package/src/customtypes/widgets/nestable/Separator.ts +15 -14
- package/src/customtypes/widgets/nestable/Text.ts +18 -17
- package/src/customtypes/widgets/nestable/Timestamp.ts +19 -18
- package/src/customtypes/widgets/nestable/index.ts +15 -15
- package/src/customtypes/widgets/shared/ImageConstraint.ts +31 -29
- package/src/customtypes/widgets/shared/index.ts +1 -1
- package/src/customtypes/widgets/slices/CompositeSlice.ts +21 -21
- package/src/customtypes/widgets/slices/LegacySlice.ts +5 -10
- package/src/customtypes/widgets/slices/SharedSlice.ts +33 -31
- package/src/customtypes/widgets/slices/SharedSliceRef.ts +6 -6
- package/src/customtypes/widgets/slices/Slice.ts +4 -4
- package/src/customtypes/widgets/slices/Slices.ts +95 -73
- package/src/customtypes/widgets/slices/SlicesTypes.ts +3 -3
- package/src/customtypes/widgets/slices/index.ts +7 -7
- package/src/documents/DocumentData.ts +54 -0
- package/src/documents/index.ts +2 -0
- package/src/documents/widgets/EmptyContent.ts +8 -0
- package/src/documents/widgets/GroupContent.ts +91 -0
- package/src/documents/widgets/SimpleWidgetContent.ts +96 -0
- package/src/documents/widgets/StaticWidgetContent.ts +46 -0
- package/src/documents/widgets/UIDContent.ts +18 -0
- package/src/documents/widgets/index.ts +56 -0
- package/src/documents/widgets/nestable/BooleanContent.ts +21 -0
- package/src/documents/widgets/nestable/EmbedContent.ts +54 -0
- package/src/documents/widgets/nestable/FieldContent.ts +45 -0
- package/src/documents/widgets/nestable/GeoPointContent.ts +18 -0
- package/src/documents/widgets/nestable/ImageContent.ts +51 -0
- package/src/documents/widgets/nestable/IntegrationFieldsContent.ts +26 -0
- package/src/documents/widgets/nestable/Link/DocumentLink.ts +18 -0
- package/src/documents/widgets/nestable/Link/ExternalLink.ts +31 -0
- package/src/documents/widgets/nestable/Link/FileLink.ts +29 -0
- package/src/documents/widgets/nestable/Link/ImageLink.ts +31 -0
- package/src/documents/widgets/nestable/Link/LinkContent.ts +22 -0
- package/src/documents/widgets/nestable/Link/index.ts +33 -0
- package/src/documents/widgets/nestable/SeparatorContent.ts +8 -0
- package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +122 -0
- package/src/documents/widgets/nestable/StructuredTextContent/index.ts +25 -0
- package/src/documents/widgets/nestable/index.ts +35 -0
- package/src/documents/widgets/slices/CompositeSliceContent.ts +77 -0
- package/src/documents/widgets/slices/SharedSliceContent.ts +94 -0
- package/src/documents/widgets/slices/SimpleSliceContent.ts +4 -0
- package/src/documents/widgets/slices/SliceWidgetContent.ts +51 -0
- package/src/documents/widgets/slices/SlicesContent.ts +91 -0
- package/src/documents/widgets/slices/index.ts +5 -0
- package/src/index.ts +3 -1
- package/src/validators/DateFromString.ts +17 -0
- package/src/validators/DateFromStringOrNumber.ts +17 -0
- package/src/validators/DateFromTsMs.ts +17 -0
- package/src/validators/IntFromNumber.ts +22 -24
- package/src/validators/IntFromPixels.ts +27 -26
- package/src/validators/NonEmptyString.ts +9 -0
- package/src/validators/NonEmptyStringOrNull.ts +22 -0
- package/src/validators/NumberOrNull.ts +5 -0
- package/src/validators/StringFromBoolean.ts +17 -19
- package/src/validators/StringFromNumber.ts +17 -19
- package/src/validators/StringOrNull.ts +4 -2
- package/src/validators/function.ts +71 -0
- package/src/validators/index.ts +12 -0
- package/dist/customtypes/Section.js +0 -40
- package/dist/customtypes/index.d.ts +0 -4
- package/dist/customtypes/index.js +0 -30
- package/dist/customtypes/widgets/Group.js +0 -45
- package/dist/customtypes/widgets/UID.js +0 -42
- package/dist/customtypes/widgets/Widget.js +0 -51
- package/dist/customtypes/widgets/index.d.ts +0 -7
- package/dist/customtypes/widgets/index.js +0 -35
- package/dist/customtypes/widgets/nestable/BooleanField.js +0 -42
- package/dist/customtypes/widgets/nestable/Color.js +0 -41
- package/dist/customtypes/widgets/nestable/Date.js +0 -42
- package/dist/customtypes/widgets/nestable/Embed.js +0 -42
- package/dist/customtypes/widgets/nestable/GeoPoint.js +0 -40
- package/dist/customtypes/widgets/nestable/Image.d.ts +0 -23
- package/dist/customtypes/widgets/nestable/Image.js +0 -50
- package/dist/customtypes/widgets/nestable/IntegrationField.js +0 -42
- package/dist/customtypes/widgets/nestable/Link.js +0 -78
- package/dist/customtypes/widgets/nestable/NestableWidget.js +0 -58
- package/dist/customtypes/widgets/nestable/Number.js +0 -45
- package/dist/customtypes/widgets/nestable/Range.js +0 -45
- package/dist/customtypes/widgets/nestable/RichText.js +0 -134
- package/dist/customtypes/widgets/nestable/Select.d.ts +0 -15
- package/dist/customtypes/widgets/nestable/Select.js +0 -45
- package/dist/customtypes/widgets/nestable/Separator.js +0 -39
- package/dist/customtypes/widgets/nestable/Text.js +0 -42
- package/dist/customtypes/widgets/nestable/Timestamp.js +0 -42
- package/dist/customtypes/widgets/nestable/index.d.ts +0 -15
- package/dist/customtypes/widgets/shared/ImageConstraint.js +0 -48
- package/dist/customtypes/widgets/shared/index.d.ts +0 -1
- package/dist/customtypes/widgets/slices/CompositeSlice.js +0 -46
- package/dist/customtypes/widgets/slices/LegacySlice.js +0 -34
- package/dist/customtypes/widgets/slices/SharedSlice.js +0 -56
- package/dist/customtypes/widgets/slices/SharedSliceRef.js +0 -30
- package/dist/customtypes/widgets/slices/Slice.d.ts +0 -6
- package/dist/customtypes/widgets/slices/Slices.js +0 -106
- package/dist/customtypes/widgets/slices/index.d.ts +0 -7
- package/dist/customtypes/widgets/slices/index.js +0 -37
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -23
- package/dist/index.js.map +0 -1
- package/dist/validators/IntFromNumber.d.ts +0 -7
- package/dist/validators/IntFromNumber.js +0 -35
- package/dist/validators/IntFromPixels.d.ts +0 -7
- package/dist/validators/IntFromPixels.js +0 -43
- package/dist/validators/StringFromBoolean.d.ts +0 -7
- package/dist/validators/StringFromBoolean.js +0 -31
- package/dist/validators/StringFromNumber.d.ts +0 -7
- package/dist/validators/StringFromNumber.js +0 -31
- package/dist/validators/StringOrNull.d.ts +0 -2
- package/dist/validators/StringOrNull.js +0 -24
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import * as t from
|
|
1
|
+
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { StringOrNull } from "../../../validators"
|
|
4
4
|
import NestableWidget from "../nestable/NestableWidget"
|
|
5
|
-
import
|
|
5
|
+
import SlicesTypes from "./SlicesTypes"
|
|
6
6
|
|
|
7
7
|
const CompositeSliceConfig = t.exact(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
t.partial({
|
|
9
|
+
label: StringOrNull,
|
|
10
|
+
}),
|
|
11
11
|
)
|
|
12
12
|
type CompositeSliceConfig = t.TypeOf<typeof CompositeSliceConfig>
|
|
13
13
|
|
|
14
14
|
const CompositeSlice = t.exact(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
29
|
)
|
|
30
30
|
type CompositeSlice = t.TypeOf<typeof CompositeSlice>
|
|
31
31
|
|
|
32
|
-
export default CompositeSlice
|
|
32
|
+
export default CompositeSlice
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import * as t from
|
|
1
|
+
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import NestableWidget from
|
|
5
|
-
import Group from '../Group'
|
|
3
|
+
import Group from "../Group"
|
|
4
|
+
import NestableWidget from "../nestable/NestableWidget"
|
|
6
5
|
|
|
7
|
-
const LegacySlice = t.union([
|
|
8
|
-
UID,
|
|
9
|
-
NestableWidget,
|
|
10
|
-
Group
|
|
11
|
-
])
|
|
6
|
+
const LegacySlice = t.union([NestableWidget, Group])
|
|
12
7
|
|
|
13
8
|
type LegacySlice = t.TypeOf<typeof LegacySlice>
|
|
14
9
|
|
|
15
|
-
export default LegacySlice
|
|
10
|
+
export default LegacySlice
|
|
@@ -1,42 +1,44 @@
|
|
|
1
|
-
import * as t from
|
|
2
|
-
import { withFallback } from
|
|
3
|
-
import NestableWidget from '../nestable/NestableWidget'
|
|
4
|
-
import SlicesTypes from './SlicesTypes'
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
import { withFallback } from "io-ts-types/lib/withFallback"
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
import NestableWidget from "../nestable/NestableWidget"
|
|
5
|
+
import SlicesTypes from "./SlicesTypes"
|
|
6
|
+
|
|
7
|
+
const IMAGE_PLACEHOLDER_URL =
|
|
8
|
+
"https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format"
|
|
7
9
|
|
|
8
10
|
const Variation = t.exact(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
t.intersection([
|
|
12
|
+
t.type({
|
|
13
|
+
id: t.string,
|
|
14
|
+
name: t.string,
|
|
15
|
+
description: t.string,
|
|
16
|
+
imageUrl: withFallback(t.string, IMAGE_PLACEHOLDER_URL),
|
|
17
|
+
docURL: t.string,
|
|
18
|
+
version: t.string,
|
|
19
|
+
}),
|
|
20
|
+
t.partial({
|
|
21
|
+
display: t.string,
|
|
22
|
+
primary: t.record(t.string, NestableWidget),
|
|
23
|
+
items: t.record(t.string, NestableWidget),
|
|
24
|
+
}),
|
|
25
|
+
]),
|
|
24
26
|
)
|
|
25
27
|
|
|
26
28
|
type Variation = t.TypeOf<typeof Variation>
|
|
27
29
|
|
|
28
30
|
const SharedSlice = t.exact(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
t.intersection([
|
|
32
|
+
t.type({
|
|
33
|
+
id: t.string,
|
|
34
|
+
type: t.literal(SlicesTypes.SharedSlice),
|
|
35
|
+
name: t.string,
|
|
36
|
+
variations: t.array(Variation),
|
|
37
|
+
}),
|
|
38
|
+
t.partial({
|
|
39
|
+
description: t.string,
|
|
40
|
+
}),
|
|
41
|
+
]),
|
|
40
42
|
)
|
|
41
43
|
|
|
42
44
|
type SharedSlice = t.TypeOf<typeof SharedSlice>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import * as t from
|
|
1
|
+
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import SlicesTypes from
|
|
3
|
+
import SlicesTypes from "./SlicesTypes"
|
|
4
4
|
|
|
5
5
|
const SharedSliceRef = t.exact(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
t.type({
|
|
7
|
+
type: t.literal(SlicesTypes.SharedSlice),
|
|
8
|
+
}),
|
|
9
9
|
)
|
|
10
10
|
type SharedSliceRef = t.TypeOf<typeof SharedSliceRef>
|
|
11
11
|
|
|
12
|
-
export default SharedSliceRef
|
|
12
|
+
export default SharedSliceRef
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import SharedSliceRef from "./SharedSliceRef"
|
|
1
|
+
import type CompositeSlice from "./CompositeSlice"
|
|
2
|
+
import type LegacySlice from "./LegacySlice"
|
|
3
|
+
import type SharedSlice from "./SharedSlice"
|
|
4
|
+
import type SharedSliceRef from "./SharedSliceRef"
|
|
5
5
|
|
|
6
6
|
export type DynamicSlice = CompositeSlice | LegacySlice | SharedSliceRef
|
|
7
7
|
export type StaticSlice = CompositeSlice | LegacySlice | SharedSlice
|
|
@@ -1,51 +1,60 @@
|
|
|
1
|
-
import * as t from
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import { Format } from
|
|
5
|
-
import
|
|
6
|
-
import CompositeSlice from
|
|
7
|
-
import
|
|
8
|
-
import SharedSlice from
|
|
9
|
-
import
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { StringOrNull } from "../../../validators"
|
|
4
|
+
import { Format } from "../../Format"
|
|
5
|
+
import WidgetTypes from "../WidgetTypes"
|
|
6
|
+
import CompositeSlice from "./CompositeSlice"
|
|
7
|
+
import LegacySlice from "./LegacySlice"
|
|
8
|
+
import SharedSlice from "./SharedSlice"
|
|
9
|
+
import SharedSliceRef from "./SharedSliceRef"
|
|
10
|
+
import SlicesTypes from "./SlicesTypes"
|
|
10
11
|
|
|
11
12
|
const SlicesLabels = t.union([
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
t.record(
|
|
14
|
+
t.string,
|
|
15
|
+
t.array(
|
|
16
|
+
t.exact(
|
|
17
|
+
t.intersection([
|
|
18
|
+
t.type({
|
|
19
|
+
name: t.string,
|
|
20
|
+
}),
|
|
21
|
+
t.partial({
|
|
22
|
+
display: t.string,
|
|
23
|
+
}),
|
|
24
|
+
]),
|
|
25
|
+
),
|
|
26
|
+
),
|
|
27
|
+
),
|
|
28
|
+
t.null,
|
|
28
29
|
])
|
|
29
30
|
type SlicesLabels = t.TypeOf<typeof SlicesLabels>
|
|
30
31
|
|
|
31
32
|
export function slicesConfigReader<F extends Format>(format: F) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
return t.exact(
|
|
34
|
+
t.partial({
|
|
35
|
+
label: StringOrNull,
|
|
36
|
+
labels: SlicesLabels,
|
|
37
|
+
choices: t.record(
|
|
38
|
+
t.string,
|
|
39
|
+
t.union([
|
|
40
|
+
LegacySlice,
|
|
41
|
+
CompositeSlice,
|
|
42
|
+
(() => {
|
|
43
|
+
switch (format) {
|
|
44
|
+
case Format.Static:
|
|
45
|
+
return SharedSlice
|
|
46
|
+
case Format.Dynamic:
|
|
47
|
+
return SharedSliceRef
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Invalid Format Exception: ${format} doesn't exist`,
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
})(),
|
|
54
|
+
]),
|
|
55
|
+
),
|
|
56
|
+
}),
|
|
57
|
+
)
|
|
49
58
|
}
|
|
50
59
|
export const StaticSlicesConfig = slicesConfigReader(Format.Static)
|
|
51
60
|
export type StaticSlicesConfig = t.TypeOf<typeof StaticSlicesConfig>
|
|
@@ -54,34 +63,41 @@ export const DynamicSlicesConfig = slicesConfigReader(Format.Dynamic)
|
|
|
54
63
|
export type DynamicSlicesConfig = t.TypeOf<typeof DynamicSlicesConfig>
|
|
55
64
|
|
|
56
65
|
const SlicesConfig = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
toStatic(
|
|
67
|
+
config: DynamicSlicesConfig,
|
|
68
|
+
sharedSlices: Map<string, SharedSlice>,
|
|
69
|
+
): StaticSlicesConfig {
|
|
70
|
+
const choices: {
|
|
71
|
+
[key: string]: LegacySlice | CompositeSlice | SharedSlice
|
|
72
|
+
} = Object.entries(config.choices || {}).reduce((acc, [ref, slice]) => {
|
|
73
|
+
if (slice.type === SlicesTypes.SharedSlice) {
|
|
74
|
+
const sharedSlice = sharedSlices.get(ref)
|
|
75
|
+
if (sharedSlice) return { ...acc, [ref]: sharedSlice }
|
|
76
|
+
else return acc
|
|
77
|
+
} else {
|
|
78
|
+
return { ...acc, [ref]: slice }
|
|
79
|
+
}
|
|
80
|
+
}, {})
|
|
81
|
+
|
|
82
|
+
return { ...config, choices } as StaticSlicesConfig
|
|
83
|
+
},
|
|
71
84
|
}
|
|
72
85
|
|
|
73
86
|
export function slicesReader<F extends Format>(format: F) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
return t.exact(
|
|
88
|
+
t.intersection([
|
|
89
|
+
t.type({
|
|
90
|
+
type: t.union([
|
|
91
|
+
t.literal(WidgetTypes.Slices),
|
|
92
|
+
t.literal(WidgetTypes.LegacySlices),
|
|
93
|
+
]),
|
|
94
|
+
}),
|
|
95
|
+
t.partial({
|
|
96
|
+
fieldset: StringOrNull,
|
|
97
|
+
config: slicesConfigReader(format),
|
|
98
|
+
}),
|
|
99
|
+
]),
|
|
100
|
+
)
|
|
85
101
|
}
|
|
86
102
|
|
|
87
103
|
export const StaticSlices = slicesReader(Format.Static)
|
|
@@ -91,10 +107,16 @@ export const DynamicSlices = slicesReader(Format.Dynamic)
|
|
|
91
107
|
export type DynamicSlices = t.TypeOf<typeof DynamicSlices>
|
|
92
108
|
|
|
93
109
|
export const Slices = {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
toStatic(
|
|
111
|
+
slices: DynamicSlices,
|
|
112
|
+
sharedSlices: Map<string, SharedSlice>,
|
|
113
|
+
): StaticSlices {
|
|
114
|
+
if (!slices.config) return slices as StaticSlices
|
|
115
|
+
else {
|
|
116
|
+
return {
|
|
117
|
+
...slices,
|
|
118
|
+
config: SlicesConfig.toStatic(slices.config, sharedSlices),
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
100
122
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { default as CompositeSlice } from
|
|
2
|
-
export { default as LegacySlice } from
|
|
3
|
-
export { default as SharedSlice } from
|
|
4
|
-
export { default as SharedSliceRef } from
|
|
5
|
-
export
|
|
6
|
-
export * as
|
|
7
|
-
export
|
|
1
|
+
export { default as CompositeSlice } from "./CompositeSlice"
|
|
2
|
+
export { default as LegacySlice } from "./LegacySlice"
|
|
3
|
+
export { default as SharedSlice } from "./SharedSlice"
|
|
4
|
+
export { default as SharedSliceRef } from "./SharedSliceRef"
|
|
5
|
+
export * as Slice from "./Slice"
|
|
6
|
+
export * as SliceZone from "./Slices"
|
|
7
|
+
export { default as SlicesTypes } from "./SlicesTypes"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as O from "fp-ts/lib/Option"
|
|
2
|
+
|
|
3
|
+
import { type WidgetContent, type WidgetKey, Widget } from "./widgets"
|
|
4
|
+
|
|
5
|
+
type DocumentData = Map<WidgetKey, O.Option<WidgetContent>>
|
|
6
|
+
function computeWidget(
|
|
7
|
+
key: WidgetKey,
|
|
8
|
+
widgets: Map<WidgetKey, unknown>,
|
|
9
|
+
widgetTypes: Map<WidgetKey, string>,
|
|
10
|
+
widgetPositions: Map<WidgetKey, number>,
|
|
11
|
+
): O.Option<WidgetContent> {
|
|
12
|
+
const widget = widgets.get(key)
|
|
13
|
+
if (widget === undefined) {
|
|
14
|
+
return O.none
|
|
15
|
+
}
|
|
16
|
+
return Widget.fromJson(key, widget, widgetTypes, widgetPositions)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const DocumentData = {
|
|
20
|
+
getWidget(
|
|
21
|
+
key: WidgetKey,
|
|
22
|
+
widgets: Map<WidgetKey, unknown>,
|
|
23
|
+
widgetTypes: Map<WidgetKey, string>,
|
|
24
|
+
widgetPositions: Map<WidgetKey, number>,
|
|
25
|
+
parsed: Map<string, O.Option<WidgetContent>>,
|
|
26
|
+
): O.Option<WidgetContent> {
|
|
27
|
+
const widget = parsed.get(key)
|
|
28
|
+
if (widget === undefined) {
|
|
29
|
+
return computeWidget(key, widgets, widgetTypes, widgetPositions)
|
|
30
|
+
}
|
|
31
|
+
return widget
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
fromJson(
|
|
35
|
+
widgets: Map<WidgetKey, unknown>,
|
|
36
|
+
widgetTypes: Map<WidgetKey, string>,
|
|
37
|
+
widgetPositions: Map<WidgetKey, number>,
|
|
38
|
+
): DocumentData {
|
|
39
|
+
return Array.from(widgets.keys()).reduce<
|
|
40
|
+
Map<WidgetKey, O.Option<WidgetContent>>
|
|
41
|
+
>((acc, widgetKey) => {
|
|
42
|
+
const parsedWidget = this.getWidget(
|
|
43
|
+
widgetKey,
|
|
44
|
+
widgets,
|
|
45
|
+
widgetTypes,
|
|
46
|
+
widgetPositions,
|
|
47
|
+
acc,
|
|
48
|
+
)
|
|
49
|
+
return new Map([...Array.from(acc.entries()), [widgetKey, parsedWidget]])
|
|
50
|
+
}, new Map<WidgetKey, O.Option<WidgetContent>>())
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default DocumentData
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const EmptyContentType = "EmptyContent"
|
|
2
|
+
export type EmptyContent = { type: string; __TYPE__: typeof EmptyContentType }
|
|
3
|
+
|
|
4
|
+
export const EmptyContent = {
|
|
5
|
+
is: (value: unknown): value is EmptyContent => {
|
|
6
|
+
return (value as EmptyContent).__TYPE__ === EmptyContentType
|
|
7
|
+
},
|
|
8
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as A from "fp-ts/Array"
|
|
2
|
+
import * as O from "fp-ts/Option"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
|
|
5
|
+
import { SimpleWidgetContent } from "./SimpleWidgetContent"
|
|
6
|
+
|
|
7
|
+
export const GroupItemContentType = "GroupItemContent"
|
|
8
|
+
export interface GroupItemContent {
|
|
9
|
+
__TYPE__: typeof GroupItemContentType
|
|
10
|
+
value: Array<[string, SimpleWidgetContent]>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const GroupContentType = "GroupContentType"
|
|
14
|
+
export interface GroupContent {
|
|
15
|
+
__TYPE__: typeof GroupContentType
|
|
16
|
+
value: GroupItemContent[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const GroupContent = Object.freeze({
|
|
20
|
+
itemsContentsFromJson: (
|
|
21
|
+
prefixedKey: string,
|
|
22
|
+
jsItems: Array<unknown> | undefined,
|
|
23
|
+
fieldTypes: Map<string, string>,
|
|
24
|
+
fieldPositions: Map<string, number>,
|
|
25
|
+
): Array<GroupItemContent> => {
|
|
26
|
+
if (jsItems) {
|
|
27
|
+
return jsItems.map((jsItem) => {
|
|
28
|
+
if (typeof jsItem === "object" && jsItem !== null) {
|
|
29
|
+
const sorted = Object.entries(jsItem).sort(([k1], [k2]) => {
|
|
30
|
+
const p1 = fieldPositions.get(`${prefixedKey}.${k1}`) ?? 10000
|
|
31
|
+
const p2 = fieldPositions.get(`${prefixedKey}.${k2}`) ?? 10000
|
|
32
|
+
return p1 - p2
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const w: O.Option<[string, SimpleWidgetContent]>[] = sorted.map(
|
|
36
|
+
([k, v]) => {
|
|
37
|
+
const kind = fieldTypes.get(`${prefixedKey}.${k}`)
|
|
38
|
+
if (kind) {
|
|
39
|
+
return O.map<
|
|
40
|
+
SimpleWidgetContent,
|
|
41
|
+
[string, SimpleWidgetContent]
|
|
42
|
+
>((content) => {
|
|
43
|
+
return [k, content]
|
|
44
|
+
})(SimpleWidgetContent.from(kind, v))
|
|
45
|
+
} else {
|
|
46
|
+
return O.none
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
__TYPE__: "GroupItemContent",
|
|
53
|
+
value: A.compact(w),
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
return {
|
|
57
|
+
__TYPE__: "GroupItemContent",
|
|
58
|
+
value: [],
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
} else {
|
|
63
|
+
return []
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
fromJson: (
|
|
68
|
+
prefixes: Array<string>,
|
|
69
|
+
key: string,
|
|
70
|
+
value: unknown,
|
|
71
|
+
fieldTypes: Map<string, string>,
|
|
72
|
+
fieldPositions: Map<string, number>,
|
|
73
|
+
): O.Option<GroupContent> => {
|
|
74
|
+
const prefixedKey = Array.of(prefixes, [key]).flat().join(".")
|
|
75
|
+
|
|
76
|
+
const maybeJsItems: O.Option<Array<unknown>> = O.fromEither(
|
|
77
|
+
t.array(t.unknown).decode(value),
|
|
78
|
+
)
|
|
79
|
+
return O.map((items: Array<unknown>) => {
|
|
80
|
+
return {
|
|
81
|
+
value: GroupContent.itemsContentsFromJson(
|
|
82
|
+
prefixedKey,
|
|
83
|
+
items,
|
|
84
|
+
fieldTypes,
|
|
85
|
+
fieldPositions,
|
|
86
|
+
),
|
|
87
|
+
__TYPE__: GroupContentType,
|
|
88
|
+
} as const
|
|
89
|
+
})(maybeJsItems)
|
|
90
|
+
},
|
|
91
|
+
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { pipe } from "fp-ts/function"
|
|
2
|
+
import * as O from "fp-ts/Option"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
|
|
5
|
+
import type { EmptyContent } from "./EmptyContent"
|
|
6
|
+
import BooleanContent from "./nestable/BooleanContent"
|
|
7
|
+
import EmbedContent from "./nestable/EmbedContent"
|
|
8
|
+
import FieldContent from "./nestable/FieldContent"
|
|
9
|
+
import { GeoPointContent, GeoPointContentO } from "./nestable/GeoPointContent"
|
|
10
|
+
import { ImageContent, ImageContentO } from "./nestable/ImageContent"
|
|
11
|
+
import IntegrationFieldsContent from "./nestable/IntegrationFieldsContent"
|
|
12
|
+
import { LinkContent } from "./nestable/Link"
|
|
13
|
+
import type { SeparatorContent } from "./nestable/SeparatorContent"
|
|
14
|
+
import { StructuredTextContent } from "./nestable/StructuredTextContent"
|
|
15
|
+
import { UIDContent } from "./UIDContent"
|
|
16
|
+
|
|
17
|
+
//TODO: rework that using import such as EmptyContentType
|
|
18
|
+
export const SimpleWidgetContentType = [
|
|
19
|
+
"EmptyContent",
|
|
20
|
+
"ImageContent",
|
|
21
|
+
"GeoPointContent",
|
|
22
|
+
"EmbedContent",
|
|
23
|
+
"BooleanContent",
|
|
24
|
+
"IntegrationFieldsContent",
|
|
25
|
+
"StructuredTextContent",
|
|
26
|
+
"LinkContent",
|
|
27
|
+
"UIDContent",
|
|
28
|
+
"SeparatorContent",
|
|
29
|
+
"FieldContent",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
export type NonEmptySimpleWidgetContent =
|
|
33
|
+
| IntegrationFieldsContent
|
|
34
|
+
| StructuredTextContent
|
|
35
|
+
| ImageContentO
|
|
36
|
+
| GeoPointContentO
|
|
37
|
+
| EmbedContent
|
|
38
|
+
| LinkContent
|
|
39
|
+
| UIDContent
|
|
40
|
+
| SeparatorContent
|
|
41
|
+
| FieldContent
|
|
42
|
+
| BooleanContent
|
|
43
|
+
|
|
44
|
+
export type SimpleWidgetContent = NonEmptySimpleWidgetContent | EmptyContent
|
|
45
|
+
|
|
46
|
+
export function is(value: unknown): value is SimpleWidgetContent {
|
|
47
|
+
const asSwc = value as SimpleWidgetContent
|
|
48
|
+
return SimpleWidgetContentType.includes(asSwc.__TYPE__)
|
|
49
|
+
}
|
|
50
|
+
const valueNullCodec = t.type({
|
|
51
|
+
value: t.null,
|
|
52
|
+
})
|
|
53
|
+
export const SimpleWidgetContent = {
|
|
54
|
+
from: (type: string, content: unknown): O.Option<SimpleWidgetContent> => {
|
|
55
|
+
if (content === null || valueNullCodec.is(content)) {
|
|
56
|
+
const result: EmptyContent = { type: type, __TYPE__: "EmptyContent" }
|
|
57
|
+
return O.some(result)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
switch (type) {
|
|
61
|
+
case "StructuredText":
|
|
62
|
+
return O.fromEither(StructuredTextContent.decode(content))
|
|
63
|
+
case "IntegrationFields":
|
|
64
|
+
return O.fromEither(IntegrationFieldsContent.decode(content))
|
|
65
|
+
case "Image":
|
|
66
|
+
return pipe(
|
|
67
|
+
O.fromEither(ImageContent.decode(content)),
|
|
68
|
+
O.map((imageContent) => ImageContent.encode(imageContent)),
|
|
69
|
+
)
|
|
70
|
+
case "GeoPoint":
|
|
71
|
+
return pipe(
|
|
72
|
+
O.fromEither(GeoPointContent.decode(content)),
|
|
73
|
+
O.map((geopointContent) => GeoPointContent.encode(geopointContent)),
|
|
74
|
+
)
|
|
75
|
+
case "Embed":
|
|
76
|
+
return O.fromEither(EmbedContent.decode(content))
|
|
77
|
+
case "Link":
|
|
78
|
+
return O.fromEither(LinkContent.decode(content))
|
|
79
|
+
case "UID":
|
|
80
|
+
return O.fromEither(UIDContent.decode(content))
|
|
81
|
+
case "Separator":
|
|
82
|
+
return O.some({ __TYPE__: "SeparatorContent" })
|
|
83
|
+
case "Boolean":
|
|
84
|
+
return O.fromEither(BooleanContent.decode(content))
|
|
85
|
+
default:
|
|
86
|
+
if (FieldContent.types.includes(type)) {
|
|
87
|
+
return FieldContent.forType(type, content)
|
|
88
|
+
} else {
|
|
89
|
+
return O.none
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
//TODO: rework that
|
|
94
|
+
is: (value: unknown): value is SimpleWidgetContent =>
|
|
95
|
+
SimpleWidgetContentType.includes((value as SimpleWidgetContent).__TYPE__),
|
|
96
|
+
}
|