@kaitify/core 0.0.1-beta.27 → 0.0.1-beta.28
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-core.es.js +137 -130
- package/lib/kaitify-core.umd.js +1 -1
- package/lib/model/Editor.d.ts +15 -0
- package/package.json +1 -1
- package/lib/model/config/dom-observe.d.ts +0 -10
package/lib/kaitify-core.es.js
CHANGED
|
@@ -3244,7 +3244,6 @@ const onComposition = async function(e) {
|
|
|
3244
3244
|
if (this.isSelectionInTargetNode(parentNode)) {
|
|
3245
3245
|
updateSelection$1.apply(this);
|
|
3246
3246
|
}
|
|
3247
|
-
await this.updateView();
|
|
3248
3247
|
} else if (!parentNode.isText()) {
|
|
3249
3248
|
const index = Array.from(parentElement.childNodes).findIndex((item) => item === element2);
|
|
3250
3249
|
const node = this.domParseNode(element2);
|
|
@@ -3254,10 +3253,9 @@ const onComposition = async function(e) {
|
|
|
3254
3253
|
if (this.selection.focused()) {
|
|
3255
3254
|
this.setSelectionAfter(node, "all");
|
|
3256
3255
|
}
|
|
3257
|
-
await this.updateView();
|
|
3258
3256
|
}
|
|
3259
3257
|
this.isComposition = false;
|
|
3260
|
-
|
|
3258
|
+
await this.updateView();
|
|
3261
3259
|
}
|
|
3262
3260
|
};
|
|
3263
3261
|
const onKeyboard = function(e) {
|
|
@@ -3309,129 +3307,6 @@ const onCut = function(e) {
|
|
|
3309
3307
|
event2.preventDefault();
|
|
3310
3308
|
}
|
|
3311
3309
|
};
|
|
3312
|
-
const removeDomObserve = (editor) => {
|
|
3313
|
-
if (editor.domObserver) {
|
|
3314
|
-
editor.domObserver.disconnect();
|
|
3315
|
-
editor.domObserver = null;
|
|
3316
|
-
}
|
|
3317
|
-
};
|
|
3318
|
-
const setDomObserve = (editor) => {
|
|
3319
|
-
if (!window.MutationObserver) {
|
|
3320
|
-
console.warn("The current browser does not support MutationObserver");
|
|
3321
|
-
return;
|
|
3322
|
-
}
|
|
3323
|
-
removeDomObserve(editor);
|
|
3324
|
-
editor.domObserver = new MutationObserver((mutationList) => {
|
|
3325
|
-
if (editor.isComposition) {
|
|
3326
|
-
return;
|
|
3327
|
-
}
|
|
3328
|
-
const updateRecords = [];
|
|
3329
|
-
for (let i = 0; i < mutationList.length; i++) {
|
|
3330
|
-
const mutationRecord = mutationList[i];
|
|
3331
|
-
if (mutationRecord.type == "characterData") {
|
|
3332
|
-
if (!updateRecords.find((item) => item.type === "update" && item.elm === mutationRecord.target)) {
|
|
3333
|
-
updateRecords.push({
|
|
3334
|
-
type: "update",
|
|
3335
|
-
elm: mutationRecord.target
|
|
3336
|
-
});
|
|
3337
|
-
}
|
|
3338
|
-
} else if (mutationRecord.type == "attributes") {
|
|
3339
|
-
if (mutationRecord.target != editor.$el && !updateRecords.find((item) => item.type === "update" && item.elm === mutationRecord.target)) {
|
|
3340
|
-
updateRecords.push({
|
|
3341
|
-
type: "update",
|
|
3342
|
-
elm: mutationRecord.target
|
|
3343
|
-
});
|
|
3344
|
-
}
|
|
3345
|
-
} else if (mutationRecord.type == "childList") {
|
|
3346
|
-
if (mutationRecord.addedNodes.length > 0) {
|
|
3347
|
-
mutationRecord.addedNodes.forEach((addNode) => {
|
|
3348
|
-
if (!updateRecords.find((item) => item.type === "add" && item.elm === addNode)) {
|
|
3349
|
-
updateRecords.push({
|
|
3350
|
-
type: "add",
|
|
3351
|
-
elm: addNode
|
|
3352
|
-
});
|
|
3353
|
-
}
|
|
3354
|
-
});
|
|
3355
|
-
}
|
|
3356
|
-
if (mutationRecord.removedNodes.length > 0) {
|
|
3357
|
-
mutationRecord.removedNodes.forEach((removedNode) => {
|
|
3358
|
-
const recordIndex = updateRecords.findIndex((item) => item.type === "add" && item.elm === removedNode);
|
|
3359
|
-
if (recordIndex > -1) {
|
|
3360
|
-
updateRecords.splice(recordIndex, 1);
|
|
3361
|
-
} else if (!updateRecords.find((item) => item.type === "remove" && item.elm === removedNode)) {
|
|
3362
|
-
updateRecords.push({
|
|
3363
|
-
type: "remove",
|
|
3364
|
-
elm: removedNode
|
|
3365
|
-
});
|
|
3366
|
-
}
|
|
3367
|
-
});
|
|
3368
|
-
}
|
|
3369
|
-
}
|
|
3370
|
-
}
|
|
3371
|
-
if (updateRecords.length > 0) {
|
|
3372
|
-
updateRecords.forEach((record) => {
|
|
3373
|
-
if (record.type === "update") {
|
|
3374
|
-
const elm = record.elm.nodeType === 3 ? record.elm.parentNode : record.elm;
|
|
3375
|
-
const nodeKey = elm.getAttribute(NODE_MARK);
|
|
3376
|
-
const node = nodeKey ? KNode.searchByKey(nodeKey, editor.stackNodes) : null;
|
|
3377
|
-
if (node) {
|
|
3378
|
-
const newNode2 = editor.domParseNode(elm);
|
|
3379
|
-
editor.addNodeAfter(newNode2, node);
|
|
3380
|
-
if (editor.isSelectionInTargetNode(node, "start")) {
|
|
3381
|
-
editor.setSelectionAfter(newNode2, "start");
|
|
3382
|
-
}
|
|
3383
|
-
if (editor.isSelectionInTargetNode(node, "end")) {
|
|
3384
|
-
editor.setSelectionAfter(newNode2, "end");
|
|
3385
|
-
}
|
|
3386
|
-
const index = (node.parent ? node.parent.children : editor.stackNodes).findIndex((item) => item.isEqual(node));
|
|
3387
|
-
(node.parent ? node.parent.children : editor.stackNodes).splice(index, 1);
|
|
3388
|
-
}
|
|
3389
|
-
} else if (record.type === "add") {
|
|
3390
|
-
if (updateRecords.some((item) => item.type === "update" && (item.elm.nodeType === 3 ? item.elm.parentNode : item.elm).contains(record.elm))) {
|
|
3391
|
-
return;
|
|
3392
|
-
}
|
|
3393
|
-
const parentElement = record.elm.parentNode;
|
|
3394
|
-
const index = Array.from(parentElement.childNodes).findIndex((item) => item === record.elm);
|
|
3395
|
-
const node = editor.domParseNode(record.elm);
|
|
3396
|
-
if (parentElement === editor.$el) {
|
|
3397
|
-
editor.stackNodes.splice(index, 0, node);
|
|
3398
|
-
} else {
|
|
3399
|
-
const nodeKey = parentElement.getAttribute(NODE_MARK);
|
|
3400
|
-
const parentNode = nodeKey ? KNode.searchByKey(nodeKey, editor.stackNodes) : null;
|
|
3401
|
-
if (parentNode) editor.addNode(node, parentNode, index);
|
|
3402
|
-
}
|
|
3403
|
-
parentElement.removeChild(record.elm);
|
|
3404
|
-
} else if (record.type === "remove") {
|
|
3405
|
-
if (updateRecords.some((item) => item.type === "update" && (item.elm.nodeType === 3 ? item.elm.parentNode : item.elm).contains(record.elm))) {
|
|
3406
|
-
return;
|
|
3407
|
-
}
|
|
3408
|
-
const elm = record.elm.nodeType === 3 ? record.elm.parentNode : record.elm;
|
|
3409
|
-
const nodeKey = elm.getAttribute(NODE_MARK);
|
|
3410
|
-
const node = nodeKey ? KNode.searchByKey(nodeKey, editor.stackNodes) : null;
|
|
3411
|
-
if (node) {
|
|
3412
|
-
const startInNode = editor.isSelectionInTargetNode(node, "start");
|
|
3413
|
-
const endInNode = editor.isSelectionInTargetNode(node, "end");
|
|
3414
|
-
node.toEmpty();
|
|
3415
|
-
if (startInNode) {
|
|
3416
|
-
editor.updateSelectionRecently("start");
|
|
3417
|
-
}
|
|
3418
|
-
if (endInNode) {
|
|
3419
|
-
editor.updateSelectionRecently("end");
|
|
3420
|
-
}
|
|
3421
|
-
}
|
|
3422
|
-
}
|
|
3423
|
-
});
|
|
3424
|
-
editor.updateView();
|
|
3425
|
-
}
|
|
3426
|
-
});
|
|
3427
|
-
editor.domObserver.observe(editor.$el, {
|
|
3428
|
-
attributes: true,
|
|
3429
|
-
characterData: true,
|
|
3430
|
-
characterDataOldValue: true,
|
|
3431
|
-
childList: true,
|
|
3432
|
-
subtree: true
|
|
3433
|
-
});
|
|
3434
|
-
};
|
|
3435
3310
|
class Extension {
|
|
3436
3311
|
constructor(name) {
|
|
3437
3312
|
/**
|
|
@@ -6208,6 +6083,7 @@ const imageResizable = (editor) => {
|
|
|
6208
6083
|
event$1.interaction.stop();
|
|
6209
6084
|
return;
|
|
6210
6085
|
}
|
|
6086
|
+
editor.removeDomObserve();
|
|
6211
6087
|
event.on(event$1.target, "dragstart", (e) => e.preventDefault());
|
|
6212
6088
|
const node = editor.findNode(event$1.target);
|
|
6213
6089
|
data.set(event$1.target, "node", node);
|
|
@@ -6376,6 +6252,7 @@ const videoResizable = (editor) => {
|
|
|
6376
6252
|
event$1.interaction.stop();
|
|
6377
6253
|
return;
|
|
6378
6254
|
}
|
|
6255
|
+
editor.removeDomObserve();
|
|
6379
6256
|
event.on(event$1.target, "dragstart", (e) => e.preventDefault());
|
|
6380
6257
|
const node = editor.findNode(event$1.target);
|
|
6381
6258
|
data.set(event$1.target, "node", node);
|
|
@@ -35941,6 +35818,7 @@ const tableResizable = (editor) => {
|
|
|
35941
35818
|
event$1.interaction.stop();
|
|
35942
35819
|
return;
|
|
35943
35820
|
}
|
|
35821
|
+
editor.removeDomObserve();
|
|
35944
35822
|
event.on(event$1.target, "dragstart", (e) => e.preventDefault());
|
|
35945
35823
|
const node = editor.findNode(event$1.target);
|
|
35946
35824
|
const index = node.parent.children.findIndex((item) => item.isEqual(node));
|
|
@@ -38209,10 +38087,10 @@ class Editor {
|
|
|
38209
38087
|
checkNodes.apply(this);
|
|
38210
38088
|
setPlaceholder.apply(this);
|
|
38211
38089
|
const oldHtml = this.$el.innerHTML;
|
|
38212
|
-
removeDomObserve(
|
|
38090
|
+
this.removeDomObserve();
|
|
38213
38091
|
const useDefault = typeof this.onUpdateView == "function" ? await this.onUpdateView.apply(this, [false]) : true;
|
|
38214
38092
|
useDefault && defaultUpdateView.apply(this, [false]);
|
|
38215
|
-
setDomObserve(
|
|
38093
|
+
this.setDomObserve();
|
|
38216
38094
|
const newHtml = this.$el.innerHTML;
|
|
38217
38095
|
if (oldHtml != newHtml) {
|
|
38218
38096
|
if (typeof this.onChange == "function") {
|
|
@@ -38276,10 +38154,10 @@ class Editor {
|
|
|
38276
38154
|
});
|
|
38277
38155
|
checkNodes.apply(this);
|
|
38278
38156
|
setPlaceholder.apply(this);
|
|
38279
|
-
removeDomObserve(
|
|
38157
|
+
this.removeDomObserve();
|
|
38280
38158
|
const useDefault = typeof this.onUpdateView == "function" ? await this.onUpdateView.apply(this, [true]) : true;
|
|
38281
38159
|
if (useDefault) defaultUpdateView.apply(this, [true]);
|
|
38282
|
-
setDomObserve(
|
|
38160
|
+
this.setDomObserve();
|
|
38283
38161
|
this.history.setState(this.stackNodes, this.selection);
|
|
38284
38162
|
this.oldStackNodes = this.stackNodes.map((item) => item.fullClone());
|
|
38285
38163
|
if (typeof this.afterUpdateView == "function") this.afterUpdateView.apply(this);
|
|
@@ -38366,6 +38244,135 @@ class Editor {
|
|
|
38366
38244
|
}
|
|
38367
38245
|
return true;
|
|
38368
38246
|
}
|
|
38247
|
+
/**
|
|
38248
|
+
* 移除对编辑器的dom监听
|
|
38249
|
+
*/
|
|
38250
|
+
removeDomObserve() {
|
|
38251
|
+
if (this.domObserver) {
|
|
38252
|
+
this.domObserver.disconnect();
|
|
38253
|
+
this.domObserver = null;
|
|
38254
|
+
}
|
|
38255
|
+
}
|
|
38256
|
+
/**
|
|
38257
|
+
* 设置对编辑器的dom监听,主要解决非法dom插入问题
|
|
38258
|
+
*/
|
|
38259
|
+
setDomObserve() {
|
|
38260
|
+
if (!window.MutationObserver) {
|
|
38261
|
+
console.warn("The current browser does not support MutationObserver");
|
|
38262
|
+
return;
|
|
38263
|
+
}
|
|
38264
|
+
this.removeDomObserve();
|
|
38265
|
+
this.domObserver = new MutationObserver((mutationList) => {
|
|
38266
|
+
if (this.isComposition) {
|
|
38267
|
+
return;
|
|
38268
|
+
}
|
|
38269
|
+
const updateRecords = [];
|
|
38270
|
+
for (let i = 0; i < mutationList.length; i++) {
|
|
38271
|
+
const mutationRecord = mutationList[i];
|
|
38272
|
+
if (mutationRecord.type == "characterData") {
|
|
38273
|
+
if (!updateRecords.find((item) => item.type === "update" && item.elm === mutationRecord.target)) {
|
|
38274
|
+
updateRecords.push({
|
|
38275
|
+
type: "update",
|
|
38276
|
+
elm: mutationRecord.target
|
|
38277
|
+
});
|
|
38278
|
+
}
|
|
38279
|
+
} else if (mutationRecord.type == "attributes") {
|
|
38280
|
+
if (mutationRecord.target != this.$el && !updateRecords.find((item) => item.type === "update" && item.elm === mutationRecord.target)) {
|
|
38281
|
+
updateRecords.push({
|
|
38282
|
+
type: "update",
|
|
38283
|
+
elm: mutationRecord.target
|
|
38284
|
+
});
|
|
38285
|
+
}
|
|
38286
|
+
} else if (mutationRecord.type == "childList") {
|
|
38287
|
+
if (mutationRecord.addedNodes.length > 0) {
|
|
38288
|
+
mutationRecord.addedNodes.forEach((addNode) => {
|
|
38289
|
+
if (!updateRecords.find((item) => item.type === "add" && item.elm === addNode)) {
|
|
38290
|
+
updateRecords.push({
|
|
38291
|
+
type: "add",
|
|
38292
|
+
elm: addNode
|
|
38293
|
+
});
|
|
38294
|
+
}
|
|
38295
|
+
});
|
|
38296
|
+
}
|
|
38297
|
+
if (mutationRecord.removedNodes.length > 0) {
|
|
38298
|
+
mutationRecord.removedNodes.forEach((removedNode) => {
|
|
38299
|
+
const recordIndex = updateRecords.findIndex((item) => item.type === "add" && item.elm === removedNode);
|
|
38300
|
+
if (recordIndex > -1) {
|
|
38301
|
+
updateRecords.splice(recordIndex, 1);
|
|
38302
|
+
} else if (!updateRecords.find((item) => item.type === "remove" && item.elm === removedNode)) {
|
|
38303
|
+
updateRecords.push({
|
|
38304
|
+
type: "remove",
|
|
38305
|
+
elm: removedNode
|
|
38306
|
+
});
|
|
38307
|
+
}
|
|
38308
|
+
});
|
|
38309
|
+
}
|
|
38310
|
+
}
|
|
38311
|
+
}
|
|
38312
|
+
if (updateRecords.length > 0) {
|
|
38313
|
+
updateRecords.forEach((record) => {
|
|
38314
|
+
if (record.type === "update") {
|
|
38315
|
+
const elm = record.elm.nodeType === 3 ? record.elm.parentNode : record.elm;
|
|
38316
|
+
const nodeKey = elm.getAttribute(NODE_MARK);
|
|
38317
|
+
const node = nodeKey ? KNode.searchByKey(nodeKey, this.stackNodes) : null;
|
|
38318
|
+
if (node) {
|
|
38319
|
+
const newNode2 = this.domParseNode(elm);
|
|
38320
|
+
this.addNodeAfter(newNode2, node);
|
|
38321
|
+
if (this.isSelectionInTargetNode(node, "start")) {
|
|
38322
|
+
this.setSelectionAfter(newNode2, "start");
|
|
38323
|
+
}
|
|
38324
|
+
if (this.isSelectionInTargetNode(node, "end")) {
|
|
38325
|
+
this.setSelectionAfter(newNode2, "end");
|
|
38326
|
+
}
|
|
38327
|
+
const index = (node.parent ? node.parent.children : this.stackNodes).findIndex((item) => item.isEqual(node));
|
|
38328
|
+
(node.parent ? node.parent.children : this.stackNodes).splice(index, 1);
|
|
38329
|
+
}
|
|
38330
|
+
} else if (record.type === "add") {
|
|
38331
|
+
if (updateRecords.some((item) => item.type === "update" && (item.elm.nodeType === 3 ? item.elm.parentNode : item.elm).contains(record.elm))) {
|
|
38332
|
+
return;
|
|
38333
|
+
}
|
|
38334
|
+
const parentElement = record.elm.parentNode;
|
|
38335
|
+
const index = Array.from(parentElement.childNodes).findIndex((item) => item === record.elm);
|
|
38336
|
+
const node = this.domParseNode(record.elm);
|
|
38337
|
+
if (parentElement === this.$el) {
|
|
38338
|
+
this.stackNodes.splice(index, 0, node);
|
|
38339
|
+
} else {
|
|
38340
|
+
const nodeKey = parentElement.getAttribute(NODE_MARK);
|
|
38341
|
+
const parentNode = nodeKey ? KNode.searchByKey(nodeKey, this.stackNodes) : null;
|
|
38342
|
+
if (parentNode) this.addNode(node, parentNode, index);
|
|
38343
|
+
}
|
|
38344
|
+
parentElement.removeChild(record.elm);
|
|
38345
|
+
} else if (record.type === "remove") {
|
|
38346
|
+
if (updateRecords.some((item) => item.type === "update" && (item.elm.nodeType === 3 ? item.elm.parentNode : item.elm).contains(record.elm))) {
|
|
38347
|
+
return;
|
|
38348
|
+
}
|
|
38349
|
+
const elm = record.elm.nodeType === 3 ? record.elm.parentNode : record.elm;
|
|
38350
|
+
const nodeKey = elm.getAttribute(NODE_MARK);
|
|
38351
|
+
const node = nodeKey ? KNode.searchByKey(nodeKey, this.stackNodes) : null;
|
|
38352
|
+
if (node) {
|
|
38353
|
+
const startInNode = this.isSelectionInTargetNode(node, "start");
|
|
38354
|
+
const endInNode = this.isSelectionInTargetNode(node, "end");
|
|
38355
|
+
node.toEmpty();
|
|
38356
|
+
if (startInNode) {
|
|
38357
|
+
this.updateSelectionRecently("start");
|
|
38358
|
+
}
|
|
38359
|
+
if (endInNode) {
|
|
38360
|
+
this.updateSelectionRecently("end");
|
|
38361
|
+
}
|
|
38362
|
+
}
|
|
38363
|
+
}
|
|
38364
|
+
});
|
|
38365
|
+
this.updateView();
|
|
38366
|
+
}
|
|
38367
|
+
});
|
|
38368
|
+
this.domObserver.observe(this.$el, {
|
|
38369
|
+
attributes: true,
|
|
38370
|
+
characterData: true,
|
|
38371
|
+
characterDataOldValue: true,
|
|
38372
|
+
childList: true,
|
|
38373
|
+
subtree: true
|
|
38374
|
+
});
|
|
38375
|
+
}
|
|
38369
38376
|
/**
|
|
38370
38377
|
* 配置编辑器,返回创建的编辑器
|
|
38371
38378
|
*/
|