@use-kona/editor 0.1.9 → 0.1.11
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.
|
@@ -59,8 +59,9 @@ class ListsPlugin {
|
|
|
59
59
|
if (prevList) {
|
|
60
60
|
const currentDepth = this.getListDepth(editor, path);
|
|
61
61
|
const prevDepth = this.getListDepth(editor, prevList[1]);
|
|
62
|
-
if (this.isList(editor, prevList[0]) && currentDepth === prevDepth) try {
|
|
62
|
+
if (this.isList(editor, prevList[0]) && currentDepth === prevDepth && prevList[0].type === node.type) try {
|
|
63
63
|
Transforms.mergeNodes(editor, {
|
|
64
|
+
at: path,
|
|
64
65
|
match: (n)=>this.isList(editor, n)
|
|
65
66
|
});
|
|
66
67
|
} catch (e) {}
|
|
@@ -131,7 +132,7 @@ class ListsPlugin {
|
|
|
131
132
|
children: props.children
|
|
132
133
|
}),
|
|
133
134
|
serialize: (element, children)=>{
|
|
134
|
-
if (element.type === ListsPlugin.
|
|
135
|
+
if (element.type === ListsPlugin.LIST_ITEM_ELEMENT) return `<li>${children}</li>`;
|
|
135
136
|
},
|
|
136
137
|
deserialize: (element, children)=>{
|
|
137
138
|
const { nodeName } = element;
|
|
@@ -225,16 +226,26 @@ class ListsPlugin {
|
|
|
225
226
|
].includes(n.type)
|
|
226
227
|
});
|
|
227
228
|
else {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
const { selection } = editor;
|
|
230
|
+
if (!selection) return;
|
|
231
|
+
const nodes = Array.from(Editor.nodes(editor, {
|
|
232
|
+
at: Editor.unhangRange(editor, selection),
|
|
233
|
+
match: (n)=>Element.isElement(n),
|
|
234
|
+
mode: 'highest'
|
|
235
|
+
}));
|
|
236
|
+
if (!nodes.length) return;
|
|
233
237
|
Transforms.wrapNodes(editor, {
|
|
234
238
|
type: listType,
|
|
235
239
|
children: []
|
|
236
240
|
}, {
|
|
237
|
-
|
|
241
|
+
mode: 'highest',
|
|
242
|
+
match: (n)=>Element.isElement(n) && n.type === listItemType
|
|
243
|
+
});
|
|
244
|
+
Transforms.setNodes(editor, {
|
|
245
|
+
type: listItemType
|
|
246
|
+
}, {
|
|
247
|
+
at: nodes[0][1],
|
|
248
|
+
split: true
|
|
238
249
|
});
|
|
239
250
|
}
|
|
240
251
|
});
|
package/package.json
CHANGED
|
@@ -44,7 +44,7 @@ export class ListsPlugin implements IPlugin {
|
|
|
44
44
|
|
|
45
45
|
editor.normalizeNode = (entry: NodeEntry) => {
|
|
46
46
|
const [node, path] = entry;
|
|
47
|
-
|
|
47
|
+
//
|
|
48
48
|
if (this.isList(editor, node as CustomElement)) {
|
|
49
49
|
/* Unwrap lists around non-list-items */
|
|
50
50
|
for (const [child, childPath] of Array.from(
|
|
@@ -99,7 +99,7 @@ export class ListsPlugin implements IPlugin {
|
|
|
99
99
|
|
|
100
100
|
const prevList =
|
|
101
101
|
prevListItemPath &&
|
|
102
|
-
Editor.above(editor, {
|
|
102
|
+
Editor.above<CustomElement>(editor, {
|
|
103
103
|
at: prevListItemPath,
|
|
104
104
|
match: (n) => this.isList(editor, n as CustomElement),
|
|
105
105
|
});
|
|
@@ -110,10 +110,12 @@ export class ListsPlugin implements IPlugin {
|
|
|
110
110
|
|
|
111
111
|
if (
|
|
112
112
|
this.isList(editor, prevList[0] as CustomElement) &&
|
|
113
|
-
currentDepth === prevDepth
|
|
113
|
+
currentDepth === prevDepth &&
|
|
114
|
+
prevList[0].type === (node as CustomElement).type
|
|
114
115
|
) {
|
|
115
116
|
try {
|
|
116
117
|
Transforms.mergeNodes(editor, {
|
|
118
|
+
at: path,
|
|
117
119
|
match: (n) => this.isList(editor, n as CustomElement),
|
|
118
120
|
});
|
|
119
121
|
} catch (e) {}
|
|
@@ -218,7 +220,7 @@ export class ListsPlugin implements IPlugin {
|
|
|
218
220
|
);
|
|
219
221
|
},
|
|
220
222
|
serialize: (element, children) => {
|
|
221
|
-
if (element.type === ListsPlugin.
|
|
223
|
+
if (element.type === ListsPlugin.LIST_ITEM_ELEMENT) {
|
|
222
224
|
return `<li>${children}</li>`;
|
|
223
225
|
}
|
|
224
226
|
},
|
|
@@ -395,11 +397,39 @@ export class ListsPlugin implements IPlugin {
|
|
|
395
397
|
},
|
|
396
398
|
);
|
|
397
399
|
} else {
|
|
398
|
-
|
|
400
|
+
const { selection } = editor;
|
|
401
|
+
|
|
402
|
+
if (!selection) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const nodes = Array.from(
|
|
407
|
+
Editor.nodes(editor, {
|
|
408
|
+
at: Editor.unhangRange(editor, selection),
|
|
409
|
+
match: (n) => Element.isElement(n),
|
|
410
|
+
mode: 'highest',
|
|
411
|
+
}),
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
if (!nodes.length) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
|
|
399
418
|
Transforms.wrapNodes(
|
|
400
419
|
editor,
|
|
401
420
|
{ type: listType, children: [] },
|
|
402
|
-
{
|
|
421
|
+
{
|
|
422
|
+
mode: 'highest',
|
|
423
|
+
match: (n) => {
|
|
424
|
+
return Element.isElement(n) && n.type === listItemType;
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
Transforms.setNodes(
|
|
430
|
+
editor,
|
|
431
|
+
{ type: listItemType },
|
|
432
|
+
{ at: nodes[0][1], split: true },
|
|
403
433
|
);
|
|
404
434
|
}
|
|
405
435
|
});
|