@platecms/delta-cast-util-from-slate 1.16.0 → 1.17.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 +35 -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.17.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.17.0",
|
|
21
|
+
"@platecms/delta-castscript": "1.17.0",
|
|
22
|
+
"@platecms/delta-client": "1.17.0",
|
|
23
|
+
"@platecms/delta-plate-resource-notation": "1.17.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
|
@@ -282,6 +282,41 @@ describe("nested nodes", () => {
|
|
|
282
282
|
expect(result).toEqual(expected);
|
|
283
283
|
});
|
|
284
284
|
|
|
285
|
+
it("should convert a slate internalLink element to cast", () => {
|
|
286
|
+
// Arrange
|
|
287
|
+
const slate: Descendant[] = [
|
|
288
|
+
{
|
|
289
|
+
type: "link",
|
|
290
|
+
url: "https://www.asset-link.com",
|
|
291
|
+
children: [
|
|
292
|
+
{
|
|
293
|
+
text: "Asset link!",
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
internal: {
|
|
297
|
+
prn: "prn:content-value:asset",
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
];
|
|
301
|
+
|
|
302
|
+
const expected: Root = c("root", [
|
|
303
|
+
c(
|
|
304
|
+
"internalLink",
|
|
305
|
+
{
|
|
306
|
+
url: "https://www.asset-link.com",
|
|
307
|
+
prn: "prn:content-value:asset",
|
|
308
|
+
},
|
|
309
|
+
[c("text", "Asset link!")],
|
|
310
|
+
),
|
|
311
|
+
]);
|
|
312
|
+
|
|
313
|
+
// Act
|
|
314
|
+
const result = fromSlate(slate);
|
|
315
|
+
|
|
316
|
+
// Assert
|
|
317
|
+
expect(result).toEqual(expected);
|
|
318
|
+
});
|
|
319
|
+
|
|
285
320
|
it("should convert an internal link from slate to cast", () => {
|
|
286
321
|
// Arrange
|
|
287
322
|
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
|
};
|