diff --git a/node_modules/quill/dist/quill.js b/node_modules/quill/dist/quill.js index 811b3d0..9243ab6 100644 --- a/node_modules/quill/dist/quill.js +++ b/node_modules/quill/dist/quill.js @@ -4295,7 +4295,7 @@ var Scroll = function (_Parchment$Scroll) { value: function enable() { var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; - this.domNode.setAttribute('contenteditable', enabled); + this.domNode.setAttribute('contenteditable', enabled ? 'plaintext-only' : false); } }, { key: 'formatAt', @@ -8896,7 +8896,8 @@ var debug = (0, _logger2.default)('quill:clipboard'); var DOM_KEY = '__ql-matcher'; -var CLIPBOARD_CONFIG = [[Node.TEXT_NODE, matchText], [Node.TEXT_NODE, matchNewline], ['br', matchBreak], [Node.ELEMENT_NODE, matchNewline], [Node.ELEMENT_NODE, matchBlot], [Node.ELEMENT_NODE, matchSpacing], [Node.ELEMENT_NODE, matchAttributor], [Node.ELEMENT_NODE, matchStyles], ['li', matchIndent], ['b', matchAlias.bind(matchAlias, 'bold')], ['i', matchAlias.bind(matchAlias, 'italic')], ['style', matchIgnore]]; +// var CLIPBOARD_CONFIG = [[Node.TEXT_NODE, matchText], [Node.TEXT_NODE, matchNewline], ['br', matchBreak], [Node.ELEMENT_NODE, matchNewline], [Node.ELEMENT_NODE, matchBlot], [Node.ELEMENT_NODE, matchSpacing], [Node.ELEMENT_NODE, matchAttributor], [Node.ELEMENT_NODE, matchStyles], ['li', matchIndent], ['b', matchAlias.bind(matchAlias, 'bold')], ['i', matchAlias.bind(matchAlias, 'italic')], ['style', matchIgnore]]; +var CLIPBOARD_CONFIG = [[Node.TEXT_NODE, matchText], [Node.TEXT_NODE, matchNewline], ['br', matchBreak], [Node.ELEMENT_NODE, matchNewline]]; var ATTRIBUTE_ATTRIBUTORS = [_align.AlignAttribute, _direction.DirectionAttribute].reduce(function (memo, attr) { memo[attr.keyName] = attr; @@ -8916,10 +8917,10 @@ var Clipboard = function (_Module) { var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this, quill, options)); - _this.quill.root.addEventListener('paste', _this.onPaste.bind(_this)); - _this.container = _this.quill.addContainer('ql-clipboard'); - _this.container.setAttribute('contenteditable', true); - _this.container.setAttribute('tabindex', -1); + // _this.quill.root.addEventListener('paste', _this.onPaste.bind(_this)); + // _this.container = _this.quill.addContainer('ql-clipboard'); + // _this.container.setAttribute('contenteditable', true); + // _this.container.setAttribute('tabindex', -1); _this.matchers = []; CLIPBOARD_CONFIG.concat(_this.options.matchers).forEach(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), @@ -8941,28 +8942,33 @@ var Clipboard = function (_Module) { key: 'convert', value: function convert(html) { if (typeof html === 'string') { - this.container.innerHTML = html.replace(/\>\r?\n +\<'); // Remove spaces between tags + // this.container.innerHTML = html.replace(/\>\r?\n +\<'); // Remove spaces between tags + var parser = new DOMParser(); + var htmlNoSpaces = html.replace(/\>\r?\n +\<'); // Remove spaces between tags + this.container = parser.parseFromString(htmlNoSpaces, "text/html").body; return this.convert(); } var formats = this.quill.getFormat(this.quill.selection.savedRange.index); - if (formats[_code2.default.blotName]) { - var text = this.container.innerText; - this.container.innerHTML = ''; - return new _quillDelta2.default().insert(text, _defineProperty({}, _code2.default.blotName, formats[_code2.default.blotName])); - } + // if (formats[_code2.default.blotName]) { + // var text = this.container.innerText; + // this.container.innerHTML = ''; + // return new _quillDelta2.default().insert(text, _defineProperty({}, _code2.default.blotName, formats[_code2.default.blotName])); + // } var _prepareMatching = this.prepareMatching(), _prepareMatching2 = _slicedToArray(_prepareMatching, 2), elementMatchers = _prepareMatching2[0], textMatchers = _prepareMatching2[1]; - var delta = traverse(this.container, elementMatchers, textMatchers); + // var delta = traverse(this.container, elementMatchers, textMatchers); + var delta = traverse(this.container, elementMatchers, textMatchers, formats); // Remove trailing newline if (deltaEndsWith(delta, '\n') && delta.ops[delta.ops.length - 1].attributes == null) { delta = delta.compose(new _quillDelta2.default().retain(delta.length() - 1).delete(1)); } debug.log('convert', this.container.innerHTML, delta); - this.container.innerHTML = ''; + // this.container.innerHTML = ''; + this.container = null; return delta; } }, { @@ -9056,9 +9062,10 @@ function applyFormat(delta, format, value) { } function computeStyle(node) { - if (node.nodeType !== Node.ELEMENT_NODE) return {}; - var DOM_KEY = '__ql-computed-style'; - return node[DOM_KEY] || (node[DOM_KEY] = window.getComputedStyle(node)); + // if (node.nodeType !== Node.ELEMENT_NODE) return {}; + // var DOM_KEY = '__ql-computed-style'; + // return node[DOM_KEY] || (node[DOM_KEY] = window.getComputedStyle(node)); + return node.style; } function deltaEndsWith(delta, text) { @@ -9070,28 +9077,43 @@ function deltaEndsWith(delta, text) { } return endText.slice(-1 * text.length) === text; } +function deltaIs(delta, text) { + var allText = ""; + for (var i = delta.ops.length - 1; i >= 0 && allText.length <= text.length; --i) { + var op = delta.ops[i]; + if (typeof op.insert !== 'string') break; + allText = op.insert + allText; + } + return allText === text; +} function isLine(node) { if (node.childNodes.length === 0) return false; // Exclude embed blocks var style = computeStyle(node); - return ['block', 'list-item'].indexOf(style.display) > -1; + // return ['block', 'list-item'].indexOf(style.display) > -1; + return ['block', 'list-item'].indexOf(style.display) > -1 || node.nodeName === 'DIV' || node.nodeName === 'P' || node.nodeName === 'TIME'; } -function traverse(node, elementMatchers, textMatchers) { +// function traverse(node, elementMatchers, textMatchers) { +function traverse(node, elementMatchers, textMatchers, attributes) { // Post-order if (node.nodeType === node.TEXT_NODE) { return textMatchers.reduce(function (delta, matcher) { - return matcher(node, delta); + // return matcher(node, delta); + return matcher(node, delta, attributes); }, new _quillDelta2.default()); } else if (node.nodeType === node.ELEMENT_NODE) { return [].reduce.call(node.childNodes || [], function (delta, childNode) { - var childrenDelta = traverse(childNode, elementMatchers, textMatchers); + // var childrenDelta = traverse(childNode, elementMatchers, textMatchers); + var childrenDelta = traverse(childNode, elementMatchers, textMatchers, attributes); if (childNode.nodeType === node.ELEMENT_NODE) { childrenDelta = elementMatchers.reduce(function (childrenDelta, matcher) { - return matcher(childNode, childrenDelta); + // return matcher(childNode, childrenDelta); + return matcher(childNode, childrenDelta, attributes); }, childrenDelta); childrenDelta = (childNode[DOM_KEY] || []).reduce(function (childrenDelta, matcher) { - return matcher(childNode, childrenDelta); + // return matcher(childNode, childrenDelta); + return matcher(childNode, childrenDelta, attributes); }, childrenDelta); } return delta.concat(childrenDelta); @@ -9177,8 +9199,10 @@ function matchIndent(node, delta) { } function matchNewline(node, delta) { - if (!deltaEndsWith(delta, '\n')) { - if (isLine(node) || delta.length() > 0 && node.nextSibling && isLine(node.nextSibling)) { + // if (!deltaEndsWith(delta, '\n')) { + if (!deltaIs(delta, '\n') && !deltaEndsWith(delta, '\n\n')) { + // if (isLine(node) || delta.length() > 0 && node.nextSibling && isLine(node.nextSibling)) { + if (delta.length() > 0 && isLine(node)) { delta.insert('\n'); } } @@ -9186,7 +9210,7 @@ function matchNewline(node, delta) { } function matchSpacing(node, delta) { - if (isLine(node) && node.nextElementSibling != null && !deltaEndsWith(delta, '\n\n')) { + if (isLine(node) && node.nextElementSibling != null && !deltaIs(delta, '\n') && !deltaEndsWith(delta, '\n\n')) { var nodeHeight = node.offsetHeight + parseFloat(computeStyle(node).marginTop) + parseFloat(computeStyle(node).marginBottom); if (node.nextElementSibling.offsetTop > node.offsetTop + nodeHeight * 1.5) { delta.insert('\n'); @@ -9214,7 +9238,7 @@ function matchStyles(node, delta) { return delta; } -function matchText(node, delta) { +function matchText(node, delta, attributes) { var text = node.data; // Word represents empty line with   if (node.parentNode.tagName === 'O:P') { @@ -9238,7 +9262,7 @@ function matchText(node, delta) { text = text.replace(/\s+$/, replacer.bind(replacer, false)); } } - return delta.insert(text); + return delta.insert(text, attributes); } exports.default = Clipboard; \ No newline at end of file