@prismicio/types-internal 1.5.2 → 2.0.0-alpha.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/common/WidgetKey.d.ts +3 -0
- package/lib/common/WidgetKey.js +8 -0
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +4 -0
- package/lib/content/Document.d.ts +4285 -2573
- package/lib/content/Document.js +87 -10
- package/lib/content/LegacyContentCtx.d.ts +41 -0
- package/lib/content/LegacyContentCtx.js +65 -0
- package/lib/content/fields/EmptyContent.d.ts +16 -0
- package/lib/content/fields/EmptyContent.js +30 -0
- package/lib/content/fields/GroupContent.d.ts +1063 -364
- package/lib/content/fields/GroupContent.js +65 -6
- package/lib/content/fields/UIDContent.d.ts +10 -1
- package/lib/content/fields/UIDContent.js +17 -4
- package/lib/content/fields/WidgetContent.d.ts +6820 -0
- package/lib/content/fields/WidgetContent.js +57 -0
- package/lib/content/fields/index.d.ts +1 -2989
- package/lib/content/fields/index.js +1 -18
- package/lib/content/fields/nestable/BooleanContent.d.ts +10 -1
- package/lib/content/fields/nestable/BooleanContent.js +17 -4
- package/lib/content/fields/nestable/EmbedContent.d.ts +56 -5
- package/lib/content/fields/nestable/EmbedContent.js +57 -6
- package/lib/content/fields/nestable/FieldContent/ColorContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/ColorContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/DateContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/DateContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/NumberContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/NumberContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/RangeContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/RangeContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/SelectContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/SelectContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/TextContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/TextContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/TimestampContent.d.ts +18 -0
- package/lib/content/fields/nestable/FieldContent/TimestampContent.js +34 -0
- package/lib/content/fields/nestable/FieldContent/common.d.ts +1 -0
- package/lib/content/fields/nestable/FieldContent/common.js +4 -0
- package/lib/content/fields/nestable/FieldContent/index.d.ts +49 -0
- package/lib/content/fields/nestable/FieldContent/index.js +38 -0
- package/lib/content/fields/nestable/FieldContent.d.ts +7 -1
- package/lib/content/fields/nestable/FieldContent.js +19 -4
- package/lib/content/fields/nestable/GeoPointContent.d.ts +19 -4
- package/lib/content/fields/nestable/GeoPointContent.js +22 -5
- package/lib/content/fields/nestable/ImageContent.d.ts +109 -11
- package/lib/content/fields/nestable/ImageContent.js +64 -6
- package/lib/content/fields/nestable/IntegrationFieldContent.d.ts +10 -1
- package/lib/content/fields/nestable/IntegrationFieldContent.js +20 -4
- package/lib/content/fields/nestable/LinkContent.d.ts +240 -87
- package/lib/content/fields/nestable/LinkContent.js +133 -36
- package/lib/content/fields/nestable/NestableContent.d.ts +711 -251
- package/lib/content/fields/nestable/NestableContent.js +116 -13
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +594 -0
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +151 -0
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +489 -0
- package/lib/content/fields/nestable/RichTextContent/index.js +27 -0
- package/lib/content/fields/nestable/SeparatorContent.d.ts +8 -1
- package/lib/content/fields/nestable/SeparatorContent.js +15 -4
- package/lib/content/fields/slices/CompositeSliceContent.d.ts +296 -362
- package/lib/content/fields/slices/RepeatableContent.d.ts +148 -181
- package/lib/content/fields/slices/SharedSliceContent.d.ts +296 -362
- package/lib/content/fields/slices/SimpleSliceContent.d.ts +296 -362
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +1709 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +81 -0
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +582 -0
- package/lib/content/fields/slices/Slice/RepeatableContent.js +18 -0
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +1713 -0
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +98 -0
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +1429 -0
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +24 -0
- package/lib/content/fields/slices/Slice/index.d.ts +3216 -0
- package/lib/content/fields/slices/Slice/index.js +41 -0
- package/lib/content/fields/slices/SliceItem.d.ts +3498 -0
- package/lib/content/fields/slices/SliceItem.js +61 -0
- package/lib/content/fields/slices/SlicesContent.d.ts +4243 -3576
- package/lib/content/fields/slices/SlicesContent.js +28 -18
- package/lib/content/fields/slices/index.d.ts +4 -3
- package/lib/content/fields/slices/index.js +4 -3
- package/lib/content/index.d.ts +1 -0
- package/lib/content/index.js +1 -0
- package/lib/content/utils.d.ts +10 -0
- package/lib/content/utils.js +19 -0
- package/lib/customtypes/CustomType.d.ts +366 -366
- package/lib/customtypes/CustomType.js +4 -7
- package/lib/customtypes/Section.d.ts +366 -366
- package/lib/customtypes/Section.js +2 -2
- package/lib/customtypes/diff/SharedSlice.d.ts +6 -7
- package/lib/customtypes/diff/Variation.d.ts +10 -7
- package/lib/customtypes/widgets/Group.d.ts +1 -0
- package/lib/customtypes/widgets/Group.js +6 -5
- package/lib/customtypes/widgets/UID.d.ts +1 -0
- package/lib/customtypes/widgets/UID.js +3 -2
- package/lib/customtypes/widgets/Widget.d.ts +384 -362
- package/lib/customtypes/widgets/Widget.js +29 -8
- package/lib/customtypes/widgets/index.d.ts +6 -7
- package/lib/customtypes/widgets/index.js +6 -11
- package/lib/customtypes/widgets/nestable/BooleanField.d.ts +10 -3
- package/lib/customtypes/widgets/nestable/BooleanField.js +6 -6
- package/lib/customtypes/widgets/nestable/Color.d.ts +8 -3
- package/lib/customtypes/widgets/nestable/Color.js +6 -6
- package/lib/customtypes/widgets/nestable/Date.d.ts +9 -3
- package/lib/customtypes/widgets/nestable/Date.js +6 -6
- package/lib/customtypes/widgets/nestable/Embed.d.ts +9 -3
- package/lib/customtypes/widgets/nestable/Embed.js +6 -6
- package/lib/customtypes/widgets/nestable/GeoPoint.d.ts +7 -3
- package/lib/customtypes/widgets/nestable/GeoPoint.js +6 -6
- package/lib/customtypes/widgets/nestable/Image.d.ts +25 -3
- package/lib/customtypes/widgets/nestable/Image.js +8 -8
- package/lib/customtypes/widgets/nestable/IntegrationField.d.ts +9 -3
- package/lib/customtypes/widgets/nestable/IntegrationField.js +6 -6
- package/lib/customtypes/widgets/nestable/Link.d.ts +14 -2
- package/lib/customtypes/widgets/nestable/Link.js +7 -6
- package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +3 -3
- package/lib/customtypes/widgets/nestable/NestableWidget.js +30 -30
- package/lib/customtypes/widgets/nestable/Number.d.ts +11 -3
- package/lib/customtypes/widgets/nestable/Number.js +6 -6
- package/lib/customtypes/widgets/nestable/Range.d.ts +11 -3
- package/lib/customtypes/widgets/nestable/Range.js +6 -6
- package/lib/customtypes/widgets/nestable/RichText.d.ts +1 -0
- package/lib/customtypes/widgets/nestable/RichText.js +3 -3
- package/lib/customtypes/widgets/nestable/Select.d.ts +10 -3
- package/lib/customtypes/widgets/nestable/Select.js +6 -6
- package/lib/customtypes/widgets/nestable/Separator.d.ts +7 -3
- package/lib/customtypes/widgets/nestable/Separator.js +6 -6
- package/lib/customtypes/widgets/nestable/Text.d.ts +9 -2
- package/lib/customtypes/widgets/nestable/Text.js +7 -6
- package/lib/customtypes/widgets/nestable/Timestamp.d.ts +9 -3
- package/lib/customtypes/widgets/nestable/Timestamp.js +6 -6
- package/lib/customtypes/widgets/nestable/index.d.ts +15 -15
- package/lib/customtypes/widgets/nestable/index.js +15 -31
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +1 -0
- package/lib/customtypes/widgets/slices/CompositeSlice.js +7 -6
- package/lib/customtypes/widgets/slices/LegacySlice.js +2 -2
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +1 -0
- package/lib/customtypes/widgets/slices/SharedSlice.js +7 -7
- package/lib/customtypes/widgets/slices/SharedSliceRef.js +2 -2
- package/lib/customtypes/widgets/slices/Slices.d.ts +364 -362
- package/lib/customtypes/widgets/slices/Slices.js +8 -8
- package/lib/customtypes/widgets/slices/SlicesTypes.d.ts +6 -5
- package/lib/customtypes/widgets/slices/SlicesTypes.js +8 -4
- package/lib/documents/DocumentData.d.ts +3 -14
- package/lib/documents/DocumentData.js +5 -60
- package/lib/documents/widgets/nestable/ImageContent.d.ts +1 -1
- package/lib/documents/widgets/nestable/ImageContent.js +2 -2
- package/lib/utils/Objects.d.ts +1 -0
- package/lib/utils/Objects.js +10 -1
- package/package.json +1 -1
- package/src/common/WidgetKey.ts +13 -0
- package/src/common/index.ts +1 -0
- package/src/content/Document.ts +129 -16
- package/src/content/LegacyContentCtx.ts +57 -0
- package/src/content/fields/EmptyContent.ts +45 -0
- package/src/content/fields/GroupContent.ts +103 -8
- package/src/content/fields/UIDContent.ts +33 -3
- package/src/content/fields/WidgetContent.ts +76 -0
- package/src/content/fields/index.ts +1 -23
- package/src/content/fields/nestable/BooleanContent.ts +32 -3
- package/src/content/fields/nestable/EmbedContent.ts +79 -8
- package/src/content/fields/nestable/FieldContent/ColorContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/DateContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/NumberContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/RangeContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/SelectContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/TextContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/TimestampContent.ts +48 -0
- package/src/content/fields/nestable/FieldContent/common.ts +1 -0
- package/src/content/fields/nestable/FieldContent/index.ts +40 -0
- package/src/content/fields/nestable/GeoPointContent.ts +38 -7
- package/src/content/fields/nestable/ImageContent.ts +91 -11
- package/src/content/fields/nestable/IntegrationFieldContent.ts +42 -3
- package/src/content/fields/nestable/LinkContent.ts +208 -47
- package/src/content/fields/nestable/NestableContent.ts +180 -24
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +205 -0
- package/src/content/fields/nestable/RichTextContent/index.ts +43 -0
- package/src/content/fields/nestable/SeparatorContent.ts +26 -3
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +118 -0
- package/src/content/fields/slices/{RepeatableContent.ts → Slice/RepeatableContent.ts} +7 -4
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +129 -0
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +30 -0
- package/src/content/fields/slices/Slice/index.ts +47 -0
- package/src/content/fields/slices/SliceItem.ts +83 -0
- package/src/content/fields/slices/SlicesContent.ts +47 -19
- package/src/content/fields/slices/index.ts +4 -3
- package/src/content/index.ts +1 -0
- package/src/content/utils.ts +20 -0
- package/src/customtypes/CustomType.ts +4 -10
- package/src/customtypes/Section.ts +1 -1
- package/src/customtypes/diff/SharedSlice.ts +2 -2
- package/src/customtypes/diff/Variation.ts +8 -2
- package/src/customtypes/widgets/Group.ts +4 -4
- package/src/customtypes/widgets/UID.ts +3 -2
- package/src/customtypes/widgets/Widget.ts +53 -7
- package/src/customtypes/widgets/index.ts +6 -7
- package/src/customtypes/widgets/nestable/BooleanField.ts +7 -8
- package/src/customtypes/widgets/nestable/Color.ts +6 -8
- package/src/customtypes/widgets/nestable/Date.ts +7 -8
- package/src/customtypes/widgets/nestable/Embed.ts +7 -8
- package/src/customtypes/widgets/nestable/GeoPoint.ts +7 -8
- package/src/customtypes/widgets/nestable/Image.ts +9 -10
- package/src/customtypes/widgets/nestable/IntegrationField.ts +6 -8
- package/src/customtypes/widgets/nestable/Link.ts +7 -6
- package/src/customtypes/widgets/nestable/NestableWidget.ts +17 -18
- package/src/customtypes/widgets/nestable/Number.ts +7 -8
- package/src/customtypes/widgets/nestable/Range.ts +7 -8
- package/src/customtypes/widgets/nestable/RichText.ts +3 -2
- package/src/customtypes/widgets/nestable/Select.ts +7 -8
- package/src/customtypes/widgets/nestable/Separator.ts +7 -8
- package/src/customtypes/widgets/nestable/Text.ts +7 -6
- package/src/customtypes/widgets/nestable/Timestamp.ts +7 -8
- package/src/customtypes/widgets/nestable/index.ts +15 -15
- package/src/customtypes/widgets/slices/CompositeSlice.ts +5 -4
- package/src/customtypes/widgets/slices/LegacySlice.ts +1 -1
- package/src/customtypes/widgets/slices/SharedSlice.ts +5 -4
- package/src/customtypes/widgets/slices/SharedSliceRef.ts +2 -2
- package/src/customtypes/widgets/slices/Slices.ts +7 -6
- package/src/customtypes/widgets/slices/SlicesTypes.ts +10 -5
- package/src/utils/Objects.ts +12 -0
- package/src/content/fields/nestable/FieldContent.ts +0 -25
- package/src/content/fields/nestable/RichTextContent.ts +0 -32
- package/src/content/fields/slices/CompositeSliceContent.ts +0 -14
- package/src/content/fields/slices/SharedSliceContent.ts +0 -14
- package/src/content/fields/slices/SimpleSliceContent.ts +0 -7
- package/src/customtypes/widgets/WidgetTypes.ts +0 -24
- package/src/documents/DocumentData.ts +0 -112
- package/src/documents/index.ts +0 -2
- package/src/documents/widgets/EmptyContent.ts +0 -8
- package/src/documents/widgets/GroupContent.ts +0 -91
- package/src/documents/widgets/SimpleWidgetContent.ts +0 -96
- package/src/documents/widgets/StaticWidgetContent.ts +0 -46
- package/src/documents/widgets/UIDContent.ts +0 -18
- package/src/documents/widgets/index.ts +0 -70
- package/src/documents/widgets/nestable/BooleanContent.ts +0 -21
- package/src/documents/widgets/nestable/EmbedContent.ts +0 -56
- package/src/documents/widgets/nestable/FieldContent.ts +0 -53
- package/src/documents/widgets/nestable/GeoPointContent.ts +0 -18
- package/src/documents/widgets/nestable/ImageContent.ts +0 -51
- package/src/documents/widgets/nestable/IntegrationFieldsContent.ts +0 -26
- package/src/documents/widgets/nestable/Link/DocumentLink.ts +0 -18
- package/src/documents/widgets/nestable/Link/ExternalLink.ts +0 -31
- package/src/documents/widgets/nestable/Link/FileLink.ts +0 -30
- package/src/documents/widgets/nestable/Link/ImageLink.ts +0 -31
- package/src/documents/widgets/nestable/Link/LinkContent.ts +0 -25
- package/src/documents/widgets/nestable/Link/index.ts +0 -35
- package/src/documents/widgets/nestable/SeparatorContent.ts +0 -13
- package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +0 -126
- package/src/documents/widgets/nestable/StructuredTextContent/index.ts +0 -25
- package/src/documents/widgets/nestable/index.ts +0 -35
- package/src/documents/widgets/slices/CompositeSliceContent.ts +0 -77
- package/src/documents/widgets/slices/SharedSliceContent.ts +0 -94
- package/src/documents/widgets/slices/SimpleSliceContent.ts +0 -4
- package/src/documents/widgets/slices/SliceWidgetContent.ts +0 -51
- package/src/documents/widgets/slices/SlicesContent.ts +0 -91
- package/src/documents/widgets/slices/index.ts +0 -5
- package/src/index.ts +0 -3
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import { WidgetKey } from "../../../
|
|
3
|
+
import { WidgetKey } from "../../../common"
|
|
4
4
|
import { StringOrNull } from "../../../validators"
|
|
5
|
-
import { WidgetTypes } from "../WidgetTypes"
|
|
6
5
|
import CompositeSlice from "./CompositeSlice"
|
|
7
6
|
import LegacySlice from "./LegacySlice"
|
|
8
7
|
import { SharedSlice } from "./SharedSlice"
|
|
9
8
|
import SharedSliceRef from "./SharedSliceRef"
|
|
10
|
-
|
|
9
|
+
|
|
10
|
+
export const LegacySlicesFieldType = "Choice"
|
|
11
|
+
export const SlicesFieldType = "Slices"
|
|
11
12
|
|
|
12
13
|
export const SlicesLabels = t.union([
|
|
13
14
|
t.record(
|
|
@@ -57,7 +58,7 @@ const SlicesConfig = {
|
|
|
57
58
|
const choices: {
|
|
58
59
|
[key: string]: LegacySlice | CompositeSlice | SharedSlice
|
|
59
60
|
} = Object.entries(config.choices || {}).reduce((acc, [ref, slice]) => {
|
|
60
|
-
if (slice.type ===
|
|
61
|
+
if (slice.type === "SharedSlice") {
|
|
61
62
|
const sharedSlice = sharedSlices.get(ref)
|
|
62
63
|
if (sharedSlice) return { ...acc, [ref]: sharedSlice }
|
|
63
64
|
else return acc
|
|
@@ -77,8 +78,8 @@ export function slicesReader<
|
|
|
77
78
|
t.intersection([
|
|
78
79
|
t.type({
|
|
79
80
|
type: t.union([
|
|
80
|
-
t.literal(
|
|
81
|
-
t.literal(
|
|
81
|
+
t.literal(SlicesFieldType),
|
|
82
|
+
t.literal(LegacySlicesFieldType),
|
|
82
83
|
]),
|
|
83
84
|
}),
|
|
84
85
|
t.partial({
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Slice: "Slice",
|
|
3
|
-
SharedSlice: "SharedSlice",
|
|
4
|
-
} as const
|
|
1
|
+
import * as t from "io-ts"
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
import { CompositeSliceType } from "./CompositeSlice"
|
|
4
|
+
import { SharedSliceType } from "./SharedSlice"
|
|
5
|
+
|
|
6
|
+
export const SlicesTypes = t.keyof({
|
|
7
|
+
[CompositeSliceType]: null,
|
|
8
|
+
[SharedSliceType]: null,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export type SlicesTypes = t.TypeOf<typeof SlicesTypes>
|
package/src/utils/Objects.ts
CHANGED
|
@@ -21,3 +21,15 @@ export function zipObjects<A, B = A>(
|
|
|
21
21
|
export function isNotEmpty<A extends object>(obj: A): boolean {
|
|
22
22
|
return Boolean(Object.keys(obj).length)
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
export function withOptionals<T extends object>(
|
|
26
|
+
object: T,
|
|
27
|
+
optionals: Array<[keyof T, T[keyof T] | null | undefined]>,
|
|
28
|
+
): T {
|
|
29
|
+
return {
|
|
30
|
+
...object,
|
|
31
|
+
...optionals.reduce((acc, [key, value]) => {
|
|
32
|
+
return value ? { ...acc, [key]: value } : acc
|
|
33
|
+
}, {}),
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts"
|
|
2
|
-
|
|
3
|
-
import { FieldContentType as type } from "../../../documents/widgets/nestable/FieldContent"
|
|
4
|
-
import TrimmedString from "../../../validators/TrimmedString"
|
|
5
|
-
|
|
6
|
-
export const FieldType = t.keyof({
|
|
7
|
-
Text: null,
|
|
8
|
-
Date: null,
|
|
9
|
-
Timestamp: null,
|
|
10
|
-
Color: null,
|
|
11
|
-
Number: null,
|
|
12
|
-
Range: null,
|
|
13
|
-
Select: null,
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
export type FieldType = t.TypeOf<typeof FieldType>
|
|
17
|
-
|
|
18
|
-
export const FieldContent = t.strict({
|
|
19
|
-
type: FieldType,
|
|
20
|
-
value: TrimmedString,
|
|
21
|
-
__TYPE__: t.literal(type),
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
export type FieldContent = t.TypeOf<typeof FieldContent>
|
|
25
|
-
export const FieldContentType = type
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts"
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
Blocks,
|
|
5
|
-
StructuredTextContentType as type,
|
|
6
|
-
} from "../../../documents/widgets/nestable/StructuredTextContent"
|
|
7
|
-
import {
|
|
8
|
-
Block as b,
|
|
9
|
-
EmbedBlock as eBlock,
|
|
10
|
-
ImageBlock as iBlock,
|
|
11
|
-
TextBlock as tBlock,
|
|
12
|
-
} from "../../../documents/widgets/nestable/StructuredTextContent/Block"
|
|
13
|
-
|
|
14
|
-
export const RichTextContent = t.strict({
|
|
15
|
-
__TYPE__: t.literal(type),
|
|
16
|
-
value: t.array(Blocks.Block),
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
export type RichTextContent = t.TypeOf<typeof RichTextContent>
|
|
20
|
-
export const RichTextContentType = type
|
|
21
|
-
|
|
22
|
-
export const TextBlock = tBlock
|
|
23
|
-
export type TextBlock = tBlock
|
|
24
|
-
|
|
25
|
-
export const ImageBlock = iBlock
|
|
26
|
-
export type ImageBlock = iBlock
|
|
27
|
-
|
|
28
|
-
export const EmbedBlock = eBlock
|
|
29
|
-
export type EmbedBlock = eBlock
|
|
30
|
-
|
|
31
|
-
export const Block = b
|
|
32
|
-
export type Block = b
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts"
|
|
2
|
-
|
|
3
|
-
import { CompositeSliceContentType as type } from "../../../documents/widgets/slices"
|
|
4
|
-
import { NestableContent } from "../nestable"
|
|
5
|
-
import { RepeatableWidgets } from "./RepeatableContent"
|
|
6
|
-
|
|
7
|
-
export const CompositeSliceContent = t.strict({
|
|
8
|
-
__TYPE__: t.literal(type),
|
|
9
|
-
nonRepeat: t.record(t.string, NestableContent),
|
|
10
|
-
repeat: RepeatableWidgets,
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
export type CompositeSliceContent = t.TypeOf<typeof CompositeSliceContent>
|
|
14
|
-
export const CompositeSliceContentType = type
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts"
|
|
2
|
-
|
|
3
|
-
import { SharedSliceContentType as type } from "../../../documents/widgets/slices"
|
|
4
|
-
import { NestableContent } from "../nestable"
|
|
5
|
-
import { RepeatableWidgets } from "./RepeatableContent"
|
|
6
|
-
|
|
7
|
-
export const SharedSliceContent = t.strict({
|
|
8
|
-
__TYPE__: t.literal(type),
|
|
9
|
-
variation: t.string,
|
|
10
|
-
primary: t.record(t.string, NestableContent),
|
|
11
|
-
items: RepeatableWidgets,
|
|
12
|
-
})
|
|
13
|
-
export type SharedSliceContent = t.TypeOf<typeof SharedSliceContent>
|
|
14
|
-
export const SharedSliceContentType = type
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts"
|
|
2
|
-
|
|
3
|
-
import { GroupContent } from "../GroupContent"
|
|
4
|
-
import { NestableContent } from "../nestable"
|
|
5
|
-
|
|
6
|
-
export const SimpleSliceContent = t.union([NestableContent, GroupContent])
|
|
7
|
-
export type SimpleSliceContent = t.TypeOf<typeof SimpleSliceContent>
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export const WidgetTypes = {
|
|
2
|
-
Text: "Text",
|
|
3
|
-
RichText: "StructuredText",
|
|
4
|
-
Color: "Color",
|
|
5
|
-
Image: "Image",
|
|
6
|
-
Date: "Date",
|
|
7
|
-
Timestamp: "Timestamp",
|
|
8
|
-
Number: "Number",
|
|
9
|
-
Range: "Range",
|
|
10
|
-
Select: "Select",
|
|
11
|
-
Link: "Link",
|
|
12
|
-
Embed: "Embed",
|
|
13
|
-
GeoPoint: "GeoPoint",
|
|
14
|
-
Separator: "Separator",
|
|
15
|
-
UID: "UID",
|
|
16
|
-
BooleanField: "Boolean",
|
|
17
|
-
IntegrationField: "IntegrationFields",
|
|
18
|
-
Group: "Group",
|
|
19
|
-
Slices: "Slices",
|
|
20
|
-
// Legacy type for slices
|
|
21
|
-
LegacySlices: "Choice",
|
|
22
|
-
} as const
|
|
23
|
-
|
|
24
|
-
export type WidgetTypes = typeof WidgetTypes[keyof typeof WidgetTypes]
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { isRight } from "fp-ts/lib/Either"
|
|
2
|
-
import * as O from "fp-ts/lib/Option"
|
|
3
|
-
import * as t from "io-ts"
|
|
4
|
-
|
|
5
|
-
import { type WidgetContent, type WidgetKey, Widget } from "./widgets"
|
|
6
|
-
|
|
7
|
-
type DocumentData = Map<WidgetKey, O.Option<WidgetContent>>
|
|
8
|
-
function computeWidget(
|
|
9
|
-
key: WidgetKey,
|
|
10
|
-
widgets: Map<WidgetKey, unknown>,
|
|
11
|
-
widgetTypes: Map<WidgetKey, string>,
|
|
12
|
-
widgetPositions: Map<WidgetKey, number>,
|
|
13
|
-
): O.Option<WidgetContent> {
|
|
14
|
-
const widget = widgets.get(key)
|
|
15
|
-
if (widget === undefined) {
|
|
16
|
-
return O.none
|
|
17
|
-
}
|
|
18
|
-
return Widget.fromJson(key, widget, widgetTypes, widgetPositions)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const DocumentData = {
|
|
22
|
-
getWidget(
|
|
23
|
-
key: WidgetKey,
|
|
24
|
-
widgets: Map<WidgetKey, unknown>,
|
|
25
|
-
widgetTypes: Map<WidgetKey, string>,
|
|
26
|
-
widgetPositions: Map<WidgetKey, number>,
|
|
27
|
-
parsed: Map<string, O.Option<WidgetContent>>,
|
|
28
|
-
): O.Option<WidgetContent> {
|
|
29
|
-
const widget = parsed.get(key)
|
|
30
|
-
if (widget === undefined) {
|
|
31
|
-
return computeWidget(key, widgets, widgetTypes, widgetPositions)
|
|
32
|
-
}
|
|
33
|
-
return widget
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
fromJson(
|
|
37
|
-
widgets: Map<WidgetKey, unknown>,
|
|
38
|
-
widgetTypes: Map<WidgetKey, string>,
|
|
39
|
-
widgetPositions: Map<WidgetKey, number>,
|
|
40
|
-
): DocumentData {
|
|
41
|
-
return Array.from(widgets.keys()).reduce<
|
|
42
|
-
Map<WidgetKey, O.Option<WidgetContent>>
|
|
43
|
-
>((acc, widgetKey) => {
|
|
44
|
-
const parsedWidget = this.getWidget(
|
|
45
|
-
widgetKey,
|
|
46
|
-
widgets,
|
|
47
|
-
widgetTypes,
|
|
48
|
-
widgetPositions,
|
|
49
|
-
acc,
|
|
50
|
-
)
|
|
51
|
-
return new Map([...Array.from(acc.entries()), [widgetKey, parsedWidget]])
|
|
52
|
-
}, new Map<WidgetKey, O.Option<WidgetContent>>())
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
partitionData(data: { [p: string]: unknown }): {
|
|
56
|
-
types: Map<string, string>
|
|
57
|
-
positions: Map<string, number>
|
|
58
|
-
widgets: Map<WidgetKey, unknown>
|
|
59
|
-
slugs: ReadonlyArray<string>
|
|
60
|
-
uid: string | undefined
|
|
61
|
-
} {
|
|
62
|
-
const fields: [string, unknown][] = Object.entries(data)
|
|
63
|
-
|
|
64
|
-
const { types, positions, widgets } = fields.reduce(
|
|
65
|
-
(acc, [k, v]) => {
|
|
66
|
-
if (k.endsWith("_TYPE")) {
|
|
67
|
-
const decodedValue = t.string.decode(v)
|
|
68
|
-
if (isRight(decodedValue)) {
|
|
69
|
-
return {
|
|
70
|
-
...acc,
|
|
71
|
-
types: acc.types.set(
|
|
72
|
-
k.substring(0, k.length - 5),
|
|
73
|
-
decodedValue.right,
|
|
74
|
-
),
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (k.endsWith("_POSITION") && typeof v === "number") {
|
|
79
|
-
return {
|
|
80
|
-
...acc,
|
|
81
|
-
positions: acc.positions.set(k.substring(0, k.length - 9), v),
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (!k.endsWith("_POSITION") && !k.endsWith("_TYPE")) {
|
|
85
|
-
return {
|
|
86
|
-
...acc,
|
|
87
|
-
widgets: acc.widgets.set(k, v),
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return acc
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
types: new Map<string, string>(),
|
|
94
|
-
positions: new Map<string, number>(),
|
|
95
|
-
widgets: new Map<string, unknown>(),
|
|
96
|
-
},
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
const slugs = (data["slugs_INTERNAL"] as string[]) || []
|
|
100
|
-
const uid = data["uid"] as string | undefined
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
widgets,
|
|
104
|
-
types,
|
|
105
|
-
positions,
|
|
106
|
-
uid,
|
|
107
|
-
slugs,
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export default DocumentData
|
package/src/documents/index.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,96 +0,0 @@
|
|
|
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, EmbedContentO } from "./nestable/EmbedContent"
|
|
8
|
-
import FieldContent, { FieldType } 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
|
-
| EmbedContentO
|
|
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 as FieldType, 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
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import * as O from "fp-ts/Option"
|
|
2
|
-
|
|
3
|
-
import { GroupContent, GroupContentType } from "./GroupContent"
|
|
4
|
-
import {
|
|
5
|
-
NonEmptySimpleWidgetContent,
|
|
6
|
-
SimpleWidgetContent,
|
|
7
|
-
} from "./SimpleWidgetContent"
|
|
8
|
-
|
|
9
|
-
type StaticWidgetContent = SimpleWidgetContent | GroupContent
|
|
10
|
-
export type NonEmptyStaticWidgetContent =
|
|
11
|
-
| NonEmptySimpleWidgetContent
|
|
12
|
-
| GroupContent
|
|
13
|
-
|
|
14
|
-
const StaticWidgetContent = {
|
|
15
|
-
fromJson: (
|
|
16
|
-
prefixes: Array<string>,
|
|
17
|
-
key: string,
|
|
18
|
-
value: unknown,
|
|
19
|
-
fieldTypes: Map<string, string>,
|
|
20
|
-
fieldPositions: Map<string, number>,
|
|
21
|
-
): O.Option<StaticWidgetContent> => {
|
|
22
|
-
const prefixedKey = Array.of(prefixes, [key]).flat().join(".")
|
|
23
|
-
const type = fieldTypes.get(prefixedKey)
|
|
24
|
-
if (type === "Group") {
|
|
25
|
-
return GroupContent.fromJson(
|
|
26
|
-
prefixes,
|
|
27
|
-
key,
|
|
28
|
-
value,
|
|
29
|
-
fieldTypes,
|
|
30
|
-
fieldPositions,
|
|
31
|
-
)
|
|
32
|
-
} else if (type) {
|
|
33
|
-
return SimpleWidgetContent.from(type, value)
|
|
34
|
-
} else {
|
|
35
|
-
return O.none
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
is: (value: unknown): value is StaticWidgetContent => {
|
|
39
|
-
return (
|
|
40
|
-
SimpleWidgetContent.is(value) ||
|
|
41
|
-
GroupContentType === (value as StaticWidgetContent).__TYPE__
|
|
42
|
-
)
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export default StaticWidgetContent
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Chain } from "fp-ts/Either"
|
|
2
|
-
import * as t from "io-ts"
|
|
3
|
-
|
|
4
|
-
export type UIDContent = {
|
|
5
|
-
__TYPE__: "UIDContent"
|
|
6
|
-
value: string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const UIDContentType = "UIDContent"
|
|
10
|
-
export const UIDContent = new t.Type<UIDContent, string>(
|
|
11
|
-
"UIDContent",
|
|
12
|
-
(u): u is UIDContent => (u as UIDContent)?.__TYPE__ === UIDContentType,
|
|
13
|
-
(u, c) =>
|
|
14
|
-
Chain.chain(t.string.validate(u, c), (u) => {
|
|
15
|
-
return t.success({ value: u, __TYPE__: "UIDContent" } as const)
|
|
16
|
-
}),
|
|
17
|
-
(uidContent) => uidContent.value,
|
|
18
|
-
)
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts"
|
|
2
|
-
|
|
3
|
-
import { refineType } from "../../validators/function"
|
|
4
|
-
import { EmptyContentType } from "./EmptyContent"
|
|
5
|
-
import { GroupContentType } from "./GroupContent"
|
|
6
|
-
import { NestableTypes } from "./nestable"
|
|
7
|
-
import { SlicesContent, SlicesContentType } from "./slices"
|
|
8
|
-
import StaticWidgetContent from "./StaticWidgetContent"
|
|
9
|
-
import { UIDContentType } from "./UIDContent"
|
|
10
|
-
|
|
11
|
-
export * from "./EmptyContent"
|
|
12
|
-
export * from "./GroupContent"
|
|
13
|
-
export * as Nestable from "./nestable"
|
|
14
|
-
export * from "./SimpleWidgetContent"
|
|
15
|
-
export * as Slices from "./slices"
|
|
16
|
-
export {
|
|
17
|
-
type NonEmptyStaticWidgetContent,
|
|
18
|
-
default as StaticWidgetContent,
|
|
19
|
-
} from "./StaticWidgetContent"
|
|
20
|
-
export * from "./UIDContent"
|
|
21
|
-
|
|
22
|
-
export const WidgetTypes = {
|
|
23
|
-
...NestableTypes,
|
|
24
|
-
Empty: EmptyContentType,
|
|
25
|
-
UID: UIDContentType,
|
|
26
|
-
Group: GroupContentType,
|
|
27
|
-
slices: SlicesContentType,
|
|
28
|
-
} as const
|
|
29
|
-
|
|
30
|
-
export type WidgetTypes = typeof WidgetTypes[keyof typeof WidgetTypes]
|
|
31
|
-
|
|
32
|
-
const widgetKeyRegex = new RegExp("^[^<>]+$")
|
|
33
|
-
|
|
34
|
-
export const WidgetKey = refineType(
|
|
35
|
-
t.string,
|
|
36
|
-
"WidgetKey",
|
|
37
|
-
(s: string) => s.length === 0 || widgetKeyRegex.test(s),
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
export type WidgetKey = t.TypeOf<typeof WidgetKey>
|
|
41
|
-
|
|
42
|
-
export type WidgetContent = SlicesContent | StaticWidgetContent
|
|
43
|
-
|
|
44
|
-
export const Widget = {
|
|
45
|
-
fromJson(
|
|
46
|
-
widgetKey: WidgetKey,
|
|
47
|
-
widgetValue: unknown,
|
|
48
|
-
widgetTypes: Map<WidgetKey, string>,
|
|
49
|
-
widgetPositions: Map<WidgetKey, number>,
|
|
50
|
-
) {
|
|
51
|
-
const fieldType = widgetTypes.get(widgetKey)
|
|
52
|
-
|
|
53
|
-
if (fieldType === "Slices") {
|
|
54
|
-
return SlicesContent.fromJson(
|
|
55
|
-
widgetKey,
|
|
56
|
-
widgetValue,
|
|
57
|
-
widgetTypes,
|
|
58
|
-
widgetPositions,
|
|
59
|
-
)
|
|
60
|
-
} else {
|
|
61
|
-
return StaticWidgetContent.fromJson(
|
|
62
|
-
[],
|
|
63
|
-
widgetKey,
|
|
64
|
-
widgetValue,
|
|
65
|
-
widgetTypes,
|
|
66
|
-
widgetPositions,
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Chain } from "fp-ts/Either"
|
|
2
|
-
import * as t from "io-ts"
|
|
3
|
-
|
|
4
|
-
type BooleanContent = {
|
|
5
|
-
__TYPE__: "BooleanContent"
|
|
6
|
-
value: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const BooleanContentType = "BooleanContent"
|
|
10
|
-
const BooleanContent = new t.Type<BooleanContent, boolean>(
|
|
11
|
-
"BooleanContent",
|
|
12
|
-
(u): u is BooleanContent =>
|
|
13
|
-
(u as BooleanContent)?.__TYPE__ === BooleanContentType,
|
|
14
|
-
(u, c) =>
|
|
15
|
-
Chain.chain(t.boolean.validate(u, c), (u) => {
|
|
16
|
-
return t.success({ value: u, __TYPE__: BooleanContentType } as const)
|
|
17
|
-
}),
|
|
18
|
-
(booleanContent) => t.boolean.encode(booleanContent.value),
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
export default BooleanContent
|