@platecms/delta-cast-util-from-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 +9 -7
- package/src/lib/index.spec.ts +29 -0
- package/src/lib/index.ts +26 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platecms/delta-cast-util-from-slate",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Utility to convert slate nodes to a CAST tree.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,20 +17,22 @@
|
|
|
17
17
|
"src/**/*"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@platecms/delta-cast": "
|
|
21
|
-
"@platecms/delta-castscript": "
|
|
22
|
-
"@platecms/delta-client": "
|
|
23
|
-
"@platecms/delta-plate-resource-notation": "
|
|
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
|
}
|
package/src/lib/index.spec.ts
CHANGED
|
@@ -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 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
|
+
});
|
|
153
182
|
});
|
|
154
183
|
|
|
155
184
|
describe("nested nodes", () => {
|
package/src/lib/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
BlockquoteElement,
|
|
7
7
|
CodeElement,
|
|
8
8
|
ContentValueElement,
|
|
9
|
+
ContentValueSuggestionElement,
|
|
9
10
|
DeltaLeaf,
|
|
10
11
|
HeadingElement,
|
|
11
12
|
LinkElement,
|
|
@@ -24,7 +25,7 @@ export function fromSlate(value: Descendant[]): Root {
|
|
|
24
25
|
|
|
25
26
|
const handleNode = zwitch("type", {
|
|
26
27
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
27
|
-
handlers: { paragraph, heading, list, listItem, blockquote, code, contentValue, link },
|
|
28
|
+
handlers: { paragraph, heading, list, listItem, blockquote, code, contentValue, contentValueSuggestion, link },
|
|
28
29
|
});
|
|
29
30
|
|
|
30
31
|
function all(nodes: Descendant[], state: object = {}): Content[] {
|
|
@@ -127,6 +128,30 @@ function contentValue(node: ContentValueElement): Content {
|
|
|
127
128
|
};
|
|
128
129
|
}
|
|
129
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
|
+
|
|
148
|
+
return {
|
|
149
|
+
type: "contentValue",
|
|
150
|
+
prn: node.prn,
|
|
151
|
+
value: node.root,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
130
155
|
function extractText(nodes: DeltaLeaf[]): Text[] {
|
|
131
156
|
return compact(
|
|
132
157
|
nodes.map((node) => {
|