@kaitify/vue 0.0.1-beta.23 → 0.0.1-beta.24
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/lib/kaitify-vue.es.js +87 -86
- package/lib/kaitify-vue.umd.js +1 -1
- package/package.json +3 -3
package/lib/kaitify-vue.es.js
CHANGED
|
@@ -3184,12 +3184,10 @@ const onComposition = async function(e) {
|
|
|
3184
3184
|
const parentElement = element2.parentElement;
|
|
3185
3185
|
const parentNode = this.findNode(parentElement);
|
|
3186
3186
|
if (parentNode.isText() && parentNode.textContent != element2.textContent) {
|
|
3187
|
-
const textContent = parentNode.textContent || "";
|
|
3188
3187
|
parentNode.textContent = element2.textContent || "";
|
|
3189
3188
|
if (this.isSelectionInTargetNode(parentNode)) {
|
|
3190
3189
|
updateSelection$1.apply(this);
|
|
3191
3190
|
}
|
|
3192
|
-
element2.textContent = textContent;
|
|
3193
3191
|
await this.updateView();
|
|
3194
3192
|
} else if (!parentNode.isText()) {
|
|
3195
3193
|
const index = Array.from(parentElement.childNodes).findIndex((item) => item === element2);
|
|
@@ -3255,30 +3253,6 @@ const onCut = function(e) {
|
|
|
3255
3253
|
event2.preventDefault();
|
|
3256
3254
|
}
|
|
3257
3255
|
};
|
|
3258
|
-
const isLegalDom = (editor, dom) => {
|
|
3259
|
-
let legal = true;
|
|
3260
|
-
if (dom.nodeType == 3) {
|
|
3261
|
-
if (dom.parentNode && dom.parentNode.childNodes.length == 1) {
|
|
3262
|
-
try {
|
|
3263
|
-
const node = editor.findNode(dom.parentNode);
|
|
3264
|
-
if (!node.isText()) {
|
|
3265
|
-
legal = false;
|
|
3266
|
-
}
|
|
3267
|
-
} catch (error2) {
|
|
3268
|
-
legal = false;
|
|
3269
|
-
}
|
|
3270
|
-
} else {
|
|
3271
|
-
legal = false;
|
|
3272
|
-
}
|
|
3273
|
-
} else if (dom.nodeType == 1) {
|
|
3274
|
-
try {
|
|
3275
|
-
editor.findNode(dom);
|
|
3276
|
-
} catch (error2) {
|
|
3277
|
-
legal = false;
|
|
3278
|
-
}
|
|
3279
|
-
}
|
|
3280
|
-
return legal;
|
|
3281
|
-
};
|
|
3282
3256
|
const removeDomObserve = (editor) => {
|
|
3283
3257
|
if (editor.domObserver) {
|
|
3284
3258
|
editor.domObserver.disconnect();
|
|
@@ -3295,80 +3269,107 @@ const setDomObserve = (editor) => {
|
|
|
3295
3269
|
if (editor.isComposition) {
|
|
3296
3270
|
return;
|
|
3297
3271
|
}
|
|
3298
|
-
|
|
3299
|
-
const illegalDoms = [];
|
|
3272
|
+
const updateRecords = [];
|
|
3300
3273
|
for (let i = 0; i < mutationList.length; i++) {
|
|
3301
3274
|
const mutationRecord = mutationList[i];
|
|
3302
3275
|
if (mutationRecord.type == "characterData") {
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
} else if (!parentNode.isText()) {
|
|
3316
|
-
const index = Array.from(parentElement.childNodes).findIndex((item) => item === mutationRecord.target);
|
|
3317
|
-
const node = editor.domParseNode(mutationRecord.target);
|
|
3318
|
-
parentNode.children.splice(index, 0, node);
|
|
3319
|
-
node.parent = parentNode;
|
|
3320
|
-
illegalDoms.push(mutationRecord.target);
|
|
3321
|
-
if (editor.selection.focused()) {
|
|
3322
|
-
editor.setSelectionAfter(node, "all");
|
|
3323
|
-
}
|
|
3324
|
-
hasUpdate = true;
|
|
3276
|
+
if (!updateRecords.find((item) => item.type === "update" && item.elm === mutationRecord.target)) {
|
|
3277
|
+
updateRecords.push({
|
|
3278
|
+
type: "update",
|
|
3279
|
+
elm: mutationRecord.target
|
|
3280
|
+
});
|
|
3281
|
+
}
|
|
3282
|
+
} else if (mutationRecord.type == "attributes") {
|
|
3283
|
+
if (mutationRecord.target != editor.$el && !updateRecords.find((item) => item.type === "update" && item.elm === mutationRecord.target)) {
|
|
3284
|
+
updateRecords.push({
|
|
3285
|
+
type: "update",
|
|
3286
|
+
elm: mutationRecord.target
|
|
3287
|
+
});
|
|
3325
3288
|
}
|
|
3326
3289
|
} else if (mutationRecord.type == "childList") {
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3290
|
+
if (mutationRecord.addedNodes.length > 0) {
|
|
3291
|
+
mutationRecord.addedNodes.forEach((addNode) => {
|
|
3292
|
+
if (!updateRecords.find((item) => item.type === "add" && item.elm === addNode)) {
|
|
3293
|
+
updateRecords.push({
|
|
3294
|
+
type: "add",
|
|
3295
|
+
elm: addNode
|
|
3296
|
+
});
|
|
3297
|
+
}
|
|
3298
|
+
});
|
|
3299
|
+
}
|
|
3300
|
+
if (mutationRecord.removedNodes.length > 0) {
|
|
3301
|
+
mutationRecord.removedNodes.forEach((removedNode) => {
|
|
3302
|
+
const recordIndex = updateRecords.findIndex((item) => item.type === "add" && item.elm === removedNode);
|
|
3303
|
+
if (recordIndex > -1) {
|
|
3304
|
+
updateRecords.splice(recordIndex, 1);
|
|
3305
|
+
} else if (!updateRecords.find((item) => item.type === "remove" && item.elm === removedNode)) {
|
|
3306
|
+
updateRecords.push({
|
|
3307
|
+
type: "remove",
|
|
3308
|
+
elm: removedNode
|
|
3309
|
+
});
|
|
3310
|
+
}
|
|
3311
|
+
});
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
}
|
|
3315
|
+
if (updateRecords.length > 0) {
|
|
3316
|
+
updateRecords.forEach((record) => {
|
|
3317
|
+
if (record.type === "update") {
|
|
3318
|
+
const elm = record.elm.nodeType === 3 ? record.elm.parentNode : record.elm;
|
|
3319
|
+
const nodeKey = elm.getAttribute(NODE_MARK);
|
|
3320
|
+
const node = nodeKey ? KNode.searchByKey(nodeKey, editor.stackNodes) : null;
|
|
3321
|
+
if (node) {
|
|
3322
|
+
const newNode2 = editor.domParseNode(elm);
|
|
3323
|
+
editor.addNodeAfter(newNode2, node);
|
|
3324
|
+
if (editor.isSelectionInTargetNode(node, "start")) {
|
|
3325
|
+
editor.setSelectionAfter(newNode2, "start");
|
|
3326
|
+
}
|
|
3327
|
+
if (editor.isSelectionInTargetNode(node, "end")) {
|
|
3328
|
+
editor.setSelectionAfter(newNode2, "end");
|
|
3329
|
+
}
|
|
3330
|
+
const index = (node.parent ? node.parent.children : editor.stackNodes).findIndex((item) => item.isEqual(node));
|
|
3331
|
+
(node.parent ? node.parent.children : editor.stackNodes).splice(index, 1);
|
|
3332
|
+
}
|
|
3333
|
+
} else if (record.type === "add") {
|
|
3334
|
+
if (updateRecords.some((item) => item.type === "update" && (item.elm.nodeType === 3 ? item.elm.parentNode : item.elm).contains(record.elm))) {
|
|
3335
|
+
return;
|
|
3336
|
+
}
|
|
3337
|
+
const parentElement = record.elm.parentNode;
|
|
3338
|
+
const index = Array.from(parentElement.childNodes).findIndex((item) => item === record.elm);
|
|
3339
|
+
const node = editor.domParseNode(record.elm);
|
|
3330
3340
|
if (parentElement === editor.$el) {
|
|
3331
|
-
|
|
3332
|
-
const index = Array.from(parentElement.childNodes).findIndex((item) => item === el);
|
|
3333
|
-
const node = editor.domParseNode(el);
|
|
3334
|
-
editor.stackNodes.splice(index, 0, node);
|
|
3335
|
-
illegalDoms.push(el);
|
|
3336
|
-
if (editor.selection.focused()) {
|
|
3337
|
-
editor.setSelectionAfter(node, "all");
|
|
3338
|
-
}
|
|
3339
|
-
hasUpdate = true;
|
|
3340
|
-
});
|
|
3341
|
+
editor.stackNodes.splice(index, 0, node);
|
|
3341
3342
|
} else {
|
|
3342
|
-
const
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3343
|
+
const nodeKey = parentElement.getAttribute(NODE_MARK);
|
|
3344
|
+
const parentNode = nodeKey ? KNode.searchByKey(nodeKey, editor.stackNodes) : null;
|
|
3345
|
+
if (parentNode) editor.addNode(node, parentNode, index);
|
|
3346
|
+
}
|
|
3347
|
+
parentElement.removeChild(record.elm);
|
|
3348
|
+
} else if (record.type === "remove") {
|
|
3349
|
+
if (updateRecords.some((item) => item.type === "update" && (item.elm.nodeType === 3 ? item.elm.parentNode : item.elm).contains(record.elm))) {
|
|
3350
|
+
return;
|
|
3351
|
+
}
|
|
3352
|
+
const elm = record.elm.nodeType === 3 ? record.elm.parentNode : record.elm;
|
|
3353
|
+
const nodeKey = elm.getAttribute(NODE_MARK);
|
|
3354
|
+
const node = nodeKey ? KNode.searchByKey(nodeKey, editor.stackNodes) : null;
|
|
3355
|
+
if (node) {
|
|
3356
|
+
const startInNode = editor.isSelectionInTargetNode(node, "start");
|
|
3357
|
+
const endInNode = editor.isSelectionInTargetNode(node, "end");
|
|
3358
|
+
node.toEmpty();
|
|
3359
|
+
if (startInNode) {
|
|
3360
|
+
editor.updateSelectionRecently("start");
|
|
3361
|
+
}
|
|
3362
|
+
if (endInNode) {
|
|
3363
|
+
editor.updateSelectionRecently("end");
|
|
3364
|
+
}
|
|
3359
3365
|
}
|
|
3360
3366
|
}
|
|
3361
|
-
}
|
|
3362
|
-
}
|
|
3363
|
-
if (hasUpdate) {
|
|
3364
|
-
illegalDoms.forEach((item) => {
|
|
3365
|
-
item.remove();
|
|
3366
3367
|
});
|
|
3367
3368
|
editor.updateView();
|
|
3368
3369
|
}
|
|
3369
3370
|
});
|
|
3370
3371
|
editor.domObserver.observe(editor.$el, {
|
|
3371
|
-
attributes:
|
|
3372
|
+
attributes: true,
|
|
3372
3373
|
characterData: true,
|
|
3373
3374
|
characterDataOldValue: true,
|
|
3374
3375
|
childList: true,
|