@platecms/delta-cast-util-from-slate 1.2.0 → 1.4.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-from-slate",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Utility to convert slate nodes to a CAST tree.",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {
@@ -17,16 +17,15 @@
17
17
  "src/**/*"
18
18
  ],
19
19
  "dependencies": {
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",
20
+ "@platecms/delta-cast": "1.4.0",
21
+ "@platecms/delta-castscript": "1.4.0",
22
+ "@platecms/delta-client": "1.4.0",
23
+ "@platecms/delta-plate-resource-notation": "1.4.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",
@@ -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 slate to cast", () => {
155
- // Arrange
156
- const slate: Descendant[] = [
157
- {
158
- type: "contentValueSuggestion",
159
- prn: "prn:content-value:content-value",
160
- root: c("root", [c("paragraph", "Hello, world!")]),
161
- children: [
162
- {
163
- text: "",
164
- },
165
- ],
166
- },
167
- ];
168
-
169
- const expected: Root = c("root", [
170
- c("contentValue", {
171
- prn: "prn:content-value:content-value",
172
- value: c("root", [c("paragraph", "Hello, world!")]),
173
- }),
174
- ]);
175
-
176
- // Act
177
- const result = fromSlate(slate);
178
-
179
- // Assert
180
- expect(result).toEqual(expected);
181
- });
182
153
  });
183
154
 
184
155
  describe("nested nodes", () => {
package/src/lib/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Content, InlineContent, ListItem, Root, Text } from "@platecms/delta-cast";
1
+ import { CastSuggestion, Content, InlineContent, ListItem, Root, Text } from "@platecms/delta-cast";
2
2
  import { Descendant } from "slate";
3
3
  import { wrapNode } from "./utils/wrapNode";
4
4
  import { zwitch } from "zwitch";
@@ -6,13 +6,13 @@ import {
6
6
  BlockquoteElement,
7
7
  CodeElement,
8
8
  ContentValueElement,
9
- ContentValueSuggestionElement,
10
9
  DeltaLeaf,
11
10
  HeadingElement,
12
11
  LinkElement,
13
12
  ListElement,
14
13
  ListItemElement,
15
14
  ParagraphElement,
15
+ Suggestion,
16
16
  } from "@platecms/delta-client/slate";
17
17
  import { compact } from "../schema/lib/utils";
18
18
  export function fromSlate(value: Descendant[]): Root {
@@ -25,7 +25,7 @@ export function fromSlate(value: Descendant[]): Root {
25
25
 
26
26
  const handleNode = zwitch("type", {
27
27
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
28
- handlers: { paragraph, heading, list, listItem, blockquote, code, contentValue, contentValueSuggestion, link },
28
+ handlers: { paragraph, heading, list, listItem, blockquote, code, contentValue, link, suggestion },
29
29
  });
30
30
 
31
31
  function all(nodes: Descendant[], state: object = {}): Content[] {
@@ -128,27 +128,19 @@ function contentValue(node: ContentValueElement): Content {
128
128
  };
129
129
  }
130
130
 
131
- function contentValueSuggestion(node: ContentValueSuggestionElement): Content {
132
- const firstChild = node.children[0];
133
-
134
- if ("text" in firstChild) {
135
- return wrapNode(
136
- {
137
- ...firstChild,
138
- text: "",
139
- },
140
- {
141
- prn: node.prn,
142
- type: "contentValue",
143
- value: node.root,
144
- },
145
- );
146
- }
147
-
131
+ function suggestion(node: Suggestion): CastSuggestion {
148
132
  return {
149
- type: "contentValue",
150
- prn: node.prn,
151
- value: node.root,
133
+ type: "castSuggestion",
134
+ original: node.original,
135
+ suggested: {
136
+ prn: node.suggested.prn,
137
+ type: "contentValue",
138
+ value: node.suggested.root,
139
+ },
140
+ message: node.message,
141
+ method: node.method,
142
+ startIndex: node.startIndex,
143
+ endIndex: node.endIndex,
152
144
  };
153
145
  }
154
146