@platecms/delta-cast-util-to-slate 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -7
- package/src/lib/handlers/blockContent/{blockquote.d.ts → blockquote.ts} +5 -1
- package/src/lib/handlers/blockContent/code.ts +7 -0
- package/src/lib/handlers/blockContent/heading.ts +11 -0
- package/src/lib/handlers/blockContent/list.ts +11 -0
- package/src/lib/handlers/blockContent/listItem.ts +10 -0
- package/src/lib/handlers/blockContent/{paragraph.d.ts → paragraph.ts} +5 -1
- package/src/lib/handlers/inlineContent/bold.ts +10 -0
- package/src/lib/handlers/inlineContent/{contentValue.d.ts → contentValue.ts} +13 -1
- package/src/lib/handlers/inlineContent/externalLink.ts +12 -0
- package/src/lib/handlers/inlineContent/highlight.ts +10 -0
- package/src/lib/handlers/inlineContent/inlineCode.ts +10 -0
- package/src/lib/handlers/inlineContent/internalLink.ts +29 -0
- package/src/lib/handlers/inlineContent/italic.ts +10 -0
- package/src/lib/handlers/inlineContent/strikethrough.ts +10 -0
- package/src/lib/handlers/inlineContent/text.ts +11 -0
- package/src/lib/handlers/inlineContent/underline.ts +10 -0
- package/src/lib/index.spec.ts +341 -0
- package/src/lib/index.ts +57 -0
- package/src/lib/utils/handlers.ts +37 -0
- package/src/index.js +0 -5
- package/src/index.js.map +0 -1
- package/src/lib/handlers/blockContent/blockquote.js +0 -8
- package/src/lib/handlers/blockContent/blockquote.js.map +0 -1
- package/src/lib/handlers/blockContent/code.d.ts +0 -3
- package/src/lib/handlers/blockContent/code.js +0 -8
- package/src/lib/handlers/blockContent/code.js.map +0 -1
- package/src/lib/handlers/blockContent/heading.d.ts +0 -3
- package/src/lib/handlers/blockContent/heading.js +0 -12
- package/src/lib/handlers/blockContent/heading.js.map +0 -1
- package/src/lib/handlers/blockContent/list.d.ts +0 -3
- package/src/lib/handlers/blockContent/list.js +0 -12
- package/src/lib/handlers/blockContent/list.js.map +0 -1
- package/src/lib/handlers/blockContent/listItem.d.ts +0 -3
- package/src/lib/handlers/blockContent/listItem.js +0 -11
- package/src/lib/handlers/blockContent/listItem.js.map +0 -1
- package/src/lib/handlers/blockContent/paragraph.js +0 -8
- package/src/lib/handlers/blockContent/paragraph.js.map +0 -1
- package/src/lib/handlers/inlineContent/bold.d.ts +0 -3
- package/src/lib/handlers/inlineContent/bold.js +0 -11
- package/src/lib/handlers/inlineContent/bold.js.map +0 -1
- package/src/lib/handlers/inlineContent/contentValue.js +0 -16
- package/src/lib/handlers/inlineContent/contentValue.js.map +0 -1
- package/src/lib/handlers/inlineContent/externalLink.d.ts +0 -3
- package/src/lib/handlers/inlineContent/externalLink.js +0 -13
- package/src/lib/handlers/inlineContent/externalLink.js.map +0 -1
- package/src/lib/handlers/inlineContent/highlight.d.ts +0 -3
- package/src/lib/handlers/inlineContent/highlight.js +0 -11
- package/src/lib/handlers/inlineContent/highlight.js.map +0 -1
- package/src/lib/handlers/inlineContent/inlineCode.d.ts +0 -3
- package/src/lib/handlers/inlineContent/inlineCode.js +0 -11
- package/src/lib/handlers/inlineContent/inlineCode.js.map +0 -1
- package/src/lib/handlers/inlineContent/internalLink.d.ts +0 -3
- package/src/lib/handlers/inlineContent/internalLink.js +0 -29
- package/src/lib/handlers/inlineContent/internalLink.js.map +0 -1
- package/src/lib/handlers/inlineContent/italic.d.ts +0 -3
- package/src/lib/handlers/inlineContent/italic.js +0 -11
- package/src/lib/handlers/inlineContent/italic.js.map +0 -1
- package/src/lib/handlers/inlineContent/strikethrough.d.ts +0 -3
- package/src/lib/handlers/inlineContent/strikethrough.js +0 -11
- package/src/lib/handlers/inlineContent/strikethrough.js.map +0 -1
- package/src/lib/handlers/inlineContent/text.d.ts +0 -3
- package/src/lib/handlers/inlineContent/text.js +0 -12
- package/src/lib/handlers/inlineContent/text.js.map +0 -1
- package/src/lib/handlers/inlineContent/underline.d.ts +0 -3
- package/src/lib/handlers/inlineContent/underline.js +0 -11
- package/src/lib/handlers/inlineContent/underline.js.map +0 -1
- package/src/lib/index.d.ts +0 -4
- package/src/lib/index.js +0 -52
- package/src/lib/index.js.map +0 -1
- package/src/lib/utils/handlers.d.ts +0 -8
- package/src/lib/utils/handlers.js +0 -33
- package/src/lib/utils/handlers.js.map +0 -1
- /package/src/{index.d.ts → index.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platecms/delta-cast-util-to-slate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Utility to convert CAST trees to Slate nodes.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"src/**/*"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@platecms/delta-cast": "0.
|
|
21
|
-
"@platecms/delta-castscript": "0.
|
|
22
|
-
"@platecms/delta-client": "0.
|
|
23
|
-
"@platecms/delta-plate-resource-notation": "0.
|
|
20
|
+
"@platecms/delta-cast": "0.7.0",
|
|
21
|
+
"@platecms/delta-castscript": "0.7.0",
|
|
22
|
+
"@platecms/delta-client": "0.7.0",
|
|
23
|
+
"@platecms/delta-plate-resource-notation": "0.7.0",
|
|
24
24
|
"@graphql-typed-document-node/core": "3.2.0",
|
|
25
25
|
"class-transformer": "0.5.1",
|
|
26
26
|
"graphql": "16.11.0",
|
|
@@ -32,6 +32,5 @@
|
|
|
32
32
|
"zwitch": "2.0.4",
|
|
33
33
|
"@apollo/client": "3.13.9",
|
|
34
34
|
"defu": "6.1.4"
|
|
35
|
-
}
|
|
36
|
-
"type": "commonjs"
|
|
35
|
+
}
|
|
37
36
|
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { Blockquote } from "@platecms/delta-cast";
|
|
2
2
|
import { BlockquoteElement } from "@platecms/delta-client/slate";
|
|
3
|
-
|
|
3
|
+
import { handleBlockContent } from "../../utils/handlers";
|
|
4
|
+
|
|
5
|
+
export default function blockquote(node: Blockquote): BlockquoteElement {
|
|
6
|
+
return handleBlockContent(node) as BlockquoteElement;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Code, InlineContent } from "@platecms/delta-cast";
|
|
2
|
+
import { CodeElement } from "@platecms/delta-client/slate";
|
|
3
|
+
import { handleBlockContent } from "../../utils/handlers";
|
|
4
|
+
|
|
5
|
+
export default function code(node: Code): CodeElement {
|
|
6
|
+
return handleBlockContent(node as Code & { children: InlineContent[] }) as CodeElement;
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Heading } from "@platecms/delta-cast";
|
|
2
|
+
import { resolveCustomTextNodes } from "../../utils/handlers";
|
|
3
|
+
import { DeltaElement } from "@platecms/delta-client/slate";
|
|
4
|
+
|
|
5
|
+
export default function heading(node: Heading): DeltaElement {
|
|
6
|
+
return {
|
|
7
|
+
type: node.type,
|
|
8
|
+
level: node.level,
|
|
9
|
+
children: resolveCustomTextNodes(node.children),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { List } from "@platecms/delta-cast";
|
|
2
|
+
import { ListElement, ListItemElement } from "@platecms/delta-client/slate";
|
|
3
|
+
import { all } from "./../../index";
|
|
4
|
+
|
|
5
|
+
export default function list(node: List): ListElement {
|
|
6
|
+
return {
|
|
7
|
+
type: node.type,
|
|
8
|
+
ordered: node.ordered,
|
|
9
|
+
children: all(node.children) as ListItemElement[],
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { resolveCustomTextNodes } from "../../utils/handlers";
|
|
2
|
+
import { DeltaElement } from "@platecms/delta-client/slate";
|
|
3
|
+
import { ListItem } from "@platecms/delta-cast";
|
|
4
|
+
|
|
5
|
+
export default function listItem(node: ListItem): DeltaElement {
|
|
6
|
+
return {
|
|
7
|
+
type: node.type,
|
|
8
|
+
children: resolveCustomTextNodes(node.children),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { Paragraph } from "@platecms/delta-cast";
|
|
2
|
+
import { handleBlockContent } from "../../utils/handlers";
|
|
2
3
|
import { DeltaElement } from "@platecms/delta-client/slate";
|
|
3
|
-
|
|
4
|
+
|
|
5
|
+
export default function paragraph(node: Paragraph): DeltaElement {
|
|
6
|
+
return handleBlockContent(node);
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Bold } from "@platecms/delta-cast";
|
|
2
|
+
import { resolveCustomTextNodes } from "../../utils/handlers";
|
|
3
|
+
import { DeltaLeaf } from "@platecms/delta-client/slate";
|
|
4
|
+
|
|
5
|
+
export default function bold(node: Bold, state: Omit<DeltaLeaf, "text"> = {}): DeltaLeaf[] {
|
|
6
|
+
return resolveCustomTextNodes(node.children, {
|
|
7
|
+
...state,
|
|
8
|
+
bold: true,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
import { InterpolatedContentValue } from "@platecms/delta-cast";
|
|
2
2
|
import { ContentValueElement } from "@platecms/delta-client/slate";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
export default function contentValue(node: InterpolatedContentValue): ContentValueElement {
|
|
5
|
+
return {
|
|
6
|
+
prn: node.prn,
|
|
7
|
+
type: "contentValue",
|
|
8
|
+
root: node.value,
|
|
9
|
+
children: [
|
|
10
|
+
{
|
|
11
|
+
text: "",
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExternalLink } from "@platecms/delta-cast";
|
|
2
|
+
import { resolveCustomTextNodes } from "../../utils/handlers";
|
|
3
|
+
import { LinkElement } from "@platecms/delta-client/slate";
|
|
4
|
+
|
|
5
|
+
export default function externalLink(node: ExternalLink): LinkElement {
|
|
6
|
+
return {
|
|
7
|
+
type: "link",
|
|
8
|
+
url: node.url,
|
|
9
|
+
children: resolveCustomTextNodes(node.children),
|
|
10
|
+
target: node.target,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Highlight } from "@platecms/delta-cast";
|
|
2
|
+
import { resolveCustomTextNodes } from "../../utils/handlers";
|
|
3
|
+
import { DeltaLeaf } from "@platecms/delta-client/slate";
|
|
4
|
+
|
|
5
|
+
export default function highlight(node: Highlight, state: Omit<DeltaLeaf, "text"> = {}): DeltaLeaf[] {
|
|
6
|
+
return resolveCustomTextNodes(node.children, {
|
|
7
|
+
...state,
|
|
8
|
+
highlight: true,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { InlineCode } from "@platecms/delta-cast";
|
|
2
|
+
import { resolveCustomTextNodes } from "../../utils/handlers";
|
|
3
|
+
import { DeltaLeaf } from "@platecms/delta-client/slate";
|
|
4
|
+
|
|
5
|
+
export default function inlineCode(node: InlineCode, state: Omit<DeltaLeaf, "text"> = {}): DeltaLeaf[] {
|
|
6
|
+
return resolveCustomTextNodes([{ type: "text", value: node.value }], {
|
|
7
|
+
...state,
|
|
8
|
+
inlineCode: true,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { InternalLink } from "@platecms/delta-cast";
|
|
2
|
+
import { resolveCustomTextNodes } from "../../utils/handlers";
|
|
3
|
+
import { LinkElement } from "@platecms/delta-client/slate";
|
|
4
|
+
import { InvalidPrnError, PRN } from "@platecms/delta-plate-resource-notation";
|
|
5
|
+
|
|
6
|
+
function isGridPlacementPrn(prn: string): boolean {
|
|
7
|
+
try {
|
|
8
|
+
return PRN.fromString(prn).resourceType === "grid-placement";
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (error instanceof InvalidPrnError) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function internalLink(node: InternalLink): LinkElement {
|
|
19
|
+
return {
|
|
20
|
+
type: "link",
|
|
21
|
+
url: node.url!,
|
|
22
|
+
children: resolveCustomTextNodes(node.children),
|
|
23
|
+
target: node.target,
|
|
24
|
+
internal: {
|
|
25
|
+
prn: node.prn,
|
|
26
|
+
anchor: isGridPlacementPrn(node.prn),
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Italic } from "@platecms/delta-cast";
|
|
2
|
+
import { resolveCustomTextNodes } from "../../utils/handlers";
|
|
3
|
+
import { DeltaLeaf } from "@platecms/delta-client/slate";
|
|
4
|
+
|
|
5
|
+
export default function italic(node: Italic, state: Omit<DeltaLeaf, "text"> = {}): DeltaLeaf[] {
|
|
6
|
+
return resolveCustomTextNodes(node.children, {
|
|
7
|
+
...state,
|
|
8
|
+
italic: true,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Strikethrough } from "@platecms/delta-cast";
|
|
2
|
+
import { resolveCustomTextNodes } from "../../utils/handlers";
|
|
3
|
+
import { DeltaLeaf } from "@platecms/delta-client/slate";
|
|
4
|
+
|
|
5
|
+
export default function strikethrough(node: Strikethrough, state: Omit<DeltaLeaf, "text"> = {}): DeltaLeaf[] {
|
|
6
|
+
return resolveCustomTextNodes(node.children, {
|
|
7
|
+
...state,
|
|
8
|
+
strikethrough: true,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Text } from "@platecms/delta-cast";
|
|
2
|
+
import { DeltaLeaf } from "@platecms/delta-client/slate";
|
|
3
|
+
|
|
4
|
+
export default function text(node: Text, state: Omit<DeltaLeaf, "text"> = {}): DeltaLeaf[] {
|
|
5
|
+
return [
|
|
6
|
+
{
|
|
7
|
+
...state,
|
|
8
|
+
text: node.value,
|
|
9
|
+
},
|
|
10
|
+
];
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Underline } from "@platecms/delta-cast";
|
|
2
|
+
import { resolveCustomTextNodes } from "../../utils/handlers";
|
|
3
|
+
import { DeltaLeaf } from "@platecms/delta-client/slate";
|
|
4
|
+
|
|
5
|
+
export default function underline(node: Underline, state: Omit<DeltaLeaf, "text"> = {}): DeltaLeaf[] {
|
|
6
|
+
return resolveCustomTextNodes(node.children, {
|
|
7
|
+
...state,
|
|
8
|
+
underline: true,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { describe, it } from "vitest";
|
|
2
|
+
import { Descendant } from "slate";
|
|
3
|
+
import { toSlate } from "../index";
|
|
4
|
+
import { c } from "@platecms/delta-castscript";
|
|
5
|
+
import { Root } from "@platecms/delta-cast";
|
|
6
|
+
|
|
7
|
+
describe("single nodes", () => {
|
|
8
|
+
it("should convert a paragraph from cast to slate", () => {
|
|
9
|
+
// Arrange
|
|
10
|
+
const cast: Root = c("root", [c("paragraph", "Hello, world!")]);
|
|
11
|
+
|
|
12
|
+
const slate: Descendant[] = [
|
|
13
|
+
{
|
|
14
|
+
type: "paragraph",
|
|
15
|
+
children: [
|
|
16
|
+
{
|
|
17
|
+
text: "Hello, world!",
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
// Act
|
|
24
|
+
const result = toSlate(cast);
|
|
25
|
+
|
|
26
|
+
// Assert
|
|
27
|
+
expect(result).toEqual(slate);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should convert a heading from cast to slate", () => {
|
|
31
|
+
// Arrange
|
|
32
|
+
const cast: Root = c("root", [c("heading", "Hello, world!", { level: 1 })]);
|
|
33
|
+
|
|
34
|
+
const expected: Descendant[] = [
|
|
35
|
+
{
|
|
36
|
+
type: "heading",
|
|
37
|
+
level: 1,
|
|
38
|
+
children: [
|
|
39
|
+
{
|
|
40
|
+
text: "Hello, world!",
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
// Act
|
|
47
|
+
const result = toSlate(cast);
|
|
48
|
+
|
|
49
|
+
// Assert
|
|
50
|
+
expect(result).toEqual(expected);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should convert a list from cast to slate", () => {
|
|
54
|
+
// Arrange
|
|
55
|
+
const cast: Root = c("root", [c("list", { ordered: false }, [c("listItem", "Hello, world!")])]);
|
|
56
|
+
|
|
57
|
+
const expected: Descendant[] = [
|
|
58
|
+
{
|
|
59
|
+
type: "list",
|
|
60
|
+
ordered: false,
|
|
61
|
+
children: [
|
|
62
|
+
{
|
|
63
|
+
type: "listItem",
|
|
64
|
+
children: [
|
|
65
|
+
{
|
|
66
|
+
text: "Hello, world!",
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
// Act
|
|
75
|
+
const result = toSlate(cast);
|
|
76
|
+
|
|
77
|
+
// Assert
|
|
78
|
+
expect(result).toEqual(expected);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("should convert a blockquote from cast to slate", () => {
|
|
82
|
+
// Arrange
|
|
83
|
+
const cast: Root = c("root", [c("blockquote", [c("text", "Hello, world!")])]);
|
|
84
|
+
|
|
85
|
+
const expected: Descendant[] = [
|
|
86
|
+
{
|
|
87
|
+
type: "blockquote",
|
|
88
|
+
children: [
|
|
89
|
+
{
|
|
90
|
+
text: "Hello, world!",
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
// Act
|
|
97
|
+
const result = toSlate(cast);
|
|
98
|
+
|
|
99
|
+
// Assert
|
|
100
|
+
expect(result).toEqual(expected);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("should convert code from cast to slate", () => {
|
|
104
|
+
// Arrange
|
|
105
|
+
const cast: Root = c("root", [c("code", "Hello, world!")]);
|
|
106
|
+
|
|
107
|
+
const expected: Descendant[] = [
|
|
108
|
+
{
|
|
109
|
+
type: "code",
|
|
110
|
+
children: [
|
|
111
|
+
{
|
|
112
|
+
text: "Hello, world!",
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
// Act
|
|
119
|
+
const result = toSlate(cast);
|
|
120
|
+
|
|
121
|
+
// Assert
|
|
122
|
+
expect(result).toEqual(expected);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("should convert a content value from cast to slate", () => {
|
|
126
|
+
// Arrange
|
|
127
|
+
const cast: Root = c("root", [
|
|
128
|
+
c("contentValue", {
|
|
129
|
+
prn: "prn:content-value:content-value",
|
|
130
|
+
value: c("root", [c("paragraph", "Hello, world!")]),
|
|
131
|
+
}),
|
|
132
|
+
]);
|
|
133
|
+
|
|
134
|
+
const expected: Descendant[] = [
|
|
135
|
+
{
|
|
136
|
+
type: "contentValue",
|
|
137
|
+
prn: "prn:content-value:content-value",
|
|
138
|
+
root: c("root", [c("paragraph", "Hello, world!")]),
|
|
139
|
+
children: [
|
|
140
|
+
{
|
|
141
|
+
text: "",
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
// Act
|
|
148
|
+
const result = toSlate(cast);
|
|
149
|
+
|
|
150
|
+
// Assert
|
|
151
|
+
expect(result).toEqual(expected);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("nested nodes", () => {
|
|
156
|
+
it("should convert a nested tree from cast to slate", () => {
|
|
157
|
+
// Arrange
|
|
158
|
+
const cast: Root = c("root", [
|
|
159
|
+
c("list", { ordered: false }, [c("listItem", [c("italic", [c("bold", "Hello, world!")])])]),
|
|
160
|
+
c("paragraph", [
|
|
161
|
+
c("underline", [c("strikethrough", "Hello, world!")]),
|
|
162
|
+
c("inlineCode", { value: "Hello, world!" }),
|
|
163
|
+
c("contentValue", {
|
|
164
|
+
prn: "prn:content-value:content-value",
|
|
165
|
+
value: c("root", [c("paragraph", "Hello, world!")]),
|
|
166
|
+
}),
|
|
167
|
+
]),
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
const expected: Descendant[] = [
|
|
171
|
+
{
|
|
172
|
+
type: "list",
|
|
173
|
+
ordered: false,
|
|
174
|
+
children: [
|
|
175
|
+
{
|
|
176
|
+
type: "listItem",
|
|
177
|
+
children: [
|
|
178
|
+
{
|
|
179
|
+
text: "Hello, world!",
|
|
180
|
+
bold: true,
|
|
181
|
+
italic: true,
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
type: "paragraph",
|
|
189
|
+
children: [
|
|
190
|
+
{
|
|
191
|
+
text: "Hello, world!",
|
|
192
|
+
strikethrough: true,
|
|
193
|
+
underline: true,
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
text: "Hello, world!",
|
|
197
|
+
inlineCode: true,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
type: "contentValue",
|
|
201
|
+
prn: "prn:content-value:content-value",
|
|
202
|
+
root: c("root", [c("paragraph", "Hello, world!")]),
|
|
203
|
+
children: [
|
|
204
|
+
{
|
|
205
|
+
text: "",
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
];
|
|
212
|
+
|
|
213
|
+
// Act
|
|
214
|
+
const result = toSlate(cast);
|
|
215
|
+
|
|
216
|
+
// Assert
|
|
217
|
+
expect(result).toEqual(expected);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe("links", () => {
|
|
221
|
+
it("should convert an external link from cast to slate", () => {
|
|
222
|
+
// Arrange
|
|
223
|
+
const cast: Root = c("root", [
|
|
224
|
+
c("externalLink", { url: "https://www.google.com" }, [c("text", "Hello, world!")]),
|
|
225
|
+
]);
|
|
226
|
+
|
|
227
|
+
const expected: Descendant[] = [
|
|
228
|
+
{
|
|
229
|
+
type: "link",
|
|
230
|
+
url: "https://www.google.com",
|
|
231
|
+
children: [
|
|
232
|
+
{
|
|
233
|
+
text: "Hello, world!",
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
},
|
|
237
|
+
];
|
|
238
|
+
|
|
239
|
+
// Act
|
|
240
|
+
const result = toSlate(cast);
|
|
241
|
+
|
|
242
|
+
// Assert
|
|
243
|
+
expect(result).toEqual(expected);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("should convert an external link from cast to slate", () => {
|
|
247
|
+
// Arrange
|
|
248
|
+
const cast: Root = c("root", [
|
|
249
|
+
c("externalLink", { url: "https://www.google.com", target: "blank" }, [c("text", "Hello, world!")]),
|
|
250
|
+
]);
|
|
251
|
+
|
|
252
|
+
const expected: Descendant[] = [
|
|
253
|
+
{
|
|
254
|
+
type: "link",
|
|
255
|
+
url: "https://www.google.com",
|
|
256
|
+
target: "blank",
|
|
257
|
+
children: [
|
|
258
|
+
{
|
|
259
|
+
text: "Hello, world!",
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
},
|
|
263
|
+
];
|
|
264
|
+
|
|
265
|
+
// Act
|
|
266
|
+
const result = toSlate(cast);
|
|
267
|
+
|
|
268
|
+
// Assert
|
|
269
|
+
expect(result).toEqual(expected);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("should convert an internal link from cast to slate", () => {
|
|
273
|
+
// Arrange
|
|
274
|
+
const cast: Root = c("root", [
|
|
275
|
+
c("internalLink", { url: "https://www.google.com", prn: "prn:path-part:path-part" }, [
|
|
276
|
+
c("text", "Hello, world!"),
|
|
277
|
+
]),
|
|
278
|
+
]);
|
|
279
|
+
|
|
280
|
+
const expected: Descendant[] = [
|
|
281
|
+
{
|
|
282
|
+
type: "link",
|
|
283
|
+
url: "https://www.google.com",
|
|
284
|
+
children: [
|
|
285
|
+
{
|
|
286
|
+
text: "Hello, world!",
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
target: undefined,
|
|
290
|
+
internal: {
|
|
291
|
+
prn: "prn:path-part:path-part",
|
|
292
|
+
anchor: false,
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
];
|
|
296
|
+
|
|
297
|
+
// Act
|
|
298
|
+
const result = toSlate(cast);
|
|
299
|
+
|
|
300
|
+
// Assert
|
|
301
|
+
expect(result).toEqual(expected);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("should convert an internal anchor link from cast to slate", () => {
|
|
305
|
+
// Arrange
|
|
306
|
+
const cast: Root = c("root", [
|
|
307
|
+
c(
|
|
308
|
+
"internalLink",
|
|
309
|
+
{
|
|
310
|
+
url: "https://www.google.com#anchor-name",
|
|
311
|
+
prn: "prn:text:org-id:cxc:grid-placement:1",
|
|
312
|
+
},
|
|
313
|
+
[c("text", "Hello, world!")],
|
|
314
|
+
),
|
|
315
|
+
]);
|
|
316
|
+
|
|
317
|
+
const expected: Descendant[] = [
|
|
318
|
+
{
|
|
319
|
+
type: "link",
|
|
320
|
+
url: "https://www.google.com#anchor-name",
|
|
321
|
+
children: [
|
|
322
|
+
{
|
|
323
|
+
text: "Hello, world!",
|
|
324
|
+
},
|
|
325
|
+
],
|
|
326
|
+
target: undefined,
|
|
327
|
+
internal: {
|
|
328
|
+
prn: "prn:text:org-id:cxc:grid-placement:1",
|
|
329
|
+
anchor: true,
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
];
|
|
333
|
+
|
|
334
|
+
// Act
|
|
335
|
+
const result = toSlate(cast);
|
|
336
|
+
|
|
337
|
+
// Assert
|
|
338
|
+
expect(result).toEqual(expected);
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
});
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Descendant } from "slate";
|
|
2
|
+
import { Content, Root } from "@platecms/delta-cast";
|
|
3
|
+
import { zwitch } from "zwitch";
|
|
4
|
+
import paragraph from "./handlers/blockContent/paragraph";
|
|
5
|
+
import heading from "./handlers/blockContent/heading";
|
|
6
|
+
import contentValue from "./handlers/inlineContent/contentValue";
|
|
7
|
+
import list from "./handlers/blockContent/list";
|
|
8
|
+
import listItem from "./handlers/blockContent/listItem";
|
|
9
|
+
import code from "./handlers/blockContent/code";
|
|
10
|
+
import blockquote from "./handlers/blockContent/blockquote";
|
|
11
|
+
import highlight from "./handlers/inlineContent/highlight";
|
|
12
|
+
import inlineCode from "./handlers/inlineContent/inlineCode";
|
|
13
|
+
import externalLink from "./handlers/inlineContent/externalLink";
|
|
14
|
+
import { DeltaElement } from "@platecms/delta-client/slate";
|
|
15
|
+
import internalLink from "./handlers/inlineContent/internalLink";
|
|
16
|
+
|
|
17
|
+
export function toSlate(value: Root): Descendant[] {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
19
|
+
return all(value.children);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const one = zwitch("type", {
|
|
23
|
+
handlers: {
|
|
24
|
+
paragraph,
|
|
25
|
+
heading,
|
|
26
|
+
contentValue,
|
|
27
|
+
list,
|
|
28
|
+
listItem,
|
|
29
|
+
code,
|
|
30
|
+
blockquote,
|
|
31
|
+
highlight,
|
|
32
|
+
inlineCode,
|
|
33
|
+
externalLink,
|
|
34
|
+
internalLink,
|
|
35
|
+
},
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
37
|
+
unknown: (_: unknown) => defaultHandler(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export function all(nodes: Content[]): Descendant[] {
|
|
41
|
+
let index = -1;
|
|
42
|
+
const results = [];
|
|
43
|
+
|
|
44
|
+
while (++index < nodes.length) {
|
|
45
|
+
const result = one(nodes[index]);
|
|
46
|
+
results.push(result);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return results;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function defaultHandler(): DeltaElement {
|
|
53
|
+
return {
|
|
54
|
+
type: "paragraph",
|
|
55
|
+
children: [],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BlockContent, InlineContent } from "@platecms/delta-cast";
|
|
2
|
+
import { flatten } from "lodash";
|
|
3
|
+
import { zwitch } from "zwitch";
|
|
4
|
+
import text from "../handlers/inlineContent/text";
|
|
5
|
+
import bold from "../handlers/inlineContent/bold";
|
|
6
|
+
import contentValue from "../handlers/inlineContent/contentValue";
|
|
7
|
+
import italic from "../handlers/inlineContent/italic";
|
|
8
|
+
import strikethrough from "../handlers/inlineContent/strikethrough";
|
|
9
|
+
import underline from "../handlers/inlineContent/underline";
|
|
10
|
+
import inlineCode from "../handlers/inlineContent/inlineCode";
|
|
11
|
+
import { DeltaElement, DeltaLeaf } from "@platecms/delta-client/slate";
|
|
12
|
+
import internalLink from "../handlers/inlineContent/internalLink";
|
|
13
|
+
import externalLink from "../handlers/inlineContent/externalLink";
|
|
14
|
+
|
|
15
|
+
const one = zwitch("type", {
|
|
16
|
+
handlers: { text, bold, italic, underline, contentValue, strikethrough, inlineCode, internalLink, externalLink },
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
18
|
+
unknown: (value: unknown, _: object = {}) => defaultHandler(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
function handleBlockContent(node: { type: BlockContent["type"]; children: InlineContent[] }): DeltaElement {
|
|
22
|
+
return {
|
|
23
|
+
type: node.type,
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
25
|
+
children: resolveCustomTextNodes(node.children),
|
|
26
|
+
} as unknown as DeltaElement;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function resolveCustomTextNodes(nodes: InlineContent[], state: Omit<DeltaLeaf, "text"> = {}): DeltaLeaf[] {
|
|
30
|
+
return flatten(nodes.map((node): DeltaLeaf[] => one(node, state)));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function defaultHandler(): DeltaLeaf[] {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { handleBlockContent, resolveCustomTextNodes };
|
package/src/index.js
DELETED
package/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/cast-util-to-slate/src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = blockquote;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function blockquote(node) {
|
|
6
|
-
return (0, handlers_1.handleBlockContent)(node);
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=blockquote.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blockquote.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/blockContent/blockquote.ts"],"names":[],"mappings":";;AAIA,6BAEC;AAJD,mDAA0D;AAE1D,SAAwB,UAAU,CAAC,IAAgB;IACjD,OAAO,IAAA,6BAAkB,EAAC,IAAI,CAAsB,CAAC;AACvD,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = code;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function code(node) {
|
|
6
|
-
return (0, handlers_1.handleBlockContent)(node);
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=code.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/blockContent/code.ts"],"names":[],"mappings":";;AAIA,uBAEC;AAJD,mDAA0D;AAE1D,SAAwB,IAAI,CAAC,IAAU;IACrC,OAAO,IAAA,6BAAkB,EAAC,IAA4C,CAAgB,CAAC;AACzF,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = heading;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function heading(node) {
|
|
6
|
-
return {
|
|
7
|
-
type: node.type,
|
|
8
|
-
level: node.level,
|
|
9
|
-
children: (0, handlers_1.resolveCustomTextNodes)(node.children),
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=heading.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"heading.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/blockContent/heading.ts"],"names":[],"mappings":";;AAIA,0BAMC;AATD,mDAA8D;AAG9D,SAAwB,OAAO,CAAC,IAAa;IAC3C,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,QAAQ,EAAE,IAAA,iCAAsB,EAAC,IAAI,CAAC,QAAQ,CAAC;KAChD,CAAC;AACJ,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = list;
|
|
4
|
-
const index_1 = require("./../../index");
|
|
5
|
-
function list(node) {
|
|
6
|
-
return {
|
|
7
|
-
type: node.type,
|
|
8
|
-
ordered: node.ordered,
|
|
9
|
-
children: (0, index_1.all)(node.children),
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=list.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/blockContent/list.ts"],"names":[],"mappings":";;AAIA,uBAMC;AARD,yCAAoC;AAEpC,SAAwB,IAAI,CAAC,IAAU;IACrC,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,QAAQ,EAAE,IAAA,WAAG,EAAC,IAAI,CAAC,QAAQ,CAAsB;KAClD,CAAC;AACJ,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = listItem;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function listItem(node) {
|
|
6
|
-
return {
|
|
7
|
-
type: node.type,
|
|
8
|
-
children: (0, handlers_1.resolveCustomTextNodes)(node.children),
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=listItem.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"listItem.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/blockContent/listItem.ts"],"names":[],"mappings":";;AAIA,2BAKC;AATD,mDAA8D;AAI9D,SAAwB,QAAQ,CAAC,IAAc;IAC7C,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,QAAQ,EAAE,IAAA,iCAAsB,EAAC,IAAI,CAAC,QAAQ,CAAC;KAChD,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = paragraph;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function paragraph(node) {
|
|
6
|
-
return (0, handlers_1.handleBlockContent)(node);
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=paragraph.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paragraph.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/blockContent/paragraph.ts"],"names":[],"mappings":";;AAIA,4BAEC;AALD,mDAA0D;AAG1D,SAAwB,SAAS,CAAC,IAAe;IAC/C,OAAO,IAAA,6BAAkB,EAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = bold;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function bold(node, state = {}) {
|
|
6
|
-
return (0, handlers_1.resolveCustomTextNodes)(node.children, {
|
|
7
|
-
...state,
|
|
8
|
-
bold: true,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=bold.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bold.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/inlineContent/bold.ts"],"names":[],"mappings":";;AAIA,uBAKC;AARD,mDAA8D;AAG9D,SAAwB,IAAI,CAAC,IAAU,EAAE,QAAiC,EAAE;IAC1E,OAAO,IAAA,iCAAsB,EAAC,IAAI,CAAC,QAAQ,EAAE;QAC3C,GAAG,KAAK;QACR,IAAI,EAAE,IAAI;KACX,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = contentValue;
|
|
4
|
-
function contentValue(node) {
|
|
5
|
-
return {
|
|
6
|
-
prn: node.prn,
|
|
7
|
-
type: "contentValue",
|
|
8
|
-
root: node.value,
|
|
9
|
-
children: [
|
|
10
|
-
{
|
|
11
|
-
text: "",
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=contentValue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contentValue.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/inlineContent/contentValue.ts"],"names":[],"mappings":";;AAGA,+BAWC;AAXD,SAAwB,YAAY,CAAC,IAA8B;IACjE,OAAO;QACL,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,IAAI,CAAC,KAAK;QAChB,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,EAAE;aACT;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = externalLink;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function externalLink(node) {
|
|
6
|
-
return {
|
|
7
|
-
type: "link",
|
|
8
|
-
url: node.url,
|
|
9
|
-
children: (0, handlers_1.resolveCustomTextNodes)(node.children),
|
|
10
|
-
target: node.target,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=externalLink.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"externalLink.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/inlineContent/externalLink.ts"],"names":[],"mappings":";;AAIA,+BAOC;AAVD,mDAA8D;AAG9D,SAAwB,YAAY,CAAC,IAAkB;IACrD,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,QAAQ,EAAE,IAAA,iCAAsB,EAAC,IAAI,CAAC,QAAQ,CAAC;QAC/C,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = highlight;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function highlight(node, state = {}) {
|
|
6
|
-
return (0, handlers_1.resolveCustomTextNodes)(node.children, {
|
|
7
|
-
...state,
|
|
8
|
-
highlight: true,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=highlight.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"highlight.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/inlineContent/highlight.ts"],"names":[],"mappings":";;AAIA,4BAKC;AARD,mDAA8D;AAG9D,SAAwB,SAAS,CAAC,IAAe,EAAE,QAAiC,EAAE;IACpF,OAAO,IAAA,iCAAsB,EAAC,IAAI,CAAC,QAAQ,EAAE;QAC3C,GAAG,KAAK;QACR,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = inlineCode;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function inlineCode(node, state = {}) {
|
|
6
|
-
return (0, handlers_1.resolveCustomTextNodes)([{ type: "text", value: node.value }], {
|
|
7
|
-
...state,
|
|
8
|
-
inlineCode: true,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=inlineCode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inlineCode.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/inlineContent/inlineCode.ts"],"names":[],"mappings":";;AAIA,6BAKC;AARD,mDAA8D;AAG9D,SAAwB,UAAU,CAAC,IAAgB,EAAE,QAAiC,EAAE;IACtF,OAAO,IAAA,iCAAsB,EAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE;QACnE,GAAG,KAAK;QACR,UAAU,EAAE,IAAI;KACjB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = internalLink;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
const delta_plate_resource_notation_1 = require("@platecms/delta-plate-resource-notation");
|
|
6
|
-
function isGridPlacementPrn(prn) {
|
|
7
|
-
try {
|
|
8
|
-
return delta_plate_resource_notation_1.PRN.fromString(prn).resourceType === "grid-placement";
|
|
9
|
-
}
|
|
10
|
-
catch (error) {
|
|
11
|
-
if (error instanceof delta_plate_resource_notation_1.InvalidPrnError) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
throw error;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function internalLink(node) {
|
|
18
|
-
return {
|
|
19
|
-
type: "link",
|
|
20
|
-
url: node.url,
|
|
21
|
-
children: (0, handlers_1.resolveCustomTextNodes)(node.children),
|
|
22
|
-
target: node.target,
|
|
23
|
-
internal: {
|
|
24
|
-
prn: node.prn,
|
|
25
|
-
anchor: isGridPlacementPrn(node.prn),
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=internalLink.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internalLink.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/inlineContent/internalLink.ts"],"names":[],"mappings":";;AAiBA,+BAWC;AA3BD,mDAA8D;AAE9D,2FAA+E;AAE/E,SAAS,kBAAkB,CAAC,GAAW;IACrC,IAAI,CAAC;QACH,OAAO,mCAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,YAAY,KAAK,gBAAgB,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,+CAAe,EAAE,CAAC;YACrC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAwB,YAAY,CAAC,IAAkB;IACrD,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,IAAI,CAAC,GAAI;QACd,QAAQ,EAAE,IAAA,iCAAsB,EAAC,IAAI,CAAC,QAAQ,CAAC;QAC/C,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,QAAQ,EAAE;YACR,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,MAAM,EAAE,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC;SACrC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = italic;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function italic(node, state = {}) {
|
|
6
|
-
return (0, handlers_1.resolveCustomTextNodes)(node.children, {
|
|
7
|
-
...state,
|
|
8
|
-
italic: true,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=italic.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"italic.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/inlineContent/italic.ts"],"names":[],"mappings":";;AAIA,yBAKC;AARD,mDAA8D;AAG9D,SAAwB,MAAM,CAAC,IAAY,EAAE,QAAiC,EAAE;IAC9E,OAAO,IAAA,iCAAsB,EAAC,IAAI,CAAC,QAAQ,EAAE;QAC3C,GAAG,KAAK;QACR,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = strikethrough;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function strikethrough(node, state = {}) {
|
|
6
|
-
return (0, handlers_1.resolveCustomTextNodes)(node.children, {
|
|
7
|
-
...state,
|
|
8
|
-
strikethrough: true,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=strikethrough.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strikethrough.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/inlineContent/strikethrough.ts"],"names":[],"mappings":";;AAIA,gCAKC;AARD,mDAA8D;AAG9D,SAAwB,aAAa,CAAC,IAAmB,EAAE,QAAiC,EAAE;IAC5F,OAAO,IAAA,iCAAsB,EAAC,IAAI,CAAC,QAAQ,EAAE;QAC3C,GAAG,KAAK;QACR,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/inlineContent/text.ts"],"names":[],"mappings":";;AAGA,uBAOC;AAPD,SAAwB,IAAI,CAAC,IAAU,EAAE,QAAiC,EAAE;IAC1E,OAAO;QACL;YACE,GAAG,KAAK;YACR,IAAI,EAAE,IAAI,CAAC,KAAK;SACjB;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = underline;
|
|
4
|
-
const handlers_1 = require("../../utils/handlers");
|
|
5
|
-
function underline(node, state = {}) {
|
|
6
|
-
return (0, handlers_1.resolveCustomTextNodes)(node.children, {
|
|
7
|
-
...state,
|
|
8
|
-
underline: true,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=underline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"underline.js","sourceRoot":"","sources":["../../../../../../../../packages/cast-util-to-slate/src/lib/handlers/inlineContent/underline.ts"],"names":[],"mappings":";;AAIA,4BAKC;AARD,mDAA8D;AAG9D,SAAwB,SAAS,CAAC,IAAe,EAAE,QAAiC,EAAE;IACpF,OAAO,IAAA,iCAAsB,EAAC,IAAI,CAAC,QAAQ,EAAE;QAC3C,GAAG,KAAK;QACR,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;AACL,CAAC"}
|
package/src/lib/index.d.ts
DELETED
package/src/lib/index.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toSlate = toSlate;
|
|
4
|
-
exports.all = all;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const zwitch_1 = require("zwitch");
|
|
7
|
-
const paragraph_1 = tslib_1.__importDefault(require("./handlers/blockContent/paragraph"));
|
|
8
|
-
const heading_1 = tslib_1.__importDefault(require("./handlers/blockContent/heading"));
|
|
9
|
-
const contentValue_1 = tslib_1.__importDefault(require("./handlers/inlineContent/contentValue"));
|
|
10
|
-
const list_1 = tslib_1.__importDefault(require("./handlers/blockContent/list"));
|
|
11
|
-
const listItem_1 = tslib_1.__importDefault(require("./handlers/blockContent/listItem"));
|
|
12
|
-
const code_1 = tslib_1.__importDefault(require("./handlers/blockContent/code"));
|
|
13
|
-
const blockquote_1 = tslib_1.__importDefault(require("./handlers/blockContent/blockquote"));
|
|
14
|
-
const highlight_1 = tslib_1.__importDefault(require("./handlers/inlineContent/highlight"));
|
|
15
|
-
const inlineCode_1 = tslib_1.__importDefault(require("./handlers/inlineContent/inlineCode"));
|
|
16
|
-
const externalLink_1 = tslib_1.__importDefault(require("./handlers/inlineContent/externalLink"));
|
|
17
|
-
const internalLink_1 = tslib_1.__importDefault(require("./handlers/inlineContent/internalLink"));
|
|
18
|
-
function toSlate(value) {
|
|
19
|
-
return all(value.children);
|
|
20
|
-
}
|
|
21
|
-
const one = (0, zwitch_1.zwitch)("type", {
|
|
22
|
-
handlers: {
|
|
23
|
-
paragraph: paragraph_1.default,
|
|
24
|
-
heading: heading_1.default,
|
|
25
|
-
contentValue: contentValue_1.default,
|
|
26
|
-
list: list_1.default,
|
|
27
|
-
listItem: listItem_1.default,
|
|
28
|
-
code: code_1.default,
|
|
29
|
-
blockquote: blockquote_1.default,
|
|
30
|
-
highlight: highlight_1.default,
|
|
31
|
-
inlineCode: inlineCode_1.default,
|
|
32
|
-
externalLink: externalLink_1.default,
|
|
33
|
-
internalLink: internalLink_1.default,
|
|
34
|
-
},
|
|
35
|
-
unknown: (_) => defaultHandler(),
|
|
36
|
-
});
|
|
37
|
-
function all(nodes) {
|
|
38
|
-
let index = -1;
|
|
39
|
-
const results = [];
|
|
40
|
-
while (++index < nodes.length) {
|
|
41
|
-
const result = one(nodes[index]);
|
|
42
|
-
results.push(result);
|
|
43
|
-
}
|
|
44
|
-
return results;
|
|
45
|
-
}
|
|
46
|
-
function defaultHandler() {
|
|
47
|
-
return {
|
|
48
|
-
type: "paragraph",
|
|
49
|
-
children: [],
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=index.js.map
|
package/src/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/cast-util-to-slate/src/lib/index.ts"],"names":[],"mappings":";;AAgBA,0BAGC;AAoBD,kBAUC;;AA/CD,mCAAgC;AAChC,0FAA0D;AAC1D,sFAAsD;AACtD,iGAAiE;AACjE,gFAAgD;AAChD,wFAAwD;AACxD,gFAAgD;AAChD,4FAA4D;AAC5D,2FAA2D;AAC3D,6FAA6D;AAC7D,iGAAiE;AAEjE,iGAAiE;AAEjE,SAAgB,OAAO,CAAC,KAAW;IAEjC,OAAO,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,GAAG,GAAG,IAAA,eAAM,EAAC,MAAM,EAAE;IACzB,QAAQ,EAAE;QACR,SAAS,EAAT,mBAAS;QACT,OAAO,EAAP,iBAAO;QACP,YAAY,EAAZ,sBAAY;QACZ,IAAI,EAAJ,cAAI;QACJ,QAAQ,EAAR,kBAAQ;QACR,IAAI,EAAJ,cAAI;QACJ,UAAU,EAAV,oBAAU;QACV,SAAS,EAAT,mBAAS;QACT,UAAU,EAAV,oBAAU;QACV,YAAY,EAAZ,sBAAY;QACZ,YAAY,EAAZ,sBAAY;KACb;IAED,OAAO,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,cAAc,EAAE;CAC1C,CAAC,CAAC;AAEH,SAAgB,GAAG,CAAC,KAAgB;IAClC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;IACf,MAAM,OAAO,GAAG,EAAE,CAAC;IAEnB,OAAO,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACjC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,cAAc;IACrB,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,QAAQ,EAAE,EAAE;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BlockContent, InlineContent } from "@platecms/delta-cast";
|
|
2
|
-
import { DeltaElement, DeltaLeaf } from "@platecms/delta-client/slate";
|
|
3
|
-
declare function handleBlockContent(node: {
|
|
4
|
-
type: BlockContent["type"];
|
|
5
|
-
children: InlineContent[];
|
|
6
|
-
}): DeltaElement;
|
|
7
|
-
declare function resolveCustomTextNodes(nodes: InlineContent[], state?: Omit<DeltaLeaf, "text">): DeltaLeaf[];
|
|
8
|
-
export { handleBlockContent, resolveCustomTextNodes };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleBlockContent = handleBlockContent;
|
|
4
|
-
exports.resolveCustomTextNodes = resolveCustomTextNodes;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const lodash_1 = require("lodash");
|
|
7
|
-
const zwitch_1 = require("zwitch");
|
|
8
|
-
const text_1 = tslib_1.__importDefault(require("../handlers/inlineContent/text"));
|
|
9
|
-
const bold_1 = tslib_1.__importDefault(require("../handlers/inlineContent/bold"));
|
|
10
|
-
const contentValue_1 = tslib_1.__importDefault(require("../handlers/inlineContent/contentValue"));
|
|
11
|
-
const italic_1 = tslib_1.__importDefault(require("../handlers/inlineContent/italic"));
|
|
12
|
-
const strikethrough_1 = tslib_1.__importDefault(require("../handlers/inlineContent/strikethrough"));
|
|
13
|
-
const underline_1 = tslib_1.__importDefault(require("../handlers/inlineContent/underline"));
|
|
14
|
-
const inlineCode_1 = tslib_1.__importDefault(require("../handlers/inlineContent/inlineCode"));
|
|
15
|
-
const internalLink_1 = tslib_1.__importDefault(require("../handlers/inlineContent/internalLink"));
|
|
16
|
-
const externalLink_1 = tslib_1.__importDefault(require("../handlers/inlineContent/externalLink"));
|
|
17
|
-
const one = (0, zwitch_1.zwitch)("type", {
|
|
18
|
-
handlers: { text: text_1.default, bold: bold_1.default, italic: italic_1.default, underline: underline_1.default, contentValue: contentValue_1.default, strikethrough: strikethrough_1.default, inlineCode: inlineCode_1.default, internalLink: internalLink_1.default, externalLink: externalLink_1.default },
|
|
19
|
-
unknown: (value, _ = {}) => defaultHandler(),
|
|
20
|
-
});
|
|
21
|
-
function handleBlockContent(node) {
|
|
22
|
-
return {
|
|
23
|
-
type: node.type,
|
|
24
|
-
children: resolveCustomTextNodes(node.children),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function resolveCustomTextNodes(nodes, state = {}) {
|
|
28
|
-
return (0, lodash_1.flatten)(nodes.map((node) => one(node, state)));
|
|
29
|
-
}
|
|
30
|
-
function defaultHandler() {
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=handlers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../../../../../../packages/cast-util-to-slate/src/lib/utils/handlers.ts"],"names":[],"mappings":";;AAoCS,gDAAkB;AAAE,wDAAsB;;AAnCnD,mCAAiC;AACjC,mCAAgC;AAChC,kFAAkD;AAClD,kFAAkD;AAClD,kGAAkE;AAClE,sFAAsD;AACtD,oGAAoE;AACpE,4FAA4D;AAC5D,8FAA8D;AAE9D,kGAAkE;AAClE,kGAAkE;AAElE,MAAM,GAAG,GAAG,IAAA,eAAM,EAAC,MAAM,EAAE;IACzB,QAAQ,EAAE,EAAE,IAAI,EAAJ,cAAI,EAAE,IAAI,EAAJ,cAAI,EAAE,MAAM,EAAN,gBAAM,EAAE,SAAS,EAAT,mBAAS,EAAE,YAAY,EAAZ,sBAAY,EAAE,aAAa,EAAb,uBAAa,EAAE,UAAU,EAAV,oBAAU,EAAE,YAAY,EAAZ,sBAAY,EAAE,YAAY,EAAZ,sBAAY,EAAE;IAEhH,OAAO,EAAE,CAAC,KAAc,EAAE,IAAY,EAAE,EAAE,EAAE,CAAC,cAAc,EAAE;CAC9D,CAAC,CAAC;AAEH,SAAS,kBAAkB,CAAC,IAA+D;IACzF,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QAEf,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC;KACrB,CAAC;AAC/B,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAsB,EAAE,QAAiC,EAAE;IACzF,OAAO,IAAA,gBAAO,EAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAe,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,cAAc;IACrB,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
File without changes
|