have an ownerDocument with no reference to the body\n\n\n return element != null && (_element$ownerDocumen = element.ownerDocument) != null && _element$ownerDocumen.body ? element.ownerDocument : document;\n}\nfunction isCursorOutsideInteractiveBorder(popperTreeData, event) {\n var clientX = event.clientX,\n clientY = event.clientY;\n return popperTreeData.every(function (_ref) {\n var popperRect = _ref.popperRect,\n popperState = _ref.popperState,\n props = _ref.props;\n var interactiveBorder = props.interactiveBorder;\n var basePlacement = getBasePlacement(popperState.placement);\n var offsetData = popperState.modifiersData.offset;\n\n if (!offsetData) {\n return true;\n }\n\n var topDistance = basePlacement === 'bottom' ? offsetData.top.y : 0;\n var bottomDistance = basePlacement === 'top' ? offsetData.bottom.y : 0;\n var leftDistance = basePlacement === 'right' ? offsetData.left.x : 0;\n var rightDistance = basePlacement === 'left' ? offsetData.right.x : 0;\n var exceedsTop = popperRect.top - clientY + topDistance > interactiveBorder;\n var exceedsBottom = clientY - popperRect.bottom - bottomDistance > interactiveBorder;\n var exceedsLeft = popperRect.left - clientX + leftDistance > interactiveBorder;\n var exceedsRight = clientX - popperRect.right - rightDistance > interactiveBorder;\n return exceedsTop || exceedsBottom || exceedsLeft || exceedsRight;\n });\n}\nfunction updateTransitionEndListener(box, action, listener) {\n var method = action + \"EventListener\"; // some browsers apparently support `transition` (unprefixed) but only fire\n // `webkitTransitionEnd`...\n\n ['transitionend', 'webkitTransitionEnd'].forEach(function (event) {\n box[method](event, listener);\n });\n}\n/**\n * Compared to xxx.contains, this function works for dom structures with shadow\n * dom\n */\n\nfunction actualContains(parent, child) {\n var target = child;\n\n while (target) {\n var _target$getRootNode;\n\n if (parent.contains(target)) {\n return true;\n }\n\n target = target.getRootNode == null ? void 0 : (_target$getRootNode = target.getRootNode()) == null ? void 0 : _target$getRootNode.host;\n }\n\n return false;\n}\n\nvar currentInput = {\n isTouch: false\n};\nvar lastMouseMoveTime = 0;\n/**\n * When a `touchstart` event is fired, it's assumed the user is using touch\n * input. We'll bind a `mousemove` event listener to listen for mouse input in\n * the future. This way, the `isTouch` property is fully dynamic and will handle\n * hybrid devices that use a mix of touch + mouse input.\n */\n\nfunction onDocumentTouchStart() {\n if (currentInput.isTouch) {\n return;\n }\n\n currentInput.isTouch = true;\n\n if (window.performance) {\n document.addEventListener('mousemove', onDocumentMouseMove);\n }\n}\n/**\n * When two `mousemove` event are fired consecutively within 20ms, it's assumed\n * the user is using mouse input again. `mousemove` can fire on touch devices as\n * well, but very rarely that quickly.\n */\n\nfunction onDocumentMouseMove() {\n var now = performance.now();\n\n if (now - lastMouseMoveTime < 20) {\n currentInput.isTouch = false;\n document.removeEventListener('mousemove', onDocumentMouseMove);\n }\n\n lastMouseMoveTime = now;\n}\n/**\n * When an element is in focus and has a tippy, leaving the tab/window and\n * returning causes it to show again. For mouse users this is unexpected, but\n * for keyboard use it makes sense.\n * TODO: find a better technique to solve this problem\n */\n\nfunction onWindowBlur() {\n var activeElement = document.activeElement;\n\n if (isReferenceElement(activeElement)) {\n var instance = activeElement._tippy;\n\n if (activeElement.blur && !instance.state.isVisible) {\n activeElement.blur();\n }\n }\n}\nfunction bindGlobalEventListeners() {\n document.addEventListener('touchstart', onDocumentTouchStart, TOUCH_OPTIONS);\n window.addEventListener('blur', onWindowBlur);\n}\n\nvar isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';\nvar isIE11 = isBrowser ? // @ts-ignore\n!!window.msCrypto : false;\n\nfunction createMemoryLeakWarning(method) {\n var txt = method === 'destroy' ? 'n already-' : ' ';\n return [method + \"() was called on a\" + txt + \"destroyed instance. This is a no-op but\", 'indicates a potential memory leak.'].join(' ');\n}\nfunction clean(value) {\n var spacesAndTabs = /[ \\t]{2,}/g;\n var lineStartWithSpaces = /^[ \\t]*/gm;\n return value.replace(spacesAndTabs, ' ').replace(lineStartWithSpaces, '').trim();\n}\n\nfunction getDevMessage(message) {\n return clean(\"\\n %ctippy.js\\n\\n %c\" + clean(message) + \"\\n\\n %c\\uD83D\\uDC77\\u200D This is a development-only message. It will be removed in production.\\n \");\n}\n\nfunction getFormattedMessage(message) {\n return [getDevMessage(message), // title\n 'color: #00C584; font-size: 1.3em; font-weight: bold;', // message\n 'line-height: 1.5', // footer\n 'color: #a6a095;'];\n} // Assume warnings and errors never have the same message\n\nvar visitedMessages;\n\nif (process.env.NODE_ENV !== \"production\") {\n resetVisitedMessages();\n}\n\nfunction resetVisitedMessages() {\n visitedMessages = new Set();\n}\nfunction warnWhen(condition, message) {\n if (condition && !visitedMessages.has(message)) {\n var _console;\n\n visitedMessages.add(message);\n\n (_console = console).warn.apply(_console, getFormattedMessage(message));\n }\n}\nfunction errorWhen(condition, message) {\n if (condition && !visitedMessages.has(message)) {\n var _console2;\n\n visitedMessages.add(message);\n\n (_console2 = console).error.apply(_console2, getFormattedMessage(message));\n }\n}\nfunction validateTargets(targets) {\n var didPassFalsyValue = !targets;\n var didPassPlainObject = Object.prototype.toString.call(targets) === '[object Object]' && !targets.addEventListener;\n errorWhen(didPassFalsyValue, ['tippy() was passed', '`' + String(targets) + '`', 'as its targets (first) argument. Valid types are: String, Element,', 'Element[], or NodeList.'].join(' '));\n errorWhen(didPassPlainObject, ['tippy() was passed a plain object which is not supported as an argument', 'for virtual positioning. Use props.getReferenceClientRect instead.'].join(' '));\n}\n\nvar pluginProps = {\n animateFill: false,\n followCursor: false,\n inlinePositioning: false,\n sticky: false\n};\nvar renderProps = {\n allowHTML: false,\n animation: 'fade',\n arrow: true,\n content: '',\n inertia: false,\n maxWidth: 350,\n role: 'tooltip',\n theme: '',\n zIndex: 9999\n};\nvar defaultProps = Object.assign({\n appendTo: TIPPY_DEFAULT_APPEND_TO,\n aria: {\n content: 'auto',\n expanded: 'auto'\n },\n delay: 0,\n duration: [300, 250],\n getReferenceClientRect: null,\n hideOnClick: true,\n ignoreAttributes: false,\n interactive: false,\n interactiveBorder: 2,\n interactiveDebounce: 0,\n moveTransition: '',\n offset: [0, 10],\n onAfterUpdate: function onAfterUpdate() {},\n onBeforeUpdate: function onBeforeUpdate() {},\n onCreate: function onCreate() {},\n onDestroy: function onDestroy() {},\n onHidden: function onHidden() {},\n onHide: function onHide() {},\n onMount: function onMount() {},\n onShow: function onShow() {},\n onShown: function onShown() {},\n onTrigger: function onTrigger() {},\n onUntrigger: function onUntrigger() {},\n onClickOutside: function onClickOutside() {},\n placement: 'top',\n plugins: [],\n popperOptions: {},\n render: null,\n showOnCreate: false,\n touch: true,\n trigger: 'mouseenter focus',\n triggerTarget: null\n}, pluginProps, renderProps);\nvar defaultKeys = Object.keys(defaultProps);\nvar setDefaultProps = function setDefaultProps(partialProps) {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== \"production\") {\n validateProps(partialProps, []);\n }\n\n var keys = Object.keys(partialProps);\n keys.forEach(function (key) {\n defaultProps[key] = partialProps[key];\n });\n};\nfunction getExtendedPassedProps(passedProps) {\n var plugins = passedProps.plugins || [];\n var pluginProps = plugins.reduce(function (acc, plugin) {\n var name = plugin.name,\n defaultValue = plugin.defaultValue;\n\n if (name) {\n var _name;\n\n acc[name] = passedProps[name] !== undefined ? passedProps[name] : (_name = defaultProps[name]) != null ? _name : defaultValue;\n }\n\n return acc;\n }, {});\n return Object.assign({}, passedProps, pluginProps);\n}\nfunction getDataAttributeProps(reference, plugins) {\n var propKeys = plugins ? Object.keys(getExtendedPassedProps(Object.assign({}, defaultProps, {\n plugins: plugins\n }))) : defaultKeys;\n var props = propKeys.reduce(function (acc, key) {\n var valueAsString = (reference.getAttribute(\"data-tippy-\" + key) || '').trim();\n\n if (!valueAsString) {\n return acc;\n }\n\n if (key === 'content') {\n acc[key] = valueAsString;\n } else {\n try {\n acc[key] = JSON.parse(valueAsString);\n } catch (e) {\n acc[key] = valueAsString;\n }\n }\n\n return acc;\n }, {});\n return props;\n}\nfunction evaluateProps(reference, props) {\n var out = Object.assign({}, props, {\n content: invokeWithArgsOrReturn(props.content, [reference])\n }, props.ignoreAttributes ? {} : getDataAttributeProps(reference, props.plugins));\n out.aria = Object.assign({}, defaultProps.aria, out.aria);\n out.aria = {\n expanded: out.aria.expanded === 'auto' ? props.interactive : out.aria.expanded,\n content: out.aria.content === 'auto' ? props.interactive ? null : 'describedby' : out.aria.content\n };\n return out;\n}\nfunction validateProps(partialProps, plugins) {\n if (partialProps === void 0) {\n partialProps = {};\n }\n\n if (plugins === void 0) {\n plugins = [];\n }\n\n var keys = Object.keys(partialProps);\n keys.forEach(function (prop) {\n var nonPluginProps = removeProperties(defaultProps, Object.keys(pluginProps));\n var didPassUnknownProp = !hasOwnProperty(nonPluginProps, prop); // Check if the prop exists in `plugins`\n\n if (didPassUnknownProp) {\n didPassUnknownProp = plugins.filter(function (plugin) {\n return plugin.name === prop;\n }).length === 0;\n }\n\n warnWhen(didPassUnknownProp, [\"`\" + prop + \"`\", \"is not a valid prop. You may have spelled it incorrectly, or if it's\", 'a plugin, forgot to pass it in an array as props.plugins.', '\\n\\n', 'All props: https://atomiks.github.io/tippyjs/v6/all-props/\\n', 'Plugins: https://atomiks.github.io/tippyjs/v6/plugins/'].join(' '));\n });\n}\n\nvar innerHTML = function innerHTML() {\n return 'innerHTML';\n};\n\nfunction dangerouslySetInnerHTML(element, html) {\n element[innerHTML()] = html;\n}\n\nfunction createArrowElement(value) {\n var arrow = div();\n\n if (value === true) {\n arrow.className = ARROW_CLASS;\n } else {\n arrow.className = SVG_ARROW_CLASS;\n\n if (isElement(value)) {\n arrow.appendChild(value);\n } else {\n dangerouslySetInnerHTML(arrow, value);\n }\n }\n\n return arrow;\n}\n\nfunction setContent(content, props) {\n if (isElement(props.content)) {\n dangerouslySetInnerHTML(content, '');\n content.appendChild(props.content);\n } else if (typeof props.content !== 'function') {\n if (props.allowHTML) {\n dangerouslySetInnerHTML(content, props.content);\n } else {\n content.textContent = props.content;\n }\n }\n}\nfunction getChildren(popper) {\n var box = popper.firstElementChild;\n var boxChildren = arrayFrom(box.children);\n return {\n box: box,\n content: boxChildren.find(function (node) {\n return node.classList.contains(CONTENT_CLASS);\n }),\n arrow: boxChildren.find(function (node) {\n return node.classList.contains(ARROW_CLASS) || node.classList.contains(SVG_ARROW_CLASS);\n }),\n backdrop: boxChildren.find(function (node) {\n return node.classList.contains(BACKDROP_CLASS);\n })\n };\n}\nfunction render(instance) {\n var popper = div();\n var box = div();\n box.className = BOX_CLASS;\n box.setAttribute('data-state', 'hidden');\n box.setAttribute('tabindex', '-1');\n var content = div();\n content.className = CONTENT_CLASS;\n content.setAttribute('data-state', 'hidden');\n setContent(content, instance.props);\n popper.appendChild(box);\n box.appendChild(content);\n onUpdate(instance.props, instance.props);\n\n function onUpdate(prevProps, nextProps) {\n var _getChildren = getChildren(popper),\n box = _getChildren.box,\n content = _getChildren.content,\n arrow = _getChildren.arrow;\n\n if (nextProps.theme) {\n box.setAttribute('data-theme', nextProps.theme);\n } else {\n box.removeAttribute('data-theme');\n }\n\n if (typeof nextProps.animation === 'string') {\n box.setAttribute('data-animation', nextProps.animation);\n } else {\n box.removeAttribute('data-animation');\n }\n\n if (nextProps.inertia) {\n box.setAttribute('data-inertia', '');\n } else {\n box.removeAttribute('data-inertia');\n }\n\n box.style.maxWidth = typeof nextProps.maxWidth === 'number' ? nextProps.maxWidth + \"px\" : nextProps.maxWidth;\n\n if (nextProps.role) {\n box.setAttribute('role', nextProps.role);\n } else {\n box.removeAttribute('role');\n }\n\n if (prevProps.content !== nextProps.content || prevProps.allowHTML !== nextProps.allowHTML) {\n setContent(content, instance.props);\n }\n\n if (nextProps.arrow) {\n if (!arrow) {\n box.appendChild(createArrowElement(nextProps.arrow));\n } else if (prevProps.arrow !== nextProps.arrow) {\n box.removeChild(arrow);\n box.appendChild(createArrowElement(nextProps.arrow));\n }\n } else if (arrow) {\n box.removeChild(arrow);\n }\n }\n\n return {\n popper: popper,\n onUpdate: onUpdate\n };\n} // Runtime check to identify if the render function is the default one; this\n// way we can apply default CSS transitions logic and it can be tree-shaken away\n\nrender.$$tippy = true;\n\nvar idCounter = 1;\nvar mouseMoveListeners = []; // Used by `hideAll()`\n\nvar mountedInstances = [];\nfunction createTippy(reference, passedProps) {\n var props = evaluateProps(reference, Object.assign({}, defaultProps, getExtendedPassedProps(removeUndefinedProps(passedProps)))); // ===========================================================================\n // 🔒 Private members\n // ===========================================================================\n\n var showTimeout;\n var hideTimeout;\n var scheduleHideAnimationFrame;\n var isVisibleFromClick = false;\n var didHideDueToDocumentMouseDown = false;\n var didTouchMove = false;\n var ignoreOnFirstUpdate = false;\n var lastTriggerEvent;\n var currentTransitionEndListener;\n var onFirstUpdate;\n var listeners = [];\n var debouncedOnMouseMove = debounce(onMouseMove, props.interactiveDebounce);\n var currentTarget; // ===========================================================================\n // 🔑 Public members\n // ===========================================================================\n\n var id = idCounter++;\n var popperInstance = null;\n var plugins = unique(props.plugins);\n var state = {\n // Is the instance currently enabled?\n isEnabled: true,\n // Is the tippy currently showing and not transitioning out?\n isVisible: false,\n // Has the instance been destroyed?\n isDestroyed: false,\n // Is the tippy currently mounted to the DOM?\n isMounted: false,\n // Has the tippy finished transitioning in?\n isShown: false\n };\n var instance = {\n // properties\n id: id,\n reference: reference,\n popper: div(),\n popperInstance: popperInstance,\n props: props,\n state: state,\n plugins: plugins,\n // methods\n clearDelayTimeouts: clearDelayTimeouts,\n setProps: setProps,\n setContent: setContent,\n show: show,\n hide: hide,\n hideWithInteractivity: hideWithInteractivity,\n enable: enable,\n disable: disable,\n unmount: unmount,\n destroy: destroy\n }; // TODO: Investigate why this early return causes a TDZ error in the tests —\n // it doesn't seem to happen in the browser\n\n /* istanbul ignore if */\n\n if (!props.render) {\n if (process.env.NODE_ENV !== \"production\") {\n errorWhen(true, 'render() function has not been supplied.');\n }\n\n return instance;\n } // ===========================================================================\n // Initial mutations\n // ===========================================================================\n\n\n var _props$render = props.render(instance),\n popper = _props$render.popper,\n onUpdate = _props$render.onUpdate;\n\n popper.setAttribute('data-tippy-root', '');\n popper.id = \"tippy-\" + instance.id;\n instance.popper = popper;\n reference._tippy = instance;\n popper._tippy = instance;\n var pluginsHooks = plugins.map(function (plugin) {\n return plugin.fn(instance);\n });\n var hasAriaExpanded = reference.hasAttribute('aria-expanded');\n addListeners();\n handleAriaExpandedAttribute();\n handleStyles();\n invokeHook('onCreate', [instance]);\n\n if (props.showOnCreate) {\n scheduleShow();\n } // Prevent a tippy with a delay from hiding if the cursor left then returned\n // before it started hiding\n\n\n popper.addEventListener('mouseenter', function () {\n if (instance.props.interactive && instance.state.isVisible) {\n instance.clearDelayTimeouts();\n }\n });\n popper.addEventListener('mouseleave', function () {\n if (instance.props.interactive && instance.props.trigger.indexOf('mouseenter') >= 0) {\n getDocument().addEventListener('mousemove', debouncedOnMouseMove);\n }\n });\n return instance; // ===========================================================================\n // 🔒 Private methods\n // ===========================================================================\n\n function getNormalizedTouchSettings() {\n var touch = instance.props.touch;\n return Array.isArray(touch) ? touch : [touch, 0];\n }\n\n function getIsCustomTouchBehavior() {\n return getNormalizedTouchSettings()[0] === 'hold';\n }\n\n function getIsDefaultRenderFn() {\n var _instance$props$rende;\n\n // @ts-ignore\n return !!((_instance$props$rende = instance.props.render) != null && _instance$props$rende.$$tippy);\n }\n\n function getCurrentTarget() {\n return currentTarget || reference;\n }\n\n function getDocument() {\n var parent = getCurrentTarget().parentNode;\n return parent ? getOwnerDocument(parent) : document;\n }\n\n function getDefaultTemplateChildren() {\n return getChildren(popper);\n }\n\n function getDelay(isShow) {\n // For touch or keyboard input, force `0` delay for UX reasons\n // Also if the instance is mounted but not visible (transitioning out),\n // ignore delay\n if (instance.state.isMounted && !instance.state.isVisible || currentInput.isTouch || lastTriggerEvent && lastTriggerEvent.type === 'focus') {\n return 0;\n }\n\n return getValueAtIndexOrReturn(instance.props.delay, isShow ? 0 : 1, defaultProps.delay);\n }\n\n function handleStyles(fromHide) {\n if (fromHide === void 0) {\n fromHide = false;\n }\n\n popper.style.pointerEvents = instance.props.interactive && !fromHide ? '' : 'none';\n popper.style.zIndex = \"\" + instance.props.zIndex;\n }\n\n function invokeHook(hook, args, shouldInvokePropsHook) {\n if (shouldInvokePropsHook === void 0) {\n shouldInvokePropsHook = true;\n }\n\n pluginsHooks.forEach(function (pluginHooks) {\n if (pluginHooks[hook]) {\n pluginHooks[hook].apply(pluginHooks, args);\n }\n });\n\n if (shouldInvokePropsHook) {\n var _instance$props;\n\n (_instance$props = instance.props)[hook].apply(_instance$props, args);\n }\n }\n\n function handleAriaContentAttribute() {\n var aria = instance.props.aria;\n\n if (!aria.content) {\n return;\n }\n\n var attr = \"aria-\" + aria.content;\n var id = popper.id;\n var nodes = normalizeToArray(instance.props.triggerTarget || reference);\n nodes.forEach(function (node) {\n var currentValue = node.getAttribute(attr);\n\n if (instance.state.isVisible) {\n node.setAttribute(attr, currentValue ? currentValue + \" \" + id : id);\n } else {\n var nextValue = currentValue && currentValue.replace(id, '').trim();\n\n if (nextValue) {\n node.setAttribute(attr, nextValue);\n } else {\n node.removeAttribute(attr);\n }\n }\n });\n }\n\n function handleAriaExpandedAttribute() {\n if (hasAriaExpanded || !instance.props.aria.expanded) {\n return;\n }\n\n var nodes = normalizeToArray(instance.props.triggerTarget || reference);\n nodes.forEach(function (node) {\n if (instance.props.interactive) {\n node.setAttribute('aria-expanded', instance.state.isVisible && node === getCurrentTarget() ? 'true' : 'false');\n } else {\n node.removeAttribute('aria-expanded');\n }\n });\n }\n\n function cleanupInteractiveMouseListeners() {\n getDocument().removeEventListener('mousemove', debouncedOnMouseMove);\n mouseMoveListeners = mouseMoveListeners.filter(function (listener) {\n return listener !== debouncedOnMouseMove;\n });\n }\n\n function onDocumentPress(event) {\n // Moved finger to scroll instead of an intentional tap outside\n if (currentInput.isTouch) {\n if (didTouchMove || event.type === 'mousedown') {\n return;\n }\n }\n\n var actualTarget = event.composedPath && event.composedPath()[0] || event.target; // Clicked on interactive popper\n\n if (instance.props.interactive && actualContains(popper, actualTarget)) {\n return;\n } // Clicked on the event listeners target\n\n\n if (normalizeToArray(instance.props.triggerTarget || reference).some(function (el) {\n return actualContains(el, actualTarget);\n })) {\n if (currentInput.isTouch) {\n return;\n }\n\n if (instance.state.isVisible && instance.props.trigger.indexOf('click') >= 0) {\n return;\n }\n } else {\n invokeHook('onClickOutside', [instance, event]);\n }\n\n if (instance.props.hideOnClick === true) {\n instance.clearDelayTimeouts();\n instance.hide(); // `mousedown` event is fired right before `focus` if pressing the\n // currentTarget. This lets a tippy with `focus` trigger know that it\n // should not show\n\n didHideDueToDocumentMouseDown = true;\n setTimeout(function () {\n didHideDueToDocumentMouseDown = false;\n }); // The listener gets added in `scheduleShow()`, but this may be hiding it\n // before it shows, and hide()'s early bail-out behavior can prevent it\n // from being cleaned up\n\n if (!instance.state.isMounted) {\n removeDocumentPress();\n }\n }\n }\n\n function onTouchMove() {\n didTouchMove = true;\n }\n\n function onTouchStart() {\n didTouchMove = false;\n }\n\n function addDocumentPress() {\n var doc = getDocument();\n doc.addEventListener('mousedown', onDocumentPress, true);\n doc.addEventListener('touchend', onDocumentPress, TOUCH_OPTIONS);\n doc.addEventListener('touchstart', onTouchStart, TOUCH_OPTIONS);\n doc.addEventListener('touchmove', onTouchMove, TOUCH_OPTIONS);\n }\n\n function removeDocumentPress() {\n var doc = getDocument();\n doc.removeEventListener('mousedown', onDocumentPress, true);\n doc.removeEventListener('touchend', onDocumentPress, TOUCH_OPTIONS);\n doc.removeEventListener('touchstart', onTouchStart, TOUCH_OPTIONS);\n doc.removeEventListener('touchmove', onTouchMove, TOUCH_OPTIONS);\n }\n\n function onTransitionedOut(duration, callback) {\n onTransitionEnd(duration, function () {\n if (!instance.state.isVisible && popper.parentNode && popper.parentNode.contains(popper)) {\n callback();\n }\n });\n }\n\n function onTransitionedIn(duration, callback) {\n onTransitionEnd(duration, callback);\n }\n\n function onTransitionEnd(duration, callback) {\n var box = getDefaultTemplateChildren().box;\n\n function listener(event) {\n if (event.target === box) {\n updateTransitionEndListener(box, 'remove', listener);\n callback();\n }\n } // Make callback synchronous if duration is 0\n // `transitionend` won't fire otherwise\n\n\n if (duration === 0) {\n return callback();\n }\n\n updateTransitionEndListener(box, 'remove', currentTransitionEndListener);\n updateTransitionEndListener(box, 'add', listener);\n currentTransitionEndListener = listener;\n }\n\n function on(eventType, handler, options) {\n if (options === void 0) {\n options = false;\n }\n\n var nodes = normalizeToArray(instance.props.triggerTarget || reference);\n nodes.forEach(function (node) {\n node.addEventListener(eventType, handler, options);\n listeners.push({\n node: node,\n eventType: eventType,\n handler: handler,\n options: options\n });\n });\n }\n\n function addListeners() {\n if (getIsCustomTouchBehavior()) {\n on('touchstart', onTrigger, {\n passive: true\n });\n on('touchend', onMouseLeave, {\n passive: true\n });\n }\n\n splitBySpaces(instance.props.trigger).forEach(function (eventType) {\n if (eventType === 'manual') {\n return;\n }\n\n on(eventType, onTrigger);\n\n switch (eventType) {\n case 'mouseenter':\n on('mouseleave', onMouseLeave);\n break;\n\n case 'focus':\n on(isIE11 ? 'focusout' : 'blur', onBlurOrFocusOut);\n break;\n\n case 'focusin':\n on('focusout', onBlurOrFocusOut);\n break;\n }\n });\n }\n\n function removeListeners() {\n listeners.forEach(function (_ref) {\n var node = _ref.node,\n eventType = _ref.eventType,\n handler = _ref.handler,\n options = _ref.options;\n node.removeEventListener(eventType, handler, options);\n });\n listeners = [];\n }\n\n function onTrigger(event) {\n var _lastTriggerEvent;\n\n var shouldScheduleClickHide = false;\n\n if (!instance.state.isEnabled || isEventListenerStopped(event) || didHideDueToDocumentMouseDown) {\n return;\n }\n\n var wasFocused = ((_lastTriggerEvent = lastTriggerEvent) == null ? void 0 : _lastTriggerEvent.type) === 'focus';\n lastTriggerEvent = event;\n currentTarget = event.currentTarget;\n handleAriaExpandedAttribute();\n\n if (!instance.state.isVisible && isMouseEvent(event)) {\n // If scrolling, `mouseenter` events can be fired if the cursor lands\n // over a new target, but `mousemove` events don't get fired. This\n // causes interactive tooltips to get stuck open until the cursor is\n // moved\n mouseMoveListeners.forEach(function (listener) {\n return listener(event);\n });\n } // Toggle show/hide when clicking click-triggered tooltips\n\n\n if (event.type === 'click' && (instance.props.trigger.indexOf('mouseenter') < 0 || isVisibleFromClick) && instance.props.hideOnClick !== false && instance.state.isVisible) {\n shouldScheduleClickHide = true;\n } else {\n scheduleShow(event);\n }\n\n if (event.type === 'click') {\n isVisibleFromClick = !shouldScheduleClickHide;\n }\n\n if (shouldScheduleClickHide && !wasFocused) {\n scheduleHide(event);\n }\n }\n\n function onMouseMove(event) {\n var target = event.target;\n var isCursorOverReferenceOrPopper = getCurrentTarget().contains(target) || popper.contains(target);\n\n if (event.type === 'mousemove' && isCursorOverReferenceOrPopper) {\n return;\n }\n\n var popperTreeData = getNestedPopperTree().concat(popper).map(function (popper) {\n var _instance$popperInsta;\n\n var instance = popper._tippy;\n var state = (_instance$popperInsta = instance.popperInstance) == null ? void 0 : _instance$popperInsta.state;\n\n if (state) {\n return {\n popperRect: popper.getBoundingClientRect(),\n popperState: state,\n props: props\n };\n }\n\n return null;\n }).filter(Boolean);\n\n if (isCursorOutsideInteractiveBorder(popperTreeData, event)) {\n cleanupInteractiveMouseListeners();\n scheduleHide(event);\n }\n }\n\n function onMouseLeave(event) {\n var shouldBail = isEventListenerStopped(event) || instance.props.trigger.indexOf('click') >= 0 && isVisibleFromClick;\n\n if (shouldBail) {\n return;\n }\n\n if (instance.props.interactive) {\n instance.hideWithInteractivity(event);\n return;\n }\n\n scheduleHide(event);\n }\n\n function onBlurOrFocusOut(event) {\n if (instance.props.trigger.indexOf('focusin') < 0 && event.target !== getCurrentTarget()) {\n return;\n } // If focus was moved to within the popper\n\n\n if (instance.props.interactive && event.relatedTarget && popper.contains(event.relatedTarget)) {\n return;\n }\n\n scheduleHide(event);\n }\n\n function isEventListenerStopped(event) {\n return currentInput.isTouch ? getIsCustomTouchBehavior() !== event.type.indexOf('touch') >= 0 : false;\n }\n\n function createPopperInstance() {\n destroyPopperInstance();\n var _instance$props2 = instance.props,\n popperOptions = _instance$props2.popperOptions,\n placement = _instance$props2.placement,\n offset = _instance$props2.offset,\n getReferenceClientRect = _instance$props2.getReferenceClientRect,\n moveTransition = _instance$props2.moveTransition;\n var arrow = getIsDefaultRenderFn() ? getChildren(popper).arrow : null;\n var computedReference = getReferenceClientRect ? {\n getBoundingClientRect: getReferenceClientRect,\n contextElement: getReferenceClientRect.contextElement || getCurrentTarget()\n } : reference;\n var tippyModifier = {\n name: '$$tippy',\n enabled: true,\n phase: 'beforeWrite',\n requires: ['computeStyles'],\n fn: function fn(_ref2) {\n var state = _ref2.state;\n\n if (getIsDefaultRenderFn()) {\n var _getDefaultTemplateCh = getDefaultTemplateChildren(),\n box = _getDefaultTemplateCh.box;\n\n ['placement', 'reference-hidden', 'escaped'].forEach(function (attr) {\n if (attr === 'placement') {\n box.setAttribute('data-placement', state.placement);\n } else {\n if (state.attributes.popper[\"data-popper-\" + attr]) {\n box.setAttribute(\"data-\" + attr, '');\n } else {\n box.removeAttribute(\"data-\" + attr);\n }\n }\n });\n state.attributes.popper = {};\n }\n }\n };\n var modifiers = [{\n name: 'offset',\n options: {\n offset: offset\n }\n }, {\n name: 'preventOverflow',\n options: {\n padding: {\n top: 2,\n bottom: 2,\n left: 5,\n right: 5\n }\n }\n }, {\n name: 'flip',\n options: {\n padding: 5\n }\n }, {\n name: 'computeStyles',\n options: {\n adaptive: !moveTransition\n }\n }, tippyModifier];\n\n if (getIsDefaultRenderFn() && arrow) {\n modifiers.push({\n name: 'arrow',\n options: {\n element: arrow,\n padding: 3\n }\n });\n }\n\n modifiers.push.apply(modifiers, (popperOptions == null ? void 0 : popperOptions.modifiers) || []);\n instance.popperInstance = createPopper(computedReference, popper, Object.assign({}, popperOptions, {\n placement: placement,\n onFirstUpdate: onFirstUpdate,\n modifiers: modifiers\n }));\n }\n\n function destroyPopperInstance() {\n if (instance.popperInstance) {\n instance.popperInstance.destroy();\n instance.popperInstance = null;\n }\n }\n\n function mount() {\n var appendTo = instance.props.appendTo;\n var parentNode; // By default, we'll append the popper to the triggerTargets's parentNode so\n // it's directly after the reference element so the elements inside the\n // tippy can be tabbed to\n // If there are clipping issues, the user can specify a different appendTo\n // and ensure focus management is handled correctly manually\n\n var node = getCurrentTarget();\n\n if (instance.props.interactive && appendTo === TIPPY_DEFAULT_APPEND_TO || appendTo === 'parent') {\n parentNode = node.parentNode;\n } else {\n parentNode = invokeWithArgsOrReturn(appendTo, [node]);\n } // The popper element needs to exist on the DOM before its position can be\n // updated as Popper needs to read its dimensions\n\n\n if (!parentNode.contains(popper)) {\n parentNode.appendChild(popper);\n }\n\n instance.state.isMounted = true;\n createPopperInstance();\n /* istanbul ignore else */\n\n if (process.env.NODE_ENV !== \"production\") {\n // Accessibility check\n warnWhen(instance.props.interactive && appendTo === defaultProps.appendTo && node.nextElementSibling !== popper, ['Interactive tippy element may not be accessible via keyboard', 'navigation because it is not directly after the reference element', 'in the DOM source order.', '\\n\\n', 'Using a wrapper or tag around the reference element', 'solves this by creating a new parentNode context.', '\\n\\n', 'Specifying `appendTo: document.body` silences this warning, but it', 'assumes you are using a focus management solution to handle', 'keyboard navigation.', '\\n\\n', 'See: https://atomiks.github.io/tippyjs/v6/accessibility/#interactivity'].join(' '));\n }\n }\n\n function getNestedPopperTree() {\n return arrayFrom(popper.querySelectorAll('[data-tippy-root]'));\n }\n\n function scheduleShow(event) {\n instance.clearDelayTimeouts();\n\n if (event) {\n invokeHook('onTrigger', [instance, event]);\n }\n\n addDocumentPress();\n var delay = getDelay(true);\n\n var _getNormalizedTouchSe = getNormalizedTouchSettings(),\n touchValue = _getNormalizedTouchSe[0],\n touchDelay = _getNormalizedTouchSe[1];\n\n if (currentInput.isTouch && touchValue === 'hold' && touchDelay) {\n delay = touchDelay;\n }\n\n if (delay) {\n showTimeout = setTimeout(function () {\n instance.show();\n }, delay);\n } else {\n instance.show();\n }\n }\n\n function scheduleHide(event) {\n instance.clearDelayTimeouts();\n invokeHook('onUntrigger', [instance, event]);\n\n if (!instance.state.isVisible) {\n removeDocumentPress();\n return;\n } // For interactive tippies, scheduleHide is added to a document.body handler\n // from onMouseLeave so must intercept scheduled hides from mousemove/leave\n // events when trigger contains mouseenter and click, and the tip is\n // currently shown as a result of a click.\n\n\n if (instance.props.trigger.indexOf('mouseenter') >= 0 && instance.props.trigger.indexOf('click') >= 0 && ['mouseleave', 'mousemove'].indexOf(event.type) >= 0 && isVisibleFromClick) {\n return;\n }\n\n var delay = getDelay(false);\n\n if (delay) {\n hideTimeout = setTimeout(function () {\n if (instance.state.isVisible) {\n instance.hide();\n }\n }, delay);\n } else {\n // Fixes a `transitionend` problem when it fires 1 frame too\n // late sometimes, we don't want hide() to be called.\n scheduleHideAnimationFrame = requestAnimationFrame(function () {\n instance.hide();\n });\n }\n } // ===========================================================================\n // 🔑 Public methods\n // ===========================================================================\n\n\n function enable() {\n instance.state.isEnabled = true;\n }\n\n function disable() {\n // Disabling the instance should also hide it\n // https://github.com/atomiks/tippy.js-react/issues/106\n instance.hide();\n instance.state.isEnabled = false;\n }\n\n function clearDelayTimeouts() {\n clearTimeout(showTimeout);\n clearTimeout(hideTimeout);\n cancelAnimationFrame(scheduleHideAnimationFrame);\n }\n\n function setProps(partialProps) {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== \"production\") {\n warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('setProps'));\n }\n\n if (instance.state.isDestroyed) {\n return;\n }\n\n invokeHook('onBeforeUpdate', [instance, partialProps]);\n removeListeners();\n var prevProps = instance.props;\n var nextProps = evaluateProps(reference, Object.assign({}, prevProps, removeUndefinedProps(partialProps), {\n ignoreAttributes: true\n }));\n instance.props = nextProps;\n addListeners();\n\n if (prevProps.interactiveDebounce !== nextProps.interactiveDebounce) {\n cleanupInteractiveMouseListeners();\n debouncedOnMouseMove = debounce(onMouseMove, nextProps.interactiveDebounce);\n } // Ensure stale aria-expanded attributes are removed\n\n\n if (prevProps.triggerTarget && !nextProps.triggerTarget) {\n normalizeToArray(prevProps.triggerTarget).forEach(function (node) {\n node.removeAttribute('aria-expanded');\n });\n } else if (nextProps.triggerTarget) {\n reference.removeAttribute('aria-expanded');\n }\n\n handleAriaExpandedAttribute();\n handleStyles();\n\n if (onUpdate) {\n onUpdate(prevProps, nextProps);\n }\n\n if (instance.popperInstance) {\n createPopperInstance(); // Fixes an issue with nested tippies if they are all getting re-rendered,\n // and the nested ones get re-rendered first.\n // https://github.com/atomiks/tippyjs-react/issues/177\n // TODO: find a cleaner / more efficient solution(!)\n\n getNestedPopperTree().forEach(function (nestedPopper) {\n // React (and other UI libs likely) requires a rAF wrapper as it flushes\n // its work in one\n requestAnimationFrame(nestedPopper._tippy.popperInstance.forceUpdate);\n });\n }\n\n invokeHook('onAfterUpdate', [instance, partialProps]);\n }\n\n function setContent(content) {\n instance.setProps({\n content: content\n });\n }\n\n function show() {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== \"production\") {\n warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('show'));\n } // Early bail-out\n\n\n var isAlreadyVisible = instance.state.isVisible;\n var isDestroyed = instance.state.isDestroyed;\n var isDisabled = !instance.state.isEnabled;\n var isTouchAndTouchDisabled = currentInput.isTouch && !instance.props.touch;\n var duration = getValueAtIndexOrReturn(instance.props.duration, 0, defaultProps.duration);\n\n if (isAlreadyVisible || isDestroyed || isDisabled || isTouchAndTouchDisabled) {\n return;\n } // Normalize `disabled` behavior across browsers.\n // Firefox allows events on disabled elements, but Chrome doesn't.\n // Using a wrapper element (i.e. ) is recommended.\n\n\n if (getCurrentTarget().hasAttribute('disabled')) {\n return;\n }\n\n invokeHook('onShow', [instance], false);\n\n if (instance.props.onShow(instance) === false) {\n return;\n }\n\n instance.state.isVisible = true;\n\n if (getIsDefaultRenderFn()) {\n popper.style.visibility = 'visible';\n }\n\n handleStyles();\n addDocumentPress();\n\n if (!instance.state.isMounted) {\n popper.style.transition = 'none';\n } // If flipping to the opposite side after hiding at least once, the\n // animation will use the wrong placement without resetting the duration\n\n\n if (getIsDefaultRenderFn()) {\n var _getDefaultTemplateCh2 = getDefaultTemplateChildren(),\n box = _getDefaultTemplateCh2.box,\n content = _getDefaultTemplateCh2.content;\n\n setTransitionDuration([box, content], 0);\n }\n\n onFirstUpdate = function onFirstUpdate() {\n var _instance$popperInsta2;\n\n if (!instance.state.isVisible || ignoreOnFirstUpdate) {\n return;\n }\n\n ignoreOnFirstUpdate = true; // reflow\n\n void popper.offsetHeight;\n popper.style.transition = instance.props.moveTransition;\n\n if (getIsDefaultRenderFn() && instance.props.animation) {\n var _getDefaultTemplateCh3 = getDefaultTemplateChildren(),\n _box = _getDefaultTemplateCh3.box,\n _content = _getDefaultTemplateCh3.content;\n\n setTransitionDuration([_box, _content], duration);\n setVisibilityState([_box, _content], 'visible');\n }\n\n handleAriaContentAttribute();\n handleAriaExpandedAttribute();\n pushIfUnique(mountedInstances, instance); // certain modifiers (e.g. `maxSize`) require a second update after the\n // popper has been positioned for the first time\n\n (_instance$popperInsta2 = instance.popperInstance) == null ? void 0 : _instance$popperInsta2.forceUpdate();\n invokeHook('onMount', [instance]);\n\n if (instance.props.animation && getIsDefaultRenderFn()) {\n onTransitionedIn(duration, function () {\n instance.state.isShown = true;\n invokeHook('onShown', [instance]);\n });\n }\n };\n\n mount();\n }\n\n function hide() {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== \"production\") {\n warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('hide'));\n } // Early bail-out\n\n\n var isAlreadyHidden = !instance.state.isVisible;\n var isDestroyed = instance.state.isDestroyed;\n var isDisabled = !instance.state.isEnabled;\n var duration = getValueAtIndexOrReturn(instance.props.duration, 1, defaultProps.duration);\n\n if (isAlreadyHidden || isDestroyed || isDisabled) {\n return;\n }\n\n invokeHook('onHide', [instance], false);\n\n if (instance.props.onHide(instance) === false) {\n return;\n }\n\n instance.state.isVisible = false;\n instance.state.isShown = false;\n ignoreOnFirstUpdate = false;\n isVisibleFromClick = false;\n\n if (getIsDefaultRenderFn()) {\n popper.style.visibility = 'hidden';\n }\n\n cleanupInteractiveMouseListeners();\n removeDocumentPress();\n handleStyles(true);\n\n if (getIsDefaultRenderFn()) {\n var _getDefaultTemplateCh4 = getDefaultTemplateChildren(),\n box = _getDefaultTemplateCh4.box,\n content = _getDefaultTemplateCh4.content;\n\n if (instance.props.animation) {\n setTransitionDuration([box, content], duration);\n setVisibilityState([box, content], 'hidden');\n }\n }\n\n handleAriaContentAttribute();\n handleAriaExpandedAttribute();\n\n if (instance.props.animation) {\n if (getIsDefaultRenderFn()) {\n onTransitionedOut(duration, instance.unmount);\n }\n } else {\n instance.unmount();\n }\n }\n\n function hideWithInteractivity(event) {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== \"production\") {\n warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('hideWithInteractivity'));\n }\n\n getDocument().addEventListener('mousemove', debouncedOnMouseMove);\n pushIfUnique(mouseMoveListeners, debouncedOnMouseMove);\n debouncedOnMouseMove(event);\n }\n\n function unmount() {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== \"production\") {\n warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('unmount'));\n }\n\n if (instance.state.isVisible) {\n instance.hide();\n }\n\n if (!instance.state.isMounted) {\n return;\n }\n\n destroyPopperInstance(); // If a popper is not interactive, it will be appended outside the popper\n // tree by default. This seems mainly for interactive tippies, but we should\n // find a workaround if possible\n\n getNestedPopperTree().forEach(function (nestedPopper) {\n nestedPopper._tippy.unmount();\n });\n\n if (popper.parentNode) {\n popper.parentNode.removeChild(popper);\n }\n\n mountedInstances = mountedInstances.filter(function (i) {\n return i !== instance;\n });\n instance.state.isMounted = false;\n invokeHook('onHidden', [instance]);\n }\n\n function destroy() {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== \"production\") {\n warnWhen(instance.state.isDestroyed, createMemoryLeakWarning('destroy'));\n }\n\n if (instance.state.isDestroyed) {\n return;\n }\n\n instance.clearDelayTimeouts();\n instance.unmount();\n removeListeners();\n delete reference._tippy;\n instance.state.isDestroyed = true;\n invokeHook('onDestroy', [instance]);\n }\n}\n\nfunction tippy(targets, optionalProps) {\n if (optionalProps === void 0) {\n optionalProps = {};\n }\n\n var plugins = defaultProps.plugins.concat(optionalProps.plugins || []);\n /* istanbul ignore else */\n\n if (process.env.NODE_ENV !== \"production\") {\n validateTargets(targets);\n validateProps(optionalProps, plugins);\n }\n\n bindGlobalEventListeners();\n var passedProps = Object.assign({}, optionalProps, {\n plugins: plugins\n });\n var elements = getArrayOfElements(targets);\n /* istanbul ignore else */\n\n if (process.env.NODE_ENV !== \"production\") {\n var isSingleContentElement = isElement(passedProps.content);\n var isMoreThanOneReferenceElement = elements.length > 1;\n warnWhen(isSingleContentElement && isMoreThanOneReferenceElement, ['tippy() was passed an Element as the `content` prop, but more than', 'one tippy instance was created by this invocation. This means the', 'content element will only be appended to the last tippy instance.', '\\n\\n', 'Instead, pass the .innerHTML of the element, or use a function that', 'returns a cloned version of the element instead.', '\\n\\n', '1) content: element.innerHTML\\n', '2) content: () => element.cloneNode(true)'].join(' '));\n }\n\n var instances = elements.reduce(function (acc, reference) {\n var instance = reference && createTippy(reference, passedProps);\n\n if (instance) {\n acc.push(instance);\n }\n\n return acc;\n }, []);\n return isElement(targets) ? instances[0] : instances;\n}\n\ntippy.defaultProps = defaultProps;\ntippy.setDefaultProps = setDefaultProps;\ntippy.currentInput = currentInput;\nvar hideAll = function hideAll(_temp) {\n var _ref = _temp === void 0 ? {} : _temp,\n excludedReferenceOrInstance = _ref.exclude,\n duration = _ref.duration;\n\n mountedInstances.forEach(function (instance) {\n var isExcluded = false;\n\n if (excludedReferenceOrInstance) {\n isExcluded = isReferenceElement(excludedReferenceOrInstance) ? instance.reference === excludedReferenceOrInstance : instance.popper === excludedReferenceOrInstance.popper;\n }\n\n if (!isExcluded) {\n var originalDuration = instance.props.duration;\n instance.setProps({\n duration: duration\n });\n instance.hide();\n\n if (!instance.state.isDestroyed) {\n instance.setProps({\n duration: originalDuration\n });\n }\n }\n });\n};\n\n// every time the popper is destroyed (i.e. a new target), removing the styles\n// and causing transitions to break for singletons when the console is open, but\n// most notably for non-transform styles being used, `gpuAcceleration: false`.\n\nvar applyStylesModifier = Object.assign({}, applyStyles, {\n effect: function effect(_ref) {\n var state = _ref.state;\n var initialStyles = {\n popper: {\n position: state.options.strategy,\n left: '0',\n top: '0',\n margin: '0'\n },\n arrow: {\n position: 'absolute'\n },\n reference: {}\n };\n Object.assign(state.elements.popper.style, initialStyles.popper);\n state.styles = initialStyles;\n\n if (state.elements.arrow) {\n Object.assign(state.elements.arrow.style, initialStyles.arrow);\n } // intentionally return no cleanup function\n // return () => { ... }\n\n }\n});\n\nvar createSingleton = function createSingleton(tippyInstances, optionalProps) {\n var _optionalProps$popper;\n\n if (optionalProps === void 0) {\n optionalProps = {};\n }\n\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== \"production\") {\n errorWhen(!Array.isArray(tippyInstances), ['The first argument passed to createSingleton() must be an array of', 'tippy instances. The passed value was', String(tippyInstances)].join(' '));\n }\n\n var individualInstances = tippyInstances;\n var references = [];\n var triggerTargets = [];\n var currentTarget;\n var overrides = optionalProps.overrides;\n var interceptSetPropsCleanups = [];\n var shownOnCreate = false;\n\n function setTriggerTargets() {\n triggerTargets = individualInstances.map(function (instance) {\n return normalizeToArray(instance.props.triggerTarget || instance.reference);\n }).reduce(function (acc, item) {\n return acc.concat(item);\n }, []);\n }\n\n function setReferences() {\n references = individualInstances.map(function (instance) {\n return instance.reference;\n });\n }\n\n function enableInstances(isEnabled) {\n individualInstances.forEach(function (instance) {\n if (isEnabled) {\n instance.enable();\n } else {\n instance.disable();\n }\n });\n }\n\n function interceptSetProps(singleton) {\n return individualInstances.map(function (instance) {\n var originalSetProps = instance.setProps;\n\n instance.setProps = function (props) {\n originalSetProps(props);\n\n if (instance.reference === currentTarget) {\n singleton.setProps(props);\n }\n };\n\n return function () {\n instance.setProps = originalSetProps;\n };\n });\n } // have to pass singleton, as it maybe undefined on first call\n\n\n function prepareInstance(singleton, target) {\n var index = triggerTargets.indexOf(target); // bail-out\n\n if (target === currentTarget) {\n return;\n }\n\n currentTarget = target;\n var overrideProps = (overrides || []).concat('content').reduce(function (acc, prop) {\n acc[prop] = individualInstances[index].props[prop];\n return acc;\n }, {});\n singleton.setProps(Object.assign({}, overrideProps, {\n getReferenceClientRect: typeof overrideProps.getReferenceClientRect === 'function' ? overrideProps.getReferenceClientRect : function () {\n var _references$index;\n\n return (_references$index = references[index]) == null ? void 0 : _references$index.getBoundingClientRect();\n }\n }));\n }\n\n enableInstances(false);\n setReferences();\n setTriggerTargets();\n var plugin = {\n fn: function fn() {\n return {\n onDestroy: function onDestroy() {\n enableInstances(true);\n },\n onHidden: function onHidden() {\n currentTarget = null;\n },\n onClickOutside: function onClickOutside(instance) {\n if (instance.props.showOnCreate && !shownOnCreate) {\n shownOnCreate = true;\n currentTarget = null;\n }\n },\n onShow: function onShow(instance) {\n if (instance.props.showOnCreate && !shownOnCreate) {\n shownOnCreate = true;\n prepareInstance(instance, references[0]);\n }\n },\n onTrigger: function onTrigger(instance, event) {\n prepareInstance(instance, event.currentTarget);\n }\n };\n }\n };\n var singleton = tippy(div(), Object.assign({}, removeProperties(optionalProps, ['overrides']), {\n plugins: [plugin].concat(optionalProps.plugins || []),\n triggerTarget: triggerTargets,\n popperOptions: Object.assign({}, optionalProps.popperOptions, {\n modifiers: [].concat(((_optionalProps$popper = optionalProps.popperOptions) == null ? void 0 : _optionalProps$popper.modifiers) || [], [applyStylesModifier])\n })\n }));\n var originalShow = singleton.show;\n\n singleton.show = function (target) {\n originalShow(); // first time, showOnCreate or programmatic call with no params\n // default to showing first instance\n\n if (!currentTarget && target == null) {\n return prepareInstance(singleton, references[0]);\n } // triggered from event (do nothing as prepareInstance already called by onTrigger)\n // programmatic call with no params when already visible (do nothing again)\n\n\n if (currentTarget && target == null) {\n return;\n } // target is index of instance\n\n\n if (typeof target === 'number') {\n return references[target] && prepareInstance(singleton, references[target]);\n } // target is a child tippy instance\n\n\n if (individualInstances.indexOf(target) >= 0) {\n var ref = target.reference;\n return prepareInstance(singleton, ref);\n } // target is a ReferenceElement\n\n\n if (references.indexOf(target) >= 0) {\n return prepareInstance(singleton, target);\n }\n };\n\n singleton.showNext = function () {\n var first = references[0];\n\n if (!currentTarget) {\n return singleton.show(0);\n }\n\n var index = references.indexOf(currentTarget);\n singleton.show(references[index + 1] || first);\n };\n\n singleton.showPrevious = function () {\n var last = references[references.length - 1];\n\n if (!currentTarget) {\n return singleton.show(last);\n }\n\n var index = references.indexOf(currentTarget);\n var target = references[index - 1] || last;\n singleton.show(target);\n };\n\n var originalSetProps = singleton.setProps;\n\n singleton.setProps = function (props) {\n overrides = props.overrides || overrides;\n originalSetProps(props);\n };\n\n singleton.setInstances = function (nextInstances) {\n enableInstances(true);\n interceptSetPropsCleanups.forEach(function (fn) {\n return fn();\n });\n individualInstances = nextInstances;\n enableInstances(false);\n setReferences();\n setTriggerTargets();\n interceptSetPropsCleanups = interceptSetProps(singleton);\n singleton.setProps({\n triggerTarget: triggerTargets\n });\n };\n\n interceptSetPropsCleanups = interceptSetProps(singleton);\n return singleton;\n};\n\nvar BUBBLING_EVENTS_MAP = {\n mouseover: 'mouseenter',\n focusin: 'focus',\n click: 'click'\n};\n/**\n * Creates a delegate instance that controls the creation of tippy instances\n * for child elements (`target` CSS selector).\n */\n\nfunction delegate(targets, props) {\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== \"production\") {\n errorWhen(!(props && props.target), ['You must specity a `target` prop indicating a CSS selector string matching', 'the target elements that should receive a tippy.'].join(' '));\n }\n\n var listeners = [];\n var childTippyInstances = [];\n var disabled = false;\n var target = props.target;\n var nativeProps = removeProperties(props, ['target']);\n var parentProps = Object.assign({}, nativeProps, {\n trigger: 'manual',\n touch: false\n });\n var childProps = Object.assign({\n touch: defaultProps.touch\n }, nativeProps, {\n showOnCreate: true\n });\n var returnValue = tippy(targets, parentProps);\n var normalizedReturnValue = normalizeToArray(returnValue);\n\n function onTrigger(event) {\n if (!event.target || disabled) {\n return;\n }\n\n var targetNode = event.target.closest(target);\n\n if (!targetNode) {\n return;\n } // Get relevant trigger with fallbacks:\n // 1. Check `data-tippy-trigger` attribute on target node\n // 2. Fallback to `trigger` passed to `delegate()`\n // 3. Fallback to `defaultProps.trigger`\n\n\n var trigger = targetNode.getAttribute('data-tippy-trigger') || props.trigger || defaultProps.trigger; // @ts-ignore\n\n if (targetNode._tippy) {\n return;\n }\n\n if (event.type === 'touchstart' && typeof childProps.touch === 'boolean') {\n return;\n }\n\n if (event.type !== 'touchstart' && trigger.indexOf(BUBBLING_EVENTS_MAP[event.type]) < 0) {\n return;\n }\n\n var instance = tippy(targetNode, childProps);\n\n if (instance) {\n childTippyInstances = childTippyInstances.concat(instance);\n }\n }\n\n function on(node, eventType, handler, options) {\n if (options === void 0) {\n options = false;\n }\n\n node.addEventListener(eventType, handler, options);\n listeners.push({\n node: node,\n eventType: eventType,\n handler: handler,\n options: options\n });\n }\n\n function addEventListeners(instance) {\n var reference = instance.reference;\n on(reference, 'touchstart', onTrigger, TOUCH_OPTIONS);\n on(reference, 'mouseover', onTrigger);\n on(reference, 'focusin', onTrigger);\n on(reference, 'click', onTrigger);\n }\n\n function removeEventListeners() {\n listeners.forEach(function (_ref) {\n var node = _ref.node,\n eventType = _ref.eventType,\n handler = _ref.handler,\n options = _ref.options;\n node.removeEventListener(eventType, handler, options);\n });\n listeners = [];\n }\n\n function applyMutations(instance) {\n var originalDestroy = instance.destroy;\n var originalEnable = instance.enable;\n var originalDisable = instance.disable;\n\n instance.destroy = function (shouldDestroyChildInstances) {\n if (shouldDestroyChildInstances === void 0) {\n shouldDestroyChildInstances = true;\n }\n\n if (shouldDestroyChildInstances) {\n childTippyInstances.forEach(function (instance) {\n instance.destroy();\n });\n }\n\n childTippyInstances = [];\n removeEventListeners();\n originalDestroy();\n };\n\n instance.enable = function () {\n originalEnable();\n childTippyInstances.forEach(function (instance) {\n return instance.enable();\n });\n disabled = false;\n };\n\n instance.disable = function () {\n originalDisable();\n childTippyInstances.forEach(function (instance) {\n return instance.disable();\n });\n disabled = true;\n };\n\n addEventListeners(instance);\n }\n\n normalizedReturnValue.forEach(applyMutations);\n return returnValue;\n}\n\nvar animateFill = {\n name: 'animateFill',\n defaultValue: false,\n fn: function fn(instance) {\n var _instance$props$rende;\n\n // @ts-ignore\n if (!((_instance$props$rende = instance.props.render) != null && _instance$props$rende.$$tippy)) {\n if (process.env.NODE_ENV !== \"production\") {\n errorWhen(instance.props.animateFill, 'The `animateFill` plugin requires the default render function.');\n }\n\n return {};\n }\n\n var _getChildren = getChildren(instance.popper),\n box = _getChildren.box,\n content = _getChildren.content;\n\n var backdrop = instance.props.animateFill ? createBackdropElement() : null;\n return {\n onCreate: function onCreate() {\n if (backdrop) {\n box.insertBefore(backdrop, box.firstElementChild);\n box.setAttribute('data-animatefill', '');\n box.style.overflow = 'hidden';\n instance.setProps({\n arrow: false,\n animation: 'shift-away'\n });\n }\n },\n onMount: function onMount() {\n if (backdrop) {\n var transitionDuration = box.style.transitionDuration;\n var duration = Number(transitionDuration.replace('ms', '')); // The content should fade in after the backdrop has mostly filled the\n // tooltip element. `clip-path` is the other alternative but is not\n // well-supported and is buggy on some devices.\n\n content.style.transitionDelay = Math.round(duration / 10) + \"ms\";\n backdrop.style.transitionDuration = transitionDuration;\n setVisibilityState([backdrop], 'visible');\n }\n },\n onShow: function onShow() {\n if (backdrop) {\n backdrop.style.transitionDuration = '0ms';\n }\n },\n onHide: function onHide() {\n if (backdrop) {\n setVisibilityState([backdrop], 'hidden');\n }\n }\n };\n }\n};\n\nfunction createBackdropElement() {\n var backdrop = div();\n backdrop.className = BACKDROP_CLASS;\n setVisibilityState([backdrop], 'hidden');\n return backdrop;\n}\n\nvar mouseCoords = {\n clientX: 0,\n clientY: 0\n};\nvar activeInstances = [];\n\nfunction storeMouseCoords(_ref) {\n var clientX = _ref.clientX,\n clientY = _ref.clientY;\n mouseCoords = {\n clientX: clientX,\n clientY: clientY\n };\n}\n\nfunction addMouseCoordsListener(doc) {\n doc.addEventListener('mousemove', storeMouseCoords);\n}\n\nfunction removeMouseCoordsListener(doc) {\n doc.removeEventListener('mousemove', storeMouseCoords);\n}\n\nvar followCursor = {\n name: 'followCursor',\n defaultValue: false,\n fn: function fn(instance) {\n var reference = instance.reference;\n var doc = getOwnerDocument(instance.props.triggerTarget || reference);\n var isInternalUpdate = false;\n var wasFocusEvent = false;\n var isUnmounted = true;\n var prevProps = instance.props;\n\n function getIsInitialBehavior() {\n return instance.props.followCursor === 'initial' && instance.state.isVisible;\n }\n\n function addListener() {\n doc.addEventListener('mousemove', onMouseMove);\n }\n\n function removeListener() {\n doc.removeEventListener('mousemove', onMouseMove);\n }\n\n function unsetGetReferenceClientRect() {\n isInternalUpdate = true;\n instance.setProps({\n getReferenceClientRect: null\n });\n isInternalUpdate = false;\n }\n\n function onMouseMove(event) {\n // If the instance is interactive, avoid updating the position unless it's\n // over the reference element\n var isCursorOverReference = event.target ? reference.contains(event.target) : true;\n var followCursor = instance.props.followCursor;\n var clientX = event.clientX,\n clientY = event.clientY;\n var rect = reference.getBoundingClientRect();\n var relativeX = clientX - rect.left;\n var relativeY = clientY - rect.top;\n\n if (isCursorOverReference || !instance.props.interactive) {\n instance.setProps({\n // @ts-ignore - unneeded DOMRect properties\n getReferenceClientRect: function getReferenceClientRect() {\n var rect = reference.getBoundingClientRect();\n var x = clientX;\n var y = clientY;\n\n if (followCursor === 'initial') {\n x = rect.left + relativeX;\n y = rect.top + relativeY;\n }\n\n var top = followCursor === 'horizontal' ? rect.top : y;\n var right = followCursor === 'vertical' ? rect.right : x;\n var bottom = followCursor === 'horizontal' ? rect.bottom : y;\n var left = followCursor === 'vertical' ? rect.left : x;\n return {\n width: right - left,\n height: bottom - top,\n top: top,\n right: right,\n bottom: bottom,\n left: left\n };\n }\n });\n }\n }\n\n function create() {\n if (instance.props.followCursor) {\n activeInstances.push({\n instance: instance,\n doc: doc\n });\n addMouseCoordsListener(doc);\n }\n }\n\n function destroy() {\n activeInstances = activeInstances.filter(function (data) {\n return data.instance !== instance;\n });\n\n if (activeInstances.filter(function (data) {\n return data.doc === doc;\n }).length === 0) {\n removeMouseCoordsListener(doc);\n }\n }\n\n return {\n onCreate: create,\n onDestroy: destroy,\n onBeforeUpdate: function onBeforeUpdate() {\n prevProps = instance.props;\n },\n onAfterUpdate: function onAfterUpdate(_, _ref2) {\n var followCursor = _ref2.followCursor;\n\n if (isInternalUpdate) {\n return;\n }\n\n if (followCursor !== undefined && prevProps.followCursor !== followCursor) {\n destroy();\n\n if (followCursor) {\n create();\n\n if (instance.state.isMounted && !wasFocusEvent && !getIsInitialBehavior()) {\n addListener();\n }\n } else {\n removeListener();\n unsetGetReferenceClientRect();\n }\n }\n },\n onMount: function onMount() {\n if (instance.props.followCursor && !wasFocusEvent) {\n if (isUnmounted) {\n onMouseMove(mouseCoords);\n isUnmounted = false;\n }\n\n if (!getIsInitialBehavior()) {\n addListener();\n }\n }\n },\n onTrigger: function onTrigger(_, event) {\n if (isMouseEvent(event)) {\n mouseCoords = {\n clientX: event.clientX,\n clientY: event.clientY\n };\n }\n\n wasFocusEvent = event.type === 'focus';\n },\n onHidden: function onHidden() {\n if (instance.props.followCursor) {\n unsetGetReferenceClientRect();\n removeListener();\n isUnmounted = true;\n }\n }\n };\n }\n};\n\nfunction getProps(props, modifier) {\n var _props$popperOptions;\n\n return {\n popperOptions: Object.assign({}, props.popperOptions, {\n modifiers: [].concat((((_props$popperOptions = props.popperOptions) == null ? void 0 : _props$popperOptions.modifiers) || []).filter(function (_ref) {\n var name = _ref.name;\n return name !== modifier.name;\n }), [modifier])\n })\n };\n}\n\nvar inlinePositioning = {\n name: 'inlinePositioning',\n defaultValue: false,\n fn: function fn(instance) {\n var reference = instance.reference;\n\n function isEnabled() {\n return !!instance.props.inlinePositioning;\n }\n\n var placement;\n var cursorRectIndex = -1;\n var isInternalUpdate = false;\n var triedPlacements = [];\n var modifier = {\n name: 'tippyInlinePositioning',\n enabled: true,\n phase: 'afterWrite',\n fn: function fn(_ref2) {\n var state = _ref2.state;\n\n if (isEnabled()) {\n if (triedPlacements.indexOf(state.placement) !== -1) {\n triedPlacements = [];\n }\n\n if (placement !== state.placement && triedPlacements.indexOf(state.placement) === -1) {\n triedPlacements.push(state.placement);\n instance.setProps({\n // @ts-ignore - unneeded DOMRect properties\n getReferenceClientRect: function getReferenceClientRect() {\n return _getReferenceClientRect(state.placement);\n }\n });\n }\n\n placement = state.placement;\n }\n }\n };\n\n function _getReferenceClientRect(placement) {\n return getInlineBoundingClientRect(getBasePlacement(placement), reference.getBoundingClientRect(), arrayFrom(reference.getClientRects()), cursorRectIndex);\n }\n\n function setInternalProps(partialProps) {\n isInternalUpdate = true;\n instance.setProps(partialProps);\n isInternalUpdate = false;\n }\n\n function addModifier() {\n if (!isInternalUpdate) {\n setInternalProps(getProps(instance.props, modifier));\n }\n }\n\n return {\n onCreate: addModifier,\n onAfterUpdate: addModifier,\n onTrigger: function onTrigger(_, event) {\n if (isMouseEvent(event)) {\n var rects = arrayFrom(instance.reference.getClientRects());\n var cursorRect = rects.find(function (rect) {\n return rect.left - 2 <= event.clientX && rect.right + 2 >= event.clientX && rect.top - 2 <= event.clientY && rect.bottom + 2 >= event.clientY;\n });\n var index = rects.indexOf(cursorRect);\n cursorRectIndex = index > -1 ? index : cursorRectIndex;\n }\n },\n onHidden: function onHidden() {\n cursorRectIndex = -1;\n }\n };\n }\n};\nfunction getInlineBoundingClientRect(currentBasePlacement, boundingRect, clientRects, cursorRectIndex) {\n // Not an inline element, or placement is not yet known\n if (clientRects.length < 2 || currentBasePlacement === null) {\n return boundingRect;\n } // There are two rects and they are disjoined\n\n\n if (clientRects.length === 2 && cursorRectIndex >= 0 && clientRects[0].left > clientRects[1].right) {\n return clientRects[cursorRectIndex] || boundingRect;\n }\n\n switch (currentBasePlacement) {\n case 'top':\n case 'bottom':\n {\n var firstRect = clientRects[0];\n var lastRect = clientRects[clientRects.length - 1];\n var isTop = currentBasePlacement === 'top';\n var top = firstRect.top;\n var bottom = lastRect.bottom;\n var left = isTop ? firstRect.left : lastRect.left;\n var right = isTop ? firstRect.right : lastRect.right;\n var width = right - left;\n var height = bottom - top;\n return {\n top: top,\n bottom: bottom,\n left: left,\n right: right,\n width: width,\n height: height\n };\n }\n\n case 'left':\n case 'right':\n {\n var minLeft = Math.min.apply(Math, clientRects.map(function (rects) {\n return rects.left;\n }));\n var maxRight = Math.max.apply(Math, clientRects.map(function (rects) {\n return rects.right;\n }));\n var measureRects = clientRects.filter(function (rect) {\n return currentBasePlacement === 'left' ? rect.left === minLeft : rect.right === maxRight;\n });\n var _top = measureRects[0].top;\n var _bottom = measureRects[measureRects.length - 1].bottom;\n var _left = minLeft;\n var _right = maxRight;\n\n var _width = _right - _left;\n\n var _height = _bottom - _top;\n\n return {\n top: _top,\n bottom: _bottom,\n left: _left,\n right: _right,\n width: _width,\n height: _height\n };\n }\n\n default:\n {\n return boundingRect;\n }\n }\n}\n\nvar sticky = {\n name: 'sticky',\n defaultValue: false,\n fn: function fn(instance) {\n var reference = instance.reference,\n popper = instance.popper;\n\n function getReference() {\n return instance.popperInstance ? instance.popperInstance.state.elements.reference : reference;\n }\n\n function shouldCheck(value) {\n return instance.props.sticky === true || instance.props.sticky === value;\n }\n\n var prevRefRect = null;\n var prevPopRect = null;\n\n function updatePosition() {\n var currentRefRect = shouldCheck('reference') ? getReference().getBoundingClientRect() : null;\n var currentPopRect = shouldCheck('popper') ? popper.getBoundingClientRect() : null;\n\n if (currentRefRect && areRectsDifferent(prevRefRect, currentRefRect) || currentPopRect && areRectsDifferent(prevPopRect, currentPopRect)) {\n if (instance.popperInstance) {\n instance.popperInstance.update();\n }\n }\n\n prevRefRect = currentRefRect;\n prevPopRect = currentPopRect;\n\n if (instance.state.isMounted) {\n requestAnimationFrame(updatePosition);\n }\n }\n\n return {\n onMount: function onMount() {\n if (instance.props.sticky) {\n updatePosition();\n }\n }\n };\n }\n};\n\nfunction areRectsDifferent(rectA, rectB) {\n if (rectA && rectB) {\n return rectA.top !== rectB.top || rectA.right !== rectB.right || rectA.bottom !== rectB.bottom || rectA.left !== rectB.left;\n }\n\n return true;\n}\n\ntippy.setDefaultProps({\n render: render\n});\n\nexport default tippy;\nexport { animateFill, createSingleton, delegate, followCursor, hideAll, inlinePositioning, ROUND_ARROW as roundArrow, sticky };\n//# sourceMappingURL=tippy.esm.js.map\n","import { isTextSelection, isNodeSelection, posToDOMRect, Extension } from '@tiptap/core';\nimport { Plugin, PluginKey } from '@tiptap/pm/state';\nimport tippy from 'tippy.js';\n\nclass BubbleMenuView {\n constructor({ editor, element, view, tippyOptions = {}, updateDelay = 250, shouldShow, }) {\n this.preventHide = false;\n this.shouldShow = ({ view, state, from, to, }) => {\n const { doc, selection } = state;\n const { empty } = selection;\n // Sometime check for `empty` is not enough.\n // Doubleclick an empty paragraph returns a node size of 2.\n // So we check also for an empty text size.\n const isEmptyTextBlock = !doc.textBetween(from, to).length && isTextSelection(state.selection);\n // When clicking on a element inside the bubble menu the editor \"blur\" event\n // is called and the bubble menu item is focussed. In this case we should\n // consider the menu as part of the editor and keep showing the menu\n const isChildOfMenu = this.element.contains(document.activeElement);\n const hasEditorFocus = view.hasFocus() || isChildOfMenu;\n if (!hasEditorFocus || empty || isEmptyTextBlock || !this.editor.isEditable) {\n return false;\n }\n return true;\n };\n this.mousedownHandler = () => {\n this.preventHide = true;\n };\n this.dragstartHandler = () => {\n this.hide();\n };\n this.focusHandler = () => {\n // we use `setTimeout` to make sure `selection` is already updated\n setTimeout(() => this.update(this.editor.view));\n };\n this.blurHandler = ({ event }) => {\n var _a;\n if (this.preventHide) {\n this.preventHide = false;\n return;\n }\n if ((event === null || event === void 0 ? void 0 : event.relatedTarget) && ((_a = this.element.parentNode) === null || _a === void 0 ? void 0 : _a.contains(event.relatedTarget))) {\n return;\n }\n if ((event === null || event === void 0 ? void 0 : event.relatedTarget) === this.editor.view.dom) {\n return;\n }\n this.hide();\n };\n this.tippyBlurHandler = (event) => {\n this.blurHandler({ event });\n };\n this.handleDebouncedUpdate = (view, oldState) => {\n const selectionChanged = !(oldState === null || oldState === void 0 ? void 0 : oldState.selection.eq(view.state.selection));\n const docChanged = !(oldState === null || oldState === void 0 ? void 0 : oldState.doc.eq(view.state.doc));\n if (!selectionChanged && !docChanged) {\n return;\n }\n if (this.updateDebounceTimer) {\n clearTimeout(this.updateDebounceTimer);\n }\n this.updateDebounceTimer = window.setTimeout(() => {\n this.updateHandler(view, selectionChanged, docChanged, oldState);\n }, this.updateDelay);\n };\n this.updateHandler = (view, selectionChanged, docChanged, oldState) => {\n var _a, _b, _c;\n const { state, composing } = view;\n const { selection } = state;\n const isSame = !selectionChanged && !docChanged;\n if (composing || isSame) {\n return;\n }\n this.createTooltip();\n // support for CellSelections\n const { ranges } = selection;\n const from = Math.min(...ranges.map(range => range.$from.pos));\n const to = Math.max(...ranges.map(range => range.$to.pos));\n const shouldShow = (_a = this.shouldShow) === null || _a === void 0 ? void 0 : _a.call(this, {\n editor: this.editor,\n element: this.element,\n view,\n state,\n oldState,\n from,\n to,\n });\n if (!shouldShow) {\n this.hide();\n return;\n }\n (_b = this.tippy) === null || _b === void 0 ? void 0 : _b.setProps({\n getReferenceClientRect: ((_c = this.tippyOptions) === null || _c === void 0 ? void 0 : _c.getReferenceClientRect)\n || (() => {\n if (isNodeSelection(state.selection)) {\n let node = view.nodeDOM(from);\n if (node) {\n const nodeViewWrapper = node.dataset.nodeViewWrapper ? node : node.querySelector('[data-node-view-wrapper]');\n if (nodeViewWrapper) {\n node = nodeViewWrapper.firstChild;\n }\n if (node) {\n return node.getBoundingClientRect();\n }\n }\n }\n return posToDOMRect(view, from, to);\n }),\n });\n this.show();\n };\n this.editor = editor;\n this.element = element;\n this.view = view;\n this.updateDelay = updateDelay;\n if (shouldShow) {\n this.shouldShow = shouldShow;\n }\n this.element.addEventListener('mousedown', this.mousedownHandler, { capture: true });\n this.view.dom.addEventListener('dragstart', this.dragstartHandler);\n this.editor.on('focus', this.focusHandler);\n this.editor.on('blur', this.blurHandler);\n this.tippyOptions = tippyOptions;\n // Detaches menu content from its current parent\n this.element.remove();\n this.element.style.visibility = 'visible';\n }\n createTooltip() {\n const { element: editorElement } = this.editor.options;\n const editorIsAttached = !!editorElement.parentElement;\n this.element.tabIndex = 0;\n if (this.tippy || !editorIsAttached) {\n return;\n }\n this.tippy = tippy(editorElement, {\n duration: 0,\n getReferenceClientRect: null,\n content: this.element,\n interactive: true,\n trigger: 'manual',\n placement: 'top',\n hideOnClick: 'toggle',\n ...this.tippyOptions,\n });\n // maybe we have to hide tippy on its own blur event as well\n if (this.tippy.popper.firstChild) {\n this.tippy.popper.firstChild.addEventListener('blur', this.tippyBlurHandler);\n }\n }\n update(view, oldState) {\n const { state } = view;\n const hasValidSelection = state.selection.from !== state.selection.to;\n if (this.updateDelay > 0 && hasValidSelection) {\n this.handleDebouncedUpdate(view, oldState);\n return;\n }\n const selectionChanged = !(oldState === null || oldState === void 0 ? void 0 : oldState.selection.eq(view.state.selection));\n const docChanged = !(oldState === null || oldState === void 0 ? void 0 : oldState.doc.eq(view.state.doc));\n this.updateHandler(view, selectionChanged, docChanged, oldState);\n }\n show() {\n var _a;\n (_a = this.tippy) === null || _a === void 0 ? void 0 : _a.show();\n }\n hide() {\n var _a;\n (_a = this.tippy) === null || _a === void 0 ? void 0 : _a.hide();\n }\n destroy() {\n var _a, _b;\n if ((_a = this.tippy) === null || _a === void 0 ? void 0 : _a.popper.firstChild) {\n this.tippy.popper.firstChild.removeEventListener('blur', this.tippyBlurHandler);\n }\n (_b = this.tippy) === null || _b === void 0 ? void 0 : _b.destroy();\n this.element.removeEventListener('mousedown', this.mousedownHandler, { capture: true });\n this.view.dom.removeEventListener('dragstart', this.dragstartHandler);\n this.editor.off('focus', this.focusHandler);\n this.editor.off('blur', this.blurHandler);\n }\n}\nconst BubbleMenuPlugin = (options) => {\n return new Plugin({\n key: typeof options.pluginKey === 'string' ? new PluginKey(options.pluginKey) : options.pluginKey,\n view: view => new BubbleMenuView({ view, ...options }),\n });\n};\n\n/**\n * This extension allows you to create a bubble menu.\n * @see https://tiptap.dev/api/extensions/bubble-menu\n */\nconst BubbleMenu = Extension.create({\n name: 'bubbleMenu',\n addOptions() {\n return {\n element: null,\n tippyOptions: {},\n pluginKey: 'bubbleMenu',\n updateDelay: undefined,\n shouldShow: null,\n };\n },\n addProseMirrorPlugins() {\n if (!this.options.element) {\n return [];\n }\n return [\n BubbleMenuPlugin({\n pluginKey: this.options.pluginKey,\n editor: this.editor,\n element: this.options.element,\n tippyOptions: this.options.tippyOptions,\n updateDelay: this.options.updateDelay,\n shouldShow: this.options.shouldShow,\n }),\n ];\n },\n});\n\nexport { BubbleMenu, BubbleMenuPlugin, BubbleMenuView, BubbleMenu as default };\n//# sourceMappingURL=index.js.map\n","import { getText, getTextSerializersFromSchema, posToDOMRect, Extension } from '@tiptap/core';\nimport { Plugin, PluginKey } from '@tiptap/pm/state';\nimport tippy from 'tippy.js';\n\nclass FloatingMenuView {\n getTextContent(node) {\n return getText(node, { textSerializers: getTextSerializersFromSchema(this.editor.schema) });\n }\n constructor({ editor, element, view, tippyOptions = {}, shouldShow, }) {\n this.preventHide = false;\n this.shouldShow = ({ view, state }) => {\n const { selection } = state;\n const { $anchor, empty } = selection;\n const isRootDepth = $anchor.depth === 1;\n const isEmptyTextBlock = $anchor.parent.isTextblock && !$anchor.parent.type.spec.code && !$anchor.parent.textContent && $anchor.parent.childCount === 0 && !this.getTextContent($anchor.parent);\n if (!view.hasFocus()\n || !empty\n || !isRootDepth\n || !isEmptyTextBlock\n || !this.editor.isEditable) {\n return false;\n }\n return true;\n };\n this.mousedownHandler = () => {\n this.preventHide = true;\n };\n this.focusHandler = () => {\n // we use `setTimeout` to make sure `selection` is already updated\n setTimeout(() => this.update(this.editor.view));\n };\n this.blurHandler = ({ event }) => {\n var _a;\n if (this.preventHide) {\n this.preventHide = false;\n return;\n }\n if ((event === null || event === void 0 ? void 0 : event.relatedTarget) && ((_a = this.element.parentNode) === null || _a === void 0 ? void 0 : _a.contains(event.relatedTarget))) {\n return;\n }\n if ((event === null || event === void 0 ? void 0 : event.relatedTarget) === this.editor.view.dom) {\n return;\n }\n this.hide();\n };\n this.tippyBlurHandler = (event) => {\n this.blurHandler({ event });\n };\n this.editor = editor;\n this.element = element;\n this.view = view;\n if (shouldShow) {\n this.shouldShow = shouldShow;\n }\n this.element.addEventListener('mousedown', this.mousedownHandler, { capture: true });\n this.editor.on('focus', this.focusHandler);\n this.editor.on('blur', this.blurHandler);\n this.tippyOptions = tippyOptions;\n // Detaches menu content from its current parent\n this.element.remove();\n this.element.style.visibility = 'visible';\n }\n createTooltip() {\n const { element: editorElement } = this.editor.options;\n const editorIsAttached = !!editorElement.parentElement;\n this.element.tabIndex = 0;\n if (this.tippy || !editorIsAttached) {\n return;\n }\n this.tippy = tippy(editorElement, {\n duration: 0,\n getReferenceClientRect: null,\n content: this.element,\n interactive: true,\n trigger: 'manual',\n placement: 'right',\n hideOnClick: 'toggle',\n ...this.tippyOptions,\n });\n // maybe we have to hide tippy on its own blur event as well\n if (this.tippy.popper.firstChild) {\n this.tippy.popper.firstChild.addEventListener('blur', this.tippyBlurHandler);\n }\n }\n update(view, oldState) {\n var _a, _b, _c;\n const { state } = view;\n const { doc, selection } = state;\n const { from, to } = selection;\n const isSame = oldState && oldState.doc.eq(doc) && oldState.selection.eq(selection);\n if (isSame) {\n return;\n }\n this.createTooltip();\n const shouldShow = (_a = this.shouldShow) === null || _a === void 0 ? void 0 : _a.call(this, {\n editor: this.editor,\n view,\n state,\n oldState,\n });\n if (!shouldShow) {\n this.hide();\n return;\n }\n (_b = this.tippy) === null || _b === void 0 ? void 0 : _b.setProps({\n getReferenceClientRect: ((_c = this.tippyOptions) === null || _c === void 0 ? void 0 : _c.getReferenceClientRect) || (() => posToDOMRect(view, from, to)),\n });\n this.show();\n }\n show() {\n var _a;\n (_a = this.tippy) === null || _a === void 0 ? void 0 : _a.show();\n }\n hide() {\n var _a;\n (_a = this.tippy) === null || _a === void 0 ? void 0 : _a.hide();\n }\n destroy() {\n var _a, _b;\n if ((_a = this.tippy) === null || _a === void 0 ? void 0 : _a.popper.firstChild) {\n this.tippy.popper.firstChild.removeEventListener('blur', this.tippyBlurHandler);\n }\n (_b = this.tippy) === null || _b === void 0 ? void 0 : _b.destroy();\n this.element.removeEventListener('mousedown', this.mousedownHandler, { capture: true });\n this.editor.off('focus', this.focusHandler);\n this.editor.off('blur', this.blurHandler);\n }\n}\nconst FloatingMenuPlugin = (options) => {\n return new Plugin({\n key: typeof options.pluginKey === 'string' ? new PluginKey(options.pluginKey) : options.pluginKey,\n view: view => new FloatingMenuView({ view, ...options }),\n });\n};\n\n/**\n * This extension allows you to create a floating menu.\n * @see https://tiptap.dev/api/extensions/floating-menu\n */\nconst FloatingMenu = Extension.create({\n name: 'floatingMenu',\n addOptions() {\n return {\n element: null,\n tippyOptions: {},\n pluginKey: 'floatingMenu',\n shouldShow: null,\n };\n },\n addProseMirrorPlugins() {\n if (!this.options.element) {\n return [];\n }\n return [\n FloatingMenuPlugin({\n pluginKey: this.options.pluginKey,\n editor: this.editor,\n element: this.options.element,\n tippyOptions: this.options.tippyOptions,\n shouldShow: this.options.shouldShow,\n }),\n ];\n },\n});\n\nexport { FloatingMenu, FloatingMenuPlugin, FloatingMenuView, FloatingMenu as default };\n//# sourceMappingURL=index.js.map\n","import { BubbleMenuPlugin } from '@tiptap/extension-bubble-menu';\nimport { defineComponent, ref, onMounted, onBeforeUnmount, h, markRaw, customRef, getCurrentInstance, watchEffect, nextTick, unref, shallowRef, reactive, render, provide } from 'vue';\nimport { Editor as Editor$1, NodeView } from '@tiptap/core';\nexport * from '@tiptap/core';\nimport { FloatingMenuPlugin } from '@tiptap/extension-floating-menu';\n\nconst BubbleMenu = defineComponent({\n name: 'BubbleMenu',\n props: {\n pluginKey: {\n type: [String, Object],\n default: 'bubbleMenu',\n },\n editor: {\n type: Object,\n required: true,\n },\n updateDelay: {\n type: Number,\n default: undefined,\n },\n tippyOptions: {\n type: Object,\n default: () => ({}),\n },\n shouldShow: {\n type: Function,\n default: null,\n },\n },\n setup(props, { slots }) {\n const root = ref(null);\n onMounted(() => {\n const { updateDelay, editor, pluginKey, shouldShow, tippyOptions, } = props;\n editor.registerPlugin(BubbleMenuPlugin({\n updateDelay,\n editor,\n element: root.value,\n pluginKey,\n shouldShow,\n tippyOptions,\n }));\n });\n onBeforeUnmount(() => {\n const { pluginKey, editor } = props;\n editor.unregisterPlugin(pluginKey);\n });\n return () => { var _a; return h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };\n },\n});\n\n/* eslint-disable react-hooks/rules-of-hooks */\nfunction useDebouncedRef(value) {\n return customRef((track, trigger) => {\n return {\n get() {\n track();\n return value;\n },\n set(newValue) {\n // update state\n value = newValue;\n // update view as soon as possible\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n trigger();\n });\n });\n },\n };\n });\n}\nclass Editor extends Editor$1 {\n constructor(options = {}) {\n super(options);\n this.contentComponent = null;\n this.appContext = null;\n this.reactiveState = useDebouncedRef(this.view.state);\n this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);\n this.on('beforeTransaction', ({ nextState }) => {\n this.reactiveState.value = nextState;\n this.reactiveExtensionStorage.value = this.extensionStorage;\n });\n return markRaw(this); // eslint-disable-line\n }\n get state() {\n return this.reactiveState ? this.reactiveState.value : this.view.state;\n }\n get storage() {\n return this.reactiveExtensionStorage ? this.reactiveExtensionStorage.value : super.storage;\n }\n /**\n * Register a ProseMirror plugin.\n */\n registerPlugin(plugin, handlePlugins) {\n const nextState = super.registerPlugin(plugin, handlePlugins);\n if (this.reactiveState) {\n this.reactiveState.value = nextState;\n }\n return nextState;\n }\n /**\n * Unregister a ProseMirror plugin.\n */\n unregisterPlugin(nameOrPluginKey) {\n const nextState = super.unregisterPlugin(nameOrPluginKey);\n if (this.reactiveState && nextState) {\n this.reactiveState.value = nextState;\n }\n return nextState;\n }\n}\n\nconst EditorContent = defineComponent({\n name: 'EditorContent',\n props: {\n editor: {\n default: null,\n type: Object,\n },\n },\n setup(props) {\n const rootEl = ref();\n const instance = getCurrentInstance();\n watchEffect(() => {\n const editor = props.editor;\n if (editor && editor.options.element && rootEl.value) {\n nextTick(() => {\n if (!rootEl.value || !editor.options.element.firstChild) {\n return;\n }\n const element = unref(rootEl.value);\n rootEl.value.append(...editor.options.element.childNodes);\n // @ts-ignore\n editor.contentComponent = instance.ctx._;\n if (instance) {\n editor.appContext = {\n ...instance.appContext,\n // Vue internally uses prototype chain to forward/shadow injects across the entire component chain\n // so don't use object spread operator or 'Object.assign' and just set `provides` as is on editor's appContext\n // @ts-expect-error forward instance's 'provides' into appContext\n provides: instance.provides,\n };\n }\n editor.setOptions({\n element,\n });\n editor.createNodeViews();\n });\n }\n });\n onBeforeUnmount(() => {\n const editor = props.editor;\n if (!editor) {\n return;\n }\n editor.contentComponent = null;\n editor.appContext = null;\n });\n return { rootEl };\n },\n render() {\n return h('div', {\n ref: (el) => { this.rootEl = el; },\n });\n },\n});\n\nconst FloatingMenu = defineComponent({\n name: 'FloatingMenu',\n props: {\n pluginKey: {\n // TODO: TypeScript breaks :(\n // type: [String, Object as PropType>],\n type: null,\n default: 'floatingMenu',\n },\n editor: {\n type: Object,\n required: true,\n },\n tippyOptions: {\n type: Object,\n default: () => ({}),\n },\n shouldShow: {\n type: Function,\n default: null,\n },\n },\n setup(props, { slots }) {\n const root = ref(null);\n onMounted(() => {\n const { pluginKey, editor, tippyOptions, shouldShow, } = props;\n editor.registerPlugin(FloatingMenuPlugin({\n pluginKey,\n editor,\n element: root.value,\n tippyOptions,\n shouldShow,\n }));\n });\n onBeforeUnmount(() => {\n const { pluginKey, editor } = props;\n editor.unregisterPlugin(pluginKey);\n });\n return () => { var _a; return h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };\n },\n});\n\nconst NodeViewContent = defineComponent({\n name: 'NodeViewContent',\n props: {\n as: {\n type: String,\n default: 'div',\n },\n },\n render() {\n return h(this.as, {\n style: {\n whiteSpace: 'pre-wrap',\n },\n 'data-node-view-content': '',\n });\n },\n});\n\nconst NodeViewWrapper = defineComponent({\n name: 'NodeViewWrapper',\n props: {\n as: {\n type: String,\n default: 'div',\n },\n },\n inject: ['onDragStart', 'decorationClasses'],\n render() {\n var _a, _b;\n return h(this.as, {\n // @ts-ignore\n class: this.decorationClasses,\n style: {\n whiteSpace: 'normal',\n },\n 'data-node-view-wrapper': '',\n // @ts-ignore (https://github.com/vuejs/vue-next/issues/3031)\n onDragstart: this.onDragStart,\n }, (_b = (_a = this.$slots).default) === null || _b === void 0 ? void 0 : _b.call(_a));\n },\n});\n\nconst useEditor = (options = {}) => {\n const editor = shallowRef();\n onMounted(() => {\n editor.value = new Editor(options);\n });\n onBeforeUnmount(() => {\n var _a, _b, _c;\n // Cloning root node (and its children) to avoid content being lost by destroy\n const nodes = (_a = editor.value) === null || _a === void 0 ? void 0 : _a.options.element;\n const newEl = nodes === null || nodes === void 0 ? void 0 : nodes.cloneNode(true);\n (_b = nodes === null || nodes === void 0 ? void 0 : nodes.parentNode) === null || _b === void 0 ? void 0 : _b.replaceChild(newEl, nodes);\n (_c = editor.value) === null || _c === void 0 ? void 0 : _c.destroy();\n });\n return editor;\n};\n\n/**\n * This class is used to render Vue components inside the editor.\n */\nclass VueRenderer {\n constructor(component, { props = {}, editor }) {\n this.editor = editor;\n this.component = markRaw(component);\n this.el = document.createElement('div');\n this.props = reactive(props);\n this.renderedComponent = this.renderComponent();\n }\n get element() {\n return this.renderedComponent.el;\n }\n get ref() {\n var _a, _b, _c, _d;\n // Composition API\n if ((_b = (_a = this.renderedComponent.vNode) === null || _a === void 0 ? void 0 : _a.component) === null || _b === void 0 ? void 0 : _b.exposed) {\n return this.renderedComponent.vNode.component.exposed;\n }\n // Option API\n return (_d = (_c = this.renderedComponent.vNode) === null || _c === void 0 ? void 0 : _c.component) === null || _d === void 0 ? void 0 : _d.proxy;\n }\n renderComponent() {\n let vNode = h(this.component, this.props);\n if (this.editor.appContext) {\n vNode.appContext = this.editor.appContext;\n }\n if (typeof document !== 'undefined' && this.el) {\n render(vNode, this.el);\n }\n const destroy = () => {\n if (this.el) {\n render(null, this.el);\n }\n this.el = null;\n vNode = null;\n };\n return { vNode, destroy, el: this.el ? this.el.firstElementChild : null };\n }\n updateProps(props = {}) {\n Object.entries(props).forEach(([key, value]) => {\n this.props[key] = value;\n });\n this.renderComponent();\n }\n destroy() {\n this.renderedComponent.destroy();\n }\n}\n\n/* eslint-disable no-underscore-dangle */\nconst nodeViewProps = {\n editor: {\n type: Object,\n required: true,\n },\n node: {\n type: Object,\n required: true,\n },\n decorations: {\n type: Object,\n required: true,\n },\n selected: {\n type: Boolean,\n required: true,\n },\n extension: {\n type: Object,\n required: true,\n },\n getPos: {\n type: Function,\n required: true,\n },\n updateAttributes: {\n type: Function,\n required: true,\n },\n deleteNode: {\n type: Function,\n required: true,\n },\n view: {\n type: Object,\n required: true,\n },\n innerDecorations: {\n type: Object,\n required: true,\n },\n HTMLAttributes: {\n type: Object,\n required: true,\n },\n};\nclass VueNodeView extends NodeView {\n mount() {\n const props = {\n editor: this.editor,\n node: this.node,\n decorations: this.decorations,\n innerDecorations: this.innerDecorations,\n view: this.view,\n selected: false,\n extension: this.extension,\n HTMLAttributes: this.HTMLAttributes,\n getPos: () => this.getPos(),\n updateAttributes: (attributes = {}) => this.updateAttributes(attributes),\n deleteNode: () => this.deleteNode(),\n };\n const onDragStart = this.onDragStart.bind(this);\n this.decorationClasses = ref(this.getDecorationClasses());\n const extendedComponent = defineComponent({\n extends: { ...this.component },\n props: Object.keys(props),\n template: this.component.template,\n setup: reactiveProps => {\n var _a, _b;\n provide('onDragStart', onDragStart);\n provide('decorationClasses', this.decorationClasses);\n return (_b = (_a = this.component).setup) === null || _b === void 0 ? void 0 : _b.call(_a, reactiveProps, {\n expose: () => undefined,\n });\n },\n // add support for scoped styles\n // @ts-ignore\n // eslint-disable-next-line\n __scopeId: this.component.__scopeId,\n // add support for CSS Modules\n // @ts-ignore\n // eslint-disable-next-line\n __cssModules: this.component.__cssModules,\n // add support for vue devtools\n // @ts-ignore\n // eslint-disable-next-line\n __name: this.component.__name,\n // @ts-ignore\n // eslint-disable-next-line\n __file: this.component.__file,\n });\n this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);\n this.editor.on('selectionUpdate', this.handleSelectionUpdate);\n this.renderer = new VueRenderer(extendedComponent, {\n editor: this.editor,\n props,\n });\n }\n /**\n * Return the DOM element.\n * This is the element that will be used to display the node view.\n */\n get dom() {\n if (!this.renderer.element || !this.renderer.element.hasAttribute('data-node-view-wrapper')) {\n throw Error('Please use the NodeViewWrapper component for your node view.');\n }\n return this.renderer.element;\n }\n /**\n * Return the content DOM element.\n * This is the element that will be used to display the rich-text content of the node.\n */\n get contentDOM() {\n if (this.node.isLeaf) {\n return null;\n }\n return this.dom.querySelector('[data-node-view-content]');\n }\n /**\n * On editor selection update, check if the node is selected.\n * If it is, call `selectNode`, otherwise call `deselectNode`.\n */\n handleSelectionUpdate() {\n const { from, to } = this.editor.state.selection;\n const pos = this.getPos();\n if (typeof pos !== 'number') {\n return;\n }\n if (from <= pos && to >= pos + this.node.nodeSize) {\n if (this.renderer.props.selected) {\n return;\n }\n this.selectNode();\n }\n else {\n if (!this.renderer.props.selected) {\n return;\n }\n this.deselectNode();\n }\n }\n /**\n * On update, update the React component.\n * To prevent unnecessary updates, the `update` option can be used.\n */\n update(node, decorations, innerDecorations) {\n const rerenderComponent = (props) => {\n this.decorationClasses.value = this.getDecorationClasses();\n this.renderer.updateProps(props);\n };\n if (typeof this.options.update === 'function') {\n const oldNode = this.node;\n const oldDecorations = this.decorations;\n const oldInnerDecorations = this.innerDecorations;\n this.node = node;\n this.decorations = decorations;\n this.innerDecorations = innerDecorations;\n return this.options.update({\n oldNode,\n oldDecorations,\n newNode: node,\n newDecorations: decorations,\n oldInnerDecorations,\n innerDecorations,\n updateProps: () => rerenderComponent({ node, decorations, innerDecorations }),\n });\n }\n if (node.type !== this.node.type) {\n return false;\n }\n if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {\n return true;\n }\n this.node = node;\n this.decorations = decorations;\n this.innerDecorations = innerDecorations;\n rerenderComponent({ node, decorations, innerDecorations });\n return true;\n }\n /**\n * Select the node.\n * Add the `selected` prop and the `ProseMirror-selectednode` class.\n */\n selectNode() {\n this.renderer.updateProps({\n selected: true,\n });\n if (this.renderer.element) {\n this.renderer.element.classList.add('ProseMirror-selectednode');\n }\n }\n /**\n * Deselect the node.\n * Remove the `selected` prop and the `ProseMirror-selectednode` class.\n */\n deselectNode() {\n this.renderer.updateProps({\n selected: false,\n });\n if (this.renderer.element) {\n this.renderer.element.classList.remove('ProseMirror-selectednode');\n }\n }\n getDecorationClasses() {\n return (this.decorations\n // @ts-ignore\n .map(item => item.type.attrs.class)\n .flat()\n .join(' '));\n }\n destroy() {\n this.renderer.destroy();\n this.editor.off('selectionUpdate', this.handleSelectionUpdate);\n }\n}\nfunction VueNodeViewRenderer(component, options) {\n return props => {\n // try to get the parent component\n // this is important for vue devtools to show the component hierarchy correctly\n // maybe it’s `undefined` because isn’t rendered yet\n if (!props.editor.contentComponent) {\n return {};\n }\n // check for class-component and normalize if neccessary\n const normalizedComponent = typeof component === 'function' && '__vccOpts' in component\n ? component.__vccOpts\n : component;\n return new VueNodeView(normalizedComponent, props, options);\n };\n}\n\nexport { BubbleMenu, Editor, EditorContent, FloatingMenu, NodeViewContent, NodeViewWrapper, VueNodeViewRenderer, VueRenderer, nodeViewProps, useEditor };\n//# sourceMappingURL=index.js.map\n","import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core';\n\n/**\n * Matches a blockquote to a `>` as input.\n */\nconst inputRegex = /^\\s*>\\s$/;\n/**\n * This extension allows you to create blockquotes.\n * @see https://tiptap.dev/api/nodes/blockquote\n */\nconst Blockquote = Node.create({\n name: 'blockquote',\n addOptions() {\n return {\n HTMLAttributes: {},\n };\n },\n content: 'block+',\n group: 'block',\n defining: true,\n parseHTML() {\n return [\n { tag: 'blockquote' },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return ['blockquote', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];\n },\n addCommands() {\n return {\n setBlockquote: () => ({ commands }) => {\n return commands.wrapIn(this.name);\n },\n toggleBlockquote: () => ({ commands }) => {\n return commands.toggleWrap(this.name);\n },\n unsetBlockquote: () => ({ commands }) => {\n return commands.lift(this.name);\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-b': () => this.editor.commands.toggleBlockquote(),\n };\n },\n addInputRules() {\n return [\n wrappingInputRule({\n find: inputRegex,\n type: this.type,\n }),\n ];\n },\n});\n\nexport { Blockquote, Blockquote as default, inputRegex };\n//# sourceMappingURL=index.js.map\n","import { Mark, mergeAttributes, markInputRule, markPasteRule } from '@tiptap/core';\n\n/**\n * Matches bold text via `**` as input.\n */\nconst starInputRegex = /(?:^|\\s)(\\*\\*(?!\\s+\\*\\*)((?:[^*]+))\\*\\*(?!\\s+\\*\\*))$/;\n/**\n * Matches bold text via `**` while pasting.\n */\nconst starPasteRegex = /(?:^|\\s)(\\*\\*(?!\\s+\\*\\*)((?:[^*]+))\\*\\*(?!\\s+\\*\\*))/g;\n/**\n * Matches bold text via `__` as input.\n */\nconst underscoreInputRegex = /(?:^|\\s)(__(?!\\s+__)((?:[^_]+))__(?!\\s+__))$/;\n/**\n * Matches bold text via `__` while pasting.\n */\nconst underscorePasteRegex = /(?:^|\\s)(__(?!\\s+__)((?:[^_]+))__(?!\\s+__))/g;\n/**\n * This extension allows you to mark text as bold.\n * @see https://tiptap.dev/api/marks/bold\n */\nconst Bold = Mark.create({\n name: 'bold',\n addOptions() {\n return {\n HTMLAttributes: {},\n };\n },\n parseHTML() {\n return [\n {\n tag: 'strong',\n },\n {\n tag: 'b',\n getAttrs: node => node.style.fontWeight !== 'normal' && null,\n },\n {\n style: 'font-weight=400',\n clearMark: mark => mark.type.name === this.name,\n },\n {\n style: 'font-weight',\n getAttrs: value => /^(bold(er)?|[5-9]\\d{2,})$/.test(value) && null,\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return ['strong', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];\n },\n addCommands() {\n return {\n setBold: () => ({ commands }) => {\n return commands.setMark(this.name);\n },\n toggleBold: () => ({ commands }) => {\n return commands.toggleMark(this.name);\n },\n unsetBold: () => ({ commands }) => {\n return commands.unsetMark(this.name);\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n 'Mod-b': () => this.editor.commands.toggleBold(),\n 'Mod-B': () => this.editor.commands.toggleBold(),\n };\n },\n addInputRules() {\n return [\n markInputRule({\n find: starInputRegex,\n type: this.type,\n }),\n markInputRule({\n find: underscoreInputRegex,\n type: this.type,\n }),\n ];\n },\n addPasteRules() {\n return [\n markPasteRule({\n find: starPasteRegex,\n type: this.type,\n }),\n markPasteRule({\n find: underscorePasteRegex,\n type: this.type,\n }),\n ];\n },\n});\n\nexport { Bold, Bold as default, starInputRegex, starPasteRegex, underscoreInputRegex, underscorePasteRegex };\n//# sourceMappingURL=index.js.map\n","import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core';\n\nconst ListItemName = 'listItem';\nconst TextStyleName = 'textStyle';\n/**\n * Matches a bullet list to a dash or asterisk.\n */\nconst inputRegex = /^\\s*([-+*])\\s$/;\n/**\n * This extension allows you to create bullet lists.\n * This requires the ListItem extension\n * @see https://tiptap.dev/api/nodes/bullet-list\n * @see https://tiptap.dev/api/nodes/list-item.\n */\nconst BulletList = Node.create({\n name: 'bulletList',\n addOptions() {\n return {\n itemTypeName: 'listItem',\n HTMLAttributes: {},\n keepMarks: false,\n keepAttributes: false,\n };\n },\n group: 'block list',\n content() {\n return `${this.options.itemTypeName}+`;\n },\n parseHTML() {\n return [\n { tag: 'ul' },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];\n },\n addCommands() {\n return {\n toggleBulletList: () => ({ commands, chain }) => {\n if (this.options.keepAttributes) {\n return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();\n }\n return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),\n };\n },\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: inputRegex,\n type: this.type,\n });\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: inputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: () => { return this.editor.getAttributes(TextStyleName); },\n editor: this.editor,\n });\n }\n return [\n inputRule,\n ];\n },\n});\n\nexport { BulletList, BulletList as default, inputRegex };\n//# sourceMappingURL=index.js.map\n","import { Mark, mergeAttributes, markInputRule, markPasteRule } from '@tiptap/core';\n\n/**\n * Regular expressions to match inline code blocks enclosed in backticks.\n * It matches:\n * - An opening backtick, followed by\n * - Any text that doesn't include a backtick (captured for marking), followed by\n * - A closing backtick.\n * This ensures that any text between backticks is formatted as code,\n * regardless of the surrounding characters (exception being another backtick).\n */\nconst inputRegex = /(^|[^`])`([^`]+)`(?!`)/;\n/**\n * Matches inline code while pasting.\n */\nconst pasteRegex = /(^|[^`])`([^`]+)`(?!`)/g;\n/**\n * This extension allows you to mark text as inline code.\n * @see https://tiptap.dev/api/marks/code\n */\nconst Code = Mark.create({\n name: 'code',\n addOptions() {\n return {\n HTMLAttributes: {},\n };\n },\n excludes: '_',\n code: true,\n exitable: true,\n parseHTML() {\n return [\n { tag: 'code' },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return ['code', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];\n },\n addCommands() {\n return {\n setCode: () => ({ commands }) => {\n return commands.setMark(this.name);\n },\n toggleCode: () => ({ commands }) => {\n return commands.toggleMark(this.name);\n },\n unsetCode: () => ({ commands }) => {\n return commands.unsetMark(this.name);\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n 'Mod-e': () => this.editor.commands.toggleCode(),\n };\n },\n addInputRules() {\n return [\n markInputRule({\n find: inputRegex,\n type: this.type,\n }),\n ];\n },\n addPasteRules() {\n return [\n markPasteRule({\n find: pasteRegex,\n type: this.type,\n }),\n ];\n },\n});\n\nexport { Code, Code as default, inputRegex, pasteRegex };\n//# sourceMappingURL=index.js.map\n","import { Node, mergeAttributes, textblockTypeInputRule } from '@tiptap/core';\nimport { Selection, Plugin, PluginKey, TextSelection } from '@tiptap/pm/state';\n\n/**\n * Matches a code block with backticks.\n */\nconst backtickInputRegex = /^```([a-z]+)?[\\s\\n]$/;\n/**\n * Matches a code block with tildes.\n */\nconst tildeInputRegex = /^~~~([a-z]+)?[\\s\\n]$/;\n/**\n * This extension allows you to create code blocks.\n * @see https://tiptap.dev/api/nodes/code-block\n */\nconst CodeBlock = Node.create({\n name: 'codeBlock',\n addOptions() {\n return {\n languageClassPrefix: 'language-',\n exitOnTripleEnter: true,\n exitOnArrowDown: true,\n defaultLanguage: null,\n HTMLAttributes: {},\n };\n },\n content: 'text*',\n marks: '',\n group: 'block',\n code: true,\n defining: true,\n addAttributes() {\n return {\n language: {\n default: this.options.defaultLanguage,\n parseHTML: element => {\n var _a;\n const { languageClassPrefix } = this.options;\n const classNames = [...(((_a = element.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList) || [])];\n const languages = classNames\n .filter(className => className.startsWith(languageClassPrefix))\n .map(className => className.replace(languageClassPrefix, ''));\n const language = languages[0];\n if (!language) {\n return null;\n }\n return language;\n },\n rendered: false,\n },\n };\n },\n parseHTML() {\n return [\n {\n tag: 'pre',\n preserveWhitespace: 'full',\n },\n ];\n },\n renderHTML({ node, HTMLAttributes }) {\n return [\n 'pre',\n mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),\n [\n 'code',\n {\n class: node.attrs.language\n ? this.options.languageClassPrefix + node.attrs.language\n : null,\n },\n 0,\n ],\n ];\n },\n addCommands() {\n return {\n setCodeBlock: attributes => ({ commands }) => {\n return commands.setNode(this.name, attributes);\n },\n toggleCodeBlock: attributes => ({ commands }) => {\n return commands.toggleNode(this.name, 'paragraph', attributes);\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n 'Mod-Alt-c': () => this.editor.commands.toggleCodeBlock(),\n // remove code block when at start of document or code block is empty\n Backspace: () => {\n const { empty, $anchor } = this.editor.state.selection;\n const isAtStart = $anchor.pos === 1;\n if (!empty || $anchor.parent.type.name !== this.name) {\n return false;\n }\n if (isAtStart || !$anchor.parent.textContent.length) {\n return this.editor.commands.clearNodes();\n }\n return false;\n },\n // exit node on triple enter\n Enter: ({ editor }) => {\n if (!this.options.exitOnTripleEnter) {\n return false;\n }\n const { state } = editor;\n const { selection } = state;\n const { $from, empty } = selection;\n if (!empty || $from.parent.type !== this.type) {\n return false;\n }\n const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;\n const endsWithDoubleNewline = $from.parent.textContent.endsWith('\\n\\n');\n if (!isAtEnd || !endsWithDoubleNewline) {\n return false;\n }\n return editor\n .chain()\n .command(({ tr }) => {\n tr.delete($from.pos - 2, $from.pos);\n return true;\n })\n .exitCode()\n .run();\n },\n // exit node on arrow down\n ArrowDown: ({ editor }) => {\n if (!this.options.exitOnArrowDown) {\n return false;\n }\n const { state } = editor;\n const { selection, doc } = state;\n const { $from, empty } = selection;\n if (!empty || $from.parent.type !== this.type) {\n return false;\n }\n const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;\n if (!isAtEnd) {\n return false;\n }\n const after = $from.after();\n if (after === undefined) {\n return false;\n }\n const nodeAfter = doc.nodeAt(after);\n if (nodeAfter) {\n return editor.commands.command(({ tr }) => {\n tr.setSelection(Selection.near(doc.resolve(after)));\n return true;\n });\n }\n return editor.commands.exitCode();\n },\n };\n },\n addInputRules() {\n return [\n textblockTypeInputRule({\n find: backtickInputRegex,\n type: this.type,\n getAttributes: match => ({\n language: match[1],\n }),\n }),\n textblockTypeInputRule({\n find: tildeInputRegex,\n type: this.type,\n getAttributes: match => ({\n language: match[1],\n }),\n }),\n ];\n },\n addProseMirrorPlugins() {\n return [\n // this plugin creates a code block for pasted content from VS Code\n // we can also detect the copied code language\n new Plugin({\n key: new PluginKey('codeBlockVSCodeHandler'),\n props: {\n handlePaste: (view, event) => {\n if (!event.clipboardData) {\n return false;\n }\n // don’t create a new code block within code blocks\n if (this.editor.isActive(this.type.name)) {\n return false;\n }\n const text = event.clipboardData.getData('text/plain');\n const vscode = event.clipboardData.getData('vscode-editor-data');\n const vscodeData = vscode ? JSON.parse(vscode) : undefined;\n const language = vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;\n if (!text || !language) {\n return false;\n }\n const { tr, schema } = view.state;\n // prepare a text node\n // strip carriage return chars from text pasted as code\n // see: https://github.com/ProseMirror/prosemirror-view/commit/a50a6bcceb4ce52ac8fcc6162488d8875613aacd\n const textNode = schema.text(text.replace(/\\r\\n?/g, '\\n'));\n // create a code block with the text node\n // replace selection with the code block\n tr.replaceSelectionWith(this.type.create({ language }, textNode));\n if (tr.selection.$from.parent.type !== this.type) {\n // put cursor inside the newly created code block\n tr.setSelection(TextSelection.near(tr.doc.resolve(Math.max(0, tr.selection.from - 2))));\n }\n // store meta information\n // this is useful for other plugins that depends on the paste event\n // like the paste rule plugin\n tr.setMeta('paste', true);\n view.dispatch(tr);\n return true;\n },\n },\n }),\n ];\n },\n});\n\nexport { CodeBlock, backtickInputRegex, CodeBlock as default, tildeInputRegex };\n//# sourceMappingURL=index.js.map\n","import { Node } from '@tiptap/core';\n\n/**\n * The default document node which represents the top level node of the editor.\n * @see https://tiptap.dev/api/nodes/document\n */\nconst Document = Node.create({\n name: 'doc',\n topNode: true,\n content: 'block+',\n});\n\nexport { Document, Document as default };\n//# sourceMappingURL=index.js.map\n","import { Plugin } from 'prosemirror-state';\nimport { dropPoint } from 'prosemirror-transform';\n\n/**\nCreate a plugin that, when added to a ProseMirror instance,\ncauses a decoration to show up at the drop position when something\nis dragged over the editor.\n\nNodes may add a `disableDropCursor` property to their spec to\ncontrol the showing of a drop cursor inside them. This may be a\nboolean or a function, which will be called with a view and a\nposition, and should return a boolean.\n*/\nfunction dropCursor(options = {}) {\n return new Plugin({\n view(editorView) { return new DropCursorView(editorView, options); }\n });\n}\nclass DropCursorView {\n constructor(editorView, options) {\n var _a;\n this.editorView = editorView;\n this.cursorPos = null;\n this.element = null;\n this.timeout = -1;\n this.width = (_a = options.width) !== null && _a !== void 0 ? _a : 1;\n this.color = options.color === false ? undefined : (options.color || \"black\");\n this.class = options.class;\n this.handlers = [\"dragover\", \"dragend\", \"drop\", \"dragleave\"].map(name => {\n let handler = (e) => { this[name](e); };\n editorView.dom.addEventListener(name, handler);\n return { name, handler };\n });\n }\n destroy() {\n this.handlers.forEach(({ name, handler }) => this.editorView.dom.removeEventListener(name, handler));\n }\n update(editorView, prevState) {\n if (this.cursorPos != null && prevState.doc != editorView.state.doc) {\n if (this.cursorPos > editorView.state.doc.content.size)\n this.setCursor(null);\n else\n this.updateOverlay();\n }\n }\n setCursor(pos) {\n if (pos == this.cursorPos)\n return;\n this.cursorPos = pos;\n if (pos == null) {\n this.element.parentNode.removeChild(this.element);\n this.element = null;\n }\n else {\n this.updateOverlay();\n }\n }\n updateOverlay() {\n let $pos = this.editorView.state.doc.resolve(this.cursorPos);\n let isBlock = !$pos.parent.inlineContent, rect;\n let editorDOM = this.editorView.dom, editorRect = editorDOM.getBoundingClientRect();\n let scaleX = editorRect.width / editorDOM.offsetWidth, scaleY = editorRect.height / editorDOM.offsetHeight;\n if (isBlock) {\n let before = $pos.nodeBefore, after = $pos.nodeAfter;\n if (before || after) {\n let node = this.editorView.nodeDOM(this.cursorPos - (before ? before.nodeSize : 0));\n if (node) {\n let nodeRect = node.getBoundingClientRect();\n let top = before ? nodeRect.bottom : nodeRect.top;\n if (before && after)\n top = (top + this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top) / 2;\n let halfWidth = (this.width / 2) * scaleY;\n rect = { left: nodeRect.left, right: nodeRect.right, top: top - halfWidth, bottom: top + halfWidth };\n }\n }\n }\n if (!rect) {\n let coords = this.editorView.coordsAtPos(this.cursorPos);\n let halfWidth = (this.width / 2) * scaleX;\n rect = { left: coords.left - halfWidth, right: coords.left + halfWidth, top: coords.top, bottom: coords.bottom };\n }\n let parent = this.editorView.dom.offsetParent;\n if (!this.element) {\n this.element = parent.appendChild(document.createElement(\"div\"));\n if (this.class)\n this.element.className = this.class;\n this.element.style.cssText = \"position: absolute; z-index: 50; pointer-events: none;\";\n if (this.color) {\n this.element.style.backgroundColor = this.color;\n }\n }\n this.element.classList.toggle(\"prosemirror-dropcursor-block\", isBlock);\n this.element.classList.toggle(\"prosemirror-dropcursor-inline\", !isBlock);\n let parentLeft, parentTop;\n if (!parent || parent == document.body && getComputedStyle(parent).position == \"static\") {\n parentLeft = -pageXOffset;\n parentTop = -pageYOffset;\n }\n else {\n let rect = parent.getBoundingClientRect();\n let parentScaleX = rect.width / parent.offsetWidth, parentScaleY = rect.height / parent.offsetHeight;\n parentLeft = rect.left - parent.scrollLeft * parentScaleX;\n parentTop = rect.top - parent.scrollTop * parentScaleY;\n }\n this.element.style.left = (rect.left - parentLeft) / scaleX + \"px\";\n this.element.style.top = (rect.top - parentTop) / scaleY + \"px\";\n this.element.style.width = (rect.right - rect.left) / scaleX + \"px\";\n this.element.style.height = (rect.bottom - rect.top) / scaleY + \"px\";\n }\n scheduleRemoval(timeout) {\n clearTimeout(this.timeout);\n this.timeout = setTimeout(() => this.setCursor(null), timeout);\n }\n dragover(event) {\n if (!this.editorView.editable)\n return;\n let pos = this.editorView.posAtCoords({ left: event.clientX, top: event.clientY });\n let node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside);\n let disableDropCursor = node && node.type.spec.disableDropCursor;\n let disabled = typeof disableDropCursor == \"function\"\n ? disableDropCursor(this.editorView, pos, event)\n : disableDropCursor;\n if (pos && !disabled) {\n let target = pos.pos;\n if (this.editorView.dragging && this.editorView.dragging.slice) {\n let point = dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice);\n if (point != null)\n target = point;\n }\n this.setCursor(target);\n this.scheduleRemoval(5000);\n }\n }\n dragend() {\n this.scheduleRemoval(20);\n }\n drop() {\n this.scheduleRemoval(20);\n }\n dragleave(event) {\n if (!this.editorView.dom.contains(event.relatedTarget))\n this.setCursor(null);\n }\n}\n\nexport { dropCursor };\n","import { Extension } from '@tiptap/core';\nimport { dropCursor } from '@tiptap/pm/dropcursor';\n\n/**\n * This extension allows you to add a drop cursor to your editor.\n * A drop cursor is a line that appears when you drag and drop content\n * inbetween nodes.\n * @see https://tiptap.dev/api/extensions/dropcursor\n */\nconst Dropcursor = Extension.create({\n name: 'dropCursor',\n addOptions() {\n return {\n color: 'currentColor',\n width: 1,\n class: undefined,\n };\n },\n addProseMirrorPlugins() {\n return [\n dropCursor(this.options),\n ];\n },\n});\n\nexport { Dropcursor, Dropcursor as default };\n//# sourceMappingURL=index.js.map\n","import { keydownHandler } from 'prosemirror-keymap';\nimport { Selection, NodeSelection, TextSelection, Plugin } from 'prosemirror-state';\nimport { Slice, Fragment } from 'prosemirror-model';\nimport { DecorationSet, Decoration } from 'prosemirror-view';\n\n/**\nGap cursor selections are represented using this class. Its\n`$anchor` and `$head` properties both point at the cursor position.\n*/\nclass GapCursor extends Selection {\n /**\n Create a gap cursor.\n */\n constructor($pos) {\n super($pos, $pos);\n }\n map(doc, mapping) {\n let $pos = doc.resolve(mapping.map(this.head));\n return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos);\n }\n content() { return Slice.empty; }\n eq(other) {\n return other instanceof GapCursor && other.head == this.head;\n }\n toJSON() {\n return { type: \"gapcursor\", pos: this.head };\n }\n /**\n @internal\n */\n static fromJSON(doc, json) {\n if (typeof json.pos != \"number\")\n throw new RangeError(\"Invalid input for GapCursor.fromJSON\");\n return new GapCursor(doc.resolve(json.pos));\n }\n /**\n @internal\n */\n getBookmark() { return new GapBookmark(this.anchor); }\n /**\n @internal\n */\n static valid($pos) {\n let parent = $pos.parent;\n if (parent.isTextblock || !closedBefore($pos) || !closedAfter($pos))\n return false;\n let override = parent.type.spec.allowGapCursor;\n if (override != null)\n return override;\n let deflt = parent.contentMatchAt($pos.index()).defaultType;\n return deflt && deflt.isTextblock;\n }\n /**\n @internal\n */\n static findGapCursorFrom($pos, dir, mustMove = false) {\n search: for (;;) {\n if (!mustMove && GapCursor.valid($pos))\n return $pos;\n let pos = $pos.pos, next = null;\n // Scan up from this position\n for (let d = $pos.depth;; d--) {\n let parent = $pos.node(d);\n if (dir > 0 ? $pos.indexAfter(d) < parent.childCount : $pos.index(d) > 0) {\n next = parent.child(dir > 0 ? $pos.indexAfter(d) : $pos.index(d) - 1);\n break;\n }\n else if (d == 0) {\n return null;\n }\n pos += dir;\n let $cur = $pos.doc.resolve(pos);\n if (GapCursor.valid($cur))\n return $cur;\n }\n // And then down into the next node\n for (;;) {\n let inside = dir > 0 ? next.firstChild : next.lastChild;\n if (!inside) {\n if (next.isAtom && !next.isText && !NodeSelection.isSelectable(next)) {\n $pos = $pos.doc.resolve(pos + next.nodeSize * dir);\n mustMove = false;\n continue search;\n }\n break;\n }\n next = inside;\n pos += dir;\n let $cur = $pos.doc.resolve(pos);\n if (GapCursor.valid($cur))\n return $cur;\n }\n return null;\n }\n }\n}\nGapCursor.prototype.visible = false;\nGapCursor.findFrom = GapCursor.findGapCursorFrom;\nSelection.jsonID(\"gapcursor\", GapCursor);\nclass GapBookmark {\n constructor(pos) {\n this.pos = pos;\n }\n map(mapping) {\n return new GapBookmark(mapping.map(this.pos));\n }\n resolve(doc) {\n let $pos = doc.resolve(this.pos);\n return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos);\n }\n}\nfunction needsGap(type) {\n return type.isAtom || type.spec.isolating || type.spec.createGapCursor;\n}\nfunction closedBefore($pos) {\n for (let d = $pos.depth; d >= 0; d--) {\n let index = $pos.index(d), parent = $pos.node(d);\n // At the start of this parent, look at next one\n if (index == 0) {\n if (parent.type.spec.isolating)\n return true;\n continue;\n }\n // See if the node before (or its first ancestor) is closed\n for (let before = parent.child(index - 1);; before = before.lastChild) {\n if ((before.childCount == 0 && !before.inlineContent) || needsGap(before.type))\n return true;\n if (before.inlineContent)\n return false;\n }\n }\n // Hit start of document\n return true;\n}\nfunction closedAfter($pos) {\n for (let d = $pos.depth; d >= 0; d--) {\n let index = $pos.indexAfter(d), parent = $pos.node(d);\n if (index == parent.childCount) {\n if (parent.type.spec.isolating)\n return true;\n continue;\n }\n for (let after = parent.child(index);; after = after.firstChild) {\n if ((after.childCount == 0 && !after.inlineContent) || needsGap(after.type))\n return true;\n if (after.inlineContent)\n return false;\n }\n }\n return true;\n}\n\n/**\nCreate a gap cursor plugin. When enabled, this will capture clicks\nnear and arrow-key-motion past places that don't have a normally\nselectable position nearby, and create a gap cursor selection for\nthem. The cursor is drawn as an element with class\n`ProseMirror-gapcursor`. You can either include\n`style/gapcursor.css` from the package's directory or add your own\nstyles to make it visible.\n*/\nfunction gapCursor() {\n return new Plugin({\n props: {\n decorations: drawGapCursor,\n createSelectionBetween(_view, $anchor, $head) {\n return $anchor.pos == $head.pos && GapCursor.valid($head) ? new GapCursor($head) : null;\n },\n handleClick,\n handleKeyDown,\n handleDOMEvents: { beforeinput: beforeinput }\n }\n });\n}\nconst handleKeyDown = keydownHandler({\n \"ArrowLeft\": arrow(\"horiz\", -1),\n \"ArrowRight\": arrow(\"horiz\", 1),\n \"ArrowUp\": arrow(\"vert\", -1),\n \"ArrowDown\": arrow(\"vert\", 1)\n});\nfunction arrow(axis, dir) {\n const dirStr = axis == \"vert\" ? (dir > 0 ? \"down\" : \"up\") : (dir > 0 ? \"right\" : \"left\");\n return function (state, dispatch, view) {\n let sel = state.selection;\n let $start = dir > 0 ? sel.$to : sel.$from, mustMove = sel.empty;\n if (sel instanceof TextSelection) {\n if (!view.endOfTextblock(dirStr) || $start.depth == 0)\n return false;\n mustMove = false;\n $start = state.doc.resolve(dir > 0 ? $start.after() : $start.before());\n }\n let $found = GapCursor.findGapCursorFrom($start, dir, mustMove);\n if (!$found)\n return false;\n if (dispatch)\n dispatch(state.tr.setSelection(new GapCursor($found)));\n return true;\n };\n}\nfunction handleClick(view, pos, event) {\n if (!view || !view.editable)\n return false;\n let $pos = view.state.doc.resolve(pos);\n if (!GapCursor.valid($pos))\n return false;\n let clickPos = view.posAtCoords({ left: event.clientX, top: event.clientY });\n if (clickPos && clickPos.inside > -1 && NodeSelection.isSelectable(view.state.doc.nodeAt(clickPos.inside)))\n return false;\n view.dispatch(view.state.tr.setSelection(new GapCursor($pos)));\n return true;\n}\n// This is a hack that, when a composition starts while a gap cursor\n// is active, quickly creates an inline context for the composition to\n// happen in, to avoid it being aborted by the DOM selection being\n// moved into a valid position.\nfunction beforeinput(view, event) {\n if (event.inputType != \"insertCompositionText\" || !(view.state.selection instanceof GapCursor))\n return false;\n let { $from } = view.state.selection;\n let insert = $from.parent.contentMatchAt($from.index()).findWrapping(view.state.schema.nodes.text);\n if (!insert)\n return false;\n let frag = Fragment.empty;\n for (let i = insert.length - 1; i >= 0; i--)\n frag = Fragment.from(insert[i].createAndFill(null, frag));\n let tr = view.state.tr.replace($from.pos, $from.pos, new Slice(frag, 0, 0));\n tr.setSelection(TextSelection.near(tr.doc.resolve($from.pos + 1)));\n view.dispatch(tr);\n return false;\n}\nfunction drawGapCursor(state) {\n if (!(state.selection instanceof GapCursor))\n return null;\n let node = document.createElement(\"div\");\n node.className = \"ProseMirror-gapcursor\";\n return DecorationSet.create(state.doc, [Decoration.widget(state.selection.head, node, { key: \"gapcursor\" })]);\n}\n\nexport { GapCursor, gapCursor };\n","import { Extension, callOrReturn, getExtensionField } from '@tiptap/core';\nimport { gapCursor } from '@tiptap/pm/gapcursor';\n\n/**\n * This extension allows you to add a gap cursor to your editor.\n * A gap cursor is a cursor that appears when you click on a place\n * where no content is present, for example inbetween nodes.\n * @see https://tiptap.dev/api/extensions/gapcursor\n */\nconst Gapcursor = Extension.create({\n name: 'gapCursor',\n addProseMirrorPlugins() {\n return [\n gapCursor(),\n ];\n },\n extendNodeSchema(extension) {\n var _a;\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n };\n return {\n allowGapCursor: (_a = callOrReturn(getExtensionField(extension, 'allowGapCursor', context))) !== null && _a !== void 0 ? _a : null,\n };\n },\n});\n\nexport { Gapcursor, Gapcursor as default };\n//# sourceMappingURL=index.js.map\n","import { Node, mergeAttributes } from '@tiptap/core';\n\n/**\n * This extension allows you to insert hard breaks.\n * @see https://www.tiptap.dev/api/nodes/hard-break\n */\nconst HardBreak = Node.create({\n name: 'hardBreak',\n addOptions() {\n return {\n keepMarks: true,\n HTMLAttributes: {},\n };\n },\n inline: true,\n group: 'inline',\n selectable: false,\n linebreakReplacement: true,\n parseHTML() {\n return [\n { tag: 'br' },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return ['br', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)];\n },\n renderText() {\n return '\\n';\n },\n addCommands() {\n return {\n setHardBreak: () => ({ commands, chain, state, editor, }) => {\n return commands.first([\n () => commands.exitCode(),\n () => commands.command(() => {\n const { selection, storedMarks } = state;\n if (selection.$from.parent.type.spec.isolating) {\n return false;\n }\n const { keepMarks } = this.options;\n const { splittableMarks } = editor.extensionManager;\n const marks = storedMarks\n || (selection.$to.parentOffset && selection.$from.marks());\n return chain()\n .insertContent({ type: this.name })\n .command(({ tr, dispatch }) => {\n if (dispatch && marks && keepMarks) {\n const filteredMarks = marks\n .filter(mark => splittableMarks.includes(mark.type.name));\n tr.ensureMarks(filteredMarks);\n }\n return true;\n })\n .run();\n }),\n ]);\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n 'Mod-Enter': () => this.editor.commands.setHardBreak(),\n 'Shift-Enter': () => this.editor.commands.setHardBreak(),\n };\n },\n});\n\nexport { HardBreak, HardBreak as default };\n//# sourceMappingURL=index.js.map\n","import { Node, mergeAttributes, textblockTypeInputRule } from '@tiptap/core';\n\n/**\n * This extension allows you to create headings.\n * @see https://www.tiptap.dev/api/nodes/heading\n */\nconst Heading = Node.create({\n name: 'heading',\n addOptions() {\n return {\n levels: [1, 2, 3, 4, 5, 6],\n HTMLAttributes: {},\n };\n },\n content: 'inline*',\n group: 'block',\n defining: true,\n addAttributes() {\n return {\n level: {\n default: 1,\n rendered: false,\n },\n };\n },\n parseHTML() {\n return this.options.levels\n .map((level) => ({\n tag: `h${level}`,\n attrs: { level },\n }));\n },\n renderHTML({ node, HTMLAttributes }) {\n const hasLevel = this.options.levels.includes(node.attrs.level);\n const level = hasLevel\n ? node.attrs.level\n : this.options.levels[0];\n return [`h${level}`, mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];\n },\n addCommands() {\n return {\n setHeading: attributes => ({ commands }) => {\n if (!this.options.levels.includes(attributes.level)) {\n return false;\n }\n return commands.setNode(this.name, attributes);\n },\n toggleHeading: attributes => ({ commands }) => {\n if (!this.options.levels.includes(attributes.level)) {\n return false;\n }\n return commands.toggleNode(this.name, 'paragraph', attributes);\n },\n };\n },\n addKeyboardShortcuts() {\n return this.options.levels.reduce((items, level) => ({\n ...items,\n ...{\n [`Mod-Alt-${level}`]: () => this.editor.commands.toggleHeading({ level }),\n },\n }), {});\n },\n addInputRules() {\n return this.options.levels.map(level => {\n return textblockTypeInputRule({\n find: new RegExp(`^(#{${Math.min(...this.options.levels)},${level}})\\\\s$`),\n type: this.type,\n getAttributes: {\n level,\n },\n });\n });\n },\n});\n\nexport { Heading, Heading as default };\n//# sourceMappingURL=index.js.map\n","var GOOD_LEAF_SIZE = 200;\n\n// :: class A rope sequence is a persistent sequence data structure\n// that supports appending, prepending, and slicing without doing a\n// full copy. It is represented as a mostly-balanced tree.\nvar RopeSequence = function RopeSequence () {};\n\nRopeSequence.prototype.append = function append (other) {\n if (!other.length) { return this }\n other = RopeSequence.from(other);\n\n return (!this.length && other) ||\n (other.length < GOOD_LEAF_SIZE && this.leafAppend(other)) ||\n (this.length < GOOD_LEAF_SIZE && other.leafPrepend(this)) ||\n this.appendInner(other)\n};\n\n// :: (union<[T], RopeSequence>) → RopeSequence\n// Prepend an array or other rope to this one, returning a new rope.\nRopeSequence.prototype.prepend = function prepend (other) {\n if (!other.length) { return this }\n return RopeSequence.from(other).append(this)\n};\n\nRopeSequence.prototype.appendInner = function appendInner (other) {\n return new Append(this, other)\n};\n\n// :: (?number, ?number) → RopeSequence\n// Create a rope repesenting a sub-sequence of this rope.\nRopeSequence.prototype.slice = function slice (from, to) {\n if ( from === void 0 ) from = 0;\n if ( to === void 0 ) to = this.length;\n\n if (from >= to) { return RopeSequence.empty }\n return this.sliceInner(Math.max(0, from), Math.min(this.length, to))\n};\n\n// :: (number) → T\n// Retrieve the element at the given position from this rope.\nRopeSequence.prototype.get = function get (i) {\n if (i < 0 || i >= this.length) { return undefined }\n return this.getInner(i)\n};\n\n// :: ((element: T, index: number) → ?bool, ?number, ?number)\n// Call the given function for each element between the given\n// indices. This tends to be more efficient than looping over the\n// indices and calling `get`, because it doesn't have to descend the\n// tree for every element.\nRopeSequence.prototype.forEach = function forEach (f, from, to) {\n if ( from === void 0 ) from = 0;\n if ( to === void 0 ) to = this.length;\n\n if (from <= to)\n { this.forEachInner(f, from, to, 0); }\n else\n { this.forEachInvertedInner(f, from, to, 0); }\n};\n\n// :: ((element: T, index: number) → U, ?number, ?number) → [U]\n// Map the given functions over the elements of the rope, producing\n// a flat array.\nRopeSequence.prototype.map = function map (f, from, to) {\n if ( from === void 0 ) from = 0;\n if ( to === void 0 ) to = this.length;\n\n var result = [];\n this.forEach(function (elt, i) { return result.push(f(elt, i)); }, from, to);\n return result\n};\n\n// :: (?union<[T], RopeSequence>) → RopeSequence\n// Create a rope representing the given array, or return the rope\n// itself if a rope was given.\nRopeSequence.from = function from (values) {\n if (values instanceof RopeSequence) { return values }\n return values && values.length ? new Leaf(values) : RopeSequence.empty\n};\n\nvar Leaf = /*@__PURE__*/(function (RopeSequence) {\n function Leaf(values) {\n RopeSequence.call(this);\n this.values = values;\n }\n\n if ( RopeSequence ) Leaf.__proto__ = RopeSequence;\n Leaf.prototype = Object.create( RopeSequence && RopeSequence.prototype );\n Leaf.prototype.constructor = Leaf;\n\n var prototypeAccessors = { length: { configurable: true },depth: { configurable: true } };\n\n Leaf.prototype.flatten = function flatten () {\n return this.values\n };\n\n Leaf.prototype.sliceInner = function sliceInner (from, to) {\n if (from == 0 && to == this.length) { return this }\n return new Leaf(this.values.slice(from, to))\n };\n\n Leaf.prototype.getInner = function getInner (i) {\n return this.values[i]\n };\n\n Leaf.prototype.forEachInner = function forEachInner (f, from, to, start) {\n for (var i = from; i < to; i++)\n { if (f(this.values[i], start + i) === false) { return false } }\n };\n\n Leaf.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) {\n for (var i = from - 1; i >= to; i--)\n { if (f(this.values[i], start + i) === false) { return false } }\n };\n\n Leaf.prototype.leafAppend = function leafAppend (other) {\n if (this.length + other.length <= GOOD_LEAF_SIZE)\n { return new Leaf(this.values.concat(other.flatten())) }\n };\n\n Leaf.prototype.leafPrepend = function leafPrepend (other) {\n if (this.length + other.length <= GOOD_LEAF_SIZE)\n { return new Leaf(other.flatten().concat(this.values)) }\n };\n\n prototypeAccessors.length.get = function () { return this.values.length };\n\n prototypeAccessors.depth.get = function () { return 0 };\n\n Object.defineProperties( Leaf.prototype, prototypeAccessors );\n\n return Leaf;\n}(RopeSequence));\n\n// :: RopeSequence\n// The empty rope sequence.\nRopeSequence.empty = new Leaf([]);\n\nvar Append = /*@__PURE__*/(function (RopeSequence) {\n function Append(left, right) {\n RopeSequence.call(this);\n this.left = left;\n this.right = right;\n this.length = left.length + right.length;\n this.depth = Math.max(left.depth, right.depth) + 1;\n }\n\n if ( RopeSequence ) Append.__proto__ = RopeSequence;\n Append.prototype = Object.create( RopeSequence && RopeSequence.prototype );\n Append.prototype.constructor = Append;\n\n Append.prototype.flatten = function flatten () {\n return this.left.flatten().concat(this.right.flatten())\n };\n\n Append.prototype.getInner = function getInner (i) {\n return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length)\n };\n\n Append.prototype.forEachInner = function forEachInner (f, from, to, start) {\n var leftLen = this.left.length;\n if (from < leftLen &&\n this.left.forEachInner(f, from, Math.min(to, leftLen), start) === false)\n { return false }\n if (to > leftLen &&\n this.right.forEachInner(f, Math.max(from - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false)\n { return false }\n };\n\n Append.prototype.forEachInvertedInner = function forEachInvertedInner (f, from, to, start) {\n var leftLen = this.left.length;\n if (from > leftLen &&\n this.right.forEachInvertedInner(f, from - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false)\n { return false }\n if (to < leftLen &&\n this.left.forEachInvertedInner(f, Math.min(from, leftLen), to, start) === false)\n { return false }\n };\n\n Append.prototype.sliceInner = function sliceInner (from, to) {\n if (from == 0 && to == this.length) { return this }\n var leftLen = this.left.length;\n if (to <= leftLen) { return this.left.slice(from, to) }\n if (from >= leftLen) { return this.right.slice(from - leftLen, to - leftLen) }\n return this.left.slice(from, leftLen).append(this.right.slice(0, to - leftLen))\n };\n\n Append.prototype.leafAppend = function leafAppend (other) {\n var inner = this.right.leafAppend(other);\n if (inner) { return new Append(this.left, inner) }\n };\n\n Append.prototype.leafPrepend = function leafPrepend (other) {\n var inner = this.left.leafPrepend(other);\n if (inner) { return new Append(inner, this.right) }\n };\n\n Append.prototype.appendInner = function appendInner (other) {\n if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1)\n { return new Append(this.left, new Append(this.right, other)) }\n return new Append(this, other)\n };\n\n return Append;\n}(RopeSequence));\n\nexport default RopeSequence;\n","import RopeSequence from 'rope-sequence';\nimport { Mapping } from 'prosemirror-transform';\nimport { PluginKey, Plugin } from 'prosemirror-state';\n\n// ProseMirror's history isn't simply a way to roll back to a previous\n// state, because ProseMirror supports applying changes without adding\n// them to the history (for example during collaboration).\n//\n// To this end, each 'Branch' (one for the undo history and one for\n// the redo history) keeps an array of 'Items', which can optionally\n// hold a step (an actual undoable change), and always hold a position\n// map (which is needed to move changes below them to apply to the\n// current document).\n//\n// An item that has both a step and a selection bookmark is the start\n// of an 'event' — a group of changes that will be undone or redone at\n// once. (It stores only the bookmark, since that way we don't have to\n// provide a document until the selection is actually applied, which\n// is useful when compressing.)\n// Used to schedule history compression\nconst max_empty_items = 500;\nclass Branch {\n constructor(items, eventCount) {\n this.items = items;\n this.eventCount = eventCount;\n }\n // Pop the latest event off the branch's history and apply it\n // to a document transform.\n popEvent(state, preserveItems) {\n if (this.eventCount == 0)\n return null;\n let end = this.items.length;\n for (;; end--) {\n let next = this.items.get(end - 1);\n if (next.selection) {\n --end;\n break;\n }\n }\n let remap, mapFrom;\n if (preserveItems) {\n remap = this.remapping(end, this.items.length);\n mapFrom = remap.maps.length;\n }\n let transform = state.tr;\n let selection, remaining;\n let addAfter = [], addBefore = [];\n this.items.forEach((item, i) => {\n if (!item.step) {\n if (!remap) {\n remap = this.remapping(end, i + 1);\n mapFrom = remap.maps.length;\n }\n mapFrom--;\n addBefore.push(item);\n return;\n }\n if (remap) {\n addBefore.push(new Item(item.map));\n let step = item.step.map(remap.slice(mapFrom)), map;\n if (step && transform.maybeStep(step).doc) {\n map = transform.mapping.maps[transform.mapping.maps.length - 1];\n addAfter.push(new Item(map, undefined, undefined, addAfter.length + addBefore.length));\n }\n mapFrom--;\n if (map)\n remap.appendMap(map, mapFrom);\n }\n else {\n transform.maybeStep(item.step);\n }\n if (item.selection) {\n selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection;\n remaining = new Branch(this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), this.eventCount - 1);\n return false;\n }\n }, this.items.length, 0);\n return { remaining: remaining, transform, selection: selection };\n }\n // Create a new branch with the given transform added.\n addTransform(transform, selection, histOptions, preserveItems) {\n let newItems = [], eventCount = this.eventCount;\n let oldItems = this.items, lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null;\n for (let i = 0; i < transform.steps.length; i++) {\n let step = transform.steps[i].invert(transform.docs[i]);\n let item = new Item(transform.mapping.maps[i], step, selection), merged;\n if (merged = lastItem && lastItem.merge(item)) {\n item = merged;\n if (i)\n newItems.pop();\n else\n oldItems = oldItems.slice(0, oldItems.length - 1);\n }\n newItems.push(item);\n if (selection) {\n eventCount++;\n selection = undefined;\n }\n if (!preserveItems)\n lastItem = item;\n }\n let overflow = eventCount - histOptions.depth;\n if (overflow > DEPTH_OVERFLOW) {\n oldItems = cutOffEvents(oldItems, overflow);\n eventCount -= overflow;\n }\n return new Branch(oldItems.append(newItems), eventCount);\n }\n remapping(from, to) {\n let maps = new Mapping;\n this.items.forEach((item, i) => {\n let mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from\n ? maps.maps.length - item.mirrorOffset : undefined;\n maps.appendMap(item.map, mirrorPos);\n }, from, to);\n return maps;\n }\n addMaps(array) {\n if (this.eventCount == 0)\n return this;\n return new Branch(this.items.append(array.map(map => new Item(map))), this.eventCount);\n }\n // When the collab module receives remote changes, the history has\n // to know about those, so that it can adjust the steps that were\n // rebased on top of the remote changes, and include the position\n // maps for the remote changes in its array of items.\n rebased(rebasedTransform, rebasedCount) {\n if (!this.eventCount)\n return this;\n let rebasedItems = [], start = Math.max(0, this.items.length - rebasedCount);\n let mapping = rebasedTransform.mapping;\n let newUntil = rebasedTransform.steps.length;\n let eventCount = this.eventCount;\n this.items.forEach(item => { if (item.selection)\n eventCount--; }, start);\n let iRebased = rebasedCount;\n this.items.forEach(item => {\n let pos = mapping.getMirror(--iRebased);\n if (pos == null)\n return;\n newUntil = Math.min(newUntil, pos);\n let map = mapping.maps[pos];\n if (item.step) {\n let step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]);\n let selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos));\n if (selection)\n eventCount++;\n rebasedItems.push(new Item(map, step, selection));\n }\n else {\n rebasedItems.push(new Item(map));\n }\n }, start);\n let newMaps = [];\n for (let i = rebasedCount; i < newUntil; i++)\n newMaps.push(new Item(mapping.maps[i]));\n let items = this.items.slice(0, start).append(newMaps).append(rebasedItems);\n let branch = new Branch(items, eventCount);\n if (branch.emptyItemCount() > max_empty_items)\n branch = branch.compress(this.items.length - rebasedItems.length);\n return branch;\n }\n emptyItemCount() {\n let count = 0;\n this.items.forEach(item => { if (!item.step)\n count++; });\n return count;\n }\n // Compressing a branch means rewriting it to push the air (map-only\n // items) out. During collaboration, these naturally accumulate\n // because each remote change adds one. The `upto` argument is used\n // to ensure that only the items below a given level are compressed,\n // because `rebased` relies on a clean, untouched set of items in\n // order to associate old items with rebased steps.\n compress(upto = this.items.length) {\n let remap = this.remapping(0, upto), mapFrom = remap.maps.length;\n let items = [], events = 0;\n this.items.forEach((item, i) => {\n if (i >= upto) {\n items.push(item);\n if (item.selection)\n events++;\n }\n else if (item.step) {\n let step = item.step.map(remap.slice(mapFrom)), map = step && step.getMap();\n mapFrom--;\n if (map)\n remap.appendMap(map, mapFrom);\n if (step) {\n let selection = item.selection && item.selection.map(remap.slice(mapFrom));\n if (selection)\n events++;\n let newItem = new Item(map.invert(), step, selection), merged, last = items.length - 1;\n if (merged = items.length && items[last].merge(newItem))\n items[last] = merged;\n else\n items.push(newItem);\n }\n }\n else if (item.map) {\n mapFrom--;\n }\n }, this.items.length, 0);\n return new Branch(RopeSequence.from(items.reverse()), events);\n }\n}\nBranch.empty = new Branch(RopeSequence.empty, 0);\nfunction cutOffEvents(items, n) {\n let cutPoint;\n items.forEach((item, i) => {\n if (item.selection && (n-- == 0)) {\n cutPoint = i;\n return false;\n }\n });\n return items.slice(cutPoint);\n}\nclass Item {\n constructor(\n // The (forward) step map for this item.\n map, \n // The inverted step\n step, \n // If this is non-null, this item is the start of a group, and\n // this selection is the starting selection for the group (the one\n // that was active before the first step was applied)\n selection, \n // If this item is the inverse of a previous mapping on the stack,\n // this points at the inverse's offset\n mirrorOffset) {\n this.map = map;\n this.step = step;\n this.selection = selection;\n this.mirrorOffset = mirrorOffset;\n }\n merge(other) {\n if (this.step && other.step && !other.selection) {\n let step = other.step.merge(this.step);\n if (step)\n return new Item(step.getMap().invert(), step, this.selection);\n }\n }\n}\n// The value of the state field that tracks undo/redo history for that\n// state. Will be stored in the plugin state when the history plugin\n// is active.\nclass HistoryState {\n constructor(done, undone, prevRanges, prevTime, prevComposition) {\n this.done = done;\n this.undone = undone;\n this.prevRanges = prevRanges;\n this.prevTime = prevTime;\n this.prevComposition = prevComposition;\n }\n}\nconst DEPTH_OVERFLOW = 20;\n// Record a transformation in undo history.\nfunction applyTransaction(history, state, tr, options) {\n let historyTr = tr.getMeta(historyKey), rebased;\n if (historyTr)\n return historyTr.historyState;\n if (tr.getMeta(closeHistoryKey))\n history = new HistoryState(history.done, history.undone, null, 0, -1);\n let appended = tr.getMeta(\"appendedTransaction\");\n if (tr.steps.length == 0) {\n return history;\n }\n else if (appended && appended.getMeta(historyKey)) {\n if (appended.getMeta(historyKey).redo)\n return new HistoryState(history.done.addTransform(tr, undefined, options, mustPreserveItems(state)), history.undone, rangesFor(tr.mapping.maps), history.prevTime, history.prevComposition);\n else\n return new HistoryState(history.done, history.undone.addTransform(tr, undefined, options, mustPreserveItems(state)), null, history.prevTime, history.prevComposition);\n }\n else if (tr.getMeta(\"addToHistory\") !== false && !(appended && appended.getMeta(\"addToHistory\") === false)) {\n // Group transforms that occur in quick succession into one event.\n let composition = tr.getMeta(\"composition\");\n let newGroup = history.prevTime == 0 ||\n (!appended && history.prevComposition != composition &&\n (history.prevTime < (tr.time || 0) - options.newGroupDelay || !isAdjacentTo(tr, history.prevRanges)));\n let prevRanges = appended ? mapRanges(history.prevRanges, tr.mapping) : rangesFor(tr.mapping.maps);\n return new HistoryState(history.done.addTransform(tr, newGroup ? state.selection.getBookmark() : undefined, options, mustPreserveItems(state)), Branch.empty, prevRanges, tr.time, composition == null ? history.prevComposition : composition);\n }\n else if (rebased = tr.getMeta(\"rebased\")) {\n // Used by the collab module to tell the history that some of its\n // content has been rebased.\n return new HistoryState(history.done.rebased(tr, rebased), history.undone.rebased(tr, rebased), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition);\n }\n else {\n return new HistoryState(history.done.addMaps(tr.mapping.maps), history.undone.addMaps(tr.mapping.maps), mapRanges(history.prevRanges, tr.mapping), history.prevTime, history.prevComposition);\n }\n}\nfunction isAdjacentTo(transform, prevRanges) {\n if (!prevRanges)\n return false;\n if (!transform.docChanged)\n return true;\n let adjacent = false;\n transform.mapping.maps[0].forEach((start, end) => {\n for (let i = 0; i < prevRanges.length; i += 2)\n if (start <= prevRanges[i + 1] && end >= prevRanges[i])\n adjacent = true;\n });\n return adjacent;\n}\nfunction rangesFor(maps) {\n let result = [];\n for (let i = maps.length - 1; i >= 0 && result.length == 0; i--)\n maps[i].forEach((_from, _to, from, to) => result.push(from, to));\n return result;\n}\nfunction mapRanges(ranges, mapping) {\n if (!ranges)\n return null;\n let result = [];\n for (let i = 0; i < ranges.length; i += 2) {\n let from = mapping.map(ranges[i], 1), to = mapping.map(ranges[i + 1], -1);\n if (from <= to)\n result.push(from, to);\n }\n return result;\n}\n// Apply the latest event from one branch to the document and shift the event\n// onto the other branch.\nfunction histTransaction(history, state, redo) {\n let preserveItems = mustPreserveItems(state);\n let histOptions = historyKey.get(state).spec.config;\n let pop = (redo ? history.undone : history.done).popEvent(state, preserveItems);\n if (!pop)\n return null;\n let selection = pop.selection.resolve(pop.transform.doc);\n let added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems);\n let newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0, -1);\n return pop.transform.setSelection(selection).setMeta(historyKey, { redo, historyState: newHist });\n}\nlet cachedPreserveItems = false, cachedPreserveItemsPlugins = null;\n// Check whether any plugin in the given state has a\n// `historyPreserveItems` property in its spec, in which case we must\n// preserve steps exactly as they came in, so that they can be\n// rebased.\nfunction mustPreserveItems(state) {\n let plugins = state.plugins;\n if (cachedPreserveItemsPlugins != plugins) {\n cachedPreserveItems = false;\n cachedPreserveItemsPlugins = plugins;\n for (let i = 0; i < plugins.length; i++)\n if (plugins[i].spec.historyPreserveItems) {\n cachedPreserveItems = true;\n break;\n }\n }\n return cachedPreserveItems;\n}\n/**\nSet a flag on the given transaction that will prevent further steps\nfrom being appended to an existing history event (so that they\nrequire a separate undo command to undo).\n*/\nfunction closeHistory(tr) {\n return tr.setMeta(closeHistoryKey, true);\n}\nconst historyKey = new PluginKey(\"history\");\nconst closeHistoryKey = new PluginKey(\"closeHistory\");\n/**\nReturns a plugin that enables the undo history for an editor. The\nplugin will track undo and redo stacks, which can be used with the\n[`undo`](https://prosemirror.net/docs/ref/#history.undo) and [`redo`](https://prosemirror.net/docs/ref/#history.redo) commands.\n\nYou can set an `\"addToHistory\"` [metadata\nproperty](https://prosemirror.net/docs/ref/#state.Transaction.setMeta) of `false` on a transaction\nto prevent it from being rolled back by undo.\n*/\nfunction history(config = {}) {\n config = { depth: config.depth || 100,\n newGroupDelay: config.newGroupDelay || 500 };\n return new Plugin({\n key: historyKey,\n state: {\n init() {\n return new HistoryState(Branch.empty, Branch.empty, null, 0, -1);\n },\n apply(tr, hist, state) {\n return applyTransaction(hist, state, tr, config);\n }\n },\n config,\n props: {\n handleDOMEvents: {\n beforeinput(view, e) {\n let inputType = e.inputType;\n let command = inputType == \"historyUndo\" ? undo : inputType == \"historyRedo\" ? redo : null;\n if (!command || !view.editable)\n return false;\n e.preventDefault();\n return command(view.state, view.dispatch);\n }\n }\n }\n });\n}\nfunction buildCommand(redo, scroll) {\n return (state, dispatch) => {\n let hist = historyKey.getState(state);\n if (!hist || (redo ? hist.undone : hist.done).eventCount == 0)\n return false;\n if (dispatch) {\n let tr = histTransaction(hist, state, redo);\n if (tr)\n dispatch(scroll ? tr.scrollIntoView() : tr);\n }\n return true;\n };\n}\n/**\nA command function that undoes the last change, if any.\n*/\nconst undo = buildCommand(false, true);\n/**\nA command function that redoes the last undone change, if any.\n*/\nconst redo = buildCommand(true, true);\n/**\nA command function that undoes the last change. Don't scroll the\nselection into view.\n*/\nconst undoNoScroll = buildCommand(false, false);\n/**\nA command function that redoes the last undone change. Don't\nscroll the selection into view.\n*/\nconst redoNoScroll = buildCommand(true, false);\n/**\nThe amount of undoable events available in a given state.\n*/\nfunction undoDepth(state) {\n let hist = historyKey.getState(state);\n return hist ? hist.done.eventCount : 0;\n}\n/**\nThe amount of redoable events available in a given editor state.\n*/\nfunction redoDepth(state) {\n let hist = historyKey.getState(state);\n return hist ? hist.undone.eventCount : 0;\n}\n/**\nReturns true if the given transaction was generated by the history\nplugin.\n*/\nfunction isHistoryTransaction(tr) {\n return tr.getMeta(historyKey) != null;\n}\n\nexport { closeHistory, history, isHistoryTransaction, redo, redoDepth, redoNoScroll, undo, undoDepth, undoNoScroll };\n","import { Extension } from '@tiptap/core';\nimport { undo, redo, history } from '@tiptap/pm/history';\n\n/**\n * This extension allows you to undo and redo recent changes.\n * @see https://www.tiptap.dev/api/extensions/history\n *\n * **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove\n * the `history` extension, as it is not compatible with the `collaboration` extension.\n *\n * `@tiptap/extension-collaboration` uses its own history implementation.\n */\nconst History = Extension.create({\n name: 'history',\n addOptions() {\n return {\n depth: 100,\n newGroupDelay: 500,\n };\n },\n addCommands() {\n return {\n undo: () => ({ state, dispatch }) => {\n return undo(state, dispatch);\n },\n redo: () => ({ state, dispatch }) => {\n return redo(state, dispatch);\n },\n };\n },\n addProseMirrorPlugins() {\n return [\n history(this.options),\n ];\n },\n addKeyboardShortcuts() {\n return {\n 'Mod-z': () => this.editor.commands.undo(),\n 'Shift-Mod-z': () => this.editor.commands.redo(),\n 'Mod-y': () => this.editor.commands.redo(),\n // Russian keyboard layouts\n 'Mod-я': () => this.editor.commands.undo(),\n 'Shift-Mod-я': () => this.editor.commands.redo(),\n };\n },\n});\n\nexport { History, History as default };\n//# sourceMappingURL=index.js.map\n","import { Node, mergeAttributes, canInsertNode, isNodeSelection, nodeInputRule } from '@tiptap/core';\nimport { TextSelection, NodeSelection } from '@tiptap/pm/state';\n\n/**\n * This extension allows you to insert horizontal rules.\n * @see https://www.tiptap.dev/api/nodes/horizontal-rule\n */\nconst HorizontalRule = Node.create({\n name: 'horizontalRule',\n addOptions() {\n return {\n HTMLAttributes: {},\n };\n },\n group: 'block',\n parseHTML() {\n return [{ tag: 'hr' }];\n },\n renderHTML({ HTMLAttributes }) {\n return ['hr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)];\n },\n addCommands() {\n return {\n setHorizontalRule: () => ({ chain, state }) => {\n // Check if we can insert the node at the current selection\n if (!canInsertNode(state, state.schema.nodes[this.name])) {\n return false;\n }\n const { selection } = state;\n const { $from: $originFrom, $to: $originTo } = selection;\n const currentChain = chain();\n if ($originFrom.parentOffset === 0) {\n currentChain.insertContentAt({\n from: Math.max($originFrom.pos - 1, 0),\n to: $originTo.pos,\n }, {\n type: this.name,\n });\n }\n else if (isNodeSelection(selection)) {\n currentChain.insertContentAt($originTo.pos, {\n type: this.name,\n });\n }\n else {\n currentChain.insertContent({ type: this.name });\n }\n return (currentChain\n // set cursor after horizontal rule\n .command(({ tr, dispatch }) => {\n var _a;\n if (dispatch) {\n const { $to } = tr.selection;\n const posAfter = $to.end();\n if ($to.nodeAfter) {\n if ($to.nodeAfter.isTextblock) {\n tr.setSelection(TextSelection.create(tr.doc, $to.pos + 1));\n }\n else if ($to.nodeAfter.isBlock) {\n tr.setSelection(NodeSelection.create(tr.doc, $to.pos));\n }\n else {\n tr.setSelection(TextSelection.create(tr.doc, $to.pos));\n }\n }\n else {\n // add node after horizontal rule if it’s the end of the document\n const node = (_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create();\n if (node) {\n tr.insert(posAfter, node);\n tr.setSelection(TextSelection.create(tr.doc, posAfter + 1));\n }\n }\n tr.scrollIntoView();\n }\n return true;\n })\n .run());\n },\n };\n },\n addInputRules() {\n return [\n nodeInputRule({\n find: /^(?:---|—-|___\\s|\\*\\*\\*\\s)$/,\n type: this.type,\n }),\n ];\n },\n});\n\nexport { HorizontalRule, HorizontalRule as default };\n//# sourceMappingURL=index.js.map\n","import { Mark, mergeAttributes, markInputRule, markPasteRule } from '@tiptap/core';\n\n/**\n * Matches an italic to a *italic* on input.\n */\nconst starInputRegex = /(?:^|\\s)(\\*(?!\\s+\\*)((?:[^*]+))\\*(?!\\s+\\*))$/;\n/**\n * Matches an italic to a *italic* on paste.\n */\nconst starPasteRegex = /(?:^|\\s)(\\*(?!\\s+\\*)((?:[^*]+))\\*(?!\\s+\\*))/g;\n/**\n * Matches an italic to a _italic_ on input.\n */\nconst underscoreInputRegex = /(?:^|\\s)(_(?!\\s+_)((?:[^_]+))_(?!\\s+_))$/;\n/**\n * Matches an italic to a _italic_ on paste.\n */\nconst underscorePasteRegex = /(?:^|\\s)(_(?!\\s+_)((?:[^_]+))_(?!\\s+_))/g;\n/**\n * This extension allows you to create italic text.\n * @see https://www.tiptap.dev/api/marks/italic\n */\nconst Italic = Mark.create({\n name: 'italic',\n addOptions() {\n return {\n HTMLAttributes: {},\n };\n },\n parseHTML() {\n return [\n {\n tag: 'em',\n },\n {\n tag: 'i',\n getAttrs: node => node.style.fontStyle !== 'normal' && null,\n },\n {\n style: 'font-style=normal',\n clearMark: mark => mark.type.name === this.name,\n },\n {\n style: 'font-style=italic',\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return ['em', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];\n },\n addCommands() {\n return {\n setItalic: () => ({ commands }) => {\n return commands.setMark(this.name);\n },\n toggleItalic: () => ({ commands }) => {\n return commands.toggleMark(this.name);\n },\n unsetItalic: () => ({ commands }) => {\n return commands.unsetMark(this.name);\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n 'Mod-i': () => this.editor.commands.toggleItalic(),\n 'Mod-I': () => this.editor.commands.toggleItalic(),\n };\n },\n addInputRules() {\n return [\n markInputRule({\n find: starInputRegex,\n type: this.type,\n }),\n markInputRule({\n find: underscoreInputRegex,\n type: this.type,\n }),\n ];\n },\n addPasteRules() {\n return [\n markPasteRule({\n find: starPasteRegex,\n type: this.type,\n }),\n markPasteRule({\n find: underscorePasteRegex,\n type: this.type,\n }),\n ];\n },\n});\n\nexport { Italic, Italic as default, starInputRegex, starPasteRegex, underscoreInputRegex, underscorePasteRegex };\n//# sourceMappingURL=index.js.map\n","import { Node, mergeAttributes } from '@tiptap/core';\n\n/**\n * This extension allows you to create list items.\n * @see https://www.tiptap.dev/api/nodes/list-item\n */\nconst ListItem = Node.create({\n name: 'listItem',\n addOptions() {\n return {\n HTMLAttributes: {},\n bulletListTypeName: 'bulletList',\n orderedListTypeName: 'orderedList',\n };\n },\n content: 'paragraph block*',\n defining: true,\n parseHTML() {\n return [\n {\n tag: 'li',\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return ['li', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];\n },\n addKeyboardShortcuts() {\n return {\n Enter: () => this.editor.commands.splitListItem(this.name),\n Tab: () => this.editor.commands.sinkListItem(this.name),\n 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),\n };\n },\n});\n\nexport { ListItem, ListItem as default };\n//# sourceMappingURL=index.js.map\n","import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core';\n\nconst ListItemName = 'listItem';\nconst TextStyleName = 'textStyle';\n/**\n * Matches an ordered list to a 1. on input (or any number followed by a dot).\n */\nconst inputRegex = /^(\\d+)\\.\\s$/;\n/**\n * This extension allows you to create ordered lists.\n * This requires the ListItem extension\n * @see https://www.tiptap.dev/api/nodes/ordered-list\n * @see https://www.tiptap.dev/api/nodes/list-item\n */\nconst OrderedList = Node.create({\n name: 'orderedList',\n addOptions() {\n return {\n itemTypeName: 'listItem',\n HTMLAttributes: {},\n keepMarks: false,\n keepAttributes: false,\n };\n },\n group: 'block list',\n content() {\n return `${this.options.itemTypeName}+`;\n },\n addAttributes() {\n return {\n start: {\n default: 1,\n parseHTML: element => {\n return element.hasAttribute('start')\n ? parseInt(element.getAttribute('start') || '', 10)\n : 1;\n },\n },\n type: {\n default: null,\n parseHTML: element => element.getAttribute('type'),\n },\n };\n },\n parseHTML() {\n return [\n {\n tag: 'ol',\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n const { start, ...attributesWithoutStart } = HTMLAttributes;\n return start === 1\n ? ['ol', mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart), 0]\n : ['ol', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];\n },\n addCommands() {\n return {\n toggleOrderedList: () => ({ commands, chain }) => {\n if (this.options.keepAttributes) {\n return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();\n }\n return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-7': () => this.editor.commands.toggleOrderedList(),\n };\n },\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: inputRegex,\n type: this.type,\n getAttributes: match => ({ start: +match[1] }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],\n });\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: inputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],\n editor: this.editor,\n });\n }\n return [\n inputRule,\n ];\n },\n});\n\nexport { OrderedList, OrderedList as default, inputRegex };\n//# sourceMappingURL=index.js.map\n","import { Node, mergeAttributes } from '@tiptap/core';\n\n/**\n * This extension allows you to create paragraphs.\n * @see https://www.tiptap.dev/api/nodes/paragraph\n */\nconst Paragraph = Node.create({\n name: 'paragraph',\n priority: 1000,\n addOptions() {\n return {\n HTMLAttributes: {},\n };\n },\n group: 'block',\n content: 'inline*',\n parseHTML() {\n return [\n { tag: 'p' },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return ['p', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];\n },\n addCommands() {\n return {\n setParagraph: () => ({ commands }) => {\n return commands.setNode(this.name);\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n 'Mod-Alt-0': () => this.editor.commands.setParagraph(),\n };\n },\n});\n\nexport { Paragraph, Paragraph as default };\n//# sourceMappingURL=index.js.map\n","import { Mark, mergeAttributes, markInputRule, markPasteRule } from '@tiptap/core';\n\n/**\n * Matches a strike to a ~~strike~~ on input.\n */\nconst inputRegex = /(?:^|\\s)(~~(?!\\s+~~)((?:[^~]+))~~(?!\\s+~~))$/;\n/**\n * Matches a strike to a ~~strike~~ on paste.\n */\nconst pasteRegex = /(?:^|\\s)(~~(?!\\s+~~)((?:[^~]+))~~(?!\\s+~~))/g;\n/**\n * This extension allows you to create strike text.\n * @see https://www.tiptap.dev/api/marks/strike\n */\nconst Strike = Mark.create({\n name: 'strike',\n addOptions() {\n return {\n HTMLAttributes: {},\n };\n },\n parseHTML() {\n return [\n {\n tag: 's',\n },\n {\n tag: 'del',\n },\n {\n tag: 'strike',\n },\n {\n style: 'text-decoration',\n consuming: false,\n getAttrs: style => (style.includes('line-through') ? {} : false),\n },\n ];\n },\n renderHTML({ HTMLAttributes }) {\n return ['s', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];\n },\n addCommands() {\n return {\n setStrike: () => ({ commands }) => {\n return commands.setMark(this.name);\n },\n toggleStrike: () => ({ commands }) => {\n return commands.toggleMark(this.name);\n },\n unsetStrike: () => ({ commands }) => {\n return commands.unsetMark(this.name);\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-s': () => this.editor.commands.toggleStrike(),\n };\n },\n addInputRules() {\n return [\n markInputRule({\n find: inputRegex,\n type: this.type,\n }),\n ];\n },\n addPasteRules() {\n return [\n markPasteRule({\n find: pasteRegex,\n type: this.type,\n }),\n ];\n },\n});\n\nexport { Strike, Strike as default, inputRegex, pasteRegex };\n//# sourceMappingURL=index.js.map\n","import { Node } from '@tiptap/core';\n\n/**\n * This extension allows you to create text nodes.\n * @see https://www.tiptap.dev/api/nodes/text\n */\nconst Text = Node.create({\n name: 'text',\n group: 'inline',\n});\n\nexport { Text, Text as default };\n//# sourceMappingURL=index.js.map\n","import { Extension } from '@tiptap/core';\nimport { Blockquote } from '@tiptap/extension-blockquote';\nimport { Bold } from '@tiptap/extension-bold';\nimport { BulletList } from '@tiptap/extension-bullet-list';\nimport { Code } from '@tiptap/extension-code';\nimport { CodeBlock } from '@tiptap/extension-code-block';\nimport { Document } from '@tiptap/extension-document';\nimport { Dropcursor } from '@tiptap/extension-dropcursor';\nimport { Gapcursor } from '@tiptap/extension-gapcursor';\nimport { HardBreak } from '@tiptap/extension-hard-break';\nimport { Heading } from '@tiptap/extension-heading';\nimport { History } from '@tiptap/extension-history';\nimport { HorizontalRule } from '@tiptap/extension-horizontal-rule';\nimport { Italic } from '@tiptap/extension-italic';\nimport { ListItem } from '@tiptap/extension-list-item';\nimport { OrderedList } from '@tiptap/extension-ordered-list';\nimport { Paragraph } from '@tiptap/extension-paragraph';\nimport { Strike } from '@tiptap/extension-strike';\nimport { Text } from '@tiptap/extension-text';\n\n/**\n * The starter kit is a collection of essential editor extensions.\n *\n * It’s a good starting point for building your own editor.\n */\nconst StarterKit = Extension.create({\n name: 'starterKit',\n addExtensions() {\n const extensions = [];\n if (this.options.bold !== false) {\n extensions.push(Bold.configure(this.options.bold));\n }\n if (this.options.blockquote !== false) {\n extensions.push(Blockquote.configure(this.options.blockquote));\n }\n if (this.options.bulletList !== false) {\n extensions.push(BulletList.configure(this.options.bulletList));\n }\n if (this.options.code !== false) {\n extensions.push(Code.configure(this.options.code));\n }\n if (this.options.codeBlock !== false) {\n extensions.push(CodeBlock.configure(this.options.codeBlock));\n }\n if (this.options.document !== false) {\n extensions.push(Document.configure(this.options.document));\n }\n if (this.options.dropcursor !== false) {\n extensions.push(Dropcursor.configure(this.options.dropcursor));\n }\n if (this.options.gapcursor !== false) {\n extensions.push(Gapcursor.configure(this.options.gapcursor));\n }\n if (this.options.hardBreak !== false) {\n extensions.push(HardBreak.configure(this.options.hardBreak));\n }\n if (this.options.heading !== false) {\n extensions.push(Heading.configure(this.options.heading));\n }\n if (this.options.history !== false) {\n extensions.push(History.configure(this.options.history));\n }\n if (this.options.horizontalRule !== false) {\n extensions.push(HorizontalRule.configure(this.options.horizontalRule));\n }\n if (this.options.italic !== false) {\n extensions.push(Italic.configure(this.options.italic));\n }\n if (this.options.listItem !== false) {\n extensions.push(ListItem.configure(this.options.listItem));\n }\n if (this.options.orderedList !== false) {\n extensions.push(OrderedList.configure(this.options.orderedList));\n }\n if (this.options.paragraph !== false) {\n extensions.push(Paragraph.configure(this.options.paragraph));\n }\n if (this.options.strike !== false) {\n extensions.push(Strike.configure(this.options.strike));\n }\n if (this.options.text !== false) {\n extensions.push(Text.configure(this.options.text));\n }\n return extensions;\n },\n});\n\nexport { StarterKit, StarterKit as default };\n//# sourceMappingURL=index.js.map\n","// src/index.ts\nimport { Plugin as Plugin2 } from \"prosemirror-state\";\n\n// src/cellselection.ts\nimport { Fragment, Slice } from \"prosemirror-model\";\nimport {\n NodeSelection as NodeSelection2,\n Selection,\n SelectionRange,\n TextSelection\n} from \"prosemirror-state\";\nimport { Decoration, DecorationSet } from \"prosemirror-view\";\n\n// src/tablemap.ts\nvar readFromCache;\nvar addToCache;\nif (typeof WeakMap != \"undefined\") {\n let cache = /* @__PURE__ */ new WeakMap();\n readFromCache = (key) => cache.get(key);\n addToCache = (key, value) => {\n cache.set(key, value);\n return value;\n };\n} else {\n const cache = [];\n const cacheSize = 10;\n let cachePos = 0;\n readFromCache = (key) => {\n for (let i = 0; i < cache.length; i += 2)\n if (cache[i] == key) return cache[i + 1];\n };\n addToCache = (key, value) => {\n if (cachePos == cacheSize) cachePos = 0;\n cache[cachePos++] = key;\n return cache[cachePos++] = value;\n };\n}\nvar TableMap = class {\n constructor(width, height, map, problems) {\n this.width = width;\n this.height = height;\n this.map = map;\n this.problems = problems;\n }\n // Find the dimensions of the cell at the given position.\n findCell(pos) {\n for (let i = 0; i < this.map.length; i++) {\n const curPos = this.map[i];\n if (curPos != pos) continue;\n const left = i % this.width;\n const top = i / this.width | 0;\n let right = left + 1;\n let bottom = top + 1;\n for (let j = 1; right < this.width && this.map[i + j] == curPos; j++) {\n right++;\n }\n for (let j = 1; bottom < this.height && this.map[i + this.width * j] == curPos; j++) {\n bottom++;\n }\n return { left, top, right, bottom };\n }\n throw new RangeError(`No cell with offset ${pos} found`);\n }\n // Find the left side of the cell at the given position.\n colCount(pos) {\n for (let i = 0; i < this.map.length; i++) {\n if (this.map[i] == pos) {\n return i % this.width;\n }\n }\n throw new RangeError(`No cell with offset ${pos} found`);\n }\n // Find the next cell in the given direction, starting from the cell\n // at `pos`, if any.\n nextCell(pos, axis, dir) {\n const { left, right, top, bottom } = this.findCell(pos);\n if (axis == \"horiz\") {\n if (dir < 0 ? left == 0 : right == this.width) return null;\n return this.map[top * this.width + (dir < 0 ? left - 1 : right)];\n } else {\n if (dir < 0 ? top == 0 : bottom == this.height) return null;\n return this.map[left + this.width * (dir < 0 ? top - 1 : bottom)];\n }\n }\n // Get the rectangle spanning the two given cells.\n rectBetween(a, b) {\n const {\n left: leftA,\n right: rightA,\n top: topA,\n bottom: bottomA\n } = this.findCell(a);\n const {\n left: leftB,\n right: rightB,\n top: topB,\n bottom: bottomB\n } = this.findCell(b);\n return {\n left: Math.min(leftA, leftB),\n top: Math.min(topA, topB),\n right: Math.max(rightA, rightB),\n bottom: Math.max(bottomA, bottomB)\n };\n }\n // Return the position of all cells that have the top left corner in\n // the given rectangle.\n cellsInRect(rect) {\n const result = [];\n const seen = {};\n for (let row = rect.top; row < rect.bottom; row++) {\n for (let col = rect.left; col < rect.right; col++) {\n const index = row * this.width + col;\n const pos = this.map[index];\n if (seen[pos]) continue;\n seen[pos] = true;\n if (col == rect.left && col && this.map[index - 1] == pos || row == rect.top && row && this.map[index - this.width] == pos) {\n continue;\n }\n result.push(pos);\n }\n }\n return result;\n }\n // Return the position at which the cell at the given row and column\n // starts, or would start, if a cell started there.\n positionAt(row, col, table) {\n for (let i = 0, rowStart = 0; ; i++) {\n const rowEnd = rowStart + table.child(i).nodeSize;\n if (i == row) {\n let index = col + row * this.width;\n const rowEndIndex = (row + 1) * this.width;\n while (index < rowEndIndex && this.map[index] < rowStart) index++;\n return index == rowEndIndex ? rowEnd - 1 : this.map[index];\n }\n rowStart = rowEnd;\n }\n }\n // Find the table map for the given table node.\n static get(table) {\n return readFromCache(table) || addToCache(table, computeMap(table));\n }\n};\nfunction computeMap(table) {\n if (table.type.spec.tableRole != \"table\")\n throw new RangeError(\"Not a table node: \" + table.type.name);\n const width = findWidth(table), height = table.childCount;\n const map = [];\n let mapPos = 0;\n let problems = null;\n const colWidths = [];\n for (let i = 0, e = width * height; i < e; i++) map[i] = 0;\n for (let row = 0, pos = 0; row < height; row++) {\n const rowNode = table.child(row);\n pos++;\n for (let i = 0; ; i++) {\n while (mapPos < map.length && map[mapPos] != 0) mapPos++;\n if (i == rowNode.childCount) break;\n const cellNode = rowNode.child(i);\n const { colspan, rowspan, colwidth } = cellNode.attrs;\n for (let h = 0; h < rowspan; h++) {\n if (h + row >= height) {\n (problems || (problems = [])).push({\n type: \"overlong_rowspan\",\n pos,\n n: rowspan - h\n });\n break;\n }\n const start = mapPos + h * width;\n for (let w = 0; w < colspan; w++) {\n if (map[start + w] == 0) map[start + w] = pos;\n else\n (problems || (problems = [])).push({\n type: \"collision\",\n row,\n pos,\n n: colspan - w\n });\n const colW = colwidth && colwidth[w];\n if (colW) {\n const widthIndex = (start + w) % width * 2, prev = colWidths[widthIndex];\n if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) {\n colWidths[widthIndex] = colW;\n colWidths[widthIndex + 1] = 1;\n } else if (prev == colW) {\n colWidths[widthIndex + 1]++;\n }\n }\n }\n }\n mapPos += colspan;\n pos += cellNode.nodeSize;\n }\n const expectedPos = (row + 1) * width;\n let missing = 0;\n while (mapPos < expectedPos) if (map[mapPos++] == 0) missing++;\n if (missing)\n (problems || (problems = [])).push({ type: \"missing\", row, n: missing });\n pos++;\n }\n if (width === 0 || height === 0)\n (problems || (problems = [])).push({ type: \"zero_sized\" });\n const tableMap = new TableMap(width, height, map, problems);\n let badWidths = false;\n for (let i = 0; !badWidths && i < colWidths.length; i += 2)\n if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true;\n if (badWidths) findBadColWidths(tableMap, colWidths, table);\n return tableMap;\n}\nfunction findWidth(table) {\n let width = -1;\n let hasRowSpan = false;\n for (let row = 0; row < table.childCount; row++) {\n const rowNode = table.child(row);\n let rowWidth = 0;\n if (hasRowSpan)\n for (let j = 0; j < row; j++) {\n const prevRow = table.child(j);\n for (let i = 0; i < prevRow.childCount; i++) {\n const cell = prevRow.child(i);\n if (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan;\n }\n }\n for (let i = 0; i < rowNode.childCount; i++) {\n const cell = rowNode.child(i);\n rowWidth += cell.attrs.colspan;\n if (cell.attrs.rowspan > 1) hasRowSpan = true;\n }\n if (width == -1) width = rowWidth;\n else if (width != rowWidth) width = Math.max(width, rowWidth);\n }\n return width;\n}\nfunction findBadColWidths(map, colWidths, table) {\n if (!map.problems) map.problems = [];\n const seen = {};\n for (let i = 0; i < map.map.length; i++) {\n const pos = map.map[i];\n if (seen[pos]) continue;\n seen[pos] = true;\n const node = table.nodeAt(pos);\n if (!node) {\n throw new RangeError(`No cell with offset ${pos} found`);\n }\n let updated = null;\n const attrs = node.attrs;\n for (let j = 0; j < attrs.colspan; j++) {\n const col = (i + j) % map.width;\n const colWidth = colWidths[col * 2];\n if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth))\n (updated || (updated = freshColWidth(attrs)))[j] = colWidth;\n }\n if (updated)\n map.problems.unshift({\n type: \"colwidth mismatch\",\n pos,\n colwidth: updated\n });\n }\n}\nfunction freshColWidth(attrs) {\n if (attrs.colwidth) return attrs.colwidth.slice();\n const result = [];\n for (let i = 0; i < attrs.colspan; i++) result.push(0);\n return result;\n}\n\n// src/util.ts\nimport { PluginKey } from \"prosemirror-state\";\n\n// src/schema.ts\nfunction getCellAttrs(dom, extraAttrs) {\n if (typeof dom === \"string\") {\n return {};\n }\n const widthAttr = dom.getAttribute(\"data-colwidth\");\n const widths = widthAttr && /^\\d+(,\\d+)*$/.test(widthAttr) ? widthAttr.split(\",\").map((s) => Number(s)) : null;\n const colspan = Number(dom.getAttribute(\"colspan\") || 1);\n const result = {\n colspan,\n rowspan: Number(dom.getAttribute(\"rowspan\") || 1),\n colwidth: widths && widths.length == colspan ? widths : null\n };\n for (const prop in extraAttrs) {\n const getter = extraAttrs[prop].getFromDOM;\n const value = getter && getter(dom);\n if (value != null) {\n result[prop] = value;\n }\n }\n return result;\n}\nfunction setCellAttrs(node, extraAttrs) {\n const attrs = {};\n if (node.attrs.colspan != 1) attrs.colspan = node.attrs.colspan;\n if (node.attrs.rowspan != 1) attrs.rowspan = node.attrs.rowspan;\n if (node.attrs.colwidth)\n attrs[\"data-colwidth\"] = node.attrs.colwidth.join(\",\");\n for (const prop in extraAttrs) {\n const setter = extraAttrs[prop].setDOMAttr;\n if (setter) setter(node.attrs[prop], attrs);\n }\n return attrs;\n}\nfunction validateColwidth(value) {\n if (value === null) {\n return;\n }\n if (!Array.isArray(value)) {\n throw new TypeError(\"colwidth must be null or an array\");\n }\n for (const item of value) {\n if (typeof item !== \"number\") {\n throw new TypeError(\"colwidth must be null or an array of numbers\");\n }\n }\n}\nfunction tableNodes(options) {\n const extraAttrs = options.cellAttributes || {};\n const cellAttrs = {\n colspan: { default: 1, validate: \"number\" },\n rowspan: { default: 1, validate: \"number\" },\n colwidth: { default: null, validate: validateColwidth }\n };\n for (const prop in extraAttrs)\n cellAttrs[prop] = {\n default: extraAttrs[prop].default,\n validate: extraAttrs[prop].validate\n };\n return {\n table: {\n content: \"table_row+\",\n tableRole: \"table\",\n isolating: true,\n group: options.tableGroup,\n parseDOM: [{ tag: \"table\" }],\n toDOM() {\n return [\"table\", [\"tbody\", 0]];\n }\n },\n table_row: {\n content: \"(table_cell | table_header)*\",\n tableRole: \"row\",\n parseDOM: [{ tag: \"tr\" }],\n toDOM() {\n return [\"tr\", 0];\n }\n },\n table_cell: {\n content: options.cellContent,\n attrs: cellAttrs,\n tableRole: \"cell\",\n isolating: true,\n parseDOM: [\n { tag: \"td\", getAttrs: (dom) => getCellAttrs(dom, extraAttrs) }\n ],\n toDOM(node) {\n return [\"td\", setCellAttrs(node, extraAttrs), 0];\n }\n },\n table_header: {\n content: options.cellContent,\n attrs: cellAttrs,\n tableRole: \"header_cell\",\n isolating: true,\n parseDOM: [\n { tag: \"th\", getAttrs: (dom) => getCellAttrs(dom, extraAttrs) }\n ],\n toDOM(node) {\n return [\"th\", setCellAttrs(node, extraAttrs), 0];\n }\n }\n };\n}\nfunction tableNodeTypes(schema) {\n let result = schema.cached.tableNodeTypes;\n if (!result) {\n result = schema.cached.tableNodeTypes = {};\n for (const name in schema.nodes) {\n const type = schema.nodes[name], role = type.spec.tableRole;\n if (role) result[role] = type;\n }\n }\n return result;\n}\n\n// src/util.ts\nvar tableEditingKey = new PluginKey(\"selectingCells\");\nfunction cellAround($pos) {\n for (let d = $pos.depth - 1; d > 0; d--)\n if ($pos.node(d).type.spec.tableRole == \"row\")\n return $pos.node(0).resolve($pos.before(d + 1));\n return null;\n}\nfunction cellWrapping($pos) {\n for (let d = $pos.depth; d > 0; d--) {\n const role = $pos.node(d).type.spec.tableRole;\n if (role === \"cell\" || role === \"header_cell\") return $pos.node(d);\n }\n return null;\n}\nfunction isInTable(state) {\n const $head = state.selection.$head;\n for (let d = $head.depth; d > 0; d--)\n if ($head.node(d).type.spec.tableRole == \"row\") return true;\n return false;\n}\nfunction selectionCell(state) {\n const sel = state.selection;\n if (\"$anchorCell\" in sel && sel.$anchorCell) {\n return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;\n } else if (\"node\" in sel && sel.node && sel.node.type.spec.tableRole == \"cell\") {\n return sel.$anchor;\n }\n const $cell = cellAround(sel.$head) || cellNear(sel.$head);\n if ($cell) {\n return $cell;\n }\n throw new RangeError(`No cell found around position ${sel.head}`);\n}\nfunction cellNear($pos) {\n for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {\n const role = after.type.spec.tableRole;\n if (role == \"cell\" || role == \"header_cell\") return $pos.doc.resolve(pos);\n }\n for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {\n const role = before.type.spec.tableRole;\n if (role == \"cell\" || role == \"header_cell\")\n return $pos.doc.resolve(pos - before.nodeSize);\n }\n}\nfunction pointsAtCell($pos) {\n return $pos.parent.type.spec.tableRole == \"row\" && !!$pos.nodeAfter;\n}\nfunction moveCellForward($pos) {\n return $pos.node(0).resolve($pos.pos + $pos.nodeAfter.nodeSize);\n}\nfunction inSameTable($cellA, $cellB) {\n return $cellA.depth == $cellB.depth && $cellA.pos >= $cellB.start(-1) && $cellA.pos <= $cellB.end(-1);\n}\nfunction findCell($pos) {\n return TableMap.get($pos.node(-1)).findCell($pos.pos - $pos.start(-1));\n}\nfunction colCount($pos) {\n return TableMap.get($pos.node(-1)).colCount($pos.pos - $pos.start(-1));\n}\nfunction nextCell($pos, axis, dir) {\n const table = $pos.node(-1);\n const map = TableMap.get(table);\n const tableStart = $pos.start(-1);\n const moved = map.nextCell($pos.pos - tableStart, axis, dir);\n return moved == null ? null : $pos.node(0).resolve(tableStart + moved);\n}\nfunction removeColSpan(attrs, pos, n = 1) {\n const result = { ...attrs, colspan: attrs.colspan - n };\n if (result.colwidth) {\n result.colwidth = result.colwidth.slice();\n result.colwidth.splice(pos, n);\n if (!result.colwidth.some((w) => w > 0)) result.colwidth = null;\n }\n return result;\n}\nfunction addColSpan(attrs, pos, n = 1) {\n const result = { ...attrs, colspan: attrs.colspan + n };\n if (result.colwidth) {\n result.colwidth = result.colwidth.slice();\n for (let i = 0; i < n; i++) result.colwidth.splice(pos, 0, 0);\n }\n return result;\n}\nfunction columnIsHeader(map, table, col) {\n const headerCell = tableNodeTypes(table.type.schema).header_cell;\n for (let row = 0; row < map.height; row++)\n if (table.nodeAt(map.map[col + row * map.width]).type != headerCell)\n return false;\n return true;\n}\n\n// src/cellselection.ts\nvar CellSelection = class _CellSelection extends Selection {\n // A table selection is identified by its anchor and head cells. The\n // positions given to this constructor should point _before_ two\n // cells in the same table. They may be the same, to select a single\n // cell.\n constructor($anchorCell, $headCell = $anchorCell) {\n const table = $anchorCell.node(-1);\n const map = TableMap.get(table);\n const tableStart = $anchorCell.start(-1);\n const rect = map.rectBetween(\n $anchorCell.pos - tableStart,\n $headCell.pos - tableStart\n );\n const doc = $anchorCell.node(0);\n const cells = map.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart);\n cells.unshift($headCell.pos - tableStart);\n const ranges = cells.map((pos) => {\n const cell = table.nodeAt(pos);\n if (!cell) {\n throw RangeError(`No cell with offset ${pos} found`);\n }\n const from = tableStart + pos + 1;\n return new SelectionRange(\n doc.resolve(from),\n doc.resolve(from + cell.content.size)\n );\n });\n super(ranges[0].$from, ranges[0].$to, ranges);\n this.$anchorCell = $anchorCell;\n this.$headCell = $headCell;\n }\n map(doc, mapping) {\n const $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos));\n const $headCell = doc.resolve(mapping.map(this.$headCell.pos));\n if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) {\n const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1);\n if (tableChanged && this.isRowSelection())\n return _CellSelection.rowSelection($anchorCell, $headCell);\n else if (tableChanged && this.isColSelection())\n return _CellSelection.colSelection($anchorCell, $headCell);\n else return new _CellSelection($anchorCell, $headCell);\n }\n return TextSelection.between($anchorCell, $headCell);\n }\n // Returns a rectangular slice of table rows containing the selected\n // cells.\n content() {\n const table = this.$anchorCell.node(-1);\n const map = TableMap.get(table);\n const tableStart = this.$anchorCell.start(-1);\n const rect = map.rectBetween(\n this.$anchorCell.pos - tableStart,\n this.$headCell.pos - tableStart\n );\n const seen = {};\n const rows = [];\n for (let row = rect.top; row < rect.bottom; row++) {\n const rowContent = [];\n for (let index = row * map.width + rect.left, col = rect.left; col < rect.right; col++, index++) {\n const pos = map.map[index];\n if (seen[pos]) continue;\n seen[pos] = true;\n const cellRect = map.findCell(pos);\n let cell = table.nodeAt(pos);\n if (!cell) {\n throw RangeError(`No cell with offset ${pos} found`);\n }\n const extraLeft = rect.left - cellRect.left;\n const extraRight = cellRect.right - rect.right;\n if (extraLeft > 0 || extraRight > 0) {\n let attrs = cell.attrs;\n if (extraLeft > 0) {\n attrs = removeColSpan(attrs, 0, extraLeft);\n }\n if (extraRight > 0) {\n attrs = removeColSpan(\n attrs,\n attrs.colspan - extraRight,\n extraRight\n );\n }\n if (cellRect.left < rect.left) {\n cell = cell.type.createAndFill(attrs);\n if (!cell) {\n throw RangeError(\n `Could not create cell with attrs ${JSON.stringify(attrs)}`\n );\n }\n } else {\n cell = cell.type.create(attrs, cell.content);\n }\n }\n if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) {\n const attrs = {\n ...cell.attrs,\n rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top)\n };\n if (cellRect.top < rect.top) {\n cell = cell.type.createAndFill(attrs);\n } else {\n cell = cell.type.create(attrs, cell.content);\n }\n }\n rowContent.push(cell);\n }\n rows.push(table.child(row).copy(Fragment.from(rowContent)));\n }\n const fragment = this.isColSelection() && this.isRowSelection() ? table : rows;\n return new Slice(Fragment.from(fragment), 1, 1);\n }\n replace(tr, content = Slice.empty) {\n const mapFrom = tr.steps.length, ranges = this.ranges;\n for (let i = 0; i < ranges.length; i++) {\n const { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);\n tr.replace(\n mapping.map($from.pos),\n mapping.map($to.pos),\n i ? Slice.empty : content\n );\n }\n const sel = Selection.findFrom(\n tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)),\n -1\n );\n if (sel) tr.setSelection(sel);\n }\n replaceWith(tr, node) {\n this.replace(tr, new Slice(Fragment.from(node), 0, 0));\n }\n forEachCell(f) {\n const table = this.$anchorCell.node(-1);\n const map = TableMap.get(table);\n const tableStart = this.$anchorCell.start(-1);\n const cells = map.cellsInRect(\n map.rectBetween(\n this.$anchorCell.pos - tableStart,\n this.$headCell.pos - tableStart\n )\n );\n for (let i = 0; i < cells.length; i++) {\n f(table.nodeAt(cells[i]), tableStart + cells[i]);\n }\n }\n // True if this selection goes all the way from the top to the\n // bottom of the table.\n isColSelection() {\n const anchorTop = this.$anchorCell.index(-1);\n const headTop = this.$headCell.index(-1);\n if (Math.min(anchorTop, headTop) > 0) return false;\n const anchorBottom = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan;\n const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan;\n return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount;\n }\n // Returns the smallest column selection that covers the given anchor\n // and head cell.\n static colSelection($anchorCell, $headCell = $anchorCell) {\n const table = $anchorCell.node(-1);\n const map = TableMap.get(table);\n const tableStart = $anchorCell.start(-1);\n const anchorRect = map.findCell($anchorCell.pos - tableStart);\n const headRect = map.findCell($headCell.pos - tableStart);\n const doc = $anchorCell.node(0);\n if (anchorRect.top <= headRect.top) {\n if (anchorRect.top > 0)\n $anchorCell = doc.resolve(tableStart + map.map[anchorRect.left]);\n if (headRect.bottom < map.height)\n $headCell = doc.resolve(\n tableStart + map.map[map.width * (map.height - 1) + headRect.right - 1]\n );\n } else {\n if (headRect.top > 0)\n $headCell = doc.resolve(tableStart + map.map[headRect.left]);\n if (anchorRect.bottom < map.height)\n $anchorCell = doc.resolve(\n tableStart + map.map[map.width * (map.height - 1) + anchorRect.right - 1]\n );\n }\n return new _CellSelection($anchorCell, $headCell);\n }\n // True if this selection goes all the way from the left to the\n // right of the table.\n isRowSelection() {\n const table = this.$anchorCell.node(-1);\n const map = TableMap.get(table);\n const tableStart = this.$anchorCell.start(-1);\n const anchorLeft = map.colCount(this.$anchorCell.pos - tableStart);\n const headLeft = map.colCount(this.$headCell.pos - tableStart);\n if (Math.min(anchorLeft, headLeft) > 0) return false;\n const anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan;\n const headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan;\n return Math.max(anchorRight, headRight) == map.width;\n }\n eq(other) {\n return other instanceof _CellSelection && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos;\n }\n // Returns the smallest row selection that covers the given anchor\n // and head cell.\n static rowSelection($anchorCell, $headCell = $anchorCell) {\n const table = $anchorCell.node(-1);\n const map = TableMap.get(table);\n const tableStart = $anchorCell.start(-1);\n const anchorRect = map.findCell($anchorCell.pos - tableStart);\n const headRect = map.findCell($headCell.pos - tableStart);\n const doc = $anchorCell.node(0);\n if (anchorRect.left <= headRect.left) {\n if (anchorRect.left > 0)\n $anchorCell = doc.resolve(\n tableStart + map.map[anchorRect.top * map.width]\n );\n if (headRect.right < map.width)\n $headCell = doc.resolve(\n tableStart + map.map[map.width * (headRect.top + 1) - 1]\n );\n } else {\n if (headRect.left > 0)\n $headCell = doc.resolve(tableStart + map.map[headRect.top * map.width]);\n if (anchorRect.right < map.width)\n $anchorCell = doc.resolve(\n tableStart + map.map[map.width * (anchorRect.top + 1) - 1]\n );\n }\n return new _CellSelection($anchorCell, $headCell);\n }\n toJSON() {\n return {\n type: \"cell\",\n anchor: this.$anchorCell.pos,\n head: this.$headCell.pos\n };\n }\n static fromJSON(doc, json) {\n return new _CellSelection(doc.resolve(json.anchor), doc.resolve(json.head));\n }\n static create(doc, anchorCell, headCell = anchorCell) {\n return new _CellSelection(doc.resolve(anchorCell), doc.resolve(headCell));\n }\n getBookmark() {\n return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos);\n }\n};\nCellSelection.prototype.visible = false;\nSelection.jsonID(\"cell\", CellSelection);\nvar CellBookmark = class _CellBookmark {\n constructor(anchor, head) {\n this.anchor = anchor;\n this.head = head;\n }\n map(mapping) {\n return new _CellBookmark(mapping.map(this.anchor), mapping.map(this.head));\n }\n resolve(doc) {\n const $anchorCell = doc.resolve(this.anchor), $headCell = doc.resolve(this.head);\n if ($anchorCell.parent.type.spec.tableRole == \"row\" && $headCell.parent.type.spec.tableRole == \"row\" && $anchorCell.index() < $anchorCell.parent.childCount && $headCell.index() < $headCell.parent.childCount && inSameTable($anchorCell, $headCell))\n return new CellSelection($anchorCell, $headCell);\n else return Selection.near($headCell, 1);\n }\n};\nfunction drawCellSelection(state) {\n if (!(state.selection instanceof CellSelection)) return null;\n const cells = [];\n state.selection.forEachCell((node, pos) => {\n cells.push(\n Decoration.node(pos, pos + node.nodeSize, { class: \"selectedCell\" })\n );\n });\n return DecorationSet.create(state.doc, cells);\n}\nfunction isCellBoundarySelection({ $from, $to }) {\n if ($from.pos == $to.pos || $from.pos < $to.pos - 6) return false;\n let afterFrom = $from.pos;\n let beforeTo = $to.pos;\n let depth = $from.depth;\n for (; depth >= 0; depth--, afterFrom++)\n if ($from.after(depth + 1) < $from.end(depth)) break;\n for (let d = $to.depth; d >= 0; d--, beforeTo--)\n if ($to.before(d + 1) > $to.start(d)) break;\n return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole);\n}\nfunction isTextSelectionAcrossCells({ $from, $to }) {\n let fromCellBoundaryNode;\n let toCellBoundaryNode;\n for (let i = $from.depth; i > 0; i--) {\n const node = $from.node(i);\n if (node.type.spec.tableRole === \"cell\" || node.type.spec.tableRole === \"header_cell\") {\n fromCellBoundaryNode = node;\n break;\n }\n }\n for (let i = $to.depth; i > 0; i--) {\n const node = $to.node(i);\n if (node.type.spec.tableRole === \"cell\" || node.type.spec.tableRole === \"header_cell\") {\n toCellBoundaryNode = node;\n break;\n }\n }\n return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;\n}\nfunction normalizeSelection(state, tr, allowTableNodeSelection) {\n const sel = (tr || state).selection;\n const doc = (tr || state).doc;\n let normalize;\n let role;\n if (sel instanceof NodeSelection2 && (role = sel.node.type.spec.tableRole)) {\n if (role == \"cell\" || role == \"header_cell\") {\n normalize = CellSelection.create(doc, sel.from);\n } else if (role == \"row\") {\n const $cell = doc.resolve(sel.from + 1);\n normalize = CellSelection.rowSelection($cell, $cell);\n } else if (!allowTableNodeSelection) {\n const map = TableMap.get(sel.node);\n const start = sel.from + 1;\n const lastCell = start + map.map[map.width * map.height - 1];\n normalize = CellSelection.create(doc, start + 1, lastCell);\n }\n } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) {\n normalize = TextSelection.create(doc, sel.from);\n } else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {\n normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());\n }\n if (normalize) (tr || (tr = state.tr)).setSelection(normalize);\n return tr;\n}\n\n// src/fixtables.ts\nimport { PluginKey as PluginKey2 } from \"prosemirror-state\";\nvar fixTablesKey = new PluginKey2(\"fix-tables\");\nfunction changedDescendants(old, cur, offset, f) {\n const oldSize = old.childCount, curSize = cur.childCount;\n outer: for (let i = 0, j = 0; i < curSize; i++) {\n const child = cur.child(i);\n for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {\n if (old.child(scan) == child) {\n j = scan + 1;\n offset += child.nodeSize;\n continue outer;\n }\n }\n f(child, offset);\n if (j < oldSize && old.child(j).sameMarkup(child))\n changedDescendants(old.child(j), child, offset + 1, f);\n else child.nodesBetween(0, child.content.size, f, offset + 1);\n offset += child.nodeSize;\n }\n}\nfunction fixTables(state, oldState) {\n let tr;\n const check = (node, pos) => {\n if (node.type.spec.tableRole == \"table\")\n tr = fixTable(state, node, pos, tr);\n };\n if (!oldState) state.doc.descendants(check);\n else if (oldState.doc != state.doc)\n changedDescendants(oldState.doc, state.doc, 0, check);\n return tr;\n}\nfunction fixTable(state, table, tablePos, tr) {\n const map = TableMap.get(table);\n if (!map.problems) return tr;\n if (!tr) tr = state.tr;\n const mustAdd = [];\n for (let i = 0; i < map.height; i++) mustAdd.push(0);\n for (let i = 0; i < map.problems.length; i++) {\n const prob = map.problems[i];\n if (prob.type == \"collision\") {\n const cell = table.nodeAt(prob.pos);\n if (!cell) continue;\n const attrs = cell.attrs;\n for (let j = 0; j < attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n;\n tr.setNodeMarkup(\n tr.mapping.map(tablePos + 1 + prob.pos),\n null,\n removeColSpan(attrs, attrs.colspan - prob.n, prob.n)\n );\n } else if (prob.type == \"missing\") {\n mustAdd[prob.row] += prob.n;\n } else if (prob.type == \"overlong_rowspan\") {\n const cell = table.nodeAt(prob.pos);\n if (!cell) continue;\n tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {\n ...cell.attrs,\n rowspan: cell.attrs.rowspan - prob.n\n });\n } else if (prob.type == \"colwidth mismatch\") {\n const cell = table.nodeAt(prob.pos);\n if (!cell) continue;\n tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, {\n ...cell.attrs,\n colwidth: prob.colwidth\n });\n } else if (prob.type == \"zero_sized\") {\n const pos = tr.mapping.map(tablePos);\n tr.delete(pos, pos + table.nodeSize);\n }\n }\n let first, last;\n for (let i = 0; i < mustAdd.length; i++)\n if (mustAdd[i]) {\n if (first == null) first = i;\n last = i;\n }\n for (let i = 0, pos = tablePos + 1; i < map.height; i++) {\n const row = table.child(i);\n const end = pos + row.nodeSize;\n const add = mustAdd[i];\n if (add > 0) {\n let role = \"cell\";\n if (row.firstChild) {\n role = row.firstChild.type.spec.tableRole;\n }\n const nodes = [];\n for (let j = 0; j < add; j++) {\n const node = tableNodeTypes(state.schema)[role].createAndFill();\n if (node) nodes.push(node);\n }\n const side = (i == 0 || first == i - 1) && last == i ? pos + 1 : end - 1;\n tr.insert(tr.mapping.map(side), nodes);\n }\n pos = end;\n }\n return tr.setMeta(fixTablesKey, { fixTables: true });\n}\n\n// src/input.ts\nimport { keydownHandler } from \"prosemirror-keymap\";\nimport { Fragment as Fragment4 } from \"prosemirror-model\";\nimport {\n Selection as Selection2,\n TextSelection as TextSelection3\n} from \"prosemirror-state\";\n\n// src/commands.ts\nimport {\n Fragment as Fragment2,\n Slice as Slice2\n} from \"prosemirror-model\";\nimport {\n TextSelection as TextSelection2\n} from \"prosemirror-state\";\n\n// src/utils/convert.ts\nfunction convertTableNodeToArrayOfRows(tableNode) {\n const map = TableMap.get(tableNode);\n const rows = [];\n const rowCount = map.height;\n const colCount2 = map.width;\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n const row = [];\n for (let colIndex = 0; colIndex < colCount2; colIndex++) {\n const cellIndex = rowIndex * colCount2 + colIndex;\n const cellPos = map.map[cellIndex];\n if (rowIndex > 0) {\n const topCellIndex = cellIndex - colCount2;\n const topCellPos = map.map[topCellIndex];\n if (cellPos === topCellPos) {\n row.push(null);\n continue;\n }\n }\n if (colIndex > 0) {\n const leftCellIndex = cellIndex - 1;\n const leftCellPos = map.map[leftCellIndex];\n if (cellPos === leftCellPos) {\n row.push(null);\n continue;\n }\n }\n row.push(tableNode.nodeAt(cellPos));\n }\n rows.push(row);\n }\n return rows;\n}\nfunction convertArrayOfRowsToTableNode(tableNode, arrayOfNodes) {\n const newRows = [];\n const map = TableMap.get(tableNode);\n const rowCount = map.height;\n const colCount2 = map.width;\n for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {\n const oldRow = tableNode.child(rowIndex);\n const newCells = [];\n for (let colIndex = 0; colIndex < colCount2; colIndex++) {\n const cell = arrayOfNodes[rowIndex][colIndex];\n if (!cell) {\n continue;\n }\n const cellPos = map.map[rowIndex * map.width + colIndex];\n const oldCell = tableNode.nodeAt(cellPos);\n if (!oldCell) {\n continue;\n }\n const newCell = oldCell.type.createChecked(\n cell.attrs,\n cell.content,\n cell.marks\n );\n newCells.push(newCell);\n }\n const newRow = oldRow.type.createChecked(\n oldRow.attrs,\n newCells,\n oldRow.marks\n );\n newRows.push(newRow);\n }\n const newTable = tableNode.type.createChecked(\n tableNode.attrs,\n newRows,\n tableNode.marks\n );\n return newTable;\n}\n\n// src/utils/query.ts\nfunction isCellSelection(value) {\n return value instanceof CellSelection;\n}\nfunction findTable($pos) {\n return findParentNode((node) => node.type.spec.tableRole === \"table\", $pos);\n}\nfunction findCellRange(selection, anchorHit, headHit) {\n var _a, _b;\n if (anchorHit == null && headHit == null && isCellSelection(selection)) {\n return [selection.$anchorCell, selection.$headCell];\n }\n const anchor = (_a = anchorHit != null ? anchorHit : headHit) != null ? _a : selection.anchor;\n const head = (_b = headHit != null ? headHit : anchorHit) != null ? _b : selection.head;\n const doc = selection.$head.doc;\n const $anchorCell = findCellPos(doc, anchor);\n const $headCell = findCellPos(doc, head);\n if ($anchorCell && $headCell && inSameTable($anchorCell, $headCell)) {\n return [$anchorCell, $headCell];\n }\n return null;\n}\nfunction findCellPos(doc, pos) {\n const $pos = doc.resolve(pos);\n return cellAround($pos) || cellNear($pos);\n}\nfunction findParentNode(predicate, $pos) {\n for (let depth = $pos.depth; depth >= 0; depth -= 1) {\n const node = $pos.node(depth);\n if (predicate(node)) {\n const pos = depth === 0 ? 0 : $pos.before(depth);\n const start = $pos.start(depth);\n return { node, pos, start, depth };\n }\n }\n return null;\n}\n\n// src/utils/get-cells.ts\nfunction getCellsInColumn(columnIndex, selection) {\n const table = findTable(selection.$from);\n if (!table) {\n return;\n }\n const map = TableMap.get(table.node);\n if (columnIndex < 0 || columnIndex > map.width - 1) {\n return;\n }\n const cells = map.cellsInRect({\n left: columnIndex,\n right: columnIndex + 1,\n top: 0,\n bottom: map.height\n });\n return cells.map((nodePos) => {\n const node = table.node.nodeAt(nodePos);\n const pos = nodePos + table.start;\n return { pos, start: pos + 1, node, depth: table.depth + 2 };\n });\n}\nfunction getCellsInRow(rowIndex, selection) {\n const table = findTable(selection.$from);\n if (!table) {\n return;\n }\n const map = TableMap.get(table.node);\n if (rowIndex < 0 || rowIndex > map.height - 1) {\n return;\n }\n const cells = map.cellsInRect({\n left: 0,\n right: map.width,\n top: rowIndex,\n bottom: rowIndex + 1\n });\n return cells.map((nodePos) => {\n const node = table.node.nodeAt(nodePos);\n const pos = nodePos + table.start;\n return { pos, start: pos + 1, node, depth: table.depth + 2 };\n });\n}\n\n// src/utils/selection-range.ts\nfunction getSelectionRangeInColumn(tr, startColIndex, endColIndex = startColIndex) {\n let startIndex = startColIndex;\n let endIndex = endColIndex;\n for (let i = startColIndex; i >= 0; i--) {\n const cells = getCellsInColumn(i, tr.selection);\n if (cells) {\n cells.forEach((cell) => {\n const maybeEndIndex = cell.node.attrs.colspan + i - 1;\n if (maybeEndIndex >= startIndex) {\n startIndex = i;\n }\n if (maybeEndIndex > endIndex) {\n endIndex = maybeEndIndex;\n }\n });\n }\n }\n for (let i = startColIndex; i <= endIndex; i++) {\n const cells = getCellsInColumn(i, tr.selection);\n if (cells) {\n cells.forEach((cell) => {\n const maybeEndIndex = cell.node.attrs.colspan + i - 1;\n if (cell.node.attrs.colspan > 1 && maybeEndIndex > endIndex) {\n endIndex = maybeEndIndex;\n }\n });\n }\n }\n const indexes = [];\n for (let i = startIndex; i <= endIndex; i++) {\n const maybeCells = getCellsInColumn(i, tr.selection);\n if (maybeCells && maybeCells.length > 0) {\n indexes.push(i);\n }\n }\n startIndex = indexes[0];\n endIndex = indexes[indexes.length - 1];\n const firstSelectedColumnCells = getCellsInColumn(startIndex, tr.selection);\n const firstRowCells = getCellsInRow(0, tr.selection);\n if (!firstSelectedColumnCells || !firstRowCells) {\n return;\n }\n const $anchor = tr.doc.resolve(\n firstSelectedColumnCells[firstSelectedColumnCells.length - 1].pos\n );\n let headCell;\n for (let i = endIndex; i >= startIndex; i--) {\n const columnCells = getCellsInColumn(i, tr.selection);\n if (columnCells && columnCells.length > 0) {\n for (let j = firstRowCells.length - 1; j >= 0; j--) {\n if (firstRowCells[j].pos === columnCells[0].pos) {\n headCell = columnCells[0];\n break;\n }\n }\n if (headCell) {\n break;\n }\n }\n }\n if (!headCell) {\n return;\n }\n const $head = tr.doc.resolve(headCell.pos);\n return { $anchor, $head, indexes };\n}\nfunction getSelectionRangeInRow(tr, startRowIndex, endRowIndex = startRowIndex) {\n let startIndex = startRowIndex;\n let endIndex = endRowIndex;\n for (let i = startRowIndex; i >= 0; i--) {\n const cells = getCellsInRow(i, tr.selection);\n if (cells) {\n cells.forEach((cell) => {\n const maybeEndIndex = cell.node.attrs.rowspan + i - 1;\n if (maybeEndIndex >= startIndex) {\n startIndex = i;\n }\n if (maybeEndIndex > endIndex) {\n endIndex = maybeEndIndex;\n }\n });\n }\n }\n for (let i = startRowIndex; i <= endIndex; i++) {\n const cells = getCellsInRow(i, tr.selection);\n if (cells) {\n cells.forEach((cell) => {\n const maybeEndIndex = cell.node.attrs.rowspan + i - 1;\n if (cell.node.attrs.rowspan > 1 && maybeEndIndex > endIndex) {\n endIndex = maybeEndIndex;\n }\n });\n }\n }\n const indexes = [];\n for (let i = startIndex; i <= endIndex; i++) {\n const maybeCells = getCellsInRow(i, tr.selection);\n if (maybeCells && maybeCells.length > 0) {\n indexes.push(i);\n }\n }\n startIndex = indexes[0];\n endIndex = indexes[indexes.length - 1];\n const firstSelectedRowCells = getCellsInRow(startIndex, tr.selection);\n const firstColumnCells = getCellsInColumn(0, tr.selection);\n if (!firstSelectedRowCells || !firstColumnCells) {\n return;\n }\n const $anchor = tr.doc.resolve(\n firstSelectedRowCells[firstSelectedRowCells.length - 1].pos\n );\n let headCell;\n for (let i = endIndex; i >= startIndex; i--) {\n const rowCells = getCellsInRow(i, tr.selection);\n if (rowCells && rowCells.length > 0) {\n for (let j = firstColumnCells.length - 1; j >= 0; j--) {\n if (firstColumnCells[j].pos === rowCells[0].pos) {\n headCell = rowCells[0];\n break;\n }\n }\n if (headCell) {\n break;\n }\n }\n }\n if (!headCell) {\n return;\n }\n const $head = tr.doc.resolve(headCell.pos);\n return { $anchor, $head, indexes };\n}\n\n// src/utils/move-row-in-array-of-rows.ts\nfunction moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, directionOverride) {\n const direction = indexesOrigin[0] > indexesTarget[0] ? -1 : 1;\n const rowsExtracted = rows.splice(indexesOrigin[0], indexesOrigin.length);\n const positionOffset = rowsExtracted.length % 2 === 0 ? 1 : 0;\n let target;\n if (directionOverride === -1 && direction === 1) {\n target = indexesTarget[0] - 1;\n } else if (directionOverride === 1 && direction === -1) {\n target = indexesTarget[indexesTarget.length - 1] - positionOffset + 1;\n } else {\n target = direction === -1 ? indexesTarget[0] : indexesTarget[indexesTarget.length - 1] - positionOffset;\n }\n rows.splice(target, 0, ...rowsExtracted);\n return rows;\n}\n\n// src/utils/transpose.ts\nfunction transpose(array) {\n return array[0].map((_, i) => {\n return array.map((column) => column[i]);\n });\n}\n\n// src/utils/move-column.ts\nfunction moveColumn(moveColParams) {\n var _a, _b;\n const { tr, originIndex, targetIndex, select, pos } = moveColParams;\n const $pos = tr.doc.resolve(pos);\n const table = findTable($pos);\n if (!table) return false;\n const indexesOriginColumn = (_a = getSelectionRangeInColumn(\n tr,\n originIndex\n )) == null ? void 0 : _a.indexes;\n const indexesTargetColumn = (_b = getSelectionRangeInColumn(\n tr,\n targetIndex\n )) == null ? void 0 : _b.indexes;\n if (!indexesOriginColumn || !indexesTargetColumn) return false;\n if (indexesOriginColumn.includes(targetIndex)) return false;\n const newTable = moveTableColumn(\n table.node,\n indexesOriginColumn,\n indexesTargetColumn,\n 0\n );\n tr.replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);\n if (!select) return true;\n const map = TableMap.get(newTable);\n const start = table.start;\n const index = targetIndex;\n const lastCell = map.positionAt(map.height - 1, index, newTable);\n const $lastCell = tr.doc.resolve(start + lastCell);\n const firstCell = map.positionAt(0, index, newTable);\n const $firstCell = tr.doc.resolve(start + firstCell);\n tr.setSelection(CellSelection.colSelection($lastCell, $firstCell));\n return true;\n}\nfunction moveTableColumn(table, indexesOrigin, indexesTarget, direction) {\n let rows = transpose(convertTableNodeToArrayOfRows(table));\n rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);\n rows = transpose(rows);\n return convertArrayOfRowsToTableNode(table, rows);\n}\n\n// src/utils/move-row.ts\nfunction moveRow(moveRowParams) {\n var _a, _b;\n const { tr, originIndex, targetIndex, select, pos } = moveRowParams;\n const $pos = tr.doc.resolve(pos);\n const table = findTable($pos);\n if (!table) return false;\n const indexesOriginRow = (_a = getSelectionRangeInRow(tr, originIndex)) == null ? void 0 : _a.indexes;\n const indexesTargetRow = (_b = getSelectionRangeInRow(tr, targetIndex)) == null ? void 0 : _b.indexes;\n if (!indexesOriginRow || !indexesTargetRow) return false;\n if (indexesOriginRow.includes(targetIndex)) return false;\n const newTable = moveTableRow(\n table.node,\n indexesOriginRow,\n indexesTargetRow,\n 0\n );\n tr.replaceWith(table.pos, table.pos + table.node.nodeSize, newTable);\n if (!select) return true;\n const map = TableMap.get(newTable);\n const start = table.start;\n const index = targetIndex;\n const lastCell = map.positionAt(index, map.width - 1, newTable);\n const $lastCell = tr.doc.resolve(start + lastCell);\n const firstCell = map.positionAt(index, 0, newTable);\n const $firstCell = tr.doc.resolve(start + firstCell);\n tr.setSelection(CellSelection.rowSelection($lastCell, $firstCell));\n return true;\n}\nfunction moveTableRow(table, indexesOrigin, indexesTarget, direction) {\n let rows = convertTableNodeToArrayOfRows(table);\n rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction);\n return convertArrayOfRowsToTableNode(table, rows);\n}\n\n// src/commands.ts\nfunction selectedRect(state) {\n const sel = state.selection;\n const $pos = selectionCell(state);\n const table = $pos.node(-1);\n const tableStart = $pos.start(-1);\n const map = TableMap.get(table);\n const rect = sel instanceof CellSelection ? map.rectBetween(\n sel.$anchorCell.pos - tableStart,\n sel.$headCell.pos - tableStart\n ) : map.findCell($pos.pos - tableStart);\n return { ...rect, tableStart, map, table };\n}\nfunction addColumn(tr, { map, tableStart, table }, col) {\n let refColumn = col > 0 ? -1 : 0;\n if (columnIsHeader(map, table, col + refColumn)) {\n refColumn = col == 0 || col == map.width ? null : 0;\n }\n for (let row = 0; row < map.height; row++) {\n const index = row * map.width + col;\n if (col > 0 && col < map.width && map.map[index - 1] == map.map[index]) {\n const pos = map.map[index];\n const cell = table.nodeAt(pos);\n tr.setNodeMarkup(\n tr.mapping.map(tableStart + pos),\n null,\n addColSpan(cell.attrs, col - map.colCount(pos))\n );\n row += cell.attrs.rowspan - 1;\n } else {\n const type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map.map[index + refColumn]).type;\n const pos = map.positionAt(row, col, table);\n tr.insert(tr.mapping.map(tableStart + pos), type.createAndFill());\n }\n }\n return tr;\n}\nfunction addColumnBefore(state, dispatch) {\n if (!isInTable(state)) return false;\n if (dispatch) {\n const rect = selectedRect(state);\n dispatch(addColumn(state.tr, rect, rect.left));\n }\n return true;\n}\nfunction addColumnAfter(state, dispatch) {\n if (!isInTable(state)) return false;\n if (dispatch) {\n const rect = selectedRect(state);\n dispatch(addColumn(state.tr, rect, rect.right));\n }\n return true;\n}\nfunction removeColumn(tr, { map, table, tableStart }, col) {\n const mapStart = tr.mapping.maps.length;\n for (let row = 0; row < map.height; ) {\n const index = row * map.width + col;\n const pos = map.map[index];\n const cell = table.nodeAt(pos);\n const attrs = cell.attrs;\n if (col > 0 && map.map[index - 1] == pos || col < map.width - 1 && map.map[index + 1] == pos) {\n tr.setNodeMarkup(\n tr.mapping.slice(mapStart).map(tableStart + pos),\n null,\n removeColSpan(attrs, col - map.colCount(pos))\n );\n } else {\n const start = tr.mapping.slice(mapStart).map(tableStart + pos);\n tr.delete(start, start + cell.nodeSize);\n }\n row += attrs.rowspan;\n }\n}\nfunction deleteColumn(state, dispatch) {\n if (!isInTable(state)) return false;\n if (dispatch) {\n const rect = selectedRect(state);\n const tr = state.tr;\n if (rect.left == 0 && rect.right == rect.map.width) return false;\n for (let i = rect.right - 1; ; i--) {\n removeColumn(tr, rect, i);\n if (i == rect.left) break;\n const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;\n if (!table) {\n throw RangeError(\"No table found\");\n }\n rect.table = table;\n rect.map = TableMap.get(table);\n }\n dispatch(tr);\n }\n return true;\n}\nfunction rowIsHeader(map, table, row) {\n var _a;\n const headerCell = tableNodeTypes(table.type.schema).header_cell;\n for (let col = 0; col < map.width; col++)\n if (((_a = table.nodeAt(map.map[col + row * map.width])) == null ? void 0 : _a.type) != headerCell)\n return false;\n return true;\n}\nfunction addRow(tr, { map, tableStart, table }, row) {\n var _a;\n let rowPos = tableStart;\n for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;\n const cells = [];\n let refRow = row > 0 ? -1 : 0;\n if (rowIsHeader(map, table, row + refRow))\n refRow = row == 0 || row == map.height ? null : 0;\n for (let col = 0, index = map.width * row; col < map.width; col++, index++) {\n if (row > 0 && row < map.height && map.map[index] == map.map[index - map.width]) {\n const pos = map.map[index];\n const attrs = table.nodeAt(pos).attrs;\n tr.setNodeMarkup(tableStart + pos, null, {\n ...attrs,\n rowspan: attrs.rowspan + 1\n });\n col += attrs.colspan - 1;\n } else {\n const type = refRow == null ? tableNodeTypes(table.type.schema).cell : (_a = table.nodeAt(map.map[index + refRow * map.width])) == null ? void 0 : _a.type;\n const node = type == null ? void 0 : type.createAndFill();\n if (node) cells.push(node);\n }\n }\n tr.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells));\n return tr;\n}\nfunction addRowBefore(state, dispatch) {\n if (!isInTable(state)) return false;\n if (dispatch) {\n const rect = selectedRect(state);\n dispatch(addRow(state.tr, rect, rect.top));\n }\n return true;\n}\nfunction addRowAfter(state, dispatch) {\n if (!isInTable(state)) return false;\n if (dispatch) {\n const rect = selectedRect(state);\n dispatch(addRow(state.tr, rect, rect.bottom));\n }\n return true;\n}\nfunction removeRow(tr, { map, table, tableStart }, row) {\n let rowPos = 0;\n for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize;\n const nextRow = rowPos + table.child(row).nodeSize;\n const mapFrom = tr.mapping.maps.length;\n tr.delete(rowPos + tableStart, nextRow + tableStart);\n const seen = /* @__PURE__ */ new Set();\n for (let col = 0, index = row * map.width; col < map.width; col++, index++) {\n const pos = map.map[index];\n if (seen.has(pos)) continue;\n seen.add(pos);\n if (row > 0 && pos == map.map[index - map.width]) {\n const attrs = table.nodeAt(pos).attrs;\n tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + tableStart), null, {\n ...attrs,\n rowspan: attrs.rowspan - 1\n });\n col += attrs.colspan - 1;\n } else if (row < map.height && pos == map.map[index + map.width]) {\n const cell = table.nodeAt(pos);\n const attrs = cell.attrs;\n const copy = cell.type.create(\n { ...attrs, rowspan: cell.attrs.rowspan - 1 },\n cell.content\n );\n const newPos = map.positionAt(row + 1, col, table);\n tr.insert(tr.mapping.slice(mapFrom).map(tableStart + newPos), copy);\n col += attrs.colspan - 1;\n }\n }\n}\nfunction deleteRow(state, dispatch) {\n if (!isInTable(state)) return false;\n if (dispatch) {\n const rect = selectedRect(state), tr = state.tr;\n if (rect.top == 0 && rect.bottom == rect.map.height) return false;\n for (let i = rect.bottom - 1; ; i--) {\n removeRow(tr, rect, i);\n if (i == rect.top) break;\n const table = rect.tableStart ? tr.doc.nodeAt(rect.tableStart - 1) : tr.doc;\n if (!table) {\n throw RangeError(\"No table found\");\n }\n rect.table = table;\n rect.map = TableMap.get(rect.table);\n }\n dispatch(tr);\n }\n return true;\n}\nfunction isEmpty(cell) {\n const c = cell.content;\n return c.childCount == 1 && c.child(0).isTextblock && c.child(0).childCount == 0;\n}\nfunction cellsOverlapRectangle({ width, height, map }, rect) {\n let indexTop = rect.top * width + rect.left, indexLeft = indexTop;\n let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1);\n for (let i = rect.top; i < rect.bottom; i++) {\n if (rect.left > 0 && map[indexLeft] == map[indexLeft - 1] || rect.right < width && map[indexRight] == map[indexRight + 1])\n return true;\n indexLeft += width;\n indexRight += width;\n }\n for (let i = rect.left; i < rect.right; i++) {\n if (rect.top > 0 && map[indexTop] == map[indexTop - width] || rect.bottom < height && map[indexBottom] == map[indexBottom + width])\n return true;\n indexTop++;\n indexBottom++;\n }\n return false;\n}\nfunction mergeCells(state, dispatch) {\n const sel = state.selection;\n if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos)\n return false;\n const rect = selectedRect(state), { map } = rect;\n if (cellsOverlapRectangle(map, rect)) return false;\n if (dispatch) {\n const tr = state.tr;\n const seen = {};\n let content = Fragment2.empty;\n let mergedPos;\n let mergedCell;\n for (let row = rect.top; row < rect.bottom; row++) {\n for (let col = rect.left; col < rect.right; col++) {\n const cellPos = map.map[row * map.width + col];\n const cell = rect.table.nodeAt(cellPos);\n if (seen[cellPos] || !cell) continue;\n seen[cellPos] = true;\n if (mergedPos == null) {\n mergedPos = cellPos;\n mergedCell = cell;\n } else {\n if (!isEmpty(cell)) content = content.append(cell.content);\n const mapped = tr.mapping.map(cellPos + rect.tableStart);\n tr.delete(mapped, mapped + cell.nodeSize);\n }\n }\n }\n if (mergedPos == null || mergedCell == null) {\n return true;\n }\n tr.setNodeMarkup(mergedPos + rect.tableStart, null, {\n ...addColSpan(\n mergedCell.attrs,\n mergedCell.attrs.colspan,\n rect.right - rect.left - mergedCell.attrs.colspan\n ),\n rowspan: rect.bottom - rect.top\n });\n if (content.size) {\n const end = mergedPos + 1 + mergedCell.content.size;\n const start = isEmpty(mergedCell) ? mergedPos + 1 : end;\n tr.replaceWith(start + rect.tableStart, end + rect.tableStart, content);\n }\n tr.setSelection(\n new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart))\n );\n dispatch(tr);\n }\n return true;\n}\nfunction splitCell(state, dispatch) {\n const nodeTypes = tableNodeTypes(state.schema);\n return splitCellWithType(({ node }) => {\n return nodeTypes[node.type.spec.tableRole];\n })(state, dispatch);\n}\nfunction splitCellWithType(getCellType) {\n return (state, dispatch) => {\n var _a;\n const sel = state.selection;\n let cellNode;\n let cellPos;\n if (!(sel instanceof CellSelection)) {\n cellNode = cellWrapping(sel.$from);\n if (!cellNode) return false;\n cellPos = (_a = cellAround(sel.$from)) == null ? void 0 : _a.pos;\n } else {\n if (sel.$anchorCell.pos != sel.$headCell.pos) return false;\n cellNode = sel.$anchorCell.nodeAfter;\n cellPos = sel.$anchorCell.pos;\n }\n if (cellNode == null || cellPos == null) {\n return false;\n }\n if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {\n return false;\n }\n if (dispatch) {\n let baseAttrs = cellNode.attrs;\n const attrs = [];\n const colwidth = baseAttrs.colwidth;\n if (baseAttrs.rowspan > 1) baseAttrs = { ...baseAttrs, rowspan: 1 };\n if (baseAttrs.colspan > 1) baseAttrs = { ...baseAttrs, colspan: 1 };\n const rect = selectedRect(state), tr = state.tr;\n for (let i = 0; i < rect.right - rect.left; i++)\n attrs.push(\n colwidth ? {\n ...baseAttrs,\n colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null\n } : baseAttrs\n );\n let lastCell;\n for (let row = rect.top; row < rect.bottom; row++) {\n let pos = rect.map.positionAt(row, rect.left, rect.table);\n if (row == rect.top) pos += cellNode.nodeSize;\n for (let col = rect.left, i = 0; col < rect.right; col++, i++) {\n if (col == rect.left && row == rect.top) continue;\n tr.insert(\n lastCell = tr.mapping.map(pos + rect.tableStart, 1),\n getCellType({ node: cellNode, row, col }).createAndFill(attrs[i])\n );\n }\n }\n tr.setNodeMarkup(\n cellPos,\n getCellType({ node: cellNode, row: rect.top, col: rect.left }),\n attrs[0]\n );\n if (sel instanceof CellSelection)\n tr.setSelection(\n new CellSelection(\n tr.doc.resolve(sel.$anchorCell.pos),\n lastCell ? tr.doc.resolve(lastCell) : void 0\n )\n );\n dispatch(tr);\n }\n return true;\n };\n}\nfunction setCellAttr(name, value) {\n return function(state, dispatch) {\n if (!isInTable(state)) return false;\n const $cell = selectionCell(state);\n if ($cell.nodeAfter.attrs[name] === value) return false;\n if (dispatch) {\n const tr = state.tr;\n if (state.selection instanceof CellSelection)\n state.selection.forEachCell((node, pos) => {\n if (node.attrs[name] !== value)\n tr.setNodeMarkup(pos, null, {\n ...node.attrs,\n [name]: value\n });\n });\n else\n tr.setNodeMarkup($cell.pos, null, {\n ...$cell.nodeAfter.attrs,\n [name]: value\n });\n dispatch(tr);\n }\n return true;\n };\n}\nfunction deprecated_toggleHeader(type) {\n return function(state, dispatch) {\n if (!isInTable(state)) return false;\n if (dispatch) {\n const types = tableNodeTypes(state.schema);\n const rect = selectedRect(state), tr = state.tr;\n const cells = rect.map.cellsInRect(\n type == \"column\" ? {\n left: rect.left,\n top: 0,\n right: rect.right,\n bottom: rect.map.height\n } : type == \"row\" ? {\n left: 0,\n top: rect.top,\n right: rect.map.width,\n bottom: rect.bottom\n } : rect\n );\n const nodes = cells.map((pos) => rect.table.nodeAt(pos));\n for (let i = 0; i < cells.length; i++)\n if (nodes[i].type == types.header_cell)\n tr.setNodeMarkup(\n rect.tableStart + cells[i],\n types.cell,\n nodes[i].attrs\n );\n if (tr.steps.length == 0)\n for (let i = 0; i < cells.length; i++)\n tr.setNodeMarkup(\n rect.tableStart + cells[i],\n types.header_cell,\n nodes[i].attrs\n );\n dispatch(tr);\n }\n return true;\n };\n}\nfunction isHeaderEnabledByType(type, rect, types) {\n const cellPositions = rect.map.cellsInRect({\n left: 0,\n top: 0,\n right: type == \"row\" ? rect.map.width : 1,\n bottom: type == \"column\" ? rect.map.height : 1\n });\n for (let i = 0; i < cellPositions.length; i++) {\n const cell = rect.table.nodeAt(cellPositions[i]);\n if (cell && cell.type !== types.header_cell) {\n return false;\n }\n }\n return true;\n}\nfunction toggleHeader(type, options) {\n options = options || { useDeprecatedLogic: false };\n if (options.useDeprecatedLogic) return deprecated_toggleHeader(type);\n return function(state, dispatch) {\n if (!isInTable(state)) return false;\n if (dispatch) {\n const types = tableNodeTypes(state.schema);\n const rect = selectedRect(state), tr = state.tr;\n const isHeaderRowEnabled = isHeaderEnabledByType(\"row\", rect, types);\n const isHeaderColumnEnabled = isHeaderEnabledByType(\n \"column\",\n rect,\n types\n );\n const isHeaderEnabled = type === \"column\" ? isHeaderRowEnabled : type === \"row\" ? isHeaderColumnEnabled : false;\n const selectionStartsAt = isHeaderEnabled ? 1 : 0;\n const cellsRect = type == \"column\" ? {\n left: 0,\n top: selectionStartsAt,\n right: 1,\n bottom: rect.map.height\n } : type == \"row\" ? {\n left: selectionStartsAt,\n top: 0,\n right: rect.map.width,\n bottom: 1\n } : rect;\n const newType = type == \"column\" ? isHeaderColumnEnabled ? types.cell : types.header_cell : type == \"row\" ? isHeaderRowEnabled ? types.cell : types.header_cell : types.cell;\n rect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => {\n const cellPos = relativeCellPos + rect.tableStart;\n const cell = tr.doc.nodeAt(cellPos);\n if (cell) {\n tr.setNodeMarkup(cellPos, newType, cell.attrs);\n }\n });\n dispatch(tr);\n }\n return true;\n };\n}\nvar toggleHeaderRow = toggleHeader(\"row\", {\n useDeprecatedLogic: true\n});\nvar toggleHeaderColumn = toggleHeader(\"column\", {\n useDeprecatedLogic: true\n});\nvar toggleHeaderCell = toggleHeader(\"cell\", {\n useDeprecatedLogic: true\n});\nfunction findNextCell($cell, dir) {\n if (dir < 0) {\n const before = $cell.nodeBefore;\n if (before) return $cell.pos - before.nodeSize;\n for (let row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) {\n const rowNode = $cell.node(-1).child(row);\n const lastChild = rowNode.lastChild;\n if (lastChild) {\n return rowEnd - 1 - lastChild.nodeSize;\n }\n rowEnd -= rowNode.nodeSize;\n }\n } else {\n if ($cell.index() < $cell.parent.childCount - 1) {\n return $cell.pos + $cell.nodeAfter.nodeSize;\n }\n const table = $cell.node(-1);\n for (let row = $cell.indexAfter(-1), rowStart = $cell.after(); row < table.childCount; row++) {\n const rowNode = table.child(row);\n if (rowNode.childCount) return rowStart + 1;\n rowStart += rowNode.nodeSize;\n }\n }\n return null;\n}\nfunction goToNextCell(direction) {\n return function(state, dispatch) {\n if (!isInTable(state)) return false;\n const cell = findNextCell(selectionCell(state), direction);\n if (cell == null) return false;\n if (dispatch) {\n const $cell = state.doc.resolve(cell);\n dispatch(\n state.tr.setSelection(TextSelection2.between($cell, moveCellForward($cell))).scrollIntoView()\n );\n }\n return true;\n };\n}\nfunction deleteTable(state, dispatch) {\n const $pos = state.selection.$anchor;\n for (let d = $pos.depth; d > 0; d--) {\n const node = $pos.node(d);\n if (node.type.spec.tableRole == \"table\") {\n if (dispatch)\n dispatch(\n state.tr.delete($pos.before(d), $pos.after(d)).scrollIntoView()\n );\n return true;\n }\n }\n return false;\n}\nfunction deleteCellSelection(state, dispatch) {\n const sel = state.selection;\n if (!(sel instanceof CellSelection)) return false;\n if (dispatch) {\n const tr = state.tr;\n const baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;\n sel.forEachCell((cell, pos) => {\n if (!cell.content.eq(baseContent))\n tr.replace(\n tr.mapping.map(pos + 1),\n tr.mapping.map(pos + cell.nodeSize - 1),\n new Slice2(baseContent, 0, 0)\n );\n });\n if (tr.docChanged) dispatch(tr);\n }\n return true;\n}\nfunction moveTableRow2(options) {\n return (state, dispatch) => {\n const {\n from: originIndex,\n to: targetIndex,\n select = true,\n pos = state.selection.from\n } = options;\n const tr = state.tr;\n if (moveRow({ tr, originIndex, targetIndex, select, pos })) {\n dispatch == null ? void 0 : dispatch(tr);\n return true;\n }\n return false;\n };\n}\nfunction moveTableColumn2(options) {\n return (state, dispatch) => {\n const {\n from: originIndex,\n to: targetIndex,\n select = true,\n pos = state.selection.from\n } = options;\n const tr = state.tr;\n if (moveColumn({ tr, originIndex, targetIndex, select, pos })) {\n dispatch == null ? void 0 : dispatch(tr);\n return true;\n }\n return false;\n };\n}\n\n// src/copypaste.ts\nimport { Fragment as Fragment3, Slice as Slice3 } from \"prosemirror-model\";\nimport { Transform } from \"prosemirror-transform\";\nfunction pastedCells(slice) {\n if (!slice.size) return null;\n let { content, openStart, openEnd } = slice;\n while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == \"table\")) {\n openStart--;\n openEnd--;\n content = content.child(0).content;\n }\n const first = content.child(0);\n const role = first.type.spec.tableRole;\n const schema = first.type.schema, rows = [];\n if (role == \"row\") {\n for (let i = 0; i < content.childCount; i++) {\n let cells = content.child(i).content;\n const left = i ? 0 : Math.max(0, openStart - 1);\n const right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1);\n if (left || right)\n cells = fitSlice(\n tableNodeTypes(schema).row,\n new Slice3(cells, left, right)\n ).content;\n rows.push(cells);\n }\n } else if (role == \"cell\" || role == \"header_cell\") {\n rows.push(\n openStart || openEnd ? fitSlice(\n tableNodeTypes(schema).row,\n new Slice3(content, openStart, openEnd)\n ).content : content\n );\n } else {\n return null;\n }\n return ensureRectangular(schema, rows);\n}\nfunction ensureRectangular(schema, rows) {\n const widths = [];\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i];\n for (let j = row.childCount - 1; j >= 0; j--) {\n const { rowspan, colspan } = row.child(j).attrs;\n for (let r = i; r < i + rowspan; r++)\n widths[r] = (widths[r] || 0) + colspan;\n }\n }\n let width = 0;\n for (let r = 0; r < widths.length; r++) width = Math.max(width, widths[r]);\n for (let r = 0; r < widths.length; r++) {\n if (r >= rows.length) rows.push(Fragment3.empty);\n if (widths[r] < width) {\n const empty = tableNodeTypes(schema).cell.createAndFill();\n const cells = [];\n for (let i = widths[r]; i < width; i++) {\n cells.push(empty);\n }\n rows[r] = rows[r].append(Fragment3.from(cells));\n }\n }\n return { height: rows.length, width, rows };\n}\nfunction fitSlice(nodeType, slice) {\n const node = nodeType.createAndFill();\n const tr = new Transform(node).replace(0, node.content.size, slice);\n return tr.doc;\n}\nfunction clipCells({ width, height, rows }, newWidth, newHeight) {\n if (width != newWidth) {\n const added = [];\n const newRows = [];\n for (let row = 0; row < rows.length; row++) {\n const frag = rows[row], cells = [];\n for (let col = added[row] || 0, i = 0; col < newWidth; i++) {\n let cell = frag.child(i % frag.childCount);\n if (col + cell.attrs.colspan > newWidth)\n cell = cell.type.createChecked(\n removeColSpan(\n cell.attrs,\n cell.attrs.colspan,\n col + cell.attrs.colspan - newWidth\n ),\n cell.content\n );\n cells.push(cell);\n col += cell.attrs.colspan;\n for (let j = 1; j < cell.attrs.rowspan; j++)\n added[row + j] = (added[row + j] || 0) + cell.attrs.colspan;\n }\n newRows.push(Fragment3.from(cells));\n }\n rows = newRows;\n width = newWidth;\n }\n if (height != newHeight) {\n const newRows = [];\n for (let row = 0, i = 0; row < newHeight; row++, i++) {\n const cells = [], source = rows[i % height];\n for (let j = 0; j < source.childCount; j++) {\n let cell = source.child(j);\n if (row + cell.attrs.rowspan > newHeight)\n cell = cell.type.create(\n {\n ...cell.attrs,\n rowspan: Math.max(1, newHeight - cell.attrs.rowspan)\n },\n cell.content\n );\n cells.push(cell);\n }\n newRows.push(Fragment3.from(cells));\n }\n rows = newRows;\n height = newHeight;\n }\n return { width, height, rows };\n}\nfunction growTable(tr, map, table, start, width, height, mapFrom) {\n const schema = tr.doc.type.schema;\n const types = tableNodeTypes(schema);\n let empty;\n let emptyHead;\n if (width > map.width) {\n for (let row = 0, rowEnd = 0; row < map.height; row++) {\n const rowNode = table.child(row);\n rowEnd += rowNode.nodeSize;\n const cells = [];\n let add;\n if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell)\n add = empty || (empty = types.cell.createAndFill());\n else add = emptyHead || (emptyHead = types.header_cell.createAndFill());\n for (let i = map.width; i < width; i++) cells.push(add);\n tr.insert(tr.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells);\n }\n }\n if (height > map.height) {\n const cells = [];\n for (let i = 0, start2 = (map.height - 1) * map.width; i < Math.max(map.width, width); i++) {\n const header = i >= map.width ? false : table.nodeAt(map.map[start2 + i]).type == types.header_cell;\n cells.push(\n header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty || (empty = types.cell.createAndFill())\n );\n }\n const emptyRow = types.row.create(null, Fragment3.from(cells)), rows = [];\n for (let i = map.height; i < height; i++) rows.push(emptyRow);\n tr.insert(tr.mapping.slice(mapFrom).map(start + table.nodeSize - 2), rows);\n }\n return !!(empty || emptyHead);\n}\nfunction isolateHorizontal(tr, map, table, start, left, right, top, mapFrom) {\n if (top == 0 || top == map.height) return false;\n let found = false;\n for (let col = left; col < right; col++) {\n const index = top * map.width + col, pos = map.map[index];\n if (map.map[index - map.width] == pos) {\n found = true;\n const cell = table.nodeAt(pos);\n const { top: cellTop, left: cellLeft } = map.findCell(pos);\n tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + start), null, {\n ...cell.attrs,\n rowspan: top - cellTop\n });\n tr.insert(\n tr.mapping.slice(mapFrom).map(map.positionAt(top, cellLeft, table)),\n cell.type.createAndFill({\n ...cell.attrs,\n rowspan: cellTop + cell.attrs.rowspan - top\n })\n );\n col += cell.attrs.colspan - 1;\n }\n }\n return found;\n}\nfunction isolateVertical(tr, map, table, start, top, bottom, left, mapFrom) {\n if (left == 0 || left == map.width) return false;\n let found = false;\n for (let row = top; row < bottom; row++) {\n const index = row * map.width + left, pos = map.map[index];\n if (map.map[index - 1] == pos) {\n found = true;\n const cell = table.nodeAt(pos);\n const cellLeft = map.colCount(pos);\n const updatePos = tr.mapping.slice(mapFrom).map(pos + start);\n tr.setNodeMarkup(\n updatePos,\n null,\n removeColSpan(\n cell.attrs,\n left - cellLeft,\n cell.attrs.colspan - (left - cellLeft)\n )\n );\n tr.insert(\n updatePos + cell.nodeSize,\n cell.type.createAndFill(\n removeColSpan(cell.attrs, 0, left - cellLeft)\n )\n );\n row += cell.attrs.rowspan - 1;\n }\n }\n return found;\n}\nfunction insertCells(state, dispatch, tableStart, rect, cells) {\n let table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc;\n if (!table) {\n throw new Error(\"No table found\");\n }\n let map = TableMap.get(table);\n const { top, left } = rect;\n const right = left + cells.width, bottom = top + cells.height;\n const tr = state.tr;\n let mapFrom = 0;\n function recomp() {\n table = tableStart ? tr.doc.nodeAt(tableStart - 1) : tr.doc;\n if (!table) {\n throw new Error(\"No table found\");\n }\n map = TableMap.get(table);\n mapFrom = tr.mapping.maps.length;\n }\n if (growTable(tr, map, table, tableStart, right, bottom, mapFrom)) recomp();\n if (isolateHorizontal(tr, map, table, tableStart, left, right, top, mapFrom))\n recomp();\n if (isolateHorizontal(tr, map, table, tableStart, left, right, bottom, mapFrom))\n recomp();\n if (isolateVertical(tr, map, table, tableStart, top, bottom, left, mapFrom))\n recomp();\n if (isolateVertical(tr, map, table, tableStart, top, bottom, right, mapFrom))\n recomp();\n for (let row = top; row < bottom; row++) {\n const from = map.positionAt(row, left, table), to = map.positionAt(row, right, table);\n tr.replace(\n tr.mapping.slice(mapFrom).map(from + tableStart),\n tr.mapping.slice(mapFrom).map(to + tableStart),\n new Slice3(cells.rows[row - top], 0, 0)\n );\n }\n recomp();\n tr.setSelection(\n new CellSelection(\n tr.doc.resolve(tableStart + map.positionAt(top, left, table)),\n tr.doc.resolve(tableStart + map.positionAt(bottom - 1, right - 1, table))\n )\n );\n dispatch(tr);\n}\n\n// src/input.ts\nvar handleKeyDown = keydownHandler({\n ArrowLeft: arrow(\"horiz\", -1),\n ArrowRight: arrow(\"horiz\", 1),\n ArrowUp: arrow(\"vert\", -1),\n ArrowDown: arrow(\"vert\", 1),\n \"Shift-ArrowLeft\": shiftArrow(\"horiz\", -1),\n \"Shift-ArrowRight\": shiftArrow(\"horiz\", 1),\n \"Shift-ArrowUp\": shiftArrow(\"vert\", -1),\n \"Shift-ArrowDown\": shiftArrow(\"vert\", 1),\n Backspace: deleteCellSelection,\n \"Mod-Backspace\": deleteCellSelection,\n Delete: deleteCellSelection,\n \"Mod-Delete\": deleteCellSelection\n});\nfunction maybeSetSelection(state, dispatch, selection) {\n if (selection.eq(state.selection)) return false;\n if (dispatch) dispatch(state.tr.setSelection(selection).scrollIntoView());\n return true;\n}\nfunction arrow(axis, dir) {\n return (state, dispatch, view) => {\n if (!view) return false;\n const sel = state.selection;\n if (sel instanceof CellSelection) {\n return maybeSetSelection(\n state,\n dispatch,\n Selection2.near(sel.$headCell, dir)\n );\n }\n if (axis != \"horiz\" && !sel.empty) return false;\n const end = atEndOfCell(view, axis, dir);\n if (end == null) return false;\n if (axis == \"horiz\") {\n return maybeSetSelection(\n state,\n dispatch,\n Selection2.near(state.doc.resolve(sel.head + dir), dir)\n );\n } else {\n const $cell = state.doc.resolve(end);\n const $next = nextCell($cell, axis, dir);\n let newSel;\n if ($next) newSel = Selection2.near($next, 1);\n else if (dir < 0)\n newSel = Selection2.near(state.doc.resolve($cell.before(-1)), -1);\n else newSel = Selection2.near(state.doc.resolve($cell.after(-1)), 1);\n return maybeSetSelection(state, dispatch, newSel);\n }\n };\n}\nfunction shiftArrow(axis, dir) {\n return (state, dispatch, view) => {\n if (!view) return false;\n const sel = state.selection;\n let cellSel;\n if (sel instanceof CellSelection) {\n cellSel = sel;\n } else {\n const end = atEndOfCell(view, axis, dir);\n if (end == null) return false;\n cellSel = new CellSelection(state.doc.resolve(end));\n }\n const $head = nextCell(cellSel.$headCell, axis, dir);\n if (!$head) return false;\n return maybeSetSelection(\n state,\n dispatch,\n new CellSelection(cellSel.$anchorCell, $head)\n );\n };\n}\nfunction handleTripleClick(view, pos) {\n const doc = view.state.doc, $cell = cellAround(doc.resolve(pos));\n if (!$cell) return false;\n view.dispatch(view.state.tr.setSelection(new CellSelection($cell)));\n return true;\n}\nfunction handlePaste(view, _, slice) {\n if (!isInTable(view.state)) return false;\n let cells = pastedCells(slice);\n const sel = view.state.selection;\n if (sel instanceof CellSelection) {\n if (!cells)\n cells = {\n width: 1,\n height: 1,\n rows: [\n Fragment4.from(\n fitSlice(tableNodeTypes(view.state.schema).cell, slice)\n )\n ]\n };\n const table = sel.$anchorCell.node(-1);\n const start = sel.$anchorCell.start(-1);\n const rect = TableMap.get(table).rectBetween(\n sel.$anchorCell.pos - start,\n sel.$headCell.pos - start\n );\n cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top);\n insertCells(view.state, view.dispatch, start, rect, cells);\n return true;\n } else if (cells) {\n const $cell = selectionCell(view.state);\n const start = $cell.start(-1);\n insertCells(\n view.state,\n view.dispatch,\n start,\n TableMap.get($cell.node(-1)).findCell($cell.pos - start),\n cells\n );\n return true;\n } else {\n return false;\n }\n}\nfunction handleMouseDown(view, startEvent) {\n var _a;\n if (startEvent.ctrlKey || startEvent.metaKey) return;\n const startDOMCell = domInCell(view, startEvent.target);\n let $anchor;\n if (startEvent.shiftKey && view.state.selection instanceof CellSelection) {\n setCellSelection(view.state.selection.$anchorCell, startEvent);\n startEvent.preventDefault();\n } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_a = cellUnderMouse(view, startEvent)) == null ? void 0 : _a.pos) != $anchor.pos) {\n setCellSelection($anchor, startEvent);\n startEvent.preventDefault();\n } else if (!startDOMCell) {\n return;\n }\n function setCellSelection($anchor2, event) {\n let $head = cellUnderMouse(view, event);\n const starting = tableEditingKey.getState(view.state) == null;\n if (!$head || !inSameTable($anchor2, $head)) {\n if (starting) $head = $anchor2;\n else return;\n }\n const selection = new CellSelection($anchor2, $head);\n if (starting || !view.state.selection.eq(selection)) {\n const tr = view.state.tr.setSelection(selection);\n if (starting) tr.setMeta(tableEditingKey, $anchor2.pos);\n view.dispatch(tr);\n }\n }\n function stop() {\n view.root.removeEventListener(\"mouseup\", stop);\n view.root.removeEventListener(\"dragstart\", stop);\n view.root.removeEventListener(\"mousemove\", move);\n if (tableEditingKey.getState(view.state) != null)\n view.dispatch(view.state.tr.setMeta(tableEditingKey, -1));\n }\n function move(_event) {\n const event = _event;\n const anchor = tableEditingKey.getState(view.state);\n let $anchor2;\n if (anchor != null) {\n $anchor2 = view.state.doc.resolve(anchor);\n } else if (domInCell(view, event.target) != startDOMCell) {\n $anchor2 = cellUnderMouse(view, startEvent);\n if (!$anchor2) return stop();\n }\n if ($anchor2) setCellSelection($anchor2, event);\n }\n view.root.addEventListener(\"mouseup\", stop);\n view.root.addEventListener(\"dragstart\", stop);\n view.root.addEventListener(\"mousemove\", move);\n}\nfunction atEndOfCell(view, axis, dir) {\n if (!(view.state.selection instanceof TextSelection3)) return null;\n const { $head } = view.state.selection;\n for (let d = $head.depth - 1; d >= 0; d--) {\n const parent = $head.node(d), index = dir < 0 ? $head.index(d) : $head.indexAfter(d);\n if (index != (dir < 0 ? 0 : parent.childCount)) return null;\n if (parent.type.spec.tableRole == \"cell\" || parent.type.spec.tableRole == \"header_cell\") {\n const cellPos = $head.before(d);\n const dirStr = axis == \"vert\" ? dir > 0 ? \"down\" : \"up\" : dir > 0 ? \"right\" : \"left\";\n return view.endOfTextblock(dirStr) ? cellPos : null;\n }\n }\n return null;\n}\nfunction domInCell(view, dom) {\n for (; dom && dom != view.dom; dom = dom.parentNode) {\n if (dom.nodeName == \"TD\" || dom.nodeName == \"TH\") {\n return dom;\n }\n }\n return null;\n}\nfunction cellUnderMouse(view, event) {\n const mousePos = view.posAtCoords({\n left: event.clientX,\n top: event.clientY\n });\n if (!mousePos) return null;\n return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null;\n}\n\n// src/columnresizing.ts\nimport { Plugin, PluginKey as PluginKey3 } from \"prosemirror-state\";\nimport {\n Decoration as Decoration2,\n DecorationSet as DecorationSet2\n} from \"prosemirror-view\";\n\n// src/tableview.ts\nvar TableView = class {\n constructor(node, defaultCellMinWidth) {\n this.node = node;\n this.defaultCellMinWidth = defaultCellMinWidth;\n this.dom = document.createElement(\"div\");\n this.dom.className = \"tableWrapper\";\n this.table = this.dom.appendChild(document.createElement(\"table\"));\n this.table.style.setProperty(\n \"--default-cell-min-width\",\n `${defaultCellMinWidth}px`\n );\n this.colgroup = this.table.appendChild(document.createElement(\"colgroup\"));\n updateColumnsOnResize(node, this.colgroup, this.table, defaultCellMinWidth);\n this.contentDOM = this.table.appendChild(document.createElement(\"tbody\"));\n }\n update(node) {\n if (node.type != this.node.type) return false;\n this.node = node;\n updateColumnsOnResize(\n node,\n this.colgroup,\n this.table,\n this.defaultCellMinWidth\n );\n return true;\n }\n ignoreMutation(record) {\n return record.type == \"attributes\" && (record.target == this.table || this.colgroup.contains(record.target));\n }\n};\nfunction updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overrideCol, overrideValue) {\n var _a;\n let totalWidth = 0;\n let fixedWidth = true;\n let nextDOM = colgroup.firstChild;\n const row = node.firstChild;\n if (!row) return;\n for (let i = 0, col = 0; i < row.childCount; i++) {\n const { colspan, colwidth } = row.child(i).attrs;\n for (let j = 0; j < colspan; j++, col++) {\n const hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j];\n const cssWidth = hasWidth ? hasWidth + \"px\" : \"\";\n totalWidth += hasWidth || defaultCellMinWidth;\n if (!hasWidth) fixedWidth = false;\n if (!nextDOM) {\n const col2 = document.createElement(\"col\");\n col2.style.width = cssWidth;\n colgroup.appendChild(col2);\n } else {\n if (nextDOM.style.width != cssWidth) {\n nextDOM.style.width = cssWidth;\n }\n nextDOM = nextDOM.nextSibling;\n }\n }\n }\n while (nextDOM) {\n const after = nextDOM.nextSibling;\n (_a = nextDOM.parentNode) == null ? void 0 : _a.removeChild(nextDOM);\n nextDOM = after;\n }\n if (fixedWidth) {\n table.style.width = totalWidth + \"px\";\n table.style.minWidth = \"\";\n } else {\n table.style.width = \"\";\n table.style.minWidth = totalWidth + \"px\";\n }\n}\n\n// src/columnresizing.ts\nvar columnResizingPluginKey = new PluginKey3(\n \"tableColumnResizing\"\n);\nfunction columnResizing({\n handleWidth = 5,\n cellMinWidth = 25,\n defaultCellMinWidth = 100,\n View = TableView,\n lastColumnResizable = true\n} = {}) {\n const plugin = new Plugin({\n key: columnResizingPluginKey,\n state: {\n init(_, state) {\n var _a, _b;\n const nodeViews = (_b = (_a = plugin.spec) == null ? void 0 : _a.props) == null ? void 0 : _b.nodeViews;\n const tableName = tableNodeTypes(state.schema).table.name;\n if (View && nodeViews) {\n nodeViews[tableName] = (node, view) => {\n return new View(node, defaultCellMinWidth, view);\n };\n }\n return new ResizeState(-1, false);\n },\n apply(tr, prev) {\n return prev.apply(tr);\n }\n },\n props: {\n attributes: (state) => {\n const pluginState = columnResizingPluginKey.getState(state);\n return pluginState && pluginState.activeHandle > -1 ? { class: \"resize-cursor\" } : {};\n },\n handleDOMEvents: {\n mousemove: (view, event) => {\n handleMouseMove(view, event, handleWidth, lastColumnResizable);\n },\n mouseleave: (view) => {\n handleMouseLeave(view);\n },\n mousedown: (view, event) => {\n handleMouseDown2(view, event, cellMinWidth, defaultCellMinWidth);\n }\n },\n decorations: (state) => {\n const pluginState = columnResizingPluginKey.getState(state);\n if (pluginState && pluginState.activeHandle > -1) {\n return handleDecorations(state, pluginState.activeHandle);\n }\n },\n nodeViews: {}\n }\n });\n return plugin;\n}\nvar ResizeState = class _ResizeState {\n constructor(activeHandle, dragging) {\n this.activeHandle = activeHandle;\n this.dragging = dragging;\n }\n apply(tr) {\n const state = this;\n const action = tr.getMeta(columnResizingPluginKey);\n if (action && action.setHandle != null)\n return new _ResizeState(action.setHandle, false);\n if (action && action.setDragging !== void 0)\n return new _ResizeState(state.activeHandle, action.setDragging);\n if (state.activeHandle > -1 && tr.docChanged) {\n let handle = tr.mapping.map(state.activeHandle, -1);\n if (!pointsAtCell(tr.doc.resolve(handle))) {\n handle = -1;\n }\n return new _ResizeState(handle, state.dragging);\n }\n return state;\n }\n};\nfunction handleMouseMove(view, event, handleWidth, lastColumnResizable) {\n if (!view.editable) return;\n const pluginState = columnResizingPluginKey.getState(view.state);\n if (!pluginState) return;\n if (!pluginState.dragging) {\n const target = domCellAround(event.target);\n let cell = -1;\n if (target) {\n const { left, right } = target.getBoundingClientRect();\n if (event.clientX - left <= handleWidth)\n cell = edgeCell(view, event, \"left\", handleWidth);\n else if (right - event.clientX <= handleWidth)\n cell = edgeCell(view, event, \"right\", handleWidth);\n }\n if (cell != pluginState.activeHandle) {\n if (!lastColumnResizable && cell !== -1) {\n const $cell = view.state.doc.resolve(cell);\n const table = $cell.node(-1);\n const map = TableMap.get(table);\n const tableStart = $cell.start(-1);\n const col = map.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1;\n if (col == map.width - 1) {\n return;\n }\n }\n updateHandle(view, cell);\n }\n }\n}\nfunction handleMouseLeave(view) {\n if (!view.editable) return;\n const pluginState = columnResizingPluginKey.getState(view.state);\n if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging)\n updateHandle(view, -1);\n}\nfunction handleMouseDown2(view, event, cellMinWidth, defaultCellMinWidth) {\n var _a;\n if (!view.editable) return false;\n const win = (_a = view.dom.ownerDocument.defaultView) != null ? _a : window;\n const pluginState = columnResizingPluginKey.getState(view.state);\n if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging)\n return false;\n const cell = view.state.doc.nodeAt(pluginState.activeHandle);\n const width = currentColWidth(view, pluginState.activeHandle, cell.attrs);\n view.dispatch(\n view.state.tr.setMeta(columnResizingPluginKey, {\n setDragging: { startX: event.clientX, startWidth: width }\n })\n );\n function finish(event2) {\n win.removeEventListener(\"mouseup\", finish);\n win.removeEventListener(\"mousemove\", move);\n const pluginState2 = columnResizingPluginKey.getState(view.state);\n if (pluginState2 == null ? void 0 : pluginState2.dragging) {\n updateColumnWidth(\n view,\n pluginState2.activeHandle,\n draggedWidth(pluginState2.dragging, event2, cellMinWidth)\n );\n view.dispatch(\n view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null })\n );\n }\n }\n function move(event2) {\n if (!event2.which) return finish(event2);\n const pluginState2 = columnResizingPluginKey.getState(view.state);\n if (!pluginState2) return;\n if (pluginState2.dragging) {\n const dragged = draggedWidth(pluginState2.dragging, event2, cellMinWidth);\n displayColumnWidth(\n view,\n pluginState2.activeHandle,\n dragged,\n defaultCellMinWidth\n );\n }\n }\n displayColumnWidth(\n view,\n pluginState.activeHandle,\n width,\n defaultCellMinWidth\n );\n win.addEventListener(\"mouseup\", finish);\n win.addEventListener(\"mousemove\", move);\n event.preventDefault();\n return true;\n}\nfunction currentColWidth(view, cellPos, { colspan, colwidth }) {\n const width = colwidth && colwidth[colwidth.length - 1];\n if (width) return width;\n const dom = view.domAtPos(cellPos);\n const node = dom.node.childNodes[dom.offset];\n let domWidth = node.offsetWidth, parts = colspan;\n if (colwidth) {\n for (let i = 0; i < colspan; i++)\n if (colwidth[i]) {\n domWidth -= colwidth[i];\n parts--;\n }\n }\n return domWidth / parts;\n}\nfunction domCellAround(target) {\n while (target && target.nodeName != \"TD\" && target.nodeName != \"TH\")\n target = target.classList && target.classList.contains(\"ProseMirror\") ? null : target.parentNode;\n return target;\n}\nfunction edgeCell(view, event, side, handleWidth) {\n const offset = side == \"right\" ? -handleWidth : handleWidth;\n const found = view.posAtCoords({\n left: event.clientX + offset,\n top: event.clientY\n });\n if (!found) return -1;\n const { pos } = found;\n const $cell = cellAround(view.state.doc.resolve(pos));\n if (!$cell) return -1;\n if (side == \"right\") return $cell.pos;\n const map = TableMap.get($cell.node(-1)), start = $cell.start(-1);\n const index = map.map.indexOf($cell.pos - start);\n return index % map.width == 0 ? -1 : start + map.map[index - 1];\n}\nfunction draggedWidth(dragging, event, resizeMinWidth) {\n const offset = event.clientX - dragging.startX;\n return Math.max(resizeMinWidth, dragging.startWidth + offset);\n}\nfunction updateHandle(view, value) {\n view.dispatch(\n view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value })\n );\n}\nfunction updateColumnWidth(view, cell, width) {\n const $cell = view.state.doc.resolve(cell);\n const table = $cell.node(-1), map = TableMap.get(table), start = $cell.start(-1);\n const col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;\n const tr = view.state.tr;\n for (let row = 0; row < map.height; row++) {\n const mapIndex = row * map.width + col;\n if (row && map.map[mapIndex] == map.map[mapIndex - map.width]) continue;\n const pos = map.map[mapIndex];\n const attrs = table.nodeAt(pos).attrs;\n const index = attrs.colspan == 1 ? 0 : col - map.colCount(pos);\n if (attrs.colwidth && attrs.colwidth[index] == width) continue;\n const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan);\n colwidth[index] = width;\n tr.setNodeMarkup(start + pos, null, { ...attrs, colwidth });\n }\n if (tr.docChanged) view.dispatch(tr);\n}\nfunction displayColumnWidth(view, cell, width, defaultCellMinWidth) {\n const $cell = view.state.doc.resolve(cell);\n const table = $cell.node(-1), start = $cell.start(-1);\n const col = TableMap.get(table).colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;\n let dom = view.domAtPos($cell.start(-1)).node;\n while (dom && dom.nodeName != \"TABLE\") {\n dom = dom.parentNode;\n }\n if (!dom) return;\n updateColumnsOnResize(\n table,\n dom.firstChild,\n dom,\n defaultCellMinWidth,\n col,\n width\n );\n}\nfunction zeroes(n) {\n return Array(n).fill(0);\n}\nfunction handleDecorations(state, cell) {\n var _a;\n const decorations = [];\n const $cell = state.doc.resolve(cell);\n const table = $cell.node(-1);\n if (!table) {\n return DecorationSet2.empty;\n }\n const map = TableMap.get(table);\n const start = $cell.start(-1);\n const col = map.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1;\n for (let row = 0; row < map.height; row++) {\n const index = col + row * map.width;\n if ((col == map.width - 1 || map.map[index] != map.map[index + 1]) && (row == 0 || map.map[index] != map.map[index - map.width])) {\n const cellPos = map.map[index];\n const pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1;\n const dom = document.createElement(\"div\");\n dom.className = \"column-resize-handle\";\n if ((_a = columnResizingPluginKey.getState(state)) == null ? void 0 : _a.dragging) {\n decorations.push(\n Decoration2.node(\n start + cellPos,\n start + cellPos + table.nodeAt(cellPos).nodeSize,\n {\n class: \"column-resize-dragging\"\n }\n )\n );\n }\n decorations.push(Decoration2.widget(pos, dom));\n }\n }\n return DecorationSet2.create(state.doc, decorations);\n}\n\n// src/index.ts\nfunction tableEditing({\n allowTableNodeSelection = false\n} = {}) {\n return new Plugin2({\n key: tableEditingKey,\n // This piece of state is used to remember when a mouse-drag\n // cell-selection is happening, so that it can continue even as\n // transactions (which might move its anchor cell) come in.\n state: {\n init() {\n return null;\n },\n apply(tr, cur) {\n const set = tr.getMeta(tableEditingKey);\n if (set != null) return set == -1 ? null : set;\n if (cur == null || !tr.docChanged) return cur;\n const { deleted, pos } = tr.mapping.mapResult(cur);\n return deleted ? null : pos;\n }\n },\n props: {\n decorations: drawCellSelection,\n handleDOMEvents: {\n mousedown: handleMouseDown\n },\n createSelectionBetween(view) {\n return tableEditingKey.getState(view.state) != null ? view.state.selection : null;\n },\n handleTripleClick,\n handleKeyDown,\n handlePaste\n },\n appendTransaction(_, oldState, state) {\n return normalizeSelection(\n state,\n fixTables(state, oldState),\n allowTableNodeSelection\n );\n }\n });\n}\nexport {\n CellBookmark,\n CellSelection,\n ResizeState,\n TableMap,\n TableView,\n clipCells as __clipCells,\n insertCells as __insertCells,\n pastedCells as __pastedCells,\n addColSpan,\n addColumn,\n addColumnAfter,\n addColumnBefore,\n addRow,\n addRowAfter,\n addRowBefore,\n cellAround,\n cellNear,\n colCount,\n columnIsHeader,\n columnResizing,\n columnResizingPluginKey,\n deleteCellSelection,\n deleteColumn,\n deleteRow,\n deleteTable,\n findCell,\n findCellPos,\n findCellRange,\n findTable,\n fixTables,\n fixTablesKey,\n goToNextCell,\n handlePaste,\n inSameTable,\n isInTable,\n mergeCells,\n moveCellForward,\n moveTableColumn2 as moveTableColumn,\n moveTableRow2 as moveTableRow,\n nextCell,\n pointsAtCell,\n removeColSpan,\n removeColumn,\n removeRow,\n rowIsHeader,\n selectedRect,\n selectionCell,\n setCellAttr,\n splitCell,\n splitCellWithType,\n tableEditing,\n tableEditingKey,\n tableNodeTypes,\n tableNodes,\n toggleHeader,\n toggleHeaderCell,\n toggleHeaderColumn,\n toggleHeaderRow,\n updateColumnsOnResize\n};\n","import { findParentNodeClosestToPos, Node, mergeAttributes, callOrReturn, getExtensionField } from '@tiptap/core';\nimport { TextSelection } from '@tiptap/pm/state';\nimport { CellSelection, addColumnBefore, addColumnAfter, deleteColumn, addRowBefore, addRowAfter, deleteRow, deleteTable, mergeCells, splitCell, toggleHeader, toggleHeaderCell, setCellAttr, goToNextCell, fixTables, columnResizing, tableEditing } from '@tiptap/pm/tables';\n\nfunction getColStyleDeclaration(minWidth, width) {\n if (width) {\n // apply the stored width unless it is below the configured minimum cell width\n return ['width', `${Math.max(width, minWidth)}px`];\n }\n // set the minimum with on the column if it has no stored width\n return ['min-width', `${minWidth}px`];\n}\n\nfunction updateColumns(node, colgroup, //