@haluo/biz 1.0.0 → 1.0.1

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/dist/haluo-biz.js CHANGED
@@ -1,4 +1,4 @@
1
- import { resolveComponent, resolveDirective, openBlock, createElementBlock, createElementVNode, createVNode, withCtx, normalizeStyle, createCommentVNode, normalizeClass, toDisplayString, withDirectives, Fragment, renderList, createBlock, defineComponent, inject, computed, unref, isRef, renderSlot, createTextVNode, provide, toRefs, reactive, watch, onMounted, withKeys, ref, h, render as render$3, vShow } from "vue";
1
+ import { resolveComponent, resolveDirective, openBlock, createElementBlock, createElementVNode, createVNode, withCtx, normalizeStyle, createCommentVNode, normalizeClass, toDisplayString, withDirectives, Fragment, renderList, createBlock, defineComponent, inject, computed, unref, isRef, renderSlot, createTextVNode, provide, getCurrentInstance, toRefs, reactive, watch, onMounted, withKeys, ref, h, render as render$3, vShow } from "vue";
2
2
  import util from "@haluo/util";
3
3
  import draggable from "vuedraggable";
4
4
  const __vite_glob_0_0 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAABLBAMAAADKYGfZAAAAG1BMVEUAAAAAAABHcExSUlLz8/P////IyMifn5/k5OQx49C2AAAACXRSTlMzZgB/7//CpN1ci7LLAAABHUlEQVR4AY3TgUbAUBjF8e0NmiiAY28QIYCkXqB9GUBIT7AHCHvvss3l73Y4g3vx87ft3m8Yp+C5GZSxecyYMuZzZMqYz5EpYz5Hpoz5HJkS1uceP67N7TeYyF7r59xs9XmxlgNbj/W+6hmMua86c9vfCsbcXdV6xpYHsj53xF4msj7XYmB97oqB9bmlxcC6XIuBdbkWI2Nur3qfyFouqc0K3g05/6XI+f+GnD8F5NyZMmdvCHP2vjFX7vYyt7tZYO7p7f/JYs7NKXMZk2fMZUyeMZcxecZcxuQZcxmTZ8xlTJ4xlzF5xlzG5BlzGZNnzGVMnjGXMXnGXMbkGXMZk2fMZUyeMZcxecZcxuQZcxmTZ8xlTJ4xlzFlbB5+AVncQI3j46OFAAAAAElFTkSuQmCC";
@@ -1134,6 +1134,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
1134
1134
  emits("update:visible", val);
1135
1135
  }
1136
1136
  });
1137
+ const { proxy } = getCurrentInstance();
1137
1138
  const { visible, getList } = toRefs(props);
