vue-editify 0.1.23 → 0.1.25
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/examples/App.vue +1 -1
- package/lib/editify.es.js +101 -74
- package/lib/editify.umd.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/style.css +1 -1
- package/package.json +2 -2
- package/src/editify/editify.less +19 -17
- package/src/icon/iconfont.css +1 -1
- package/src/icon/iconfont.ttf +0 -0
- package/src/icon/iconfont.woff +0 -0
- package/src/index.ts +1 -1
- package/src/plugins/attachment/index.ts +40 -6
package/examples/App.vue
CHANGED
package/lib/editify.es.js
CHANGED
@@ -2466,73 +2466,6 @@ const breakFormat = function(element2) {
|
|
2466
2466
|
}
|
2467
2467
|
}
|
2468
2468
|
};
|
2469
|
-
const mergeWithParentElement = function(element2) {
|
2470
|
-
const canMerge = (parent, child) => {
|
2471
|
-
if (child.isText() && parent.isInline()) {
|
2472
|
-
return parent.parsedom == AlexElement.TEXT_NODE;
|
2473
|
-
}
|
2474
|
-
if (parent.isInline() && child.isInline() || parent.isInblock() && child.isInblock()) {
|
2475
|
-
return parent.parsedom == child.parsedom;
|
2476
|
-
}
|
2477
|
-
return false;
|
2478
|
-
};
|
2479
|
-
const merge = (parent, child) => {
|
2480
|
-
if (child.isText()) {
|
2481
|
-
parent.type = "text";
|
2482
|
-
parent.parsedom = null;
|
2483
|
-
if (child.hasMarks()) {
|
2484
|
-
if (parent.hasMarks()) {
|
2485
|
-
Object.assign(parent.marks, cloneData$1(child.marks));
|
2486
|
-
} else {
|
2487
|
-
parent.marks = cloneData$1(child.marks);
|
2488
|
-
}
|
2489
|
-
}
|
2490
|
-
if (child.hasStyles()) {
|
2491
|
-
if (parent.hasStyles()) {
|
2492
|
-
Object.assign(parent.styles, cloneData$1(child.styles));
|
2493
|
-
} else {
|
2494
|
-
parent.styles = cloneData$1(child.styles);
|
2495
|
-
}
|
2496
|
-
}
|
2497
|
-
parent.textContent = child.textContent;
|
2498
|
-
parent.children = null;
|
2499
|
-
if (this.range && child.isContains(this.range.anchor.element)) {
|
2500
|
-
this.range.anchor.element = parent;
|
2501
|
-
}
|
2502
|
-
if (this.range && child.isContains(this.range.focus.element)) {
|
2503
|
-
this.range.focus.element = parent;
|
2504
|
-
}
|
2505
|
-
} else {
|
2506
|
-
if (child.hasMarks()) {
|
2507
|
-
if (parent.hasMarks()) {
|
2508
|
-
Object.assign(parent.marks, cloneData$1(child.marks));
|
2509
|
-
} else {
|
2510
|
-
parent.marks = cloneData$1(child.marks);
|
2511
|
-
}
|
2512
|
-
}
|
2513
|
-
if (child.hasStyles()) {
|
2514
|
-
if (parent.hasStyles()) {
|
2515
|
-
Object.assign(parent.styles, cloneData$1(child.styles));
|
2516
|
-
} else {
|
2517
|
-
parent.styles = cloneData$1(child.styles);
|
2518
|
-
}
|
2519
|
-
}
|
2520
|
-
if (child.hasChildren()) {
|
2521
|
-
parent.children = [...child.children];
|
2522
|
-
parent.children.forEach((item) => {
|
2523
|
-
item.parent = parent;
|
2524
|
-
});
|
2525
|
-
}
|
2526
|
-
mergeElement(parent);
|
2527
|
-
}
|
2528
|
-
};
|
2529
|
-
const mergeElement = (ele) => {
|
2530
|
-
if (ele.hasChildren() && ele.children.length == 1 && ele.children[0] && canMerge(ele, ele.children[0])) {
|
2531
|
-
merge(ele, ele.children[0]);
|
2532
|
-
}
|
2533
|
-
};
|
2534
|
-
mergeElement(element2);
|
2535
|
-
};
|
2536
2469
|
const mergeWithBrotherElement = function(element2) {
|
2537
2470
|
const canMerge = (pel, nel) => {
|
2538
2471
|
if (pel.isEmpty() || nel.isEmpty()) {
|
@@ -2631,6 +2564,78 @@ const mergeWithBrotherElement = function(element2) {
|
|
2631
2564
|
};
|
2632
2565
|
mergeElement(element2);
|
2633
2566
|
};
|
2567
|
+
const mergeWithParentElement = function(element2) {
|
2568
|
+
const canMerge = (parent, child) => {
|
2569
|
+
if (child.isText() && parent.isInline()) {
|
2570
|
+
return parent.parsedom == AlexElement.TEXT_NODE;
|
2571
|
+
}
|
2572
|
+
if (parent.isInline() && child.isInline() || parent.isInblock() && child.isInblock()) {
|
2573
|
+
return parent.parsedom == child.parsedom;
|
2574
|
+
}
|
2575
|
+
return false;
|
2576
|
+
};
|
2577
|
+
const merge = (parent, child) => {
|
2578
|
+
if (child.isText()) {
|
2579
|
+
parent.type = "text";
|
2580
|
+
parent.parsedom = null;
|
2581
|
+
if (child.hasMarks()) {
|
2582
|
+
if (parent.hasMarks()) {
|
2583
|
+
Object.assign(parent.marks, cloneData$1(child.marks));
|
2584
|
+
} else {
|
2585
|
+
parent.marks = cloneData$1(child.marks);
|
2586
|
+
}
|
2587
|
+
}
|
2588
|
+
if (child.hasStyles()) {
|
2589
|
+
if (parent.hasStyles()) {
|
2590
|
+
Object.assign(parent.styles, cloneData$1(child.styles));
|
2591
|
+
} else {
|
2592
|
+
parent.styles = cloneData$1(child.styles);
|
2593
|
+
}
|
2594
|
+
}
|
2595
|
+
parent.textContent = child.textContent;
|
2596
|
+
parent.children = null;
|
2597
|
+
if (this.range && child.isContains(this.range.anchor.element)) {
|
2598
|
+
this.range.anchor.element = parent;
|
2599
|
+
}
|
2600
|
+
if (this.range && child.isContains(this.range.focus.element)) {
|
2601
|
+
this.range.focus.element = parent;
|
2602
|
+
}
|
2603
|
+
} else {
|
2604
|
+
if (child.hasMarks()) {
|
2605
|
+
if (parent.hasMarks()) {
|
2606
|
+
Object.assign(parent.marks, cloneData$1(child.marks));
|
2607
|
+
} else {
|
2608
|
+
parent.marks = cloneData$1(child.marks);
|
2609
|
+
}
|
2610
|
+
}
|
2611
|
+
if (child.hasStyles()) {
|
2612
|
+
if (parent.hasStyles()) {
|
2613
|
+
Object.assign(parent.styles, cloneData$1(child.styles));
|
2614
|
+
} else {
|
2615
|
+
parent.styles = cloneData$1(child.styles);
|
2616
|
+
}
|
2617
|
+
}
|
2618
|
+
if (child.hasChildren()) {
|
2619
|
+
parent.children = [...child.children];
|
2620
|
+
parent.children.forEach((item) => {
|
2621
|
+
item.parent = parent;
|
2622
|
+
});
|
2623
|
+
}
|
2624
|
+
mergeElement(parent);
|
2625
|
+
}
|
2626
|
+
};
|
2627
|
+
const mergeElement = (ele) => {
|
2628
|
+
if (ele.hasChildren() && ele.children.length == 1 && ele.children[0] && canMerge(ele, ele.children[0])) {
|
2629
|
+
merge(ele, ele.children[0]);
|
2630
|
+
}
|
2631
|
+
};
|
2632
|
+
mergeElement(element2);
|
2633
|
+
};
|
2634
|
+
const mergeWithSpaceTextElement = function(element2) {
|
2635
|
+
if (element2.isText()) {
|
2636
|
+
element2.textContent = element2.textContent.replace(/[\uFEFF]+/, "\uFEFF");
|
2637
|
+
}
|
2638
|
+
};
|
2634
2639
|
const { Mac } = platform.os();
|
2635
2640
|
const isUndo = function(e) {
|
2636
2641
|
if (Mac) {
|
@@ -3818,7 +3823,7 @@ class AlexEditor {
|
|
3818
3823
|
let renderRules = this.renderRules.filter((fn) => {
|
3819
3824
|
return typeof fn == "function";
|
3820
3825
|
});
|
3821
|
-
[handleNotStackBlock, handleInblockWithOther, handleInlineChildrenNotInblock, breakFormat, mergeWithParentElement, mergeWithBrotherElement, mergeWithParentElement, ...renderRules].forEach((fn) => {
|
3826
|
+
[handleNotStackBlock, handleInblockWithOther, handleInlineChildrenNotInblock, breakFormat, mergeWithParentElement, mergeWithBrotherElement, mergeWithParentElement, mergeWithSpaceTextElement, ...renderRules].forEach((fn) => {
|
3822
3827
|
format(this.stack, fn, true);
|
3823
3828
|
});
|
3824
3829
|
handleStackEmpty.apply(this);
|
@@ -26082,6 +26087,7 @@ const attachment = (options) => {
|
|
26082
26087
|
title: options.title || editTrans("insertAttachment"),
|
26083
26088
|
leftBorder: options.leftBorder,
|
26084
26089
|
rightBorder: options.rightBorder,
|
26090
|
+
disabled: editifyInstance.exposed.editor.value ? hasPreInRange(editifyInstance.exposed.editor.value, editifyInstance.exposed.dataRangeCaches.value) : false,
|
26085
26091
|
default: () => h(Icon, { value: "attachment" }),
|
26086
26092
|
layer: (_name, btnInstance) => h(InsertAttachment, {
|
26087
26093
|
color: color2,
|
@@ -26096,11 +26102,20 @@ const attachment = (options) => {
|
|
26096
26102
|
btnInstance.$refs.layerRef.setPosition();
|
26097
26103
|
},
|
26098
26104
|
onInsert: (url) => {
|
26099
|
-
const
|
26105
|
+
const marks = {
|
26106
|
+
"data-attachment": url,
|
26107
|
+
"data-attachment-name": editTrans("attachmentDownloadName"),
|
26108
|
+
contenteditable: "false"
|
26109
|
+
};
|
26110
|
+
const attachmentElement = new AlexElement("closed", "span", marks, null, null);
|
26100
26111
|
const editor = editifyInstance.exposed.editor.value;
|
26101
26112
|
editor.insertElement(attachmentElement);
|
26102
|
-
|
26103
|
-
|
26113
|
+
const beforeText = AlexElement.getSpaceElement();
|
26114
|
+
const afterText = AlexElement.getSpaceElement();
|
26115
|
+
editor.addElementAfter(afterText, attachmentElement);
|
26116
|
+
editor.addElementBefore(beforeText, attachmentElement);
|
26117
|
+
editor.range.anchor.moveToStart(afterText);
|
26118
|
+
editor.range.focus.moveToStart(afterText);
|
26104
26119
|
editor.formatElementStack();
|
26105
26120
|
editor.domRender();
|
26106
26121
|
editor.rangeRender();
|
@@ -26135,12 +26150,24 @@ const attachment = (options) => {
|
|
26135
26150
|
},
|
26136
26151
|
//span元素粘贴保留data-attachment
|
26137
26152
|
pasteKeepMarks: {
|
26138
|
-
"data-attachment": ["span"]
|
26153
|
+
"data-attachment": ["span"],
|
26154
|
+
"data-attachment-name": ["span"]
|
26139
26155
|
},
|
26140
|
-
|
26156
|
+
//自定义渲染规范
|
26141
26157
|
renderRule: (el) => {
|
26142
26158
|
if (el.type == "closed" && el.hasMarks() && el.marks["data-attachment"]) {
|
26143
26159
|
el.marks["title"] = editTrans("downloadAttachment");
|
26160
|
+
const editor = editifyInstance.exposed.editor.value;
|
26161
|
+
const previousElement = editor.getPreviousElement(el);
|
26162
|
+
const newTextElement = editor.getNextElement(el);
|
26163
|
+
if (!previousElement || !previousElement.isSpaceText()) {
|
26164
|
+
const spaceText = AlexElement.getSpaceElement();
|
26165
|
+
editor.addElementBefore(spaceText, el);
|
26166
|
+
}
|
26167
|
+
if (!newTextElement || !newTextElement.isSpaceText()) {
|
26168
|
+
const spaceText = AlexElement.getSpaceElement();
|
26169
|
+
editor.addElementAfter(spaceText, el);
|
26170
|
+
}
|
26144
26171
|
}
|
26145
26172
|
}
|
26146
26173
|
};
|
@@ -26150,7 +26177,7 @@ const attachment = (options) => {
|
|
26150
26177
|
const install = (app) => {
|
26151
26178
|
app.component(Editify.name, Editify);
|
26152
26179
|
};
|
26153
|
-
const version = "0.1.
|
26180
|
+
const version = "0.1.25";
|
26154
26181
|
export {
|
26155
26182
|
AlexElement,
|
26156
26183
|
Editify,
|