@prismicio/types-internal 2.2.0-alpha.21 → 2.2.0-alpha.23
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 +936 -24
- package/lib/content/fields/GroupContent.d.ts +273 -7
- package/lib/content/fields/WidgetContent.d.ts +1248 -32
- package/lib/content/fields/nestable/NestableContent.d.ts +156 -4
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +582 -51
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +32 -49
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +195 -5
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +312 -8
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +117 -3
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +312 -8
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +312 -8
- package/lib/content/fields/slices/Slice/index.d.ts +702 -18
- package/lib/content/fields/slices/SliceItem.d.ts +702 -18
- package/lib/content/fields/slices/SlicesContent.d.ts +936 -24
- package/lib/import/converters/fields/nestable/Image.d.ts +24 -2
- package/lib/import/converters/fields/nestable/Image.js +16 -17
- package/lib/import/converters/fields/nestable/RichText/textBlock.js +21 -14
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +16 -2
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +7 -5
- package/package.json +1 -1
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +48 -58
- package/src/import/converters/fields/nestable/Image.ts +9 -11
- package/src/import/converters/fields/nestable/RichText/embedBlock.ts +14 -11
- package/src/import/converters/fields/nestable/RichText/imageBlock.ts +15 -12
- package/src/import/converters/fields/nestable/RichText/index.ts +4 -4
- package/src/import/converters/fields/nestable/RichText/textBlock.ts +39 -26
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +9 -5
- package/lib/import/converters/fields/nestable/GeooPoint.d.ts +0 -3
- package/lib/import/converters/fields/nestable/GeooPoint.js +0 -15
- package/lib/import/converters/fields/nestable/RichText.d.ts +0 -4
- package/lib/import/converters/fields/nestable/RichText.js +0 -55
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import type { Asset } from "../../../../common";
|
|
2
|
-
import type { ImageContent
|
|
2
|
+
import type { ImageContent } from "../../../../content";
|
|
3
3
|
import type { ImageField, ImportImage } from "../../../validators";
|
|
4
4
|
import type { ImportImageBlock } from "../../../validators/fields/nestable/ImportRichText/blocks";
|
|
5
|
-
export declare function convertImageView<Input extends ImageField | ImportImageBlock>(inputImage: Input, image: Asset):
|
|
5
|
+
export declare function convertImageView<Input extends ImageField | ImportImageBlock>(inputImage: Input, image: Asset): {
|
|
6
|
+
origin: {
|
|
7
|
+
id: string;
|
|
8
|
+
url: string;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
edit: {
|
|
15
|
+
zoom: number;
|
|
16
|
+
crop: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
background: string;
|
|
21
|
+
};
|
|
22
|
+
} & {
|
|
23
|
+
url?: string;
|
|
24
|
+
credits?: string | null;
|
|
25
|
+
alt?: string | null;
|
|
26
|
+
provider?: string | null | undefined;
|
|
27
|
+
};
|
|
6
28
|
export declare const imageConverter: (imageField: ImportImage["value"], assets: Record<Asset["id"], Asset | undefined>) => ImageContent | undefined;
|
|
@@ -4,40 +4,39 @@ exports.imageConverter = exports.convertImageView = void 0;
|
|
|
4
4
|
const common_1 = require("../../../../common");
|
|
5
5
|
const Objects_1 = require("../../../../utils/Objects");
|
|
6
6
|
function convertImageView(inputImage, image) {
|
|
7
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
8
8
|
// We can do that because anyway all properties being read
|
|
9
9
|
const imageField = {
|
|
10
10
|
...inputImage,
|
|
11
|
-
edit:
|
|
12
|
-
|
|
13
|
-
:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
dimensions: "dimensions" in inputImage ? inputImage.dimensions : {},
|
|
11
|
+
edit: {
|
|
12
|
+
x: 0,
|
|
13
|
+
y: 0,
|
|
14
|
+
zoom: 1,
|
|
15
|
+
...inputImage.edit,
|
|
16
|
+
},
|
|
17
|
+
dimensions: (_a = inputImage.dimensions) !== null && _a !== void 0 ? _a : {},
|
|
19
18
|
};
|
|
20
19
|
return (0, Objects_1.withOptionals)({
|
|
21
20
|
origin: {
|
|
22
21
|
id: image.id,
|
|
23
22
|
url: image.origin_url,
|
|
24
23
|
// All images returned form Asset API should have width and height properties.
|
|
25
|
-
width: (
|
|
26
|
-
height: (
|
|
24
|
+
width: (_b = image.width) !== null && _b !== void 0 ? _b : 0,
|
|
25
|
+
height: (_c = image.height) !== null && _c !== void 0 ? _c : 0,
|
|
27
26
|
},
|
|
28
27
|
// All images returned form Asset API should have width and height properties.
|
|
29
28
|
// Image width and height will be only applied if there are no constraints and user didn't overwrite it
|
|
30
|
-
width: (
|
|
31
|
-
height: (
|
|
29
|
+
width: (_f = (_e = (_d = imageField === null || imageField === void 0 ? void 0 : imageField.dimensions) === null || _d === void 0 ? void 0 : _d.width) !== null && _e !== void 0 ? _e : image.width) !== null && _f !== void 0 ? _f : 0,
|
|
30
|
+
height: (_j = (_h = (_g = imageField === null || imageField === void 0 ? void 0 : imageField.dimensions) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : image.height) !== null && _j !== void 0 ? _j : 0,
|
|
32
31
|
// If edit is not provided, we crop constraint width and height from the left upper corner.
|
|
33
32
|
// WARN: If constraints are greater than image dimensions cut outside the image (background will fill extra space).
|
|
34
33
|
edit: {
|
|
35
|
-
zoom: (
|
|
34
|
+
zoom: (_l = (_k = imageField.edit) === null || _k === void 0 ? void 0 : _k.zoom) !== null && _l !== void 0 ? _l : 1,
|
|
36
35
|
crop: {
|
|
37
|
-
x: (
|
|
38
|
-
y: (
|
|
36
|
+
x: (_o = (_m = imageField.edit) === null || _m === void 0 ? void 0 : _m.x) !== null && _o !== void 0 ? _o : 0,
|
|
37
|
+
y: (_q = (_p = imageField.edit) === null || _p === void 0 ? void 0 : _p.y) !== null && _q !== void 0 ? _q : 0,
|
|
39
38
|
},
|
|
40
|
-
background: (
|
|
39
|
+
background: (_s = (_r = imageField.edit) === null || _r === void 0 ? void 0 : _r.background) !== null && _s !== void 0 ? _s : (image.extension === "png" ? "transparent" : "#ffffff"),
|
|
41
40
|
},
|
|
42
41
|
url: image.url,
|
|
43
42
|
}, [
|
|
@@ -7,28 +7,35 @@ function textBlockConverter(block, assets) {
|
|
|
7
7
|
type: block.type,
|
|
8
8
|
content: {
|
|
9
9
|
text: block.text,
|
|
10
|
-
...
|
|
10
|
+
...(() => {
|
|
11
|
+
if (block.spans) {
|
|
12
|
+
const convertedSpans = spansConverter(block.spans, assets);
|
|
13
|
+
if (!convertedSpans)
|
|
14
|
+
return {};
|
|
15
|
+
return { spans: convertedSpans };
|
|
16
|
+
}
|
|
17
|
+
return {};
|
|
18
|
+
})(),
|
|
11
19
|
},
|
|
12
|
-
...block.direction ? { direction: block.direction } : {},
|
|
20
|
+
...(block.direction ? { direction: block.direction } : {}),
|
|
13
21
|
};
|
|
14
22
|
}
|
|
15
23
|
exports.textBlockConverter = textBlockConverter;
|
|
16
24
|
function spansConverter(spans, assets) {
|
|
17
|
-
return spans.map(span => {
|
|
18
|
-
var _a;
|
|
19
|
-
if (span.type === 'hyperlink') {
|
|
20
|
-
const { __TYPE__, ...data } = ((_a = (0, Link_1.linkConverter)(span.data, assets)) === null || _a === void 0 ? void 0 : _a.value) || {};
|
|
21
|
-
return {
|
|
22
|
-
type: span.type,
|
|
23
|
-
start: span.start,
|
|
24
|
-
end: span.end,
|
|
25
|
-
data: data
|
|
26
|
-
};
|
|
27
|
-
}
|
|
25
|
+
return spans.map((span) => {
|
|
28
26
|
return {
|
|
29
27
|
type: span.type,
|
|
30
28
|
start: span.start,
|
|
31
|
-
end: span.end
|
|
29
|
+
end: span.end,
|
|
30
|
+
...(() => {
|
|
31
|
+
if (span.type === "hyperlink") {
|
|
32
|
+
const convertedLinkContent = (0, Link_1.linkConverter)(span.data, assets);
|
|
33
|
+
if (!convertedLinkContent)
|
|
34
|
+
return {};
|
|
35
|
+
return { data: convertedLinkContent === null || convertedLinkContent === void 0 ? void 0 : convertedLinkContent.value };
|
|
36
|
+
}
|
|
37
|
+
return {};
|
|
38
|
+
})(),
|
|
32
39
|
};
|
|
33
40
|
});
|
|
34
41
|
}
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
export declare const ImportImageBlockType: t.LiteralC<"image">;
|
|
3
3
|
export declare type ImportImageBlockType = t.TypeOf<typeof ImportImageBlockType>;
|
|
4
|
-
export declare const ImportImageBlock: t.ExactC<t.TypeC<{
|
|
4
|
+
export declare const ImportImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
5
5
|
type: t.LiteralC<"image">;
|
|
6
|
+
}>, t.IntersectionC<[t.TypeC<{
|
|
6
7
|
id: t.StringC;
|
|
7
|
-
}
|
|
8
|
+
}>, t.PartialC<{
|
|
9
|
+
dimensions: t.PartialC<{
|
|
10
|
+
width: t.NumberC;
|
|
11
|
+
height: t.NumberC;
|
|
12
|
+
}>;
|
|
13
|
+
edit: t.PartialC<{
|
|
14
|
+
x: t.NumberC;
|
|
15
|
+
y: t.NumberC;
|
|
16
|
+
zoom: t.NumberC;
|
|
17
|
+
background: t.StringC;
|
|
18
|
+
}>;
|
|
19
|
+
copyright: t.UnionC<[t.StringC, t.NullC]>;
|
|
20
|
+
alt: t.UnionC<[t.StringC, t.NullC]>;
|
|
21
|
+
}>]>]>>;
|
|
8
22
|
export declare type ImportImageBlock = t.TypeOf<typeof ImportImageBlock>;
|
|
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ImportImageBlock = exports.ImportImageBlockType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
-
const validators_1 = require("
|
|
6
|
+
const validators_1 = require("../../Image/validators");
|
|
7
7
|
exports.ImportImageBlockType = t.literal("image");
|
|
8
|
-
exports.ImportImageBlock = t.
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
})
|
|
8
|
+
exports.ImportImageBlock = t.exact(t.intersection([
|
|
9
|
+
t.type({
|
|
10
|
+
type: exports.ImportImageBlockType,
|
|
11
|
+
}),
|
|
12
|
+
validators_1.ImportImageView,
|
|
13
|
+
]));
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { either } from "fp-ts"
|
|
2
|
-
import {
|
|
2
|
+
import { isRight } from "fp-ts/lib/Either"
|
|
3
3
|
import { pipe } from "fp-ts/lib/function"
|
|
4
4
|
import * as t from "io-ts"
|
|
5
5
|
|
|
@@ -18,66 +18,54 @@ import {
|
|
|
18
18
|
import { ImageContentView } from "../ImageContent"
|
|
19
19
|
import { Link, LinkLegacy } from "../LinkContent"
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
t.
|
|
23
|
-
t.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return [...acc, { ...meta, data: decoded.right }]
|
|
56
|
-
} else if (meta.type !== "hyperlink") {
|
|
57
|
-
return [...acc, meta]
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return acc
|
|
21
|
+
const SpanFn = (linkCodec: typeof Link | typeof LinkLegacy) =>
|
|
22
|
+
t.exact(
|
|
23
|
+
t.intersection([
|
|
24
|
+
t.partial({
|
|
25
|
+
data: linkCodec,
|
|
26
|
+
}),
|
|
27
|
+
t.type({
|
|
28
|
+
start: t.number,
|
|
29
|
+
end: t.number,
|
|
30
|
+
type: t.union([RichTextNodeTypeCodec, t.literal("label")]),
|
|
31
|
+
}),
|
|
32
|
+
]),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
export const Span = SpanFn(Link)
|
|
36
|
+
export type Span = t.TypeOf<typeof Span>
|
|
37
|
+
|
|
38
|
+
export const SpanLegacy = SpanFn(LinkLegacy)
|
|
39
|
+
export type SpanLegacy = t.TypeOf<typeof SpanLegacy>
|
|
40
|
+
|
|
41
|
+
export const ValidatedSpans = <C extends typeof Span | typeof SpanLegacy>(
|
|
42
|
+
spanCodec: C,
|
|
43
|
+
) => {
|
|
44
|
+
type S = t.TypeOf<C>
|
|
45
|
+
|
|
46
|
+
return new t.Type<S[], S[], unknown>(
|
|
47
|
+
"ValidatedSpans",
|
|
48
|
+
(spans): spans is S[] => Array.isArray(spans) && spans.every(spanCodec.is),
|
|
49
|
+
(spans: unknown, c) => {
|
|
50
|
+
if (Array.isArray(spans)) {
|
|
51
|
+
const res = spans
|
|
52
|
+
.reduce<Array<S>>((acc, maybeSpan) => {
|
|
53
|
+
const decodedSpan = spanCodec.decode(maybeSpan)
|
|
54
|
+
return isRight(decodedSpan) ? [...acc, decodedSpan.right] : acc
|
|
61
55
|
}, [])
|
|
62
|
-
.sort((m1:
|
|
56
|
+
.sort((m1: S, m2: S) => m1.start - m2.start)
|
|
63
57
|
return t.success(res)
|
|
64
|
-
} else return t.failure(
|
|
58
|
+
} else return t.failure(spans, c)
|
|
65
59
|
},
|
|
66
60
|
(m) => {
|
|
67
|
-
return m.reduce<Array<
|
|
68
|
-
|
|
69
|
-
// since the Span data are typed as unknown we have to redecode for type safety and then encode to either new format or legacy.
|
|
70
|
-
const decoded = linkCodec.decode(meta.data)
|
|
71
|
-
if (isLeft(decoded)) return acc
|
|
72
|
-
|
|
73
|
-
return [...acc, { ...meta, data: linkCodec.encode(decoded.right) }]
|
|
74
|
-
}
|
|
75
|
-
return [...acc, Meta.encode(meta)]
|
|
61
|
+
return m.reduce<Array<S>>((acc, meta) => {
|
|
62
|
+
return [...acc, spanCodec.encode(meta)]
|
|
76
63
|
}, [])
|
|
77
64
|
},
|
|
78
65
|
)
|
|
66
|
+
}
|
|
79
67
|
|
|
80
|
-
const ImageBlockCodec = (linkCodec:
|
|
68
|
+
const ImageBlockCodec = (linkCodec: typeof Link | typeof LinkLegacy) =>
|
|
81
69
|
t.exact(
|
|
82
70
|
t.intersection([
|
|
83
71
|
t.type({
|
|
@@ -169,8 +157,9 @@ export function checkEmbedBlock(block: Block): block is EmbedBlock {
|
|
|
169
157
|
return block.type === RichTextNodeType.embed
|
|
170
158
|
}
|
|
171
159
|
|
|
172
|
-
|
|
173
|
-
|
|
160
|
+
const TextBlockCodec = <C extends typeof Span | typeof SpanLegacy>(
|
|
161
|
+
spanCodec: C,
|
|
162
|
+
) =>
|
|
174
163
|
t.exact(
|
|
175
164
|
t.intersection([
|
|
176
165
|
t.type({
|
|
@@ -184,7 +173,7 @@ const TextBlockCodec = (linkCodec: LinkCodec) =>
|
|
|
184
173
|
text: t.string,
|
|
185
174
|
}),
|
|
186
175
|
t.partial({
|
|
187
|
-
spans:
|
|
176
|
+
spans: ValidatedSpans(spanCodec),
|
|
188
177
|
}),
|
|
189
178
|
]),
|
|
190
179
|
}),
|
|
@@ -195,10 +184,11 @@ const TextBlockCodec = (linkCodec: LinkCodec) =>
|
|
|
195
184
|
]),
|
|
196
185
|
)
|
|
197
186
|
|
|
198
|
-
|
|
187
|
+
/* These Text block will decode codec A and encode from codec B to A */
|
|
188
|
+
export const TextBlock = TextBlockCodec(Span)
|
|
199
189
|
export type TextBlock = t.TypeOf<typeof TextBlock>
|
|
200
190
|
|
|
201
|
-
|
|
191
|
+
const TextBlockLegacy = TextBlockCodec(SpanLegacy)
|
|
202
192
|
type TextBlockLegacy = t.TypeOf<typeof TextBlockLegacy>
|
|
203
193
|
|
|
204
194
|
const legacyBlockCodec = t.union([
|
|
@@ -3,24 +3,22 @@ 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
8
|
export function convertImageView<Input extends ImageField | ImportImageBlock>(
|
|
9
9
|
inputImage: Input,
|
|
10
10
|
image: Asset,
|
|
11
|
-
)
|
|
11
|
+
) {
|
|
12
12
|
// We can do that because anyway all properties being read
|
|
13
13
|
const imageField: ImageField = {
|
|
14
14
|
...inputImage,
|
|
15
|
-
edit:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
dimensions: "dimensions" in inputImage ? inputImage.dimensions : {},
|
|
15
|
+
edit: {
|
|
16
|
+
x: 0,
|
|
17
|
+
y: 0,
|
|
18
|
+
zoom: 1,
|
|
19
|
+
...inputImage.edit,
|
|
20
|
+
},
|
|
21
|
+
dimensions: inputImage.dimensions ?? {},
|
|
24
22
|
}
|
|
25
23
|
return withOptionals<ImageContentView>(
|
|
26
24
|
{
|
|
@@ -1,14 +1,17 @@
|
|
|
1
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"
|
|
2
|
+
import type { EmbedBlock } from "../../../../../content"
|
|
3
|
+
import type { ImportEmbedBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks"
|
|
4
|
+
import { embedConverter } from "../Embed"
|
|
5
5
|
|
|
6
|
-
export function embedBlockConverter(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
export function embedBlockConverter(
|
|
7
|
+
block: ImportEmbedBlock,
|
|
8
|
+
embeds: Record<string, Embed | undefined>,
|
|
9
|
+
): EmbedBlock {
|
|
10
|
+
const embedData = embedConverter(block.oembed, embeds)
|
|
11
|
+
|
|
12
|
+
if (!embedData) throw new Error("Failed to convert embed data")
|
|
13
|
+
return {
|
|
14
|
+
type: block.type,
|
|
15
|
+
data: embedData,
|
|
16
|
+
}
|
|
14
17
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
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"
|
|
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
5
|
|
|
6
|
-
export function imageBlockConverter(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
export function imageBlockConverter(
|
|
7
|
+
block: ImportImageBlock,
|
|
8
|
+
assets: Record<Asset["id"], Asset | undefined>,
|
|
9
|
+
): ImageBlock {
|
|
10
|
+
return {
|
|
11
|
+
type: block.type,
|
|
12
|
+
data: convertImageView<ImportImageBlock>(
|
|
13
|
+
block,
|
|
14
|
+
getAssetOrThrow(assets)(block.id),
|
|
15
|
+
),
|
|
16
|
+
}
|
|
14
17
|
}
|
|
@@ -15,9 +15,9 @@ export const richTextConverter = (
|
|
|
15
15
|
return {
|
|
16
16
|
__TYPE__: RichTextContentType,
|
|
17
17
|
value: richTextField.map((block) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
22
|
}
|
|
23
23
|
}
|
|
@@ -3,33 +3,46 @@ import type { TextBlock } from "../../../../../content"
|
|
|
3
3
|
import type { ImportTextBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks"
|
|
4
4
|
import { linkConverter } from "../Link"
|
|
5
5
|
|
|
6
|
-
export function textBlockConverter(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
export function textBlockConverter(
|
|
7
|
+
block: ImportTextBlock,
|
|
8
|
+
assets: Record<Asset["id"], Asset | undefined>,
|
|
9
|
+
): TextBlock {
|
|
10
|
+
return {
|
|
11
|
+
type: block.type,
|
|
12
|
+
content: {
|
|
13
|
+
text: block.text,
|
|
14
|
+
...(() => {
|
|
15
|
+
if (block.spans) {
|
|
16
|
+
const convertedSpans = spansConverter(block.spans, assets)
|
|
17
|
+
if (!convertedSpans) return {}
|
|
18
|
+
|
|
19
|
+
return { spans: convertedSpans }
|
|
20
|
+
}
|
|
21
|
+
return {}
|
|
22
|
+
})(),
|
|
23
|
+
},
|
|
24
|
+
...(block.direction ? { direction: block.direction } : {}),
|
|
25
|
+
}
|
|
15
26
|
}
|
|
16
27
|
|
|
17
|
-
function spansConverter(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
function spansConverter(
|
|
29
|
+
spans: NonNullable<ImportTextBlock["spans"]>,
|
|
30
|
+
assets: Record<Asset["id"], Asset | undefined>,
|
|
31
|
+
): TextBlock["content"]["spans"] {
|
|
32
|
+
return spans.map((span) => {
|
|
33
|
+
return {
|
|
34
|
+
type: span.type,
|
|
35
|
+
start: span.start,
|
|
36
|
+
end: span.end,
|
|
37
|
+
...(() => {
|
|
38
|
+
if (span.type === "hyperlink") {
|
|
39
|
+
const convertedLinkContent = linkConverter(span.data, assets)
|
|
40
|
+
if (!convertedLinkContent) return {}
|
|
28
41
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
return { data: convertedLinkContent?.value }
|
|
43
|
+
}
|
|
44
|
+
return {}
|
|
45
|
+
})(),
|
|
46
|
+
}
|
|
47
|
+
})
|
|
35
48
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { ImportImageView } from "../../Image/validators"
|
|
4
4
|
|
|
5
5
|
export const ImportImageBlockType = t.literal("image")
|
|
6
6
|
export type ImportImageBlockType = t.TypeOf<typeof ImportImageBlockType>
|
|
7
7
|
|
|
8
|
-
export const ImportImageBlock = t.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export const ImportImageBlock = t.exact(
|
|
9
|
+
t.intersection([
|
|
10
|
+
t.type({
|
|
11
|
+
type: ImportImageBlockType,
|
|
12
|
+
}),
|
|
13
|
+
ImportImageView,
|
|
14
|
+
]),
|
|
15
|
+
)
|
|
12
16
|
|
|
13
17
|
export type ImportImageBlock = t.TypeOf<typeof ImportImageBlock>
|
|
@@ -1,15 +0,0 @@
|
|
|
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,4 +0,0 @@
|
|
|
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;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.richTextConverter = void 0;
|
|
4
|
-
const content_1 = require("../../../../content");
|
|
5
|
-
const Embed_1 = require("./Embed");
|
|
6
|
-
const Image_1 = require("./Image");
|
|
7
|
-
const Link_1 = require("./Link");
|
|
8
|
-
const richTextBlockConverter = (importBlock, assets, embeds) => {
|
|
9
|
-
var _a, _b, _c;
|
|
10
|
-
if (importBlock.type === "image") {
|
|
11
|
-
return {
|
|
12
|
-
type: importBlock.type,
|
|
13
|
-
data: (0, Image_1.imageBlockConverter)(importBlock, assets),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
else if (importBlock.type === "embed") {
|
|
17
|
-
const embedData = (0, Embed_1.embedConverter)(importBlock.oembed, embeds);
|
|
18
|
-
if (!embedData)
|
|
19
|
-
throw new Error("Failed to convert embed data");
|
|
20
|
-
return {
|
|
21
|
-
type: importBlock.type,
|
|
22
|
-
data: embedData,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
// Text block
|
|
27
|
-
return {
|
|
28
|
-
type: importBlock.type,
|
|
29
|
-
direction: (_a = importBlock.direction) !== null && _a !== void 0 ? _a : "ltr",
|
|
30
|
-
content: {
|
|
31
|
-
text: importBlock.text,
|
|
32
|
-
spans: (_c = (_b = importBlock.spans) === null || _b === void 0 ? void 0 : _b.map((span) => {
|
|
33
|
-
const linkData = span.type === "hyperlink"
|
|
34
|
-
? (0, Link_1.linkConverter)(span.data, assets)
|
|
35
|
-
: undefined;
|
|
36
|
-
return {
|
|
37
|
-
type: span.type,
|
|
38
|
-
start: span.start,
|
|
39
|
-
end: span.end,
|
|
40
|
-
data: linkData,
|
|
41
|
-
};
|
|
42
|
-
})) !== null && _c !== void 0 ? _c : [],
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const richTextConverter = (richTextField, assets, embeds) => {
|
|
48
|
-
if (richTextField === null)
|
|
49
|
-
return;
|
|
50
|
-
return {
|
|
51
|
-
__TYPE__: content_1.RichTextContentType,
|
|
52
|
-
value: richTextField.map((block) => richTextBlockConverter(block, assets, embeds)),
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
exports.richTextConverter = richTextConverter;
|