@prismicio/types-internal 2.2.0-traverse.alpha-6 → 2.2.0-traverse.alpha-8
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/_internal/utils.d.ts +3 -6
- package/lib/content/Document.d.ts +1248 -32
- package/lib/content/Document.js +1 -1
- 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 -6
- package/lib/content/fields/nestable/NestableContent.js +1 -29
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +582 -28
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +29 -46
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +195 -5
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +314 -10
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +18 -12
- 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/SharedSliceContent.js +5 -1
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +312 -8
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +1 -1
- 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/content/fields/slices/SlicesContent.js +2 -4
- package/lib/customtypes/CustomType.d.ts +1 -1
- package/lib/customtypes/CustomType.js +3 -3
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +0 -5
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +1 -2
- 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 +25 -3
- package/lib/import/converters/fields/nestable/Image.js +21 -25
- 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 +41 -0
- package/lib/import/converters/fields/nestable/index.d.ts +1 -1
- package/lib/import/converters/fields/nestable/index.js +1 -1
- package/lib/import/validators/fields/ImportContent.js +3 -3
- package/lib/import/validators/fields/ImportField.d.ts +1 -1
- package/lib/import/validators/fields/ImportSlices/ImportSlices.js +4 -3
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +1 -1
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +1 -1
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +20 -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/lib/import/validators/fields/nestable/Nestable.d.ts +1 -1
- package/lib/validators/DefaultOrElse.js +3 -3
- package/package.json +1 -1
- package/src/_internal/utils.ts +3 -7
- package/src/content/Document.ts +2 -2
- package/src/content/fields/nestable/NestableContent.ts +0 -32
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +48 -58
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +26 -16
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +7 -1
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +1 -1
- package/src/content/fields/slices/SlicesContent.ts +4 -6
- package/src/customtypes/CustomType.ts +1 -1
- package/src/customtypes/widgets/slices/CompositeSlice.ts +0 -6
- package/src/customtypes/widgets/slices/SharedSlice.ts +2 -2
- package/src/import/converters/fields/nestable/Image.ts +10 -22
- package/src/import/converters/fields/nestable/RichText/embedBlock.ts +17 -0
- package/src/import/converters/fields/nestable/RichText/imageBlock.ts +17 -0
- package/src/import/converters/fields/nestable/RichText/index.ts +23 -0
- package/src/import/converters/fields/nestable/RichText/textBlock.ts +48 -0
- package/src/import/converters/fields/nestable/index.ts +1 -1
- package/src/import/validators/fields/ImportContent.ts +3 -3
- package/src/import/validators/fields/ImportSlices/ImportSlices.ts +7 -5
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +1 -1
- package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +38 -25
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +9 -5
- package/src/validators/DefaultOrElse.ts +4 -4
- package/src/import/converters/fields/nestable/RichText.ts +0 -62
- /package/src/import/converters/fields/nestable/{GeooPoint.ts → GeoPoint.ts} +0 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as E from "fp-ts/Either"
|
|
2
|
+
import { pipe } from "fp-ts/function"
|
|
1
3
|
import * as t from "io-ts"
|
|
2
4
|
|
|
3
5
|
import type { RichText as RichTextCustomType } from "../../../../../customtypes"
|
|
@@ -6,36 +8,47 @@ import { withCustomError } from "../../../../../validators/function"
|
|
|
6
8
|
import { ImportContent } from "../../ImportContent"
|
|
7
9
|
import { ImportBlock } from "./ImportBlock"
|
|
8
10
|
|
|
9
|
-
export const ImportRichText = (customType?: RichTextCustomType) =>
|
|
10
|
-
|
|
11
|
+
export const ImportRichText = (customType?: RichTextCustomType) => {
|
|
12
|
+
const single = customType?.config?.single?.split(",")
|
|
13
|
+
const multi = customType?.config?.multi?.split(",")
|
|
14
|
+
const allowedBlockTypes = multi || single
|
|
15
|
+
|
|
16
|
+
const isSingleBlockAllowed = multi === undefined && single !== undefined
|
|
17
|
+
|
|
18
|
+
const BlockCodec = ImportBlock(allowedBlockTypes ?? [])
|
|
19
|
+
const RichTextArrayCodec = withCustomError(
|
|
20
|
+
t.array(BlockCodec),
|
|
21
|
+
() => "Rich text field must be an array",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
return ImportContent(
|
|
11
25
|
"StructuredText",
|
|
12
26
|
EmptyArrayOrElse(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
27
|
+
new t.ArrayType<typeof BlockCodec, ImportBlock[], ImportBlock[]>(
|
|
28
|
+
RichTextArrayCodec.name,
|
|
29
|
+
(u): u is ImportBlock[] => RichTextArrayCodec.is(u),
|
|
30
|
+
(u, c) => {
|
|
31
|
+
if (allowedBlockTypes === undefined) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"Invalid custom type for the rich text field: the model is missing a 'single' or 'multi' field defining a list of allowed block types",
|
|
34
|
+
)
|
|
35
|
+
}
|
|
21
36
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
: t.array(ImportBlock(single)).validate(u, c)
|
|
28
|
-
} else {
|
|
29
|
-
throw new Error(
|
|
30
|
-
"Rich text config must have either a 'single' or 'multi' field defined",
|
|
31
|
-
)
|
|
37
|
+
return pipe(
|
|
38
|
+
RichTextArrayCodec.validate(u, c),
|
|
39
|
+
E.chain((blocks) => {
|
|
40
|
+
if (isSingleBlockAllowed && blocks.length > 1) {
|
|
41
|
+
return t.failure(blocks, c, "This field only allows one block")
|
|
32
42
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
return t.success(blocks)
|
|
44
|
+
}),
|
|
45
|
+
)
|
|
46
|
+
},
|
|
47
|
+
t.identity,
|
|
48
|
+
BlockCodec,
|
|
38
49
|
),
|
|
39
50
|
),
|
|
40
51
|
)
|
|
52
|
+
}
|
|
53
|
+
|
|
41
54
|
export type ImportRichText = t.TypeOf<ReturnType<typeof ImportRichText>>
|
|
@@ -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>
|
|
@@ -6,11 +6,11 @@ import { EmptyArray, EmptyObject } from "./BasicTypes"
|
|
|
6
6
|
export const DefaultOrElse = <I, A, O = A>(inputValidator: t.Type<I>) => {
|
|
7
7
|
return (codec: t.Type<A, O>) =>
|
|
8
8
|
new t.Type<A | null, O | undefined>(
|
|
9
|
-
|
|
9
|
+
`DefaultOrElse<${inputValidator.name}, ${codec.name}>`,
|
|
10
10
|
(u: unknown): u is A | null => null === u || codec.is(u),
|
|
11
|
-
(u: unknown) => {
|
|
12
|
-
if (isRight(inputValidator.
|
|
13
|
-
return codec.
|
|
11
|
+
(u: unknown, c) => {
|
|
12
|
+
if (isRight(inputValidator.validate(u, c))) return t.success(null)
|
|
13
|
+
return codec.validate(u, c)
|
|
14
14
|
},
|
|
15
15
|
(chunk) => (chunk ? codec.encode(chunk) : undefined),
|
|
16
16
|
)
|
|
@@ -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
|