@prismicio/types-internal 2.2.0-alpha.18 → 2.2.0-alpha.19
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/fields/nestable/RichTextContent/Blocks.d.ts +23 -0
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +5 -5
- package/lib/import/converters/fields/nestable/GeoPoint.d.ts +3 -0
- package/lib/import/converters/fields/nestable/GeoPoint.js +15 -0
- package/lib/import/converters/fields/nestable/Image.d.ts +2 -2
- package/lib/import/converters/fields/nestable/Image.js +5 -8
- package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/embedBlock.js +14 -0
- package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/imageBlock.js +12 -0
- package/lib/import/converters/fields/nestable/RichText/index.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/index.js +22 -0
- package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/textBlock.js +27 -0
- package/lib/import/converters/fields/nestable/index.d.ts +1 -1
- package/lib/import/converters/fields/nestable/index.js +1 -1
- package/package.json +1 -1
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +1 -1
- package/src/import/converters/fields/nestable/Image.ts +5 -15
- package/src/import/converters/fields/nestable/RichText/embedBlock.ts +14 -0
- package/src/import/converters/fields/nestable/RichText/imageBlock.ts +14 -0
- package/src/import/converters/fields/nestable/RichText/index.ts +23 -0
- package/src/import/converters/fields/nestable/RichText/textBlock.ts +27 -0
- package/src/import/converters/fields/nestable/index.ts +1 -1
- package/src/import/converters/fields/nestable/RichText.ts +0 -62
- /package/src/import/converters/fields/nestable/{GeooPoint.ts → GeoPoint.ts} +0 -0
|
@@ -214,6 +214,29 @@ export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
214
214
|
direction: t.StringC;
|
|
215
215
|
}>]>>;
|
|
216
216
|
export declare type TextBlock = t.TypeOf<typeof TextBlock>;
|
|
217
|
+
export declare const TextBlockLegacy: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
218
|
+
type: t.Type<"image" | "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "strong" | "em" | "preformatted" | "hyperlink" | "embed" | "list-item" | "o-list-item" | "rtl", "image" | "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "strong" | "em" | "preformatted" | "hyperlink" | "embed" | "list-item" | "o-list-item" | "rtl", unknown>;
|
|
219
|
+
content: t.IntersectionC<[t.TypeC<{
|
|
220
|
+
text: t.StringC;
|
|
221
|
+
}>, t.PartialC<{
|
|
222
|
+
spans: t.Type<({
|
|
223
|
+
data?: unknown;
|
|
224
|
+
} & {
|
|
225
|
+
start: number;
|
|
226
|
+
end: number;
|
|
227
|
+
type: "image" | "label" | "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "strong" | "em" | "preformatted" | "hyperlink" | "embed" | "list-item" | "o-list-item" | "rtl";
|
|
228
|
+
})[], ({
|
|
229
|
+
data?: unknown;
|
|
230
|
+
} & {
|
|
231
|
+
start: number;
|
|
232
|
+
end: number;
|
|
233
|
+
type: "image" | "label" | "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "strong" | "em" | "preformatted" | "hyperlink" | "embed" | "list-item" | "o-list-item" | "rtl";
|
|
234
|
+
})[], unknown>;
|
|
235
|
+
}>]>;
|
|
236
|
+
}>, t.PartialC<{
|
|
237
|
+
label: t.StringC;
|
|
238
|
+
direction: t.StringC;
|
|
239
|
+
}>]>>;
|
|
217
240
|
export declare const BlockLegacy: t.Type<({
|
|
218
241
|
type: "image";
|
|
219
242
|
data: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Block = exports.BlockLegacy = exports.TextBlock = exports.checkEmbedBlock = exports.EmbedBlock = exports.checkImageBlock = exports.ImageBlock = exports.ValidatedMetas = exports.Span = exports.Meta = void 0;
|
|
3
|
+
exports.Block = exports.BlockLegacy = exports.TextBlockLegacy = exports.TextBlock = exports.checkEmbedBlock = exports.EmbedBlock = exports.checkImageBlock = exports.ImageBlock = exports.ValidatedMetas = exports.Span = exports.Meta = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const Either_1 = require("fp-ts/lib/Either");
|
|
@@ -144,20 +144,20 @@ const TextBlockCodec = (linkCodec) => t.exact(t.intersection([
|
|
|
144
144
|
}),
|
|
145
145
|
]));
|
|
146
146
|
exports.TextBlock = TextBlockCodec(LinkContent_1.Link);
|
|
147
|
-
|
|
147
|
+
exports.TextBlockLegacy = TextBlockCodec(LinkContent_1.LinkLegacy);
|
|
148
148
|
const legacyBlockCodec = t.union([
|
|
149
149
|
EmbedBlockLegacy,
|
|
150
150
|
ImageBlockLegacy,
|
|
151
|
-
TextBlockLegacy,
|
|
151
|
+
exports.TextBlockLegacy,
|
|
152
152
|
]);
|
|
153
|
-
exports.BlockLegacy = new t.Type("BlockLegacy", (u) => EmbedBlockLegacy.is(u) || ImageBlockLegacy.is(u) || TextBlockLegacy.is(u), (legacyBlock) => legacyBlockCodec.decode(legacyBlock), (block) => {
|
|
153
|
+
exports.BlockLegacy = new t.Type("BlockLegacy", (u) => EmbedBlockLegacy.is(u) || ImageBlockLegacy.is(u) || exports.TextBlockLegacy.is(u), (legacyBlock) => legacyBlockCodec.decode(legacyBlock), (block) => {
|
|
154
154
|
return (() => {
|
|
155
155
|
if (exports.ImageBlock.is(block))
|
|
156
156
|
return ImageBlockLegacy.encode(block);
|
|
157
157
|
else if (exports.EmbedBlock.is(block))
|
|
158
158
|
return EmbedBlockLegacy.encode(block);
|
|
159
159
|
else
|
|
160
|
-
return TextBlockLegacy.encode(block);
|
|
160
|
+
return exports.TextBlockLegacy.encode(block);
|
|
161
161
|
})();
|
|
162
162
|
});
|
|
163
163
|
exports.Block = t.union([exports.ImageBlock, exports.EmbedBlock, exports.TextBlock]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.geopointConverter = void 0;
|
|
4
|
+
const geopointConverter = (field) => {
|
|
5
|
+
if (field === null)
|
|
6
|
+
return;
|
|
7
|
+
return {
|
|
8
|
+
position: {
|
|
9
|
+
lat: field.latitude,
|
|
10
|
+
lng: field.longitude,
|
|
11
|
+
},
|
|
12
|
+
__TYPE__: "GeoPointContent",
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.geopointConverter = geopointConverter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Asset } from "../../../../common";
|
|
2
2
|
import type { ImageContent, ImageContentView } from "../../../../content";
|
|
3
|
-
import type { ImportImage } from "../../../validators";
|
|
3
|
+
import type { ImageField, ImportImage } from "../../../validators";
|
|
4
4
|
import type { ImportImageBlock } from "../../../validators/fields/nestable/ImportRichText/blocks";
|
|
5
|
-
export declare
|
|
5
|
+
export declare function convertImageView<Input extends ImageField | ImportImageBlock>(inputImage: Input, image: Asset): ImageContentView;
|
|
6
6
|
export declare const imageConverter: (imageField: ImportImage["value"], assets: Record<Asset["id"], Asset | undefined>) => ImageContent | undefined;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.imageConverter = exports.
|
|
3
|
+
exports.imageConverter = exports.convertImageView = void 0;
|
|
4
4
|
const common_1 = require("../../../../common");
|
|
5
5
|
const Objects_1 = require("../../../../utils/Objects");
|
|
6
|
-
function
|
|
6
|
+
function convertImageView(inputImage, image) {
|
|
7
7
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
8
8
|
// We can do that because anyway all properties being read
|
|
9
9
|
const imageField = {
|
|
@@ -45,25 +45,22 @@ function convertImage(inputImage, image) {
|
|
|
45
45
|
["credits", (imageField === null || imageField === void 0 ? void 0 : imageField.copyright) || image.credits],
|
|
46
46
|
]);
|
|
47
47
|
}
|
|
48
|
+
exports.convertImageView = convertImageView;
|
|
48
49
|
function convertThumbnails(imageField, assets) {
|
|
49
50
|
return Object.entries(imageField.thumbnails).reduce((acc, [thumbnailName, thumbnail]) => {
|
|
50
51
|
return {
|
|
51
52
|
...acc,
|
|
52
|
-
[thumbnailName]:
|
|
53
|
+
[thumbnailName]: convertImageView(thumbnail, (0, common_1.getAssetOrThrow)(assets)(thumbnail.id)),
|
|
53
54
|
};
|
|
54
55
|
}, {});
|
|
55
56
|
}
|
|
56
|
-
const imageBlockConverter = (imageBlock, assets) => {
|
|
57
|
-
return convertImage(imageBlock, (0, common_1.getAssetOrThrow)(assets)(imageBlock.id));
|
|
58
|
-
};
|
|
59
|
-
exports.imageBlockConverter = imageBlockConverter;
|
|
60
57
|
// All assets from `imageField` must be present in `assets`
|
|
61
58
|
// If not then function will throw an error
|
|
62
59
|
const imageConverter = (imageField, assets) => {
|
|
63
60
|
if (!imageField)
|
|
64
61
|
return;
|
|
65
62
|
return {
|
|
66
|
-
...
|
|
63
|
+
...convertImageView(imageField, (0, common_1.getAssetOrThrow)(assets)(imageField.id)),
|
|
67
64
|
thumbnails: convertThumbnails(imageField, assets),
|
|
68
65
|
__TYPE__: "ImageContent",
|
|
69
66
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Embed } from "../../../../../common";
|
|
2
|
+
import type { EmbedBlock } from "../../../../../content";
|
|
3
|
+
import type { ImportEmbedBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
|
|
4
|
+
export declare function embedBlockConverter(block: ImportEmbedBlock, embeds: Record<string, Embed | undefined>): EmbedBlock;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.embedBlockConverter = void 0;
|
|
4
|
+
const Embed_1 = require("../Embed");
|
|
5
|
+
function embedBlockConverter(block, embeds) {
|
|
6
|
+
const embedData = (0, Embed_1.embedConverter)(block.oembed, embeds);
|
|
7
|
+
if (!embedData)
|
|
8
|
+
throw new Error("Failed to convert embed data");
|
|
9
|
+
return {
|
|
10
|
+
type: block.type,
|
|
11
|
+
data: embedData,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
exports.embedBlockConverter = embedBlockConverter;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Asset } from "../../../../../common";
|
|
2
|
+
import type { ImageBlock } from "../../../../../content";
|
|
3
|
+
import type { ImportImageBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
|
|
4
|
+
export declare function imageBlockConverter(block: ImportImageBlock, assets: Record<Asset["id"], Asset | undefined>): ImageBlock;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imageBlockConverter = void 0;
|
|
4
|
+
const common_1 = require("../../../../../common");
|
|
5
|
+
const Image_1 = require("../Image");
|
|
6
|
+
function imageBlockConverter(block, assets) {
|
|
7
|
+
return {
|
|
8
|
+
type: block.type,
|
|
9
|
+
data: (0, Image_1.convertImageView)(block, (0, common_1.getAssetOrThrow)(assets)(block.id)),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
exports.imageBlockConverter = imageBlockConverter;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Asset, Embed } from "../../../../../common";
|
|
2
|
+
import type { RichTextContent } from "../../../../../content";
|
|
3
|
+
import type { ImportRichText } from "../../../../validators";
|
|
4
|
+
export declare const richTextConverter: (richTextField: ImportRichText["value"], assets: Record<Asset["id"], Asset | undefined>, embeds: Record<string, Embed | undefined>) => RichTextContent | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.richTextConverter = void 0;
|
|
4
|
+
const content_1 = require("../../../../../content");
|
|
5
|
+
const embedBlock_1 = require("./embedBlock");
|
|
6
|
+
const imageBlock_1 = require("./imageBlock");
|
|
7
|
+
const textBlock_1 = require("./textBlock");
|
|
8
|
+
const richTextConverter = (richTextField, assets, embeds) => {
|
|
9
|
+
if (richTextField === null)
|
|
10
|
+
return;
|
|
11
|
+
return {
|
|
12
|
+
__TYPE__: content_1.RichTextContentType,
|
|
13
|
+
value: richTextField.map((block) => {
|
|
14
|
+
if (block.type === "image")
|
|
15
|
+
return (0, imageBlock_1.imageBlockConverter)(block, assets);
|
|
16
|
+
else if (block.type === "embed")
|
|
17
|
+
return (0, embedBlock_1.embedBlockConverter)(block, embeds);
|
|
18
|
+
return (0, textBlock_1.textBlockConverter)(block, assets);
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.richTextConverter = richTextConverter;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Asset } from "../../../../../common";
|
|
2
|
+
import type { TextBlock } from "../../../../../content";
|
|
3
|
+
import type { ImportTextBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
|
|
4
|
+
export declare function textBlockConverter(block: ImportTextBlock, assets: Record<Asset["id"], Asset | undefined>): TextBlock;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.textBlockConverter = void 0;
|
|
4
|
+
const Link_1 = require("../Link");
|
|
5
|
+
function textBlockConverter(block, assets) {
|
|
6
|
+
return {
|
|
7
|
+
type: block.type,
|
|
8
|
+
content: {
|
|
9
|
+
text: block.text,
|
|
10
|
+
...block.spans ? { spans: spansConverter(block.spans, assets) } : {}
|
|
11
|
+
},
|
|
12
|
+
...block.direction ? { direction: block.direction } : {},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.textBlockConverter = textBlockConverter;
|
|
16
|
+
function spansConverter(spans, assets) {
|
|
17
|
+
return spans.map(span => {
|
|
18
|
+
var _a;
|
|
19
|
+
return {
|
|
20
|
+
type: span.type,
|
|
21
|
+
start: span.start,
|
|
22
|
+
end: span.end,
|
|
23
|
+
// Text blocks in Content format have for data the Link type and not the whole LinkContent object
|
|
24
|
+
...span.type === "hyperlink" ? { data: (_a = (0, Link_1.linkConverter)(span.data, assets)) === null || _a === void 0 ? void 0 : _a.value } : {}
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
(0, tslib_1.__exportStar)(require("./Color"), exports);
|
|
6
6
|
(0, tslib_1.__exportStar)(require("./Date"), exports);
|
|
7
7
|
(0, tslib_1.__exportStar)(require("./Embed"), exports);
|
|
8
|
-
(0, tslib_1.__exportStar)(require("./
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./GeoPoint"), exports);
|
|
9
9
|
(0, tslib_1.__exportStar)(require("./Image"), exports);
|
|
10
10
|
(0, tslib_1.__exportStar)(require("./Link"), exports);
|
|
11
11
|
(0, tslib_1.__exportStar)(require("./Nestable"), exports);
|
package/package.json
CHANGED
|
@@ -198,7 +198,7 @@ const TextBlockCodec = (linkCodec: LinkCodec) =>
|
|
|
198
198
|
export const TextBlock = TextBlockCodec(Link)
|
|
199
199
|
export type TextBlock = t.TypeOf<typeof TextBlock>
|
|
200
200
|
|
|
201
|
-
const TextBlockLegacy = TextBlockCodec(LinkLegacy)
|
|
201
|
+
export const TextBlockLegacy = TextBlockCodec(LinkLegacy)
|
|
202
202
|
type TextBlockLegacy = t.TypeOf<typeof TextBlockLegacy>
|
|
203
203
|
|
|
204
204
|
const legacyBlockCodec = t.union([
|
|
@@ -3,12 +3,12 @@ import { getAssetOrThrow } from "../../../../common"
|
|
|
3
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
|
+
import type { ImportImageBlock } from "../../../validators/fields/nestable/ImportRichText/blocks";
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
export function convertImageView<Input extends ImageField | ImportImageBlock>(
|
|
9
9
|
inputImage: Input,
|
|
10
10
|
image: Asset,
|
|
11
|
-
) {
|
|
11
|
+
): ImageContentView {
|
|
12
12
|
// We can do that because anyway all properties being read
|
|
13
13
|
const imageField: ImageField = {
|
|
14
14
|
...inputImage,
|
|
@@ -64,7 +64,7 @@ function convertThumbnails(
|
|
|
64
64
|
(acc, [thumbnailName, thumbnail]) => {
|
|
65
65
|
return {
|
|
66
66
|
...acc,
|
|
67
|
-
[thumbnailName]:
|
|
67
|
+
[thumbnailName]: convertImageView(
|
|
68
68
|
thumbnail,
|
|
69
69
|
getAssetOrThrow(assets)(thumbnail.id),
|
|
70
70
|
),
|
|
@@ -74,16 +74,6 @@ function convertThumbnails(
|
|
|
74
74
|
)
|
|
75
75
|
}
|
|
76
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
|
-
|
|
87
77
|
// All assets from `imageField` must be present in `assets`
|
|
88
78
|
// If not then function will throw an error
|
|
89
79
|
export const imageConverter = (
|
|
@@ -93,7 +83,7 @@ export const imageConverter = (
|
|
|
93
83
|
if (!imageField) return
|
|
94
84
|
|
|
95
85
|
return {
|
|
96
|
-
...
|
|
86
|
+
...convertImageView<ImageField>(
|
|
97
87
|
imageField,
|
|
98
88
|
getAssetOrThrow(assets)(imageField.id),
|
|
99
89
|
),
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Embed } from "../../../../../common"
|
|
2
|
+
import type { EmbedBlock } from "../../../../../content";
|
|
3
|
+
import type { ImportEmbedBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
|
|
4
|
+
import { embedConverter } from "../Embed";
|
|
5
|
+
|
|
6
|
+
export function embedBlockConverter(block: ImportEmbedBlock, embeds: Record<string, Embed | undefined>): EmbedBlock {
|
|
7
|
+
const embedData = embedConverter(block.oembed, embeds)
|
|
8
|
+
|
|
9
|
+
if (!embedData) throw new Error("Failed to convert embed data")
|
|
10
|
+
return {
|
|
11
|
+
type: block.type,
|
|
12
|
+
data: embedData,
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Asset, getAssetOrThrow } from "../../../../../common";
|
|
2
|
+
import type { ImageBlock } from "../../../../../content";
|
|
3
|
+
import type { ImportImageBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
|
|
4
|
+
import { convertImageView } from "../Image";
|
|
5
|
+
|
|
6
|
+
export function imageBlockConverter(block: ImportImageBlock, assets: Record<Asset["id"], Asset | undefined>): ImageBlock {
|
|
7
|
+
return {
|
|
8
|
+
type: block.type,
|
|
9
|
+
data: convertImageView<ImportImageBlock>(
|
|
10
|
+
block,
|
|
11
|
+
getAssetOrThrow(assets)(block.id)
|
|
12
|
+
),
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Asset, Embed } from "../../../../../common"
|
|
2
|
+
import type { RichTextContent } from "../../../../../content"
|
|
3
|
+
import { RichTextContentType } from "../../../../../content"
|
|
4
|
+
import type { ImportRichText } from "../../../../validators"
|
|
5
|
+
import { embedBlockConverter } from "./embedBlock"
|
|
6
|
+
import { imageBlockConverter } from "./imageBlock"
|
|
7
|
+
import { textBlockConverter } from "./textBlock"
|
|
8
|
+
|
|
9
|
+
export const richTextConverter = (
|
|
10
|
+
richTextField: ImportRichText["value"],
|
|
11
|
+
assets: Record<Asset["id"], Asset | undefined>,
|
|
12
|
+
embeds: Record<string, Embed | undefined>,
|
|
13
|
+
): RichTextContent | undefined => {
|
|
14
|
+
if (richTextField === null) return
|
|
15
|
+
return {
|
|
16
|
+
__TYPE__: RichTextContentType,
|
|
17
|
+
value: richTextField.map((block) => {
|
|
18
|
+
if (block.type === "image") return imageBlockConverter(block, assets)
|
|
19
|
+
else if (block.type === "embed") return embedBlockConverter(block, embeds)
|
|
20
|
+
return textBlockConverter(block, assets)
|
|
21
|
+
}),
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Asset } from "../../../../../common"
|
|
2
|
+
import type { TextBlock } from "../../../../../content"
|
|
3
|
+
import type { ImportTextBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks"
|
|
4
|
+
import { linkConverter } from "../Link"
|
|
5
|
+
|
|
6
|
+
export function textBlockConverter(block: ImportTextBlock, assets: Record<Asset["id"], Asset | undefined>): TextBlock {
|
|
7
|
+
return {
|
|
8
|
+
type: block.type,
|
|
9
|
+
content: {
|
|
10
|
+
text: block.text,
|
|
11
|
+
...block.spans ? { spans: spansConverter(block.spans, assets) }: {}
|
|
12
|
+
},
|
|
13
|
+
...block.direction ? { direction: block.direction } : {},
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function spansConverter(spans: NonNullable<ImportTextBlock['spans']>, assets: Record<Asset["id"], Asset | undefined>): TextBlock['content']['spans'] {
|
|
18
|
+
return spans.map(span => {
|
|
19
|
+
return {
|
|
20
|
+
type: span.type,
|
|
21
|
+
start: span.start,
|
|
22
|
+
end: span.end,
|
|
23
|
+
// Text blocks in Content format have for data the Link type and not the whole LinkContent object
|
|
24
|
+
...span.type === "hyperlink" ? { data: linkConverter(span.data, assets)?.value } : {}
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { Asset, Embed } from "../../../../common"
|
|
2
|
-
import type { Block, RichTextContent } from "../../../../content"
|
|
3
|
-
import { RichTextContentType } from "../../../../content"
|
|
4
|
-
import type { ImportBlock, ImportRichText } from "../../../validators"
|
|
5
|
-
import { embedConverter } from "./Embed"
|
|
6
|
-
import { imageBlockConverter } from "./Image"
|
|
7
|
-
import { linkConverter } from "./Link"
|
|
8
|
-
|
|
9
|
-
const richTextBlockConverter = (
|
|
10
|
-
importBlock: ImportBlock,
|
|
11
|
-
assets: Record<Asset["id"], Asset | undefined>,
|
|
12
|
-
embeds: Record<string, Embed | undefined>,
|
|
13
|
-
): Block => {
|
|
14
|
-
if (importBlock.type === "image") {
|
|
15
|
-
return {
|
|
16
|
-
type: importBlock.type,
|
|
17
|
-
data: imageBlockConverter(importBlock, assets),
|
|
18
|
-
}
|
|
19
|
-
} else if (importBlock.type === "embed") {
|
|
20
|
-
const embedData = embedConverter(importBlock.oembed, embeds)
|
|
21
|
-
if (!embedData) throw new Error("Failed to convert embed data")
|
|
22
|
-
return {
|
|
23
|
-
type: importBlock.type,
|
|
24
|
-
data: embedData,
|
|
25
|
-
}
|
|
26
|
-
} else {
|
|
27
|
-
// Text block
|
|
28
|
-
return {
|
|
29
|
-
type: importBlock.type,
|
|
30
|
-
direction: importBlock.direction ?? "ltr",
|
|
31
|
-
content: {
|
|
32
|
-
text: importBlock.text,
|
|
33
|
-
spans:
|
|
34
|
-
importBlock.spans?.map((span) => {
|
|
35
|
-
const linkData =
|
|
36
|
-
span.type === "hyperlink"
|
|
37
|
-
? linkConverter(span.data, assets)
|
|
38
|
-
: undefined
|
|
39
|
-
return {
|
|
40
|
-
type: span.type,
|
|
41
|
-
start: span.start,
|
|
42
|
-
end: span.end,
|
|
43
|
-
data: linkData,
|
|
44
|
-
}
|
|
45
|
-
}) ?? [],
|
|
46
|
-
},
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export const richTextConverter = (
|
|
51
|
-
richTextField: ImportRichText["value"],
|
|
52
|
-
assets: Record<Asset["id"], Asset | undefined>,
|
|
53
|
-
embeds: Record<string, Embed | undefined>,
|
|
54
|
-
): RichTextContent | undefined => {
|
|
55
|
-
if (richTextField === null) return
|
|
56
|
-
return {
|
|
57
|
-
__TYPE__: RichTextContentType,
|
|
58
|
-
value: richTextField.map((block) =>
|
|
59
|
-
richTextBlockConverter(block, assets, embeds),
|
|
60
|
-
),
|
|
61
|
-
}
|
|
62
|
-
}
|
|
File without changes
|