@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,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Slices = exports.DynamicSlices = exports.StaticSlices = exports.slicesReader = exports.DynamicSlicesConfig = exports.StaticSlicesConfig = exports.slicesConfigReader = exports.SlicesLabels = void 0;
|
|
3
|
+
exports.Slices = exports.DynamicSlices = exports.StaticSlices = exports.slicesReader = exports.DynamicSlicesConfig = exports.StaticSlicesConfig = exports.slicesConfigReader = exports.SlicesLabels = exports.SlicesFieldType = exports.LegacySlicesFieldType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
-
const
|
|
6
|
+
const common_1 = require("../../../common");
|
|
7
7
|
const validators_1 = require("../../../validators");
|
|
8
|
-
const WidgetTypes_1 = require("../WidgetTypes");
|
|
9
8
|
const CompositeSlice_1 = (0, tslib_1.__importDefault)(require("./CompositeSlice"));
|
|
10
9
|
const LegacySlice_1 = (0, tslib_1.__importDefault)(require("./LegacySlice"));
|
|
11
10
|
const SharedSlice_1 = require("./SharedSlice");
|
|
12
11
|
const SharedSliceRef_1 = (0, tslib_1.__importDefault)(require("./SharedSliceRef"));
|
|
13
|
-
|
|
12
|
+
exports.LegacySlicesFieldType = "Choice";
|
|
13
|
+
exports.SlicesFieldType = "Slices";
|
|
14
14
|
exports.SlicesLabels = t.union([
|
|
15
15
|
t.record(t.string, t.readonlyArray(t.exact(t.intersection([
|
|
16
16
|
t.type({
|
|
@@ -26,7 +26,7 @@ function slicesConfigReader(codec) {
|
|
|
26
26
|
return t.exact(t.partial({
|
|
27
27
|
label: validators_1.StringOrNull,
|
|
28
28
|
labels: exports.SlicesLabels,
|
|
29
|
-
choices: t.record(
|
|
29
|
+
choices: t.record(common_1.WidgetKey, t.union([LegacySlice_1.default, CompositeSlice_1.default, codec])),
|
|
30
30
|
}));
|
|
31
31
|
}
|
|
32
32
|
exports.slicesConfigReader = slicesConfigReader;
|
|
@@ -35,7 +35,7 @@ exports.DynamicSlicesConfig = slicesConfigReader(SharedSliceRef_1.default);
|
|
|
35
35
|
const SlicesConfig = {
|
|
36
36
|
toStatic(config, sharedSlices) {
|
|
37
37
|
const choices = Object.entries(config.choices || {}).reduce((acc, [ref, slice]) => {
|
|
38
|
-
if (slice.type ===
|
|
38
|
+
if (slice.type === "SharedSlice") {
|
|
39
39
|
const sharedSlice = sharedSlices.get(ref);
|
|
40
40
|
if (sharedSlice)
|
|
41
41
|
return { ...acc, [ref]: sharedSlice };
|
|
@@ -53,8 +53,8 @@ function slicesReader(codec) {
|
|
|
53
53
|
return t.exact(t.intersection([
|
|
54
54
|
t.type({
|
|
55
55
|
type: t.union([
|
|
56
|
-
t.literal(
|
|
57
|
-
t.literal(
|
|
56
|
+
t.literal(exports.SlicesFieldType),
|
|
57
|
+
t.literal(exports.LegacySlicesFieldType),
|
|
58
58
|
]),
|
|
59
59
|
}),
|
|
60
60
|
t.partial({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const SlicesTypes: t.KeyofC<{
|
|
3
|
+
Slice: null;
|
|
4
|
+
SharedSlice: null;
|
|
5
|
+
}>;
|
|
6
|
+
export declare type SlicesTypes = t.TypeOf<typeof SlicesTypes>;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SlicesTypes = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const CompositeSlice_1 = require("./CompositeSlice");
|
|
7
|
+
const SharedSlice_1 = require("./SharedSlice");
|
|
8
|
+
exports.SlicesTypes = t.keyof({
|
|
9
|
+
[CompositeSlice_1.CompositeSliceType]: null,
|
|
10
|
+
[SharedSlice_1.SharedSliceType]: null,
|
|
11
|
+
});
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
declare type DocumentData = Map<WidgetKey, O.Option<WidgetContent>>;
|
|
1
|
+
import { WidgetContent, WidgetKey } from "../content";
|
|
2
|
+
import type { FieldTypes } from "../customtypes/widgets";
|
|
4
3
|
declare const DocumentData: {
|
|
5
|
-
getWidget(key: WidgetKey,
|
|
6
|
-
fromJson(widgets: Map<WidgetKey, unknown>, widgetTypes: Map<WidgetKey, string>, widgetPositions: Map<WidgetKey, number>): DocumentData;
|
|
7
|
-
partitionData(data: {
|
|
8
|
-
[p: string]: unknown;
|
|
9
|
-
}): {
|
|
10
|
-
types: Map<string, string>;
|
|
11
|
-
positions: Map<string, number>;
|
|
12
|
-
widgets: Map<WidgetKey, unknown>;
|
|
13
|
-
slugs: ReadonlyArray<string>;
|
|
14
|
-
uid: string | undefined;
|
|
15
|
-
};
|
|
4
|
+
getWidget(key: WidgetKey, widgetTypes: Map<WidgetKey, FieldTypes>, parsed: Map<string, WidgetContent>): WidgetContent | undefined;
|
|
16
5
|
};
|
|
17
6
|
export default DocumentData;
|
|
@@ -1,70 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const O = (0, tslib_1.__importStar)(require("fp-ts/lib/Option"));
|
|
6
|
-
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
-
const widgets_1 = require("./widgets");
|
|
8
|
-
function computeWidget(key, widgets, widgetTypes, widgetPositions) {
|
|
9
|
-
const widget = widgets.get(key);
|
|
10
|
-
if (widget === undefined) {
|
|
11
|
-
return O.none;
|
|
12
|
-
}
|
|
13
|
-
return widgets_1.Widget.fromJson(key, widget, widgetTypes, widgetPositions);
|
|
14
|
-
}
|
|
3
|
+
const content_1 = require("../content");
|
|
4
|
+
const LegacyContentCtx_1 = require("../content/LegacyContentCtx");
|
|
15
5
|
const DocumentData = {
|
|
16
|
-
getWidget(key,
|
|
6
|
+
getWidget(key, widgetTypes, parsed) {
|
|
17
7
|
const widget = parsed.get(key);
|
|
18
8
|
if (widget === undefined) {
|
|
19
|
-
|
|
9
|
+
const res = (0, content_1.WidgetLegacy)((0, LegacyContentCtx_1.defaultCtx)(key, widgetTypes)).decode(parsed);
|
|
10
|
+
return !res || res._tag === "Left" ? undefined : res.right;
|
|
20
11
|
}
|
|
21
12
|
return widget;
|
|
22
13
|
},
|
|
23
|
-
fromJson(widgets, widgetTypes, widgetPositions) {
|
|
24
|
-
return Array.from(widgets.keys()).reduce((acc, widgetKey) => {
|
|
25
|
-
const parsedWidget = this.getWidget(widgetKey, widgets, widgetTypes, widgetPositions, acc);
|
|
26
|
-
return new Map([...Array.from(acc.entries()), [widgetKey, parsedWidget]]);
|
|
27
|
-
}, new Map());
|
|
28
|
-
},
|
|
29
|
-
partitionData(data) {
|
|
30
|
-
const fields = Object.entries(data);
|
|
31
|
-
const { types, positions, widgets } = fields.reduce((acc, [k, v]) => {
|
|
32
|
-
if (k.endsWith("_TYPE")) {
|
|
33
|
-
const decodedValue = t.string.decode(v);
|
|
34
|
-
if ((0, Either_1.isRight)(decodedValue)) {
|
|
35
|
-
return {
|
|
36
|
-
...acc,
|
|
37
|
-
types: acc.types.set(k.substring(0, k.length - 5), decodedValue.right),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
if (k.endsWith("_POSITION") && typeof v === "number") {
|
|
42
|
-
return {
|
|
43
|
-
...acc,
|
|
44
|
-
positions: acc.positions.set(k.substring(0, k.length - 9), v),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
if (!k.endsWith("_POSITION") && !k.endsWith("_TYPE")) {
|
|
48
|
-
return {
|
|
49
|
-
...acc,
|
|
50
|
-
widgets: acc.widgets.set(k, v),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return acc;
|
|
54
|
-
}, {
|
|
55
|
-
types: new Map(),
|
|
56
|
-
positions: new Map(),
|
|
57
|
-
widgets: new Map(),
|
|
58
|
-
});
|
|
59
|
-
const slugs = data["slugs_INTERNAL"] || [];
|
|
60
|
-
const uid = data["uid"];
|
|
61
|
-
return {
|
|
62
|
-
widgets,
|
|
63
|
-
types,
|
|
64
|
-
positions,
|
|
65
|
-
uid,
|
|
66
|
-
slugs,
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
14
|
};
|
|
70
15
|
exports.default = DocumentData;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
export declare const ImageContentType = "ImageContent";
|
|
2
3
|
export declare const ImageContentView: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
3
4
|
origin: t.ExactC<t.TypeC<{
|
|
4
5
|
id: t.StringC;
|
|
@@ -23,7 +24,6 @@ export declare const ImageContentView: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
23
24
|
provider: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
24
25
|
}>]>>;
|
|
25
26
|
export declare type ImageContentView = t.TypeOf<typeof ImageContentView>;
|
|
26
|
-
export declare const ImageContentType = "ImageContent";
|
|
27
27
|
export declare const ImageContent: t.Type<{
|
|
28
28
|
origin: {
|
|
29
29
|
id: string;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImageContent = exports.
|
|
3
|
+
exports.ImageContent = exports.ImageContentView = exports.ImageContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const validators_1 = require("../../../validators");
|
|
7
7
|
const function_1 = require("../../../validators/function");
|
|
8
|
+
exports.ImageContentType = "ImageContent";
|
|
8
9
|
const Origin = t.exact(t.type({
|
|
9
10
|
id: t.string,
|
|
10
11
|
url: t.string,
|
|
@@ -32,7 +33,6 @@ exports.ImageContentView = t.exact(t.intersection([
|
|
|
32
33
|
provider: validators_1.StringOrNull,
|
|
33
34
|
}),
|
|
34
35
|
]));
|
|
35
|
-
exports.ImageContentType = "ImageContent";
|
|
36
36
|
exports.ImageContent = (0, function_1.addType)(t.intersection([
|
|
37
37
|
exports.ImageContentView,
|
|
38
38
|
t.partial({
|
package/lib/utils/Objects.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export declare function zipObjects<A, B = A>(objLeft?: Partial<Record<string, A>
|
|
|
3
3
|
right?: B | undefined;
|
|
4
4
|
}>>;
|
|
5
5
|
export declare function isNotEmpty<A extends object>(obj: A): boolean;
|
|
6
|
+
export declare function withOptionals<T extends object>(object: T, optionals: Array<[keyof T, T[keyof T] | null | undefined]>): T;
|
package/lib/utils/Objects.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNotEmpty = exports.zipObjects = void 0;
|
|
3
|
+
exports.withOptionals = exports.isNotEmpty = exports.zipObjects = void 0;
|
|
4
4
|
function zipObjects(objLeft, objRight) {
|
|
5
5
|
const allKeys = [
|
|
6
6
|
...new Set(Object.keys(objLeft || {}).concat(Object.keys(objRight || {}))),
|
|
@@ -19,3 +19,12 @@ function isNotEmpty(obj) {
|
|
|
19
19
|
return Boolean(Object.keys(obj).length);
|
|
20
20
|
}
|
|
21
21
|
exports.isNotEmpty = isNotEmpty;
|
|
22
|
+
function withOptionals(object, optionals) {
|
|
23
|
+
return {
|
|
24
|
+
...object,
|
|
25
|
+
...optionals.reduce((acc, [key, value]) => {
|
|
26
|
+
return value ? { ...acc, [key]: value } : acc;
|
|
27
|
+
}, {}),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
exports.withOptionals = withOptionals;
|
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { refineType } from "../validators/function"
|
|
4
|
+
|
|
5
|
+
const widgetKeyRegex = new RegExp("^[^<>]+$")
|
|
6
|
+
|
|
7
|
+
export const WidgetKey = refineType(
|
|
8
|
+
t.string,
|
|
9
|
+
"WidgetKey",
|
|
10
|
+
(s: string) => s.length === 0 || widgetKeyRegex.test(s),
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
export type WidgetKey = t.TypeOf<typeof WidgetKey>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./WidgetKey"
|
package/src/content/Document.ts
CHANGED
|
@@ -1,21 +1,134 @@
|
|
|
1
|
+
import { either } from "fp-ts"
|
|
2
|
+
import { pipe } from "fp-ts/lib/function"
|
|
1
3
|
import * as t from "io-ts"
|
|
2
4
|
|
|
3
|
-
import { WidgetKey
|
|
5
|
+
import { WidgetKey } from "../common"
|
|
6
|
+
import { WidgetContent, WidgetLegacy } from "./fields"
|
|
4
7
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "./
|
|
10
|
-
|
|
11
|
-
export const WidgetKey = KeyForWidgetContent
|
|
12
|
-
export type WidgetKey = KeyForWidgetContent
|
|
13
|
-
|
|
14
|
-
const WidgetContent = t.union([
|
|
15
|
-
SlicesContent,
|
|
16
|
-
UIDContent,
|
|
17
|
-
NestableContent,
|
|
18
|
-
GroupContent,
|
|
19
|
-
])
|
|
8
|
+
defaultCtx,
|
|
9
|
+
FieldOrSliceType,
|
|
10
|
+
LegacyContentCtx,
|
|
11
|
+
WithTypes,
|
|
12
|
+
} from "./LegacyContentCtx"
|
|
13
|
+
|
|
20
14
|
export const Document = t.record(WidgetKey, WidgetContent)
|
|
21
15
|
export type Document = t.TypeOf<typeof Document>
|
|
16
|
+
|
|
17
|
+
const legacyDocReader = t.record(WidgetKey, t.unknown)
|
|
18
|
+
type DocumentLegacy = t.TypeOf<typeof legacyDocReader>
|
|
19
|
+
|
|
20
|
+
const DocumentLegacyCodec = (allTypes?: LegacyContentCtx["allTypes"]) => {
|
|
21
|
+
return new t.Type<Document, WithTypes<DocumentLegacy>, unknown>(
|
|
22
|
+
"Document",
|
|
23
|
+
(u): u is Document => !!u && typeof u === "object",
|
|
24
|
+
(doc) => {
|
|
25
|
+
return pipe(
|
|
26
|
+
legacyDocReader.decode(doc),
|
|
27
|
+
either.map((parsedDoc) => {
|
|
28
|
+
return Object.entries(parsedDoc).reduce(
|
|
29
|
+
(acc, [widgetKey, widgetValue]) => {
|
|
30
|
+
const widgetCtx = defaultCtx(widgetKey, allTypes)
|
|
31
|
+
const parsedW = WidgetLegacy(widgetCtx).decode(widgetValue)
|
|
32
|
+
if (!parsedW || parsedW?._tag === "Left") return acc
|
|
33
|
+
|
|
34
|
+
return { ...acc, [widgetKey]: parsedW.right }
|
|
35
|
+
},
|
|
36
|
+
{},
|
|
37
|
+
)
|
|
38
|
+
}),
|
|
39
|
+
)
|
|
40
|
+
},
|
|
41
|
+
(g: Document) => {
|
|
42
|
+
return Object.entries(g).reduce(
|
|
43
|
+
(acc, [key, value]) => {
|
|
44
|
+
const widgetCtx = defaultCtx(key, allTypes)
|
|
45
|
+
const result = WidgetLegacy(widgetCtx).encode(value)
|
|
46
|
+
if (!result) return acc
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
content: { ...acc.content, [key]: result.content },
|
|
50
|
+
types: { ...acc.types, ...result.types },
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{ content: {}, types: {} },
|
|
54
|
+
)
|
|
55
|
+
},
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function extractMetadata(data: { [p: string]: unknown }): {
|
|
60
|
+
types: Map<string, FieldOrSliceType>
|
|
61
|
+
widgets: Partial<Record<WidgetKey, unknown>>
|
|
62
|
+
slugs: ReadonlyArray<string>
|
|
63
|
+
uid: string | undefined
|
|
64
|
+
} {
|
|
65
|
+
const fields: [string, unknown][] = Object.entries(data)
|
|
66
|
+
|
|
67
|
+
const { types, widgets } = fields.reduce(
|
|
68
|
+
(acc, [k, v]) => {
|
|
69
|
+
if (k.endsWith("_TYPE")) {
|
|
70
|
+
const decodedValue = FieldOrSliceType.decode(v)
|
|
71
|
+
if (decodedValue._tag === "Right") {
|
|
72
|
+
return {
|
|
73
|
+
...acc,
|
|
74
|
+
types: acc.types.set(
|
|
75
|
+
k.substring(0, k.length - 5),
|
|
76
|
+
decodedValue.right,
|
|
77
|
+
),
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!k.endsWith("_POSITION") && !k.endsWith("_TYPE")) {
|
|
82
|
+
return {
|
|
83
|
+
...acc,
|
|
84
|
+
widgets: {
|
|
85
|
+
...acc.widgets,
|
|
86
|
+
[k]: v,
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return acc
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
types: new Map<string, FieldOrSliceType>(),
|
|
94
|
+
widgets: {},
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
const slugs = (data["slugs_INTERNAL"] as string[]) || []
|
|
99
|
+
const uid = data["uid"] as string | undefined
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
widgets,
|
|
103
|
+
types,
|
|
104
|
+
uid,
|
|
105
|
+
slugs,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parseLegacyDocument(legacyDoc: unknown): Document | undefined {
|
|
110
|
+
const result = pipe(
|
|
111
|
+
// ensure it's the right document format first
|
|
112
|
+
t.record(WidgetKey, t.unknown).decode(legacyDoc),
|
|
113
|
+
either.chain((doc) => {
|
|
114
|
+
// extract all metadata, meaning all _TYPES keys from legacy format + the widgets as unknown
|
|
115
|
+
const { types, widgets } = extractMetadata(doc)
|
|
116
|
+
// parse the actual widgets
|
|
117
|
+
return DocumentLegacyCodec(types).decode(widgets)
|
|
118
|
+
}),
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
return result._tag === "Left" ? undefined : result.right
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function encodeToLegacyDocument(document: Document): DocumentLegacy {
|
|
125
|
+
const encoded = DocumentLegacyCodec().encode(document)
|
|
126
|
+
return { ...encoded.content, ...encoded.types }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export const DocumentLegacy = {
|
|
130
|
+
_codec: DocumentLegacyCodec,
|
|
131
|
+
extractMetadata,
|
|
132
|
+
parse: parseLegacyDocument,
|
|
133
|
+
encode: encodeToLegacyDocument,
|
|
134
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
|
|
3
|
+
import { FieldTypes, SlicesTypes } from "../customtypes/widgets"
|
|
4
|
+
|
|
5
|
+
export const FieldOrSliceType = t.union([FieldTypes, SlicesTypes])
|
|
6
|
+
export type FieldOrSliceType = t.TypeOf<typeof FieldOrSliceType>
|
|
7
|
+
export class LegacyContentCtx {
|
|
8
|
+
fieldKey: string
|
|
9
|
+
prefixedKey: string
|
|
10
|
+
keyOfType: string
|
|
11
|
+
fieldPath: Array<string>
|
|
12
|
+
fieldType?: FieldOrSliceType | undefined
|
|
13
|
+
allTypes: Map<string, FieldOrSliceType>
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
fieldKey: string,
|
|
17
|
+
fieldPath?: Array<string>,
|
|
18
|
+
allTypes?: Map<string, FieldOrSliceType>,
|
|
19
|
+
) {
|
|
20
|
+
this.fieldKey = fieldKey
|
|
21
|
+
this.fieldPath = fieldPath || []
|
|
22
|
+
this.allTypes = allTypes || new Map<string, FieldOrSliceType>()
|
|
23
|
+
|
|
24
|
+
const prefixedKey = Array.of(this.fieldPath, [this.fieldKey])
|
|
25
|
+
.flat()
|
|
26
|
+
.join(".")
|
|
27
|
+
|
|
28
|
+
this.prefixedKey = prefixedKey
|
|
29
|
+
this.keyOfType = `${prefixedKey}_TYPE`
|
|
30
|
+
|
|
31
|
+
this.fieldType = this.allTypes.get(this.prefixedKey)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getFieldCtx(
|
|
36
|
+
fieldKey: string,
|
|
37
|
+
ctx: LegacyContentCtx,
|
|
38
|
+
prefixes?: Array<string>,
|
|
39
|
+
): LegacyContentCtx {
|
|
40
|
+
return new LegacyContentCtx(
|
|
41
|
+
fieldKey,
|
|
42
|
+
[...ctx.fieldPath, ctx.fieldKey, ...(prefixes || [])],
|
|
43
|
+
ctx.allTypes,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function defaultCtx(
|
|
48
|
+
key: string,
|
|
49
|
+
allTypes: Map<string, FieldOrSliceType> = new Map(),
|
|
50
|
+
): LegacyContentCtx {
|
|
51
|
+
return new LegacyContentCtx(key, [], allTypes)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type WithTypes<T> = {
|
|
55
|
+
types: Record<string, FieldOrSliceType>
|
|
56
|
+
content: T
|
|
57
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { either } from "fp-ts"
|
|
2
|
+
import { pipe } from "fp-ts/lib/function"
|
|
3
|
+
import * as t from "io-ts"
|
|
4
|
+
|
|
5
|
+
import type { FieldOrSliceType } from "../LegacyContentCtx"
|
|
6
|
+
import { hasContentType } from "../utils"
|
|
7
|
+
|
|
8
|
+
export const EmptyContentType = "EmptyContent"
|
|
9
|
+
|
|
10
|
+
export const isEmptyContent = (u: unknown): u is EmptyContent =>
|
|
11
|
+
hasContentType(u) && u.__TYPE__ === EmptyContentType
|
|
12
|
+
|
|
13
|
+
const legacyReader = t.union([
|
|
14
|
+
t.null,
|
|
15
|
+
t.type({
|
|
16
|
+
value: t.null,
|
|
17
|
+
}),
|
|
18
|
+
])
|
|
19
|
+
type EmptyLegacy = t.TypeOf<typeof legacyReader>
|
|
20
|
+
|
|
21
|
+
export const EmptyLegacy = (type: FieldOrSliceType) =>
|
|
22
|
+
new t.Type<EmptyContent, unknown, unknown>(
|
|
23
|
+
"EmptyLegacy",
|
|
24
|
+
isEmptyContent,
|
|
25
|
+
(content) => {
|
|
26
|
+
return pipe(
|
|
27
|
+
legacyReader.decode(content),
|
|
28
|
+
either.map(() => {
|
|
29
|
+
return {
|
|
30
|
+
type,
|
|
31
|
+
__TYPE__: EmptyContentType,
|
|
32
|
+
}
|
|
33
|
+
}),
|
|
34
|
+
)
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
() => null,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
export const EmptyContent = t.strict({
|
|
41
|
+
type: t.string,
|
|
42
|
+
__TYPE__: t.literal(EmptyContentType),
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
export type EmptyContent = t.TypeOf<typeof EmptyContent>
|
|
@@ -1,21 +1,116 @@
|
|
|
1
|
+
import { either } from "fp-ts"
|
|
2
|
+
import { pipe } from "fp-ts/lib/function"
|
|
1
3
|
import * as t from "io-ts"
|
|
2
4
|
|
|
3
5
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
FieldOrSliceType,
|
|
7
|
+
getFieldCtx,
|
|
8
|
+
LegacyContentCtx,
|
|
9
|
+
WithTypes,
|
|
10
|
+
} from "../LegacyContentCtx"
|
|
11
|
+
import { hasContentType } from "../utils"
|
|
12
|
+
import { NestableContent, NestableLegacy } from "./nestable"
|
|
13
|
+
|
|
14
|
+
export const GroupItemContentType = "GroupItemContent" as const
|
|
8
15
|
|
|
9
16
|
export const GroupItemContent = t.strict({
|
|
10
|
-
__TYPE__: t.literal(
|
|
17
|
+
__TYPE__: t.literal(GroupItemContentType),
|
|
11
18
|
value: t.array(t.tuple([t.string, NestableContent])),
|
|
12
19
|
})
|
|
13
20
|
export type GroupItemContent = t.TypeOf<typeof GroupItemContent>
|
|
14
|
-
|
|
21
|
+
|
|
22
|
+
const itemLegacyReader = t.array(t.tuple([t.string, t.unknown]))
|
|
23
|
+
export type GroupItemLegacy = t.TypeOf<typeof itemLegacyReader>
|
|
24
|
+
|
|
25
|
+
export const GroupItemLegacy = (ctx: LegacyContentCtx) => {
|
|
26
|
+
return new t.Type<GroupItemContent, WithTypes<GroupItemLegacy>>(
|
|
27
|
+
"GroupItemLegacy",
|
|
28
|
+
(u): u is GroupItemContent =>
|
|
29
|
+
hasContentType(u) && u.__TYPE__ === GroupItemContentType,
|
|
30
|
+
(u) => {
|
|
31
|
+
const parsed = pipe(
|
|
32
|
+
itemLegacyReader.decode(u),
|
|
33
|
+
either.map((items) => {
|
|
34
|
+
const parsedItems = items.reduce<Array<[string, NestableContent]>>(
|
|
35
|
+
(acc, [itemKey, itemValue]) => {
|
|
36
|
+
const itemCtx = getFieldCtx(itemKey, ctx)
|
|
37
|
+
const result = NestableLegacy(itemCtx).decode(itemValue)
|
|
38
|
+
if (!result) return acc
|
|
39
|
+
|
|
40
|
+
if (result._tag === "Right")
|
|
41
|
+
return [...acc, [itemKey, result.right]]
|
|
42
|
+
else return acc
|
|
43
|
+
},
|
|
44
|
+
[],
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
value: parsedItems,
|
|
49
|
+
__TYPE__: GroupItemContentType,
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
)
|
|
53
|
+
return parsed
|
|
54
|
+
},
|
|
55
|
+
(item) => {
|
|
56
|
+
return item.value.reduce<WithTypes<GroupItemLegacy>>(
|
|
57
|
+
(acc, [key, value]) => {
|
|
58
|
+
const itemCtx = getFieldCtx(key, ctx)
|
|
59
|
+
const encoded = NestableLegacy(itemCtx).encode(value)
|
|
60
|
+
if (!encoded) return acc
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
content: [...acc.content, [key, encoded.content]],
|
|
64
|
+
types: { ...acc.types, ...encoded.types },
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{ content: [], types: {} },
|
|
68
|
+
)
|
|
69
|
+
},
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type GroupLegacy = Array<GroupItemLegacy>
|
|
74
|
+
export const GroupLegacy = (ctx: LegacyContentCtx) => {
|
|
75
|
+
const codec = t.array(GroupItemLegacy(ctx))
|
|
76
|
+
|
|
77
|
+
return new t.Type<GroupContent, WithTypes<GroupLegacy>, unknown>(
|
|
78
|
+
"GroupLegacy",
|
|
79
|
+
isGroupContent,
|
|
80
|
+
(items) => {
|
|
81
|
+
return pipe(
|
|
82
|
+
codec.decode(items),
|
|
83
|
+
either.map((parsedItems) => {
|
|
84
|
+
return {
|
|
85
|
+
value: parsedItems,
|
|
86
|
+
__TYPE__: GroupContentType,
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
)
|
|
90
|
+
},
|
|
91
|
+
(g: GroupContent) => {
|
|
92
|
+
const res = codec.encode(g.value)
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
content: res.map((block) => block.content),
|
|
96
|
+
types: res.reduce<Record<string, FieldOrSliceType>>(
|
|
97
|
+
(acc, block) => {
|
|
98
|
+
return { ...acc, ...block.types }
|
|
99
|
+
},
|
|
100
|
+
{ [ctx.keyOfType]: "Group" },
|
|
101
|
+
),
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const GroupContentType = "GroupContentType" as const
|
|
108
|
+
|
|
109
|
+
export const isGroupContent = (u: unknown): u is GroupContent =>
|
|
110
|
+
hasContentType(u) && u.__TYPE__ === GroupContentType
|
|
15
111
|
|
|
16
112
|
export const GroupContent = t.strict({
|
|
17
|
-
__TYPE__: t.literal(
|
|
113
|
+
__TYPE__: t.literal(GroupContentType),
|
|
18
114
|
value: t.array(GroupItemContent),
|
|
19
115
|
})
|
|
20
116
|
export type GroupContent = t.TypeOf<typeof GroupContent>
|
|
21
|
-
export const GroupContentType = groupType
|