1138
1139
  const data = reactive({
1139
1140
  params: {
@@ -1161,8 +1162,10 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
1161
1162
  data.article = item;
1162
1163
  };
1163
1164
  const confirm = () => {
1164
- if (!data.article)
1165
- return {};
1165
+ if (!data.article) {
1166
+ proxy.$message.error("\u8BF7\u9009\u62E9\u6587\u7AE0");
1167
+ return;
1168
+ }
1166
1169
  emits("change", data.article);
1167
1170
  };
1168
1171
  const getArticleList = async (reset) => {
@@ -1706,3776 +1709,125 @@ const mountArticleDom = (props, del) => {
1706
1709
  return div;
1707
1710
  };
1708
1711
  const car_ciose = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAABLBAMAAADKYGfZAAAAG1BMVEUAAAAAAABHcExSUlLz8/P////IyMifn5/k5OQx49C2AAAACXRSTlMzZgB/7//CpN1ci7LLAAABHUlEQVR4AY3TgUbAUBjF8e0NmiiAY28QIYCkXqB9GUBIT7AHCHvvss3l73Y4g3vx87ft3m8Yp+C5GZSxecyYMuZzZMqYz5EpYz5Hpoz5HJkS1uceP67N7TeYyF7r59xs9XmxlgNbj/W+6hmMua86c9vfCsbcXdV6xpYHsj53xF4msj7XYmB97oqB9bmlxcC6XIuBdbkWI2Nur3qfyFouqc0K3g05/6XI+f+GnD8F5NyZMmdvCHP2vjFX7vYyt7tZYO7p7f/JYs7NKXMZk2fMZUyeMZcxecZcxuQZcxmTZ8xlTJ4xlzF5xlzG5BlzGZNnzGVMnjGXMXnGXMbkGXMZk2fMZUyeMZcxecZcxuQZcxmTZ8xlTJ4xlzFlbB5+AVncQI3j46OFAAAAAElFTkSuQmCC";
1709
- (function(doc, undefined$1) {
1710
- var DOCUMENT_POSITION_PRECEDING = 2;
1711
- var ELEMENT_NODE = 1;
1712
- var TEXT_NODE = 3;
1713
- var DOCUMENT_NODE = 9;
1714
- var DOCUMENT_FRAGMENT_NODE = 11;
1715
- var SHOW_ELEMENT = 1;
1716
- var SHOW_TEXT = 4;
1717
- var START_TO_START = 0;
1718
- var START_TO_END = 1;
1719
- var END_TO_END = 2;
1720
- var END_TO_START = 3;
1721
- var HIGHLIGHT_CLASS = "highlight";
1722
- var COLOUR_CLASS = "colour";
1723
- var FONT_FAMILY_CLASS = "font";
1724
- var FONT_SIZE_CLASS = "size";
1725
- var ZWS = "\u200B";
1726
- var win = doc.defaultView;
1727
- var ua = navigator.userAgent;
1728
- var isAndroid = /Android/.test(ua);
1729
- var isIOS = /iP(?:ad|hone|od)/.test(ua);
1730
- var isMac = /Mac OS X/.test(ua);
1731
- var isWin = /Windows NT/.test(ua);
1732
- var isGecko = /Gecko\//.test(ua);
1733
- var isIElt11 = /Trident\/[456]\./.test(ua);
1734
- var isPresto = !!win.opera;
1735
- var isEdge = /Edge\//.test(ua);
1736
- var isWebKit = !isEdge && /WebKit\//.test(ua);
1737
- var isIE = /Trident\/[4567]\./.test(ua);
1738
- var ctrlKey = isMac ? "meta-" : "ctrl-";
1739
- var useTextFixer = isIElt11 || isPresto;
1740
- var cantFocusEmptyTextNodes = isIElt11 || isWebKit;
1741
- var losesSelectionOnBlur = isIElt11;
1742
- var canObserveMutations = typeof MutationObserver !== "undefined";
1743
- var canWeakMap = typeof WeakMap !== "undefined";
1744
- var notWS = /[^ \t\r\n]/;
1745
- var indexOf = Array.prototype.indexOf;
1746
- if (!Object.create) {
1747
- Object.create = function(proto2) {
1748
- var F = function() {
1749
- };
1750
- F.prototype = proto2;
1751
- return new F();
1712
+ const Editor_vue_vue_type_style_index_0_lang = "";
1713
+ const cursorImg = `url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACIAAAAYCAMAAACoeN87AAAAh1BMVEUAAAACAgL39/cICAgFBQUAAAADAwMKCgr6+vrn5+fr6+v6+voEBAT19fXm5ubf39+pqanBwcH8/PzOzs76+vrx8fHz8/P29vbh4eHm5ubT09OXl5f///9ZWVkiIiLIyMjGxsY+Pj5LS0uenp4vLy/V1dXk5OSsrKxnZ2eRkZF1dXXj4+ODg4P4y9kGAAAAHHRSTlMACMUDDQYOCuONi8MSt2tJMCryT9OpqKaRezobrP6h8wAAAR9JREFUKM+dk1lygzAMQOMtxoQlS/dKBrMn7f3PVwEFPND0I+/Dg8RD0mjM7nGEZoIOqfwc+0jTVE+RgcAcTQBvbFFOvM7zJvgcIw2uaKF0DuRS5LW1RBmKMQyhdugyMGJWGMciywrkauobZrY2kgxPQQCcFGIPFvb+sNGkSLUo3iDqEvPzqJz5IVF/KEnTIVak0IG35rJV1OFGr7AEKJHULh7KRKRE86gHLPKZAjnrkwEpgV4U6zEqEugRpL+TmXtVEGaQlO0sfK1sVnds7Pf/yim42q9FccjVai/q5WornKlsm4hVFRGX6NFlT7rPSlPb3GgxNnrmHvF7nxYh5A5dDaEaWzGf4TsGzpXQFsut2yDC37tr1O4eSurhD6CaPzWzJeCQ3tPtAAAAAElFTkSuQmCC) 28 10, text`;
1714
+ const keyToEditorMethod = {
1715
+ bold: "bold",
1716
+ italic: "italic",
1717
+ underline: "underline",
1718
+ size: "setFontSize",
1719
+ color: "setTextColour"
1720
+ };
1721
+ const _sfc_main = {
1722
+ name: "Edit",
1723
+ components: {
1724
+ InsertArticle: _sfc_main$5,
1725
+ ImgUpload: _sfc_main$4,
1726
+ VideoUpload,
1727
+ CollectArticle
1728
+ },
1729
+ props: [
1730
+ "disabled",
1731
+ "isOss",
1732
+ "getEassyDetail",
1733
+ "getArticleList",
1734
+ "importEssay",
1735
+ "uploadImageByOther"
1736
+ ],
1737
+ data() {
1738
+ return {
1739
+ hasArticleCard: false,
1740
+ cursorStyle: "auto",
1741
+ titleCount: 0,
1742
+ viewLinkDialog: false,
1743
+ linkForm: {
1744
+ linkAddress: "",
1745
+ linkWriting: ""
1746
+ },
1747
+ setAlignFlag: true,
1748
+ article: {},
1749
+ imgList: [],
1750
+ videoList: [],
1751
+ visibleVideo: false,
1752
+ visibleCollectArticle: false,
1753
+ visibleArticle: false,
1754
+ visibleImg: false,
1755
+ imgType: "normal",
1756
+ typeEnum: {
1757
+ "\u6587\u5B57": "1",
1758
+ "\u56FE\u7247": "2",
1759
+ "\u56FE\u6587": "3",
1760
+ "\u6BB5\u843D\u6807\u9898": "4",
1761
+ "\u5173\u8054": "5",
1762
+ "\u5355\u89C6\u9891": "6",
1763
+ "\u89C6\u9891\u6587\u5B57": "7",
1764
+ "URL": "8",
1765
+ "\u6587\u7AE0\u5361\u7247": "11"
1766
+ },
1767
+ fontInfo: {
1768
+ size: ""
1769
+ },
1770
+ user: {},
1771
+ editor: {},
1772
+ editorDom: {},
1773
+ uploadStore: {},
1774
+ linkContent: "",
1775
+ loadingText: "",
1776
+ progressPercent: "",
1777
+ currentIndex: 0,
1778
+ loading: false,
1779
+ viewStatus: false,
1780
+ linkStatus: false,
1781
+ styleStatus: {
1782
+ bold: false,
1783
+ italic: false,
1784
+ size: "",
1785
+ color: "",
1786
+ underline: false,
1787
+ title: false
1788
+ },
1789
+ contentLen: 0,
1790
+ imgCount: 0,
1791
+ backState: {
1792
+ redo: false,
1793
+ undo: false
1794
+ },
1795
+ countList: [],
1796
+ replaceSeamless: 0,
1797
+ seamlessCount: 0
1752
1798
  };
1753
- }
1754
- var typeToBitArray = {
1755
- 1: 1,
1756
- 2: 2,
1757
- 3: 4,
1758
- 8: 128,
1759
- 9: 256,
1760
- 11: 1024
1761
- };
1762
- function TreeWalker(root, nodeType, filter) {
1763
- this.root = this.currentNode = root;
1764
- this.nodeType = nodeType;
1765
- this.filter = filter;
1766
- }
1767
- TreeWalker.prototype.nextNode = function() {
1768
- var current = this.currentNode, root = this.root, nodeType = this.nodeType, filter = this.filter, node;
1769
- while (true) {
1770
- node = current.firstChild;
1771
- while (!node && current) {
1772
- if (current === root) {
1773
- break;
1774
- }
1775
- node = current.nextSibling;
1776
- if (!node) {
1777
- current = current.parentNode;
1778
- }
1779
- }
1780
- if (!node) {
1781
- return null;
1782
- }
1783
- if (typeToBitArray[node.nodeType] & nodeType && filter(node)) {
1784
- this.currentNode = node;
1785
- return node;
1786
- }
1787
- current = node;
1788
- }
1789
- };
1790
- TreeWalker.prototype.previousNode = function() {
1791
- var current = this.currentNode, root = this.root, nodeType = this.nodeType, filter = this.filter, node;
1792
- while (true) {
1793
- if (current === root) {
1794
- return null;
1795
- }
1796
- node = current.previousSibling;
1797
- if (node) {
1798
- while (current = node.lastChild) {
1799
- node = current;
1800
- }
1801
- } else {
1802
- node = current.parentNode;
1803
- }
1804
- if (!node) {
1805
- return null;
1806
- }
1807
- if (typeToBitArray[node.nodeType] & nodeType && filter(node)) {
1808
- this.currentNode = node;
1809
- return node;
1810
- }
1811
- current = node;
1812
- }
1813
- };
1814
- TreeWalker.prototype.previousPONode = function() {
1815
- var current = this.currentNode, root = this.root, nodeType = this.nodeType, filter = this.filter, node;
1816
- while (true) {
1817
- node = current.lastChild;
1818
- while (!node && current) {
1819
- if (current === root) {
1820
- break;
1821
- }
1822
- node = current.previousSibling;
1823
- if (!node) {
1824
- current = current.parentNode;
1825
- }
1826
- }
1827
- if (!node) {
1828
- return null;
1829
- }
1830
- if (typeToBitArray[node.nodeType] & nodeType && filter(node)) {
1831
- this.currentNode = node;
1832
- return node;
1833
- }
1834
- current = node;
1835
- }
1836
- };
1837
- var inlineNodeNames = /^(?:#text|A(?:BBR|CRONYM)?|B(?:R|D[IO])?|C(?:ITE|ODE)|D(?:ATA|EL|FN)|EM|FONT|HR|I(?:FRAME|MG|NPUT|NS)?|KBD|Q|R(?:P|T|UBY)|S(?:AMP|MALL|PAN|TR(?:IKE|ONG)|U[BP])?|TIME|U|VAR|WBR)$/;
1838
- var leafNodeNames = {
1839
- BR: 1,
1840
- HR: 1,
1841
- IFRAME: 1,
1842
- IMG: 1,
1843
- INPUT: 1
1844
- };
1845
- function every(nodeList, fn) {
1846
- var l = nodeList.length;
1847
- while (l--) {
1848
- if (!fn(nodeList[l])) {
1849
- return false;
1850
- }
1851
- }
1852
- return true;
1853
- }
1854
- var UNKNOWN = 0;
1855
- var INLINE = 1;
1856
- var BLOCK = 2;
1857
- var CONTAINER = 3;
1858
- var nodeCategoryCache = canWeakMap ? /* @__PURE__ */ new WeakMap() : null;
1859
- function isLeaf(node) {
1860
- return node.nodeType === ELEMENT_NODE && !!leafNodeNames[node.nodeName];
1861
- }
1862
- function getNodeCategory(node) {
1863
- switch (node.nodeType) {
1864
- case TEXT_NODE:
1865
- return INLINE;
1866
- case ELEMENT_NODE:
1867
- case DOCUMENT_FRAGMENT_NODE:
1868
- if (canWeakMap && nodeCategoryCache.has(node)) {
1869
- return nodeCategoryCache.get(node);
1870
- }
1871
- break;
1872
- default:
1873
- return UNKNOWN;
1874
- }
1875
- var nodeCategory;
1876
- if (!every(node.childNodes, isInline)) {
1877
- nodeCategory = CONTAINER;
1878
- } else if (inlineNodeNames.test(node.nodeName)) {
1879
- nodeCategory = INLINE;
1880
- } else {
1881
- nodeCategory = BLOCK;
1882
- }
1883
- if (canWeakMap) {
1884
- nodeCategoryCache.set(node, nodeCategory);
1885
- }
1886
- return nodeCategory;
1887
- }
1888
- function isInline(node) {
1889
- return getNodeCategory(node) === INLINE;
1890
- }
1891
- function isBlock(node) {
1892
- return getNodeCategory(node) === BLOCK;
1893
- }
1894
- function isContainer(node) {
1895
- return getNodeCategory(node) === CONTAINER;
1896
- }
1897
- function getBlockWalker(node, root) {
1898
- var walker2 = new TreeWalker(root, SHOW_ELEMENT, isBlock);
1899
- walker2.currentNode = node;
1900
- return walker2;
1901
- }
1902
- function getPreviousBlock(node, root) {
1903
- node = getBlockWalker(node, root).previousNode();
1904
- return node !== root ? node : null;
1905
- }
1906
- function getNextBlock(node, root) {
1907
- node = getBlockWalker(node, root).nextNode();
1908
- return node !== root ? node : null;
1909
- }
1910
- function isEmptyBlock(block) {
1911
- return !block.textContent && !block.querySelector("IMG");
1912
- }
1913
- function areAlike(node, node2) {
1914
- return !isLeaf(node) && (node.nodeType === node2.nodeType && node.nodeName === node2.nodeName && node.nodeName !== "A" && node.className === node2.className && (!node.style && !node2.style || node.style.cssText === node2.style.cssText));
1915
- }
1916
- function hasTagAttributes(node, tag, attributes) {
1917
- if (node.nodeName !== tag) {
1918
- return false;
1919
- }
1920
- for (var attr in attributes) {
1921
- if (node.getAttribute(attr) !== attributes[attr]) {
1922
- return false;
1923
- }
1924
- }
1925
- return true;
1926
- }
1927
- function getNearest(node, root, tag, attributes) {
1928
- while (node && node !== root && tag !== "SPAN") {
1929
- if (hasTagAttributes(node, tag, attributes)) {
1930
- return node;
1931
- }
1932
- node = node.parentNode;
1933
- }
1934
- return null;
1935
- }
1936
- function isOrContains(parent, node) {
1937
- while (node) {
1938
- if (node === parent) {
1939
- return true;
1940
- }
1941
- node = node.parentNode;
1942
- }
1943
- return false;
1944
- }
1945
- function getPath(node, root) {
1946
- var path = "";
1947
- var id, className, classNames, dir;
1948
- if (node && node !== root) {
1949
- path = getPath(node.parentNode, root);
1950
- if (node.nodeType === ELEMENT_NODE) {
1951
- path += (path ? ">" : "") + node.nodeName;
1952
- if (id = node.id) {
1953
- path += "#" + id;
1954
- }
1955
- if (className = node.className.trim()) {
1956
- classNames = className.split(/\s\s*/);
1957
- classNames.sort();
1958
- path += ".";
1959
- path += classNames.join(".");
1960
- }
1961
- if (dir = node.dir) {
1962
- path += "[dir=" + dir + "]";
1963
- }
1964
- if (classNames) {
1965
- if (indexOf.call(classNames, HIGHLIGHT_CLASS) > -1) {
1966
- path += "[backgroundColor=" + node.style.backgroundColor.replace(/ /g, "") + "]";
1967
- }
1968
- if (indexOf.call(classNames, COLOUR_CLASS) > -1) {
1969
- path += "[color=" + node.style.color.replace(/ /g, "") + "]";
1970
- }
1971
- if (indexOf.call(classNames, FONT_FAMILY_CLASS) > -1) {
1972
- path += "[fontFamily=" + node.style.fontFamily.replace(/ /g, "") + "]";
1973
- }
1974
- if (indexOf.call(classNames, FONT_SIZE_CLASS) > -1) {
1975
- path += "[fontSize=" + node.style.fontSize + "]";
1976
- }
1977
- }
1978
- }
1979
- }
1980
- return path;
1981
- }
1982
- function getLength(node) {
1983
- var nodeType = node.nodeType;
1984
- return nodeType === ELEMENT_NODE || nodeType === DOCUMENT_FRAGMENT_NODE ? node.childNodes.length : node.length || 0;
1985
- }
1986
- function detach(node) {
1987
- var parent = node.parentNode;
1988
- if (parent) {
1989
- parent.removeChild(node);
1990
- }
1991
- return node;
1992
- }
1993
- function replaceWith(node, node2) {
1994
- var parent = node.parentNode;
1995
- if (parent) {
1996
- parent.replaceChild(node2, node);
1997
- }
1998
- }
1999
- function empty(node) {
2000
- var frag = node.ownerDocument.createDocumentFragment(), childNodes = node.childNodes, l = childNodes ? childNodes.length : 0;
2001
- while (l--) {
2002
- frag.appendChild(node.firstChild);
2003
- }
2004
- return frag;
2005
- }
2006
- function createElement(doc2, tag, props, children) {
2007
- var el = doc2.createElement(tag), attr, value, i, l;
2008
- if (props instanceof Array) {
2009
- children = props;
2010
- props = null;
2011
- }
2012
- if (props) {
2013
- for (attr in props) {
2014
- value = props[attr];
2015
- if (value !== undefined$1) {
2016
- el.setAttribute(attr, props[attr]);
2017
- }
2018
- }
2019
- }
2020
- if (children) {
2021
- for (i = 0, l = children.length; i < l; i += 1) {
2022
- el.appendChild(children[i]);
2023
- }
2024
- }
2025
- return el;
2026
- }
2027
- function fixCursor(node, root) {
2028
- var self2 = root.__squire__;
2029
- var doc2 = node.ownerDocument;
2030
- var originalNode = node;
2031
- var fixer, child;
2032
- if (node === root) {
2033
- if (!(child = node.firstChild) || child.nodeName === "BR") {
2034
- fixer = self2.createDefaultBlock();
2035
- if (child) {
2036
- node.replaceChild(fixer, child);
2037
- } else {
2038
- node.appendChild(fixer);
2039
- }
2040
- node = fixer;
2041
- fixer = null;
2042
- }
2043
- }
2044
- if (node.nodeType === TEXT_NODE) {
2045
- return originalNode;
2046
- }
2047
- if (isInline(node)) {
2048
- child = node.firstChild;
2049
- while (cantFocusEmptyTextNodes && child && child.nodeType === TEXT_NODE && !child.data) {
2050
- node.removeChild(child);
2051
- child = node.firstChild;
2052
- }
2053
- if (!child) {
2054
- if (cantFocusEmptyTextNodes) {
2055
- fixer = doc2.createTextNode(ZWS);
2056
- self2._didAddZWS();
2057
- } else {
2058
- fixer = doc2.createTextNode("");
2059
- }
2060
- }
2061
- } else {
2062
- if (useTextFixer) {
2063
- while (node.nodeType !== TEXT_NODE && !isLeaf(node)) {
2064
- child = node.firstChild;
2065
- if (!child) {
2066
- fixer = doc2.createTextNode("");
2067
- break;
2068
- }
2069
- node = child;
2070
- }
2071
- if (node.nodeType === TEXT_NODE) {
2072
- if (/^ +$/.test(node.data)) {
2073
- node.data = "";
2074
- }
2075
- } else if (isLeaf(node)) {
2076
- node.parentNode.insertBefore(doc2.createTextNode(""), node);
2077
- }
2078
- } else if (!node.querySelector("BR")) {
2079
- fixer = createElement(doc2, "BR");
2080
- while ((child = node.lastElementChild) && !isInline(child)) {
2081
- node = child;
2082
- }
2083
- }
2084
- }
2085
- if (fixer) {
2086
- try {
2087
- node.appendChild(fixer);
2088
- } catch (error) {
2089
- self2.didError({
2090
- name: "Squire: fixCursor \u2013\xA0" + error,
2091
- message: "Parent: " + node.nodeName + "/" + node.innerHTML + " appendChild: " + fixer.nodeName
2092
- });
1799
+ },
1800
+ computed: {
1801
+ align() {
1802
+ if (!this.isInputing && !this.titleCount && !this.hasArticleCard) {
1803
+ return this.getCursorAlignStyle() || "left";
2093
1804
  }
1805
+ return "left";
1806
+ },
1807
+ isInputing() {
1808
+ return this.contentLen > 0 || this.imgCount > 0;
2094
1809
  }
2095
- return originalNode;
2096
- }
2097
- function fixContainer(container, root) {
2098
- var children = container.childNodes;
2099
- var doc2 = container.ownerDocument;
2100
- var wrapper = null;
2101
- var i, l, child, isBR;
2102
- var config = root.__squire__._config;
2103
- for (i = 0, l = children.length; i < l; i += 1) {
2104
- child = children[i];
2105
- isBR = child.nodeName === "BR";
2106
- if (!isBR && isInline(child)) {
2107
- if (child.classList && child.classList.contains("halo-picture-area")) {
2108
- return;
2109
- }
2110
- if (!wrapper) {
2111
- wrapper = createElement(
2112
- doc2,
2113
- config.blockTag,
2114
- config.blockAttributes
2115
- );
2116
- }
2117
- wrapper.appendChild(child);
2118
- i -= 1;
2119
- l -= 1;
2120
- } else if (isBR || wrapper) {
2121
- if (!wrapper) {
2122
- wrapper = createElement(
2123
- doc2,
2124
- config.blockTag,
2125
- config.blockAttributes
2126
- );
2127
- }
2128
- fixCursor(wrapper, root);
2129
- if (isBR) {
2130
- container.replaceChild(wrapper, child);
2131
- } else {
2132
- container.insertBefore(wrapper, child);
2133
- i += 1;
2134
- l += 1;
1810
+ },
1811
+ watch: {
1812
+ progressPercent(val) {
1813
+ const inner = document.querySelector(".video-progress .inner");
1814
+ console.log(val, "\u89C6\u9891\u4E0A\u4F20\u8FDB\u5EA6");
1815
+ if (inner) {
1816
+ inner.style.width = val + "%";
1817
+ if (val === 100) {
1818
+ document.querySelector(".video-progress").innerHTML = `
1819
+ <div class="no-calc" style="text-align:center;color:#999999;font-size:18px;">\u6B63\u5728\u83B7\u53D6\u89C6\u9891\u5C01\u9762</div>
1820
+ `;
2135
1821
  }
2136
- wrapper = null;
2137
- }
2138
- if (isContainer(child)) {
2139
- fixContainer(child, root);
2140
- }
2141
- }
2142
- if (wrapper) {
2143
- container.appendChild(fixCursor(wrapper, root));
2144
- }
2145
- return container;
2146
- }
2147
- function split(node, offset, stopNode, root) {
2148
- var nodeType = node.nodeType, parent, clone, next;
2149
- if (nodeType === TEXT_NODE && node !== stopNode) {
2150
- return split(
2151
- node.parentNode,
2152
- node.splitText(offset),
2153
- stopNode,
2154
- root
2155
- );
2156
- }
2157
- if (nodeType === ELEMENT_NODE) {
2158
- if (typeof offset === "number") {
2159
- offset = offset < node.childNodes.length ? node.childNodes[offset] : null;
2160
- }
2161
- if (node === stopNode) {
2162
- return offset;
2163
- }
2164
- parent = node.parentNode;
2165
- clone = node.cloneNode(false);
2166
- while (offset) {
2167
- next = offset.nextSibling;
2168
- clone.appendChild(offset);
2169
- offset = next;
2170
- }
2171
- if (node.nodeName === "OL" && getNearest(node, root, "BLOCKQUOTE")) {
2172
- clone.start = (+node.start || 1) + node.childNodes.length - 1;
2173
1822
  }
2174
- fixCursor(node, root);
2175
- fixCursor(clone, root);
2176
- if (next = node.nextSibling) {
2177
- parent.insertBefore(clone, next);
2178
- } else {
2179
- parent.appendChild(clone);
2180
- }
2181
- return split(parent, clone, stopNode, root);
2182
- }
2183
- return offset;
2184
- }
2185
- function _mergeInlines(node, fakeRange) {
2186
- var children = node.childNodes, l = children.length, frags = [], child, prev, len;
2187
- while (l--) {
2188
- child = children[l];
2189
- prev = l && children[l - 1];
2190
- if (l && isInline(child) && areAlike(child, prev) && !leafNodeNames[child.nodeName]) {
2191
- if (fakeRange.startContainer === child) {
2192
- fakeRange.startContainer = prev;
2193
- fakeRange.startOffset += getLength(prev);
2194
- }
2195
- if (fakeRange.endContainer === child) {
2196
- fakeRange.endContainer = prev;
2197
- fakeRange.endOffset += getLength(prev);
2198
- }
2199
- if (fakeRange.startContainer === node) {
2200
- if (fakeRange.startOffset > l) {
2201
- fakeRange.startOffset -= 1;
2202
- } else if (fakeRange.startOffset === l) {
2203
- fakeRange.startContainer = prev;
2204
- fakeRange.startOffset = getLength(prev);
2205
- }
2206
- }
2207
- if (fakeRange.endContainer === node) {
2208
- if (fakeRange.endOffset > l) {
2209
- fakeRange.endOffset -= 1;
2210
- } else if (fakeRange.endOffset === l) {
2211
- fakeRange.endContainer = prev;
2212
- fakeRange.endOffset = getLength(prev);
2213
- }
2214
- }
2215
- detach(child);
2216
- if (child.nodeType === TEXT_NODE) {
2217
- prev.appendData(child.data);
2218
- } else {
2219
- frags.push(empty(child));
2220
- }
2221
- } else if (child.nodeType === ELEMENT_NODE) {
2222
- len = frags.length;
2223
- while (len--) {
2224
- child.appendChild(frags.pop());
1823
+ },
1824
+ disabled: {
1825
+ handler(val) {
1826
+ if (val) {
1827
+ this.editorDom.contentEditable = "false";
2225
1828
  }
2226
- _mergeInlines(child, fakeRange);
2227
- }
2228
- }
2229
- }
2230
- function mergeInlines(node, range) {
2231
- if (node.nodeType === TEXT_NODE) {
2232
- node = node.parentNode;
2233
- }
2234
- if (node.nodeType === ELEMENT_NODE) {
2235
- var fakeRange = {
2236
- startContainer: range.startContainer,
2237
- startOffset: range.startOffset,
2238
- endContainer: range.endContainer,
2239
- endOffset: range.endOffset
2240
- };
2241
- _mergeInlines(node, fakeRange);
2242
- range.setStart(fakeRange.startContainer, fakeRange.startOffset);
2243
- range.setEnd(fakeRange.endContainer, fakeRange.endOffset);
2244
- }
2245
- }
2246
- function mergeWithBlock(block, next, range, root) {
2247
- var container = next;
2248
- var parent, last, offset;
2249
- while ((parent = container.parentNode) && parent !== root && parent.nodeType === ELEMENT_NODE && parent.childNodes.length === 1) {
2250
- container = parent;
2251
- }
2252
- detach(container);
2253
- offset = block.childNodes.length;
2254
- last = block.lastChild;
2255
- if (last && last.nodeName === "BR") {
2256
- block.removeChild(last);
2257
- offset -= 1;
2258
- }
2259
- block.appendChild(empty(next));
2260
- range.setStart(block, offset);
2261
- range.collapse(true);
2262
- mergeInlines(block, range);
2263
- if (isPresto && (last = block.lastChild) && last.nodeName === "BR") {
2264
- block.removeChild(last);
2265
- }
2266
- }
2267
- function mergeContainers(node, root) {
2268
- var prev = node.previousSibling, first = node.firstChild, doc2 = node.ownerDocument, isListItem = node.nodeName === "LI", needsFix, block;
2269
- if (isListItem && (!first || !/^[OU]L$/.test(first.nodeName))) {
2270
- return;
2271
- }
2272
- if (prev && areAlike(prev, node)) {
2273
- if (!isContainer(prev)) {
2274
- if (isListItem) {
2275
- block = createElement(doc2, "DIV");
2276
- block.appendChild(empty(prev));
2277
- prev.appendChild(block);
2278
- } else {
2279
- return;
2280
- }
2281
- }
2282
- detach(node);
2283
- needsFix = !isContainer(node);
2284
- prev.appendChild(empty(node));
2285
- if (needsFix) {
2286
- fixContainer(prev, root);
2287
- }
2288
- if (first) {
2289
- mergeContainers(first, root);
2290
- }
2291
- } else if (isListItem) {
2292
- prev = createElement(doc2, "DIV");
2293
- node.insertBefore(prev, first);
2294
- fixCursor(prev, root);
2295
- }
2296
- }
2297
- var getNodeBefore = function(node, offset) {
2298
- var children = node.childNodes;
2299
- while (offset && node.nodeType === ELEMENT_NODE) {
2300
- node = children[offset - 1];
2301
- children = node.childNodes;
2302
- offset = children.length;
2303
- }
2304
- return node;
2305
- };
2306
- var getNodeAfter = function(node, offset) {
2307
- if (node.nodeType === ELEMENT_NODE) {
2308
- var children = node.childNodes;
2309
- if (offset < children.length) {
2310
- node = children[offset];
2311
- } else {
2312
- while (node && !node.nextSibling) {
2313
- node = node.parentNode;
2314
- }
2315
- if (node) {
2316
- node = node.nextSibling;
2317
- }
2318
- }
2319
- }
2320
- return node;
2321
- };
2322
- var insertNodeInRange = function(range, node) {
2323
- var startContainer = range.startContainer, startOffset = range.startOffset, endContainer = range.endContainer, endOffset = range.endOffset, parent, children, childCount, afterSplit;
2324
- if (startContainer.nodeType === TEXT_NODE) {
2325
- parent = startContainer.parentNode;
2326
- children = parent.childNodes;
2327
- if (startOffset === startContainer.length) {
2328
- startOffset = indexOf.call(children, startContainer) + 1;
2329
- if (range.collapsed) {
2330
- endContainer = parent;
2331
- endOffset = startOffset;
2332
- }
2333
- } else {
2334
- if (startOffset) {
2335
- afterSplit = startContainer.splitText(startOffset);
2336
- if (endContainer === startContainer) {
2337
- endOffset -= startOffset;
2338
- endContainer = afterSplit;
2339
- } else if (endContainer === parent) {
2340
- endOffset += 1;
2341
- }
2342
- startContainer = afterSplit;
2343
- }
2344
- startOffset = indexOf.call(children, startContainer);
2345
- }
2346
- startContainer = parent;
2347
- } else {
2348
- children = startContainer.childNodes;
2349
- }
2350
- childCount = children.length;
2351
- if (startOffset === childCount) {
2352
- startContainer.appendChild(node);
2353
- } else {
2354
- startContainer.insertBefore(node, children[startOffset]);
2355
- }
2356
- if (startContainer === endContainer) {
2357
- endOffset += children.length - childCount;
2358
- }
2359
- range.setStart(startContainer, startOffset);
2360
- range.setEnd(endContainer, endOffset);
2361
- };
2362
- var extractContentsOfRange = function(range, common, root) {
2363
- var startContainer = range.startContainer, startOffset = range.startOffset, endContainer = range.endContainer, endOffset = range.endOffset;
2364
- if (!common) {
2365
- common = range.commonAncestorContainer;
2366
- }
2367
- if (common.nodeType === TEXT_NODE) {
2368
- common = common.parentNode;
2369
- }
2370
- var endNode = split(endContainer, endOffset, common, root), startNode = split(startContainer, startOffset, common, root), frag = common.ownerDocument.createDocumentFragment(), next, before, after;
2371
- while (startNode !== endNode) {
2372
- next = startNode.nextSibling;
2373
- frag.appendChild(startNode);
2374
- startNode = next;
2375
- }
2376
- startContainer = common;
2377
- startOffset = endNode ? indexOf.call(common.childNodes, endNode) : common.childNodes.length;
2378
- after = common.childNodes[startOffset];
2379
- before = after && after.previousSibling;
2380
- if (before && before.nodeType === TEXT_NODE && after.nodeType === TEXT_NODE) {
2381
- startContainer = before;
2382
- startOffset = before.length;
2383
- before.appendData(after.data);
2384
- detach(after);
2385
- }
2386
- range.setStart(startContainer, startOffset);
2387
- range.collapse(true);
2388
- fixCursor(common, root);
2389
- return frag;
2390
- };
2391
- var deleteContentsOfRange = function(range, root) {
2392
- var startBlock = getStartBlockOfRange(range, root);
2393
- var endBlock = getEndBlockOfRange(range, root);
2394
- var needsMerge = startBlock !== endBlock;
2395
- var frag, child;
2396
- moveRangeBoundariesDownTree(range);
2397
- moveRangeBoundariesUpTree(range, startBlock, endBlock, root);
2398
- frag = extractContentsOfRange(range, null, root);
2399
- moveRangeBoundariesDownTree(range);
2400
- if (needsMerge) {
2401
- endBlock = getEndBlockOfRange(range, root);
2402
- if (startBlock && endBlock && startBlock !== endBlock) {
2403
- mergeWithBlock(startBlock, endBlock, range, root);
2404
- }
2405
- }
2406
- if (startBlock) {
2407
- fixCursor(startBlock, root);
2408
- }
2409
- child = root.firstChild;
2410
- if (!child || child.nodeName === "BR") {
2411
- fixCursor(root, root);
2412
- range.selectNodeContents(root.firstChild);
2413
- } else {
2414
- range.collapse(true);
2415
- }
2416
- return frag;
2417
- };
2418
- var insertTreeFragmentIntoRange = function(range, frag, root) {
2419
- var node, block, blockContentsAfterSplit, stopPoint, container, offset;
2420
- var replaceBlock, firstBlockInFrag, nodeAfterSplit, nodeBeforeSplit;
2421
- var tempRange;
2422
- fixContainer(frag, root);
2423
- node = frag;
2424
- while (node = getNextBlock(node, root)) {
2425
- fixCursor(node, root);
2426
- }
2427
- if (!range.collapsed) {
2428
- deleteContentsOfRange(range, root);
2429
- }
2430
- moveRangeBoundariesDownTree(range);
2431
- range.collapse(false);
2432
- stopPoint = getNearest(range.endContainer, root, "BLOCKQUOTE") || root;
2433
- block = getStartBlockOfRange(range, root);
2434
- firstBlockInFrag = getNextBlock(frag, frag);
2435
- replaceBlock = !!block && isEmptyBlock(block);
2436
- if (block && firstBlockInFrag && !replaceBlock && !getNearest(firstBlockInFrag, frag, "PRE") && !getNearest(firstBlockInFrag, frag, "TABLE")) {
2437
- moveRangeBoundariesUpTree(range, block, block, root);
2438
- range.collapse(true);
2439
- container = range.endContainer;
2440
- offset = range.endOffset;
2441
- cleanupBRs(block, root, false);
2442
- if (isInline(container)) {
2443
- nodeAfterSplit = split(
2444
- container,
2445
- offset,
2446
- getPreviousBlock(container, root),
2447
- root
2448
- );
2449
- container = nodeAfterSplit.parentNode;
2450
- offset = indexOf.call(container.childNodes, nodeAfterSplit);
2451
- }
2452
- if (offset !== getLength(container)) {
2453
- blockContentsAfterSplit = root.ownerDocument.createDocumentFragment();
2454
- while (node = container.childNodes[offset]) {
2455
- blockContentsAfterSplit.appendChild(node);
2456
- }
2457
- }
2458
- mergeWithBlock(container, firstBlockInFrag, range, root);
2459
- offset = indexOf.call(container.parentNode.childNodes, container) + 1;
2460
- container = container.parentNode;
2461
- range.setEnd(container, offset);
2462
- }
2463
- if (getLength(frag)) {
2464
- if (replaceBlock) {
2465
- range.setEndBefore(block);
2466
- range.collapse(false);
2467
- detach(block);
2468
- }
2469
- moveRangeBoundariesUpTree(range, stopPoint, stopPoint, root);
2470
- nodeAfterSplit = split(
2471
- range.endContainer,
2472
- range.endOffset,
2473
- stopPoint,
2474
- root
2475
- );
2476
- nodeBeforeSplit = nodeAfterSplit ? nodeAfterSplit.previousSibling : stopPoint.lastChild;
2477
- stopPoint.insertBefore(frag, nodeAfterSplit);
2478
- if (nodeAfterSplit) {
2479
- range.setEndBefore(nodeAfterSplit);
2480
- } else {
2481
- range.setEnd(stopPoint, getLength(stopPoint));
2482
- }
2483
- block = getEndBlockOfRange(range, root);
2484
- moveRangeBoundariesDownTree(range);
2485
- container = range.endContainer;
2486
- offset = range.endOffset;
2487
- if (nodeAfterSplit && isContainer(nodeAfterSplit)) {
2488
- mergeContainers(nodeAfterSplit, root);
2489
- }
2490
- nodeAfterSplit = nodeBeforeSplit && nodeBeforeSplit.nextSibling;
2491
- if (nodeAfterSplit && isContainer(nodeAfterSplit)) {
2492
- mergeContainers(nodeAfterSplit, root);
2493
- }
2494
- range.setEnd(container, offset);
2495
- }
2496
- if (blockContentsAfterSplit) {
2497
- tempRange = range.cloneRange();
2498
- mergeWithBlock(block, blockContentsAfterSplit, tempRange, root);
2499
- range.setEnd(tempRange.endContainer, tempRange.endOffset);
2500
- }
2501
- moveRangeBoundariesDownTree(range);
2502
- };
2503
- var isNodeContainedInRange = function(range, node, partial) {
2504
- var nodeRange = node.ownerDocument.createRange();
2505
- nodeRange.selectNode(node);
2506
- if (partial) {
2507
- var nodeEndBeforeStart = range.compareBoundaryPoints(
2508
- END_TO_START,
2509
- nodeRange
2510
- ) > -1, nodeStartAfterEnd = range.compareBoundaryPoints(
2511
- START_TO_END,
2512
- nodeRange
2513
- ) < 1;
2514
- return !nodeEndBeforeStart && !nodeStartAfterEnd;
2515
- } else {
2516
- var nodeStartAfterStart = range.compareBoundaryPoints(
2517
- START_TO_START,
2518
- nodeRange
2519
- ) < 1, nodeEndBeforeEnd = range.compareBoundaryPoints(
2520
- END_TO_END,
2521
- nodeRange
2522
- ) > -1;
2523
- return nodeStartAfterStart && nodeEndBeforeEnd;
2524
- }
2525
- };
2526
- var moveRangeBoundariesDownTree = function(range) {
2527
- var startContainer = range.startContainer, startOffset = range.startOffset, endContainer = range.endContainer, endOffset = range.endOffset, maySkipBR = true, child;
2528
- while (startContainer.nodeType !== TEXT_NODE) {
2529
- child = startContainer.childNodes[startOffset];
2530
- if (!child || isLeaf(child)) {
2531
- break;
2532
- }
2533
- startContainer = child;
2534
- startOffset = 0;
2535
- }
2536
- if (endOffset) {
2537
- while (endContainer.nodeType !== TEXT_NODE) {
2538
- child = endContainer.childNodes[endOffset - 1];
2539
- if (!child || isLeaf(child)) {
2540
- if (maySkipBR && child && child.nodeName === "BR") {
2541
- endOffset -= 1;
2542
- maySkipBR = false;
2543
- continue;
2544
- }
2545
- break;
2546
- }
2547
- endContainer = child;
2548
- endOffset = getLength(endContainer);
2549
- }
2550
- } else {
2551
- while (endContainer.nodeType !== TEXT_NODE) {
2552
- child = endContainer.firstChild;
2553
- if (!child || isLeaf(child)) {
2554
- break;
2555
- }
2556
- endContainer = child;
2557
- }
2558
- }
2559
- if (range.collapsed) {
2560
- range.setStart(endContainer, endOffset);
2561
- range.setEnd(startContainer, startOffset);
2562
- } else {
2563
- range.setStart(startContainer, startOffset);
2564
- range.setEnd(endContainer, endOffset);
2565
- }
2566
- };
2567
- var moveRangeBoundariesUpTree = function(range, startMax, endMax, root) {
2568
- var startContainer = range.startContainer;
2569
- var startOffset = range.startOffset;
2570
- var endContainer = range.endContainer;
2571
- var endOffset = range.endOffset;
2572
- var maySkipBR = true;
2573
- var parent;
2574
- if (!startMax) {
2575
- startMax = range.commonAncestorContainer;
2576
- }
2577
- if (!endMax) {
2578
- endMax = startMax;
2579
- }
2580
- while (!startOffset && startContainer !== startMax && startContainer !== root) {
2581
- parent = startContainer.parentNode;
2582
- startOffset = indexOf.call(parent.childNodes, startContainer);
2583
- startContainer = parent;
2584
- }
2585
- while (true) {
2586
- if (maySkipBR && endContainer.nodeType !== TEXT_NODE && endContainer.childNodes[endOffset] && endContainer.childNodes[endOffset].nodeName === "BR") {
2587
- endOffset += 1;
2588
- maySkipBR = false;
2589
- }
2590
- if (endContainer === endMax || endContainer === root || endOffset !== getLength(endContainer)) {
2591
- break;
2592
- }
2593
- parent = endContainer.parentNode;
2594
- endOffset = indexOf.call(parent.childNodes, endContainer) + 1;
2595
- endContainer = parent;
2596
- }
2597
- range.setStart(startContainer, startOffset);
2598
- range.setEnd(endContainer, endOffset);
2599
- };
2600
- var getStartBlockOfRange = function(range, root) {
2601
- var container = range.startContainer, block;
2602
- if (isInline(container)) {
2603
- block = getPreviousBlock(container, root);
2604
- } else if (container !== root && isBlock(container)) {
2605
- block = container;
2606
- } else {
2607
- block = getNodeBefore(container, range.startOffset);
2608
- block = getNextBlock(block, root);
2609
- }
2610
- return block && isNodeContainedInRange(range, block, true) ? block : null;
2611
- };
2612
- var getEndBlockOfRange = function(range, root) {
2613
- var container = range.endContainer, block, child;
2614
- if (isInline(container)) {
2615
- block = getPreviousBlock(container, root);
2616
- } else if (container !== root && isBlock(container)) {
2617
- block = container;
2618
- } else {
2619
- block = getNodeAfter(container, range.endOffset);
2620
- if (!block || !isOrContains(root, block)) {
2621
- block = root;
2622
- while (child = block.lastChild) {
2623
- block = child;
2624
- }
2625
- }
2626
- block = getPreviousBlock(block, root);
2627
- }
2628
- return block && isNodeContainedInRange(range, block, true) ? block : null;
2629
- };
2630
- var contentWalker = new TreeWalker(
2631
- null,
2632
- SHOW_TEXT | SHOW_ELEMENT,
2633
- function(node) {
2634
- return node.nodeType === TEXT_NODE ? notWS.test(node.data) : node.nodeName === "IMG";
2635
- }
2636
- );
2637
- var rangeDoesStartAtBlockBoundary = function(range, root) {
2638
- var startContainer = range.startContainer;
2639
- var startOffset = range.startOffset;
2640
- var nodeAfterCursor;
2641
- contentWalker.root = null;
2642
- if (startContainer.nodeType === TEXT_NODE) {
2643
- if (startOffset) {
2644
- return false;
2645
- }
2646
- nodeAfterCursor = startContainer;
2647
- } else {
2648
- nodeAfterCursor = getNodeAfter(startContainer, startOffset);
2649
- if (nodeAfterCursor && !isOrContains(root, nodeAfterCursor)) {
2650
- nodeAfterCursor = null;
2651
- }
2652
- if (!nodeAfterCursor) {
2653
- nodeAfterCursor = getNodeBefore(startContainer, startOffset);
2654
- if (nodeAfterCursor.nodeType === TEXT_NODE && nodeAfterCursor.length) {
2655
- return false;
2656
- }
2657
- }
2658
- }
2659
- contentWalker.currentNode = nodeAfterCursor;
2660
- contentWalker.root = getStartBlockOfRange(range, root);
2661
- return !contentWalker.previousNode();
2662
- };
2663
- var rangeDoesEndAtBlockBoundary = function(range, root) {
2664
- var endContainer = range.endContainer, endOffset = range.endOffset, length;
2665
- contentWalker.root = null;
2666
- if (endContainer.nodeType === TEXT_NODE) {
2667
- length = endContainer.data.length;
2668
- if (length && endOffset < length) {
2669
- return false;
2670
- }
2671
- contentWalker.currentNode = endContainer;
2672
- } else {
2673
- contentWalker.currentNode = getNodeBefore(endContainer, endOffset);
2674
- }
2675
- contentWalker.root = getEndBlockOfRange(range, root);
2676
- return !contentWalker.nextNode();
2677
- };
2678
- var expandRangeToBlockBoundaries = function(range, root) {
2679
- var start = getStartBlockOfRange(range, root), end = getEndBlockOfRange(range, root), parent;
2680
- if (start && end) {
2681
- parent = start.parentNode;
2682
- range.setStart(parent, indexOf.call(parent.childNodes, start));
2683
- parent = end.parentNode;
2684
- range.setEnd(parent, indexOf.call(parent.childNodes, end) + 1);
2685
- }
2686
- };
2687
- var keys = {
2688
- 8: "backspace",
2689
- 9: "tab",
2690
- 13: "enter",
2691
- 32: "space",
2692
- 33: "pageup",
2693
- 34: "pagedown",
2694
- 37: "left",
2695
- 39: "right",
2696
- 46: "delete",
2697
- 219: "[",
2698
- 221: "]"
2699
- };
2700
- var onKey = function(event) {
2701
- if (event.target.classList.contains("desc-input"))
2702
- return;
2703
- var code = event.keyCode, key = keys[code], modifiers = "", range = this.getSelection();
2704
- if (event.defaultPrevented) {
2705
- return;
2706
- }
2707
- if (!key) {
2708
- key = String.fromCharCode(code).toLowerCase();
2709
- if (!/^[A-Za-z0-9]$/.test(key)) {
2710
- key = "";
2711
- }
2712
- }
2713
- if (isPresto && event.which === 46) {
2714
- key = ".";
2715
- }
2716
- if (code > 111 && code < 124) {
2717
- key = "f" + (code - 111);
2718
- }
2719
- if (key !== "backspace" && key !== "delete") {
2720
- if (event.altKey) {
2721
- modifiers += "alt-";
2722
- }
2723
- if (event.ctrlKey) {
2724
- modifiers += "ctrl-";
2725
- }
2726
- if (event.metaKey) {
2727
- modifiers += "meta-";
2728
- }
2729
- }
2730
- if (event.shiftKey) {
2731
- modifiers += "shift-";
2732
- }
2733
- key = modifiers + key;
2734
- if (this._keyHandlers[key]) {
2735
- this._keyHandlers[key](this, event, range);
2736
- } else if (!range.collapsed && !event.ctrlKey && !event.metaKey && (event.key || key).length === 1) {
2737
- this.saveUndoState(range);
2738
- deleteContentsOfRange(range, this._root);
2739
- this._ensureBottomLine();
2740
- this.setSelection(range);
2741
- this._updatePath(range, true);
2742
- }
2743
- };
2744
- var mapKeyTo = function(method) {
2745
- return function(self2, event) {
2746
- event.preventDefault();
2747
- self2[method]();
2748
- };
2749
- };
2750
- var mapKeyToFormat = function(tag, remove) {
2751
- remove = remove || null;
2752
- return function(self2, event) {
2753
- event.preventDefault();
2754
- var range = self2.getSelection();
2755
- if (self2.hasFormat(tag, null, range)) {
2756
- self2.changeFormat(null, { tag }, range);
2757
- } else {
2758
- self2.changeFormat({ tag }, remove, range);
2759
- }
2760
- };
2761
- };
2762
- var afterDelete = function(self2, range) {
2763
- try {
2764
- if (!range) {
2765
- range = self2.getSelection();
2766
- }
2767
- var node = range.startContainer, parent;
2768
- if (node.nodeType === TEXT_NODE) {
2769
- node = node.parentNode;
2770
- }
2771
- parent = node;
2772
- while (isInline(parent) && (!parent.textContent || parent.textContent === ZWS)) {
2773
- node = parent;
2774
- parent = node.parentNode;
2775
- }
2776
- if (node !== parent) {
2777
- range.setStart(
2778
- parent,
2779
- indexOf.call(parent.childNodes, node)
2780
- );
2781
- range.collapse(true);
2782
- parent.removeChild(node);
2783
- if (!isBlock(parent)) {
2784
- parent = getPreviousBlock(parent, self2._root);
2785
- }
2786
- fixCursor(parent, self2._root);
2787
- moveRangeBoundariesDownTree(range);
2788
- }
2789
- if (node === self2._root && (node = node.firstChild) && node.nodeName === "BR") {
2790
- detach(node);
2791
- }
2792
- self2._ensureBottomLine();
2793
- self2.setSelection(range);
2794
- self2._updatePath(range, true);
2795
- } catch (error) {
2796
- self2.didError(error);
2797
- }
2798
- };
2799
- var keyHandlers = {
2800
- enter: function(self2, event, range) {
2801
- var root = self2._root;
2802
- var block, parent, nodeAfterSplit;
2803
- event.preventDefault();
2804
- self2._recordUndoState(range);
2805
- addLinks(range.startContainer, root, self2);
2806
- self2._removeZWS();
2807
- self2._getRangeAndRemoveBookmark(range);
2808
- if (!range.collapsed) {
2809
- deleteContentsOfRange(range, root);
2810
- }
2811
- block = getStartBlockOfRange(range, root);
2812
- if (!block || /^T[HD]$/.test(block.nodeName)) {
2813
- parent = getNearest(range.endContainer, root, "A");
2814
- if (parent) {
2815
- parent = parent.parentNode;
2816
- moveRangeBoundariesUpTree(range, parent, parent, root);
2817
- range.collapse(false);
2818
- }
2819
- insertNodeInRange(range, self2.createElement("BR"));
2820
- range.collapse(false);
2821
- self2.setSelection(range);
2822
- self2._updatePath(range, true);
2823
- return;
2824
- }
2825
- if (parent = getNearest(block, root, "LI")) {
2826
- block = parent;
2827
- }
2828
- if (isEmptyBlock(block)) {
2829
- if (getNearest(block, root, "UL") || getNearest(block, root, "OL")) {
2830
- return self2.decreaseListLevel(range);
2831
- } else if (getNearest(block, root, "BLOCKQUOTE")) {
2832
- return self2.modifyBlocks(removeBlockQuote, range);
2833
- }
2834
- }
2835
- nodeAfterSplit = splitBlock(
2836
- self2,
2837
- block,
2838
- range.startContainer,
2839
- range.startOffset
2840
- );
2841
- removeZWS(block);
2842
- removeEmptyInlines(block);
2843
- fixCursor(block, root);
2844
- while (nodeAfterSplit.nodeType === ELEMENT_NODE) {
2845
- var child = nodeAfterSplit.firstChild, next;
2846
- if (nodeAfterSplit.nodeName === "A" && (!nodeAfterSplit.textContent || nodeAfterSplit.textContent === ZWS)) {
2847
- child = self2._doc.createTextNode("");
2848
- replaceWith(nodeAfterSplit, child);
2849
- nodeAfterSplit = child;
2850
- break;
2851
- }
2852
- while (child && child.nodeType === TEXT_NODE && !child.data) {
2853
- next = child.nextSibling;
2854
- if (!next || next.nodeName === "BR") {
2855
- break;
2856
- }
2857
- detach(child);
2858
- child = next;
2859
- }
2860
- if (!child || child.nodeName === "BR" || child.nodeType === TEXT_NODE && !isPresto) {
2861
- break;
2862
- }
2863
- nodeAfterSplit = child;
2864
- }
2865
- range = self2.createRange(nodeAfterSplit, 0);
2866
- self2.setSelection(range);
2867
- self2._updatePath(range, true);
2868
- },
2869
- backspace: function(self2, event, range) {
2870
- var root = self2._root;
2871
- self2._removeZWS();
2872
- self2.saveUndoState(range);
2873
- if (!range.collapsed) {
2874
- event.preventDefault();
2875
- deleteContentsOfRange(range, root);
2876
- afterDelete(self2, range);
2877
- } else if (rangeDoesStartAtBlockBoundary(range, root)) {
2878
- event.preventDefault();
2879
- var current = getStartBlockOfRange(range, root);
2880
- var previous;
2881
- if (!current) {
2882
- return;
2883
- }
2884
- fixContainer(current.parentNode, root);
2885
- previous = getPreviousBlock(current, root);
2886
- if (previous) {
2887
- if (!previous.isContentEditable) {
2888
- detach(previous);
2889
- return;
2890
- }
2891
- mergeWithBlock(previous, current, range, root);
2892
- current = previous.parentNode;
2893
- while (current !== root && !current.nextSibling) {
2894
- current = current.parentNode;
2895
- }
2896
- if (current !== root && (current = current.nextSibling)) {
2897
- mergeContainers(current, root);
2898
- }
2899
- self2.setSelection(range);
2900
- } else if (current) {
2901
- if (getNearest(current, root, "UL") || getNearest(current, root, "OL")) {
2902
- return self2.decreaseListLevel(range);
2903
- } else if (getNearest(current, root, "BLOCKQUOTE")) {
2904
- return self2.modifyBlocks(decreaseBlockQuoteLevel, range);
2905
- }
2906
- self2.setSelection(range);
2907
- self2._updatePath(range, true);
2908
- }
2909
- } else {
2910
- self2.setSelection(range);
2911
- setTimeout(function() {
2912
- afterDelete(self2);
2913
- }, 0);
2914
- }
2915
- },
2916
- "delete": function(self2, event, range) {
2917
- var root = self2._root;
2918
- var current, next, originalRange, cursorContainer, cursorOffset, nodeAfterCursor;
2919
- self2._removeZWS();
2920
- self2.saveUndoState(range);
2921
- if (!range.collapsed) {
2922
- event.preventDefault();
2923
- deleteContentsOfRange(range, root);
2924
- afterDelete(self2, range);
2925
- } else if (rangeDoesEndAtBlockBoundary(range, root)) {
2926
- event.preventDefault();
2927
- current = getStartBlockOfRange(range, root);
2928
- if (!current) {
2929
- return;
2930
- }
2931
- fixContainer(current.parentNode, root);
2932
- next = getNextBlock(current, root);
2933
- if (next) {
2934
- if (!next.isContentEditable) {
2935
- detach(next);
2936
- return;
2937
- }
2938
- mergeWithBlock(current, next, range, root);
2939
- next = current.parentNode;
2940
- while (next !== root && !next.nextSibling) {
2941
- next = next.parentNode;
2942
- }
2943
- if (next !== root && (next = next.nextSibling)) {
2944
- mergeContainers(next, root);
2945
- }
2946
- self2.setSelection(range);
2947
- self2._updatePath(range, true);
2948
- }
2949
- } else {
2950
- originalRange = range.cloneRange();
2951
- moveRangeBoundariesUpTree(range, root, root, root);
2952
- cursorContainer = range.endContainer;
2953
- cursorOffset = range.endOffset;
2954
- if (cursorContainer.nodeType === ELEMENT_NODE) {
2955
- nodeAfterCursor = cursorContainer.childNodes[cursorOffset];
2956
- if (nodeAfterCursor && nodeAfterCursor.nodeName === "IMG") {
2957
- event.preventDefault();
2958
- detach(nodeAfterCursor);
2959
- moveRangeBoundariesDownTree(range);
2960
- afterDelete(self2, range);
2961
- return;
2962
- }
2963
- }
2964
- self2.setSelection(originalRange);
2965
- setTimeout(function() {
2966
- afterDelete(self2);
2967
- }, 0);
2968
- }
2969
- },
2970
- tab: function(self2, event, range) {
2971
- var root = self2._root;
2972
- var node, parent;
2973
- self2._removeZWS();
2974
- if (range.collapsed && rangeDoesStartAtBlockBoundary(range, root)) {
2975
- node = getStartBlockOfRange(range, root);
2976
- while (parent = node.parentNode) {
2977
- if (parent.nodeName === "UL" || parent.nodeName === "OL") {
2978
- event.preventDefault();
2979
- self2.increaseListLevel(range);
2980
- break;
2981
- }
2982
- node = parent;
2983
- }
2984
- }
2985
- },
2986
- "shift-tab": function(self2, event, range) {
2987
- var root = self2._root;
2988
- var node;
2989
- self2._removeZWS();
2990
- if (range.collapsed && rangeDoesStartAtBlockBoundary(range, root)) {
2991
- node = range.startContainer;
2992
- if (getNearest(node, root, "UL") || getNearest(node, root, "OL")) {
2993
- event.preventDefault();
2994
- self2.decreaseListLevel(range);
2995
- }
2996
- }
2997
- },
2998
- space: function(self2, _, range) {
2999
- var node, parent;
3000
- self2._recordUndoState(range);
3001
- addLinks(range.startContainer, self2._root, self2);
3002
- self2._getRangeAndRemoveBookmark(range);
3003
- node = range.endContainer;
3004
- parent = node.parentNode;
3005
- if (range.collapsed && range.endOffset === getLength(node)) {
3006
- if (node.nodeName === "A") {
3007
- range.setStartAfter(node);
3008
- } else if (parent.nodeName === "A" && !node.nextSibling) {
3009
- range.setStartAfter(parent);
3010
- }
3011
- }
3012
- if (!range.collapsed) {
3013
- deleteContentsOfRange(range, self2._root);
3014
- self2._ensureBottomLine();
3015
- self2.setSelection(range);
3016
- self2._updatePath(range, true);
3017
- }
3018
- self2.setSelection(range);
3019
- },
3020
- left: function(self2) {
3021
- self2._removeZWS();
3022
- },
3023
- right: function(self2) {
3024
- self2._removeZWS();
3025
- }
3026
- };
3027
- if (isMac && isGecko) {
3028
- keyHandlers["meta-left"] = function(self2, event) {
3029
- event.preventDefault();
3030
- var sel = getWindowSelection(self2);
3031
- if (sel && sel.modify) {
3032
- sel.modify("move", "backward", "lineboundary");
3033
- }
3034
- };
3035
- keyHandlers["meta-right"] = function(self2, event) {
3036
- event.preventDefault();
3037
- var sel = getWindowSelection(self2);
3038
- if (sel && sel.modify) {
3039
- sel.modify("move", "forward", "lineboundary");
3040
- }
3041
- };
3042
- }
3043
- if (!isMac) {
3044
- keyHandlers.pageup = function(self2) {
3045
- self2.moveCursorToStart();
3046
- };
3047
- keyHandlers.pagedown = function(self2) {
3048
- self2.moveCursorToEnd();
3049
- };
3050
- }
3051
- keyHandlers[ctrlKey + "b"] = mapKeyToFormat("B");
3052
- keyHandlers[ctrlKey + "i"] = mapKeyToFormat("I");
3053
- keyHandlers[ctrlKey + "u"] = mapKeyToFormat("U");
3054
- keyHandlers[ctrlKey + "shift-7"] = mapKeyToFormat("S");
3055
- keyHandlers[ctrlKey + "shift-5"] = mapKeyToFormat("SUB", { tag: "SUP" });
3056
- keyHandlers[ctrlKey + "shift-6"] = mapKeyToFormat("SUP", { tag: "SUB" });
3057
- keyHandlers[ctrlKey + "shift-8"] = mapKeyTo("makeUnorderedList");
3058
- keyHandlers[ctrlKey + "shift-9"] = mapKeyTo("makeOrderedList");
3059
- keyHandlers[ctrlKey + "["] = mapKeyTo("decreaseQuoteLevel");
3060
- keyHandlers[ctrlKey + "]"] = mapKeyTo("increaseQuoteLevel");
3061
- keyHandlers[ctrlKey + "y"] = mapKeyTo("redo");
3062
- keyHandlers[ctrlKey + "z"] = mapKeyTo("undo");
3063
- keyHandlers[ctrlKey + "shift-z"] = mapKeyTo("redo");
3064
- var fontSizes = {
3065
- 1: 10,
3066
- 2: 13,
3067
- 3: 16,
3068
- 4: 18,
3069
- 5: 24,
3070
- 6: 32,
3071
- 7: 48
3072
- };
3073
- var styleToSemantic = {
3074
- backgroundColor: {
3075
- regexp: notWS,
3076
- replace: function(doc2, colour) {
3077
- return createElement(doc2, "SPAN", {
3078
- "class": HIGHLIGHT_CLASS,
3079
- style: "background-color:" + colour
3080
- });
3081
- }
3082
- },
3083
- color: {
3084
- regexp: notWS,
3085
- replace: function(doc2, colour) {
3086
- return createElement(doc2, "SPAN", {
3087
- "class": COLOUR_CLASS,
3088
- style: "color:" + colour
3089
- });
3090
- }
3091
- },
3092
- fontWeight: {
3093
- regexp: /^bold|^700/i,
3094
- replace: function(doc2) {
3095
- return createElement(doc2, "B");
3096
- }
3097
- },
3098
- fontStyle: {
3099
- regexp: /^italic/i,
3100
- replace: function(doc2) {
3101
- return createElement(doc2, "I");
3102
- }
3103
- },
3104
- fontFamily: {
3105
- regexp: notWS,
3106
- replace: function(doc2, family) {
3107
- return createElement(doc2, "SPAN", {
3108
- "class": FONT_FAMILY_CLASS,
3109
- style: "font-family:" + family
3110
- });
3111
- }
3112
- },
3113
- fontSize: {
3114
- regexp: notWS,
3115
- replace: function(doc2, size) {
3116
- return createElement(doc2, "SPAN", {
3117
- "class": FONT_SIZE_CLASS,
3118
- style: "font-size:" + size
3119
- });
3120
- }
3121
- },
3122
- textDecoration: {
3123
- regexp: /^underline/i,
3124
- replace: function(doc2) {
3125
- return createElement(doc2, "U");
3126
- }
3127
- }
3128
- };
3129
- var replaceWithTag = function(tag) {
3130
- return function(node, parent) {
3131
- var el = createElement(node.ownerDocument, tag);
3132
- parent.replaceChild(el, node);
3133
- el.appendChild(empty(node));
3134
- return el;
3135
- };
3136
- };
3137
- var replaceStyles = function(node, parent) {
3138
- var style = node.style;
3139
- var doc2 = node.ownerDocument;
3140
- var attr, converter, css, newTreeBottom, newTreeTop, el;
3141
- for (attr in styleToSemantic) {
3142
- converter = styleToSemantic[attr];
3143
- css = style[attr];
3144
- if (css && converter.regexp.test(css)) {
3145
- el = converter.replace(doc2, css);
3146
- if (!newTreeTop) {
3147
- newTreeTop = el;
3148
- }
3149
- if (newTreeBottom) {
3150
- newTreeBottom.appendChild(el);
3151
- }
3152
- newTreeBottom = el;
3153
- node.style[attr] = "";
3154
- }
3155
- }
3156
- if (newTreeTop) {
3157
- newTreeBottom.appendChild(empty(node));
3158
- if (node.nodeName === "SPAN") {
3159
- parent.replaceChild(newTreeTop, node);
3160
- } else {
3161
- node.appendChild(newTreeTop);
3162
- }
3163
- }
3164
- return newTreeBottom || node;
3165
- };
3166
- var stylesRewriters = {
3167
- P: replaceStyles,
3168
- SPAN: replaceStyles,
3169
- STRONG: replaceWithTag("B"),
3170
- EM: replaceWithTag("I"),
3171
- INS: replaceWithTag("U"),
3172
- STRIKE: replaceWithTag("S"),
3173
- FONT: function(node, parent) {
3174
- var face = node.face, size = node.size, colour = node.color, doc2 = node.ownerDocument, fontSpan, sizeSpan, colourSpan, newTreeBottom, newTreeTop;
3175
- if (face) {
3176
- fontSpan = createElement(doc2, "SPAN", {
3177
- "class": FONT_FAMILY_CLASS,
3178
- style: "font-family:" + face
3179
- });
3180
- newTreeTop = fontSpan;
3181
- newTreeBottom = fontSpan;
3182
- }
3183
- if (size) {
3184
- sizeSpan = createElement(doc2, "SPAN", {
3185
- "class": FONT_SIZE_CLASS,
3186
- style: "font-size:" + fontSizes[size] + "px"
3187
- });
3188
- if (!newTreeTop) {
3189
- newTreeTop = sizeSpan;
3190
- }
3191
- if (newTreeBottom) {
3192
- newTreeBottom.appendChild(sizeSpan);
3193
- }
3194
- newTreeBottom = sizeSpan;
3195
- }
3196
- if (colour && /^#?([\dA-F]{3}){1,2}$/i.test(colour)) {
3197
- if (colour.charAt(0) !== "#") {
3198
- colour = "#" + colour;
3199
- }
3200
- colourSpan = createElement(doc2, "SPAN", {
3201
- "class": COLOUR_CLASS,
3202
- style: "color:" + colour
3203
- });
3204
- if (!newTreeTop) {
3205
- newTreeTop = colourSpan;
3206
- }
3207
- if (newTreeBottom) {
3208
- newTreeBottom.appendChild(colourSpan);
3209
- }
3210
- newTreeBottom = colourSpan;
3211
- }
3212
- if (!newTreeTop) {
3213
- newTreeTop = newTreeBottom = createElement(doc2, "SPAN");
3214
- }
3215
- parent.replaceChild(newTreeTop, node);
3216
- newTreeBottom.appendChild(empty(node));
3217
- return newTreeBottom;
3218
- },
3219
- TT: function(node, parent) {
3220
- var el = createElement(node.ownerDocument, "SPAN", {
3221
- "class": FONT_FAMILY_CLASS,
3222
- style: 'font-family:menlo,consolas,"courier new",monospace'
3223
- });
3224
- parent.replaceChild(el, node);
3225
- el.appendChild(empty(node));
3226
- return el;
3227
- }
3228
- };
3229
- var allowedBlock = /^(?:A(?:DDRESS|RTICLE|SIDE|UDIO)|BLOCKQUOTE|CAPTION|D(?:[DLT]|IV)|F(?:IGURE|IGCAPTION|OOTER)|H[1-6]|HEADER|L(?:ABEL|EGEND|I)|O(?:L|UTPUT)|P(?:RE)?|SECTION|T(?:ABLE|BODY|D|FOOT|H|HEAD|R)|COL(?:GROUP)?|UL)$/;
3230
- var blacklist = /^(?:HEAD|META|STYLE)/;
3231
- var walker = new TreeWalker(null, SHOW_TEXT | SHOW_ELEMENT, function() {
3232
- return true;
3233
- });
3234
- var cleanTree = function cleanTree2(node, preserveWS) {
3235
- if (node.classList && node.classList.contains("halo-img-content")) {
3236
- return node;
3237
- }
3238
- var children = node.childNodes, nonInlineParent, i, l, child, nodeName, nodeType, rewriter, childLength, startsWithWS, endsWithWS, data, sibling;
3239
- nonInlineParent = node;
3240
- while (isInline(nonInlineParent)) {
3241
- nonInlineParent = nonInlineParent.parentNode;
3242
- }
3243
- walker.root = nonInlineParent;
3244
- for (i = 0, l = children.length; i < l; i += 1) {
3245
- child = children[i];
3246
- nodeName = child.nodeName;
3247
- nodeType = child.nodeType;
3248
- rewriter = stylesRewriters[nodeName];
3249
- if (nodeType === ELEMENT_NODE) {
3250
- childLength = child.childNodes.length;
3251
- if (rewriter) {
3252
- child = rewriter(child, node);
3253
- } else if (blacklist.test(nodeName)) {
3254
- node.removeChild(child);
3255
- i -= 1;
3256
- l -= 1;
3257
- continue;
3258
- } else if (!allowedBlock.test(nodeName) && !isInline(child)) {
3259
- i -= 1;
3260
- l += childLength - 1;
3261
- node.replaceChild(empty(child), child);
3262
- continue;
3263
- }
3264
- if (childLength) {
3265
- cleanTree2(child, preserveWS || nodeName === "PRE");
3266
- }
3267
- } else {
3268
- if (nodeType === TEXT_NODE) {
3269
- data = child.data;
3270
- startsWithWS = !notWS.test(data.charAt(0));
3271
- endsWithWS = !notWS.test(data.charAt(data.length - 1));
3272
- if (preserveWS || !startsWithWS && !endsWithWS) {
3273
- continue;
3274
- }
3275
- if (startsWithWS) {
3276
- walker.currentNode = child;
3277
- while (sibling = walker.previousPONode()) {
3278
- nodeName = sibling.nodeName;
3279
- if (nodeName === "IMG" || nodeName === "#text" && notWS.test(sibling.data)) {
3280
- break;
3281
- }
3282
- if (!isInline(sibling)) {
3283
- sibling = null;
3284
- break;
3285
- }
3286
- }
3287
- data = data.replace(/^[ \t\r\n]+/g, sibling ? " " : "");
3288
- }
3289
- if (endsWithWS) {
3290
- walker.currentNode = child;
3291
- while (sibling = walker.nextNode()) {
3292
- if (nodeName === "IMG" || nodeName === "#text" && notWS.test(sibling.data)) {
3293
- break;
3294
- }
3295
- if (!isInline(sibling)) {
3296
- sibling = null;
3297
- break;
3298
- }
3299
- }
3300
- data = data.replace(/[ \t\r\n]+$/g, sibling ? " " : "");
3301
- }
3302
- if (data) {
3303
- child.data = data;
3304
- continue;
3305
- }
3306
- }
3307
- node.removeChild(child);
3308
- i -= 1;
3309
- l -= 1;
3310
- }
3311
- }
3312
- return node;
3313
- };
3314
- var removeEmptyInlines = function removeEmptyInlines2(node) {
3315
- var children = node.childNodes, l = children.length, child;
3316
- while (l--) {
3317
- child = children[l];
3318
- if (child.nodeType === ELEMENT_NODE && !isLeaf(child)) {
3319
- removeEmptyInlines2(child);
3320
- if (isInline(child) && !child.firstChild) {
3321
- node.removeChild(child);
3322
- }
3323
- } else if (child.nodeType === TEXT_NODE && !child.data) {
3324
- node.removeChild(child);
3325
- }
3326
- }
3327
- };
3328
- var notWSTextNode = function(node) {
3329
- return node.nodeType === ELEMENT_NODE ? node.nodeName === "BR" : notWS.test(node.data);
3330
- };
3331
- var isLineBreak = function(br, isLBIfEmptyBlock) {
3332
- var block = br.parentNode;
3333
- var walker2;
3334
- while (isInline(block)) {
3335
- block = block.parentNode;
3336
- }
3337
- walker2 = new TreeWalker(
3338
- block,
3339
- SHOW_ELEMENT | SHOW_TEXT,
3340
- notWSTextNode
3341
- );
3342
- walker2.currentNode = br;
3343
- return !!walker2.nextNode() || isLBIfEmptyBlock && !walker2.previousNode();
3344
- };
3345
- var cleanupBRs = function(node, root, keepForBlankLine) {
3346
- var brs = node.querySelectorAll("BR");
3347
- var brBreaksLine = [];
3348
- var l = brs.length;
3349
- var i, br, parent;
3350
- for (i = 0; i < l; i += 1) {
3351
- brBreaksLine[i] = isLineBreak(brs[i], keepForBlankLine);
3352
- }
3353
- while (l--) {
3354
- br = brs[l];
3355
- parent = br.parentNode;
3356
- if (!parent) {
3357
- continue;
3358
- }
3359
- if (!brBreaksLine[l]) {
3360
- detach(br);
3361
- } else if (!isInline(parent)) {
3362
- fixContainer(parent, root);
3363
- }
3364
- }
3365
- };
3366
- var setClipboardData = function(clipboardData, node, root) {
3367
- var body = node.ownerDocument.body;
3368
- var html, text;
3369
- cleanupBRs(node, root, true);
3370
- node.setAttribute(
3371
- "style",
3372
- "position:fixed;overflow:hidden;bottom:100%;right:100%;"
3373
- );
3374
- body.appendChild(node);
3375
- html = node.innerHTML;
3376
- text = node.innerText || node.textContent;
3377
- if (isWin) {
3378
- text = text.replace(/\r?\n/g, "\r\n");
3379
- }
3380
- clipboardData.setData("text/html", html);
3381
- clipboardData.setData("text/plain", text);
3382
- body.removeChild(node);
3383
- };
3384
- var onCut = function(event) {
3385
- var clipboardData = event.clipboardData;
3386
- var range = this.getSelection();
3387
- var root = this._root;
3388
- var self2 = this;
3389
- var startBlock, endBlock, copyRoot, contents, parent, newContents, node;
3390
- if (range.collapsed) {
3391
- event.preventDefault();
3392
- return;
3393
- }
3394
- this.saveUndoState(range);
3395
- if (!isEdge && !isIOS && clipboardData) {
3396
- startBlock = getStartBlockOfRange(range, root);
3397
- endBlock = getEndBlockOfRange(range, root);
3398
- copyRoot = startBlock === endBlock && startBlock || root;
3399
- contents = deleteContentsOfRange(range, root);
3400
- parent = range.commonAncestorContainer;
3401
- if (parent.nodeType === TEXT_NODE) {
3402
- parent = parent.parentNode;
3403
- }
3404
- while (parent && parent !== copyRoot) {
3405
- newContents = parent.cloneNode(false);
3406
- newContents.appendChild(contents);
3407
- contents = newContents;
3408
- parent = parent.parentNode;
3409
- }
3410
- node = this.createElement("div");
3411
- node.appendChild(contents);
3412
- setClipboardData(clipboardData, node, root);
3413
- event.preventDefault();
3414
- } else {
3415
- setTimeout(function() {
3416
- try {
3417
- self2._ensureBottomLine();
3418
- } catch (error) {
3419
- self2.didError(error);
3420
- }
3421
- }, 0);
3422
- }
3423
- this.setSelection(range);
3424
- };
3425
- var onCopy = function(event) {
3426
- var clipboardData = event.clipboardData;
3427
- var range = this.getSelection();
3428
- var root = this._root;
3429
- var startBlock, endBlock, copyRoot, contents, parent, newContents, node;
3430
- if (!isEdge && !isIOS && clipboardData) {
3431
- startBlock = getStartBlockOfRange(range, root);
3432
- endBlock = getEndBlockOfRange(range, root);
3433
- copyRoot = startBlock === endBlock && startBlock || root;
3434
- range = range.cloneRange();
3435
- moveRangeBoundariesDownTree(range);
3436
- moveRangeBoundariesUpTree(range, copyRoot, copyRoot, root);
3437
- contents = range.cloneContents();
3438
- parent = range.commonAncestorContainer;
3439
- if (parent.nodeType === TEXT_NODE) {
3440
- parent = parent.parentNode;
3441
- }
3442
- while (parent && parent !== copyRoot) {
3443
- newContents = parent.cloneNode(false);
3444
- newContents.appendChild(contents);
3445
- contents = newContents;
3446
- parent = parent.parentNode;
3447
- }
3448
- node = this.createElement("div");
3449
- node.appendChild(contents);
3450
- setClipboardData(clipboardData, node, root);
3451
- event.preventDefault();
3452
- }
3453
- };
3454
- function monitorShiftKey(event) {
3455
- this.isShiftDown = event.shiftKey;
3456
- }
3457
- var onPaste = function(event) {
3458
- if (event.target.tagName === "TEXTAREA")
3459
- return true;
3460
- var clipboardData = event.clipboardData;
3461
- var items = clipboardData && clipboardData.items;
3462
- var choosePlain = this.isShiftDown;
3463
- var fireDrop = false;
3464
- var hasImage = false;
3465
- var plainItem = null;
3466
- var self2 = this;
3467
- var l, item, type, types, data;
3468
- if (isEdge && items) {
3469
- l = items.length;
3470
- while (l--) {
3471
- if (!choosePlain && /^image\/.*/.test(items[l].type)) {
3472
- hasImage = true;
3473
- }
3474
- }
3475
- if (!hasImage) {
3476
- items = null;
3477
- }
3478
- }
3479
- if (items) {
3480
- event.preventDefault();
3481
- l = items.length;
3482
- while (l--) {
3483
- item = items[l];
3484
- type = item.type;
3485
- if (!choosePlain && type === "text/html") {
3486
- item.getAsString(function(html) {
3487
- self2.insertHTML(html, true);
3488
- });
3489
- return;
3490
- }
3491
- if (type === "text/plain") {
3492
- plainItem = item;
3493
- }
3494
- if (!choosePlain && /^image\/.*/.test(type)) {
3495
- hasImage = true;
3496
- }
3497
- }
3498
- if (hasImage) {
3499
- this.fireEvent("dragover", {
3500
- dataTransfer: clipboardData,
3501
- preventDefault: function() {
3502
- fireDrop = true;
3503
- }
3504
- });
3505
- if (fireDrop) {
3506
- this.fireEvent("drop", {
3507
- dataTransfer: clipboardData
3508
- });
3509
- }
3510
- } else if (plainItem) {
3511
- plainItem.getAsString(function(text) {
3512
- self2.insertPlainText(text, true);
3513
- });
3514
- }
3515
- return;
3516
- }
3517
- types = clipboardData && clipboardData.types;
3518
- if (!isEdge && types && (indexOf.call(types, "text/html") > -1 || !isGecko && indexOf.call(types, "text/plain") > -1 && indexOf.call(types, "text/rtf") < 0)) {
3519
- event.preventDefault();
3520
- if (!choosePlain && (data = clipboardData.getData("text/html"))) {
3521
- this.insertHTML(data, true);
3522
- } else if ((data = clipboardData.getData("text/plain")) || (data = clipboardData.getData("text/uri-list"))) {
3523
- this.insertPlainText(data, true);
3524
- }
3525
- return;
3526
- }
3527
- this._awaitingPaste = true;
3528
- var body = this._doc.body, range = this.getSelection(), startContainer = range.startContainer, startOffset = range.startOffset, endContainer = range.endContainer, endOffset = range.endOffset;
3529
- var pasteArea = this.createElement("DIV", {
3530
- contenteditable: "true",
3531
- style: "position:fixed; overflow:hidden; top:0; right:100%; width:1px; height:1px;"
3532
- });
3533
- body.appendChild(pasteArea);
3534
- range.selectNodeContents(pasteArea);
3535
- this.setSelection(range);
3536
- setTimeout(function() {
3537
- try {
3538
- self2._awaitingPaste = false;
3539
- var html = "", next = pasteArea, first, range2;
3540
- while (pasteArea = next) {
3541
- next = pasteArea.nextSibling;
3542
- detach(pasteArea);
3543
- first = pasteArea.firstChild;
3544
- if (first && first === pasteArea.lastChild && first.nodeName === "DIV") {
3545
- pasteArea = first;
3546
- }
3547
- html += pasteArea.innerHTML;
3548
- }
3549
- range2 = self2.createRange(
3550
- startContainer,
3551
- startOffset,
3552
- endContainer,
3553
- endOffset
3554
- );
3555
- self2.setSelection(range2);
3556
- if (html) {
3557
- self2.insertHTML(html, true);
3558
- }
3559
- } catch (error) {
3560
- self2.didError(error);
3561
- }
3562
- }, 0);
3563
- };
3564
- var onDrop = function(event) {
3565
- var types = event.dataTransfer.types;
3566
- var l = types.length;
3567
- var hasPlain = false;
3568
- var hasHTML = false;
3569
- while (l--) {
3570
- switch (types[l]) {
3571
- case "text/plain":
3572
- hasPlain = true;
3573
- break;
3574
- case "text/html":
3575
- hasHTML = true;
3576
- break;
3577
- default:
3578
- return;
3579
- }
3580
- }
3581
- if (hasHTML || hasPlain) {
3582
- this.saveUndoState();
3583
- }
3584
- };
3585
- function mergeObjects(base, extras, mayOverride) {
3586
- var prop, value;
3587
- if (!base) {
3588
- base = {};
3589
- }
3590
- if (extras) {
3591
- for (prop in extras) {
3592
- if (mayOverride || !(prop in base)) {
3593
- value = extras[prop];
3594
- base[prop] = value && value.constructor === Object ? mergeObjects(base[prop], value, mayOverride) : value;
3595
- }
3596
- }
3597
- }
3598
- return base;
3599
- }
3600
- function Squire(root, config) {
3601
- if (root.nodeType === DOCUMENT_NODE) {
3602
- root = root.body;
3603
- }
3604
- var doc2 = root.ownerDocument;
3605
- var win2 = doc2.defaultView;
3606
- var mutation;
3607
- this._win = win2;
3608
- this._doc = doc2;
3609
- this._root = root;
3610
- this._events = {};
3611
- this._isFocused = false;
3612
- this._lastSelection = null;
3613
- if (losesSelectionOnBlur) {
3614
- this.addEventListener("beforedeactivate", this.getSelection);
3615
- }
3616
- this._hasZWS = false;
3617
- this._lastAnchorNode = null;
3618
- this._lastFocusNode = null;
3619
- this._path = "";
3620
- this._willUpdatePath = false;
3621
- if ("onselectionchange" in doc2) {
3622
- this.addEventListener("selectionchange", this._updatePathOnEvent);
3623
- } else {
3624
- this.addEventListener("keyup", this._updatePathOnEvent);
3625
- this.addEventListener("mouseup", this._updatePathOnEvent);
3626
- }
3627
- this._undoIndex = -1;
3628
- this._undoStack = [];
3629
- this._undoStackLength = 0;
3630
- this._isInUndoState = false;
3631
- this._ignoreChange = false;
3632
- this._ignoreAllChanges = false;
3633
- if (canObserveMutations) {
3634
- mutation = new MutationObserver(this._docWasChanged.bind(this));
3635
- mutation.observe(root, {
3636
- childList: true,
3637
- attributes: true,
3638
- characterData: true,
3639
- subtree: true
3640
- });
3641
- this._mutation = mutation;
3642
- } else {
3643
- this.addEventListener("keyup", this._keyUpDetectChange);
3644
- }
3645
- this._restoreSelection = false;
3646
- this.addEventListener("blur", enableRestoreSelection);
3647
- this.addEventListener("mousedown", disableRestoreSelection);
3648
- this.addEventListener("touchstart", disableRestoreSelection);
3649
- this.addEventListener("focus", restoreSelection);
3650
- this._awaitingPaste = false;
3651
- this.addEventListener(isIElt11 ? "beforecut" : "cut", onCut);
3652
- this.addEventListener("copy", onCopy);
3653
- this.addEventListener("keydown", monitorShiftKey);
3654
- this.addEventListener("keyup", monitorShiftKey);
3655
- this.addEventListener(isIElt11 ? "beforepaste" : "paste", onPaste);
3656
- this.addEventListener("drop", onDrop);
3657
- this.addEventListener(isPresto ? "keypress" : "keydown", onKey);
3658
- this._keyHandlers = Object.create(keyHandlers);
3659
- this.setConfig(config);
3660
- if (isIElt11) {
3661
- win2.Text.prototype.splitText = function(offset) {
3662
- var afterSplit = this.ownerDocument.createTextNode(
3663
- this.data.slice(offset)
3664
- ), next = this.nextSibling, parent = this.parentNode, toDelete = this.length - offset;
3665
- if (next) {
3666
- parent.insertBefore(afterSplit, next);
3667
- } else {
3668
- parent.appendChild(afterSplit);
3669
- }
3670
- if (toDelete) {
3671
- this.deleteData(offset, toDelete);
3672
- }
3673
- return afterSplit;
3674
- };
3675
- }
3676
- root.setAttribute("contenteditable", "true");
3677
- try {
3678
- doc2.execCommand("enableObjectResizing", false, "false");
3679
- doc2.execCommand("enableInlineTableEditing", false, "false");
3680
- } catch (error) {
3681
- }
3682
- root.__squire__ = this;
3683
- this.setHTML("");
3684
- }
3685
- var proto = Squire.prototype;
3686
- var sanitizeToDOMFragment = function(html, isPaste, self2) {
3687
- var doc2 = self2._doc;
3688
- var frag = html ? DOMPurify.sanitize(html, {
3689
- ALLOW_UNKNOWN_PROTOCOLS: true,
3690
- WHOLE_DOCUMENT: false,
3691
- RETURN_DOM: true,
3692
- RETURN_DOM_FRAGMENT: true
3693
- }) : null;
3694
- return frag ? doc2.importNode(frag, true) : doc2.createDocumentFragment();
3695
- };
3696
- proto.setConfig = function(config) {
3697
- config = mergeObjects({
3698
- blockTag: "DIV",
3699
- blockAttributes: null,
3700
- tagAttributes: {
3701
- blockquote: null,
3702
- ul: null,
3703
- ol: null,
3704
- li: null,
3705
- a: null
3706
- },
3707
- leafNodeNames,
3708
- undo: {
3709
- documentSizeThreshold: -1,
3710
- undoLimit: -1
3711
- },
3712
- isInsertedHTMLSanitized: true,
3713
- isSetHTMLSanitized: true,
3714
- sanitizeToDOMFragment: typeof DOMPurify !== "undefined" && DOMPurify.isSupported ? sanitizeToDOMFragment : null
3715
- }, config, true);
3716
- config.blockTag = config.blockTag.toUpperCase();
3717
- this._config = config;
3718
- return this;
3719
- };
3720
- proto.createElement = function(tag, props, children) {
3721
- return createElement(this._doc, tag, props, children);
3722
- };
3723
- proto.createDefaultBlock = function(children) {
3724
- var config = this._config;
3725
- return fixCursor(
3726
- this.createElement(config.blockTag, config.blockAttributes, children),
3727
- this._root
3728
- );
3729
- };
3730
- proto.didError = function(error) {
3731
- console.log(error);
3732
- };
3733
- proto.getDocument = function() {
3734
- return this._doc;
3735
- };
3736
- proto.getRoot = function() {
3737
- return this._root;
3738
- };
3739
- proto.modifyDocument = function(modificationCallback) {
3740
- var mutation = this._mutation;
3741
- if (mutation) {
3742
- if (mutation.takeRecords().length) {
3743
- this._docWasChanged();
3744
- }
3745
- mutation.disconnect();
3746
- }
3747
- this._ignoreAllChanges = true;
3748
- modificationCallback();
3749
- this._ignoreAllChanges = false;
3750
- if (mutation) {
3751
- mutation.observe(this._root, {
3752
- childList: true,
3753
- attributes: true,
3754
- characterData: true,
3755
- subtree: true
3756
- });
3757
- this._ignoreChange = false;
3758
- }
3759
- };
3760
- var customEvents = {
3761
- pathChange: 1,
3762
- select: 1,
3763
- input: 1,
3764
- undoStateChange: 1
3765
- };
3766
- proto.fireEvent = function(type, event) {
3767
- var handlers = this._events[type];
3768
- var isFocused, l, obj;
3769
- if (/^(?:focus|blur)/.test(type)) {
3770
- isFocused = this._root === this._doc.activeElement;
3771
- if (type === "focus") {
3772
- if (!isFocused || this._isFocused) {
3773
- return this;
3774
- }
3775
- this._isFocused = true;
3776
- } else {
3777
- if (isFocused || !this._isFocused) {
3778
- return this;
3779
- }
3780
- this._isFocused = false;
3781
- }
3782
- }
3783
- if (handlers) {
3784
- if (!event) {
3785
- event = {};
3786
- }
3787
- if (event.type !== type) {
3788
- event.type = type;
3789
- }
3790
- handlers = handlers.slice();
3791
- l = handlers.length;
3792
- while (l--) {
3793
- obj = handlers[l];
3794
- try {
3795
- if (obj.handleEvent) {
3796
- obj.handleEvent(event);
3797
- } else {
3798
- obj.call(this, event);
3799
- }
3800
- } catch (error) {
3801
- error.details = "Squire: fireEvent error. Event type: " + type;
3802
- this.didError(error);
3803
- }
3804
- }
3805
- }
3806
- return this;
3807
- };
3808
- proto.destroy = function() {
3809
- var events = this._events;
3810
- var type;
3811
- for (type in events) {
3812
- this.removeEventListener(type);
3813
- }
3814
- if (this._mutation) {
3815
- this._mutation.disconnect();
3816
- }
3817
- delete this._root.__squire__;
3818
- this._undoIndex = -1;
3819
- this._undoStack = [];
3820
- this._undoStackLength = 0;
3821
- };
3822
- proto.handleEvent = function(event) {
3823
- this.fireEvent(event.type, event);
3824
- };
3825
- proto.addEventListener = function(type, fn) {
3826
- var handlers = this._events[type];
3827
- var target = this._root;
3828
- if (!fn) {
3829
- this.didError({
3830
- name: "Squire: addEventListener with null or undefined fn",
3831
- message: "Event type: " + type
3832
- });
3833
- return this;
3834
- }
3835
- if (!handlers) {
3836
- handlers = this._events[type] = [];
3837
- if (!customEvents[type]) {
3838
- if (type === "selectionchange") {
3839
- target = this._doc;
3840
- }
3841
- target.addEventListener(type, this, true);
3842
- }
3843
- }
3844
- handlers.push(fn);
3845
- return this;
3846
- };
3847
- proto.removeEventListener = function(type, fn) {
3848
- var handlers = this._events[type];
3849
- var target = this._root;
3850
- var l;
3851
- if (handlers) {
3852
- if (fn) {
3853
- l = handlers.length;
3854
- while (l--) {
3855
- if (handlers[l] === fn) {
3856
- handlers.splice(l, 1);
3857
- }
3858
- }
3859
- } else {
3860
- handlers.length = 0;
3861
- }
3862
- if (!handlers.length) {
3863
- delete this._events[type];
3864
- if (!customEvents[type]) {
3865
- if (type === "selectionchange") {
3866
- target = this._doc;
3867
- }
3868
- target.removeEventListener(type, this, true);
3869
- }
3870
- }
3871
- }
3872
- return this;
3873
- };
3874
- proto.createRange = function(range, startOffset, endContainer, endOffset) {
3875
- if (range instanceof this._win.Range) {
3876
- return range.cloneRange();
3877
- }
3878
- var domRange = this._doc.createRange();
3879
- domRange.setStart(range, startOffset);
3880
- if (endContainer) {
3881
- domRange.setEnd(endContainer, endOffset);
3882
- } else {
3883
- domRange.setEnd(range, startOffset);
3884
- }
3885
- return domRange;
3886
- };
3887
- proto.getCursorPosition = function(range) {
3888
- if (!range && !(range = this.getSelection()) || !range.getBoundingClientRect) {
3889
- return null;
3890
- }
3891
- var rect = range.getBoundingClientRect();
3892
- var node, parent;
3893
- if (rect && !rect.top) {
3894
- this._ignoreChange = true;
3895
- node = this._doc.createElement("SPAN");
3896
- node.textContent = ZWS;
3897
- insertNodeInRange(range, node);
3898
- rect = node.getBoundingClientRect();
3899
- parent = node.parentNode;
3900
- parent.removeChild(node);
3901
- mergeInlines(parent, range);
3902
- }
3903
- return rect;
3904
- };
3905
- proto._moveCursorTo = function(toStart) {
3906
- var root = this._root, range = this.createRange(root, toStart ? 0 : root.childNodes.length);
3907
- moveRangeBoundariesDownTree(range);
3908
- this.setSelection(range);
3909
- return this;
3910
- };
3911
- proto.moveCursorToStart = function() {
3912
- return this._moveCursorTo(true);
3913
- };
3914
- proto.moveCursorToEnd = function() {
3915
- return this._moveCursorTo(false);
3916
- };
3917
- var getWindowSelection = function(self2) {
3918
- return self2._win.getSelection() || null;
3919
- };
3920
- proto.setSelection = function(range) {
3921
- if (range) {
3922
- this._lastSelection = range;
3923
- if (!this._isFocused) {
3924
- enableRestoreSelection.call(this);
3925
- } else if (isAndroid && !this._restoreSelection) {
3926
- enableRestoreSelection.call(this);
3927
- this.blur();
3928
- this.focus();
3929
- } else {
3930
- if (isIOS) {
3931
- this._win.focus();
3932
- }
3933
- var sel = getWindowSelection(this);
3934
- if (sel) {
3935
- sel.removeAllRanges();
3936
- sel.addRange(range);
3937
- }
3938
- }
3939
- }
3940
- return this;
3941
- };
3942
- proto.getSelection = function() {
3943
- var sel = getWindowSelection(this);
3944
- var root = this._root;
3945
- var selection, startContainer, endContainer, node;
3946
- if (this._isFocused && sel && sel.rangeCount) {
3947
- selection = sel.getRangeAt(0).cloneRange();
3948
- startContainer = selection.startContainer;
3949
- endContainer = selection.endContainer;
3950
- if (startContainer && isLeaf(startContainer)) {
3951
- selection.setStartBefore(startContainer);
3952
- }
3953
- if (endContainer && isLeaf(endContainer)) {
3954
- selection.setEndBefore(endContainer);
3955
- }
3956
- }
3957
- if (selection && isOrContains(root, selection.commonAncestorContainer)) {
3958
- this._lastSelection = selection;
3959
- } else {
3960
- selection = this._lastSelection;
3961
- node = selection.commonAncestorContainer;
3962
- if (!isOrContains(node.ownerDocument, node)) {
3963
- selection = null;
3964
- }
3965
- }
3966
- if (!selection) {
3967
- selection = this.createRange(root.firstChild, 0);
3968
- }
3969
- return selection;
3970
- };
3971
- function enableRestoreSelection() {
3972
- this._restoreSelection = true;
3973
- }
3974
- function disableRestoreSelection() {
3975
- this._restoreSelection = false;
3976
- }
3977
- function restoreSelection() {
3978
- if (this._restoreSelection) {
3979
- this.setSelection(this._lastSelection);
3980
- }
3981
- }
3982
- proto.getSelectedText = function() {
3983
- var range = this.getSelection();
3984
- if (!range || range.collapsed) {
3985
- return "";
3986
- }
3987
- var walker2 = new TreeWalker(
3988
- range.commonAncestorContainer,
3989
- SHOW_TEXT | SHOW_ELEMENT,
3990
- function(node2) {
3991
- return isNodeContainedInRange(range, node2, true);
3992
- }
3993
- );
3994
- var startContainer = range.startContainer;
3995
- var endContainer = range.endContainer;
3996
- var node = walker2.currentNode = startContainer;
3997
- var textContent = "";
3998
- var addedTextInBlock = false;
3999
- var value;
4000
- if (!walker2.filter(node)) {
4001
- node = walker2.nextNode();
4002
- }
4003
- while (node) {
4004
- if (node.nodeType === TEXT_NODE) {
4005
- value = node.data;
4006
- if (value && /\S/.test(value)) {
4007
- if (node === endContainer) {
4008
- value = value.slice(0, range.endOffset);
4009
- }
4010
- if (node === startContainer) {
4011
- value = value.slice(range.startOffset);
4012
- }
4013
- textContent += value;
4014
- addedTextInBlock = true;
4015
- }
4016
- } else if (node.nodeName === "BR" || addedTextInBlock && !isInline(node)) {
4017
- textContent += "\n";
4018
- addedTextInBlock = false;
4019
- }
4020
- node = walker2.nextNode();
4021
- }
4022
- return textContent;
4023
- };
4024
- proto.getPath = function() {
4025
- return this._path;
4026
- };
4027
- var removeZWS = function(root, keepNode) {
4028
- var walker2 = new TreeWalker(root, SHOW_TEXT, function() {
4029
- return true;
4030
- }), parent, node, index;
4031
- while (node = walker2.nextNode()) {
4032
- while ((index = node.data.indexOf(ZWS)) > -1 && (!keepNode || node.parentNode !== keepNode)) {
4033
- if (node.length === 1) {
4034
- do {
4035
- parent = node.parentNode;
4036
- parent.removeChild(node);
4037
- node = parent;
4038
- walker2.currentNode = parent;
4039
- } while (isInline(node) && !getLength(node));
4040
- break;
4041
- } else {
4042
- node.deleteData(index, 1);
4043
- }
4044
- }
4045
- }
4046
- };
4047
- proto._didAddZWS = function() {
4048
- this._hasZWS = true;
4049
- };
4050
- proto._removeZWS = function() {
4051
- if (!this._hasZWS) {
4052
- return;
4053
- }
4054
- removeZWS(this._root);
4055
- this._hasZWS = false;
4056
- };
4057
- proto._updatePath = function(range, force) {
4058
- if (!range) {
4059
- return;
4060
- }
4061
- var anchor = range.startContainer, focus = range.endContainer, newPath;
4062
- if (force || anchor !== this._lastAnchorNode || focus !== this._lastFocusNode) {
4063
- this._lastAnchorNode = anchor;
4064
- this._lastFocusNode = focus;
4065
- newPath = anchor && focus ? anchor === focus ? getPath(focus, this._root) : "(selection)" : "";
4066
- if (this._path !== newPath) {
4067
- this._path = newPath;
4068
- this.fireEvent("pathChange", { path: newPath });
4069
- }
4070
- }
4071
- this.fireEvent(range.collapsed ? "cursor" : "select", {
4072
- range
4073
- });
4074
- };
4075
- proto._updatePathOnEvent = function(event) {
4076
- var self2 = this;
4077
- if (self2._isFocused && !self2._willUpdatePath) {
4078
- self2._willUpdatePath = true;
4079
- setTimeout(function() {
4080
- self2._willUpdatePath = false;
4081
- self2._updatePath(self2.getSelection());
4082
- }, 0);
4083
- }
4084
- };
4085
- proto.focus = function() {
4086
- this._root.focus();
4087
- if (isIE) {
4088
- this.fireEvent("focus");
4089
- }
4090
- return this;
4091
- };
4092
- proto.blur = function() {
4093
- this._root.blur();
4094
- if (isIE) {
4095
- this.fireEvent("blur");
4096
- }
4097
- return this;
4098
- };
4099
- var startSelectionId = "squire-selection-start";
4100
- var endSelectionId = "squire-selection-end";
4101
- proto._saveRangeToBookmark = function(range) {
4102
- var startNode = this.createElement("INPUT", {
4103
- id: startSelectionId,
4104
- type: "hidden"
4105
- }), endNode = this.createElement("INPUT", {
4106
- id: endSelectionId,
4107
- type: "hidden"
4108
- }), temp;
4109
- insertNodeInRange(range, startNode);
4110
- range.collapse(false);
4111
- insertNodeInRange(range, endNode);
4112
- if (startNode.compareDocumentPosition(endNode) & DOCUMENT_POSITION_PRECEDING) {
4113
- startNode.id = endSelectionId;
4114
- endNode.id = startSelectionId;
4115
- temp = startNode;
4116
- startNode = endNode;
4117
- endNode = temp;
4118
- }
4119
- range.setStartAfter(startNode);
4120
- range.setEndBefore(endNode);
4121
- };
4122
- proto._getRangeAndRemoveBookmark = function(range) {
4123
- var root = this._root, start = root.querySelector("#" + startSelectionId), end = root.querySelector("#" + endSelectionId);
4124
- if (start && end) {
4125
- var startContainer = start.parentNode, endContainer = end.parentNode, startOffset = indexOf.call(startContainer.childNodes, start), endOffset = indexOf.call(endContainer.childNodes, end);
4126
- if (startContainer === endContainer) {
4127
- endOffset -= 1;
4128
- }
4129
- detach(start);
4130
- detach(end);
4131
- if (!range) {
4132
- range = this._doc.createRange();
4133
- }
4134
- range.setStart(startContainer, startOffset);
4135
- range.setEnd(endContainer, endOffset);
4136
- mergeInlines(startContainer, range);
4137
- if (startContainer !== endContainer) {
4138
- mergeInlines(endContainer, range);
4139
- }
4140
- if (range.collapsed) {
4141
- startContainer = range.startContainer;
4142
- if (startContainer.nodeType === TEXT_NODE) {
4143
- endContainer = startContainer.childNodes[range.startOffset];
4144
- if (!endContainer || endContainer.nodeType !== TEXT_NODE) {
4145
- endContainer = startContainer.childNodes[range.startOffset - 1];
4146
- }
4147
- if (endContainer && endContainer.nodeType === TEXT_NODE) {
4148
- range.setStart(endContainer, 0);
4149
- range.collapse(true);
4150
- }
4151
- }
4152
- }
4153
- }
4154
- return range || null;
4155
- };
4156
- proto._keyUpDetectChange = function(event) {
4157
- var code = event.keyCode;
4158
- if (!event.ctrlKey && !event.metaKey && !event.altKey && (code < 16 || code > 20) && (code < 33 || code > 45)) {
4159
- this._docWasChanged();
4160
- }
4161
- };
4162
- proto._docWasChanged = function() {
4163
- if (canWeakMap) {
4164
- nodeCategoryCache = /* @__PURE__ */ new WeakMap();
4165
- }
4166
- if (this._ignoreAllChanges) {
4167
- return;
4168
- }
4169
- if (canObserveMutations && this._ignoreChange) {
4170
- this._ignoreChange = false;
4171
- return;
4172
- }
4173
- if (this._isInUndoState) {
4174
- this._isInUndoState = false;
4175
- this.fireEvent("undoStateChange", {
4176
- canUndo: true,
4177
- canRedo: false
4178
- });
4179
- }
4180
- this.fireEvent("input");
4181
- };
4182
- proto._recordUndoState = function(range, replace) {
4183
- if (!this._isInUndoState || replace) {
4184
- var undoIndex = this._undoIndex;
4185
- var undoStack = this._undoStack;
4186
- var undoConfig = this._config.undo;
4187
- var undoThreshold = undoConfig.documentSizeThreshold;
4188
- var undoLimit = undoConfig.undoLimit;
4189
- var html;
4190
- if (!replace) {
4191
- undoIndex += 1;
4192
- }
4193
- if (undoIndex < this._undoStackLength) {
4194
- undoStack.length = this._undoStackLength = undoIndex;
4195
- }
4196
- if (range) {
4197
- this._saveRangeToBookmark(range);
4198
- }
4199
- html = this._getHTML();
4200
- if (undoThreshold > -1 && html.length * 2 > undoThreshold) {
4201
- if (undoLimit > -1 && undoIndex > undoLimit) {
4202
- undoStack.splice(0, undoIndex - undoLimit);
4203
- undoIndex = undoLimit;
4204
- this._undoStackLength = undoLimit;
4205
- }
4206
- }
4207
- undoStack[undoIndex] = html;
4208
- this._undoIndex = undoIndex;
4209
- this._undoStackLength += 1;
4210
- this._isInUndoState = true;
4211
- }
4212
- };
4213
- proto.saveUndoState = function(range) {
4214
- if (range === undefined$1) {
4215
- range = this.getSelection();
4216
- }
4217
- this._recordUndoState(range, this._isInUndoState);
4218
- this._getRangeAndRemoveBookmark(range);
4219
- return this;
4220
- };
4221
- proto.getUndoOrRedoState = function() {
4222
- return {
4223
- undo: this._undoIndex !== 0 || !this._isInUndoState,
4224
- redo: this._undoIndex + 1 < this._undoStackLength && this._isInUndoState
4225
- };
4226
- };
4227
- proto.undo = function() {
4228
- if (this._undoIndex !== 0 || !this._isInUndoState) {
4229
- this._recordUndoState(this.getSelection(), false);
4230
- this._undoIndex -= 1;
4231
- this._setHTML(this._undoStack[this._undoIndex]);
4232
- var range = this._getRangeAndRemoveBookmark();
4233
- if (range) {
4234
- this.setSelection(range);
4235
- }
4236
- this._isInUndoState = true;
4237
- this.fireEvent("undoStateChange", {
4238
- canUndo: this._undoIndex !== 0,
4239
- canRedo: true
4240
- });
4241
- this.fireEvent("input");
4242
- }
4243
- return this;
4244
- };
4245
- proto.redo = function() {
4246
- var undoIndex = this._undoIndex, undoStackLength = this._undoStackLength;
4247
- if (undoIndex + 1 < undoStackLength && this._isInUndoState) {
4248
- this._undoIndex += 1;
4249
- this._setHTML(this._undoStack[this._undoIndex]);
4250
- var range = this._getRangeAndRemoveBookmark();
4251
- if (range) {
4252
- this.setSelection(range);
4253
- }
4254
- this.fireEvent("undoStateChange", {
4255
- canUndo: true,
4256
- canRedo: undoIndex + 2 < undoStackLength
4257
- });
4258
- this.fireEvent("input");
4259
- }
4260
- return this;
4261
- };
4262
- proto.hasFormat = function(tag, attributes, range) {
4263
- tag = tag.toUpperCase();
4264
- if (!attributes) {
4265
- attributes = {};
4266
- }
4267
- if (!range && !(range = this.getSelection())) {
4268
- return false;
4269
- }
4270
- if (!range.collapsed && range.startContainer.nodeType === TEXT_NODE && range.startOffset === range.startContainer.length && range.startContainer.nextSibling) {
4271
- range.setStartBefore(range.startContainer.nextSibling);
4272
- }
4273
- if (!range.collapsed && range.endContainer.nodeType === TEXT_NODE && range.endOffset === 0 && range.endContainer.previousSibling) {
4274
- range.setEndAfter(range.endContainer.previousSibling);
4275
- }
4276
- var root = this._root;
4277
- var common = range.commonAncestorContainer;
4278
- var walker2, node;
4279
- if (getNearest(common, root, tag, attributes)) {
4280
- return true;
4281
- }
4282
- if (common.nodeType === TEXT_NODE) {
4283
- return false;
4284
- }
4285
- walker2 = new TreeWalker(common, SHOW_TEXT, function(node2) {
4286
- return isNodeContainedInRange(range, node2, true);
4287
- });
4288
- var seenNode = false;
4289
- while (node = walker2.nextNode()) {
4290
- if (!getNearest(node, root, tag, attributes)) {
4291
- return false;
4292
- }
4293
- seenNode = true;
4294
- }
4295
- return seenNode;
4296
- };
4297
- proto.getFontInfo = function(range) {
4298
- var fontInfo = {
4299
- color: undefined$1,
4300
- backgroundColor: undefined$1,
4301
- family: undefined$1,
4302
- size: undefined$1
4303
- };
4304
- var seenAttributes = 0;
4305
- var element, style, attr;
4306
- if (!range && !(range = this.getSelection())) {
4307
- return fontInfo;
4308
- }
4309
- element = range.commonAncestorContainer;
4310
- if (range.collapsed || element.nodeType === TEXT_NODE) {
4311
- if (element.nodeType === TEXT_NODE) {
4312
- element = element.parentNode;
4313
- }
4314
- while (seenAttributes < 4 && element) {
4315
- if (style = element.style) {
4316
- if (!fontInfo.color && (attr = style.color)) {
4317
- fontInfo.color = attr;
4318
- seenAttributes += 1;
4319
- }
4320
- if (!fontInfo.backgroundColor && (attr = style.backgroundColor)) {
4321
- fontInfo.backgroundColor = attr;
4322
- seenAttributes += 1;
4323
- }
4324
- if (!fontInfo.family && (attr = style.fontFamily)) {
4325
- fontInfo.family = attr;
4326
- seenAttributes += 1;
4327
- }
4328
- if (!fontInfo.size && (attr = style.fontSize)) {
4329
- fontInfo.size = attr;
4330
- seenAttributes += 1;
4331
- }
4332
- }
4333
- element = element.parentNode;
4334
- }
4335
- }
4336
- return fontInfo;
4337
- };
4338
- proto._addFormat = function(tag, attributes, range) {
4339
- var root = this._root;
4340
- var el, walker2, startContainer, endContainer, startOffset, endOffset, node, needsFormat, block;
4341
- if (range.collapsed) {
4342
- el = fixCursor(this.createElement(tag, attributes), root);
4343
- insertNodeInRange(range, el);
4344
- range.setStart(el.firstChild, el.firstChild.length);
4345
- range.collapse(true);
4346
- block = el;
4347
- while (isInline(block)) {
4348
- block = block.parentNode;
4349
- }
4350
- removeZWS(block, el);
4351
- } else {
4352
- walker2 = new TreeWalker(
4353
- range.commonAncestorContainer,
4354
- SHOW_TEXT | SHOW_ELEMENT,
4355
- function(node2) {
4356
- return (node2.nodeType === TEXT_NODE || node2.nodeName === "BR" || node2.nodeName === "IMG") && isNodeContainedInRange(range, node2, true);
4357
- }
4358
- );
4359
- startContainer = range.startContainer;
4360
- startOffset = range.startOffset;
4361
- endContainer = range.endContainer;
4362
- endOffset = range.endOffset;
4363
- walker2.currentNode = startContainer;
4364
- if (!walker2.filter(startContainer)) {
4365
- startContainer = walker2.nextNode();
4366
- startOffset = 0;
4367
- }
4368
- if (!startContainer) {
4369
- return range;
4370
- }
4371
- do {
4372
- node = walker2.currentNode;
4373
- needsFormat = !getNearest(node, root, tag, attributes);
4374
- if (needsFormat) {
4375
- if (node === endContainer && node.length > endOffset) {
4376
- node.splitText(endOffset);
4377
- }
4378
- if (node === startContainer && startOffset) {
4379
- node = node.splitText(startOffset);
4380
- if (endContainer === startContainer) {
4381
- endContainer = node;
4382
- endOffset -= startOffset;
4383
- }
4384
- startContainer = node;
4385
- startOffset = 0;
4386
- }
4387
- el = this.createElement(tag, attributes);
4388
- replaceWith(node, el);
4389
- el.appendChild(node);
4390
- }
4391
- } while (walker2.nextNode());
4392
- if (endContainer.nodeType !== TEXT_NODE) {
4393
- if (node.nodeType === TEXT_NODE) {
4394
- endContainer = node;
4395
- endOffset = node.length;
4396
- } else {
4397
- endContainer = node.parentNode;
4398
- endOffset = 1;
4399
- }
4400
- }
4401
- range = this.createRange(
4402
- startContainer,
4403
- startOffset,
4404
- endContainer,
4405
- endOffset
4406
- );
4407
- }
4408
- return range;
4409
- };
4410
- proto._removeFormat = function(tag, attributes, range, partial) {
4411
- this._saveRangeToBookmark(range);
4412
- var doc2 = this._doc, fixer;
4413
- if (range.collapsed) {
4414
- if (cantFocusEmptyTextNodes) {
4415
- fixer = doc2.createTextNode(ZWS);
4416
- this._didAddZWS();
4417
- } else {
4418
- fixer = doc2.createTextNode("");
4419
- }
4420
- insertNodeInRange(range, fixer);
4421
- }
4422
- var root = range.commonAncestorContainer;
4423
- while (isInline(root)) {
4424
- root = root.parentNode;
4425
- }
4426
- var startContainer = range.startContainer, startOffset = range.startOffset, endContainer = range.endContainer, endOffset = range.endOffset, toWrap = [], examineNode = function(node, exemplar) {
4427
- if (isNodeContainedInRange(range, node, false)) {
4428
- return;
4429
- }
4430
- var isText = node.nodeType === TEXT_NODE, child, next;
4431
- if (!isNodeContainedInRange(range, node, true)) {
4432
- if (node.nodeName !== "INPUT" && (!isText || node.data)) {
4433
- toWrap.push([exemplar, node]);
4434
- }
4435
- return;
4436
- }
4437
- if (isText) {
4438
- if (node === endContainer && endOffset !== node.length) {
4439
- toWrap.push([exemplar, node.splitText(endOffset)]);
4440
- }
4441
- if (node === startContainer && startOffset) {
4442
- node.splitText(startOffset);
4443
- toWrap.push([exemplar, node]);
4444
- }
4445
- } else {
4446
- for (child = node.firstChild; child; child = next) {
4447
- next = child.nextSibling;
4448
- examineNode(child, exemplar);
4449
- }
4450
- }
4451
- }, formatTags = Array.prototype.filter.call(
4452
- root.getElementsByTagName(tag),
4453
- function(el) {
4454
- return isNodeContainedInRange(range, el, true) && hasTagAttributes(el, tag, attributes);
4455
- }
4456
- );
4457
- if (!partial) {
4458
- formatTags.forEach(function(node) {
4459
- examineNode(node, node);
4460
- });
4461
- }
4462
- toWrap.forEach(function(item) {
4463
- var el = item[0].cloneNode(false), node = item[1];
4464
- replaceWith(node, el);
4465
- el.appendChild(node);
4466
- });
4467
- formatTags.forEach(function(el) {
4468
- replaceWith(el, empty(el));
4469
- });
4470
- this._getRangeAndRemoveBookmark(range);
4471
- if (fixer) {
4472
- range.collapse(false);
4473
- }
4474
- mergeInlines(root, range);
4475
- return range;
4476
- };
4477
- proto.hasFormatTag = function(tag) {
4478
- const range = this.getSelection();
4479
- const node = range.startContainer;
4480
- return !!getNearest(node, this._root, tag);
4481
- };
4482
- proto.changeFormat = function(add, remove, range, partial) {
4483
- if (!range && !(range = this.getSelection())) {
4484
- return this;
4485
- }
4486
- this.saveUndoState(range);
4487
- if (remove) {
4488
- range = this._removeFormat(
4489
- remove.tag.toUpperCase(),
4490
- remove.attributes || {},
4491
- range,
4492
- partial
4493
- );
4494
- }
4495
- if (add) {
4496
- range = this._addFormat(
4497
- add.tag.toUpperCase(),
4498
- add.attributes || {},
4499
- range
4500
- );
4501
- }
4502
- this.setSelection(range);
4503
- this._updatePath(range, true);
4504
- if (!canObserveMutations) {
4505
- this._docWasChanged();
4506
- }
4507
- return this;
4508
- };
4509
- var tagAfterSplit = {
4510
- DT: "DD",
4511
- DD: "DT",
4512
- LI: "LI",
4513
- PRE: "PRE"
4514
- };
4515
- var splitBlock = function(self2, block, node, offset) {
4516
- var splitTag = tagAfterSplit[block.nodeName], splitProperties = null, nodeAfterSplit = split(node, offset, block.parentNode, self2._root), config = self2._config;
4517
- var temAttr;
4518
- if (!splitTag) {
4519
- splitTag = config.blockTag;
4520
- var attr = { ...config.blockAttributes };
4521
- splitProperties = attr;
4522
- temAttr = { ...attr };
4523
- delete temAttr.class;
4524
- }
4525
- if (!hasTagAttributes(nodeAfterSplit, splitTag, temAttr || splitProperties)) {
4526
- block = createElement(
4527
- nodeAfterSplit.ownerDocument,
4528
- splitTag,
4529
- splitProperties
4530
- );
4531
- if (nodeAfterSplit.dir) {
4532
- block.dir = nodeAfterSplit.dir;
4533
- }
4534
- replaceWith(nodeAfterSplit, block);
4535
- block.appendChild(empty(nodeAfterSplit));
4536
- nodeAfterSplit = block;
4537
- }
4538
- return nodeAfterSplit;
4539
- };
4540
- proto.forEachBlock = function(fn, mutates, range) {
4541
- if (!range && !(range = this.getSelection())) {
4542
- return this;
4543
- }
4544
- if (mutates) {
4545
- this.saveUndoState(range);
4546
- }
4547
- var root = this._root;
4548
- var start = getStartBlockOfRange(range, root);
4549
- var end = getEndBlockOfRange(range, root);
4550
- if (start && end) {
4551
- do {
4552
- if (fn(start) || start === end) {
4553
- break;
4554
- }
4555
- } while (start = getNextBlock(start, root));
4556
- }
4557
- if (mutates) {
4558
- this.setSelection(range);
4559
- this._updatePath(range, true);
4560
- if (!canObserveMutations) {
4561
- this._docWasChanged();
4562
- }
4563
- }
4564
- return this;
4565
- };
4566
- proto.modifyBlocks = function(modify, range) {
4567
- if (!range && !(range = this.getSelection())) {
4568
- return this;
4569
- }
4570
- this._recordUndoState(range, this._isInUndoState);
4571
- var root = this._root;
4572
- var frag;
4573
- expandRangeToBlockBoundaries(range, root);
4574
- moveRangeBoundariesUpTree(range, root, root, root);
4575
- frag = extractContentsOfRange(range, root, root);
4576
- insertNodeInRange(range, modify.call(this, frag));
4577
- if (range.endOffset < range.endContainer.childNodes.length) {
4578
- mergeContainers(range.endContainer.childNodes[range.endOffset], root);
4579
- }
4580
- mergeContainers(range.startContainer.childNodes[range.startOffset], root);
4581
- this._getRangeAndRemoveBookmark(range);
4582
- this.setSelection(range);
4583
- this._updatePath(range, true);
4584
- if (!canObserveMutations) {
4585
- this._docWasChanged();
4586
- }
4587
- return this;
4588
- };
4589
- var increaseBlockQuoteLevel = function(frag) {
4590
- return this.createElement(
4591
- "BLOCKQUOTE",
4592
- this._config.tagAttributes.blockquote,
4593
- [
4594
- frag
4595
- ]
4596
- );
4597
- };
4598
- var decreaseBlockQuoteLevel = function(frag) {
4599
- var root = this._root;
4600
- var blockquotes = frag.querySelectorAll("blockquote");
4601
- Array.prototype.filter.call(blockquotes, function(el) {
4602
- return !getNearest(el.parentNode, root, "BLOCKQUOTE");
4603
- }).forEach(function(el) {
4604
- replaceWith(el, empty(el));
4605
- });
4606
- return frag;
4607
- };
4608
- var removeBlockQuote = function() {
4609
- return this.createDefaultBlock([
4610
- this.createElement("INPUT", {
4611
- id: startSelectionId,
4612
- type: "hidden"
4613
- }),
4614
- this.createElement("INPUT", {
4615
- id: endSelectionId,
4616
- type: "hidden"
4617
- })
4618
- ]);
4619
- };
4620
- var makeList = function(self2, frag, type) {
4621
- var walker2 = getBlockWalker(frag, self2._root), node, tag, prev, newLi, tagAttributes = self2._config.tagAttributes, listAttrs = tagAttributes[type.toLowerCase()], listItemAttrs = tagAttributes.li;
4622
- while (node = walker2.nextNode()) {
4623
- if (node.parentNode.nodeName === "LI") {
4624
- node = node.parentNode;
4625
- walker2.currentNode = node.lastChild;
4626
- }
4627
- if (node.nodeName !== "LI") {
4628
- newLi = self2.createElement("LI", listItemAttrs);
4629
- if (node.dir) {
4630
- newLi.dir = node.dir;
4631
- }
4632
- if ((prev = node.previousSibling) && prev.nodeName === type) {
4633
- prev.appendChild(newLi);
4634
- detach(node);
4635
- } else {
4636
- replaceWith(
4637
- node,
4638
- self2.createElement(type, listAttrs, [
4639
- newLi
4640
- ])
4641
- );
4642
- }
4643
- newLi.appendChild(empty(node));
4644
- walker2.currentNode = newLi;
4645
- } else {
4646
- node = node.parentNode;
4647
- tag = node.nodeName;
4648
- if (tag !== type && /^[OU]L$/.test(tag)) {
4649
- replaceWith(
4650
- node,
4651
- self2.createElement(type, listAttrs, [empty(node)])
4652
- );
4653
- }
4654
- }
4655
- }
4656
- };
4657
- var makeUnorderedList = function(frag) {
4658
- makeList(this, frag, "UL");
4659
- return frag;
4660
- };
4661
- var makeOrderedList = function(frag) {
4662
- makeList(this, frag, "OL");
4663
- return frag;
4664
- };
4665
- var removeList = function(frag) {
4666
- var lists = frag.querySelectorAll("UL, OL"), items = frag.querySelectorAll("LI"), root = this._root, i, l, list, listFrag, item;
4667
- for (i = 0, l = lists.length; i < l; i += 1) {
4668
- list = lists[i];
4669
- listFrag = empty(list);
4670
- fixContainer(listFrag, root);
4671
- replaceWith(list, listFrag);
4672
- }
4673
- for (i = 0, l = items.length; i < l; i += 1) {
4674
- item = items[i];
4675
- if (isBlock(item)) {
4676
- replaceWith(
4677
- item,
4678
- this.createDefaultBlock([empty(item)])
4679
- );
4680
- } else {
4681
- fixContainer(item, root);
4682
- replaceWith(item, empty(item));
4683
- }
4684
- }
4685
- return frag;
4686
- };
4687
- var getListSelection = function(range, root) {
4688
- var list = range.commonAncestorContainer;
4689
- var startLi = range.startContainer;
4690
- var endLi = range.endContainer;
4691
- while (list && list !== root && !/^[OU]L$/.test(list.nodeName)) {
4692
- list = list.parentNode;
4693
- }
4694
- if (!list || list === root) {
4695
- return null;
4696
- }
4697
- if (startLi === list) {
4698
- startLi = startLi.childNodes[range.startOffset];
4699
- }
4700
- if (endLi === list) {
4701
- endLi = endLi.childNodes[range.endOffset];
4702
- }
4703
- while (startLi && startLi.parentNode !== list) {
4704
- startLi = startLi.parentNode;
4705
- }
4706
- while (endLi && endLi.parentNode !== list) {
4707
- endLi = endLi.parentNode;
4708
- }
4709
- return [list, startLi, endLi];
4710
- };
4711
- proto.increaseListLevel = function(range) {
4712
- if (!range && !(range = this.getSelection())) {
4713
- return this.focus();
4714
- }
4715
- var root = this._root;
4716
- var listSelection = getListSelection(range, root);
4717
- if (!listSelection) {
4718
- return this.focus();
4719
- }
4720
- var list = listSelection[0];
4721
- var startLi = listSelection[1];
4722
- var endLi = listSelection[2];
4723
- if (!startLi || startLi === list.firstChild) {
4724
- return this.focus();
4725
- }
4726
- this._recordUndoState(range, this._isInUndoState);
4727
- var type = list.nodeName;
4728
- var newParent = startLi.previousSibling;
4729
- var listAttrs, next;
4730
- if (newParent.nodeName !== type) {
4731
- listAttrs = this._config.tagAttributes[type.toLowerCase()];
4732
- newParent = this.createElement(type, listAttrs);
4733
- list.insertBefore(newParent, startLi);
4734
- }
4735
- do {
4736
- next = startLi === endLi ? null : startLi.nextSibling;
4737
- newParent.appendChild(startLi);
4738
- } while (startLi = next);
4739
- next = newParent.nextSibling;
4740
- if (next) {
4741
- mergeContainers(next, root);
4742
- }
4743
- this._getRangeAndRemoveBookmark(range);
4744
- this.setSelection(range);
4745
- this._updatePath(range, true);
4746
- if (!canObserveMutations) {
4747
- this._docWasChanged();
4748
- }
4749
- return this.focus();
4750
- };
4751
- proto.decreaseListLevel = function(range) {
4752
- if (!range && !(range = this.getSelection())) {
4753
- return this.focus();
4754
- }
4755
- var root = this._root;
4756
- var listSelection = getListSelection(range, root);
4757
- if (!listSelection) {
4758
- return this.focus();
4759
- }
4760
- var list = listSelection[0];
4761
- var startLi = listSelection[1];
4762
- var endLi = listSelection[2];
4763
- if (!startLi) {
4764
- startLi = list.firstChild;
4765
- }
4766
- if (!endLi) {
4767
- endLi = list.lastChild;
4768
- }
4769
- this._recordUndoState(range, this._isInUndoState);
4770
- var newParent = list.parentNode;
4771
- var next;
4772
- var insertBefore = !endLi.nextSibling ? list.nextSibling : split(list, endLi.nextSibling, newParent, root);
4773
- if (newParent !== root && newParent.nodeName === "LI") {
4774
- newParent = newParent.parentNode;
4775
- while (insertBefore) {
4776
- next = insertBefore.nextSibling;
4777
- endLi.appendChild(insertBefore);
4778
- insertBefore = next;
4779
- }
4780
- insertBefore = list.parentNode.nextSibling;
4781
- }
4782
- var makeNotList = !/^[OU]L$/.test(newParent.nodeName);
4783
- do {
4784
- next = startLi === endLi ? null : startLi.nextSibling;
4785
- list.removeChild(startLi);
4786
- if (makeNotList && startLi.nodeName === "LI") {
4787
- startLi = this.createDefaultBlock([empty(startLi)]);
4788
- }
4789
- newParent.insertBefore(startLi, insertBefore);
4790
- } while (startLi = next);
4791
- if (!list.firstChild) {
4792
- detach(list);
4793
- }
4794
- if (insertBefore) {
4795
- mergeContainers(insertBefore, root);
4796
- }
4797
- this._getRangeAndRemoveBookmark(range);
4798
- this.setSelection(range);
4799
- this._updatePath(range, true);
4800
- if (!canObserveMutations) {
4801
- this._docWasChanged();
4802
- }
4803
- return this.focus();
4804
- };
4805
- proto._ensureBottomLine = function() {
4806
- var root = this._root;
4807
- var last = root.lastElementChild;
4808
- if (!last || last.nodeName !== this._config.blockTag || !isBlock(last)) {
4809
- root.appendChild(this.createDefaultBlock());
4810
- }
4811
- };
4812
- proto.setKeyHandler = function(key, fn) {
4813
- this._keyHandlers[key] = fn;
4814
- return this;
4815
- };
4816
- proto._getHTML = function() {
4817
- return this._root.innerHTML;
4818
- };
4819
- function fixTextarea(node) {
4820
- var nodes = node.childNodes;
4821
- for (let i = 0; i < nodes.length; i++) {
4822
- const node2 = nodes[i];
4823
- if (node2.nodeType === 1) {
4824
- if (node2.classList.contains("halo-img-content")) {
4825
- var img = node2.querySelector("img");
4826
- var desc = img.dataset.desc;
4827
- var textarea = node2.querySelector("textarea");
4828
- textarea.innerHTML = "";
4829
- textarea.value = desc || "";
4830
- }
4831
- }
4832
- }
4833
- }
4834
- proto._setHTML = function(html) {
4835
- var root = this._root;
4836
- var node = root;
4837
- node.innerHTML = html;
4838
- fixTextarea(node);
4839
- do {
4840
- fixCursor(node, root);
4841
- } while (node = getNextBlock(node, root));
4842
- this._ignoreChange = true;
4843
- };
4844
- proto.getHTML = function(withBookMark) {
4845
- var brs = [], root, node, fixer, html, l, range;
4846
- if (withBookMark && (range = this.getSelection())) {
4847
- this._saveRangeToBookmark(range);
4848
- }
4849
- if (useTextFixer) {
4850
- root = this._root;
4851
- node = root;
4852
- while (node = getNextBlock(node, root)) {
4853
- if (!node.textContent && !node.querySelector("BR")) {
4854
- fixer = this.createElement("BR");
4855
- node.appendChild(fixer);
4856
- brs.push(fixer);
4857
- }
4858
- }
4859
- }
4860
- html = this._getHTML().replace(/\u200B/g, "");
4861
- if (useTextFixer) {
4862
- l = brs.length;
4863
- while (l--) {
4864
- detach(brs[l]);
4865
- }
4866
- }
4867
- if (range) {
4868
- this._getRangeAndRemoveBookmark(range);
4869
- }
4870
- return html;
4871
- };
4872
- proto.setHTML = function(html) {
4873
- var config = this._config;
4874
- var sanitizeToDOMFragment2 = config.isSetHTMLSanitized ? config.sanitizeToDOMFragment : null;
4875
- var root = this._root;
4876
- var div, frag, child;
4877
- if (typeof sanitizeToDOMFragment2 === "function") {
4878
- frag = sanitizeToDOMFragment2(html, false, this);
4879
- } else {
4880
- div = this.createElement("DIV");
4881
- div.innerHTML = html;
4882
- frag = this._doc.createDocumentFragment();
4883
- frag.appendChild(empty(div));
4884
- }
4885
- cleanTree(frag);
4886
- cleanupBRs(frag, root, false);
4887
- fixContainer(frag, root);
4888
- var node = frag;
4889
- while (node = getNextBlock(node, root)) {
4890
- fixCursor(node, root);
4891
- }
4892
- this._ignoreChange = true;
4893
- while (child = root.lastChild) {
4894
- root.removeChild(child);
4895
- }
4896
- root.appendChild(frag);
4897
- fixCursor(root, root);
4898
- this._undoIndex = -1;
4899
- this._undoStack.length = 0;
4900
- this._undoStackLength = 0;
4901
- this._isInUndoState = false;
4902
- var range = this._getRangeAndRemoveBookmark() || this.createRange(root.firstChild, 0);
4903
- this.saveUndoState(range);
4904
- this._lastSelection = range;
4905
- enableRestoreSelection.call(this);
4906
- this._updatePath(range, true);
4907
- return this;
4908
- };
4909
- proto.insertElement = function(el, range) {
4910
- if (!range) {
4911
- range = this.getSelection();
4912
- }
4913
- range.collapse(true);
4914
- if (isInline(el)) {
4915
- insertNodeInRange(range, el);
4916
- range.setStartAfter(el);
4917
- } else {
4918
- var root = this._root;
4919
- var splitNode = getStartBlockOfRange(range, root) || root;
4920
- var parent, nodeAfterSplit;
4921
- while (splitNode !== root && !splitNode.nextSibling) {
4922
- splitNode = splitNode.parentNode;
4923
- }
4924
- if (splitNode !== root) {
4925
- parent = splitNode.parentNode;
4926
- nodeAfterSplit = split(parent, splitNode.nextSibling, root, root);
4927
- }
4928
- if (nodeAfterSplit) {
4929
- root.insertBefore(el, nodeAfterSplit);
4930
- const node = this.createDefaultBlock();
4931
- root.insertBefore(node, nodeAfterSplit);
4932
- nodeAfterSplit = node;
4933
- } else {
4934
- root.appendChild(el);
4935
- nodeAfterSplit = this.createDefaultBlock();
4936
- root.appendChild(nodeAfterSplit);
4937
- }
4938
- range.setStart(nodeAfterSplit, 0);
4939
- range.setEnd(nodeAfterSplit, 0);
4940
- moveRangeBoundariesDownTree(range);
4941
- }
4942
- this.focus();
4943
- this.setSelection(range);
4944
- this._updatePath(range);
4945
- if (!canObserveMutations) {
4946
- this._docWasChanged();
4947
- }
4948
- return this;
4949
- };
4950
- proto.insertImage = function(src, attributes) {
4951
- var img = this.createElement("IMG", mergeObjects({
4952
- src
4953
- }, attributes, true));
4954
- this.insertElement(img);
4955
- return img;
4956
- };
4957
- var linkRegExp = /\b((?:(?:ht|f)tps?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))|([\w\-.%+]+@(?:[\w\-]+\.)+[A-Z]{2,}\b)(?:\?[^&?\s]+=[^&?\s]+(?:&[^&?\s]+=[^&?\s]+)*)?/i;
4958
- var addLinks = function(frag, root, self2) {
4959
- var doc2 = frag.ownerDocument, walker2 = new TreeWalker(
4960
- frag,
4961
- SHOW_TEXT,
4962
- function(node2) {
4963
- return !getNearest(node2, root, "A");
4964
- }
4965
- ), defaultAttributes = self2._config.tagAttributes.a, node, data, parent, match, index, endIndex, child;
4966
- while (node = walker2.nextNode()) {
4967
- data = node.data;
4968
- parent = node.parentNode;
4969
- while (match = linkRegExp.exec(data)) {
4970
- index = match.index;
4971
- endIndex = index + match[0].length;
4972
- if (index) {
4973
- child = doc2.createTextNode(data.slice(0, index));
4974
- parent.insertBefore(child, node);
4975
- }
4976
- child = self2.createElement("A", mergeObjects({
4977
- href: match[1] ? /^(?:ht|f)tps?:/i.test(match[1]) ? match[1] : "http://" + match[1] : "mailto:" + match[0]
4978
- }, defaultAttributes, false));
4979
- child.textContent = data.slice(index, endIndex);
4980
- parent.insertBefore(child, node);
4981
- node.data = data = data.slice(endIndex);
4982
- }
4983
- }
4984
- };
4985
- proto.insertHTML = function(html, isPaste) {
4986
- var config = this._config;
4987
- var sanitizeToDOMFragment2 = config.isInsertedHTMLSanitized ? config.sanitizeToDOMFragment : null;
4988
- var range = this.getSelection();
4989
- var doc2 = this._doc;
4990
- var startFragmentIndex, endFragmentIndex;
4991
- var div, frag, root, node, event;
4992
- if (typeof sanitizeToDOMFragment2 === "function") {
4993
- frag = sanitizeToDOMFragment2(html, isPaste, this);
4994
- } else {
4995
- if (isPaste) {
4996
- startFragmentIndex = html.indexOf("<!--StartFragment-->");
4997
- endFragmentIndex = html.lastIndexOf("<!--EndFragment-->");
4998
- if (startFragmentIndex > -1 && endFragmentIndex > -1) {
4999
- html = html.slice(startFragmentIndex + 20, endFragmentIndex);
5000
- }
5001
- }
5002
- if (/<\/td>((?!<\/tr>)[\s\S])*$/i.test(html)) {
5003
- html = "<TR>" + html + "</TR>";
5004
- }
5005
- if (/<\/tr>((?!<\/table>)[\s\S])*$/i.test(html)) {
5006
- html = "<TABLE>" + html + "</TABLE>";
5007
- }
5008
- div = this.createElement("DIV");
5009
- div.innerHTML = html;
5010
- frag = doc2.createDocumentFragment();
5011
- frag.appendChild(empty(div));
5012
- }
5013
- this.saveUndoState(range);
5014
- try {
5015
- root = this._root;
5016
- node = frag;
5017
- event = {
5018
- fragment: frag,
5019
- preventDefault: function() {
5020
- this.defaultPrevented = true;
5021
- },
5022
- defaultPrevented: false
5023
- };
5024
- addLinks(frag, frag, this);
5025
- cleanTree(frag);
5026
- cleanupBRs(frag, root, false);
5027
- removeEmptyInlines(frag);
5028
- frag.normalize();
5029
- while (node = getNextBlock(node, frag)) {
5030
- fixCursor(node, root);
5031
- }
5032
- if (isPaste) {
5033
- this.fireEvent("willPaste", event);
5034
- }
5035
- if (!event.defaultPrevented) {
5036
- insertTreeFragmentIntoRange(range, event.fragment, root);
5037
- if (!canObserveMutations) {
5038
- this._docWasChanged();
5039
- }
5040
- range.collapse(false);
5041
- this._ensureBottomLine();
5042
- }
5043
- this.setSelection(range);
5044
- this._updatePath(range, true);
5045
- if (isPaste) {
5046
- this.focus();
5047
- }
5048
- } catch (error) {
5049
- this.didError(error);
5050
- }
5051
- return this;
5052
- };
5053
- var escapeHTMLFragement = function(text) {
5054
- return text.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;").split('"').join("&quot;");
5055
- };
5056
- proto.insertPlainText = function(plainText, isPaste) {
5057
- var lines = plainText.split("\n");
5058
- var config = this._config;
5059
- var tag = config.blockTag;
5060
- var attributes = config.blockAttributes;
5061
- var closeBlock = "</" + tag + ">";
5062
- var openBlock2 = "<" + tag;
5063
- var attr, i, l, line;
5064
- for (attr in attributes) {
5065
- openBlock2 += " " + attr + '="' + escapeHTMLFragement(attributes[attr]) + '"';
5066
- }
5067
- openBlock2 += ">";
5068
- for (i = 0, l = lines.length; i < l; i += 1) {
5069
- line = lines[i];
5070
- line = escapeHTMLFragement(line).replace(/ (?= )/g, "&nbsp;");
5071
- lines[i] = openBlock2 + (line || "<BR>") + closeBlock;
5072
- }
5073
- return this.insertHTML(lines.join(""), isPaste);
5074
- };
5075
- var command = function(method, arg, arg2) {
5076
- return function() {
5077
- this[method](arg, arg2);
5078
- return this.focus();
5079
- };
5080
- };
5081
- proto.addStyles = function(styles) {
5082
- if (styles) {
5083
- var head = this._doc.documentElement.firstChild, style = this.createElement("STYLE", {
5084
- type: "text/css"
5085
- });
5086
- style.appendChild(this._doc.createTextNode(styles));
5087
- head.appendChild(style);
5088
- }
5089
- return this;
5090
- };
5091
- proto.bold = command("changeFormat", { tag: "B" });
5092
- proto.italic = command("changeFormat", { tag: "I" });
5093
- proto.underline = command("changeFormat", { tag: "U" });
5094
- proto.strikethrough = command("changeFormat", { tag: "S" });
5095
- proto.subscript = command("changeFormat", { tag: "SUB" }, { tag: "SUP" });
5096
- proto.superscript = command("changeFormat", { tag: "SUP" }, { tag: "SUB" });
5097
- proto.removeBold = command("changeFormat", null, { tag: "B" });
5098
- proto.removeItalic = command("changeFormat", null, { tag: "I" });
5099
- proto.removeUnderline = command("changeFormat", null, { tag: "U" });
5100
- proto.removeStrikethrough = command("changeFormat", null, { tag: "S" });
5101
- proto.removeSubscript = command("changeFormat", null, { tag: "SUB" });
5102
- proto.removeSuperscript = command("changeFormat", null, { tag: "SUP" });
5103
- proto.makeLink = function(url, attributes) {
5104
- var range = this.getSelection();
5105
- if (range.collapsed) {
5106
- var protocolEnd = url.indexOf(":") + 1;
5107
- if (protocolEnd) {
5108
- while (url[protocolEnd] === "/") {
5109
- protocolEnd += 1;
5110
- }
5111
- }
5112
- insertNodeInRange(
5113
- range,
5114
- this._doc.createTextNode(url.slice(protocolEnd))
5115
- );
5116
- }
5117
- attributes = mergeObjects(
5118
- mergeObjects({
5119
- href: url
5120
- }, attributes, true),
5121
- this._config.tagAttributes.a,
5122
- false
5123
- );
5124
- this.changeFormat({
5125
- tag: "A",
5126
- attributes
5127
- }, {
5128
- tag: "A"
5129
- }, range);
5130
- return this.focus();
5131
- };
5132
- proto.removeLink = function() {
5133
- this.changeFormat(null, {
5134
- tag: "A"
5135
- }, this.getSelection(), true);
5136
- return this.focus();
5137
- };
5138
- proto.setFontFace = function(name) {
5139
- this.changeFormat(name ? {
5140
- tag: "SPAN",
5141
- attributes: {
5142
- "class": FONT_FAMILY_CLASS,
5143
- style: "font-family: " + name + ", sans-serif;"
5144
- }
5145
- } : null, {
5146
- tag: "SPAN",
5147
- attributes: { "class": FONT_FAMILY_CLASS }
5148
- });
5149
- return this.focus();
5150
- };
5151
- proto.setFontSize = function(size) {
5152
- this.changeFormat(size ? {
5153
- tag: "SPAN",
5154
- attributes: {
5155
- "class": FONT_SIZE_CLASS,
5156
- style: "font-size: " + (typeof size === "number" ? size + "px" : size)
5157
- }
5158
- } : null, {
5159
- tag: "SPAN",
5160
- attributes: { "class": FONT_SIZE_CLASS }
5161
- });
5162
- return this.focus();
5163
- };
5164
- proto.setTextColour = function(colour) {
5165
- this.changeFormat(colour ? {
5166
- tag: "SPAN",
5167
- attributes: {
5168
- "class": COLOUR_CLASS,
5169
- style: "color:" + colour
5170
- }
5171
- } : null);
5172
- return this.focus();
5173
- };
5174
- proto.setHighlightColour = function(colour) {
5175
- this.changeFormat(colour ? {
5176
- tag: "SPAN",
5177
- attributes: {
5178
- "class": HIGHLIGHT_CLASS,
5179
- style: "background-color:" + colour
5180
- }
5181
- } : colour, {
5182
- tag: "SPAN",
5183
- attributes: { "class": HIGHLIGHT_CLASS }
5184
- });
5185
- return this.focus();
5186
- };
5187
- proto.setTextAlignment = function(alignment) {
5188
- this.forEachBlock(function(block) {
5189
- var className = block.className.split(/\s+/).filter(function(klass) {
5190
- return !!klass && !/^align/.test(klass);
5191
- }).join(" ");
5192
- if (alignment) {
5193
- block.className = className + " align-" + alignment;
5194
- block.style.textAlign = alignment;
5195
- } else {
5196
- block.className = className;
5197
- block.style.textAlign = "";
5198
- }
5199
- }, true);
5200
- return this.focus();
5201
- };
5202
- proto.setIndent = function() {
5203
- this.forEachBlock(function(block) {
5204
- var className = block.className.split(/\s+/).filter(function(klass) {
5205
- return !!klass && !/^indent/.test(klass);
5206
- }).join(" ");
5207
- if (block.className.indexOf("indent-text") > -1) {
5208
- block.className = className;
5209
- block.style.textIndent = "";
5210
- } else {
5211
- block.className = className + " indent-text";
5212
- block.style.textIndent = "2em";
5213
- }
5214
- }, true);
5215
- return this.focus();
5216
- };
5217
- proto.setTextDirection = function(direction) {
5218
- this.forEachBlock(function(block) {
5219
- if (direction) {
5220
- block.dir = direction;
5221
- } else {
5222
- block.removeAttribute("dir");
5223
- }
5224
- }, true);
5225
- return this.focus();
5226
- };
5227
- function removeFormatting(self2, root, clean) {
5228
- var node, next;
5229
- for (node = root.firstChild; node; node = next) {
5230
- next = node.nextSibling;
5231
- if (isInline(node)) {
5232
- if (node.nodeType === TEXT_NODE || node.nodeName === "BR" || node.nodeName === "IMG") {
5233
- clean.appendChild(node);
5234
- continue;
5235
- }
5236
- } else if (isBlock(node)) {
5237
- clean.appendChild(self2.createDefaultBlock([
5238
- removeFormatting(
5239
- self2,
5240
- node,
5241
- self2._doc.createDocumentFragment()
5242
- )
5243
- ]));
5244
- continue;
5245
- }
5246
- removeFormatting(self2, node, clean);
5247
- }
5248
- return clean;
5249
- }
5250
- proto.removeAllFormatting = function(range) {
5251
- if (!range && !(range = this.getSelection()) || range.collapsed) {
5252
- return this;
5253
- }
5254
- var root = this._root;
5255
- var stopNode = range.commonAncestorContainer;
5256
- while (stopNode && !isBlock(stopNode)) {
5257
- stopNode = stopNode.parentNode;
5258
- }
5259
- if (!stopNode) {
5260
- expandRangeToBlockBoundaries(range, root);
5261
- stopNode = root;
5262
- }
5263
- if (stopNode.nodeType === TEXT_NODE) {
5264
- return this;
5265
- }
5266
- this.saveUndoState(range);
5267
- moveRangeBoundariesUpTree(range, stopNode, stopNode, root);
5268
- var doc2 = stopNode.ownerDocument;
5269
- var startContainer = range.startContainer;
5270
- var startOffset = range.startOffset;
5271
- var endContainer = range.endContainer;
5272
- var endOffset = range.endOffset;
5273
- var formattedNodes = doc2.createDocumentFragment();
5274
- var cleanNodes = doc2.createDocumentFragment();
5275
- var nodeAfterSplit = split(endContainer, endOffset, stopNode, root);
5276
- var nodeInSplit = split(startContainer, startOffset, stopNode, root);
5277
- var nextNode, childNodes;
5278
- while (nodeInSplit !== nodeAfterSplit) {
5279
- nextNode = nodeInSplit.nextSibling;
5280
- formattedNodes.appendChild(nodeInSplit);
5281
- nodeInSplit = nextNode;
5282
- }
5283
- removeFormatting(this, formattedNodes, cleanNodes);
5284
- cleanNodes.normalize();
5285
- nodeInSplit = cleanNodes.firstChild;
5286
- nextNode = cleanNodes.lastChild;
5287
- childNodes = stopNode.childNodes;
5288
- if (nodeInSplit) {
5289
- stopNode.insertBefore(cleanNodes, nodeAfterSplit);
5290
- startOffset = indexOf.call(childNodes, nodeInSplit);
5291
- endOffset = indexOf.call(childNodes, nextNode) + 1;
5292
- } else {
5293
- startOffset = indexOf.call(childNodes, nodeAfterSplit);
5294
- endOffset = startOffset;
5295
- }
5296
- range.setStart(stopNode, startOffset);
5297
- range.setEnd(stopNode, endOffset);
5298
- mergeInlines(stopNode, range);
5299
- moveRangeBoundariesDownTree(range);
5300
- this.setSelection(range);
5301
- this._updatePath(range, true);
5302
- return this.focus();
5303
- };
5304
- proto.increaseQuoteLevel = command("modifyBlocks", increaseBlockQuoteLevel);
5305
- proto.decreaseQuoteLevel = command("modifyBlocks", decreaseBlockQuoteLevel);
5306
- proto.makeUnorderedList = command("modifyBlocks", makeUnorderedList);
5307
- proto.makeOrderedList = command("modifyBlocks", makeOrderedList);
5308
- proto.removeList = command("modifyBlocks", removeList);
5309
- proto.empty = empty;
5310
- Squire.isInline = isInline;
5311
- Squire.isBlock = isBlock;
5312
- Squire.isContainer = isContainer;
5313
- Squire.getBlockWalker = getBlockWalker;
5314
- Squire.getPreviousBlock = getPreviousBlock;
5315
- Squire.getNextBlock = getNextBlock;
5316
- Squire.areAlike = areAlike;
5317
- Squire.hasTagAttributes = hasTagAttributes;
5318
- Squire.getNearest = getNearest;
5319
- Squire.isOrContains = isOrContains;
5320
- Squire.detach = detach;
5321
- Squire.replaceWith = replaceWith;
5322
- Squire.empty = empty;
5323
- Squire.getNodeBefore = getNodeBefore;
5324
- Squire.getNodeAfter = getNodeAfter;
5325
- Squire.insertNodeInRange = insertNodeInRange;
5326
- Squire.extractContentsOfRange = extractContentsOfRange;
5327
- Squire.deleteContentsOfRange = deleteContentsOfRange;
5328
- Squire.insertTreeFragmentIntoRange = insertTreeFragmentIntoRange;
5329
- Squire.isNodeContainedInRange = isNodeContainedInRange;
5330
- Squire.moveRangeBoundariesDownTree = moveRangeBoundariesDownTree;
5331
- Squire.moveRangeBoundariesUpTree = moveRangeBoundariesUpTree;
5332
- Squire.getStartBlockOfRange = getStartBlockOfRange;
5333
- Squire.getEndBlockOfRange = getEndBlockOfRange;
5334
- Squire.contentWalker = contentWalker;
5335
- Squire.rangeDoesStartAtBlockBoundary = rangeDoesStartAtBlockBoundary;
5336
- Squire.rangeDoesEndAtBlockBoundary = rangeDoesEndAtBlockBoundary;
5337
- Squire.expandRangeToBlockBoundaries = expandRangeToBlockBoundaries;
5338
- Squire.onPaste = onPaste;
5339
- Squire.addLinks = addLinks;
5340
- Squire.splitBlock = splitBlock;
5341
- Squire.startSelectionId = startSelectionId;
5342
- Squire.endSelectionId = endSelectionId;
5343
- if (typeof exports === "object") {
5344
- module.exports = Squire;
5345
- } else if (typeof define === "function" && define.amd) {
5346
- define(function() {
5347
- return Squire;
5348
- });
5349
- } else {
5350
- win.Squire = Squire;
5351
- if (top !== win && doc.documentElement.getAttribute("data-squireinit") === "true") {
5352
- win.editor = new Squire(doc);
5353
- if (win.onEditorLoad) {
5354
- win.onEditorLoad(win.editor);
5355
- win.onEditorLoad = null;
5356
- }
5357
- }
5358
- }
5359
- })(document);
5360
- const Editor_vue_vue_type_style_index_0_lang = "";
5361
- const cursorImg = `url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACIAAAAYCAMAAACoeN87AAAAh1BMVEUAAAACAgL39/cICAgFBQUAAAADAwMKCgr6+vrn5+fr6+v6+voEBAT19fXm5ubf39+pqanBwcH8/PzOzs76+vrx8fHz8/P29vbh4eHm5ubT09OXl5f///9ZWVkiIiLIyMjGxsY+Pj5LS0uenp4vLy/V1dXk5OSsrKxnZ2eRkZF1dXXj4+ODg4P4y9kGAAAAHHRSTlMACMUDDQYOCuONi8MSt2tJMCryT9OpqKaRezobrP6h8wAAAR9JREFUKM+dk1lygzAMQOMtxoQlS/dKBrMn7f3PVwEFPND0I+/Dg8RD0mjM7nGEZoIOqfwc+0jTVE+RgcAcTQBvbFFOvM7zJvgcIw2uaKF0DuRS5LW1RBmKMQyhdugyMGJWGMciywrkauobZrY2kgxPQQCcFGIPFvb+sNGkSLUo3iDqEvPzqJz5IVF/KEnTIVak0IG35rJV1OFGr7AEKJHULh7KRKRE86gHLPKZAjnrkwEpgV4U6zEqEugRpL+TmXtVEGaQlO0sfK1sVnds7Pf/yim42q9FccjVai/q5WornKlsm4hVFRGX6NFlT7rPSlPb3GgxNnrmHvF7nxYh5A5dDaEaWzGf4TsGzpXQFsut2yDC37tr1O4eSurhD6CaPzWzJeCQ3tPtAAAAAElFTkSuQmCC) 28 10, text`;
5362
- const keyToEditorMethod = {
5363
- bold: "bold",
5364
- italic: "italic",
5365
- underline: "underline",
5366
- size: "setFontSize",
5367
- color: "setTextColour"
5368
- };
5369
- const _sfc_main = {
5370
- name: "Edit",
5371
- components: {
5372
- InsertArticle: _sfc_main$5,
5373
- ImgUpload: _sfc_main$4,
5374
- VideoUpload,
5375
- CollectArticle
5376
- },
5377
- props: [
5378
- "disabled",
5379
- "isOss",
5380
- "getEassyDetail",
5381
- "getArticleList",
5382
- "importEssay",
5383
- "uploadImageByOther"
5384
- ],
5385
- data() {
5386
- return {
5387
- hasArticleCard: false,
5388
- cursorStyle: "auto",
5389
- titleCount: 0,
5390
- viewLinkDialog: false,
5391
- linkForm: {
5392
- linkAddress: "",
5393
- linkWriting: ""
5394
- },
5395
- setAlignFlag: true,
5396
- article: {},
5397
- imgList: [],
5398
- videoList: [],
5399
- visibleVideo: false,
5400
- visibleCollectArticle: false,
5401
- visibleArticle: false,
5402
- visibleImg: false,
5403
- imgType: "normal",
5404
- typeEnum: {
5405
- "\u6587\u5B57": "1",
5406
- "\u56FE\u7247": "2",
5407
- "\u56FE\u6587": "3",
5408
- "\u6BB5\u843D\u6807\u9898": "4",
5409
- "\u5173\u8054": "5",
5410
- "\u5355\u89C6\u9891": "6",
5411
- "\u89C6\u9891\u6587\u5B57": "7",
5412
- "URL": "8",
5413
- "\u6587\u7AE0\u5361\u7247": "11"
5414
- },
5415
- fontInfo: {
5416
- size: ""
5417
- },
5418
- user: {},
5419
- editor: {},
5420
- editorDom: {},
5421
- uploadStore: {},
5422
- linkContent: "",
5423
- loadingText: "",
5424
- progressPercent: "",
5425
- currentIndex: 0,
5426
- loading: false,
5427
- viewStatus: false,
5428
- linkStatus: false,
5429
- styleStatus: {
5430
- bold: false,
5431
- italic: false,
5432
- size: "",
5433
- color: "",
5434
- underline: false,
5435
- title: false
5436
- },
5437
- contentLen: 0,
5438
- imgCount: 0,
5439
- backState: {
5440
- redo: false,
5441
- undo: false
5442
- },
5443
- countList: [],
5444
- replaceSeamless: 0,
5445
- seamlessCount: 0
5446
- };
5447
- },
5448
- computed: {
5449
- align() {
5450
- if (!this.isInputing && !this.titleCount && !this.hasArticleCard) {
5451
- return this.getCursorAlignStyle() || "left";
5452
- }
5453
- return "left";
5454
- },
5455
- isInputing() {
5456
- return this.contentLen > 0 || this.imgCount > 0;
5457
- }
5458
- },
5459
- watch: {
5460
- progressPercent(val) {
5461
- const inner = document.querySelector(".video-progress .inner");
5462
- console.log(val, "\u89C6\u9891\u4E0A\u4F20\u8FDB\u5EA6");
5463
- if (inner) {
5464
- inner.style.width = val + "%";
5465
- if (val === 100) {
5466
- document.querySelector(".video-progress").innerHTML = `
5467
- <div class="no-calc" style="text-align:center;color:#999999;font-size:18px;">\u6B63\u5728\u83B7\u53D6\u89C6\u9891\u5C01\u9762</div>
5468
- `;
5469
- }
5470
- }
5471
- },
5472
- disabled: {
5473
- handler(val) {
5474
- if (val) {
5475
- this.editorDom.contentEditable = "false";
5476
- }
5477
- },
5478
- immediate: true
1829
+ },
1830
+ immediate: true
5479
1831
  }
5480
1832
  },
5481
1833
  created() {
@@ -5491,7 +1843,9 @@ const _sfc_main = {
5491
1843
  me.editorDom = document.getElementById("editor-content");
5492
1844
  me.editorDom.addEventListener("blur", this.canSetAlign);
5493
1845
  if (!window.Squire) {
5494
- me.initSquire();
1846
+ import("./squire-raw.806d5241.js").then(function() {
1847
+ me.initSquire();
1848
+ });
5495
1849
  } else {
5496
1850
  me.initSquire();
5497
1851
  }
@@ -6627,8 +2981,8 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
6627
2981
  onKeyup: _cache[0] || (_cache[0] = ($event) => $options.setBack($event))
6628
2982
  }, null, 36),
6629
2983
  createVNode(_component_el_dialog, {
6630
- visible: $data.viewLinkDialog,
6631
- "onUpdate:visible": _cache[4] || (_cache[4] = ($event) => $data.viewLinkDialog = $event),
2984
+ modelValue: $data.viewLinkDialog,
2985
+ "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => $data.viewLinkDialog = $event),
6632
2986
  "before-close": $options.handleClose,
6633
2987
  class: "squire-dialog-content",
6634
2988
  "append-to-body": ""
@@ -6687,7 +3041,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
6687
3041
  ])
6688
3042
  ]),
6689
3043
  _: 1
6690
- }, 8, ["visible", "before-close"]),
3044
+ }, 8, ["modelValue", "before-close"]),
6691
3045
  createVNode(_component_InsertArticle, {
6692
3046
  article: $data.article,
6693
3047
  visible: $data.visibleArticle,