From 6be0ace70ff4180dfe612c8026ecfb9a88a92651 Mon Sep 17 00:00:00 2001 From: Marc Bachmann Date: Fri, 20 Oct 2023 10:21:25 +0200 Subject: [PATCH] chore: Remove bowser module exposed on `Editable.browser` BREAKING CHANGE: Remove bowser module exposed on `Editable.browser` --- package-lock.json | 6 ------ package.json | 1 - src/core.js | 2 -- src/feature-detection.js | 12 +++++++----- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8497a7c8..c1c373fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "license": "MIT", "dependencies": { "@babel/runtime": "^7.16.7", - "bowser": "2.11.0", "lodash-es": "^4.17.21" }, "devDependencies": { @@ -3295,11 +3294,6 @@ "multicast-dns": "^7.2.5" } }, - "node_modules/bowser": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.11.0.tgz", - "integrity": "sha512-AlcaJBi/pqqJBIQ8U9Mcpc9i8Aqxn88Skv5d+xBX006BY5u8N3mGLHa5Lgppa7L/HfwgwLgZ6NYs+Ag6uUmJRA==" - }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", diff --git a/package.json b/package.json index 093e6e68..3afffb4a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "version": "0.0.0-development", "dependencies": { "@babel/runtime": "^7.16.7", - "bowser": "2.11.0", "lodash-es": "^4.17.21" }, "devDependencies": { diff --git a/src/core.js b/src/core.js index c6142cc7..34246de9 100644 --- a/src/core.js +++ b/src/core.js @@ -9,7 +9,6 @@ import Cursor from './cursor' import highlightSupport from './highlight-support' import MonitoredHighlighting from './monitored-highlighting' import createDefaultEvents from './create-default-events' -import browser from 'bowser' import {textNodesUnder, getTextNodeAndRelativeOffset} from './util/element' import {binaryCursorSearch} from './util/binary_search' import {domArray, createRange, nodeContainsRange} from './util/dom' @@ -513,7 +512,6 @@ export class Editable { // Expose modules and editable Editable.parser = parser Editable.content = content -Editable.browser = browser // Set up callback functions for several events. ;['focus', 'blur', 'flow', 'selection', 'cursor', 'newline', diff --git a/src/feature-detection.js b/src/feature-detection.js index 3f7f0add..bd8c13cc 100644 --- a/src/feature-detection.js +++ b/src/feature-detection.js @@ -1,5 +1,3 @@ -import browser from 'bowser' - /** * Check for contenteditable support * @@ -10,9 +8,13 @@ import browser from 'bowser' */ export const contenteditable = typeof document.documentElement.contentEditable !== 'undefined' -const parser = browser.getParser(window.navigator.userAgent) -const browserEngine = parser.getEngineName() -const webKit = browserEngine === 'WebKit' +// Detect webkit browser engine +// That way we can detect the contenteditable span bug on safari, but exclude chrome +// Regex taken from: https://github.com/lancedikson/bowser/blob/f09411489ced05811c91cc6670a8e4ca9cbe39a7/src/parser-engines.js#L93-L106 +// Attention, this might be error prone as any engine version change breaks this. +const isBlink = /(apple)?webkit\/537\.36/i.test(window.navigator.userAgent) +const isWebkit = /(apple)?webkit/i.test(window.navigator.userAgent) +const webKit = !isBlink && isWebkit /** * Check selectionchange event (supported in IE, Chrome, Firefox and Safari)