@platecms/delta-cast-util-to-slate 0.13.0 → 1.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platecms/delta-cast-util-to-slate",
3
- "version": "0.13.0",
3
+ "version": "1.2.0",
4
4
  "description": "Utility to convert CAST trees to Slate nodes.",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {
@@ -17,20 +17,22 @@
17
17
  "src/**/*"
18
18
  ],
19
19
  "dependencies": {
20
- "@platecms/delta-cast": "0.13.0",
21
- "@platecms/delta-castscript": "0.13.0",
22
- "@platecms/delta-client": "0.13.0",
23
- "@platecms/delta-plate-resource-notation": "0.13.0",
20
+ "@platecms/delta-cast": "1.2.0",
21
+ "@platecms/delta-castscript": "1.2.0",
22
+ "@platecms/delta-client": "1.2.0",
23
+ "@platecms/delta-plate-resource-notation": "1.2.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
- "lodash": "4.17.21",
28
27
  "reflect-metadata": "0.2.2",
29
28
  "slate": "0.118.0",
30
29
  "slate-react": "0.117.4",
31
30
  "tslib": "2.8.1",
32
31
  "zwitch": "2.0.4",
33
32
  "@apollo/client": "3.13.9",
34
- "defu": "6.1.4"
33
+ "defu": "6.1.4",
34
+ "axios": "1.11.0",
35
+ "uuid": "11.1.0",
36
+ "@faker-js/faker": "9.9.0"
35
37
  }
36
38
  }
@@ -0,0 +1,17 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }
@@ -150,6 +150,35 @@ 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
+ });
153
182
  });
154
183
 
155
184
  describe("nested nodes", () => {
@@ -308,7 +337,7 @@ describe("nested nodes", () => {
308
337
  "internalLink",
309
338
  {
310
339
  url: "https://www.google.com#anchor-name",
311
- prn: "prn:text:org-id:cxc:grid-placement:1",
340
+ prn: "prn:text:org-id:cms:grid-placement:1",
312
341
  },
313
342
  [c("text", "Hello, world!")],
314
343
  ),
@@ -325,7 +354,7 @@ describe("nested nodes", () => {
325
354
  ],
326
355
  target: undefined,
327
356
  internal: {
328
- prn: "prn:text:org-id:cxc:grid-placement:1",
357
+ prn: "prn:text:org-id:cms:grid-placement:1",
329
358
  anchor: true,
330
359
  },
331
360
  },
package/src/lib/index.ts CHANGED
@@ -13,6 +13,8 @@ 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 casSuggestion from "./handlers/casSuggestion";
17
+ import contentValueSuggestion from "./handlers/inlineContent/contentValueSuggestion";
16
18
 
17
19
  export function toSlate(value: Root): Descendant[] {
18
20
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
@@ -32,6 +34,8 @@ const one = zwitch("type", {
32
34
  inlineCode,
33
35
  externalLink,
34
36
  internalLink,
37
+ casSuggestion,
38
+ contentValueSuggestion,
35
39
  },
36
40
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
37
41
  unknown: (_: unknown) => defaultHandler(),
@@ -10,9 +10,23 @@ 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 casSuggestion from "../handlers/casSuggestion";
14
+ import contentValueSuggestion from "../handlers/inlineContent/contentValueSuggestion";
13
15
 
14
16
  const one = zwitch("type", {
15
- handlers: { text, bold, italic, underline, contentValue, strikethrough, inlineCode, internalLink, externalLink },
17
+ handlers: {
18
+ text,
19
+ bold,
20
+ italic,
21
+ underline,
22
+ contentValue,
23
+ strikethrough,
24
+ inlineCode,
25
+ internalLink,
26
+ externalLink,
27
+ casSuggestion,
28
+ contentValueSuggestion,
29
+ },
16
30
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
17
31
  unknown: (value: unknown, _: object = {}) => defaultHandler(),
18
32
  });