{"version":3,"file":"slate-dom-CgCPnaaC.js","sources":["../../node_modules/slate-dom/dist/index.es.js"],"sourcesContent":["import { Transforms, Element, Editor, Scrubber, Range, Node, Text, Path, Point } from 'slate';\nimport { isHotkey } from 'is-hotkey';\n\n/**\n * Types.\n */\n// COMPAT: This is required to prevent TypeScript aliases from doing some very\n// weird things for Slate's types with the same name as globals. (2019/11/27)\n// https://github.com/microsoft/TypeScript/issues/35002\nvar DOMNode = globalThis.Node;\nvar DOMElement = globalThis.Element;\nvar DOMText = globalThis.Text;\nvar DOMRange = globalThis.Range;\nvar DOMSelection = globalThis.Selection;\nvar DOMStaticRange = globalThis.StaticRange;\n/**\n * Returns the host window of a DOM node\n */\nvar getDefaultView = value => {\n return value && value.ownerDocument && value.ownerDocument.defaultView || null;\n};\n/**\n * Check if a DOM node is a comment node.\n */\nvar isDOMComment = value => {\n return isDOMNode(value) && value.nodeType === 8;\n};\n/**\n * Check if a DOM node is an element node.\n */\nvar isDOMElement = value => {\n return isDOMNode(value) && value.nodeType === 1;\n};\n/**\n * Check if a value is a DOM node.\n */\nvar isDOMNode = value => {\n var window = getDefaultView(value);\n return !!window && value instanceof window.Node;\n};\n/**\n * Check if a value is a DOM selection.\n */\nvar isDOMSelection = value => {\n var window = value && value.anchorNode && getDefaultView(value.anchorNode);\n return !!window && value instanceof window.Selection;\n};\n/**\n * Check if a DOM node is an element node.\n */\nvar isDOMText = value => {\n return isDOMNode(value) && value.nodeType === 3;\n};\n/**\n * Checks whether a paste event is a plaintext-only event.\n */\nvar isPlainTextOnlyPaste = event => {\n return event.clipboardData && event.clipboardData.getData('text/plain') !== '' && event.clipboardData.types.length === 1;\n};\n/**\n * Normalize a DOM point so that it always refers to a text node.\n */\nvar normalizeDOMPoint = domPoint => {\n var [node, offset] = domPoint;\n // If it's an element node, its offset refers to the index of its children\n // including comment nodes, so try to find the right text child node.\n if (isDOMElement(node) && node.childNodes.length) {\n var isLast = offset === node.childNodes.length;\n var index = isLast ? offset - 1 : offset;\n [node, index] = getEditableChildAndIndex(node, index, isLast ? 'backward' : 'forward');\n // If the editable child found is in front of input offset, we instead seek to its end\n isLast = index < offset;\n // If the node has children, traverse until we have a leaf node. Leaf nodes\n // can be either text nodes, or other void DOM nodes.\n while (isDOMElement(node) && node.childNodes.length) {\n var i = isLast ? node.childNodes.length - 1 : 0;\n node = getEditableChild(node, i, isLast ? 'backward' : 'forward');\n }\n // Determine the new offset inside the text node.\n offset = isLast && node.textContent != null ? node.textContent.length : 0;\n }\n // Return the node and offset.\n return [node, offset];\n};\n/**\n * Determines whether the active element is nested within a shadowRoot\n */\nvar hasShadowRoot = node => {\n var parent = node && node.parentNode;\n while (parent) {\n if (parent.toString() === '[object ShadowRoot]') {\n return true;\n }\n parent = parent.parentNode;\n }\n return false;\n};\n/**\n * Get the nearest editable child and index at `index` in a `parent`, preferring\n * `direction`.\n */\nvar getEditableChildAndIndex = (parent, index, direction) => {\n var {\n childNodes\n } = parent;\n var child = childNodes[index];\n var i = index;\n var triedForward = false;\n var triedBackward = false;\n // While the child is a comment node, or an element node with no children,\n // keep iterating to find a sibling non-void, non-comment node.\n while (isDOMComment(child) || isDOMElement(child) && child.childNodes.length === 0 || isDOMElement(child) && child.getAttribute('contenteditable') === 'false') {\n if (triedForward && triedBackward) {\n break;\n }\n if (i >= childNodes.length) {\n triedForward = true;\n i = index - 1;\n direction = 'backward';\n continue;\n }\n if (i < 0) {\n triedBackward = true;\n i = index + 1;\n direction = 'forward';\n continue;\n }\n child = childNodes[i];\n index = i;\n i += direction === 'forward' ? 1 : -1;\n }\n return [child, index];\n};\n/**\n * Get the nearest editable child at `index` in a `parent`, preferring\n * `direction`.\n */\nvar getEditableChild = (parent, index, direction) => {\n var [child] = getEditableChildAndIndex(parent, index, direction);\n return child;\n};\n/**\n * Get a plaintext representation of the content of a node, accounting for block\n * elements which get a newline appended.\n *\n * The domNode must be attached to the DOM.\n */\nvar getPlainText = domNode => {\n var text = '';\n if (isDOMText(domNode) && domNode.nodeValue) {\n return domNode.nodeValue;\n }\n if (isDOMElement(domNode)) {\n for (var childNode of Array.from(domNode.childNodes)) {\n text += getPlainText(childNode);\n }\n var display = getComputedStyle(domNode).getPropertyValue('display');\n if (display === 'block' || display === 'list' || domNode.tagName === 'BR') {\n text += '\\n';\n }\n }\n return text;\n};\n/**\n * Get x-slate-fragment attribute from data-slate-fragment\n */\nvar catchSlateFragment = /data-slate-fragment=\"(.+?)\"/m;\nvar getSlateFragmentAttribute = dataTransfer => {\n var htmlData = dataTransfer.getData('text/html');\n var [, fragment] = htmlData.match(catchSlateFragment) || [];\n return fragment;\n};\n/**\n * Get the dom selection from Shadow Root if possible, otherwise from the document\n */\nvar getSelection = root => {\n if (root.getSelection != null) {\n return root.getSelection();\n }\n return document.getSelection();\n};\n/**\n * Check whether a mutation originates from a editable element inside the editor.\n */\nvar isTrackedMutation = (editor, mutation, batch) => {\n var {\n target\n } = mutation;\n if (isDOMElement(target) && target.matches('[contentEditable=\"false\"]')) {\n return false;\n }\n var {\n document\n } = DOMEditor.getWindow(editor);\n if (document.contains(target)) {\n return DOMEditor.hasDOMNode(editor, target, {\n editable: true\n });\n }\n var parentMutation = batch.find(_ref => {\n var {\n addedNodes,\n removedNodes\n } = _ref;\n for (var node of addedNodes) {\n if (node === target || node.contains(target)) {\n return true;\n }\n }\n for (var _node of removedNodes) {\n if (_node === target || _node.contains(target)) {\n return true;\n }\n }\n });\n if (!parentMutation || parentMutation === mutation) {\n return false;\n }\n // Target add/remove is tracked. Track the mutation if we track the parent mutation.\n return isTrackedMutation(editor, parentMutation, batch);\n};\n/**\n * Retrieves the deepest active element in the DOM, considering nested shadow DOMs.\n */\nvar getActiveElement = () => {\n var activeElement = document.activeElement;\n while ((_activeElement = activeElement) !== null && _activeElement !== void 0 && _activeElement.shadowRoot && (_activeElement$shadow = activeElement.shadowRoot) !== null && _activeElement$shadow !== void 0 && _activeElement$shadow.activeElement) {\n var _activeElement, _activeElement$shadow, _activeElement2;\n activeElement = (_activeElement2 = activeElement) === null || _activeElement2 === void 0 || (_activeElement2 = _activeElement2.shadowRoot) === null || _activeElement2 === void 0 ? void 0 : _activeElement2.activeElement;\n }\n return activeElement;\n};\n/**\n * @returns `true` if `otherNode` is before `node` in the document; otherwise, `false`.\n */\nvar isBefore = (node, otherNode) => Boolean(node.compareDocumentPosition(otherNode) & DOMNode.DOCUMENT_POSITION_PRECEDING);\n/**\n * @returns `true` if `otherNode` is after `node` in the document; otherwise, `false`.\n */\nvar isAfter = (node, otherNode) => Boolean(node.compareDocumentPosition(otherNode) & DOMNode.DOCUMENT_POSITION_FOLLOWING);\n\nvar _navigator$userAgent$, _navigator$userAgent$2;\nvar IS_IOS = typeof navigator !== 'undefined' && typeof window !== 'undefined' && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;\nvar IS_APPLE = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent);\nvar IS_ANDROID = typeof navigator !== 'undefined' && /Android/.test(navigator.userAgent);\nvar IS_FIREFOX = typeof navigator !== 'undefined' && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);\nvar IS_WEBKIT = typeof navigator !== 'undefined' && /AppleWebKit(?!.*Chrome)/i.test(navigator.userAgent);\n// \"modern\" Edge was released at 79.x\nvar IS_EDGE_LEGACY = typeof navigator !== 'undefined' && /Edge?\\/(?:[0-6][0-9]|[0-7][0-8])(?:\\.)/i.test(navigator.userAgent);\nvar IS_CHROME = typeof navigator !== 'undefined' && /Chrome/i.test(navigator.userAgent);\n// Native `beforeInput` events don't work well with react on Chrome 75\n// and older, Chrome 76+ can use `beforeInput` though.\nvar IS_CHROME_LEGACY = typeof navigator !== 'undefined' && /Chrome?\\/(?:[0-7][0-5]|[0-6][0-9])(?:\\.)/i.test(navigator.userAgent);\nvar IS_ANDROID_CHROME_LEGACY = IS_ANDROID && typeof navigator !== 'undefined' && /Chrome?\\/(?:[0-5]?\\d)(?:\\.)/i.test(navigator.userAgent);\n// Firefox did not support `beforeInput` until `v87`.\nvar IS_FIREFOX_LEGACY = typeof navigator !== 'undefined' && /^(?!.*Seamonkey)(?=.*Firefox\\/(?:[0-7][0-9]|[0-8][0-6])(?:\\.)).*/i.test(navigator.userAgent);\n// UC mobile browser\nvar IS_UC_MOBILE = typeof navigator !== 'undefined' && /.*UCBrowser/.test(navigator.userAgent);\n// Wechat browser (not including mac wechat)\nvar IS_WECHATBROWSER = typeof navigator !== 'undefined' && /.*Wechat/.test(navigator.userAgent) && !/.*MacWechat/.test(navigator.userAgent); // avoid lookbehind (buggy in safari < 16.4)\n// Check if DOM is available as React does internally.\n// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js\nvar CAN_USE_DOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');\n// Check if the browser is Safari and older than 17\ntypeof navigator !== 'undefined' && /Safari/.test(navigator.userAgent) && /Version\\/(\\d+)/.test(navigator.userAgent) && ((_navigator$userAgent$ = navigator.userAgent.match(/Version\\/(\\d+)/)) !== null && _navigator$userAgent$ !== void 0 && _navigator$userAgent$[1] ? parseInt((_navigator$userAgent$2 = navigator.userAgent.match(/Version\\/(\\d+)/)) === null || _navigator$userAgent$2 === void 0 ? void 0 : _navigator$userAgent$2[1], 10) < 17 : false);\n// COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event\n// Chrome Legacy doesn't support `beforeinput` correctly\nvar HAS_BEFORE_INPUT_SUPPORT = (!IS_CHROME_LEGACY || !IS_ANDROID_CHROME_LEGACY) && !IS_EDGE_LEGACY &&\n// globalThis is undefined in older browsers\ntypeof globalThis !== 'undefined' && globalThis.InputEvent &&\n// @ts-ignore The `getTargetRanges` property isn't recognized.\ntypeof globalThis.InputEvent.prototype.getTargetRanges === 'function';\n\nfunction _typeof(o) {\n \"@babel/helpers - typeof\";\n\n return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {\n return typeof o;\n } : function (o) {\n return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;\n }, _typeof(o);\n}\n\nfunction _toPrimitive(input, hint) {\n if (_typeof(input) !== \"object\" || input === null) return input;\n var prim = input[Symbol.toPrimitive];\n if (prim !== undefined) {\n var res = prim.call(input, hint || \"default\");\n if (_typeof(res) !== \"object\") return res;\n throw new TypeError(\"@@toPrimitive must return a primitive value.\");\n }\n return (hint === \"string\" ? String : Number)(input);\n}\n\nfunction _toPropertyKey(arg) {\n var key = _toPrimitive(arg, \"string\");\n return _typeof(key) === \"symbol\" ? key : String(key);\n}\n\nfunction _defineProperty(obj, key, value) {\n key = _toPropertyKey(key);\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n return obj;\n}\n\n/**\n * An auto-incrementing identifier for keys.\n */\nvar n = 0;\n/**\n * A class that keeps track of a key string. We use a full class here because we\n * want to be able to use them as keys in `WeakMap` objects.\n */\nclass Key {\n constructor() {\n _defineProperty(this, \"id\", void 0);\n this.id = \"\".concat(n++);\n }\n}\n\n/**\n * Two weak maps that allow us rebuild a path given a node. They are populated\n * at render time such that after a render occurs we can always backtrack.\n */\nvar IS_NODE_MAP_DIRTY = new WeakMap();\nvar NODE_TO_INDEX = new WeakMap();\nvar NODE_TO_PARENT = new WeakMap();\n/**\n * Weak maps that allow us to go between Slate nodes and DOM nodes. These\n * are used to resolve DOM event-related logic into Slate actions.\n */\nvar EDITOR_TO_WINDOW = new WeakMap();\nvar EDITOR_TO_ELEMENT = new WeakMap();\nvar EDITOR_TO_PLACEHOLDER_ELEMENT = new WeakMap();\nvar ELEMENT_TO_NODE = new WeakMap();\nvar NODE_TO_ELEMENT = new WeakMap();\nvar NODE_TO_KEY = new WeakMap();\nvar EDITOR_TO_KEY_TO_ELEMENT = new WeakMap();\n/**\n * Weak maps for storing editor-related state.\n */\nvar IS_READ_ONLY = new WeakMap();\nvar IS_FOCUSED = new WeakMap();\nvar IS_COMPOSING = new WeakMap();\nvar EDITOR_TO_USER_SELECTION = new WeakMap();\n/**\n * Weak map for associating the context `onChange` context with the plugin.\n */\nvar EDITOR_TO_ON_CHANGE = new WeakMap();\n/**\n * Weak maps for saving pending state on composition stage.\n */\nvar EDITOR_TO_SCHEDULE_FLUSH = new WeakMap();\nvar EDITOR_TO_PENDING_INSERTION_MARKS = new WeakMap();\nvar EDITOR_TO_USER_MARKS = new WeakMap();\n/**\n * Android input handling specific weak-maps\n */\nvar EDITOR_TO_PENDING_DIFFS = new WeakMap();\nvar EDITOR_TO_PENDING_ACTION = new WeakMap();\nvar EDITOR_TO_PENDING_SELECTION = new WeakMap();\nvar EDITOR_TO_FORCE_RENDER = new WeakMap();\n/**\n * Symbols.\n */\nvar PLACEHOLDER_SYMBOL = Symbol('placeholder');\nvar MARK_PLACEHOLDER_SYMBOL = Symbol('mark-placeholder');\n\n// eslint-disable-next-line no-redeclare\nvar DOMEditor = {\n androidPendingDiffs: editor => EDITOR_TO_PENDING_DIFFS.get(editor),\n androidScheduleFlush: editor => {\n var _EDITOR_TO_SCHEDULE_F;\n (_EDITOR_TO_SCHEDULE_F = EDITOR_TO_SCHEDULE_FLUSH.get(editor)) === null || _EDITOR_TO_SCHEDULE_F === void 0 || _EDITOR_TO_SCHEDULE_F();\n },\n blur: editor => {\n var el = DOMEditor.toDOMNode(editor, editor);\n var root = DOMEditor.findDocumentOrShadowRoot(editor);\n IS_FOCUSED.set(editor, false);\n if (root.activeElement === el) {\n el.blur();\n }\n },\n deselect: editor => {\n var {\n selection\n } = editor;\n var root = DOMEditor.findDocumentOrShadowRoot(editor);\n var domSelection = getSelection(root);\n if (domSelection && domSelection.rangeCount > 0) {\n domSelection.removeAllRanges();\n }\n if (selection) {\n Transforms.deselect(editor);\n }\n },\n findDocumentOrShadowRoot: editor => {\n var el = DOMEditor.toDOMNode(editor, editor);\n var root = el.getRootNode();\n if (root instanceof Document || root instanceof ShadowRoot) {\n return root;\n }\n return el.ownerDocument;\n },\n findEventRange: (editor, event) => {\n if ('nativeEvent' in event) {\n event = event.nativeEvent;\n }\n var {\n clientX: x,\n clientY: y,\n target\n } = event;\n if (x == null || y == null) {\n throw new Error(\"Cannot resolve a Slate range from a DOM event: \".concat(event));\n }\n var node = DOMEditor.toSlateNode(editor, event.target);\n var path = DOMEditor.findPath(editor, node);\n // If the drop target is inside a void node, move it into either the\n // next or previous node, depending on which side the `x` and `y`\n // coordinates are closest to.\n if (Element.isElement(node) && Editor.isVoid(editor, node)) {\n var rect = target.getBoundingClientRect();\n var isPrev = editor.isInline(node) ? x - rect.left < rect.left + rect.width - x : y - rect.top < rect.top + rect.height - y;\n var edge = Editor.point(editor, path, {\n edge: isPrev ? 'start' : 'end'\n });\n var point = isPrev ? Editor.before(editor, edge) : Editor.after(editor, edge);\n if (point) {\n var _range = Editor.range(editor, point);\n return _range;\n }\n }\n // Else resolve a range from the caret position where the drop occured.\n var domRange;\n var {\n document\n } = DOMEditor.getWindow(editor);\n // COMPAT: In Firefox, `caretRangeFromPoint` doesn't exist. (2016/07/25)\n if (document.caretRangeFromPoint) {\n domRange = document.caretRangeFromPoint(x, y);\n } else {\n var position = document.caretPositionFromPoint(x, y);\n if (position) {\n domRange = document.createRange();\n domRange.setStart(position.offsetNode, position.offset);\n domRange.setEnd(position.offsetNode, position.offset);\n }\n }\n if (!domRange) {\n throw new Error(\"Cannot resolve a Slate range from a DOM event: \".concat(event));\n }\n // Resolve a Slate range from the DOM range.\n var range = DOMEditor.toSlateRange(editor, domRange, {\n exactMatch: false,\n suppressThrow: false\n });\n return range;\n },\n findKey: (editor, node) => {\n var key = NODE_TO_KEY.get(node);\n if (!key) {\n key = new Key();\n NODE_TO_KEY.set(node, key);\n }\n return key;\n },\n findPath: (editor, node) => {\n var path = [];\n var child = node;\n while (true) {\n var parent = NODE_TO_PARENT.get(child);\n if (parent == null) {\n if (Editor.isEditor(child)) {\n return path;\n } else {\n break;\n }\n }\n var i = NODE_TO_INDEX.get(child);\n if (i == null) {\n break;\n }\n path.unshift(i);\n child = parent;\n }\n throw new Error(\"Unable to find the path for Slate node: \".concat(Scrubber.stringify(node)));\n },\n focus: function focus(editor) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n retries: 5\n };\n // Return if already focused\n if (IS_FOCUSED.get(editor)) {\n return;\n }\n // Retry setting focus if the editor has pending operations.\n // The DOM (selection) is unstable while changes are applied.\n // Retry until retries are exhausted or editor is focused.\n if (options.retries <= 0) {\n throw new Error('Could not set focus, editor seems stuck with pending operations');\n }\n if (editor.operations.length > 0) {\n setTimeout(() => {\n DOMEditor.focus(editor, {\n retries: options.retries - 1\n });\n }, 10);\n return;\n }\n var el = DOMEditor.toDOMNode(editor, editor);\n var root = DOMEditor.findDocumentOrShadowRoot(editor);\n if (root.activeElement !== el) {\n // Ensure that the DOM selection state is set to the editor's selection\n if (editor.selection && root instanceof Document) {\n var domSelection = getSelection(root);\n var domRange = DOMEditor.toDOMRange(editor, editor.selection);\n domSelection === null || domSelection === void 0 || domSelection.removeAllRanges();\n domSelection === null || domSelection === void 0 || domSelection.addRange(domRange);\n }\n // Create a new selection in the top of the document if missing\n if (!editor.selection) {\n Transforms.select(editor, Editor.start(editor, []));\n }\n // IS_FOCUSED should be set before calling el.focus() to ensure that\n // FocusedContext is updated to the correct value\n IS_FOCUSED.set(editor, true);\n el.focus({\n preventScroll: true\n });\n }\n },\n getWindow: editor => {\n var window = EDITOR_TO_WINDOW.get(editor);\n if (!window) {\n throw new Error('Unable to find a host window element for this editor');\n }\n return window;\n },\n hasDOMNode: function hasDOMNode(editor, target) {\n var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n var {\n editable = false\n } = options;\n var editorEl = DOMEditor.toDOMNode(editor, editor);\n var targetEl;\n // COMPAT: In Firefox, reading `target.nodeType` will throw an error if\n // target is originating from an internal \"restricted\" element (e.g. a\n // stepper arrow on a number input). (2018/05/04)\n // https://github.com/ianstormtaylor/slate/issues/1819\n try {\n targetEl = isDOMElement(target) ? target : target.parentElement;\n } catch (err) {\n if (err instanceof Error && !err.message.includes('Permission denied to access property \"nodeType\"')) {\n throw err;\n }\n }\n if (!targetEl) {\n return false;\n }\n return targetEl.closest(\"[data-slate-editor]\") === editorEl && (!editable || targetEl.isContentEditable ? true : typeof targetEl.isContentEditable === 'boolean' &&\n // isContentEditable exists only on HTMLElement, and on other nodes it will be undefined\n // this is the core logic that lets you know you got the right editor.selection instead of null when editor is contenteditable=\"false\"(readOnly)\n targetEl.closest('[contenteditable=\"false\"]') === editorEl || !!targetEl.getAttribute('data-slate-zero-width'));\n },\n hasEditableTarget: (editor, target) => isDOMNode(target) && DOMEditor.hasDOMNode(editor, target, {\n editable: true\n }),\n hasRange: (editor, range) => {\n var {\n anchor,\n focus\n } = range;\n return Editor.hasPath(editor, anchor.path) && Editor.hasPath(editor, focus.path);\n },\n hasSelectableTarget: (editor, target) => DOMEditor.hasEditableTarget(editor, target) || DOMEditor.isTargetInsideNonReadonlyVoid(editor, target),\n hasTarget: (editor, target) => isDOMNode(target) && DOMEditor.hasDOMNode(editor, target),\n insertData: (editor, data) => {\n editor.insertData(data);\n },\n insertFragmentData: (editor, data) => editor.insertFragmentData(data),\n insertTextData: (editor, data) => editor.insertTextData(data),\n isComposing: editor => {\n return !!IS_COMPOSING.get(editor);\n },\n isFocused: editor => !!IS_FOCUSED.get(editor),\n isReadOnly: editor => !!IS_READ_ONLY.get(editor),\n isTargetInsideNonReadonlyVoid: (editor, target) => {\n if (IS_READ_ONLY.get(editor)) return false;\n var slateNode = DOMEditor.hasTarget(editor, target) && DOMEditor.toSlateNode(editor, target);\n return Element.isElement(slateNode) && Editor.isVoid(editor, slateNode);\n },\n setFragmentData: (editor, data, originEvent) => editor.setFragmentData(data, originEvent),\n toDOMNode: (editor, node) => {\n var KEY_TO_ELEMENT = EDITOR_TO_KEY_TO_ELEMENT.get(editor);\n var domNode = Editor.isEditor(node) ? EDITOR_TO_ELEMENT.get(editor) : KEY_TO_ELEMENT === null || KEY_TO_ELEMENT === void 0 ? void 0 : KEY_TO_ELEMENT.get(DOMEditor.findKey(editor, node));\n if (!domNode) {\n throw new Error(\"Cannot resolve a DOM node from Slate node: \".concat(Scrubber.stringify(node)));\n }\n return domNode;\n },\n toDOMPoint: (editor, point) => {\n var [node] = Editor.node(editor, point.path);\n var el = DOMEditor.toDOMNode(editor, node);\n var domPoint;\n // If we're inside a void node, force the offset to 0, otherwise the zero\n // width spacing character will result in an incorrect offset of 1\n if (Editor.void(editor, {\n at: point\n })) {\n point = {\n path: point.path,\n offset: 0\n };\n }\n // For each leaf, we need to isolate its content, which means filtering\n // to its direct text and zero-width spans. (We have to filter out any\n // other siblings that may have been rendered alongside them.)\n var selector = \"[data-slate-string], [data-slate-zero-width]\";\n var texts = Array.from(el.querySelectorAll(selector));\n var start = 0;\n for (var i = 0; i < texts.length; i++) {\n var text = texts[i];\n var domNode = text.childNodes[0];\n if (domNode == null || domNode.textContent == null) {\n continue;\n }\n var {\n length\n } = domNode.textContent;\n var attr = text.getAttribute('data-slate-length');\n var trueLength = attr == null ? length : parseInt(attr, 10);\n var end = start + trueLength;\n // Prefer putting the selection inside the mark placeholder to ensure\n // composed text is displayed with the correct marks.\n var nextText = texts[i + 1];\n if (point.offset === end && nextText !== null && nextText !== void 0 && nextText.hasAttribute('data-slate-mark-placeholder')) {\n var _nextText$textContent;\n var domText = nextText.childNodes[0];\n domPoint = [\n // COMPAT: If we don't explicity set the dom point to be on the actual\n // dom text element, chrome will put the selection behind the actual dom\n // text element, causing domRange.getBoundingClientRect() calls on a collapsed\n // selection to return incorrect zero values (https://bugs.chromium.org/p/chromium/issues/detail?id=435438)\n // which will cause issues when scrolling to it.\n domText instanceof DOMText ? domText : nextText, (_nextText$textContent = nextText.textContent) !== null && _nextText$textContent !== void 0 && _nextText$textContent.startsWith('\\uFEFF') ? 1 : 0];\n break;\n }\n if (point.offset <= end) {\n var offset = Math.min(length, Math.max(0, point.offset - start));\n domPoint = [domNode, offset];\n break;\n }\n start = end;\n }\n if (!domPoint) {\n throw new Error(\"Cannot resolve a DOM point from Slate point: \".concat(Scrubber.stringify(point)));\n }\n return domPoint;\n },\n toDOMRange: (editor, range) => {\n var {\n anchor,\n focus\n } = range;\n var isBackward = Range.isBackward(range);\n var domAnchor = DOMEditor.toDOMPoint(editor, anchor);\n var domFocus = Range.isCollapsed(range) ? domAnchor : DOMEditor.toDOMPoint(editor, focus);\n var window = DOMEditor.getWindow(editor);\n var domRange = window.document.createRange();\n var [startNode, startOffset] = isBackward ? domFocus : domAnchor;\n var [endNode, endOffset] = isBackward ? domAnchor : domFocus;\n // A slate Point at zero-width Leaf always has an offset of 0 but a native DOM selection at\n // zero-width node has an offset of 1 so we have to check if we are in a zero-width node and\n // adjust the offset accordingly.\n var startEl = isDOMElement(startNode) ? startNode : startNode.parentElement;\n var isStartAtZeroWidth = !!startEl.getAttribute('data-slate-zero-width');\n var endEl = isDOMElement(endNode) ? endNode : endNode.parentElement;\n var isEndAtZeroWidth = !!endEl.getAttribute('data-slate-zero-width');\n domRange.setStart(startNode, isStartAtZeroWidth ? 1 : startOffset);\n domRange.setEnd(endNode, isEndAtZeroWidth ? 1 : endOffset);\n return domRange;\n },\n toSlateNode: (editor, domNode) => {\n var domEl = isDOMElement(domNode) ? domNode : domNode.parentElement;\n if (domEl && !domEl.hasAttribute('data-slate-node')) {\n domEl = domEl.closest(\"[data-slate-node]\");\n }\n var node = domEl ? ELEMENT_TO_NODE.get(domEl) : null;\n if (!node) {\n throw new Error(\"Cannot resolve a Slate node from DOM node: \".concat(domEl));\n }\n return node;\n },\n toSlatePoint: (editor, domPoint, options) => {\n var {\n exactMatch,\n suppressThrow,\n searchDirection = 'backward'\n } = options;\n var [nearestNode, nearestOffset] = exactMatch ? domPoint : normalizeDOMPoint(domPoint);\n var parentNode = nearestNode.parentNode;\n var textNode = null;\n var offset = 0;\n if (parentNode) {\n var _domNode$textContent, _domNode$textContent2;\n var editorEl = DOMEditor.toDOMNode(editor, editor);\n var potentialVoidNode = parentNode.closest('[data-slate-void=\"true\"]');\n // Need to ensure that the closest void node is actually a void node\n // within this editor, and not a void node within some parent editor. This can happen\n // if this editor is within a void node of another editor (\"nested editors\", like in\n // the \"Editable Voids\" example on the docs site).\n var voidNode = potentialVoidNode && editorEl.contains(potentialVoidNode) ? potentialVoidNode : null;\n var potentialNonEditableNode = parentNode.closest('[contenteditable=\"false\"]');\n var nonEditableNode = potentialNonEditableNode && editorEl.contains(potentialNonEditableNode) ? potentialNonEditableNode : null;\n var leafNode = parentNode.closest('[data-slate-leaf]');\n var domNode = null;\n // Calculate how far into the text node the `nearestNode` is, so that we\n // can determine what the offset relative to the text node is.\n if (leafNode) {\n textNode = leafNode.closest('[data-slate-node=\"text\"]');\n if (textNode) {\n var window = DOMEditor.getWindow(editor);\n var range = window.document.createRange();\n range.setStart(textNode, 0);\n range.setEnd(nearestNode, nearestOffset);\n var contents = range.cloneContents();\n var removals = [...Array.prototype.slice.call(contents.querySelectorAll('[data-slate-zero-width]')), ...Array.prototype.slice.call(contents.querySelectorAll('[contenteditable=false]'))];\n removals.forEach(el => {\n // COMPAT: While composing at the start of a text node, some keyboards put\n // the text content inside the zero width space.\n if (IS_ANDROID && !exactMatch && el.hasAttribute('data-slate-zero-width') && el.textContent.length > 0 && el.textContext !== '\\uFEFF') {\n if (el.textContent.startsWith('\\uFEFF')) {\n el.textContent = el.textContent.slice(1);\n }\n return;\n }\n el.parentNode.removeChild(el);\n });\n // COMPAT: Edge has a bug where Range.prototype.toString() will\n // convert \\n into \\r\\n. The bug causes a loop when slate-dom\n // attempts to reposition its cursor to match the native position. Use\n // textContent.length instead.\n // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10291116/\n offset = contents.textContent.length;\n domNode = textNode;\n }\n } else if (voidNode) {\n // For void nodes, the element with the offset key will be a cousin, not an\n // ancestor, so find it by going down from the nearest void parent and taking the\n // first one that isn't inside a nested editor.\n var leafNodes = voidNode.querySelectorAll('[data-slate-leaf]');\n for (var index = 0; index < leafNodes.length; index++) {\n var current = leafNodes[index];\n if (DOMEditor.hasDOMNode(editor, current)) {\n leafNode = current;\n break;\n }\n }\n // COMPAT: In read-only editors the leaf is not rendered.\n if (!leafNode) {\n offset = 1;\n } else {\n textNode = leafNode.closest('[data-slate-node=\"text\"]');\n domNode = leafNode;\n offset = domNode.textContent.length;\n domNode.querySelectorAll('[data-slate-zero-width]').forEach(el => {\n offset -= el.textContent.length;\n });\n }\n } else if (nonEditableNode) {\n // Find the edge of the nearest leaf in `searchDirection`\n var getLeafNodes = node => node ? node.querySelectorAll(\n // Exclude leaf nodes in nested editors\n '[data-slate-leaf]:not(:scope [data-slate-editor] [data-slate-leaf])') : [];\n var elementNode = nonEditableNode.closest('[data-slate-node=\"element\"]');\n if (searchDirection === 'forward') {\n var _leafNodes$find;\n var _leafNodes = [...getLeafNodes(elementNode), ...getLeafNodes(elementNode === null || elementNode === void 0 ? void 0 : elementNode.nextElementSibling)];\n leafNode = (_leafNodes$find = _leafNodes.find(leaf => isAfter(nonEditableNode, leaf))) !== null && _leafNodes$find !== void 0 ? _leafNodes$find : null;\n } else {\n var _leafNodes2$findLast;\n var _leafNodes2 = [...getLeafNodes(elementNode === null || elementNode === void 0 ? void 0 : elementNode.previousElementSibling), ...getLeafNodes(elementNode)];\n leafNode = (_leafNodes2$findLast = _leafNodes2.findLast(leaf => isBefore(nonEditableNode, leaf))) !== null && _leafNodes2$findLast !== void 0 ? _leafNodes2$findLast : null;\n }\n if (leafNode) {\n textNode = leafNode.closest('[data-slate-node=\"text\"]');\n domNode = leafNode;\n if (searchDirection === 'forward') {\n offset = 0;\n } else {\n offset = domNode.textContent.length;\n domNode.querySelectorAll('[data-slate-zero-width]').forEach(el => {\n offset -= el.textContent.length;\n });\n }\n }\n }\n if (domNode && offset === domNode.textContent.length &&\n // COMPAT: Android IMEs might remove the zero width space while composing,\n // and we don't add it for line-breaks.\n IS_ANDROID && domNode.getAttribute('data-slate-zero-width') === 'z' && (_domNode$textContent = domNode.textContent) !== null && _domNode$textContent !== void 0 && _domNode$textContent.startsWith('\\uFEFF') && (\n // COMPAT: If the parent node is a Slate zero-width space, editor is\n // because the text node should have no characters. However, during IME\n // composition the ASCII characters will be prepended to the zero-width\n // space, so subtract 1 from the offset to account for the zero-width\n // space character.\n parentNode.hasAttribute('data-slate-zero-width') ||\n // COMPAT: In Firefox, `range.cloneContents()` returns an extra trailing '\\n'\n // when the document ends with a new-line character. This results in the offset\n // length being off by one, so we need to subtract one to account for this.\n IS_FIREFOX && (_domNode$textContent2 = domNode.textContent) !== null && _domNode$textContent2 !== void 0 && _domNode$textContent2.endsWith('\\n\\n'))) {\n offset--;\n }\n }\n if (IS_ANDROID && !textNode && !exactMatch) {\n var node = parentNode.hasAttribute('data-slate-node') ? parentNode : parentNode.closest('[data-slate-node]');\n if (node && DOMEditor.hasDOMNode(editor, node, {\n editable: true\n })) {\n var _slateNode = DOMEditor.toSlateNode(editor, node);\n var {\n path: _path,\n offset: _offset\n } = Editor.start(editor, DOMEditor.findPath(editor, _slateNode));\n if (!node.querySelector('[data-slate-leaf]')) {\n _offset = nearestOffset;\n }\n return {\n path: _path,\n offset: _offset\n };\n }\n }\n if (!textNode) {\n if (suppressThrow) {\n return null;\n }\n throw new Error(\"Cannot resolve a Slate point from DOM point: \".concat(domPoint));\n }\n // COMPAT: If someone is clicking from one Slate editor into another,\n // the select event fires twice, once for the old editor's `element`\n // first, and then afterwards for the correct `element`. (2017/03/03)\n var slateNode = DOMEditor.toSlateNode(editor, textNode);\n var path = DOMEditor.findPath(editor, slateNode);\n return {\n path,\n offset\n };\n },\n toSlateRange: (editor, domRange, options) => {\n var _focusNode$textConten;\n var {\n exactMatch,\n suppressThrow\n } = options;\n var el = isDOMSelection(domRange) ? domRange.anchorNode : domRange.startContainer;\n var anchorNode;\n var anchorOffset;\n var focusNode;\n var focusOffset;\n var isCollapsed;\n if (el) {\n if (isDOMSelection(domRange)) {\n // COMPAT: In firefox the normal seletion way does not work\n // (https://github.com/ianstormtaylor/slate/pull/5486#issue-1820720223)\n if (IS_FIREFOX && domRange.rangeCount > 1) {\n focusNode = domRange.focusNode; // Focus node works fine\n var firstRange = domRange.getRangeAt(0);\n var lastRange = domRange.getRangeAt(domRange.rangeCount - 1);\n // Here we are in the contenteditable mode of a table in firefox\n if (focusNode instanceof HTMLTableRowElement && firstRange.startContainer instanceof HTMLTableRowElement && lastRange.startContainer instanceof HTMLTableRowElement) {\n // HTMLElement, becouse Element is a slate element\n function getLastChildren(element) {\n if (element.childElementCount > 0) {\n return getLastChildren(element.children[0]);\n } else {\n return element;\n }\n }\n var firstNodeRow = firstRange.startContainer;\n var lastNodeRow = lastRange.startContainer;\n // This should never fail as \"The HTMLElement interface represents any HTML element.\"\n var firstNode = getLastChildren(firstNodeRow.children[firstRange.startOffset]);\n var lastNode = getLastChildren(lastNodeRow.children[lastRange.startOffset]);\n // Zero, as we allways take the right one as the anchor point\n focusOffset = 0;\n if (lastNode.childNodes.length > 0) {\n anchorNode = lastNode.childNodes[0];\n } else {\n anchorNode = lastNode;\n }\n if (firstNode.childNodes.length > 0) {\n focusNode = firstNode.childNodes[0];\n } else {\n focusNode = firstNode;\n }\n if (lastNode instanceof HTMLElement) {\n anchorOffset = lastNode.innerHTML.length;\n } else {\n // Fallback option\n anchorOffset = 0;\n }\n } else {\n // This is the read only mode of a firefox table\n // Right to left\n if (firstRange.startContainer === focusNode) {\n anchorNode = lastRange.endContainer;\n anchorOffset = lastRange.endOffset;\n focusOffset = firstRange.startOffset;\n } else {\n // Left to right\n anchorNode = firstRange.startContainer;\n anchorOffset = firstRange.endOffset;\n focusOffset = lastRange.startOffset;\n }\n }\n } else {\n anchorNode = domRange.anchorNode;\n anchorOffset = domRange.anchorOffset;\n focusNode = domRange.focusNode;\n focusOffset = domRange.focusOffset;\n }\n // COMPAT: There's a bug in chrome that always returns `true` for\n // `isCollapsed` for a Selection that comes from a ShadowRoot.\n // (2020/08/08)\n // https://bugs.chromium.org/p/chromium/issues/detail?id=447523\n // IsCollapsed might not work in firefox, but this will\n if (IS_CHROME && hasShadowRoot(anchorNode) || IS_FIREFOX) {\n isCollapsed = domRange.anchorNode === domRange.focusNode && domRange.anchorOffset === domRange.focusOffset;\n } else {\n isCollapsed = domRange.isCollapsed;\n }\n } else {\n anchorNode = domRange.startContainer;\n anchorOffset = domRange.startOffset;\n focusNode = domRange.endContainer;\n focusOffset = domRange.endOffset;\n isCollapsed = domRange.collapsed;\n }\n }\n if (anchorNode == null || focusNode == null || anchorOffset == null || focusOffset == null) {\n throw new Error(\"Cannot resolve a Slate range from DOM range: \".concat(domRange));\n }\n // COMPAT: Firefox sometimes includes an extra \\n (rendered by TextString\n // when isTrailing is true) in the focusOffset, resulting in an invalid\n // Slate point. (2023/11/01)\n if (IS_FIREFOX && (_focusNode$textConten = focusNode.textContent) !== null && _focusNode$textConten !== void 0 && _focusNode$textConten.endsWith('\\n\\n') && focusOffset === focusNode.textContent.length) {\n focusOffset--;\n }\n var anchor = DOMEditor.toSlatePoint(editor, [anchorNode, anchorOffset], {\n exactMatch,\n suppressThrow\n });\n if (!anchor) {\n return null;\n }\n var focusBeforeAnchor = isBefore(anchorNode, focusNode) || anchorNode === focusNode && focusOffset < anchorOffset;\n var focus = isCollapsed ? anchor : DOMEditor.toSlatePoint(editor, [focusNode, focusOffset], {\n exactMatch,\n suppressThrow,\n searchDirection: focusBeforeAnchor ? 'forward' : 'backward'\n });\n if (!focus) {\n return null;\n }\n var range = {\n anchor: anchor,\n focus: focus\n };\n // if the selection is a hanging range that ends in a void\n // and the DOM focus is an Element\n // (meaning that the selection ends before the element)\n // unhang the range to avoid mistakenly including the void\n if (Range.isExpanded(range) && Range.isForward(range) && isDOMElement(focusNode) && Editor.void(editor, {\n at: range.focus,\n mode: 'highest'\n })) {\n range = Editor.unhangRange(editor, range, {\n voids: true\n });\n }\n return range;\n }\n};\n\n/**\n * Check whether a text diff was applied in a way we can perform the pending action on /\n * recover the pending selection.\n */\nfunction verifyDiffState(editor, textDiff) {\n var {\n path,\n diff\n } = textDiff;\n if (!Editor.hasPath(editor, path)) {\n return false;\n }\n var node = Node.get(editor, path);\n if (!Text.isText(node)) {\n return false;\n }\n if (diff.start !== node.text.length || diff.text.length === 0) {\n return node.text.slice(diff.start, diff.start + diff.text.length) === diff.text;\n }\n var nextPath = Path.next(path);\n if (!Editor.hasPath(editor, nextPath)) {\n return false;\n }\n var nextNode = Node.get(editor, nextPath);\n return Text.isText(nextNode) && nextNode.text.startsWith(diff.text);\n}\nfunction applyStringDiff(text) {\n for (var _len = arguments.length, diffs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n diffs[_key - 1] = arguments[_key];\n }\n return diffs.reduce((text, diff) => text.slice(0, diff.start) + diff.text + text.slice(diff.end), text);\n}\nfunction longestCommonPrefixLength(str, another) {\n var length = Math.min(str.length, another.length);\n for (var i = 0; i < length; i++) {\n if (str.charAt(i) !== another.charAt(i)) {\n return i;\n }\n }\n return length;\n}\nfunction longestCommonSuffixLength(str, another, max) {\n var length = Math.min(str.length, another.length, max);\n for (var i = 0; i < length; i++) {\n if (str.charAt(str.length - i - 1) !== another.charAt(another.length - i - 1)) {\n return i;\n }\n }\n return length;\n}\n/**\n * Remove redundant changes from the diff so that it spans the minimal possible range\n */\nfunction normalizeStringDiff(targetText, diff) {\n var {\n start,\n end,\n text\n } = diff;\n var removedText = targetText.slice(start, end);\n var prefixLength = longestCommonPrefixLength(removedText, text);\n var max = Math.min(removedText.length - prefixLength, text.length - prefixLength);\n var suffixLength = longestCommonSuffixLength(removedText, text, max);\n var normalized = {\n start: start + prefixLength,\n end: end - suffixLength,\n text: text.slice(prefixLength, text.length - suffixLength)\n };\n if (normalized.start === normalized.end && normalized.text.length === 0) {\n return null;\n }\n return normalized;\n}\n/**\n * Return a string diff that is equivalent to applying b after a spanning the range of\n * both changes\n */\nfunction mergeStringDiffs(targetText, a, b) {\n var start = Math.min(a.start, b.start);\n var overlap = Math.max(0, Math.min(a.start + a.text.length, b.end) - b.start);\n var applied = applyStringDiff(targetText, a, b);\n var sliceEnd = Math.max(b.start + b.text.length, a.start + a.text.length + (a.start + a.text.length > b.start ? b.text.length : 0) - overlap);\n var text = applied.slice(start, sliceEnd);\n var end = Math.max(a.end, b.end - a.text.length + (a.end - a.start));\n return normalizeStringDiff(targetText, {\n start,\n end,\n text\n });\n}\n/**\n * Get the slate range the text diff spans.\n */\nfunction targetRange(textDiff) {\n var {\n path,\n diff\n } = textDiff;\n return {\n anchor: {\n path,\n offset: diff.start\n },\n focus: {\n path,\n offset: diff.end\n }\n };\n}\n/**\n * Normalize a 'pending point' a.k.a a point based on the dom state before applying\n * the pending diffs. Since the pending diffs might have been inserted with different\n * marks we have to 'walk' the offset from the starting position to ensure we still\n * have a valid point inside the document\n */\nfunction normalizePoint(editor, point) {\n var {\n path,\n offset\n } = point;\n if (!Editor.hasPath(editor, path)) {\n return null;\n }\n var leaf = Node.get(editor, path);\n if (!Text.isText(leaf)) {\n return null;\n }\n var parentBlock = Editor.above(editor, {\n match: n => Element.isElement(n) && Editor.isBlock(editor, n),\n at: path\n });\n if (!parentBlock) {\n return null;\n }\n while (offset > leaf.text.length) {\n var entry = Editor.next(editor, {\n at: path,\n match: Text.isText\n });\n if (!entry || !Path.isDescendant(entry[1], parentBlock[1])) {\n return null;\n }\n offset -= leaf.text.length;\n leaf = entry[0];\n path = entry[1];\n }\n return {\n path,\n offset\n };\n}\n/**\n * Normalize a 'pending selection' to ensure it's valid in the current document state.\n */\nfunction normalizeRange(editor, range) {\n var anchor = normalizePoint(editor, range.anchor);\n if (!anchor) {\n return null;\n }\n if (Range.isCollapsed(range)) {\n return {\n anchor,\n focus: anchor\n };\n }\n var focus = normalizePoint(editor, range.focus);\n if (!focus) {\n return null;\n }\n return {\n anchor,\n focus\n };\n}\nfunction transformPendingPoint(editor, point, op) {\n var pendingDiffs = EDITOR_TO_PENDING_DIFFS.get(editor);\n var textDiff = pendingDiffs === null || pendingDiffs === void 0 ? void 0 : pendingDiffs.find(_ref => {\n var {\n path\n } = _ref;\n return Path.equals(path, point.path);\n });\n if (!textDiff || point.offset <= textDiff.diff.start) {\n return Point.transform(point, op, {\n affinity: 'backward'\n });\n }\n var {\n diff\n } = textDiff;\n // Point references location inside the diff => transform the point based on the location\n // the diff will be applied to and add the offset inside the diff.\n if (point.offset <= diff.start + diff.text.length) {\n var _anchor = {\n path: point.path,\n offset: diff.start\n };\n var _transformed = Point.transform(_anchor, op, {\n affinity: 'backward'\n });\n if (!_transformed) {\n return null;\n }\n return {\n path: _transformed.path,\n offset: _transformed.offset + point.offset - diff.start\n };\n }\n // Point references location after the diff\n var anchor = {\n path: point.path,\n offset: point.offset - diff.text.length + diff.end - diff.start\n };\n var transformed = Point.transform(anchor, op, {\n affinity: 'backward'\n });\n if (!transformed) {\n return null;\n }\n if (op.type === 'split_node' && Path.equals(op.path, point.path) && anchor.offset < op.position && diff.start < op.position) {\n return transformed;\n }\n return {\n path: transformed.path,\n offset: transformed.offset + diff.text.length - diff.end + diff.start\n };\n}\nfunction transformPendingRange(editor, range, op) {\n var anchor = transformPendingPoint(editor, range.anchor, op);\n if (!anchor) {\n return null;\n }\n if (Range.isCollapsed(range)) {\n return {\n anchor,\n focus: anchor\n };\n }\n var focus = transformPendingPoint(editor, range.focus, op);\n if (!focus) {\n return null;\n }\n return {\n anchor,\n focus\n };\n}\nfunction transformTextDiff(textDiff, op) {\n var {\n path,\n diff,\n id\n } = textDiff;\n switch (op.type) {\n case 'insert_text':\n {\n if (!Path.equals(op.path, path) || op.offset >= diff.end) {\n return textDiff;\n }\n if (op.offset <= diff.start) {\n return {\n diff: {\n start: op.text.length + diff.start,\n end: op.text.length + diff.end,\n text: diff.text\n },\n id,\n path\n };\n }\n return {\n diff: {\n start: diff.start,\n end: diff.end + op.text.length,\n text: diff.text\n },\n id,\n path\n };\n }\n case 'remove_text':\n {\n if (!Path.equals(op.path, path) || op.offset >= diff.end) {\n return textDiff;\n }\n if (op.offset + op.text.length <= diff.start) {\n return {\n diff: {\n start: diff.start - op.text.length,\n end: diff.end - op.text.length,\n text: diff.text\n },\n id,\n path\n };\n }\n return {\n diff: {\n start: diff.start,\n end: diff.end - op.text.length,\n text: diff.text\n },\n id,\n path\n };\n }\n case 'split_node':\n {\n if (!Path.equals(op.path, path) || op.position >= diff.end) {\n return {\n diff,\n id,\n path: Path.transform(path, op, {\n affinity: 'backward'\n })\n };\n }\n if (op.position > diff.start) {\n return {\n diff: {\n start: diff.start,\n end: Math.min(op.position, diff.end),\n text: diff.text\n },\n id,\n path\n };\n }\n return {\n diff: {\n start: diff.start - op.position,\n end: diff.end - op.position,\n text: diff.text\n },\n id,\n path: Path.transform(path, op, {\n affinity: 'forward'\n })\n };\n }\n case 'merge_node':\n {\n if (!Path.equals(op.path, path)) {\n return {\n diff,\n id,\n path: Path.transform(path, op)\n };\n }\n return {\n diff: {\n start: diff.start + op.position,\n end: diff.end + op.position,\n text: diff.text\n },\n id,\n path: Path.transform(path, op)\n };\n }\n }\n var newPath = Path.transform(path, op);\n if (!newPath) {\n return null;\n }\n return {\n diff,\n path: newPath,\n id\n };\n}\n\n/**\n * Utilities for single-line deletion\n */\nvar doRectsIntersect = (rect, compareRect) => {\n var middle = (compareRect.top + compareRect.bottom) / 2;\n return rect.top <= middle && rect.bottom >= middle;\n};\nvar areRangesSameLine = (editor, range1, range2) => {\n var rect1 = DOMEditor.toDOMRange(editor, range1).getBoundingClientRect();\n var rect2 = DOMEditor.toDOMRange(editor, range2).getBoundingClientRect();\n return doRectsIntersect(rect1, rect2) && doRectsIntersect(rect2, rect1);\n};\n/**\n * A helper utility that returns the end portion of a `Range`\n * which is located on a single line.\n *\n * @param {Editor} editor The editor object to compare against\n * @param {Range} parentRange The parent range to compare against\n * @returns {Range} A valid portion of the parentRange which is one a single line\n */\nvar findCurrentLineRange = (editor, parentRange) => {\n var parentRangeBoundary = Editor.range(editor, Range.end(parentRange));\n var positions = Array.from(Editor.positions(editor, {\n at: parentRange\n }));\n var left = 0;\n var right = positions.length;\n var middle = Math.floor(right / 2);\n if (areRangesSameLine(editor, Editor.range(editor, positions[left]), parentRangeBoundary)) {\n return Editor.range(editor, positions[left], parentRangeBoundary);\n }\n if (positions.length < 2) {\n return Editor.range(editor, positions[positions.length - 1], parentRangeBoundary);\n }\n while (middle !== positions.length && middle !== left) {\n if (areRangesSameLine(editor, Editor.range(editor, positions[middle]), parentRangeBoundary)) {\n right = middle;\n } else {\n left = middle;\n }\n middle = Math.floor((left + right) / 2);\n }\n return Editor.range(editor, positions[right], parentRangeBoundary);\n};\n\nfunction ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }\nfunction _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }\n/**\n * `withDOM` adds DOM specific behaviors to the editor.\n *\n * If you are using TypeScript, you must extend Slate's CustomTypes to use\n * this plugin.\n *\n * See https://docs.slatejs.org/concepts/11-typescript to learn how.\n */\nvar withDOM = function withDOM(editor) {\n var clipboardFormatKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'x-slate-fragment';\n var e = editor;\n var {\n apply,\n onChange,\n deleteBackward,\n addMark,\n removeMark\n } = e;\n // The WeakMap which maps a key to a specific HTMLElement must be scoped to the editor instance to\n // avoid collisions between editors in the DOM that share the same value.\n EDITOR_TO_KEY_TO_ELEMENT.set(e, new WeakMap());\n e.addMark = (key, value) => {\n var _EDITOR_TO_SCHEDULE_F, _EDITOR_TO_PENDING_DI;\n (_EDITOR_TO_SCHEDULE_F = EDITOR_TO_SCHEDULE_FLUSH.get(e)) === null || _EDITOR_TO_SCHEDULE_F === void 0 || _EDITOR_TO_SCHEDULE_F();\n if (!EDITOR_TO_PENDING_INSERTION_MARKS.get(e) && (_EDITOR_TO_PENDING_DI = EDITOR_TO_PENDING_DIFFS.get(e)) !== null && _EDITOR_TO_PENDING_DI !== void 0 && _EDITOR_TO_PENDING_DI.length) {\n // Ensure the current pending diffs originating from changes before the addMark\n // are applied with the current formatting\n EDITOR_TO_PENDING_INSERTION_MARKS.set(e, null);\n }\n EDITOR_TO_USER_MARKS.delete(e);\n addMark(key, value);\n };\n e.removeMark = key => {\n var _EDITOR_TO_PENDING_DI2;\n if (!EDITOR_TO_PENDING_INSERTION_MARKS.get(e) && (_EDITOR_TO_PENDING_DI2 = EDITOR_TO_PENDING_DIFFS.get(e)) !== null && _EDITOR_TO_PENDING_DI2 !== void 0 && _EDITOR_TO_PENDING_DI2.length) {\n // Ensure the current pending diffs originating from changes before the addMark\n // are applied with the current formatting\n EDITOR_TO_PENDING_INSERTION_MARKS.set(e, null);\n }\n EDITOR_TO_USER_MARKS.delete(e);\n removeMark(key);\n };\n e.deleteBackward = unit => {\n if (unit !== 'line') {\n return deleteBackward(unit);\n }\n if (e.selection && Range.isCollapsed(e.selection)) {\n var parentBlockEntry = Editor.above(e, {\n match: n => Element.isElement(n) && Editor.isBlock(e, n),\n at: e.selection\n });\n if (parentBlockEntry) {\n var [, parentBlockPath] = parentBlockEntry;\n var parentElementRange = Editor.range(e, parentBlockPath, e.selection.anchor);\n var currentLineRange = findCurrentLineRange(e, parentElementRange);\n if (!Range.isCollapsed(currentLineRange)) {\n Transforms.delete(e, {\n at: currentLineRange\n });\n }\n }\n }\n };\n // This attempts to reset the NODE_TO_KEY entry to the correct value\n // as apply() changes the object reference and hence invalidates the NODE_TO_KEY entry\n e.apply = op => {\n var matches = [];\n var pathRefMatches = [];\n var pendingDiffs = EDITOR_TO_PENDING_DIFFS.get(e);\n if (pendingDiffs !== null && pendingDiffs !== void 0 && pendingDiffs.length) {\n var transformed = pendingDiffs.map(textDiff => transformTextDiff(textDiff, op)).filter(Boolean);\n EDITOR_TO_PENDING_DIFFS.set(e, transformed);\n }\n var pendingSelection = EDITOR_TO_PENDING_SELECTION.get(e);\n if (pendingSelection) {\n EDITOR_TO_PENDING_SELECTION.set(e, transformPendingRange(e, pendingSelection, op));\n }\n var pendingAction = EDITOR_TO_PENDING_ACTION.get(e);\n if (pendingAction !== null && pendingAction !== void 0 && pendingAction.at) {\n var at = Point.isPoint(pendingAction === null || pendingAction === void 0 ? void 0 : pendingAction.at) ? transformPendingPoint(e, pendingAction.at, op) : transformPendingRange(e, pendingAction.at, op);\n EDITOR_TO_PENDING_ACTION.set(e, at ? _objectSpread(_objectSpread({}, pendingAction), {}, {\n at\n }) : null);\n }\n switch (op.type) {\n case 'insert_text':\n case 'remove_text':\n case 'set_node':\n case 'split_node':\n {\n matches.push(...getMatches(e, op.path));\n break;\n }\n case 'set_selection':\n {\n var _EDITOR_TO_USER_SELEC;\n // Selection was manually set, don't restore the user selection after the change.\n (_EDITOR_TO_USER_SELEC = EDITOR_TO_USER_SELECTION.get(e)) === null || _EDITOR_TO_USER_SELEC === void 0 || _EDITOR_TO_USER_SELEC.unref();\n EDITOR_TO_USER_SELECTION.delete(e);\n break;\n }\n case 'insert_node':\n case 'remove_node':\n {\n matches.push(...getMatches(e, Path.parent(op.path)));\n break;\n }\n case 'merge_node':\n {\n var prevPath = Path.previous(op.path);\n matches.push(...getMatches(e, prevPath));\n break;\n }\n case 'move_node':\n {\n var commonPath = Path.common(Path.parent(op.path), Path.parent(op.newPath));\n matches.push(...getMatches(e, commonPath));\n var changedPath;\n if (Path.isBefore(op.path, op.newPath)) {\n matches.push(...getMatches(e, Path.parent(op.path)));\n changedPath = op.newPath;\n } else {\n matches.push(...getMatches(e, Path.parent(op.newPath)));\n changedPath = op.path;\n }\n var changedNode = Node.get(editor, Path.parent(changedPath));\n var changedNodeKey = DOMEditor.findKey(e, changedNode);\n var changedPathRef = Editor.pathRef(e, Path.parent(changedPath));\n pathRefMatches.push([changedPathRef, changedNodeKey]);\n break;\n }\n }\n apply(op);\n switch (op.type) {\n case 'insert_node':\n case 'remove_node':\n case 'merge_node':\n case 'move_node':\n case 'split_node':\n {\n IS_NODE_MAP_DIRTY.set(e, true);\n }\n }\n for (var [path, key] of matches) {\n var [node] = Editor.node(e, path);\n NODE_TO_KEY.set(node, key);\n }\n for (var [pathRef, _key] of pathRefMatches) {\n if (pathRef.current) {\n var [_node] = Editor.node(e, pathRef.current);\n NODE_TO_KEY.set(_node, _key);\n }\n pathRef.unref();\n }\n };\n e.setFragmentData = data => {\n var {\n selection\n } = e;\n if (!selection) {\n return;\n }\n var [start, end] = Range.edges(selection);\n var startVoid = Editor.void(e, {\n at: start.path\n });\n var endVoid = Editor.void(e, {\n at: end.path\n });\n if (Range.isCollapsed(selection) && !startVoid) {\n return;\n }\n // Create a fake selection so that we can add a Base64-encoded copy of the\n // fragment to the HTML, to decode on future pastes.\n var domRange = DOMEditor.toDOMRange(e, selection);\n var contents = domRange.cloneContents();\n var attach = contents.childNodes[0];\n // Make sure attach is non-empty, since empty nodes will not get copied.\n contents.childNodes.forEach(node => {\n if (node.textContent && node.textContent.trim() !== '') {\n attach = node;\n }\n });\n // COMPAT: If the end node is a void node, we need to move the end of the\n // range from the void node's spacer span, to the end of the void node's\n // content, since the spacer is before void's content in the DOM.\n if (endVoid) {\n var [voidNode] = endVoid;\n var r = domRange.cloneRange();\n var domNode = DOMEditor.toDOMNode(e, voidNode);\n r.setEndAfter(domNode);\n contents = r.cloneContents();\n }\n // COMPAT: If the start node is a void node, we need to attach the encoded\n // fragment to the void node's content node instead of the spacer, because\n // attaching it to empty `