vue-editify 0.0.17 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- package/examples/App.vue +6 -2
- package/lib/editify.es.js +519 -287
- package/lib/editify.umd.js +1 -1
- package/lib/style.css +1 -1
- package/package.json +3 -3
- package/src/Editify.vue +191 -94
- package/src/core/index.js +3 -0
- package/src/index.js +1 -1
package/lib/editify.es.js
CHANGED
@@ -186,10 +186,10 @@ const string$1 = {
|
|
186
186
|
},
|
187
187
|
/**
|
188
188
|
* 去除字符串空格
|
189
|
-
* @param {Object} str
|
189
|
+
* @param {Object} str 原始字符串
|
190
190
|
* @param {Object} global 为true时去除所有空格,否则只去除两边空格
|
191
191
|
*/
|
192
|
-
trim(str, global) {
|
192
|
+
trim(str, global = false) {
|
193
193
|
if (typeof str != "string") {
|
194
194
|
throw new TypeError("The first argument must be a string");
|
195
195
|
}
|
@@ -209,9 +209,9 @@ const element$1 = {
|
|
209
209
|
return data2 && data2 instanceof Window;
|
210
210
|
},
|
211
211
|
/**
|
212
|
-
*
|
212
|
+
* 获取元素距离某个定位祖先元素左侧/顶部/底部/右侧的距离
|
213
213
|
* @param {Object} el 元素
|
214
|
-
* @param {Object} root
|
214
|
+
* @param {Object} root 定位父元素或者祖先元素,未指定则为document.body
|
215
215
|
*/
|
216
216
|
getElementPoint(el, root) {
|
217
217
|
if (!this.isElement(el)) {
|
@@ -241,9 +241,9 @@ const element$1 = {
|
|
241
241
|
};
|
242
242
|
},
|
243
243
|
/**
|
244
|
-
*
|
245
|
-
* @param {Object} parentNode
|
246
|
-
* @param {Object} childNode
|
244
|
+
* 判断某个元素是否包含指定元素,包含相等关系和父子关系
|
245
|
+
* @param {Object} parentNode 父元素或祖先元素
|
246
|
+
* @param {Object} childNode 子元素
|
247
247
|
*/
|
248
248
|
isContains(parentNode, childNode) {
|
249
249
|
if (!this.isElement(parentNode)) {
|
@@ -263,9 +263,9 @@ const element$1 = {
|
|
263
263
|
}
|
264
264
|
},
|
265
265
|
/**
|
266
|
-
*
|
267
|
-
* @param {Object} parentNode
|
268
|
-
* @param {Object} childNode
|
266
|
+
* 判断某个元素是否是指定元素的父元素
|
267
|
+
* @param {Object} parentNode 父元素
|
268
|
+
* @param {Object} childNode 子元素
|
269
269
|
*/
|
270
270
|
isParentNode(parentNode, childNode) {
|
271
271
|
if (!this.isElement(parentNode)) {
|
@@ -280,8 +280,8 @@ const element$1 = {
|
|
280
280
|
return childNode.parentNode === parentNode;
|
281
281
|
},
|
282
282
|
/**
|
283
|
-
*
|
284
|
-
* @param {Object} el
|
283
|
+
* 查找某个元素下指定选择器的子元素
|
284
|
+
* @param {Object} el 元素
|
285
285
|
* @param {Object} selector 支持多选择器,等同于querySelectorAll的参数
|
286
286
|
*/
|
287
287
|
children(el, selector) {
|
@@ -297,8 +297,8 @@ const element$1 = {
|
|
297
297
|
});
|
298
298
|
},
|
299
299
|
/**
|
300
|
-
*
|
301
|
-
* @param {Object} el
|
300
|
+
* 查找某个元素下指定选择器的兄弟元素
|
301
|
+
* @param {Object} el 元素
|
302
302
|
* @param {Object} selector 取值等同于queryselectorAll的参数,支持多选择器
|
303
303
|
*/
|
304
304
|
siblings(el, selector) {
|
@@ -372,7 +372,7 @@ const element$1 = {
|
|
372
372
|
},
|
373
373
|
/**
|
374
374
|
* 移除class
|
375
|
-
* @param {Object} el
|
375
|
+
* @param {Object} el 元素
|
376
376
|
* @param {Object} className 支持多类,以空格划分
|
377
377
|
*/
|
378
378
|
removeClass(el, className) {
|
@@ -390,7 +390,7 @@ const element$1 = {
|
|
390
390
|
},
|
391
391
|
/**
|
392
392
|
* 添加class
|
393
|
-
* @param {Object} el
|
393
|
+
* @param {Object} el 元素
|
394
394
|
* @param {Object} className 支持多类,以空格划分
|
395
395
|
*/
|
396
396
|
addClass(el, className) {
|
@@ -408,7 +408,7 @@ const element$1 = {
|
|
408
408
|
},
|
409
409
|
/**
|
410
410
|
* 判断指定元素是否含有指定类名
|
411
|
-
* @param {Object} el
|
411
|
+
* @param {Object} el 元素
|
412
412
|
* @param {Object} className 支持多类,以空格划分
|
413
413
|
*/
|
414
414
|
hasClass(el, className) {
|
@@ -736,7 +736,7 @@ const element$1 = {
|
|
736
736
|
};
|
737
737
|
},
|
738
738
|
/**
|
739
|
-
*
|
739
|
+
* 判断是否是元素
|
740
740
|
* @param {Object} el
|
741
741
|
*/
|
742
742
|
isElement(el) {
|
@@ -755,7 +755,7 @@ const element$1 = {
|
|
755
755
|
if (parentEle.children.length == 1) {
|
756
756
|
return parentEle.children[0];
|
757
757
|
} else {
|
758
|
-
return parentEle.children;
|
758
|
+
return Array.from(parentEle.children);
|
759
759
|
}
|
760
760
|
}
|
761
761
|
};
|
@@ -810,7 +810,7 @@ const data$1 = {
|
|
810
810
|
}
|
811
811
|
},
|
812
812
|
/**
|
813
|
-
*
|
813
|
+
* 设置元素指定数据
|
814
814
|
* @param {Object} el
|
815
815
|
* @param {Object} key
|
816
816
|
* @param {Object} value
|
@@ -831,68 +831,74 @@ const common$1 = {
|
|
831
831
|
/**
|
832
832
|
* 常用判断
|
833
833
|
* @param {Object} text 要判断的字符串
|
834
|
-
* @param {Object}
|
834
|
+
* @param {Object} param 判断的类型字符串
|
835
835
|
*/
|
836
|
-
matchingText(text2,
|
836
|
+
matchingText(text2, param) {
|
837
837
|
if (!text2 || typeof text2 != "string") {
|
838
838
|
throw new TypeError("The first argument must be a string");
|
839
839
|
}
|
840
|
-
if (!
|
840
|
+
if (!param || typeof param != "string") {
|
841
841
|
throw new TypeError("The second argument must be a string");
|
842
842
|
}
|
843
843
|
let reg = null;
|
844
|
-
if (
|
844
|
+
if (param == "Chinese") {
|
845
845
|
reg = /^[\u4e00-\u9fa5]+$/;
|
846
846
|
}
|
847
|
-
if (
|
847
|
+
if (param == "chinese") {
|
848
848
|
reg = /[\u4e00-\u9fa5]/;
|
849
849
|
}
|
850
|
-
if (
|
850
|
+
if (param == "email") {
|
851
851
|
reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
|
852
852
|
}
|
853
|
-
if (
|
853
|
+
if (param == "username") {
|
854
854
|
reg = /^[a-zA-Z0-9_]{4,16}$/;
|
855
855
|
}
|
856
|
-
if (
|
856
|
+
if (param == "int+") {
|
857
857
|
reg = /^\d+$/;
|
858
858
|
}
|
859
|
-
if (
|
859
|
+
if (param == "int-") {
|
860
860
|
reg = /^-\d+$/;
|
861
861
|
}
|
862
|
-
if (
|
862
|
+
if (param == "int") {
|
863
863
|
reg = /^-?\d+$/;
|
864
864
|
}
|
865
|
-
if (
|
865
|
+
if (param == "pos") {
|
866
866
|
reg = /^\d*\.?\d+$/;
|
867
867
|
}
|
868
|
-
if (
|
868
|
+
if (param == "neg") {
|
869
869
|
reg = /^-\d*\.?\d+$/;
|
870
870
|
}
|
871
|
-
if (
|
871
|
+
if (param == "number") {
|
872
872
|
reg = /^-?\d*\.?\d+$/;
|
873
873
|
}
|
874
|
-
if (
|
874
|
+
if (param == "phone") {
|
875
875
|
reg = /^1[0-9]\d{9}$/;
|
876
876
|
}
|
877
|
-
if (
|
877
|
+
if (param == "idCard") {
|
878
878
|
reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
|
879
879
|
}
|
880
|
-
if (
|
881
|
-
reg = /^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([
|
880
|
+
if (param == "url") {
|
881
|
+
reg = /^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*\/?$/;
|
882
882
|
}
|
883
|
-
if (
|
883
|
+
if (param == "IPv4") {
|
884
884
|
reg = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
885
885
|
}
|
886
|
-
if (
|
886
|
+
if (param == "hex") {
|
887
887
|
reg = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
|
888
888
|
}
|
889
|
-
if (
|
889
|
+
if (param == "rgb") {
|
890
|
+
reg = /^rgb\((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d),\s?(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d),\s?(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\)$/;
|
891
|
+
}
|
892
|
+
if (param == "rgba") {
|
893
|
+
reg = /^rgba\((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d),\s?(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d),\s?(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d),\s?(0?\.\d|1(\.0)?|0)\)$/;
|
894
|
+
}
|
895
|
+
if (param == "QQ") {
|
890
896
|
reg = /^[1-9][0-9]{4,10}$/;
|
891
897
|
}
|
892
|
-
if (
|
898
|
+
if (param == "weixin") {
|
893
899
|
reg = /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/;
|
894
900
|
}
|
895
|
-
if (
|
901
|
+
if (param == "plate") {
|
896
902
|
reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/;
|
897
903
|
}
|
898
904
|
if (!reg) {
|
@@ -930,12 +936,10 @@ const common$1 = {
|
|
930
936
|
if (this.isObject(obj2)) {
|
931
937
|
if (Object.keys(obj2).length == 0) {
|
932
938
|
return true;
|
933
|
-
} else {
|
934
|
-
return false;
|
935
939
|
}
|
936
|
-
} else {
|
937
940
|
return false;
|
938
941
|
}
|
942
|
+
return false;
|
939
943
|
},
|
940
944
|
/**
|
941
945
|
* 判断两个参数是否相等
|
@@ -947,32 +951,25 @@ const common$1 = {
|
|
947
951
|
return false;
|
948
952
|
}
|
949
953
|
if (this.isObject(a) && this.isObject(b)) {
|
950
|
-
a = Object.assign({}, a);
|
951
|
-
b = Object.assign({}, b);
|
952
954
|
let aProps = Object.getOwnPropertyNames(a);
|
953
955
|
let bProps = Object.getOwnPropertyNames(b);
|
954
956
|
if (aProps.length != bProps.length) {
|
955
957
|
return false;
|
956
958
|
}
|
957
959
|
let length = aProps.length;
|
960
|
+
let isEqual = true;
|
958
961
|
for (let i = 0; i < length; i++) {
|
959
962
|
let propName = aProps[i];
|
960
963
|
let propA = a[propName];
|
961
964
|
let propB = b[propName];
|
962
|
-
if (this.
|
963
|
-
|
964
|
-
|
965
|
-
} else {
|
966
|
-
return false;
|
967
|
-
}
|
968
|
-
} else if (propA !== propB) {
|
969
|
-
return false;
|
965
|
+
if (!this.equal(propA, propB)) {
|
966
|
+
isEqual = false;
|
967
|
+
break;
|
970
968
|
}
|
971
969
|
}
|
972
|
-
return
|
973
|
-
} else {
|
974
|
-
return a === b;
|
970
|
+
return isEqual;
|
975
971
|
}
|
972
|
+
return a === b;
|
976
973
|
},
|
977
974
|
/**
|
978
975
|
* 是否对象
|
@@ -993,9 +990,28 @@ const common$1 = {
|
|
993
990
|
throw new TypeError("No text to copy is defined");
|
994
991
|
}
|
995
992
|
if (!navigator.clipboard) {
|
996
|
-
throw new Error("navigator.clipboard must be obtained in a secure environment, such as localhost, 127.0.0.1, or https, so the
|
993
|
+
throw new Error("navigator.clipboard must be obtained in a secure environment, such as localhost, 127.0.0.1, or https, so the method won't work");
|
997
994
|
}
|
998
995
|
return navigator.clipboard.writeText(text2);
|
996
|
+
},
|
997
|
+
/**
|
998
|
+
* 深度克隆
|
999
|
+
* @param {Object} data
|
1000
|
+
*/
|
1001
|
+
clone(data2) {
|
1002
|
+
if (this.isObject(data2)) {
|
1003
|
+
if (Array.isArray(data2)) {
|
1004
|
+
return data2.map((item) => {
|
1005
|
+
return this.clone(item);
|
1006
|
+
});
|
1007
|
+
}
|
1008
|
+
let newData = {};
|
1009
|
+
for (let key in data2) {
|
1010
|
+
newData[key] = this.clone(data2[key]);
|
1011
|
+
}
|
1012
|
+
return newData;
|
1013
|
+
}
|
1014
|
+
return data2;
|
999
1015
|
}
|
1000
1016
|
};
|
1001
1017
|
const parseEventName$1 = (eventName) => {
|
@@ -1503,9 +1519,11 @@ const platform$1 = {
|
|
1503
1519
|
Windows_Version: function() {
|
1504
1520
|
if (userAgent.includes("Windows NT 6.1") || userAgent.includes("Windows 7")) {
|
1505
1521
|
return "Win7";
|
1506
|
-
}
|
1522
|
+
}
|
1523
|
+
if (userAgent.includes("Windows NT 6.3") || userAgent.includes("Windows NT 6.2") || userAgent.includes("Windows NT 8")) {
|
1507
1524
|
return "Win8";
|
1508
|
-
}
|
1525
|
+
}
|
1526
|
+
if (userAgent.includes("Windows NT 10") || userAgent.includes("Windows NT 6.4")) {
|
1509
1527
|
return "Win10";
|
1510
1528
|
}
|
1511
1529
|
return "";
|
@@ -1868,6 +1886,37 @@ const initEditorOptions = (options) => {
|
|
1868
1886
|
}
|
1869
1887
|
return opts;
|
1870
1888
|
};
|
1889
|
+
const queryHasValue = (obj$1$1, name, value) => {
|
1890
|
+
if (value == null || value == void 0) {
|
1891
|
+
return obj$1$1.hasOwnProperty(name);
|
1892
|
+
}
|
1893
|
+
let ownValue = obj$1$1[name];
|
1894
|
+
if (ownValue == null || ownValue == void 0) {
|
1895
|
+
return false;
|
1896
|
+
}
|
1897
|
+
if (typeof value == "string") {
|
1898
|
+
value = value.toLocaleLowerCase();
|
1899
|
+
}
|
1900
|
+
if (typeof ownValue == "string") {
|
1901
|
+
ownValue = ownValue.toLocaleLowerCase();
|
1902
|
+
}
|
1903
|
+
if (typeof value == "string" && value && (obj$1.common.matchingText(value, "rgb") || obj$1.common.matchingText(value, "rgba"))) {
|
1904
|
+
value = obj$1.string.trim(value, true);
|
1905
|
+
}
|
1906
|
+
if (typeof ownValue == "string" && ownValue && (obj$1.common.matchingText(ownValue, "rgb") || obj$1.common.matchingText(ownValue, "rgba"))) {
|
1907
|
+
ownValue = obj$1.string.trim(ownValue, true);
|
1908
|
+
}
|
1909
|
+
if (typeof value == "string" && value && obj$1.common.matchingText(value, "hex")) {
|
1910
|
+
const arr = obj$1.color.hex2rgb(value);
|
1911
|
+
value = `rgb(${arr[0]},${arr[1]},${arr[2]})`;
|
1912
|
+
}
|
1913
|
+
if (typeof ownValue == "string" && ownValue && obj$1.common.matchingText(ownValue, "hex")) {
|
1914
|
+
const arr = obj$1.color.hex2rgb(ownValue);
|
1915
|
+
ownValue = `rgb(${arr[0]},${arr[1]},${arr[2]})`;
|
1916
|
+
}
|
1917
|
+
console.log(ownValue, value);
|
1918
|
+
return ownValue == value;
|
1919
|
+
};
|
1871
1920
|
const _AlexElement = class _AlexElement2 {
|
1872
1921
|
constructor(type, parsedom, marks, styles, textContent) {
|
1873
1922
|
this.key = createUniqueKey();
|
@@ -2267,6 +2316,12 @@ __publicField(_AlexElement, "BLOCK_NODE", "p");
|
|
2267
2316
|
__publicField(_AlexElement, "TEXT_NODE", "span");
|
2268
2317
|
__publicField(_AlexElement, "VOID_NODES", ["colgroup", "col"]);
|
2269
2318
|
let AlexElement = _AlexElement;
|
2319
|
+
class AlexRange {
|
2320
|
+
constructor(anchor, focus) {
|
2321
|
+
this.anchor = anchor;
|
2322
|
+
this.focus = focus;
|
2323
|
+
}
|
2324
|
+
}
|
2270
2325
|
class AlexPoint {
|
2271
2326
|
constructor(element2, offset) {
|
2272
2327
|
this.element = element2;
|
@@ -2358,12 +2413,6 @@ class AlexPoint {
|
|
2358
2413
|
}
|
2359
2414
|
}
|
2360
2415
|
}
|
2361
|
-
class AlexRange {
|
2362
|
-
constructor(anchor, focus) {
|
2363
|
-
this.anchor = anchor;
|
2364
|
-
this.focus = focus;
|
2365
|
-
}
|
2366
|
-
}
|
2367
2416
|
class AlexHistory {
|
2368
2417
|
constructor() {
|
2369
2418
|
this.records = [];
|
@@ -2379,15 +2428,7 @@ class AlexHistory {
|
|
2379
2428
|
const newStack = stack.map((ele) => {
|
2380
2429
|
return ele.__fullClone();
|
2381
2430
|
});
|
2382
|
-
const
|
2383
|
-
return ele.key == range.anchor.element.key;
|
2384
|
-
});
|
2385
|
-
const focusElement = AlexElement.flatElements(newStack).find((ele) => {
|
2386
|
-
return ele.key == range.focus.element.key;
|
2387
|
-
});
|
2388
|
-
const anchor = new AlexPoint(anchorElement, range.anchor.offset);
|
2389
|
-
const focus = new AlexPoint(focusElement, range.focus.offset);
|
2390
|
-
const newRange = new AlexRange(anchor, focus);
|
2431
|
+
const newRange = this.__cloneRange(newStack, range);
|
2391
2432
|
this.records.push({
|
2392
2433
|
stack: newStack,
|
2393
2434
|
range: newRange
|
@@ -2414,21 +2455,38 @@ class AlexHistory {
|
|
2414
2455
|
const newStack = stack.map((ele) => {
|
2415
2456
|
return ele.__fullClone();
|
2416
2457
|
});
|
2417
|
-
const
|
2418
|
-
return ele.key == range.anchor.element.key;
|
2419
|
-
});
|
2420
|
-
const focusElement = AlexElement.flatElements(newStack).find((ele) => {
|
2421
|
-
return ele.key == range.focus.element.key;
|
2422
|
-
});
|
2423
|
-
const anchor = new AlexPoint(anchorElement, range.anchor.offset);
|
2424
|
-
const focus = new AlexPoint(focusElement, range.focus.offset);
|
2425
|
-
const newRange = new AlexRange(anchor, focus);
|
2458
|
+
const newRange = this.__cloneRange(newStack, range);
|
2426
2459
|
return {
|
2427
2460
|
current,
|
2428
2461
|
stack: newStack,
|
2429
2462
|
range: newRange
|
2430
2463
|
};
|
2431
2464
|
}
|
2465
|
+
/**
|
2466
|
+
* 更新当前历史记录的range
|
2467
|
+
*/
|
2468
|
+
updateCurrentRange(range) {
|
2469
|
+
const records = this.records[this.current];
|
2470
|
+
const newRange = this.__cloneRange(records.stack, range);
|
2471
|
+
this.records[this.current].range = newRange;
|
2472
|
+
}
|
2473
|
+
/**
|
2474
|
+
* 克隆range
|
2475
|
+
*/
|
2476
|
+
__cloneRange(newStack, range) {
|
2477
|
+
if (range) {
|
2478
|
+
const anchorElement = AlexElement.flatElements(newStack).find((ele) => {
|
2479
|
+
return ele.key == range.anchor.element.key;
|
2480
|
+
});
|
2481
|
+
const focusElement = AlexElement.flatElements(newStack).find((ele) => {
|
2482
|
+
return ele.key == range.focus.element.key;
|
2483
|
+
});
|
2484
|
+
const anchor = new AlexPoint(anchorElement, range.anchor.offset);
|
2485
|
+
const focus = new AlexPoint(focusElement, range.focus.offset);
|
2486
|
+
return new AlexRange(anchor, focus);
|
2487
|
+
}
|
2488
|
+
return null;
|
2489
|
+
}
|
2432
2490
|
}
|
2433
2491
|
const blockParse = [
|
2434
2492
|
{
|
@@ -2670,10 +2728,10 @@ const breakFormat = function(element2) {
|
|
2670
2728
|
});
|
2671
2729
|
if (allIsBreak && children.length) {
|
2672
2730
|
const breakEl = children[0];
|
2673
|
-
if (element2.isContains(this.range.anchor.element)) {
|
2731
|
+
if (this.range && element2.isContains(this.range.anchor.element)) {
|
2674
2732
|
this.range.anchor.moveToStart(breakEl);
|
2675
2733
|
}
|
2676
|
-
if (element2.isContains(this.range.focus.element)) {
|
2734
|
+
if (this.range && element2.isContains(this.range.focus.element)) {
|
2677
2735
|
this.range.focus.moveToStart(breakEl);
|
2678
2736
|
}
|
2679
2737
|
element2.children = [breakEl];
|
@@ -2702,7 +2760,7 @@ const mergeWithBrotherElement = function(element2) {
|
|
2702
2760
|
const merge = (pel, nel) => {
|
2703
2761
|
if (pel.isEmpty() || nel.isEmpty()) {
|
2704
2762
|
if (nel.isEmpty()) {
|
2705
|
-
if (nel.isContains(this.range.anchor.element)) {
|
2763
|
+
if (this.range && nel.isContains(this.range.anchor.element)) {
|
2706
2764
|
if (pel.isEmpty()) {
|
2707
2765
|
this.range.anchor.element = pel;
|
2708
2766
|
this.range.anchor.offset = 0;
|
@@ -2710,7 +2768,7 @@ const mergeWithBrotherElement = function(element2) {
|
|
2710
2768
|
this.range.anchor.moveToEnd(pel);
|
2711
2769
|
}
|
2712
2770
|
}
|
2713
|
-
if (nel.isContains(this.range.focus.element)) {
|
2771
|
+
if (this.range && nel.isContains(this.range.focus.element)) {
|
2714
2772
|
if (pel.isEmpty()) {
|
2715
2773
|
this.range.focus.element = pel;
|
2716
2774
|
this.range.focus.offset = 0;
|
@@ -2723,7 +2781,7 @@ const mergeWithBrotherElement = function(element2) {
|
|
2723
2781
|
});
|
2724
2782
|
nel.parent.children.splice(index, 1);
|
2725
2783
|
} else if (pel.isEmpty()) {
|
2726
|
-
if (pel.isContains(this.range.anchor.element)) {
|
2784
|
+
if (this.range && pel.isContains(this.range.anchor.element)) {
|
2727
2785
|
if (nel.isEmpty()) {
|
2728
2786
|
this.range.anchor.element = nel;
|
2729
2787
|
this.range.anchor.offset = 0;
|
@@ -2731,7 +2789,7 @@ const mergeWithBrotherElement = function(element2) {
|
|
2731
2789
|
this.range.anchor.moveToStart(nel);
|
2732
2790
|
}
|
2733
2791
|
}
|
2734
|
-
if (pel.isContains(this.range.focus.element)) {
|
2792
|
+
if (this.range && pel.isContains(this.range.focus.element)) {
|
2735
2793
|
if (nel.isEmpty()) {
|
2736
2794
|
this.range.focus.element = nel;
|
2737
2795
|
this.range.focus.offset = 0;
|
@@ -2745,11 +2803,11 @@ const mergeWithBrotherElement = function(element2) {
|
|
2745
2803
|
pel.parent.children.splice(index, 1);
|
2746
2804
|
}
|
2747
2805
|
} else if (pel.isText()) {
|
2748
|
-
if (nel.isEqual(this.range.anchor.element)) {
|
2806
|
+
if (this.range && nel.isEqual(this.range.anchor.element)) {
|
2749
2807
|
this.range.anchor.element = pel;
|
2750
2808
|
this.range.anchor.offset = pel.textContent.length + this.range.anchor.offset;
|
2751
2809
|
}
|
2752
|
-
if (nel.isEqual(this.range.focus.element)) {
|
2810
|
+
if (this.range && nel.isEqual(this.range.focus.element)) {
|
2753
2811
|
this.range.focus.element = pel;
|
2754
2812
|
this.range.focus.offset = pel.textContent.length + this.range.focus.offset;
|
2755
2813
|
}
|
@@ -2814,10 +2872,10 @@ const mergeWithParentElement = function(element2) {
|
|
2814
2872
|
}
|
2815
2873
|
parent.textContent = child.textContent;
|
2816
2874
|
parent.children = null;
|
2817
|
-
if (child.isContains(this.range.anchor.element)) {
|
2875
|
+
if (this.range && child.isContains(this.range.anchor.element)) {
|
2818
2876
|
this.range.anchor.element = parent;
|
2819
2877
|
}
|
2820
|
-
if (child.isContains(this.range.focus.element)) {
|
2878
|
+
if (this.range && child.isContains(this.range.focus.element)) {
|
2821
2879
|
this.range.focus.element = parent;
|
2822
2880
|
}
|
2823
2881
|
} else {
|
@@ -2869,14 +2927,6 @@ const checkStack = function() {
|
|
2869
2927
|
const breakEle = new AlexElement("closed", "br", null, null, null);
|
2870
2928
|
this.addElementTo(breakEle, ele);
|
2871
2929
|
this.stack = [ele];
|
2872
|
-
const anchor = new AlexPoint(breakEle, 0);
|
2873
|
-
const focus = new AlexPoint(breakEle, 0);
|
2874
|
-
this.range = new AlexRange(anchor, focus);
|
2875
|
-
} else {
|
2876
|
-
const firstElement = elements[0];
|
2877
|
-
const anchor = new AlexPoint(firstElement, 0);
|
2878
|
-
const focus = new AlexPoint(firstElement, 0);
|
2879
|
-
this.range = new AlexRange(anchor, focus);
|
2880
2930
|
}
|
2881
2931
|
};
|
2882
2932
|
const setRecentlyPoint = function(point) {
|
@@ -2935,7 +2985,7 @@ const setRangeInVisible = function() {
|
|
2935
2985
|
}
|
2936
2986
|
const childRect = target.getBoundingClientRect();
|
2937
2987
|
const parentRect = root2.getBoundingClientRect();
|
2938
|
-
if (childRect.top < parentRect.top
|
2988
|
+
if (childRect.top < parentRect.top) {
|
2939
2989
|
await obj$1.element.setScrollTop({
|
2940
2990
|
el: root2,
|
2941
2991
|
number: 0
|
@@ -2946,7 +2996,7 @@ const setRangeInVisible = function() {
|
|
2946
2996
|
el: root2,
|
2947
2997
|
number: tempChildRect.top - tempParentRect.top - tempChildRect.height * 2
|
2948
2998
|
});
|
2949
|
-
} else if (childRect.bottom > parentRect.bottom
|
2999
|
+
} else if (childRect.bottom > parentRect.bottom) {
|
2950
3000
|
await obj$1.element.setScrollTop({
|
2951
3001
|
el: root2,
|
2952
3002
|
number: 0
|
@@ -3034,8 +3084,12 @@ const handleSelectionChange = function() {
|
|
3034
3084
|
const focusEle = this.getElementByKey(focusKey);
|
3035
3085
|
const anchor = new AlexPoint(anchorEle, anchorOffset);
|
3036
3086
|
const focus = new AlexPoint(focusEle, focusOffset);
|
3037
|
-
this.range
|
3038
|
-
|
3087
|
+
if (this.range) {
|
3088
|
+
this.range.anchor = anchor;
|
3089
|
+
this.range.focus = focus;
|
3090
|
+
} else {
|
3091
|
+
this.range = new AlexRange(anchor, focus);
|
3092
|
+
}
|
3039
3093
|
this.emit("rangeUpdate", this.range);
|
3040
3094
|
}
|
3041
3095
|
}
|
@@ -3197,6 +3251,18 @@ class AlexEditor {
|
|
3197
3251
|
obj$1.event.on(this.$el, "focus.alex_editor", handleFocus.bind(this));
|
3198
3252
|
obj$1.event.on(this.$el, "blur.alex_editor", handleBlur.bind(this));
|
3199
3253
|
}
|
3254
|
+
/**
|
3255
|
+
* 初始化range
|
3256
|
+
*/
|
3257
|
+
initRange() {
|
3258
|
+
const elements = AlexElement.flatElements(this.stack).filter((el) => {
|
3259
|
+
return !el.isEmpty() && !AlexElement.VOID_NODES.includes(el.parsedom);
|
3260
|
+
});
|
3261
|
+
const firstElement = elements[0];
|
3262
|
+
const anchor = new AlexPoint(firstElement, 0);
|
3263
|
+
const focus = new AlexPoint(firstElement, 0);
|
3264
|
+
this.range = new AlexRange(anchor, focus);
|
3265
|
+
}
|
3200
3266
|
/**
|
3201
3267
|
* 根据光标进行粘贴操作
|
3202
3268
|
*/
|
@@ -3204,6 +3270,9 @@ class AlexEditor {
|
|
3204
3270
|
if (this.disabled) {
|
3205
3271
|
return;
|
3206
3272
|
}
|
3273
|
+
if (!this.range) {
|
3274
|
+
return;
|
3275
|
+
}
|
3207
3276
|
if (!this.useClipboard) {
|
3208
3277
|
return;
|
3209
3278
|
}
|
@@ -3310,6 +3379,9 @@ class AlexEditor {
|
|
3310
3379
|
if (!this.useClipboard) {
|
3311
3380
|
return;
|
3312
3381
|
}
|
3382
|
+
if (!this.range) {
|
3383
|
+
return;
|
3384
|
+
}
|
3313
3385
|
if (!this.allowCut) {
|
3314
3386
|
return;
|
3315
3387
|
}
|
@@ -3330,6 +3402,9 @@ class AlexEditor {
|
|
3330
3402
|
if (!this.useClipboard) {
|
3331
3403
|
return;
|
3332
3404
|
}
|
3405
|
+
if (!this.range) {
|
3406
|
+
return;
|
3407
|
+
}
|
3333
3408
|
if (!this.allowCopy) {
|
3334
3409
|
return;
|
3335
3410
|
}
|
@@ -3365,6 +3440,9 @@ class AlexEditor {
|
|
3365
3440
|
if (this.disabled) {
|
3366
3441
|
return;
|
3367
3442
|
}
|
3443
|
+
if (!this.range) {
|
3444
|
+
return;
|
3445
|
+
}
|
3368
3446
|
if (this.range.anchor.isEqual(this.range.focus)) {
|
3369
3447
|
const previousElement = this.getPreviousElementOfPoint(this.range.anchor);
|
3370
3448
|
const block = this.range.anchor.element.getBlock();
|
@@ -3631,6 +3709,9 @@ class AlexEditor {
|
|
3631
3709
|
if (!data2 || typeof data2 != "string") {
|
3632
3710
|
throw new Error("The argument must be a string");
|
3633
3711
|
}
|
3712
|
+
if (!this.range) {
|
3713
|
+
return;
|
3714
|
+
}
|
3634
3715
|
if (this.range.anchor.isEqual(this.range.focus)) {
|
3635
3716
|
if (!this.range.anchor.element.isPreStyle()) {
|
3636
3717
|
data2 = data2.replace(/\s/g, () => {
|
@@ -3666,6 +3747,9 @@ class AlexEditor {
|
|
3666
3747
|
if (this.disabled) {
|
3667
3748
|
return;
|
3668
3749
|
}
|
3750
|
+
if (!this.range) {
|
3751
|
+
return;
|
3752
|
+
}
|
3669
3753
|
if (this.range.anchor.isEqual(this.range.focus)) {
|
3670
3754
|
const previousElement = this.getPreviousElementOfPoint(this.range.anchor);
|
3671
3755
|
const nextElement = this.getNextElementOfPoint(this.range.anchor);
|
@@ -3766,6 +3850,9 @@ class AlexEditor {
|
|
3766
3850
|
if (this.disabled) {
|
3767
3851
|
return;
|
3768
3852
|
}
|
3853
|
+
if (!this.range) {
|
3854
|
+
return;
|
3855
|
+
}
|
3769
3856
|
if (!AlexElement.isElement(ele)) {
|
3770
3857
|
throw new Error("The argument must be an AlexElement instance");
|
3771
3858
|
}
|
@@ -3912,10 +3999,10 @@ class AlexEditor {
|
|
3912
3999
|
while (index < element2.children.length) {
|
3913
4000
|
const ele = element2.children[index];
|
3914
4001
|
if (ele.isEmpty()) {
|
3915
|
-
if (ele.isContains(this.range.anchor.element)) {
|
4002
|
+
if (this.range && ele.isContains(this.range.anchor.element)) {
|
3916
4003
|
setRecentlyPoint.apply(this, [this.range.anchor]);
|
3917
4004
|
}
|
3918
|
-
if (ele.isContains(this.range.focus.element)) {
|
4005
|
+
if (this.range && ele.isContains(this.range.focus.element)) {
|
3919
4006
|
setRecentlyPoint.apply(this, [this.range.focus]);
|
3920
4007
|
}
|
3921
4008
|
element2.children.splice(index, 1);
|
@@ -3944,10 +4031,10 @@ class AlexEditor {
|
|
3944
4031
|
while (index < this.stack.length) {
|
3945
4032
|
const ele = this.stack[index];
|
3946
4033
|
if (ele.isEmpty()) {
|
3947
|
-
if (ele.isContains(this.range.anchor.element)) {
|
4034
|
+
if (this.range && ele.isContains(this.range.anchor.element)) {
|
3948
4035
|
setRecentlyPoint.apply(this, [this.range.anchor]);
|
3949
4036
|
}
|
3950
|
-
if (ele.isContains(this.range.focus.element)) {
|
4037
|
+
if (this.range && ele.isContains(this.range.focus.element)) {
|
3951
4038
|
setRecentlyPoint.apply(this, [this.range.focus]);
|
3952
4039
|
}
|
3953
4040
|
this.stack.splice(index, 1);
|
@@ -3958,10 +4045,10 @@ class AlexEditor {
|
|
3958
4045
|
}
|
3959
4046
|
this.formatElement(ele);
|
3960
4047
|
if (ele.isEmpty()) {
|
3961
|
-
if (ele.isContains(this.range.anchor.element)) {
|
4048
|
+
if (this.range && ele.isContains(this.range.anchor.element)) {
|
3962
4049
|
setRecentlyPoint.apply(this, [this.range.anchor]);
|
3963
4050
|
}
|
3964
|
-
if (ele.isContains(this.range.focus.element)) {
|
4051
|
+
if (this.range && ele.isContains(this.range.focus.element)) {
|
3965
4052
|
setRecentlyPoint.apply(this, [this.range.focus]);
|
3966
4053
|
}
|
3967
4054
|
this.stack.splice(index, 1);
|
@@ -4006,6 +4093,11 @@ class AlexEditor {
|
|
4006
4093
|
if (this.disabled) {
|
4007
4094
|
return;
|
4008
4095
|
}
|
4096
|
+
if (!this.range) {
|
4097
|
+
const selection2 = window.getSelection();
|
4098
|
+
selection2.removeAllRanges();
|
4099
|
+
return;
|
4100
|
+
}
|
4009
4101
|
const handler = (point) => {
|
4010
4102
|
let node = null;
|
4011
4103
|
let offset = null;
|
@@ -4293,6 +4385,9 @@ class AlexEditor {
|
|
4293
4385
|
* 获取选区之间的元素
|
4294
4386
|
*/
|
4295
4387
|
getElementsByRange(includes = false, flat = false) {
|
4388
|
+
if (!this.range) {
|
4389
|
+
return;
|
4390
|
+
}
|
4296
4391
|
if (this.range.anchor.isEqual(this.range.focus)) {
|
4297
4392
|
return [];
|
4298
4393
|
}
|
@@ -4401,6 +4496,9 @@ class AlexEditor {
|
|
4401
4496
|
* 分割选区选中的元素,会更新光标位置
|
4402
4497
|
*/
|
4403
4498
|
splitElementsByRange(includes = false, flat = false) {
|
4499
|
+
if (!this.range) {
|
4500
|
+
return;
|
4501
|
+
}
|
4404
4502
|
const result = this.getElementsByRange(includes, flat);
|
4405
4503
|
let elements = [];
|
4406
4504
|
result.forEach((item, index) => {
|
@@ -4522,6 +4620,11 @@ class AlexEditor {
|
|
4522
4620
|
if (this.disabled) {
|
4523
4621
|
return;
|
4524
4622
|
}
|
4623
|
+
let rangeIsNull = false;
|
4624
|
+
if (!this.range) {
|
4625
|
+
this.initRange();
|
4626
|
+
rangeIsNull = true;
|
4627
|
+
}
|
4525
4628
|
if (AlexElement.isElement(element2)) {
|
4526
4629
|
this.range.anchor.moveToStart(element2);
|
4527
4630
|
this.range.focus.moveToStart(element2);
|
@@ -4535,6 +4638,9 @@ class AlexEditor {
|
|
4535
4638
|
this.range.anchor.moveToStart(flatElements[0]);
|
4536
4639
|
this.range.focus.moveToStart(flatElements[0]);
|
4537
4640
|
}
|
4641
|
+
if (rangeIsNull) {
|
4642
|
+
this.history.updateCurrentRange(this.range);
|
4643
|
+
}
|
4538
4644
|
}
|
4539
4645
|
/**
|
4540
4646
|
* 将虚拟光标设置到指定元素最后
|
@@ -4543,6 +4649,11 @@ class AlexEditor {
|
|
4543
4649
|
if (this.disabled) {
|
4544
4650
|
return;
|
4545
4651
|
}
|
4652
|
+
let rangeIsNull = false;
|
4653
|
+
if (!this.range) {
|
4654
|
+
this.initRange();
|
4655
|
+
rangeIsNull = true;
|
4656
|
+
}
|
4546
4657
|
if (AlexElement.isElement(element2)) {
|
4547
4658
|
this.range.anchor.moveToEnd(element2);
|
4548
4659
|
this.range.focus.moveToEnd(element2);
|
@@ -4557,6 +4668,9 @@ class AlexEditor {
|
|
4557
4668
|
this.range.anchor.moveToEnd(flatElements[length - 1]);
|
4558
4669
|
this.range.focus.moveToEnd(flatElements[length - 1]);
|
4559
4670
|
}
|
4671
|
+
if (rangeIsNull) {
|
4672
|
+
this.history.updateCurrentRange(this.range);
|
4673
|
+
}
|
4560
4674
|
}
|
4561
4675
|
/**
|
4562
4676
|
* 禁用编辑器
|
@@ -4579,6 +4693,9 @@ class AlexEditor {
|
|
4579
4693
|
if (this.disabled) {
|
4580
4694
|
return;
|
4581
4695
|
}
|
4696
|
+
if (!this.range) {
|
4697
|
+
return;
|
4698
|
+
}
|
4582
4699
|
if (!obj$1.common.isObject(styles)) {
|
4583
4700
|
throw new Error("The argument must be an object");
|
4584
4701
|
}
|
@@ -4624,6 +4741,9 @@ class AlexEditor {
|
|
4624
4741
|
if (this.disabled) {
|
4625
4742
|
return;
|
4626
4743
|
}
|
4744
|
+
if (!this.range) {
|
4745
|
+
return;
|
4746
|
+
}
|
4627
4747
|
const removeFn = (el) => {
|
4628
4748
|
if (Array.isArray(styleNames)) {
|
4629
4749
|
if (el.hasStyles()) {
|
@@ -4665,12 +4785,12 @@ class AlexEditor {
|
|
4665
4785
|
if (!name) {
|
4666
4786
|
throw new Error("The first argument cannot be null");
|
4667
4787
|
}
|
4788
|
+
if (!this.range) {
|
4789
|
+
return false;
|
4790
|
+
}
|
4668
4791
|
if (this.range.anchor.isEqual(this.range.focus)) {
|
4669
4792
|
if (this.range.anchor.element.isText() && this.range.anchor.element.hasStyles()) {
|
4670
|
-
|
4671
|
-
return this.range.anchor.element.styles.hasOwnProperty(name);
|
4672
|
-
}
|
4673
|
-
return this.range.anchor.element.styles[name] == value;
|
4793
|
+
return queryHasValue(this.range.anchor.element.styles, name, value);
|
4674
4794
|
}
|
4675
4795
|
return false;
|
4676
4796
|
}
|
@@ -4690,10 +4810,7 @@ class AlexEditor {
|
|
4690
4810
|
}
|
4691
4811
|
let flag = result.every((item) => {
|
4692
4812
|
if (item.element.hasStyles()) {
|
4693
|
-
|
4694
|
-
return item.element.styles.hasOwnProperty(name);
|
4695
|
-
}
|
4696
|
-
return item.element.styles[name] == value;
|
4813
|
+
return queryHasValue(item.element.styles, name, value);
|
4697
4814
|
}
|
4698
4815
|
return false;
|
4699
4816
|
});
|
@@ -4706,6 +4823,9 @@ class AlexEditor {
|
|
4706
4823
|
if (this.disabled) {
|
4707
4824
|
return;
|
4708
4825
|
}
|
4826
|
+
if (!this.range) {
|
4827
|
+
return;
|
4828
|
+
}
|
4709
4829
|
if (!obj$1.common.isObject(marks)) {
|
4710
4830
|
throw new Error("The argument must be an object");
|
4711
4831
|
}
|
@@ -4751,6 +4871,9 @@ class AlexEditor {
|
|
4751
4871
|
if (this.disabled) {
|
4752
4872
|
return;
|
4753
4873
|
}
|
4874
|
+
if (!this.range) {
|
4875
|
+
return;
|
4876
|
+
}
|
4754
4877
|
const removeFn = (el) => {
|
4755
4878
|
if (Array.isArray(markNames)) {
|
4756
4879
|
if (el.hasMarks()) {
|
@@ -4792,12 +4915,12 @@ class AlexEditor {
|
|
4792
4915
|
if (!name) {
|
4793
4916
|
throw new Error("The first argument cannot be null");
|
4794
4917
|
}
|
4918
|
+
if (!this.range) {
|
4919
|
+
return false;
|
4920
|
+
}
|
4795
4921
|
if (this.range.anchor.isEqual(this.range.focus)) {
|
4796
4922
|
if (this.range.anchor.element.isText() && this.range.anchor.element.hasMarks()) {
|
4797
|
-
|
4798
|
-
return this.range.anchor.element.marks.hasOwnProperty(name);
|
4799
|
-
}
|
4800
|
-
return this.range.anchor.element.marks[name] == value;
|
4923
|
+
return queryHasValue(this.range.anchor.element.marks, name, value);
|
4801
4924
|
}
|
4802
4925
|
return false;
|
4803
4926
|
}
|
@@ -4817,10 +4940,7 @@ class AlexEditor {
|
|
4817
4940
|
}
|
4818
4941
|
let flag = result.every((item) => {
|
4819
4942
|
if (item.element.hasMarks()) {
|
4820
|
-
|
4821
|
-
return item.element.marks.hasOwnProperty(name);
|
4822
|
-
}
|
4823
|
-
return item.element.marks[name] == value;
|
4943
|
+
return queryHasValue(item.element.marks, name, value);
|
4824
4944
|
}
|
4825
4945
|
return false;
|
4826
4946
|
});
|
@@ -5037,10 +5157,10 @@ const string = {
|
|
5037
5157
|
},
|
5038
5158
|
/**
|
5039
5159
|
* 去除字符串空格
|
5040
|
-
* @param {Object} str
|
5160
|
+
* @param {Object} str 原始字符串
|
5041
5161
|
* @param {Object} global 为true时去除所有空格,否则只去除两边空格
|
5042
5162
|
*/
|
5043
|
-
trim(str, global) {
|
5163
|
+
trim(str, global = false) {
|
5044
5164
|
if (typeof str != "string") {
|
5045
5165
|
throw new TypeError("The first argument must be a string");
|
5046
5166
|
}
|
@@ -5060,9 +5180,9 @@ const element = {
|
|
5060
5180
|
return data2 && data2 instanceof Window;
|
5061
5181
|
},
|
5062
5182
|
/**
|
5063
|
-
*
|
5183
|
+
* 获取元素距离某个定位祖先元素左侧/顶部/底部/右侧的距离
|
5064
5184
|
* @param {Object} el 元素
|
5065
|
-
* @param {Object} root
|
5185
|
+
* @param {Object} root 定位父元素或者祖先元素,未指定则为document.body
|
5066
5186
|
*/
|
5067
5187
|
getElementPoint(el, root) {
|
5068
5188
|
if (!this.isElement(el)) {
|
@@ -5092,9 +5212,9 @@ const element = {
|
|
5092
5212
|
};
|
5093
5213
|
},
|
5094
5214
|
/**
|
5095
|
-
*
|
5096
|
-
* @param {Object} parentNode
|
5097
|
-
* @param {Object} childNode
|
5215
|
+
* 判断某个元素是否包含指定元素,包含相等关系和父子关系
|
5216
|
+
* @param {Object} parentNode 父元素或祖先元素
|
5217
|
+
* @param {Object} childNode 子元素
|
5098
5218
|
*/
|
5099
5219
|
isContains(parentNode, childNode) {
|
5100
5220
|
if (!this.isElement(parentNode)) {
|
@@ -5114,9 +5234,9 @@ const element = {
|
|
5114
5234
|
}
|
5115
5235
|
},
|
5116
5236
|
/**
|
5117
|
-
*
|
5118
|
-
* @param {Object} parentNode
|
5119
|
-
* @param {Object} childNode
|
5237
|
+
* 判断某个元素是否是指定元素的父元素
|
5238
|
+
* @param {Object} parentNode 父元素
|
5239
|
+
* @param {Object} childNode 子元素
|
5120
5240
|
*/
|
5121
5241
|
isParentNode(parentNode, childNode) {
|
5122
5242
|
if (!this.isElement(parentNode)) {
|
@@ -5131,8 +5251,8 @@ const element = {
|
|
5131
5251
|
return childNode.parentNode === parentNode;
|
5132
5252
|
},
|
5133
5253
|
/**
|
5134
|
-
*
|
5135
|
-
* @param {Object} el
|
5254
|
+
* 查找某个元素下指定选择器的子元素
|
5255
|
+
* @param {Object} el 元素
|
5136
5256
|
* @param {Object} selector 支持多选择器,等同于querySelectorAll的参数
|
5137
5257
|
*/
|
5138
5258
|
children(el, selector) {
|
@@ -5148,8 +5268,8 @@ const element = {
|
|
5148
5268
|
});
|
5149
5269
|
},
|
5150
5270
|
/**
|
5151
|
-
*
|
5152
|
-
* @param {Object} el
|
5271
|
+
* 查找某个元素下指定选择器的兄弟元素
|
5272
|
+
* @param {Object} el 元素
|
5153
5273
|
* @param {Object} selector 取值等同于queryselectorAll的参数,支持多选择器
|
5154
5274
|
*/
|
5155
5275
|
siblings(el, selector) {
|
@@ -5223,7 +5343,7 @@ const element = {
|
|
5223
5343
|
},
|
5224
5344
|
/**
|
5225
5345
|
* 移除class
|
5226
|
-
* @param {Object} el
|
5346
|
+
* @param {Object} el 元素
|
5227
5347
|
* @param {Object} className 支持多类,以空格划分
|
5228
5348
|
*/
|
5229
5349
|
removeClass(el, className) {
|
@@ -5241,7 +5361,7 @@ const element = {
|
|
5241
5361
|
},
|
5242
5362
|
/**
|
5243
5363
|
* 添加class
|
5244
|
-
* @param {Object} el
|
5364
|
+
* @param {Object} el 元素
|
5245
5365
|
* @param {Object} className 支持多类,以空格划分
|
5246
5366
|
*/
|
5247
5367
|
addClass(el, className) {
|
@@ -5259,7 +5379,7 @@ const element = {
|
|
5259
5379
|
},
|
5260
5380
|
/**
|
5261
5381
|
* 判断指定元素是否含有指定类名
|
5262
|
-
* @param {Object} el
|
5382
|
+
* @param {Object} el 元素
|
5263
5383
|
* @param {Object} className 支持多类,以空格划分
|
5264
5384
|
*/
|
5265
5385
|
hasClass(el, className) {
|
@@ -5587,7 +5707,7 @@ const element = {
|
|
5587
5707
|
};
|
5588
5708
|
},
|
5589
5709
|
/**
|
5590
|
-
*
|
5710
|
+
* 判断是否是元素
|
5591
5711
|
* @param {Object} el
|
5592
5712
|
*/
|
5593
5713
|
isElement(el) {
|
@@ -5606,7 +5726,7 @@ const element = {
|
|
5606
5726
|
if (parentEle.children.length == 1) {
|
5607
5727
|
return parentEle.children[0];
|
5608
5728
|
} else {
|
5609
|
-
return parentEle.children;
|
5729
|
+
return Array.from(parentEle.children);
|
5610
5730
|
}
|
5611
5731
|
}
|
5612
5732
|
};
|
@@ -5661,7 +5781,7 @@ const data = {
|
|
5661
5781
|
}
|
5662
5782
|
},
|
5663
5783
|
/**
|
5664
|
-
*
|
5784
|
+
* 设置元素指定数据
|
5665
5785
|
* @param {Object} el
|
5666
5786
|
* @param {Object} key
|
5667
5787
|
* @param {Object} value
|
@@ -5682,68 +5802,74 @@ const common = {
|
|
5682
5802
|
/**
|
5683
5803
|
* 常用判断
|
5684
5804
|
* @param {Object} text 要判断的字符串
|
5685
|
-
* @param {Object}
|
5805
|
+
* @param {Object} param 判断的类型字符串
|
5686
5806
|
*/
|
5687
|
-
matchingText(text2,
|
5807
|
+
matchingText(text2, param) {
|
5688
5808
|
if (!text2 || typeof text2 != "string") {
|
5689
5809
|
throw new TypeError("The first argument must be a string");
|
5690
5810
|
}
|
5691
|
-
if (!
|
5811
|
+
if (!param || typeof param != "string") {
|
5692
5812
|
throw new TypeError("The second argument must be a string");
|
5693
5813
|
}
|
5694
5814
|
let reg = null;
|
5695
|
-
if (
|
5815
|
+
if (param == "Chinese") {
|
5696
5816
|
reg = /^[\u4e00-\u9fa5]+$/;
|
5697
5817
|
}
|
5698
|
-
if (
|
5818
|
+
if (param == "chinese") {
|
5699
5819
|
reg = /[\u4e00-\u9fa5]/;
|
5700
5820
|
}
|
5701
|
-
if (
|
5821
|
+
if (param == "email") {
|
5702
5822
|
reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
|
5703
5823
|
}
|
5704
|
-
if (
|
5824
|
+
if (param == "username") {
|
5705
5825
|
reg = /^[a-zA-Z0-9_]{4,16}$/;
|
5706
5826
|
}
|
5707
|
-
if (
|
5827
|
+
if (param == "int+") {
|
5708
5828
|
reg = /^\d+$/;
|
5709
5829
|
}
|
5710
|
-
if (
|
5830
|
+
if (param == "int-") {
|
5711
5831
|
reg = /^-\d+$/;
|
5712
5832
|
}
|
5713
|
-
if (
|
5833
|
+
if (param == "int") {
|
5714
5834
|
reg = /^-?\d+$/;
|
5715
5835
|
}
|
5716
|
-
if (
|
5836
|
+
if (param == "pos") {
|
5717
5837
|
reg = /^\d*\.?\d+$/;
|
5718
5838
|
}
|
5719
|
-
if (
|
5839
|
+
if (param == "neg") {
|
5720
5840
|
reg = /^-\d*\.?\d+$/;
|
5721
5841
|
}
|
5722
|
-
if (
|
5842
|
+
if (param == "number") {
|
5723
5843
|
reg = /^-?\d*\.?\d+$/;
|
5724
5844
|
}
|
5725
|
-
if (
|
5845
|
+
if (param == "phone") {
|
5726
5846
|
reg = /^1[0-9]\d{9}$/;
|
5727
5847
|
}
|
5728
|
-
if (
|
5848
|
+
if (param == "idCard") {
|
5729
5849
|
reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
|
5730
5850
|
}
|
5731
|
-
if (
|
5732
|
-
reg = /^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([
|
5851
|
+
if (param == "url") {
|
5852
|
+
reg = /^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*\/?$/;
|
5733
5853
|
}
|
5734
|
-
if (
|
5854
|
+
if (param == "IPv4") {
|
5735
5855
|
reg = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
5736
5856
|
}
|
5737
|
-
if (
|
5857
|
+
if (param == "hex") {
|
5738
5858
|
reg = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
|
5739
5859
|
}
|
5740
|
-
if (
|
5860
|
+
if (param == "rgb") {
|
5861
|
+
reg = /^rgb\((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d),\s?(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d),\s?(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\)$/;
|
5862
|
+
}
|
5863
|
+
if (param == "rgba") {
|
5864
|
+
reg = /^rgba\((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d),\s?(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d),\s?(25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d),\s?(0?\.\d|1(\.0)?|0)\)$/;
|
5865
|
+
}
|
5866
|
+
if (param == "QQ") {
|
5741
5867
|
reg = /^[1-9][0-9]{4,10}$/;
|
5742
5868
|
}
|
5743
|
-
if (
|
5869
|
+
if (param == "weixin") {
|
5744
5870
|
reg = /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/;
|
5745
5871
|
}
|
5746
|
-
if (
|
5872
|
+
if (param == "plate") {
|
5747
5873
|
reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/;
|
5748
5874
|
}
|
5749
5875
|
if (!reg) {
|
@@ -5781,12 +5907,10 @@ const common = {
|
|
5781
5907
|
if (this.isObject(obj2)) {
|
5782
5908
|
if (Object.keys(obj2).length == 0) {
|
5783
5909
|
return true;
|
5784
|
-
} else {
|
5785
|
-
return false;
|
5786
5910
|
}
|
5787
|
-
} else {
|
5788
5911
|
return false;
|
5789
5912
|
}
|
5913
|
+
return false;
|
5790
5914
|
},
|
5791
5915
|
/**
|
5792
5916
|
* 判断两个参数是否相等
|
@@ -5798,32 +5922,25 @@ const common = {
|
|
5798
5922
|
return false;
|
5799
5923
|
}
|
5800
5924
|
if (this.isObject(a) && this.isObject(b)) {
|
5801
|
-
a = Object.assign({}, a);
|
5802
|
-
b = Object.assign({}, b);
|
5803
5925
|
let aProps = Object.getOwnPropertyNames(a);
|
5804
5926
|
let bProps = Object.getOwnPropertyNames(b);
|
5805
5927
|
if (aProps.length != bProps.length) {
|
5806
5928
|
return false;
|
5807
5929
|
}
|
5808
5930
|
let length = aProps.length;
|
5931
|
+
let isEqual = true;
|
5809
5932
|
for (let i = 0; i < length; i++) {
|
5810
5933
|
let propName = aProps[i];
|
5811
5934
|
let propA = a[propName];
|
5812
5935
|
let propB = b[propName];
|
5813
|
-
if (this.
|
5814
|
-
|
5815
|
-
|
5816
|
-
} else {
|
5817
|
-
return false;
|
5818
|
-
}
|
5819
|
-
} else if (propA !== propB) {
|
5820
|
-
return false;
|
5936
|
+
if (!this.equal(propA, propB)) {
|
5937
|
+
isEqual = false;
|
5938
|
+
break;
|
5821
5939
|
}
|
5822
5940
|
}
|
5823
|
-
return
|
5824
|
-
} else {
|
5825
|
-
return a === b;
|
5941
|
+
return isEqual;
|
5826
5942
|
}
|
5943
|
+
return a === b;
|
5827
5944
|
},
|
5828
5945
|
/**
|
5829
5946
|
* 是否对象
|
@@ -5844,9 +5961,28 @@ const common = {
|
|
5844
5961
|
throw new TypeError("No text to copy is defined");
|
5845
5962
|
}
|
5846
5963
|
if (!navigator.clipboard) {
|
5847
|
-
throw new Error("navigator.clipboard must be obtained in a secure environment, such as localhost, 127.0.0.1, or https, so the
|
5964
|
+
throw new Error("navigator.clipboard must be obtained in a secure environment, such as localhost, 127.0.0.1, or https, so the method won't work");
|
5848
5965
|
}
|
5849
5966
|
return navigator.clipboard.writeText(text2);
|
5967
|
+
},
|
5968
|
+
/**
|
5969
|
+
* 深度克隆
|
5970
|
+
* @param {Object} data
|
5971
|
+
*/
|
5972
|
+
clone(data2) {
|
5973
|
+
if (this.isObject(data2)) {
|
5974
|
+
if (Array.isArray(data2)) {
|
5975
|
+
return data2.map((item) => {
|
5976
|
+
return this.clone(item);
|
5977
|
+
});
|
5978
|
+
}
|
5979
|
+
let newData = {};
|
5980
|
+
for (let key in data2) {
|
5981
|
+
newData[key] = this.clone(data2[key]);
|
5982
|
+
}
|
5983
|
+
return newData;
|
5984
|
+
}
|
5985
|
+
return data2;
|
5850
5986
|
}
|
5851
5987
|
};
|
5852
5988
|
const parseEventName = (eventName) => {
|
@@ -6354,9 +6490,11 @@ const platform = {
|
|
6354
6490
|
Windows_Version: function() {
|
6355
6491
|
if (userAgent.includes("Windows NT 6.1") || userAgent.includes("Windows 7")) {
|
6356
6492
|
return "Win7";
|
6357
|
-
}
|
6493
|
+
}
|
6494
|
+
if (userAgent.includes("Windows NT 6.3") || userAgent.includes("Windows NT 6.2") || userAgent.includes("Windows NT 8")) {
|
6358
6495
|
return "Win8";
|
6359
|
-
}
|
6496
|
+
}
|
6497
|
+
if (userAgent.includes("Windows NT 10") || userAgent.includes("Windows NT 6.4")) {
|
6360
6498
|
return "Win10";
|
6361
6499
|
}
|
6362
6500
|
return "";
|
@@ -15363,6 +15501,9 @@ const tableHandle = function(element2) {
|
|
15363
15501
|
}
|
15364
15502
|
};
|
15365
15503
|
const updateRangeInPre = function(element2, originalTextElements, newElements) {
|
15504
|
+
if (!this.range) {
|
15505
|
+
return;
|
15506
|
+
}
|
15366
15507
|
if (this.range.anchor.element.getBlock().isEqual(element2)) {
|
15367
15508
|
const elIndex = originalTextElements.findIndex((el) => this.range.anchor.element.isEqual(el));
|
15368
15509
|
const offset = originalTextElements.filter((el, i2) => i2 < elIndex).reduce((total, item, i2) => total + item.textContent.length, 0) + this.range.anchor.offset;
|
@@ -20951,7 +21092,7 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
|
|
20951
21092
|
], 14, _hoisted_1$1);
|
20952
21093
|
}
|
20953
21094
|
const Menu = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-4c7850ff"]]);
|
20954
|
-
const
|
21095
|
+
const Editify_vue_vue_type_style_index_0_scoped_bcab43d0_lang = "";
|
20955
21096
|
const _sfc_main = {
|
20956
21097
|
name: "editify",
|
20957
21098
|
props: { ...editorProps },
|
@@ -21044,10 +21185,10 @@ const _sfc_main = {
|
|
21044
21185
|
return;
|
21045
21186
|
}
|
21046
21187
|
this.editor.stack = this.editor.parseHtml(newVal);
|
21188
|
+
this.editor.range = null;
|
21047
21189
|
this.editor.formatElementStack();
|
21048
|
-
this.editor.range.anchor.moveToStart(this.editor.stack[0]);
|
21049
|
-
this.editor.range.focus.moveToStart(this.editor.stack[0]);
|
21050
21190
|
this.editor.domRender();
|
21191
|
+
this.editor.rangeRender();
|
21051
21192
|
},
|
21052
21193
|
//代码视图切换
|
21053
21194
|
isSourceView(newValue) {
|
@@ -21334,6 +21475,9 @@ const _sfc_main = {
|
|
21334
21475
|
} else {
|
21335
21476
|
element2.marks["data-editify-task"] = "checked";
|
21336
21477
|
}
|
21478
|
+
if (!this.editor.range) {
|
21479
|
+
this.editor.initRange();
|
21480
|
+
}
|
21337
21481
|
this.editor.range.anchor.moveToEnd(element2);
|
21338
21482
|
this.editor.range.focus.moveToEnd(element2);
|
21339
21483
|
this.editor.formatElementStack();
|
@@ -21414,6 +21558,9 @@ const _sfc_main = {
|
|
21414
21558
|
const key = node.getAttribute("data-editify-element");
|
21415
21559
|
if (key) {
|
21416
21560
|
const element2 = this.editor.getElementByKey(key);
|
21561
|
+
if (!this.editor.range) {
|
21562
|
+
this.editor.initRange();
|
21563
|
+
}
|
21417
21564
|
this.editor.range.anchor.moveToStart(element2);
|
21418
21565
|
this.editor.range.focus.moveToEnd(element2);
|
21419
21566
|
this.editor.rangeRender();
|
@@ -21563,6 +21710,9 @@ const _sfc_main = {
|
|
21563
21710
|
if (this.disabled) {
|
21564
21711
|
return null;
|
21565
21712
|
}
|
21713
|
+
if (!this.editor.range) {
|
21714
|
+
return null;
|
21715
|
+
}
|
21566
21716
|
if (this.editor.range.anchor.element.isEqual(this.editor.range.focus.element)) {
|
21567
21717
|
return this.getParsedomElementByElement(this.editor.range.anchor.element, parsedom);
|
21568
21718
|
}
|
@@ -21595,6 +21745,9 @@ const _sfc_main = {
|
|
21595
21745
|
if (this.disabled) {
|
21596
21746
|
return;
|
21597
21747
|
}
|
21748
|
+
if (!this.editor.range) {
|
21749
|
+
return;
|
21750
|
+
}
|
21598
21751
|
const element2 = this.getCurrentParsedomElement(parsedom);
|
21599
21752
|
if (element2) {
|
21600
21753
|
element2.toEmpty();
|
@@ -21608,6 +21761,9 @@ const _sfc_main = {
|
|
21608
21761
|
if (this.disabled) {
|
21609
21762
|
return;
|
21610
21763
|
}
|
21764
|
+
if (!this.editor.range) {
|
21765
|
+
return;
|
21766
|
+
}
|
21611
21767
|
const link = this.getCurrentParsedomElement("a");
|
21612
21768
|
if (link) {
|
21613
21769
|
link.parsedom = AlexElement.TEXT_NODE;
|
@@ -21623,6 +21779,9 @@ const _sfc_main = {
|
|
21623
21779
|
if (this.disabled) {
|
21624
21780
|
return;
|
21625
21781
|
}
|
21782
|
+
if (!this.editor.range) {
|
21783
|
+
return;
|
21784
|
+
}
|
21626
21785
|
const values = getButtonOptionsConfig(this.$editTrans, this.$editLocale).heading.map((item) => {
|
21627
21786
|
return item.value;
|
21628
21787
|
});
|
@@ -21655,6 +21814,9 @@ const _sfc_main = {
|
|
21655
21814
|
if (this.disabled) {
|
21656
21815
|
return;
|
21657
21816
|
}
|
21817
|
+
if (!this.editor.range) {
|
21818
|
+
return;
|
21819
|
+
}
|
21658
21820
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
21659
21821
|
const block = this.editor.range.anchor.element.getBlock();
|
21660
21822
|
const isList = blockIsList(block, ordered);
|
@@ -21691,6 +21853,9 @@ const _sfc_main = {
|
|
21691
21853
|
if (this.disabled) {
|
21692
21854
|
return;
|
21693
21855
|
}
|
21856
|
+
if (!this.editor.range) {
|
21857
|
+
return;
|
21858
|
+
}
|
21694
21859
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
21695
21860
|
const block = this.editor.range.anchor.element.getBlock();
|
21696
21861
|
const isTask = blockIsTask(block);
|
@@ -21727,6 +21892,9 @@ const _sfc_main = {
|
|
21727
21892
|
if (this.disabled) {
|
21728
21893
|
return;
|
21729
21894
|
}
|
21895
|
+
if (!this.editor.range) {
|
21896
|
+
return;
|
21897
|
+
}
|
21730
21898
|
const active = this.queryTextStyle(name, value);
|
21731
21899
|
if (active) {
|
21732
21900
|
this.editor.removeTextStyle([name]);
|
@@ -21748,6 +21916,9 @@ const _sfc_main = {
|
|
21748
21916
|
if (this.disabled) {
|
21749
21917
|
return;
|
21750
21918
|
}
|
21919
|
+
if (!this.editor.range) {
|
21920
|
+
return;
|
21921
|
+
}
|
21751
21922
|
const active = this.queryTextMark(name, value);
|
21752
21923
|
if (active) {
|
21753
21924
|
this.editor.removeTextMark([name]);
|
@@ -21769,6 +21940,9 @@ const _sfc_main = {
|
|
21769
21940
|
if (this.disabled) {
|
21770
21941
|
return;
|
21771
21942
|
}
|
21943
|
+
if (!this.editor.range) {
|
21944
|
+
return;
|
21945
|
+
}
|
21772
21946
|
this.editor.removeTextStyle();
|
21773
21947
|
this.editor.removeTextMark();
|
21774
21948
|
this.editor.formatElementStack();
|
@@ -21780,6 +21954,9 @@ const _sfc_main = {
|
|
21780
21954
|
if (this.disabled) {
|
21781
21955
|
return;
|
21782
21956
|
}
|
21957
|
+
if (!this.editor.range) {
|
21958
|
+
return;
|
21959
|
+
}
|
21783
21960
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
21784
21961
|
const block = this.editor.range.anchor.element.getBlock();
|
21785
21962
|
const inblock = this.editor.range.anchor.element.getInblock();
|
@@ -21873,6 +22050,9 @@ const _sfc_main = {
|
|
21873
22050
|
if (this.disabled) {
|
21874
22051
|
return;
|
21875
22052
|
}
|
22053
|
+
if (!this.editor.range) {
|
22054
|
+
return;
|
22055
|
+
}
|
21876
22056
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
21877
22057
|
const block = this.editor.range.anchor.element.getBlock();
|
21878
22058
|
const oldParsedom = block.parsedom;
|
@@ -21907,6 +22087,9 @@ const _sfc_main = {
|
|
21907
22087
|
if (this.disabled) {
|
21908
22088
|
return;
|
21909
22089
|
}
|
22090
|
+
if (!this.editor.range) {
|
22091
|
+
return;
|
22092
|
+
}
|
21910
22093
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
21911
22094
|
const block = this.editor.range.anchor.element.getBlock();
|
21912
22095
|
const inblock = this.editor.range.anchor.element.getInblock();
|
@@ -21970,6 +22153,9 @@ const _sfc_main = {
|
|
21970
22153
|
if (this.disabled) {
|
21971
22154
|
return;
|
21972
22155
|
}
|
22156
|
+
if (!this.editor.range) {
|
22157
|
+
return;
|
22158
|
+
}
|
21973
22159
|
const fn = (element2) => {
|
21974
22160
|
if (element2.hasStyles()) {
|
21975
22161
|
if (element2.styles.hasOwnProperty("text-indent")) {
|
@@ -22018,6 +22204,9 @@ const _sfc_main = {
|
|
22018
22204
|
if (this.disabled) {
|
22019
22205
|
return;
|
22020
22206
|
}
|
22207
|
+
if (!this.editor.range) {
|
22208
|
+
return;
|
22209
|
+
}
|
22021
22210
|
const fn = (element2) => {
|
22022
22211
|
if (element2.hasStyles() && element2.styles.hasOwnProperty("text-indent")) {
|
22023
22212
|
let val = element2.styles["text-indent"];
|
@@ -22058,6 +22247,9 @@ const _sfc_main = {
|
|
22058
22247
|
if (this.disabled) {
|
22059
22248
|
return;
|
22060
22249
|
}
|
22250
|
+
if (!this.editor.range) {
|
22251
|
+
return;
|
22252
|
+
}
|
22061
22253
|
if (!url2 || typeof url2 != "string") {
|
22062
22254
|
throw new Error("An image address must be given");
|
22063
22255
|
}
|
@@ -22080,6 +22272,9 @@ const _sfc_main = {
|
|
22080
22272
|
if (this.disabled) {
|
22081
22273
|
return;
|
22082
22274
|
}
|
22275
|
+
if (!this.editor.range) {
|
22276
|
+
return;
|
22277
|
+
}
|
22083
22278
|
if (!url2 || typeof url2 != "string") {
|
22084
22279
|
throw new Error("A video address must be given");
|
22085
22280
|
}
|
@@ -22105,171 +22300,199 @@ const _sfc_main = {
|
|
22105
22300
|
},
|
22106
22301
|
//api:选区是否含有代码块样式
|
22107
22302
|
hasPreStyle() {
|
22303
|
+
if (!this.editor.range) {
|
22304
|
+
return false;
|
22305
|
+
}
|
22108
22306
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
22109
22307
|
return this.editor.range.anchor.element.isPreStyle();
|
22110
|
-
} else {
|
22111
|
-
const result = this.editor.getElementsByRange(true, false);
|
22112
|
-
return result.some((item) => {
|
22113
|
-
return item.element.isPreStyle();
|
22114
|
-
});
|
22115
22308
|
}
|
22309
|
+
const result = this.editor.getElementsByRange(true, false);
|
22310
|
+
return result.some((item) => {
|
22311
|
+
return item.element.isPreStyle();
|
22312
|
+
});
|
22116
22313
|
},
|
22117
22314
|
//api:选区是否含有引用
|
22118
22315
|
hasQuote() {
|
22316
|
+
if (!this.editor.range) {
|
22317
|
+
return false;
|
22318
|
+
}
|
22119
22319
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
22120
22320
|
const block = this.editor.range.anchor.element.getBlock();
|
22121
22321
|
return block.parsedom == "blockquote";
|
22122
|
-
} else {
|
22123
|
-
const result = this.editor.getElementsByRange(true, false);
|
22124
|
-
return result.some((item) => {
|
22125
|
-
if (item.element.isBlock()) {
|
22126
|
-
return item.element.parsedom == "blockquote";
|
22127
|
-
} else {
|
22128
|
-
const block = item.element.getBlock();
|
22129
|
-
return block.parsedom == "blockquote";
|
22130
|
-
}
|
22131
|
-
});
|
22132
22322
|
}
|
22323
|
+
const result = this.editor.getElementsByRange(true, false);
|
22324
|
+
return result.some((item) => {
|
22325
|
+
if (item.element.isBlock()) {
|
22326
|
+
return item.element.parsedom == "blockquote";
|
22327
|
+
} else {
|
22328
|
+
const block = item.element.getBlock();
|
22329
|
+
return block.parsedom == "blockquote";
|
22330
|
+
}
|
22331
|
+
});
|
22133
22332
|
},
|
22134
22333
|
//api:选区是否含有列表
|
22135
22334
|
hasList(ordered = false) {
|
22335
|
+
if (!this.editor.range) {
|
22336
|
+
return false;
|
22337
|
+
}
|
22136
22338
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
22137
22339
|
const block = this.editor.range.anchor.element.getBlock();
|
22138
22340
|
return blockIsList(block, ordered);
|
22139
|
-
} else {
|
22140
|
-
const result = this.editor.getElementsByRange(true, false);
|
22141
|
-
return result.some((item) => {
|
22142
|
-
if (item.element.isBlock()) {
|
22143
|
-
return blockIsList(item.element, ordered);
|
22144
|
-
} else {
|
22145
|
-
const block = item.element.getBlock();
|
22146
|
-
return blockIsList(block, ordered);
|
22147
|
-
}
|
22148
|
-
});
|
22149
22341
|
}
|
22342
|
+
const result = this.editor.getElementsByRange(true, false);
|
22343
|
+
return result.some((item) => {
|
22344
|
+
if (item.element.isBlock()) {
|
22345
|
+
return blockIsList(item.element, ordered);
|
22346
|
+
} else {
|
22347
|
+
const block = item.element.getBlock();
|
22348
|
+
return blockIsList(block, ordered);
|
22349
|
+
}
|
22350
|
+
});
|
22150
22351
|
},
|
22151
22352
|
//api:选区是否含有链接
|
22152
22353
|
hasLink() {
|
22354
|
+
if (!this.editor.range) {
|
22355
|
+
return false;
|
22356
|
+
}
|
22153
22357
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
22154
22358
|
return !!this.getParsedomElementByElement(this.editor.range.anchor.element, "a");
|
22155
|
-
} else {
|
22156
|
-
const result = this.editor.getElementsByRange(true, true).filter((item) => {
|
22157
|
-
return item.element.isText();
|
22158
|
-
});
|
22159
|
-
return result.some((item) => {
|
22160
|
-
return !!this.getParsedomElementByElement(item.element, "a");
|
22161
|
-
});
|
22162
22359
|
}
|
22360
|
+
const result = this.editor.getElementsByRange(true, true).filter((item) => {
|
22361
|
+
return item.element.isText();
|
22362
|
+
});
|
22363
|
+
return result.some((item) => {
|
22364
|
+
return !!this.getParsedomElementByElement(item.element, "a");
|
22365
|
+
});
|
22163
22366
|
},
|
22164
22367
|
//api:选区是否含有表格
|
22165
22368
|
hasTable() {
|
22369
|
+
if (!this.editor.range) {
|
22370
|
+
return false;
|
22371
|
+
}
|
22166
22372
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
22167
22373
|
const block = this.editor.range.anchor.element.getBlock();
|
22168
22374
|
return block.parsedom == "table";
|
22169
|
-
} else {
|
22170
|
-
const result = this.editor.getElementsByRange(true, false);
|
22171
|
-
return result.some((item) => {
|
22172
|
-
if (item.element.isBlock()) {
|
22173
|
-
return item.element.parsedom == "table";
|
22174
|
-
} else {
|
22175
|
-
const block = item.element.getBlock();
|
22176
|
-
return block.parsedom == "table";
|
22177
|
-
}
|
22178
|
-
});
|
22179
22375
|
}
|
22376
|
+
const result = this.editor.getElementsByRange(true, false);
|
22377
|
+
return result.some((item) => {
|
22378
|
+
if (item.element.isBlock()) {
|
22379
|
+
return item.element.parsedom == "table";
|
22380
|
+
} else {
|
22381
|
+
const block = item.element.getBlock();
|
22382
|
+
return block.parsedom == "table";
|
22383
|
+
}
|
22384
|
+
});
|
22180
22385
|
},
|
22181
22386
|
//api:选区是否含有任务列表
|
22182
22387
|
hasTask() {
|
22388
|
+
if (!this.editor.range) {
|
22389
|
+
return false;
|
22390
|
+
}
|
22183
22391
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
22184
22392
|
const block = this.editor.range.anchor.element.getBlock();
|
22185
22393
|
return blockIsTask(block);
|
22186
|
-
} else {
|
22187
|
-
const result = this.editor.getElementsByRange(true, false);
|
22188
|
-
return result.some((item) => {
|
22189
|
-
if (item.element.isBlock()) {
|
22190
|
-
return blockIsTask(item.element);
|
22191
|
-
} else {
|
22192
|
-
const block = item.element.getBlock();
|
22193
|
-
return blockIsTask(block);
|
22194
|
-
}
|
22195
|
-
});
|
22196
22394
|
}
|
22395
|
+
const result = this.editor.getElementsByRange(true, false);
|
22396
|
+
return result.some((item) => {
|
22397
|
+
if (item.element.isBlock()) {
|
22398
|
+
return blockIsTask(item.element);
|
22399
|
+
} else {
|
22400
|
+
const block = item.element.getBlock();
|
22401
|
+
return blockIsTask(block);
|
22402
|
+
}
|
22403
|
+
});
|
22197
22404
|
},
|
22198
22405
|
//选区是否含有图片
|
22199
22406
|
hasImage() {
|
22407
|
+
if (!this.editor.range) {
|
22408
|
+
return false;
|
22409
|
+
}
|
22200
22410
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
22201
22411
|
return this.editor.range.anchor.element.isClosed() && this.editor.range.anchor.element.parsedom == "img";
|
22202
|
-
} else {
|
22203
|
-
const result = this.editor.getElementsByRange(true, true);
|
22204
|
-
return result.some((item) => {
|
22205
|
-
return item.element.isClosed() && item.element.parsedom == "img";
|
22206
|
-
});
|
22207
22412
|
}
|
22413
|
+
const result = this.editor.getElementsByRange(true, true);
|
22414
|
+
return result.some((item) => {
|
22415
|
+
return item.element.isClosed() && item.element.parsedom == "img";
|
22416
|
+
});
|
22208
22417
|
},
|
22209
22418
|
//选区是否含有视频
|
22210
22419
|
hasVideo() {
|
22420
|
+
if (!this.editor.range) {
|
22421
|
+
return false;
|
22422
|
+
}
|
22211
22423
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
22212
22424
|
return this.editor.range.anchor.element.isClosed() && this.editor.range.anchor.element.parsedom == "video";
|
22213
|
-
} else {
|
22214
|
-
const result = this.editor.getElementsByRange(true, true);
|
22215
|
-
return result.some((item) => {
|
22216
|
-
return item.element.isClosed() && item.element.parsedom == "video";
|
22217
|
-
});
|
22218
22425
|
}
|
22426
|
+
const result = this.editor.getElementsByRange(true, true);
|
22427
|
+
return result.some((item) => {
|
22428
|
+
return item.element.isClosed() && item.element.parsedom == "video";
|
22429
|
+
});
|
22219
22430
|
},
|
22220
22431
|
//api:选区是否全部在引用内
|
22221
22432
|
inQuote() {
|
22433
|
+
if (!this.editor.range) {
|
22434
|
+
return false;
|
22435
|
+
}
|
22222
22436
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
22223
22437
|
const block = this.editor.range.anchor.element.getBlock();
|
22224
22438
|
return block.parsedom == "blockquote";
|
22225
|
-
} else {
|
22226
|
-
const result = this.editor.getElementsByRange(true, false);
|
22227
|
-
return result.every((item) => {
|
22228
|
-
if (item.element.isBlock()) {
|
22229
|
-
return item.element.parsedom == "blockquote";
|
22230
|
-
} else {
|
22231
|
-
const block = item.element.getBlock();
|
22232
|
-
return block.parsedom == "blockquote";
|
22233
|
-
}
|
22234
|
-
});
|
22235
22439
|
}
|
22440
|
+
const result = this.editor.getElementsByRange(true, false);
|
22441
|
+
return result.every((item) => {
|
22442
|
+
if (item.element.isBlock()) {
|
22443
|
+
return item.element.parsedom == "blockquote";
|
22444
|
+
} else {
|
22445
|
+
const block = item.element.getBlock();
|
22446
|
+
return block.parsedom == "blockquote";
|
22447
|
+
}
|
22448
|
+
});
|
22236
22449
|
},
|
22237
22450
|
//api:选区是否全部在列表内
|
22238
22451
|
inList(ordered = false) {
|
22452
|
+
if (!this.editor.range) {
|
22453
|
+
return false;
|
22454
|
+
}
|
22239
22455
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
22240
22456
|
const block = this.editor.range.anchor.element.getBlock();
|
22241
22457
|
return blockIsList(block, ordered);
|
22242
|
-
} else {
|
22243
|
-
const result = this.editor.getElementsByRange(true, false);
|
22244
|
-
return result.every((item) => {
|
22245
|
-
if (item.element.isBlock()) {
|
22246
|
-
return blockIsList(item.element, ordered);
|
22247
|
-
} else {
|
22248
|
-
const block = item.element.getBlock();
|
22249
|
-
return blockIsList(block, ordered);
|
22250
|
-
}
|
22251
|
-
});
|
22252
22458
|
}
|
22459
|
+
const result = this.editor.getElementsByRange(true, false);
|
22460
|
+
return result.every((item) => {
|
22461
|
+
if (item.element.isBlock()) {
|
22462
|
+
return blockIsList(item.element, ordered);
|
22463
|
+
} else {
|
22464
|
+
const block = item.element.getBlock();
|
22465
|
+
return blockIsList(block, ordered);
|
22466
|
+
}
|
22467
|
+
});
|
22253
22468
|
},
|
22254
22469
|
//api:选区是否全部在任务列表里
|
22255
22470
|
inTask() {
|
22471
|
+
if (!this.editor.range) {
|
22472
|
+
return false;
|
22473
|
+
}
|
22256
22474
|
if (this.editor.range.anchor.isEqual(this.editor.range.focus)) {
|
22257
22475
|
const block = this.editor.range.anchor.element.getBlock();
|
22258
22476
|
return blockIsTask(block);
|
22259
|
-
} else {
|
22260
|
-
const result = this.editor.getElementsByRange(true, false);
|
22261
|
-
return result.every((item) => {
|
22262
|
-
if (item.element.isBlock()) {
|
22263
|
-
return blockIsTask(item.element);
|
22264
|
-
} else {
|
22265
|
-
const block = item.element.getBlock();
|
22266
|
-
return blockIsTask(block);
|
22267
|
-
}
|
22268
|
-
});
|
22269
22477
|
}
|
22478
|
+
const result = this.editor.getElementsByRange(true, false);
|
22479
|
+
return result.every((item) => {
|
22480
|
+
if (item.element.isBlock()) {
|
22481
|
+
return blockIsTask(item.element);
|
22482
|
+
} else {
|
22483
|
+
const block = item.element.getBlock();
|
22484
|
+
return blockIsTask(block);
|
22485
|
+
}
|
22486
|
+
});
|
22270
22487
|
},
|
22271
22488
|
//api:创建一个空的表格
|
22272
22489
|
insertTable(rowLength, colLength) {
|
22490
|
+
if (this.disabled) {
|
22491
|
+
return;
|
22492
|
+
}
|
22493
|
+
if (!this.editor.range) {
|
22494
|
+
return;
|
22495
|
+
}
|
22273
22496
|
const table = new AlexElement("block", "table", null, null, null);
|
22274
22497
|
const tbody = new AlexElement("inblock", "tbody", null, null, null);
|
22275
22498
|
this.editor.addElementTo(tbody, table);
|
@@ -22299,6 +22522,9 @@ const _sfc_main = {
|
|
22299
22522
|
if (this.disabled) {
|
22300
22523
|
return;
|
22301
22524
|
}
|
22525
|
+
if (!this.editor.range) {
|
22526
|
+
return;
|
22527
|
+
}
|
22302
22528
|
const pre = this.getCurrentParsedomElement("pre");
|
22303
22529
|
if (pre) {
|
22304
22530
|
let content = "";
|
@@ -22372,6 +22598,9 @@ const _sfc_main = {
|
|
22372
22598
|
if (this.disabled) {
|
22373
22599
|
return;
|
22374
22600
|
}
|
22601
|
+
if (!this.editor.range) {
|
22602
|
+
return;
|
22603
|
+
}
|
22375
22604
|
this.editor.insertText(text2);
|
22376
22605
|
this.editor.formatElementStack();
|
22377
22606
|
this.editor.domRender();
|
@@ -22382,6 +22611,9 @@ const _sfc_main = {
|
|
22382
22611
|
if (this.disabled) {
|
22383
22612
|
return;
|
22384
22613
|
}
|
22614
|
+
if (!this.editor.range) {
|
22615
|
+
return;
|
22616
|
+
}
|
22385
22617
|
const elements = this.editor.parseHtml(html);
|
22386
22618
|
for (let i = 0; i < elements.length; i++) {
|
22387
22619
|
this.editor.insertElement(elements[i], false);
|
@@ -22453,7 +22685,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
22453
22685
|
])) : createCommentVNode("", true)
|
22454
22686
|
]);
|
22455
22687
|
}
|
22456
|
-
const Editify = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-
|
22688
|
+
const Editify = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-bcab43d0"]]);
|
22457
22689
|
const iconfont = "";
|
22458
22690
|
const en_US = {
|
22459
22691
|
textWrapUp: "Up feed",
|
@@ -22632,7 +22864,7 @@ const i18n = (locale) => {
|
|
22632
22864
|
return translations[locale][key];
|
22633
22865
|
};
|
22634
22866
|
};
|
22635
|
-
const version = "0.0.
|
22867
|
+
const version = "0.0.19";
|
22636
22868
|
const install = (app, props) => {
|
22637
22869
|
const locale = (props ? props.locale : "zh_CN") || "zh_CN";
|
22638
22870
|
app.provide("$editTrans", i18n(locale));
|