@prismicio/types-internal 2.2.0-traverse.alpha-2 → 2.2.0-traverse.alpha-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/lib/content/Document.d.ts +13 -4
- package/lib/content/Document.js +7 -74
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +1 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +30 -1
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +1 -0
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +41 -1
- package/lib/customtypes/CustomType.d.ts +5 -2
- package/lib/customtypes/CustomType.js +1 -1
- package/lib/import/converters/fields/nestable/Image.d.ts +3 -1
- package/lib/import/converters/fields/nestable/Image.js +18 -2
- package/lib/import/converters/fields/nestable/Nestable.js +2 -0
- package/lib/import/converters/fields/nestable/RichText.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText.js +55 -0
- package/lib/import/converters/fields/nestable/index.d.ts +1 -0
- package/lib/import/converters/fields/nestable/index.js +1 -0
- package/lib/import/validators/fields/ImportField.d.ts +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +1 -1
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +1 -1
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +1 -1
- package/lib/import/validators/fields/nestable/Embed.d.ts +3 -0
- package/lib/import/validators/fields/nestable/Embed.js +3 -8
- package/lib/import/validators/fields/nestable/GeoPoint.js +2 -2
- package/lib/import/validators/fields/nestable/Image/default.d.ts +22 -0
- package/lib/import/validators/fields/nestable/Image/default.js +19 -0
- package/lib/import/validators/fields/nestable/Image/index.d.ts +19 -0
- package/lib/import/validators/fields/nestable/Image/index.js +22 -22
- package/lib/import/validators/fields/nestable/Image/merge.d.ts +23 -0
- package/lib/import/validators/fields/nestable/Image/{Decoder.js → merge.js} +18 -14
- package/lib/import/validators/fields/nestable/Image/{Validator.d.ts → validators.d.ts} +4 -2
- package/lib/import/validators/fields/nestable/Image/{Validator.js → validators.js} +7 -3
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +25 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +26 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +11 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +8 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +11 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +70 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +43 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +65 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +20 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +4 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +7 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +17 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +22 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.js +7 -0
- package/lib/import/validators/fields/nestable/Link.d.ts +21 -6
- package/lib/import/validators/fields/nestable/Link.js +8 -8
- package/lib/import/validators/fields/nestable/Nestable.d.ts +8 -1
- package/lib/import/validators/fields/nestable/Nestable.js +5 -1
- package/lib/import/validators/fields/nestable/index.d.ts +2 -1
- package/lib/import/validators/fields/nestable/index.js +4 -1
- package/package.json +1 -1
- package/src/content/Document.ts +22 -98
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +37 -1
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +45 -0
- package/src/customtypes/CustomType.ts +6 -5
- package/src/import/converters/fields/nestable/Image.ts +34 -4
- package/src/import/converters/fields/nestable/Nestable.ts +3 -0
- package/src/import/converters/fields/nestable/RichText.ts +62 -0
- package/src/import/converters/fields/nestable/index.ts +1 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +1 -1
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +1 -1
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +1 -1
- package/src/import/validators/fields/nestable/Embed.ts +4 -17
- package/src/import/validators/fields/nestable/GeoPoint.ts +2 -2
- package/src/import/validators/fields/nestable/Image/default.ts +25 -0
- package/src/import/validators/fields/nestable/Image/index.ts +34 -36
- package/src/import/validators/fields/nestable/Image/{Decoder.ts → merge.ts} +23 -20
- package/src/import/validators/fields/nestable/Image/{Validator.ts → validators.ts} +9 -2
- package/src/import/validators/fields/nestable/ImportRichText/ImportBlock.ts +39 -0
- package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +41 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.ts +44 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.ts +13 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +13 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.ts +56 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/Span.ts +44 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/index.ts +4 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.ts +24 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.ts +8 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.ts +26 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/index.ts +2 -0
- package/src/import/validators/fields/nestable/ImportRichText/index.ts +2 -0
- package/src/import/validators/fields/nestable/Link.ts +18 -13
- package/src/import/validators/fields/nestable/Nestable.ts +6 -1
- package/src/import/validators/fields/nestable/index.ts +2 -1
- package/lib/import/validators/fields/nestable/Image/Decoder.d.ts +0 -26
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpanLocation = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const validators_1 = require("../../../../../../../validators");
|
|
7
|
+
exports.SpanLocation = t.type({
|
|
8
|
+
start: validators_1.Number,
|
|
9
|
+
end: validators_1.Number,
|
|
10
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const TextSpanType: t.KeyofC<{
|
|
3
|
+
strong: null;
|
|
4
|
+
em: null;
|
|
5
|
+
label: null;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const TextSpan: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
8
|
+
type: t.KeyofC<{
|
|
9
|
+
strong: null;
|
|
10
|
+
em: null;
|
|
11
|
+
label: null;
|
|
12
|
+
}>;
|
|
13
|
+
}>, t.TypeC<{
|
|
14
|
+
start: t.NumberC;
|
|
15
|
+
end: t.NumberC;
|
|
16
|
+
}>]>>;
|
|
17
|
+
export declare type TextSpan = t.TypeOf<typeof TextSpan>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextSpan = exports.TextSpanType = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const SpanLocation_1 = require("./SpanLocation");
|
|
7
|
+
const TextSpanTypes = {
|
|
8
|
+
Strong: "strong",
|
|
9
|
+
Em: "em",
|
|
10
|
+
Label: "label",
|
|
11
|
+
};
|
|
12
|
+
exports.TextSpanType = t.keyof({
|
|
13
|
+
[TextSpanTypes.Strong]: null,
|
|
14
|
+
[TextSpanTypes.Em]: null,
|
|
15
|
+
[TextSpanTypes.Label]: null,
|
|
16
|
+
});
|
|
17
|
+
exports.TextSpan = t.exact(t.intersection([
|
|
18
|
+
t.type({
|
|
19
|
+
type: exports.TextSpanType,
|
|
20
|
+
}),
|
|
21
|
+
SpanLocation_1.SpanLocation,
|
|
22
|
+
]));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportRichText = exports.ImportBlock = void 0;
|
|
4
|
+
var ImportBlock_1 = require("./ImportBlock");
|
|
5
|
+
Object.defineProperty(exports, "ImportBlock", { enumerable: true, get: function () { return ImportBlock_1.ImportBlock; } });
|
|
6
|
+
var ImportRichText_1 = require("./ImportRichText");
|
|
7
|
+
Object.defineProperty(exports, "ImportRichText", { enumerable: true, get: function () { return ImportRichText_1.ImportRichText; } });
|
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
import type { TypeOf } from "io-ts";
|
|
2
2
|
import * as t from "io-ts";
|
|
3
|
-
declare const WebLink: t.IntersectionC<[t.TypeC<{
|
|
3
|
+
declare const WebLink: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
4
4
|
link_type: t.LiteralC<"Web">;
|
|
5
5
|
url: t.StringC;
|
|
6
6
|
}>, t.PartialC<{
|
|
7
7
|
target: t.StringC;
|
|
8
|
-
}>]
|
|
8
|
+
}>]>>;
|
|
9
9
|
export declare type WebLink = t.TypeOf<typeof WebLink>;
|
|
10
|
-
declare const DocumentLink: t.TypeC<{
|
|
10
|
+
declare const DocumentLink: t.ExactC<t.TypeC<{
|
|
11
11
|
link_type: t.LiteralC<"Document">;
|
|
12
12
|
id: t.Type<string, string, unknown>;
|
|
13
|
-
}
|
|
13
|
+
}>>;
|
|
14
14
|
export declare type DocumentLink = t.TypeOf<typeof DocumentLink>;
|
|
15
|
-
declare const MediaLink: t.TypeC<{
|
|
15
|
+
declare const MediaLink: t.ExactC<t.TypeC<{
|
|
16
16
|
link_type: t.LiteralC<"Media">;
|
|
17
17
|
id: t.StringC;
|
|
18
|
-
}
|
|
18
|
+
}>>;
|
|
19
19
|
export declare type MediaLink = t.TypeOf<typeof MediaLink>;
|
|
20
|
+
export declare const Link: t.Type<({
|
|
21
|
+
link_type: "Web";
|
|
22
|
+
url: string;
|
|
23
|
+
} & {
|
|
24
|
+
target?: string;
|
|
25
|
+
}) | {
|
|
26
|
+
link_type: "Document";
|
|
27
|
+
id: string;
|
|
28
|
+
} | {
|
|
29
|
+
link_type: "Media";
|
|
30
|
+
id: string;
|
|
31
|
+
}, {
|
|
32
|
+
link_type: "Document" | "Web" | "Media";
|
|
33
|
+
}, unknown>;
|
|
34
|
+
export declare type Link = TypeOf<typeof Link>;
|
|
20
35
|
export declare const ImportLink: t.Type<{
|
|
21
36
|
type: "Link";
|
|
22
37
|
value: ({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImportLink = void 0;
|
|
3
|
+
exports.ImportLink = exports.Link = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const DocumentId_1 = require("../../../../utils/DocumentId");
|
|
@@ -10,7 +10,7 @@ const ImportContent_1 = require("../ImportContent");
|
|
|
10
10
|
const LinkTypeValidator = t.type({
|
|
11
11
|
link_type: (0, function_1.withCustomError)(t.union([t.literal("Web"), t.literal("Document"), t.literal("Media")]), () => "The value must be `Web`, `Document` or `Media`"),
|
|
12
12
|
});
|
|
13
|
-
const WebLink = t.intersection([
|
|
13
|
+
const WebLink = t.exact(t.intersection([
|
|
14
14
|
t.type({
|
|
15
15
|
link_type: t.literal("Web"),
|
|
16
16
|
url: validators_1.String,
|
|
@@ -18,18 +18,18 @@ const WebLink = t.intersection([
|
|
|
18
18
|
t.partial({
|
|
19
19
|
target: validators_1.String,
|
|
20
20
|
}),
|
|
21
|
-
]);
|
|
22
|
-
const DocumentLink = t.
|
|
21
|
+
]));
|
|
22
|
+
const DocumentLink = t.strict({
|
|
23
23
|
link_type: t.literal("Document"),
|
|
24
24
|
id: DocumentId_1.DocumentId,
|
|
25
25
|
});
|
|
26
|
-
const MediaLink = t.
|
|
26
|
+
const MediaLink = t.strict({
|
|
27
27
|
link_type: t.literal("Media"),
|
|
28
28
|
id: validators_1.String,
|
|
29
29
|
});
|
|
30
|
-
|
|
30
|
+
exports.Link = LinkTypeValidator.pipe(t.union([WebLink, DocumentLink, MediaLink]));
|
|
31
31
|
// This is the default value for the link
|
|
32
|
-
const AnyLink = t.
|
|
32
|
+
const AnyLink = t.strict({
|
|
33
33
|
link_type: t.literal("Any"),
|
|
34
34
|
});
|
|
35
|
-
exports.ImportLink = (0, ImportContent_1.ImportContent)("Link", (0, validators_1.DefaultOrElse)(AnyLink)(Link));
|
|
35
|
+
exports.ImportLink = (0, ImportContent_1.ImportContent)("Link", (0, validators_1.DefaultOrElse)(AnyLink)(exports.Link));
|
|
@@ -5,12 +5,13 @@ import { ImportDate } from "./Date";
|
|
|
5
5
|
import { ImportEmbed } from "./Embed";
|
|
6
6
|
import { ImportGeoPoint } from "./GeoPoint";
|
|
7
7
|
import { ImportImage } from "./Image";
|
|
8
|
+
import { ImportRichText } from "./ImportRichText";
|
|
8
9
|
import { ImportLink } from "./Link";
|
|
9
10
|
import { ImportNumber } from "./Number";
|
|
10
11
|
import { ImportSelect } from "./Select";
|
|
11
12
|
import { ImportText } from "./Text";
|
|
12
13
|
import { ImportTimestamp } from "./Timestamp";
|
|
13
|
-
export declare type ImportNestable = ImportBoolean | ImportColor | ImportNumber | ImportSelect | ImportText | ImportDate | ImportTimestamp | ImportEmbed | ImportLink | ImportGeoPoint | ImportImage;
|
|
14
|
+
export declare type ImportNestable = ImportBoolean | ImportColor | ImportNumber | ImportSelect | ImportText | ImportDate | ImportTimestamp | ImportEmbed | ImportLink | ImportGeoPoint | ImportImage | ImportRichText;
|
|
14
15
|
export declare const ImportNestable: {
|
|
15
16
|
is(u: unknown): u is ImportNestable;
|
|
16
17
|
decode: (field: NestableWidget) => (content: unknown) => {
|
|
@@ -59,6 +60,9 @@ export declare const ImportNestable: {
|
|
|
59
60
|
}, {
|
|
60
61
|
link_type: "Document" | "Web" | "Media";
|
|
61
62
|
} | undefined, unknown> | import("io-ts").Type<{
|
|
63
|
+
type: "StructuredText";
|
|
64
|
+
value: import("./ImportRichText").ImportBlock[] | null;
|
|
65
|
+
}, unknown[] | undefined, unknown> | import("io-ts").Type<{
|
|
62
66
|
type: "Number";
|
|
63
67
|
value: number | null;
|
|
64
68
|
}, number | undefined, unknown> | import("io-ts").Type<{
|
|
@@ -83,6 +87,9 @@ export declare const ImportNestable: {
|
|
|
83
87
|
}> | import("fp-ts/lib/Either").Right<{
|
|
84
88
|
type: "Number";
|
|
85
89
|
value: number | null;
|
|
90
|
+
}> | import("fp-ts/lib/Either").Right<{
|
|
91
|
+
type: "StructuredText";
|
|
92
|
+
value: import("./ImportRichText").ImportBlock[] | null;
|
|
86
93
|
}> | import("fp-ts/lib/Either").Right<{
|
|
87
94
|
type: "Link";
|
|
88
95
|
value: ({
|
|
@@ -7,6 +7,7 @@ const Date_1 = require("./Date");
|
|
|
7
7
|
const Embed_1 = require("./Embed");
|
|
8
8
|
const GeoPoint_1 = require("./GeoPoint");
|
|
9
9
|
const Image_1 = require("./Image");
|
|
10
|
+
const ImportRichText_1 = require("./ImportRichText");
|
|
10
11
|
const Link_1 = require("./Link");
|
|
11
12
|
const Number_1 = require("./Number");
|
|
12
13
|
const Select_1 = require("./Select");
|
|
@@ -24,7 +25,8 @@ exports.ImportNestable = {
|
|
|
24
25
|
Embed_1.ImportEmbed.is(u) ||
|
|
25
26
|
Link_1.ImportLink.is(u) ||
|
|
26
27
|
GeoPoint_1.ImportGeoPoint.is(u) ||
|
|
27
|
-
(0, Image_1.ImportImage)().is(u)
|
|
28
|
+
(0, Image_1.ImportImage)().is(u) ||
|
|
29
|
+
(0, ImportRichText_1.ImportRichText)().is(u));
|
|
28
30
|
},
|
|
29
31
|
decode: (field) => {
|
|
30
32
|
return (content) => {
|
|
@@ -52,6 +54,8 @@ exports.ImportNestable = {
|
|
|
52
54
|
return (0, Image_1.ImportImage)(field);
|
|
53
55
|
case "GeoPoint":
|
|
54
56
|
return GeoPoint_1.ImportGeoPoint;
|
|
57
|
+
case "StructuredText":
|
|
58
|
+
return (0, ImportRichText_1.ImportRichText)(field);
|
|
55
59
|
default:
|
|
56
60
|
throw new Error(`Unsupported type of nestable field ${field.type}`);
|
|
57
61
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export * from "./Boolean";
|
|
2
2
|
export * from "./Color";
|
|
3
3
|
export * from "./Date";
|
|
4
|
-
export
|
|
4
|
+
export { ImportEmbed } from "./Embed";
|
|
5
5
|
export * from "./GeoPoint";
|
|
6
6
|
export * from "./Image";
|
|
7
7
|
export * from "./Image/index";
|
|
8
|
+
export * from "./ImportRichText";
|
|
8
9
|
export * from "./Link";
|
|
9
10
|
export * from "./Nestable";
|
|
10
11
|
export * from "./Number";
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportEmbed = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
(0, tslib_1.__exportStar)(require("./Boolean"), exports);
|
|
5
6
|
(0, tslib_1.__exportStar)(require("./Color"), exports);
|
|
6
7
|
(0, tslib_1.__exportStar)(require("./Date"), exports);
|
|
7
|
-
|
|
8
|
+
var Embed_1 = require("./Embed");
|
|
9
|
+
Object.defineProperty(exports, "ImportEmbed", { enumerable: true, get: function () { return Embed_1.ImportEmbed; } });
|
|
8
10
|
(0, tslib_1.__exportStar)(require("./GeoPoint"), exports);
|
|
9
11
|
(0, tslib_1.__exportStar)(require("./Image"), exports);
|
|
10
12
|
(0, tslib_1.__exportStar)(require("./Image/index"), exports);
|
|
13
|
+
(0, tslib_1.__exportStar)(require("./ImportRichText"), exports);
|
|
11
14
|
(0, tslib_1.__exportStar)(require("./Link"), exports);
|
|
12
15
|
(0, tslib_1.__exportStar)(require("./Nestable"), exports);
|
|
13
16
|
(0, tslib_1.__exportStar)(require("./Number"), exports);
|
package/package.json
CHANGED
package/src/content/Document.ts
CHANGED
|
@@ -9,20 +9,12 @@ import {
|
|
|
9
9
|
TraverseWidgetContentFn,
|
|
10
10
|
} from "../_internal/utils"
|
|
11
11
|
import { WidgetKey } from "../common"
|
|
12
|
+
import { type StaticWidget, collectSharedSlices } from "../customtypes"
|
|
12
13
|
import {
|
|
13
|
-
type StaticWidget,
|
|
14
|
-
collectSharedSlices,
|
|
15
|
-
flattenStaticWidgets,
|
|
16
|
-
StaticCustomType,
|
|
17
|
-
VariationFields,
|
|
18
|
-
} from "../customtypes"
|
|
19
|
-
import {
|
|
20
|
-
CompositeSliceItemContent,
|
|
21
|
-
GroupItemContent,
|
|
22
14
|
isCompositeSliceItemContent,
|
|
23
15
|
isSimpleSliceItemContent,
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
migrateCompositeSlice,
|
|
17
|
+
migrateSimpleSlice,
|
|
26
18
|
traverseGroupContent,
|
|
27
19
|
traverseSlices,
|
|
28
20
|
WidgetContent,
|
|
@@ -132,7 +124,10 @@ function extractMetadata(data: { [p: string]: unknown }): {
|
|
|
132
124
|
|
|
133
125
|
function parseLegacyDocument(
|
|
134
126
|
legacyDoc: unknown,
|
|
135
|
-
customType:
|
|
127
|
+
customType: {
|
|
128
|
+
customTypeId: string
|
|
129
|
+
fields: Record<string, StaticWidget>
|
|
130
|
+
},
|
|
136
131
|
): Document | undefined {
|
|
137
132
|
const result = pipe(
|
|
138
133
|
// ensure it's the right document format first
|
|
@@ -172,7 +167,10 @@ export function traverseDocument({
|
|
|
172
167
|
model,
|
|
173
168
|
}: {
|
|
174
169
|
document: Document
|
|
175
|
-
model?:
|
|
170
|
+
model?: {
|
|
171
|
+
customTypeId: string
|
|
172
|
+
fields: Record<string, StaticWidget>
|
|
173
|
+
}
|
|
176
174
|
}) {
|
|
177
175
|
return ({
|
|
178
176
|
transformWidget = ({ content }) => content,
|
|
@@ -183,7 +181,7 @@ export function traverseDocument({
|
|
|
183
181
|
}): Document => {
|
|
184
182
|
const fieldModels =
|
|
185
183
|
model &&
|
|
186
|
-
|
|
184
|
+
Object.entries(model.fields).reduce<Record<string, StaticWidget>>(
|
|
187
185
|
(acc, [key, def]) => ({ ...acc, [key]: def }),
|
|
188
186
|
{},
|
|
189
187
|
)
|
|
@@ -192,7 +190,7 @@ export function traverseDocument({
|
|
|
192
190
|
const fieldModel = fieldModels && fieldModels[key]
|
|
193
191
|
|
|
194
192
|
const path = ContentPath.make([
|
|
195
|
-
{ key: model?.
|
|
193
|
+
{ key: model?.customTypeId, type: "CustomType" },
|
|
196
194
|
{ key, type: "Widget" },
|
|
197
195
|
])
|
|
198
196
|
|
|
@@ -263,88 +261,14 @@ export function collectWidgets<W extends WidgetContent>(
|
|
|
263
261
|
return collected
|
|
264
262
|
}
|
|
265
263
|
|
|
266
|
-
function
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
widget: {
|
|
275
|
-
__TYPE__: "SharedSliceContent",
|
|
276
|
-
variation: model.variationId,
|
|
277
|
-
primary: Object.entries(content.widget.nonRepeat).reduce(
|
|
278
|
-
(acc, [fieldKey, fieldContent]) => {
|
|
279
|
-
return model.fields.primary?.[fieldKey]
|
|
280
|
-
? { ...acc, [fieldKey]: fieldContent }
|
|
281
|
-
: acc
|
|
282
|
-
},
|
|
283
|
-
{},
|
|
284
|
-
),
|
|
285
|
-
items: content.widget.repeat.map((groupItem) => {
|
|
286
|
-
return {
|
|
287
|
-
__TYPE__: "GroupItemContent",
|
|
288
|
-
value: groupItem.value.reduce<GroupItemContent["value"]>(
|
|
289
|
-
(acc, [fieldKey, fieldContent]) => {
|
|
290
|
-
return model.fields.items?.[fieldKey]
|
|
291
|
-
? acc.concat([[fieldKey, fieldContent]])
|
|
292
|
-
: acc
|
|
293
|
-
},
|
|
294
|
-
[],
|
|
295
|
-
),
|
|
296
|
-
}
|
|
297
|
-
}, []),
|
|
298
|
-
},
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
function migrateSimpleSlice(
|
|
303
|
-
model: VariationFields,
|
|
304
|
-
content: SimpleSliceItemContent,
|
|
305
|
-
): SharedSliceItemContent {
|
|
306
|
-
if (content.widget.__TYPE__ === "GroupContentType") {
|
|
307
|
-
return {
|
|
308
|
-
key: content.key,
|
|
309
|
-
name: model.sliceName,
|
|
310
|
-
maybeLabel: content.maybeLabel,
|
|
311
|
-
widget: {
|
|
312
|
-
__TYPE__: "SharedSliceContent",
|
|
313
|
-
variation: model.variationId,
|
|
314
|
-
primary: {},
|
|
315
|
-
items: content.widget.value.map((groupItem) => {
|
|
316
|
-
return {
|
|
317
|
-
__TYPE__: "GroupItemContent",
|
|
318
|
-
value: groupItem.value.reduce<GroupItemContent["value"]>(
|
|
319
|
-
(acc, [fieldKey, fieldContent]) => {
|
|
320
|
-
return model.fields.items?.[fieldKey]
|
|
321
|
-
? acc.concat([[fieldKey, fieldContent]])
|
|
322
|
-
: acc
|
|
323
|
-
},
|
|
324
|
-
[],
|
|
325
|
-
),
|
|
326
|
-
}
|
|
327
|
-
}, []),
|
|
328
|
-
},
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return {
|
|
332
|
-
key: content.key,
|
|
333
|
-
name: model.sliceName,
|
|
334
|
-
maybeLabel: content.maybeLabel,
|
|
335
|
-
widget: {
|
|
336
|
-
__TYPE__: "SharedSliceContent",
|
|
337
|
-
variation: model.variationId,
|
|
338
|
-
primary: model.fields.primary?.[content.name]
|
|
339
|
-
? { [content.key]: content.widget }
|
|
340
|
-
: {},
|
|
341
|
-
items: [],
|
|
342
|
-
},
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
export function migrateDocument(document: Document, model: StaticCustomType) {
|
|
347
|
-
const needsMigration = Object.values(collectSharedSlices(model)).some(
|
|
264
|
+
export function migrateDocument(
|
|
265
|
+
document: Document,
|
|
266
|
+
customType: {
|
|
267
|
+
customTypeId: string
|
|
268
|
+
fields: Record<string, StaticWidget>
|
|
269
|
+
},
|
|
270
|
+
) {
|
|
271
|
+
const needsMigration = Object.values(collectSharedSlices(customType)).some(
|
|
348
272
|
(slice) => Boolean(slice.legacyPaths),
|
|
349
273
|
)
|
|
350
274
|
|
|
@@ -352,7 +276,7 @@ export function migrateDocument(document: Document, model: StaticCustomType) {
|
|
|
352
276
|
|
|
353
277
|
return traverseDocument({
|
|
354
278
|
document,
|
|
355
|
-
model,
|
|
279
|
+
model: customType,
|
|
356
280
|
})({
|
|
357
281
|
transformSlice: ({ content, model }) => {
|
|
358
282
|
if (isCompositeSliceItemContent(content) && model?.type === "SharedSlice")
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
WithTypes,
|
|
19
19
|
} from "../../../LegacyContentCtx"
|
|
20
20
|
import { hasContentType } from "../../../utils"
|
|
21
|
-
import { traverseGroupItemsContent } from "../../GroupContent"
|
|
21
|
+
import { GroupItemContent, traverseGroupItemsContent } from "../../GroupContent"
|
|
22
22
|
import {
|
|
23
23
|
isNestableContent,
|
|
24
24
|
NestableContent,
|
|
@@ -205,3 +205,39 @@ export function traverseCompositeSliceContent({
|
|
|
205
205
|
})
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
+
|
|
209
|
+
export function migrateCompositeSlice(
|
|
210
|
+
model: VariationFields,
|
|
211
|
+
content: CompositeSliceItemContent,
|
|
212
|
+
): SharedSliceItemContent {
|
|
213
|
+
return {
|
|
214
|
+
key: content.key,
|
|
215
|
+
name: model.sliceName,
|
|
216
|
+
maybeLabel: content.maybeLabel,
|
|
217
|
+
widget: {
|
|
218
|
+
__TYPE__: "SharedSliceContent",
|
|
219
|
+
variation: model.variationId,
|
|
220
|
+
primary: Object.entries(content.widget.nonRepeat).reduce(
|
|
221
|
+
(acc, [fieldKey, fieldContent]) => {
|
|
222
|
+
return model.fields.primary?.[fieldKey]
|
|
223
|
+
? { ...acc, [fieldKey]: fieldContent }
|
|
224
|
+
: acc
|
|
225
|
+
},
|
|
226
|
+
{},
|
|
227
|
+
),
|
|
228
|
+
items: content.widget.repeat.map((groupItem) => {
|
|
229
|
+
return {
|
|
230
|
+
__TYPE__: "GroupItemContent",
|
|
231
|
+
value: groupItem.value.reduce<GroupItemContent["value"]>(
|
|
232
|
+
(acc, [fieldKey, fieldContent]) => {
|
|
233
|
+
return model.fields.items?.[fieldKey]
|
|
234
|
+
? acc.concat([[fieldKey, fieldContent]])
|
|
235
|
+
: acc
|
|
236
|
+
},
|
|
237
|
+
[],
|
|
238
|
+
),
|
|
239
|
+
}
|
|
240
|
+
}, []),
|
|
241
|
+
},
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
import type { LegacyContentCtx } from "../../../LegacyContentCtx"
|
|
14
14
|
import {
|
|
15
15
|
GroupContent,
|
|
16
|
+
GroupItemContent,
|
|
16
17
|
GroupLegacy,
|
|
17
18
|
isGroupContent,
|
|
18
19
|
traverseGroupContent,
|
|
@@ -129,3 +130,47 @@ export function traverseSimpleSliceContent({
|
|
|
129
130
|
)
|
|
130
131
|
}
|
|
131
132
|
}
|
|
133
|
+
|
|
134
|
+
export function migrateSimpleSlice(
|
|
135
|
+
model: VariationFields,
|
|
136
|
+
content: SimpleSliceItemContent,
|
|
137
|
+
): SharedSliceItemContent {
|
|
138
|
+
if (content.widget.__TYPE__ === "GroupContentType") {
|
|
139
|
+
return {
|
|
140
|
+
key: content.key,
|
|
141
|
+
name: model.sliceName,
|
|
142
|
+
maybeLabel: content.maybeLabel,
|
|
143
|
+
widget: {
|
|
144
|
+
__TYPE__: "SharedSliceContent",
|
|
145
|
+
variation: model.variationId,
|
|
146
|
+
primary: {},
|
|
147
|
+
items: content.widget.value.map((groupItem) => {
|
|
148
|
+
return {
|
|
149
|
+
__TYPE__: "GroupItemContent",
|
|
150
|
+
value: groupItem.value.reduce<GroupItemContent["value"]>(
|
|
151
|
+
(acc, [fieldKey, fieldContent]) => {
|
|
152
|
+
return model.fields.items?.[fieldKey]
|
|
153
|
+
? acc.concat([[fieldKey, fieldContent]])
|
|
154
|
+
: acc
|
|
155
|
+
},
|
|
156
|
+
[],
|
|
157
|
+
),
|
|
158
|
+
}
|
|
159
|
+
}, []),
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
key: content.key,
|
|
165
|
+
name: model.sliceName,
|
|
166
|
+
maybeLabel: content.maybeLabel,
|
|
167
|
+
widget: {
|
|
168
|
+
__TYPE__: "SharedSliceContent",
|
|
169
|
+
variation: model.variationId,
|
|
170
|
+
primary: model.fields.primary?.[content.name]
|
|
171
|
+
? { [content.key]: content.widget }
|
|
172
|
+
: {},
|
|
173
|
+
items: [],
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -215,7 +215,7 @@ export function filterMissingSharedSlices(
|
|
|
215
215
|
|
|
216
216
|
export function flattenCustomTypeFields(
|
|
217
217
|
customType: StaticCustomType,
|
|
218
|
-
):
|
|
218
|
+
): Record<string, StaticWidget> {
|
|
219
219
|
return Object.values(customType.json).reduce(
|
|
220
220
|
(acc, tab) => ({
|
|
221
221
|
...acc,
|
|
@@ -225,10 +225,11 @@ export function flattenCustomTypeFields(
|
|
|
225
225
|
)
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
export function collectSharedSlices(
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
228
|
+
export function collectSharedSlices(customType: {
|
|
229
|
+
customTypeId: string
|
|
230
|
+
fields: Record<string, StaticWidget>
|
|
231
|
+
}): Record<string, SharedSlice> {
|
|
232
|
+
return Object.entries(customType.fields).reduce((acc, [, w]) => {
|
|
232
233
|
if (w.type === "Slices" || w.type === "Choice") {
|
|
233
234
|
return {
|
|
234
235
|
...acc,
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import type { Asset } from "../../../../common"
|
|
2
2
|
import { getAssetOrThrow } from "../../../../common"
|
|
3
|
-
import type { ImageContent } from "../../../../content"
|
|
3
|
+
import type { ImageContent, ImageContentView } from "../../../../content"
|
|
4
4
|
import { withOptionals } from "../../../../utils/Objects"
|
|
5
5
|
import type { ImageField, ImportImage } from "../../../validators"
|
|
6
|
+
import type { ImportImageBlock } from "../../../validators/fields/nestable/ImportRichText/blocks"
|
|
6
7
|
|
|
7
|
-
function convertImage
|
|
8
|
-
|
|
8
|
+
function convertImage<Input extends ImageField | ImportImageBlock>(
|
|
9
|
+
inputImage: Input,
|
|
10
|
+
image: Asset,
|
|
11
|
+
) {
|
|
12
|
+
// We can do that because anyway all properties being read
|
|
13
|
+
const imageField: ImageField = {
|
|
14
|
+
...inputImage,
|
|
15
|
+
edit:
|
|
16
|
+
"edit" in inputImage
|
|
17
|
+
? inputImage.edit
|
|
18
|
+
: {
|
|
19
|
+
x: 0,
|
|
20
|
+
y: 0,
|
|
21
|
+
zoom: 1,
|
|
22
|
+
},
|
|
23
|
+
dimensions: "dimensions" in inputImage ? inputImage.dimensions : {},
|
|
24
|
+
}
|
|
25
|
+
return withOptionals<ImageContentView>(
|
|
9
26
|
{
|
|
10
27
|
origin: {
|
|
11
28
|
id: image.id,
|
|
@@ -57,6 +74,16 @@ function convertThumbnails(
|
|
|
57
74
|
)
|
|
58
75
|
}
|
|
59
76
|
|
|
77
|
+
export const imageBlockConverter = (
|
|
78
|
+
imageBlock: ImportImageBlock,
|
|
79
|
+
assets: Record<Asset["id"], Asset | undefined>,
|
|
80
|
+
): ImageContentView => {
|
|
81
|
+
return convertImage<ImportImageBlock>(
|
|
82
|
+
imageBlock,
|
|
83
|
+
getAssetOrThrow(assets)(imageBlock.id),
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
60
87
|
// All assets from `imageField` must be present in `assets`
|
|
61
88
|
// If not then function will throw an error
|
|
62
89
|
export const imageConverter = (
|
|
@@ -66,7 +93,10 @@ export const imageConverter = (
|
|
|
66
93
|
if (!imageField) return
|
|
67
94
|
|
|
68
95
|
return {
|
|
69
|
-
...convertImage(
|
|
96
|
+
...convertImage<ImageField>(
|
|
97
|
+
imageField,
|
|
98
|
+
getAssetOrThrow(assets)(imageField.id),
|
|
99
|
+
),
|
|
70
100
|
thumbnails: convertThumbnails(imageField, assets),
|
|
71
101
|
__TYPE__: "ImageContent" as const,
|
|
72
102
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
imageConverter,
|
|
12
12
|
linkConverter,
|
|
13
13
|
numberConverter,
|
|
14
|
+
richTextConverter,
|
|
14
15
|
selectConverter,
|
|
15
16
|
textConverter,
|
|
16
17
|
timestampConverter,
|
|
@@ -44,6 +45,8 @@ export function convertNestableWidget(
|
|
|
44
45
|
return linkConverter(field.value, assets)
|
|
45
46
|
case "Image":
|
|
46
47
|
return imageConverter(field.value, assets)
|
|
48
|
+
case "StructuredText":
|
|
49
|
+
return richTextConverter(field.value, assets, embeds)
|
|
47
50
|
default:
|
|
48
51
|
throw new Error(
|
|
49
52
|
`Unsupported type of nestable converter ${JSON.stringify(field)}`,
|