@platecms/delta-cast-util-to-slate 1.2.0 → 1.3.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 +7 -7
- package/src/lib/handlers/inlineContent/castSuggestion.ts +25 -0
- package/src/lib/index.spec.ts +0 -29
- package/src/lib/index.ts +2 -4
- package/src/lib/utils/handlers.ts +2 -4
- package/src/lib/handlers/casSuggestion.ts +0 -17
- package/src/lib/handlers/inlineContent/contentValueSuggestion.ts +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platecms/delta-cast-util-to-slate",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Utility to convert CAST trees to Slate nodes.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,22 +17,22 @@
|
|
|
17
17
|
"src/**/*"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@platecms/delta-cast": "1.
|
|
21
|
-
"@platecms/delta-castscript": "1.
|
|
22
|
-
"@platecms/delta-client": "1.
|
|
23
|
-
"@platecms/delta-plate-resource-notation": "1.
|
|
20
|
+
"@platecms/delta-cast": "1.3.0",
|
|
21
|
+
"@platecms/delta-castscript": "1.3.0",
|
|
22
|
+
"@platecms/delta-client": "1.3.0",
|
|
23
|
+
"@platecms/delta-plate-resource-notation": "1.3.0",
|
|
24
24
|
"@graphql-typed-document-node/core": "3.2.0",
|
|
25
25
|
"class-transformer": "0.5.1",
|
|
26
26
|
"graphql": "16.11.0",
|
|
27
27
|
"reflect-metadata": "0.2.2",
|
|
28
28
|
"slate": "0.118.0",
|
|
29
|
-
"slate-react": "0.117.4",
|
|
30
29
|
"tslib": "2.8.1",
|
|
31
30
|
"zwitch": "2.0.4",
|
|
32
31
|
"@apollo/client": "3.13.9",
|
|
33
32
|
"defu": "6.1.4",
|
|
34
33
|
"axios": "1.11.0",
|
|
35
34
|
"uuid": "11.1.0",
|
|
36
|
-
"@faker-js/faker": "9.9.0"
|
|
35
|
+
"@faker-js/faker": "9.9.0",
|
|
36
|
+
"lodash": "4.17.21"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CastSuggestion } from "@platecms/delta-cast";
|
|
2
|
+
import { Suggestion } from "@platecms/delta-client/slate";
|
|
3
|
+
import { toPlaintext } from "@platecms/delta-cast-util-to-plaintext";
|
|
4
|
+
|
|
5
|
+
export default function castSuggestion(node: CastSuggestion): Suggestion {
|
|
6
|
+
return {
|
|
7
|
+
type: "suggestion",
|
|
8
|
+
original: node.original,
|
|
9
|
+
suggested: {
|
|
10
|
+
prn: node.suggested.prn,
|
|
11
|
+
type: "contentValue",
|
|
12
|
+
root: node.suggested.value,
|
|
13
|
+
children: [],
|
|
14
|
+
},
|
|
15
|
+
message: node.message,
|
|
16
|
+
method: node.method,
|
|
17
|
+
startIndex: node.startIndex,
|
|
18
|
+
endIndex: node.endIndex,
|
|
19
|
+
children: [
|
|
20
|
+
{
|
|
21
|
+
text: toPlaintext(node.original),
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
}
|
package/src/lib/index.spec.ts
CHANGED
|
@@ -150,35 +150,6 @@ describe("single nodes", () => {
|
|
|
150
150
|
// Assert
|
|
151
151
|
expect(result).toEqual(expected);
|
|
152
152
|
});
|
|
153
|
-
|
|
154
|
-
it("should convert a content value suggestion from cast to slate", () => {
|
|
155
|
-
// Arrange
|
|
156
|
-
const cast: Root = c("root", [
|
|
157
|
-
c("contentValueSuggestion", {
|
|
158
|
-
prn: "prn:content-value:content-value",
|
|
159
|
-
value: c("root", [c("paragraph", "Hello, world!")]),
|
|
160
|
-
}),
|
|
161
|
-
]);
|
|
162
|
-
|
|
163
|
-
const expected: Descendant[] = [
|
|
164
|
-
{
|
|
165
|
-
type: "contentValueSuggestion",
|
|
166
|
-
prn: "prn:content-value:content-value",
|
|
167
|
-
root: c("root", [c("paragraph", "Hello, world!")]),
|
|
168
|
-
children: [
|
|
169
|
-
{
|
|
170
|
-
text: "",
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
},
|
|
174
|
-
];
|
|
175
|
-
|
|
176
|
-
// Assert
|
|
177
|
-
const result = toSlate(cast);
|
|
178
|
-
|
|
179
|
-
// Assert
|
|
180
|
-
expect(result).toEqual(expected);
|
|
181
|
-
});
|
|
182
153
|
});
|
|
183
154
|
|
|
184
155
|
describe("nested nodes", () => {
|
package/src/lib/index.ts
CHANGED
|
@@ -13,8 +13,7 @@ import inlineCode from "./handlers/inlineContent/inlineCode";
|
|
|
13
13
|
import externalLink from "./handlers/inlineContent/externalLink";
|
|
14
14
|
import { DeltaElement } from "@platecms/delta-client/slate";
|
|
15
15
|
import internalLink from "./handlers/inlineContent/internalLink";
|
|
16
|
-
import
|
|
17
|
-
import contentValueSuggestion from "./handlers/inlineContent/contentValueSuggestion";
|
|
16
|
+
import castSuggestion from "./handlers/inlineContent/castSuggestion";
|
|
18
17
|
|
|
19
18
|
export function toSlate(value: Root): Descendant[] {
|
|
20
19
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
@@ -34,8 +33,7 @@ const one = zwitch("type", {
|
|
|
34
33
|
inlineCode,
|
|
35
34
|
externalLink,
|
|
36
35
|
internalLink,
|
|
37
|
-
|
|
38
|
-
contentValueSuggestion,
|
|
36
|
+
castSuggestion,
|
|
39
37
|
},
|
|
40
38
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
41
39
|
unknown: (_: unknown) => defaultHandler(),
|
|
@@ -10,8 +10,7 @@ import inlineCode from "../handlers/inlineContent/inlineCode";
|
|
|
10
10
|
import { DeltaElement, DeltaLeaf } from "@platecms/delta-client/slate";
|
|
11
11
|
import internalLink from "../handlers/inlineContent/internalLink";
|
|
12
12
|
import externalLink from "../handlers/inlineContent/externalLink";
|
|
13
|
-
import
|
|
14
|
-
import contentValueSuggestion from "../handlers/inlineContent/contentValueSuggestion";
|
|
13
|
+
import castSuggestion from "../handlers/inlineContent/castSuggestion";
|
|
15
14
|
|
|
16
15
|
const one = zwitch("type", {
|
|
17
16
|
handlers: {
|
|
@@ -24,8 +23,7 @@ const one = zwitch("type", {
|
|
|
24
23
|
inlineCode,
|
|
25
24
|
internalLink,
|
|
26
25
|
externalLink,
|
|
27
|
-
|
|
28
|
-
contentValueSuggestion,
|
|
26
|
+
castSuggestion,
|
|
29
27
|
},
|
|
30
28
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
31
29
|
unknown: (value: unknown, _: object = {}) => defaultHandler(),
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CasSuggestion } from "@platecms/delta-cast";
|
|
2
|
-
import { Suggestion } from "@platecms/delta-client/slate";
|
|
3
|
-
|
|
4
|
-
export default function casSuggestion(node: CasSuggestion): Suggestion {
|
|
5
|
-
return {
|
|
6
|
-
type: "suggestion",
|
|
7
|
-
original: node.original,
|
|
8
|
-
suggested: node.suggested,
|
|
9
|
-
message: node.message,
|
|
10
|
-
method: node.method,
|
|
11
|
-
children: [
|
|
12
|
-
{
|
|
13
|
-
text: "",
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ContentValueSuggestion } from "@platecms/delta-cast";
|
|
2
|
-
import { ContentValueSuggestionElement } from "@platecms/delta-client/slate";
|
|
3
|
-
|
|
4
|
-
export default function contentValueSuggestion(node: ContentValueSuggestion): ContentValueSuggestionElement {
|
|
5
|
-
return {
|
|
6
|
-
prn: node.prn,
|
|
7
|
-
type: "contentValueSuggestion",
|
|
8
|
-
root: node.value,
|
|
9
|
-
children: [
|
|
10
|
-
{
|
|
11
|
-
text: "",
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
};
|
|
15
|
-
}
|