@platecms/delta-cast-util-from-slate 1.16.1 → 1.18.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 +5 -5
- package/src/lib/index.spec.ts +57 -0
- package/src/lib/index.ts +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platecms/delta-cast-util-from-slate",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
4
4
|
"description": "Utility to convert slate nodes to a CAST tree.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -17,10 +17,10 @@
|
|
|
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.18.0",
|
|
21
|
+
"@platecms/delta-castscript": "1.18.0",
|
|
22
|
+
"@platecms/delta-client": "1.18.0",
|
|
23
|
+
"@platecms/delta-plate-resource-notation": "1.18.0",
|
|
24
24
|
"@graphql-typed-document-node/core": "3.2.0",
|
|
25
25
|
"class-transformer": "0.5.1",
|
|
26
26
|
"graphql": "16.11.0",
|
package/src/lib/index.spec.ts
CHANGED
|
@@ -27,6 +27,28 @@ describe("single nodes", () => {
|
|
|
27
27
|
expect(result).toEqual(expected);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
it("should convert a soft return within a paragraph from slate to cast", () => {
|
|
31
|
+
// Arrange
|
|
32
|
+
const slate: Descendant[] = [
|
|
33
|
+
{
|
|
34
|
+
type: "paragraph",
|
|
35
|
+
children: [
|
|
36
|
+
{
|
|
37
|
+
text: "Line one\nLine two",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const expected: Root = c("root", [c("paragraph", "Line one\nLine two")]);
|
|
44
|
+
|
|
45
|
+
// Act
|
|
46
|
+
const result = fromSlate(slate);
|
|
47
|
+
|
|
48
|
+
// Assert
|
|
49
|
+
expect(result).toEqual(expected);
|
|
50
|
+
});
|
|
51
|
+
|
|
30
52
|
it("should convert a heading from slate to cast", () => {
|
|
31
53
|
// Arrange
|
|
32
54
|
const slate: Descendant[] = [
|
|
@@ -282,6 +304,41 @@ describe("nested nodes", () => {
|
|
|
282
304
|
expect(result).toEqual(expected);
|
|
283
305
|
});
|
|
284
306
|
|
|
307
|
+
it("should convert a slate internalLink element to cast", () => {
|
|
308
|
+
// Arrange
|
|
309
|
+
const slate: Descendant[] = [
|
|
310
|
+
{
|
|
311
|
+
type: "link",
|
|
312
|
+
url: "https://www.asset-link.com",
|
|
313
|
+
children: [
|
|
314
|
+
{
|
|
315
|
+
text: "Asset link!",
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
internal: {
|
|
319
|
+
prn: "prn:content-value:asset",
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
];
|
|
323
|
+
|
|
324
|
+
const expected: Root = c("root", [
|
|
325
|
+
c(
|
|
326
|
+
"internalLink",
|
|
327
|
+
{
|
|
328
|
+
url: "https://www.asset-link.com",
|
|
329
|
+
prn: "prn:content-value:asset",
|
|
330
|
+
},
|
|
331
|
+
[c("text", "Asset link!")],
|
|
332
|
+
),
|
|
333
|
+
]);
|
|
334
|
+
|
|
335
|
+
// Act
|
|
336
|
+
const result = fromSlate(slate);
|
|
337
|
+
|
|
338
|
+
// Assert
|
|
339
|
+
expect(result).toEqual(expected);
|
|
340
|
+
});
|
|
341
|
+
|
|
285
342
|
it("should convert an internal link from slate to cast", () => {
|
|
286
343
|
// Arrange
|
|
287
344
|
const slate: Descendant[] = [
|
package/src/lib/index.ts
CHANGED
|
@@ -170,9 +170,19 @@ function link(node: LinkElement, _: object = {}): Content {
|
|
|
170
170
|
};
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
if (node.prn !== undefined && node.prn !== null && node.prn.length > 0) {
|
|
174
|
+
return {
|
|
175
|
+
type: "internalLink",
|
|
176
|
+
prn: node.prn,
|
|
177
|
+
url: node.url,
|
|
178
|
+
target: node.target,
|
|
179
|
+
children: extractText(node.children),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
173
183
|
return {
|
|
174
184
|
type: "externalLink",
|
|
175
|
-
url: node.url,
|
|
185
|
+
url: node.url ?? "",
|
|
176
186
|
target: node.target,
|
|
177
187
|
children: extractText(node.children),
|
|
178
188
|
};
|