From 3eb8addeeb21345d967a96dca8b8b7f929f34747 Mon Sep 17 00:00:00 2001 From: web-padawan Date: Fri, 5 Oct 2018 21:30:07 +0300 Subject: [PATCH] Rebuild quill with refactored polyfill detection --- vendor/quill.js | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/vendor/quill.js b/vendor/quill.js index 5a03055..9515348 100644 --- a/vendor/quill.js +++ b/vendor/quill.js @@ -3046,25 +3046,7 @@ var Selection = function () { }, { key: 'getNativeRange', value: function getNativeRange() { - var nativeRange = void 0; - - // in Safari 10+ and iOS we need to use shadow selection polyfill - var ua = navigator.userAgent; - var isSafari = /^((?!chrome|android).)*safari/i.test(ua) || /iPad|iPhone/.test(ua); - var hasPolyfill = window.ShadyDOM && window.ShadyDOM.inUse; - var hasShadow = window.ShadowRoot !== undefined && this.rootDocument instanceof ShadowRoot; - var hasSelection = this.rootDocument.getSelection; - - if (hasShadow && !hasPolyfill && !hasSelection && isSafari) { - nativeRange = (0, _shadowSelectionPolyfill.getRange)(this.rootDocument); - } else { - // only Chrome has getSelection() API for ShadowRoot, in Firefox 63 document API works - var root = hasShadow && hasSelection ? this.rootDocument : document; - var selection = root.getSelection(); - if (selection == null || selection.rangeCount <= 0) return null; - nativeRange = selection.getRangeAt(0); - } - + var nativeRange = (0, _shadowSelectionPolyfill.getRange)(this.rootDocument); if (nativeRange == null) return null; var range = this.normalizeNative(nativeRange); debug.info('getNativeRange', range); @@ -6363,8 +6345,23 @@ function ignoredTrailingSpace(node) { var cachedRange = new Map(); function getRange(root) { - if (root.getSelection) { - var s = root.getSelection(); + var ua = navigator.userAgent; + var hasSelection = root.getSelection; + var useDocument = false; + if (root === document) { + useDocument = true; + } else { + // fall back to using global API in the following cases: + // 1. no shadow DOM supported / polyfilled + // 2. ShadyDOM polyfill is in use (including case when it is forced) + // 3. Firefox 63 which returns nodes from shadow trees using document API + var isSafari = /^((?!chrome|android).)*safari/i.test(ua) || /iPad|iPhone/.test(ua); + var hasShadow = window.ShadowRoot !== undefined && root instanceof ShadowRoot; + var hasPolyfill = window.ShadyDOM && window.ShadyDOM.inUse; + useDocument = !hasShadow || hasPolyfill || !hasSelection && !isSafari; + } + if (useDocument || hasSelection) { + var s = (useDocument ? document : root).getSelection(); return s.rangeCount ? s.getRangeAt(0) : null; }