var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {}; function getDefaultExportFromCjs(x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x; } var react = { exports: {} }; var react_production = {}; var hasRequiredReact_production; function requireReact_production() { if (hasRequiredReact_production) return react_production; hasRequiredReact_production = 1; var REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = /* @__PURE__ */ Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = /* @__PURE__ */ Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = /* @__PURE__ */ Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = /* @__PURE__ */ Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = /* @__PURE__ */ Symbol.for("react.suspense"), REACT_MEMO_TYPE = /* @__PURE__ */ Symbol.for("react.memo"), REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy"), REACT_ACTIVITY_TYPE = /* @__PURE__ */ Symbol.for("react.activity"), MAYBE_ITERATOR_SYMBOL = Symbol.iterator; function getIteratorFn(maybeIterable) { if (null === maybeIterable || "object" !== typeof maybeIterable) return null; maybeIterable = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable["@@iterator"]; return "function" === typeof maybeIterable ? maybeIterable : null; } var ReactNoopUpdateQueue = { isMounted: function() { return false; }, enqueueForceUpdate: function() { }, enqueueReplaceState: function() { }, enqueueSetState: function() { } }, assign = Object.assign, emptyObject = {}; function Component(props, context, updater) { this.props = props; this.context = context; this.refs = emptyObject; this.updater = updater || ReactNoopUpdateQueue; } Component.prototype.isReactComponent = {}; Component.prototype.setState = function(partialState, callback) { if ("object" !== typeof partialState && "function" !== typeof partialState && null != partialState) throw Error( "takes an object of state variables to update or a function which returns an object of state variables." ); this.updater.enqueueSetState(this, partialState, callback, "setState"); }; Component.prototype.forceUpdate = function(callback) { this.updater.enqueueForceUpdate(this, callback, "forceUpdate"); }; function ComponentDummy() { } ComponentDummy.prototype = Component.prototype; function PureComponent(props, context, updater) { this.props = props; this.context = context; this.refs = emptyObject; this.updater = updater || ReactNoopUpdateQueue; } var pureComponentPrototype = PureComponent.prototype = new ComponentDummy(); pureComponentPrototype.constructor = PureComponent; assign(pureComponentPrototype, Component.prototype); pureComponentPrototype.isPureReactComponent = true; var isArrayImpl = Array.isArray; function noop2() { } var ReactSharedInternals = { H: null, A: null, T: null, S: null }, hasOwnProperty2 = Object.prototype.hasOwnProperty; function ReactElement(type, key, props) { var refProp = props.ref; return { $$typeof: REACT_ELEMENT_TYPE, type, key, ref: void 0 !== refProp ? refProp : null, props }; } function cloneAndReplaceKey(oldElement, newKey) { return ReactElement(oldElement.type, newKey, oldElement.props); } function isValidElement(object) { return "object" === typeof object && null !== object && object.$$typeof === REACT_ELEMENT_TYPE; } function escape(key) { var escaperLookup = { "=": "=0", ":": "=2" }; return "$" + key.replace(/[=:]/g, function(match) { return escaperLookup[match]; }); } var userProvidedKeyEscapeRegex = /\/+/g; function getElementKey(element, index) { return "object" === typeof element && null !== element && null != element.key ? escape("" + element.key) : index.toString(36); } function resolveThenable(thenable) { switch (thenable.status) { case "fulfilled": return thenable.value; case "rejected": throw thenable.reason; default: switch ("string" === typeof thenable.status ? thenable.then(noop2, noop2) : (thenable.status = "pending", thenable.then( function(fulfilledValue) { "pending" === thenable.status && (thenable.status = "fulfilled", thenable.value = fulfilledValue); }, function(error) { "pending" === thenable.status && (thenable.status = "rejected", thenable.reason = error); } )), thenable.status) { case "fulfilled": return thenable.value; case "rejected": throw thenable.reason; } } throw thenable; } function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) { var type = typeof children; if ("undefined" === type || "boolean" === type) children = null; var invokeCallback = false; if (null === children) invokeCallback = true; else switch (type) { case "bigint": case "string": case "number": invokeCallback = true; break; case "object": switch (children.$$typeof) { case REACT_ELEMENT_TYPE: case REACT_PORTAL_TYPE: invokeCallback = true; break; case REACT_LAZY_TYPE: return invokeCallback = children._init, mapIntoArray( invokeCallback(children._payload), array, escapedPrefix, nameSoFar, callback ); } } if (invokeCallback) return callback = callback(children), invokeCallback = "" === nameSoFar ? "." + getElementKey(children, 0) : nameSoFar, isArrayImpl(callback) ? (escapedPrefix = "", null != invokeCallback && (escapedPrefix = invokeCallback.replace(userProvidedKeyEscapeRegex, "$&/") + "/"), mapIntoArray(callback, array, escapedPrefix, "", function(c) { return c; })) : null != callback && (isValidElement(callback) && (callback = cloneAndReplaceKey( callback, escapedPrefix + (null == callback.key || children && children.key === callback.key ? "" : ("" + callback.key).replace( userProvidedKeyEscapeRegex, "$&/" ) + "/") + invokeCallback )), array.push(callback)), 1; invokeCallback = 0; var nextNamePrefix = "" === nameSoFar ? "." : nameSoFar + ":"; if (isArrayImpl(children)) for (var i = 0; i < children.length; i++) nameSoFar = children[i], type = nextNamePrefix + getElementKey(nameSoFar, i), invokeCallback += mapIntoArray( nameSoFar, array, escapedPrefix, type, callback ); else if (i = getIteratorFn(children), "function" === typeof i) for (children = i.call(children), i = 0; !(nameSoFar = children.next()).done; ) nameSoFar = nameSoFar.value, type = nextNamePrefix + getElementKey(nameSoFar, i++), invokeCallback += mapIntoArray( nameSoFar, array, escapedPrefix, type, callback ); else if ("object" === type) { if ("function" === typeof children.then) return mapIntoArray( resolveThenable(children), array, escapedPrefix, nameSoFar, callback ); array = String(children); throw Error( "Objects are not valid as a React child (found: " + ("[object Object]" === array ? "object with keys {" + Object.keys(children).join(", ") + "}" : array) + "). If you meant to render a collection of children, use an array instead." ); } return invokeCallback; } function mapChildren2(children, func, context) { if (null == children) return children; var result = [], count = 0; mapIntoArray(children, result, "", "", function(child) { return func.call(context, child, count++); }); return result; } function lazyInitializer(payload) { if (-1 === payload._status) { var ctor = payload._result; ctor = ctor(); ctor.then( function(moduleObject) { if (0 === payload._status || -1 === payload._status) payload._status = 1, payload._result = moduleObject; }, function(error) { if (0 === payload._status || -1 === payload._status) payload._status = 2, payload._result = error; } ); -1 === payload._status && (payload._status = 0, payload._result = ctor); } if (1 === payload._status) return payload._result.default; throw payload._result; } var reportGlobalError = "function" === typeof reportError ? reportError : function(error) { if ("object" === typeof window && "function" === typeof window.ErrorEvent) { var event = new window.ErrorEvent("error", { bubbles: true, cancelable: true, message: "object" === typeof error && null !== error && "string" === typeof error.message ? String(error.message) : String(error), error }); if (!window.dispatchEvent(event)) return; } else if ("object" === typeof process && "function" === typeof process.emit) { process.emit("uncaughtException", error); return; } console.error(error); }, Children = { map: mapChildren2, forEach: function(children, forEachFunc, forEachContext) { mapChildren2( children, function() { forEachFunc.apply(this, arguments); }, forEachContext ); }, count: function(children) { var n = 0; mapChildren2(children, function() { n++; }); return n; }, toArray: function(children) { return mapChildren2(children, function(child) { return child; }) || []; }, only: function(children) { if (!isValidElement(children)) throw Error( "React.Children.only expected to receive a single React element child." ); return children; } }; react_production.Activity = REACT_ACTIVITY_TYPE; react_production.Children = Children; react_production.Component = Component; react_production.Fragment = REACT_FRAGMENT_TYPE; react_production.Profiler = REACT_PROFILER_TYPE; react_production.PureComponent = PureComponent; react_production.StrictMode = REACT_STRICT_MODE_TYPE; react_production.Suspense = REACT_SUSPENSE_TYPE; react_production.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = ReactSharedInternals; react_production.__COMPILER_RUNTIME = { __proto__: null, c: function(size2) { return ReactSharedInternals.H.useMemoCache(size2); } }; react_production.cache = function(fn) { return function() { return fn.apply(null, arguments); }; }; react_production.cacheSignal = function() { return null; }; react_production.cloneElement = function(element, config, children) { if (null === element || void 0 === element) throw Error( "The argument must be a React element, but you passed " + element + "." ); var props = assign({}, element.props), key = element.key; if (null != config) for (propName in void 0 !== config.key && (key = "" + config.key), config) !hasOwnProperty2.call(config, propName) || "key" === propName || "__self" === propName || "__source" === propName || "ref" === propName && void 0 === config.ref || (props[propName] = config[propName]); var propName = arguments.length - 2; if (1 === propName) props.children = children; else if (1 < propName) { for (var childArray = Array(propName), i = 0; i < propName; i++) childArray[i] = arguments[i + 2]; props.children = childArray; } return ReactElement(element.type, key, props); }; react_production.createContext = function(defaultValue) { defaultValue = { $$typeof: REACT_CONTEXT_TYPE, _currentValue: defaultValue, _currentValue2: defaultValue, _threadCount: 0, Provider: null, Consumer: null }; defaultValue.Provider = defaultValue; defaultValue.Consumer = { $$typeof: REACT_CONSUMER_TYPE, _context: defaultValue }; return defaultValue; }; react_production.createElement = function(type, config, children) { var propName, props = {}, key = null; if (null != config) for (propName in void 0 !== config.key && (key = "" + config.key), config) hasOwnProperty2.call(config, propName) && "key" !== propName && "__self" !== propName && "__source" !== propName && (props[propName] = config[propName]); var childrenLength = arguments.length - 2; if (1 === childrenLength) props.children = children; else if (1 < childrenLength) { for (var childArray = Array(childrenLength), i = 0; i < childrenLength; i++) childArray[i] = arguments[i + 2]; props.children = childArray; } if (type && type.defaultProps) for (propName in childrenLength = type.defaultProps, childrenLength) void 0 === props[propName] && (props[propName] = childrenLength[propName]); return ReactElement(type, key, props); }; react_production.createRef = function() { return { current: null }; }; react_production.forwardRef = function(render) { return { $$typeof: REACT_FORWARD_REF_TYPE, render }; }; react_production.isValidElement = isValidElement; react_production.lazy = function(ctor) { return { $$typeof: REACT_LAZY_TYPE, _payload: { _status: -1, _result: ctor }, _init: lazyInitializer }; }; react_production.memo = function(type, compare) { return { $$typeof: REACT_MEMO_TYPE, type, compare: void 0 === compare ? null : compare }; }; react_production.startTransition = function(scope) { var prevTransition = ReactSharedInternals.T, currentTransition = {}; ReactSharedInternals.T = currentTransition; try { var returnValue = scope(), onStartTransitionFinish = ReactSharedInternals.S; null !== onStartTransitionFinish && onStartTransitionFinish(currentTransition, returnValue); "object" === typeof returnValue && null !== returnValue && "function" === typeof returnValue.then && returnValue.then(noop2, reportGlobalError); } catch (error) { reportGlobalError(error); } finally { null !== prevTransition && null !== currentTransition.types && (prevTransition.types = currentTransition.types), ReactSharedInternals.T = prevTransition; } }; react_production.unstable_useCacheRefresh = function() { return ReactSharedInternals.H.useCacheRefresh(); }; react_production.use = function(usable) { return ReactSharedInternals.H.use(usable); }; react_production.useActionState = function(action, initialState, permalink) { return ReactSharedInternals.H.useActionState(action, initialState, permalink); }; react_production.useCallback = function(callback, deps) { return ReactSharedInternals.H.useCallback(callback, deps); }; react_production.useContext = function(Context) { return ReactSharedInternals.H.useContext(Context); }; react_production.useDebugValue = function() { }; react_production.useDeferredValue = function(value, initialValue) { return ReactSharedInternals.H.useDeferredValue(value, initialValue); }; react_production.useEffect = function(create, deps) { return ReactSharedInternals.H.useEffect(create, deps); }; react_production.useEffectEvent = function(callback) { return ReactSharedInternals.H.useEffectEvent(callback); }; react_production.useId = function() { return ReactSharedInternals.H.useId(); }; react_production.useImperativeHandle = function(ref, create, deps) { return ReactSharedInternals.H.useImperativeHandle(ref, create, deps); }; react_production.useInsertionEffect = function(create, deps) { return ReactSharedInternals.H.useInsertionEffect(create, deps); }; react_production.useLayoutEffect = function(create, deps) { return ReactSharedInternals.H.useLayoutEffect(create, deps); }; react_production.useMemo = function(create, deps) { return ReactSharedInternals.H.useMemo(create, deps); }; react_production.useOptimistic = function(passthrough, reducer) { return ReactSharedInternals.H.useOptimistic(passthrough, reducer); }; react_production.useReducer = function(reducer, initialArg, init2) { return ReactSharedInternals.H.useReducer(reducer, initialArg, init2); }; react_production.useRef = function(initialValue) { return ReactSharedInternals.H.useRef(initialValue); }; react_production.useState = function(initialState) { return ReactSharedInternals.H.useState(initialState); }; react_production.useSyncExternalStore = function(subscribe, getSnapshot, getServerSnapshot) { return ReactSharedInternals.H.useSyncExternalStore( subscribe, getSnapshot, getServerSnapshot ); }; react_production.useTransition = function() { return ReactSharedInternals.H.useTransition(); }; react_production.version = "19.2.4"; return react_production; } var react_development = { exports: {} }; react_development.exports; var hasRequiredReact_development; function requireReact_development() { if (hasRequiredReact_development) return react_development.exports; hasRequiredReact_development = 1; (function(module, exports$1) { "production" !== process.env.NODE_ENV && (function() { function defineDeprecationWarning(methodName, info) { Object.defineProperty(Component.prototype, methodName, { get: function() { console.warn( "%s(...) is deprecated in plain JavaScript React classes. %s", info[0], info[1] ); } }); } function getIteratorFn(maybeIterable) { if (null === maybeIterable || "object" !== typeof maybeIterable) return null; maybeIterable = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable["@@iterator"]; return "function" === typeof maybeIterable ? maybeIterable : null; } function warnNoop(publicInstance, callerName) { publicInstance = (publicInstance = publicInstance.constructor) && (publicInstance.displayName || publicInstance.name) || "ReactClass"; var warningKey = publicInstance + "." + callerName; didWarnStateUpdateForUnmountedComponent[warningKey] || (console.error( "Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.", callerName, publicInstance ), didWarnStateUpdateForUnmountedComponent[warningKey] = true); } function Component(props, context, updater) { this.props = props; this.context = context; this.refs = emptyObject; this.updater = updater || ReactNoopUpdateQueue; } function ComponentDummy() { } function PureComponent(props, context, updater) { this.props = props; this.context = context; this.refs = emptyObject; this.updater = updater || ReactNoopUpdateQueue; } function noop2() { } function testStringCoercion(value) { return "" + value; } function checkKeyStringCoercion(value) { try { testStringCoercion(value); var JSCompiler_inline_result = false; } catch (e) { JSCompiler_inline_result = true; } if (JSCompiler_inline_result) { JSCompiler_inline_result = console; var JSCompiler_temp_const = JSCompiler_inline_result.error; var JSCompiler_inline_result$jscomp$0 = "function" === typeof Symbol && Symbol.toStringTag && value[Symbol.toStringTag] || value.constructor.name || "Object"; JSCompiler_temp_const.call( JSCompiler_inline_result, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", JSCompiler_inline_result$jscomp$0 ); return testStringCoercion(value); } } function getComponentNameFromType(type) { if (null == type) return null; if ("function" === typeof type) return type.$$typeof === REACT_CLIENT_REFERENCE ? null : type.displayName || type.name || null; if ("string" === typeof type) return type; switch (type) { case REACT_FRAGMENT_TYPE: return "Fragment"; case REACT_PROFILER_TYPE: return "Profiler"; case REACT_STRICT_MODE_TYPE: return "StrictMode"; case REACT_SUSPENSE_TYPE: return "Suspense"; case REACT_SUSPENSE_LIST_TYPE: return "SuspenseList"; case REACT_ACTIVITY_TYPE: return "Activity"; } if ("object" === typeof type) switch ("number" === typeof type.tag && console.error( "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue." ), type.$$typeof) { case REACT_PORTAL_TYPE: return "Portal"; case REACT_CONTEXT_TYPE: return type.displayName || "Context"; case REACT_CONSUMER_TYPE: return (type._context.displayName || "Context") + ".Consumer"; case REACT_FORWARD_REF_TYPE: var innerType = type.render; type = type.displayName; type || (type = innerType.displayName || innerType.name || "", type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef"); return type; case REACT_MEMO_TYPE: return innerType = type.displayName || null, null !== innerType ? innerType : getComponentNameFromType(type.type) || "Memo"; case REACT_LAZY_TYPE: innerType = type._payload; type = type._init; try { return getComponentNameFromType(type(innerType)); } catch (x) { } } return null; } function getTaskName(type) { if (type === REACT_FRAGMENT_TYPE) return "<>"; if ("object" === typeof type && null !== type && type.$$typeof === REACT_LAZY_TYPE) return "<...>"; try { var name = getComponentNameFromType(type); return name ? "<" + name + ">" : "<...>"; } catch (x) { return "<...>"; } } function getOwner() { var dispatcher = ReactSharedInternals.A; return null === dispatcher ? null : dispatcher.getOwner(); } function UnknownOwner() { return Error("react-stack-top-frame"); } function hasValidKey(config) { if (hasOwnProperty2.call(config, "key")) { var getter = Object.getOwnPropertyDescriptor(config, "key").get; if (getter && getter.isReactWarning) return false; } return void 0 !== config.key; } function defineKeyPropWarningGetter(props, displayName) { function warnAboutAccessingKey() { specialPropKeyWarningShown || (specialPropKeyWarningShown = true, console.error( "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", displayName )); } warnAboutAccessingKey.isReactWarning = true; Object.defineProperty(props, "key", { get: warnAboutAccessingKey, configurable: true }); } function elementRefGetterWithDeprecationWarning() { var componentName = getComponentNameFromType(this.type); didWarnAboutElementRef[componentName] || (didWarnAboutElementRef[componentName] = true, console.error( "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release." )); componentName = this.props.ref; return void 0 !== componentName ? componentName : null; } function ReactElement(type, key, props, owner, debugStack, debugTask) { var refProp = props.ref; type = { $$typeof: REACT_ELEMENT_TYPE, type, key, props, _owner: owner }; null !== (void 0 !== refProp ? refProp : null) ? Object.defineProperty(type, "ref", { enumerable: false, get: elementRefGetterWithDeprecationWarning }) : Object.defineProperty(type, "ref", { enumerable: false, value: null }); type._store = {}; Object.defineProperty(type._store, "validated", { configurable: false, enumerable: false, writable: true, value: 0 }); Object.defineProperty(type, "_debugInfo", { configurable: false, enumerable: false, writable: true, value: null }); Object.defineProperty(type, "_debugStack", { configurable: false, enumerable: false, writable: true, value: debugStack }); Object.defineProperty(type, "_debugTask", { configurable: false, enumerable: false, writable: true, value: debugTask }); Object.freeze && (Object.freeze(type.props), Object.freeze(type)); return type; } function cloneAndReplaceKey(oldElement, newKey) { newKey = ReactElement( oldElement.type, newKey, oldElement.props, oldElement._owner, oldElement._debugStack, oldElement._debugTask ); oldElement._store && (newKey._store.validated = oldElement._store.validated); return newKey; } function validateChildKeys(node) { isValidElement(node) ? node._store && (node._store.validated = 1) : "object" === typeof node && null !== node && node.$$typeof === REACT_LAZY_TYPE && ("fulfilled" === node._payload.status ? isValidElement(node._payload.value) && node._payload.value._store && (node._payload.value._store.validated = 1) : node._store && (node._store.validated = 1)); } function isValidElement(object) { return "object" === typeof object && null !== object && object.$$typeof === REACT_ELEMENT_TYPE; } function escape(key) { var escaperLookup = { "=": "=0", ":": "=2" }; return "$" + key.replace(/[=:]/g, function(match) { return escaperLookup[match]; }); } function getElementKey(element, index) { return "object" === typeof element && null !== element && null != element.key ? (checkKeyStringCoercion(element.key), escape("" + element.key)) : index.toString(36); } function resolveThenable(thenable) { switch (thenable.status) { case "fulfilled": return thenable.value; case "rejected": throw thenable.reason; default: switch ("string" === typeof thenable.status ? thenable.then(noop2, noop2) : (thenable.status = "pending", thenable.then( function(fulfilledValue) { "pending" === thenable.status && (thenable.status = "fulfilled", thenable.value = fulfilledValue); }, function(error) { "pending" === thenable.status && (thenable.status = "rejected", thenable.reason = error); } )), thenable.status) { case "fulfilled": return thenable.value; case "rejected": throw thenable.reason; } } throw thenable; } function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) { var type = typeof children; if ("undefined" === type || "boolean" === type) children = null; var invokeCallback = false; if (null === children) invokeCallback = true; else switch (type) { case "bigint": case "string": case "number": invokeCallback = true; break; case "object": switch (children.$$typeof) { case REACT_ELEMENT_TYPE: case REACT_PORTAL_TYPE: invokeCallback = true; break; case REACT_LAZY_TYPE: return invokeCallback = children._init, mapIntoArray( invokeCallback(children._payload), array, escapedPrefix, nameSoFar, callback ); } } if (invokeCallback) { invokeCallback = children; callback = callback(invokeCallback); var childKey = "" === nameSoFar ? "." + getElementKey(invokeCallback, 0) : nameSoFar; isArrayImpl(callback) ? (escapedPrefix = "", null != childKey && (escapedPrefix = childKey.replace(userProvidedKeyEscapeRegex, "$&/") + "/"), mapIntoArray(callback, array, escapedPrefix, "", function(c) { return c; })) : null != callback && (isValidElement(callback) && (null != callback.key && (invokeCallback && invokeCallback.key === callback.key || checkKeyStringCoercion(callback.key)), escapedPrefix = cloneAndReplaceKey( callback, escapedPrefix + (null == callback.key || invokeCallback && invokeCallback.key === callback.key ? "" : ("" + callback.key).replace( userProvidedKeyEscapeRegex, "$&/" ) + "/") + childKey ), "" !== nameSoFar && null != invokeCallback && isValidElement(invokeCallback) && null == invokeCallback.key && invokeCallback._store && !invokeCallback._store.validated && (escapedPrefix._store.validated = 2), callback = escapedPrefix), array.push(callback)); return 1; } invokeCallback = 0; childKey = "" === nameSoFar ? "." : nameSoFar + ":"; if (isArrayImpl(children)) for (var i = 0; i < children.length; i++) nameSoFar = children[i], type = childKey + getElementKey(nameSoFar, i), invokeCallback += mapIntoArray( nameSoFar, array, escapedPrefix, type, callback ); else if (i = getIteratorFn(children), "function" === typeof i) for (i === children.entries && (didWarnAboutMaps || console.warn( "Using Maps as children is not supported. Use an array of keyed ReactElements instead." ), didWarnAboutMaps = true), children = i.call(children), i = 0; !(nameSoFar = children.next()).done; ) nameSoFar = nameSoFar.value, type = childKey + getElementKey(nameSoFar, i++), invokeCallback += mapIntoArray( nameSoFar, array, escapedPrefix, type, callback ); else if ("object" === type) { if ("function" === typeof children.then) return mapIntoArray( resolveThenable(children), array, escapedPrefix, nameSoFar, callback ); array = String(children); throw Error( "Objects are not valid as a React child (found: " + ("[object Object]" === array ? "object with keys {" + Object.keys(children).join(", ") + "}" : array) + "). If you meant to render a collection of children, use an array instead." ); } return invokeCallback; } function mapChildren2(children, func, context) { if (null == children) return children; var result = [], count = 0; mapIntoArray(children, result, "", "", function(child) { return func.call(context, child, count++); }); return result; } function lazyInitializer(payload) { if (-1 === payload._status) { var ioInfo = payload._ioInfo; null != ioInfo && (ioInfo.start = ioInfo.end = performance.now()); ioInfo = payload._result; var thenable = ioInfo(); thenable.then( function(moduleObject) { if (0 === payload._status || -1 === payload._status) { payload._status = 1; payload._result = moduleObject; var _ioInfo = payload._ioInfo; null != _ioInfo && (_ioInfo.end = performance.now()); void 0 === thenable.status && (thenable.status = "fulfilled", thenable.value = moduleObject); } }, function(error) { if (0 === payload._status || -1 === payload._status) { payload._status = 2; payload._result = error; var _ioInfo2 = payload._ioInfo; null != _ioInfo2 && (_ioInfo2.end = performance.now()); void 0 === thenable.status && (thenable.status = "rejected", thenable.reason = error); } } ); ioInfo = payload._ioInfo; if (null != ioInfo) { ioInfo.value = thenable; var displayName = thenable.displayName; "string" === typeof displayName && (ioInfo.name = displayName); } -1 === payload._status && (payload._status = 0, payload._result = thenable); } if (1 === payload._status) return ioInfo = payload._result, void 0 === ioInfo && console.error( "lazy: Expected the result of a dynamic import() call. Instead received: %s\n\nYour code should look like: \n const MyComponent = lazy(() => import('./MyComponent'))\n\nDid you accidentally put curly braces around the import?", ioInfo ), "default" in ioInfo || console.error( "lazy: Expected the result of a dynamic import() call. Instead received: %s\n\nYour code should look like: \n const MyComponent = lazy(() => import('./MyComponent'))", ioInfo ), ioInfo.default; throw payload._result; } function resolveDispatcher() { var dispatcher = ReactSharedInternals.H; null === dispatcher && console.error( "Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem." ); return dispatcher; } function releaseAsyncTransition() { ReactSharedInternals.asyncTransitions--; } function enqueueTask(task) { if (null === enqueueTaskImpl) try { var requireString = ("require" + Math.random()).slice(0, 7); enqueueTaskImpl = (module && module[requireString]).call( module, "timers" ).setImmediate; } catch (_err) { enqueueTaskImpl = function(callback) { false === didWarnAboutMessageChannel && (didWarnAboutMessageChannel = true, "undefined" === typeof MessageChannel && console.error( "This browser does not have a MessageChannel implementation, so enqueuing tasks via await act(async () => ...) will fail. Please file an issue at https://github.com/facebook/react/issues if you encounter this warning." )); var channel = new MessageChannel(); channel.port1.onmessage = callback; channel.port2.postMessage(void 0); }; } return enqueueTaskImpl(task); } function aggregateErrors(errors) { return 1 < errors.length && "function" === typeof AggregateError ? new AggregateError(errors) : errors[0]; } function popActScope(prevActQueue, prevActScopeDepth) { prevActScopeDepth !== actScopeDepth - 1 && console.error( "You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one. " ); actScopeDepth = prevActScopeDepth; } function recursivelyFlushAsyncActWork(returnValue, resolve, reject) { var queue = ReactSharedInternals.actQueue; if (null !== queue) if (0 !== queue.length) try { flushActQueue(queue); enqueueTask(function() { return recursivelyFlushAsyncActWork(returnValue, resolve, reject); }); return; } catch (error) { ReactSharedInternals.thrownErrors.push(error); } else ReactSharedInternals.actQueue = null; 0 < ReactSharedInternals.thrownErrors.length ? (queue = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, reject(queue)) : resolve(returnValue); } function flushActQueue(queue) { if (!isFlushing) { isFlushing = true; var i = 0; try { for (; i < queue.length; i++) { var callback = queue[i]; do { ReactSharedInternals.didUsePromise = false; var continuation = callback(false); if (null !== continuation) { if (ReactSharedInternals.didUsePromise) { queue[i] = callback; queue.splice(0, i); return; } callback = continuation; } else break; } while (1); } queue.length = 0; } catch (error) { queue.splice(0, i + 1), ReactSharedInternals.thrownErrors.push(error); } finally { isFlushing = false; } } } "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error()); var REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = /* @__PURE__ */ Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = /* @__PURE__ */ Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = /* @__PURE__ */ Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = /* @__PURE__ */ Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = /* @__PURE__ */ Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = /* @__PURE__ */ Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = /* @__PURE__ */ Symbol.for("react.memo"), REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy"), REACT_ACTIVITY_TYPE = /* @__PURE__ */ Symbol.for("react.activity"), MAYBE_ITERATOR_SYMBOL = Symbol.iterator, didWarnStateUpdateForUnmountedComponent = {}, ReactNoopUpdateQueue = { isMounted: function() { return false; }, enqueueForceUpdate: function(publicInstance) { warnNoop(publicInstance, "forceUpdate"); }, enqueueReplaceState: function(publicInstance) { warnNoop(publicInstance, "replaceState"); }, enqueueSetState: function(publicInstance) { warnNoop(publicInstance, "setState"); } }, assign = Object.assign, emptyObject = {}; Object.freeze(emptyObject); Component.prototype.isReactComponent = {}; Component.prototype.setState = function(partialState, callback) { if ("object" !== typeof partialState && "function" !== typeof partialState && null != partialState) throw Error( "takes an object of state variables to update or a function which returns an object of state variables." ); this.updater.enqueueSetState(this, partialState, callback, "setState"); }; Component.prototype.forceUpdate = function(callback) { this.updater.enqueueForceUpdate(this, callback, "forceUpdate"); }; var deprecatedAPIs = { isMounted: [ "isMounted", "Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks." ], replaceState: [ "replaceState", "Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)." ] }; for (fnName in deprecatedAPIs) deprecatedAPIs.hasOwnProperty(fnName) && defineDeprecationWarning(fnName, deprecatedAPIs[fnName]); ComponentDummy.prototype = Component.prototype; deprecatedAPIs = PureComponent.prototype = new ComponentDummy(); deprecatedAPIs.constructor = PureComponent; assign(deprecatedAPIs, Component.prototype); deprecatedAPIs.isPureReactComponent = true; var isArrayImpl = Array.isArray, REACT_CLIENT_REFERENCE = /* @__PURE__ */ Symbol.for("react.client.reference"), ReactSharedInternals = { H: null, A: null, T: null, S: null, actQueue: null, asyncTransitions: 0, isBatchingLegacy: false, didScheduleLegacyUpdate: false, didUsePromise: false, thrownErrors: [], getCurrentStack: null, recentlyCreatedOwnerStacks: 0 }, hasOwnProperty2 = Object.prototype.hasOwnProperty, createTask = console.createTask ? console.createTask : function() { return null; }; deprecatedAPIs = { react_stack_bottom_frame: function(callStackForError) { return callStackForError(); } }; var specialPropKeyWarningShown, didWarnAboutOldJSXRuntime; var didWarnAboutElementRef = {}; var unknownOwnerDebugStack = deprecatedAPIs.react_stack_bottom_frame.bind( deprecatedAPIs, UnknownOwner )(); var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner)); var didWarnAboutMaps = false, userProvidedKeyEscapeRegex = /\/+/g, reportGlobalError = "function" === typeof reportError ? reportError : function(error) { if ("object" === typeof window && "function" === typeof window.ErrorEvent) { var event = new window.ErrorEvent("error", { bubbles: true, cancelable: true, message: "object" === typeof error && null !== error && "string" === typeof error.message ? String(error.message) : String(error), error }); if (!window.dispatchEvent(event)) return; } else if ("object" === typeof process && "function" === typeof process.emit) { process.emit("uncaughtException", error); return; } console.error(error); }, didWarnAboutMessageChannel = false, enqueueTaskImpl = null, actScopeDepth = 0, didWarnNoAwaitAct = false, isFlushing = false, queueSeveralMicrotasks = "function" === typeof queueMicrotask ? function(callback) { queueMicrotask(function() { return queueMicrotask(callback); }); } : enqueueTask; deprecatedAPIs = Object.freeze({ __proto__: null, c: function(size2) { return resolveDispatcher().useMemoCache(size2); } }); var fnName = { map: mapChildren2, forEach: function(children, forEachFunc, forEachContext) { mapChildren2( children, function() { forEachFunc.apply(this, arguments); }, forEachContext ); }, count: function(children) { var n = 0; mapChildren2(children, function() { n++; }); return n; }, toArray: function(children) { return mapChildren2(children, function(child) { return child; }) || []; }, only: function(children) { if (!isValidElement(children)) throw Error( "React.Children.only expected to receive a single React element child." ); return children; } }; exports$1.Activity = REACT_ACTIVITY_TYPE; exports$1.Children = fnName; exports$1.Component = Component; exports$1.Fragment = REACT_FRAGMENT_TYPE; exports$1.Profiler = REACT_PROFILER_TYPE; exports$1.PureComponent = PureComponent; exports$1.StrictMode = REACT_STRICT_MODE_TYPE; exports$1.Suspense = REACT_SUSPENSE_TYPE; exports$1.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = ReactSharedInternals; exports$1.__COMPILER_RUNTIME = deprecatedAPIs; exports$1.act = function(callback) { var prevActQueue = ReactSharedInternals.actQueue, prevActScopeDepth = actScopeDepth; actScopeDepth++; var queue = ReactSharedInternals.actQueue = null !== prevActQueue ? prevActQueue : [], didAwaitActCall = false; try { var result = callback(); } catch (error) { ReactSharedInternals.thrownErrors.push(error); } if (0 < ReactSharedInternals.thrownErrors.length) throw popActScope(prevActQueue, prevActScopeDepth), callback = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, callback; if (null !== result && "object" === typeof result && "function" === typeof result.then) { var thenable = result; queueSeveralMicrotasks(function() { didAwaitActCall || didWarnNoAwaitAct || (didWarnNoAwaitAct = true, console.error( "You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);" )); }); return { then: function(resolve, reject) { didAwaitActCall = true; thenable.then( function(returnValue) { popActScope(prevActQueue, prevActScopeDepth); if (0 === prevActScopeDepth) { try { flushActQueue(queue), enqueueTask(function() { return recursivelyFlushAsyncActWork( returnValue, resolve, reject ); }); } catch (error$0) { ReactSharedInternals.thrownErrors.push(error$0); } if (0 < ReactSharedInternals.thrownErrors.length) { var _thrownError = aggregateErrors( ReactSharedInternals.thrownErrors ); ReactSharedInternals.thrownErrors.length = 0; reject(_thrownError); } } else resolve(returnValue); }, function(error) { popActScope(prevActQueue, prevActScopeDepth); 0 < ReactSharedInternals.thrownErrors.length ? (error = aggregateErrors( ReactSharedInternals.thrownErrors ), ReactSharedInternals.thrownErrors.length = 0, reject(error)) : reject(error); } ); } }; } var returnValue$jscomp$0 = result; popActScope(prevActQueue, prevActScopeDepth); 0 === prevActScopeDepth && (flushActQueue(queue), 0 !== queue.length && queueSeveralMicrotasks(function() { didAwaitActCall || didWarnNoAwaitAct || (didWarnNoAwaitAct = true, console.error( "A component suspended inside an `act` scope, but the `act` call was not awaited. When testing React components that depend on asynchronous data, you must await the result:\n\nawait act(() => ...)" )); }), ReactSharedInternals.actQueue = null); if (0 < ReactSharedInternals.thrownErrors.length) throw callback = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, callback; return { then: function(resolve, reject) { didAwaitActCall = true; 0 === prevActScopeDepth ? (ReactSharedInternals.actQueue = queue, enqueueTask(function() { return recursivelyFlushAsyncActWork( returnValue$jscomp$0, resolve, reject ); })) : resolve(returnValue$jscomp$0); } }; }; exports$1.cache = function(fn) { return function() { return fn.apply(null, arguments); }; }; exports$1.cacheSignal = function() { return null; }; exports$1.captureOwnerStack = function() { var getCurrentStack = ReactSharedInternals.getCurrentStack; return null === getCurrentStack ? null : getCurrentStack(); }; exports$1.cloneElement = function(element, config, children) { if (null === element || void 0 === element) throw Error( "The argument must be a React element, but you passed " + element + "." ); var props = assign({}, element.props), key = element.key, owner = element._owner; if (null != config) { var JSCompiler_inline_result; a: { if (hasOwnProperty2.call(config, "ref") && (JSCompiler_inline_result = Object.getOwnPropertyDescriptor( config, "ref" ).get) && JSCompiler_inline_result.isReactWarning) { JSCompiler_inline_result = false; break a; } JSCompiler_inline_result = void 0 !== config.ref; } JSCompiler_inline_result && (owner = getOwner()); hasValidKey(config) && (checkKeyStringCoercion(config.key), key = "" + config.key); for (propName in config) !hasOwnProperty2.call(config, propName) || "key" === propName || "__self" === propName || "__source" === propName || "ref" === propName && void 0 === config.ref || (props[propName] = config[propName]); } var propName = arguments.length - 2; if (1 === propName) props.children = children; else if (1 < propName) { JSCompiler_inline_result = Array(propName); for (var i = 0; i < propName; i++) JSCompiler_inline_result[i] = arguments[i + 2]; props.children = JSCompiler_inline_result; } props = ReactElement( element.type, key, props, owner, element._debugStack, element._debugTask ); for (key = 2; key < arguments.length; key++) validateChildKeys(arguments[key]); return props; }; exports$1.createContext = function(defaultValue) { defaultValue = { $$typeof: REACT_CONTEXT_TYPE, _currentValue: defaultValue, _currentValue2: defaultValue, _threadCount: 0, Provider: null, Consumer: null }; defaultValue.Provider = defaultValue; defaultValue.Consumer = { $$typeof: REACT_CONSUMER_TYPE, _context: defaultValue }; defaultValue._currentRenderer = null; defaultValue._currentRenderer2 = null; return defaultValue; }; exports$1.createElement = function(type, config, children) { for (var i = 2; i < arguments.length; i++) validateChildKeys(arguments[i]); i = {}; var key = null; if (null != config) for (propName in didWarnAboutOldJSXRuntime || !("__self" in config) || "key" in config || (didWarnAboutOldJSXRuntime = true, console.warn( "Your app (or one of its dependencies) is using an outdated JSX transform. Update to the modern JSX transform for faster performance: https://react.dev/link/new-jsx-transform" )), hasValidKey(config) && (checkKeyStringCoercion(config.key), key = "" + config.key), config) hasOwnProperty2.call(config, propName) && "key" !== propName && "__self" !== propName && "__source" !== propName && (i[propName] = config[propName]); var childrenLength = arguments.length - 2; if (1 === childrenLength) i.children = children; else if (1 < childrenLength) { for (var childArray = Array(childrenLength), _i = 0; _i < childrenLength; _i++) childArray[_i] = arguments[_i + 2]; Object.freeze && Object.freeze(childArray); i.children = childArray; } if (type && type.defaultProps) for (propName in childrenLength = type.defaultProps, childrenLength) void 0 === i[propName] && (i[propName] = childrenLength[propName]); key && defineKeyPropWarningGetter( i, "function" === typeof type ? type.displayName || type.name || "Unknown" : type ); var propName = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++; return ReactElement( type, key, i, getOwner(), propName ? Error("react-stack-top-frame") : unknownOwnerDebugStack, propName ? createTask(getTaskName(type)) : unknownOwnerDebugTask ); }; exports$1.createRef = function() { var refObject = { current: null }; Object.seal(refObject); return refObject; }; exports$1.forwardRef = function(render) { null != render && render.$$typeof === REACT_MEMO_TYPE ? console.error( "forwardRef requires a render function but received a `memo` component. Instead of forwardRef(memo(...)), use memo(forwardRef(...))." ) : "function" !== typeof render ? console.error( "forwardRef requires a render function but was given %s.", null === render ? "null" : typeof render ) : 0 !== render.length && 2 !== render.length && console.error( "forwardRef render functions accept exactly two parameters: props and ref. %s", 1 === render.length ? "Did you forget to use the ref parameter?" : "Any additional parameter will be undefined." ); null != render && null != render.defaultProps && console.error( "forwardRef render functions do not support defaultProps. Did you accidentally pass a React component?" ); var elementType = { $$typeof: REACT_FORWARD_REF_TYPE, render }, ownName; Object.defineProperty(elementType, "displayName", { enumerable: false, configurable: true, get: function() { return ownName; }, set: function(name) { ownName = name; render.name || render.displayName || (Object.defineProperty(render, "name", { value: name }), render.displayName = name); } }); return elementType; }; exports$1.isValidElement = isValidElement; exports$1.lazy = function(ctor) { ctor = { _status: -1, _result: ctor }; var lazyType = { $$typeof: REACT_LAZY_TYPE, _payload: ctor, _init: lazyInitializer }, ioInfo = { name: "lazy", start: -1, end: -1, value: null, owner: null, debugStack: Error("react-stack-top-frame"), debugTask: console.createTask ? console.createTask("lazy()") : null }; ctor._ioInfo = ioInfo; lazyType._debugInfo = [{ awaited: ioInfo }]; return lazyType; }; exports$1.memo = function(type, compare) { null == type && console.error( "memo: The first argument must be a component. Instead received: %s", null === type ? "null" : typeof type ); compare = { $$typeof: REACT_MEMO_TYPE, type, compare: void 0 === compare ? null : compare }; var ownName; Object.defineProperty(compare, "displayName", { enumerable: false, configurable: true, get: function() { return ownName; }, set: function(name) { ownName = name; type.name || type.displayName || (Object.defineProperty(type, "name", { value: name }), type.displayName = name); } }); return compare; }; exports$1.startTransition = function(scope) { var prevTransition = ReactSharedInternals.T, currentTransition = {}; currentTransition._updatedFibers = /* @__PURE__ */ new Set(); ReactSharedInternals.T = currentTransition; try { var returnValue = scope(), onStartTransitionFinish = ReactSharedInternals.S; null !== onStartTransitionFinish && onStartTransitionFinish(currentTransition, returnValue); "object" === typeof returnValue && null !== returnValue && "function" === typeof returnValue.then && (ReactSharedInternals.asyncTransitions++, returnValue.then(releaseAsyncTransition, releaseAsyncTransition), returnValue.then(noop2, reportGlobalError)); } catch (error) { reportGlobalError(error); } finally { null === prevTransition && currentTransition._updatedFibers && (scope = currentTransition._updatedFibers.size, currentTransition._updatedFibers.clear(), 10 < scope && console.warn( "Detected a large number of updates inside startTransition. If this is due to a subscription please re-write it to use React provided hooks. Otherwise concurrent mode guarantees are off the table." )), null !== prevTransition && null !== currentTransition.types && (null !== prevTransition.types && prevTransition.types !== currentTransition.types && console.error( "We expected inner Transitions to have transferred the outer types set and that you cannot add to the outer Transition while inside the inner.This is a bug in React." ), prevTransition.types = currentTransition.types), ReactSharedInternals.T = prevTransition; } }; exports$1.unstable_useCacheRefresh = function() { return resolveDispatcher().useCacheRefresh(); }; exports$1.use = function(usable) { return resolveDispatcher().use(usable); }; exports$1.useActionState = function(action, initialState, permalink) { return resolveDispatcher().useActionState( action, initialState, permalink ); }; exports$1.useCallback = function(callback, deps) { return resolveDispatcher().useCallback(callback, deps); }; exports$1.useContext = function(Context) { var dispatcher = resolveDispatcher(); Context.$$typeof === REACT_CONSUMER_TYPE && console.error( "Calling useContext(Context.Consumer) is not supported and will cause bugs. Did you mean to call useContext(Context) instead?" ); return dispatcher.useContext(Context); }; exports$1.useDebugValue = function(value, formatterFn) { return resolveDispatcher().useDebugValue(value, formatterFn); }; exports$1.useDeferredValue = function(value, initialValue) { return resolveDispatcher().useDeferredValue(value, initialValue); }; exports$1.useEffect = function(create, deps) { null == create && console.warn( "React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?" ); return resolveDispatcher().useEffect(create, deps); }; exports$1.useEffectEvent = function(callback) { return resolveDispatcher().useEffectEvent(callback); }; exports$1.useId = function() { return resolveDispatcher().useId(); }; exports$1.useImperativeHandle = function(ref, create, deps) { return resolveDispatcher().useImperativeHandle(ref, create, deps); }; exports$1.useInsertionEffect = function(create, deps) { null == create && console.warn( "React Hook useInsertionEffect requires an effect callback. Did you forget to pass a callback to the hook?" ); return resolveDispatcher().useInsertionEffect(create, deps); }; exports$1.useLayoutEffect = function(create, deps) { null == create && console.warn( "React Hook useLayoutEffect requires an effect callback. Did you forget to pass a callback to the hook?" ); return resolveDispatcher().useLayoutEffect(create, deps); }; exports$1.useMemo = function(create, deps) { return resolveDispatcher().useMemo(create, deps); }; exports$1.useOptimistic = function(passthrough, reducer) { return resolveDispatcher().useOptimistic(passthrough, reducer); }; exports$1.useReducer = function(reducer, initialArg, init2) { return resolveDispatcher().useReducer(reducer, initialArg, init2); }; exports$1.useRef = function(initialValue) { return resolveDispatcher().useRef(initialValue); }; exports$1.useState = function(initialState) { return resolveDispatcher().useState(initialState); }; exports$1.useSyncExternalStore = function(subscribe, getSnapshot, getServerSnapshot) { return resolveDispatcher().useSyncExternalStore( subscribe, getSnapshot, getServerSnapshot ); }; exports$1.useTransition = function() { return resolveDispatcher().useTransition(); }; exports$1.version = "19.2.4"; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error()); })(); })(react_development, react_development.exports); return react_development.exports; } var hasRequiredReact; function requireReact() { if (hasRequiredReact) return react.exports; hasRequiredReact = 1; if (process.env.NODE_ENV === "production") { react.exports = requireReact_production(); } else { react.exports = requireReact_development(); } return react.exports; } var reactExports = requireReact(); const React = /* @__PURE__ */ getDefaultExportFromCjs(reactExports); var reactDom = { exports: {} }; var reactDom_production = {}; var hasRequiredReactDom_production; function requireReactDom_production() { if (hasRequiredReactDom_production) return reactDom_production; hasRequiredReactDom_production = 1; var React2 = requireReact(); function formatProdErrorMessage(code) { var url = "https://react.dev/errors/" + code; if (1 < arguments.length) { url += "?args[]=" + encodeURIComponent(arguments[1]); for (var i = 2; i < arguments.length; i++) url += "&args[]=" + encodeURIComponent(arguments[i]); } return "Minified React error #" + code + "; visit " + url + " for the full message or use the non-minified dev environment for full errors and additional helpful warnings."; } function noop2() { } var Internals = { d: { f: noop2, r: function() { throw Error(formatProdErrorMessage(522)); }, D: noop2, C: noop2, L: noop2, m: noop2, X: noop2, S: noop2, M: noop2 }, p: 0, findDOMNode: null }, REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal"); function createPortal$1(children, containerInfo, implementation) { var key = 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : null; return { $$typeof: REACT_PORTAL_TYPE, key: null == key ? null : "" + key, children, containerInfo, implementation }; } var ReactSharedInternals = React2.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE; function getCrossOriginStringAs(as, input) { if ("font" === as) return ""; if ("string" === typeof input) return "use-credentials" === input ? input : ""; } reactDom_production.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = Internals; reactDom_production.createPortal = function(children, container) { var key = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : null; if (!container || 1 !== container.nodeType && 9 !== container.nodeType && 11 !== container.nodeType) throw Error(formatProdErrorMessage(299)); return createPortal$1(children, container, null, key); }; reactDom_production.flushSync = function(fn) { var previousTransition = ReactSharedInternals.T, previousUpdatePriority = Internals.p; try { if (ReactSharedInternals.T = null, Internals.p = 2, fn) return fn(); } finally { ReactSharedInternals.T = previousTransition, Internals.p = previousUpdatePriority, Internals.d.f(); } }; reactDom_production.preconnect = function(href, options) { "string" === typeof href && (options ? (options = options.crossOrigin, options = "string" === typeof options ? "use-credentials" === options ? options : "" : void 0) : options = null, Internals.d.C(href, options)); }; reactDom_production.prefetchDNS = function(href) { "string" === typeof href && Internals.d.D(href); }; reactDom_production.preinit = function(href, options) { if ("string" === typeof href && options && "string" === typeof options.as) { var as = options.as, crossOrigin = getCrossOriginStringAs(as, options.crossOrigin), integrity = "string" === typeof options.integrity ? options.integrity : void 0, fetchPriority = "string" === typeof options.fetchPriority ? options.fetchPriority : void 0; "style" === as ? Internals.d.S( href, "string" === typeof options.precedence ? options.precedence : void 0, { crossOrigin, integrity, fetchPriority } ) : "script" === as && Internals.d.X(href, { crossOrigin, integrity, fetchPriority, nonce: "string" === typeof options.nonce ? options.nonce : void 0 }); } }; reactDom_production.preinitModule = function(href, options) { if ("string" === typeof href) if ("object" === typeof options && null !== options) { if (null == options.as || "script" === options.as) { var crossOrigin = getCrossOriginStringAs( options.as, options.crossOrigin ); Internals.d.M(href, { crossOrigin, integrity: "string" === typeof options.integrity ? options.integrity : void 0, nonce: "string" === typeof options.nonce ? options.nonce : void 0 }); } } else null == options && Internals.d.M(href); }; reactDom_production.preload = function(href, options) { if ("string" === typeof href && "object" === typeof options && null !== options && "string" === typeof options.as) { var as = options.as, crossOrigin = getCrossOriginStringAs(as, options.crossOrigin); Internals.d.L(href, as, { crossOrigin, integrity: "string" === typeof options.integrity ? options.integrity : void 0, nonce: "string" === typeof options.nonce ? options.nonce : void 0, type: "string" === typeof options.type ? options.type : void 0, fetchPriority: "string" === typeof options.fetchPriority ? options.fetchPriority : void 0, referrerPolicy: "string" === typeof options.referrerPolicy ? options.referrerPolicy : void 0, imageSrcSet: "string" === typeof options.imageSrcSet ? options.imageSrcSet : void 0, imageSizes: "string" === typeof options.imageSizes ? options.imageSizes : void 0, media: "string" === typeof options.media ? options.media : void 0 }); } }; reactDom_production.preloadModule = function(href, options) { if ("string" === typeof href) if (options) { var crossOrigin = getCrossOriginStringAs(options.as, options.crossOrigin); Internals.d.m(href, { as: "string" === typeof options.as && "script" !== options.as ? options.as : void 0, crossOrigin, integrity: "string" === typeof options.integrity ? options.integrity : void 0 }); } else Internals.d.m(href); }; reactDom_production.requestFormReset = function(form) { Internals.d.r(form); }; reactDom_production.unstable_batchedUpdates = function(fn, a) { return fn(a); }; reactDom_production.useFormState = function(action, initialState, permalink) { return ReactSharedInternals.H.useFormState(action, initialState, permalink); }; reactDom_production.useFormStatus = function() { return ReactSharedInternals.H.useHostTransitionStatus(); }; reactDom_production.version = "19.2.4"; return reactDom_production; } var reactDom_development = {}; var hasRequiredReactDom_development; function requireReactDom_development() { if (hasRequiredReactDom_development) return reactDom_development; hasRequiredReactDom_development = 1; "production" !== process.env.NODE_ENV && (function() { function noop2() { } function testStringCoercion(value) { return "" + value; } function createPortal$1(children, containerInfo, implementation) { var key = 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : null; try { testStringCoercion(key); var JSCompiler_inline_result = false; } catch (e) { JSCompiler_inline_result = true; } JSCompiler_inline_result && (console.error( "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", "function" === typeof Symbol && Symbol.toStringTag && key[Symbol.toStringTag] || key.constructor.name || "Object" ), testStringCoercion(key)); return { $$typeof: REACT_PORTAL_TYPE, key: null == key ? null : "" + key, children, containerInfo, implementation }; } function getCrossOriginStringAs(as, input) { if ("font" === as) return ""; if ("string" === typeof input) return "use-credentials" === input ? input : ""; } function getValueDescriptorExpectingObjectForWarning(thing) { return null === thing ? "`null`" : void 0 === thing ? "`undefined`" : "" === thing ? "an empty string" : 'something with type "' + typeof thing + '"'; } function getValueDescriptorExpectingEnumForWarning(thing) { return null === thing ? "`null`" : void 0 === thing ? "`undefined`" : "" === thing ? "an empty string" : "string" === typeof thing ? JSON.stringify(thing) : "number" === typeof thing ? "`" + thing + "`" : 'something with type "' + typeof thing + '"'; } function resolveDispatcher() { var dispatcher = ReactSharedInternals.H; null === dispatcher && console.error( "Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem." ); return dispatcher; } "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error()); var React2 = requireReact(), Internals = { d: { f: noop2, r: function() { throw Error( "Invalid form element. requestFormReset must be passed a form that was rendered by React." ); }, D: noop2, C: noop2, L: noop2, m: noop2, X: noop2, S: noop2, M: noop2 }, p: 0, findDOMNode: null }, REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal"), ReactSharedInternals = React2.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE; "function" === typeof Map && null != Map.prototype && "function" === typeof Map.prototype.forEach && "function" === typeof Set && null != Set.prototype && "function" === typeof Set.prototype.clear && "function" === typeof Set.prototype.forEach || console.error( "React depends on Map and Set built-in types. Make sure that you load a polyfill in older browsers. https://reactjs.org/link/react-polyfills" ); reactDom_development.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = Internals; reactDom_development.createPortal = function(children, container) { var key = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : null; if (!container || 1 !== container.nodeType && 9 !== container.nodeType && 11 !== container.nodeType) throw Error("Target container is not a DOM element."); return createPortal$1(children, container, null, key); }; reactDom_development.flushSync = function(fn) { var previousTransition = ReactSharedInternals.T, previousUpdatePriority = Internals.p; try { if (ReactSharedInternals.T = null, Internals.p = 2, fn) return fn(); } finally { ReactSharedInternals.T = previousTransition, Internals.p = previousUpdatePriority, Internals.d.f() && console.error( "flushSync was called from inside a lifecycle method. React cannot flush when React is already rendering. Consider moving this call to a scheduler task or micro task." ); } }; reactDom_development.preconnect = function(href, options) { "string" === typeof href && href ? null != options && "object" !== typeof options ? console.error( "ReactDOM.preconnect(): Expected the `options` argument (second) to be an object but encountered %s instead. The only supported option at this time is `crossOrigin` which accepts a string.", getValueDescriptorExpectingEnumForWarning(options) ) : null != options && "string" !== typeof options.crossOrigin && console.error( "ReactDOM.preconnect(): Expected the `crossOrigin` option (second argument) to be a string but encountered %s instead. Try removing this option or passing a string value instead.", getValueDescriptorExpectingObjectForWarning(options.crossOrigin) ) : console.error( "ReactDOM.preconnect(): Expected the `href` argument (first) to be a non-empty string but encountered %s instead.", getValueDescriptorExpectingObjectForWarning(href) ); "string" === typeof href && (options ? (options = options.crossOrigin, options = "string" === typeof options ? "use-credentials" === options ? options : "" : void 0) : options = null, Internals.d.C(href, options)); }; reactDom_development.prefetchDNS = function(href) { if ("string" !== typeof href || !href) console.error( "ReactDOM.prefetchDNS(): Expected the `href` argument (first) to be a non-empty string but encountered %s instead.", getValueDescriptorExpectingObjectForWarning(href) ); else if (1 < arguments.length) { var options = arguments[1]; "object" === typeof options && options.hasOwnProperty("crossOrigin") ? console.error( "ReactDOM.prefetchDNS(): Expected only one argument, `href`, but encountered %s as a second argument instead. This argument is reserved for future options and is currently disallowed. It looks like the you are attempting to set a crossOrigin property for this DNS lookup hint. Browsers do not perform DNS queries using CORS and setting this attribute on the resource hint has no effect. Try calling ReactDOM.prefetchDNS() with just a single string argument, `href`.", getValueDescriptorExpectingEnumForWarning(options) ) : console.error( "ReactDOM.prefetchDNS(): Expected only one argument, `href`, but encountered %s as a second argument instead. This argument is reserved for future options and is currently disallowed. Try calling ReactDOM.prefetchDNS() with just a single string argument, `href`.", getValueDescriptorExpectingEnumForWarning(options) ); } "string" === typeof href && Internals.d.D(href); }; reactDom_development.preinit = function(href, options) { "string" === typeof href && href ? null == options || "object" !== typeof options ? console.error( "ReactDOM.preinit(): Expected the `options` argument (second) to be an object with an `as` property describing the type of resource to be preinitialized but encountered %s instead.", getValueDescriptorExpectingEnumForWarning(options) ) : "style" !== options.as && "script" !== options.as && console.error( 'ReactDOM.preinit(): Expected the `as` property in the `options` argument (second) to contain a valid value describing the type of resource to be preinitialized but encountered %s instead. Valid values for `as` are "style" and "script".', getValueDescriptorExpectingEnumForWarning(options.as) ) : console.error( "ReactDOM.preinit(): Expected the `href` argument (first) to be a non-empty string but encountered %s instead.", getValueDescriptorExpectingObjectForWarning(href) ); if ("string" === typeof href && options && "string" === typeof options.as) { var as = options.as, crossOrigin = getCrossOriginStringAs(as, options.crossOrigin), integrity = "string" === typeof options.integrity ? options.integrity : void 0, fetchPriority = "string" === typeof options.fetchPriority ? options.fetchPriority : void 0; "style" === as ? Internals.d.S( href, "string" === typeof options.precedence ? options.precedence : void 0, { crossOrigin, integrity, fetchPriority } ) : "script" === as && Internals.d.X(href, { crossOrigin, integrity, fetchPriority, nonce: "string" === typeof options.nonce ? options.nonce : void 0 }); } }; reactDom_development.preinitModule = function(href, options) { var encountered = ""; "string" === typeof href && href || (encountered += " The `href` argument encountered was " + getValueDescriptorExpectingObjectForWarning(href) + "."); void 0 !== options && "object" !== typeof options ? encountered += " The `options` argument encountered was " + getValueDescriptorExpectingObjectForWarning(options) + "." : options && "as" in options && "script" !== options.as && (encountered += " The `as` option encountered was " + getValueDescriptorExpectingEnumForWarning(options.as) + "."); if (encountered) console.error( "ReactDOM.preinitModule(): Expected up to two arguments, a non-empty `href` string and, optionally, an `options` object with a valid `as` property.%s", encountered ); else switch (encountered = options && "string" === typeof options.as ? options.as : "script", encountered) { case "script": break; default: encountered = getValueDescriptorExpectingEnumForWarning(encountered), console.error( 'ReactDOM.preinitModule(): Currently the only supported "as" type for this function is "script" but received "%s" instead. This warning was generated for `href` "%s". In the future other module types will be supported, aligning with the import-attributes proposal. Learn more here: (https://github.com/tc39/proposal-import-attributes)', encountered, href ); } if ("string" === typeof href) if ("object" === typeof options && null !== options) { if (null == options.as || "script" === options.as) encountered = getCrossOriginStringAs( options.as, options.crossOrigin ), Internals.d.M(href, { crossOrigin: encountered, integrity: "string" === typeof options.integrity ? options.integrity : void 0, nonce: "string" === typeof options.nonce ? options.nonce : void 0 }); } else null == options && Internals.d.M(href); }; reactDom_development.preload = function(href, options) { var encountered = ""; "string" === typeof href && href || (encountered += " The `href` argument encountered was " + getValueDescriptorExpectingObjectForWarning(href) + "."); null == options || "object" !== typeof options ? encountered += " The `options` argument encountered was " + getValueDescriptorExpectingObjectForWarning(options) + "." : "string" === typeof options.as && options.as || (encountered += " The `as` option encountered was " + getValueDescriptorExpectingObjectForWarning(options.as) + "."); encountered && console.error( 'ReactDOM.preload(): Expected two arguments, a non-empty `href` string and an `options` object with an `as` property valid for a `` tag.%s', encountered ); if ("string" === typeof href && "object" === typeof options && null !== options && "string" === typeof options.as) { encountered = options.as; var crossOrigin = getCrossOriginStringAs( encountered, options.crossOrigin ); Internals.d.L(href, encountered, { crossOrigin, integrity: "string" === typeof options.integrity ? options.integrity : void 0, nonce: "string" === typeof options.nonce ? options.nonce : void 0, type: "string" === typeof options.type ? options.type : void 0, fetchPriority: "string" === typeof options.fetchPriority ? options.fetchPriority : void 0, referrerPolicy: "string" === typeof options.referrerPolicy ? options.referrerPolicy : void 0, imageSrcSet: "string" === typeof options.imageSrcSet ? options.imageSrcSet : void 0, imageSizes: "string" === typeof options.imageSizes ? options.imageSizes : void 0, media: "string" === typeof options.media ? options.media : void 0 }); } }; reactDom_development.preloadModule = function(href, options) { var encountered = ""; "string" === typeof href && href || (encountered += " The `href` argument encountered was " + getValueDescriptorExpectingObjectForWarning(href) + "."); void 0 !== options && "object" !== typeof options ? encountered += " The `options` argument encountered was " + getValueDescriptorExpectingObjectForWarning(options) + "." : options && "as" in options && "string" !== typeof options.as && (encountered += " The `as` option encountered was " + getValueDescriptorExpectingObjectForWarning(options.as) + "."); encountered && console.error( 'ReactDOM.preloadModule(): Expected two arguments, a non-empty `href` string and, optionally, an `options` object with an `as` property valid for a `` tag.%s', encountered ); "string" === typeof href && (options ? (encountered = getCrossOriginStringAs( options.as, options.crossOrigin ), Internals.d.m(href, { as: "string" === typeof options.as && "script" !== options.as ? options.as : void 0, crossOrigin: encountered, integrity: "string" === typeof options.integrity ? options.integrity : void 0 })) : Internals.d.m(href)); }; reactDom_development.requestFormReset = function(form) { Internals.d.r(form); }; reactDom_development.unstable_batchedUpdates = function(fn, a) { return fn(a); }; reactDom_development.useFormState = function(action, initialState, permalink) { return resolveDispatcher().useFormState(action, initialState, permalink); }; reactDom_development.useFormStatus = function() { return resolveDispatcher().useHostTransitionStatus(); }; reactDom_development.version = "19.2.4"; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error()); })(); return reactDom_development; } var hasRequiredReactDom; function requireReactDom() { if (hasRequiredReactDom) return reactDom.exports; hasRequiredReactDom = 1; function checkDCE() { if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === "undefined" || typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE !== "function") { return; } if (process.env.NODE_ENV !== "production") { throw new Error("^_^"); } try { __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(checkDCE); } catch (err) { console.error(err); } } if (process.env.NODE_ENV === "production") { checkDCE(); reactDom.exports = requireReactDom_production(); } else { reactDom.exports = requireReactDom_development(); } return reactDom.exports; } var reactDomExports = requireReactDom(); const ReactDOM = /* @__PURE__ */ getDefaultExportFromCjs(reactDomExports); var shim = { exports: {} }; var useSyncExternalStoreShim_production = {}; var hasRequiredUseSyncExternalStoreShim_production; function requireUseSyncExternalStoreShim_production() { if (hasRequiredUseSyncExternalStoreShim_production) return useSyncExternalStoreShim_production; hasRequiredUseSyncExternalStoreShim_production = 1; var React2 = requireReact(); function is(x, y) { return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y; } var objectIs = "function" === typeof Object.is ? Object.is : is, useState = React2.useState, useEffect = React2.useEffect, useLayoutEffect = React2.useLayoutEffect, useDebugValue = React2.useDebugValue; function useSyncExternalStore$2(subscribe, getSnapshot) { var value = getSnapshot(), _useState = useState({ inst: { value, getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1]; useLayoutEffect( function() { inst.value = value; inst.getSnapshot = getSnapshot; checkIfSnapshotChanged(inst) && forceUpdate({ inst }); }, [subscribe, value, getSnapshot] ); useEffect( function() { checkIfSnapshotChanged(inst) && forceUpdate({ inst }); return subscribe(function() { checkIfSnapshotChanged(inst) && forceUpdate({ inst }); }); }, [subscribe] ); useDebugValue(value); return value; } function checkIfSnapshotChanged(inst) { var latestGetSnapshot = inst.getSnapshot; inst = inst.value; try { var nextValue = latestGetSnapshot(); return !objectIs(inst, nextValue); } catch (error) { return true; } } function useSyncExternalStore$1(subscribe, getSnapshot) { return getSnapshot(); } var shim2 = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2; useSyncExternalStoreShim_production.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim2; return useSyncExternalStoreShim_production; } var useSyncExternalStoreShim_development = {}; var hasRequiredUseSyncExternalStoreShim_development; function requireUseSyncExternalStoreShim_development() { if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development; hasRequiredUseSyncExternalStoreShim_development = 1; "production" !== process.env.NODE_ENV && (function() { function is(x, y) { return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y; } function useSyncExternalStore$2(subscribe, getSnapshot) { didWarnOld18Alpha || void 0 === React2.startTransition || (didWarnOld18Alpha = true, console.error( "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release." )); var value = getSnapshot(); if (!didWarnUncachedGetSnapshot) { var cachedValue = getSnapshot(); objectIs(value, cachedValue) || (console.error( "The result of getSnapshot should be cached to avoid an infinite loop" ), didWarnUncachedGetSnapshot = true); } cachedValue = useState({ inst: { value, getSnapshot } }); var inst = cachedValue[0].inst, forceUpdate = cachedValue[1]; useLayoutEffect( function() { inst.value = value; inst.getSnapshot = getSnapshot; checkIfSnapshotChanged(inst) && forceUpdate({ inst }); }, [subscribe, value, getSnapshot] ); useEffect( function() { checkIfSnapshotChanged(inst) && forceUpdate({ inst }); return subscribe(function() { checkIfSnapshotChanged(inst) && forceUpdate({ inst }); }); }, [subscribe] ); useDebugValue(value); return value; } function checkIfSnapshotChanged(inst) { var latestGetSnapshot = inst.getSnapshot; inst = inst.value; try { var nextValue = latestGetSnapshot(); return !objectIs(inst, nextValue); } catch (error) { return true; } } function useSyncExternalStore$1(subscribe, getSnapshot) { return getSnapshot(); } "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error()); var React2 = requireReact(), objectIs = "function" === typeof Object.is ? Object.is : is, useState = React2.useState, useEffect = React2.useEffect, useLayoutEffect = React2.useLayoutEffect, useDebugValue = React2.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim2 = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2; useSyncExternalStoreShim_development.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim2; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error()); })(); return useSyncExternalStoreShim_development; } var hasRequiredShim; function requireShim() { if (hasRequiredShim) return shim.exports; hasRequiredShim = 1; if (process.env.NODE_ENV === "production") { shim.exports = requireUseSyncExternalStoreShim_production(); } else { shim.exports = requireUseSyncExternalStoreShim_development(); } return shim.exports; } var shimExports = requireShim(); var jsxRuntime = { exports: {} }; var reactJsxRuntime_production = {}; var hasRequiredReactJsxRuntime_production; function requireReactJsxRuntime_production() { if (hasRequiredReactJsxRuntime_production) return reactJsxRuntime_production; hasRequiredReactJsxRuntime_production = 1; var REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("react.transitional.element"), REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment"); function jsxProd(type, config, maybeKey) { var key = null; void 0 !== maybeKey && (key = "" + maybeKey); void 0 !== config.key && (key = "" + config.key); if ("key" in config) { maybeKey = {}; for (var propName in config) "key" !== propName && (maybeKey[propName] = config[propName]); } else maybeKey = config; config = maybeKey.ref; return { $$typeof: REACT_ELEMENT_TYPE, type, key, ref: void 0 !== config ? config : null, props: maybeKey }; } reactJsxRuntime_production.Fragment = REACT_FRAGMENT_TYPE; reactJsxRuntime_production.jsx = jsxProd; reactJsxRuntime_production.jsxs = jsxProd; return reactJsxRuntime_production; } var reactJsxRuntime_development = {}; var hasRequiredReactJsxRuntime_development; function requireReactJsxRuntime_development() { if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development; hasRequiredReactJsxRuntime_development = 1; "production" !== process.env.NODE_ENV && (function() { function getComponentNameFromType(type) { if (null == type) return null; if ("function" === typeof type) return type.$$typeof === REACT_CLIENT_REFERENCE ? null : type.displayName || type.name || null; if ("string" === typeof type) return type; switch (type) { case REACT_FRAGMENT_TYPE: return "Fragment"; case REACT_PROFILER_TYPE: return "Profiler"; case REACT_STRICT_MODE_TYPE: return "StrictMode"; case REACT_SUSPENSE_TYPE: return "Suspense"; case REACT_SUSPENSE_LIST_TYPE: return "SuspenseList"; case REACT_ACTIVITY_TYPE: return "Activity"; } if ("object" === typeof type) switch ("number" === typeof type.tag && console.error( "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue." ), type.$$typeof) { case REACT_PORTAL_TYPE: return "Portal"; case REACT_CONTEXT_TYPE: return type.displayName || "Context"; case REACT_CONSUMER_TYPE: return (type._context.displayName || "Context") + ".Consumer"; case REACT_FORWARD_REF_TYPE: var innerType = type.render; type = type.displayName; type || (type = innerType.displayName || innerType.name || "", type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef"); return type; case REACT_MEMO_TYPE: return innerType = type.displayName || null, null !== innerType ? innerType : getComponentNameFromType(type.type) || "Memo"; case REACT_LAZY_TYPE: innerType = type._payload; type = type._init; try { return getComponentNameFromType(type(innerType)); } catch (x) { } } return null; } function testStringCoercion(value) { return "" + value; } function checkKeyStringCoercion(value) { try { testStringCoercion(value); var JSCompiler_inline_result = false; } catch (e) { JSCompiler_inline_result = true; } if (JSCompiler_inline_result) { JSCompiler_inline_result = console; var JSCompiler_temp_const = JSCompiler_inline_result.error; var JSCompiler_inline_result$jscomp$0 = "function" === typeof Symbol && Symbol.toStringTag && value[Symbol.toStringTag] || value.constructor.name || "Object"; JSCompiler_temp_const.call( JSCompiler_inline_result, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", JSCompiler_inline_result$jscomp$0 ); return testStringCoercion(value); } } function getTaskName(type) { if (type === REACT_FRAGMENT_TYPE) return "<>"; if ("object" === typeof type && null !== type && type.$$typeof === REACT_LAZY_TYPE) return "<...>"; try { var name = getComponentNameFromType(type); return name ? "<" + name + ">" : "<...>"; } catch (x) { return "<...>"; } } function getOwner() { var dispatcher = ReactSharedInternals.A; return null === dispatcher ? null : dispatcher.getOwner(); } function UnknownOwner() { return Error("react-stack-top-frame"); } function hasValidKey(config) { if (hasOwnProperty2.call(config, "key")) { var getter = Object.getOwnPropertyDescriptor(config, "key").get; if (getter && getter.isReactWarning) return false; } return void 0 !== config.key; } function defineKeyPropWarningGetter(props, displayName) { function warnAboutAccessingKey() { specialPropKeyWarningShown || (specialPropKeyWarningShown = true, console.error( "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", displayName )); } warnAboutAccessingKey.isReactWarning = true; Object.defineProperty(props, "key", { get: warnAboutAccessingKey, configurable: true }); } function elementRefGetterWithDeprecationWarning() { var componentName = getComponentNameFromType(this.type); didWarnAboutElementRef[componentName] || (didWarnAboutElementRef[componentName] = true, console.error( "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release." )); componentName = this.props.ref; return void 0 !== componentName ? componentName : null; } function ReactElement(type, key, props, owner, debugStack, debugTask) { var refProp = props.ref; type = { $$typeof: REACT_ELEMENT_TYPE, type, key, props, _owner: owner }; null !== (void 0 !== refProp ? refProp : null) ? Object.defineProperty(type, "ref", { enumerable: false, get: elementRefGetterWithDeprecationWarning }) : Object.defineProperty(type, "ref", { enumerable: false, value: null }); type._store = {}; Object.defineProperty(type._store, "validated", { configurable: false, enumerable: false, writable: true, value: 0 }); Object.defineProperty(type, "_debugInfo", { configurable: false, enumerable: false, writable: true, value: null }); Object.defineProperty(type, "_debugStack", { configurable: false, enumerable: false, writable: true, value: debugStack }); Object.defineProperty(type, "_debugTask", { configurable: false, enumerable: false, writable: true, value: debugTask }); Object.freeze && (Object.freeze(type.props), Object.freeze(type)); return type; } function jsxDEVImpl(type, config, maybeKey, isStaticChildren, debugStack, debugTask) { var children = config.children; if (void 0 !== children) if (isStaticChildren) if (isArrayImpl(children)) { for (isStaticChildren = 0; isStaticChildren < children.length; isStaticChildren++) validateChildKeys(children[isStaticChildren]); Object.freeze && Object.freeze(children); } else console.error( "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead." ); else validateChildKeys(children); if (hasOwnProperty2.call(config, "key")) { children = getComponentNameFromType(type); var keys2 = Object.keys(config).filter(function(k) { return "key" !== k; }); isStaticChildren = 0 < keys2.length ? "{key: someKey, " + keys2.join(": ..., ") + ": ...}" : "{key: someKey}"; didWarnAboutKeySpread[children + isStaticChildren] || (keys2 = 0 < keys2.length ? "{" + keys2.join(": ..., ") + ": ...}" : "{}", console.error( 'A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />', isStaticChildren, children, keys2, children ), didWarnAboutKeySpread[children + isStaticChildren] = true); } children = null; void 0 !== maybeKey && (checkKeyStringCoercion(maybeKey), children = "" + maybeKey); hasValidKey(config) && (checkKeyStringCoercion(config.key), children = "" + config.key); if ("key" in config) { maybeKey = {}; for (var propName in config) "key" !== propName && (maybeKey[propName] = config[propName]); } else maybeKey = config; children && defineKeyPropWarningGetter( maybeKey, "function" === typeof type ? type.displayName || type.name || "Unknown" : type ); return ReactElement( type, children, maybeKey, getOwner(), debugStack, debugTask ); } function validateChildKeys(node) { isValidElement(node) ? node._store && (node._store.validated = 1) : "object" === typeof node && null !== node && node.$$typeof === REACT_LAZY_TYPE && ("fulfilled" === node._payload.status ? isValidElement(node._payload.value) && node._payload.value._store && (node._payload.value._store.validated = 1) : node._store && (node._store.validated = 1)); } function isValidElement(object) { return "object" === typeof object && null !== object && object.$$typeof === REACT_ELEMENT_TYPE; } var React2 = requireReact(), REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = /* @__PURE__ */ Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = /* @__PURE__ */ Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = /* @__PURE__ */ Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = /* @__PURE__ */ Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = /* @__PURE__ */ Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = /* @__PURE__ */ Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = /* @__PURE__ */ Symbol.for("react.memo"), REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy"), REACT_ACTIVITY_TYPE = /* @__PURE__ */ Symbol.for("react.activity"), REACT_CLIENT_REFERENCE = /* @__PURE__ */ Symbol.for("react.client.reference"), ReactSharedInternals = React2.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, hasOwnProperty2 = Object.prototype.hasOwnProperty, isArrayImpl = Array.isArray, createTask = console.createTask ? console.createTask : function() { return null; }; React2 = { react_stack_bottom_frame: function(callStackForError) { return callStackForError(); } }; var specialPropKeyWarningShown; var didWarnAboutElementRef = {}; var unknownOwnerDebugStack = React2.react_stack_bottom_frame.bind( React2, UnknownOwner )(); var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner)); var didWarnAboutKeySpread = {}; reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE; reactJsxRuntime_development.jsx = function(type, config, maybeKey) { var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++; return jsxDEVImpl( type, config, maybeKey, false, trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack, trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask ); }; reactJsxRuntime_development.jsxs = function(type, config, maybeKey) { var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++; return jsxDEVImpl( type, config, maybeKey, true, trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack, trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask ); }; })(); return reactJsxRuntime_development; } var hasRequiredJsxRuntime; function requireJsxRuntime() { if (hasRequiredJsxRuntime) return jsxRuntime.exports; hasRequiredJsxRuntime = 1; if (process.env.NODE_ENV === "production") { jsxRuntime.exports = requireReactJsxRuntime_production(); } else { jsxRuntime.exports = requireReactJsxRuntime_development(); } return jsxRuntime.exports; } var jsxRuntimeExports = requireJsxRuntime(); function OrderedMap(content) { this.content = content; } OrderedMap.prototype = { constructor: OrderedMap, find: function(key) { for (var i = 0; i < this.content.length; i += 2) if (this.content[i] === key) return i; return -1; }, // :: (string) → ?any // Retrieve the value stored under `key`, or return undefined when // no such key exists. get: function(key) { var found2 = this.find(key); return found2 == -1 ? void 0 : this.content[found2 + 1]; }, // :: (string, any, ?string) → OrderedMap // Create a new map by replacing the value of `key` with a new // value, or adding a binding to the end of the map. If `newKey` is // given, the key of the binding will be replaced with that key. update: function(key, value, newKey) { var self2 = newKey && newKey != key ? this.remove(newKey) : this; var found2 = self2.find(key), content = self2.content.slice(); if (found2 == -1) { content.push(newKey || key, value); } else { content[found2 + 1] = value; if (newKey) content[found2] = newKey; } return new OrderedMap(content); }, // :: (string) → OrderedMap // Return a map with the given key removed, if it existed. remove: function(key) { var found2 = this.find(key); if (found2 == -1) return this; var content = this.content.slice(); content.splice(found2, 2); return new OrderedMap(content); }, // :: (string, any) → OrderedMap // Add a new key to the start of the map. addToStart: function(key, value) { return new OrderedMap([key, value].concat(this.remove(key).content)); }, // :: (string, any) → OrderedMap // Add a new key to the end of the map. addToEnd: function(key, value) { var content = this.remove(key).content.slice(); content.push(key, value); return new OrderedMap(content); }, // :: (string, string, any) → OrderedMap // Add a key after the given key. If `place` is not found, the new // key is added to the end. addBefore: function(place, key, value) { var without = this.remove(key), content = without.content.slice(); var found2 = without.find(place); content.splice(found2 == -1 ? content.length : found2, 0, key, value); return new OrderedMap(content); }, // :: ((key: string, value: any)) // Call the given function for each key/value pair in the map, in // order. forEach: function(f) { for (var i = 0; i < this.content.length; i += 2) f(this.content[i], this.content[i + 1]); }, // :: (union) → OrderedMap // Create a new map by prepending the keys in this map that don't // appear in `map` before the keys in `map`. prepend: function(map2) { map2 = OrderedMap.from(map2); if (!map2.size) return this; return new OrderedMap(map2.content.concat(this.subtract(map2).content)); }, // :: (union) → OrderedMap // Create a new map by appending the keys in this map that don't // appear in `map` after the keys in `map`. append: function(map2) { map2 = OrderedMap.from(map2); if (!map2.size) return this; return new OrderedMap(this.subtract(map2).content.concat(map2.content)); }, // :: (union) → OrderedMap // Create a map containing all the keys in this map that don't // appear in `map`. subtract: function(map2) { var result = this; map2 = OrderedMap.from(map2); for (var i = 0; i < map2.content.length; i += 2) result = result.remove(map2.content[i]); return result; }, // :: () → Object // Turn ordered map into a plain object. toObject: function() { var result = {}; this.forEach(function(key, value) { result[key] = value; }); return result; }, // :: number // The amount of keys in this map. get size() { return this.content.length >> 1; } }; OrderedMap.from = function(value) { if (value instanceof OrderedMap) return value; var content = []; if (value) for (var prop in value) content.push(prop, value[prop]); return new OrderedMap(content); }; function findDiffStart(a, b, pos) { for (let i = 0; ; i++) { if (i == a.childCount || i == b.childCount) return a.childCount == b.childCount ? null : pos; let childA = a.child(i), childB = b.child(i); if (childA == childB) { pos += childA.nodeSize; continue; } if (!childA.sameMarkup(childB)) return pos; if (childA.isText && childA.text != childB.text) { for (let j = 0; childA.text[j] == childB.text[j]; j++) pos++; return pos; } if (childA.content.size || childB.content.size) { let inner = findDiffStart(childA.content, childB.content, pos + 1); if (inner != null) return inner; } pos += childA.nodeSize; } } function findDiffEnd(a, b, posA, posB) { for (let iA = a.childCount, iB = b.childCount; ; ) { if (iA == 0 || iB == 0) return iA == iB ? null : { a: posA, b: posB }; let childA = a.child(--iA), childB = b.child(--iB), size2 = childA.nodeSize; if (childA == childB) { posA -= size2; posB -= size2; continue; } if (!childA.sameMarkup(childB)) return { a: posA, b: posB }; if (childA.isText && childA.text != childB.text) { let same = 0, minSize = Math.min(childA.text.length, childB.text.length); while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) { same++; posA--; posB--; } return { a: posA, b: posB }; } if (childA.content.size || childB.content.size) { let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1); if (inner) return inner; } posA -= size2; posB -= size2; } } class Fragment { /** @internal */ constructor(content, size2) { this.content = content; this.size = size2 || 0; if (size2 == null) for (let i = 0; i < content.length; i++) this.size += content[i].nodeSize; } /** Invoke a callback for all descendant nodes between the given two positions (relative to start of this fragment). Doesn't descend into a node when the callback returns `false`. */ nodesBetween(from2, to, f, nodeStart = 0, parent) { for (let i = 0, pos = 0; pos < to; i++) { let child = this.content[i], end = pos + child.nodeSize; if (end > from2 && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) { let start = pos + 1; child.nodesBetween(Math.max(0, from2 - start), Math.min(child.content.size, to - start), f, nodeStart + start); } pos = end; } } /** Call the given callback for every descendant node. `pos` will be relative to the start of the fragment. The callback may return `false` to prevent traversal of a given node's children. */ descendants(f) { this.nodesBetween(0, this.size, f); } /** Extract the text between `from` and `to`. See the same method on [`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween). */ textBetween(from2, to, blockSeparator, leafText) { let text = "", first2 = true; this.nodesBetween(from2, to, (node, pos) => { let nodeText = node.isText ? node.text.slice(Math.max(from2, pos) - pos, to - pos) : !node.isLeaf ? "" : leafText ? typeof leafText === "function" ? leafText(node) : leafText : node.type.spec.leafText ? node.type.spec.leafText(node) : ""; if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) { if (first2) first2 = false; else text += blockSeparator; } text += nodeText; }, 0); return text; } /** Create a new fragment containing the combined content of this fragment and the other. */ append(other) { if (!other.size) return this; if (!this.size) return other; let last = this.lastChild, first2 = other.firstChild, content = this.content.slice(), i = 0; if (last.isText && last.sameMarkup(first2)) { content[content.length - 1] = last.withText(last.text + first2.text); i = 1; } for (; i < other.content.length; i++) content.push(other.content[i]); return new Fragment(content, this.size + other.size); } /** Cut out the sub-fragment between the two given positions. */ cut(from2, to = this.size) { if (from2 == 0 && to == this.size) return this; let result = [], size2 = 0; if (to > from2) for (let i = 0, pos = 0; pos < to; i++) { let child = this.content[i], end = pos + child.nodeSize; if (end > from2) { if (pos < from2 || end > to) { if (child.isText) child = child.cut(Math.max(0, from2 - pos), Math.min(child.text.length, to - pos)); else child = child.cut(Math.max(0, from2 - pos - 1), Math.min(child.content.size, to - pos - 1)); } result.push(child); size2 += child.nodeSize; } pos = end; } return new Fragment(result, size2); } /** @internal */ cutByIndex(from2, to) { if (from2 == to) return Fragment.empty; if (from2 == 0 && to == this.content.length) return this; return new Fragment(this.content.slice(from2, to)); } /** Create a new fragment in which the node at the given index is replaced by the given node. */ replaceChild(index, node) { let current = this.content[index]; if (current == node) return this; let copy2 = this.content.slice(); let size2 = this.size + node.nodeSize - current.nodeSize; copy2[index] = node; return new Fragment(copy2, size2); } /** Create a new fragment by prepending the given node to this fragment. */ addToStart(node) { return new Fragment([node].concat(this.content), this.size + node.nodeSize); } /** Create a new fragment by appending the given node to this fragment. */ addToEnd(node) { return new Fragment(this.content.concat(node), this.size + node.nodeSize); } /** Compare this fragment to another one. */ eq(other) { if (this.content.length != other.content.length) return false; for (let i = 0; i < this.content.length; i++) if (!this.content[i].eq(other.content[i])) return false; return true; } /** The first child of the fragment, or `null` if it is empty. */ get firstChild() { return this.content.length ? this.content[0] : null; } /** The last child of the fragment, or `null` if it is empty. */ get lastChild() { return this.content.length ? this.content[this.content.length - 1] : null; } /** The number of child nodes in this fragment. */ get childCount() { return this.content.length; } /** Get the child node at the given index. Raise an error when the index is out of range. */ child(index) { let found2 = this.content[index]; if (!found2) throw new RangeError("Index " + index + " out of range for " + this); return found2; } /** Get the child node at the given index, if it exists. */ maybeChild(index) { return this.content[index] || null; } /** Call `f` for every child node, passing the node, its offset into this parent node, and its index. */ forEach(f) { for (let i = 0, p = 0; i < this.content.length; i++) { let child = this.content[i]; f(child, p, i); p += child.nodeSize; } } /** Find the first position at which this fragment and another fragment differ, or `null` if they are the same. */ findDiffStart(other, pos = 0) { return findDiffStart(this, other, pos); } /** Find the first position, searching from the end, at which this fragment and the given fragment differ, or `null` if they are the same. Since this position will not be the same in both nodes, an object with two separate positions is returned. */ findDiffEnd(other, pos = this.size, otherPos = other.size) { return findDiffEnd(this, other, pos, otherPos); } /** Find the index and inner offset corresponding to a given relative position in this fragment. The result object will be reused (overwritten) the next time the function is called. @internal */ findIndex(pos) { if (pos == 0) return retIndex(0, pos); if (pos == this.size) return retIndex(this.content.length, pos); if (pos > this.size || pos < 0) throw new RangeError(`Position ${pos} outside of fragment (${this})`); for (let i = 0, curPos = 0; ; i++) { let cur = this.child(i), end = curPos + cur.nodeSize; if (end >= pos) { if (end == pos) return retIndex(i + 1, end); return retIndex(i, curPos); } curPos = end; } } /** Return a debugging string that describes this fragment. */ toString() { return "<" + this.toStringInner() + ">"; } /** @internal */ toStringInner() { return this.content.join(", "); } /** Create a JSON-serializeable representation of this fragment. */ toJSON() { return this.content.length ? this.content.map((n) => n.toJSON()) : null; } /** Deserialize a fragment from its JSON representation. */ static fromJSON(schema, value) { if (!value) return Fragment.empty; if (!Array.isArray(value)) throw new RangeError("Invalid input for Fragment.fromJSON"); return new Fragment(value.map(schema.nodeFromJSON)); } /** Build a fragment from an array of nodes. Ensures that adjacent text nodes with the same marks are joined together. */ static fromArray(array) { if (!array.length) return Fragment.empty; let joined, size2 = 0; for (let i = 0; i < array.length; i++) { let node = array[i]; size2 += node.nodeSize; if (i && node.isText && array[i - 1].sameMarkup(node)) { if (!joined) joined = array.slice(0, i); joined[joined.length - 1] = node.withText(joined[joined.length - 1].text + node.text); } else if (joined) { joined.push(node); } } return new Fragment(joined || array, size2); } /** Create a fragment from something that can be interpreted as a set of nodes. For `null`, it returns the empty fragment. For a fragment, the fragment itself. For a node or array of nodes, a fragment containing those nodes. */ static from(nodes) { if (!nodes) return Fragment.empty; if (nodes instanceof Fragment) return nodes; if (Array.isArray(nodes)) return this.fromArray(nodes); if (nodes.attrs) return new Fragment([nodes], nodes.nodeSize); throw new RangeError("Can not convert " + nodes + " to a Fragment" + (nodes.nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : "")); } } Fragment.empty = new Fragment([], 0); const found = { index: 0, offset: 0 }; function retIndex(index, offset2) { found.index = index; found.offset = offset2; return found; } function compareDeep(a, b) { if (a === b) return true; if (!(a && typeof a == "object") || !(b && typeof b == "object")) return false; let array = Array.isArray(a); if (Array.isArray(b) != array) return false; if (array) { if (a.length != b.length) return false; for (let i = 0; i < a.length; i++) if (!compareDeep(a[i], b[i])) return false; } else { for (let p in a) if (!(p in b) || !compareDeep(a[p], b[p])) return false; for (let p in b) if (!(p in a)) return false; } return true; } let Mark$1 = class Mark { /** @internal */ constructor(type, attrs) { this.type = type; this.attrs = attrs; } /** Given a set of marks, create a new set which contains this one as well, in the right position. If this mark is already in the set, the set itself is returned. If any marks that are set to be [exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present, those are replaced by this one. */ addToSet(set) { let copy2, placed = false; for (let i = 0; i < set.length; i++) { let other = set[i]; if (this.eq(other)) return set; if (this.type.excludes(other.type)) { if (!copy2) copy2 = set.slice(0, i); } else if (other.type.excludes(this.type)) { return set; } else { if (!placed && other.type.rank > this.type.rank) { if (!copy2) copy2 = set.slice(0, i); copy2.push(this); placed = true; } if (copy2) copy2.push(other); } } if (!copy2) copy2 = set.slice(); if (!placed) copy2.push(this); return copy2; } /** Remove this mark from the given set, returning a new set. If this mark is not in the set, the set itself is returned. */ removeFromSet(set) { for (let i = 0; i < set.length; i++) if (this.eq(set[i])) return set.slice(0, i).concat(set.slice(i + 1)); return set; } /** Test whether this mark is in the given set of marks. */ isInSet(set) { for (let i = 0; i < set.length; i++) if (this.eq(set[i])) return true; return false; } /** Test whether this mark has the same type and attributes as another mark. */ eq(other) { return this == other || this.type == other.type && compareDeep(this.attrs, other.attrs); } /** Convert this mark to a JSON-serializeable representation. */ toJSON() { let obj = { type: this.type.name }; for (let _ in this.attrs) { obj.attrs = this.attrs; break; } return obj; } /** Deserialize a mark from JSON. */ static fromJSON(schema, json) { if (!json) throw new RangeError("Invalid input for Mark.fromJSON"); let type = schema.marks[json.type]; if (!type) throw new RangeError(`There is no mark type ${json.type} in this schema`); let mark = type.create(json.attrs); type.checkAttrs(mark.attrs); return mark; } /** Test whether two sets of marks are identical. */ static sameSet(a, b) { if (a == b) return true; if (a.length != b.length) return false; for (let i = 0; i < a.length; i++) if (!a[i].eq(b[i])) return false; return true; } /** Create a properly sorted mark set from null, a single mark, or an unsorted array of marks. */ static setFrom(marks) { if (!marks || Array.isArray(marks) && marks.length == 0) return Mark.none; if (marks instanceof Mark) return [marks]; let copy2 = marks.slice(); copy2.sort((a, b) => a.type.rank - b.type.rank); return copy2; } }; Mark$1.none = []; class ReplaceError extends Error { } class Slice { /** Create a slice. When specifying a non-zero open depth, you must make sure that there are nodes of at least that depth at the appropriate side of the fragment—i.e. if the fragment is an empty paragraph node, `openStart` and `openEnd` can't be greater than 1. It is not necessary for the content of open nodes to conform to the schema's content constraints, though it should be a valid start/end/middle for such a node, depending on which sides are open. */ constructor(content, openStart, openEnd) { this.content = content; this.openStart = openStart; this.openEnd = openEnd; } /** The size this slice would add when inserted into a document. */ get size() { return this.content.size - this.openStart - this.openEnd; } /** @internal */ insertAt(pos, fragment) { let content = insertInto(this.content, pos + this.openStart, fragment); return content && new Slice(content, this.openStart, this.openEnd); } /** @internal */ removeBetween(from2, to) { return new Slice(removeRange(this.content, from2 + this.openStart, to + this.openStart), this.openStart, this.openEnd); } /** Tests whether this slice is equal to another slice. */ eq(other) { return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd; } /** @internal */ toString() { return this.content + "(" + this.openStart + "," + this.openEnd + ")"; } /** Convert a slice to a JSON-serializable representation. */ toJSON() { if (!this.content.size) return null; let json = { content: this.content.toJSON() }; if (this.openStart > 0) json.openStart = this.openStart; if (this.openEnd > 0) json.openEnd = this.openEnd; return json; } /** Deserialize a slice from its JSON representation. */ static fromJSON(schema, json) { if (!json) return Slice.empty; let openStart = json.openStart || 0, openEnd = json.openEnd || 0; if (typeof openStart != "number" || typeof openEnd != "number") throw new RangeError("Invalid input for Slice.fromJSON"); return new Slice(Fragment.fromJSON(schema, json.content), openStart, openEnd); } /** Create a slice from a fragment by taking the maximum possible open value on both side of the fragment. */ static maxOpen(fragment, openIsolating = true) { let openStart = 0, openEnd = 0; for (let n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild) openStart++; for (let n = fragment.lastChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.lastChild) openEnd++; return new Slice(fragment, openStart, openEnd); } } Slice.empty = new Slice(Fragment.empty, 0, 0); function removeRange(content, from2, to) { let { index, offset: offset2 } = content.findIndex(from2), child = content.maybeChild(index); let { index: indexTo, offset: offsetTo } = content.findIndex(to); if (offset2 == from2 || child.isText) { if (offsetTo != to && !content.child(indexTo).isText) throw new RangeError("Removing non-flat range"); return content.cut(0, from2).append(content.cut(to)); } if (index != indexTo) throw new RangeError("Removing non-flat range"); return content.replaceChild(index, child.copy(removeRange(child.content, from2 - offset2 - 1, to - offset2 - 1))); } function insertInto(content, dist, insert, parent) { let { index, offset: offset2 } = content.findIndex(dist), child = content.maybeChild(index); if (offset2 == dist || child.isText) { if (parent && !parent.canReplace(index, index, insert)) return null; return content.cut(0, dist).append(insert).append(content.cut(dist)); } let inner = insertInto(child.content, dist - offset2 - 1, insert, child); return inner && content.replaceChild(index, child.copy(inner)); } function replace($from, $to, slice2) { if (slice2.openStart > $from.depth) throw new ReplaceError("Inserted content deeper than insertion position"); if ($from.depth - slice2.openStart != $to.depth - slice2.openEnd) throw new ReplaceError("Inconsistent open depths"); return replaceOuter($from, $to, slice2, 0); } function replaceOuter($from, $to, slice2, depth) { let index = $from.index(depth), node = $from.node(depth); if (index == $to.index(depth) && depth < $from.depth - slice2.openStart) { let inner = replaceOuter($from, $to, slice2, depth + 1); return node.copy(node.content.replaceChild(index, inner)); } else if (!slice2.content.size) { return close(node, replaceTwoWay($from, $to, depth)); } else if (!slice2.openStart && !slice2.openEnd && $from.depth == depth && $to.depth == depth) { let parent = $from.parent, content = parent.content; return close(parent, content.cut(0, $from.parentOffset).append(slice2.content).append(content.cut($to.parentOffset))); } else { let { start, end } = prepareSliceForReplace(slice2, $from); return close(node, replaceThreeWay($from, start, end, $to, depth)); } } function checkJoin(main, sub) { if (!sub.type.compatibleContent(main.type)) throw new ReplaceError("Cannot join " + sub.type.name + " onto " + main.type.name); } function joinable$1($before, $after, depth) { let node = $before.node(depth); checkJoin(node, $after.node(depth)); return node; } function addNode(child, target) { let last = target.length - 1; if (last >= 0 && child.isText && child.sameMarkup(target[last])) target[last] = child.withText(target[last].text + child.text); else target.push(child); } function addRange($start, $end, depth, target) { let node = ($end || $start).node(depth); let startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount; if ($start) { startIndex = $start.index(depth); if ($start.depth > depth) { startIndex++; } else if ($start.textOffset) { addNode($start.nodeAfter, target); startIndex++; } } for (let i = startIndex; i < endIndex; i++) addNode(node.child(i), target); if ($end && $end.depth == depth && $end.textOffset) addNode($end.nodeBefore, target); } function close(node, content) { node.type.checkContent(content); return node.copy(content); } function replaceThreeWay($from, $start, $end, $to, depth) { let openStart = $from.depth > depth && joinable$1($from, $start, depth + 1); let openEnd = $to.depth > depth && joinable$1($end, $to, depth + 1); let content = []; addRange(null, $from, depth, content); if (openStart && openEnd && $start.index(depth) == $end.index(depth)) { checkJoin(openStart, openEnd); addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content); } else { if (openStart) addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content); addRange($start, $end, depth, content); if (openEnd) addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content); } addRange($to, null, depth, content); return new Fragment(content); } function replaceTwoWay($from, $to, depth) { let content = []; addRange(null, $from, depth, content); if ($from.depth > depth) { let type = joinable$1($from, $to, depth + 1); addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content); } addRange($to, null, depth, content); return new Fragment(content); } function prepareSliceForReplace(slice2, $along) { let extra = $along.depth - slice2.openStart, parent = $along.node(extra); let node = parent.copy(slice2.content); for (let i = extra - 1; i >= 0; i--) node = $along.node(i).copy(Fragment.from(node)); return { start: node.resolveNoCache(slice2.openStart + extra), end: node.resolveNoCache(node.content.size - slice2.openEnd - extra) }; } class ResolvedPos { /** @internal */ constructor(pos, path, parentOffset) { this.pos = pos; this.path = path; this.parentOffset = parentOffset; this.depth = path.length / 3 - 1; } /** @internal */ resolveDepth(val) { if (val == null) return this.depth; if (val < 0) return this.depth + val; return val; } /** The parent node that the position points into. Note that even if a position points into a text node, that node is not considered the parent—text nodes are ‘flat’ in this model, and have no content. */ get parent() { return this.node(this.depth); } /** The root node in which the position was resolved. */ get doc() { return this.node(0); } /** The ancestor node at the given level. `p.node(p.depth)` is the same as `p.parent`. */ node(depth) { return this.path[this.resolveDepth(depth) * 3]; } /** The index into the ancestor at the given level. If this points at the 3rd node in the 2nd paragraph on the top level, for example, `p.index(0)` is 1 and `p.index(1)` is 2. */ index(depth) { return this.path[this.resolveDepth(depth) * 3 + 1]; } /** The index pointing after this position into the ancestor at the given level. */ indexAfter(depth) { depth = this.resolveDepth(depth); return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1); } /** The (absolute) position at the start of the node at the given level. */ start(depth) { depth = this.resolveDepth(depth); return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1; } /** The (absolute) position at the end of the node at the given level. */ end(depth) { depth = this.resolveDepth(depth); return this.start(depth) + this.node(depth).content.size; } /** The (absolute) position directly before the wrapping node at the given level, or, when `depth` is `this.depth + 1`, the original position. */ before(depth) { depth = this.resolveDepth(depth); if (!depth) throw new RangeError("There is no position before the top-level node"); return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1]; } /** The (absolute) position directly after the wrapping node at the given level, or the original position when `depth` is `this.depth + 1`. */ after(depth) { depth = this.resolveDepth(depth); if (!depth) throw new RangeError("There is no position after the top-level node"); return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize; } /** When this position points into a text node, this returns the distance between the position and the start of the text node. Will be zero for positions that point between nodes. */ get textOffset() { return this.pos - this.path[this.path.length - 1]; } /** Get the node directly after the position, if any. If the position points into a text node, only the part of that node after the position is returned. */ get nodeAfter() { let parent = this.parent, index = this.index(this.depth); if (index == parent.childCount) return null; let dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index); return dOff ? parent.child(index).cut(dOff) : child; } /** Get the node directly before the position, if any. If the position points into a text node, only the part of that node before the position is returned. */ get nodeBefore() { let index = this.index(this.depth); let dOff = this.pos - this.path[this.path.length - 1]; if (dOff) return this.parent.child(index).cut(0, dOff); return index == 0 ? null : this.parent.child(index - 1); } /** Get the position at the given index in the parent node at the given depth (which defaults to `this.depth`). */ posAtIndex(index, depth) { depth = this.resolveDepth(depth); let node = this.path[depth * 3], pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1; for (let i = 0; i < index; i++) pos += node.child(i).nodeSize; return pos; } /** Get the marks at this position, factoring in the surrounding marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the position is at the start of a non-empty node, the marks of the node after it (if any) are returned. */ marks() { let parent = this.parent, index = this.index(); if (parent.content.size == 0) return Mark$1.none; if (this.textOffset) return parent.child(index).marks; let main = parent.maybeChild(index - 1), other = parent.maybeChild(index); if (!main) { let tmp = main; main = other; other = tmp; } let marks = main.marks; for (var i = 0; i < marks.length; i++) if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks))) marks = marks[i--].removeFromSet(marks); return marks; } /** Get the marks after the current position, if any, except those that are non-inclusive and not present at position `$end`. This is mostly useful for getting the set of marks to preserve after a deletion. Will return `null` if this position is at the end of its parent node or its parent node isn't a textblock (in which case no marks should be preserved). */ marksAcross($end) { let after = this.parent.maybeChild(this.index()); if (!after || !after.isInline) return null; let marks = after.marks, next = $end.parent.maybeChild($end.index()); for (var i = 0; i < marks.length; i++) if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks))) marks = marks[i--].removeFromSet(marks); return marks; } /** The depth up to which this position and the given (non-resolved) position share the same parent nodes. */ sharedDepth(pos) { for (let depth = this.depth; depth > 0; depth--) if (this.start(depth) <= pos && this.end(depth) >= pos) return depth; return 0; } /** Returns a range based on the place where this position and the given position diverge around block content. If both point into the same textblock, for example, a range around that textblock will be returned. If they point into different blocks, the range around those blocks in their shared ancestor is returned. You can pass in an optional predicate that will be called with a parent node to see if a range into that parent is acceptable. */ blockRange(other = this, pred) { if (other.pos < this.pos) return other.blockRange(this); for (let d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--) if (other.pos <= this.end(d) && (!pred || pred(this.node(d)))) return new NodeRange(this, other, d); return null; } /** Query whether the given position shares the same parent node. */ sameParent(other) { return this.pos - this.parentOffset == other.pos - other.parentOffset; } /** Return the greater of this and the given position. */ max(other) { return other.pos > this.pos ? other : this; } /** Return the smaller of this and the given position. */ min(other) { return other.pos < this.pos ? other : this; } /** @internal */ toString() { let str = ""; for (let i = 1; i <= this.depth; i++) str += (str ? "/" : "") + this.node(i).type.name + "_" + this.index(i - 1); return str + ":" + this.parentOffset; } /** @internal */ static resolve(doc2, pos) { if (!(pos >= 0 && pos <= doc2.content.size)) throw new RangeError("Position " + pos + " out of range"); let path = []; let start = 0, parentOffset = pos; for (let node = doc2; ; ) { let { index, offset: offset2 } = node.content.findIndex(parentOffset); let rem = parentOffset - offset2; path.push(node, index, start + offset2); if (!rem) break; node = node.child(index); if (node.isText) break; parentOffset = rem - 1; start += offset2 + 1; } return new ResolvedPos(pos, path, parentOffset); } /** @internal */ static resolveCached(doc2, pos) { let cache = resolveCache.get(doc2); if (cache) { for (let i = 0; i < cache.elts.length; i++) { let elt = cache.elts[i]; if (elt.pos == pos) return elt; } } else { resolveCache.set(doc2, cache = new ResolveCache()); } let result = cache.elts[cache.i] = ResolvedPos.resolve(doc2, pos); cache.i = (cache.i + 1) % resolveCacheSize; return result; } } class ResolveCache { constructor() { this.elts = []; this.i = 0; } } const resolveCacheSize = 12, resolveCache = /* @__PURE__ */ new WeakMap(); class NodeRange { /** Construct a node range. `$from` and `$to` should point into the same node until at least the given `depth`, since a node range denotes an adjacent set of nodes in a single parent node. */ constructor($from, $to, depth) { this.$from = $from; this.$to = $to; this.depth = depth; } /** The position at the start of the range. */ get start() { return this.$from.before(this.depth + 1); } /** The position at the end of the range. */ get end() { return this.$to.after(this.depth + 1); } /** The parent node that the range points into. */ get parent() { return this.$from.node(this.depth); } /** The start index of the range in the parent node. */ get startIndex() { return this.$from.index(this.depth); } /** The end index of the range in the parent node. */ get endIndex() { return this.$to.indexAfter(this.depth); } } const emptyAttrs = /* @__PURE__ */ Object.create(null); let Node$1 = class Node2 { /** @internal */ constructor(type, attrs, content, marks = Mark$1.none) { this.type = type; this.attrs = attrs; this.marks = marks; this.content = content || Fragment.empty; } /** The array of this node's child nodes. */ get children() { return this.content.content; } /** The size of this node, as defined by the integer-based [indexing scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the amount of characters. For other leaf nodes, it is one. For non-leaf nodes, it is the size of the content plus two (the start and end token). */ get nodeSize() { return this.isLeaf ? 1 : 2 + this.content.size; } /** The number of children that the node has. */ get childCount() { return this.content.childCount; } /** Get the child node at the given index. Raises an error when the index is out of range. */ child(index) { return this.content.child(index); } /** Get the child node at the given index, if it exists. */ maybeChild(index) { return this.content.maybeChild(index); } /** Call `f` for every child node, passing the node, its offset into this parent node, and its index. */ forEach(f) { this.content.forEach(f); } /** Invoke a callback for all descendant nodes recursively between the given two positions that are relative to start of this node's content. The callback is invoked with the node, its position relative to the original node (method receiver), its parent node, and its child index. When the callback returns false for a given node, that node's children will not be recursed over. The last parameter can be used to specify a starting position to count from. */ nodesBetween(from2, to, f, startPos = 0) { this.content.nodesBetween(from2, to, f, startPos, this); } /** Call the given callback for every descendant node. Doesn't descend into a node when the callback returns `false`. */ descendants(f) { this.nodesBetween(0, this.content.size, f); } /** Concatenates all the text nodes found in this fragment and its children. */ get textContent() { return this.isLeaf && this.type.spec.leafText ? this.type.spec.leafText(this) : this.textBetween(0, this.content.size, ""); } /** Get all text between positions `from` and `to`. When `blockSeparator` is given, it will be inserted to separate text from different block nodes. If `leafText` is given, it'll be inserted for every non-text leaf node encountered, otherwise [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec.leafText) will be used. */ textBetween(from2, to, blockSeparator, leafText) { return this.content.textBetween(from2, to, blockSeparator, leafText); } /** Returns this node's first child, or `null` if there are no children. */ get firstChild() { return this.content.firstChild; } /** Returns this node's last child, or `null` if there are no children. */ get lastChild() { return this.content.lastChild; } /** Test whether two nodes represent the same piece of document. */ eq(other) { return this == other || this.sameMarkup(other) && this.content.eq(other.content); } /** Compare the markup (type, attributes, and marks) of this node to those of another. Returns `true` if both have the same markup. */ sameMarkup(other) { return this.hasMarkup(other.type, other.attrs, other.marks); } /** Check whether this node's markup correspond to the given type, attributes, and marks. */ hasMarkup(type, attrs, marks) { return this.type == type && compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) && Mark$1.sameSet(this.marks, marks || Mark$1.none); } /** Create a new node with the same markup as this node, containing the given content (or empty, if no content is given). */ copy(content = null) { if (content == this.content) return this; return new Node2(this.type, this.attrs, content, this.marks); } /** Create a copy of this node, with the given set of marks instead of the node's own marks. */ mark(marks) { return marks == this.marks ? this : new Node2(this.type, this.attrs, this.content, marks); } /** Create a copy of this node with only the content between the given positions. If `to` is not given, it defaults to the end of the node. */ cut(from2, to = this.content.size) { if (from2 == 0 && to == this.content.size) return this; return this.copy(this.content.cut(from2, to)); } /** Cut out the part of the document between the given positions, and return it as a `Slice` object. */ slice(from2, to = this.content.size, includeParents = false) { if (from2 == to) return Slice.empty; let $from = this.resolve(from2), $to = this.resolve(to); let depth = includeParents ? 0 : $from.sharedDepth(to); let start = $from.start(depth), node = $from.node(depth); let content = node.content.cut($from.pos - start, $to.pos - start); return new Slice(content, $from.depth - depth, $to.depth - depth); } /** Replace the part of the document between the given positions with the given slice. The slice must 'fit', meaning its open sides must be able to connect to the surrounding content, and its content nodes must be valid children for the node they are placed into. If any of this is violated, an error of type [`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown. */ replace(from2, to, slice2) { return replace(this.resolve(from2), this.resolve(to), slice2); } /** Find the node directly after the given position. */ nodeAt(pos) { for (let node = this; ; ) { let { index, offset: offset2 } = node.content.findIndex(pos); node = node.maybeChild(index); if (!node) return null; if (offset2 == pos || node.isText) return node; pos -= offset2 + 1; } } /** Find the (direct) child node after the given offset, if any, and return it along with its index and offset relative to this node. */ childAfter(pos) { let { index, offset: offset2 } = this.content.findIndex(pos); return { node: this.content.maybeChild(index), index, offset: offset2 }; } /** Find the (direct) child node before the given offset, if any, and return it along with its index and offset relative to this node. */ childBefore(pos) { if (pos == 0) return { node: null, index: 0, offset: 0 }; let { index, offset: offset2 } = this.content.findIndex(pos); if (offset2 < pos) return { node: this.content.child(index), index, offset: offset2 }; let node = this.content.child(index - 1); return { node, index: index - 1, offset: offset2 - node.nodeSize }; } /** Resolve the given position in the document, returning an [object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context. */ resolve(pos) { return ResolvedPos.resolveCached(this, pos); } /** @internal */ resolveNoCache(pos) { return ResolvedPos.resolve(this, pos); } /** Test whether a given mark or mark type occurs in this document between the two given positions. */ rangeHasMark(from2, to, type) { let found2 = false; if (to > from2) this.nodesBetween(from2, to, (node) => { if (type.isInSet(node.marks)) found2 = true; return !found2; }); return found2; } /** True when this is a block (non-inline node) */ get isBlock() { return this.type.isBlock; } /** True when this is a textblock node, a block node with inline content. */ get isTextblock() { return this.type.isTextblock; } /** True when this node allows inline content. */ get inlineContent() { return this.type.inlineContent; } /** True when this is an inline node (a text node or a node that can appear among text). */ get isInline() { return this.type.isInline; } /** True when this is a text node. */ get isText() { return this.type.isText; } /** True when this is a leaf node. */ get isLeaf() { return this.type.isLeaf; } /** True when this is an atom, i.e. when it does not have directly editable content. This is usually the same as `isLeaf`, but can be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom) on a node's spec (typically used when the node is displayed as an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)). */ get isAtom() { return this.type.isAtom; } /** Return a string representation of this node for debugging purposes. */ toString() { if (this.type.spec.toDebugString) return this.type.spec.toDebugString(this); let name = this.type.name; if (this.content.size) name += "(" + this.content.toStringInner() + ")"; return wrapMarks(this.marks, name); } /** Get the content match in this node at the given index. */ contentMatchAt(index) { let match = this.type.contentMatch.matchFragment(this.content, 0, index); if (!match) throw new Error("Called contentMatchAt on a node with invalid content"); return match; } /** Test whether replacing the range between `from` and `to` (by child index) with the given replacement fragment (which defaults to the empty fragment) would leave the node's content valid. You can optionally pass `start` and `end` indices into the replacement fragment. */ canReplace(from2, to, replacement = Fragment.empty, start = 0, end = replacement.childCount) { let one = this.contentMatchAt(from2).matchFragment(replacement, start, end); let two = one && one.matchFragment(this.content, to); if (!two || !two.validEnd) return false; for (let i = start; i < end; i++) if (!this.type.allowsMarks(replacement.child(i).marks)) return false; return true; } /** Test whether replacing the range `from` to `to` (by index) with a node of the given type would leave the node's content valid. */ canReplaceWith(from2, to, type, marks) { if (marks && !this.type.allowsMarks(marks)) return false; let start = this.contentMatchAt(from2).matchType(type); let end = start && start.matchFragment(this.content, to); return end ? end.validEnd : false; } /** Test whether the given node's content could be appended to this node. If that node is empty, this will only return true if there is at least one node type that can appear in both nodes (to avoid merging completely incompatible nodes). */ canAppend(other) { if (other.content.size) return this.canReplace(this.childCount, this.childCount, other.content); else return this.type.compatibleContent(other.type); } /** Check whether this node and its descendants conform to the schema, and raise an exception when they do not. */ check() { this.type.checkContent(this.content); this.type.checkAttrs(this.attrs); let copy2 = Mark$1.none; for (let i = 0; i < this.marks.length; i++) { let mark = this.marks[i]; mark.type.checkAttrs(mark.attrs); copy2 = mark.addToSet(copy2); } if (!Mark$1.sameSet(copy2, this.marks)) throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map((m) => m.type.name)}`); this.content.forEach((node) => node.check()); } /** Return a JSON-serializeable representation of this node. */ toJSON() { let obj = { type: this.type.name }; for (let _ in this.attrs) { obj.attrs = this.attrs; break; } if (this.content.size) obj.content = this.content.toJSON(); if (this.marks.length) obj.marks = this.marks.map((n) => n.toJSON()); return obj; } /** Deserialize a node from its JSON representation. */ static fromJSON(schema, json) { if (!json) throw new RangeError("Invalid input for Node.fromJSON"); let marks = void 0; if (json.marks) { if (!Array.isArray(json.marks)) throw new RangeError("Invalid mark data for Node.fromJSON"); marks = json.marks.map(schema.markFromJSON); } if (json.type == "text") { if (typeof json.text != "string") throw new RangeError("Invalid text node in JSON"); return schema.text(json.text, marks); } let content = Fragment.fromJSON(schema, json.content); let node = schema.nodeType(json.type).create(json.attrs, content, marks); node.type.checkAttrs(node.attrs); return node; } }; Node$1.prototype.text = void 0; class TextNode extends Node$1 { /** @internal */ constructor(type, attrs, content, marks) { super(type, attrs, null, marks); if (!content) throw new RangeError("Empty text nodes are not allowed"); this.text = content; } toString() { if (this.type.spec.toDebugString) return this.type.spec.toDebugString(this); return wrapMarks(this.marks, JSON.stringify(this.text)); } get textContent() { return this.text; } textBetween(from2, to) { return this.text.slice(from2, to); } get nodeSize() { return this.text.length; } mark(marks) { return marks == this.marks ? this : new TextNode(this.type, this.attrs, this.text, marks); } withText(text) { if (text == this.text) return this; return new TextNode(this.type, this.attrs, text, this.marks); } cut(from2 = 0, to = this.text.length) { if (from2 == 0 && to == this.text.length) return this; return this.withText(this.text.slice(from2, to)); } eq(other) { return this.sameMarkup(other) && this.text == other.text; } toJSON() { let base2 = super.toJSON(); base2.text = this.text; return base2; } } function wrapMarks(marks, str) { for (let i = marks.length - 1; i >= 0; i--) str = marks[i].type.name + "(" + str + ")"; return str; } class ContentMatch { /** @internal */ constructor(validEnd) { this.validEnd = validEnd; this.next = []; this.wrapCache = []; } /** @internal */ static parse(string, nodeTypes) { let stream = new TokenStream(string, nodeTypes); if (stream.next == null) return ContentMatch.empty; let expr = parseExpr(stream); if (stream.next) stream.err("Unexpected trailing text"); let match = dfa(nfa(expr)); checkForDeadEnds(match, stream); return match; } /** Match a node type, returning a match after that node if successful. */ matchType(type) { for (let i = 0; i < this.next.length; i++) if (this.next[i].type == type) return this.next[i].next; return null; } /** Try to match a fragment. Returns the resulting match when successful. */ matchFragment(frag, start = 0, end = frag.childCount) { let cur = this; for (let i = start; cur && i < end; i++) cur = cur.matchType(frag.child(i).type); return cur; } /** @internal */ get inlineContent() { return this.next.length != 0 && this.next[0].type.isInline; } /** Get the first matching node type at this match position that can be generated. */ get defaultType() { for (let i = 0; i < this.next.length; i++) { let { type } = this.next[i]; if (!(type.isText || type.hasRequiredAttrs())) return type; } return null; } /** @internal */ compatible(other) { for (let i = 0; i < this.next.length; i++) for (let j = 0; j < other.next.length; j++) if (this.next[i].type == other.next[j].type) return true; return false; } /** Try to match the given fragment, and if that fails, see if it can be made to match by inserting nodes in front of it. When successful, return a fragment of inserted nodes (which may be empty if nothing had to be inserted). When `toEnd` is true, only return a fragment if the resulting match goes to the end of the content expression. */ fillBefore(after, toEnd = false, startIndex = 0) { let seen = [this]; function search(match, types) { let finished = match.matchFragment(after, startIndex); if (finished && (!toEnd || finished.validEnd)) return Fragment.from(types.map((tp) => tp.createAndFill())); for (let i = 0; i < match.next.length; i++) { let { type, next } = match.next[i]; if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) { seen.push(next); let found2 = search(next, types.concat(type)); if (found2) return found2; } } return null; } return search(this, []); } /** Find a set of wrapping node types that would allow a node of the given type to appear at this position. The result may be empty (when it fits directly) and will be null when no such wrapping exists. */ findWrapping(target) { for (let i = 0; i < this.wrapCache.length; i += 2) if (this.wrapCache[i] == target) return this.wrapCache[i + 1]; let computed = this.computeWrapping(target); this.wrapCache.push(target, computed); return computed; } /** @internal */ computeWrapping(target) { let seen = /* @__PURE__ */ Object.create(null), active = [{ match: this, type: null, via: null }]; while (active.length) { let current = active.shift(), match = current.match; if (match.matchType(target)) { let result = []; for (let obj = current; obj.type; obj = obj.via) result.push(obj.type); return result.reverse(); } for (let i = 0; i < match.next.length; i++) { let { type, next } = match.next[i]; if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) { active.push({ match: type.contentMatch, type, via: current }); seen[type.name] = true; } } } return null; } /** The number of outgoing edges this node has in the finite automaton that describes the content expression. */ get edgeCount() { return this.next.length; } /** Get the _n_​th outgoing edge from this node in the finite automaton that describes the content expression. */ edge(n) { if (n >= this.next.length) throw new RangeError(`There's no ${n}th edge in this content match`); return this.next[n]; } /** @internal */ toString() { let seen = []; function scan(m) { seen.push(m); for (let i = 0; i < m.next.length; i++) if (seen.indexOf(m.next[i].next) == -1) scan(m.next[i].next); } scan(this); return seen.map((m, i) => { let out = i + (m.validEnd ? "*" : " ") + " "; for (let i2 = 0; i2 < m.next.length; i2++) out += (i2 ? ", " : "") + m.next[i2].type.name + "->" + seen.indexOf(m.next[i2].next); return out; }).join("\n"); } } ContentMatch.empty = new ContentMatch(true); class TokenStream { constructor(string, nodeTypes) { this.string = string; this.nodeTypes = nodeTypes; this.inline = null; this.pos = 0; this.tokens = string.split(/\s*(?=\b|\W|$)/); if (this.tokens[this.tokens.length - 1] == "") this.tokens.pop(); if (this.tokens[0] == "") this.tokens.shift(); } get next() { return this.tokens[this.pos]; } eat(tok) { return this.next == tok && (this.pos++ || true); } err(str) { throw new SyntaxError(str + " (in content expression '" + this.string + "')"); } } function parseExpr(stream) { let exprs = []; do { exprs.push(parseExprSeq(stream)); } while (stream.eat("|")); return exprs.length == 1 ? exprs[0] : { type: "choice", exprs }; } function parseExprSeq(stream) { let exprs = []; do { exprs.push(parseExprSubscript(stream)); } while (stream.next && stream.next != ")" && stream.next != "|"); return exprs.length == 1 ? exprs[0] : { type: "seq", exprs }; } function parseExprSubscript(stream) { let expr = parseExprAtom(stream); for (; ; ) { if (stream.eat("+")) expr = { type: "plus", expr }; else if (stream.eat("*")) expr = { type: "star", expr }; else if (stream.eat("?")) expr = { type: "opt", expr }; else if (stream.eat("{")) expr = parseExprRange(stream, expr); else break; } return expr; } function parseNum(stream) { if (/\D/.test(stream.next)) stream.err("Expected number, got '" + stream.next + "'"); let result = Number(stream.next); stream.pos++; return result; } function parseExprRange(stream, expr) { let min2 = parseNum(stream), max2 = min2; if (stream.eat(",")) { if (stream.next != "}") max2 = parseNum(stream); else max2 = -1; } if (!stream.eat("}")) stream.err("Unclosed braced range"); return { type: "range", min: min2, max: max2, expr }; } function resolveName(stream, name) { let types = stream.nodeTypes, type = types[name]; if (type) return [type]; let result = []; for (let typeName in types) { let type2 = types[typeName]; if (type2.isInGroup(name)) result.push(type2); } if (result.length == 0) stream.err("No node type or group '" + name + "' found"); return result; } function parseExprAtom(stream) { if (stream.eat("(")) { let expr = parseExpr(stream); if (!stream.eat(")")) stream.err("Missing closing paren"); return expr; } else if (!/\W/.test(stream.next)) { let exprs = resolveName(stream, stream.next).map((type) => { if (stream.inline == null) stream.inline = type.isInline; else if (stream.inline != type.isInline) stream.err("Mixing inline and block content"); return { type: "name", value: type }; }); stream.pos++; return exprs.length == 1 ? exprs[0] : { type: "choice", exprs }; } else { stream.err("Unexpected token '" + stream.next + "'"); } } function nfa(expr) { let nfa2 = [[]]; connect(compile(expr, 0), node()); return nfa2; function node() { return nfa2.push([]) - 1; } function edge(from2, to, term) { let edge2 = { term, to }; nfa2[from2].push(edge2); return edge2; } function connect(edges, to) { edges.forEach((edge2) => edge2.to = to); } function compile(expr2, from2) { if (expr2.type == "choice") { return expr2.exprs.reduce((out, expr3) => out.concat(compile(expr3, from2)), []); } else if (expr2.type == "seq") { for (let i = 0; ; i++) { let next = compile(expr2.exprs[i], from2); if (i == expr2.exprs.length - 1) return next; connect(next, from2 = node()); } } else if (expr2.type == "star") { let loop = node(); edge(from2, loop); connect(compile(expr2.expr, loop), loop); return [edge(loop)]; } else if (expr2.type == "plus") { let loop = node(); connect(compile(expr2.expr, from2), loop); connect(compile(expr2.expr, loop), loop); return [edge(loop)]; } else if (expr2.type == "opt") { return [edge(from2)].concat(compile(expr2.expr, from2)); } else if (expr2.type == "range") { let cur = from2; for (let i = 0; i < expr2.min; i++) { let next = node(); connect(compile(expr2.expr, cur), next); cur = next; } if (expr2.max == -1) { connect(compile(expr2.expr, cur), cur); } else { for (let i = expr2.min; i < expr2.max; i++) { let next = node(); edge(cur, next); connect(compile(expr2.expr, cur), next); cur = next; } } return [edge(cur)]; } else if (expr2.type == "name") { return [edge(from2, void 0, expr2.value)]; } else { throw new Error("Unknown expr type"); } } } function cmp(a, b) { return b - a; } function nullFrom(nfa2, node) { let result = []; scan(node); return result.sort(cmp); function scan(node2) { let edges = nfa2[node2]; if (edges.length == 1 && !edges[0].term) return scan(edges[0].to); result.push(node2); for (let i = 0; i < edges.length; i++) { let { term, to } = edges[i]; if (!term && result.indexOf(to) == -1) scan(to); } } } function dfa(nfa2) { let labeled = /* @__PURE__ */ Object.create(null); return explore(nullFrom(nfa2, 0)); function explore(states) { let out = []; states.forEach((node) => { nfa2[node].forEach(({ term, to }) => { if (!term) return; let set; for (let i = 0; i < out.length; i++) if (out[i][0] == term) set = out[i][1]; nullFrom(nfa2, to).forEach((node2) => { if (!set) out.push([term, set = []]); if (set.indexOf(node2) == -1) set.push(node2); }); }); }); let state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa2.length - 1) > -1); for (let i = 0; i < out.length; i++) { let states2 = out[i][1].sort(cmp); state.next.push({ type: out[i][0], next: labeled[states2.join(",")] || explore(states2) }); } return state; } } function checkForDeadEnds(match, stream) { for (let i = 0, work = [match]; i < work.length; i++) { let state = work[i], dead = !state.validEnd, nodes = []; for (let j = 0; j < state.next.length; j++) { let { type, next } = state.next[j]; nodes.push(type.name); if (dead && !(type.isText || type.hasRequiredAttrs())) dead = false; if (work.indexOf(next) == -1) work.push(next); } if (dead) stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)"); } } function defaultAttrs(attrs) { let defaults2 = /* @__PURE__ */ Object.create(null); for (let attrName in attrs) { let attr = attrs[attrName]; if (!attr.hasDefault) return null; defaults2[attrName] = attr.default; } return defaults2; } function computeAttrs(attrs, value) { let built = /* @__PURE__ */ Object.create(null); for (let name in attrs) { let given = value && value[name]; if (given === void 0) { let attr = attrs[name]; if (attr.hasDefault) given = attr.default; else throw new RangeError("No value supplied for attribute " + name); } built[name] = given; } return built; } function checkAttrs(attrs, values, type, name) { for (let name2 in values) if (!(name2 in attrs)) throw new RangeError(`Unsupported attribute ${name2} for ${type} of type ${name2}`); for (let name2 in attrs) { let attr = attrs[name2]; if (attr.validate) attr.validate(values[name2]); } } function initAttrs(typeName, attrs) { let result = /* @__PURE__ */ Object.create(null); if (attrs) for (let name in attrs) result[name] = new Attribute(typeName, name, attrs[name]); return result; } let NodeType$1 = class NodeType { /** @internal */ constructor(name, schema, spec) { this.name = name; this.schema = schema; this.spec = spec; this.markSet = null; this.groups = spec.group ? spec.group.split(" ") : []; this.attrs = initAttrs(name, spec.attrs); this.defaultAttrs = defaultAttrs(this.attrs); this.contentMatch = null; this.inlineContent = null; this.isBlock = !(spec.inline || name == "text"); this.isText = name == "text"; } /** True if this is an inline type. */ get isInline() { return !this.isBlock; } /** True if this is a textblock type, a block that contains inline content. */ get isTextblock() { return this.isBlock && this.inlineContent; } /** True for node types that allow no content. */ get isLeaf() { return this.contentMatch == ContentMatch.empty; } /** True when this node is an atom, i.e. when it does not have directly editable content. */ get isAtom() { return this.isLeaf || !!this.spec.atom; } /** Return true when this node type is part of the given [group](https://prosemirror.net/docs/ref/#model.NodeSpec.group). */ isInGroup(group) { return this.groups.indexOf(group) > -1; } /** The node type's [whitespace](https://prosemirror.net/docs/ref/#model.NodeSpec.whitespace) option. */ get whitespace() { return this.spec.whitespace || (this.spec.code ? "pre" : "normal"); } /** Tells you whether this node type has any required attributes. */ hasRequiredAttrs() { for (let n in this.attrs) if (this.attrs[n].isRequired) return true; return false; } /** Indicates whether this node allows some of the same content as the given node type. */ compatibleContent(other) { return this == other || this.contentMatch.compatible(other.contentMatch); } /** @internal */ computeAttrs(attrs) { if (!attrs && this.defaultAttrs) return this.defaultAttrs; else return computeAttrs(this.attrs, attrs); } /** Create a `Node` of this type. The given attributes are checked and defaulted (you can pass `null` to use the type's defaults entirely, if no required attributes exist). `content` may be a `Fragment`, a node, an array of nodes, or `null`. Similarly `marks` may be `null` to default to the empty set of marks. */ create(attrs = null, content, marks) { if (this.isText) throw new Error("NodeType.create can't construct text nodes"); return new Node$1(this, this.computeAttrs(attrs), Fragment.from(content), Mark$1.setFrom(marks)); } /** Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content against the node type's content restrictions, and throw an error if it doesn't match. */ createChecked(attrs = null, content, marks) { content = Fragment.from(content); this.checkContent(content); return new Node$1(this, this.computeAttrs(attrs), content, Mark$1.setFrom(marks)); } /** Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is necessary to add nodes to the start or end of the given fragment to make it fit the node. If no fitting wrapping can be found, return null. Note that, due to the fact that required nodes can always be created, this will always succeed if you pass null or `Fragment.empty` as content. */ createAndFill(attrs = null, content, marks) { attrs = this.computeAttrs(attrs); content = Fragment.from(content); if (content.size) { let before = this.contentMatch.fillBefore(content); if (!before) return null; content = before.append(content); } let matched = this.contentMatch.matchFragment(content); let after = matched && matched.fillBefore(Fragment.empty, true); if (!after) return null; return new Node$1(this, attrs, content.append(after), Mark$1.setFrom(marks)); } /** Returns true if the given fragment is valid content for this node type. */ validContent(content) { let result = this.contentMatch.matchFragment(content); if (!result || !result.validEnd) return false; for (let i = 0; i < content.childCount; i++) if (!this.allowsMarks(content.child(i).marks)) return false; return true; } /** Throws a RangeError if the given fragment is not valid content for this node type. @internal */ checkContent(content) { if (!this.validContent(content)) throw new RangeError(`Invalid content for node ${this.name}: ${content.toString().slice(0, 50)}`); } /** @internal */ checkAttrs(attrs) { checkAttrs(this.attrs, attrs, "node", this.name); } /** Check whether the given mark type is allowed in this node. */ allowsMarkType(markType) { return this.markSet == null || this.markSet.indexOf(markType) > -1; } /** Test whether the given set of marks are allowed in this node. */ allowsMarks(marks) { if (this.markSet == null) return true; for (let i = 0; i < marks.length; i++) if (!this.allowsMarkType(marks[i].type)) return false; return true; } /** Removes the marks that are not allowed in this node from the given set. */ allowedMarks(marks) { if (this.markSet == null) return marks; let copy2; for (let i = 0; i < marks.length; i++) { if (!this.allowsMarkType(marks[i].type)) { if (!copy2) copy2 = marks.slice(0, i); } else if (copy2) { copy2.push(marks[i]); } } return !copy2 ? marks : copy2.length ? copy2 : Mark$1.none; } /** @internal */ static compile(nodes, schema) { let result = /* @__PURE__ */ Object.create(null); nodes.forEach((name, spec) => result[name] = new NodeType(name, schema, spec)); let topType = schema.spec.topNode || "doc"; if (!result[topType]) throw new RangeError("Schema is missing its top node type ('" + topType + "')"); if (!result.text) throw new RangeError("Every schema needs a 'text' type"); for (let _ in result.text.attrs) throw new RangeError("The text node type should not have attributes"); return result; } }; function validateType(typeName, attrName, type) { let types = type.split("|"); return (value) => { let name = value === null ? "null" : typeof value; if (types.indexOf(name) < 0) throw new RangeError(`Expected value of type ${types} for attribute ${attrName} on type ${typeName}, got ${name}`); }; } class Attribute { constructor(typeName, attrName, options) { this.hasDefault = Object.prototype.hasOwnProperty.call(options, "default"); this.default = options.default; this.validate = typeof options.validate == "string" ? validateType(typeName, attrName, options.validate) : options.validate; } get isRequired() { return !this.hasDefault; } } class MarkType { /** @internal */ constructor(name, rank, schema, spec) { this.name = name; this.rank = rank; this.schema = schema; this.spec = spec; this.attrs = initAttrs(name, spec.attrs); this.excluded = null; let defaults2 = defaultAttrs(this.attrs); this.instance = defaults2 ? new Mark$1(this, defaults2) : null; } /** Create a mark of this type. `attrs` may be `null` or an object containing only some of the mark's attributes. The others, if they have defaults, will be added. */ create(attrs = null) { if (!attrs && this.instance) return this.instance; return new Mark$1(this, computeAttrs(this.attrs, attrs)); } /** @internal */ static compile(marks, schema) { let result = /* @__PURE__ */ Object.create(null), rank = 0; marks.forEach((name, spec) => result[name] = new MarkType(name, rank++, schema, spec)); return result; } /** When there is a mark of this type in the given set, a new set without it is returned. Otherwise, the input set is returned. */ removeFromSet(set) { for (var i = 0; i < set.length; i++) if (set[i].type == this) { set = set.slice(0, i).concat(set.slice(i + 1)); i--; } return set; } /** Tests whether there is a mark of this type in the given set. */ isInSet(set) { for (let i = 0; i < set.length; i++) if (set[i].type == this) return set[i]; } /** @internal */ checkAttrs(attrs) { checkAttrs(this.attrs, attrs, "mark", this.name); } /** Queries whether a given mark type is [excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one. */ excludes(other) { return this.excluded.indexOf(other) > -1; } } class Schema { /** Construct a schema from a schema [specification](https://prosemirror.net/docs/ref/#model.SchemaSpec). */ constructor(spec) { this.linebreakReplacement = null; this.cached = /* @__PURE__ */ Object.create(null); let instanceSpec = this.spec = {}; for (let prop in spec) instanceSpec[prop] = spec[prop]; instanceSpec.nodes = OrderedMap.from(spec.nodes), instanceSpec.marks = OrderedMap.from(spec.marks || {}), this.nodes = NodeType$1.compile(this.spec.nodes, this); this.marks = MarkType.compile(this.spec.marks, this); let contentExprCache = /* @__PURE__ */ Object.create(null); for (let prop in this.nodes) { if (prop in this.marks) throw new RangeError(prop + " can not be both a node and a mark"); let type = this.nodes[prop], contentExpr = type.spec.content || "", markExpr = type.spec.marks; type.contentMatch = contentExprCache[contentExpr] || (contentExprCache[contentExpr] = ContentMatch.parse(contentExpr, this.nodes)); type.inlineContent = type.contentMatch.inlineContent; if (type.spec.linebreakReplacement) { if (this.linebreakReplacement) throw new RangeError("Multiple linebreak nodes defined"); if (!type.isInline || !type.isLeaf) throw new RangeError("Linebreak replacement nodes must be inline leaf nodes"); this.linebreakReplacement = type; } type.markSet = markExpr == "_" ? null : markExpr ? gatherMarks(this, markExpr.split(" ")) : markExpr == "" || !type.inlineContent ? [] : null; } for (let prop in this.marks) { let type = this.marks[prop], excl = type.spec.excludes; type.excluded = excl == null ? [type] : excl == "" ? [] : gatherMarks(this, excl.split(" ")); } this.nodeFromJSON = (json) => Node$1.fromJSON(this, json); this.markFromJSON = (json) => Mark$1.fromJSON(this, json); this.topNodeType = this.nodes[this.spec.topNode || "doc"]; this.cached.wrappings = /* @__PURE__ */ Object.create(null); } /** Create a node in this schema. The `type` may be a string or a `NodeType` instance. Attributes will be extended with defaults, `content` may be a `Fragment`, `null`, a `Node`, or an array of nodes. */ node(type, attrs = null, content, marks) { if (typeof type == "string") type = this.nodeType(type); else if (!(type instanceof NodeType$1)) throw new RangeError("Invalid node type: " + type); else if (type.schema != this) throw new RangeError("Node type from different schema used (" + type.name + ")"); return type.createChecked(attrs, content, marks); } /** Create a text node in the schema. Empty text nodes are not allowed. */ text(text, marks) { let type = this.nodes.text; return new TextNode(type, type.defaultAttrs, text, Mark$1.setFrom(marks)); } /** Create a mark with the given type and attributes. */ mark(type, attrs) { if (typeof type == "string") type = this.marks[type]; return type.create(attrs); } /** @internal */ nodeType(name) { let found2 = this.nodes[name]; if (!found2) throw new RangeError("Unknown node type: " + name); return found2; } } function gatherMarks(schema, marks) { let found2 = []; for (let i = 0; i < marks.length; i++) { let name = marks[i], mark = schema.marks[name], ok = mark; if (mark) { found2.push(mark); } else { for (let prop in schema.marks) { let mark2 = schema.marks[prop]; if (name == "_" || mark2.spec.group && mark2.spec.group.split(" ").indexOf(name) > -1) found2.push(ok = mark2); } } if (!ok) throw new SyntaxError("Unknown mark type: '" + marks[i] + "'"); } return found2; } function isTagRule(rule) { return rule.tag != null; } function isStyleRule(rule) { return rule.style != null; } class DOMParser { /** Create a parser that targets the given schema, using the given parsing rules. */ constructor(schema, rules) { this.schema = schema; this.rules = rules; this.tags = []; this.styles = []; let matchedStyles = this.matchedStyles = []; rules.forEach((rule) => { if (isTagRule(rule)) { this.tags.push(rule); } else if (isStyleRule(rule)) { let prop = /[^=]*/.exec(rule.style)[0]; if (matchedStyles.indexOf(prop) < 0) matchedStyles.push(prop); this.styles.push(rule); } }); this.normalizeLists = !this.tags.some((r) => { if (!/^(ul|ol)\b/.test(r.tag) || !r.node) return false; let node = schema.nodes[r.node]; return node.contentMatch.matchType(node); }); } /** Parse a document from the content of a DOM node. */ parse(dom, options = {}) { let context = new ParseContext(this, options, false); context.addAll(dom, Mark$1.none, options.from, options.to); return context.finish(); } /** Parses the content of the given DOM node, like [`parse`](https://prosemirror.net/docs/ref/#model.DOMParser.parse), and takes the same set of options. But unlike that method, which produces a whole node, this one returns a slice that is open at the sides, meaning that the schema constraints aren't applied to the start of nodes to the left of the input and the end of nodes at the end. */ parseSlice(dom, options = {}) { let context = new ParseContext(this, options, true); context.addAll(dom, Mark$1.none, options.from, options.to); return Slice.maxOpen(context.finish()); } /** @internal */ matchTag(dom, context, after) { for (let i = after ? this.tags.indexOf(after) + 1 : 0; i < this.tags.length; i++) { let rule = this.tags[i]; if (matches(dom, rule.tag) && (rule.namespace === void 0 || dom.namespaceURI == rule.namespace) && (!rule.context || context.matchesContext(rule.context))) { if (rule.getAttrs) { let result = rule.getAttrs(dom); if (result === false) continue; rule.attrs = result || void 0; } return rule; } } } /** @internal */ matchStyle(prop, value, context, after) { for (let i = after ? this.styles.indexOf(after) + 1 : 0; i < this.styles.length; i++) { let rule = this.styles[i], style2 = rule.style; if (style2.indexOf(prop) != 0 || rule.context && !context.matchesContext(rule.context) || // Test that the style string either precisely matches the prop, // or has an '=' sign after the prop, followed by the given // value. style2.length > prop.length && (style2.charCodeAt(prop.length) != 61 || style2.slice(prop.length + 1) != value)) continue; if (rule.getAttrs) { let result = rule.getAttrs(value); if (result === false) continue; rule.attrs = result || void 0; } return rule; } } /** @internal */ static schemaRules(schema) { let result = []; function insert(rule) { let priority = rule.priority == null ? 50 : rule.priority, i = 0; for (; i < result.length; i++) { let next = result[i], nextPriority = next.priority == null ? 50 : next.priority; if (nextPriority < priority) break; } result.splice(i, 0, rule); } for (let name in schema.marks) { let rules = schema.marks[name].spec.parseDOM; if (rules) rules.forEach((rule) => { insert(rule = copy(rule)); if (!(rule.mark || rule.ignore || rule.clearMark)) rule.mark = name; }); } for (let name in schema.nodes) { let rules = schema.nodes[name].spec.parseDOM; if (rules) rules.forEach((rule) => { insert(rule = copy(rule)); if (!(rule.node || rule.ignore || rule.mark)) rule.node = name; }); } return result; } /** Construct a DOM parser using the parsing rules listed in a schema's [node specs](https://prosemirror.net/docs/ref/#model.NodeSpec.parseDOM), reordered by [priority](https://prosemirror.net/docs/ref/#model.GenericParseRule.priority). */ static fromSchema(schema) { return schema.cached.domParser || (schema.cached.domParser = new DOMParser(schema, DOMParser.schemaRules(schema))); } } const blockTags = { address: true, article: true, aside: true, blockquote: true, canvas: true, dd: true, div: true, dl: true, fieldset: true, figcaption: true, figure: true, footer: true, form: true, h1: true, h2: true, h3: true, h4: true, h5: true, h6: true, header: true, hgroup: true, hr: true, li: true, noscript: true, ol: true, output: true, p: true, pre: true, section: true, table: true, tfoot: true, ul: true }; const ignoreTags = { head: true, noscript: true, object: true, script: true, style: true, title: true }; const listTags = { ol: true, ul: true }; const OPT_PRESERVE_WS = 1, OPT_PRESERVE_WS_FULL = 2, OPT_OPEN_LEFT = 4; function wsOptionsFor(type, preserveWhitespace, base2) { if (preserveWhitespace != null) return (preserveWhitespace ? OPT_PRESERVE_WS : 0) | (preserveWhitespace === "full" ? OPT_PRESERVE_WS_FULL : 0); return type && type.whitespace == "pre" ? OPT_PRESERVE_WS | OPT_PRESERVE_WS_FULL : base2 & ~OPT_OPEN_LEFT; } class NodeContext { constructor(type, attrs, marks, solid, match, options) { this.type = type; this.attrs = attrs; this.marks = marks; this.solid = solid; this.options = options; this.content = []; this.activeMarks = Mark$1.none; this.match = match || (options & OPT_OPEN_LEFT ? null : type.contentMatch); } findWrapping(node) { if (!this.match) { if (!this.type) return []; let fill = this.type.contentMatch.fillBefore(Fragment.from(node)); if (fill) { this.match = this.type.contentMatch.matchFragment(fill); } else { let start = this.type.contentMatch, wrap2; if (wrap2 = start.findWrapping(node.type)) { this.match = start; return wrap2; } else { return null; } } } return this.match.findWrapping(node.type); } finish(openEnd) { if (!(this.options & OPT_PRESERVE_WS)) { let last = this.content[this.content.length - 1], m; if (last && last.isText && (m = /[ \t\r\n\u000c]+$/.exec(last.text))) { let text = last; if (last.text.length == m[0].length) this.content.pop(); else this.content[this.content.length - 1] = text.withText(text.text.slice(0, text.text.length - m[0].length)); } } let content = Fragment.from(this.content); if (!openEnd && this.match) content = content.append(this.match.fillBefore(Fragment.empty, true)); return this.type ? this.type.create(this.attrs, content, this.marks) : content; } inlineContext(node) { if (this.type) return this.type.inlineContent; if (this.content.length) return this.content[0].isInline; return node.parentNode && !blockTags.hasOwnProperty(node.parentNode.nodeName.toLowerCase()); } } class ParseContext { constructor(parser, options, isOpen) { this.parser = parser; this.options = options; this.isOpen = isOpen; this.open = 0; this.localPreserveWS = false; let topNode = options.topNode, topContext; let topOptions = wsOptionsFor(null, options.preserveWhitespace, 0) | (isOpen ? OPT_OPEN_LEFT : 0); if (topNode) topContext = new NodeContext(topNode.type, topNode.attrs, Mark$1.none, true, options.topMatch || topNode.type.contentMatch, topOptions); else if (isOpen) topContext = new NodeContext(null, null, Mark$1.none, true, null, topOptions); else topContext = new NodeContext(parser.schema.topNodeType, null, Mark$1.none, true, null, topOptions); this.nodes = [topContext]; this.find = options.findPositions; this.needsBlock = false; } get top() { return this.nodes[this.open]; } // Add a DOM node to the content. Text is inserted as text node, // otherwise, the node is passed to `addElement` or, if it has a // `style` attribute, `addElementWithStyles`. addDOM(dom, marks) { if (dom.nodeType == 3) this.addTextNode(dom, marks); else if (dom.nodeType == 1) this.addElement(dom, marks); } addTextNode(dom, marks) { let value = dom.nodeValue; let top = this.top, preserveWS = top.options & OPT_PRESERVE_WS_FULL ? "full" : this.localPreserveWS || (top.options & OPT_PRESERVE_WS) > 0; let { schema } = this.parser; if (preserveWS === "full" || top.inlineContext(dom) || /[^ \t\r\n\u000c]/.test(value)) { if (!preserveWS) { value = value.replace(/[ \t\r\n\u000c]+/g, " "); if (/^[ \t\r\n\u000c]/.test(value) && this.open == this.nodes.length - 1) { let nodeBefore = top.content[top.content.length - 1]; let domNodeBefore = dom.previousSibling; if (!nodeBefore || domNodeBefore && domNodeBefore.nodeName == "BR" || nodeBefore.isText && /[ \t\r\n\u000c]$/.test(nodeBefore.text)) value = value.slice(1); } } else if (preserveWS === "full") { value = value.replace(/\r\n?/g, "\n"); } else if (schema.linebreakReplacement && /[\r\n]/.test(value) && this.top.findWrapping(schema.linebreakReplacement.create())) { let lines = value.split(/\r?\n|\r/); for (let i = 0; i < lines.length; i++) { if (i) this.insertNode(schema.linebreakReplacement.create(), marks, true); if (lines[i]) this.insertNode(schema.text(lines[i]), marks, !/\S/.test(lines[i])); } value = ""; } else { value = value.replace(/\r?\n|\r/g, " "); } if (value) this.insertNode(schema.text(value), marks, !/\S/.test(value)); this.findInText(dom); } else { this.findInside(dom); } } // Try to find a handler for the given tag and use that to parse. If // none is found, the element's content nodes are added directly. addElement(dom, marks, matchAfter) { let outerWS = this.localPreserveWS, top = this.top; if (dom.tagName == "PRE" || /pre/.test(dom.style && dom.style.whiteSpace)) this.localPreserveWS = true; let name = dom.nodeName.toLowerCase(), ruleID; if (listTags.hasOwnProperty(name) && this.parser.normalizeLists) normalizeList(dom); let rule = this.options.ruleFromNode && this.options.ruleFromNode(dom) || (ruleID = this.parser.matchTag(dom, this, matchAfter)); out: if (rule ? rule.ignore : ignoreTags.hasOwnProperty(name)) { this.findInside(dom); this.ignoreFallback(dom, marks); } else if (!rule || rule.skip || rule.closeParent) { if (rule && rule.closeParent) this.open = Math.max(0, this.open - 1); else if (rule && rule.skip.nodeType) dom = rule.skip; let sync, oldNeedsBlock = this.needsBlock; if (blockTags.hasOwnProperty(name)) { if (top.content.length && top.content[0].isInline && this.open) { this.open--; top = this.top; } sync = true; if (!top.type) this.needsBlock = true; } else if (!dom.firstChild) { this.leafFallback(dom, marks); break out; } let innerMarks = rule && rule.skip ? marks : this.readStyles(dom, marks); if (innerMarks) this.addAll(dom, innerMarks); if (sync) this.sync(top); this.needsBlock = oldNeedsBlock; } else { let innerMarks = this.readStyles(dom, marks); if (innerMarks) this.addElementByRule(dom, rule, innerMarks, rule.consuming === false ? ruleID : void 0); } this.localPreserveWS = outerWS; } // Called for leaf DOM nodes that would otherwise be ignored leafFallback(dom, marks) { if (dom.nodeName == "BR" && this.top.type && this.top.type.inlineContent) this.addTextNode(dom.ownerDocument.createTextNode("\n"), marks); } // Called for ignored nodes ignoreFallback(dom, marks) { if (dom.nodeName == "BR" && (!this.top.type || !this.top.type.inlineContent)) this.findPlace(this.parser.schema.text("-"), marks, true); } // Run any style parser associated with the node's styles. Either // return an updated array of marks, or null to indicate some of the // styles had a rule with `ignore` set. readStyles(dom, marks) { let styles = dom.style; if (styles && styles.length) for (let i = 0; i < this.parser.matchedStyles.length; i++) { let name = this.parser.matchedStyles[i], value = styles.getPropertyValue(name); if (value) for (let after = void 0; ; ) { let rule = this.parser.matchStyle(name, value, this, after); if (!rule) break; if (rule.ignore) return null; if (rule.clearMark) marks = marks.filter((m) => !rule.clearMark(m)); else marks = marks.concat(this.parser.schema.marks[rule.mark].create(rule.attrs)); if (rule.consuming === false) after = rule; else break; } } return marks; } // Look up a handler for the given node. If none are found, return // false. Otherwise, apply it, use its return value to drive the way // the node's content is wrapped, and return true. addElementByRule(dom, rule, marks, continueAfter) { let sync, nodeType; if (rule.node) { nodeType = this.parser.schema.nodes[rule.node]; if (!nodeType.isLeaf) { let inner = this.enter(nodeType, rule.attrs || null, marks, rule.preserveWhitespace); if (inner) { sync = true; marks = inner; } } else if (!this.insertNode(nodeType.create(rule.attrs), marks, dom.nodeName == "BR")) { this.leafFallback(dom, marks); } } else { let markType = this.parser.schema.marks[rule.mark]; marks = marks.concat(markType.create(rule.attrs)); } let startIn = this.top; if (nodeType && nodeType.isLeaf) { this.findInside(dom); } else if (continueAfter) { this.addElement(dom, marks, continueAfter); } else if (rule.getContent) { this.findInside(dom); rule.getContent(dom, this.parser.schema).forEach((node) => this.insertNode(node, marks, false)); } else { let contentDOM = dom; if (typeof rule.contentElement == "string") contentDOM = dom.querySelector(rule.contentElement); else if (typeof rule.contentElement == "function") contentDOM = rule.contentElement(dom); else if (rule.contentElement) contentDOM = rule.contentElement; this.findAround(dom, contentDOM, true); this.addAll(contentDOM, marks); this.findAround(dom, contentDOM, false); } if (sync && this.sync(startIn)) this.open--; } // Add all child nodes between `startIndex` and `endIndex` (or the // whole node, if not given). If `sync` is passed, use it to // synchronize after every block element. addAll(parent, marks, startIndex, endIndex) { let index = startIndex || 0; for (let dom = startIndex ? parent.childNodes[startIndex] : parent.firstChild, end = endIndex == null ? null : parent.childNodes[endIndex]; dom != end; dom = dom.nextSibling, ++index) { this.findAtPoint(parent, index); this.addDOM(dom, marks); } this.findAtPoint(parent, index); } // Try to find a way to fit the given node type into the current // context. May add intermediate wrappers and/or leave non-solid // nodes that we're in. findPlace(node, marks, cautious) { let route, sync; for (let depth = this.open, penalty = 0; depth >= 0; depth--) { let cx = this.nodes[depth]; let found2 = cx.findWrapping(node); if (found2 && (!route || route.length > found2.length + penalty)) { route = found2; sync = cx; if (!found2.length) break; } if (cx.solid) { if (cautious) break; penalty += 2; } } if (!route) return null; this.sync(sync); for (let i = 0; i < route.length; i++) marks = this.enterInner(route[i], null, marks, false); return marks; } // Try to insert the given node, adjusting the context when needed. insertNode(node, marks, cautious) { if (node.isInline && this.needsBlock && !this.top.type) { let block = this.textblockFromContext(); if (block) marks = this.enterInner(block, null, marks); } let innerMarks = this.findPlace(node, marks, cautious); if (innerMarks) { this.closeExtra(); let top = this.top; if (top.match) top.match = top.match.matchType(node.type); let nodeMarks = Mark$1.none; for (let m of innerMarks.concat(node.marks)) if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, node.type)) nodeMarks = m.addToSet(nodeMarks); top.content.push(node.mark(nodeMarks)); return true; } return false; } // Try to start a node of the given type, adjusting the context when // necessary. enter(type, attrs, marks, preserveWS) { let innerMarks = this.findPlace(type.create(attrs), marks, false); if (innerMarks) innerMarks = this.enterInner(type, attrs, marks, true, preserveWS); return innerMarks; } // Open a node of the given type enterInner(type, attrs, marks, solid = false, preserveWS) { this.closeExtra(); let top = this.top; top.match = top.match && top.match.matchType(type); let options = wsOptionsFor(type, preserveWS, top.options); if (top.options & OPT_OPEN_LEFT && top.content.length == 0) options |= OPT_OPEN_LEFT; let applyMarks = Mark$1.none; marks = marks.filter((m) => { if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, type)) { applyMarks = m.addToSet(applyMarks); return false; } return true; }); this.nodes.push(new NodeContext(type, attrs, applyMarks, solid, null, options)); this.open++; return marks; } // Make sure all nodes above this.open are finished and added to // their parents closeExtra(openEnd = false) { let i = this.nodes.length - 1; if (i > this.open) { for (; i > this.open; i--) this.nodes[i - 1].content.push(this.nodes[i].finish(openEnd)); this.nodes.length = this.open + 1; } } finish() { this.open = 0; this.closeExtra(this.isOpen); return this.nodes[0].finish(!!(this.isOpen || this.options.topOpen)); } sync(to) { for (let i = this.open; i >= 0; i--) { if (this.nodes[i] == to) { this.open = i; return true; } else if (this.localPreserveWS) { this.nodes[i].options |= OPT_PRESERVE_WS; } } return false; } get currentPos() { this.closeExtra(); let pos = 0; for (let i = this.open; i >= 0; i--) { let content = this.nodes[i].content; for (let j = content.length - 1; j >= 0; j--) pos += content[j].nodeSize; if (i) pos++; } return pos; } findAtPoint(parent, offset2) { if (this.find) for (let i = 0; i < this.find.length; i++) { if (this.find[i].node == parent && this.find[i].offset == offset2) this.find[i].pos = this.currentPos; } } findInside(parent) { if (this.find) for (let i = 0; i < this.find.length; i++) { if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) this.find[i].pos = this.currentPos; } } findAround(parent, content, before) { if (parent != content && this.find) for (let i = 0; i < this.find.length; i++) { if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) { let pos = content.compareDocumentPosition(this.find[i].node); if (pos & (before ? 2 : 4)) this.find[i].pos = this.currentPos; } } } findInText(textNode) { if (this.find) for (let i = 0; i < this.find.length; i++) { if (this.find[i].node == textNode) this.find[i].pos = this.currentPos - (textNode.nodeValue.length - this.find[i].offset); } } // Determines whether the given context string matches this context. matchesContext(context) { if (context.indexOf("|") > -1) return context.split(/\s*\|\s*/).some(this.matchesContext, this); let parts = context.split("/"); let option = this.options.context; let useRoot = !this.isOpen && (!option || option.parent.type == this.nodes[0].type); let minDepth = -(option ? option.depth + 1 : 0) + (useRoot ? 0 : 1); let match = (i, depth) => { for (; i >= 0; i--) { let part = parts[i]; if (part == "") { if (i == parts.length - 1 || i == 0) continue; for (; depth >= minDepth; depth--) if (match(i - 1, depth)) return true; return false; } else { let next = depth > 0 || depth == 0 && useRoot ? this.nodes[depth].type : option && depth >= minDepth ? option.node(depth - minDepth).type : null; if (!next || next.name != part && !next.isInGroup(part)) return false; depth--; } } return true; }; return match(parts.length - 1, this.open); } textblockFromContext() { let $context = this.options.context; if ($context) for (let d = $context.depth; d >= 0; d--) { let deflt = $context.node(d).contentMatchAt($context.indexAfter(d)).defaultType; if (deflt && deflt.isTextblock && deflt.defaultAttrs) return deflt; } for (let name in this.parser.schema.nodes) { let type = this.parser.schema.nodes[name]; if (type.isTextblock && type.defaultAttrs) return type; } } } function normalizeList(dom) { for (let child = dom.firstChild, prevItem = null; child; child = child.nextSibling) { let name = child.nodeType == 1 ? child.nodeName.toLowerCase() : null; if (name && listTags.hasOwnProperty(name) && prevItem) { prevItem.appendChild(child); child = prevItem; } else if (name == "li") { prevItem = child; } else if (name) { prevItem = null; } } } function matches(dom, selector) { return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector); } function copy(obj) { let copy2 = {}; for (let prop in obj) copy2[prop] = obj[prop]; return copy2; } function markMayApply(markType, nodeType) { let nodes = nodeType.schema.nodes; for (let name in nodes) { let parent = nodes[name]; if (!parent.allowsMarkType(markType)) continue; let seen = [], scan = (match) => { seen.push(match); for (let i = 0; i < match.edgeCount; i++) { let { type, next } = match.edge(i); if (type == nodeType) return true; if (seen.indexOf(next) < 0 && scan(next)) return true; } }; if (scan(parent.contentMatch)) return true; } } class DOMSerializer { /** Create a serializer. `nodes` should map node names to functions that take a node and return a description of the corresponding DOM. `marks` does the same for mark names, but also gets an argument that tells it whether the mark's content is block or inline content (for typical use, it'll always be inline). A mark serializer may be `null` to indicate that marks of that type should not be serialized. */ constructor(nodes, marks) { this.nodes = nodes; this.marks = marks; } /** Serialize the content of this fragment to a DOM fragment. When not in the browser, the `document` option, containing a DOM document, should be passed so that the serializer can create nodes. */ serializeFragment(fragment, options = {}, target) { if (!target) target = doc$1(options).createDocumentFragment(); let top = target, active = []; fragment.forEach((node) => { if (active.length || node.marks.length) { let keep = 0, rendered = 0; while (keep < active.length && rendered < node.marks.length) { let next = node.marks[rendered]; if (!this.marks[next.type.name]) { rendered++; continue; } if (!next.eq(active[keep][0]) || next.type.spec.spanning === false) break; keep++; rendered++; } while (keep < active.length) top = active.pop()[1]; while (rendered < node.marks.length) { let add = node.marks[rendered++]; let markDOM = this.serializeMark(add, node.isInline, options); if (markDOM) { active.push([add, top]); top.appendChild(markDOM.dom); top = markDOM.contentDOM || markDOM.dom; } } } top.appendChild(this.serializeNodeInner(node, options)); }); return target; } /** @internal */ serializeNodeInner(node, options) { let { dom, contentDOM } = renderSpec(doc$1(options), this.nodes[node.type.name](node), null, node.attrs); if (contentDOM) { if (node.isLeaf) throw new RangeError("Content hole not allowed in a leaf node spec"); this.serializeFragment(node.content, options, contentDOM); } return dom; } /** Serialize this node to a DOM node. This can be useful when you need to serialize a part of a document, as opposed to the whole document. To serialize a whole document, use [`serializeFragment`](https://prosemirror.net/docs/ref/#model.DOMSerializer.serializeFragment) on its [content](https://prosemirror.net/docs/ref/#model.Node.content). */ serializeNode(node, options = {}) { let dom = this.serializeNodeInner(node, options); for (let i = node.marks.length - 1; i >= 0; i--) { let wrap2 = this.serializeMark(node.marks[i], node.isInline, options); if (wrap2) { (wrap2.contentDOM || wrap2.dom).appendChild(dom); dom = wrap2.dom; } } return dom; } /** @internal */ serializeMark(mark, inline2, options = {}) { let toDOM = this.marks[mark.type.name]; return toDOM && renderSpec(doc$1(options), toDOM(mark, inline2), null, mark.attrs); } static renderSpec(doc2, structure, xmlNS = null, blockArraysIn) { return renderSpec(doc2, structure, xmlNS, blockArraysIn); } /** Build a serializer using the [`toDOM`](https://prosemirror.net/docs/ref/#model.NodeSpec.toDOM) properties in a schema's node and mark specs. */ static fromSchema(schema) { return schema.cached.domSerializer || (schema.cached.domSerializer = new DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema))); } /** Gather the serializers in a schema's node specs into an object. This can be useful as a base to build a custom serializer from. */ static nodesFromSchema(schema) { let result = gatherToDOM(schema.nodes); if (!result.text) result.text = (node) => node.text; return result; } /** Gather the serializers in a schema's mark specs into an object. */ static marksFromSchema(schema) { return gatherToDOM(schema.marks); } } function gatherToDOM(obj) { let result = {}; for (let name in obj) { let toDOM = obj[name].spec.toDOM; if (toDOM) result[name] = toDOM; } return result; } function doc$1(options) { return options.document || window.document; } const suspiciousAttributeCache = /* @__PURE__ */ new WeakMap(); function suspiciousAttributes(attrs) { let value = suspiciousAttributeCache.get(attrs); if (value === void 0) suspiciousAttributeCache.set(attrs, value = suspiciousAttributesInner(attrs)); return value; } function suspiciousAttributesInner(attrs) { let result = null; function scan(value) { if (value && typeof value == "object") { if (Array.isArray(value)) { if (typeof value[0] == "string") { if (!result) result = []; result.push(value); } else { for (let i = 0; i < value.length; i++) scan(value[i]); } } else { for (let prop in value) scan(value[prop]); } } } scan(attrs); return result; } function renderSpec(doc2, structure, xmlNS, blockArraysIn) { if (typeof structure == "string") return { dom: doc2.createTextNode(structure) }; if (structure.nodeType != null) return { dom: structure }; if (structure.dom && structure.dom.nodeType != null) return structure; let tagName = structure[0], suspicious; if (typeof tagName != "string") throw new RangeError("Invalid array passed to renderSpec"); if (blockArraysIn && (suspicious = suspiciousAttributes(blockArraysIn)) && suspicious.indexOf(structure) > -1) throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack."); let space = tagName.indexOf(" "); if (space > 0) { xmlNS = tagName.slice(0, space); tagName = tagName.slice(space + 1); } let contentDOM; let dom = xmlNS ? doc2.createElementNS(xmlNS, tagName) : doc2.createElement(tagName); let attrs = structure[1], start = 1; if (attrs && typeof attrs == "object" && attrs.nodeType == null && !Array.isArray(attrs)) { start = 2; for (let name in attrs) if (attrs[name] != null) { let space2 = name.indexOf(" "); if (space2 > 0) dom.setAttributeNS(name.slice(0, space2), name.slice(space2 + 1), attrs[name]); else if (name == "style" && dom.style) dom.style.cssText = attrs[name]; else dom.setAttribute(name, attrs[name]); } } for (let i = start; i < structure.length; i++) { let child = structure[i]; if (child === 0) { if (i < structure.length - 1 || i > start) throw new RangeError("Content hole must be the only child of its parent node"); return { dom, contentDOM: dom }; } else { let { dom: inner, contentDOM: innerContent } = renderSpec(doc2, child, xmlNS, blockArraysIn); dom.appendChild(inner); if (innerContent) { if (contentDOM) throw new RangeError("Multiple content holes"); contentDOM = innerContent; } } } return { dom, contentDOM }; } const lower16 = 65535; const factor16 = Math.pow(2, 16); function makeRecover(index, offset2) { return index + offset2 * factor16; } function recoverIndex(value) { return value & lower16; } function recoverOffset(value) { return (value - (value & lower16)) / factor16; } const DEL_BEFORE = 1, DEL_AFTER = 2, DEL_ACROSS = 4, DEL_SIDE = 8; class MapResult { /** @internal */ constructor(pos, delInfo, recover) { this.pos = pos; this.delInfo = delInfo; this.recover = recover; } /** Tells you whether the position was deleted, that is, whether the step removed the token on the side queried (via the `assoc`) argument from the document. */ get deleted() { return (this.delInfo & DEL_SIDE) > 0; } /** Tells you whether the token before the mapped position was deleted. */ get deletedBefore() { return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0; } /** True when the token after the mapped position was deleted. */ get deletedAfter() { return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0; } /** Tells whether any of the steps mapped through deletes across the position (including both the token before and after the position). */ get deletedAcross() { return (this.delInfo & DEL_ACROSS) > 0; } } class StepMap { /** Create a position map. The modifications to the document are represented as an array of numbers, in which each group of three represents a modified chunk as `[start, oldSize, newSize]`. */ constructor(ranges, inverted = false) { this.ranges = ranges; this.inverted = inverted; if (!ranges.length && StepMap.empty) return StepMap.empty; } /** @internal */ recover(value) { let diff = 0, index = recoverIndex(value); if (!this.inverted) for (let i = 0; i < index; i++) diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1]; return this.ranges[index * 3] + diff + recoverOffset(value); } mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); } map(pos, assoc = 1) { return this._map(pos, assoc, true); } /** @internal */ _map(pos, assoc, simple) { let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2; for (let i = 0; i < this.ranges.length; i += 3) { let start = this.ranges[i] - (this.inverted ? diff : 0); if (start > pos) break; let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize; if (pos <= end) { let side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc; let result = start + diff + (side < 0 ? 0 : newSize); if (simple) return result; let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start); let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS; if (assoc < 0 ? pos != start : pos != end) del |= DEL_SIDE; return new MapResult(result, del, recover); } diff += newSize - oldSize; } return simple ? pos + diff : new MapResult(pos + diff, 0, null); } /** @internal */ touches(pos, recover) { let diff = 0, index = recoverIndex(recover); let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2; for (let i = 0; i < this.ranges.length; i += 3) { let start = this.ranges[i] - (this.inverted ? diff : 0); if (start > pos) break; let oldSize = this.ranges[i + oldIndex], end = start + oldSize; if (pos <= end && i == index * 3) return true; diff += this.ranges[i + newIndex] - oldSize; } return false; } /** Calls the given function on each of the changed ranges included in this map. */ forEach(f) { let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2; for (let i = 0, diff = 0; i < this.ranges.length; i += 3) { let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff); let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex]; f(oldStart, oldStart + oldSize, newStart, newStart + newSize); diff += newSize - oldSize; } } /** Create an inverted version of this map. The result can be used to map positions in the post-step document to the pre-step document. */ invert() { return new StepMap(this.ranges, !this.inverted); } /** @internal */ toString() { return (this.inverted ? "-" : "") + JSON.stringify(this.ranges); } /** Create a map that moves all positions by offset `n` (which may be negative). This can be useful when applying steps meant for a sub-document to a larger document, or vice-versa. */ static offset(n) { return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]); } } StepMap.empty = new StepMap([]); class Mapping { /** Create a new mapping with the given position maps. */ constructor(maps, mirror, from2 = 0, to = maps ? maps.length : 0) { this.mirror = mirror; this.from = from2; this.to = to; this._maps = maps || []; this.ownData = !(maps || mirror); } /** The step maps in this mapping. */ get maps() { return this._maps; } /** Create a mapping that maps only through a part of this one. */ slice(from2 = 0, to = this.maps.length) { return new Mapping(this._maps, this.mirror, from2, to); } /** Add a step map to the end of this mapping. If `mirrors` is given, it should be the index of the step map that is the mirror image of this one. */ appendMap(map2, mirrors) { if (!this.ownData) { this._maps = this._maps.slice(); this.mirror = this.mirror && this.mirror.slice(); this.ownData = true; } this.to = this._maps.push(map2); if (mirrors != null) this.setMirror(this._maps.length - 1, mirrors); } /** Add all the step maps in a given mapping to this one (preserving mirroring information). */ appendMapping(mapping) { for (let i = 0, startSize = this._maps.length; i < mapping._maps.length; i++) { let mirr = mapping.getMirror(i); this.appendMap(mapping._maps[i], mirr != null && mirr < i ? startSize + mirr : void 0); } } /** Finds the offset of the step map that mirrors the map at the given offset, in this mapping (as per the second argument to `appendMap`). */ getMirror(n) { if (this.mirror) { for (let i = 0; i < this.mirror.length; i++) if (this.mirror[i] == n) return this.mirror[i + (i % 2 ? -1 : 1)]; } } /** @internal */ setMirror(n, m) { if (!this.mirror) this.mirror = []; this.mirror.push(n, m); } /** Append the inverse of the given mapping to this one. */ appendMappingInverted(mapping) { for (let i = mapping.maps.length - 1, totalSize = this._maps.length + mapping._maps.length; i >= 0; i--) { let mirr = mapping.getMirror(i); this.appendMap(mapping._maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : void 0); } } /** Create an inverted version of this mapping. */ invert() { let inverse = new Mapping(); inverse.appendMappingInverted(this); return inverse; } /** Map a position through this mapping. */ map(pos, assoc = 1) { if (this.mirror) return this._map(pos, assoc, true); for (let i = this.from; i < this.to; i++) pos = this._maps[i].map(pos, assoc); return pos; } /** Map a position through this mapping, returning a mapping result. */ mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); } /** @internal */ _map(pos, assoc, simple) { let delInfo = 0; for (let i = this.from; i < this.to; i++) { let map2 = this._maps[i], result = map2.mapResult(pos, assoc); if (result.recover != null) { let corr = this.getMirror(i); if (corr != null && corr > i && corr < this.to) { i = corr; pos = this._maps[corr].recover(result.recover); continue; } } delInfo |= result.delInfo; pos = result.pos; } return simple ? pos : new MapResult(pos, delInfo, null); } } const stepsByID = /* @__PURE__ */ Object.create(null); class Step { /** Get the step map that represents the changes made by this step, and which can be used to transform between positions in the old and the new document. */ getMap() { return StepMap.empty; } /** Try to merge this step with another one, to be applied directly after it. Returns the merged step when possible, null if the steps can't be merged. */ merge(other) { return null; } /** Deserialize a step from its JSON representation. Will call through to the step class' own implementation of this method. */ static fromJSON(schema, json) { if (!json || !json.stepType) throw new RangeError("Invalid input for Step.fromJSON"); let type = stepsByID[json.stepType]; if (!type) throw new RangeError(`No step type ${json.stepType} defined`); return type.fromJSON(schema, json); } /** To be able to serialize steps to JSON, each step needs a string ID to attach to its JSON representation. Use this method to register an ID for your step classes. Try to pick something that's unlikely to clash with steps from other modules. */ static jsonID(id, stepClass) { if (id in stepsByID) throw new RangeError("Duplicate use of step JSON ID " + id); stepsByID[id] = stepClass; stepClass.prototype.jsonID = id; return stepClass; } } class StepResult { /** @internal */ constructor(doc2, failed) { this.doc = doc2; this.failed = failed; } /** Create a successful step result. */ static ok(doc2) { return new StepResult(doc2, null); } /** Create a failed step result. */ static fail(message) { return new StepResult(null, message); } /** Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given arguments. Create a successful result if it succeeds, and a failed one if it throws a `ReplaceError`. */ static fromReplace(doc2, from2, to, slice2) { try { return StepResult.ok(doc2.replace(from2, to, slice2)); } catch (e) { if (e instanceof ReplaceError) return StepResult.fail(e.message); throw e; } } } function mapFragment(fragment, f, parent) { let mapped = []; for (let i = 0; i < fragment.childCount; i++) { let child = fragment.child(i); if (child.content.size) child = child.copy(mapFragment(child.content, f, child)); if (child.isInline) child = f(child, parent, i); mapped.push(child); } return Fragment.fromArray(mapped); } class AddMarkStep extends Step { /** Create a mark step. */ constructor(from2, to, mark) { super(); this.from = from2; this.to = to; this.mark = mark; } apply(doc2) { let oldSlice = doc2.slice(this.from, this.to), $from = doc2.resolve(this.from); let parent = $from.node($from.sharedDepth(this.to)); let slice2 = new Slice(mapFragment(oldSlice.content, (node, parent2) => { if (!node.isAtom || !parent2.type.allowsMarkType(this.mark.type)) return node; return node.mark(this.mark.addToSet(node.marks)); }, parent), oldSlice.openStart, oldSlice.openEnd); return StepResult.fromReplace(doc2, this.from, this.to, slice2); } invert() { return new RemoveMarkStep(this.from, this.to, this.mark); } map(mapping) { let from2 = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1); if (from2.deleted && to.deleted || from2.pos >= to.pos) return null; return new AddMarkStep(from2.pos, to.pos, this.mark); } merge(other) { if (other instanceof AddMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from) return new AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark); return null; } toJSON() { return { stepType: "addMark", mark: this.mark.toJSON(), from: this.from, to: this.to }; } /** @internal */ static fromJSON(schema, json) { if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for AddMarkStep.fromJSON"); return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark)); } } Step.jsonID("addMark", AddMarkStep); class RemoveMarkStep extends Step { /** Create a mark-removing step. */ constructor(from2, to, mark) { super(); this.from = from2; this.to = to; this.mark = mark; } apply(doc2) { let oldSlice = doc2.slice(this.from, this.to); let slice2 = new Slice(mapFragment(oldSlice.content, (node) => { return node.mark(this.mark.removeFromSet(node.marks)); }, doc2), oldSlice.openStart, oldSlice.openEnd); return StepResult.fromReplace(doc2, this.from, this.to, slice2); } invert() { return new AddMarkStep(this.from, this.to, this.mark); } map(mapping) { let from2 = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1); if (from2.deleted && to.deleted || from2.pos >= to.pos) return null; return new RemoveMarkStep(from2.pos, to.pos, this.mark); } merge(other) { if (other instanceof RemoveMarkStep && other.mark.eq(this.mark) && this.from <= other.to && this.to >= other.from) return new RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark); return null; } toJSON() { return { stepType: "removeMark", mark: this.mark.toJSON(), from: this.from, to: this.to }; } /** @internal */ static fromJSON(schema, json) { if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for RemoveMarkStep.fromJSON"); return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark)); } } Step.jsonID("removeMark", RemoveMarkStep); class AddNodeMarkStep extends Step { /** Create a node mark step. */ constructor(pos, mark) { super(); this.pos = pos; this.mark = mark; } apply(doc2) { let node = doc2.nodeAt(this.pos); if (!node) return StepResult.fail("No node at mark step's position"); let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks)); return StepResult.fromReplace(doc2, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1)); } invert(doc2) { let node = doc2.nodeAt(this.pos); if (node) { let newSet = this.mark.addToSet(node.marks); if (newSet.length == node.marks.length) { for (let i = 0; i < node.marks.length; i++) if (!node.marks[i].isInSet(newSet)) return new AddNodeMarkStep(this.pos, node.marks[i]); return new AddNodeMarkStep(this.pos, this.mark); } } return new RemoveNodeMarkStep(this.pos, this.mark); } map(mapping) { let pos = mapping.mapResult(this.pos, 1); return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark); } toJSON() { return { stepType: "addNodeMark", pos: this.pos, mark: this.mark.toJSON() }; } /** @internal */ static fromJSON(schema, json) { if (typeof json.pos != "number") throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON"); return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark)); } } Step.jsonID("addNodeMark", AddNodeMarkStep); class RemoveNodeMarkStep extends Step { /** Create a mark-removing step. */ constructor(pos, mark) { super(); this.pos = pos; this.mark = mark; } apply(doc2) { let node = doc2.nodeAt(this.pos); if (!node) return StepResult.fail("No node at mark step's position"); let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks)); return StepResult.fromReplace(doc2, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1)); } invert(doc2) { let node = doc2.nodeAt(this.pos); if (!node || !this.mark.isInSet(node.marks)) return this; return new AddNodeMarkStep(this.pos, this.mark); } map(mapping) { let pos = mapping.mapResult(this.pos, 1); return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark); } toJSON() { return { stepType: "removeNodeMark", pos: this.pos, mark: this.mark.toJSON() }; } /** @internal */ static fromJSON(schema, json) { if (typeof json.pos != "number") throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON"); return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark)); } } Step.jsonID("removeNodeMark", RemoveNodeMarkStep); class ReplaceStep extends Step { /** The given `slice` should fit the 'gap' between `from` and `to`—the depths must line up, and the surrounding nodes must be able to be joined with the open sides of the slice. When `structure` is true, the step will fail if the content between from and to is not just a sequence of closing and then opening tokens (this is to guard against rebased replace steps overwriting something they weren't supposed to). */ constructor(from2, to, slice2, structure = false) { super(); this.from = from2; this.to = to; this.slice = slice2; this.structure = structure; } apply(doc2) { if (this.structure && contentBetween(doc2, this.from, this.to)) return StepResult.fail("Structure replace would overwrite content"); return StepResult.fromReplace(doc2, this.from, this.to, this.slice); } getMap() { return new StepMap([this.from, this.to - this.from, this.slice.size]); } invert(doc2) { return new ReplaceStep(this.from, this.from + this.slice.size, doc2.slice(this.from, this.to)); } map(mapping) { let to = mapping.mapResult(this.to, -1); let from2 = this.from == this.to && ReplaceStep.MAP_BIAS < 0 ? to : mapping.mapResult(this.from, 1); if (from2.deletedAcross && to.deletedAcross) return null; return new ReplaceStep(from2.pos, Math.max(from2.pos, to.pos), this.slice, this.structure); } merge(other) { if (!(other instanceof ReplaceStep) || other.structure || this.structure) return null; if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) { let slice2 = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd); return new ReplaceStep(this.from, this.to + (other.to - other.from), slice2, this.structure); } else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) { let slice2 = this.slice.size + other.slice.size == 0 ? Slice.empty : new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd); return new ReplaceStep(other.from, this.to, slice2, this.structure); } else { return null; } } toJSON() { let json = { stepType: "replace", from: this.from, to: this.to }; if (this.slice.size) json.slice = this.slice.toJSON(); if (this.structure) json.structure = true; return json; } /** @internal */ static fromJSON(schema, json) { if (typeof json.from != "number" || typeof json.to != "number") throw new RangeError("Invalid input for ReplaceStep.fromJSON"); return new ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure); } } ReplaceStep.MAP_BIAS = 1; Step.jsonID("replace", ReplaceStep); class ReplaceAroundStep extends Step { /** Create a replace-around step with the given range and gap. `insert` should be the point in the slice into which the content of the gap should be moved. `structure` has the same meaning as it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class. */ constructor(from2, to, gapFrom, gapTo, slice2, insert, structure = false) { super(); this.from = from2; this.to = to; this.gapFrom = gapFrom; this.gapTo = gapTo; this.slice = slice2; this.insert = insert; this.structure = structure; } apply(doc2) { if (this.structure && (contentBetween(doc2, this.from, this.gapFrom) || contentBetween(doc2, this.gapTo, this.to))) return StepResult.fail("Structure gap-replace would overwrite content"); let gap = doc2.slice(this.gapFrom, this.gapTo); if (gap.openStart || gap.openEnd) return StepResult.fail("Gap is not a flat range"); let inserted = this.slice.insertAt(this.insert, gap.content); if (!inserted) return StepResult.fail("Content does not fit in gap"); return StepResult.fromReplace(doc2, this.from, this.to, inserted); } getMap() { return new StepMap([ this.from, this.gapFrom - this.from, this.insert, this.gapTo, this.to - this.gapTo, this.slice.size - this.insert ]); } invert(doc2) { let gap = this.gapTo - this.gapFrom; return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc2.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure); } map(mapping) { let from2 = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1); let gapFrom = this.from == this.gapFrom ? from2.pos : mapping.map(this.gapFrom, -1); let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1); if (from2.deletedAcross && to.deletedAcross || gapFrom < from2.pos || gapTo > to.pos) return null; return new ReplaceAroundStep(from2.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure); } toJSON() { let json = { stepType: "replaceAround", from: this.from, to: this.to, gapFrom: this.gapFrom, gapTo: this.gapTo, insert: this.insert }; if (this.slice.size) json.slice = this.slice.toJSON(); if (this.structure) json.structure = true; return json; } /** @internal */ static fromJSON(schema, json) { if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number") throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON"); return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure); } } Step.jsonID("replaceAround", ReplaceAroundStep); function contentBetween(doc2, from2, to) { let $from = doc2.resolve(from2), dist = to - from2, depth = $from.depth; while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) { depth--; dist--; } if (dist > 0) { let next = $from.node(depth).maybeChild($from.indexAfter(depth)); while (dist > 0) { if (!next || next.isLeaf) return true; next = next.firstChild; dist--; } } return false; } function addMark(tr2, from2, to, mark) { let removed = [], added = []; let removing, adding; tr2.doc.nodesBetween(from2, to, (node, pos, parent) => { if (!node.isInline) return; let marks = node.marks; if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) { let start = Math.max(pos, from2), end = Math.min(pos + node.nodeSize, to); let newSet = mark.addToSet(marks); for (let i = 0; i < marks.length; i++) { if (!marks[i].isInSet(newSet)) { if (removing && removing.to == start && removing.mark.eq(marks[i])) removing.to = end; else removed.push(removing = new RemoveMarkStep(start, end, marks[i])); } } if (adding && adding.to == start) adding.to = end; else added.push(adding = new AddMarkStep(start, end, mark)); } }); removed.forEach((s) => tr2.step(s)); added.forEach((s) => tr2.step(s)); } function removeMark(tr2, from2, to, mark) { let matched = [], step = 0; tr2.doc.nodesBetween(from2, to, (node, pos) => { if (!node.isInline) return; step++; let toRemove = null; if (mark instanceof MarkType) { let set = node.marks, found2; while (found2 = mark.isInSet(set)) { (toRemove || (toRemove = [])).push(found2); set = found2.removeFromSet(set); } } else if (mark) { if (mark.isInSet(node.marks)) toRemove = [mark]; } else { toRemove = node.marks; } if (toRemove && toRemove.length) { let end = Math.min(pos + node.nodeSize, to); for (let i = 0; i < toRemove.length; i++) { let style2 = toRemove[i], found2; for (let j = 0; j < matched.length; j++) { let m = matched[j]; if (m.step == step - 1 && style2.eq(matched[j].style)) found2 = m; } if (found2) { found2.to = end; found2.step = step; } else { matched.push({ style: style2, from: Math.max(pos, from2), to: end, step }); } } } }); matched.forEach((m) => tr2.step(new RemoveMarkStep(m.from, m.to, m.style))); } function clearIncompatible(tr2, pos, parentType, match = parentType.contentMatch, clearNewlines = true) { let node = tr2.doc.nodeAt(pos); let replSteps = [], cur = pos + 1; for (let i = 0; i < node.childCount; i++) { let child = node.child(i), end = cur + child.nodeSize; let allowed = match.matchType(child.type); if (!allowed) { replSteps.push(new ReplaceStep(cur, end, Slice.empty)); } else { match = allowed; for (let j = 0; j < child.marks.length; j++) if (!parentType.allowsMarkType(child.marks[j].type)) tr2.step(new RemoveMarkStep(cur, end, child.marks[j])); if (clearNewlines && child.isText && parentType.whitespace != "pre") { let m, newline = /\r?\n|\r/g, slice2; while (m = newline.exec(child.text)) { if (!slice2) slice2 = new Slice(Fragment.from(parentType.schema.text(" ", parentType.allowedMarks(child.marks))), 0, 0); replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice2)); } } } cur = end; } if (!match.validEnd) { let fill = match.fillBefore(Fragment.empty, true); tr2.replace(cur, cur, new Slice(fill, 0, 0)); } for (let i = replSteps.length - 1; i >= 0; i--) tr2.step(replSteps[i]); } function canCut(node, start, end) { return (start == 0 || node.canReplace(start, node.childCount)) && (end == node.childCount || node.canReplace(0, end)); } function liftTarget(range) { let parent = range.parent; let content = parent.content.cutByIndex(range.startIndex, range.endIndex); for (let depth = range.depth, contentBefore = 0, contentAfter = 0; ; --depth) { let node = range.$from.node(depth); let index = range.$from.index(depth) + contentBefore, endIndex = range.$to.indexAfter(depth) - contentAfter; if (depth < range.depth && node.canReplace(index, endIndex, content)) return depth; if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex)) break; if (index) contentBefore = 1; if (endIndex < node.childCount) contentAfter = 1; } return null; } function lift$2(tr2, range, target) { let { $from, $to, depth } = range; let gapStart = $from.before(depth + 1), gapEnd = $to.after(depth + 1); let start = gapStart, end = gapEnd; let before = Fragment.empty, openStart = 0; for (let d = depth, splitting = false; d > target; d--) if (splitting || $from.index(d) > 0) { splitting = true; before = Fragment.from($from.node(d).copy(before)); openStart++; } else { start--; } let after = Fragment.empty, openEnd = 0; for (let d = depth, splitting = false; d > target; d--) if (splitting || $to.after(d + 1) < $to.end(d)) { splitting = true; after = Fragment.from($to.node(d).copy(after)); openEnd++; } else { end++; } tr2.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true)); } function findWrapping(range, nodeType, attrs = null, innerRange = range) { let around = findWrappingOutside(range, nodeType); let inner = around && findWrappingInside(innerRange, nodeType); if (!inner) return null; return around.map(withAttrs).concat({ type: nodeType, attrs }).concat(inner.map(withAttrs)); } function withAttrs(type) { return { type, attrs: null }; } function findWrappingOutside(range, type) { let { parent, startIndex, endIndex } = range; let around = parent.contentMatchAt(startIndex).findWrapping(type); if (!around) return null; let outer = around.length ? around[0] : type; return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null; } function findWrappingInside(range, type) { let { parent, startIndex, endIndex } = range; let inner = parent.child(startIndex); let inside = type.contentMatch.findWrapping(inner.type); if (!inside) return null; let lastType = inside.length ? inside[inside.length - 1] : type; let innerMatch = lastType.contentMatch; for (let i = startIndex; innerMatch && i < endIndex; i++) innerMatch = innerMatch.matchType(parent.child(i).type); if (!innerMatch || !innerMatch.validEnd) return null; return inside; } function wrap(tr2, range, wrappers) { let content = Fragment.empty; for (let i = wrappers.length - 1; i >= 0; i--) { if (content.size) { let match = wrappers[i].type.contentMatch.matchFragment(content); if (!match || !match.validEnd) throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper"); } content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content)); } let start = range.start, end = range.end; tr2.step(new ReplaceAroundStep(start, end, start, end, new Slice(content, 0, 0), wrappers.length, true)); } function setBlockType$1(tr2, from2, to, type, attrs) { if (!type.isTextblock) throw new RangeError("Type given to setBlockType should be a textblock"); let mapFrom = tr2.steps.length; tr2.doc.nodesBetween(from2, to, (node, pos) => { let attrsHere = typeof attrs == "function" ? attrs(node) : attrs; if (node.isTextblock && !node.hasMarkup(type, attrsHere) && canChangeType(tr2.doc, tr2.mapping.slice(mapFrom).map(pos), type)) { let convertNewlines = null; if (type.schema.linebreakReplacement) { let pre = type.whitespace == "pre", supportLinebreak = !!type.contentMatch.matchType(type.schema.linebreakReplacement); if (pre && !supportLinebreak) convertNewlines = false; else if (!pre && supportLinebreak) convertNewlines = true; } if (convertNewlines === false) replaceLinebreaks(tr2, node, pos, mapFrom); clearIncompatible(tr2, tr2.mapping.slice(mapFrom).map(pos, 1), type, void 0, convertNewlines === null); let mapping = tr2.mapping.slice(mapFrom); let startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1); tr2.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type.create(attrsHere, null, node.marks)), 0, 0), 1, true)); if (convertNewlines === true) replaceNewlines(tr2, node, pos, mapFrom); return false; } }); } function replaceNewlines(tr2, node, pos, mapFrom) { node.forEach((child, offset2) => { if (child.isText) { let m, newline = /\r?\n|\r/g; while (m = newline.exec(child.text)) { let start = tr2.mapping.slice(mapFrom).map(pos + 1 + offset2 + m.index); tr2.replaceWith(start, start + 1, node.type.schema.linebreakReplacement.create()); } } }); } function replaceLinebreaks(tr2, node, pos, mapFrom) { node.forEach((child, offset2) => { if (child.type == child.type.schema.linebreakReplacement) { let start = tr2.mapping.slice(mapFrom).map(pos + 1 + offset2); tr2.replaceWith(start, start + 1, node.type.schema.text("\n")); } }); } function canChangeType(doc2, pos, type) { let $pos = doc2.resolve(pos), index = $pos.index(); return $pos.parent.canReplaceWith(index, index + 1, type); } function setNodeMarkup(tr2, pos, type, attrs, marks) { let node = tr2.doc.nodeAt(pos); if (!node) throw new RangeError("No node at given position"); if (!type) type = node.type; let newNode = type.create(attrs, null, marks || node.marks); if (node.isLeaf) return tr2.replaceWith(pos, pos + node.nodeSize, newNode); if (!type.validContent(node.content)) throw new RangeError("Invalid content for node type " + type.name); tr2.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true)); } function canSplit(doc2, pos, depth = 1, typesAfter) { let $pos = doc2.resolve(pos), base2 = $pos.depth - depth; let innerType = typesAfter && typesAfter[typesAfter.length - 1] || $pos.parent; if (base2 < 0 || $pos.parent.type.spec.isolating || !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) || !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount))) return false; for (let d = $pos.depth - 1, i = depth - 2; d > base2; d--, i--) { let node = $pos.node(d), index2 = $pos.index(d); if (node.type.spec.isolating) return false; let rest = node.content.cutByIndex(index2, node.childCount); let overrideChild = typesAfter && typesAfter[i + 1]; if (overrideChild) rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs)); let after = typesAfter && typesAfter[i] || node; if (!node.canReplace(index2 + 1, node.childCount) || !after.type.validContent(rest)) return false; } let index = $pos.indexAfter(base2); let baseType = typesAfter && typesAfter[0]; return $pos.node(base2).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base2 + 1).type); } function split(tr2, pos, depth = 1, typesAfter) { let $pos = tr2.doc.resolve(pos), before = Fragment.empty, after = Fragment.empty; for (let d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) { before = Fragment.from($pos.node(d).copy(before)); let typeAfter = typesAfter && typesAfter[i]; after = Fragment.from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after)); } tr2.step(new ReplaceStep(pos, pos, new Slice(before.append(after), depth, depth), true)); } function canJoin(doc2, pos) { let $pos = doc2.resolve(pos), index = $pos.index(); return joinable($pos.nodeBefore, $pos.nodeAfter) && $pos.parent.canReplace(index, index + 1); } function canAppendWithSubstitutedLinebreaks(a, b) { if (!b.content.size) a.type.compatibleContent(b.type); let match = a.contentMatchAt(a.childCount); let { linebreakReplacement } = a.type.schema; for (let i = 0; i < b.childCount; i++) { let child = b.child(i); let type = child.type == linebreakReplacement ? a.type.schema.nodes.text : child.type; match = match.matchType(type); if (!match) return false; if (!a.type.allowsMarks(child.marks)) return false; } return match.validEnd; } function joinable(a, b) { return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b)); } function joinPoint(doc2, pos, dir = -1) { let $pos = doc2.resolve(pos); for (let d = $pos.depth; ; d--) { let before, after, index = $pos.index(d); if (d == $pos.depth) { before = $pos.nodeBefore; after = $pos.nodeAfter; } else if (dir > 0) { before = $pos.node(d + 1); index++; after = $pos.node(d).maybeChild(index); } else { before = $pos.node(d).maybeChild(index - 1); after = $pos.node(d + 1); } if (before && !before.isTextblock && joinable(before, after) && $pos.node(d).canReplace(index, index + 1)) return pos; if (d == 0) break; pos = dir < 0 ? $pos.before(d) : $pos.after(d); } } function join(tr2, pos, depth) { let convertNewlines = null; let { linebreakReplacement } = tr2.doc.type.schema; let $before = tr2.doc.resolve(pos - depth), beforeType = $before.node().type; if (linebreakReplacement && beforeType.inlineContent) { let pre = beforeType.whitespace == "pre"; let supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement); if (pre && !supportLinebreak) convertNewlines = false; else if (!pre && supportLinebreak) convertNewlines = true; } let mapFrom = tr2.steps.length; if (convertNewlines === false) { let $after = tr2.doc.resolve(pos + depth); replaceLinebreaks(tr2, $after.node(), $after.before(), mapFrom); } if (beforeType.inlineContent) clearIncompatible(tr2, pos + depth - 1, beforeType, $before.node().contentMatchAt($before.index()), convertNewlines == null); let mapping = tr2.mapping.slice(mapFrom), start = mapping.map(pos - depth); tr2.step(new ReplaceStep(start, mapping.map(pos + depth, -1), Slice.empty, true)); if (convertNewlines === true) { let $full = tr2.doc.resolve(start); replaceNewlines(tr2, $full.node(), $full.before(), tr2.steps.length); } return tr2; } function insertPoint(doc2, pos, nodeType) { let $pos = doc2.resolve(pos); if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType)) return pos; if ($pos.parentOffset == 0) for (let d = $pos.depth - 1; d >= 0; d--) { let index = $pos.index(d); if ($pos.node(d).canReplaceWith(index, index, nodeType)) return $pos.before(d + 1); if (index > 0) return null; } if ($pos.parentOffset == $pos.parent.content.size) for (let d = $pos.depth - 1; d >= 0; d--) { let index = $pos.indexAfter(d); if ($pos.node(d).canReplaceWith(index, index, nodeType)) return $pos.after(d + 1); if (index < $pos.node(d).childCount) return null; } return null; } function dropPoint(doc2, pos, slice2) { let $pos = doc2.resolve(pos); if (!slice2.content.size) return pos; let content = slice2.content; for (let i = 0; i < slice2.openStart; i++) content = content.firstChild.content; for (let pass = 1; pass <= (slice2.openStart == 0 && slice2.size ? 2 : 1); pass++) { for (let d = $pos.depth; d >= 0; d--) { let bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1; let insertPos = $pos.index(d) + (bias > 0 ? 1 : 0); let parent = $pos.node(d), fits = false; if (pass == 1) { fits = parent.canReplace(insertPos, insertPos, content); } else { let wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type); fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]); } if (fits) return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1); } } return null; } function replaceStep(doc2, from2, to = from2, slice2 = Slice.empty) { if (from2 == to && !slice2.size) return null; let $from = doc2.resolve(from2), $to = doc2.resolve(to); if (fitsTrivially($from, $to, slice2)) return new ReplaceStep(from2, to, slice2); return new Fitter($from, $to, slice2).fit(); } function fitsTrivially($from, $to, slice2) { return !slice2.openStart && !slice2.openEnd && $from.start() == $to.start() && $from.parent.canReplace($from.index(), $to.index(), slice2.content); } class Fitter { constructor($from, $to, unplaced) { this.$from = $from; this.$to = $to; this.unplaced = unplaced; this.frontier = []; this.placed = Fragment.empty; for (let i = 0; i <= $from.depth; i++) { let node = $from.node(i); this.frontier.push({ type: node.type, match: node.contentMatchAt($from.indexAfter(i)) }); } for (let i = $from.depth; i > 0; i--) this.placed = Fragment.from($from.node(i).copy(this.placed)); } get depth() { return this.frontier.length - 1; } fit() { while (this.unplaced.size) { let fit = this.findFittable(); if (fit) this.placeNodes(fit); else this.openMore() || this.dropNode(); } let moveInline = this.mustMoveInline(), placedSize = this.placed.size - this.depth - this.$from.depth; let $from = this.$from, $to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline)); if (!$to) return null; let content = this.placed, openStart = $from.depth, openEnd = $to.depth; while (openStart && openEnd && content.childCount == 1) { content = content.firstChild.content; openStart--; openEnd--; } let slice2 = new Slice(content, openStart, openEnd); if (moveInline > -1) return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice2, placedSize); if (slice2.size || $from.pos != this.$to.pos) return new ReplaceStep($from.pos, $to.pos, slice2); return null; } // Find a position on the start spine of `this.unplaced` that has // content that can be moved somewhere on the frontier. Returns two // depths, one for the slice and one for the frontier. findFittable() { let startDepth = this.unplaced.openStart; for (let cur = this.unplaced.content, d = 0, openEnd = this.unplaced.openEnd; d < startDepth; d++) { let node = cur.firstChild; if (cur.childCount > 1) openEnd = 0; if (node.type.spec.isolating && openEnd <= d) { startDepth = d; break; } cur = node.content; } for (let pass = 1; pass <= 2; pass++) { for (let sliceDepth = pass == 1 ? startDepth : this.unplaced.openStart; sliceDepth >= 0; sliceDepth--) { let fragment, parent = null; if (sliceDepth) { parent = contentAt(this.unplaced.content, sliceDepth - 1).firstChild; fragment = parent.content; } else { fragment = this.unplaced.content; } let first2 = fragment.firstChild; for (let frontierDepth = this.depth; frontierDepth >= 0; frontierDepth--) { let { type, match } = this.frontier[frontierDepth], wrap2, inject = null; if (pass == 1 && (first2 ? match.matchType(first2.type) || (inject = match.fillBefore(Fragment.from(first2), false)) : parent && type.compatibleContent(parent.type))) return { sliceDepth, frontierDepth, parent, inject }; else if (pass == 2 && first2 && (wrap2 = match.findWrapping(first2.type))) return { sliceDepth, frontierDepth, parent, wrap: wrap2 }; if (parent && match.matchType(parent.type)) break; } } } } openMore() { let { content, openStart, openEnd } = this.unplaced; let inner = contentAt(content, openStart); if (!inner.childCount || inner.firstChild.isLeaf) return false; this.unplaced = new Slice(content, openStart + 1, Math.max(openEnd, inner.size + openStart >= content.size - openEnd ? openStart + 1 : 0)); return true; } dropNode() { let { content, openStart, openEnd } = this.unplaced; let inner = contentAt(content, openStart); if (inner.childCount <= 1 && openStart > 0) { let openAtEnd = content.size - openStart <= openStart + inner.size; this.unplaced = new Slice(dropFromFragment(content, openStart - 1, 1), openStart - 1, openAtEnd ? openStart - 1 : openEnd); } else { this.unplaced = new Slice(dropFromFragment(content, openStart, 1), openStart, openEnd); } } // Move content from the unplaced slice at `sliceDepth` to the // frontier node at `frontierDepth`. Close that frontier node when // applicable. placeNodes({ sliceDepth, frontierDepth, parent, inject, wrap: wrap2 }) { while (this.depth > frontierDepth) this.closeFrontierNode(); if (wrap2) for (let i = 0; i < wrap2.length; i++) this.openFrontierNode(wrap2[i]); let slice2 = this.unplaced, fragment = parent ? parent.content : slice2.content; let openStart = slice2.openStart - sliceDepth; let taken = 0, add = []; let { match, type } = this.frontier[frontierDepth]; if (inject) { for (let i = 0; i < inject.childCount; i++) add.push(inject.child(i)); match = match.matchFragment(inject); } let openEndCount = fragment.size + sliceDepth - (slice2.content.size - slice2.openEnd); while (taken < fragment.childCount) { let next = fragment.child(taken), matches2 = match.matchType(next.type); if (!matches2) break; taken++; if (taken > 1 || openStart == 0 || next.content.size) { match = matches2; add.push(closeNodeStart(next.mark(type.allowedMarks(next.marks)), taken == 1 ? openStart : 0, taken == fragment.childCount ? openEndCount : -1)); } } let toEnd = taken == fragment.childCount; if (!toEnd) openEndCount = -1; this.placed = addToFragment(this.placed, frontierDepth, Fragment.from(add)); this.frontier[frontierDepth].match = match; if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1) this.closeFrontierNode(); for (let i = 0, cur = fragment; i < openEndCount; i++) { let node = cur.lastChild; this.frontier.push({ type: node.type, match: node.contentMatchAt(node.childCount) }); cur = node.content; } this.unplaced = !toEnd ? new Slice(dropFromFragment(slice2.content, sliceDepth, taken), slice2.openStart, slice2.openEnd) : sliceDepth == 0 ? Slice.empty : new Slice(dropFromFragment(slice2.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice2.openEnd : sliceDepth - 1); } mustMoveInline() { if (!this.$to.parent.isTextblock) return -1; let top = this.frontier[this.depth], level; if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) || this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth) return -1; let { depth } = this.$to, after = this.$to.after(depth); while (depth > 1 && after == this.$to.end(--depth)) ++after; return after; } findCloseLevel($to) { scan: for (let i = Math.min(this.depth, $to.depth); i >= 0; i--) { let { match, type } = this.frontier[i]; let dropInner = i < $to.depth && $to.end(i + 1) == $to.pos + ($to.depth - (i + 1)); let fit = contentAfterFits($to, i, type, match, dropInner); if (!fit) continue; for (let d = i - 1; d >= 0; d--) { let { match: match2, type: type2 } = this.frontier[d]; let matches2 = contentAfterFits($to, d, type2, match2, true); if (!matches2 || matches2.childCount) continue scan; } return { depth: i, fit, move: dropInner ? $to.doc.resolve($to.after(i + 1)) : $to }; } } close($to) { let close2 = this.findCloseLevel($to); if (!close2) return null; while (this.depth > close2.depth) this.closeFrontierNode(); if (close2.fit.childCount) this.placed = addToFragment(this.placed, close2.depth, close2.fit); $to = close2.move; for (let d = close2.depth + 1; d <= $to.depth; d++) { let node = $to.node(d), add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d)); this.openFrontierNode(node.type, node.attrs, add); } return $to; } openFrontierNode(type, attrs = null, content) { let top = this.frontier[this.depth]; top.match = top.match.matchType(type); this.placed = addToFragment(this.placed, this.depth, Fragment.from(type.create(attrs, content))); this.frontier.push({ type, match: type.contentMatch }); } closeFrontierNode() { let open = this.frontier.pop(); let add = open.match.fillBefore(Fragment.empty, true); if (add.childCount) this.placed = addToFragment(this.placed, this.frontier.length, add); } } function dropFromFragment(fragment, depth, count) { if (depth == 0) return fragment.cutByIndex(count, fragment.childCount); return fragment.replaceChild(0, fragment.firstChild.copy(dropFromFragment(fragment.firstChild.content, depth - 1, count))); } function addToFragment(fragment, depth, content) { if (depth == 0) return fragment.append(content); return fragment.replaceChild(fragment.childCount - 1, fragment.lastChild.copy(addToFragment(fragment.lastChild.content, depth - 1, content))); } function contentAt(fragment, depth) { for (let i = 0; i < depth; i++) fragment = fragment.firstChild.content; return fragment; } function closeNodeStart(node, openStart, openEnd) { if (openStart <= 0) return node; let frag = node.content; if (openStart > 1) frag = frag.replaceChild(0, closeNodeStart(frag.firstChild, openStart - 1, frag.childCount == 1 ? openEnd - 1 : 0)); if (openStart > 0) { frag = node.type.contentMatch.fillBefore(frag).append(frag); if (openEnd <= 0) frag = frag.append(node.type.contentMatch.matchFragment(frag).fillBefore(Fragment.empty, true)); } return node.copy(frag); } function contentAfterFits($to, depth, type, match, open) { let node = $to.node(depth), index = open ? $to.indexAfter(depth) : $to.index(depth); if (index == node.childCount && !type.compatibleContent(node.type)) return null; let fit = match.fillBefore(node.content, true, index); return fit && !invalidMarks(type, node.content, index) ? fit : null; } function invalidMarks(type, fragment, start) { for (let i = start; i < fragment.childCount; i++) if (!type.allowsMarks(fragment.child(i).marks)) return true; return false; } function definesContent(type) { return type.spec.defining || type.spec.definingForContent; } function replaceRange(tr2, from2, to, slice2) { if (!slice2.size) return tr2.deleteRange(from2, to); let $from = tr2.doc.resolve(from2), $to = tr2.doc.resolve(to); if (fitsTrivially($from, $to, slice2)) return tr2.step(new ReplaceStep(from2, to, slice2)); let targetDepths = coveredDepths($from, $to); if (targetDepths[targetDepths.length - 1] == 0) targetDepths.pop(); let preferredTarget = -($from.depth + 1); targetDepths.unshift(preferredTarget); for (let d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) { let spec = $from.node(d).type.spec; if (spec.defining || spec.definingAsContext || spec.isolating) break; if (targetDepths.indexOf(d) > -1) preferredTarget = d; else if ($from.before(d) == pos) targetDepths.splice(1, 0, -d); } let preferredTargetIndex = targetDepths.indexOf(preferredTarget); let leftNodes = [], preferredDepth = slice2.openStart; for (let content = slice2.content, i = 0; ; i++) { let node = content.firstChild; leftNodes.push(node); if (i == slice2.openStart) break; content = node.content; } for (let d = preferredDepth - 1; d >= 0; d--) { let leftNode = leftNodes[d], def = definesContent(leftNode.type); if (def && !leftNode.sameMarkup($from.node(Math.abs(preferredTarget) - 1))) preferredDepth = d; else if (def || !leftNode.type.isTextblock) break; } for (let j = slice2.openStart; j >= 0; j--) { let openDepth = (j + preferredDepth + 1) % (slice2.openStart + 1); let insert = leftNodes[openDepth]; if (!insert) continue; for (let i = 0; i < targetDepths.length; i++) { let targetDepth = targetDepths[(i + preferredTargetIndex) % targetDepths.length], expand = true; if (targetDepth < 0) { expand = false; targetDepth = -targetDepth; } let parent = $from.node(targetDepth - 1), index = $from.index(targetDepth - 1); if (parent.canReplaceWith(index, index, insert.type, insert.marks)) return tr2.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, new Slice(closeFragment(slice2.content, 0, slice2.openStart, openDepth), openDepth, slice2.openEnd)); } } let startSteps = tr2.steps.length; for (let i = targetDepths.length - 1; i >= 0; i--) { tr2.replace(from2, to, slice2); if (tr2.steps.length > startSteps) break; let depth = targetDepths[i]; if (depth < 0) continue; from2 = $from.before(depth); to = $to.after(depth); } } function closeFragment(fragment, depth, oldOpen, newOpen, parent) { if (depth < oldOpen) { let first2 = fragment.firstChild; fragment = fragment.replaceChild(0, first2.copy(closeFragment(first2.content, depth + 1, oldOpen, newOpen, first2))); } if (depth > newOpen) { let match = parent.contentMatchAt(0); let start = match.fillBefore(fragment).append(fragment); fragment = start.append(match.matchFragment(start).fillBefore(Fragment.empty, true)); } return fragment; } function replaceRangeWith(tr2, from2, to, node) { if (!node.isInline && from2 == to && tr2.doc.resolve(from2).parent.content.size) { let point = insertPoint(tr2.doc, from2, node.type); if (point != null) from2 = to = point; } tr2.replaceRange(from2, to, new Slice(Fragment.from(node), 0, 0)); } function deleteRange$1(tr2, from2, to) { let $from = tr2.doc.resolve(from2), $to = tr2.doc.resolve(to); if ($from.parent.isTextblock && $to.parent.isTextblock && $from.start() != $to.start() && $from.parentOffset == 0 && $to.parentOffset == 0) { let shared = $from.sharedDepth(to), isolated = false; for (let d = $from.depth; d > shared; d--) if ($from.node(d).type.spec.isolating) isolated = true; for (let d = $to.depth; d > shared; d--) if ($to.node(d).type.spec.isolating) isolated = true; if (!isolated) { for (let d = $from.depth; d > 0 && from2 == $from.start(d); d--) from2 = $from.before(d); for (let d = $to.depth; d > 0 && to == $to.start(d); d--) to = $to.before(d); $from = tr2.doc.resolve(from2); $to = tr2.doc.resolve(to); } } let covered = coveredDepths($from, $to); for (let i = 0; i < covered.length; i++) { let depth = covered[i], last = i == covered.length - 1; if (last && depth == 0 || $from.node(depth).type.contentMatch.validEnd) return tr2.delete($from.start(depth), $to.end(depth)); if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1)))) return tr2.delete($from.before(depth), $to.after(depth)); } for (let d = 1; d <= $from.depth && d <= $to.depth; d++) { if (from2 - $from.start(d) == $from.depth - d && to > $from.end(d) && $to.end(d) - to != $to.depth - d && $from.start(d - 1) == $to.start(d - 1) && $from.node(d - 1).canReplace($from.index(d - 1), $to.index(d - 1))) return tr2.delete($from.before(d), to); } tr2.delete(from2, to); } function coveredDepths($from, $to) { let result = [], minDepth = Math.min($from.depth, $to.depth); for (let d = minDepth; d >= 0; d--) { let start = $from.start(d); if (start < $from.pos - ($from.depth - d) || $to.end(d) > $to.pos + ($to.depth - d) || $from.node(d).type.spec.isolating || $to.node(d).type.spec.isolating) break; if (start == $to.start(d) || d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent && d && $to.start(d - 1) == start - 1) result.push(d); } return result; } class AttrStep extends Step { /** Construct an attribute step. */ constructor(pos, attr, value) { super(); this.pos = pos; this.attr = attr; this.value = value; } apply(doc2) { let node = doc2.nodeAt(this.pos); if (!node) return StepResult.fail("No node at attribute step's position"); let attrs = /* @__PURE__ */ Object.create(null); for (let name in node.attrs) attrs[name] = node.attrs[name]; attrs[this.attr] = this.value; let updated = node.type.create(attrs, null, node.marks); return StepResult.fromReplace(doc2, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1)); } getMap() { return StepMap.empty; } invert(doc2) { return new AttrStep(this.pos, this.attr, doc2.nodeAt(this.pos).attrs[this.attr]); } map(mapping) { let pos = mapping.mapResult(this.pos, 1); return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value); } toJSON() { return { stepType: "attr", pos: this.pos, attr: this.attr, value: this.value }; } static fromJSON(schema, json) { if (typeof json.pos != "number" || typeof json.attr != "string") throw new RangeError("Invalid input for AttrStep.fromJSON"); return new AttrStep(json.pos, json.attr, json.value); } } Step.jsonID("attr", AttrStep); class DocAttrStep extends Step { /** Construct an attribute step. */ constructor(attr, value) { super(); this.attr = attr; this.value = value; } apply(doc2) { let attrs = /* @__PURE__ */ Object.create(null); for (let name in doc2.attrs) attrs[name] = doc2.attrs[name]; attrs[this.attr] = this.value; let updated = doc2.type.create(attrs, doc2.content, doc2.marks); return StepResult.ok(updated); } getMap() { return StepMap.empty; } invert(doc2) { return new DocAttrStep(this.attr, doc2.attrs[this.attr]); } map(mapping) { return this; } toJSON() { return { stepType: "docAttr", attr: this.attr, value: this.value }; } static fromJSON(schema, json) { if (typeof json.attr != "string") throw new RangeError("Invalid input for DocAttrStep.fromJSON"); return new DocAttrStep(json.attr, json.value); } } Step.jsonID("docAttr", DocAttrStep); let TransformError = class extends Error { }; TransformError = function TransformError2(message) { let err = Error.call(this, message); err.__proto__ = TransformError2.prototype; return err; }; TransformError.prototype = Object.create(Error.prototype); TransformError.prototype.constructor = TransformError; TransformError.prototype.name = "TransformError"; class Transform { /** Create a transform that starts with the given document. */ constructor(doc2) { this.doc = doc2; this.steps = []; this.docs = []; this.mapping = new Mapping(); } /** The starting document. */ get before() { return this.docs.length ? this.docs[0] : this.doc; } /** Apply a new step in this transform, saving the result. Throws an error when the step fails. */ step(step) { let result = this.maybeStep(step); if (result.failed) throw new TransformError(result.failed); return this; } /** Try to apply a step in this transformation, ignoring it if it fails. Returns the step result. */ maybeStep(step) { let result = step.apply(this.doc); if (!result.failed) this.addStep(step, result.doc); return result; } /** True when the document has been changed (when there are any steps). */ get docChanged() { return this.steps.length > 0; } /** Return a single range, in post-transform document positions, that covers all content changed by this transform. Returns null if no replacements are made. Note that this will ignore changes that add/remove marks without replacing the underlying content. */ changedRange() { let from2 = 1e9, to = -1e9; for (let i = 0; i < this.mapping.maps.length; i++) { let map2 = this.mapping.maps[i]; if (i) { from2 = map2.map(from2, 1); to = map2.map(to, -1); } map2.forEach((_f, _t, fromB, toB) => { from2 = Math.min(from2, fromB); to = Math.max(to, toB); }); } return from2 == 1e9 ? null : { from: from2, to }; } /** @internal */ addStep(step, doc2) { this.docs.push(this.doc); this.steps.push(step); this.mapping.appendMap(step.getMap()); this.doc = doc2; } /** Replace the part of the document between `from` and `to` with the given `slice`. */ replace(from2, to = from2, slice2 = Slice.empty) { let step = replaceStep(this.doc, from2, to, slice2); if (step) this.step(step); return this; } /** Replace the given range with the given content, which may be a fragment, node, or array of nodes. */ replaceWith(from2, to, content) { return this.replace(from2, to, new Slice(Fragment.from(content), 0, 0)); } /** Delete the content between the given positions. */ delete(from2, to) { return this.replace(from2, to, Slice.empty); } /** Insert the given content at the given position. */ insert(pos, content) { return this.replaceWith(pos, pos, content); } /** Replace a range of the document with a given slice, using `from`, `to`, and the slice's [`openStart`](https://prosemirror.net/docs/ref/#model.Slice.openStart) property as hints, rather than fixed start and end points. This method may grow the replaced area or close open nodes in the slice in order to get a fit that is more in line with WYSIWYG expectations, by dropping fully covered parent nodes of the replaced region when they are marked [non-defining as context](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext), or including an open parent node from the slice that _is_ marked as [defining its content](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent). This is the method, for example, to handle paste. The similar [`replace`](https://prosemirror.net/docs/ref/#transform.Transform.replace) method is a more primitive tool which will _not_ move the start and end of its given range, and is useful in situations where you need more precise control over what happens. */ replaceRange(from2, to, slice2) { replaceRange(this, from2, to, slice2); return this; } /** Replace the given range with a node, but use `from` and `to` as hints, rather than precise positions. When from and to are the same and are at the start or end of a parent node in which the given node doesn't fit, this method may _move_ them out towards a parent that does allow the given node to be placed. When the given range completely covers a parent node, this method may completely replace that parent node. */ replaceRangeWith(from2, to, node) { replaceRangeWith(this, from2, to, node); return this; } /** Delete the given range, expanding it to cover fully covered parent nodes until a valid replace is found. */ deleteRange(from2, to) { deleteRange$1(this, from2, to); return this; } /** Split the content in the given range off from its parent, if there is sibling content before or after it, and move it up the tree to the depth specified by `target`. You'll probably want to use [`liftTarget`](https://prosemirror.net/docs/ref/#transform.liftTarget) to compute `target`, to make sure the lift is valid. */ lift(range, target) { lift$2(this, range, target); return this; } /** Join the blocks around the given position. If depth is 2, their last and first siblings are also joined, and so on. */ join(pos, depth = 1) { join(this, pos, depth); return this; } /** Wrap the given [range](https://prosemirror.net/docs/ref/#model.NodeRange) in the given set of wrappers. The wrappers are assumed to be valid in this position, and should probably be computed with [`findWrapping`](https://prosemirror.net/docs/ref/#transform.findWrapping). */ wrap(range, wrappers) { wrap(this, range, wrappers); return this; } /** Set the type of all textblocks (partly) between `from` and `to` to the given node type with the given attributes. */ setBlockType(from2, to = from2, type, attrs = null) { setBlockType$1(this, from2, to, type, attrs); return this; } /** Change the type, attributes, and/or marks of the node at `pos`. When `type` isn't given, the existing node type is preserved, */ setNodeMarkup(pos, type, attrs = null, marks) { setNodeMarkup(this, pos, type, attrs, marks); return this; } /** Set a single attribute on a given node to a new value. The `pos` addresses the document content. Use `setDocAttribute` to set attributes on the document itself. */ setNodeAttribute(pos, attr, value) { this.step(new AttrStep(pos, attr, value)); return this; } /** Set a single attribute on the document to a new value. */ setDocAttribute(attr, value) { this.step(new DocAttrStep(attr, value)); return this; } /** Add a mark to the node at position `pos`. */ addNodeMark(pos, mark) { this.step(new AddNodeMarkStep(pos, mark)); return this; } /** Remove a mark (or all marks of the given type) from the node at position `pos`. */ removeNodeMark(pos, mark) { let node = this.doc.nodeAt(pos); if (!node) throw new RangeError("No node at position " + pos); if (mark instanceof Mark$1) { if (mark.isInSet(node.marks)) this.step(new RemoveNodeMarkStep(pos, mark)); } else { let set = node.marks, found2, steps = []; while (found2 = mark.isInSet(set)) { steps.push(new RemoveNodeMarkStep(pos, found2)); set = found2.removeFromSet(set); } for (let i = steps.length - 1; i >= 0; i--) this.step(steps[i]); } return this; } /** Split the node at the given position, and optionally, if `depth` is greater than one, any number of nodes above that. By default, the parts split off will inherit the node type of the original node. This can be changed by passing an array of types and attributes to use after the split (with the outermost nodes coming first). */ split(pos, depth = 1, typesAfter) { split(this, pos, depth, typesAfter); return this; } /** Add the given mark to the inline content between `from` and `to`. */ addMark(from2, to, mark) { addMark(this, from2, to, mark); return this; } /** Remove marks from inline nodes between `from` and `to`. When `mark` is a single mark, remove precisely that mark. When it is a mark type, remove all marks of that type. When it is null, remove all marks of any type. */ removeMark(from2, to, mark) { removeMark(this, from2, to, mark); return this; } /** Removes all marks and nodes from the content of the node at `pos` that don't match the given new parent node type. Accepts an optional starting [content match](https://prosemirror.net/docs/ref/#model.ContentMatch) as third argument. */ clearIncompatible(pos, parentType, match) { clearIncompatible(this, pos, parentType, match); return this; } } const classesById = /* @__PURE__ */ Object.create(null); class Selection { /** Initialize a selection with the head and anchor and ranges. If no ranges are given, constructs a single range across `$anchor` and `$head`. */ constructor($anchor, $head, ranges) { this.$anchor = $anchor; this.$head = $head; this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))]; } /** The selection's anchor, as an unresolved position. */ get anchor() { return this.$anchor.pos; } /** The selection's head. */ get head() { return this.$head.pos; } /** The lower bound of the selection's main range. */ get from() { return this.$from.pos; } /** The upper bound of the selection's main range. */ get to() { return this.$to.pos; } /** The resolved lower bound of the selection's main range. */ get $from() { return this.ranges[0].$from; } /** The resolved upper bound of the selection's main range. */ get $to() { return this.ranges[0].$to; } /** Indicates whether the selection contains any content. */ get empty() { let ranges = this.ranges; for (let i = 0; i < ranges.length; i++) if (ranges[i].$from.pos != ranges[i].$to.pos) return false; return true; } /** Get the content of this selection as a slice. */ content() { return this.$from.doc.slice(this.from, this.to, true); } /** Replace the selection with a slice or, if no slice is given, delete the selection. Will append to the given transaction. */ replace(tr2, content = Slice.empty) { let lastNode = content.content.lastChild, lastParent = null; for (let i = 0; i < content.openEnd; i++) { lastParent = lastNode; lastNode = lastNode.lastChild; } let mapFrom = tr2.steps.length, ranges = this.ranges; for (let i = 0; i < ranges.length; i++) { let { $from, $to } = ranges[i], mapping = tr2.mapping.slice(mapFrom); tr2.replaceRange(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content); if (i == 0) selectionToInsertionEnd$1(tr2, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1); } } /** Replace the selection with the given node, appending the changes to the given transaction. */ replaceWith(tr2, node) { let mapFrom = tr2.steps.length, ranges = this.ranges; for (let i = 0; i < ranges.length; i++) { let { $from, $to } = ranges[i], mapping = tr2.mapping.slice(mapFrom); let from2 = mapping.map($from.pos), to = mapping.map($to.pos); if (i) { tr2.deleteRange(from2, to); } else { tr2.replaceRangeWith(from2, to, node); selectionToInsertionEnd$1(tr2, mapFrom, node.isInline ? -1 : 1); } } } /** Find a valid cursor or leaf node selection starting at the given position and searching back if `dir` is negative, and forward if positive. When `textOnly` is true, only consider cursor selections. Will return null when no valid selection position is found. */ static findFrom($pos, dir, textOnly = false) { let inner = $pos.parent.inlineContent ? new TextSelection($pos) : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly); if (inner) return inner; for (let depth = $pos.depth - 1; depth >= 0; depth--) { let found2 = dir < 0 ? findSelectionIn($pos.node(0), $pos.node(depth), $pos.before(depth + 1), $pos.index(depth), dir, textOnly) : findSelectionIn($pos.node(0), $pos.node(depth), $pos.after(depth + 1), $pos.index(depth) + 1, dir, textOnly); if (found2) return found2; } return null; } /** Find a valid cursor or leaf node selection near the given position. Searches forward first by default, but if `bias` is negative, it will search backwards first. */ static near($pos, bias = 1) { return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0)); } /** Find the cursor or leaf node selection closest to the start of the given document. Will return an [`AllSelection`](https://prosemirror.net/docs/ref/#state.AllSelection) if no valid position exists. */ static atStart(doc2) { return findSelectionIn(doc2, doc2, 0, 0, 1) || new AllSelection(doc2); } /** Find the cursor or leaf node selection closest to the end of the given document. */ static atEnd(doc2) { return findSelectionIn(doc2, doc2, doc2.content.size, doc2.childCount, -1) || new AllSelection(doc2); } /** Deserialize the JSON representation of a selection. Must be implemented for custom classes (as a static class method). */ static fromJSON(doc2, json) { if (!json || !json.type) throw new RangeError("Invalid input for Selection.fromJSON"); let cls = classesById[json.type]; if (!cls) throw new RangeError(`No selection type ${json.type} defined`); return cls.fromJSON(doc2, json); } /** To be able to deserialize selections from JSON, custom selection classes must register themselves with an ID string, so that they can be disambiguated. Try to pick something that's unlikely to clash with classes from other modules. */ static jsonID(id, selectionClass) { if (id in classesById) throw new RangeError("Duplicate use of selection JSON ID " + id); classesById[id] = selectionClass; selectionClass.prototype.jsonID = id; return selectionClass; } /** Get a [bookmark](https://prosemirror.net/docs/ref/#state.SelectionBookmark) for this selection, which is a value that can be mapped without having access to a current document, and later resolved to a real selection for a given document again. (This is used mostly by the history to track and restore old selections.) The default implementation of this method just converts the selection to a text selection and returns the bookmark for that. */ getBookmark() { return TextSelection.between(this.$anchor, this.$head).getBookmark(); } } Selection.prototype.visible = true; class SelectionRange { /** Create a range. */ constructor($from, $to) { this.$from = $from; this.$to = $to; } } let warnedAboutTextSelection = false; function checkTextSelection($pos) { if (!warnedAboutTextSelection && !$pos.parent.inlineContent) { warnedAboutTextSelection = true; console["warn"]("TextSelection endpoint not pointing into a node with inline content (" + $pos.parent.type.name + ")"); } } class TextSelection extends Selection { /** Construct a text selection between the given points. */ constructor($anchor, $head = $anchor) { checkTextSelection($anchor); checkTextSelection($head); super($anchor, $head); } /** Returns a resolved position if this is a cursor selection (an empty text selection), and null otherwise. */ get $cursor() { return this.$anchor.pos == this.$head.pos ? this.$head : null; } map(doc2, mapping) { let $head = doc2.resolve(mapping.map(this.head)); if (!$head.parent.inlineContent) return Selection.near($head); let $anchor = doc2.resolve(mapping.map(this.anchor)); return new TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head); } replace(tr2, content = Slice.empty) { super.replace(tr2, content); if (content == Slice.empty) { let marks = this.$from.marksAcross(this.$to); if (marks) tr2.ensureMarks(marks); } } eq(other) { return other instanceof TextSelection && other.anchor == this.anchor && other.head == this.head; } getBookmark() { return new TextBookmark(this.anchor, this.head); } toJSON() { return { type: "text", anchor: this.anchor, head: this.head }; } /** @internal */ static fromJSON(doc2, json) { if (typeof json.anchor != "number" || typeof json.head != "number") throw new RangeError("Invalid input for TextSelection.fromJSON"); return new TextSelection(doc2.resolve(json.anchor), doc2.resolve(json.head)); } /** Create a text selection from non-resolved positions. */ static create(doc2, anchor, head = anchor) { let $anchor = doc2.resolve(anchor); return new this($anchor, head == anchor ? $anchor : doc2.resolve(head)); } /** Return a text selection that spans the given positions or, if they aren't text positions, find a text selection near them. `bias` determines whether the method searches forward (default) or backwards (negative number) first. Will fall back to calling [`Selection.near`](https://prosemirror.net/docs/ref/#state.Selection^near) when the document doesn't contain a valid text position. */ static between($anchor, $head, bias) { let dPos = $anchor.pos - $head.pos; if (!bias || dPos) bias = dPos >= 0 ? 1 : -1; if (!$head.parent.inlineContent) { let found2 = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true); if (found2) $head = found2.$head; else return Selection.near($head, bias); } if (!$anchor.parent.inlineContent) { if (dPos == 0) { $anchor = $head; } else { $anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor; if ($anchor.pos < $head.pos != dPos < 0) $anchor = $head; } } return new TextSelection($anchor, $head); } } Selection.jsonID("text", TextSelection); class TextBookmark { constructor(anchor, head) { this.anchor = anchor; this.head = head; } map(mapping) { return new TextBookmark(mapping.map(this.anchor), mapping.map(this.head)); } resolve(doc2) { return TextSelection.between(doc2.resolve(this.anchor), doc2.resolve(this.head)); } } class NodeSelection extends Selection { /** Create a node selection. Does not verify the validity of its argument. */ constructor($pos) { let node = $pos.nodeAfter; let $end = $pos.node(0).resolve($pos.pos + node.nodeSize); super($pos, $end); this.node = node; } map(doc2, mapping) { let { deleted, pos } = mapping.mapResult(this.anchor); let $pos = doc2.resolve(pos); if (deleted) return Selection.near($pos); return new NodeSelection($pos); } content() { return new Slice(Fragment.from(this.node), 0, 0); } eq(other) { return other instanceof NodeSelection && other.anchor == this.anchor; } toJSON() { return { type: "node", anchor: this.anchor }; } getBookmark() { return new NodeBookmark(this.anchor); } /** @internal */ static fromJSON(doc2, json) { if (typeof json.anchor != "number") throw new RangeError("Invalid input for NodeSelection.fromJSON"); return new NodeSelection(doc2.resolve(json.anchor)); } /** Create a node selection from non-resolved positions. */ static create(doc2, from2) { return new NodeSelection(doc2.resolve(from2)); } /** Determines whether the given node may be selected as a node selection. */ static isSelectable(node) { return !node.isText && node.type.spec.selectable !== false; } } NodeSelection.prototype.visible = false; Selection.jsonID("node", NodeSelection); class NodeBookmark { constructor(anchor) { this.anchor = anchor; } map(mapping) { let { deleted, pos } = mapping.mapResult(this.anchor); return deleted ? new TextBookmark(pos, pos) : new NodeBookmark(pos); } resolve(doc2) { let $pos = doc2.resolve(this.anchor), node = $pos.nodeAfter; if (node && NodeSelection.isSelectable(node)) return new NodeSelection($pos); return Selection.near($pos); } } class AllSelection extends Selection { /** Create an all-selection over the given document. */ constructor(doc2) { super(doc2.resolve(0), doc2.resolve(doc2.content.size)); } replace(tr2, content = Slice.empty) { if (content == Slice.empty) { tr2.delete(0, tr2.doc.content.size); let sel = Selection.atStart(tr2.doc); if (!sel.eq(tr2.selection)) tr2.setSelection(sel); } else { super.replace(tr2, content); } } toJSON() { return { type: "all" }; } /** @internal */ static fromJSON(doc2) { return new AllSelection(doc2); } map(doc2) { return new AllSelection(doc2); } eq(other) { return other instanceof AllSelection; } getBookmark() { return AllBookmark; } } Selection.jsonID("all", AllSelection); const AllBookmark = { map() { return this; }, resolve(doc2) { return new AllSelection(doc2); } }; function findSelectionIn(doc2, node, pos, index, dir, text = false) { if (node.inlineContent) return TextSelection.create(doc2, pos); for (let i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) { let child = node.child(i); if (!child.isAtom) { let inner = findSelectionIn(doc2, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text); if (inner) return inner; } else if (!text && NodeSelection.isSelectable(child)) { return NodeSelection.create(doc2, pos - (dir < 0 ? child.nodeSize : 0)); } pos += child.nodeSize * dir; } return null; } function selectionToInsertionEnd$1(tr2, startLen, bias) { let last = tr2.steps.length - 1; if (last < startLen) return; let step = tr2.steps[last]; if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) return; let map2 = tr2.mapping.maps[last], end; map2.forEach((_from, _to, _newFrom, newTo) => { if (end == null) end = newTo; }); tr2.setSelection(Selection.near(tr2.doc.resolve(end), bias)); } const UPDATED_SEL = 1, UPDATED_MARKS = 2, UPDATED_SCROLL = 4; class Transaction extends Transform { /** @internal */ constructor(state) { super(state.doc); this.curSelectionFor = 0; this.updated = 0; this.meta = /* @__PURE__ */ Object.create(null); this.time = Date.now(); this.curSelection = state.selection; this.storedMarks = state.storedMarks; } /** The transaction's current selection. This defaults to the editor selection [mapped](https://prosemirror.net/docs/ref/#state.Selection.map) through the steps in the transaction, but can be overwritten with [`setSelection`](https://prosemirror.net/docs/ref/#state.Transaction.setSelection). */ get selection() { if (this.curSelectionFor < this.steps.length) { this.curSelection = this.curSelection.map(this.doc, this.mapping.slice(this.curSelectionFor)); this.curSelectionFor = this.steps.length; } return this.curSelection; } /** Update the transaction's current selection. Will determine the selection that the editor gets when the transaction is applied. */ setSelection(selection) { if (selection.$from.doc != this.doc) throw new RangeError("Selection passed to setSelection must point at the current document"); this.curSelection = selection; this.curSelectionFor = this.steps.length; this.updated = (this.updated | UPDATED_SEL) & ~UPDATED_MARKS; this.storedMarks = null; return this; } /** Whether the selection was explicitly updated by this transaction. */ get selectionSet() { return (this.updated & UPDATED_SEL) > 0; } /** Set the current stored marks. */ setStoredMarks(marks) { this.storedMarks = marks; this.updated |= UPDATED_MARKS; return this; } /** Make sure the current stored marks or, if that is null, the marks at the selection, match the given set of marks. Does nothing if this is already the case. */ ensureMarks(marks) { if (!Mark$1.sameSet(this.storedMarks || this.selection.$from.marks(), marks)) this.setStoredMarks(marks); return this; } /** Add a mark to the set of stored marks. */ addStoredMark(mark) { return this.ensureMarks(mark.addToSet(this.storedMarks || this.selection.$head.marks())); } /** Remove a mark or mark type from the set of stored marks. */ removeStoredMark(mark) { return this.ensureMarks(mark.removeFromSet(this.storedMarks || this.selection.$head.marks())); } /** Whether the stored marks were explicitly set for this transaction. */ get storedMarksSet() { return (this.updated & UPDATED_MARKS) > 0; } /** @internal */ addStep(step, doc2) { super.addStep(step, doc2); this.updated = this.updated & ~UPDATED_MARKS; this.storedMarks = null; } /** Update the timestamp for the transaction. */ setTime(time) { this.time = time; return this; } /** Replace the current selection with the given slice. */ replaceSelection(slice2) { this.selection.replace(this, slice2); return this; } /** Replace the selection with the given node. When `inheritMarks` is true and the content is inline, it inherits the marks from the place where it is inserted. */ replaceSelectionWith(node, inheritMarks = true) { let selection = this.selection; if (inheritMarks) node = node.mark(this.storedMarks || (selection.empty ? selection.$from.marks() : selection.$from.marksAcross(selection.$to) || Mark$1.none)); selection.replaceWith(this, node); return this; } /** Delete the selection. */ deleteSelection() { this.selection.replace(this); return this; } /** Replace the given range, or the selection if no range is given, with a text node containing the given string. */ insertText(text, from2, to) { let schema = this.doc.type.schema; if (from2 == null) { if (!text) return this.deleteSelection(); return this.replaceSelectionWith(schema.text(text), true); } else { if (to == null) to = from2; if (!text) return this.deleteRange(from2, to); let marks = this.storedMarks; if (!marks) { let $from = this.doc.resolve(from2); marks = to == from2 ? $from.marks() : $from.marksAcross(this.doc.resolve(to)); } this.replaceRangeWith(from2, to, schema.text(text, marks)); if (!this.selection.empty && this.selection.to == from2 + text.length) this.setSelection(Selection.near(this.selection.$to)); return this; } } /** Store a metadata property in this transaction, keyed either by name or by plugin. */ setMeta(key, value) { this.meta[typeof key == "string" ? key : key.key] = value; return this; } /** Retrieve a metadata property for a given name or plugin. */ getMeta(key) { return this.meta[typeof key == "string" ? key : key.key]; } /** Returns true if this transaction doesn't contain any metadata, and can thus safely be extended. */ get isGeneric() { for (let _ in this.meta) return false; return true; } /** Indicate that the editor should scroll the selection into view when updated to the state produced by this transaction. */ scrollIntoView() { this.updated |= UPDATED_SCROLL; return this; } /** True when this transaction has had `scrollIntoView` called on it. */ get scrolledIntoView() { return (this.updated & UPDATED_SCROLL) > 0; } } function bind(f, self2) { return !self2 || !f ? f : f.bind(self2); } class FieldDesc { constructor(name, desc, self2) { this.name = name; this.init = bind(desc.init, self2); this.apply = bind(desc.apply, self2); } } const baseFields = [ new FieldDesc("doc", { init(config) { return config.doc || config.schema.topNodeType.createAndFill(); }, apply(tr2) { return tr2.doc; } }), new FieldDesc("selection", { init(config, instance) { return config.selection || Selection.atStart(instance.doc); }, apply(tr2) { return tr2.selection; } }), new FieldDesc("storedMarks", { init(config) { return config.storedMarks || null; }, apply(tr2, _marks, _old, state) { return state.selection.$cursor ? tr2.storedMarks : null; } }), new FieldDesc("scrollToSelection", { init() { return 0; }, apply(tr2, prev) { return tr2.scrolledIntoView ? prev + 1 : prev; } }) ]; class Configuration { constructor(schema, plugins) { this.schema = schema; this.plugins = []; this.pluginsByKey = /* @__PURE__ */ Object.create(null); this.fields = baseFields.slice(); if (plugins) plugins.forEach((plugin) => { if (this.pluginsByKey[plugin.key]) throw new RangeError("Adding different instances of a keyed plugin (" + plugin.key + ")"); this.plugins.push(plugin); this.pluginsByKey[plugin.key] = plugin; if (plugin.spec.state) this.fields.push(new FieldDesc(plugin.key, plugin.spec.state, plugin)); }); } } class EditorState { /** @internal */ constructor(config) { this.config = config; } /** The schema of the state's document. */ get schema() { return this.config.schema; } /** The plugins that are active in this state. */ get plugins() { return this.config.plugins; } /** Apply the given transaction to produce a new state. */ apply(tr2) { return this.applyTransaction(tr2).state; } /** @internal */ filterTransaction(tr2, ignore = -1) { for (let i = 0; i < this.config.plugins.length; i++) if (i != ignore) { let plugin = this.config.plugins[i]; if (plugin.spec.filterTransaction && !plugin.spec.filterTransaction.call(plugin, tr2, this)) return false; } return true; } /** Verbose variant of [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) that returns the precise transactions that were applied (which might be influenced by the [transaction hooks](https://prosemirror.net/docs/ref/#state.PluginSpec.filterTransaction) of plugins) along with the new state. */ applyTransaction(rootTr) { if (!this.filterTransaction(rootTr)) return { state: this, transactions: [] }; let trs = [rootTr], newState = this.applyInner(rootTr), seen = null; for (; ; ) { let haveNew = false; for (let i = 0; i < this.config.plugins.length; i++) { let plugin = this.config.plugins[i]; if (plugin.spec.appendTransaction) { let n = seen ? seen[i].n : 0, oldState = seen ? seen[i].state : this; let tr2 = n < trs.length && plugin.spec.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState); if (tr2 && newState.filterTransaction(tr2, i)) { tr2.setMeta("appendedTransaction", rootTr); if (!seen) { seen = []; for (let j = 0; j < this.config.plugins.length; j++) seen.push(j < i ? { state: newState, n: trs.length } : { state: this, n: 0 }); } trs.push(tr2); newState = newState.applyInner(tr2); haveNew = true; } if (seen) seen[i] = { state: newState, n: trs.length }; } } if (!haveNew) return { state: newState, transactions: trs }; } } /** @internal */ applyInner(tr2) { if (!tr2.before.eq(this.doc)) throw new RangeError("Applying a mismatched transaction"); let newInstance = new EditorState(this.config), fields = this.config.fields; for (let i = 0; i < fields.length; i++) { let field = fields[i]; newInstance[field.name] = field.apply(tr2, this[field.name], this, newInstance); } return newInstance; } /** Accessor that constructs and returns a new [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state. */ get tr() { return new Transaction(this); } /** Create a new state. */ static create(config) { let $config = new Configuration(config.doc ? config.doc.type.schema : config.schema, config.plugins); let instance = new EditorState($config); for (let i = 0; i < $config.fields.length; i++) instance[$config.fields[i].name] = $config.fields[i].init(config, instance); return instance; } /** Create a new state based on this one, but with an adjusted set of active plugins. State fields that exist in both sets of plugins are kept unchanged. Those that no longer exist are dropped, and those that are new are initialized using their [`init`](https://prosemirror.net/docs/ref/#state.StateField.init) method, passing in the new configuration object.. */ reconfigure(config) { let $config = new Configuration(this.schema, config.plugins); let fields = $config.fields, instance = new EditorState($config); for (let i = 0; i < fields.length; i++) { let name = fields[i].name; instance[name] = this.hasOwnProperty(name) ? this[name] : fields[i].init(config, instance); } return instance; } /** Serialize this state to JSON. If you want to serialize the state of plugins, pass an object mapping property names to use in the resulting JSON object to plugin objects. The argument may also be a string or number, in which case it is ignored, to support the way `JSON.stringify` calls `toString` methods. */ toJSON(pluginFields) { let result = { doc: this.doc.toJSON(), selection: this.selection.toJSON() }; if (this.storedMarks) result.storedMarks = this.storedMarks.map((m) => m.toJSON()); if (pluginFields && typeof pluginFields == "object") for (let prop in pluginFields) { if (prop == "doc" || prop == "selection") throw new RangeError("The JSON fields `doc` and `selection` are reserved"); let plugin = pluginFields[prop], state = plugin.spec.state; if (state && state.toJSON) result[prop] = state.toJSON.call(plugin, this[plugin.key]); } return result; } /** Deserialize a JSON representation of a state. `config` should have at least a `schema` field, and should contain array of plugins to initialize the state with. `pluginFields` can be used to deserialize the state of plugins, by associating plugin instances with the property names they use in the JSON object. */ static fromJSON(config, json, pluginFields) { if (!json) throw new RangeError("Invalid input for EditorState.fromJSON"); if (!config.schema) throw new RangeError("Required config field 'schema' missing"); let $config = new Configuration(config.schema, config.plugins); let instance = new EditorState($config); $config.fields.forEach((field) => { if (field.name == "doc") { instance.doc = Node$1.fromJSON(config.schema, json.doc); } else if (field.name == "selection") { instance.selection = Selection.fromJSON(instance.doc, json.selection); } else if (field.name == "storedMarks") { if (json.storedMarks) instance.storedMarks = json.storedMarks.map(config.schema.markFromJSON); } else { if (pluginFields) for (let prop in pluginFields) { let plugin = pluginFields[prop], state = plugin.spec.state; if (plugin.key == field.name && state && state.fromJSON && Object.prototype.hasOwnProperty.call(json, prop)) { instance[field.name] = state.fromJSON.call(plugin, config, json[prop], instance); return; } } instance[field.name] = field.init(config, instance); } }); return instance; } } function bindProps(obj, self2, target) { for (let prop in obj) { let val = obj[prop]; if (val instanceof Function) val = val.bind(self2); else if (prop == "handleDOMEvents") val = bindProps(val, self2, {}); target[prop] = val; } return target; } class Plugin { /** Create a plugin. */ constructor(spec) { this.spec = spec; this.props = {}; if (spec.props) bindProps(spec.props, this, this.props); this.key = spec.key ? spec.key.key : createKey("plugin"); } /** Extract the plugin's state field from an editor state. */ getState(state) { return state[this.key]; } } const keys$1 = /* @__PURE__ */ Object.create(null); function createKey(name) { if (name in keys$1) return name + "$" + ++keys$1[name]; keys$1[name] = 0; return name + "$"; } class PluginKey { /** Create a plugin key. */ constructor(name = "key") { this.key = createKey(name); } /** Get the active plugin with this key, if any, from an editor state. */ get(state) { return state.config.pluginsByKey[this.key]; } /** Get the plugin's state from an editor state. */ getState(state) { return state[this.key]; } } const deleteSelection$1 = (state, dispatch) => { if (state.selection.empty) return false; if (dispatch) dispatch(state.tr.deleteSelection().scrollIntoView()); return true; }; function atBlockStart(state, view) { let { $cursor } = state.selection; if (!$cursor || (view ? !view.endOfTextblock("backward", state) : $cursor.parentOffset > 0)) return null; return $cursor; } const joinBackward$1 = (state, dispatch, view) => { let $cursor = atBlockStart(state, view); if (!$cursor) return false; let $cut = findCutBefore($cursor); if (!$cut) { let range = $cursor.blockRange(), target = range && liftTarget(range); if (target == null) return false; if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); return true; } let before = $cut.nodeBefore; if (deleteBarrier(state, $cut, dispatch, -1)) return true; if ($cursor.parent.content.size == 0 && (textblockAt(before, "end") || NodeSelection.isSelectable(before))) { for (let depth = $cursor.depth; ; depth--) { let delStep = replaceStep(state.doc, $cursor.before(depth), $cursor.after(depth), Slice.empty); if (delStep && delStep.slice.size < delStep.to - delStep.from) { if (dispatch) { let tr2 = state.tr.step(delStep); tr2.setSelection(textblockAt(before, "end") ? Selection.findFrom(tr2.doc.resolve(tr2.mapping.map($cut.pos, -1)), -1) : NodeSelection.create(tr2.doc, $cut.pos - before.nodeSize)); dispatch(tr2.scrollIntoView()); } return true; } if (depth == 1 || $cursor.node(depth - 1).childCount > 1) break; } } if (before.isAtom && $cut.depth == $cursor.depth - 1) { if (dispatch) dispatch(state.tr.delete($cut.pos - before.nodeSize, $cut.pos).scrollIntoView()); return true; } return false; }; const joinTextblockBackward$1 = (state, dispatch, view) => { let $cursor = atBlockStart(state, view); if (!$cursor) return false; let $cut = findCutBefore($cursor); return $cut ? joinTextblocksAround(state, $cut, dispatch) : false; }; const joinTextblockForward$1 = (state, dispatch, view) => { let $cursor = atBlockEnd(state, view); if (!$cursor) return false; let $cut = findCutAfter($cursor); return $cut ? joinTextblocksAround(state, $cut, dispatch) : false; }; function joinTextblocksAround(state, $cut, dispatch) { let before = $cut.nodeBefore, beforeText = before, beforePos = $cut.pos - 1; for (; !beforeText.isTextblock; beforePos--) { if (beforeText.type.spec.isolating) return false; let child = beforeText.lastChild; if (!child) return false; beforeText = child; } let after = $cut.nodeAfter, afterText = after, afterPos = $cut.pos + 1; for (; !afterText.isTextblock; afterPos++) { if (afterText.type.spec.isolating) return false; let child = afterText.firstChild; if (!child) return false; afterText = child; } let step = replaceStep(state.doc, beforePos, afterPos, Slice.empty); if (!step || step.from != beforePos || step instanceof ReplaceStep && step.slice.size >= afterPos - beforePos) return false; if (dispatch) { let tr2 = state.tr.step(step); tr2.setSelection(TextSelection.create(tr2.doc, beforePos)); dispatch(tr2.scrollIntoView()); } return true; } function textblockAt(node, side, only = false) { for (let scan = node; scan; scan = side == "start" ? scan.firstChild : scan.lastChild) { if (scan.isTextblock) return true; if (only && scan.childCount != 1) return false; } return false; } const selectNodeBackward$1 = (state, dispatch, view) => { let { $head, empty: empty2 } = state.selection, $cut = $head; if (!empty2) return false; if ($head.parent.isTextblock) { if (view ? !view.endOfTextblock("backward", state) : $head.parentOffset > 0) return false; $cut = findCutBefore($head); } let node = $cut && $cut.nodeBefore; if (!node || !NodeSelection.isSelectable(node)) return false; if (dispatch) dispatch(state.tr.setSelection(NodeSelection.create(state.doc, $cut.pos - node.nodeSize)).scrollIntoView()); return true; }; function findCutBefore($pos) { if (!$pos.parent.type.spec.isolating) for (let i = $pos.depth - 1; i >= 0; i--) { if ($pos.index(i) > 0) return $pos.doc.resolve($pos.before(i + 1)); if ($pos.node(i).type.spec.isolating) break; } return null; } function atBlockEnd(state, view) { let { $cursor } = state.selection; if (!$cursor || (view ? !view.endOfTextblock("forward", state) : $cursor.parentOffset < $cursor.parent.content.size)) return null; return $cursor; } const joinForward$1 = (state, dispatch, view) => { let $cursor = atBlockEnd(state, view); if (!$cursor) return false; let $cut = findCutAfter($cursor); if (!$cut) return false; let after = $cut.nodeAfter; if (deleteBarrier(state, $cut, dispatch, 1)) return true; if ($cursor.parent.content.size == 0 && (textblockAt(after, "start") || NodeSelection.isSelectable(after))) { let delStep = replaceStep(state.doc, $cursor.before(), $cursor.after(), Slice.empty); if (delStep && delStep.slice.size < delStep.to - delStep.from) { if (dispatch) { let tr2 = state.tr.step(delStep); tr2.setSelection(textblockAt(after, "start") ? Selection.findFrom(tr2.doc.resolve(tr2.mapping.map($cut.pos)), 1) : NodeSelection.create(tr2.doc, tr2.mapping.map($cut.pos))); dispatch(tr2.scrollIntoView()); } return true; } } if (after.isAtom && $cut.depth == $cursor.depth - 1) { if (dispatch) dispatch(state.tr.delete($cut.pos, $cut.pos + after.nodeSize).scrollIntoView()); return true; } return false; }; const selectNodeForward$1 = (state, dispatch, view) => { let { $head, empty: empty2 } = state.selection, $cut = $head; if (!empty2) return false; if ($head.parent.isTextblock) { if (view ? !view.endOfTextblock("forward", state) : $head.parentOffset < $head.parent.content.size) return false; $cut = findCutAfter($head); } let node = $cut && $cut.nodeAfter; if (!node || !NodeSelection.isSelectable(node)) return false; if (dispatch) dispatch(state.tr.setSelection(NodeSelection.create(state.doc, $cut.pos)).scrollIntoView()); return true; }; function findCutAfter($pos) { if (!$pos.parent.type.spec.isolating) for (let i = $pos.depth - 1; i >= 0; i--) { let parent = $pos.node(i); if ($pos.index(i) + 1 < parent.childCount) return $pos.doc.resolve($pos.after(i + 1)); if (parent.type.spec.isolating) break; } return null; } const joinUp$1 = (state, dispatch) => { let sel = state.selection, nodeSel = sel instanceof NodeSelection, point; if (nodeSel) { if (sel.node.isTextblock || !canJoin(state.doc, sel.from)) return false; point = sel.from; } else { point = joinPoint(state.doc, sel.from, -1); if (point == null) return false; } if (dispatch) { let tr2 = state.tr.join(point); if (nodeSel) tr2.setSelection(NodeSelection.create(tr2.doc, point - state.doc.resolve(point).nodeBefore.nodeSize)); dispatch(tr2.scrollIntoView()); } return true; }; const joinDown$1 = (state, dispatch) => { let sel = state.selection, point; if (sel instanceof NodeSelection) { if (sel.node.isTextblock || !canJoin(state.doc, sel.to)) return false; point = sel.to; } else { point = joinPoint(state.doc, sel.to, 1); if (point == null) return false; } if (dispatch) dispatch(state.tr.join(point).scrollIntoView()); return true; }; const lift$1 = (state, dispatch) => { let { $from, $to } = state.selection; let range = $from.blockRange($to), target = range && liftTarget(range); if (target == null) return false; if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); return true; }; const newlineInCode$1 = (state, dispatch) => { let { $head, $anchor } = state.selection; if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) return false; if (dispatch) dispatch(state.tr.insertText("\n").scrollIntoView()); return true; }; function defaultBlockAt$1(match) { for (let i = 0; i < match.edgeCount; i++) { let { type } = match.edge(i); if (type.isTextblock && !type.hasRequiredAttrs()) return type; } return null; } const exitCode$1 = (state, dispatch) => { let { $head, $anchor } = state.selection; if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) return false; let above = $head.node(-1), after = $head.indexAfter(-1), type = defaultBlockAt$1(above.contentMatchAt(after)); if (!type || !above.canReplaceWith(after, after, type)) return false; if (dispatch) { let pos = $head.after(), tr2 = state.tr.replaceWith(pos, pos, type.createAndFill()); tr2.setSelection(Selection.near(tr2.doc.resolve(pos), 1)); dispatch(tr2.scrollIntoView()); } return true; }; const createParagraphNear$1 = (state, dispatch) => { let sel = state.selection, { $from, $to } = sel; if (sel instanceof AllSelection || $from.parent.inlineContent || $to.parent.inlineContent) return false; let type = defaultBlockAt$1($to.parent.contentMatchAt($to.indexAfter())); if (!type || !type.isTextblock) return false; if (dispatch) { let side = (!$from.parentOffset && $to.index() < $to.parent.childCount ? $from : $to).pos; let tr2 = state.tr.insert(side, type.createAndFill()); tr2.setSelection(TextSelection.create(tr2.doc, side + 1)); dispatch(tr2.scrollIntoView()); } return true; }; const liftEmptyBlock$1 = (state, dispatch) => { let { $cursor } = state.selection; if (!$cursor || $cursor.parent.content.size) return false; if ($cursor.depth > 1 && $cursor.after() != $cursor.end(-1)) { let before = $cursor.before(); if (canSplit(state.doc, before)) { if (dispatch) dispatch(state.tr.split(before).scrollIntoView()); return true; } } let range = $cursor.blockRange(), target = range && liftTarget(range); if (target == null) return false; if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); return true; }; function splitBlockAs(splitNode) { return (state, dispatch) => { let { $from, $to } = state.selection; if (state.selection instanceof NodeSelection && state.selection.node.isBlock) { if (!$from.parentOffset || !canSplit(state.doc, $from.pos)) return false; if (dispatch) dispatch(state.tr.split($from.pos).scrollIntoView()); return true; } if (!$from.depth) return false; let types = []; let splitDepth, deflt, atEnd = false, atStart = false; for (let d = $from.depth; ; d--) { let node = $from.node(d); if (node.isBlock) { atEnd = $from.end(d) == $from.pos + ($from.depth - d); atStart = $from.start(d) == $from.pos - ($from.depth - d); deflt = defaultBlockAt$1($from.node(d - 1).contentMatchAt($from.indexAfter(d - 1))); types.unshift(atEnd && deflt ? { type: deflt } : null); splitDepth = d; break; } else { if (d == 1) return false; types.unshift(null); } } let tr2 = state.tr; if (state.selection instanceof TextSelection || state.selection instanceof AllSelection) tr2.deleteSelection(); let splitPos = tr2.mapping.map($from.pos); let can = canSplit(tr2.doc, splitPos, types.length, types); if (!can) { types[0] = deflt ? { type: deflt } : null; can = canSplit(tr2.doc, splitPos, types.length, types); } if (!can) return false; tr2.split(splitPos, types.length, types); if (!atEnd && atStart && $from.node(splitDepth).type != deflt) { let first2 = tr2.mapping.map($from.before(splitDepth)), $first = tr2.doc.resolve(first2); if (deflt && $from.node(splitDepth - 1).canReplaceWith($first.index(), $first.index() + 1, deflt)) tr2.setNodeMarkup(tr2.mapping.map($from.before(splitDepth)), deflt); } if (dispatch) dispatch(tr2.scrollIntoView()); return true; }; } const splitBlock$1 = splitBlockAs(); const selectParentNode$1 = (state, dispatch) => { let { $from, to } = state.selection, pos; let same = $from.sharedDepth(to); if (same == 0) return false; pos = $from.before(same); if (dispatch) dispatch(state.tr.setSelection(NodeSelection.create(state.doc, pos))); return true; }; function joinMaybeClear(state, $pos, dispatch) { let before = $pos.nodeBefore, after = $pos.nodeAfter, index = $pos.index(); if (!before || !after || !before.type.compatibleContent(after.type)) return false; if (!before.content.size && $pos.parent.canReplace(index - 1, index)) { if (dispatch) dispatch(state.tr.delete($pos.pos - before.nodeSize, $pos.pos).scrollIntoView()); return true; } if (!$pos.parent.canReplace(index, index + 1) || !(after.isTextblock || canJoin(state.doc, $pos.pos))) return false; if (dispatch) dispatch(state.tr.join($pos.pos).scrollIntoView()); return true; } function deleteBarrier(state, $cut, dispatch, dir) { let before = $cut.nodeBefore, after = $cut.nodeAfter, conn, match; let isolated = before.type.spec.isolating || after.type.spec.isolating; if (!isolated && joinMaybeClear(state, $cut, dispatch)) return true; let canDelAfter = !isolated && $cut.parent.canReplace($cut.index(), $cut.index() + 1); if (canDelAfter && (conn = (match = before.contentMatchAt(before.childCount)).findWrapping(after.type)) && match.matchType(conn[0] || after.type).validEnd) { if (dispatch) { let end = $cut.pos + after.nodeSize, wrap2 = Fragment.empty; for (let i = conn.length - 1; i >= 0; i--) wrap2 = Fragment.from(conn[i].create(null, wrap2)); wrap2 = Fragment.from(before.copy(wrap2)); let tr2 = state.tr.step(new ReplaceAroundStep($cut.pos - 1, end, $cut.pos, end, new Slice(wrap2, 1, 0), conn.length, true)); let $joinAt = tr2.doc.resolve(end + 2 * conn.length); if ($joinAt.nodeAfter && $joinAt.nodeAfter.type == before.type && canJoin(tr2.doc, $joinAt.pos)) tr2.join($joinAt.pos); dispatch(tr2.scrollIntoView()); } return true; } let selAfter = after.type.spec.isolating || dir > 0 && isolated ? null : Selection.findFrom($cut, 1); let range = selAfter && selAfter.$from.blockRange(selAfter.$to), target = range && liftTarget(range); if (target != null && target >= $cut.depth) { if (dispatch) dispatch(state.tr.lift(range, target).scrollIntoView()); return true; } if (canDelAfter && textblockAt(after, "start", true) && textblockAt(before, "end")) { let at = before, wrap2 = []; for (; ; ) { wrap2.push(at); if (at.isTextblock) break; at = at.lastChild; } let afterText = after, afterDepth = 1; for (; !afterText.isTextblock; afterText = afterText.firstChild) afterDepth++; if (at.canReplace(at.childCount, at.childCount, afterText.content)) { if (dispatch) { let end = Fragment.empty; for (let i = wrap2.length - 1; i >= 0; i--) end = Fragment.from(wrap2[i].copy(end)); let tr2 = state.tr.step(new ReplaceAroundStep($cut.pos - wrap2.length, $cut.pos + after.nodeSize, $cut.pos + afterDepth, $cut.pos + after.nodeSize - afterDepth, new Slice(end, wrap2.length, 0), 0, true)); dispatch(tr2.scrollIntoView()); } return true; } } return false; } function selectTextblockSide(side) { return function(state, dispatch) { let sel = state.selection, $pos = side < 0 ? sel.$from : sel.$to; let depth = $pos.depth; while ($pos.node(depth).isInline) { if (!depth) return false; depth--; } if (!$pos.node(depth).isTextblock) return false; if (dispatch) dispatch(state.tr.setSelection(TextSelection.create(state.doc, side < 0 ? $pos.start(depth) : $pos.end(depth)))); return true; }; } const selectTextblockStart$1 = selectTextblockSide(-1); const selectTextblockEnd$1 = selectTextblockSide(1); function wrapIn$1(nodeType, attrs = null) { return function(state, dispatch) { let { $from, $to } = state.selection; let range = $from.blockRange($to), wrapping = range && findWrapping(range, nodeType, attrs); if (!wrapping) return false; if (dispatch) dispatch(state.tr.wrap(range, wrapping).scrollIntoView()); return true; }; } function setBlockType(nodeType, attrs = null) { return function(state, dispatch) { let applicable = false; for (let i = 0; i < state.selection.ranges.length && !applicable; i++) { let { $from: { pos: from2 }, $to: { pos: to } } = state.selection.ranges[i]; state.doc.nodesBetween(from2, to, (node, pos) => { if (applicable) return false; if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) return; if (node.type == nodeType) { applicable = true; } else { let $pos = state.doc.resolve(pos), index = $pos.index(); applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType); } }); } if (!applicable) return false; if (dispatch) { let tr2 = state.tr; for (let i = 0; i < state.selection.ranges.length; i++) { let { $from: { pos: from2 }, $to: { pos: to } } = state.selection.ranges[i]; tr2.setBlockType(from2, to, nodeType, attrs); } dispatch(tr2.scrollIntoView()); } return true; }; } function chainCommands(...commands) { return function(state, dispatch, view) { for (let i = 0; i < commands.length; i++) if (commands[i](state, dispatch, view)) return true; return false; }; } chainCommands(deleteSelection$1, joinBackward$1, selectNodeBackward$1); chainCommands(deleteSelection$1, joinForward$1, selectNodeForward$1); ({ "Enter": chainCommands(newlineInCode$1, createParagraphNear$1, liftEmptyBlock$1, splitBlock$1) }); typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : typeof os != "undefined" && os.platform ? os.platform() == "darwin" : false; function wrapInList$1(listType, attrs = null) { return function(state, dispatch) { let { $from, $to } = state.selection; let range = $from.blockRange($to); if (!range) return false; let tr2 = dispatch ? state.tr : null; if (!wrapRangeInList(tr2, range, listType, attrs)) return false; if (dispatch) dispatch(tr2.scrollIntoView()); return true; }; } function wrapRangeInList(tr2, range, listType, attrs = null) { let doJoin = false, outerRange = range, doc2 = range.$from.doc; if (range.depth >= 2 && range.$from.node(range.depth - 1).type.compatibleContent(listType) && range.startIndex == 0) { if (range.$from.index(range.depth - 1) == 0) return false; let $insert = doc2.resolve(range.start - 2); outerRange = new NodeRange($insert, $insert, range.depth); if (range.endIndex < range.parent.childCount) range = new NodeRange(range.$from, doc2.resolve(range.$to.end(range.depth)), range.depth); doJoin = true; } let wrap2 = findWrapping(outerRange, listType, attrs, range); if (!wrap2) return false; if (tr2) doWrapInList(tr2, range, wrap2, doJoin, listType); return true; } function doWrapInList(tr2, range, wrappers, joinBefore, listType) { let content = Fragment.empty; for (let i = wrappers.length - 1; i >= 0; i--) content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content)); tr2.step(new ReplaceAroundStep(range.start - (joinBefore ? 2 : 0), range.end, range.start, range.end, new Slice(content, 0, 0), wrappers.length, true)); let found2 = 0; for (let i = 0; i < wrappers.length; i++) if (wrappers[i].type == listType) found2 = i + 1; let splitDepth = wrappers.length - found2; let splitPos = range.start + wrappers.length - (joinBefore ? 2 : 0), parent = range.parent; for (let i = range.startIndex, e = range.endIndex, first2 = true; i < e; i++, first2 = false) { if (!first2 && canSplit(tr2.doc, splitPos, splitDepth)) { tr2.split(splitPos, splitDepth); splitPos += 2 * splitDepth; } splitPos += parent.child(i).nodeSize; } return tr2; } function liftListItem$1(itemType) { return function(state, dispatch) { let { $from, $to } = state.selection; let range = $from.blockRange($to, (node) => node.childCount > 0 && node.firstChild.type == itemType); if (!range) return false; if (!dispatch) return true; if ($from.node(range.depth - 1).type == itemType) return liftToOuterList(state, dispatch, itemType, range); else return liftOutOfList(state, dispatch, range); }; } function liftToOuterList(state, dispatch, itemType, range) { let tr2 = state.tr, end = range.end, endOfList = range.$to.end(range.depth); if (end < endOfList) { tr2.step(new ReplaceAroundStep(end - 1, endOfList, end, endOfList, new Slice(Fragment.from(itemType.create(null, range.parent.copy())), 1, 0), 1, true)); range = new NodeRange(tr2.doc.resolve(range.$from.pos), tr2.doc.resolve(endOfList), range.depth); } const target = liftTarget(range); if (target == null) return false; tr2.lift(range, target); let $after = tr2.doc.resolve(tr2.mapping.map(end, -1) - 1); if (canJoin(tr2.doc, $after.pos) && $after.nodeBefore.type == $after.nodeAfter.type) tr2.join($after.pos); dispatch(tr2.scrollIntoView()); return true; } function liftOutOfList(state, dispatch, range) { let tr2 = state.tr, list = range.parent; for (let pos = range.end, i = range.endIndex - 1, e = range.startIndex; i > e; i--) { pos -= list.child(i).nodeSize; tr2.delete(pos - 1, pos + 1); } let $start = tr2.doc.resolve(range.start), item = $start.nodeAfter; if (tr2.mapping.map(range.end) != range.start + $start.nodeAfter.nodeSize) return false; let atStart = range.startIndex == 0, atEnd = range.endIndex == list.childCount; let parent = $start.node(-1), indexBefore = $start.index(-1); if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, item.content.append(atEnd ? Fragment.empty : Fragment.from(list)))) return false; let start = $start.pos, end = start + item.nodeSize; tr2.step(new ReplaceAroundStep(start - (atStart ? 1 : 0), end + (atEnd ? 1 : 0), start + 1, end - 1, new Slice((atStart ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))).append(atEnd ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1)); dispatch(tr2.scrollIntoView()); return true; } function sinkListItem$1(itemType) { return function(state, dispatch) { let { $from, $to } = state.selection; let range = $from.blockRange($to, (node) => node.childCount > 0 && node.firstChild.type == itemType); if (!range) return false; let startIndex = range.startIndex; if (startIndex == 0) return false; let parent = range.parent, nodeBefore = parent.child(startIndex - 1); if (nodeBefore.type != itemType) return false; if (dispatch) { let nestedBefore = nodeBefore.lastChild && nodeBefore.lastChild.type == parent.type; let inner = Fragment.from(nestedBefore ? itemType.create() : null); let slice2 = new Slice(Fragment.from(itemType.create(null, Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0); let before = range.start, after = range.end; dispatch(state.tr.step(new ReplaceAroundStep(before - (nestedBefore ? 3 : 1), after, before, after, slice2, 1, true)).scrollIntoView()); } return true; }; } const domIndex = function(node) { for (var index = 0; ; index++) { node = node.previousSibling; if (!node) return index; } }; const parentNode = function(node) { let parent = node.assignedSlot || node.parentNode; return parent && parent.nodeType == 11 ? parent.host : parent; }; let reusedRange = null; const textRange = function(node, from2, to) { let range = reusedRange || (reusedRange = document.createRange()); range.setEnd(node, to == null ? node.nodeValue.length : to); range.setStart(node, from2 || 0); return range; }; const clearReusedRange = function() { reusedRange = null; }; const isEquivalentPosition = function(node, off, targetNode, targetOff) { return targetNode && (scanFor(node, off, targetNode, targetOff, -1) || scanFor(node, off, targetNode, targetOff, 1)); }; const atomElements = /^(img|br|input|textarea|hr)$/i; function scanFor(node, off, targetNode, targetOff, dir) { var _a; for (; ; ) { if (node == targetNode && off == targetOff) return true; if (off == (dir < 0 ? 0 : nodeSize(node))) { let parent = node.parentNode; if (!parent || parent.nodeType != 1 || hasBlockDesc(node) || atomElements.test(node.nodeName) || node.contentEditable == "false") return false; off = domIndex(node) + (dir < 0 ? 0 : 1); node = parent; } else if (node.nodeType == 1) { let child = node.childNodes[off + (dir < 0 ? -1 : 0)]; if (child.nodeType == 1 && child.contentEditable == "false") { if ((_a = child.pmViewDesc) === null || _a === void 0 ? void 0 : _a.ignoreForSelection) off += dir; else return false; } else { node = child; off = dir < 0 ? nodeSize(node) : 0; } } else { return false; } } } function nodeSize(node) { return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length; } function textNodeBefore$1(node, offset2) { for (; ; ) { if (node.nodeType == 3 && offset2) return node; if (node.nodeType == 1 && offset2 > 0) { if (node.contentEditable == "false") return null; node = node.childNodes[offset2 - 1]; offset2 = nodeSize(node); } else if (node.parentNode && !hasBlockDesc(node)) { offset2 = domIndex(node); node = node.parentNode; } else { return null; } } } function textNodeAfter$1(node, offset2) { for (; ; ) { if (node.nodeType == 3 && offset2 < node.nodeValue.length) return node; if (node.nodeType == 1 && offset2 < node.childNodes.length) { if (node.contentEditable == "false") return null; node = node.childNodes[offset2]; offset2 = 0; } else if (node.parentNode && !hasBlockDesc(node)) { offset2 = domIndex(node) + 1; node = node.parentNode; } else { return null; } } } function isOnEdge(node, offset2, parent) { for (let atStart = offset2 == 0, atEnd = offset2 == nodeSize(node); atStart || atEnd; ) { if (node == parent) return true; let index = domIndex(node); node = node.parentNode; if (!node) return false; atStart = atStart && index == 0; atEnd = atEnd && index == nodeSize(node); } } function hasBlockDesc(dom) { let desc; for (let cur = dom; cur; cur = cur.parentNode) if (desc = cur.pmViewDesc) break; return desc && desc.node && desc.node.isBlock && (desc.dom == dom || desc.contentDOM == dom); } const selectionCollapsed = function(domSel) { return domSel.focusNode && isEquivalentPosition(domSel.focusNode, domSel.focusOffset, domSel.anchorNode, domSel.anchorOffset); }; function keyEvent(keyCode, key) { let event = document.createEvent("Event"); event.initEvent("keydown", true, true); event.keyCode = keyCode; event.key = event.code = key; return event; } function deepActiveElement(doc2) { let elt = doc2.activeElement; while (elt && elt.shadowRoot) elt = elt.shadowRoot.activeElement; return elt; } function caretFromPoint(doc2, x, y) { if (doc2.caretPositionFromPoint) { try { let pos = doc2.caretPositionFromPoint(x, y); if (pos) return { node: pos.offsetNode, offset: Math.min(nodeSize(pos.offsetNode), pos.offset) }; } catch (_) { } } if (doc2.caretRangeFromPoint) { let range = doc2.caretRangeFromPoint(x, y); if (range) return { node: range.startContainer, offset: Math.min(nodeSize(range.startContainer), range.startOffset) }; } } const nav = typeof navigator != "undefined" ? navigator : null; const doc = typeof document != "undefined" ? document : null; const agent = nav && nav.userAgent || ""; const ie_edge = /Edge\/(\d+)/.exec(agent); const ie_upto10 = /MSIE \d/.exec(agent); const ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent); const ie$1 = !!(ie_upto10 || ie_11up || ie_edge); const ie_version = ie_upto10 ? document.documentMode : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0; const gecko = !ie$1 && /gecko\/(\d+)/i.test(agent); gecko && +(/Firefox\/(\d+)/.exec(agent) || [0, 0])[1]; const _chrome = !ie$1 && /Chrome\/(\d+)/.exec(agent); const chrome = !!_chrome; const chrome_version = _chrome ? +_chrome[1] : 0; const safari = !ie$1 && !!nav && /Apple Computer/.test(nav.vendor); const ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2); const mac$2 = ios || (nav ? /Mac/.test(nav.platform) : false); const windows$1 = nav ? /Win/.test(nav.platform) : false; const android = /Android \d/.test(agent); const webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style; const webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0; function windowRect(doc2) { let vp = doc2.defaultView && doc2.defaultView.visualViewport; if (vp) return { left: 0, right: vp.width, top: 0, bottom: vp.height }; return { left: 0, right: doc2.documentElement.clientWidth, top: 0, bottom: doc2.documentElement.clientHeight }; } function getSide$1(value, side) { return typeof value == "number" ? value : value[side]; } function clientRect(node) { let rect = node.getBoundingClientRect(); let scaleX = rect.width / node.offsetWidth || 1; let scaleY = rect.height / node.offsetHeight || 1; return { left: rect.left, right: rect.left + node.clientWidth * scaleX, top: rect.top, bottom: rect.top + node.clientHeight * scaleY }; } function scrollRectIntoView(view, rect, startDOM) { let scrollThreshold = view.someProp("scrollThreshold") || 0, scrollMargin = view.someProp("scrollMargin") || 5; let doc2 = view.dom.ownerDocument; for (let parent = startDOM || view.dom; ; ) { if (!parent) break; if (parent.nodeType != 1) { parent = parentNode(parent); continue; } let elt = parent; let atTop = elt == doc2.body; let bounding = atTop ? windowRect(doc2) : clientRect(elt); let moveX = 0, moveY = 0; if (rect.top < bounding.top + getSide$1(scrollThreshold, "top")) moveY = -(bounding.top - rect.top + getSide$1(scrollMargin, "top")); else if (rect.bottom > bounding.bottom - getSide$1(scrollThreshold, "bottom")) moveY = rect.bottom - rect.top > bounding.bottom - bounding.top ? rect.top + getSide$1(scrollMargin, "top") - bounding.top : rect.bottom - bounding.bottom + getSide$1(scrollMargin, "bottom"); if (rect.left < bounding.left + getSide$1(scrollThreshold, "left")) moveX = -(bounding.left - rect.left + getSide$1(scrollMargin, "left")); else if (rect.right > bounding.right - getSide$1(scrollThreshold, "right")) moveX = rect.right - bounding.right + getSide$1(scrollMargin, "right"); if (moveX || moveY) { if (atTop) { doc2.defaultView.scrollBy(moveX, moveY); } else { let startX = elt.scrollLeft, startY = elt.scrollTop; if (moveY) elt.scrollTop += moveY; if (moveX) elt.scrollLeft += moveX; let dX = elt.scrollLeft - startX, dY = elt.scrollTop - startY; rect = { left: rect.left - dX, top: rect.top - dY, right: rect.right - dX, bottom: rect.bottom - dY }; } } let pos = atTop ? "fixed" : getComputedStyle(parent).position; if (/^(fixed|sticky)$/.test(pos)) break; parent = pos == "absolute" ? parent.offsetParent : parentNode(parent); } } function storeScrollPos(view) { let rect = view.dom.getBoundingClientRect(), startY = Math.max(0, rect.top); let refDOM, refTop; for (let x = (rect.left + rect.right) / 2, y = startY + 1; y < Math.min(innerHeight, rect.bottom); y += 5) { let dom = view.root.elementFromPoint(x, y); if (!dom || dom == view.dom || !view.dom.contains(dom)) continue; let localRect = dom.getBoundingClientRect(); if (localRect.top >= startY - 20) { refDOM = dom; refTop = localRect.top; break; } } return { refDOM, refTop, stack: scrollStack(view.dom) }; } function scrollStack(dom) { let stack = [], doc2 = dom.ownerDocument; for (let cur = dom; cur; cur = parentNode(cur)) { stack.push({ dom: cur, top: cur.scrollTop, left: cur.scrollLeft }); if (dom == doc2) break; } return stack; } function resetScrollPos({ refDOM, refTop, stack }) { let newRefTop = refDOM ? refDOM.getBoundingClientRect().top : 0; restoreScrollStack(stack, newRefTop == 0 ? 0 : newRefTop - refTop); } function restoreScrollStack(stack, dTop) { for (let i = 0; i < stack.length; i++) { let { dom, top, left } = stack[i]; if (dom.scrollTop != top + dTop) dom.scrollTop = top + dTop; if (dom.scrollLeft != left) dom.scrollLeft = left; } } let preventScrollSupported = null; function focusPreventScroll(dom) { if (dom.setActive) return dom.setActive(); if (preventScrollSupported) return dom.focus(preventScrollSupported); let stored = scrollStack(dom); dom.focus(preventScrollSupported == null ? { get preventScroll() { preventScrollSupported = { preventScroll: true }; return true; } } : void 0); if (!preventScrollSupported) { preventScrollSupported = false; restoreScrollStack(stored, 0); } } function findOffsetInNode(node, coords) { let closest, dxClosest = 2e8, coordsClosest, offset2 = 0; let rowBot = coords.top, rowTop = coords.top; let firstBelow, coordsBelow; for (let child = node.firstChild, childIndex = 0; child; child = child.nextSibling, childIndex++) { let rects; if (child.nodeType == 1) rects = child.getClientRects(); else if (child.nodeType == 3) rects = textRange(child).getClientRects(); else continue; for (let i = 0; i < rects.length; i++) { let rect = rects[i]; if (rect.top <= rowBot && rect.bottom >= rowTop) { rowBot = Math.max(rect.bottom, rowBot); rowTop = Math.min(rect.top, rowTop); let dx = rect.left > coords.left ? rect.left - coords.left : rect.right < coords.left ? coords.left - rect.right : 0; if (dx < dxClosest) { closest = child; dxClosest = dx; coordsClosest = dx && closest.nodeType == 3 ? { left: rect.right < coords.left ? rect.right : rect.left, top: coords.top } : coords; if (child.nodeType == 1 && dx) offset2 = childIndex + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0); continue; } } else if (rect.top > coords.top && !firstBelow && rect.left <= coords.left && rect.right >= coords.left) { firstBelow = child; coordsBelow = { left: Math.max(rect.left, Math.min(rect.right, coords.left)), top: rect.top }; } if (!closest && (coords.left >= rect.right && coords.top >= rect.top || coords.left >= rect.left && coords.top >= rect.bottom)) offset2 = childIndex + 1; } } if (!closest && firstBelow) { closest = firstBelow; coordsClosest = coordsBelow; dxClosest = 0; } if (closest && closest.nodeType == 3) return findOffsetInText(closest, coordsClosest); if (!closest || dxClosest && closest.nodeType == 1) return { node, offset: offset2 }; return findOffsetInNode(closest, coordsClosest); } function findOffsetInText(node, coords) { let len = node.nodeValue.length; let range = document.createRange(), result; for (let i = 0; i < len; i++) { range.setEnd(node, i + 1); range.setStart(node, i); let rect = singleRect(range, 1); if (rect.top == rect.bottom) continue; if (inRect(coords, rect)) { result = { node, offset: i + (coords.left >= (rect.left + rect.right) / 2 ? 1 : 0) }; break; } } range.detach(); return result || { node, offset: 0 }; } function inRect(coords, rect) { return coords.left >= rect.left - 1 && coords.left <= rect.right + 1 && coords.top >= rect.top - 1 && coords.top <= rect.bottom + 1; } function targetKludge(dom, coords) { let parent = dom.parentNode; if (parent && /^li$/i.test(parent.nodeName) && coords.left < dom.getBoundingClientRect().left) return parent; return dom; } function posFromElement(view, elt, coords) { let { node, offset: offset2 } = findOffsetInNode(elt, coords), bias = -1; if (node.nodeType == 1 && !node.firstChild) { let rect = node.getBoundingClientRect(); bias = rect.left != rect.right && coords.left > (rect.left + rect.right) / 2 ? 1 : -1; } return view.docView.posFromDOM(node, offset2, bias); } function posFromCaret(view, node, offset2, coords) { let outsideBlock = -1; for (let cur = node, sawBlock = false; ; ) { if (cur == view.dom) break; let desc = view.docView.nearestDesc(cur, true), rect; if (!desc) return null; if (desc.dom.nodeType == 1 && (desc.node.isBlock && desc.parent || !desc.contentDOM) && // Ignore elements with zero-size bounding rectangles ((rect = desc.dom.getBoundingClientRect()).width || rect.height)) { if (desc.node.isBlock && desc.parent && !/^T(R|BODY|HEAD|FOOT)$/.test(desc.dom.nodeName)) { if (!sawBlock && rect.left > coords.left || rect.top > coords.top) outsideBlock = desc.posBefore; else if (!sawBlock && rect.right < coords.left || rect.bottom < coords.top) outsideBlock = desc.posAfter; sawBlock = true; } if (!desc.contentDOM && outsideBlock < 0 && !desc.node.isText) { let before = desc.node.isBlock ? coords.top < (rect.top + rect.bottom) / 2 : coords.left < (rect.left + rect.right) / 2; return before ? desc.posBefore : desc.posAfter; } } cur = desc.dom.parentNode; } return outsideBlock > -1 ? outsideBlock : view.docView.posFromDOM(node, offset2, -1); } function elementFromPoint(element, coords, box) { let len = element.childNodes.length; if (len && box.top < box.bottom) { for (let startI = Math.max(0, Math.min(len - 1, Math.floor(len * (coords.top - box.top) / (box.bottom - box.top)) - 2)), i = startI; ; ) { let child = element.childNodes[i]; if (child.nodeType == 1) { let rects = child.getClientRects(); for (let j = 0; j < rects.length; j++) { let rect = rects[j]; if (inRect(coords, rect)) return elementFromPoint(child, coords, rect); } } if ((i = (i + 1) % len) == startI) break; } } return element; } function posAtCoords(view, coords) { let doc2 = view.dom.ownerDocument, node, offset2 = 0; let caret = caretFromPoint(doc2, coords.left, coords.top); if (caret) ({ node, offset: offset2 } = caret); let elt = (view.root.elementFromPoint ? view.root : doc2).elementFromPoint(coords.left, coords.top); let pos; if (!elt || !view.dom.contains(elt.nodeType != 1 ? elt.parentNode : elt)) { let box = view.dom.getBoundingClientRect(); if (!inRect(coords, box)) return null; elt = elementFromPoint(view.dom, coords, box); if (!elt) return null; } if (safari) { for (let p = elt; node && p; p = parentNode(p)) if (p.draggable) node = void 0; } elt = targetKludge(elt, coords); if (node) { if (gecko && node.nodeType == 1) { offset2 = Math.min(offset2, node.childNodes.length); if (offset2 < node.childNodes.length) { let next = node.childNodes[offset2], box; if (next.nodeName == "IMG" && (box = next.getBoundingClientRect()).right <= coords.left && box.bottom > coords.top) offset2++; } } let prev; if (webkit && offset2 && node.nodeType == 1 && (prev = node.childNodes[offset2 - 1]).nodeType == 1 && prev.contentEditable == "false" && prev.getBoundingClientRect().top >= coords.top) offset2--; if (node == view.dom && offset2 == node.childNodes.length - 1 && node.lastChild.nodeType == 1 && coords.top > node.lastChild.getBoundingClientRect().bottom) pos = view.state.doc.content.size; else if (offset2 == 0 || node.nodeType != 1 || node.childNodes[offset2 - 1].nodeName != "BR") pos = posFromCaret(view, node, offset2, coords); } if (pos == null) pos = posFromElement(view, elt, coords); let desc = view.docView.nearestDesc(elt, true); return { pos, inside: desc ? desc.posAtStart - desc.border : -1 }; } function nonZero(rect) { return rect.top < rect.bottom || rect.left < rect.right; } function singleRect(target, bias) { let rects = target.getClientRects(); if (rects.length) { let first2 = rects[bias < 0 ? 0 : rects.length - 1]; if (nonZero(first2)) return first2; } return Array.prototype.find.call(rects, nonZero) || target.getBoundingClientRect(); } const BIDI = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/; function coordsAtPos(view, pos, side) { let { node, offset: offset2, atom } = view.docView.domFromPos(pos, side < 0 ? -1 : 1); let supportEmptyRange = webkit || gecko; if (node.nodeType == 3) { if (supportEmptyRange && (BIDI.test(node.nodeValue) || (side < 0 ? !offset2 : offset2 == node.nodeValue.length))) { let rect = singleRect(textRange(node, offset2, offset2), side); if (gecko && offset2 && /\s/.test(node.nodeValue[offset2 - 1]) && offset2 < node.nodeValue.length) { let rectBefore = singleRect(textRange(node, offset2 - 1, offset2 - 1), -1); if (rectBefore.top == rect.top) { let rectAfter = singleRect(textRange(node, offset2, offset2 + 1), -1); if (rectAfter.top != rect.top) return flattenV(rectAfter, rectAfter.left < rectBefore.left); } } return rect; } else { let from2 = offset2, to = offset2, takeSide = side < 0 ? 1 : -1; if (side < 0 && !offset2) { to++; takeSide = -1; } else if (side >= 0 && offset2 == node.nodeValue.length) { from2--; takeSide = 1; } else if (side < 0) { from2--; } else { to++; } return flattenV(singleRect(textRange(node, from2, to), takeSide), takeSide < 0); } } let $dom = view.state.doc.resolve(pos - (atom || 0)); if (!$dom.parent.inlineContent) { if (atom == null && offset2 && (side < 0 || offset2 == nodeSize(node))) { let before = node.childNodes[offset2 - 1]; if (before.nodeType == 1) return flattenH(before.getBoundingClientRect(), false); } if (atom == null && offset2 < nodeSize(node)) { let after = node.childNodes[offset2]; if (after.nodeType == 1) return flattenH(after.getBoundingClientRect(), true); } return flattenH(node.getBoundingClientRect(), side >= 0); } if (atom == null && offset2 && (side < 0 || offset2 == nodeSize(node))) { let before = node.childNodes[offset2 - 1]; let target = before.nodeType == 3 ? textRange(before, nodeSize(before) - (supportEmptyRange ? 0 : 1)) : before.nodeType == 1 && (before.nodeName != "BR" || !before.nextSibling) ? before : null; if (target) return flattenV(singleRect(target, 1), false); } if (atom == null && offset2 < nodeSize(node)) { let after = node.childNodes[offset2]; while (after.pmViewDesc && after.pmViewDesc.ignoreForCoords) after = after.nextSibling; let target = !after ? null : after.nodeType == 3 ? textRange(after, 0, supportEmptyRange ? 0 : 1) : after.nodeType == 1 ? after : null; if (target) return flattenV(singleRect(target, -1), true); } return flattenV(singleRect(node.nodeType == 3 ? textRange(node) : node, -side), side >= 0); } function flattenV(rect, left) { if (rect.width == 0) return rect; let x = left ? rect.left : rect.right; return { top: rect.top, bottom: rect.bottom, left: x, right: x }; } function flattenH(rect, top) { if (rect.height == 0) return rect; let y = top ? rect.top : rect.bottom; return { top: y, bottom: y, left: rect.left, right: rect.right }; } function withFlushedState(view, state, f) { let viewState = view.state, active = view.root.activeElement; if (viewState != state) view.updateState(state); if (active != view.dom) view.focus(); try { return f(); } finally { if (viewState != state) view.updateState(viewState); if (active != view.dom && active) active.focus(); } } function endOfTextblockVertical(view, state, dir) { let sel = state.selection; let $pos = dir == "up" ? sel.$from : sel.$to; return withFlushedState(view, state, () => { let { node: dom } = view.docView.domFromPos($pos.pos, dir == "up" ? -1 : 1); for (; ; ) { let nearest = view.docView.nearestDesc(dom, true); if (!nearest) break; if (nearest.node.isBlock) { dom = nearest.contentDOM || nearest.dom; break; } dom = nearest.dom.parentNode; } let coords = coordsAtPos(view, $pos.pos, 1); for (let child = dom.firstChild; child; child = child.nextSibling) { let boxes; if (child.nodeType == 1) boxes = child.getClientRects(); else if (child.nodeType == 3) boxes = textRange(child, 0, child.nodeValue.length).getClientRects(); else continue; for (let i = 0; i < boxes.length; i++) { let box = boxes[i]; if (box.bottom > box.top + 1 && (dir == "up" ? coords.top - box.top > (box.bottom - coords.top) * 2 : box.bottom - coords.bottom > (coords.bottom - box.top) * 2)) return false; } } return true; }); } const maybeRTL = /[\u0590-\u08ac]/; function endOfTextblockHorizontal(view, state, dir) { let { $head } = state.selection; if (!$head.parent.isTextblock) return false; let offset2 = $head.parentOffset, atStart = !offset2, atEnd = offset2 == $head.parent.content.size; let sel = view.domSelection(); if (!sel) return $head.pos == $head.start() || $head.pos == $head.end(); if (!maybeRTL.test($head.parent.textContent) || !sel.modify) return dir == "left" || dir == "backward" ? atStart : atEnd; return withFlushedState(view, state, () => { let { focusNode: oldNode, focusOffset: oldOff, anchorNode, anchorOffset } = view.domSelectionRange(); let oldBidiLevel = sel.caretBidiLevel; sel.modify("move", dir, "character"); let parentDOM = $head.depth ? view.docView.domAfterPos($head.before()) : view.dom; let { focusNode: newNode, focusOffset: newOff } = view.domSelectionRange(); let result = newNode && !parentDOM.contains(newNode.nodeType == 1 ? newNode : newNode.parentNode) || oldNode == newNode && oldOff == newOff; try { sel.collapse(anchorNode, anchorOffset); if (oldNode && (oldNode != anchorNode || oldOff != anchorOffset) && sel.extend) sel.extend(oldNode, oldOff); } catch (_) { } if (oldBidiLevel != null) sel.caretBidiLevel = oldBidiLevel; return result; }); } let cachedState = null; let cachedDir = null; let cachedResult = false; function endOfTextblock(view, state, dir) { if (cachedState == state && cachedDir == dir) return cachedResult; cachedState = state; cachedDir = dir; return cachedResult = dir == "up" || dir == "down" ? endOfTextblockVertical(view, state, dir) : endOfTextblockHorizontal(view, state, dir); } const NOT_DIRTY = 0, CHILD_DIRTY = 1, CONTENT_DIRTY = 2, NODE_DIRTY = 3; class ViewDesc { constructor(parent, children, dom, contentDOM) { this.parent = parent; this.children = children; this.dom = dom; this.contentDOM = contentDOM; this.dirty = NOT_DIRTY; dom.pmViewDesc = this; } // Used to check whether a given description corresponds to a // widget/mark/node. matchesWidget(widget) { return false; } matchesMark(mark) { return false; } matchesNode(node, outerDeco, innerDeco) { return false; } matchesHack(nodeName) { return false; } // When parsing in-editor content (in domchange.js), we allow // descriptions to determine the parse rules that should be used to // parse them. parseRule() { return null; } // Used by the editor's event handler to ignore events that come // from certain descs. stopEvent(event) { return false; } // The size of the content represented by this desc. get size() { let size2 = 0; for (let i = 0; i < this.children.length; i++) size2 += this.children[i].size; return size2; } // For block nodes, this represents the space taken up by their // start/end tokens. get border() { return 0; } destroy() { this.parent = void 0; if (this.dom.pmViewDesc == this) this.dom.pmViewDesc = void 0; for (let i = 0; i < this.children.length; i++) this.children[i].destroy(); } posBeforeChild(child) { for (let i = 0, pos = this.posAtStart; ; i++) { let cur = this.children[i]; if (cur == child) return pos; pos += cur.size; } } get posBefore() { return this.parent.posBeforeChild(this); } get posAtStart() { return this.parent ? this.parent.posBeforeChild(this) + this.border : 0; } get posAfter() { return this.posBefore + this.size; } get posAtEnd() { return this.posAtStart + this.size - 2 * this.border; } localPosFromDOM(dom, offset2, bias) { if (this.contentDOM && this.contentDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode)) { if (bias < 0) { let domBefore, desc; if (dom == this.contentDOM) { domBefore = dom.childNodes[offset2 - 1]; } else { while (dom.parentNode != this.contentDOM) dom = dom.parentNode; domBefore = dom.previousSibling; } while (domBefore && !((desc = domBefore.pmViewDesc) && desc.parent == this)) domBefore = domBefore.previousSibling; return domBefore ? this.posBeforeChild(desc) + desc.size : this.posAtStart; } else { let domAfter, desc; if (dom == this.contentDOM) { domAfter = dom.childNodes[offset2]; } else { while (dom.parentNode != this.contentDOM) dom = dom.parentNode; domAfter = dom.nextSibling; } while (domAfter && !((desc = domAfter.pmViewDesc) && desc.parent == this)) domAfter = domAfter.nextSibling; return domAfter ? this.posBeforeChild(desc) : this.posAtEnd; } } let atEnd; if (dom == this.dom && this.contentDOM) { atEnd = offset2 > domIndex(this.contentDOM); } else if (this.contentDOM && this.contentDOM != this.dom && this.dom.contains(this.contentDOM)) { atEnd = dom.compareDocumentPosition(this.contentDOM) & 2; } else if (this.dom.firstChild) { if (offset2 == 0) for (let search = dom; ; search = search.parentNode) { if (search == this.dom) { atEnd = false; break; } if (search.previousSibling) break; } if (atEnd == null && offset2 == dom.childNodes.length) for (let search = dom; ; search = search.parentNode) { if (search == this.dom) { atEnd = true; break; } if (search.nextSibling) break; } } return (atEnd == null ? bias > 0 : atEnd) ? this.posAtEnd : this.posAtStart; } nearestDesc(dom, onlyNodes = false) { for (let first2 = true, cur = dom; cur; cur = cur.parentNode) { let desc = this.getDesc(cur), nodeDOM; if (desc && (!onlyNodes || desc.node)) { if (first2 && (nodeDOM = desc.nodeDOM) && !(nodeDOM.nodeType == 1 ? nodeDOM.contains(dom.nodeType == 1 ? dom : dom.parentNode) : nodeDOM == dom)) first2 = false; else return desc; } } } getDesc(dom) { let desc = dom.pmViewDesc; for (let cur = desc; cur; cur = cur.parent) if (cur == this) return desc; } posFromDOM(dom, offset2, bias) { for (let scan = dom; scan; scan = scan.parentNode) { let desc = this.getDesc(scan); if (desc) return desc.localPosFromDOM(dom, offset2, bias); } return -1; } // Find the desc for the node after the given pos, if any. (When a // parent node overrode rendering, there might not be one.) descAt(pos) { for (let i = 0, offset2 = 0; i < this.children.length; i++) { let child = this.children[i], end = offset2 + child.size; if (offset2 == pos && end != offset2) { while (!child.border && child.children.length) { for (let i2 = 0; i2 < child.children.length; i2++) { let inner = child.children[i2]; if (inner.size) { child = inner; break; } } } return child; } if (pos < end) return child.descAt(pos - offset2 - child.border); offset2 = end; } } domFromPos(pos, side) { if (!this.contentDOM) return { node: this.dom, offset: 0, atom: pos + 1 }; let i = 0, offset2 = 0; for (let curPos = 0; i < this.children.length; i++) { let child = this.children[i], end = curPos + child.size; if (end > pos || child instanceof TrailingHackViewDesc) { offset2 = pos - curPos; break; } curPos = end; } if (offset2) return this.children[i].domFromPos(offset2 - this.children[i].border, side); for (let prev; i && !(prev = this.children[i - 1]).size && prev instanceof WidgetViewDesc && prev.side >= 0; i--) { } if (side <= 0) { let prev, enter2 = true; for (; ; i--, enter2 = false) { prev = i ? this.children[i - 1] : null; if (!prev || prev.dom.parentNode == this.contentDOM) break; } if (prev && side && enter2 && !prev.border && !prev.domAtom) return prev.domFromPos(prev.size, side); return { node: this.contentDOM, offset: prev ? domIndex(prev.dom) + 1 : 0 }; } else { let next, enter2 = true; for (; ; i++, enter2 = false) { next = i < this.children.length ? this.children[i] : null; if (!next || next.dom.parentNode == this.contentDOM) break; } if (next && enter2 && !next.border && !next.domAtom) return next.domFromPos(0, side); return { node: this.contentDOM, offset: next ? domIndex(next.dom) : this.contentDOM.childNodes.length }; } } // Used to find a DOM range in a single parent for a given changed // range. parseRange(from2, to, base2 = 0) { if (this.children.length == 0) return { node: this.contentDOM, from: from2, to, fromOffset: 0, toOffset: this.contentDOM.childNodes.length }; let fromOffset = -1, toOffset = -1; for (let offset2 = base2, i = 0; ; i++) { let child = this.children[i], end = offset2 + child.size; if (fromOffset == -1 && from2 <= end) { let childBase = offset2 + child.border; if (from2 >= childBase && to <= end - child.border && child.node && child.contentDOM && this.contentDOM.contains(child.contentDOM)) return child.parseRange(from2, to, childBase); from2 = offset2; for (let j = i; j > 0; j--) { let prev = this.children[j - 1]; if (prev.size && prev.dom.parentNode == this.contentDOM && !prev.emptyChildAt(1)) { fromOffset = domIndex(prev.dom) + 1; break; } from2 -= prev.size; } if (fromOffset == -1) fromOffset = 0; } if (fromOffset > -1 && (end > to || i == this.children.length - 1)) { to = end; for (let j = i + 1; j < this.children.length; j++) { let next = this.children[j]; if (next.size && next.dom.parentNode == this.contentDOM && !next.emptyChildAt(-1)) { toOffset = domIndex(next.dom); break; } to += next.size; } if (toOffset == -1) toOffset = this.contentDOM.childNodes.length; break; } offset2 = end; } return { node: this.contentDOM, from: from2, to, fromOffset, toOffset }; } emptyChildAt(side) { if (this.border || !this.contentDOM || !this.children.length) return false; let child = this.children[side < 0 ? 0 : this.children.length - 1]; return child.size == 0 || child.emptyChildAt(side); } domAfterPos(pos) { let { node, offset: offset2 } = this.domFromPos(pos, 0); if (node.nodeType != 1 || offset2 == node.childNodes.length) throw new RangeError("No node after pos " + pos); return node.childNodes[offset2]; } // View descs are responsible for setting any selection that falls // entirely inside of them, so that custom implementations can do // custom things with the selection. Note that this falls apart when // a selection starts in such a node and ends in another, in which // case we just use whatever domFromPos produces as a best effort. setSelection(anchor, head, view, force = false) { let from2 = Math.min(anchor, head), to = Math.max(anchor, head); for (let i = 0, offset2 = 0; i < this.children.length; i++) { let child = this.children[i], end = offset2 + child.size; if (from2 > offset2 && to < end) return child.setSelection(anchor - offset2 - child.border, head - offset2 - child.border, view, force); offset2 = end; } let anchorDOM = this.domFromPos(anchor, anchor ? -1 : 1); let headDOM = head == anchor ? anchorDOM : this.domFromPos(head, head ? -1 : 1); let domSel = view.root.getSelection(); let selRange = view.domSelectionRange(); let brKludge = false; if ((gecko || safari) && anchor == head) { let { node, offset: offset2 } = anchorDOM; if (node.nodeType == 3) { brKludge = !!(offset2 && node.nodeValue[offset2 - 1] == "\n"); if (brKludge && offset2 == node.nodeValue.length) { for (let scan = node, after; scan; scan = scan.parentNode) { if (after = scan.nextSibling) { if (after.nodeName == "BR") anchorDOM = headDOM = { node: after.parentNode, offset: domIndex(after) + 1 }; break; } let desc = scan.pmViewDesc; if (desc && desc.node && desc.node.isBlock) break; } } } else { let prev = node.childNodes[offset2 - 1]; brKludge = prev && (prev.nodeName == "BR" || prev.contentEditable == "false"); } } if (gecko && selRange.focusNode && selRange.focusNode != headDOM.node && selRange.focusNode.nodeType == 1) { let after = selRange.focusNode.childNodes[selRange.focusOffset]; if (after && after.contentEditable == "false") force = true; } if (!(force || brKludge && safari) && isEquivalentPosition(anchorDOM.node, anchorDOM.offset, selRange.anchorNode, selRange.anchorOffset) && isEquivalentPosition(headDOM.node, headDOM.offset, selRange.focusNode, selRange.focusOffset)) return; let domSelExtended = false; if ((domSel.extend || anchor == head) && !(brKludge && gecko)) { domSel.collapse(anchorDOM.node, anchorDOM.offset); try { if (anchor != head) domSel.extend(headDOM.node, headDOM.offset); domSelExtended = true; } catch (_) { } } if (!domSelExtended) { if (anchor > head) { let tmp = anchorDOM; anchorDOM = headDOM; headDOM = tmp; } let range = document.createRange(); range.setEnd(headDOM.node, headDOM.offset); range.setStart(anchorDOM.node, anchorDOM.offset); domSel.removeAllRanges(); domSel.addRange(range); } } ignoreMutation(mutation) { return !this.contentDOM && mutation.type != "selection"; } get contentLost() { return this.contentDOM && this.contentDOM != this.dom && !this.dom.contains(this.contentDOM); } // Remove a subtree of the element tree that has been touched // by a DOM change, so that the next update will redraw it. markDirty(from2, to) { for (let offset2 = 0, i = 0; i < this.children.length; i++) { let child = this.children[i], end = offset2 + child.size; if (offset2 == end ? from2 <= end && to >= offset2 : from2 < end && to > offset2) { let startInside = offset2 + child.border, endInside = end - child.border; if (from2 >= startInside && to <= endInside) { this.dirty = from2 == offset2 || to == end ? CONTENT_DIRTY : CHILD_DIRTY; if (from2 == startInside && to == endInside && (child.contentLost || child.dom.parentNode != this.contentDOM)) child.dirty = NODE_DIRTY; else child.markDirty(from2 - startInside, to - startInside); return; } else { child.dirty = child.dom == child.contentDOM && child.dom.parentNode == this.contentDOM && !child.children.length ? CONTENT_DIRTY : NODE_DIRTY; } } offset2 = end; } this.dirty = CONTENT_DIRTY; } markParentsDirty() { let level = 1; for (let node = this.parent; node; node = node.parent, level++) { let dirty = level == 1 ? CONTENT_DIRTY : CHILD_DIRTY; if (node.dirty < dirty) node.dirty = dirty; } } get domAtom() { return false; } get ignoreForCoords() { return false; } get ignoreForSelection() { return false; } isText(text) { return false; } } class WidgetViewDesc extends ViewDesc { constructor(parent, widget, view, pos) { let self2, dom = widget.type.toDOM; if (typeof dom == "function") dom = dom(view, () => { if (!self2) return pos; if (self2.parent) return self2.parent.posBeforeChild(self2); }); if (!widget.type.spec.raw) { if (dom.nodeType != 1) { let wrap2 = document.createElement("span"); wrap2.appendChild(dom); dom = wrap2; } dom.contentEditable = "false"; dom.classList.add("ProseMirror-widget"); } super(parent, [], dom, null); this.widget = widget; this.widget = widget; self2 = this; } matchesWidget(widget) { return this.dirty == NOT_DIRTY && widget.type.eq(this.widget.type); } parseRule() { return { ignore: true }; } stopEvent(event) { let stop = this.widget.spec.stopEvent; return stop ? stop(event) : false; } ignoreMutation(mutation) { return mutation.type != "selection" || this.widget.spec.ignoreSelection; } destroy() { this.widget.type.destroy(this.dom); super.destroy(); } get domAtom() { return true; } get ignoreForSelection() { return !!this.widget.type.spec.relaxedSide; } get side() { return this.widget.type.side; } } class CompositionViewDesc extends ViewDesc { constructor(parent, dom, textDOM, text) { super(parent, [], dom, null); this.textDOM = textDOM; this.text = text; } get size() { return this.text.length; } localPosFromDOM(dom, offset2) { if (dom != this.textDOM) return this.posAtStart + (offset2 ? this.size : 0); return this.posAtStart + offset2; } domFromPos(pos) { return { node: this.textDOM, offset: pos }; } ignoreMutation(mut) { return mut.type === "characterData" && mut.target.nodeValue == mut.oldValue; } } class MarkViewDesc extends ViewDesc { constructor(parent, mark, dom, contentDOM, spec) { super(parent, [], dom, contentDOM); this.mark = mark; this.spec = spec; } static create(parent, mark, inline2, view) { let custom = view.nodeViews[mark.type.name]; let spec = custom && custom(mark, view, inline2); if (!spec || !spec.dom) spec = DOMSerializer.renderSpec(document, mark.type.spec.toDOM(mark, inline2), null, mark.attrs); return new MarkViewDesc(parent, mark, spec.dom, spec.contentDOM || spec.dom, spec); } parseRule() { if (this.dirty & NODE_DIRTY || this.mark.type.spec.reparseInView) return null; return { mark: this.mark.type.name, attrs: this.mark.attrs, contentElement: this.contentDOM }; } matchesMark(mark) { return this.dirty != NODE_DIRTY && this.mark.eq(mark); } markDirty(from2, to) { super.markDirty(from2, to); if (this.dirty != NOT_DIRTY) { let parent = this.parent; while (!parent.node) parent = parent.parent; if (parent.dirty < this.dirty) parent.dirty = this.dirty; this.dirty = NOT_DIRTY; } } slice(from2, to, view) { let copy2 = MarkViewDesc.create(this.parent, this.mark, true, view); let nodes = this.children, size2 = this.size; if (to < size2) nodes = replaceNodes(nodes, to, size2, view); if (from2 > 0) nodes = replaceNodes(nodes, 0, from2, view); for (let i = 0; i < nodes.length; i++) nodes[i].parent = copy2; copy2.children = nodes; return copy2; } ignoreMutation(mutation) { return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation); } destroy() { if (this.spec.destroy) this.spec.destroy(); super.destroy(); } } class NodeViewDesc extends ViewDesc { constructor(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, view, pos) { super(parent, [], dom, contentDOM); this.node = node; this.outerDeco = outerDeco; this.innerDeco = innerDeco; this.nodeDOM = nodeDOM; } // By default, a node is rendered using the `toDOM` method from the // node type spec. But client code can use the `nodeViews` spec to // supply a custom node view, which can influence various aspects of // the way the node works. // // (Using subclassing for this was intentionally decided against, // since it'd require exposing a whole slew of finicky // implementation details to the user code that they probably will // never need.) static create(parent, node, outerDeco, innerDeco, view, pos) { let custom = view.nodeViews[node.type.name], descObj; let spec = custom && custom(node, view, () => { if (!descObj) return pos; if (descObj.parent) return descObj.parent.posBeforeChild(descObj); }, outerDeco, innerDeco); let dom = spec && spec.dom, contentDOM = spec && spec.contentDOM; if (node.isText) { if (!dom) dom = document.createTextNode(node.text); else if (dom.nodeType != 3) throw new RangeError("Text must be rendered as a DOM text node"); } else if (!dom) { let spec2 = DOMSerializer.renderSpec(document, node.type.spec.toDOM(node), null, node.attrs); ({ dom, contentDOM } = spec2); } if (!contentDOM && !node.isText && dom.nodeName != "BR") { if (!dom.hasAttribute("contenteditable")) dom.contentEditable = "false"; if (node.type.spec.draggable) dom.draggable = true; } let nodeDOM = dom; dom = applyOuterDeco(dom, outerDeco, node); if (spec) return descObj = new CustomNodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM || null, nodeDOM, spec, view, pos + 1); else if (node.isText) return new TextViewDesc(parent, node, outerDeco, innerDeco, dom, nodeDOM, view); else return new NodeViewDesc(parent, node, outerDeco, innerDeco, dom, contentDOM || null, nodeDOM, view, pos + 1); } parseRule() { if (this.node.type.spec.reparseInView) return null; let rule = { node: this.node.type.name, attrs: this.node.attrs }; if (this.node.type.whitespace == "pre") rule.preserveWhitespace = "full"; if (!this.contentDOM) { rule.getContent = () => this.node.content; } else if (!this.contentLost) { rule.contentElement = this.contentDOM; } else { for (let i = this.children.length - 1; i >= 0; i--) { let child = this.children[i]; if (this.dom.contains(child.dom.parentNode)) { rule.contentElement = child.dom.parentNode; break; } } if (!rule.contentElement) rule.getContent = () => Fragment.empty; } return rule; } matchesNode(node, outerDeco, innerDeco) { return this.dirty == NOT_DIRTY && node.eq(this.node) && sameOuterDeco(outerDeco, this.outerDeco) && innerDeco.eq(this.innerDeco); } get size() { return this.node.nodeSize; } get border() { return this.node.isLeaf ? 0 : 1; } // Syncs `this.children` to match `this.node.content` and the local // decorations, possibly introducing nesting for marks. Then, in a // separate step, syncs the DOM inside `this.contentDOM` to // `this.children`. updateChildren(view, pos) { let inline2 = this.node.inlineContent, off = pos; let composition = view.composing ? this.localCompositionInfo(view, pos) : null; let localComposition = composition && composition.pos > -1 ? composition : null; let compositionInChild = composition && composition.pos < 0; let updater = new ViewTreeUpdater(this, localComposition && localComposition.node, view); iterDeco(this.node, this.innerDeco, (widget, i, insideNode) => { if (widget.spec.marks) updater.syncToMarks(widget.spec.marks, inline2, view, i); else if (widget.type.side >= 0 && !insideNode) updater.syncToMarks(i == this.node.childCount ? Mark$1.none : this.node.child(i).marks, inline2, view, i); updater.placeWidget(widget, view, off); }, (child, outerDeco, innerDeco, i) => { updater.syncToMarks(child.marks, inline2, view, i); let compIndex; if (updater.findNodeMatch(child, outerDeco, innerDeco, i)) ; else if (compositionInChild && view.state.selection.from > off && view.state.selection.to < off + child.nodeSize && (compIndex = updater.findIndexWithChild(composition.node)) > -1 && updater.updateNodeAt(child, outerDeco, innerDeco, compIndex, view)) ; else if (updater.updateNextNode(child, outerDeco, innerDeco, view, i, off)) ; else { updater.addNode(child, outerDeco, innerDeco, view, off); } off += child.nodeSize; }); updater.syncToMarks([], inline2, view, 0); if (this.node.isTextblock) updater.addTextblockHacks(); updater.destroyRest(); if (updater.changed || this.dirty == CONTENT_DIRTY) { if (localComposition) this.protectLocalComposition(view, localComposition); renderDescs(this.contentDOM, this.children, view); if (ios) iosHacks(this.dom); } } localCompositionInfo(view, pos) { let { from: from2, to } = view.state.selection; if (!(view.state.selection instanceof TextSelection) || from2 < pos || to > pos + this.node.content.size) return null; let textNode = view.input.compositionNode; if (!textNode || !this.dom.contains(textNode.parentNode)) return null; if (this.node.inlineContent) { let text = textNode.nodeValue; let textPos = findTextInFragment(this.node.content, text, from2 - pos, to - pos); return textPos < 0 ? null : { node: textNode, pos: textPos, text }; } else { return { node: textNode, pos: -1, text: "" }; } } protectLocalComposition(view, { node, pos, text }) { if (this.getDesc(node)) return; let topNode = node; for (; ; topNode = topNode.parentNode) { if (topNode.parentNode == this.contentDOM) break; while (topNode.previousSibling) topNode.parentNode.removeChild(topNode.previousSibling); while (topNode.nextSibling) topNode.parentNode.removeChild(topNode.nextSibling); if (topNode.pmViewDesc) topNode.pmViewDesc = void 0; } let desc = new CompositionViewDesc(this, topNode, node, text); view.input.compositionNodes.push(desc); this.children = replaceNodes(this.children, pos, pos + text.length, view, desc); } // If this desc must be updated to match the given node decoration, // do so and return true. update(node, outerDeco, innerDeco, view) { if (this.dirty == NODE_DIRTY || !node.sameMarkup(this.node)) return false; this.updateInner(node, outerDeco, innerDeco, view); return true; } updateInner(node, outerDeco, innerDeco, view) { this.updateOuterDeco(outerDeco); this.node = node; this.innerDeco = innerDeco; if (this.contentDOM) this.updateChildren(view, this.posAtStart); this.dirty = NOT_DIRTY; } updateOuterDeco(outerDeco) { if (sameOuterDeco(outerDeco, this.outerDeco)) return; let needsWrap = this.nodeDOM.nodeType != 1; let oldDOM = this.dom; this.dom = patchOuterDeco(this.dom, this.nodeDOM, computeOuterDeco(this.outerDeco, this.node, needsWrap), computeOuterDeco(outerDeco, this.node, needsWrap)); if (this.dom != oldDOM) { oldDOM.pmViewDesc = void 0; this.dom.pmViewDesc = this; } this.outerDeco = outerDeco; } // Mark this node as being the selected node. selectNode() { if (this.nodeDOM.nodeType == 1) { this.nodeDOM.classList.add("ProseMirror-selectednode"); if (this.contentDOM || !this.node.type.spec.draggable) this.nodeDOM.draggable = true; } } // Remove selected node marking from this node. deselectNode() { if (this.nodeDOM.nodeType == 1) { this.nodeDOM.classList.remove("ProseMirror-selectednode"); if (this.contentDOM || !this.node.type.spec.draggable) this.nodeDOM.removeAttribute("draggable"); } } get domAtom() { return this.node.isAtom; } } function docViewDesc(doc2, outerDeco, innerDeco, dom, view) { applyOuterDeco(dom, outerDeco, doc2); let docView = new NodeViewDesc(void 0, doc2, outerDeco, innerDeco, dom, dom, dom, view, 0); if (docView.contentDOM) docView.updateChildren(view, 0); return docView; } class TextViewDesc extends NodeViewDesc { constructor(parent, node, outerDeco, innerDeco, dom, nodeDOM, view) { super(parent, node, outerDeco, innerDeco, dom, null, nodeDOM, view, 0); } parseRule() { let skip = this.nodeDOM.parentNode; while (skip && skip != this.dom && !skip.pmIsDeco) skip = skip.parentNode; return { skip: skip || true }; } update(node, outerDeco, innerDeco, view) { if (this.dirty == NODE_DIRTY || this.dirty != NOT_DIRTY && !this.inParent() || !node.sameMarkup(this.node)) return false; this.updateOuterDeco(outerDeco); if ((this.dirty != NOT_DIRTY || node.text != this.node.text) && node.text != this.nodeDOM.nodeValue) { this.nodeDOM.nodeValue = node.text; if (view.trackWrites == this.nodeDOM) view.trackWrites = null; } this.node = node; this.dirty = NOT_DIRTY; return true; } inParent() { let parentDOM = this.parent.contentDOM; for (let n = this.nodeDOM; n; n = n.parentNode) if (n == parentDOM) return true; return false; } domFromPos(pos) { return { node: this.nodeDOM, offset: pos }; } localPosFromDOM(dom, offset2, bias) { if (dom == this.nodeDOM) return this.posAtStart + Math.min(offset2, this.node.text.length); return super.localPosFromDOM(dom, offset2, bias); } ignoreMutation(mutation) { return mutation.type != "characterData" && mutation.type != "selection"; } slice(from2, to, view) { let node = this.node.cut(from2, to), dom = document.createTextNode(node.text); return new TextViewDesc(this.parent, node, this.outerDeco, this.innerDeco, dom, dom, view); } markDirty(from2, to) { super.markDirty(from2, to); if (this.dom != this.nodeDOM && (from2 == 0 || to == this.nodeDOM.nodeValue.length)) this.dirty = NODE_DIRTY; } get domAtom() { return false; } isText(text) { return this.node.text == text; } } class TrailingHackViewDesc extends ViewDesc { parseRule() { return { ignore: true }; } matchesHack(nodeName) { return this.dirty == NOT_DIRTY && this.dom.nodeName == nodeName; } get domAtom() { return true; } get ignoreForCoords() { return this.dom.nodeName == "IMG"; } } class CustomNodeViewDesc extends NodeViewDesc { constructor(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, spec, view, pos) { super(parent, node, outerDeco, innerDeco, dom, contentDOM, nodeDOM, view, pos); this.spec = spec; } // A custom `update` method gets to decide whether the update goes // through. If it does, and there's a `contentDOM` node, our logic // updates the children. update(node, outerDeco, innerDeco, view) { if (this.dirty == NODE_DIRTY) return false; if (this.spec.update && (this.node.type == node.type || this.spec.multiType)) { let result = this.spec.update(node, outerDeco, innerDeco); if (result) this.updateInner(node, outerDeco, innerDeco, view); return result; } else if (!this.contentDOM && !node.isLeaf) { return false; } else { return super.update(node, outerDeco, innerDeco, view); } } selectNode() { this.spec.selectNode ? this.spec.selectNode() : super.selectNode(); } deselectNode() { this.spec.deselectNode ? this.spec.deselectNode() : super.deselectNode(); } setSelection(anchor, head, view, force) { this.spec.setSelection ? this.spec.setSelection(anchor, head, view.root) : super.setSelection(anchor, head, view, force); } destroy() { if (this.spec.destroy) this.spec.destroy(); super.destroy(); } stopEvent(event) { return this.spec.stopEvent ? this.spec.stopEvent(event) : false; } ignoreMutation(mutation) { return this.spec.ignoreMutation ? this.spec.ignoreMutation(mutation) : super.ignoreMutation(mutation); } } function renderDescs(parentDOM, descs, view) { let dom = parentDOM.firstChild, written = false; for (let i = 0; i < descs.length; i++) { let desc = descs[i], childDOM = desc.dom; if (childDOM.parentNode == parentDOM) { while (childDOM != dom) { dom = rm(dom); written = true; } dom = dom.nextSibling; } else { written = true; parentDOM.insertBefore(childDOM, dom); } if (desc instanceof MarkViewDesc) { let pos = dom ? dom.previousSibling : parentDOM.lastChild; renderDescs(desc.contentDOM, desc.children, view); dom = pos ? pos.nextSibling : parentDOM.firstChild; } } while (dom) { dom = rm(dom); written = true; } if (written && view.trackWrites == parentDOM) view.trackWrites = null; } const OuterDecoLevel = function(nodeName) { if (nodeName) this.nodeName = nodeName; }; OuterDecoLevel.prototype = /* @__PURE__ */ Object.create(null); const noDeco = [new OuterDecoLevel()]; function computeOuterDeco(outerDeco, node, needsWrap) { if (outerDeco.length == 0) return noDeco; let top = needsWrap ? noDeco[0] : new OuterDecoLevel(), result = [top]; for (let i = 0; i < outerDeco.length; i++) { let attrs = outerDeco[i].type.attrs; if (!attrs) continue; if (attrs.nodeName) result.push(top = new OuterDecoLevel(attrs.nodeName)); for (let name in attrs) { let val = attrs[name]; if (val == null) continue; if (needsWrap && result.length == 1) result.push(top = new OuterDecoLevel(node.isInline ? "span" : "div")); if (name == "class") top.class = (top.class ? top.class + " " : "") + val; else if (name == "style") top.style = (top.style ? top.style + ";" : "") + val; else if (name != "nodeName") top[name] = val; } } return result; } function patchOuterDeco(outerDOM, nodeDOM, prevComputed, curComputed) { if (prevComputed == noDeco && curComputed == noDeco) return nodeDOM; let curDOM = nodeDOM; for (let i = 0; i < curComputed.length; i++) { let deco = curComputed[i], prev = prevComputed[i]; if (i) { let parent; if (prev && prev.nodeName == deco.nodeName && curDOM != outerDOM && (parent = curDOM.parentNode) && parent.nodeName.toLowerCase() == deco.nodeName) { curDOM = parent; } else { parent = document.createElement(deco.nodeName); parent.pmIsDeco = true; parent.appendChild(curDOM); prev = noDeco[0]; curDOM = parent; } } patchAttributes(curDOM, prev || noDeco[0], deco); } return curDOM; } function patchAttributes(dom, prev, cur) { for (let name in prev) if (name != "class" && name != "style" && name != "nodeName" && !(name in cur)) dom.removeAttribute(name); for (let name in cur) if (name != "class" && name != "style" && name != "nodeName" && cur[name] != prev[name]) dom.setAttribute(name, cur[name]); if (prev.class != cur.class) { let prevList = prev.class ? prev.class.split(" ").filter(Boolean) : []; let curList = cur.class ? cur.class.split(" ").filter(Boolean) : []; for (let i = 0; i < prevList.length; i++) if (curList.indexOf(prevList[i]) == -1) dom.classList.remove(prevList[i]); for (let i = 0; i < curList.length; i++) if (prevList.indexOf(curList[i]) == -1) dom.classList.add(curList[i]); if (dom.classList.length == 0) dom.removeAttribute("class"); } if (prev.style != cur.style) { if (prev.style) { let prop = /\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g, m; while (m = prop.exec(prev.style)) dom.style.removeProperty(m[1]); } if (cur.style) dom.style.cssText += cur.style; } } function applyOuterDeco(dom, deco, node) { return patchOuterDeco(dom, dom, noDeco, computeOuterDeco(deco, node, dom.nodeType != 1)); } function sameOuterDeco(a, b) { if (a.length != b.length) return false; for (let i = 0; i < a.length; i++) if (!a[i].type.eq(b[i].type)) return false; return true; } function rm(dom) { let next = dom.nextSibling; dom.parentNode.removeChild(dom); return next; } class ViewTreeUpdater { constructor(top, lock, view) { this.lock = lock; this.view = view; this.index = 0; this.stack = []; this.changed = false; this.top = top; this.preMatch = preMatch(top.node.content, top); } // Destroy and remove the children between the given indices in // `this.top`. destroyBetween(start, end) { if (start == end) return; for (let i = start; i < end; i++) this.top.children[i].destroy(); this.top.children.splice(start, end - start); this.changed = true; } // Destroy all remaining children in `this.top`. destroyRest() { this.destroyBetween(this.index, this.top.children.length); } // Sync the current stack of mark descs with the given array of // marks, reusing existing mark descs when possible. syncToMarks(marks, inline2, view, parentIndex) { let keep = 0, depth = this.stack.length >> 1; let maxKeep = Math.min(depth, marks.length); while (keep < maxKeep && (keep == depth - 1 ? this.top : this.stack[keep + 1 << 1]).matchesMark(marks[keep]) && marks[keep].type.spec.spanning !== false) keep++; while (keep < depth) { this.destroyRest(); this.top.dirty = NOT_DIRTY; this.index = this.stack.pop(); this.top = this.stack.pop(); depth--; } while (depth < marks.length) { this.stack.push(this.top, this.index + 1); let found2 = -1, scanTo = this.top.children.length; if (parentIndex < this.preMatch.index) scanTo = Math.min(this.index + 3, scanTo); for (let i = this.index; i < scanTo; i++) { let next = this.top.children[i]; if (next.matchesMark(marks[depth]) && !this.isLocked(next.dom)) { found2 = i; break; } } if (found2 > -1) { if (found2 > this.index) { this.changed = true; this.destroyBetween(this.index, found2); } this.top = this.top.children[this.index]; } else { let markDesc = MarkViewDesc.create(this.top, marks[depth], inline2, view); this.top.children.splice(this.index, 0, markDesc); this.top = markDesc; this.changed = true; } this.index = 0; depth++; } } // Try to find a node desc matching the given data. Skip over it and // return true when successful. findNodeMatch(node, outerDeco, innerDeco, index) { let found2 = -1, targetDesc; if (index >= this.preMatch.index && (targetDesc = this.preMatch.matches[index - this.preMatch.index]).parent == this.top && targetDesc.matchesNode(node, outerDeco, innerDeco)) { found2 = this.top.children.indexOf(targetDesc, this.index); } else { for (let i = this.index, e = Math.min(this.top.children.length, i + 5); i < e; i++) { let child = this.top.children[i]; if (child.matchesNode(node, outerDeco, innerDeco) && !this.preMatch.matched.has(child)) { found2 = i; break; } } } if (found2 < 0) return false; this.destroyBetween(this.index, found2); this.index++; return true; } updateNodeAt(node, outerDeco, innerDeco, index, view) { let child = this.top.children[index]; if (child.dirty == NODE_DIRTY && child.dom == child.contentDOM) child.dirty = CONTENT_DIRTY; if (!child.update(node, outerDeco, innerDeco, view)) return false; this.destroyBetween(this.index, index); this.index++; return true; } findIndexWithChild(domNode) { for (; ; ) { let parent = domNode.parentNode; if (!parent) return -1; if (parent == this.top.contentDOM) { let desc = domNode.pmViewDesc; if (desc) for (let i = this.index; i < this.top.children.length; i++) { if (this.top.children[i] == desc) return i; } return -1; } domNode = parent; } } // Try to update the next node, if any, to the given data. Checks // pre-matches to avoid overwriting nodes that could still be used. updateNextNode(node, outerDeco, innerDeco, view, index, pos) { for (let i = this.index; i < this.top.children.length; i++) { let next = this.top.children[i]; if (next instanceof NodeViewDesc) { let preMatch2 = this.preMatch.matched.get(next); if (preMatch2 != null && preMatch2 != index) return false; let nextDOM = next.dom, updated; let locked = this.isLocked(nextDOM) && !(node.isText && next.node && next.node.isText && next.nodeDOM.nodeValue == node.text && next.dirty != NODE_DIRTY && sameOuterDeco(outerDeco, next.outerDeco)); if (!locked && next.update(node, outerDeco, innerDeco, view)) { this.destroyBetween(this.index, i); if (next.dom != nextDOM) this.changed = true; this.index++; return true; } else if (!locked && (updated = this.recreateWrapper(next, node, outerDeco, innerDeco, view, pos))) { this.destroyBetween(this.index, i); this.top.children[this.index] = updated; if (updated.contentDOM) { updated.dirty = CONTENT_DIRTY; updated.updateChildren(view, pos + 1); updated.dirty = NOT_DIRTY; } this.changed = true; this.index++; return true; } break; } } return false; } // When a node with content is replaced by a different node with // identical content, move over its children. recreateWrapper(next, node, outerDeco, innerDeco, view, pos) { if (next.dirty || node.isAtom || !next.children.length || !next.node.content.eq(node.content) || !sameOuterDeco(outerDeco, next.outerDeco) || !innerDeco.eq(next.innerDeco)) return null; let wrapper = NodeViewDesc.create(this.top, node, outerDeco, innerDeco, view, pos); if (wrapper.contentDOM) { wrapper.children = next.children; next.children = []; for (let ch of wrapper.children) ch.parent = wrapper; } next.destroy(); return wrapper; } // Insert the node as a newly created node desc. addNode(node, outerDeco, innerDeco, view, pos) { let desc = NodeViewDesc.create(this.top, node, outerDeco, innerDeco, view, pos); if (desc.contentDOM) desc.updateChildren(view, pos + 1); this.top.children.splice(this.index++, 0, desc); this.changed = true; } placeWidget(widget, view, pos) { let next = this.index < this.top.children.length ? this.top.children[this.index] : null; if (next && next.matchesWidget(widget) && (widget == next.widget || !next.widget.type.toDOM.parentNode)) { this.index++; } else { let desc = new WidgetViewDesc(this.top, widget, view, pos); this.top.children.splice(this.index++, 0, desc); this.changed = true; } } // Make sure a textblock looks and behaves correctly in // contentEditable. addTextblockHacks() { let lastChild = this.top.children[this.index - 1], parent = this.top; while (lastChild instanceof MarkViewDesc) { parent = lastChild; lastChild = parent.children[parent.children.length - 1]; } if (!lastChild || // Empty textblock !(lastChild instanceof TextViewDesc) || /\n$/.test(lastChild.node.text) || this.view.requiresGeckoHackNode && /\s$/.test(lastChild.node.text)) { if ((safari || chrome) && lastChild && lastChild.dom.contentEditable == "false") this.addHackNode("IMG", parent); this.addHackNode("BR", this.top); } } addHackNode(nodeName, parent) { if (parent == this.top && this.index < parent.children.length && parent.children[this.index].matchesHack(nodeName)) { this.index++; } else { let dom = document.createElement(nodeName); if (nodeName == "IMG") { dom.className = "ProseMirror-separator"; dom.alt = ""; } if (nodeName == "BR") dom.className = "ProseMirror-trailingBreak"; let hack = new TrailingHackViewDesc(this.top, [], dom, null); if (parent != this.top) parent.children.push(hack); else parent.children.splice(this.index++, 0, hack); this.changed = true; } } isLocked(node) { return this.lock && (node == this.lock || node.nodeType == 1 && node.contains(this.lock.parentNode)); } } function preMatch(frag, parentDesc) { let curDesc = parentDesc, descI = curDesc.children.length; let fI = frag.childCount, matched = /* @__PURE__ */ new Map(), matches2 = []; outer: while (fI > 0) { let desc; for (; ; ) { if (descI) { let next = curDesc.children[descI - 1]; if (next instanceof MarkViewDesc) { curDesc = next; descI = next.children.length; } else { desc = next; descI--; break; } } else if (curDesc == parentDesc) { break outer; } else { descI = curDesc.parent.children.indexOf(curDesc); curDesc = curDesc.parent; } } let node = desc.node; if (!node) continue; if (node != frag.child(fI - 1)) break; --fI; matched.set(desc, fI); matches2.push(desc); } return { index: fI, matched, matches: matches2.reverse() }; } function compareSide(a, b) { return a.type.side - b.type.side; } function iterDeco(parent, deco, onWidget, onNode) { let locals = deco.locals(parent), offset2 = 0; if (locals.length == 0) { for (let i = 0; i < parent.childCount; i++) { let child = parent.child(i); onNode(child, locals, deco.forChild(offset2, child), i); offset2 += child.nodeSize; } return; } let decoIndex = 0, active = [], restNode = null; for (let parentIndex = 0; ; ) { let widget, widgets; while (decoIndex < locals.length && locals[decoIndex].to == offset2) { let next = locals[decoIndex++]; if (next.widget) { if (!widget) widget = next; else (widgets || (widgets = [widget])).push(next); } } if (widget) { if (widgets) { widgets.sort(compareSide); for (let i = 0; i < widgets.length; i++) onWidget(widgets[i], parentIndex, !!restNode); } else { onWidget(widget, parentIndex, !!restNode); } } let child, index; if (restNode) { index = -1; child = restNode; restNode = null; } else if (parentIndex < parent.childCount) { index = parentIndex; child = parent.child(parentIndex++); } else { break; } for (let i = 0; i < active.length; i++) if (active[i].to <= offset2) active.splice(i--, 1); while (decoIndex < locals.length && locals[decoIndex].from <= offset2 && locals[decoIndex].to > offset2) active.push(locals[decoIndex++]); let end = offset2 + child.nodeSize; if (child.isText) { let cutAt = end; if (decoIndex < locals.length && locals[decoIndex].from < cutAt) cutAt = locals[decoIndex].from; for (let i = 0; i < active.length; i++) if (active[i].to < cutAt) cutAt = active[i].to; if (cutAt < end) { restNode = child.cut(cutAt - offset2); child = child.cut(0, cutAt - offset2); end = cutAt; index = -1; } } else { while (decoIndex < locals.length && locals[decoIndex].to < end) decoIndex++; } let outerDeco = child.isInline && !child.isLeaf ? active.filter((d) => !d.inline) : active.slice(); onNode(child, outerDeco, deco.forChild(offset2, child), index); offset2 = end; } } function iosHacks(dom) { if (dom.nodeName == "UL" || dom.nodeName == "OL") { let oldCSS = dom.style.cssText; dom.style.cssText = oldCSS + "; list-style: square !important"; window.getComputedStyle(dom).listStyle; dom.style.cssText = oldCSS; } } function findTextInFragment(frag, text, from2, to) { for (let i = 0, pos = 0; i < frag.childCount && pos <= to; ) { let child = frag.child(i++), childStart = pos; pos += child.nodeSize; if (!child.isText) continue; let str = child.text; while (i < frag.childCount) { let next = frag.child(i++); pos += next.nodeSize; if (!next.isText) break; str += next.text; } if (pos >= from2) { if (pos >= to && str.slice(to - text.length - childStart, to - childStart) == text) return to - text.length; let found2 = childStart < to ? str.lastIndexOf(text, to - childStart - 1) : -1; if (found2 >= 0 && found2 + text.length + childStart >= from2) return childStart + found2; if (from2 == to && str.length >= to + text.length - childStart && str.slice(to - childStart, to - childStart + text.length) == text) return to; } } return -1; } function replaceNodes(nodes, from2, to, view, replacement) { let result = []; for (let i = 0, off = 0; i < nodes.length; i++) { let child = nodes[i], start = off, end = off += child.size; if (start >= to || end <= from2) { result.push(child); } else { if (start < from2) result.push(child.slice(0, from2 - start, view)); if (replacement) { result.push(replacement); replacement = void 0; } if (end > to) result.push(child.slice(to - start, child.size, view)); } } return result; } function selectionFromDOM(view, origin = null) { let domSel = view.domSelectionRange(), doc2 = view.state.doc; if (!domSel.focusNode) return null; let nearestDesc = view.docView.nearestDesc(domSel.focusNode), inWidget = nearestDesc && nearestDesc.size == 0; let head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset, 1); if (head < 0) return null; let $head = doc2.resolve(head), anchor, selection; if (selectionCollapsed(domSel)) { anchor = head; while (nearestDesc && !nearestDesc.node) nearestDesc = nearestDesc.parent; let nearestDescNode = nearestDesc.node; if (nearestDesc && nearestDescNode.isAtom && NodeSelection.isSelectable(nearestDescNode) && nearestDesc.parent && !(nearestDescNode.isInline && isOnEdge(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) { let pos = nearestDesc.posBefore; selection = new NodeSelection(head == pos ? $head : doc2.resolve(pos)); } } else { if (domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) { let min2 = head, max2 = head; for (let i = 0; i < domSel.rangeCount; i++) { let range = domSel.getRangeAt(i); min2 = Math.min(min2, view.docView.posFromDOM(range.startContainer, range.startOffset, 1)); max2 = Math.max(max2, view.docView.posFromDOM(range.endContainer, range.endOffset, -1)); } if (min2 < 0) return null; [anchor, head] = max2 == view.state.selection.anchor ? [max2, min2] : [min2, max2]; $head = doc2.resolve(head); } else { anchor = view.docView.posFromDOM(domSel.anchorNode, domSel.anchorOffset, 1); } if (anchor < 0) return null; } let $anchor = doc2.resolve(anchor); if (!selection) { let bias = origin == "pointer" || view.state.selection.head < $head.pos && !inWidget ? 1 : -1; selection = selectionBetween(view, $anchor, $head, bias); } return selection; } function editorOwnsSelection(view) { return view.editable ? view.hasFocus() : hasSelection(view) && document.activeElement && document.activeElement.contains(view.dom); } function selectionToDOM(view, force = false) { let sel = view.state.selection; syncNodeSelection(view, sel); if (!editorOwnsSelection(view)) return; if (!force && view.input.mouseDown && view.input.mouseDown.allowDefault && chrome) { let domSel = view.domSelectionRange(), curSel = view.domObserver.currentSelection; if (domSel.anchorNode && curSel.anchorNode && isEquivalentPosition(domSel.anchorNode, domSel.anchorOffset, curSel.anchorNode, curSel.anchorOffset)) { view.input.mouseDown.delayedSelectionSync = true; view.domObserver.setCurSelection(); return; } } view.domObserver.disconnectSelection(); if (view.cursorWrapper) { selectCursorWrapper(view); } else { let { anchor, head } = sel, resetEditableFrom, resetEditableTo; if (brokenSelectBetweenUneditable && !(sel instanceof TextSelection)) { if (!sel.$from.parent.inlineContent) resetEditableFrom = temporarilyEditableNear(view, sel.from); if (!sel.empty && !sel.$from.parent.inlineContent) resetEditableTo = temporarilyEditableNear(view, sel.to); } view.docView.setSelection(anchor, head, view, force); if (brokenSelectBetweenUneditable) { if (resetEditableFrom) resetEditable(resetEditableFrom); if (resetEditableTo) resetEditable(resetEditableTo); } if (sel.visible) { view.dom.classList.remove("ProseMirror-hideselection"); } else { view.dom.classList.add("ProseMirror-hideselection"); if ("onselectionchange" in document) removeClassOnSelectionChange(view); } } view.domObserver.setCurSelection(); view.domObserver.connectSelection(); } const brokenSelectBetweenUneditable = safari || chrome && chrome_version < 63; function temporarilyEditableNear(view, pos) { let { node, offset: offset2 } = view.docView.domFromPos(pos, 0); let after = offset2 < node.childNodes.length ? node.childNodes[offset2] : null; let before = offset2 ? node.childNodes[offset2 - 1] : null; if (safari && after && after.contentEditable == "false") return setEditable(after); if ((!after || after.contentEditable == "false") && (!before || before.contentEditable == "false")) { if (after) return setEditable(after); else if (before) return setEditable(before); } } function setEditable(element) { element.contentEditable = "true"; if (safari && element.draggable) { element.draggable = false; element.wasDraggable = true; } return element; } function resetEditable(element) { element.contentEditable = "false"; if (element.wasDraggable) { element.draggable = true; element.wasDraggable = null; } } function removeClassOnSelectionChange(view) { let doc2 = view.dom.ownerDocument; doc2.removeEventListener("selectionchange", view.input.hideSelectionGuard); let domSel = view.domSelectionRange(); let node = domSel.anchorNode, offset2 = domSel.anchorOffset; doc2.addEventListener("selectionchange", view.input.hideSelectionGuard = () => { if (domSel.anchorNode != node || domSel.anchorOffset != offset2) { doc2.removeEventListener("selectionchange", view.input.hideSelectionGuard); setTimeout(() => { if (!editorOwnsSelection(view) || view.state.selection.visible) view.dom.classList.remove("ProseMirror-hideselection"); }, 20); } }); } function selectCursorWrapper(view) { let domSel = view.domSelection(); if (!domSel) return; let node = view.cursorWrapper.dom, img = node.nodeName == "IMG"; if (img) domSel.collapse(node.parentNode, domIndex(node) + 1); else domSel.collapse(node, 0); if (!img && !view.state.selection.visible && ie$1 && ie_version <= 11) { node.disabled = true; node.disabled = false; } } function syncNodeSelection(view, sel) { if (sel instanceof NodeSelection) { let desc = view.docView.descAt(sel.from); if (desc != view.lastSelectedViewDesc) { clearNodeSelection(view); if (desc) desc.selectNode(); view.lastSelectedViewDesc = desc; } } else { clearNodeSelection(view); } } function clearNodeSelection(view) { if (view.lastSelectedViewDesc) { if (view.lastSelectedViewDesc.parent) view.lastSelectedViewDesc.deselectNode(); view.lastSelectedViewDesc = void 0; } } function selectionBetween(view, $anchor, $head, bias) { return view.someProp("createSelectionBetween", (f) => f(view, $anchor, $head)) || TextSelection.between($anchor, $head, bias); } function hasFocusAndSelection(view) { if (view.editable && !view.hasFocus()) return false; return hasSelection(view); } function hasSelection(view) { let sel = view.domSelectionRange(); if (!sel.anchorNode) return false; try { return view.dom.contains(sel.anchorNode.nodeType == 3 ? sel.anchorNode.parentNode : sel.anchorNode) && (view.editable || view.dom.contains(sel.focusNode.nodeType == 3 ? sel.focusNode.parentNode : sel.focusNode)); } catch (_) { return false; } } function anchorInRightPlace(view) { let anchorDOM = view.docView.domFromPos(view.state.selection.anchor, 0); let domSel = view.domSelectionRange(); return isEquivalentPosition(anchorDOM.node, anchorDOM.offset, domSel.anchorNode, domSel.anchorOffset); } function moveSelectionBlock(state, dir) { let { $anchor, $head } = state.selection; let $side = dir > 0 ? $anchor.max($head) : $anchor.min($head); let $start = !$side.parent.inlineContent ? $side : $side.depth ? state.doc.resolve(dir > 0 ? $side.after() : $side.before()) : null; return $start && Selection.findFrom($start, dir); } function apply(view, sel) { view.dispatch(view.state.tr.setSelection(sel).scrollIntoView()); return true; } function selectHorizontally(view, dir, mods) { let sel = view.state.selection; if (sel instanceof TextSelection) { if (mods.indexOf("s") > -1) { let { $head } = sel, node = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter; if (!node || node.isText || !node.isLeaf) return false; let $newHead = view.state.doc.resolve($head.pos + node.nodeSize * (dir < 0 ? -1 : 1)); return apply(view, new TextSelection(sel.$anchor, $newHead)); } else if (!sel.empty) { return false; } else if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) { let next = moveSelectionBlock(view.state, dir); if (next && next instanceof NodeSelection) return apply(view, next); return false; } else if (!(mac$2 && mods.indexOf("m") > -1)) { let $head = sel.$head, node = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter, desc; if (!node || node.isText) return false; let nodePos = dir < 0 ? $head.pos - node.nodeSize : $head.pos; if (!(node.isAtom || (desc = view.docView.descAt(nodePos)) && !desc.contentDOM)) return false; if (NodeSelection.isSelectable(node)) { return apply(view, new NodeSelection(dir < 0 ? view.state.doc.resolve($head.pos - node.nodeSize) : $head)); } else if (webkit) { return apply(view, new TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + node.nodeSize))); } else { return false; } } } else if (sel instanceof NodeSelection && sel.node.isInline) { return apply(view, new TextSelection(dir > 0 ? sel.$to : sel.$from)); } else { let next = moveSelectionBlock(view.state, dir); if (next) return apply(view, next); return false; } } function nodeLen(node) { return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length; } function isIgnorable(dom, dir) { let desc = dom.pmViewDesc; return desc && desc.size == 0 && (dir < 0 || dom.nextSibling || dom.nodeName != "BR"); } function skipIgnoredNodes(view, dir) { return dir < 0 ? skipIgnoredNodesBefore(view) : skipIgnoredNodesAfter(view); } function skipIgnoredNodesBefore(view) { let sel = view.domSelectionRange(); let node = sel.focusNode, offset2 = sel.focusOffset; if (!node) return; let moveNode, moveOffset, force = false; if (gecko && node.nodeType == 1 && offset2 < nodeLen(node) && isIgnorable(node.childNodes[offset2], -1)) force = true; for (; ; ) { if (offset2 > 0) { if (node.nodeType != 1) { break; } else { let before = node.childNodes[offset2 - 1]; if (isIgnorable(before, -1)) { moveNode = node; moveOffset = --offset2; } else if (before.nodeType == 3) { node = before; offset2 = node.nodeValue.length; } else break; } } else if (isBlockNode(node)) { break; } else { let prev = node.previousSibling; while (prev && isIgnorable(prev, -1)) { moveNode = node.parentNode; moveOffset = domIndex(prev); prev = prev.previousSibling; } if (!prev) { node = node.parentNode; if (node == view.dom) break; offset2 = 0; } else { node = prev; offset2 = nodeLen(node); } } } if (force) setSelFocus(view, node, offset2); else if (moveNode) setSelFocus(view, moveNode, moveOffset); } function skipIgnoredNodesAfter(view) { let sel = view.domSelectionRange(); let node = sel.focusNode, offset2 = sel.focusOffset; if (!node) return; let len = nodeLen(node); let moveNode, moveOffset; for (; ; ) { if (offset2 < len) { if (node.nodeType != 1) break; let after = node.childNodes[offset2]; if (isIgnorable(after, 1)) { moveNode = node; moveOffset = ++offset2; } else break; } else if (isBlockNode(node)) { break; } else { let next = node.nextSibling; while (next && isIgnorable(next, 1)) { moveNode = next.parentNode; moveOffset = domIndex(next) + 1; next = next.nextSibling; } if (!next) { node = node.parentNode; if (node == view.dom) break; offset2 = len = 0; } else { node = next; offset2 = 0; len = nodeLen(node); } } } if (moveNode) setSelFocus(view, moveNode, moveOffset); } function isBlockNode(dom) { let desc = dom.pmViewDesc; return desc && desc.node && desc.node.isBlock; } function textNodeAfter(node, offset2) { while (node && offset2 == node.childNodes.length && !hasBlockDesc(node)) { offset2 = domIndex(node) + 1; node = node.parentNode; } while (node && offset2 < node.childNodes.length) { let next = node.childNodes[offset2]; if (next.nodeType == 3) return next; if (next.nodeType == 1 && next.contentEditable == "false") break; node = next; offset2 = 0; } } function textNodeBefore(node, offset2) { while (node && !offset2 && !hasBlockDesc(node)) { offset2 = domIndex(node); node = node.parentNode; } while (node && offset2) { let next = node.childNodes[offset2 - 1]; if (next.nodeType == 3) return next; if (next.nodeType == 1 && next.contentEditable == "false") break; node = next; offset2 = node.childNodes.length; } } function setSelFocus(view, node, offset2) { if (node.nodeType != 3) { let before, after; if (after = textNodeAfter(node, offset2)) { node = after; offset2 = 0; } else if (before = textNodeBefore(node, offset2)) { node = before; offset2 = before.nodeValue.length; } } let sel = view.domSelection(); if (!sel) return; if (selectionCollapsed(sel)) { let range = document.createRange(); range.setEnd(node, offset2); range.setStart(node, offset2); sel.removeAllRanges(); sel.addRange(range); } else if (sel.extend) { sel.extend(node, offset2); } view.domObserver.setCurSelection(); let { state } = view; setTimeout(() => { if (view.state == state) selectionToDOM(view); }, 50); } function findDirection(view, pos) { let $pos = view.state.doc.resolve(pos); if (!(chrome || windows$1) && $pos.parent.inlineContent) { let coords = view.coordsAtPos(pos); if (pos > $pos.start()) { let before = view.coordsAtPos(pos - 1); let mid = (before.top + before.bottom) / 2; if (mid > coords.top && mid < coords.bottom && Math.abs(before.left - coords.left) > 1) return before.left < coords.left ? "ltr" : "rtl"; } if (pos < $pos.end()) { let after = view.coordsAtPos(pos + 1); let mid = (after.top + after.bottom) / 2; if (mid > coords.top && mid < coords.bottom && Math.abs(after.left - coords.left) > 1) return after.left > coords.left ? "ltr" : "rtl"; } } let computed = getComputedStyle(view.dom).direction; return computed == "rtl" ? "rtl" : "ltr"; } function selectVertically(view, dir, mods) { let sel = view.state.selection; if (sel instanceof TextSelection && !sel.empty || mods.indexOf("s") > -1) return false; if (mac$2 && mods.indexOf("m") > -1) return false; let { $from, $to } = sel; if (!$from.parent.inlineContent || view.endOfTextblock(dir < 0 ? "up" : "down")) { let next = moveSelectionBlock(view.state, dir); if (next && next instanceof NodeSelection) return apply(view, next); } if (!$from.parent.inlineContent) { let side = dir < 0 ? $from : $to; let beyond = sel instanceof AllSelection ? Selection.near(side, dir) : Selection.findFrom(side, dir); return beyond ? apply(view, beyond) : false; } return false; } function stopNativeHorizontalDelete(view, dir) { if (!(view.state.selection instanceof TextSelection)) return true; let { $head, $anchor, empty: empty2 } = view.state.selection; if (!$head.sameParent($anchor)) return true; if (!empty2) return false; if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) return true; let nextNode = !$head.textOffset && (dir < 0 ? $head.nodeBefore : $head.nodeAfter); if (nextNode && !nextNode.isText) { let tr2 = view.state.tr; if (dir < 0) tr2.delete($head.pos - nextNode.nodeSize, $head.pos); else tr2.delete($head.pos, $head.pos + nextNode.nodeSize); view.dispatch(tr2); return true; } return false; } function switchEditable(view, node, state) { view.domObserver.stop(); node.contentEditable = state; view.domObserver.start(); } function safariDownArrowBug(view) { if (!safari || view.state.selection.$head.parentOffset > 0) return false; let { focusNode, focusOffset } = view.domSelectionRange(); if (focusNode && focusNode.nodeType == 1 && focusOffset == 0 && focusNode.firstChild && focusNode.firstChild.contentEditable == "false") { let child = focusNode.firstChild; switchEditable(view, child, "true"); setTimeout(() => switchEditable(view, child, "false"), 20); } return false; } function getMods(event) { let result = ""; if (event.ctrlKey) result += "c"; if (event.metaKey) result += "m"; if (event.altKey) result += "a"; if (event.shiftKey) result += "s"; return result; } function captureKeyDown(view, event) { let code = event.keyCode, mods = getMods(event); if (code == 8 || mac$2 && code == 72 && mods == "c") { return stopNativeHorizontalDelete(view, -1) || skipIgnoredNodes(view, -1); } else if (code == 46 && !event.shiftKey || mac$2 && code == 68 && mods == "c") { return stopNativeHorizontalDelete(view, 1) || skipIgnoredNodes(view, 1); } else if (code == 13 || code == 27) { return true; } else if (code == 37 || mac$2 && code == 66 && mods == "c") { let dir = code == 37 ? findDirection(view, view.state.selection.from) == "ltr" ? -1 : 1 : -1; return selectHorizontally(view, dir, mods) || skipIgnoredNodes(view, dir); } else if (code == 39 || mac$2 && code == 70 && mods == "c") { let dir = code == 39 ? findDirection(view, view.state.selection.from) == "ltr" ? 1 : -1 : 1; return selectHorizontally(view, dir, mods) || skipIgnoredNodes(view, dir); } else if (code == 38 || mac$2 && code == 80 && mods == "c") { return selectVertically(view, -1, mods) || skipIgnoredNodes(view, -1); } else if (code == 40 || mac$2 && code == 78 && mods == "c") { return safariDownArrowBug(view) || selectVertically(view, 1, mods) || skipIgnoredNodes(view, 1); } else if (mods == (mac$2 ? "m" : "c") && (code == 66 || code == 73 || code == 89 || code == 90)) { return true; } return false; } function serializeForClipboard(view, slice2) { view.someProp("transformCopied", (f) => { slice2 = f(slice2, view); }); let context = [], { content, openStart, openEnd } = slice2; while (openStart > 1 && openEnd > 1 && content.childCount == 1 && content.firstChild.childCount == 1) { openStart--; openEnd--; let node = content.firstChild; context.push(node.type.name, node.attrs != node.type.defaultAttrs ? node.attrs : null); content = node.content; } let serializer = view.someProp("clipboardSerializer") || DOMSerializer.fromSchema(view.state.schema); let doc2 = detachedDoc(), wrap2 = doc2.createElement("div"); wrap2.appendChild(serializer.serializeFragment(content, { document: doc2 })); let firstChild = wrap2.firstChild, needsWrap, wrappers = 0; while (firstChild && firstChild.nodeType == 1 && (needsWrap = wrapMap[firstChild.nodeName.toLowerCase()])) { for (let i = needsWrap.length - 1; i >= 0; i--) { let wrapper = doc2.createElement(needsWrap[i]); while (wrap2.firstChild) wrapper.appendChild(wrap2.firstChild); wrap2.appendChild(wrapper); wrappers++; } firstChild = wrap2.firstChild; } if (firstChild && firstChild.nodeType == 1) firstChild.setAttribute("data-pm-slice", `${openStart} ${openEnd}${wrappers ? ` -${wrappers}` : ""} ${JSON.stringify(context)}`); let text = view.someProp("clipboardTextSerializer", (f) => f(slice2, view)) || slice2.content.textBetween(0, slice2.content.size, "\n\n"); return { dom: wrap2, text, slice: slice2 }; } function parseFromClipboard(view, text, html, plainText, $context) { let inCode = $context.parent.type.spec.code; let dom, slice2; if (!html && !text) return null; let asText = !!text && (plainText || inCode || !html); if (asText) { view.someProp("transformPastedText", (f) => { text = f(text, inCode || plainText, view); }); if (inCode) { slice2 = new Slice(Fragment.from(view.state.schema.text(text.replace(/\r\n?/g, "\n"))), 0, 0); view.someProp("transformPasted", (f) => { slice2 = f(slice2, view, true); }); return slice2; } let parsed = view.someProp("clipboardTextParser", (f) => f(text, $context, plainText, view)); if (parsed) { slice2 = parsed; } else { let marks = $context.marks(); let { schema } = view.state, serializer = DOMSerializer.fromSchema(schema); dom = document.createElement("div"); text.split(/(?:\r\n?|\n)+/).forEach((block) => { let p = dom.appendChild(document.createElement("p")); if (block) p.appendChild(serializer.serializeNode(schema.text(block, marks))); }); } } else { view.someProp("transformPastedHTML", (f) => { html = f(html, view); }); dom = readHTML(html); if (webkit) restoreReplacedSpaces(dom); } let contextNode = dom && dom.querySelector("[data-pm-slice]"); let sliceData = contextNode && /^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(contextNode.getAttribute("data-pm-slice") || ""); if (sliceData && sliceData[3]) for (let i = +sliceData[3]; i > 0; i--) { let child = dom.firstChild; while (child && child.nodeType != 1) child = child.nextSibling; if (!child) break; dom = child; } if (!slice2) { let parser = view.someProp("clipboardParser") || view.someProp("domParser") || DOMParser.fromSchema(view.state.schema); slice2 = parser.parseSlice(dom, { preserveWhitespace: !!(asText || sliceData), context: $context, ruleFromNode(dom2) { if (dom2.nodeName == "BR" && !dom2.nextSibling && dom2.parentNode && !inlineParents.test(dom2.parentNode.nodeName)) return { ignore: true }; return null; } }); } if (sliceData) { slice2 = addContext(closeSlice(slice2, +sliceData[1], +sliceData[2]), sliceData[4]); } else { slice2 = Slice.maxOpen(normalizeSiblings(slice2.content, $context), true); if (slice2.openStart || slice2.openEnd) { let openStart = 0, openEnd = 0; for (let node = slice2.content.firstChild; openStart < slice2.openStart && !node.type.spec.isolating; openStart++, node = node.firstChild) { } for (let node = slice2.content.lastChild; openEnd < slice2.openEnd && !node.type.spec.isolating; openEnd++, node = node.lastChild) { } slice2 = closeSlice(slice2, openStart, openEnd); } } view.someProp("transformPasted", (f) => { slice2 = f(slice2, view, asText); }); return slice2; } const inlineParents = /^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i; function normalizeSiblings(fragment, $context) { if (fragment.childCount < 2) return fragment; for (let d = $context.depth; d >= 0; d--) { let parent = $context.node(d); let match = parent.contentMatchAt($context.index(d)); let lastWrap, result = []; fragment.forEach((node) => { if (!result) return; let wrap2 = match.findWrapping(node.type), inLast; if (!wrap2) return result = null; if (inLast = result.length && lastWrap.length && addToSibling(wrap2, lastWrap, node, result[result.length - 1], 0)) { result[result.length - 1] = inLast; } else { if (result.length) result[result.length - 1] = closeRight(result[result.length - 1], lastWrap.length); let wrapped = withWrappers(node, wrap2); result.push(wrapped); match = match.matchType(wrapped.type); lastWrap = wrap2; } }); if (result) return Fragment.from(result); } return fragment; } function withWrappers(node, wrap2, from2 = 0) { for (let i = wrap2.length - 1; i >= from2; i--) node = wrap2[i].create(null, Fragment.from(node)); return node; } function addToSibling(wrap2, lastWrap, node, sibling, depth) { if (depth < wrap2.length && depth < lastWrap.length && wrap2[depth] == lastWrap[depth]) { let inner = addToSibling(wrap2, lastWrap, node, sibling.lastChild, depth + 1); if (inner) return sibling.copy(sibling.content.replaceChild(sibling.childCount - 1, inner)); let match = sibling.contentMatchAt(sibling.childCount); if (match.matchType(depth == wrap2.length - 1 ? node.type : wrap2[depth + 1])) return sibling.copy(sibling.content.append(Fragment.from(withWrappers(node, wrap2, depth + 1)))); } } function closeRight(node, depth) { if (depth == 0) return node; let fragment = node.content.replaceChild(node.childCount - 1, closeRight(node.lastChild, depth - 1)); let fill = node.contentMatchAt(node.childCount).fillBefore(Fragment.empty, true); return node.copy(fragment.append(fill)); } function closeRange(fragment, side, from2, to, depth, openEnd) { let node = side < 0 ? fragment.firstChild : fragment.lastChild, inner = node.content; if (fragment.childCount > 1) openEnd = 0; if (depth < to - 1) inner = closeRange(inner, side, from2, to, depth + 1, openEnd); if (depth >= from2) inner = side < 0 ? node.contentMatchAt(0).fillBefore(inner, openEnd <= depth).append(inner) : inner.append(node.contentMatchAt(node.childCount).fillBefore(Fragment.empty, true)); return fragment.replaceChild(side < 0 ? 0 : fragment.childCount - 1, node.copy(inner)); } function closeSlice(slice2, openStart, openEnd) { if (openStart < slice2.openStart) slice2 = new Slice(closeRange(slice2.content, -1, openStart, slice2.openStart, 0, slice2.openEnd), openStart, slice2.openEnd); if (openEnd < slice2.openEnd) slice2 = new Slice(closeRange(slice2.content, 1, openEnd, slice2.openEnd, 0, 0), slice2.openStart, openEnd); return slice2; } const wrapMap = { thead: ["table"], tbody: ["table"], tfoot: ["table"], caption: ["table"], colgroup: ["table"], col: ["table", "colgroup"], tr: ["table", "tbody"], td: ["table", "tbody", "tr"], th: ["table", "tbody", "tr"] }; let _detachedDoc = null; function detachedDoc() { return _detachedDoc || (_detachedDoc = document.implementation.createHTMLDocument("title")); } let _policy = null; function maybeWrapTrusted(html) { let trustedTypes = window.trustedTypes; if (!trustedTypes) return html; if (!_policy) _policy = trustedTypes.defaultPolicy || trustedTypes.createPolicy("ProseMirrorClipboard", { createHTML: (s) => s }); return _policy.createHTML(html); } function readHTML(html) { let metas = /^(\s*]*>)*/.exec(html); if (metas) html = html.slice(metas[0].length); let elt = detachedDoc().createElement("div"); let firstTag = /<([a-z][^>\s]+)/i.exec(html), wrap2; if (wrap2 = firstTag && wrapMap[firstTag[1].toLowerCase()]) html = wrap2.map((n) => "<" + n + ">").join("") + html + wrap2.map((n) => "").reverse().join(""); elt.innerHTML = maybeWrapTrusted(html); if (wrap2) for (let i = 0; i < wrap2.length; i++) elt = elt.querySelector(wrap2[i]) || elt; return elt; } function restoreReplacedSpaces(dom) { let nodes = dom.querySelectorAll(chrome ? "span:not([class]):not([style])" : "span.Apple-converted-space"); for (let i = 0; i < nodes.length; i++) { let node = nodes[i]; if (node.childNodes.length == 1 && node.textContent == " " && node.parentNode) node.parentNode.replaceChild(dom.ownerDocument.createTextNode(" "), node); } } function addContext(slice2, context) { if (!slice2.size) return slice2; let schema = slice2.content.firstChild.type.schema, array; try { array = JSON.parse(context); } catch (e) { return slice2; } let { content, openStart, openEnd } = slice2; for (let i = array.length - 2; i >= 0; i -= 2) { let type = schema.nodes[array[i]]; if (!type || type.hasRequiredAttrs()) break; content = Fragment.from(type.create(array[i + 1], content)); openStart++; openEnd++; } return new Slice(content, openStart, openEnd); } const handlers = {}; const editHandlers = {}; const passiveHandlers = { touchstart: true, touchmove: true }; class InputState { constructor() { this.shiftKey = false; this.mouseDown = null; this.lastKeyCode = null; this.lastKeyCodeTime = 0; this.lastClick = { time: 0, x: 0, y: 0, type: "", button: 0 }; this.lastSelectionOrigin = null; this.lastSelectionTime = 0; this.lastIOSEnter = 0; this.lastIOSEnterFallbackTimeout = -1; this.lastFocus = 0; this.lastTouch = 0; this.lastChromeDelete = 0; this.composing = false; this.compositionNode = null; this.composingTimeout = -1; this.compositionNodes = []; this.compositionEndedAt = -2e8; this.compositionID = 1; this.badSafariComposition = false; this.compositionPendingChanges = 0; this.domChangeCount = 0; this.eventHandlers = /* @__PURE__ */ Object.create(null); this.hideSelectionGuard = null; } } function initInput(view) { for (let event in handlers) { let handler = handlers[event]; view.dom.addEventListener(event, view.input.eventHandlers[event] = (event2) => { if (eventBelongsToView(view, event2) && !runCustomHandler(view, event2) && (view.editable || !(event2.type in editHandlers))) handler(view, event2); }, passiveHandlers[event] ? { passive: true } : void 0); } if (safari) view.dom.addEventListener("input", () => null); ensureListeners(view); } function setSelectionOrigin(view, origin) { view.input.lastSelectionOrigin = origin; view.input.lastSelectionTime = Date.now(); } function destroyInput(view) { view.domObserver.stop(); for (let type in view.input.eventHandlers) view.dom.removeEventListener(type, view.input.eventHandlers[type]); clearTimeout(view.input.composingTimeout); clearTimeout(view.input.lastIOSEnterFallbackTimeout); } function ensureListeners(view) { view.someProp("handleDOMEvents", (currentHandlers) => { for (let type in currentHandlers) if (!view.input.eventHandlers[type]) view.dom.addEventListener(type, view.input.eventHandlers[type] = (event) => runCustomHandler(view, event)); }); } function runCustomHandler(view, event) { return view.someProp("handleDOMEvents", (handlers2) => { let handler = handlers2[event.type]; return handler ? handler(view, event) || event.defaultPrevented : false; }); } function eventBelongsToView(view, event) { if (!event.bubbles) return true; if (event.defaultPrevented) return false; for (let node = event.target; node != view.dom; node = node.parentNode) if (!node || node.nodeType == 11 || node.pmViewDesc && node.pmViewDesc.stopEvent(event)) return false; return true; } function dispatchEvent(view, event) { if (!runCustomHandler(view, event) && handlers[event.type] && (view.editable || !(event.type in editHandlers))) handlers[event.type](view, event); } editHandlers.keydown = (view, _event) => { let event = _event; view.input.shiftKey = event.keyCode == 16 || event.shiftKey; if (inOrNearComposition(view, event)) return; view.input.lastKeyCode = event.keyCode; view.input.lastKeyCodeTime = Date.now(); if (android && chrome && event.keyCode == 13) return; if (event.keyCode != 229) view.domObserver.forceFlush(); if (ios && event.keyCode == 13 && !event.ctrlKey && !event.altKey && !event.metaKey) { let now = Date.now(); view.input.lastIOSEnter = now; view.input.lastIOSEnterFallbackTimeout = setTimeout(() => { if (view.input.lastIOSEnter == now) { view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter"))); view.input.lastIOSEnter = 0; } }, 200); } else if (view.someProp("handleKeyDown", (f) => f(view, event)) || captureKeyDown(view, event)) { event.preventDefault(); } else { setSelectionOrigin(view, "key"); } }; editHandlers.keyup = (view, event) => { if (event.keyCode == 16) view.input.shiftKey = false; }; editHandlers.keypress = (view, _event) => { let event = _event; if (inOrNearComposition(view, event) || !event.charCode || event.ctrlKey && !event.altKey || mac$2 && event.metaKey) return; if (view.someProp("handleKeyPress", (f) => f(view, event))) { event.preventDefault(); return; } let sel = view.state.selection; if (!(sel instanceof TextSelection) || !sel.$from.sameParent(sel.$to)) { let text = String.fromCharCode(event.charCode); let deflt = () => view.state.tr.insertText(text).scrollIntoView(); if (!/[\r\n]/.test(text) && !view.someProp("handleTextInput", (f) => f(view, sel.$from.pos, sel.$to.pos, text, deflt))) view.dispatch(deflt()); event.preventDefault(); } }; function eventCoords(event) { return { left: event.clientX, top: event.clientY }; } function isNear(event, click) { let dx = click.x - event.clientX, dy = click.y - event.clientY; return dx * dx + dy * dy < 100; } function runHandlerOnContext(view, propName, pos, inside, event) { if (inside == -1) return false; let $pos = view.state.doc.resolve(inside); for (let i = $pos.depth + 1; i > 0; i--) { if (view.someProp(propName, (f) => i > $pos.depth ? f(view, pos, $pos.nodeAfter, $pos.before(i), event, true) : f(view, pos, $pos.node(i), $pos.before(i), event, false))) return true; } return false; } function updateSelection(view, selection, origin) { if (!view.focused) view.focus(); if (view.state.selection.eq(selection)) return; let tr2 = view.state.tr.setSelection(selection); tr2.setMeta("pointer", true); view.dispatch(tr2); } function selectClickedLeaf(view, inside) { if (inside == -1) return false; let $pos = view.state.doc.resolve(inside), node = $pos.nodeAfter; if (node && node.isAtom && NodeSelection.isSelectable(node)) { updateSelection(view, new NodeSelection($pos)); return true; } return false; } function selectClickedNode(view, inside) { if (inside == -1) return false; let sel = view.state.selection, selectedNode, selectAt; if (sel instanceof NodeSelection) selectedNode = sel.node; let $pos = view.state.doc.resolve(inside); for (let i = $pos.depth + 1; i > 0; i--) { let node = i > $pos.depth ? $pos.nodeAfter : $pos.node(i); if (NodeSelection.isSelectable(node)) { if (selectedNode && sel.$from.depth > 0 && i >= sel.$from.depth && $pos.before(sel.$from.depth + 1) == sel.$from.pos) selectAt = $pos.before(sel.$from.depth); else selectAt = $pos.before(i); break; } } if (selectAt != null) { updateSelection(view, NodeSelection.create(view.state.doc, selectAt)); return true; } else { return false; } } function handleSingleClick(view, pos, inside, event, selectNode) { return runHandlerOnContext(view, "handleClickOn", pos, inside, event) || view.someProp("handleClick", (f) => f(view, pos, event)) || (selectNode ? selectClickedNode(view, inside) : selectClickedLeaf(view, inside)); } function handleDoubleClick(view, pos, inside, event) { return runHandlerOnContext(view, "handleDoubleClickOn", pos, inside, event) || view.someProp("handleDoubleClick", (f) => f(view, pos, event)); } function handleTripleClick$1(view, pos, inside, event) { return runHandlerOnContext(view, "handleTripleClickOn", pos, inside, event) || view.someProp("handleTripleClick", (f) => f(view, pos, event)) || defaultTripleClick(view, inside, event); } function defaultTripleClick(view, inside, event) { if (event.button != 0) return false; let doc2 = view.state.doc; if (inside == -1) { if (doc2.inlineContent) { updateSelection(view, TextSelection.create(doc2, 0, doc2.content.size)); return true; } return false; } let $pos = doc2.resolve(inside); for (let i = $pos.depth + 1; i > 0; i--) { let node = i > $pos.depth ? $pos.nodeAfter : $pos.node(i); let nodePos = $pos.before(i); if (node.inlineContent) updateSelection(view, TextSelection.create(doc2, nodePos + 1, nodePos + 1 + node.content.size)); else if (NodeSelection.isSelectable(node)) updateSelection(view, NodeSelection.create(doc2, nodePos)); else continue; return true; } } function forceDOMFlush(view) { return endComposition(view); } const selectNodeModifier = mac$2 ? "metaKey" : "ctrlKey"; handlers.mousedown = (view, _event) => { let event = _event; view.input.shiftKey = event.shiftKey; let flushed = forceDOMFlush(view); let now = Date.now(), type = "singleClick"; if (now - view.input.lastClick.time < 500 && isNear(event, view.input.lastClick) && !event[selectNodeModifier] && view.input.lastClick.button == event.button) { if (view.input.lastClick.type == "singleClick") type = "doubleClick"; else if (view.input.lastClick.type == "doubleClick") type = "tripleClick"; } view.input.lastClick = { time: now, x: event.clientX, y: event.clientY, type, button: event.button }; let pos = view.posAtCoords(eventCoords(event)); if (!pos) return; if (type == "singleClick") { if (view.input.mouseDown) view.input.mouseDown.done(); view.input.mouseDown = new MouseDown(view, pos, event, !!flushed); } else if ((type == "doubleClick" ? handleDoubleClick : handleTripleClick$1)(view, pos.pos, pos.inside, event)) { event.preventDefault(); } else { setSelectionOrigin(view, "pointer"); } }; class MouseDown { constructor(view, pos, event, flushed) { this.view = view; this.pos = pos; this.event = event; this.flushed = flushed; this.delayedSelectionSync = false; this.mightDrag = null; this.startDoc = view.state.doc; this.selectNode = !!event[selectNodeModifier]; this.allowDefault = event.shiftKey; let targetNode, targetPos; if (pos.inside > -1) { targetNode = view.state.doc.nodeAt(pos.inside); targetPos = pos.inside; } else { let $pos = view.state.doc.resolve(pos.pos); targetNode = $pos.parent; targetPos = $pos.depth ? $pos.before() : 0; } const target = flushed ? null : event.target; const targetDesc = target ? view.docView.nearestDesc(target, true) : null; this.target = targetDesc && targetDesc.nodeDOM.nodeType == 1 ? targetDesc.nodeDOM : null; let { selection } = view.state; if (event.button == 0 && (targetNode.type.spec.draggable && targetNode.type.spec.selectable !== false || selection instanceof NodeSelection && selection.from <= targetPos && selection.to > targetPos)) this.mightDrag = { node: targetNode, pos: targetPos, addAttr: !!(this.target && !this.target.draggable), setUneditable: !!(this.target && gecko && !this.target.hasAttribute("contentEditable")) }; if (this.target && this.mightDrag && (this.mightDrag.addAttr || this.mightDrag.setUneditable)) { this.view.domObserver.stop(); if (this.mightDrag.addAttr) this.target.draggable = true; if (this.mightDrag.setUneditable) setTimeout(() => { if (this.view.input.mouseDown == this) this.target.setAttribute("contentEditable", "false"); }, 20); this.view.domObserver.start(); } view.root.addEventListener("mouseup", this.up = this.up.bind(this)); view.root.addEventListener("mousemove", this.move = this.move.bind(this)); setSelectionOrigin(view, "pointer"); } done() { this.view.root.removeEventListener("mouseup", this.up); this.view.root.removeEventListener("mousemove", this.move); if (this.mightDrag && this.target) { this.view.domObserver.stop(); if (this.mightDrag.addAttr) this.target.removeAttribute("draggable"); if (this.mightDrag.setUneditable) this.target.removeAttribute("contentEditable"); this.view.domObserver.start(); } if (this.delayedSelectionSync) setTimeout(() => selectionToDOM(this.view)); this.view.input.mouseDown = null; } up(event) { this.done(); if (!this.view.dom.contains(event.target)) return; let pos = this.pos; if (this.view.state.doc != this.startDoc) pos = this.view.posAtCoords(eventCoords(event)); this.updateAllowDefault(event); if (this.allowDefault || !pos) { setSelectionOrigin(this.view, "pointer"); } else if (handleSingleClick(this.view, pos.pos, pos.inside, event, this.selectNode)) { event.preventDefault(); } else if (event.button == 0 && (this.flushed || // Safari ignores clicks on draggable elements safari && this.mightDrag && !this.mightDrag.node.isAtom || // Chrome will sometimes treat a node selection as a // cursor, but still report that the node is selected // when asked through getSelection. You'll then get a // situation where clicking at the point where that // (hidden) cursor is doesn't change the selection, and // thus doesn't get a reaction from ProseMirror. This // works around that. chrome && !this.view.state.selection.visible && Math.min(Math.abs(pos.pos - this.view.state.selection.from), Math.abs(pos.pos - this.view.state.selection.to)) <= 2)) { updateSelection(this.view, Selection.near(this.view.state.doc.resolve(pos.pos))); event.preventDefault(); } else { setSelectionOrigin(this.view, "pointer"); } } move(event) { this.updateAllowDefault(event); setSelectionOrigin(this.view, "pointer"); if (event.buttons == 0) this.done(); } updateAllowDefault(event) { if (!this.allowDefault && (Math.abs(this.event.x - event.clientX) > 4 || Math.abs(this.event.y - event.clientY) > 4)) this.allowDefault = true; } } handlers.touchstart = (view) => { view.input.lastTouch = Date.now(); forceDOMFlush(view); setSelectionOrigin(view, "pointer"); }; handlers.touchmove = (view) => { view.input.lastTouch = Date.now(); setSelectionOrigin(view, "pointer"); }; handlers.contextmenu = (view) => forceDOMFlush(view); function inOrNearComposition(view, event) { if (view.composing) return true; if (safari && Math.abs(event.timeStamp - view.input.compositionEndedAt) < 500) { view.input.compositionEndedAt = -2e8; return true; } return false; } const timeoutComposition = android ? 5e3 : -1; editHandlers.compositionstart = editHandlers.compositionupdate = (view) => { if (!view.composing) { view.domObserver.flush(); let { state } = view, $pos = state.selection.$to; if (state.selection instanceof TextSelection && (state.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some((m) => m.type.spec.inclusive === false) || chrome && windows$1 && selectionBeforeUneditable(view))) { view.markCursor = view.state.storedMarks || $pos.marks(); endComposition(view, true); view.markCursor = null; } else { endComposition(view, !state.selection.empty); if (gecko && state.selection.empty && $pos.parentOffset && !$pos.textOffset && $pos.nodeBefore.marks.length) { let sel = view.domSelectionRange(); for (let node = sel.focusNode, offset2 = sel.focusOffset; node && node.nodeType == 1 && offset2 != 0; ) { let before = offset2 < 0 ? node.lastChild : node.childNodes[offset2 - 1]; if (!before) break; if (before.nodeType == 3) { let sel2 = view.domSelection(); if (sel2) sel2.collapse(before, before.nodeValue.length); break; } else { node = before; offset2 = -1; } } } } view.input.composing = true; } scheduleComposeEnd(view, timeoutComposition); }; function selectionBeforeUneditable(view) { let { focusNode, focusOffset } = view.domSelectionRange(); if (!focusNode || focusNode.nodeType != 1 || focusOffset >= focusNode.childNodes.length) return false; let next = focusNode.childNodes[focusOffset]; return next.nodeType == 1 && next.contentEditable == "false"; } editHandlers.compositionend = (view, event) => { if (view.composing) { view.input.composing = false; view.input.compositionEndedAt = event.timeStamp; view.input.compositionPendingChanges = view.domObserver.pendingRecords().length ? view.input.compositionID : 0; view.input.compositionNode = null; if (view.input.badSafariComposition) view.domObserver.forceFlush(); else if (view.input.compositionPendingChanges) Promise.resolve().then(() => view.domObserver.flush()); view.input.compositionID++; scheduleComposeEnd(view, 20); } }; function scheduleComposeEnd(view, delay) { clearTimeout(view.input.composingTimeout); if (delay > -1) view.input.composingTimeout = setTimeout(() => endComposition(view), delay); } function clearComposition(view) { if (view.composing) { view.input.composing = false; view.input.compositionEndedAt = timestampFromCustomEvent(); } while (view.input.compositionNodes.length > 0) view.input.compositionNodes.pop().markParentsDirty(); } function findCompositionNode(view) { let sel = view.domSelectionRange(); if (!sel.focusNode) return null; let textBefore = textNodeBefore$1(sel.focusNode, sel.focusOffset); let textAfter = textNodeAfter$1(sel.focusNode, sel.focusOffset); if (textBefore && textAfter && textBefore != textAfter) { let descAfter = textAfter.pmViewDesc, lastChanged = view.domObserver.lastChangedTextNode; if (textBefore == lastChanged || textAfter == lastChanged) return lastChanged; if (!descAfter || !descAfter.isText(textAfter.nodeValue)) { return textAfter; } else if (view.input.compositionNode == textAfter) { let descBefore = textBefore.pmViewDesc; if (!(!descBefore || !descBefore.isText(textBefore.nodeValue))) return textAfter; } } return textBefore || textAfter; } function timestampFromCustomEvent() { let event = document.createEvent("Event"); event.initEvent("event", true, true); return event.timeStamp; } function endComposition(view, restarting = false) { if (android && view.domObserver.flushingSoon >= 0) return; view.domObserver.forceFlush(); clearComposition(view); if (restarting || view.docView && view.docView.dirty) { let sel = selectionFromDOM(view), cur = view.state.selection; if (sel && !sel.eq(cur)) view.dispatch(view.state.tr.setSelection(sel)); else if ((view.markCursor || restarting) && !cur.$from.node(cur.$from.sharedDepth(cur.to)).inlineContent) view.dispatch(view.state.tr.deleteSelection()); else view.updateState(view.state); return true; } return false; } function captureCopy(view, dom) { if (!view.dom.parentNode) return; let wrap2 = view.dom.parentNode.appendChild(document.createElement("div")); wrap2.appendChild(dom); wrap2.style.cssText = "position: fixed; left: -10000px; top: 10px"; let sel = getSelection(), range = document.createRange(); range.selectNodeContents(dom); view.dom.blur(); sel.removeAllRanges(); sel.addRange(range); setTimeout(() => { if (wrap2.parentNode) wrap2.parentNode.removeChild(wrap2); view.focus(); }, 50); } const brokenClipboardAPI = ie$1 && ie_version < 15 || ios && webkit_version < 604; handlers.copy = editHandlers.cut = (view, _event) => { let event = _event; let sel = view.state.selection, cut2 = event.type == "cut"; if (sel.empty) return; let data = brokenClipboardAPI ? null : event.clipboardData; let slice2 = sel.content(), { dom, text } = serializeForClipboard(view, slice2); if (data) { event.preventDefault(); data.clearData(); data.setData("text/html", dom.innerHTML); data.setData("text/plain", text); } else { captureCopy(view, dom); } if (cut2) view.dispatch(view.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent", "cut")); }; function sliceSingleNode(slice2) { return slice2.openStart == 0 && slice2.openEnd == 0 && slice2.content.childCount == 1 ? slice2.content.firstChild : null; } function capturePaste(view, event) { if (!view.dom.parentNode) return; let plainText = view.input.shiftKey || view.state.selection.$from.parent.type.spec.code; let target = view.dom.parentNode.appendChild(document.createElement(plainText ? "textarea" : "div")); if (!plainText) target.contentEditable = "true"; target.style.cssText = "position: fixed; left: -10000px; top: 10px"; target.focus(); let plain = view.input.shiftKey && view.input.lastKeyCode != 45; setTimeout(() => { view.focus(); if (target.parentNode) target.parentNode.removeChild(target); if (plainText) doPaste(view, target.value, null, plain, event); else doPaste(view, target.textContent, target.innerHTML, plain, event); }, 50); } function doPaste(view, text, html, preferPlain, event) { let slice2 = parseFromClipboard(view, text, html, preferPlain, view.state.selection.$from); if (view.someProp("handlePaste", (f) => f(view, event, slice2 || Slice.empty))) return true; if (!slice2) return false; let singleNode = sliceSingleNode(slice2); let tr2 = singleNode ? view.state.tr.replaceSelectionWith(singleNode, preferPlain) : view.state.tr.replaceSelection(slice2); view.dispatch(tr2.scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste")); return true; } function getText$1(clipboardData) { let text = clipboardData.getData("text/plain") || clipboardData.getData("Text"); if (text) return text; let uris = clipboardData.getData("text/uri-list"); return uris ? uris.replace(/\r?\n/g, " ") : ""; } editHandlers.paste = (view, _event) => { let event = _event; if (view.composing && !android) return; let data = brokenClipboardAPI ? null : event.clipboardData; let plain = view.input.shiftKey && view.input.lastKeyCode != 45; if (data && doPaste(view, getText$1(data), data.getData("text/html"), plain, event)) event.preventDefault(); else capturePaste(view, event); }; class Dragging { constructor(slice2, move, node) { this.slice = slice2; this.move = move; this.node = node; } } const dragCopyModifier = mac$2 ? "altKey" : "ctrlKey"; function dragMoves(view, event) { let copy2; view.someProp("dragCopies", (test) => { copy2 = copy2 || test(event); }); return copy2 != null ? !copy2 : !event[dragCopyModifier]; } handlers.dragstart = (view, _event) => { let event = _event; let mouseDown = view.input.mouseDown; if (mouseDown) mouseDown.done(); if (!event.dataTransfer) return; let sel = view.state.selection; let pos = sel.empty ? null : view.posAtCoords(eventCoords(event)); let node; if (pos && pos.pos >= sel.from && pos.pos <= (sel instanceof NodeSelection ? sel.to - 1 : sel.to)) ; else if (mouseDown && mouseDown.mightDrag) { node = NodeSelection.create(view.state.doc, mouseDown.mightDrag.pos); } else if (event.target && event.target.nodeType == 1) { let desc = view.docView.nearestDesc(event.target, true); if (desc && desc.node.type.spec.draggable && desc != view.docView) node = NodeSelection.create(view.state.doc, desc.posBefore); } let draggedSlice = (node || view.state.selection).content(); let { dom, text, slice: slice2 } = serializeForClipboard(view, draggedSlice); if (!event.dataTransfer.files.length || !chrome || chrome_version > 120) event.dataTransfer.clearData(); event.dataTransfer.setData(brokenClipboardAPI ? "Text" : "text/html", dom.innerHTML); event.dataTransfer.effectAllowed = "copyMove"; if (!brokenClipboardAPI) event.dataTransfer.setData("text/plain", text); view.dragging = new Dragging(slice2, dragMoves(view, event), node); }; handlers.dragend = (view) => { let dragging = view.dragging; window.setTimeout(() => { if (view.dragging == dragging) view.dragging = null; }, 50); }; editHandlers.dragover = editHandlers.dragenter = (_, e) => e.preventDefault(); editHandlers.drop = (view, event) => { try { handleDrop(view, event, view.dragging); } finally { view.dragging = null; } }; function handleDrop(view, event, dragging) { if (!event.dataTransfer) return; let eventPos = view.posAtCoords(eventCoords(event)); if (!eventPos) return; let $mouse = view.state.doc.resolve(eventPos.pos); let slice2 = dragging && dragging.slice; if (slice2) { view.someProp("transformPasted", (f) => { slice2 = f(slice2, view, false); }); } else { slice2 = parseFromClipboard(view, getText$1(event.dataTransfer), brokenClipboardAPI ? null : event.dataTransfer.getData("text/html"), false, $mouse); } let move = !!(dragging && dragMoves(view, event)); if (view.someProp("handleDrop", (f) => f(view, event, slice2 || Slice.empty, move))) { event.preventDefault(); return; } if (!slice2) return; event.preventDefault(); let insertPos = slice2 ? dropPoint(view.state.doc, $mouse.pos, slice2) : $mouse.pos; if (insertPos == null) insertPos = $mouse.pos; let tr2 = view.state.tr; if (move) { let { node } = dragging; if (node) node.replace(tr2); else tr2.deleteSelection(); } let pos = tr2.mapping.map(insertPos); let isNode2 = slice2.openStart == 0 && slice2.openEnd == 0 && slice2.content.childCount == 1; let beforeInsert = tr2.doc; if (isNode2) tr2.replaceRangeWith(pos, pos, slice2.content.firstChild); else tr2.replaceRange(pos, pos, slice2); if (tr2.doc.eq(beforeInsert)) return; let $pos = tr2.doc.resolve(pos); if (isNode2 && NodeSelection.isSelectable(slice2.content.firstChild) && $pos.nodeAfter && $pos.nodeAfter.sameMarkup(slice2.content.firstChild)) { tr2.setSelection(new NodeSelection($pos)); } else { let end = tr2.mapping.map(insertPos); tr2.mapping.maps[tr2.mapping.maps.length - 1].forEach((_from, _to, _newFrom, newTo) => end = newTo); tr2.setSelection(selectionBetween(view, $pos, tr2.doc.resolve(end))); } view.focus(); view.dispatch(tr2.setMeta("uiEvent", "drop")); } handlers.focus = (view) => { view.input.lastFocus = Date.now(); if (!view.focused) { view.domObserver.stop(); view.dom.classList.add("ProseMirror-focused"); view.domObserver.start(); view.focused = true; setTimeout(() => { if (view.docView && view.hasFocus() && !view.domObserver.currentSelection.eq(view.domSelectionRange())) selectionToDOM(view); }, 20); } }; handlers.blur = (view, _event) => { let event = _event; if (view.focused) { view.domObserver.stop(); view.dom.classList.remove("ProseMirror-focused"); view.domObserver.start(); if (event.relatedTarget && view.dom.contains(event.relatedTarget)) view.domObserver.currentSelection.clear(); view.focused = false; } }; handlers.beforeinput = (view, _event) => { let event = _event; if (chrome && android && event.inputType == "deleteContentBackward") { view.domObserver.flushSoon(); let { domChangeCount } = view.input; setTimeout(() => { if (view.input.domChangeCount != domChangeCount) return; view.dom.blur(); view.focus(); if (view.someProp("handleKeyDown", (f) => f(view, keyEvent(8, "Backspace")))) return; let { $cursor } = view.state.selection; if ($cursor && $cursor.pos > 0) view.dispatch(view.state.tr.delete($cursor.pos - 1, $cursor.pos).scrollIntoView()); }, 50); } }; for (let prop in editHandlers) handlers[prop] = editHandlers[prop]; function compareObjs(a, b) { if (a == b) return true; for (let p in a) if (a[p] !== b[p]) return false; for (let p in b) if (!(p in a)) return false; return true; } class WidgetType { constructor(toDOM, spec) { this.toDOM = toDOM; this.spec = spec || noSpec; this.side = this.spec.side || 0; } map(mapping, span, offset2, oldOffset) { let { pos, deleted } = mapping.mapResult(span.from + oldOffset, this.side < 0 ? -1 : 1); return deleted ? null : new Decoration(pos - offset2, pos - offset2, this); } valid() { return true; } eq(other) { return this == other || other instanceof WidgetType && (this.spec.key && this.spec.key == other.spec.key || this.toDOM == other.toDOM && compareObjs(this.spec, other.spec)); } destroy(node) { if (this.spec.destroy) this.spec.destroy(node); } } class InlineType { constructor(attrs, spec) { this.attrs = attrs; this.spec = spec || noSpec; } map(mapping, span, offset2, oldOffset) { let from2 = mapping.map(span.from + oldOffset, this.spec.inclusiveStart ? -1 : 1) - offset2; let to = mapping.map(span.to + oldOffset, this.spec.inclusiveEnd ? 1 : -1) - offset2; return from2 >= to ? null : new Decoration(from2, to, this); } valid(_, span) { return span.from < span.to; } eq(other) { return this == other || other instanceof InlineType && compareObjs(this.attrs, other.attrs) && compareObjs(this.spec, other.spec); } static is(span) { return span.type instanceof InlineType; } destroy() { } } class NodeType2 { constructor(attrs, spec) { this.attrs = attrs; this.spec = spec || noSpec; } map(mapping, span, offset2, oldOffset) { let from2 = mapping.mapResult(span.from + oldOffset, 1); if (from2.deleted) return null; let to = mapping.mapResult(span.to + oldOffset, -1); if (to.deleted || to.pos <= from2.pos) return null; return new Decoration(from2.pos - offset2, to.pos - offset2, this); } valid(node, span) { let { index, offset: offset2 } = node.content.findIndex(span.from), child; return offset2 == span.from && !(child = node.child(index)).isText && offset2 + child.nodeSize == span.to; } eq(other) { return this == other || other instanceof NodeType2 && compareObjs(this.attrs, other.attrs) && compareObjs(this.spec, other.spec); } destroy() { } } class Decoration { /** @internal */ constructor(from2, to, type) { this.from = from2; this.to = to; this.type = type; } /** @internal */ copy(from2, to) { return new Decoration(from2, to, this.type); } /** @internal */ eq(other, offset2 = 0) { return this.type.eq(other.type) && this.from + offset2 == other.from && this.to + offset2 == other.to; } /** @internal */ map(mapping, offset2, oldOffset) { return this.type.map(mapping, this, offset2, oldOffset); } /** Creates a widget decoration, which is a DOM node that's shown in the document at the given position. It is recommended that you delay rendering the widget by passing a function that will be called when the widget is actually drawn in a view, but you can also directly pass a DOM node. `getPos` can be used to find the widget's current document position. */ static widget(pos, toDOM, spec) { return new Decoration(pos, pos, new WidgetType(toDOM, spec)); } /** Creates an inline decoration, which adds the given attributes to each inline node between `from` and `to`. */ static inline(from2, to, attrs, spec) { return new Decoration(from2, to, new InlineType(attrs, spec)); } /** Creates a node decoration. `from` and `to` should point precisely before and after a node in the document. That node, and only that node, will receive the given attributes. */ static node(from2, to, attrs, spec) { return new Decoration(from2, to, new NodeType2(attrs, spec)); } /** The spec provided when creating this decoration. Can be useful if you've stored extra information in that object. */ get spec() { return this.type.spec; } /** @internal */ get inline() { return this.type instanceof InlineType; } /** @internal */ get widget() { return this.type instanceof WidgetType; } } const none = [], noSpec = {}; class DecorationSet { /** @internal */ constructor(local, children) { this.local = local.length ? local : none; this.children = children.length ? children : none; } /** Create a set of decorations, using the structure of the given document. This will consume (modify) the `decorations` array, so you must make a copy if you want need to preserve that. */ static create(doc2, decorations) { return decorations.length ? buildTree(decorations, doc2, 0, noSpec) : empty; } /** Find all decorations in this set which touch the given range (including decorations that start or end directly at the boundaries) and match the given predicate on their spec. When `start` and `end` are omitted, all decorations in the set are considered. When `predicate` isn't given, all decorations are assumed to match. */ find(start, end, predicate) { let result = []; this.findInner(start == null ? 0 : start, end == null ? 1e9 : end, result, 0, predicate); return result; } findInner(start, end, result, offset2, predicate) { for (let i = 0; i < this.local.length; i++) { let span = this.local[i]; if (span.from <= end && span.to >= start && (!predicate || predicate(span.spec))) result.push(span.copy(span.from + offset2, span.to + offset2)); } for (let i = 0; i < this.children.length; i += 3) { if (this.children[i] < end && this.children[i + 1] > start) { let childOff = this.children[i] + 1; this.children[i + 2].findInner(start - childOff, end - childOff, result, offset2 + childOff, predicate); } } } /** Map the set of decorations in response to a change in the document. */ map(mapping, doc2, options) { if (this == empty || mapping.maps.length == 0) return this; return this.mapInner(mapping, doc2, 0, 0, options || noSpec); } /** @internal */ mapInner(mapping, node, offset2, oldOffset, options) { let newLocal; for (let i = 0; i < this.local.length; i++) { let mapped = this.local[i].map(mapping, offset2, oldOffset); if (mapped && mapped.type.valid(node, mapped)) (newLocal || (newLocal = [])).push(mapped); else if (options.onRemove) options.onRemove(this.local[i].spec); } if (this.children.length) return mapChildren(this.children, newLocal || [], mapping, node, offset2, oldOffset, options); else return newLocal ? new DecorationSet(newLocal.sort(byPos), none) : empty; } /** Add the given array of decorations to the ones in the set, producing a new set. Consumes the `decorations` array. Needs access to the current document to create the appropriate tree structure. */ add(doc2, decorations) { if (!decorations.length) return this; if (this == empty) return DecorationSet.create(doc2, decorations); return this.addInner(doc2, decorations, 0); } addInner(doc2, decorations, offset2) { let children, childIndex = 0; doc2.forEach((childNode, childOffset) => { let baseOffset = childOffset + offset2, found2; if (!(found2 = takeSpansForNode(decorations, childNode, baseOffset))) return; if (!children) children = this.children.slice(); while (childIndex < children.length && children[childIndex] < childOffset) childIndex += 3; if (children[childIndex] == childOffset) children[childIndex + 2] = children[childIndex + 2].addInner(childNode, found2, baseOffset + 1); else children.splice(childIndex, 0, childOffset, childOffset + childNode.nodeSize, buildTree(found2, childNode, baseOffset + 1, noSpec)); childIndex += 3; }); let local = moveSpans(childIndex ? withoutNulls(decorations) : decorations, -offset2); for (let i = 0; i < local.length; i++) if (!local[i].type.valid(doc2, local[i])) local.splice(i--, 1); return new DecorationSet(local.length ? this.local.concat(local).sort(byPos) : this.local, children || this.children); } /** Create a new set that contains the decorations in this set, minus the ones in the given array. */ remove(decorations) { if (decorations.length == 0 || this == empty) return this; return this.removeInner(decorations, 0); } removeInner(decorations, offset2) { let children = this.children, local = this.local; for (let i = 0; i < children.length; i += 3) { let found2; let from2 = children[i] + offset2, to = children[i + 1] + offset2; for (let j = 0, span; j < decorations.length; j++) if (span = decorations[j]) { if (span.from > from2 && span.to < to) { decorations[j] = null; (found2 || (found2 = [])).push(span); } } if (!found2) continue; if (children == this.children) children = this.children.slice(); let removed = children[i + 2].removeInner(found2, from2 + 1); if (removed != empty) { children[i + 2] = removed; } else { children.splice(i, 3); i -= 3; } } if (local.length) { for (let i = 0, span; i < decorations.length; i++) if (span = decorations[i]) { for (let j = 0; j < local.length; j++) if (local[j].eq(span, offset2)) { if (local == this.local) local = this.local.slice(); local.splice(j--, 1); } } } if (children == this.children && local == this.local) return this; return local.length || children.length ? new DecorationSet(local, children) : empty; } forChild(offset2, node) { if (this == empty) return this; if (node.isLeaf) return DecorationSet.empty; let child, local; for (let i = 0; i < this.children.length; i += 3) if (this.children[i] >= offset2) { if (this.children[i] == offset2) child = this.children[i + 2]; break; } let start = offset2 + 1, end = start + node.content.size; for (let i = 0; i < this.local.length; i++) { let dec = this.local[i]; if (dec.from < end && dec.to > start && dec.type instanceof InlineType) { let from2 = Math.max(start, dec.from) - start, to = Math.min(end, dec.to) - start; if (from2 < to) (local || (local = [])).push(dec.copy(from2, to)); } } if (local) { let localSet = new DecorationSet(local.sort(byPos), none); return child ? new DecorationGroup([localSet, child]) : localSet; } return child || empty; } /** @internal */ eq(other) { if (this == other) return true; if (!(other instanceof DecorationSet) || this.local.length != other.local.length || this.children.length != other.children.length) return false; for (let i = 0; i < this.local.length; i++) if (!this.local[i].eq(other.local[i])) return false; for (let i = 0; i < this.children.length; i += 3) if (this.children[i] != other.children[i] || this.children[i + 1] != other.children[i + 1] || !this.children[i + 2].eq(other.children[i + 2])) return false; return true; } /** @internal */ locals(node) { return removeOverlap(this.localsInner(node)); } /** @internal */ localsInner(node) { if (this == empty) return none; if (node.inlineContent || !this.local.some(InlineType.is)) return this.local; let result = []; for (let i = 0; i < this.local.length; i++) { if (!(this.local[i].type instanceof InlineType)) result.push(this.local[i]); } return result; } forEachSet(f) { f(this); } } DecorationSet.empty = new DecorationSet([], []); DecorationSet.removeOverlap = removeOverlap; const empty = DecorationSet.empty; class DecorationGroup { constructor(members) { this.members = members; } map(mapping, doc2) { const mappedDecos = this.members.map((member) => member.map(mapping, doc2, noSpec)); return DecorationGroup.from(mappedDecos); } forChild(offset2, child) { if (child.isLeaf) return DecorationSet.empty; let found2 = []; for (let i = 0; i < this.members.length; i++) { let result = this.members[i].forChild(offset2, child); if (result == empty) continue; if (result instanceof DecorationGroup) found2 = found2.concat(result.members); else found2.push(result); } return DecorationGroup.from(found2); } eq(other) { if (!(other instanceof DecorationGroup) || other.members.length != this.members.length) return false; for (let i = 0; i < this.members.length; i++) if (!this.members[i].eq(other.members[i])) return false; return true; } locals(node) { let result, sorted = true; for (let i = 0; i < this.members.length; i++) { let locals = this.members[i].localsInner(node); if (!locals.length) continue; if (!result) { result = locals; } else { if (sorted) { result = result.slice(); sorted = false; } for (let j = 0; j < locals.length; j++) result.push(locals[j]); } } return result ? removeOverlap(sorted ? result : result.sort(byPos)) : none; } // Create a group for the given array of decoration sets, or return // a single set when possible. static from(members) { switch (members.length) { case 0: return empty; case 1: return members[0]; default: return new DecorationGroup(members.every((m) => m instanceof DecorationSet) ? members : members.reduce((r, m) => r.concat(m instanceof DecorationSet ? m : m.members), [])); } } forEachSet(f) { for (let i = 0; i < this.members.length; i++) this.members[i].forEachSet(f); } } function mapChildren(oldChildren, newLocal, mapping, node, offset2, oldOffset, options) { let children = oldChildren.slice(); for (let i = 0, baseOffset = oldOffset; i < mapping.maps.length; i++) { let moved = 0; mapping.maps[i].forEach((oldStart, oldEnd, newStart, newEnd) => { let dSize = newEnd - newStart - (oldEnd - oldStart); for (let i2 = 0; i2 < children.length; i2 += 3) { let end = children[i2 + 1]; if (end < 0 || oldStart > end + baseOffset - moved) continue; let start = children[i2] + baseOffset - moved; if (oldEnd >= start) { children[i2 + 1] = oldStart <= start ? -2 : -1; } else if (oldStart >= baseOffset && dSize) { children[i2] += dSize; children[i2 + 1] += dSize; } } moved += dSize; }); baseOffset = mapping.maps[i].map(baseOffset, -1); } let mustRebuild = false; for (let i = 0; i < children.length; i += 3) if (children[i + 1] < 0) { if (children[i + 1] == -2) { mustRebuild = true; children[i + 1] = -1; continue; } let from2 = mapping.map(oldChildren[i] + oldOffset), fromLocal = from2 - offset2; if (fromLocal < 0 || fromLocal >= node.content.size) { mustRebuild = true; continue; } let to = mapping.map(oldChildren[i + 1] + oldOffset, -1), toLocal = to - offset2; let { index, offset: childOffset } = node.content.findIndex(fromLocal); let childNode = node.maybeChild(index); if (childNode && childOffset == fromLocal && childOffset + childNode.nodeSize == toLocal) { let mapped = children[i + 2].mapInner(mapping, childNode, from2 + 1, oldChildren[i] + oldOffset + 1, options); if (mapped != empty) { children[i] = fromLocal; children[i + 1] = toLocal; children[i + 2] = mapped; } else { children[i + 1] = -2; mustRebuild = true; } } else { mustRebuild = true; } } if (mustRebuild) { let decorations = mapAndGatherRemainingDecorations(children, oldChildren, newLocal, mapping, offset2, oldOffset, options); let built = buildTree(decorations, node, 0, options); newLocal = built.local; for (let i = 0; i < children.length; i += 3) if (children[i + 1] < 0) { children.splice(i, 3); i -= 3; } for (let i = 0, j = 0; i < built.children.length; i += 3) { let from2 = built.children[i]; while (j < children.length && children[j] < from2) j += 3; children.splice(j, 0, built.children[i], built.children[i + 1], built.children[i + 2]); } } return new DecorationSet(newLocal.sort(byPos), children); } function moveSpans(spans, offset2) { if (!offset2 || !spans.length) return spans; let result = []; for (let i = 0; i < spans.length; i++) { let span = spans[i]; result.push(new Decoration(span.from + offset2, span.to + offset2, span.type)); } return result; } function mapAndGatherRemainingDecorations(children, oldChildren, decorations, mapping, offset2, oldOffset, options) { function gather(set, oldOffset2) { for (let i = 0; i < set.local.length; i++) { let mapped = set.local[i].map(mapping, offset2, oldOffset2); if (mapped) decorations.push(mapped); else if (options.onRemove) options.onRemove(set.local[i].spec); } for (let i = 0; i < set.children.length; i += 3) gather(set.children[i + 2], set.children[i] + oldOffset2 + 1); } for (let i = 0; i < children.length; i += 3) if (children[i + 1] == -1) gather(children[i + 2], oldChildren[i] + oldOffset + 1); return decorations; } function takeSpansForNode(spans, node, offset2) { if (node.isLeaf) return null; let end = offset2 + node.nodeSize, found2 = null; for (let i = 0, span; i < spans.length; i++) { if ((span = spans[i]) && span.from > offset2 && span.to < end) { (found2 || (found2 = [])).push(span); spans[i] = null; } } return found2; } function withoutNulls(array) { let result = []; for (let i = 0; i < array.length; i++) if (array[i] != null) result.push(array[i]); return result; } function buildTree(spans, node, offset2, options) { let children = [], hasNulls = false; node.forEach((childNode, localStart) => { let found2 = takeSpansForNode(spans, childNode, localStart + offset2); if (found2) { hasNulls = true; let subtree = buildTree(found2, childNode, offset2 + localStart + 1, options); if (subtree != empty) children.push(localStart, localStart + childNode.nodeSize, subtree); } }); let locals = moveSpans(hasNulls ? withoutNulls(spans) : spans, -offset2).sort(byPos); for (let i = 0; i < locals.length; i++) if (!locals[i].type.valid(node, locals[i])) { if (options.onRemove) options.onRemove(locals[i].spec); locals.splice(i--, 1); } return locals.length || children.length ? new DecorationSet(locals, children) : empty; } function byPos(a, b) { return a.from - b.from || a.to - b.to; } function removeOverlap(spans) { let working = spans; for (let i = 0; i < working.length - 1; i++) { let span = working[i]; if (span.from != span.to) for (let j = i + 1; j < working.length; j++) { let next = working[j]; if (next.from == span.from) { if (next.to != span.to) { if (working == spans) working = spans.slice(); working[j] = next.copy(next.from, span.to); insertAhead(working, j + 1, next.copy(span.to, next.to)); } continue; } else { if (next.from < span.to) { if (working == spans) working = spans.slice(); working[i] = span.copy(span.from, next.from); insertAhead(working, j, span.copy(next.from, span.to)); } break; } } } return working; } function insertAhead(array, i, deco) { while (i < array.length && byPos(deco, array[i]) > 0) i++; array.splice(i, 0, deco); } function viewDecorations(view) { let found2 = []; view.someProp("decorations", (f) => { let result = f(view.state); if (result && result != empty) found2.push(result); }); if (view.cursorWrapper) found2.push(DecorationSet.create(view.state.doc, [view.cursorWrapper.deco])); return DecorationGroup.from(found2); } const observeOptions = { childList: true, characterData: true, characterDataOldValue: true, attributes: true, attributeOldValue: true, subtree: true }; const useCharData = ie$1 && ie_version <= 11; class SelectionState { constructor() { this.anchorNode = null; this.anchorOffset = 0; this.focusNode = null; this.focusOffset = 0; } set(sel) { this.anchorNode = sel.anchorNode; this.anchorOffset = sel.anchorOffset; this.focusNode = sel.focusNode; this.focusOffset = sel.focusOffset; } clear() { this.anchorNode = this.focusNode = null; } eq(sel) { return sel.anchorNode == this.anchorNode && sel.anchorOffset == this.anchorOffset && sel.focusNode == this.focusNode && sel.focusOffset == this.focusOffset; } } class DOMObserver { constructor(view, handleDOMChange) { this.view = view; this.handleDOMChange = handleDOMChange; this.queue = []; this.flushingSoon = -1; this.observer = null; this.currentSelection = new SelectionState(); this.onCharData = null; this.suppressingSelectionUpdates = false; this.lastChangedTextNode = null; this.observer = window.MutationObserver && new window.MutationObserver((mutations) => { for (let i = 0; i < mutations.length; i++) this.queue.push(mutations[i]); if (ie$1 && ie_version <= 11 && mutations.some((m) => m.type == "childList" && m.removedNodes.length || m.type == "characterData" && m.oldValue.length > m.target.nodeValue.length)) { this.flushSoon(); } else if (safari && view.composing && mutations.some((m) => m.type == "childList" && m.target.nodeName == "TR")) { view.input.badSafariComposition = true; this.flushSoon(); } else { this.flush(); } }); if (useCharData) { this.onCharData = (e) => { this.queue.push({ target: e.target, type: "characterData", oldValue: e.prevValue }); this.flushSoon(); }; } this.onSelectionChange = this.onSelectionChange.bind(this); } flushSoon() { if (this.flushingSoon < 0) this.flushingSoon = window.setTimeout(() => { this.flushingSoon = -1; this.flush(); }, 20); } forceFlush() { if (this.flushingSoon > -1) { window.clearTimeout(this.flushingSoon); this.flushingSoon = -1; this.flush(); } } start() { if (this.observer) { this.observer.takeRecords(); this.observer.observe(this.view.dom, observeOptions); } if (this.onCharData) this.view.dom.addEventListener("DOMCharacterDataModified", this.onCharData); this.connectSelection(); } stop() { if (this.observer) { let take = this.observer.takeRecords(); if (take.length) { for (let i = 0; i < take.length; i++) this.queue.push(take[i]); window.setTimeout(() => this.flush(), 20); } this.observer.disconnect(); } if (this.onCharData) this.view.dom.removeEventListener("DOMCharacterDataModified", this.onCharData); this.disconnectSelection(); } connectSelection() { this.view.dom.ownerDocument.addEventListener("selectionchange", this.onSelectionChange); } disconnectSelection() { this.view.dom.ownerDocument.removeEventListener("selectionchange", this.onSelectionChange); } suppressSelectionUpdates() { this.suppressingSelectionUpdates = true; setTimeout(() => this.suppressingSelectionUpdates = false, 50); } onSelectionChange() { if (!hasFocusAndSelection(this.view)) return; if (this.suppressingSelectionUpdates) return selectionToDOM(this.view); if (ie$1 && ie_version <= 11 && !this.view.state.selection.empty) { let sel = this.view.domSelectionRange(); if (sel.focusNode && isEquivalentPosition(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset)) return this.flushSoon(); } this.flush(); } setCurSelection() { this.currentSelection.set(this.view.domSelectionRange()); } ignoreSelectionChange(sel) { if (!sel.focusNode) return true; let ancestors = /* @__PURE__ */ new Set(), container; for (let scan = sel.focusNode; scan; scan = parentNode(scan)) ancestors.add(scan); for (let scan = sel.anchorNode; scan; scan = parentNode(scan)) if (ancestors.has(scan)) { container = scan; break; } let desc = container && this.view.docView.nearestDesc(container); if (desc && desc.ignoreMutation({ type: "selection", target: container.nodeType == 3 ? container.parentNode : container })) { this.setCurSelection(); return true; } } pendingRecords() { if (this.observer) for (let mut of this.observer.takeRecords()) this.queue.push(mut); return this.queue; } flush() { let { view } = this; if (!view.docView || this.flushingSoon > -1) return; let mutations = this.pendingRecords(); if (mutations.length) this.queue = []; let sel = view.domSelectionRange(); let newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && hasFocusAndSelection(view) && !this.ignoreSelectionChange(sel); let from2 = -1, to = -1, typeOver = false, added = []; if (view.editable) { for (let i = 0; i < mutations.length; i++) { let result = this.registerMutation(mutations[i], added); if (result) { from2 = from2 < 0 ? result.from : Math.min(result.from, from2); to = to < 0 ? result.to : Math.max(result.to, to); if (result.typeOver) typeOver = true; } } } if (added.some((n) => n.nodeName == "BR") && (view.input.lastKeyCode == 8 || view.input.lastKeyCode == 46)) { for (let node of added) if (node.nodeName == "BR" && node.parentNode) { let after = node.nextSibling; while (after && after.nodeType == 1) { if (after.contentEditable == "false") { node.parentNode.removeChild(node); break; } after = after.firstChild; } } } else if (gecko && added.length) { let brs = added.filter((n) => n.nodeName == "BR"); if (brs.length == 2) { let [a, b] = brs; if (a.parentNode && a.parentNode.parentNode == b.parentNode) b.remove(); else a.remove(); } else { let { focusNode } = this.currentSelection; for (let br of brs) { let parent = br.parentNode; if (parent && parent.nodeName == "LI" && (!focusNode || blockParent(view, focusNode) != parent)) br.remove(); } } } let readSel = null; if (from2 < 0 && newSel && view.input.lastFocus > Date.now() - 200 && Math.max(view.input.lastTouch, view.input.lastClick.time) < Date.now() - 300 && selectionCollapsed(sel) && (readSel = selectionFromDOM(view)) && readSel.eq(Selection.near(view.state.doc.resolve(0), 1))) { view.input.lastFocus = 0; selectionToDOM(view); this.currentSelection.set(sel); view.scrollToSelection(); } else if (from2 > -1 || newSel) { if (from2 > -1) { view.docView.markDirty(from2, to); checkCSS(view); } if (view.input.badSafariComposition) { view.input.badSafariComposition = false; fixUpBadSafariComposition(view, added); } this.handleDOMChange(from2, to, typeOver, added); if (view.docView && view.docView.dirty) view.updateState(view.state); else if (!this.currentSelection.eq(sel)) selectionToDOM(view); this.currentSelection.set(sel); } } registerMutation(mut, added) { if (added.indexOf(mut.target) > -1) return null; let desc = this.view.docView.nearestDesc(mut.target); if (mut.type == "attributes" && (desc == this.view.docView || mut.attributeName == "contenteditable" || // Firefox sometimes fires spurious events for null/empty styles mut.attributeName == "style" && !mut.oldValue && !mut.target.getAttribute("style"))) return null; if (!desc || desc.ignoreMutation(mut)) return null; if (mut.type == "childList") { for (let i = 0; i < mut.addedNodes.length; i++) { let node = mut.addedNodes[i]; added.push(node); if (node.nodeType == 3) this.lastChangedTextNode = node; } if (desc.contentDOM && desc.contentDOM != desc.dom && !desc.contentDOM.contains(mut.target)) return { from: desc.posBefore, to: desc.posAfter }; let prev = mut.previousSibling, next = mut.nextSibling; if (ie$1 && ie_version <= 11 && mut.addedNodes.length) { for (let i = 0; i < mut.addedNodes.length; i++) { let { previousSibling, nextSibling } = mut.addedNodes[i]; if (!previousSibling || Array.prototype.indexOf.call(mut.addedNodes, previousSibling) < 0) prev = previousSibling; if (!nextSibling || Array.prototype.indexOf.call(mut.addedNodes, nextSibling) < 0) next = nextSibling; } } let fromOffset = prev && prev.parentNode == mut.target ? domIndex(prev) + 1 : 0; let from2 = desc.localPosFromDOM(mut.target, fromOffset, -1); let toOffset = next && next.parentNode == mut.target ? domIndex(next) : mut.target.childNodes.length; let to = desc.localPosFromDOM(mut.target, toOffset, 1); return { from: from2, to }; } else if (mut.type == "attributes") { return { from: desc.posAtStart - desc.border, to: desc.posAtEnd + desc.border }; } else { this.lastChangedTextNode = mut.target; return { from: desc.posAtStart, to: desc.posAtEnd, // An event was generated for a text change that didn't change // any text. Mark the dom change to fall back to assuming the // selection was typed over with an identical value if it can't // find another change. typeOver: mut.target.nodeValue == mut.oldValue }; } } } let cssChecked = /* @__PURE__ */ new WeakMap(); let cssCheckWarned = false; function checkCSS(view) { if (cssChecked.has(view)) return; cssChecked.set(view, null); if (["normal", "nowrap", "pre-line"].indexOf(getComputedStyle(view.dom).whiteSpace) !== -1) { view.requiresGeckoHackNode = gecko; if (cssCheckWarned) return; console["warn"]("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."); cssCheckWarned = true; } } function rangeToSelectionRange(view, range) { let anchorNode = range.startContainer, anchorOffset = range.startOffset; let focusNode = range.endContainer, focusOffset = range.endOffset; let currentAnchor = view.domAtPos(view.state.selection.anchor); if (isEquivalentPosition(currentAnchor.node, currentAnchor.offset, focusNode, focusOffset)) [anchorNode, anchorOffset, focusNode, focusOffset] = [focusNode, focusOffset, anchorNode, anchorOffset]; return { anchorNode, anchorOffset, focusNode, focusOffset }; } function safariShadowSelectionRange(view, selection) { if (selection.getComposedRanges) { let range = selection.getComposedRanges(view.root)[0]; if (range) return rangeToSelectionRange(view, range); } let found2; function read(event) { event.preventDefault(); event.stopImmediatePropagation(); found2 = event.getTargetRanges()[0]; } view.dom.addEventListener("beforeinput", read, true); document.execCommand("indent"); view.dom.removeEventListener("beforeinput", read, true); return found2 ? rangeToSelectionRange(view, found2) : null; } function blockParent(view, node) { for (let p = node.parentNode; p && p != view.dom; p = p.parentNode) { let desc = view.docView.nearestDesc(p, true); if (desc && desc.node.isBlock) return p; } return null; } function fixUpBadSafariComposition(view, addedNodes) { var _a; let { focusNode, focusOffset } = view.domSelectionRange(); for (let node of addedNodes) { if (((_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.nodeName) == "TR") { let nextCell2 = node.nextSibling; while (nextCell2 && (nextCell2.nodeName != "TD" && nextCell2.nodeName != "TH")) nextCell2 = nextCell2.nextSibling; if (nextCell2) { let parent = nextCell2; for (; ; ) { let first2 = parent.firstChild; if (!first2 || first2.nodeType != 1 || first2.contentEditable == "false" || /^(BR|IMG)$/.test(first2.nodeName)) break; parent = first2; } parent.insertBefore(node, parent.firstChild); if (focusNode == node) view.domSelection().collapse(node, focusOffset); } else { node.parentNode.removeChild(node); } } } } function parseBetween(view, from_, to_) { let { node: parent, fromOffset, toOffset, from: from2, to } = view.docView.parseRange(from_, to_); let domSel = view.domSelectionRange(); let find2; let anchor = domSel.anchorNode; if (anchor && view.dom.contains(anchor.nodeType == 1 ? anchor : anchor.parentNode)) { find2 = [{ node: anchor, offset: domSel.anchorOffset }]; if (!selectionCollapsed(domSel)) find2.push({ node: domSel.focusNode, offset: domSel.focusOffset }); } if (chrome && view.input.lastKeyCode === 8) { for (let off = toOffset; off > fromOffset; off--) { let node = parent.childNodes[off - 1], desc = node.pmViewDesc; if (node.nodeName == "BR" && !desc) { toOffset = off; break; } if (!desc || desc.size) break; } } let startDoc = view.state.doc; let parser = view.someProp("domParser") || DOMParser.fromSchema(view.state.schema); let $from = startDoc.resolve(from2); let sel = null, doc2 = parser.parse(parent, { topNode: $from.parent, topMatch: $from.parent.contentMatchAt($from.index()), topOpen: true, from: fromOffset, to: toOffset, preserveWhitespace: $from.parent.type.whitespace == "pre" ? "full" : true, findPositions: find2, ruleFromNode, context: $from }); if (find2 && find2[0].pos != null) { let anchor2 = find2[0].pos, head = find2[1] && find2[1].pos; if (head == null) head = anchor2; sel = { anchor: anchor2 + from2, head: head + from2 }; } return { doc: doc2, sel, from: from2, to }; } function ruleFromNode(dom) { let desc = dom.pmViewDesc; if (desc) { return desc.parseRule(); } else if (dom.nodeName == "BR" && dom.parentNode) { if (safari && /^(ul|ol)$/i.test(dom.parentNode.nodeName)) { let skip = document.createElement("div"); skip.appendChild(document.createElement("li")); return { skip }; } else if (dom.parentNode.lastChild == dom || safari && /^(tr|table)$/i.test(dom.parentNode.nodeName)) { return { ignore: true }; } } else if (dom.nodeName == "IMG" && dom.getAttribute("mark-placeholder")) { return { ignore: true }; } return null; } const isInline = /^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i; function readDOMChange(view, from2, to, typeOver, addedNodes) { let compositionID = view.input.compositionPendingChanges || (view.composing ? view.input.compositionID : 0); view.input.compositionPendingChanges = 0; if (from2 < 0) { let origin = view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null; let newSel = selectionFromDOM(view, origin); if (newSel && !view.state.selection.eq(newSel)) { if (chrome && android && view.input.lastKeyCode === 13 && Date.now() - 100 < view.input.lastKeyCodeTime && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) return; let tr2 = view.state.tr.setSelection(newSel); if (origin == "pointer") tr2.setMeta("pointer", true); else if (origin == "key") tr2.scrollIntoView(); if (compositionID) tr2.setMeta("composition", compositionID); view.dispatch(tr2); } return; } let $before = view.state.doc.resolve(from2); let shared = $before.sharedDepth(to); from2 = $before.before(shared + 1); to = view.state.doc.resolve(to).after(shared + 1); let sel = view.state.selection; let parse = parseBetween(view, from2, to); let doc2 = view.state.doc, compare = doc2.slice(parse.from, parse.to); let preferredPos, preferredSide; if (view.input.lastKeyCode === 8 && Date.now() - 100 < view.input.lastKeyCodeTime) { preferredPos = view.state.selection.to; preferredSide = "end"; } else { preferredPos = view.state.selection.from; preferredSide = "start"; } view.input.lastKeyCode = null; let change = findDiff(compare.content, parse.doc.content, parse.from, preferredPos, preferredSide); if (change) view.input.domChangeCount++; if ((ios && view.input.lastIOSEnter > Date.now() - 225 || android) && addedNodes.some((n) => n.nodeType == 1 && !isInline.test(n.nodeName)) && (!change || change.endA >= change.endB) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) { view.input.lastIOSEnter = 0; return; } if (!change) { if (typeOver && sel instanceof TextSelection && !sel.empty && sel.$head.sameParent(sel.$anchor) && !view.composing && !(parse.sel && parse.sel.anchor != parse.sel.head)) { change = { start: sel.from, endA: sel.to, endB: sel.to }; } else { if (parse.sel) { let sel2 = resolveSelection(view, view.state.doc, parse.sel); if (sel2 && !sel2.eq(view.state.selection)) { let tr2 = view.state.tr.setSelection(sel2); if (compositionID) tr2.setMeta("composition", compositionID); view.dispatch(tr2); } } return; } } if (view.state.selection.from < view.state.selection.to && change.start == change.endB && view.state.selection instanceof TextSelection) { if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2 && view.state.selection.from >= parse.from) { change.start = view.state.selection.from; } else if (change.endA < view.state.selection.to && change.endA >= view.state.selection.to - 2 && view.state.selection.to <= parse.to) { change.endB += view.state.selection.to - change.endA; change.endA = view.state.selection.to; } } if (ie$1 && ie_version <= 11 && change.endB == change.start + 1 && change.endA == change.start && change.start > parse.from && parse.doc.textBetween(change.start - parse.from - 1, change.start - parse.from + 1) == "  ") { change.start--; change.endA--; change.endB--; } let $from = parse.doc.resolveNoCache(change.start - parse.from); let $to = parse.doc.resolveNoCache(change.endB - parse.from); let $fromA = doc2.resolve(change.start); let inlineChange = $from.sameParent($to) && $from.parent.inlineContent && $fromA.end() >= change.endA; if ((ios && view.input.lastIOSEnter > Date.now() - 225 && (!inlineChange || addedNodes.some((n) => n.nodeName == "DIV" || n.nodeName == "P")) || !inlineChange && $from.pos < parse.doc.content.size && (!$from.sameParent($to) || !$from.parent.inlineContent) && $from.pos < $to.pos && !/\S/.test(parse.doc.textBetween($from.pos, $to.pos, "", ""))) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(13, "Enter")))) { view.input.lastIOSEnter = 0; return; } if (view.state.selection.anchor > change.start && looksLikeBackspace(doc2, change.start, change.endA, $from, $to) && view.someProp("handleKeyDown", (f) => f(view, keyEvent(8, "Backspace")))) { if (android && chrome) view.domObserver.suppressSelectionUpdates(); return; } if (chrome && change.endB == change.start) view.input.lastChromeDelete = Date.now(); if (android && !inlineChange && $from.start() != $to.start() && $to.parentOffset == 0 && $from.depth == $to.depth && parse.sel && parse.sel.anchor == parse.sel.head && parse.sel.head == change.endA) { change.endB -= 2; $to = parse.doc.resolveNoCache(change.endB - parse.from); setTimeout(() => { view.someProp("handleKeyDown", function(f) { return f(view, keyEvent(13, "Enter")); }); }, 20); } let chFrom = change.start, chTo = change.endA; let mkTr = (base2) => { let tr2 = base2 || view.state.tr.replace(chFrom, chTo, parse.doc.slice(change.start - parse.from, change.endB - parse.from)); if (parse.sel) { let sel2 = resolveSelection(view, tr2.doc, parse.sel); if (sel2 && !(chrome && view.composing && sel2.empty && (change.start != change.endB || view.input.lastChromeDelete < Date.now() - 100) && (sel2.head == chFrom || sel2.head == tr2.mapping.map(chTo) - 1) || ie$1 && sel2.empty && sel2.head == chFrom)) tr2.setSelection(sel2); } if (compositionID) tr2.setMeta("composition", compositionID); return tr2.scrollIntoView(); }; let markChange; if (inlineChange) { if ($from.pos == $to.pos) { if (ie$1 && ie_version <= 11 && $from.parentOffset == 0) { view.domObserver.suppressSelectionUpdates(); setTimeout(() => selectionToDOM(view), 20); } let tr2 = mkTr(view.state.tr.delete(chFrom, chTo)); let marks = doc2.resolve(change.start).marksAcross(doc2.resolve(change.endA)); if (marks) tr2.ensureMarks(marks); view.dispatch(tr2); } else if ( // Adding or removing a mark change.endA == change.endB && (markChange = isMarkChange($from.parent.content.cut($from.parentOffset, $to.parentOffset), $fromA.parent.content.cut($fromA.parentOffset, change.endA - $fromA.start()))) ) { let tr2 = mkTr(view.state.tr); if (markChange.type == "add") tr2.addMark(chFrom, chTo, markChange.mark); else tr2.removeMark(chFrom, chTo, markChange.mark); view.dispatch(tr2); } else if ($from.parent.child($from.index()).isText && $from.index() == $to.index() - ($to.textOffset ? 0 : 1)) { let text = $from.parent.textBetween($from.parentOffset, $to.parentOffset); let deflt = () => mkTr(view.state.tr.insertText(text, chFrom, chTo)); if (!view.someProp("handleTextInput", (f) => f(view, chFrom, chTo, text, deflt))) view.dispatch(deflt()); } else { view.dispatch(mkTr()); } } else { view.dispatch(mkTr()); } } function resolveSelection(view, doc2, parsedSel) { if (Math.max(parsedSel.anchor, parsedSel.head) > doc2.content.size) return null; return selectionBetween(view, doc2.resolve(parsedSel.anchor), doc2.resolve(parsedSel.head)); } function isMarkChange(cur, prev) { let curMarks = cur.firstChild.marks, prevMarks = prev.firstChild.marks; let added = curMarks, removed = prevMarks, type, mark, update; for (let i = 0; i < prevMarks.length; i++) added = prevMarks[i].removeFromSet(added); for (let i = 0; i < curMarks.length; i++) removed = curMarks[i].removeFromSet(removed); if (added.length == 1 && removed.length == 0) { mark = added[0]; type = "add"; update = (node) => node.mark(mark.addToSet(node.marks)); } else if (added.length == 0 && removed.length == 1) { mark = removed[0]; type = "remove"; update = (node) => node.mark(mark.removeFromSet(node.marks)); } else { return null; } let updated = []; for (let i = 0; i < prev.childCount; i++) updated.push(update(prev.child(i))); if (Fragment.from(updated).eq(cur)) return { mark, type }; } function looksLikeBackspace(old, start, end, $newStart, $newEnd) { if ( // The content must have shrunk end - start <= $newEnd.pos - $newStart.pos || // newEnd must point directly at or after the end of the block that newStart points into skipClosingAndOpening($newStart, true, false) < $newEnd.pos ) return false; let $start = old.resolve(start); if (!$newStart.parent.isTextblock) { let after = $start.nodeAfter; return after != null && end == start + after.nodeSize; } if ($start.parentOffset < $start.parent.content.size || !$start.parent.isTextblock) return false; let $next = old.resolve(skipClosingAndOpening($start, true, true)); if (!$next.parent.isTextblock || $next.pos > end || skipClosingAndOpening($next, true, false) < end) return false; return $newStart.parent.content.cut($newStart.parentOffset).eq($next.parent.content); } function skipClosingAndOpening($pos, fromEnd, mayOpen) { let depth = $pos.depth, end = fromEnd ? $pos.end() : $pos.pos; while (depth > 0 && (fromEnd || $pos.indexAfter(depth) == $pos.node(depth).childCount)) { depth--; end++; fromEnd = false; } if (mayOpen) { let next = $pos.node(depth).maybeChild($pos.indexAfter(depth)); while (next && !next.isLeaf) { next = next.firstChild; end++; } } return end; } function findDiff(a, b, pos, preferredPos, preferredSide) { let start = a.findDiffStart(b, pos); if (start == null) return null; let { a: endA, b: endB } = a.findDiffEnd(b, pos + a.size, pos + b.size); if (preferredSide == "end") { let adjust = Math.max(0, start - Math.min(endA, endB)); preferredPos -= endA + adjust - start; } if (endA < start && a.size < b.size) { let move = preferredPos <= start && preferredPos >= endA ? start - preferredPos : 0; start -= move; if (start && start < b.size && isSurrogatePair(b.textBetween(start - 1, start + 1))) start += move ? 1 : -1; endB = start + (endB - endA); endA = start; } else if (endB < start) { let move = preferredPos <= start && preferredPos >= endB ? start - preferredPos : 0; start -= move; if (start && start < a.size && isSurrogatePair(a.textBetween(start - 1, start + 1))) start += move ? 1 : -1; endA = start + (endA - endB); endB = start; } return { start, endA, endB }; } function isSurrogatePair(str) { if (str.length != 2) return false; let a = str.charCodeAt(0), b = str.charCodeAt(1); return a >= 56320 && a <= 57343 && b >= 55296 && b <= 56319; } class EditorView { /** Create a view. `place` may be a DOM node that the editor should be appended to, a function that will place it into the document, or an object whose `mount` property holds the node to use as the document container. If it is `null`, the editor will not be added to the document. */ constructor(place, props) { this._root = null; this.focused = false; this.trackWrites = null; this.mounted = false; this.markCursor = null; this.cursorWrapper = null; this.lastSelectedViewDesc = void 0; this.input = new InputState(); this.prevDirectPlugins = []; this.pluginViews = []; this.requiresGeckoHackNode = false; this.dragging = null; this._props = props; this.state = props.state; this.directPlugins = props.plugins || []; this.directPlugins.forEach(checkStateComponent); this.dispatch = this.dispatch.bind(this); this.dom = place && place.mount || document.createElement("div"); if (place) { if (place.appendChild) place.appendChild(this.dom); else if (typeof place == "function") place(this.dom); else if (place.mount) this.mounted = true; } this.editable = getEditable(this); updateCursorWrapper(this); this.nodeViews = buildNodeViews(this); this.docView = docViewDesc(this.state.doc, computeDocDeco(this), viewDecorations(this), this.dom, this); this.domObserver = new DOMObserver(this, (from2, to, typeOver, added) => readDOMChange(this, from2, to, typeOver, added)); this.domObserver.start(); initInput(this); this.updatePluginViews(); } /** Holds `true` when a [composition](https://w3c.github.io/uievents/#events-compositionevents) is active. */ get composing() { return this.input.composing; } /** The view's current [props](https://prosemirror.net/docs/ref/#view.EditorProps). */ get props() { if (this._props.state != this.state) { let prev = this._props; this._props = {}; for (let name in prev) this._props[name] = prev[name]; this._props.state = this.state; } return this._props; } /** Update the view's props. Will immediately cause an update to the DOM. */ update(props) { if (props.handleDOMEvents != this._props.handleDOMEvents) ensureListeners(this); let prevProps = this._props; this._props = props; if (props.plugins) { props.plugins.forEach(checkStateComponent); this.directPlugins = props.plugins; } this.updateStateInner(props.state, prevProps); } /** Update the view by updating existing props object with the object given as argument. Equivalent to `view.update(Object.assign({}, view.props, props))`. */ setProps(props) { let updated = {}; for (let name in this._props) updated[name] = this._props[name]; updated.state = this.state; for (let name in props) updated[name] = props[name]; this.update(updated); } /** Update the editor's `state` prop, without touching any of the other props. */ updateState(state) { this.updateStateInner(state, this._props); } updateStateInner(state, prevProps) { var _a; let prev = this.state, redraw = false, updateSel = false; if (state.storedMarks && this.composing) { clearComposition(this); updateSel = true; } this.state = state; let pluginsChanged = prev.plugins != state.plugins || this._props.plugins != prevProps.plugins; if (pluginsChanged || this._props.plugins != prevProps.plugins || this._props.nodeViews != prevProps.nodeViews) { let nodeViews = buildNodeViews(this); if (changedNodeViews(nodeViews, this.nodeViews)) { this.nodeViews = nodeViews; redraw = true; } } if (pluginsChanged || prevProps.handleDOMEvents != this._props.handleDOMEvents) { ensureListeners(this); } this.editable = getEditable(this); updateCursorWrapper(this); let innerDeco = viewDecorations(this), outerDeco = computeDocDeco(this); let scroll = prev.plugins != state.plugins && !prev.doc.eq(state.doc) ? "reset" : state.scrollToSelection > prev.scrollToSelection ? "to selection" : "preserve"; let updateDoc = redraw || !this.docView.matchesNode(state.doc, outerDeco, innerDeco); if (updateDoc || !state.selection.eq(prev.selection)) updateSel = true; let oldScrollPos = scroll == "preserve" && updateSel && this.dom.style.overflowAnchor == null && storeScrollPos(this); if (updateSel) { this.domObserver.stop(); let forceSelUpdate = updateDoc && (ie$1 || chrome) && !this.composing && !prev.selection.empty && !state.selection.empty && selectionContextChanged(prev.selection, state.selection); if (updateDoc) { let chromeKludge = chrome ? this.trackWrites = this.domSelectionRange().focusNode : null; if (this.composing) this.input.compositionNode = findCompositionNode(this); if (redraw || !this.docView.update(state.doc, outerDeco, innerDeco, this)) { this.docView.updateOuterDeco(outerDeco); this.docView.destroy(); this.docView = docViewDesc(state.doc, outerDeco, innerDeco, this.dom, this); } if (chromeKludge && (!this.trackWrites || !this.dom.contains(this.trackWrites))) forceSelUpdate = true; } if (forceSelUpdate || !(this.input.mouseDown && this.domObserver.currentSelection.eq(this.domSelectionRange()) && anchorInRightPlace(this))) { selectionToDOM(this, forceSelUpdate); } else { syncNodeSelection(this, state.selection); this.domObserver.setCurSelection(); } this.domObserver.start(); } this.updatePluginViews(prev); if (((_a = this.dragging) === null || _a === void 0 ? void 0 : _a.node) && !prev.doc.eq(state.doc)) this.updateDraggedNode(this.dragging, prev); if (scroll == "reset") { this.dom.scrollTop = 0; } else if (scroll == "to selection") { this.scrollToSelection(); } else if (oldScrollPos) { resetScrollPos(oldScrollPos); } } /** @internal */ scrollToSelection() { let startDOM = this.domSelectionRange().focusNode; if (!startDOM || !this.dom.contains(startDOM.nodeType == 1 ? startDOM : startDOM.parentNode)) ; else if (this.someProp("handleScrollToSelection", (f) => f(this))) ; else if (this.state.selection instanceof NodeSelection) { let target = this.docView.domAfterPos(this.state.selection.from); if (target.nodeType == 1) scrollRectIntoView(this, target.getBoundingClientRect(), startDOM); } else { scrollRectIntoView(this, this.coordsAtPos(this.state.selection.head, 1), startDOM); } } destroyPluginViews() { let view; while (view = this.pluginViews.pop()) if (view.destroy) view.destroy(); } updatePluginViews(prevState) { if (!prevState || prevState.plugins != this.state.plugins || this.directPlugins != this.prevDirectPlugins) { this.prevDirectPlugins = this.directPlugins; this.destroyPluginViews(); for (let i = 0; i < this.directPlugins.length; i++) { let plugin = this.directPlugins[i]; if (plugin.spec.view) this.pluginViews.push(plugin.spec.view(this)); } for (let i = 0; i < this.state.plugins.length; i++) { let plugin = this.state.plugins[i]; if (plugin.spec.view) this.pluginViews.push(plugin.spec.view(this)); } } else { for (let i = 0; i < this.pluginViews.length; i++) { let pluginView = this.pluginViews[i]; if (pluginView.update) pluginView.update(this, prevState); } } } updateDraggedNode(dragging, prev) { let sel = dragging.node, found2 = -1; if (sel.from < this.state.doc.content.size && this.state.doc.nodeAt(sel.from) == sel.node) { found2 = sel.from; } else { let movedPos = sel.from + (this.state.doc.content.size - prev.doc.content.size); let moved = movedPos > 0 && movedPos < this.state.doc.content.size && this.state.doc.nodeAt(movedPos); if (moved == sel.node) found2 = movedPos; } this.dragging = new Dragging(dragging.slice, dragging.move, found2 < 0 ? void 0 : NodeSelection.create(this.state.doc, found2)); } someProp(propName, f) { let prop = this._props && this._props[propName], value; if (prop != null && (value = f ? f(prop) : prop)) return value; for (let i = 0; i < this.directPlugins.length; i++) { let prop2 = this.directPlugins[i].props[propName]; if (prop2 != null && (value = f ? f(prop2) : prop2)) return value; } let plugins = this.state.plugins; if (plugins) for (let i = 0; i < plugins.length; i++) { let prop2 = plugins[i].props[propName]; if (prop2 != null && (value = f ? f(prop2) : prop2)) return value; } } /** Query whether the view has focus. */ hasFocus() { if (ie$1) { let node = this.root.activeElement; if (node == this.dom) return true; if (!node || !this.dom.contains(node)) return false; while (node && this.dom != node && this.dom.contains(node)) { if (node.contentEditable == "false") return false; node = node.parentElement; } return true; } return this.root.activeElement == this.dom; } /** Focus the editor. */ focus() { this.domObserver.stop(); if (this.editable) focusPreventScroll(this.dom); selectionToDOM(this); this.domObserver.start(); } /** Get the document root in which the editor exists. This will usually be the top-level `document`, but might be a [shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM) root if the editor is inside one. */ get root() { let cached = this._root; if (cached == null) for (let search = this.dom.parentNode; search; search = search.parentNode) { if (search.nodeType == 9 || search.nodeType == 11 && search.host) { if (!search.getSelection) Object.getPrototypeOf(search).getSelection = () => search.ownerDocument.getSelection(); return this._root = search; } } return cached || document; } /** When an existing editor view is moved to a new document or shadow tree, call this to make it recompute its root. */ updateRoot() { this._root = null; } /** Given a pair of viewport coordinates, return the document position that corresponds to them. May return null if the given coordinates aren't inside of the editor. When an object is returned, its `pos` property is the position nearest to the coordinates, and its `inside` property holds the position of the inner node that the position falls inside of, or -1 if it is at the top level, not in any node. */ posAtCoords(coords) { return posAtCoords(this, coords); } /** Returns the viewport rectangle at a given document position. `left` and `right` will be the same number, as this returns a flat cursor-ish rectangle. If the position is between two things that aren't directly adjacent, `side` determines which element is used. When < 0, the element before the position is used, otherwise the element after. */ coordsAtPos(pos, side = 1) { return coordsAtPos(this, pos, side); } /** Find the DOM position that corresponds to the given document position. When `side` is negative, find the position as close as possible to the content before the position. When positive, prefer positions close to the content after the position. When zero, prefer as shallow a position as possible. Note that you should **not** mutate the editor's internal DOM, only inspect it (and even that is usually not necessary). */ domAtPos(pos, side = 0) { return this.docView.domFromPos(pos, side); } /** Find the DOM node that represents the document node after the given position. May return `null` when the position doesn't point in front of a node or if the node is inside an opaque node view. This is intended to be able to call things like `getBoundingClientRect` on that DOM node. Do **not** mutate the editor DOM directly, or add styling this way, since that will be immediately overriden by the editor as it redraws the node. */ nodeDOM(pos) { let desc = this.docView.descAt(pos); return desc ? desc.nodeDOM : null; } /** Find the document position that corresponds to a given DOM position. (Whenever possible, it is preferable to inspect the document structure directly, rather than poking around in the DOM, but sometimes—for example when interpreting an event target—you don't have a choice.) The `bias` parameter can be used to influence which side of a DOM node to use when the position is inside a leaf node. */ posAtDOM(node, offset2, bias = -1) { let pos = this.docView.posFromDOM(node, offset2, bias); if (pos == null) throw new RangeError("DOM position not inside the editor"); return pos; } /** Find out whether the selection is at the end of a textblock when moving in a given direction. When, for example, given `"left"`, it will return true if moving left from the current cursor position would leave that position's parent textblock. Will apply to the view's current state by default, but it is possible to pass a different state. */ endOfTextblock(dir, state) { return endOfTextblock(this, state || this.state, dir); } /** Run the editor's paste logic with the given HTML string. The `event`, if given, will be passed to the [`handlePaste`](https://prosemirror.net/docs/ref/#view.EditorProps.handlePaste) hook. */ pasteHTML(html, event) { return doPaste(this, "", html, false, event || new ClipboardEvent("paste")); } /** Run the editor's paste logic with the given plain-text input. */ pasteText(text, event) { return doPaste(this, text, null, true, event || new ClipboardEvent("paste")); } /** Serialize the given slice as it would be if it was copied from this editor. Returns a DOM element that contains a representation of the slice as its children, a textual representation, and the transformed slice (which can be different from the given input due to hooks like [`transformCopied`](https://prosemirror.net/docs/ref/#view.EditorProps.transformCopied)). */ serializeForClipboard(slice2) { return serializeForClipboard(this, slice2); } /** Removes the editor from the DOM and destroys all [node views](https://prosemirror.net/docs/ref/#view.NodeView). */ destroy() { if (!this.docView) return; destroyInput(this); this.destroyPluginViews(); if (this.mounted) { this.docView.update(this.state.doc, [], viewDecorations(this), this); this.dom.textContent = ""; } else if (this.dom.parentNode) { this.dom.parentNode.removeChild(this.dom); } this.docView.destroy(); this.docView = null; clearReusedRange(); } /** This is true when the view has been [destroyed](https://prosemirror.net/docs/ref/#view.EditorView.destroy) (and thus should not be used anymore). */ get isDestroyed() { return this.docView == null; } /** Used for testing. */ dispatchEvent(event) { return dispatchEvent(this, event); } /** @internal */ domSelectionRange() { let sel = this.domSelection(); if (!sel) return { focusNode: null, focusOffset: 0, anchorNode: null, anchorOffset: 0 }; return safari && this.root.nodeType === 11 && deepActiveElement(this.dom.ownerDocument) == this.dom && safariShadowSelectionRange(this, sel) || sel; } /** @internal */ domSelection() { return this.root.getSelection(); } } EditorView.prototype.dispatch = function(tr2) { let dispatchTransaction = this._props.dispatchTransaction; if (dispatchTransaction) dispatchTransaction.call(this, tr2); else this.updateState(this.state.apply(tr2)); }; function computeDocDeco(view) { let attrs = /* @__PURE__ */ Object.create(null); attrs.class = "ProseMirror"; attrs.contenteditable = String(view.editable); view.someProp("attributes", (value) => { if (typeof value == "function") value = value(view.state); if (value) for (let attr in value) { if (attr == "class") attrs.class += " " + value[attr]; else if (attr == "style") attrs.style = (attrs.style ? attrs.style + ";" : "") + value[attr]; else if (!attrs[attr] && attr != "contenteditable" && attr != "nodeName") attrs[attr] = String(value[attr]); } }); if (!attrs.translate) attrs.translate = "no"; return [Decoration.node(0, view.state.doc.content.size, attrs)]; } function updateCursorWrapper(view) { if (view.markCursor) { let dom = document.createElement("img"); dom.className = "ProseMirror-separator"; dom.setAttribute("mark-placeholder", "true"); dom.setAttribute("alt", ""); view.cursorWrapper = { dom, deco: Decoration.widget(view.state.selection.from, dom, { raw: true, marks: view.markCursor }) }; } else { view.cursorWrapper = null; } } function getEditable(view) { return !view.someProp("editable", (value) => value(view.state) === false); } function selectionContextChanged(sel1, sel2) { let depth = Math.min(sel1.$anchor.sharedDepth(sel1.head), sel2.$anchor.sharedDepth(sel2.head)); return sel1.$anchor.start(depth) != sel2.$anchor.start(depth); } function buildNodeViews(view) { let result = /* @__PURE__ */ Object.create(null); function add(obj) { for (let prop in obj) if (!Object.prototype.hasOwnProperty.call(result, prop)) result[prop] = obj[prop]; } view.someProp("nodeViews", add); view.someProp("markViews", add); return result; } function changedNodeViews(a, b) { let nA = 0, nB = 0; for (let prop in a) { if (a[prop] != b[prop]) return true; nA++; } for (let _ in b) nB++; return nA != nB; } function checkStateComponent(plugin) { if (plugin.spec.state || plugin.spec.filterTransaction || plugin.spec.appendTransaction) throw new RangeError("Plugins passed directly to the view must not have a state component"); } var base = { 8: "Backspace", 9: "Tab", 10: "Enter", 12: "NumLock", 13: "Enter", 16: "Shift", 17: "Control", 18: "Alt", 20: "CapsLock", 27: "Escape", 32: " ", 33: "PageUp", 34: "PageDown", 35: "End", 36: "Home", 37: "ArrowLeft", 38: "ArrowUp", 39: "ArrowRight", 40: "ArrowDown", 44: "PrintScreen", 45: "Insert", 46: "Delete", 59: ";", 61: "=", 91: "Meta", 92: "Meta", 106: "*", 107: "+", 108: ",", 109: "-", 110: ".", 111: "/", 144: "NumLock", 145: "ScrollLock", 160: "Shift", 161: "Shift", 162: "Control", 163: "Control", 164: "Alt", 165: "Alt", 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", 221: "]", 222: "'" }; var shift$2 = { 48: ")", 49: "!", 50: "@", 51: "#", 52: "$", 53: "%", 54: "^", 55: "&", 56: "*", 57: "(", 59: ":", 61: "+", 173: "_", 186: ":", 187: "+", 188: "<", 189: "_", 190: ">", 191: "?", 192: "~", 219: "{", 220: "|", 221: "}", 222: '"' }; var mac$1 = typeof navigator != "undefined" && /Mac/.test(navigator.platform); var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent); for (var i = 0; i < 10; i++) base[48 + i] = base[96 + i] = String(i); for (var i = 1; i <= 24; i++) base[i + 111] = "F" + i; for (var i = 65; i <= 90; i++) { base[i] = String.fromCharCode(i + 32); shift$2[i] = String.fromCharCode(i); } for (var code in base) if (!shift$2.hasOwnProperty(code)) shift$2[code] = base[code]; function keyName(event) { var ignoreKey = mac$1 && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || ie && event.shiftKey && event.key && event.key.length == 1 || event.key == "Unidentified"; var name = !ignoreKey && event.key || (event.shiftKey ? shift$2 : base)[event.keyCode] || event.key || "Unidentified"; if (name == "Esc") name = "Escape"; if (name == "Del") name = "Delete"; if (name == "Left") name = "ArrowLeft"; if (name == "Up") name = "ArrowUp"; if (name == "Right") name = "ArrowRight"; if (name == "Down") name = "ArrowDown"; return name; } const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform); const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform); function normalizeKeyName$1(name) { let parts = name.split(/-(?!$)/), result = parts[parts.length - 1]; if (result == "Space") result = " "; let alt, ctrl, shift2, meta; for (let i = 0; i < parts.length - 1; i++) { let mod = parts[i]; if (/^(cmd|meta|m)$/i.test(mod)) meta = true; else if (/^a(lt)?$/i.test(mod)) alt = true; else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true; else if (/^s(hift)?$/i.test(mod)) shift2 = true; else if (/^mod$/i.test(mod)) { if (mac) meta = true; else ctrl = true; } else throw new Error("Unrecognized modifier name: " + mod); } if (alt) result = "Alt-" + result; if (ctrl) result = "Ctrl-" + result; if (meta) result = "Meta-" + result; if (shift2) result = "Shift-" + result; return result; } function normalize(map2) { let copy2 = /* @__PURE__ */ Object.create(null); for (let prop in map2) copy2[normalizeKeyName$1(prop)] = map2[prop]; return copy2; } function modifiers(name, event, shift2 = true) { if (event.altKey) name = "Alt-" + name; if (event.ctrlKey) name = "Ctrl-" + name; if (event.metaKey) name = "Meta-" + name; if (shift2 && event.shiftKey) name = "Shift-" + name; return name; } function keymap(bindings) { return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } }); } function keydownHandler(bindings) { let map2 = normalize(bindings); return function(view, event) { let name = keyName(event), baseName, direct = map2[modifiers(name, event)]; if (direct && direct(view.state, view.dispatch, view)) return true; if (name.length == 1 && name != " ") { if (event.shiftKey) { let noShift = map2[modifiers(name, event, false)]; if (noShift && noShift(view.state, view.dispatch, view)) return true; } if ((event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows !(windows && event.ctrlKey && event.altKey) && (baseName = base[event.keyCode]) && baseName != name) { let fromCode = map2[modifiers(baseName, event)]; if (fromCode && fromCode(view.state, view.dispatch, view)) return true; } } return false; }; } var __defProp$1 = Object.defineProperty; var __export$1 = (target, all) => { for (var name in all) __defProp$1(target, name, { get: all[name], enumerable: true }); }; function createChainableState(config) { const { state, transaction } = config; let { selection } = transaction; let { doc: doc2 } = transaction; let { storedMarks } = transaction; return { ...state, apply: state.apply.bind(state), applyTransaction: state.applyTransaction.bind(state), plugins: state.plugins, schema: state.schema, reconfigure: state.reconfigure.bind(state), toJSON: state.toJSON.bind(state), get storedMarks() { return storedMarks; }, get selection() { return selection; }, get doc() { return doc2; }, get tr() { selection = transaction.selection; doc2 = transaction.doc; storedMarks = transaction.storedMarks; return transaction; } }; } var CommandManager = class { constructor(props) { this.editor = props.editor; this.rawCommands = this.editor.extensionManager.commands; this.customState = props.state; } get hasCustomState() { return !!this.customState; } get state() { return this.customState || this.editor.state; } get commands() { const { rawCommands, editor, state } = this; const { view } = editor; const { tr: tr2 } = state; const props = this.buildProps(tr2); return Object.fromEntries( Object.entries(rawCommands).map(([name, command2]) => { const method = (...args) => { const callback = command2(...args)(props); if (!tr2.getMeta("preventDispatch") && !this.hasCustomState) { view.dispatch(tr2); } return callback; }; return [name, method]; }) ); } get chain() { return () => this.createChain(); } get can() { return () => this.createCan(); } createChain(startTr, shouldDispatch = true) { const { rawCommands, editor, state } = this; const { view } = editor; const callbacks = []; const hasStartTransaction = !!startTr; const tr2 = startTr || state.tr; const run3 = () => { if (!hasStartTransaction && shouldDispatch && !tr2.getMeta("preventDispatch") && !this.hasCustomState) { view.dispatch(tr2); } return callbacks.every((callback) => callback === true); }; const chain = { ...Object.fromEntries( Object.entries(rawCommands).map(([name, command2]) => { const chainedCommand = (...args) => { const props = this.buildProps(tr2, shouldDispatch); const callback = command2(...args)(props); callbacks.push(callback); return chain; }; return [name, chainedCommand]; }) ), run: run3 }; return chain; } createCan(startTr) { const { rawCommands, state } = this; const dispatch = false; const tr2 = startTr || state.tr; const props = this.buildProps(tr2, dispatch); const formattedCommands = Object.fromEntries( Object.entries(rawCommands).map(([name, command2]) => { return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })]; }) ); return { ...formattedCommands, chain: () => this.createChain(tr2, dispatch) }; } buildProps(tr2, shouldDispatch = true) { const { rawCommands, editor, state } = this; const { view } = editor; const props = { tr: tr2, editor, view, state: createChainableState({ state, transaction: tr2 }), dispatch: shouldDispatch ? () => void 0 : void 0, chain: () => this.createChain(tr2, shouldDispatch), can: () => this.createCan(tr2), get commands() { return Object.fromEntries( Object.entries(rawCommands).map(([name, command2]) => { return [name, (...args) => command2(...args)(props)]; }) ); } }; return props; } }; var commands_exports = {}; __export$1(commands_exports, { blur: () => blur, clearContent: () => clearContent, clearNodes: () => clearNodes, command: () => command, createParagraphNear: () => createParagraphNear, cut: () => cut, deleteCurrentNode: () => deleteCurrentNode, deleteNode: () => deleteNode, deleteRange: () => deleteRange, deleteSelection: () => deleteSelection, enter: () => enter, exitCode: () => exitCode, extendMarkRange: () => extendMarkRange, first: () => first, focus: () => focus, forEach: () => forEach, insertContent: () => insertContent, insertContentAt: () => insertContentAt, joinBackward: () => joinBackward, joinDown: () => joinDown, joinForward: () => joinForward, joinItemBackward: () => joinItemBackward, joinItemForward: () => joinItemForward, joinTextblockBackward: () => joinTextblockBackward, joinTextblockForward: () => joinTextblockForward, joinUp: () => joinUp, keyboardShortcut: () => keyboardShortcut, lift: () => lift, liftEmptyBlock: () => liftEmptyBlock, liftListItem: () => liftListItem, newlineInCode: () => newlineInCode, resetAttributes: () => resetAttributes, scrollIntoView: () => scrollIntoView, selectAll: () => selectAll, selectNodeBackward: () => selectNodeBackward, selectNodeForward: () => selectNodeForward, selectParentNode: () => selectParentNode, selectTextblockEnd: () => selectTextblockEnd, selectTextblockStart: () => selectTextblockStart, setContent: () => setContent, setMark: () => setMark, setMeta: () => setMeta, setNode: () => setNode, setNodeSelection: () => setNodeSelection, setTextDirection: () => setTextDirection, setTextSelection: () => setTextSelection, sinkListItem: () => sinkListItem, splitBlock: () => splitBlock, splitListItem: () => splitListItem, toggleList: () => toggleList, toggleMark: () => toggleMark, toggleNode: () => toggleNode, toggleWrap: () => toggleWrap, undoInputRule: () => undoInputRule, unsetAllMarks: () => unsetAllMarks, unsetMark: () => unsetMark, unsetTextDirection: () => unsetTextDirection, updateAttributes: () => updateAttributes, wrapIn: () => wrapIn, wrapInList: () => wrapInList }); var blur = () => ({ editor, view }) => { requestAnimationFrame(() => { var _a; if (!editor.isDestroyed) { view.dom.blur(); (_a = window == null ? void 0 : window.getSelection()) == null ? void 0 : _a.removeAllRanges(); } }); return true; }; var clearContent = (emitUpdate = true) => ({ commands }) => { return commands.setContent("", { emitUpdate }); }; var clearNodes = () => ({ state, tr: tr2, dispatch }) => { const { selection } = tr2; const { ranges } = selection; if (!dispatch) { return true; } ranges.forEach(({ $from, $to }) => { state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => { if (node.type.isText) { return; } const { doc: doc2, mapping } = tr2; const $mappedFrom = doc2.resolve(mapping.map(pos)); const $mappedTo = doc2.resolve(mapping.map(pos + node.nodeSize)); const nodeRange = $mappedFrom.blockRange($mappedTo); if (!nodeRange) { return; } const targetLiftDepth = liftTarget(nodeRange); if (node.type.isTextblock) { const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index()); tr2.setNodeMarkup(nodeRange.start, defaultType); } if (targetLiftDepth || targetLiftDepth === 0) { tr2.lift(nodeRange, targetLiftDepth); } }); }); return true; }; var command = (fn) => (props) => { return fn(props); }; var createParagraphNear = () => ({ state, dispatch }) => { return createParagraphNear$1(state, dispatch); }; var cut = (originRange, targetPos) => ({ editor, tr: tr2 }) => { const { state } = editor; const contentSlice = state.doc.slice(originRange.from, originRange.to); tr2.deleteRange(originRange.from, originRange.to); const newPos = tr2.mapping.map(targetPos); tr2.insert(newPos, contentSlice.content); tr2.setSelection(new TextSelection(tr2.doc.resolve(Math.max(newPos - 1, 0)))); return true; }; var deleteCurrentNode = () => ({ tr: tr2, dispatch }) => { const { selection } = tr2; const currentNode = selection.$anchor.node(); if (currentNode.content.size > 0) { return false; } const $pos = tr2.selection.$anchor; for (let depth = $pos.depth; depth > 0; depth -= 1) { const node = $pos.node(depth); if (node.type === currentNode.type) { if (dispatch) { const from2 = $pos.before(depth); const to = $pos.after(depth); tr2.delete(from2, to).scrollIntoView(); } return true; } } return false; }; function getNodeType(nameOrType, schema) { if (typeof nameOrType === "string") { if (!schema.nodes[nameOrType]) { throw Error(`There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?`); } return schema.nodes[nameOrType]; } return nameOrType; } var deleteNode = (typeOrName) => ({ tr: tr2, state, dispatch }) => { const type = getNodeType(typeOrName, state.schema); const $pos = tr2.selection.$anchor; for (let depth = $pos.depth; depth > 0; depth -= 1) { const node = $pos.node(depth); if (node.type === type) { if (dispatch) { const from2 = $pos.before(depth); const to = $pos.after(depth); tr2.delete(from2, to).scrollIntoView(); } return true; } } return false; }; var deleteRange = (range) => ({ tr: tr2, dispatch }) => { const { from: from2, to } = range; if (dispatch) { tr2.delete(from2, to); } return true; }; var deleteSelection = () => ({ state, dispatch }) => { return deleteSelection$1(state, dispatch); }; var enter = () => ({ commands }) => { return commands.keyboardShortcut("Enter"); }; var exitCode = () => ({ state, dispatch }) => { return exitCode$1(state, dispatch); }; function isRegExp(value) { return Object.prototype.toString.call(value) === "[object RegExp]"; } function objectIncludes(object1, object2, options = { strict: true }) { const keys2 = Object.keys(object2); if (!keys2.length) { return true; } return keys2.every((key) => { if (options.strict) { return object2[key] === object1[key]; } if (isRegExp(object2[key])) { return object2[key].test(object1[key]); } return object2[key] === object1[key]; }); } function findMarkInSet(marks, type, attributes = {}) { return marks.find((item) => { return item.type === type && objectIncludes( // Only check equality for the attributes that are provided Object.fromEntries(Object.keys(attributes).map((k) => [k, item.attrs[k]])), attributes ); }); } function isMarkInSet(marks, type, attributes = {}) { return !!findMarkInSet(marks, type, attributes); } function getMarkRange($pos, type, attributes) { if (!$pos || !type) { return; } let start = $pos.parent.childAfter($pos.parentOffset); if (!start.node || !start.node.marks.some((mark2) => mark2.type === type)) { start = $pos.parent.childBefore($pos.parentOffset); } if (!start.node || !start.node.marks.some((mark2) => mark2.type === type)) { return; } if (!attributes) { const firstMark = start.node.marks.find((mark2) => mark2.type === type); if (firstMark) { attributes = firstMark.attrs; } } const mark = findMarkInSet([...start.node.marks], type, attributes); if (!mark) { return; } let startIndex = start.index; let startPos = $pos.start() + start.offset; let endIndex = startIndex + 1; let endPos = startPos + start.node.nodeSize; while (startIndex > 0 && isMarkInSet([...$pos.parent.child(startIndex - 1).marks], type, attributes)) { startIndex -= 1; startPos -= $pos.parent.child(startIndex).nodeSize; } while (endIndex < $pos.parent.childCount && isMarkInSet([...$pos.parent.child(endIndex).marks], type, attributes)) { endPos += $pos.parent.child(endIndex).nodeSize; endIndex += 1; } return { from: startPos, to: endPos }; } function getMarkType(nameOrType, schema) { if (typeof nameOrType === "string") { if (!schema.marks[nameOrType]) { throw Error(`There is no mark type named '${nameOrType}'. Maybe you forgot to add the extension?`); } return schema.marks[nameOrType]; } return nameOrType; } var extendMarkRange = (typeOrName, attributes) => ({ tr: tr2, state, dispatch }) => { const type = getMarkType(typeOrName, state.schema); const { doc: doc2, selection } = tr2; const { $from, from: from2, to } = selection; if (dispatch) { const range = getMarkRange($from, type, attributes); if (range && range.from <= from2 && range.to >= to) { const newSelection = TextSelection.create(doc2, range.from, range.to); tr2.setSelection(newSelection); } } return true; }; var first = (commands) => (props) => { const items = typeof commands === "function" ? commands(props) : commands; for (let i = 0; i < items.length; i += 1) { if (items[i](props)) { return true; } } return false; }; function isTextSelection(value) { return value instanceof TextSelection; } function minMax(value = 0, min2 = 0, max2 = 0) { return Math.min(Math.max(value, min2), max2); } function resolveFocusPosition(doc2, position = null) { if (!position) { return null; } const selectionAtStart = Selection.atStart(doc2); const selectionAtEnd = Selection.atEnd(doc2); if (position === "start" || position === true) { return selectionAtStart; } if (position === "end") { return selectionAtEnd; } const minPos = selectionAtStart.from; const maxPos = selectionAtEnd.to; if (position === "all") { return TextSelection.create(doc2, minMax(0, minPos, maxPos), minMax(doc2.content.size, minPos, maxPos)); } return TextSelection.create(doc2, minMax(position, minPos, maxPos), minMax(position, minPos, maxPos)); } function isAndroid() { return navigator.platform === "Android" || /android/i.test(navigator.userAgent); } function isiOS() { return ["iPad Simulator", "iPhone Simulator", "iPod Simulator", "iPad", "iPhone", "iPod"].includes(navigator.platform) || // iPad on iOS 13 detection navigator.userAgent.includes("Mac") && "ontouchend" in document; } function isSafari() { return typeof navigator !== "undefined" ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent) : false; } var focus = (position = null, options = {}) => ({ editor, view, tr: tr2, dispatch }) => { options = { scrollIntoView: true, ...options }; const delayedFocus = () => { if (isiOS() || isAndroid()) { view.dom.focus(); } if (isSafari() && !isiOS() && !isAndroid()) { view.dom.focus({ preventScroll: true }); } requestAnimationFrame(() => { if (!editor.isDestroyed) { view.focus(); if (options == null ? void 0 : options.scrollIntoView) { editor.commands.scrollIntoView(); } } }); }; try { if (view.hasFocus() && position === null || position === false) { return true; } } catch { return false; } if (dispatch && position === null && !isTextSelection(editor.state.selection)) { delayedFocus(); return true; } const selection = resolveFocusPosition(tr2.doc, position) || editor.state.selection; const isSameSelection = editor.state.selection.eq(selection); if (dispatch) { if (!isSameSelection) { tr2.setSelection(selection); } if (isSameSelection && tr2.storedMarks) { tr2.setStoredMarks(tr2.storedMarks); } delayedFocus(); } return true; }; var forEach = (items, fn) => (props) => { return items.every((item, index) => fn(item, { ...props, index })); }; var insertContent = (value, options) => ({ tr: tr2, commands }) => { return commands.insertContentAt({ from: tr2.selection.from, to: tr2.selection.to }, value, options); }; var removeWhitespaces = (node) => { const children = node.childNodes; for (let i = children.length - 1; i >= 0; i -= 1) { const child = children[i]; if (child.nodeType === 3 && child.nodeValue && /^(\n\s\s|\n)$/.test(child.nodeValue)) { node.removeChild(child); } else if (child.nodeType === 1) { removeWhitespaces(child); } } return node; }; function elementFromString(value) { if (typeof window === "undefined") { throw new Error("[tiptap error]: there is no window object available, so this function cannot be used"); } const wrappedValue = `${value}`; const html = new window.DOMParser().parseFromString(wrappedValue, "text/html").body; return removeWhitespaces(html); } function createNodeFromContent(content, schema, options) { if (content instanceof Node$1 || content instanceof Fragment) { return content; } options = { slice: true, parseOptions: {}, ...options }; const isJSONContent = typeof content === "object" && content !== null; const isTextContent = typeof content === "string"; if (isJSONContent) { try { const isArrayContent = Array.isArray(content) && content.length > 0; if (isArrayContent) { return Fragment.fromArray(content.map((item) => schema.nodeFromJSON(item))); } const node = schema.nodeFromJSON(content); if (options.errorOnInvalidContent) { node.check(); } return node; } catch (error) { if (options.errorOnInvalidContent) { throw new Error("[tiptap error]: Invalid JSON content", { cause: error }); } console.warn("[tiptap warn]: Invalid content.", "Passed value:", content, "Error:", error); return createNodeFromContent("", schema, options); } } if (isTextContent) { if (options.errorOnInvalidContent) { let hasInvalidContent = false; let invalidContent = ""; const contentCheckSchema = new Schema({ topNode: schema.spec.topNode, marks: schema.spec.marks, // Prosemirror's schemas are executed such that: the last to execute, matches last // This means that we can add a catch-all node at the end of the schema to catch any content that we don't know how to handle nodes: schema.spec.nodes.append({ __tiptap__private__unknown__catch__all__node: { content: "inline*", group: "block", parseDOM: [ { tag: "*", getAttrs: (e) => { hasInvalidContent = true; invalidContent = typeof e === "string" ? e : e.outerHTML; return null; } } ] } }) }); if (options.slice) { DOMParser.fromSchema(contentCheckSchema).parseSlice(elementFromString(content), options.parseOptions); } else { DOMParser.fromSchema(contentCheckSchema).parse(elementFromString(content), options.parseOptions); } if (options.errorOnInvalidContent && hasInvalidContent) { throw new Error("[tiptap error]: Invalid HTML content", { cause: new Error(`Invalid element found: ${invalidContent}`) }); } } const parser = DOMParser.fromSchema(schema); if (options.slice) { return parser.parseSlice(elementFromString(content), options.parseOptions).content; } return parser.parse(elementFromString(content), options.parseOptions); } return createNodeFromContent("", schema, options); } function selectionToInsertionEnd(tr2, startLen, bias) { const last = tr2.steps.length - 1; if (last < startLen) { return; } const step = tr2.steps[last]; if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) { return; } const map2 = tr2.mapping.maps[last]; let end = 0; map2.forEach((_from, _to, _newFrom, newTo) => { if (end === 0) { end = newTo; } }); tr2.setSelection(Selection.near(tr2.doc.resolve(end), bias)); } var isFragment = (nodeOrFragment) => { return !("type" in nodeOrFragment); }; var insertContentAt = (position, value, options) => ({ tr: tr2, dispatch, editor }) => { var _a; if (dispatch) { options = { parseOptions: editor.options.parseOptions, updateSelection: true, applyInputRules: false, applyPasteRules: false, ...options }; let content; const emitContentError = (error) => { editor.emit("contentError", { editor, error, disableCollaboration: () => { if ("collaboration" in editor.storage && typeof editor.storage.collaboration === "object" && editor.storage.collaboration) { editor.storage.collaboration.isDisabled = true; } } }); }; const parseOptions = { preserveWhitespace: "full", ...options.parseOptions }; if (!options.errorOnInvalidContent && !editor.options.enableContentCheck && editor.options.emitContentError) { try { createNodeFromContent(value, editor.schema, { parseOptions, errorOnInvalidContent: true }); } catch (e) { emitContentError(e); } } try { content = createNodeFromContent(value, editor.schema, { parseOptions, errorOnInvalidContent: (_a = options.errorOnInvalidContent) != null ? _a : editor.options.enableContentCheck }); } catch (e) { emitContentError(e); return false; } let { from: from2, to } = typeof position === "number" ? { from: position, to: position } : { from: position.from, to: position.to }; let isOnlyTextContent = true; let isOnlyBlockContent = true; const nodes = isFragment(content) ? content : [content]; nodes.forEach((node) => { node.check(); isOnlyTextContent = isOnlyTextContent ? node.isText && node.marks.length === 0 : false; isOnlyBlockContent = isOnlyBlockContent ? node.isBlock : false; }); if (from2 === to && isOnlyBlockContent) { const { parent } = tr2.doc.resolve(from2); const isEmptyTextBlock = parent.isTextblock && !parent.type.spec.code && !parent.childCount; if (isEmptyTextBlock) { from2 -= 1; to += 1; } } let newContent; if (isOnlyTextContent) { if (Array.isArray(value)) { newContent = value.map((v) => v.text || "").join(""); } else if (value instanceof Fragment) { let text = ""; value.forEach((node) => { if (node.text) { text += node.text; } }); newContent = text; } else if (typeof value === "object" && !!value && !!value.text) { newContent = value.text; } else { newContent = value; } tr2.insertText(newContent, from2, to); } else { newContent = content; const $from = tr2.doc.resolve(from2); const $fromNode = $from.node(); const fromSelectionAtStart = $from.parentOffset === 0; const isTextSelection2 = $fromNode.isText || $fromNode.isTextblock; const hasContent = $fromNode.content.size > 0; if (fromSelectionAtStart && isTextSelection2 && hasContent && isOnlyBlockContent) { from2 = Math.max(0, from2 - 1); } tr2.replaceWith(from2, to, newContent); } if (options.updateSelection) { selectionToInsertionEnd(tr2, tr2.steps.length - 1, -1); } if (options.applyInputRules) { tr2.setMeta("applyInputRules", { from: from2, text: newContent }); } if (options.applyPasteRules) { tr2.setMeta("applyPasteRules", { from: from2, text: newContent }); } } return true; }; var joinUp = () => ({ state, dispatch }) => { return joinUp$1(state, dispatch); }; var joinDown = () => ({ state, dispatch }) => { return joinDown$1(state, dispatch); }; var joinBackward = () => ({ state, dispatch }) => { return joinBackward$1(state, dispatch); }; var joinForward = () => ({ state, dispatch }) => { return joinForward$1(state, dispatch); }; var joinItemBackward = () => ({ state, dispatch, tr: tr2 }) => { try { const point = joinPoint(state.doc, state.selection.$from.pos, -1); if (point === null || point === void 0) { return false; } tr2.join(point, 2); if (dispatch) { dispatch(tr2); } return true; } catch { return false; } }; var joinItemForward = () => ({ state, dispatch, tr: tr2 }) => { try { const point = joinPoint(state.doc, state.selection.$from.pos, 1); if (point === null || point === void 0) { return false; } tr2.join(point, 2); if (dispatch) { dispatch(tr2); } return true; } catch { return false; } }; var joinTextblockBackward = () => ({ state, dispatch }) => { return joinTextblockBackward$1(state, dispatch); }; var joinTextblockForward = () => ({ state, dispatch }) => { return joinTextblockForward$1(state, dispatch); }; function isMacOS() { return typeof navigator !== "undefined" ? /Mac/.test(navigator.platform) : false; } function normalizeKeyName(name) { const parts = name.split(/-(?!$)/); let result = parts[parts.length - 1]; if (result === "Space") { result = " "; } let alt; let ctrl; let shift2; let meta; for (let i = 0; i < parts.length - 1; i += 1) { const mod = parts[i]; if (/^(cmd|meta|m)$/i.test(mod)) { meta = true; } else if (/^a(lt)?$/i.test(mod)) { alt = true; } else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true; } else if (/^s(hift)?$/i.test(mod)) { shift2 = true; } else if (/^mod$/i.test(mod)) { if (isiOS() || isMacOS()) { meta = true; } else { ctrl = true; } } else { throw new Error(`Unrecognized modifier name: ${mod}`); } } if (alt) { result = `Alt-${result}`; } if (ctrl) { result = `Ctrl-${result}`; } if (meta) { result = `Meta-${result}`; } if (shift2) { result = `Shift-${result}`; } return result; } var keyboardShortcut = (name) => ({ editor, view, tr: tr2, dispatch }) => { const keys2 = normalizeKeyName(name).split(/-(?!$)/); const key = keys2.find((item) => !["Alt", "Ctrl", "Meta", "Shift"].includes(item)); const event = new KeyboardEvent("keydown", { key: key === "Space" ? " " : key, altKey: keys2.includes("Alt"), ctrlKey: keys2.includes("Ctrl"), metaKey: keys2.includes("Meta"), shiftKey: keys2.includes("Shift"), bubbles: true, cancelable: true }); const capturedTransaction = editor.captureTransaction(() => { view.someProp("handleKeyDown", (f) => f(view, event)); }); capturedTransaction == null ? void 0 : capturedTransaction.steps.forEach((step) => { const newStep = step.map(tr2.mapping); if (newStep && dispatch) { tr2.maybeStep(newStep); } }); return true; }; function isNodeActive(state, typeOrName, attributes = {}) { const { from: from2, to, empty: empty2 } = state.selection; const type = typeOrName ? getNodeType(typeOrName, state.schema) : null; const nodeRanges = []; state.doc.nodesBetween(from2, to, (node, pos) => { if (node.isText) { return; } const relativeFrom = Math.max(from2, pos); const relativeTo = Math.min(to, pos + node.nodeSize); nodeRanges.push({ node, from: relativeFrom, to: relativeTo }); }); const selectionRange = to - from2; const matchedNodeRanges = nodeRanges.filter((nodeRange) => { if (!type) { return true; } return type.name === nodeRange.node.type.name; }).filter((nodeRange) => objectIncludes(nodeRange.node.attrs, attributes, { strict: false })); if (empty2) { return !!matchedNodeRanges.length; } const range = matchedNodeRanges.reduce((sum, nodeRange) => sum + nodeRange.to - nodeRange.from, 0); return range >= selectionRange; } var lift = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema); const isActive2 = isNodeActive(state, type, attributes); if (!isActive2) { return false; } return lift$1(state, dispatch); }; var liftEmptyBlock = () => ({ state, dispatch }) => { return liftEmptyBlock$1(state, dispatch); }; var liftListItem = (typeOrName) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema); return liftListItem$1(type)(state, dispatch); }; var newlineInCode = () => ({ state, dispatch }) => { return newlineInCode$1(state, dispatch); }; function getSchemaTypeNameByName(name, schema) { if (schema.nodes[name]) { return "node"; } if (schema.marks[name]) { return "mark"; } return null; } function deleteProps(obj, propOrProps) { const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps; return Object.keys(obj).reduce((newObj, prop) => { if (!props.includes(prop)) { newObj[prop] = obj[prop]; } return newObj; }, {}); } var resetAttributes = (typeOrName, attributes) => ({ tr: tr2, state, dispatch }) => { let nodeType = null; let markType = null; const schemaType = getSchemaTypeNameByName( typeof typeOrName === "string" ? typeOrName : typeOrName.name, state.schema ); if (!schemaType) { return false; } if (schemaType === "node") { nodeType = getNodeType(typeOrName, state.schema); } if (schemaType === "mark") { markType = getMarkType(typeOrName, state.schema); } let canReset = false; tr2.selection.ranges.forEach((range) => { state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => { if (nodeType && nodeType === node.type) { canReset = true; if (dispatch) { tr2.setNodeMarkup(pos, void 0, deleteProps(node.attrs, attributes)); } } if (markType && node.marks.length) { node.marks.forEach((mark) => { if (markType === mark.type) { canReset = true; if (dispatch) { tr2.addMark(pos, pos + node.nodeSize, markType.create(deleteProps(mark.attrs, attributes))); } } }); } }); }); return canReset; }; var scrollIntoView = () => ({ tr: tr2, dispatch }) => { if (dispatch) { tr2.scrollIntoView(); } return true; }; var selectAll = () => ({ tr: tr2, dispatch }) => { if (dispatch) { const selection = new AllSelection(tr2.doc); tr2.setSelection(selection); } return true; }; var selectNodeBackward = () => ({ state, dispatch }) => { return selectNodeBackward$1(state, dispatch); }; var selectNodeForward = () => ({ state, dispatch }) => { return selectNodeForward$1(state, dispatch); }; var selectParentNode = () => ({ state, dispatch }) => { return selectParentNode$1(state, dispatch); }; var selectTextblockEnd = () => ({ state, dispatch }) => { return selectTextblockEnd$1(state, dispatch); }; var selectTextblockStart = () => ({ state, dispatch }) => { return selectTextblockStart$1(state, dispatch); }; function createDocument(content, schema, parseOptions = {}, options = {}) { return createNodeFromContent(content, schema, { slice: false, parseOptions, errorOnInvalidContent: options.errorOnInvalidContent }); } var setContent = (content, { errorOnInvalidContent, emitUpdate = true, parseOptions = {} } = {}) => ({ editor, tr: tr2, dispatch, commands }) => { const { doc: doc2 } = tr2; if (parseOptions.preserveWhitespace !== "full") { const document2 = createDocument(content, editor.schema, parseOptions, { errorOnInvalidContent: errorOnInvalidContent != null ? errorOnInvalidContent : editor.options.enableContentCheck }); if (dispatch) { tr2.replaceWith(0, doc2.content.size, document2).setMeta("preventUpdate", !emitUpdate); } return true; } if (dispatch) { tr2.setMeta("preventUpdate", !emitUpdate); } return commands.insertContentAt({ from: 0, to: doc2.content.size }, content, { parseOptions, errorOnInvalidContent: errorOnInvalidContent != null ? errorOnInvalidContent : editor.options.enableContentCheck }); }; function getMarkAttributes(state, typeOrName) { const type = getMarkType(typeOrName, state.schema); const { from: from2, to, empty: empty2 } = state.selection; const marks = []; if (empty2) { if (state.storedMarks) { marks.push(...state.storedMarks); } marks.push(...state.selection.$head.marks()); } else { state.doc.nodesBetween(from2, to, (node) => { marks.push(...node.marks); }); } const mark = marks.find((markItem) => markItem.type.name === type.name); if (!mark) { return {}; } return { ...mark.attrs }; } function combineTransactionSteps(oldDoc, transactions) { const transform = new Transform(oldDoc); transactions.forEach((transaction) => { transaction.steps.forEach((step) => { transform.step(step); }); }); return transform; } function defaultBlockAt(match) { for (let i = 0; i < match.edgeCount; i += 1) { const { type } = match.edge(i); if (type.isTextblock && !type.hasRequiredAttrs()) { return type; } } return null; } function findChildrenInRange(node, range, predicate) { const nodesWithPos = []; node.nodesBetween(range.from, range.to, (child, pos) => { if (predicate(child)) { nodesWithPos.push({ node: child, pos }); } }); return nodesWithPos; } function findParentNodeClosestToPos($pos, predicate) { for (let i = $pos.depth; i > 0; i -= 1) { const node = $pos.node(i); if (predicate(node)) { return { pos: i > 0 ? $pos.before(i) : 0, start: $pos.start(i), depth: i, node }; } } } function findParentNode(predicate) { return (selection) => findParentNodeClosestToPos(selection.$from, predicate); } function getExtensionField(extension, field, context) { if (extension.config[field] === void 0 && extension.parent) { return getExtensionField(extension.parent, field, context); } if (typeof extension.config[field] === "function") { const value = extension.config[field].bind({ ...context, parent: extension.parent ? getExtensionField(extension.parent, field, context) : null }); return value; } return extension.config[field]; } function flattenExtensions(extensions) { return extensions.map((extension) => { const context = { name: extension.name, options: extension.options, storage: extension.storage }; const addExtensions = getExtensionField(extension, "addExtensions", context); if (addExtensions) { return [extension, ...flattenExtensions(addExtensions())]; } return extension; }).flat(10); } function getHTMLFromFragment(fragment, schema) { const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment); const temporaryDocument = document.implementation.createHTMLDocument(); const container = temporaryDocument.createElement("div"); container.appendChild(documentFragment); return container.innerHTML; } function isFunction(value) { return typeof value === "function"; } function callOrReturn(value, context = void 0, ...props) { if (isFunction(value)) { if (context) { return value.bind(context)(...props); } return value(...props); } return value; } function isEmptyObject(value = {}) { return Object.keys(value).length === 0 && value.constructor === Object; } function splitExtensions(extensions) { const baseExtensions = extensions.filter((extension) => extension.type === "extension"); const nodeExtensions = extensions.filter((extension) => extension.type === "node"); const markExtensions = extensions.filter((extension) => extension.type === "mark"); return { baseExtensions, nodeExtensions, markExtensions }; } function getAttributesFromExtensions(extensions) { const extensionAttributes = []; const { nodeExtensions, markExtensions } = splitExtensions(extensions); const nodeAndMarkExtensions = [...nodeExtensions, ...markExtensions]; const defaultAttribute = { default: null, validate: void 0, rendered: true, renderHTML: null, parseHTML: null, keepOnSplit: true, isRequired: false }; const nodeExtensionTypes = nodeExtensions.filter((ext) => ext.name !== "text").map((ext) => ext.name); const markExtensionTypes = markExtensions.map((ext) => ext.name); const allExtensionTypes = [...nodeExtensionTypes, ...markExtensionTypes]; extensions.forEach((extension) => { const context = { name: extension.name, options: extension.options, storage: extension.storage, extensions: nodeAndMarkExtensions }; const addGlobalAttributes = getExtensionField( extension, "addGlobalAttributes", context ); if (!addGlobalAttributes) { return; } const globalAttributes = addGlobalAttributes(); globalAttributes.forEach((globalAttribute) => { let resolvedTypes; if (Array.isArray(globalAttribute.types)) { resolvedTypes = globalAttribute.types; } else if (globalAttribute.types === "*") { resolvedTypes = allExtensionTypes; } else if (globalAttribute.types === "nodes") { resolvedTypes = nodeExtensionTypes; } else if (globalAttribute.types === "marks") { resolvedTypes = markExtensionTypes; } else { resolvedTypes = []; } resolvedTypes.forEach((type) => { Object.entries(globalAttribute.attributes).forEach(([name, attribute]) => { extensionAttributes.push({ type, name, attribute: { ...defaultAttribute, ...attribute } }); }); }); }); }); nodeAndMarkExtensions.forEach((extension) => { const context = { name: extension.name, options: extension.options, storage: extension.storage }; const addAttributes = getExtensionField( extension, "addAttributes", context ); if (!addAttributes) { return; } const attributes = addAttributes(); Object.entries(attributes).forEach(([name, attribute]) => { const mergedAttr = { ...defaultAttribute, ...attribute }; if (typeof (mergedAttr == null ? void 0 : mergedAttr.default) === "function") { mergedAttr.default = mergedAttr.default(); } if ((mergedAttr == null ? void 0 : mergedAttr.isRequired) && (mergedAttr == null ? void 0 : mergedAttr.default) === void 0) { delete mergedAttr.default; } extensionAttributes.push({ type: extension.name, name, attribute: mergedAttr }); }); }); return extensionAttributes; } function splitStyleDeclarations(styles) { const result = []; let current = ""; let inSingleQuote = false; let inDoubleQuote = false; let parenDepth = 0; const length = styles.length; for (let i = 0; i < length; i += 1) { const char = styles[i]; if (char === "'" && !inDoubleQuote) { inSingleQuote = !inSingleQuote; current += char; continue; } if (char === '"' && !inSingleQuote) { inDoubleQuote = !inDoubleQuote; current += char; continue; } if (!inSingleQuote && !inDoubleQuote) { if (char === "(") { parenDepth += 1; current += char; continue; } if (char === ")" && parenDepth > 0) { parenDepth -= 1; current += char; continue; } if (char === ";" && parenDepth === 0) { result.push(current); current = ""; continue; } } current += char; } if (current) { result.push(current); } return result; } function parseStyleEntries(styles) { const pairs = []; const declarations = splitStyleDeclarations(styles || ""); const numDeclarations = declarations.length; for (let i = 0; i < numDeclarations; i += 1) { const declaration = declarations[i]; const firstColonIndex = declaration.indexOf(":"); if (firstColonIndex === -1) { continue; } const property = declaration.slice(0, firstColonIndex).trim(); const value = declaration.slice(firstColonIndex + 1).trim(); if (property && value) { pairs.push([property, value]); } } return pairs; } function mergeAttributes(...objects) { return objects.filter((item) => !!item).reduce((items, item) => { const mergedAttributes = { ...items }; Object.entries(item).forEach(([key, value]) => { const exists = mergedAttributes[key]; if (!exists) { mergedAttributes[key] = value; return; } if (key === "class") { const valueClasses = value ? String(value).split(" ") : []; const existingClasses = mergedAttributes[key] ? mergedAttributes[key].split(" ") : []; const insertClasses = valueClasses.filter((valueClass) => !existingClasses.includes(valueClass)); mergedAttributes[key] = [...existingClasses, ...insertClasses].join(" "); } else if (key === "style") { const styleMap = new Map([...parseStyleEntries(mergedAttributes[key]), ...parseStyleEntries(value)]); mergedAttributes[key] = Array.from(styleMap.entries()).map(([property, val]) => `${property}: ${val}`).join("; "); } else { mergedAttributes[key] = value; } }); return mergedAttributes; }, {}); } function getRenderedAttributes(nodeOrMark, extensionAttributes) { return extensionAttributes.filter((attribute) => attribute.type === nodeOrMark.type.name).filter((item) => item.attribute.rendered).map((item) => { if (!item.attribute.renderHTML) { return { [item.name]: nodeOrMark.attrs[item.name] }; } return item.attribute.renderHTML(nodeOrMark.attrs) || {}; }).reduce((attributes, attribute) => mergeAttributes(attributes, attribute), {}); } function fromString(value) { if (typeof value !== "string") { return value; } if (value.match(/^[+-]?(?:\d*\.)?\d+$/)) { return Number(value); } if (value === "true") { return true; } if (value === "false") { return false; } return value; } function injectExtensionAttributesToParseRule(parseRule, extensionAttributes) { if ("style" in parseRule) { return parseRule; } return { ...parseRule, getAttrs: (node) => { const oldAttributes = parseRule.getAttrs ? parseRule.getAttrs(node) : parseRule.attrs; if (oldAttributes === false) { return false; } const newAttributes = extensionAttributes.reduce((items, item) => { const value = item.attribute.parseHTML ? item.attribute.parseHTML(node) : fromString(node.getAttribute(item.name)); if (value === null || value === void 0) { return items; } return { ...items, [item.name]: value }; }, {}); return { ...oldAttributes, ...newAttributes }; } }; } function cleanUpSchemaItem(data) { return Object.fromEntries( // @ts-ignore Object.entries(data).filter(([key, value]) => { if (key === "attrs" && isEmptyObject(value)) { return false; } return value !== null && value !== void 0; }) ); } function buildAttributeSpec(extensionAttribute) { var _a, _b; const spec = {}; if (!((_a = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _a.isRequired) && "default" in ((extensionAttribute == null ? void 0 : extensionAttribute.attribute) || {})) { spec.default = extensionAttribute.attribute.default; } if (((_b = extensionAttribute == null ? void 0 : extensionAttribute.attribute) == null ? void 0 : _b.validate) !== void 0) { spec.validate = extensionAttribute.attribute.validate; } return [extensionAttribute.name, spec]; } function getSchemaByResolvedExtensions(extensions, editor) { var _a; const allAttributes = getAttributesFromExtensions(extensions); const { nodeExtensions, markExtensions } = splitExtensions(extensions); const topNode = (_a = nodeExtensions.find((extension) => getExtensionField(extension, "topNode"))) == null ? void 0 : _a.name; const nodes = Object.fromEntries( nodeExtensions.map((extension) => { const extensionAttributes = allAttributes.filter((attribute) => attribute.type === extension.name); const context = { name: extension.name, options: extension.options, storage: extension.storage, editor }; const extraNodeFields = extensions.reduce((fields, e) => { const extendNodeSchema = getExtensionField(e, "extendNodeSchema", context); return { ...fields, ...extendNodeSchema ? extendNodeSchema(extension) : {} }; }, {}); const schema = cleanUpSchemaItem({ ...extraNodeFields, content: callOrReturn(getExtensionField(extension, "content", context)), marks: callOrReturn(getExtensionField(extension, "marks", context)), group: callOrReturn(getExtensionField(extension, "group", context)), inline: callOrReturn(getExtensionField(extension, "inline", context)), atom: callOrReturn(getExtensionField(extension, "atom", context)), selectable: callOrReturn(getExtensionField(extension, "selectable", context)), draggable: callOrReturn(getExtensionField(extension, "draggable", context)), code: callOrReturn(getExtensionField(extension, "code", context)), whitespace: callOrReturn(getExtensionField(extension, "whitespace", context)), linebreakReplacement: callOrReturn( getExtensionField(extension, "linebreakReplacement", context) ), defining: callOrReturn(getExtensionField(extension, "defining", context)), isolating: callOrReturn(getExtensionField(extension, "isolating", context)), attrs: Object.fromEntries(extensionAttributes.map(buildAttributeSpec)) }); const parseHTML = callOrReturn(getExtensionField(extension, "parseHTML", context)); if (parseHTML) { schema.parseDOM = parseHTML.map( (parseRule) => injectExtensionAttributesToParseRule(parseRule, extensionAttributes) ); } const renderHTML = getExtensionField(extension, "renderHTML", context); if (renderHTML) { schema.toDOM = (node) => renderHTML({ node, HTMLAttributes: getRenderedAttributes(node, extensionAttributes) }); } const renderText = getExtensionField(extension, "renderText", context); if (renderText) { schema.toText = renderText; } return [extension.name, schema]; }) ); const marks = Object.fromEntries( markExtensions.map((extension) => { const extensionAttributes = allAttributes.filter((attribute) => attribute.type === extension.name); const context = { name: extension.name, options: extension.options, storage: extension.storage, editor }; const extraMarkFields = extensions.reduce((fields, e) => { const extendMarkSchema = getExtensionField(e, "extendMarkSchema", context); return { ...fields, ...extendMarkSchema ? extendMarkSchema(extension) : {} }; }, {}); const schema = cleanUpSchemaItem({ ...extraMarkFields, inclusive: callOrReturn(getExtensionField(extension, "inclusive", context)), excludes: callOrReturn(getExtensionField(extension, "excludes", context)), group: callOrReturn(getExtensionField(extension, "group", context)), spanning: callOrReturn(getExtensionField(extension, "spanning", context)), code: callOrReturn(getExtensionField(extension, "code", context)), attrs: Object.fromEntries(extensionAttributes.map(buildAttributeSpec)) }); const parseHTML = callOrReturn(getExtensionField(extension, "parseHTML", context)); if (parseHTML) { schema.parseDOM = parseHTML.map( (parseRule) => injectExtensionAttributesToParseRule(parseRule, extensionAttributes) ); } const renderHTML = getExtensionField(extension, "renderHTML", context); if (renderHTML) { schema.toDOM = (mark) => renderHTML({ mark, HTMLAttributes: getRenderedAttributes(mark, extensionAttributes) }); } return [extension.name, schema]; }) ); return new Schema({ topNode, nodes, marks }); } function findDuplicates(items) { const filtered = items.filter((el, index) => items.indexOf(el) !== index); return Array.from(new Set(filtered)); } function sortExtensions(extensions) { const defaultPriority = 100; return extensions.sort((a, b) => { const priorityA = getExtensionField(a, "priority") || defaultPriority; const priorityB = getExtensionField(b, "priority") || defaultPriority; if (priorityA > priorityB) { return -1; } if (priorityA < priorityB) { return 1; } return 0; }); } function resolveExtensions(extensions) { const resolvedExtensions = sortExtensions(flattenExtensions(extensions)); const duplicatedNames = findDuplicates(resolvedExtensions.map((extension) => extension.name)); if (duplicatedNames.length) { console.warn( `[tiptap warn]: Duplicate extension names found: [${duplicatedNames.map((item) => `'${item}'`).join(", ")}]. This can lead to issues.` ); } return resolvedExtensions; } function getTextBetween(startNode, range, options) { const { from: from2, to } = range; const { blockSeparator = "\n\n", textSerializers = {} } = options || {}; let text = ""; startNode.nodesBetween(from2, to, (node, pos, parent, index) => { var _a; if (node.isBlock && pos > from2) { text += blockSeparator; } const textSerializer = textSerializers == null ? void 0 : textSerializers[node.type.name]; if (textSerializer) { if (parent) { text += textSerializer({ node, pos, parent, index, range }); } return false; } if (node.isText) { text += (_a = node == null ? void 0 : node.text) == null ? void 0 : _a.slice(Math.max(from2, pos) - pos, to - pos); } }); return text; } function getText(node, options) { const range = { from: 0, to: node.content.size }; return getTextBetween(node, range, options); } function getTextSerializersFromSchema(schema) { return Object.fromEntries( Object.entries(schema.nodes).filter(([, node]) => node.spec.toText).map(([name, node]) => [name, node.spec.toText]) ); } function getNodeAttributes(state, typeOrName) { const type = getNodeType(typeOrName, state.schema); const { from: from2, to } = state.selection; const nodes = []; state.doc.nodesBetween(from2, to, (node2) => { nodes.push(node2); }); const node = nodes.reverse().find((nodeItem) => nodeItem.type.name === type.name); if (!node) { return {}; } return { ...node.attrs }; } function getAttributes(state, typeOrName) { const schemaType = getSchemaTypeNameByName( typeof typeOrName === "string" ? typeOrName : typeOrName.name, state.schema ); if (schemaType === "node") { return getNodeAttributes(state, typeOrName); } if (schemaType === "mark") { return getMarkAttributes(state, typeOrName); } return {}; } function removeDuplicates(array, by = JSON.stringify) { const seen = {}; return array.filter((item) => { const key = by(item); return Object.prototype.hasOwnProperty.call(seen, key) ? false : seen[key] = true; }); } function simplifyChangedRanges(changes) { const uniqueChanges = removeDuplicates(changes); return uniqueChanges.length === 1 ? uniqueChanges : uniqueChanges.filter((change, index) => { const rest = uniqueChanges.filter((_, i) => i !== index); return !rest.some((otherChange) => { return change.oldRange.from >= otherChange.oldRange.from && change.oldRange.to <= otherChange.oldRange.to && change.newRange.from >= otherChange.newRange.from && change.newRange.to <= otherChange.newRange.to; }); }); } function getChangedRanges(transform) { const { mapping, steps } = transform; const changes = []; mapping.maps.forEach((stepMap, index) => { const ranges = []; if (!stepMap.ranges.length) { const { from: from2, to } = steps[index]; if (from2 === void 0 || to === void 0) { return; } ranges.push({ from: from2, to }); } else { stepMap.forEach((from2, to) => { ranges.push({ from: from2, to }); }); } ranges.forEach(({ from: from2, to }) => { const newStart = mapping.slice(index).map(from2, -1); const newEnd = mapping.slice(index).map(to); const oldStart = mapping.invert().map(newStart, -1); const oldEnd = mapping.invert().map(newEnd); changes.push({ oldRange: { from: oldStart, to: oldEnd }, newRange: { from: newStart, to: newEnd } }); }); }); return simplifyChangedRanges(changes); } function getMarksBetween(from2, to, doc2) { const marks = []; if (from2 === to) { doc2.resolve(from2).marks().forEach((mark) => { const $pos = doc2.resolve(from2); const range = getMarkRange($pos, mark.type); if (!range) { return; } marks.push({ mark, ...range }); }); } else { doc2.nodesBetween(from2, to, (node, pos) => { if (!node || (node == null ? void 0 : node.nodeSize) === void 0) { return; } marks.push( ...node.marks.map((mark) => ({ from: pos, to: pos + node.nodeSize, mark })) ); }); } return marks; } var getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => { const $pos = state.doc.resolve(pos); let currentDepth = maxDepth; let node = null; while (currentDepth > 0 && node === null) { const currentNode = $pos.node(currentDepth); if ((currentNode == null ? void 0 : currentNode.type.name) === typeOrName) { node = currentNode; } else { currentDepth -= 1; } } return [node, currentDepth]; }; function getSchemaTypeByName(name, schema) { return schema.nodes[name] || schema.marks[name] || null; } function getSplittedAttributes(extensionAttributes, typeName, attributes) { return Object.fromEntries( Object.entries(attributes).filter(([name]) => { const extensionAttribute = extensionAttributes.find((item) => { return item.type === typeName && item.name === name; }); if (!extensionAttribute) { return false; } return extensionAttribute.attribute.keepOnSplit; }) ); } var getTextContentFromNodes = ($from, maxMatch = 500) => { let textBefore = ""; const sliceEndPos = $from.parentOffset; $from.parent.nodesBetween(Math.max(0, sliceEndPos - maxMatch), sliceEndPos, (node, pos, parent, index) => { var _a, _b; const chunk = ((_b = (_a = node.type.spec).toText) == null ? void 0 : _b.call(_a, { node, pos, parent, index })) || node.textContent || "%leaf%"; textBefore += node.isAtom && !node.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos)); }); return textBefore; }; function isMarkActive(state, typeOrName, attributes = {}) { const { empty: empty2, ranges } = state.selection; const type = typeOrName ? getMarkType(typeOrName, state.schema) : null; if (empty2) { return !!(state.storedMarks || state.selection.$from.marks()).filter((mark) => { if (!type) { return true; } return type.name === mark.type.name; }).find((mark) => objectIncludes(mark.attrs, attributes, { strict: false })); } let selectionRange = 0; const markRanges = []; ranges.forEach(({ $from, $to }) => { const from2 = $from.pos; const to = $to.pos; state.doc.nodesBetween(from2, to, (node, pos) => { if (type && node.inlineContent && !node.type.allowsMarkType(type)) { return false; } if (!node.isText && !node.marks.length) { return; } const relativeFrom = Math.max(from2, pos); const relativeTo = Math.min(to, pos + node.nodeSize); const range2 = relativeTo - relativeFrom; selectionRange += range2; markRanges.push( ...node.marks.map((mark) => ({ mark, from: relativeFrom, to: relativeTo })) ); }); }); if (selectionRange === 0) { return false; } const matchedRange = markRanges.filter((markRange) => { if (!type) { return true; } return type.name === markRange.mark.type.name; }).filter((markRange) => objectIncludes(markRange.mark.attrs, attributes, { strict: false })).reduce((sum, markRange) => sum + markRange.to - markRange.from, 0); const excludedRange = markRanges.filter((markRange) => { if (!type) { return true; } return markRange.mark.type !== type && markRange.mark.type.excludes(type); }).reduce((sum, markRange) => sum + markRange.to - markRange.from, 0); const range = matchedRange > 0 ? matchedRange + excludedRange : matchedRange; return range >= selectionRange; } function isActive(state, name, attributes = {}) { if (!name) { return isNodeActive(state, null, attributes) || isMarkActive(state, null, attributes); } const schemaType = getSchemaTypeNameByName(name, state.schema); if (schemaType === "node") { return isNodeActive(state, name, attributes); } if (schemaType === "mark") { return isMarkActive(state, name, attributes); } return false; } var isAtEndOfNode = (state, nodeType) => { const { $from, $to, $anchor } = state.selection; if (nodeType) { const parentNode2 = findParentNode((node) => node.type.name === nodeType)(state.selection); if (!parentNode2) { return false; } const $parentPos = state.doc.resolve(parentNode2.pos + 1); if ($anchor.pos + 1 === $parentPos.end()) { return true; } return false; } if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) { return false; } return true; }; var isAtStartOfNode = (state) => { const { $from, $to } = state.selection; if ($from.parentOffset > 0 || $from.pos !== $to.pos) { return false; } return true; }; function isExtensionRulesEnabled(extension, enabled) { if (Array.isArray(enabled)) { return enabled.some((enabledExtension) => { const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name; return name === extension.name; }); } return enabled; } function isList(name, extensions) { const { nodeExtensions } = splitExtensions(extensions); const extension = nodeExtensions.find((item) => item.name === name); if (!extension) { return false; } const context = { name: extension.name, options: extension.options, storage: extension.storage }; const group = callOrReturn(getExtensionField(extension, "group", context)); if (typeof group !== "string") { return false; } return group.split(" ").includes("list"); } function isNodeEmpty(node, { checkChildren = true, ignoreWhitespace = false } = {}) { var _a; if (ignoreWhitespace) { if (node.type.name === "hardBreak") { return true; } if (node.isText) { return !/\S/.test((_a = node.text) != null ? _a : ""); } } if (node.isText) { return !node.text; } if (node.isAtom || node.isLeaf) { return false; } if (node.content.childCount === 0) { return true; } if (checkChildren) { let isContentEmpty = true; node.content.forEach((childNode) => { if (isContentEmpty === false) { return; } if (!isNodeEmpty(childNode, { ignoreWhitespace, checkChildren })) { isContentEmpty = false; } }); return isContentEmpty; } return false; } function isNodeSelection(value) { return value instanceof NodeSelection; } var MappablePosition = class _MappablePosition { constructor(position) { this.position = position; } /** * Creates a MappablePosition from a JSON object. */ static fromJSON(json) { return new _MappablePosition(json.position); } /** * Converts the MappablePosition to a JSON object. */ toJSON() { return { position: this.position }; } }; function getUpdatedPosition(position, transaction) { const mapResult = transaction.mapping.mapResult(position.position); return { position: new MappablePosition(mapResult.pos), mapResult }; } function createMappablePosition(position) { return new MappablePosition(position); } function posToDOMRect(view, from2, to) { const minPos = 0; const maxPos = view.state.doc.content.size; const resolvedFrom = minMax(from2, minPos, maxPos); const resolvedEnd = minMax(to, minPos, maxPos); const start = view.coordsAtPos(resolvedFrom); const end = view.coordsAtPos(resolvedEnd, -1); const top = Math.min(start.top, end.top); const bottom = Math.max(start.bottom, end.bottom); const left = Math.min(start.left, end.left); const right = Math.max(start.right, end.right); const width = right - left; const height = bottom - top; const x = left; const y = top; const data = { top, bottom, left, right, width, height, x, y }; return { ...data, toJSON: () => data }; } function canSetMark(state, tr2, newMarkType) { var _a; const { selection } = tr2; let cursor = null; if (isTextSelection(selection)) { cursor = selection.$cursor; } if (cursor) { const currentMarks = (_a = state.storedMarks) != null ? _a : cursor.marks(); const parentAllowsMarkType = cursor.parent.type.allowsMarkType(newMarkType); return parentAllowsMarkType && (!!newMarkType.isInSet(currentMarks) || !currentMarks.some((mark) => mark.type.excludes(newMarkType))); } const { ranges } = selection; return ranges.some(({ $from, $to }) => { let someNodeSupportsMark = $from.depth === 0 ? state.doc.inlineContent && state.doc.type.allowsMarkType(newMarkType) : false; state.doc.nodesBetween($from.pos, $to.pos, (node, _pos, parent) => { if (someNodeSupportsMark) { return false; } if (node.isInline) { const parentAllowsMarkType = !parent || parent.type.allowsMarkType(newMarkType); const currentMarksAllowMarkType = !!newMarkType.isInSet(node.marks) || !node.marks.some((otherMark) => otherMark.type.excludes(newMarkType)); someNodeSupportsMark = parentAllowsMarkType && currentMarksAllowMarkType; } return !someNodeSupportsMark; }); return someNodeSupportsMark; }); } var setMark = (typeOrName, attributes = {}) => ({ tr: tr2, state, dispatch }) => { const { selection } = tr2; const { empty: empty2, ranges } = selection; const type = getMarkType(typeOrName, state.schema); if (dispatch) { if (empty2) { const oldAttributes = getMarkAttributes(state, type); tr2.addStoredMark( type.create({ ...oldAttributes, ...attributes }) ); } else { ranges.forEach((range) => { const from2 = range.$from.pos; const to = range.$to.pos; state.doc.nodesBetween(from2, to, (node, pos) => { const trimmedFrom = Math.max(pos, from2); const trimmedTo = Math.min(pos + node.nodeSize, to); const someHasMark = node.marks.find((mark) => mark.type === type); if (someHasMark) { node.marks.forEach((mark) => { if (type === mark.type) { tr2.addMark( trimmedFrom, trimmedTo, type.create({ ...mark.attrs, ...attributes }) ); } }); } else { tr2.addMark(trimmedFrom, trimmedTo, type.create(attributes)); } }); }); } } return canSetMark(state, tr2, type); }; var setMeta = (key, value) => ({ tr: tr2 }) => { tr2.setMeta(key, value); return true; }; var setNode = (typeOrName, attributes = {}) => ({ state, dispatch, chain }) => { const type = getNodeType(typeOrName, state.schema); let attributesToCopy; if (state.selection.$anchor.sameParent(state.selection.$head)) { attributesToCopy = state.selection.$anchor.parent.attrs; } if (!type.isTextblock) { console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'); return false; } return chain().command(({ commands }) => { const canSetBlock = setBlockType(type, { ...attributesToCopy, ...attributes })(state); if (canSetBlock) { return true; } return commands.clearNodes(); }).command(({ state: updatedState }) => { return setBlockType(type, { ...attributesToCopy, ...attributes })(updatedState, dispatch); }).run(); }; var setNodeSelection = (position) => ({ tr: tr2, dispatch }) => { if (dispatch) { const { doc: doc2 } = tr2; const from2 = minMax(position, 0, doc2.content.size); const selection = NodeSelection.create(doc2, from2); tr2.setSelection(selection); } return true; }; var setTextDirection = (direction, position) => ({ tr: tr2, state, dispatch }) => { const { selection } = state; let from2; let to; if (typeof position === "number") { from2 = position; to = position; } else if (position && "from" in position && "to" in position) { from2 = position.from; to = position.to; } else { from2 = selection.from; to = selection.to; } if (dispatch) { tr2.doc.nodesBetween(from2, to, (node, pos) => { if (node.isText) { return; } tr2.setNodeMarkup(pos, void 0, { ...node.attrs, dir: direction }); }); } return true; }; var setTextSelection = (position) => ({ tr: tr2, dispatch }) => { if (dispatch) { const { doc: doc2 } = tr2; const { from: from2, to } = typeof position === "number" ? { from: position, to: position } : position; const minPos = TextSelection.atStart(doc2).from; const maxPos = TextSelection.atEnd(doc2).to; const resolvedFrom = minMax(from2, minPos, maxPos); const resolvedEnd = minMax(to, minPos, maxPos); const selection = TextSelection.create(doc2, resolvedFrom, resolvedEnd); tr2.setSelection(selection); } return true; }; var sinkListItem = (typeOrName) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema); return sinkListItem$1(type)(state, dispatch); }; function ensureMarks(state, splittableMarks) { const marks = state.storedMarks || state.selection.$to.parentOffset && state.selection.$from.marks(); if (marks) { const filteredMarks = marks.filter((mark) => splittableMarks == null ? void 0 : splittableMarks.includes(mark.type.name)); state.tr.ensureMarks(filteredMarks); } } var splitBlock = ({ keepMarks = true } = {}) => ({ tr: tr2, state, dispatch, editor }) => { const { selection, doc: doc2 } = tr2; const { $from, $to } = selection; const extensionAttributes = editor.extensionManager.attributes; const newAttributes = getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs); if (selection instanceof NodeSelection && selection.node.isBlock) { if (!$from.parentOffset || !canSplit(doc2, $from.pos)) { return false; } if (dispatch) { if (keepMarks) { ensureMarks(state, editor.extensionManager.splittableMarks); } tr2.split($from.pos).scrollIntoView(); } return true; } if (!$from.parent.isBlock) { return false; } const atEnd = $to.parentOffset === $to.parent.content.size; const deflt = $from.depth === 0 ? void 0 : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1))); let types = atEnd && deflt ? [ { type: deflt, attrs: newAttributes } ] : void 0; let can = canSplit(tr2.doc, tr2.mapping.map($from.pos), 1, types); if (!types && !can && canSplit(tr2.doc, tr2.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : void 0)) { can = true; types = deflt ? [ { type: deflt, attrs: newAttributes } ] : void 0; } if (dispatch) { if (can) { if (selection instanceof TextSelection) { tr2.deleteSelection(); } tr2.split(tr2.mapping.map($from.pos), 1, types); if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) { const first2 = tr2.mapping.map($from.before()); const $first = tr2.doc.resolve(first2); if ($from.node(-1).canReplaceWith($first.index(), $first.index() + 1, deflt)) { tr2.setNodeMarkup(tr2.mapping.map($from.before()), deflt); } } } if (keepMarks) { ensureMarks(state, editor.extensionManager.splittableMarks); } tr2.scrollIntoView(); } return can; }; var splitListItem = (typeOrName, overrideAttrs = {}) => ({ tr: tr2, state, dispatch, editor }) => { var _a; const type = getNodeType(typeOrName, state.schema); const { $from, $to } = state.selection; const node = state.selection.node; if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to)) { return false; } const grandParent = $from.node(-1); if (grandParent.type !== type) { return false; } const extensionAttributes = editor.extensionManager.attributes; if ($from.parent.content.size === 0 && $from.node(-1).childCount === $from.indexAfter(-1)) { if ($from.depth === 2 || $from.node(-3).type !== type || $from.index(-2) !== $from.node(-2).childCount - 1) { return false; } if (dispatch) { let wrap2 = Fragment.empty; const depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3; for (let d = $from.depth - depthBefore; d >= $from.depth - 3; d -= 1) { wrap2 = Fragment.from($from.node(d).copy(wrap2)); } const depthAfter = ( // eslint-disable-next-line no-nested-ternary $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3 ); const newNextTypeAttributes2 = { ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs), ...overrideAttrs }; const nextType2 = ((_a = type.contentMatch.defaultType) == null ? void 0 : _a.createAndFill(newNextTypeAttributes2)) || void 0; wrap2 = wrap2.append(Fragment.from(type.createAndFill(null, nextType2) || void 0)); const start = $from.before($from.depth - (depthBefore - 1)); tr2.replace(start, $from.after(-depthAfter), new Slice(wrap2, 4 - depthBefore, 0)); let sel = -1; tr2.doc.nodesBetween(start, tr2.doc.content.size, (n, pos) => { if (sel > -1) { return false; } if (n.isTextblock && n.content.size === 0) { sel = pos + 1; } }); if (sel > -1) { tr2.setSelection(TextSelection.near(tr2.doc.resolve(sel))); } tr2.scrollIntoView(); } return true; } const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null; const newTypeAttributes = { ...getSplittedAttributes(extensionAttributes, grandParent.type.name, grandParent.attrs), ...overrideAttrs }; const newNextTypeAttributes = { ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs), ...overrideAttrs }; tr2.delete($from.pos, $to.pos); const types = nextType ? [ { type, attrs: newTypeAttributes }, { type: nextType, attrs: newNextTypeAttributes } ] : [{ type, attrs: newTypeAttributes }]; if (!canSplit(tr2.doc, $from.pos, 2)) { return false; } if (dispatch) { const { selection, storedMarks } = state; const { splittableMarks } = editor.extensionManager; const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks(); tr2.split($from.pos, 2, types).scrollIntoView(); if (!marks || !dispatch) { return true; } const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name)); tr2.ensureMarks(filteredMarks); } return true; }; var joinListBackwards = (tr2, listType) => { const list = findParentNode((node) => node.type === listType)(tr2.selection); if (!list) { return true; } const before = tr2.doc.resolve(Math.max(0, list.pos - 1)).before(list.depth); if (before === void 0) { return true; } const nodeBefore = tr2.doc.nodeAt(before); const canJoinBackwards = list.node.type === (nodeBefore == null ? void 0 : nodeBefore.type) && canJoin(tr2.doc, list.pos); if (!canJoinBackwards) { return true; } tr2.join(list.pos); return true; }; var joinListForwards = (tr2, listType) => { const list = findParentNode((node) => node.type === listType)(tr2.selection); if (!list) { return true; } const after = tr2.doc.resolve(list.start).after(list.depth); if (after === void 0) { return true; } const nodeAfter = tr2.doc.nodeAt(after); const canJoinForwards = list.node.type === (nodeAfter == null ? void 0 : nodeAfter.type) && canJoin(tr2.doc, after); if (!canJoinForwards) { return true; } tr2.join(after); return true; }; function createInnerSelectionForWholeDocList(tr2) { const doc2 = tr2.doc; const list = doc2.firstChild; if (!list) { return null; } const $start = doc2.resolve(1); const $end = doc2.resolve(list.nodeSize - 1); return TextSelection.between($start, $end); } var toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) => ({ editor, tr: tr2, state, dispatch, chain, commands, can }) => { const { extensions, splittableMarks } = editor.extensionManager; const listType = getNodeType(listTypeOrName, state.schema); const itemType = getNodeType(itemTypeOrName, state.schema); const { selection, storedMarks } = state; const { $from, $to } = selection; const range = $from.blockRange($to); const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks(); if (!range) { return false; } const parentList = findParentNode((node) => isList(node.type.name, extensions))(selection); const isAllSelection = selection.from === 0 && selection.to === state.doc.content.size; const topLevelNodes = state.doc.content.content; const soleTopLevelNode = topLevelNodes.length === 1 ? topLevelNodes[0] : null; const allSelectionList = isAllSelection && soleTopLevelNode && isList(soleTopLevelNode.type.name, extensions) ? { node: soleTopLevelNode, pos: 0 } : null; const currentList = parentList != null ? parentList : allSelectionList; const isInsideExistingList = !!parentList && range.depth >= 1 && range.depth - parentList.depth <= 1; const hasWholeDocSelectedList = !!allSelectionList; if ((isInsideExistingList || hasWholeDocSelectedList) && currentList) { if (currentList.node.type === listType) { if (isAllSelection && hasWholeDocSelectedList) { return chain().command(({ tr: trx, dispatch: disp }) => { const nextSelection = createInnerSelectionForWholeDocList(trx); if (!nextSelection) { return false; } trx.setSelection(nextSelection); if (disp) { disp(trx); } return true; }).liftListItem(itemType).run(); } return commands.liftListItem(itemType); } if (isList(currentList.node.type.name, extensions) && listType.validContent(currentList.node.content)) { return chain().command(() => { tr2.setNodeMarkup(currentList.pos, listType); return true; }).command(() => joinListBackwards(tr2, listType)).command(() => joinListForwards(tr2, listType)).run(); } } if (!keepMarks || !marks || !dispatch) { return chain().command(() => { const canWrapInList = can().wrapInList(listType, attributes); if (canWrapInList) { return true; } return commands.clearNodes(); }).wrapInList(listType, attributes).command(() => joinListBackwards(tr2, listType)).command(() => joinListForwards(tr2, listType)).run(); } return chain().command(() => { const canWrapInList = can().wrapInList(listType, attributes); const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name)); tr2.ensureMarks(filteredMarks); if (canWrapInList) { return true; } return commands.clearNodes(); }).wrapInList(listType, attributes).command(() => joinListBackwards(tr2, listType)).command(() => joinListForwards(tr2, listType)).run(); }; var toggleMark = (typeOrName, attributes = {}, options = {}) => ({ state, commands }) => { const { extendEmptyMarkRange = false } = options; const type = getMarkType(typeOrName, state.schema); const isActive2 = isMarkActive(state, type, attributes); if (isActive2) { return commands.unsetMark(type, { extendEmptyMarkRange }); } return commands.setMark(type, attributes); }; var toggleNode = (typeOrName, toggleTypeOrName, attributes = {}) => ({ state, commands }) => { const type = getNodeType(typeOrName, state.schema); const toggleType = getNodeType(toggleTypeOrName, state.schema); const isActive2 = isNodeActive(state, type, attributes); let attributesToCopy; if (state.selection.$anchor.sameParent(state.selection.$head)) { attributesToCopy = state.selection.$anchor.parent.attrs; } if (isActive2) { return commands.setNode(toggleType, attributesToCopy); } return commands.setNode(type, { ...attributesToCopy, ...attributes }); }; var toggleWrap = (typeOrName, attributes = {}) => ({ state, commands }) => { const type = getNodeType(typeOrName, state.schema); const isActive2 = isNodeActive(state, type, attributes); if (isActive2) { return commands.lift(type); } return commands.wrapIn(type, attributes); }; var undoInputRule = () => ({ state, dispatch }) => { const plugins = state.plugins; for (let i = 0; i < plugins.length; i += 1) { const plugin = plugins[i]; let undoable; if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) { if (dispatch) { const tr2 = state.tr; const toUndo = undoable.transform; for (let j = toUndo.steps.length - 1; j >= 0; j -= 1) { tr2.step(toUndo.steps[j].invert(toUndo.docs[j])); } if (undoable.text) { const marks = tr2.doc.resolve(undoable.from).marks(); tr2.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks)); } else { tr2.delete(undoable.from, undoable.to); } } return true; } } return false; }; var unsetAllMarks = () => ({ tr: tr2, dispatch }) => { const { selection } = tr2; const { empty: empty2, ranges } = selection; if (empty2) { return true; } if (dispatch) { ranges.forEach((range) => { tr2.removeMark(range.$from.pos, range.$to.pos); }); } return true; }; var unsetMark = (typeOrName, options = {}) => ({ tr: tr2, state, dispatch }) => { var _a; const { extendEmptyMarkRange = false } = options; const { selection } = tr2; const type = getMarkType(typeOrName, state.schema); const { $from, empty: empty2, ranges } = selection; if (!dispatch) { return true; } if (empty2 && extendEmptyMarkRange) { let { from: from2, to } = selection; const attrs = (_a = $from.marks().find((mark) => mark.type === type)) == null ? void 0 : _a.attrs; const range = getMarkRange($from, type, attrs); if (range) { from2 = range.from; to = range.to; } tr2.removeMark(from2, to, type); } else { ranges.forEach((range) => { tr2.removeMark(range.$from.pos, range.$to.pos, type); }); } tr2.removeStoredMark(type); return true; }; var unsetTextDirection = (position) => ({ tr: tr2, state, dispatch }) => { const { selection } = state; let from2; let to; if (typeof position === "number") { from2 = position; to = position; } else if (position && "from" in position && "to" in position) { from2 = position.from; to = position.to; } else { from2 = selection.from; to = selection.to; } if (dispatch) { tr2.doc.nodesBetween(from2, to, (node, pos) => { if (node.isText) { return; } const newAttrs = { ...node.attrs }; delete newAttrs.dir; tr2.setNodeMarkup(pos, void 0, newAttrs); }); } return true; }; var updateAttributes = (typeOrName, attributes = {}) => ({ tr: tr2, state, dispatch }) => { let nodeType = null; let markType = null; const schemaType = getSchemaTypeNameByName( typeof typeOrName === "string" ? typeOrName : typeOrName.name, state.schema ); if (!schemaType) { return false; } if (schemaType === "node") { nodeType = getNodeType(typeOrName, state.schema); } if (schemaType === "mark") { markType = getMarkType(typeOrName, state.schema); } let canUpdate = false; tr2.selection.ranges.forEach((range) => { const from2 = range.$from.pos; const to = range.$to.pos; let lastPos; let lastNode; let trimmedFrom; let trimmedTo; if (tr2.selection.empty) { state.doc.nodesBetween(from2, to, (node, pos) => { if (nodeType && nodeType === node.type) { canUpdate = true; trimmedFrom = Math.max(pos, from2); trimmedTo = Math.min(pos + node.nodeSize, to); lastPos = pos; lastNode = node; } }); } else { state.doc.nodesBetween(from2, to, (node, pos) => { if (pos < from2 && nodeType && nodeType === node.type) { canUpdate = true; trimmedFrom = Math.max(pos, from2); trimmedTo = Math.min(pos + node.nodeSize, to); lastPos = pos; lastNode = node; } if (pos >= from2 && pos <= to) { if (nodeType && nodeType === node.type) { canUpdate = true; if (dispatch) { tr2.setNodeMarkup(pos, void 0, { ...node.attrs, ...attributes }); } } if (markType && node.marks.length) { node.marks.forEach((mark) => { if (markType === mark.type) { canUpdate = true; if (dispatch) { const trimmedFrom2 = Math.max(pos, from2); const trimmedTo2 = Math.min(pos + node.nodeSize, to); tr2.addMark( trimmedFrom2, trimmedTo2, markType.create({ ...mark.attrs, ...attributes }) ); } } }); } } }); } if (lastNode) { if (lastPos !== void 0 && dispatch) { tr2.setNodeMarkup(lastPos, void 0, { ...lastNode.attrs, ...attributes }); } if (markType && lastNode.marks.length) { lastNode.marks.forEach((mark) => { if (markType === mark.type && dispatch) { tr2.addMark( trimmedFrom, trimmedTo, markType.create({ ...mark.attrs, ...attributes }) ); } }); } } }); return canUpdate; }; var wrapIn = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema); return wrapIn$1(type, attributes)(state, dispatch); }; var wrapInList = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema); return wrapInList$1(type, attributes)(state, dispatch); }; var EventEmitter = class { constructor() { this.callbacks = {}; } on(event, fn) { if (!this.callbacks[event]) { this.callbacks[event] = []; } this.callbacks[event].push(fn); return this; } emit(event, ...args) { const callbacks = this.callbacks[event]; if (callbacks) { callbacks.forEach((callback) => callback.apply(this, args)); } return this; } off(event, fn) { const callbacks = this.callbacks[event]; if (callbacks) { if (fn) { this.callbacks[event] = callbacks.filter((callback) => callback !== fn); } else { delete this.callbacks[event]; } } return this; } once(event, fn) { const onceFn = (...args) => { this.off(event, onceFn); fn.apply(this, args); }; return this.on(event, onceFn); } removeAllListeners() { this.callbacks = {}; } }; var InputRule = class { constructor(config) { var _a; this.find = config.find; this.handler = config.handler; this.undoable = (_a = config.undoable) != null ? _a : true; } }; var inputRuleMatcherHandler = (text, find2) => { if (isRegExp(find2)) { return find2.exec(text); } const inputRuleMatch = find2(text); if (!inputRuleMatch) { return null; } const result = [inputRuleMatch.text]; result.index = inputRuleMatch.index; result.input = text; result.data = inputRuleMatch.data; if (inputRuleMatch.replaceWith) { if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) { console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'); } result.push(inputRuleMatch.replaceWith); } return result; }; function run$2(config) { var _a; const { editor, from: from2, to, text, rules, plugin } = config; const { view } = editor; if (view.composing) { return false; } const $from = view.state.doc.resolve(from2); if ( // check for code node $from.parent.type.spec.code || // check for code mark !!((_a = $from.nodeBefore || $from.nodeAfter) == null ? void 0 : _a.marks.find((mark) => mark.type.spec.code)) ) { return false; } let matched = false; const textBefore = getTextContentFromNodes($from) + text; rules.forEach((rule) => { if (matched) { return; } const match = inputRuleMatcherHandler(textBefore, rule.find); if (!match) { return; } const tr2 = view.state.tr; const state = createChainableState({ state: view.state, transaction: tr2 }); const range = { from: from2 - (match[0].length - text.length), to }; const { commands, chain, can } = new CommandManager({ editor, state }); const handler = rule.handler({ state, range, match, commands, chain, can }); if (handler === null || !tr2.steps.length) { return; } if (rule.undoable) { tr2.setMeta(plugin, { transform: tr2, from: from2, to, text }); } view.dispatch(tr2); matched = true; }); return matched; } function inputRulesPlugin(props) { const { editor, rules } = props; const plugin = new Plugin({ state: { init() { return null; }, apply(tr2, prev, state) { const stored = tr2.getMeta(plugin); if (stored) { return stored; } const simulatedInputMeta = tr2.getMeta("applyInputRules"); const isSimulatedInput = !!simulatedInputMeta; if (isSimulatedInput) { setTimeout(() => { let { text } = simulatedInputMeta; if (typeof text === "string") { text = text; } else { text = getHTMLFromFragment(Fragment.from(text), state.schema); } const { from: from2 } = simulatedInputMeta; const to = from2 + text.length; run$2({ editor, from: from2, to, text, rules, plugin }); }); } return tr2.selectionSet || tr2.docChanged ? null : prev; } }, props: { handleTextInput(view, from2, to, text) { return run$2({ editor, from: from2, to, text, rules, plugin }); }, handleDOMEvents: { compositionend: (view) => { setTimeout(() => { const { $cursor } = view.state.selection; if ($cursor) { run$2({ editor, from: $cursor.pos, to: $cursor.pos, text: "", rules, plugin }); } }); return false; } }, // add support for input rules to trigger on enter // this is useful for example for code blocks handleKeyDown(view, event) { if (event.key !== "Enter") { return false; } const { $cursor } = view.state.selection; if ($cursor) { return run$2({ editor, from: $cursor.pos, to: $cursor.pos, text: "\n", rules, plugin }); } return false; } }, // @ts-ignore isInputRules: true }); return plugin; } function getType(value) { return Object.prototype.toString.call(value).slice(8, -1); } function isPlainObject(value) { if (getType(value) !== "Object") { return false; } return value.constructor === Object && Object.getPrototypeOf(value) === Object.prototype; } function mergeDeep(target, source) { const output = { ...target }; if (isPlainObject(target) && isPlainObject(source)) { Object.keys(source).forEach((key) => { if (isPlainObject(source[key]) && isPlainObject(target[key])) { output[key] = mergeDeep(target[key], source[key]); } else { output[key] = source[key]; } }); } return output; } var Extendable = class { constructor(config = {}) { this.type = "extendable"; this.parent = null; this.child = null; this.name = ""; this.config = { name: this.name }; this.config = { ...this.config, ...config }; this.name = this.config.name; } get options() { return { ...callOrReturn( getExtensionField(this, "addOptions", { name: this.name }) ) || {} }; } get storage() { return { ...callOrReturn( getExtensionField(this, "addStorage", { name: this.name, options: this.options }) ) || {} }; } configure(options = {}) { const extension = this.extend({ ...this.config, addOptions: () => { return mergeDeep(this.options, options); } }); extension.name = this.name; extension.parent = this.parent; return extension; } extend(extendedConfig = {}) { const extension = new this.constructor({ ...this.config, ...extendedConfig }); extension.parent = this; this.child = extension; extension.name = "name" in extendedConfig ? extendedConfig.name : extension.parent.name; return extension; } }; var Mark2 = class _Mark extends Extendable { constructor() { super(...arguments); this.type = "mark"; } /** * Create a new Mark instance * @param config - Mark configuration object or a function that returns a configuration object */ static create(config = {}) { const resolvedConfig = typeof config === "function" ? config() : config; return new _Mark(resolvedConfig); } static handleExit({ editor, mark }) { const { tr: tr2 } = editor.state; const currentPos = editor.state.selection.$from; const isAtEnd = currentPos.pos === currentPos.end(); if (isAtEnd) { const currentMarks = currentPos.marks(); const isInMark = !!currentMarks.find((m) => (m == null ? void 0 : m.type.name) === mark.name); if (!isInMark) { return false; } const removeMark2 = currentMarks.find((m) => (m == null ? void 0 : m.type.name) === mark.name); if (removeMark2) { tr2.removeStoredMark(removeMark2); } tr2.insertText(" ", currentPos.pos); editor.view.dispatch(tr2); return true; } return false; } configure(options) { return super.configure(options); } extend(extendedConfig) { const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig; return super.extend(resolvedConfig); } }; function isNumber(value) { return typeof value === "number"; } var PasteRule = class { constructor(config) { this.find = config.find; this.handler = config.handler; } }; var pasteRuleMatcherHandler = (text, find2, event) => { if (isRegExp(find2)) { return [...text.matchAll(find2)]; } const matches2 = find2(text, event); if (!matches2) { return []; } return matches2.map((pasteRuleMatch) => { const result = [pasteRuleMatch.text]; result.index = pasteRuleMatch.index; result.input = text; result.data = pasteRuleMatch.data; if (pasteRuleMatch.replaceWith) { if (!pasteRuleMatch.text.includes(pasteRuleMatch.replaceWith)) { console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'); } result.push(pasteRuleMatch.replaceWith); } return result; }); }; function run2(config) { const { editor, state, from: from2, to, rule, pasteEvent, dropEvent } = config; const { commands, chain, can } = new CommandManager({ editor, state }); const handlers2 = []; state.doc.nodesBetween(from2, to, (node, pos) => { var _a, _b, _c, _d, _e; if (((_b = (_a = node.type) == null ? void 0 : _a.spec) == null ? void 0 : _b.code) || !(node.isText || node.isTextblock || node.isInline)) { return; } const contentSize = (_e = (_d = (_c = node.content) == null ? void 0 : _c.size) != null ? _d : node.nodeSize) != null ? _e : 0; const resolvedFrom = Math.max(from2, pos); const resolvedTo = Math.min(to, pos + contentSize); if (resolvedFrom >= resolvedTo) { return; } const textToMatch = node.isText ? node.text || "" : node.textBetween(resolvedFrom - pos, resolvedTo - pos, void 0, ""); const matches2 = pasteRuleMatcherHandler(textToMatch, rule.find, pasteEvent); matches2.forEach((match) => { if (match.index === void 0) { return; } const start = resolvedFrom + match.index + 1; const end = start + match[0].length; const range = { from: state.tr.mapping.map(start), to: state.tr.mapping.map(end) }; const handler = rule.handler({ state, range, match, commands, chain, can, pasteEvent, dropEvent }); handlers2.push(handler); }); }); const success = handlers2.every((handler) => handler !== null); return success; } var tiptapDragFromOtherEditor = null; var createClipboardPasteEvent = (text) => { var _a; const event = new ClipboardEvent("paste", { clipboardData: new DataTransfer() }); (_a = event.clipboardData) == null ? void 0 : _a.setData("text/html", text); return event; }; function pasteRulesPlugin(props) { const { editor, rules } = props; let dragSourceElement = null; let isPastedFromProseMirror = false; let isDroppedFromProseMirror = false; let pasteEvent = typeof ClipboardEvent !== "undefined" ? new ClipboardEvent("paste") : null; let dropEvent; try { dropEvent = typeof DragEvent !== "undefined" ? new DragEvent("drop") : null; } catch { dropEvent = null; } const processEvent = ({ state, from: from2, to, rule, pasteEvt }) => { const tr2 = state.tr; const chainableState = createChainableState({ state, transaction: tr2 }); const handler = run2({ editor, state: chainableState, from: Math.max(from2 - 1, 0), to: to.b - 1, rule, pasteEvent: pasteEvt, dropEvent }); if (!handler || !tr2.steps.length) { return; } try { dropEvent = typeof DragEvent !== "undefined" ? new DragEvent("drop") : null; } catch { dropEvent = null; } pasteEvent = typeof ClipboardEvent !== "undefined" ? new ClipboardEvent("paste") : null; return tr2; }; const plugins = rules.map((rule) => { return new Plugin({ // we register a global drag handler to track the current drag source element view(view) { const handleDragstart = (event) => { var _a; dragSourceElement = ((_a = view.dom.parentElement) == null ? void 0 : _a.contains(event.target)) ? view.dom.parentElement : null; if (dragSourceElement) { tiptapDragFromOtherEditor = editor; } }; const handleDragend = () => { if (tiptapDragFromOtherEditor) { tiptapDragFromOtherEditor = null; } }; window.addEventListener("dragstart", handleDragstart); window.addEventListener("dragend", handleDragend); return { destroy() { window.removeEventListener("dragstart", handleDragstart); window.removeEventListener("dragend", handleDragend); } }; }, props: { handleDOMEvents: { drop: (view, event) => { isDroppedFromProseMirror = dragSourceElement === view.dom.parentElement; dropEvent = event; if (!isDroppedFromProseMirror) { const dragFromOtherEditor = tiptapDragFromOtherEditor; if (dragFromOtherEditor == null ? void 0 : dragFromOtherEditor.isEditable) { setTimeout(() => { const selection = dragFromOtherEditor.state.selection; if (selection) { dragFromOtherEditor.commands.deleteRange({ from: selection.from, to: selection.to }); } }, 10); } } return false; }, paste: (_view, event) => { var _a; const html = (_a = event.clipboardData) == null ? void 0 : _a.getData("text/html"); pasteEvent = event; isPastedFromProseMirror = !!(html == null ? void 0 : html.includes("data-pm-slice")); return false; } } }, appendTransaction: (transactions, oldState, state) => { const transaction = transactions[0]; const isPaste = transaction.getMeta("uiEvent") === "paste" && !isPastedFromProseMirror; const isDrop = transaction.getMeta("uiEvent") === "drop" && !isDroppedFromProseMirror; const simulatedPasteMeta = transaction.getMeta("applyPasteRules"); const isSimulatedPaste = !!simulatedPasteMeta; if (!isPaste && !isDrop && !isSimulatedPaste) { return; } if (isSimulatedPaste) { let { text } = simulatedPasteMeta; if (typeof text === "string") { text = text; } else { text = getHTMLFromFragment(Fragment.from(text), state.schema); } const { from: from22 } = simulatedPasteMeta; const to2 = from22 + text.length; const pasteEvt = createClipboardPasteEvent(text); return processEvent({ rule, state, from: from22, to: { b: to2 }, pasteEvt }); } const from2 = oldState.doc.content.findDiffStart(state.doc.content); const to = oldState.doc.content.findDiffEnd(state.doc.content); if (!isNumber(from2) || !to || from2 === to.b) { return; } return processEvent({ rule, state, from: from2, to, pasteEvt: pasteEvent }); } }); }); return plugins; } var ExtensionManager = class { constructor(extensions, editor) { this.splittableMarks = []; this.editor = editor; this.baseExtensions = extensions; this.extensions = resolveExtensions(extensions); this.schema = getSchemaByResolvedExtensions(this.extensions, editor); this.setupExtensions(); } /** * Get all commands from the extensions. * @returns An object with all commands where the key is the command name and the value is the command function */ get commands() { return this.extensions.reduce((commands, extension) => { const context = { name: extension.name, options: extension.options, storage: this.editor.extensionStorage[extension.name], editor: this.editor, type: getSchemaTypeByName(extension.name, this.schema) }; const addCommands = getExtensionField(extension, "addCommands", context); if (!addCommands) { return commands; } return { ...commands, ...addCommands() }; }, {}); } /** * Get all registered Prosemirror plugins from the extensions. * @returns An array of Prosemirror plugins */ get plugins() { const { editor } = this; const extensions = sortExtensions([...this.extensions].reverse()); const allPlugins = extensions.flatMap((extension) => { const context = { name: extension.name, options: extension.options, storage: this.editor.extensionStorage[extension.name], editor, type: getSchemaTypeByName(extension.name, this.schema) }; const plugins = []; const addKeyboardShortcuts = getExtensionField( extension, "addKeyboardShortcuts", context ); let defaultBindings = {}; if (extension.type === "mark" && getExtensionField(extension, "exitable", context)) { defaultBindings.ArrowRight = () => Mark2.handleExit({ editor, mark: extension }); } if (addKeyboardShortcuts) { const bindings = Object.fromEntries( Object.entries(addKeyboardShortcuts()).map(([shortcut, method]) => { return [shortcut, () => method({ editor })]; }) ); defaultBindings = { ...defaultBindings, ...bindings }; } const keyMapPlugin = keymap(defaultBindings); plugins.push(keyMapPlugin); const addInputRules = getExtensionField(extension, "addInputRules", context); if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) { const rules = addInputRules(); if (rules && rules.length) { const inputResult = inputRulesPlugin({ editor, rules }); const inputPlugins = Array.isArray(inputResult) ? inputResult : [inputResult]; plugins.push(...inputPlugins); } } const addPasteRules = getExtensionField(extension, "addPasteRules", context); if (isExtensionRulesEnabled(extension, editor.options.enablePasteRules) && addPasteRules) { const rules = addPasteRules(); if (rules && rules.length) { const pasteRules = pasteRulesPlugin({ editor, rules }); plugins.push(...pasteRules); } } const addProseMirrorPlugins = getExtensionField( extension, "addProseMirrorPlugins", context ); if (addProseMirrorPlugins) { const proseMirrorPlugins = addProseMirrorPlugins(); plugins.push(...proseMirrorPlugins); } return plugins; }); return allPlugins; } /** * Get all attributes from the extensions. * @returns An array of attributes */ get attributes() { return getAttributesFromExtensions(this.extensions); } /** * Get all node views from the extensions. * @returns An object with all node views where the key is the node name and the value is the node view function */ get nodeViews() { const { editor } = this; const { nodeExtensions } = splitExtensions(this.extensions); return Object.fromEntries( nodeExtensions.filter((extension) => !!getExtensionField(extension, "addNodeView")).map((extension) => { const extensionAttributes = this.attributes.filter((attribute) => attribute.type === extension.name); const context = { name: extension.name, options: extension.options, storage: this.editor.extensionStorage[extension.name], editor, type: getNodeType(extension.name, this.schema) }; const addNodeView = getExtensionField(extension, "addNodeView", context); if (!addNodeView) { return []; } const nodeViewResult = addNodeView(); if (!nodeViewResult) { return []; } const nodeview = (node, view, getPos, decorations, innerDecorations) => { const HTMLAttributes = getRenderedAttributes(node, extensionAttributes); return nodeViewResult({ // pass-through node, view, getPos, decorations, innerDecorations, // tiptap-specific editor, extension, HTMLAttributes }); }; return [extension.name, nodeview]; }) ); } /** * Get the composed dispatchTransaction function from all extensions. * @param baseDispatch The base dispatch function (e.g. from the editor or user props) * @returns A composed dispatch function */ dispatchTransaction(baseDispatch) { const { editor } = this; const extensions = sortExtensions([...this.extensions].reverse()); return extensions.reduceRight((next, extension) => { const context = { name: extension.name, options: extension.options, storage: this.editor.extensionStorage[extension.name], editor, type: getSchemaTypeByName(extension.name, this.schema) }; const dispatchTransaction = getExtensionField( extension, "dispatchTransaction", context ); if (!dispatchTransaction) { return next; } return (transaction) => { dispatchTransaction.call(context, { transaction, next }); }; }, baseDispatch); } /** * Get the composed transformPastedHTML function from all extensions. * @param baseTransform The base transform function (e.g. from the editor props) * @returns A composed transform function that chains all extension transforms */ transformPastedHTML(baseTransform) { const { editor } = this; const extensions = sortExtensions([...this.extensions]); return extensions.reduce( (transform, extension) => { const context = { name: extension.name, options: extension.options, storage: this.editor.extensionStorage[extension.name], editor, type: getSchemaTypeByName(extension.name, this.schema) }; const extensionTransform = getExtensionField( extension, "transformPastedHTML", context ); if (!extensionTransform) { return transform; } return (html, view) => { const transformedHtml = transform(html, view); return extensionTransform.call(context, transformedHtml); }; }, baseTransform || ((html) => html) ); } get markViews() { const { editor } = this; const { markExtensions } = splitExtensions(this.extensions); return Object.fromEntries( markExtensions.filter((extension) => !!getExtensionField(extension, "addMarkView")).map((extension) => { const extensionAttributes = this.attributes.filter((attribute) => attribute.type === extension.name); const context = { name: extension.name, options: extension.options, storage: this.editor.extensionStorage[extension.name], editor, type: getMarkType(extension.name, this.schema) }; const addMarkView = getExtensionField(extension, "addMarkView", context); if (!addMarkView) { return []; } const markView = (mark, view, inline2) => { const HTMLAttributes = getRenderedAttributes(mark, extensionAttributes); return addMarkView()({ // pass-through mark, view, inline: inline2, // tiptap-specific editor, extension, HTMLAttributes, updateAttributes: (attrs) => { updateMarkViewAttributes(mark, editor, attrs); } }); }; return [extension.name, markView]; }) ); } /** * Go through all extensions, create extension storages & setup marks * & bind editor event listener. */ setupExtensions() { const extensions = this.extensions; this.editor.extensionStorage = Object.fromEntries( extensions.map((extension) => [extension.name, extension.storage]) ); extensions.forEach((extension) => { var _a; const context = { name: extension.name, options: extension.options, storage: this.editor.extensionStorage[extension.name], editor: this.editor, type: getSchemaTypeByName(extension.name, this.schema) }; if (extension.type === "mark") { const keepOnSplit = (_a = callOrReturn(getExtensionField(extension, "keepOnSplit", context))) != null ? _a : true; if (keepOnSplit) { this.splittableMarks.push(extension.name); } } const onBeforeCreate = getExtensionField(extension, "onBeforeCreate", context); const onCreate = getExtensionField(extension, "onCreate", context); const onUpdate = getExtensionField(extension, "onUpdate", context); const onSelectionUpdate = getExtensionField( extension, "onSelectionUpdate", context ); const onTransaction = getExtensionField(extension, "onTransaction", context); const onFocus = getExtensionField(extension, "onFocus", context); const onBlur = getExtensionField(extension, "onBlur", context); const onDestroy = getExtensionField(extension, "onDestroy", context); if (onBeforeCreate) { this.editor.on("beforeCreate", onBeforeCreate); } if (onCreate) { this.editor.on("create", onCreate); } if (onUpdate) { this.editor.on("update", onUpdate); } if (onSelectionUpdate) { this.editor.on("selectionUpdate", onSelectionUpdate); } if (onTransaction) { this.editor.on("transaction", onTransaction); } if (onFocus) { this.editor.on("focus", onFocus); } if (onBlur) { this.editor.on("blur", onBlur); } if (onDestroy) { this.editor.on("destroy", onDestroy); } }); } }; ExtensionManager.resolve = resolveExtensions; ExtensionManager.sort = sortExtensions; ExtensionManager.flatten = flattenExtensions; var extensions_exports = {}; __export$1(extensions_exports, { ClipboardTextSerializer: () => ClipboardTextSerializer, Commands: () => Commands, Delete: () => Delete, Drop: () => Drop, Editable: () => Editable, FocusEvents: () => FocusEvents, Keymap: () => Keymap, Paste: () => Paste, Tabindex: () => Tabindex, TextDirection: () => TextDirection, focusEventsPluginKey: () => focusEventsPluginKey }); var Extension = class _Extension extends Extendable { constructor() { super(...arguments); this.type = "extension"; } /** * Create a new Extension instance * @param config - Extension configuration object or a function that returns a configuration object */ static create(config = {}) { const resolvedConfig = typeof config === "function" ? config() : config; return new _Extension(resolvedConfig); } configure(options) { return super.configure(options); } extend(extendedConfig) { const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig; return super.extend(resolvedConfig); } }; var ClipboardTextSerializer = Extension.create({ name: "clipboardTextSerializer", addOptions() { return { blockSeparator: void 0 }; }, addProseMirrorPlugins() { return [ new Plugin({ key: new PluginKey("clipboardTextSerializer"), props: { clipboardTextSerializer: () => { const { editor } = this; const { state, schema } = editor; const { doc: doc2, selection } = state; const { ranges } = selection; const from2 = Math.min(...ranges.map((range2) => range2.$from.pos)); const to = Math.max(...ranges.map((range2) => range2.$to.pos)); const textSerializers = getTextSerializersFromSchema(schema); const range = { from: from2, to }; return getTextBetween(doc2, range, { ...this.options.blockSeparator !== void 0 ? { blockSeparator: this.options.blockSeparator } : {}, textSerializers }); } } }) ]; } }); var Commands = Extension.create({ name: "commands", addCommands() { return { ...commands_exports }; } }); var Delete = Extension.create({ name: "delete", onUpdate({ transaction, appendedTransactions }) { var _a, _b, _c; const callback = () => { var _a2, _b2, _c2, _d; if ((_d = (_c2 = (_b2 = (_a2 = this.editor.options.coreExtensionOptions) == null ? void 0 : _a2.delete) == null ? void 0 : _b2.filterTransaction) == null ? void 0 : _c2.call(_b2, transaction)) != null ? _d : transaction.getMeta("y-sync$")) { return; } const nextTransaction = combineTransactionSteps(transaction.before, [transaction, ...appendedTransactions]); const changes = getChangedRanges(nextTransaction); changes.forEach((change) => { if (nextTransaction.mapping.mapResult(change.oldRange.from).deletedAfter && nextTransaction.mapping.mapResult(change.oldRange.to).deletedBefore) { nextTransaction.before.nodesBetween(change.oldRange.from, change.oldRange.to, (node, from2) => { const to = from2 + node.nodeSize - 2; const isFullyWithinRange = change.oldRange.from <= from2 && to <= change.oldRange.to; this.editor.emit("delete", { type: "node", node, from: from2, to, newFrom: nextTransaction.mapping.map(from2), newTo: nextTransaction.mapping.map(to), deletedRange: change.oldRange, newRange: change.newRange, partial: !isFullyWithinRange, editor: this.editor, transaction, combinedTransform: nextTransaction }); }); } }); const mapping = nextTransaction.mapping; nextTransaction.steps.forEach((step, index) => { var _a3, _b3; if (step instanceof RemoveMarkStep) { const newStart = mapping.slice(index).map(step.from, -1); const newEnd = mapping.slice(index).map(step.to); const oldStart = mapping.invert().map(newStart, -1); const oldEnd = mapping.invert().map(newEnd); const foundBeforeMark = newStart > 0 ? (_a3 = nextTransaction.doc.nodeAt(newStart - 1)) == null ? void 0 : _a3.marks.some((mark) => mark.eq(step.mark)) : false; const foundAfterMark = (_b3 = nextTransaction.doc.nodeAt(newEnd)) == null ? void 0 : _b3.marks.some((mark) => mark.eq(step.mark)); this.editor.emit("delete", { type: "mark", mark: step.mark, from: step.from, to: step.to, deletedRange: { from: oldStart, to: oldEnd }, newRange: { from: newStart, to: newEnd }, partial: Boolean(foundAfterMark || foundBeforeMark), editor: this.editor, transaction, combinedTransform: nextTransaction }); } }); }; if ((_c = (_b = (_a = this.editor.options.coreExtensionOptions) == null ? void 0 : _a.delete) == null ? void 0 : _b.async) != null ? _c : true) { setTimeout(callback, 0); } else { callback(); } } }); var Drop = Extension.create({ name: "drop", addProseMirrorPlugins() { return [ new Plugin({ key: new PluginKey("tiptapDrop"), props: { handleDrop: (_, e, slice2, moved) => { this.editor.emit("drop", { editor: this.editor, event: e, slice: slice2, moved }); } } }) ]; } }); var Editable = Extension.create({ name: "editable", addProseMirrorPlugins() { return [ new Plugin({ key: new PluginKey("editable"), props: { editable: () => this.editor.options.editable } }) ]; } }); var focusEventsPluginKey = new PluginKey("focusEvents"); var FocusEvents = Extension.create({ name: "focusEvents", addProseMirrorPlugins() { const { editor } = this; return [ new Plugin({ key: focusEventsPluginKey, props: { handleDOMEvents: { focus: (view, event) => { editor.isFocused = true; const transaction = editor.state.tr.setMeta("focus", { event }).setMeta("addToHistory", false); view.dispatch(transaction); return false; }, blur: (view, event) => { editor.isFocused = false; const transaction = editor.state.tr.setMeta("blur", { event }).setMeta("addToHistory", false); view.dispatch(transaction); return false; } } } }) ]; } }); var Keymap = Extension.create({ name: "keymap", addKeyboardShortcuts() { const handleBackspace2 = () => this.editor.commands.first(({ commands }) => [ () => commands.undoInputRule(), // maybe convert first text block node to default node () => commands.command(({ tr: tr2 }) => { const { selection, doc: doc2 } = tr2; const { empty: empty2, $anchor } = selection; const { pos, parent } = $anchor; const $parentPos = $anchor.parent.isTextblock && pos > 0 ? tr2.doc.resolve(pos - 1) : $anchor; const parentIsIsolating = $parentPos.parent.type.spec.isolating; const parentPos = $anchor.pos - $anchor.parentOffset; const isAtStart = parentIsIsolating && $parentPos.parent.childCount === 1 ? parentPos === $anchor.pos : Selection.atStart(doc2).from === pos; if (!empty2 || !parent.type.isTextblock || parent.textContent.length || !isAtStart || isAtStart && $anchor.parent.type.name === "paragraph") { return false; } return commands.clearNodes(); }), () => commands.deleteSelection(), () => commands.joinBackward(), () => commands.selectNodeBackward() ]); const handleDelete2 = () => this.editor.commands.first(({ commands }) => [ () => commands.deleteSelection(), () => commands.deleteCurrentNode(), () => commands.joinForward(), () => commands.selectNodeForward() ]); const handleEnter = () => this.editor.commands.first(({ commands }) => [ () => commands.newlineInCode(), () => commands.createParagraphNear(), () => commands.liftEmptyBlock(), () => commands.splitBlock() ]); const baseKeymap = { Enter: handleEnter, "Mod-Enter": () => this.editor.commands.exitCode(), Backspace: handleBackspace2, "Mod-Backspace": handleBackspace2, "Shift-Backspace": handleBackspace2, Delete: handleDelete2, "Mod-Delete": handleDelete2, "Mod-a": () => this.editor.commands.selectAll() }; const pcKeymap = { ...baseKeymap }; const macKeymap = { ...baseKeymap, "Ctrl-h": handleBackspace2, "Alt-Backspace": handleBackspace2, "Ctrl-d": handleDelete2, "Ctrl-Alt-Backspace": handleDelete2, "Alt-Delete": handleDelete2, "Alt-d": handleDelete2, "Ctrl-a": () => this.editor.commands.selectTextblockStart(), "Ctrl-e": () => this.editor.commands.selectTextblockEnd() }; if (isiOS() || isMacOS()) { return macKeymap; } return pcKeymap; }, addProseMirrorPlugins() { return [ // With this plugin we check if the whole document was selected and deleted. // In this case we will additionally call `clearNodes()` to convert e.g. a heading // to a paragraph if necessary. // This is an alternative to ProseMirror's `AllSelection`, which doesn’t work well // with many other commands. new Plugin({ key: new PluginKey("clearDocument"), appendTransaction: (transactions, oldState, newState) => { if (transactions.some((tr22) => tr22.getMeta("composition"))) { return; } const docChanges = transactions.some((transaction) => transaction.docChanged) && !oldState.doc.eq(newState.doc); const ignoreTr = transactions.some((transaction) => transaction.getMeta("preventClearDocument")); if (!docChanges || ignoreTr) { return; } const { empty: empty2, from: from2, to } = oldState.selection; const allFrom = Selection.atStart(oldState.doc).from; const allEnd = Selection.atEnd(oldState.doc).to; const allWasSelected = from2 === allFrom && to === allEnd; if (empty2 || !allWasSelected) { return; } const isEmpty2 = isNodeEmpty(newState.doc); if (!isEmpty2) { return; } const tr2 = newState.tr; const state = createChainableState({ state: newState, transaction: tr2 }); const { commands } = new CommandManager({ editor: this.editor, state }); commands.clearNodes(); if (!tr2.steps.length) { return; } return tr2; } }) ]; } }); var Paste = Extension.create({ name: "paste", addProseMirrorPlugins() { return [ new Plugin({ key: new PluginKey("tiptapPaste"), props: { handlePaste: (_view, e, slice2) => { this.editor.emit("paste", { editor: this.editor, event: e, slice: slice2 }); } } }) ]; } }); var Tabindex = Extension.create({ name: "tabindex", addProseMirrorPlugins() { return [ new Plugin({ key: new PluginKey("tabindex"), props: { attributes: () => this.editor.isEditable ? { tabindex: "0" } : {} } }) ]; } }); var TextDirection = Extension.create({ name: "textDirection", addOptions() { return { direction: void 0 }; }, addGlobalAttributes() { if (!this.options.direction) { return []; } const { nodeExtensions } = splitExtensions(this.extensions); return [ { types: nodeExtensions.filter((extension) => extension.name !== "text").map((extension) => extension.name), attributes: { dir: { default: this.options.direction, parseHTML: (element) => { const dir = element.getAttribute("dir"); if (dir && (dir === "ltr" || dir === "rtl" || dir === "auto")) { return dir; } return this.options.direction; }, renderHTML: (attributes) => { if (!attributes.dir) { return {}; } return { dir: attributes.dir }; } } } } ]; }, addProseMirrorPlugins() { return [ new Plugin({ key: new PluginKey("textDirection"), props: { attributes: () => { const direction = this.options.direction; if (!direction) { return {}; } return { dir: direction }; } } }) ]; } }); var NodePos = class _NodePos { constructor(pos, editor, isBlock = false, node = null) { this.currentNode = null; this.actualDepth = null; this.isBlock = isBlock; this.resolvedPos = pos; this.editor = editor; this.currentNode = node; } get name() { return this.node.type.name; } get node() { return this.currentNode || this.resolvedPos.node(); } get element() { return this.editor.view.domAtPos(this.pos).node; } get depth() { var _a; return (_a = this.actualDepth) != null ? _a : this.resolvedPos.depth; } get pos() { return this.resolvedPos.pos; } get content() { return this.node.content; } set content(content) { let from2 = this.from; let to = this.to; if (this.isBlock) { if (this.content.size === 0) { console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`); return; } from2 = this.from + 1; to = this.to - 1; } this.editor.commands.insertContentAt({ from: from2, to }, content); } get attributes() { return this.node.attrs; } get textContent() { return this.node.textContent; } get size() { return this.node.nodeSize; } get from() { if (this.isBlock) { return this.pos; } return this.resolvedPos.start(this.resolvedPos.depth); } get range() { return { from: this.from, to: this.to }; } get to() { if (this.isBlock) { return this.pos + this.size; } return this.resolvedPos.end(this.resolvedPos.depth) + (this.node.isText ? 0 : 1); } get parent() { if (this.depth === 0) { return null; } const parentPos = this.resolvedPos.start(this.resolvedPos.depth - 1); const $pos = this.resolvedPos.doc.resolve(parentPos); return new _NodePos($pos, this.editor); } get before() { let $pos = this.resolvedPos.doc.resolve(this.from - (this.isBlock ? 1 : 2)); if ($pos.depth !== this.depth) { $pos = this.resolvedPos.doc.resolve(this.from - 3); } return new _NodePos($pos, this.editor); } get after() { let $pos = this.resolvedPos.doc.resolve(this.to + (this.isBlock ? 2 : 1)); if ($pos.depth !== this.depth) { $pos = this.resolvedPos.doc.resolve(this.to + 3); } return new _NodePos($pos, this.editor); } get children() { const children = []; this.node.content.forEach((node, offset2) => { const isBlock = node.isBlock && !node.isTextblock; const isNonTextAtom = node.isAtom && !node.isText; const isInline2 = node.isInline; const targetPos = this.pos + offset2 + (isNonTextAtom ? 0 : 1); if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) { return; } const $pos = this.resolvedPos.doc.resolve(targetPos); if (!isBlock && !isInline2 && $pos.depth <= this.depth) { return; } const childNodePos = new _NodePos($pos, this.editor, isBlock, isBlock || isInline2 ? node : null); if (isBlock) { childNodePos.actualDepth = this.depth + 1; } children.push(childNodePos); }); return children; } get firstChild() { return this.children[0] || null; } get lastChild() { const children = this.children; return children[children.length - 1] || null; } closest(selector, attributes = {}) { let node = null; let currentNode = this.parent; while (currentNode && !node) { if (currentNode.node.type.name === selector) { if (Object.keys(attributes).length > 0) { const nodeAttributes = currentNode.node.attrs; const attrKeys = Object.keys(attributes); for (let index = 0; index < attrKeys.length; index += 1) { const key = attrKeys[index]; if (nodeAttributes[key] !== attributes[key]) { break; } } } else { node = currentNode; } } currentNode = currentNode.parent; } return node; } querySelector(selector, attributes = {}) { return this.querySelectorAll(selector, attributes, true)[0] || null; } querySelectorAll(selector, attributes = {}, firstItemOnly = false) { let nodes = []; if (!this.children || this.children.length === 0) { return nodes; } const attrKeys = Object.keys(attributes); this.children.forEach((childPos) => { if (firstItemOnly && nodes.length > 0) { return; } if (childPos.node.type.name === selector) { const doesAllAttributesMatch = attrKeys.every((key) => attributes[key] === childPos.node.attrs[key]); if (doesAllAttributesMatch) { nodes.push(childPos); } } if (firstItemOnly && nodes.length > 0) { return; } nodes = nodes.concat(childPos.querySelectorAll(selector, attributes, firstItemOnly)); }); return nodes; } setAttribute(attributes) { const { tr: tr2 } = this.editor.state; tr2.setNodeMarkup(this.from, void 0, { ...this.node.attrs, ...attributes }); this.editor.view.dispatch(tr2); } }; var style = `.ProseMirror { position: relative; } .ProseMirror { word-wrap: break-word; white-space: pre-wrap; white-space: break-spaces; -webkit-font-variant-ligatures: none; font-variant-ligatures: none; font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */ } .ProseMirror [contenteditable="false"] { white-space: normal; } .ProseMirror [contenteditable="false"] [contenteditable="true"] { white-space: pre-wrap; } .ProseMirror pre { white-space: pre-wrap; } img.ProseMirror-separator { display: inline !important; border: none !important; margin: 0 !important; width: 0 !important; height: 0 !important; } .ProseMirror-gapcursor { display: none; pointer-events: none; position: absolute; margin: 0; } .ProseMirror-gapcursor:after { content: ""; display: block; position: absolute; top: -2px; width: 20px; border-top: 1px solid black; animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite; } @keyframes ProseMirror-cursor-blink { to { visibility: hidden; } } .ProseMirror-hideselection *::selection { background: transparent; } .ProseMirror-hideselection *::-moz-selection { background: transparent; } .ProseMirror-hideselection * { caret-color: transparent; } .ProseMirror-focused .ProseMirror-gapcursor { display: block; }`; function createStyleTag(style2, nonce, suffix) { const tiptapStyleTag = document.querySelector(`style[data-tiptap-style${""}]`); if (tiptapStyleTag !== null) { return tiptapStyleTag; } const styleNode = document.createElement("style"); if (nonce) { styleNode.setAttribute("nonce", nonce); } styleNode.setAttribute(`data-tiptap-style${""}`, ""); styleNode.innerHTML = style2; document.getElementsByTagName("head")[0].appendChild(styleNode); return styleNode; } var Editor = class extends EventEmitter { constructor(options = {}) { super(); this.css = null; this.className = "tiptap"; this.editorView = null; this.isFocused = false; this.isInitialized = false; this.extensionStorage = {}; this.instanceId = Math.random().toString(36).slice(2, 9); this.options = { element: typeof document !== "undefined" ? document.createElement("div") : null, content: "", injectCSS: true, injectNonce: void 0, extensions: [], autofocus: false, editable: true, textDirection: void 0, editorProps: {}, parseOptions: {}, coreExtensionOptions: {}, enableInputRules: true, enablePasteRules: true, enableCoreExtensions: true, enableContentCheck: false, emitContentError: false, onBeforeCreate: () => null, onCreate: () => null, onMount: () => null, onUnmount: () => null, onUpdate: () => null, onSelectionUpdate: () => null, onTransaction: () => null, onFocus: () => null, onBlur: () => null, onDestroy: () => null, onContentError: ({ error }) => { throw error; }, onPaste: () => null, onDrop: () => null, onDelete: () => null, enableExtensionDispatchTransaction: true }; this.isCapturingTransaction = false; this.capturedTransaction = null; this.utils = { getUpdatedPosition, createMappablePosition }; this.setOptions(options); this.createExtensionManager(); this.createCommandManager(); this.createSchema(); this.on("beforeCreate", this.options.onBeforeCreate); this.emit("beforeCreate", { editor: this }); this.on("mount", this.options.onMount); this.on("unmount", this.options.onUnmount); this.on("contentError", this.options.onContentError); this.on("create", this.options.onCreate); this.on("update", this.options.onUpdate); this.on("selectionUpdate", this.options.onSelectionUpdate); this.on("transaction", this.options.onTransaction); this.on("focus", this.options.onFocus); this.on("blur", this.options.onBlur); this.on("destroy", this.options.onDestroy); this.on("drop", ({ event, slice: slice2, moved }) => this.options.onDrop(event, slice2, moved)); this.on("paste", ({ event, slice: slice2 }) => this.options.onPaste(event, slice2)); this.on("delete", this.options.onDelete); const initialDoc = this.createDoc(); const selection = resolveFocusPosition(initialDoc, this.options.autofocus); this.editorState = EditorState.create({ doc: initialDoc, schema: this.schema, selection: selection || void 0 }); if (this.options.element) { this.mount(this.options.element); } } /** * Attach the editor to the DOM, creating a new editor view. */ mount(el) { if (typeof document === "undefined") { throw new Error( `[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.` ); } this.createView(el); this.emit("mount", { editor: this }); if (this.css && !document.head.contains(this.css)) { document.head.appendChild(this.css); } window.setTimeout(() => { if (this.isDestroyed) { return; } if (this.options.autofocus !== false && this.options.autofocus !== null) { this.commands.focus(this.options.autofocus); } this.emit("create", { editor: this }); this.isInitialized = true; }, 0); } /** * Remove the editor from the DOM, but still allow remounting at a different point in time */ unmount() { if (this.editorView) { const dom = this.editorView.dom; if (dom == null ? void 0 : dom.editor) { delete dom.editor; } this.editorView.destroy(); } this.editorView = null; this.isInitialized = false; if (this.css && !document.querySelectorAll(`.${this.className}`).length) { try { if (typeof this.css.remove === "function") { this.css.remove(); } else if (this.css.parentNode) { this.css.parentNode.removeChild(this.css); } } catch (error) { console.warn("Failed to remove CSS element:", error); } } this.css = null; this.emit("unmount", { editor: this }); } /** * Returns the editor storage. */ get storage() { return this.extensionStorage; } /** * An object of all registered commands. */ get commands() { return this.commandManager.commands; } /** * Create a command chain to call multiple commands at once. */ chain() { return this.commandManager.chain(); } /** * Check if a command or a command chain can be executed. Without executing it. */ can() { return this.commandManager.can(); } /** * Inject CSS styles. */ injectCSS() { if (this.options.injectCSS && typeof document !== "undefined") { this.css = createStyleTag(style, this.options.injectNonce); } } /** * Update editor options. * * @param options A list of options */ setOptions(options = {}) { this.options = { ...this.options, ...options }; if (!this.editorView || !this.state || this.isDestroyed) { return; } if (this.options.editorProps) { this.view.setProps(this.options.editorProps); } this.view.updateState(this.state); } /** * Update editable state of the editor. */ setEditable(editable, emitUpdate = true) { this.setOptions({ editable }); if (emitUpdate) { this.emit("update", { editor: this, transaction: this.state.tr, appendedTransactions: [] }); } } /** * Returns whether the editor is editable. */ get isEditable() { return this.options.editable && this.view && this.view.editable; } /** * Returns the editor view. */ get view() { if (this.editorView) { return this.editorView; } return new Proxy( { state: this.editorState, updateState: (state) => { this.editorState = state; }, dispatch: (tr2) => { this.dispatchTransaction(tr2); }, // Stub some commonly accessed properties to prevent errors composing: false, dragging: null, editable: true, isDestroyed: false }, { get: (obj, key) => { if (this.editorView) { return this.editorView[key]; } if (key === "state") { return this.editorState; } if (key in obj) { return Reflect.get(obj, key); } throw new Error( `[tiptap error]: The editor view is not available. Cannot access view['${key}']. The editor may not be mounted yet.` ); } } ); } /** * Returns the editor state. */ get state() { if (this.editorView) { this.editorState = this.view.state; } return this.editorState; } /** * Register a ProseMirror plugin. * * @param plugin A ProseMirror plugin * @param handlePlugins Control how to merge the plugin into the existing plugins. * @returns The new editor state */ registerPlugin(plugin, handlePlugins) { const plugins = isFunction(handlePlugins) ? handlePlugins(plugin, [...this.state.plugins]) : [...this.state.plugins, plugin]; const state = this.state.reconfigure({ plugins }); this.view.updateState(state); return state; } /** * Unregister a ProseMirror plugin. * * @param nameOrPluginKeyToRemove The plugins name * @returns The new editor state or undefined if the editor is destroyed */ unregisterPlugin(nameOrPluginKeyToRemove) { if (this.isDestroyed) { return void 0; } const prevPlugins = this.state.plugins; let plugins = prevPlugins; [].concat(nameOrPluginKeyToRemove).forEach((nameOrPluginKey) => { const name = typeof nameOrPluginKey === "string" ? `${nameOrPluginKey}$` : nameOrPluginKey.key; plugins = plugins.filter((plugin) => !plugin.key.startsWith(name)); }); if (prevPlugins.length === plugins.length) { return void 0; } const state = this.state.reconfigure({ plugins }); this.view.updateState(state); return state; } /** * Creates an extension manager. */ createExtensionManager() { var _a, _b; const coreExtensions = this.options.enableCoreExtensions ? [ Editable, ClipboardTextSerializer.configure({ blockSeparator: (_b = (_a = this.options.coreExtensionOptions) == null ? void 0 : _a.clipboardTextSerializer) == null ? void 0 : _b.blockSeparator }), Commands, FocusEvents, Keymap, Tabindex, Drop, Paste, Delete, TextDirection.configure({ direction: this.options.textDirection }) ].filter((ext) => { if (typeof this.options.enableCoreExtensions === "object") { return this.options.enableCoreExtensions[ext.name] !== false; } return true; }) : []; const allExtensions = [...coreExtensions, ...this.options.extensions].filter((extension) => { return ["extension", "node", "mark"].includes(extension == null ? void 0 : extension.type); }); this.extensionManager = new ExtensionManager(allExtensions, this); } /** * Creates an command manager. */ createCommandManager() { this.commandManager = new CommandManager({ editor: this }); } /** * Creates a ProseMirror schema. */ createSchema() { this.schema = this.extensionManager.schema; } /** * Creates the initial document. */ createDoc() { let doc2; try { doc2 = createDocument(this.options.content, this.schema, this.options.parseOptions, { errorOnInvalidContent: this.options.enableContentCheck }); } catch (e) { if (!(e instanceof Error) || !["[tiptap error]: Invalid JSON content", "[tiptap error]: Invalid HTML content"].includes(e.message)) { throw e; } this.emit("contentError", { editor: this, error: e, disableCollaboration: () => { if ("collaboration" in this.storage && typeof this.storage.collaboration === "object" && this.storage.collaboration) { this.storage.collaboration.isDisabled = true; } this.options.extensions = this.options.extensions.filter((extension) => extension.name !== "collaboration"); this.createExtensionManager(); } }); doc2 = createDocument(this.options.content, this.schema, this.options.parseOptions, { errorOnInvalidContent: false }); } return doc2; } /** * Creates a ProseMirror view. */ createView(element) { const { editorProps, enableExtensionDispatchTransaction } = this.options; const baseDispatch = editorProps.dispatchTransaction || this.dispatchTransaction.bind(this); const dispatch = enableExtensionDispatchTransaction ? this.extensionManager.dispatchTransaction(baseDispatch) : baseDispatch; const baseTransformPastedHTML = editorProps.transformPastedHTML; const transformPastedHTML = this.extensionManager.transformPastedHTML(baseTransformPastedHTML); this.editorView = new EditorView(element, { ...editorProps, attributes: { // add `role="textbox"` to the editor element role: "textbox", ...editorProps == null ? void 0 : editorProps.attributes }, dispatchTransaction: dispatch, transformPastedHTML, state: this.editorState, markViews: this.extensionManager.markViews, nodeViews: this.extensionManager.nodeViews }); const newState = this.state.reconfigure({ plugins: this.extensionManager.plugins }); this.view.updateState(newState); this.prependClass(); this.injectCSS(); const dom = this.view.dom; dom.editor = this; } /** * Creates all node and mark views. */ createNodeViews() { if (this.view.isDestroyed) { return; } this.view.setProps({ markViews: this.extensionManager.markViews, nodeViews: this.extensionManager.nodeViews }); } /** * Prepend class name to element. */ prependClass() { this.view.dom.className = `${this.className} ${this.view.dom.className}`; } captureTransaction(fn) { this.isCapturingTransaction = true; fn(); this.isCapturingTransaction = false; const tr2 = this.capturedTransaction; this.capturedTransaction = null; return tr2; } /** * The callback over which to send transactions (state updates) produced by the view. * * @param transaction An editor state transaction */ dispatchTransaction(transaction) { if (this.view.isDestroyed) { return; } if (this.isCapturingTransaction) { if (!this.capturedTransaction) { this.capturedTransaction = transaction; return; } transaction.steps.forEach((step) => { var _a; return (_a = this.capturedTransaction) == null ? void 0 : _a.step(step); }); return; } const { state, transactions } = this.state.applyTransaction(transaction); const selectionHasChanged = !this.state.selection.eq(state.selection); const rootTrWasApplied = transactions.includes(transaction); const prevState = this.state; this.emit("beforeTransaction", { editor: this, transaction, nextState: state }); if (!rootTrWasApplied) { return; } this.view.updateState(state); this.emit("transaction", { editor: this, transaction, appendedTransactions: transactions.slice(1) }); if (selectionHasChanged) { this.emit("selectionUpdate", { editor: this, transaction }); } const mostRecentFocusTr = transactions.findLast((tr2) => tr2.getMeta("focus") || tr2.getMeta("blur")); const focus2 = mostRecentFocusTr == null ? void 0 : mostRecentFocusTr.getMeta("focus"); const blur2 = mostRecentFocusTr == null ? void 0 : mostRecentFocusTr.getMeta("blur"); if (focus2) { this.emit("focus", { editor: this, event: focus2.event, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion transaction: mostRecentFocusTr }); } if (blur2) { this.emit("blur", { editor: this, event: blur2.event, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion transaction: mostRecentFocusTr }); } if (transaction.getMeta("preventUpdate") || !transactions.some((tr2) => tr2.docChanged) || prevState.doc.eq(state.doc)) { return; } this.emit("update", { editor: this, transaction, appendedTransactions: transactions.slice(1) }); } /** * Get attributes of the currently selected node or mark. */ getAttributes(nameOrType) { return getAttributes(this.state, nameOrType); } isActive(nameOrAttributes, attributesOrUndefined) { const name = typeof nameOrAttributes === "string" ? nameOrAttributes : null; const attributes = typeof nameOrAttributes === "string" ? attributesOrUndefined : nameOrAttributes; return isActive(this.state, name, attributes); } /** * Get the document as JSON. */ getJSON() { return this.state.doc.toJSON(); } /** * Get the document as HTML. */ getHTML() { return getHTMLFromFragment(this.state.doc.content, this.schema); } /** * Get the document as text. */ getText(options) { const { blockSeparator = "\n\n", textSerializers = {} } = options || {}; return getText(this.state.doc, { blockSeparator, textSerializers: { ...getTextSerializersFromSchema(this.schema), ...textSerializers } }); } /** * Check if there is no content. */ get isEmpty() { return isNodeEmpty(this.state.doc); } /** * Destroy the editor. */ destroy() { this.emit("destroy"); this.unmount(); this.removeAllListeners(); } /** * Check if the editor is already destroyed. */ get isDestroyed() { var _a, _b; return (_b = (_a = this.editorView) == null ? void 0 : _a.isDestroyed) != null ? _b : true; } $node(selector, attributes) { var _a; return ((_a = this.$doc) == null ? void 0 : _a.querySelector(selector, attributes)) || null; } $nodes(selector, attributes) { var _a; return ((_a = this.$doc) == null ? void 0 : _a.querySelectorAll(selector, attributes)) || null; } $pos(pos) { const $pos = this.state.doc.resolve(pos); return new NodePos($pos, this); } get $doc() { return this.$pos(0); } }; function markInputRule(config) { return new InputRule({ find: config.find, handler: ({ state, range, match }) => { const attributes = callOrReturn(config.getAttributes, void 0, match); if (attributes === false || attributes === null) { return null; } const { tr: tr2 } = state; const captureGroup = match[match.length - 1]; const fullMatch = match[0]; if (captureGroup) { const startSpaces = fullMatch.search(/\S/); const textStart = range.from + fullMatch.indexOf(captureGroup); const textEnd = textStart + captureGroup.length; const excludedMarks = getMarksBetween(range.from, range.to, state.doc).filter((item) => { const excluded = item.mark.type.excluded; return excluded.find((type) => type === config.type && type !== item.mark.type); }).filter((item) => item.to > textStart); if (excludedMarks.length) { return null; } if (textEnd < range.to) { tr2.delete(textEnd, range.to); } if (textStart > range.from) { tr2.delete(range.from + startSpaces, textStart); } const markEnd = range.from + startSpaces + captureGroup.length; tr2.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {})); tr2.removeStoredMark(config.type); } }, undoable: config.undoable }); } function nodeInputRule(config) { return new InputRule({ find: config.find, handler: ({ state, range, match }) => { const attributes = callOrReturn(config.getAttributes, void 0, match) || {}; const { tr: tr2 } = state; const start = range.from; let end = range.to; const newNode = config.type.create(attributes); if (match[1]) { const offset2 = match[0].lastIndexOf(match[1]); let matchStart = start + offset2; if (matchStart > end) { matchStart = end; } else { end = matchStart + match[1].length; } const lastChar = match[0][match[0].length - 1]; tr2.insertText(lastChar, start + match[0].length - 1); tr2.replaceWith(matchStart, end, newNode); } else if (match[0]) { const insertionStart = config.type.isInline ? start : start - 1; tr2.insert(insertionStart, config.type.create(attributes)).delete(tr2.mapping.map(start), tr2.mapping.map(end)); } tr2.scrollIntoView(); }, undoable: config.undoable }); } function textblockTypeInputRule(config) { return new InputRule({ find: config.find, handler: ({ state, range, match }) => { const $start = state.doc.resolve(range.from); const attributes = callOrReturn(config.getAttributes, void 0, match) || {}; if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), config.type)) { return null; } state.tr.delete(range.from, range.to).setBlockType(range.from, range.from, config.type, attributes); }, undoable: config.undoable }); } function wrappingInputRule(config) { return new InputRule({ find: config.find, handler: ({ state, range, match, chain }) => { const attributes = callOrReturn(config.getAttributes, void 0, match) || {}; const tr2 = state.tr.delete(range.from, range.to); const $start = tr2.doc.resolve(range.from); const blockRange = $start.blockRange(); const wrapping = blockRange && findWrapping(blockRange, config.type, attributes); if (!wrapping) { return null; } tr2.wrap(blockRange, wrapping); if (config.keepMarks && config.editor) { const { selection, storedMarks } = state; const { splittableMarks } = config.editor.extensionManager; const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks(); if (marks) { const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name)); tr2.ensureMarks(filteredMarks); } } if (config.keepAttributes) { const nodeType = config.type.name === "bulletList" || config.type.name === "orderedList" ? "listItem" : "taskList"; chain().updateAttributes(nodeType, attributes).run(); } const before = tr2.doc.resolve(range.from - 1).nodeBefore; if (before && before.type === config.type && canJoin(tr2.doc, range.from - 1) && (!config.joinPredicate || config.joinPredicate(match, before))) { tr2.join(range.from - 1); } }, undoable: config.undoable }); } var isTouchEvent = (e) => { return "touches" in e; }; var ResizableNodeView = class { /** * Creates a new ResizableNodeView instance. * * The constructor sets up the resize handles, applies initial sizing from * node attributes, and configures all resize behavior options. * * @param options - Configuration options for the resizable node view */ constructor(options) { this.directions = ["bottom-left", "bottom-right", "top-left", "top-right"]; this.minSize = { height: 8, width: 8 }; this.preserveAspectRatio = false; this.classNames = { container: "", wrapper: "", handle: "", resizing: "" }; this.initialWidth = 0; this.initialHeight = 0; this.aspectRatio = 1; this.isResizing = false; this.activeHandle = null; this.startX = 0; this.startY = 0; this.startWidth = 0; this.startHeight = 0; this.isShiftKeyPressed = false; this.lastEditableState = void 0; this.handleMap = /* @__PURE__ */ new Map(); this.handleMouseMove = (event) => { if (!this.isResizing || !this.activeHandle) { return; } const deltaX = event.clientX - this.startX; const deltaY = event.clientY - this.startY; this.handleResize(deltaX, deltaY); }; this.handleTouchMove = (event) => { if (!this.isResizing || !this.activeHandle) { return; } const touch = event.touches[0]; if (!touch) { return; } const deltaX = touch.clientX - this.startX; const deltaY = touch.clientY - this.startY; this.handleResize(deltaX, deltaY); }; this.handleMouseUp = () => { if (!this.isResizing) { return; } const finalWidth = this.element.offsetWidth; const finalHeight = this.element.offsetHeight; this.onCommit(finalWidth, finalHeight); this.isResizing = false; this.activeHandle = null; this.container.dataset.resizeState = "false"; if (this.classNames.resizing) { this.container.classList.remove(this.classNames.resizing); } document.removeEventListener("mousemove", this.handleMouseMove); document.removeEventListener("mouseup", this.handleMouseUp); document.removeEventListener("keydown", this.handleKeyDown); document.removeEventListener("keyup", this.handleKeyUp); }; this.handleKeyDown = (event) => { if (event.key === "Shift") { this.isShiftKeyPressed = true; } }; this.handleKeyUp = (event) => { if (event.key === "Shift") { this.isShiftKeyPressed = false; } }; var _a, _b, _c, _d, _e, _f; this.node = options.node; this.editor = options.editor; this.element = options.element; this.contentElement = options.contentElement; this.getPos = options.getPos; this.onResize = options.onResize; this.onCommit = options.onCommit; this.onUpdate = options.onUpdate; if ((_a = options.options) == null ? void 0 : _a.min) { this.minSize = { ...this.minSize, ...options.options.min }; } if ((_b = options.options) == null ? void 0 : _b.max) { this.maxSize = options.options.max; } if ((_c = options == null ? void 0 : options.options) == null ? void 0 : _c.directions) { this.directions = options.options.directions; } if ((_d = options.options) == null ? void 0 : _d.preserveAspectRatio) { this.preserveAspectRatio = options.options.preserveAspectRatio; } if ((_e = options.options) == null ? void 0 : _e.className) { this.classNames = { container: options.options.className.container || "", wrapper: options.options.className.wrapper || "", handle: options.options.className.handle || "", resizing: options.options.className.resizing || "" }; } if ((_f = options.options) == null ? void 0 : _f.createCustomHandle) { this.createCustomHandle = options.options.createCustomHandle; } this.wrapper = this.createWrapper(); this.container = this.createContainer(); this.applyInitialSize(); this.attachHandles(); this.editor.on("update", this.handleEditorUpdate.bind(this)); } /** * Returns the top-level DOM node that should be placed in the editor. * * This is required by the ProseMirror NodeView interface. The container * includes the wrapper, handles, and the actual content element. * * @returns The container element to be inserted into the editor */ get dom() { return this.container; } get contentDOM() { var _a; return (_a = this.contentElement) != null ? _a : null; } handleEditorUpdate() { const isEditable = this.editor.isEditable; if (isEditable === this.lastEditableState) { return; } this.lastEditableState = isEditable; if (!isEditable) { this.removeHandles(); } else if (isEditable && this.handleMap.size === 0) { this.attachHandles(); } } /** * Called when the node's content or attributes change. * * Updates the internal node reference. If a custom `onUpdate` callback * was provided, it will be called to handle additional update logic. * * @param node - The new/updated node * @param decorations - Node decorations * @param innerDecorations - Inner decorations * @returns `false` if the node type has changed (requires full rebuild), otherwise the result of `onUpdate` or `true` */ update(node, decorations, innerDecorations) { if (node.type !== this.node.type) { return false; } this.node = node; if (this.onUpdate) { return this.onUpdate(node, decorations, innerDecorations); } return true; } /** * Cleanup method called when the node view is being removed. * * Removes all event listeners to prevent memory leaks. This is required * by the ProseMirror NodeView interface. If a resize is active when * destroy is called, it will be properly cancelled. */ destroy() { if (this.isResizing) { this.container.dataset.resizeState = "false"; if (this.classNames.resizing) { this.container.classList.remove(this.classNames.resizing); } document.removeEventListener("mousemove", this.handleMouseMove); document.removeEventListener("mouseup", this.handleMouseUp); document.removeEventListener("keydown", this.handleKeyDown); document.removeEventListener("keyup", this.handleKeyUp); this.isResizing = false; this.activeHandle = null; } this.editor.off("update", this.handleEditorUpdate.bind(this)); this.container.remove(); } /** * Creates the outer container element. * * The container is the top-level element returned by the NodeView and * wraps the entire resizable node. It's set up with flexbox to handle * alignment and includes data attributes for styling and identification. * * @returns The container element */ createContainer() { const element = document.createElement("div"); element.dataset.resizeContainer = ""; element.dataset.node = this.node.type.name; element.style.display = this.node.type.isInline ? "inline-flex" : "flex"; if (this.classNames.container) { element.className = this.classNames.container; } element.appendChild(this.wrapper); return element; } /** * Creates the wrapper element that contains the content and handles. * * The wrapper uses relative positioning so that resize handles can be * positioned absolutely within it. This is the direct parent of the * content element being made resizable. * * @returns The wrapper element */ createWrapper() { const element = document.createElement("div"); element.style.position = "relative"; element.style.display = "block"; element.dataset.resizeWrapper = ""; if (this.classNames.wrapper) { element.className = this.classNames.wrapper; } element.appendChild(this.element); return element; } /** * Creates a resize handle element for a specific direction. * * Each handle is absolutely positioned and includes a data attribute * identifying its direction for styling purposes. * * @param direction - The resize direction for this handle * @returns The handle element */ createHandle(direction) { const handle = document.createElement("div"); handle.dataset.resizeHandle = direction; handle.style.position = "absolute"; if (this.classNames.handle) { handle.className = this.classNames.handle; } return handle; } /** * Positions a handle element according to its direction. * * Corner handles (e.g., 'top-left') are positioned at the intersection * of two edges. Edge handles (e.g., 'top') span the full width or height. * * @param handle - The handle element to position * @param direction - The direction determining the position */ positionHandle(handle, direction) { const isTop = direction.includes("top"); const isBottom = direction.includes("bottom"); const isLeft = direction.includes("left"); const isRight = direction.includes("right"); if (isTop) { handle.style.top = "0"; } if (isBottom) { handle.style.bottom = "0"; } if (isLeft) { handle.style.left = "0"; } if (isRight) { handle.style.right = "0"; } if (direction === "top" || direction === "bottom") { handle.style.left = "0"; handle.style.right = "0"; } if (direction === "left" || direction === "right") { handle.style.top = "0"; handle.style.bottom = "0"; } } /** * Creates and attaches all resize handles to the wrapper. * * Iterates through the configured directions, creates a handle for each, * positions it, attaches the mousedown listener, and appends it to the DOM. */ attachHandles() { this.directions.forEach((direction) => { let handle; if (this.createCustomHandle) { handle = this.createCustomHandle(direction); } else { handle = this.createHandle(direction); } if (!(handle instanceof HTMLElement)) { console.warn( `[ResizableNodeView] createCustomHandle("${direction}") did not return an HTMLElement. Falling back to default handle.` ); handle = this.createHandle(direction); } if (!this.createCustomHandle) { this.positionHandle(handle, direction); } handle.addEventListener("mousedown", (event) => this.handleResizeStart(event, direction)); handle.addEventListener("touchstart", (event) => this.handleResizeStart(event, direction)); this.handleMap.set(direction, handle); this.wrapper.appendChild(handle); }); } /** * Removes all resize handles from the wrapper. * * Cleans up the handle map and removes each handle element from the DOM. */ removeHandles() { this.handleMap.forEach((el) => el.remove()); this.handleMap.clear(); } /** * Applies initial sizing from node attributes to the element. * * If width/height attributes exist on the node, they're applied to the element. * Otherwise, the element's natural/current dimensions are measured. The aspect * ratio is calculated for later use in aspect-ratio-preserving resizes. */ applyInitialSize() { const width = this.node.attrs.width; const height = this.node.attrs.height; if (width) { this.element.style.width = `${width}px`; this.initialWidth = width; } else { this.initialWidth = this.element.offsetWidth; } if (height) { this.element.style.height = `${height}px`; this.initialHeight = height; } else { this.initialHeight = this.element.offsetHeight; } if (this.initialWidth > 0 && this.initialHeight > 0) { this.aspectRatio = this.initialWidth / this.initialHeight; } } /** * Initiates a resize operation when a handle is clicked. * * Captures the starting mouse position and element dimensions, sets up * the resize state, adds the resizing class and state attribute, and * attaches document-level listeners for mouse movement and keyboard input. * * @param event - The mouse down event * @param direction - The direction of the handle being dragged */ handleResizeStart(event, direction) { event.preventDefault(); event.stopPropagation(); this.isResizing = true; this.activeHandle = direction; if (isTouchEvent(event)) { this.startX = event.touches[0].clientX; this.startY = event.touches[0].clientY; } else { this.startX = event.clientX; this.startY = event.clientY; } this.startWidth = this.element.offsetWidth; this.startHeight = this.element.offsetHeight; if (this.startWidth > 0 && this.startHeight > 0) { this.aspectRatio = this.startWidth / this.startHeight; } this.getPos(); this.container.dataset.resizeState = "true"; if (this.classNames.resizing) { this.container.classList.add(this.classNames.resizing); } document.addEventListener("mousemove", this.handleMouseMove); document.addEventListener("touchmove", this.handleTouchMove); document.addEventListener("mouseup", this.handleMouseUp); document.addEventListener("keydown", this.handleKeyDown); document.addEventListener("keyup", this.handleKeyUp); } handleResize(deltaX, deltaY) { if (!this.activeHandle) { return; } const shouldPreserveAspectRatio = this.preserveAspectRatio || this.isShiftKeyPressed; const { width, height } = this.calculateNewDimensions(this.activeHandle, deltaX, deltaY); const constrained = this.applyConstraints(width, height, shouldPreserveAspectRatio); this.element.style.width = `${constrained.width}px`; this.element.style.height = `${constrained.height}px`; if (this.onResize) { this.onResize(constrained.width, constrained.height); } } /** * Calculates new dimensions based on mouse delta and resize direction. * * Takes the starting dimensions and applies the mouse movement delta * according to the handle direction. For corner handles, both dimensions * are affected. For edge handles, only one dimension changes. If aspect * ratio should be preserved, delegates to applyAspectRatio. * * @param direction - The active resize handle direction * @param deltaX - Horizontal mouse movement since resize start * @param deltaY - Vertical mouse movement since resize start * @returns The calculated width and height */ calculateNewDimensions(direction, deltaX, deltaY) { let newWidth = this.startWidth; let newHeight = this.startHeight; const isRight = direction.includes("right"); const isLeft = direction.includes("left"); const isBottom = direction.includes("bottom"); const isTop = direction.includes("top"); if (isRight) { newWidth = this.startWidth + deltaX; } else if (isLeft) { newWidth = this.startWidth - deltaX; } if (isBottom) { newHeight = this.startHeight + deltaY; } else if (isTop) { newHeight = this.startHeight - deltaY; } if (direction === "right" || direction === "left") { newWidth = this.startWidth + (isRight ? deltaX : -deltaX); } if (direction === "top" || direction === "bottom") { newHeight = this.startHeight + (isBottom ? deltaY : -deltaY); } const shouldPreserveAspectRatio = this.preserveAspectRatio || this.isShiftKeyPressed; if (shouldPreserveAspectRatio) { return this.applyAspectRatio(newWidth, newHeight, direction); } return { width: newWidth, height: newHeight }; } /** * Applies min/max constraints to dimensions. * * When aspect ratio is NOT preserved, constraints are applied independently * to width and height. When aspect ratio IS preserved, constraints are * applied while maintaining the aspect ratio—if one dimension hits a limit, * the other is recalculated proportionally. * * This ensures that aspect ratio is never broken when constrained. * * @param width - The unconstrained width * @param height - The unconstrained height * @param preserveAspectRatio - Whether to maintain aspect ratio while constraining * @returns The constrained dimensions */ applyConstraints(width, height, preserveAspectRatio) { var _a, _b, _c, _d; if (!preserveAspectRatio) { let constrainedWidth2 = Math.max(this.minSize.width, width); let constrainedHeight2 = Math.max(this.minSize.height, height); if ((_a = this.maxSize) == null ? void 0 : _a.width) { constrainedWidth2 = Math.min(this.maxSize.width, constrainedWidth2); } if ((_b = this.maxSize) == null ? void 0 : _b.height) { constrainedHeight2 = Math.min(this.maxSize.height, constrainedHeight2); } return { width: constrainedWidth2, height: constrainedHeight2 }; } let constrainedWidth = width; let constrainedHeight = height; if (constrainedWidth < this.minSize.width) { constrainedWidth = this.minSize.width; constrainedHeight = constrainedWidth / this.aspectRatio; } if (constrainedHeight < this.minSize.height) { constrainedHeight = this.minSize.height; constrainedWidth = constrainedHeight * this.aspectRatio; } if (((_c = this.maxSize) == null ? void 0 : _c.width) && constrainedWidth > this.maxSize.width) { constrainedWidth = this.maxSize.width; constrainedHeight = constrainedWidth / this.aspectRatio; } if (((_d = this.maxSize) == null ? void 0 : _d.height) && constrainedHeight > this.maxSize.height) { constrainedHeight = this.maxSize.height; constrainedWidth = constrainedHeight * this.aspectRatio; } return { width: constrainedWidth, height: constrainedHeight }; } /** * Adjusts dimensions to maintain the original aspect ratio. * * For horizontal handles (left/right), uses width as the primary dimension * and calculates height from it. For vertical handles (top/bottom), uses * height as primary and calculates width. For corner handles, uses width * as the primary dimension. * * @param width - The new width * @param height - The new height * @param direction - The active resize direction * @returns Dimensions adjusted to preserve aspect ratio */ applyAspectRatio(width, height, direction) { const isHorizontal = direction === "left" || direction === "right"; const isVertical = direction === "top" || direction === "bottom"; if (isHorizontal) { return { width, height: width / this.aspectRatio }; } if (isVertical) { return { width: height * this.aspectRatio, height }; } return { width, height: width / this.aspectRatio }; } }; function canInsertNode(state, nodeType) { const { selection } = state; const { $from } = selection; if (selection instanceof NodeSelection) { const index = $from.index(); const parent = $from.parent; return parent.canReplaceWith(index, index + 1, nodeType); } let depth = $from.depth; while (depth >= 0) { const index = $from.index(depth); const parent = $from.node(depth); const match = parent.contentMatchAt(index); if (match.matchType(nodeType)) { return true; } depth -= 1; } return false; } function escapeForRegEx(string) { return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); } var markdown_exports = {}; __export$1(markdown_exports, { createAtomBlockMarkdownSpec: () => createAtomBlockMarkdownSpec, createBlockMarkdownSpec: () => createBlockMarkdownSpec, createInlineMarkdownSpec: () => createInlineMarkdownSpec, parseAttributes: () => parseAttributes, parseIndentedBlocks: () => parseIndentedBlocks, renderNestedMarkdownContent: () => renderNestedMarkdownContent, serializeAttributes: () => serializeAttributes }); function parseAttributes(attrString) { if (!(attrString == null ? void 0 : attrString.trim())) { return {}; } const attributes = {}; const quotedStrings = []; const tempString = attrString.replace(/["']([^"']*)["']/g, (match) => { quotedStrings.push(match); return `__QUOTED_${quotedStrings.length - 1}__`; }); const classMatches = tempString.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g); if (classMatches) { const classes = classMatches.map((match) => match.trim().slice(1)); attributes.class = classes.join(" "); } const idMatch = tempString.match(/(?:^|\s)#([a-zA-Z][\w-]*)/); if (idMatch) { attributes.id = idMatch[1]; } const kvRegex = /([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g; const kvMatches = Array.from(tempString.matchAll(kvRegex)); kvMatches.forEach(([, key, quotedRef]) => { var _a; const quotedIndex = parseInt(((_a = quotedRef.match(/__QUOTED_(\d+)__/)) == null ? void 0 : _a[1]) || "0", 10); const quotedValue = quotedStrings[quotedIndex]; if (quotedValue) { attributes[key] = quotedValue.slice(1, -1); } }); const cleanString = tempString.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g, "").replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g, "").replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g, "").trim(); if (cleanString) { const booleanAttrs = cleanString.split(/\s+/).filter(Boolean); booleanAttrs.forEach((attr) => { if (attr.match(/^[a-zA-Z][\w-]*$/)) { attributes[attr] = true; } }); } return attributes; } function serializeAttributes(attributes) { if (!attributes || Object.keys(attributes).length === 0) { return ""; } const parts = []; if (attributes.class) { const classes = String(attributes.class).split(/\s+/).filter(Boolean); classes.forEach((cls) => parts.push(`.${cls}`)); } if (attributes.id) { parts.push(`#${attributes.id}`); } Object.entries(attributes).forEach(([key, value]) => { if (key === "class" || key === "id") { return; } if (value === true) { parts.push(key); } else if (value !== false && value != null) { parts.push(`${key}="${String(value)}"`); } }); return parts.join(" "); } function createAtomBlockMarkdownSpec(options) { const { nodeName, name: markdownName, parseAttributes: parseAttributes2 = parseAttributes, serializeAttributes: serializeAttributes2 = serializeAttributes, defaultAttributes = {}, requiredAttributes = [], allowedAttributes } = options; const blockName = markdownName || nodeName; const filterAttributes = (attrs) => { if (!allowedAttributes) { return attrs; } const filtered = {}; allowedAttributes.forEach((key) => { if (key in attrs) { filtered[key] = attrs[key]; } }); return filtered; }; return { parseMarkdown: (token, h2) => { const attrs = { ...defaultAttributes, ...token.attributes }; return h2.createNode(nodeName, attrs, []); }, markdownTokenizer: { name: nodeName, level: "block", start(src) { var _a; const regex = new RegExp(`^:::${blockName}(?:\\s|$)`, "m"); const index = (_a = src.match(regex)) == null ? void 0 : _a.index; return index !== void 0 ? index : -1; }, tokenize(src, _tokens, _lexer) { const regex = new RegExp(`^:::${blockName}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`); const match = src.match(regex); if (!match) { return void 0; } const attrString = match[1] || ""; const attributes = parseAttributes2(attrString); const missingRequired = requiredAttributes.find((required) => !(required in attributes)); if (missingRequired) { return void 0; } return { type: nodeName, raw: match[0], attributes }; } }, renderMarkdown: (node) => { const filteredAttrs = filterAttributes(node.attrs || {}); const attrs = serializeAttributes2(filteredAttrs); const attrString = attrs ? ` {${attrs}}` : ""; return `:::${blockName}${attrString} :::`; } }; } function createBlockMarkdownSpec(options) { const { nodeName, name: markdownName, getContent, parseAttributes: parseAttributes2 = parseAttributes, serializeAttributes: serializeAttributes2 = serializeAttributes, defaultAttributes = {}, content = "block", allowedAttributes } = options; const blockName = markdownName || nodeName; const filterAttributes = (attrs) => { if (!allowedAttributes) { return attrs; } const filtered = {}; allowedAttributes.forEach((key) => { if (key in attrs) { filtered[key] = attrs[key]; } }); return filtered; }; return { parseMarkdown: (token, h2) => { let nodeContent; if (getContent) { const contentResult = getContent(token); nodeContent = typeof contentResult === "string" ? [{ type: "text", text: contentResult }] : contentResult; } else if (content === "block") { nodeContent = h2.parseChildren(token.tokens || []); } else { nodeContent = h2.parseInline(token.tokens || []); } const attrs = { ...defaultAttributes, ...token.attributes }; return h2.createNode(nodeName, attrs, nodeContent); }, markdownTokenizer: { name: nodeName, level: "block", start(src) { var _a; const regex = new RegExp(`^:::${blockName}`, "m"); const index = (_a = src.match(regex)) == null ? void 0 : _a.index; return index !== void 0 ? index : -1; }, tokenize(src, _tokens, lexer) { var _a; const openingRegex = new RegExp(`^:::${blockName}(?:\\s+\\{([^}]*)\\})?\\s*\\n`); const openingMatch = src.match(openingRegex); if (!openingMatch) { return void 0; } const [openingTag, attrString = ""] = openingMatch; const attributes = parseAttributes2(attrString); let level = 1; const position = openingTag.length; let matchedContent = ""; const blockPattern = /^:::([\w-]*)(\s.*)?/gm; const remaining = src.slice(position); blockPattern.lastIndex = 0; for (; ; ) { const match = blockPattern.exec(remaining); if (match === null) { break; } const matchPos = match.index; const blockType = match[1]; if ((_a = match[2]) == null ? void 0 : _a.endsWith(":::")) { continue; } if (blockType) { level += 1; } else { level -= 1; if (level === 0) { const rawContent = remaining.slice(0, matchPos); matchedContent = rawContent.trim(); const fullMatch = src.slice(0, position + matchPos + match[0].length); let contentTokens = []; if (matchedContent) { if (content === "block") { contentTokens = lexer.blockTokens(rawContent); contentTokens.forEach((token) => { if (token.text && (!token.tokens || token.tokens.length === 0)) { token.tokens = lexer.inlineTokens(token.text); } }); while (contentTokens.length > 0) { const lastToken = contentTokens[contentTokens.length - 1]; if (lastToken.type === "paragraph" && (!lastToken.text || lastToken.text.trim() === "")) { contentTokens.pop(); } else { break; } } } else { contentTokens = lexer.inlineTokens(matchedContent); } } return { type: nodeName, raw: fullMatch, attributes, content: matchedContent, tokens: contentTokens }; } } } return void 0; } }, renderMarkdown: (node, h2) => { const filteredAttrs = filterAttributes(node.attrs || {}); const attrs = serializeAttributes2(filteredAttrs); const attrString = attrs ? ` {${attrs}}` : ""; const renderedContent = h2.renderChildren(node.content || [], "\n\n"); return `:::${blockName}${attrString} ${renderedContent} :::`; } }; } function parseShortcodeAttributes(attrString) { if (!attrString.trim()) { return {}; } const attributes = {}; const regex = /(\w+)=(?:"([^"]*)"|'([^']*)')/g; let match = regex.exec(attrString); while (match !== null) { const [, key, doubleQuoted, singleQuoted] = match; attributes[key] = doubleQuoted || singleQuoted; match = regex.exec(attrString); } return attributes; } function serializeShortcodeAttributes(attrs) { return Object.entries(attrs).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}="${value}"`).join(" "); } function createInlineMarkdownSpec(options) { const { nodeName, name: shortcodeName, getContent, parseAttributes: parseAttributes2 = parseShortcodeAttributes, serializeAttributes: serializeAttributes2 = serializeShortcodeAttributes, defaultAttributes = {}, selfClosing = false, allowedAttributes } = options; const shortcode = shortcodeName || nodeName; const filterAttributes = (attrs) => { if (!allowedAttributes) { return attrs; } const filtered = {}; allowedAttributes.forEach((attr) => { const attrName = typeof attr === "string" ? attr : attr.name; const skipIfDefault = typeof attr === "string" ? void 0 : attr.skipIfDefault; if (attrName in attrs) { const value = attrs[attrName]; if (skipIfDefault !== void 0 && value === skipIfDefault) { return; } filtered[attrName] = value; } }); return filtered; }; const escapedShortcode = shortcode.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); return { parseMarkdown: (token, h2) => { const attrs = { ...defaultAttributes, ...token.attributes }; if (selfClosing) { return h2.createNode(nodeName, attrs); } const content = getContent ? getContent(token) : token.content || ""; if (content) { return h2.createNode(nodeName, attrs, [h2.createTextNode(content)]); } return h2.createNode(nodeName, attrs, []); }, markdownTokenizer: { name: nodeName, level: "inline", start(src) { const startPattern = selfClosing ? new RegExp(`\\[${escapedShortcode}\\s*[^\\]]*\\]`) : new RegExp(`\\[${escapedShortcode}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${escapedShortcode}\\]`); const match = src.match(startPattern); const index = match == null ? void 0 : match.index; return index !== void 0 ? index : -1; }, tokenize(src, _tokens, _lexer) { const tokenPattern = selfClosing ? new RegExp(`^\\[${escapedShortcode}\\s*([^\\]]*)\\]`) : new RegExp(`^\\[${escapedShortcode}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${escapedShortcode}\\]`); const match = src.match(tokenPattern); if (!match) { return void 0; } let content = ""; let attrString = ""; if (selfClosing) { const [, attrs] = match; attrString = attrs; } else { const [, attrs, contentMatch] = match; attrString = attrs; content = contentMatch || ""; } const attributes = parseAttributes2(attrString.trim()); return { type: nodeName, raw: match[0], content: content.trim(), attributes }; } }, renderMarkdown: (node) => { let content = ""; if (getContent) { content = getContent(node); } else if (node.content && node.content.length > 0) { content = node.content.filter((child) => child.type === "text").map((child) => child.text).join(""); } const filteredAttrs = filterAttributes(node.attrs || {}); const attrs = serializeAttributes2(filteredAttrs); const attrString = attrs ? ` ${attrs}` : ""; if (selfClosing) { return `[${shortcode}${attrString}]`; } return `[${shortcode}${attrString}]${content}[/${shortcode}]`; } }; } function parseIndentedBlocks(src, config, lexer) { var _a, _b, _c, _d; const lines = src.split("\n"); const items = []; let totalRaw = ""; let i = 0; const baseIndentSize = config.baseIndentSize || 2; while (i < lines.length) { const currentLine = lines[i]; const itemMatch = currentLine.match(config.itemPattern); if (!itemMatch) { if (items.length > 0) { break; } else if (currentLine.trim() === "") { i += 1; totalRaw = `${totalRaw}${currentLine} `; continue; } else { return void 0; } } const itemData = config.extractItemData(itemMatch); const { indentLevel, mainContent } = itemData; totalRaw = `${totalRaw}${currentLine} `; const itemContent = [mainContent]; i += 1; while (i < lines.length) { const nextLine = lines[i]; if (nextLine.trim() === "") { const nextNonEmptyIndex = lines.slice(i + 1).findIndex((l) => l.trim() !== ""); if (nextNonEmptyIndex === -1) { break; } const nextNonEmpty = lines[i + 1 + nextNonEmptyIndex]; const nextIndent2 = ((_b = (_a = nextNonEmpty.match(/^(\s*)/)) == null ? void 0 : _a[1]) == null ? void 0 : _b.length) || 0; if (nextIndent2 > indentLevel) { itemContent.push(nextLine); totalRaw = `${totalRaw}${nextLine} `; i += 1; continue; } else { break; } } const nextIndent = ((_d = (_c = nextLine.match(/^(\s*)/)) == null ? void 0 : _c[1]) == null ? void 0 : _d.length) || 0; if (nextIndent > indentLevel) { itemContent.push(nextLine); totalRaw = `${totalRaw}${nextLine} `; i += 1; } else { break; } } let nestedTokens; const nestedContent = itemContent.slice(1); if (nestedContent.length > 0) { const dedentedNested = nestedContent.map((nestedLine) => nestedLine.slice(indentLevel + baseIndentSize)).join("\n"); if (dedentedNested.trim()) { if (config.customNestedParser) { nestedTokens = config.customNestedParser(dedentedNested); } else { nestedTokens = lexer.blockTokens(dedentedNested); } } } const token = config.createToken(itemData, nestedTokens); items.push(token); } if (items.length === 0) { return void 0; } return { items, raw: totalRaw }; } function renderNestedMarkdownContent(node, h2, prefixOrGenerator, ctx) { if (!node || !Array.isArray(node.content)) { return ""; } const prefix = typeof prefixOrGenerator === "function" ? prefixOrGenerator(ctx) : prefixOrGenerator; const [content, ...children] = node.content; const mainContent = h2.renderChildren([content]); let output = `${prefix}${mainContent}`; if (children && children.length > 0) { children.forEach((child, index) => { var _a, _b; const childContent = (_b = (_a = h2.renderChild) == null ? void 0 : _a.call(h2, child, index + 1)) != null ? _b : h2.renderChildren([child]); if (childContent !== void 0 && childContent !== null) { const indentedChild = childContent.split("\n").map((line) => line ? h2.indent(line) : h2.indent("")).join("\n"); output += child.type === "paragraph" ? ` ${indentedChild}` : ` ${indentedChild}`; } }); } return output; } var positionUpdateRegistries = /* @__PURE__ */ new WeakMap(); function schedulePositionCheck(editor, callback) { let registry = positionUpdateRegistries.get(editor); if (!registry) { const newRegistry = { callbacks: /* @__PURE__ */ new Set(), rafId: null, handler: () => { if (newRegistry.rafId !== null) { cancelAnimationFrame(newRegistry.rafId); } newRegistry.rafId = requestAnimationFrame(() => { newRegistry.rafId = null; newRegistry.callbacks.forEach((cb) => cb()); }); } }; positionUpdateRegistries.set(editor, newRegistry); editor.on("update", newRegistry.handler); registry = newRegistry; } registry.callbacks.add(callback); } function cancelPositionCheck(editor, callback) { const registry = positionUpdateRegistries.get(editor); if (!registry) { return; } registry.callbacks.delete(callback); if (registry.callbacks.size === 0) { if (registry.rafId !== null) { cancelAnimationFrame(registry.rafId); } editor.off("update", registry.handler); positionUpdateRegistries.delete(editor); } } function updateMarkViewAttributes(checkMark, editor, attrs = {}) { const { state } = editor; const { doc: doc2, tr: tr2 } = state; const thisMark = checkMark; doc2.descendants((node, pos) => { const from2 = tr2.mapping.map(pos); const to = tr2.mapping.map(pos) + node.nodeSize; let foundMark = null; node.marks.forEach((mark) => { if (mark !== thisMark) { return false; } foundMark = mark; }); if (!foundMark) { return; } let needsUpdate = false; Object.keys(attrs).forEach((k) => { if (attrs[k] !== foundMark.attrs[k]) { needsUpdate = true; } }); if (needsUpdate) { const updatedMark = checkMark.type.create({ ...checkMark.attrs, ...attrs }); tr2.removeMark(from2, to, checkMark.type); tr2.addMark(from2, to, updatedMark); } }); if (tr2.docChanged) { editor.view.dispatch(tr2); } } var Node3 = class _Node extends Extendable { constructor() { super(...arguments); this.type = "node"; } /** * Create a new Node instance * @param config - Node configuration object or a function that returns a configuration object */ static create(config = {}) { const resolvedConfig = typeof config === "function" ? config() : config; return new _Node(resolvedConfig); } configure(options) { return super.configure(options); } extend(extendedConfig) { const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig; return super.extend(resolvedConfig); } }; var NodeView = class { constructor(component, props, options) { this.isDragging = false; this.component = component; this.editor = props.editor; this.options = { stopEvent: null, ignoreMutation: null, ...options }; this.extension = props.extension; this.node = props.node; this.decorations = props.decorations; this.innerDecorations = props.innerDecorations; this.view = props.view; this.HTMLAttributes = props.HTMLAttributes; this.getPos = props.getPos; this.mount(); } mount() { return; } get dom() { return this.editor.view.dom; } get contentDOM() { return null; } onDragStart(event) { var _a, _b, _c, _d, _e, _f, _g; const { view } = this.editor; const target = event.target; const dragHandle = target.nodeType === 3 ? (_a = target.parentElement) == null ? void 0 : _a.closest("[data-drag-handle]") : target.closest("[data-drag-handle]"); if (!this.dom || ((_b = this.contentDOM) == null ? void 0 : _b.contains(target)) || !dragHandle) { return; } let x = 0; let y = 0; if (this.dom !== dragHandle) { const domBox = this.dom.getBoundingClientRect(); const handleBox = dragHandle.getBoundingClientRect(); const offsetX = (_d = event.offsetX) != null ? _d : (_c = event.nativeEvent) == null ? void 0 : _c.offsetX; const offsetY = (_f = event.offsetY) != null ? _f : (_e = event.nativeEvent) == null ? void 0 : _e.offsetY; x = handleBox.x - domBox.x + offsetX; y = handleBox.y - domBox.y + offsetY; } const clonedNode = this.dom.cloneNode(true); try { const domBox = this.dom.getBoundingClientRect(); clonedNode.style.width = `${Math.round(domBox.width)}px`; clonedNode.style.height = `${Math.round(domBox.height)}px`; clonedNode.style.boxSizing = "border-box"; clonedNode.style.pointerEvents = "none"; } catch { } let dragImageWrapper = null; try { dragImageWrapper = document.createElement("div"); dragImageWrapper.style.position = "absolute"; dragImageWrapper.style.top = "-9999px"; dragImageWrapper.style.left = "-9999px"; dragImageWrapper.style.pointerEvents = "none"; dragImageWrapper.appendChild(clonedNode); document.body.appendChild(dragImageWrapper); (_g = event.dataTransfer) == null ? void 0 : _g.setDragImage(clonedNode, x, y); } finally { if (dragImageWrapper) { setTimeout(() => { try { dragImageWrapper == null ? void 0 : dragImageWrapper.remove(); } catch { } }, 0); } } const pos = this.getPos(); if (typeof pos !== "number") { return; } const selection = NodeSelection.create(view.state.doc, pos); const transaction = view.state.tr.setSelection(selection); view.dispatch(transaction); } stopEvent(event) { var _a; if (!this.dom) { return false; } if (typeof this.options.stopEvent === "function") { return this.options.stopEvent({ event }); } const target = event.target; const isInElement = this.dom.contains(target) && !((_a = this.contentDOM) == null ? void 0 : _a.contains(target)); if (!isInElement) { return false; } const isDragEvent = event.type.startsWith("drag"); const isDragOverEnterEvent = event.type === "dragover" || event.type === "dragenter"; const isDropEvent = event.type === "drop"; const isInput = ["INPUT", "BUTTON", "SELECT", "TEXTAREA"].includes(target.tagName) || target.isContentEditable; if (isInput && !isDropEvent && !isDragEvent) { return true; } const { isEditable } = this.editor; const { isDragging } = this; const isDraggable = !!this.node.type.spec.draggable; const isSelectable = NodeSelection.isSelectable(this.node); const isCopyEvent = event.type === "copy"; const isPasteEvent = event.type === "paste"; const isCutEvent = event.type === "cut"; const isClickEvent = event.type === "mousedown"; if (!isDraggable && isSelectable && isDragEvent && event.target === this.dom) { event.preventDefault(); } if (isDraggable && isDragEvent && !isDragging && event.target === this.dom) { event.preventDefault(); return false; } if (isDraggable && isEditable && !isDragging && isClickEvent) { const dragHandle = target.closest("[data-drag-handle]"); const isValidDragHandle = dragHandle && (this.dom === dragHandle || this.dom.contains(dragHandle)); if (isValidDragHandle) { this.isDragging = true; document.addEventListener( "dragend", () => { this.isDragging = false; }, { once: true } ); document.addEventListener( "drop", () => { this.isDragging = false; }, { once: true } ); document.addEventListener( "mouseup", () => { this.isDragging = false; }, { once: true } ); } } if (isDragging || isDragOverEnterEvent || isDropEvent || isCopyEvent || isPasteEvent || isCutEvent || isClickEvent && isSelectable) { return false; } return true; } /** * Called when a DOM [mutation](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) or a selection change happens within the view. * @return `false` if the editor should re-read the selection or re-parse the range around the mutation * @return `true` if it can safely be ignored. */ ignoreMutation(mutation) { if (!this.dom || !this.contentDOM) { return true; } if (typeof this.options.ignoreMutation === "function") { return this.options.ignoreMutation({ mutation }); } if (this.node.isLeaf || this.node.isAtom) { return true; } if (mutation.type === "selection") { return false; } if (this.dom.contains(mutation.target) && mutation.type === "childList" && (isiOS() || isAndroid()) && this.editor.isFocused) { const changedNodes = [...Array.from(mutation.addedNodes), ...Array.from(mutation.removedNodes)]; if (changedNodes.every((node) => node.isContentEditable)) { return false; } } if (this.contentDOM === mutation.target && mutation.type === "attributes") { return true; } if (this.contentDOM.contains(mutation.target)) { return false; } return true; } /** * Update the attributes of the prosemirror node. */ updateAttributes(attributes) { this.editor.commands.command(({ tr: tr2 }) => { const pos = this.getPos(); if (typeof pos !== "number") { return false; } tr2.setNodeMarkup(pos, void 0, { ...this.node.attrs, ...attributes }); return true; }); } /** * Delete the node. */ deleteNode() { const from2 = this.getPos(); if (typeof from2 !== "number") { return; } const to = from2 + this.node.nodeSize; this.editor.commands.deleteRange({ from: from2, to }); } }; function markPasteRule(config) { return new PasteRule({ find: config.find, handler: ({ state, range, match, pasteEvent }) => { const attributes = callOrReturn(config.getAttributes, void 0, match, pasteEvent); if (attributes === false || attributes === null) { return null; } const { tr: tr2 } = state; const captureGroup = match[match.length - 1]; const fullMatch = match[0]; let markEnd = range.to; if (captureGroup) { const startSpaces = fullMatch.search(/\S/); const textStart = range.from + fullMatch.indexOf(captureGroup); const textEnd = textStart + captureGroup.length; const excludedMarks = getMarksBetween(range.from, range.to, state.doc).filter((item) => { const excluded = item.mark.type.excluded; return excluded.find((type) => type === config.type && type !== item.mark.type); }).filter((item) => item.to > textStart); if (excludedMarks.length) { return null; } if (textEnd < range.to) { tr2.delete(textEnd, range.to); } if (textStart > range.from) { tr2.delete(range.from + startSpaces, textStart); } markEnd = range.from + startSpaces + captureGroup.length; tr2.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {})); const isMatchAtEndOfText = match.index !== void 0 && match.input !== void 0 && match.index + match[0].length >= match.input.length; if (!isMatchAtEndOfText) { tr2.removeStoredMark(config.type); } } } }); } const { getOwnPropertyNames, getOwnPropertySymbols } = Object; const { hasOwnProperty } = Object.prototype; function combineComparators(comparatorA, comparatorB) { return function isEqual(a, b, state) { return comparatorA(a, b, state) && comparatorB(a, b, state); }; } function createIsCircular(areItemsEqual) { return function isCircular(a, b, state) { if (!a || !b || typeof a !== "object" || typeof b !== "object") { return areItemsEqual(a, b, state); } const { cache } = state; const cachedA = cache.get(a); const cachedB = cache.get(b); if (cachedA && cachedB) { return cachedA === b && cachedB === a; } cache.set(a, b); cache.set(b, a); const result = areItemsEqual(a, b, state); cache.delete(a); cache.delete(b); return result; }; } function getShortTag(value) { return value != null ? value[Symbol.toStringTag] : void 0; } function getStrictProperties(object) { return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object)); } const hasOwn = ( // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition Object.hasOwn || ((object, property) => hasOwnProperty.call(object, property)) ); function sameValueZeroEqual(a, b) { return a === b || !a && !b && a !== a && b !== b; } const PREACT_VNODE = "__v"; const PREACT_OWNER = "__o"; const REACT_OWNER = "_owner"; const { getOwnPropertyDescriptor, keys } = Object; function areArrayBuffersEqual(a, b) { return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a), new Uint8Array(b)); } function areArraysEqual(a, b, state) { let index = a.length; if (b.length !== index) { return false; } while (index-- > 0) { if (!state.equals(a[index], b[index], index, index, a, b, state)) { return false; } } return true; } function areDataViewsEqual(a, b) { return a.byteLength === b.byteLength && areTypedArraysEqual(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength)); } function areDatesEqual(a, b) { return sameValueZeroEqual(a.getTime(), b.getTime()); } function areErrorsEqual(a, b) { return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack; } function areFunctionsEqual(a, b) { return a === b; } function areMapsEqual(a, b, state) { const size2 = a.size; if (size2 !== b.size) { return false; } if (!size2) { return true; } const matchedIndices = new Array(size2); const aIterable = a.entries(); let aResult; let bResult; let index = 0; while (aResult = aIterable.next()) { if (aResult.done) { break; } const bIterable = b.entries(); let hasMatch = false; let matchIndex = 0; while (bResult = bIterable.next()) { if (bResult.done) { break; } if (matchedIndices[matchIndex]) { matchIndex++; continue; } const aEntry = aResult.value; const bEntry = bResult.value; if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state) && state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) { hasMatch = matchedIndices[matchIndex] = true; break; } matchIndex++; } if (!hasMatch) { return false; } index++; } return true; } const areNumbersEqual = sameValueZeroEqual; function areObjectsEqual(a, b, state) { const properties = keys(a); let index = properties.length; if (keys(b).length !== index) { return false; } while (index-- > 0) { if (!isPropertyEqual(a, b, state, properties[index])) { return false; } } return true; } function areObjectsEqualStrict(a, b, state) { const properties = getStrictProperties(a); let index = properties.length; if (getStrictProperties(b).length !== index) { return false; } let property; let descriptorA; let descriptorB; while (index-- > 0) { property = properties[index]; if (!isPropertyEqual(a, b, state, property)) { return false; } descriptorA = getOwnPropertyDescriptor(a, property); descriptorB = getOwnPropertyDescriptor(b, property); if ((descriptorA || descriptorB) && (!descriptorA || !descriptorB || descriptorA.configurable !== descriptorB.configurable || descriptorA.enumerable !== descriptorB.enumerable || descriptorA.writable !== descriptorB.writable)) { return false; } } return true; } function arePrimitiveWrappersEqual(a, b) { return sameValueZeroEqual(a.valueOf(), b.valueOf()); } function areRegExpsEqual(a, b) { return a.source === b.source && a.flags === b.flags; } function areSetsEqual(a, b, state) { const size2 = a.size; if (size2 !== b.size) { return false; } if (!size2) { return true; } const matchedIndices = new Array(size2); const aIterable = a.values(); let aResult; let bResult; while (aResult = aIterable.next()) { if (aResult.done) { break; } const bIterable = b.values(); let hasMatch = false; let matchIndex = 0; while (bResult = bIterable.next()) { if (bResult.done) { break; } if (!matchedIndices[matchIndex] && state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) { hasMatch = matchedIndices[matchIndex] = true; break; } matchIndex++; } if (!hasMatch) { return false; } } return true; } function areTypedArraysEqual(a, b) { let index = a.byteLength; if (b.byteLength !== index || a.byteOffset !== b.byteOffset) { return false; } while (index-- > 0) { if (a[index] !== b[index]) { return false; } } return true; } function areUrlsEqual(a, b) { return a.hostname === b.hostname && a.pathname === b.pathname && a.protocol === b.protocol && a.port === b.port && a.hash === b.hash && a.username === b.username && a.password === b.password; } function isPropertyEqual(a, b, state, property) { if ((property === REACT_OWNER || property === PREACT_OWNER || property === PREACT_VNODE) && (a.$$typeof || b.$$typeof)) { return true; } return hasOwn(b, property) && state.equals(a[property], b[property], property, property, a, b, state); } const ARRAY_BUFFER_TAG = "[object ArrayBuffer]"; const ARGUMENTS_TAG = "[object Arguments]"; const BOOLEAN_TAG = "[object Boolean]"; const DATA_VIEW_TAG = "[object DataView]"; const DATE_TAG = "[object Date]"; const ERROR_TAG = "[object Error]"; const MAP_TAG = "[object Map]"; const NUMBER_TAG = "[object Number]"; const OBJECT_TAG = "[object Object]"; const REG_EXP_TAG = "[object RegExp]"; const SET_TAG = "[object Set]"; const STRING_TAG = "[object String]"; const TYPED_ARRAY_TAGS = { "[object Int8Array]": true, "[object Uint8Array]": true, "[object Uint8ClampedArray]": true, "[object Int16Array]": true, "[object Uint16Array]": true, "[object Int32Array]": true, "[object Uint32Array]": true, "[object Float16Array]": true, "[object Float32Array]": true, "[object Float64Array]": true, "[object BigInt64Array]": true, "[object BigUint64Array]": true }; const URL_TAG = "[object URL]"; const toString = Object.prototype.toString; function createEqualityComparator({ areArrayBuffersEqual: areArrayBuffersEqual2, areArraysEqual: areArraysEqual2, areDataViewsEqual: areDataViewsEqual2, areDatesEqual: areDatesEqual2, areErrorsEqual: areErrorsEqual2, areFunctionsEqual: areFunctionsEqual2, areMapsEqual: areMapsEqual2, areNumbersEqual: areNumbersEqual2, areObjectsEqual: areObjectsEqual2, arePrimitiveWrappersEqual: arePrimitiveWrappersEqual2, areRegExpsEqual: areRegExpsEqual2, areSetsEqual: areSetsEqual2, areTypedArraysEqual: areTypedArraysEqual2, areUrlsEqual: areUrlsEqual2, unknownTagComparators }) { return function comparator(a, b, state) { if (a === b) { return true; } if (a == null || b == null) { return false; } const type = typeof a; if (type !== typeof b) { return false; } if (type !== "object") { if (type === "number") { return areNumbersEqual2(a, b, state); } if (type === "function") { return areFunctionsEqual2(a, b, state); } return false; } const constructor = a.constructor; if (constructor !== b.constructor) { return false; } if (constructor === Object) { return areObjectsEqual2(a, b, state); } if (Array.isArray(a)) { return areArraysEqual2(a, b, state); } if (constructor === Date) { return areDatesEqual2(a, b, state); } if (constructor === RegExp) { return areRegExpsEqual2(a, b, state); } if (constructor === Map) { return areMapsEqual2(a, b, state); } if (constructor === Set) { return areSetsEqual2(a, b, state); } const tag = toString.call(a); if (tag === DATE_TAG) { return areDatesEqual2(a, b, state); } if (tag === REG_EXP_TAG) { return areRegExpsEqual2(a, b, state); } if (tag === MAP_TAG) { return areMapsEqual2(a, b, state); } if (tag === SET_TAG) { return areSetsEqual2(a, b, state); } if (tag === OBJECT_TAG) { return typeof a.then !== "function" && typeof b.then !== "function" && areObjectsEqual2(a, b, state); } if (tag === URL_TAG) { return areUrlsEqual2(a, b, state); } if (tag === ERROR_TAG) { return areErrorsEqual2(a, b, state); } if (tag === ARGUMENTS_TAG) { return areObjectsEqual2(a, b, state); } if (TYPED_ARRAY_TAGS[tag]) { return areTypedArraysEqual2(a, b, state); } if (tag === ARRAY_BUFFER_TAG) { return areArrayBuffersEqual2(a, b, state); } if (tag === DATA_VIEW_TAG) { return areDataViewsEqual2(a, b, state); } if (tag === BOOLEAN_TAG || tag === NUMBER_TAG || tag === STRING_TAG) { return arePrimitiveWrappersEqual2(a, b, state); } if (unknownTagComparators) { let unknownTagComparator = unknownTagComparators[tag]; if (!unknownTagComparator) { const shortTag = getShortTag(a); if (shortTag) { unknownTagComparator = unknownTagComparators[shortTag]; } } if (unknownTagComparator) { return unknownTagComparator(a, b, state); } } return false; }; } function createEqualityComparatorConfig({ circular, createCustomConfig, strict }) { let config = { areArrayBuffersEqual, areArraysEqual: strict ? areObjectsEqualStrict : areArraysEqual, areDataViewsEqual, areDatesEqual, areErrorsEqual, areFunctionsEqual, areMapsEqual: strict ? combineComparators(areMapsEqual, areObjectsEqualStrict) : areMapsEqual, areNumbersEqual, areObjectsEqual: strict ? areObjectsEqualStrict : areObjectsEqual, arePrimitiveWrappersEqual, areRegExpsEqual, areSetsEqual: strict ? combineComparators(areSetsEqual, areObjectsEqualStrict) : areSetsEqual, areTypedArraysEqual: strict ? combineComparators(areTypedArraysEqual, areObjectsEqualStrict) : areTypedArraysEqual, areUrlsEqual, unknownTagComparators: void 0 }; if (createCustomConfig) { config = Object.assign({}, config, createCustomConfig(config)); } if (circular) { const areArraysEqual2 = createIsCircular(config.areArraysEqual); const areMapsEqual2 = createIsCircular(config.areMapsEqual); const areObjectsEqual2 = createIsCircular(config.areObjectsEqual); const areSetsEqual2 = createIsCircular(config.areSetsEqual); config = Object.assign({}, config, { areArraysEqual: areArraysEqual2, areMapsEqual: areMapsEqual2, areObjectsEqual: areObjectsEqual2, areSetsEqual: areSetsEqual2 }); } return config; } function createInternalEqualityComparator(compare) { return function(a, b, _indexOrKeyA, _indexOrKeyB, _parentA, _parentB, state) { return compare(a, b, state); }; } function createIsEqual({ circular, comparator, createState, equals, strict }) { if (createState) { return function isEqual(a, b) { const { cache = circular ? /* @__PURE__ */ new WeakMap() : void 0, meta } = createState(); return comparator(a, b, { cache, equals, meta, strict }); }; } if (circular) { return function isEqual(a, b) { return comparator(a, b, { cache: /* @__PURE__ */ new WeakMap(), equals, meta: void 0, strict }); }; } const state = { cache: void 0, equals, meta: void 0, strict }; return function isEqual(a, b) { return comparator(a, b, state); }; } const deepEqual = createCustomEqual(); createCustomEqual({ strict: true }); createCustomEqual({ circular: true }); createCustomEqual({ circular: true, strict: true }); createCustomEqual({ createInternalComparator: () => sameValueZeroEqual }); createCustomEqual({ strict: true, createInternalComparator: () => sameValueZeroEqual }); createCustomEqual({ circular: true, createInternalComparator: () => sameValueZeroEqual }); createCustomEqual({ circular: true, createInternalComparator: () => sameValueZeroEqual, strict: true }); function createCustomEqual(options = {}) { const { circular = false, createInternalComparator: createCustomInternalComparator, createState, strict = false } = options; const config = createEqualityComparatorConfig(options); const comparator = createEqualityComparator(config); const equals = createCustomInternalComparator ? createCustomInternalComparator(comparator) : createInternalEqualityComparator(comparator); return createIsEqual({ circular, comparator, createState, equals, strict }); } var withSelector = { exports: {} }; var withSelector_production = {}; var hasRequiredWithSelector_production; function requireWithSelector_production() { if (hasRequiredWithSelector_production) return withSelector_production; hasRequiredWithSelector_production = 1; var React2 = requireReact(), shim2 = requireShim(); function is(x, y) { return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y; } var objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim2.useSyncExternalStore, useRef = React2.useRef, useEffect = React2.useEffect, useMemo = React2.useMemo, useDebugValue = React2.useDebugValue; withSelector_production.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) { var instRef = useRef(null); if (null === instRef.current) { var inst = { hasValue: false, value: null }; instRef.current = inst; } else inst = instRef.current; instRef = useMemo( function() { function memoizedSelector(nextSnapshot) { if (!hasMemo) { hasMemo = true; memoizedSnapshot = nextSnapshot; nextSnapshot = selector(nextSnapshot); if (void 0 !== isEqual && inst.hasValue) { var currentSelection = inst.value; if (isEqual(currentSelection, nextSnapshot)) return memoizedSelection = currentSelection; } return memoizedSelection = nextSnapshot; } currentSelection = memoizedSelection; if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection; var nextSelection = selector(nextSnapshot); if (void 0 !== isEqual && isEqual(currentSelection, nextSelection)) return memoizedSnapshot = nextSnapshot, currentSelection; memoizedSnapshot = nextSnapshot; return memoizedSelection = nextSelection; } var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot; return [ function() { return memoizedSelector(getSnapshot()); }, null === maybeGetServerSnapshot ? void 0 : function() { return memoizedSelector(maybeGetServerSnapshot()); } ]; }, [getSnapshot, getServerSnapshot, selector, isEqual] ); var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]); useEffect( function() { inst.hasValue = true; inst.value = value; }, [value] ); useDebugValue(value); return value; }; return withSelector_production; } var withSelector_development = {}; var hasRequiredWithSelector_development; function requireWithSelector_development() { if (hasRequiredWithSelector_development) return withSelector_development; hasRequiredWithSelector_development = 1; "production" !== process.env.NODE_ENV && (function() { function is(x, y) { return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y; } "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error()); var React2 = requireReact(), shim2 = requireShim(), objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim2.useSyncExternalStore, useRef = React2.useRef, useEffect = React2.useEffect, useMemo = React2.useMemo, useDebugValue = React2.useDebugValue; withSelector_development.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) { var instRef = useRef(null); if (null === instRef.current) { var inst = { hasValue: false, value: null }; instRef.current = inst; } else inst = instRef.current; instRef = useMemo( function() { function memoizedSelector(nextSnapshot) { if (!hasMemo) { hasMemo = true; memoizedSnapshot = nextSnapshot; nextSnapshot = selector(nextSnapshot); if (void 0 !== isEqual && inst.hasValue) { var currentSelection = inst.value; if (isEqual(currentSelection, nextSnapshot)) return memoizedSelection = currentSelection; } return memoizedSelection = nextSnapshot; } currentSelection = memoizedSelection; if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection; var nextSelection = selector(nextSnapshot); if (void 0 !== isEqual && isEqual(currentSelection, nextSelection)) return memoizedSnapshot = nextSnapshot, currentSelection; memoizedSnapshot = nextSnapshot; return memoizedSelection = nextSelection; } var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot; return [ function() { return memoizedSelector(getSnapshot()); }, null === maybeGetServerSnapshot ? void 0 : function() { return memoizedSelector(maybeGetServerSnapshot()); } ]; }, [getSnapshot, getServerSnapshot, selector, isEqual] ); var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]); useEffect( function() { inst.hasValue = true; inst.value = value; }, [value] ); useDebugValue(value); return value; }; "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error()); })(); return withSelector_development; } var hasRequiredWithSelector; function requireWithSelector() { if (hasRequiredWithSelector) return withSelector.exports; hasRequiredWithSelector = 1; if (process.env.NODE_ENV === "production") { withSelector.exports = requireWithSelector_production(); } else { withSelector.exports = requireWithSelector_development(); } return withSelector.exports; } var withSelectorExports = requireWithSelector(); var mergeRefs = (...refs) => { return (node) => { refs.forEach((ref) => { if (typeof ref === "function") { ref(node); } else if (ref) { ref.current = node; } }); }; }; var Portals = ({ contentComponent }) => { const renderers = shimExports.useSyncExternalStore( contentComponent.subscribe, contentComponent.getSnapshot, contentComponent.getServerSnapshot ); return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: Object.values(renderers) }); }; function getInstance() { const subscribers = /* @__PURE__ */ new Set(); let renderers = {}; return { /** * Subscribe to the editor instance's changes. */ subscribe(callback) { subscribers.add(callback); return () => { subscribers.delete(callback); }; }, getSnapshot() { return renderers; }, getServerSnapshot() { return renderers; }, /** * Adds a new NodeView Renderer to the editor. */ setRenderer(id, renderer) { renderers = { ...renderers, [id]: ReactDOM.createPortal(renderer.reactElement, renderer.element, id) }; subscribers.forEach((subscriber) => subscriber()); }, /** * Removes a NodeView Renderer from the editor. */ removeRenderer(id) { const nextRenderers = { ...renderers }; delete nextRenderers[id]; renderers = nextRenderers; subscribers.forEach((subscriber) => subscriber()); } }; } var PureEditorContent = class extends React.Component { constructor(props) { var _a; super(props); this.editorContentRef = React.createRef(); this.initialized = false; this.state = { hasContentComponentInitialized: Boolean((_a = props.editor) == null ? void 0 : _a.contentComponent) }; } componentDidMount() { this.init(); } componentDidUpdate() { this.init(); } init() { var _a; const editor = this.props.editor; if (editor && !editor.isDestroyed && ((_a = editor.view.dom) == null ? void 0 : _a.parentNode)) { if (editor.contentComponent) { return; } const element = this.editorContentRef.current; element.append(...editor.view.dom.parentNode.childNodes); editor.setOptions({ element }); editor.contentComponent = getInstance(); if (!this.state.hasContentComponentInitialized) { this.unsubscribeToContentComponent = editor.contentComponent.subscribe(() => { this.setState((prevState) => { if (!prevState.hasContentComponentInitialized) { return { hasContentComponentInitialized: true }; } return prevState; }); if (this.unsubscribeToContentComponent) { this.unsubscribeToContentComponent(); } }); } editor.createNodeViews(); this.initialized = true; } } componentWillUnmount() { var _a; const editor = this.props.editor; if (!editor) { return; } this.initialized = false; if (!editor.isDestroyed) { editor.view.setProps({ nodeViews: {} }); } if (this.unsubscribeToContentComponent) { this.unsubscribeToContentComponent(); } editor.contentComponent = null; try { if (!((_a = editor.view.dom) == null ? void 0 : _a.parentNode)) { return; } const newElement = document.createElement("div"); newElement.append(...editor.view.dom.parentNode.childNodes); editor.setOptions({ element: newElement }); } catch { } } render() { const { editor, innerRef, ...rest } = this.props; return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: mergeRefs(innerRef, this.editorContentRef), ...rest }), (editor == null ? void 0 : editor.contentComponent) && /* @__PURE__ */ jsxRuntimeExports.jsx(Portals, { contentComponent: editor.contentComponent }) ] }); } }; var EditorContentWithKey = reactExports.forwardRef( (props, ref) => { const key = React.useMemo(() => { return Math.floor(Math.random() * 4294967295).toString(); }, [props.editor]); return React.createElement(PureEditorContent, { key, innerRef: ref, ...props }); } ); var EditorContent = React.memo(EditorContentWithKey); var useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? reactExports.useLayoutEffect : reactExports.useEffect; var EditorStateManager = class { constructor(initialEditor) { this.transactionNumber = 0; this.lastTransactionNumber = 0; this.subscribers = /* @__PURE__ */ new Set(); this.editor = initialEditor; this.lastSnapshot = { editor: initialEditor, transactionNumber: 0 }; this.getSnapshot = this.getSnapshot.bind(this); this.getServerSnapshot = this.getServerSnapshot.bind(this); this.watch = this.watch.bind(this); this.subscribe = this.subscribe.bind(this); } /** * Get the current editor instance. */ getSnapshot() { if (this.transactionNumber === this.lastTransactionNumber) { return this.lastSnapshot; } this.lastTransactionNumber = this.transactionNumber; this.lastSnapshot = { editor: this.editor, transactionNumber: this.transactionNumber }; return this.lastSnapshot; } /** * Always disable the editor on the server-side. */ getServerSnapshot() { return { editor: null, transactionNumber: 0 }; } /** * Subscribe to the editor instance's changes. */ subscribe(callback) { this.subscribers.add(callback); return () => { this.subscribers.delete(callback); }; } /** * Watch the editor instance for changes. */ watch(nextEditor) { this.editor = nextEditor; if (this.editor) { const fn = () => { this.transactionNumber += 1; this.subscribers.forEach((callback) => callback()); }; const currentEditor = this.editor; currentEditor.on("transaction", fn); return () => { currentEditor.off("transaction", fn); }; } return void 0; } }; function useEditorState(options) { var _a; const [editorStateManager] = reactExports.useState(() => new EditorStateManager(options.editor)); const selectedState = withSelectorExports.useSyncExternalStoreWithSelector( editorStateManager.subscribe, editorStateManager.getSnapshot, editorStateManager.getServerSnapshot, options.selector, (_a = options.equalityFn) != null ? _a : deepEqual ); useIsomorphicLayoutEffect$1(() => { return editorStateManager.watch(options.editor); }, [options.editor, editorStateManager]); reactExports.useDebugValue(selectedState); return selectedState; } var isDev = process.env.NODE_ENV !== "production"; var isSSR = typeof window === "undefined"; var isNext = isSSR || Boolean(typeof window !== "undefined" && window.next); var EditorInstanceManager = class _EditorInstanceManager { constructor(options) { this.editor = null; this.subscriptions = /* @__PURE__ */ new Set(); this.isComponentMounted = false; this.previousDeps = null; this.instanceId = ""; this.options = options; this.subscriptions = /* @__PURE__ */ new Set(); this.setEditor(this.getInitialEditor()); this.scheduleDestroy(); this.getEditor = this.getEditor.bind(this); this.getServerSnapshot = this.getServerSnapshot.bind(this); this.subscribe = this.subscribe.bind(this); this.refreshEditorInstance = this.refreshEditorInstance.bind(this); this.scheduleDestroy = this.scheduleDestroy.bind(this); this.onRender = this.onRender.bind(this); this.createEditor = this.createEditor.bind(this); } setEditor(editor) { this.editor = editor; this.instanceId = Math.random().toString(36).slice(2, 9); this.subscriptions.forEach((cb) => cb()); } getInitialEditor() { if (this.options.current.immediatelyRender === void 0) { if (isSSR || isNext) { if (isDev) { throw new Error( "Tiptap Error: SSR has been detected, please set `immediatelyRender` explicitly to `false` to avoid hydration mismatches." ); } return null; } return this.createEditor(); } if (this.options.current.immediatelyRender && isSSR && isDev) { throw new Error( "Tiptap Error: SSR has been detected, and `immediatelyRender` has been set to `true` this is an unsupported configuration that may result in errors, explicitly set `immediatelyRender` to `false` to avoid hydration mismatches." ); } if (this.options.current.immediatelyRender) { return this.createEditor(); } return null; } /** * Create a new editor instance. And attach event listeners. */ createEditor() { const optionsToApply = { ...this.options.current, // Always call the most recent version of the callback function by default onBeforeCreate: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onBeforeCreate) == null ? void 0 : _b.call(_a, ...args); }, onBlur: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onBlur) == null ? void 0 : _b.call(_a, ...args); }, onCreate: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onCreate) == null ? void 0 : _b.call(_a, ...args); }, onDestroy: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onDestroy) == null ? void 0 : _b.call(_a, ...args); }, onFocus: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onFocus) == null ? void 0 : _b.call(_a, ...args); }, onSelectionUpdate: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onSelectionUpdate) == null ? void 0 : _b.call(_a, ...args); }, onTransaction: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onTransaction) == null ? void 0 : _b.call(_a, ...args); }, onUpdate: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onUpdate) == null ? void 0 : _b.call(_a, ...args); }, onContentError: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onContentError) == null ? void 0 : _b.call(_a, ...args); }, onDrop: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onDrop) == null ? void 0 : _b.call(_a, ...args); }, onPaste: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onPaste) == null ? void 0 : _b.call(_a, ...args); }, onDelete: (...args) => { var _a, _b; return (_b = (_a = this.options.current).onDelete) == null ? void 0 : _b.call(_a, ...args); } }; const editor = new Editor(optionsToApply); return editor; } /** * Get the current editor instance. */ getEditor() { return this.editor; } /** * Always disable the editor on the server-side. */ getServerSnapshot() { return null; } /** * Subscribe to the editor instance's changes. */ subscribe(onStoreChange) { this.subscriptions.add(onStoreChange); return () => { this.subscriptions.delete(onStoreChange); }; } static compareOptions(a, b) { return Object.keys(a).every((key) => { if ([ "onCreate", "onBeforeCreate", "onDestroy", "onUpdate", "onTransaction", "onFocus", "onBlur", "onSelectionUpdate", "onContentError", "onDrop", "onPaste" ].includes(key)) { return true; } if (key === "extensions" && a.extensions && b.extensions) { if (a.extensions.length !== b.extensions.length) { return false; } return a.extensions.every((extension, index) => { var _a; if (extension !== ((_a = b.extensions) == null ? void 0 : _a[index])) { return false; } return true; }); } if (a[key] !== b[key]) { return false; } return true; }); } /** * On each render, we will create, update, or destroy the editor instance. * @param deps The dependencies to watch for changes * @returns A cleanup function */ onRender(deps) { return () => { this.isComponentMounted = true; clearTimeout(this.scheduledDestructionTimeout); if (this.editor && !this.editor.isDestroyed && deps.length === 0) { if (!_EditorInstanceManager.compareOptions(this.options.current, this.editor.options)) { this.editor.setOptions({ ...this.options.current, editable: this.editor.isEditable }); } } else { this.refreshEditorInstance(deps); } return () => { this.isComponentMounted = false; this.scheduleDestroy(); }; }; } /** * Recreate the editor instance if the dependencies have changed. */ refreshEditorInstance(deps) { if (this.editor && !this.editor.isDestroyed) { if (this.previousDeps === null) { this.previousDeps = deps; return; } const depsAreEqual = this.previousDeps.length === deps.length && this.previousDeps.every((dep, index) => dep === deps[index]); if (depsAreEqual) { return; } } if (this.editor && !this.editor.isDestroyed) { this.editor.destroy(); } this.setEditor(this.createEditor()); this.previousDeps = deps; } /** * Schedule the destruction of the editor instance. * This will only destroy the editor if it was not mounted on the next tick. * This is to avoid destroying the editor instance when it's actually still mounted. */ scheduleDestroy() { const currentInstanceId = this.instanceId; const currentEditor = this.editor; this.scheduledDestructionTimeout = setTimeout(() => { if (this.isComponentMounted && this.instanceId === currentInstanceId) { if (currentEditor) { currentEditor.setOptions(this.options.current); } return; } if (currentEditor && !currentEditor.isDestroyed) { currentEditor.destroy(); if (this.instanceId === currentInstanceId) { this.setEditor(null); } } }, 1); } }; function useEditor(options = {}, deps = []) { const mostRecentOptions = reactExports.useRef(options); mostRecentOptions.current = options; const [instanceManager] = reactExports.useState(() => new EditorInstanceManager(mostRecentOptions)); const editor = shimExports.useSyncExternalStore( instanceManager.subscribe, instanceManager.getEditor, instanceManager.getServerSnapshot ); reactExports.useDebugValue(editor); reactExports.useEffect(instanceManager.onRender(deps)); useEditorState({ editor, selector: ({ transactionNumber }) => { if (options.shouldRerenderOnTransaction === false || options.shouldRerenderOnTransaction === void 0) { return null; } if (options.immediatelyRender && transactionNumber === 0) { return 0; } return transactionNumber + 1; } }); return editor; } var EditorContext = reactExports.createContext({ editor: null }); EditorContext.Consumer; var useCurrentEditor = () => reactExports.useContext(EditorContext); var ReactNodeViewContext = reactExports.createContext({ onDragStart: () => { }, nodeViewContentChildren: void 0, nodeViewContentRef: () => { } }); var useReactNodeView = () => reactExports.useContext(ReactNodeViewContext); var NodeViewWrapper = React.forwardRef((props, ref) => { const { onDragStart } = useReactNodeView(); const Tag = props.as || "div"; return ( // @ts-ignore /* @__PURE__ */ jsxRuntimeExports.jsx( Tag, { ...props, ref, "data-node-view-wrapper": "", onDragStart, style: { whiteSpace: "normal", ...props.style } } ) ); }); function isClassComponent(Component) { return !!(typeof Component === "function" && Component.prototype && Component.prototype.isReactComponent); } function isForwardRefComponent(Component) { return !!(typeof Component === "object" && Component.$$typeof && (Component.$$typeof.toString() === "Symbol(react.forward_ref)" || Component.$$typeof.description === "react.forward_ref")); } function isMemoComponent(Component) { return !!(typeof Component === "object" && Component.$$typeof && (Component.$$typeof.toString() === "Symbol(react.memo)" || Component.$$typeof.description === "react.memo")); } function canReceiveRef(Component) { if (isClassComponent(Component)) { return true; } if (isForwardRefComponent(Component)) { return true; } if (isMemoComponent(Component)) { const wrappedComponent = Component.type; if (wrappedComponent) { return isClassComponent(wrappedComponent) || isForwardRefComponent(wrappedComponent); } } return false; } function isReact19Plus() { try { if (reactExports.version) { const majorVersion = parseInt(reactExports.version.split(".")[0], 10); return majorVersion >= 19; } } catch { } return false; } var ReactRenderer = class { /** * Immediately creates element and renders the provided React component. */ constructor(component, { editor, props = {}, as = "div", className = "" }) { this.ref = null; this.destroyed = false; this.id = Math.floor(Math.random() * 4294967295).toString(); this.component = component; this.editor = editor; this.props = props; this.element = document.createElement(as); this.element.classList.add("react-renderer"); if (className) { this.element.classList.add(...className.split(" ")); } if (this.editor.isInitialized) { reactDomExports.flushSync(() => { this.render(); }); } else { queueMicrotask(() => { if (this.destroyed) { return; } this.render(); }); } } /** * Render the React component. */ render() { var _a; if (this.destroyed) { return; } const Component = this.component; const props = this.props; const editor = this.editor; const isReact19 = isReact19Plus(); const componentCanReceiveRef = canReceiveRef(Component); const elementProps = { ...props }; if (elementProps.ref && !(isReact19 || componentCanReceiveRef)) { delete elementProps.ref; } if (!elementProps.ref && (isReact19 || componentCanReceiveRef)) { elementProps.ref = (ref) => { this.ref = ref; }; } this.reactElement = /* @__PURE__ */ jsxRuntimeExports.jsx(Component, { ...elementProps }); (_a = editor == null ? void 0 : editor.contentComponent) == null ? void 0 : _a.setRenderer(this.id, this); } /** * Re-renders the React component with new props. */ updateProps(props = {}) { if (this.destroyed) { return; } this.props = { ...this.props, ...props }; this.render(); } /** * Destroy the React component. */ destroy() { var _a; this.destroyed = true; const editor = this.editor; (_a = editor == null ? void 0 : editor.contentComponent) == null ? void 0 : _a.removeRenderer(this.id); try { if (this.element && this.element.parentNode) { this.element.parentNode.removeChild(this.element); } } catch { } } /** * Update the attributes of the element that holds the React component. */ updateAttributes(attributes) { Object.keys(attributes).forEach((key) => { this.element.setAttribute(key, attributes[key]); }); } }; React.createContext({ markViewContentRef: () => { } }); var ReactNodeView = class extends NodeView { constructor(component, props, options) { super(component, props, options); this.selectionRafId = null; this.positionCheckCallback = null; this.cachedExtensionWithSyncedStorage = null; if (!this.node.isLeaf) { if (this.options.contentDOMElementTag) { this.contentDOMElement = document.createElement(this.options.contentDOMElementTag); } else { this.contentDOMElement = document.createElement(this.node.isInline ? "span" : "div"); } this.contentDOMElement.dataset.nodeViewContentReact = ""; this.contentDOMElement.dataset.nodeViewWrapper = ""; this.contentDOMElement.style.whiteSpace = "inherit"; const contentTarget = this.dom.querySelector("[data-node-view-content]"); if (!contentTarget) { return; } contentTarget.appendChild(this.contentDOMElement); } } /** * Returns a proxy of the extension that redirects storage access to the editor's mutable storage. * This preserves the original prototype chain (instanceof checks, methods like configure/extend work). * Cached to avoid proxy creation on every update. */ get extensionWithSyncedStorage() { if (!this.cachedExtensionWithSyncedStorage) { const editor = this.editor; const extension = this.extension; this.cachedExtensionWithSyncedStorage = new Proxy(extension, { get(target, prop, receiver) { var _a; if (prop === "storage") { return (_a = editor.storage[extension.name]) != null ? _a : {}; } return Reflect.get(target, prop, receiver); } }); } return this.cachedExtensionWithSyncedStorage; } /** * Setup the React component. * Called on initialization. */ mount() { const props = { editor: this.editor, node: this.node, decorations: this.decorations, innerDecorations: this.innerDecorations, view: this.view, selected: false, extension: this.extensionWithSyncedStorage, HTMLAttributes: this.HTMLAttributes, getPos: () => this.getPos(), updateAttributes: (attributes = {}) => this.updateAttributes(attributes), deleteNode: () => this.deleteNode(), ref: reactExports.createRef() }; if (!this.component.displayName) { const capitalizeFirstChar = (string) => { return string.charAt(0).toUpperCase() + string.substring(1); }; this.component.displayName = capitalizeFirstChar(this.extension.name); } const onDragStart = this.onDragStart.bind(this); const nodeViewContentRef = (element) => { if (element && this.contentDOMElement && element.firstChild !== this.contentDOMElement) { if (element.hasAttribute("data-node-view-wrapper")) { element.removeAttribute("data-node-view-wrapper"); } element.appendChild(this.contentDOMElement); } }; const context = { onDragStart, nodeViewContentRef }; const Component = this.component; const ReactNodeViewProvider = reactExports.memo((componentProps) => { return /* @__PURE__ */ jsxRuntimeExports.jsx(ReactNodeViewContext.Provider, { value: context, children: reactExports.createElement(Component, componentProps) }); }); ReactNodeViewProvider.displayName = "ReactNodeView"; let as = this.node.isInline ? "span" : "div"; if (this.options.as) { as = this.options.as; } const { className = "" } = this.options; this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this); this.renderer = new ReactRenderer(ReactNodeViewProvider, { editor: this.editor, props, as, className: `node-${this.node.type.name} ${className}`.trim() }); this.editor.on("selectionUpdate", this.handleSelectionUpdate); this.updateElementAttributes(); this.currentPos = this.getPos(); this.positionCheckCallback = () => { const newPos = this.getPos(); if (typeof newPos !== "number" || newPos === this.currentPos) { return; } this.currentPos = newPos; this.renderer.updateProps({ getPos: () => this.getPos() }); if (typeof this.options.attrs === "function") { this.updateElementAttributes(); } }; schedulePositionCheck(this.editor, this.positionCheckCallback); } /** * Return the DOM element. * This is the element that will be used to display the node view. */ get dom() { var _a; if (this.renderer.element.firstElementChild && !((_a = this.renderer.element.firstElementChild) == null ? void 0 : _a.hasAttribute("data-node-view-wrapper"))) { throw Error("Please use the NodeViewWrapper component for your node view."); } return this.renderer.element; } /** * Return the content DOM element. * This is the element that will be used to display the rich-text content of the node. */ get contentDOM() { if (this.node.isLeaf) { return null; } return this.contentDOMElement; } /** * On editor selection update, check if the node is selected. * If it is, call `selectNode`, otherwise call `deselectNode`. */ handleSelectionUpdate() { if (this.selectionRafId) { cancelAnimationFrame(this.selectionRafId); this.selectionRafId = null; } this.selectionRafId = requestAnimationFrame(() => { this.selectionRafId = null; const { from: from2, to } = this.editor.state.selection; const pos = this.currentPos; if (typeof pos !== "number") { return; } if (from2 <= pos && to >= pos + this.node.nodeSize) { if (this.renderer.props.selected) { return; } this.selectNode(); } else { if (!this.renderer.props.selected) { return; } this.deselectNode(); } }); } /** * On update, update the React component. * To prevent unnecessary updates, the `update` option can be used. */ update(node, decorations, innerDecorations) { const rerenderComponent = (props) => { this.renderer.updateProps(props); if (typeof this.options.attrs === "function") { this.updateElementAttributes(); } }; if (node.type !== this.node.type) { return false; } if (typeof this.options.update === "function") { const oldNode = this.node; const oldDecorations = this.decorations; const oldInnerDecorations = this.innerDecorations; this.node = node; this.decorations = decorations; this.innerDecorations = innerDecorations; this.currentPos = this.getPos(); return this.options.update({ oldNode, oldDecorations, newNode: node, newDecorations: decorations, oldInnerDecorations, innerDecorations, updateProps: () => rerenderComponent({ node, decorations, innerDecorations, extension: this.extensionWithSyncedStorage }) }); } const newPos = this.getPos(); if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) { if (newPos === this.currentPos) { return true; } this.currentPos = newPos; rerenderComponent({ node, decorations, innerDecorations, extension: this.extensionWithSyncedStorage, getPos: () => this.getPos() }); return true; } this.node = node; this.decorations = decorations; this.innerDecorations = innerDecorations; this.currentPos = newPos; rerenderComponent({ node, decorations, innerDecorations, extension: this.extensionWithSyncedStorage }); return true; } /** * Select the node. * Add the `selected` prop and the `ProseMirror-selectednode` class. */ selectNode() { this.renderer.updateProps({ selected: true }); this.renderer.element.classList.add("ProseMirror-selectednode"); } /** * Deselect the node. * Remove the `selected` prop and the `ProseMirror-selectednode` class. */ deselectNode() { this.renderer.updateProps({ selected: false }); this.renderer.element.classList.remove("ProseMirror-selectednode"); } /** * Destroy the React component instance. */ destroy() { this.renderer.destroy(); this.editor.off("selectionUpdate", this.handleSelectionUpdate); if (this.positionCheckCallback) { cancelPositionCheck(this.editor, this.positionCheckCallback); this.positionCheckCallback = null; } this.contentDOMElement = null; if (this.selectionRafId) { cancelAnimationFrame(this.selectionRafId); this.selectionRafId = null; } } /** * Update the attributes of the top-level element that holds the React component. * Applying the attributes defined in the `attrs` option. */ updateElementAttributes() { if (this.options.attrs) { let attrsObj = {}; if (typeof this.options.attrs === "function") { const extensionAttributes = this.editor.extensionManager.attributes; const HTMLAttributes = getRenderedAttributes(this.node, extensionAttributes); attrsObj = this.options.attrs({ node: this.node, HTMLAttributes }); } else { attrsObj = this.options.attrs; } this.renderer.updateAttributes(attrsObj); } } }; function ReactNodeViewRenderer(component, options) { return (props) => { if (!props.editor.contentComponent) { return {}; } return new ReactNodeView(component, props, options); }; } var TiptapContext = reactExports.createContext({ get editor() { throw new Error("useTiptap must be used within a provider"); } }); TiptapContext.displayName = "TiptapContext"; var useTiptap = () => reactExports.useContext(TiptapContext); function TiptapWrapper({ editor, instance, children }) { const resolvedEditor = editor != null ? editor : instance; if (!resolvedEditor) { throw new Error("Tiptap: An editor instance is required. Pass a non-null `editor` prop."); } const tiptapContextValue = reactExports.useMemo(() => ({ editor: resolvedEditor }), [resolvedEditor]); const legacyContextValue = reactExports.useMemo(() => ({ editor: resolvedEditor }), [resolvedEditor]); return /* @__PURE__ */ jsxRuntimeExports.jsx(EditorContext.Provider, { value: legacyContextValue, children: /* @__PURE__ */ jsxRuntimeExports.jsx(TiptapContext.Provider, { value: tiptapContextValue, children }) }); } TiptapWrapper.displayName = "Tiptap"; function TiptapContent({ ...rest }) { const { editor } = useTiptap(); return /* @__PURE__ */ jsxRuntimeExports.jsx(EditorContent, { editor, ...rest }); } TiptapContent.displayName = "Tiptap.Content"; Object.assign(TiptapWrapper, { /** * The Tiptap Content component that renders the EditorContent with the editor instance from the context. * @see TiptapContent */ Content: TiptapContent }); var h = (tag, attributes) => { if (tag === "slot") { return 0; } if (tag instanceof Function) { return tag(attributes); } const { children, ...rest } = attributes != null ? attributes : {}; if (tag === "svg") { throw new Error("SVG elements are not supported in the JSX syntax, use the array syntax instead"); } return [tag, rest, children]; }; var inputRegex$4 = /^\s*>\s$/; var Blockquote = Node3.create({ name: "blockquote", addOptions() { return { HTMLAttributes: {} }; }, content: "block+", group: "block", defining: true, parseHTML() { return [{ tag: "blockquote" }]; }, renderHTML({ HTMLAttributes }) { return /* @__PURE__ */ h("blockquote", { ...mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), children: /* @__PURE__ */ h("slot", {}) }); }, parseMarkdown: (token, helpers) => { var _a; const parseBlockChildren = (_a = helpers.parseBlockChildren) != null ? _a : helpers.parseChildren; return helpers.createNode("blockquote", void 0, parseBlockChildren(token.tokens || [])); }, renderMarkdown: (node, h2) => { if (!node.content) { return ""; } const prefix = ">"; const result = []; node.content.forEach((child, index) => { var _a, _b; const childContent = (_b = (_a = h2.renderChild) == null ? void 0 : _a.call(h2, child, index)) != null ? _b : h2.renderChildren([child]); const lines = childContent.split("\n"); const linesWithPrefix = lines.map((line) => { if (line.trim() === "") { return prefix; } return `${prefix} ${line}`; }); result.push(linesWithPrefix.join("\n")); }); return result.join(` ${prefix} `); }, addCommands() { return { setBlockquote: () => ({ commands }) => { return commands.wrapIn(this.name); }, toggleBlockquote: () => ({ commands }) => { return commands.toggleWrap(this.name); }, unsetBlockquote: () => ({ commands }) => { return commands.lift(this.name); } }; }, addKeyboardShortcuts() { return { "Mod-Shift-b": () => this.editor.commands.toggleBlockquote() }; }, addInputRules() { return [ wrappingInputRule({ find: inputRegex$4, type: this.type }) ]; } }); var starInputRegex$1 = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/; var starPasteRegex$1 = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g; var underscoreInputRegex$1 = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/; var underscorePasteRegex$1 = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g; var Bold = Mark2.create({ name: "bold", addOptions() { return { HTMLAttributes: {} }; }, parseHTML() { return [ { tag: "strong" }, { tag: "b", getAttrs: (node) => node.style.fontWeight !== "normal" && null }, { style: "font-weight=400", clearMark: (mark) => mark.type.name === this.name }, { style: "font-weight", getAttrs: (value) => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null } ]; }, renderHTML({ HTMLAttributes }) { return /* @__PURE__ */ h("strong", { ...mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), children: /* @__PURE__ */ h("slot", {}) }); }, markdownTokenName: "strong", parseMarkdown: (token, helpers) => { return helpers.applyMark("bold", helpers.parseInline(token.tokens || [])); }, markdownOptions: { htmlReopen: { open: "", close: "" } }, renderMarkdown: (node, h2) => { return `**${h2.renderChildren(node)}**`; }, addCommands() { return { setBold: () => ({ commands }) => { return commands.setMark(this.name); }, toggleBold: () => ({ commands }) => { return commands.toggleMark(this.name); }, unsetBold: () => ({ commands }) => { return commands.unsetMark(this.name); } }; }, addKeyboardShortcuts() { return { "Mod-b": () => this.editor.commands.toggleBold(), "Mod-B": () => this.editor.commands.toggleBold() }; }, addInputRules() { return [ markInputRule({ find: starInputRegex$1, type: this.type }), markInputRule({ find: underscoreInputRegex$1, type: this.type }) ]; }, addPasteRules() { return [ markPasteRule({ find: starPasteRegex$1, type: this.type }), markPasteRule({ find: underscorePasteRegex$1, type: this.type }) ]; } }); var inputRegex$3 = /(^|[^`])`([^`]+)`(?!`)$/; var pasteRegex$1 = /(^|[^`])`([^`]+)`(?!`)/g; var Code = Mark2.create({ name: "code", addOptions() { return { HTMLAttributes: {} }; }, excludes: "_", code: true, exitable: true, parseHTML() { return [{ tag: "code" }]; }, renderHTML({ HTMLAttributes }) { return ["code", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, markdownTokenName: "codespan", parseMarkdown: (token, helpers) => { return helpers.applyMark("code", [{ type: "text", text: token.text || "" }]); }, renderMarkdown: (node, h2) => { if (!node.content) { return ""; } return `\`${h2.renderChildren(node.content)}\``; }, addCommands() { return { setCode: () => ({ commands }) => { return commands.setMark(this.name); }, toggleCode: () => ({ commands }) => { return commands.toggleMark(this.name); }, unsetCode: () => ({ commands }) => { return commands.unsetMark(this.name); } }; }, addKeyboardShortcuts() { return { "Mod-e": () => this.editor.commands.toggleCode() }; }, addInputRules() { return [ markInputRule({ find: inputRegex$3, type: this.type }) ]; }, addPasteRules() { return [ markPasteRule({ find: pasteRegex$1, type: this.type }) ]; } }); var DEFAULT_TAB_SIZE = 4; var backtickInputRegex = /^```([a-z]+)?[\s\n]$/; var tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/; var CodeBlock = Node3.create({ name: "codeBlock", addOptions() { return { languageClassPrefix: "language-", exitOnTripleEnter: true, exitOnArrowDown: true, defaultLanguage: null, enableTabIndentation: false, tabSize: DEFAULT_TAB_SIZE, HTMLAttributes: {} }; }, content: "text*", marks: "", group: "block", code: true, defining: true, addAttributes() { return { language: { default: this.options.defaultLanguage, parseHTML: (element) => { var _a; const { languageClassPrefix } = this.options; if (!languageClassPrefix) { return null; } const classNames = [...((_a = element.firstElementChild) == null ? void 0 : _a.classList) || []]; const languages = classNames.filter((className) => className.startsWith(languageClassPrefix)).map((className) => className.replace(languageClassPrefix, "")); const language = languages[0]; if (!language) { return null; } return language; }, rendered: false } }; }, parseHTML() { return [ { tag: "pre", preserveWhitespace: "full" } ]; }, renderHTML({ node, HTMLAttributes }) { return [ "pre", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), [ "code", { class: node.attrs.language ? this.options.languageClassPrefix + node.attrs.language : null }, 0 ] ]; }, markdownTokenName: "code", parseMarkdown: (token, helpers) => { var _a, _b; if (((_a = token.raw) == null ? void 0 : _a.startsWith("```")) === false && ((_b = token.raw) == null ? void 0 : _b.startsWith("~~~")) === false && token.codeBlockStyle !== "indented") { return []; } return helpers.createNode( "codeBlock", { language: token.lang || null }, token.text ? [helpers.createTextNode(token.text)] : [] ); }, renderMarkdown: (node, h2) => { var _a; let output = ""; const language = ((_a = node.attrs) == null ? void 0 : _a.language) || ""; if (!node.content) { output = `\`\`\`${language} \`\`\``; } else { const lines = [`\`\`\`${language}`, h2.renderChildren(node.content), "```"]; output = lines.join("\n"); } return output; }, addCommands() { return { setCodeBlock: (attributes) => ({ commands }) => { return commands.setNode(this.name, attributes); }, toggleCodeBlock: (attributes) => ({ commands }) => { return commands.toggleNode(this.name, "paragraph", attributes); } }; }, addKeyboardShortcuts() { return { "Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(), // remove code block when at start of document or code block is empty Backspace: () => { const { empty: empty2, $anchor } = this.editor.state.selection; const isAtStart = $anchor.pos === 1; if (!empty2 || $anchor.parent.type.name !== this.name) { return false; } if (isAtStart || !$anchor.parent.textContent.length) { return this.editor.commands.clearNodes(); } return false; }, // handle tab indentation Tab: ({ editor }) => { var _a; if (!this.options.enableTabIndentation) { return false; } const tabSize = (_a = this.options.tabSize) != null ? _a : DEFAULT_TAB_SIZE; const { state } = editor; const { selection } = state; const { $from, empty: empty2 } = selection; if ($from.parent.type !== this.type) { return false; } const indent = " ".repeat(tabSize); if (empty2) { return editor.commands.insertContent(indent); } return editor.commands.command(({ tr: tr2 }) => { const { from: from2, to } = selection; const text = state.doc.textBetween(from2, to, "\n", "\n"); const lines = text.split("\n"); const indentedText = lines.map((line) => indent + line).join("\n"); tr2.replaceWith(from2, to, state.schema.text(indentedText)); return true; }); }, // handle shift+tab reverse indentation "Shift-Tab": ({ editor }) => { var _a; if (!this.options.enableTabIndentation) { return false; } const tabSize = (_a = this.options.tabSize) != null ? _a : DEFAULT_TAB_SIZE; const { state } = editor; const { selection } = state; const { $from, empty: empty2 } = selection; if ($from.parent.type !== this.type) { return false; } if (empty2) { return editor.commands.command(({ tr: tr2 }) => { var _a2; const { pos } = $from; const codeBlockStart = $from.start(); const codeBlockEnd = $from.end(); const allText = state.doc.textBetween(codeBlockStart, codeBlockEnd, "\n", "\n"); const lines = allText.split("\n"); let currentLineIndex = 0; let charCount = 0; const relativeCursorPos = pos - codeBlockStart; for (let i = 0; i < lines.length; i += 1) { if (charCount + lines[i].length >= relativeCursorPos) { currentLineIndex = i; break; } charCount += lines[i].length + 1; } const currentLine = lines[currentLineIndex]; const leadingSpaces = ((_a2 = currentLine.match(/^ */)) == null ? void 0 : _a2[0]) || ""; const spacesToRemove = Math.min(leadingSpaces.length, tabSize); if (spacesToRemove === 0) { return true; } let lineStartPos = codeBlockStart; for (let i = 0; i < currentLineIndex; i += 1) { lineStartPos += lines[i].length + 1; } tr2.delete(lineStartPos, lineStartPos + spacesToRemove); const cursorPosInLine = pos - lineStartPos; if (cursorPosInLine <= spacesToRemove) { tr2.setSelection(TextSelection.create(tr2.doc, lineStartPos)); } return true; }); } return editor.commands.command(({ tr: tr2 }) => { const { from: from2, to } = selection; const text = state.doc.textBetween(from2, to, "\n", "\n"); const lines = text.split("\n"); const reverseIndentText = lines.map((line) => { var _a2; const leadingSpaces = ((_a2 = line.match(/^ */)) == null ? void 0 : _a2[0]) || ""; const spacesToRemove = Math.min(leadingSpaces.length, tabSize); return line.slice(spacesToRemove); }).join("\n"); tr2.replaceWith(from2, to, state.schema.text(reverseIndentText)); return true; }); }, // exit node on triple enter Enter: ({ editor }) => { if (!this.options.exitOnTripleEnter) { return false; } const { state } = editor; const { selection } = state; const { $from, empty: empty2 } = selection; if (!empty2 || $from.parent.type !== this.type) { return false; } const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2; const endsWithDoubleNewline = $from.parent.textContent.endsWith("\n\n"); if (!isAtEnd || !endsWithDoubleNewline) { return false; } return editor.chain().command(({ tr: tr2 }) => { tr2.delete($from.pos - 2, $from.pos); return true; }).exitCode().run(); }, // exit node on arrow down ArrowDown: ({ editor }) => { if (!this.options.exitOnArrowDown) { return false; } const { state } = editor; const { selection, doc: doc2 } = state; const { $from, empty: empty2 } = selection; if (!empty2 || $from.parent.type !== this.type) { return false; } const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2; if (!isAtEnd) { return false; } const after = $from.after(); if (after === void 0) { return false; } const nodeAfter = doc2.nodeAt(after); if (nodeAfter) { return editor.commands.command(({ tr: tr2 }) => { tr2.setSelection(Selection.near(doc2.resolve(after))); return true; }); } return editor.commands.exitCode(); } }; }, addInputRules() { return [ textblockTypeInputRule({ find: backtickInputRegex, type: this.type, getAttributes: (match) => ({ language: match[1] }) }), textblockTypeInputRule({ find: tildeInputRegex, type: this.type, getAttributes: (match) => ({ language: match[1] }) }) ]; }, addProseMirrorPlugins() { return [ // this plugin creates a code block for pasted content from VS Code // we can also detect the copied code language new Plugin({ key: new PluginKey("codeBlockVSCodeHandler"), props: { handlePaste: (view, event) => { if (!event.clipboardData) { return false; } if (this.editor.isActive(this.type.name)) { return false; } const text = event.clipboardData.getData("text/plain"); const vscode = event.clipboardData.getData("vscode-editor-data"); const vscodeData = vscode ? JSON.parse(vscode) : void 0; const language = vscodeData == null ? void 0 : vscodeData.mode; if (!text || !language) { return false; } const { tr: tr2, schema } = view.state; const textNode = schema.text(text.replace(/\r\n?/g, "\n")); tr2.replaceSelectionWith(this.type.create({ language }, textNode)); if (tr2.selection.$from.parent.type !== this.type) { tr2.setSelection(TextSelection.near(tr2.doc.resolve(Math.max(0, tr2.selection.from - 2)))); } tr2.setMeta("paste", true); view.dispatch(tr2); return true; } } }) ]; } }); var Document = Node3.create({ name: "doc", topNode: true, content: "block+", renderMarkdown: (node, h2) => { if (!node.content) { return ""; } return h2.renderChildren(node.content, "\n\n"); } }); var HardBreak = Node3.create({ name: "hardBreak", markdownTokenName: "br", addOptions() { return { keepMarks: true, HTMLAttributes: {} }; }, inline: true, group: "inline", selectable: false, linebreakReplacement: true, parseHTML() { return [{ tag: "br" }]; }, renderHTML({ HTMLAttributes }) { return ["br", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]; }, renderText() { return "\n"; }, renderMarkdown: () => ` `, parseMarkdown: () => { return { type: "hardBreak" }; }, addCommands() { return { setHardBreak: () => ({ commands, chain, state, editor }) => { return commands.first([ () => commands.exitCode(), () => commands.command(() => { const { selection, storedMarks } = state; if (selection.$from.parent.type.spec.isolating) { return false; } const { keepMarks } = this.options; const { splittableMarks } = editor.extensionManager; const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks(); return chain().insertContent({ type: this.name }).command(({ tr: tr2, dispatch }) => { if (dispatch && marks && keepMarks) { const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name)); tr2.ensureMarks(filteredMarks); } return true; }).run(); }) ]); } }; }, addKeyboardShortcuts() { return { "Mod-Enter": () => this.editor.commands.setHardBreak(), "Shift-Enter": () => this.editor.commands.setHardBreak() }; } }); var Heading = Node3.create({ name: "heading", addOptions() { return { levels: [1, 2, 3, 4, 5, 6], HTMLAttributes: {} }; }, content: "inline*", group: "block", defining: true, addAttributes() { return { level: { default: 1, rendered: false } }; }, parseHTML() { return this.options.levels.map((level) => ({ tag: `h${level}`, attrs: { level } })); }, renderHTML({ node, HTMLAttributes }) { const hasLevel = this.options.levels.includes(node.attrs.level); const level = hasLevel ? node.attrs.level : this.options.levels[0]; return [`h${level}`, mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, parseMarkdown: (token, helpers) => { return helpers.createNode("heading", { level: token.depth || 1 }, helpers.parseInline(token.tokens || [])); }, renderMarkdown: (node, h2) => { var _a; const level = ((_a = node.attrs) == null ? void 0 : _a.level) ? parseInt(node.attrs.level, 10) : 1; const headingChars = "#".repeat(level); if (!node.content) { return ""; } return `${headingChars} ${h2.renderChildren(node.content)}`; }, addCommands() { return { setHeading: (attributes) => ({ commands }) => { if (!this.options.levels.includes(attributes.level)) { return false; } return commands.setNode(this.name, attributes); }, toggleHeading: (attributes) => ({ commands }) => { if (!this.options.levels.includes(attributes.level)) { return false; } return commands.toggleNode(this.name, "paragraph", attributes); } }; }, addKeyboardShortcuts() { return this.options.levels.reduce( (items, level) => ({ ...items, ...{ [`Mod-Alt-${level}`]: () => this.editor.commands.toggleHeading({ level }) } }), {} ); }, addInputRules() { return this.options.levels.map((level) => { return textblockTypeInputRule({ find: new RegExp(`^(#{${Math.min(...this.options.levels)},${level}})\\s$`), type: this.type, getAttributes: { level } }); }); } }); var HorizontalRule = Node3.create({ name: "horizontalRule", addOptions() { return { HTMLAttributes: {}, nextNodeType: "paragraph" }; }, group: "block", parseHTML() { return [{ tag: "hr" }]; }, renderHTML({ HTMLAttributes }) { return ["hr", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]; }, markdownTokenName: "hr", parseMarkdown: (token, helpers) => { return helpers.createNode("horizontalRule"); }, renderMarkdown: () => { return "---"; }, addCommands() { return { setHorizontalRule: () => ({ chain, state }) => { if (!canInsertNode(state, state.schema.nodes[this.name])) { return false; } const { selection } = state; const { $to: $originTo } = selection; const currentChain = chain(); if (isNodeSelection(selection)) { currentChain.insertContentAt($originTo.pos, { type: this.name }); } else { currentChain.insertContent({ type: this.name }); } return currentChain.command(({ state: chainState, tr: tr2, dispatch }) => { if (dispatch) { const { $to } = tr2.selection; const posAfter = $to.end(); if ($to.nodeAfter) { if ($to.nodeAfter.isTextblock) { tr2.setSelection(TextSelection.create(tr2.doc, $to.pos + 1)); } else if ($to.nodeAfter.isBlock) { tr2.setSelection(NodeSelection.create(tr2.doc, $to.pos)); } else { tr2.setSelection(TextSelection.create(tr2.doc, $to.pos)); } } else { const nodeType = chainState.schema.nodes[this.options.nextNodeType] || $to.parent.type.contentMatch.defaultType; const node = nodeType == null ? void 0 : nodeType.create(); if (node) { tr2.insert(posAfter, node); tr2.setSelection(TextSelection.create(tr2.doc, posAfter + 1)); } } tr2.scrollIntoView(); } return true; }).run(); } }; }, addInputRules() { return [ nodeInputRule({ find: /^(?:---|—-|___\s|\*\*\*\s)$/, type: this.type }) ]; } }); var starInputRegex = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/; var starPasteRegex = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g; var underscoreInputRegex = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/; var underscorePasteRegex = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g; var Italic = Mark2.create({ name: "italic", addOptions() { return { HTMLAttributes: {} }; }, parseHTML() { return [ { tag: "em" }, { tag: "i", getAttrs: (node) => node.style.fontStyle !== "normal" && null }, { style: "font-style=normal", clearMark: (mark) => mark.type.name === this.name }, { style: "font-style=italic" } ]; }, renderHTML({ HTMLAttributes }) { return ["em", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, addCommands() { return { setItalic: () => ({ commands }) => { return commands.setMark(this.name); }, toggleItalic: () => ({ commands }) => { return commands.toggleMark(this.name); }, unsetItalic: () => ({ commands }) => { return commands.unsetMark(this.name); } }; }, markdownTokenName: "em", parseMarkdown: (token, helpers) => { return helpers.applyMark("italic", helpers.parseInline(token.tokens || [])); }, markdownOptions: { htmlReopen: { open: "", close: "" } }, renderMarkdown: (node, h2) => { return `*${h2.renderChildren(node)}*`; }, addKeyboardShortcuts() { return { "Mod-i": () => this.editor.commands.toggleItalic(), "Mod-I": () => this.editor.commands.toggleItalic() }; }, addInputRules() { return [ markInputRule({ find: starInputRegex, type: this.type }), markInputRule({ find: underscoreInputRegex, type: this.type }) ]; }, addPasteRules() { return [ markPasteRule({ find: starPasteRegex, type: this.type }), markPasteRule({ find: underscorePasteRegex, type: this.type }) ]; } }); const encodedTlds = "aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2"; const encodedUtlds = "ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2"; const numeric = "numeric"; const ascii = "ascii"; const alpha = "alpha"; const asciinumeric = "asciinumeric"; const alphanumeric = "alphanumeric"; const domain = "domain"; const emoji = "emoji"; const scheme = "scheme"; const slashscheme = "slashscheme"; const whitespace = "whitespace"; function registerGroup(name, groups) { if (!(name in groups)) { groups[name] = []; } return groups[name]; } function addToGroups(t, flags, groups) { if (flags[numeric]) { flags[asciinumeric] = true; flags[alphanumeric] = true; } if (flags[ascii]) { flags[asciinumeric] = true; flags[alpha] = true; } if (flags[asciinumeric]) { flags[alphanumeric] = true; } if (flags[alpha]) { flags[alphanumeric] = true; } if (flags[alphanumeric]) { flags[domain] = true; } if (flags[emoji]) { flags[domain] = true; } for (const k in flags) { const group = registerGroup(k, groups); if (group.indexOf(t) < 0) { group.push(t); } } } function flagsForToken(t, groups) { const result = {}; for (const c in groups) { if (groups[c].indexOf(t) >= 0) { result[c] = true; } } return result; } function State(token = null) { this.j = {}; this.jr = []; this.jd = null; this.t = token; } State.groups = {}; State.prototype = { accepts() { return !!this.t; }, /** * Follow an existing transition from the given input to the next state. * Does not mutate. * @param {string} input character or token type to transition on * @returns {?State} the next state, if any */ go(input) { const state = this; const nextState = state.j[input]; if (nextState) { return nextState; } for (let i = 0; i < state.jr.length; i++) { const regex = state.jr[i][0]; const nextState2 = state.jr[i][1]; if (nextState2 && regex.test(input)) { return nextState2; } } return state.jd; }, /** * Whether the state has a transition for the given input. Set the second * argument to true to only look for an exact match (and not a default or * regular-expression-based transition) * @param {string} input * @param {boolean} exactOnly */ has(input, exactOnly = false) { return exactOnly ? input in this.j : !!this.go(input); }, /** * Short for "transition all"; create a transition from the array of items * in the given list to the same final resulting state. * @param {string | string[]} inputs Group of inputs to transition on * @param {Transition | State} [next] Transition options * @param {Flags} [flags] Collections flags to add token to * @param {Collections} [groups] Master list of token groups */ ta(inputs, next, flags, groups) { for (let i = 0; i < inputs.length; i++) { this.tt(inputs[i], next, flags, groups); } }, /** * Short for "take regexp transition"; defines a transition for this state * when it encounters a token which matches the given regular expression * @param {RegExp} regexp Regular expression transition (populate first) * @param {T | State} [next] Transition options * @param {Flags} [flags] Collections flags to add token to * @param {Collections} [groups] Master list of token groups * @returns {State} taken after the given input */ tr(regexp, next, flags, groups) { groups = groups || State.groups; let nextState; if (next && next.j) { nextState = next; } else { nextState = new State(next); if (flags && groups) { addToGroups(next, flags, groups); } } this.jr.push([regexp, nextState]); return nextState; }, /** * Short for "take transitions", will take as many sequential transitions as * the length of the given input and returns the * resulting final state. * @param {string | string[]} input * @param {T | State} [next] Transition options * @param {Flags} [flags] Collections flags to add token to * @param {Collections} [groups] Master list of token groups * @returns {State} taken after the given input */ ts(input, next, flags, groups) { let state = this; const len = input.length; if (!len) { return state; } for (let i = 0; i < len - 1; i++) { state = state.tt(input[i]); } return state.tt(input[len - 1], next, flags, groups); }, /** * Short for "take transition", this is a method for building/working with * state machines. * * If a state already exists for the given input, returns it. * * If a token is specified, that state will emit that token when reached by * the linkify engine. * * If no state exists, it will be initialized with some default transitions * that resemble existing default transitions. * * If a state is given for the second argument, that state will be * transitioned to on the given input regardless of what that input * previously did. * * Specify a token group flags to define groups that this token belongs to. * The token will be added to corresponding entires in the given groups * object. * * @param {string} input character, token type to transition on * @param {T | State} [next] Transition options * @param {Flags} [flags] Collections flags to add token to * @param {Collections} [groups] Master list of groups * @returns {State} taken after the given input */ tt(input, next, flags, groups) { groups = groups || State.groups; const state = this; if (next && next.j) { state.j[input] = next; return next; } const t = next; let nextState, templateState = state.go(input); if (templateState) { nextState = new State(); Object.assign(nextState.j, templateState.j); nextState.jr.push.apply(nextState.jr, templateState.jr); nextState.jd = templateState.jd; nextState.t = templateState.t; } else { nextState = new State(); } if (t) { if (groups) { if (nextState.t && typeof nextState.t === "string") { const allFlags = Object.assign(flagsForToken(nextState.t, groups), flags); addToGroups(t, allFlags, groups); } else if (flags) { addToGroups(t, flags, groups); } } nextState.t = t; } state.j[input] = nextState; return nextState; } }; const ta = (state, input, next, flags, groups) => state.ta(input, next, flags, groups); const tr = (state, regexp, next, flags, groups) => state.tr(regexp, next, flags, groups); const ts = (state, input, next, flags, groups) => state.ts(input, next, flags, groups); const tt = (state, input, next, flags, groups) => state.tt(input, next, flags, groups); const WORD = "WORD"; const UWORD = "UWORD"; const ASCIINUMERICAL = "ASCIINUMERICAL"; const ALPHANUMERICAL = "ALPHANUMERICAL"; const LOCALHOST = "LOCALHOST"; const TLD = "TLD"; const UTLD = "UTLD"; const SCHEME = "SCHEME"; const SLASH_SCHEME = "SLASH_SCHEME"; const NUM = "NUM"; const WS = "WS"; const NL = "NL"; const OPENBRACE = "OPENBRACE"; const CLOSEBRACE = "CLOSEBRACE"; const OPENBRACKET = "OPENBRACKET"; const CLOSEBRACKET = "CLOSEBRACKET"; const OPENPAREN = "OPENPAREN"; const CLOSEPAREN = "CLOSEPAREN"; const OPENANGLEBRACKET = "OPENANGLEBRACKET"; const CLOSEANGLEBRACKET = "CLOSEANGLEBRACKET"; const FULLWIDTHLEFTPAREN = "FULLWIDTHLEFTPAREN"; const FULLWIDTHRIGHTPAREN = "FULLWIDTHRIGHTPAREN"; const LEFTCORNERBRACKET = "LEFTCORNERBRACKET"; const RIGHTCORNERBRACKET = "RIGHTCORNERBRACKET"; const LEFTWHITECORNERBRACKET = "LEFTWHITECORNERBRACKET"; const RIGHTWHITECORNERBRACKET = "RIGHTWHITECORNERBRACKET"; const FULLWIDTHLESSTHAN = "FULLWIDTHLESSTHAN"; const FULLWIDTHGREATERTHAN = "FULLWIDTHGREATERTHAN"; const AMPERSAND = "AMPERSAND"; const APOSTROPHE = "APOSTROPHE"; const ASTERISK = "ASTERISK"; const AT = "AT"; const BACKSLASH = "BACKSLASH"; const BACKTICK = "BACKTICK"; const CARET = "CARET"; const COLON = "COLON"; const COMMA = "COMMA"; const DOLLAR = "DOLLAR"; const DOT = "DOT"; const EQUALS = "EQUALS"; const EXCLAMATION = "EXCLAMATION"; const HYPHEN = "HYPHEN"; const PERCENT = "PERCENT"; const PIPE = "PIPE"; const PLUS = "PLUS"; const POUND = "POUND"; const QUERY = "QUERY"; const QUOTE = "QUOTE"; const FULLWIDTHMIDDLEDOT = "FULLWIDTHMIDDLEDOT"; const SEMI = "SEMI"; const SLASH = "SLASH"; const TILDE = "TILDE"; const UNDERSCORE = "UNDERSCORE"; const EMOJI$1 = "EMOJI"; const SYM = "SYM"; var tk = /* @__PURE__ */ Object.freeze({ __proto__: null, ALPHANUMERICAL, AMPERSAND, APOSTROPHE, ASCIINUMERICAL, ASTERISK, AT, BACKSLASH, BACKTICK, CARET, CLOSEANGLEBRACKET, CLOSEBRACE, CLOSEBRACKET, CLOSEPAREN, COLON, COMMA, DOLLAR, DOT, EMOJI: EMOJI$1, EQUALS, EXCLAMATION, FULLWIDTHGREATERTHAN, FULLWIDTHLEFTPAREN, FULLWIDTHLESSTHAN, FULLWIDTHMIDDLEDOT, FULLWIDTHRIGHTPAREN, HYPHEN, LEFTCORNERBRACKET, LEFTWHITECORNERBRACKET, LOCALHOST, NL, NUM, OPENANGLEBRACKET, OPENBRACE, OPENBRACKET, OPENPAREN, PERCENT, PIPE, PLUS, POUND, QUERY, QUOTE, RIGHTCORNERBRACKET, RIGHTWHITECORNERBRACKET, SCHEME, SEMI, SLASH, SLASH_SCHEME, SYM, TILDE, TLD, UNDERSCORE, UTLD, UWORD, WORD, WS }); const ASCII_LETTER = /[a-z]/; const LETTER = new RegExp("\\p{L}", "u"); const EMOJI = new RegExp("\\p{Emoji}", "u"); const DIGIT = /\d/; const SPACE = /\s/; const CR = "\r"; const LF = "\n"; const EMOJI_VARIATION = "️"; const EMOJI_JOINER = "‍"; const OBJECT_REPLACEMENT = ""; let tlds = null, utlds = null; function init$2(customSchemes = []) { const groups = {}; State.groups = groups; const Start = new State(); if (tlds == null) { tlds = decodeTlds(encodedTlds); } if (utlds == null) { utlds = decodeTlds(encodedUtlds); } tt(Start, "'", APOSTROPHE); tt(Start, "{", OPENBRACE); tt(Start, "}", CLOSEBRACE); tt(Start, "[", OPENBRACKET); tt(Start, "]", CLOSEBRACKET); tt(Start, "(", OPENPAREN); tt(Start, ")", CLOSEPAREN); tt(Start, "<", OPENANGLEBRACKET); tt(Start, ">", CLOSEANGLEBRACKET); tt(Start, "(", FULLWIDTHLEFTPAREN); tt(Start, ")", FULLWIDTHRIGHTPAREN); tt(Start, "「", LEFTCORNERBRACKET); tt(Start, "」", RIGHTCORNERBRACKET); tt(Start, "『", LEFTWHITECORNERBRACKET); tt(Start, "』", RIGHTWHITECORNERBRACKET); tt(Start, "<", FULLWIDTHLESSTHAN); tt(Start, ">", FULLWIDTHGREATERTHAN); tt(Start, "&", AMPERSAND); tt(Start, "*", ASTERISK); tt(Start, "@", AT); tt(Start, "`", BACKTICK); tt(Start, "^", CARET); tt(Start, ":", COLON); tt(Start, ",", COMMA); tt(Start, "$", DOLLAR); tt(Start, ".", DOT); tt(Start, "=", EQUALS); tt(Start, "!", EXCLAMATION); tt(Start, "-", HYPHEN); tt(Start, "%", PERCENT); tt(Start, "|", PIPE); tt(Start, "+", PLUS); tt(Start, "#", POUND); tt(Start, "?", QUERY); tt(Start, '"', QUOTE); tt(Start, "/", SLASH); tt(Start, ";", SEMI); tt(Start, "~", TILDE); tt(Start, "_", UNDERSCORE); tt(Start, "\\", BACKSLASH); tt(Start, "・", FULLWIDTHMIDDLEDOT); const Num = tr(Start, DIGIT, NUM, { [numeric]: true }); tr(Num, DIGIT, Num); const Asciinumeric = tr(Num, ASCII_LETTER, ASCIINUMERICAL, { [asciinumeric]: true }); const Alphanumeric = tr(Num, LETTER, ALPHANUMERICAL, { [alphanumeric]: true }); const Word = tr(Start, ASCII_LETTER, WORD, { [ascii]: true }); tr(Word, DIGIT, Asciinumeric); tr(Word, ASCII_LETTER, Word); tr(Asciinumeric, DIGIT, Asciinumeric); tr(Asciinumeric, ASCII_LETTER, Asciinumeric); const UWord = tr(Start, LETTER, UWORD, { [alpha]: true }); tr(UWord, ASCII_LETTER); tr(UWord, DIGIT, Alphanumeric); tr(UWord, LETTER, UWord); tr(Alphanumeric, DIGIT, Alphanumeric); tr(Alphanumeric, ASCII_LETTER); tr(Alphanumeric, LETTER, Alphanumeric); const Nl2 = tt(Start, LF, NL, { [whitespace]: true }); const Cr = tt(Start, CR, WS, { [whitespace]: true }); const Ws = tr(Start, SPACE, WS, { [whitespace]: true }); tt(Start, OBJECT_REPLACEMENT, Ws); tt(Cr, LF, Nl2); tt(Cr, OBJECT_REPLACEMENT, Ws); tr(Cr, SPACE, Ws); tt(Ws, CR); tt(Ws, LF); tr(Ws, SPACE, Ws); tt(Ws, OBJECT_REPLACEMENT, Ws); const Emoji = tr(Start, EMOJI, EMOJI$1, { [emoji]: true }); tt(Emoji, "#"); tr(Emoji, EMOJI, Emoji); tt(Emoji, EMOJI_VARIATION, Emoji); const EmojiJoiner = tt(Emoji, EMOJI_JOINER); tt(EmojiJoiner, "#"); tr(EmojiJoiner, EMOJI, Emoji); const wordjr = [[ASCII_LETTER, Word], [DIGIT, Asciinumeric]]; const uwordjr = [[ASCII_LETTER, null], [LETTER, UWord], [DIGIT, Alphanumeric]]; for (let i = 0; i < tlds.length; i++) { fastts(Start, tlds[i], TLD, WORD, wordjr); } for (let i = 0; i < utlds.length; i++) { fastts(Start, utlds[i], UTLD, UWORD, uwordjr); } addToGroups(TLD, { tld: true, ascii: true }, groups); addToGroups(UTLD, { utld: true, alpha: true }, groups); fastts(Start, "file", SCHEME, WORD, wordjr); fastts(Start, "mailto", SCHEME, WORD, wordjr); fastts(Start, "http", SLASH_SCHEME, WORD, wordjr); fastts(Start, "https", SLASH_SCHEME, WORD, wordjr); fastts(Start, "ftp", SLASH_SCHEME, WORD, wordjr); fastts(Start, "ftps", SLASH_SCHEME, WORD, wordjr); addToGroups(SCHEME, { scheme: true, ascii: true }, groups); addToGroups(SLASH_SCHEME, { slashscheme: true, ascii: true }, groups); customSchemes = customSchemes.sort((a, b) => a[0] > b[0] ? 1 : -1); for (let i = 0; i < customSchemes.length; i++) { const sch = customSchemes[i][0]; const optionalSlashSlash = customSchemes[i][1]; const flags = optionalSlashSlash ? { [scheme]: true } : { [slashscheme]: true }; if (sch.indexOf("-") >= 0) { flags[domain] = true; } else if (!ASCII_LETTER.test(sch)) { flags[numeric] = true; } else if (DIGIT.test(sch)) { flags[asciinumeric] = true; } else { flags[ascii] = true; } ts(Start, sch, sch, flags); } ts(Start, "localhost", LOCALHOST, { ascii: true }); Start.jd = new State(SYM); return { start: Start, tokens: Object.assign({ groups }, tk) }; } function run$1(start, str) { const iterable = stringToArray(str.replace(/[A-Z]/g, (c) => c.toLowerCase())); const charCount = iterable.length; const tokens = []; let cursor = 0; let charCursor = 0; while (charCursor < charCount) { let state = start; let nextState = null; let tokenLength = 0; let latestAccepting = null; let sinceAccepts = -1; let charsSinceAccepts = -1; while (charCursor < charCount && (nextState = state.go(iterable[charCursor]))) { state = nextState; if (state.accepts()) { sinceAccepts = 0; charsSinceAccepts = 0; latestAccepting = state; } else if (sinceAccepts >= 0) { sinceAccepts += iterable[charCursor].length; charsSinceAccepts++; } tokenLength += iterable[charCursor].length; cursor += iterable[charCursor].length; charCursor++; } cursor -= sinceAccepts; charCursor -= charsSinceAccepts; tokenLength -= sinceAccepts; tokens.push({ t: latestAccepting.t, // token type/name v: str.slice(cursor - tokenLength, cursor), // string value s: cursor - tokenLength, // start index e: cursor // end index (excluding) }); } return tokens; } function stringToArray(str) { const result = []; const len = str.length; let index = 0; while (index < len) { let first2 = str.charCodeAt(index); let second; let char = first2 < 55296 || first2 > 56319 || index + 1 === len || (second = str.charCodeAt(index + 1)) < 56320 || second > 57343 ? str[index] : str.slice(index, index + 2); result.push(char); index += char.length; } return result; } function fastts(state, input, t, defaultt, jr) { let next; const len = input.length; for (let i = 0; i < len - 1; i++) { const char = input[i]; if (state.j[char]) { next = state.j[char]; } else { next = new State(defaultt); next.jr = jr.slice(); state.j[char] = next; } state = next; } next = new State(t); next.jr = jr.slice(); state.j[input[len - 1]] = next; return next; } function decodeTlds(encoded) { const words = []; const stack = []; let i = 0; let digits = "0123456789"; while (i < encoded.length) { let popDigitCount = 0; while (digits.indexOf(encoded[i + popDigitCount]) >= 0) { popDigitCount++; } if (popDigitCount > 0) { words.push(stack.join("")); for (let popCount = parseInt(encoded.substring(i, i + popDigitCount), 10); popCount > 0; popCount--) { stack.pop(); } i += popDigitCount; } else { stack.push(encoded[i]); i++; } } return words; } const defaults = { defaultProtocol: "http", events: null, format: noop, formatHref: noop, nl2br: false, tagName: "a", target: null, rel: null, validate: true, truncate: Infinity, className: null, attributes: null, ignoreTags: [], render: null }; function Options(opts, defaultRender = null) { let o = Object.assign({}, defaults); if (opts) { o = Object.assign(o, opts instanceof Options ? opts.o : opts); } const ignoredTags = o.ignoreTags; const uppercaseIgnoredTags = []; for (let i = 0; i < ignoredTags.length; i++) { uppercaseIgnoredTags.push(ignoredTags[i].toUpperCase()); } this.o = o; if (defaultRender) { this.defaultRender = defaultRender; } this.ignoreTags = uppercaseIgnoredTags; } Options.prototype = { o: defaults, /** * @type string[] */ ignoreTags: [], /** * @param {IntermediateRepresentation} ir * @returns {any} */ defaultRender(ir) { return ir; }, /** * Returns true or false based on whether a token should be displayed as a * link based on the user options. * @param {MultiToken} token * @returns {boolean} */ check(token) { return this.get("validate", token.toString(), token); }, // Private methods /** * Resolve an option's value based on the value of the option and the given * params. If operator and token are specified and the target option is * callable, automatically calls the function with the given argument. * @template {keyof Opts} K * @param {K} key Name of option to use * @param {string} [operator] will be passed to the target option if it's a * function. If not specified, RAW function value gets returned * @param {MultiToken} [token] The token from linkify.tokenize * @returns {Opts[K] | any} */ get(key, operator, token) { const isCallable = operator != null; let option = this.o[key]; if (!option) { return option; } if (typeof option === "object") { option = token.t in option ? option[token.t] : defaults[key]; if (typeof option === "function" && isCallable) { option = option(operator, token); } } else if (typeof option === "function" && isCallable) { option = option(operator, token.t, token); } return option; }, /** * @template {keyof Opts} L * @param {L} key Name of options object to use * @param {string} [operator] * @param {MultiToken} [token] * @returns {Opts[L] | any} */ getObj(key, operator, token) { let obj = this.o[key]; if (typeof obj === "function" && operator != null) { obj = obj(operator, token.t, token); } return obj; }, /** * Convert the given token to a rendered element that may be added to the * calling-interface's DOM * @param {MultiToken} token Token to render to an HTML element * @returns {any} Render result; e.g., HTML string, DOM element, React * Component, etc. */ render(token) { const ir = token.render(this); const renderFn = this.get("render", null, token) || this.defaultRender; return renderFn(ir, token.t, token); } }; function noop(val) { return val; } function MultiToken(value, tokens) { this.t = "token"; this.v = value; this.tk = tokens; } MultiToken.prototype = { isLink: false, /** * Return the string this token represents. * @return {string} */ toString() { return this.v; }, /** * What should the value for this token be in the `href` HTML attribute? * Returns the `.toString` value by default. * @param {string} [scheme] * @return {string} */ toHref(scheme2) { return this.toString(); }, /** * @param {Options} options Formatting options * @returns {string} */ toFormattedString(options) { const val = this.toString(); const truncate = options.get("truncate", val, this); const formatted = options.get("format", val, this); return truncate && formatted.length > truncate ? formatted.substring(0, truncate) + "…" : formatted; }, /** * * @param {Options} options * @returns {string} */ toFormattedHref(options) { return options.get("formatHref", this.toHref(options.get("defaultProtocol")), this); }, /** * The start index of this token in the original input string * @returns {number} */ startIndex() { return this.tk[0].s; }, /** * The end index of this token in the original input string (up to this * index but not including it) * @returns {number} */ endIndex() { return this.tk[this.tk.length - 1].e; }, /** Returns an object of relevant values for this token, which includes keys * type - Kind of token ('url', 'email', etc.) * value - Original text * href - The value that should be added to the anchor tag's href attribute @method toObject @param {string} [protocol] `'http'` by default */ toObject(protocol = defaults.defaultProtocol) { return { type: this.t, value: this.toString(), isLink: this.isLink, href: this.toHref(protocol), start: this.startIndex(), end: this.endIndex() }; }, /** * * @param {Options} options Formatting option */ toFormattedObject(options) { return { type: this.t, value: this.toFormattedString(options), isLink: this.isLink, href: this.toFormattedHref(options), start: this.startIndex(), end: this.endIndex() }; }, /** * Whether this token should be rendered as a link according to the given options * @param {Options} options * @returns {boolean} */ validate(options) { return options.get("validate", this.toString(), this); }, /** * Return an object that represents how this link should be rendered. * @param {Options} options Formattinng options */ render(options) { const token = this; const href = this.toHref(options.get("defaultProtocol")); const formattedHref = options.get("formatHref", href, this); const tagName = options.get("tagName", href, token); const content = this.toFormattedString(options); const attributes = {}; const className = options.get("className", href, token); const target = options.get("target", href, token); const rel = options.get("rel", href, token); const attrs = options.getObj("attributes", href, token); const eventListeners = options.getObj("events", href, token); attributes.href = formattedHref; if (className) { attributes.class = className; } if (target) { attributes.target = target; } if (rel) { attributes.rel = rel; } if (attrs) { Object.assign(attributes, attrs); } return { tagName, attributes, content, eventListeners }; } }; function createTokenClass(type, props) { class Token extends MultiToken { constructor(value, tokens) { super(value, tokens); this.t = type; } } for (const p in props) { Token.prototype[p] = props[p]; } Token.t = type; return Token; } const Email = createTokenClass("email", { isLink: true, toHref() { return "mailto:" + this.toString(); } }); const Text$1 = createTokenClass("text"); const Nl = createTokenClass("nl"); const Url = createTokenClass("url", { isLink: true, /** Lowercases relevant parts of the domain and adds the protocol if required. Note that this will not escape unsafe HTML characters in the URL. @param {string} [scheme] default scheme (e.g., 'https') @return {string} the full href */ toHref(scheme2 = defaults.defaultProtocol) { return this.hasProtocol() ? this.v : `${scheme2}://${this.v}`; }, /** * Check whether this URL token has a protocol * @return {boolean} */ hasProtocol() { const tokens = this.tk; return tokens.length >= 2 && tokens[0].t !== LOCALHOST && tokens[1].t === COLON; } }); const makeState = (arg) => new State(arg); function init$1({ groups }) { const qsAccepting = groups.domain.concat([AMPERSAND, ASTERISK, AT, BACKSLASH, BACKTICK, CARET, DOLLAR, EQUALS, HYPHEN, NUM, PERCENT, PIPE, PLUS, POUND, SLASH, SYM, TILDE, UNDERSCORE]); const qsNonAccepting = [APOSTROPHE, COLON, COMMA, DOT, EXCLAMATION, PERCENT, QUERY, QUOTE, SEMI, OPENANGLEBRACKET, CLOSEANGLEBRACKET, OPENBRACE, CLOSEBRACE, CLOSEBRACKET, OPENBRACKET, OPENPAREN, CLOSEPAREN, FULLWIDTHLEFTPAREN, FULLWIDTHRIGHTPAREN, LEFTCORNERBRACKET, RIGHTCORNERBRACKET, LEFTWHITECORNERBRACKET, RIGHTWHITECORNERBRACKET, FULLWIDTHLESSTHAN, FULLWIDTHGREATERTHAN]; const localpartAccepting = [AMPERSAND, APOSTROPHE, ASTERISK, BACKSLASH, BACKTICK, CARET, DOLLAR, EQUALS, HYPHEN, OPENBRACE, CLOSEBRACE, PERCENT, PIPE, PLUS, POUND, QUERY, SLASH, SYM, TILDE, UNDERSCORE]; const Start = makeState(); const Localpart = tt(Start, TILDE); ta(Localpart, localpartAccepting, Localpart); ta(Localpart, groups.domain, Localpart); const Domain = makeState(), Scheme = makeState(), SlashScheme = makeState(); ta(Start, groups.domain, Domain); ta(Start, groups.scheme, Scheme); ta(Start, groups.slashscheme, SlashScheme); ta(Domain, localpartAccepting, Localpart); ta(Domain, groups.domain, Domain); const LocalpartAt = tt(Domain, AT); tt(Localpart, AT, LocalpartAt); tt(Scheme, AT, LocalpartAt); tt(SlashScheme, AT, LocalpartAt); const LocalpartDot = tt(Localpart, DOT); ta(LocalpartDot, localpartAccepting, Localpart); ta(LocalpartDot, groups.domain, Localpart); const EmailDomain = makeState(); ta(LocalpartAt, groups.domain, EmailDomain); ta(EmailDomain, groups.domain, EmailDomain); const EmailDomainDot = tt(EmailDomain, DOT); ta(EmailDomainDot, groups.domain, EmailDomain); const Email$1 = makeState(Email); ta(EmailDomainDot, groups.tld, Email$1); ta(EmailDomainDot, groups.utld, Email$1); tt(LocalpartAt, LOCALHOST, Email$1); const EmailDomainHyphen = tt(EmailDomain, HYPHEN); tt(EmailDomainHyphen, HYPHEN, EmailDomainHyphen); ta(EmailDomainHyphen, groups.domain, EmailDomain); ta(Email$1, groups.domain, EmailDomain); tt(Email$1, DOT, EmailDomainDot); tt(Email$1, HYPHEN, EmailDomainHyphen); const EmailColon = tt(Email$1, COLON); ta(EmailColon, groups.numeric, Email); const DomainHyphen = tt(Domain, HYPHEN); const DomainDot = tt(Domain, DOT); tt(DomainHyphen, HYPHEN, DomainHyphen); ta(DomainHyphen, groups.domain, Domain); ta(DomainDot, localpartAccepting, Localpart); ta(DomainDot, groups.domain, Domain); const DomainDotTld = makeState(Url); ta(DomainDot, groups.tld, DomainDotTld); ta(DomainDot, groups.utld, DomainDotTld); ta(DomainDotTld, groups.domain, Domain); ta(DomainDotTld, localpartAccepting, Localpart); tt(DomainDotTld, DOT, DomainDot); tt(DomainDotTld, HYPHEN, DomainHyphen); tt(DomainDotTld, AT, LocalpartAt); const DomainDotTldColon = tt(DomainDotTld, COLON); const DomainDotTldColonPort = makeState(Url); ta(DomainDotTldColon, groups.numeric, DomainDotTldColonPort); const Url$1 = makeState(Url); const UrlNonaccept = makeState(); ta(Url$1, qsAccepting, Url$1); ta(Url$1, qsNonAccepting, UrlNonaccept); ta(UrlNonaccept, qsAccepting, Url$1); ta(UrlNonaccept, qsNonAccepting, UrlNonaccept); tt(DomainDotTld, SLASH, Url$1); tt(DomainDotTldColonPort, SLASH, Url$1); const SchemeColon = tt(Scheme, COLON); const SlashSchemeColon = tt(SlashScheme, COLON); const SlashSchemeColonSlash = tt(SlashSchemeColon, SLASH); const UriPrefix = tt(SlashSchemeColonSlash, SLASH); ta(Scheme, groups.domain, Domain); tt(Scheme, DOT, DomainDot); tt(Scheme, HYPHEN, DomainHyphen); ta(SlashScheme, groups.domain, Domain); tt(SlashScheme, DOT, DomainDot); tt(SlashScheme, HYPHEN, DomainHyphen); ta(SchemeColon, groups.domain, Url$1); tt(SchemeColon, SLASH, Url$1); tt(SchemeColon, QUERY, Url$1); ta(UriPrefix, groups.domain, Url$1); ta(UriPrefix, qsAccepting, Url$1); tt(UriPrefix, SLASH, Url$1); const bracketPairs = [ [OPENBRACE, CLOSEBRACE], // {} [OPENBRACKET, CLOSEBRACKET], // [] [OPENPAREN, CLOSEPAREN], // () [OPENANGLEBRACKET, CLOSEANGLEBRACKET], // <> [FULLWIDTHLEFTPAREN, FULLWIDTHRIGHTPAREN], // () [LEFTCORNERBRACKET, RIGHTCORNERBRACKET], // 「」 [LEFTWHITECORNERBRACKET, RIGHTWHITECORNERBRACKET], // 『』 [FULLWIDTHLESSTHAN, FULLWIDTHGREATERTHAN] // <> ]; for (let i = 0; i < bracketPairs.length; i++) { const [OPEN, CLOSE] = bracketPairs[i]; const UrlOpen = tt(Url$1, OPEN); tt(UrlNonaccept, OPEN, UrlOpen); tt(UrlOpen, CLOSE, Url$1); const UrlOpenQ = makeState(Url); ta(UrlOpen, qsAccepting, UrlOpenQ); const UrlOpenSyms = makeState(); ta(UrlOpen, qsNonAccepting); ta(UrlOpenQ, qsAccepting, UrlOpenQ); ta(UrlOpenQ, qsNonAccepting, UrlOpenSyms); ta(UrlOpenSyms, qsAccepting, UrlOpenQ); ta(UrlOpenSyms, qsNonAccepting, UrlOpenSyms); tt(UrlOpenQ, CLOSE, Url$1); tt(UrlOpenSyms, CLOSE, Url$1); } tt(Start, LOCALHOST, DomainDotTld); tt(Start, NL, Nl); return { start: Start, tokens: tk }; } function run(start, input, tokens) { let len = tokens.length; let cursor = 0; let multis = []; let textTokens = []; while (cursor < len) { let state = start; let secondState = null; let nextState = null; let multiLength = 0; let latestAccepting = null; let sinceAccepts = -1; while (cursor < len && !(secondState = state.go(tokens[cursor].t))) { textTokens.push(tokens[cursor++]); } while (cursor < len && (nextState = secondState || state.go(tokens[cursor].t))) { secondState = null; state = nextState; if (state.accepts()) { sinceAccepts = 0; latestAccepting = state; } else if (sinceAccepts >= 0) { sinceAccepts++; } cursor++; multiLength++; } if (sinceAccepts < 0) { cursor -= multiLength; if (cursor < len) { textTokens.push(tokens[cursor]); cursor++; } } else { if (textTokens.length > 0) { multis.push(initMultiToken(Text$1, input, textTokens)); textTokens = []; } cursor -= sinceAccepts; multiLength -= sinceAccepts; const Multi = latestAccepting.t; const subtokens = tokens.slice(cursor - multiLength, cursor); multis.push(initMultiToken(Multi, input, subtokens)); } } if (textTokens.length > 0) { multis.push(initMultiToken(Text$1, input, textTokens)); } return multis; } function initMultiToken(Multi, input, tokens) { const startIdx = tokens[0].s; const endIdx = tokens[tokens.length - 1].e; const value = input.slice(startIdx, endIdx); return new Multi(value, tokens); } const warn = typeof console !== "undefined" && console && console.warn || (() => { }); const warnAdvice = "until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time."; const INIT = { scanner: null, parser: null, tokenQueue: [], pluginQueue: [], customSchemes: [], initialized: false }; function reset() { State.groups = {}; INIT.scanner = null; INIT.parser = null; INIT.tokenQueue = []; INIT.pluginQueue = []; INIT.customSchemes = []; INIT.initialized = false; return INIT; } function registerCustomProtocol(scheme2, optionalSlashSlash = false) { if (INIT.initialized) { warn(`linkifyjs: already initialized - will not register custom scheme "${scheme2}" ${warnAdvice}`); } if (!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(scheme2)) { throw new Error(`linkifyjs: incorrect scheme format. 1. Must only contain digits, lowercase ASCII letters or "-" 2. Cannot start or end with "-" 3. "-" cannot repeat`); } INIT.customSchemes.push([scheme2, optionalSlashSlash]); } function init() { INIT.scanner = init$2(INIT.customSchemes); for (let i = 0; i < INIT.tokenQueue.length; i++) { INIT.tokenQueue[i][1]({ scanner: INIT.scanner }); } INIT.parser = init$1(INIT.scanner.tokens); for (let i = 0; i < INIT.pluginQueue.length; i++) { INIT.pluginQueue[i][1]({ scanner: INIT.scanner, parser: INIT.parser }); } INIT.initialized = true; return INIT; } function tokenize(str) { if (!INIT.initialized) { init(); } return run(INIT.parser.start, str, run$1(INIT.scanner.start, str)); } tokenize.scan = run$1; function find(str, type = null, opts = null) { if (type && typeof type === "object") { if (opts) { throw Error(`linkifyjs: Invalid link type ${type}; must be a string`); } opts = type; type = null; } const options = new Options(opts); const tokens = tokenize(str); const filtered = []; for (let i = 0; i < tokens.length; i++) { const token = tokens[i]; if (token.isLink && (!type || token.t === type) && options.check(token)) { filtered.push(token.toFormattedObject(options)); } } return filtered; } var UNICODE_WHITESPACE_PATTERN = "[\0-   ᠎ -\u2029  ]"; var UNICODE_WHITESPACE_REGEX = new RegExp(UNICODE_WHITESPACE_PATTERN); var UNICODE_WHITESPACE_REGEX_END = new RegExp(`${UNICODE_WHITESPACE_PATTERN}$`); var UNICODE_WHITESPACE_REGEX_GLOBAL = new RegExp(UNICODE_WHITESPACE_PATTERN, "g"); function isValidLinkStructure(tokens) { if (tokens.length === 1) { return tokens[0].isLink; } if (tokens.length === 3 && tokens[1].isLink) { return ["()", "[]"].includes(tokens[0].value + tokens[2].value); } return false; } function autolink(options) { return new Plugin({ key: new PluginKey("autolink"), appendTransaction: (transactions, oldState, newState) => { const docChanges = transactions.some((transaction) => transaction.docChanged) && !oldState.doc.eq(newState.doc); const preventAutolink = transactions.some((transaction) => transaction.getMeta("preventAutolink")); if (!docChanges || preventAutolink) { return; } const { tr: tr2 } = newState; const transform = combineTransactionSteps(oldState.doc, [...transactions]); const changes = getChangedRanges(transform); changes.forEach(({ newRange }) => { const nodesInChangedRanges = findChildrenInRange(newState.doc, newRange, (node) => node.isTextblock); let textBlock; let textBeforeWhitespace; if (nodesInChangedRanges.length > 1) { textBlock = nodesInChangedRanges[0]; textBeforeWhitespace = newState.doc.textBetween( textBlock.pos, textBlock.pos + textBlock.node.nodeSize, void 0, " " ); } else if (nodesInChangedRanges.length) { const endText = newState.doc.textBetween(newRange.from, newRange.to, " ", " "); if (!UNICODE_WHITESPACE_REGEX_END.test(endText)) { return; } textBlock = nodesInChangedRanges[0]; textBeforeWhitespace = newState.doc.textBetween(textBlock.pos, newRange.to, void 0, " "); } if (textBlock && textBeforeWhitespace) { const wordsBeforeWhitespace = textBeforeWhitespace.split(UNICODE_WHITESPACE_REGEX).filter(Boolean); if (wordsBeforeWhitespace.length <= 0) { return false; } const lastWordBeforeSpace = wordsBeforeWhitespace[wordsBeforeWhitespace.length - 1]; const lastWordAndBlockOffset = textBlock.pos + textBeforeWhitespace.lastIndexOf(lastWordBeforeSpace); if (!lastWordBeforeSpace) { return false; } const linksBeforeSpace = tokenize(lastWordBeforeSpace).map((t) => t.toObject(options.defaultProtocol)); if (!isValidLinkStructure(linksBeforeSpace)) { return false; } linksBeforeSpace.filter((link) => link.isLink).map((link) => ({ ...link, from: lastWordAndBlockOffset + link.start + 1, to: lastWordAndBlockOffset + link.end + 1 })).filter((link) => { if (!newState.schema.marks.code) { return true; } return !newState.doc.rangeHasMark(link.from, link.to, newState.schema.marks.code); }).filter((link) => options.validate(link.value)).filter((link) => options.shouldAutoLink(link.value)).forEach((link) => { if (getMarksBetween(link.from, link.to, newState.doc).some((item) => item.mark.type === options.type)) { return; } tr2.addMark( link.from, link.to, options.type.create({ href: link.href }) ); }); } }); if (!tr2.steps.length) { return; } return tr2; } }); } function clickHandler(options) { return new Plugin({ key: new PluginKey("handleClickLink"), props: { handleClick: (view, pos, event) => { var _a, _b; if (event.button !== 0) { return false; } if (!view.editable) { return false; } let link = null; if (event.target instanceof HTMLAnchorElement) { link = event.target; } else { const target = event.target; if (!target) { return false; } const root = options.editor.view.dom; link = target.closest("a"); if (link && !root.contains(link)) { link = null; } } if (!link) { return false; } let handled = false; if (options.enableClickSelection) { const commandResult = options.editor.commands.extendMarkRange(options.type.name); handled = commandResult; } if (options.openOnClick) { const attrs = getAttributes(view.state, options.type.name); const href = (_a = link.href) != null ? _a : attrs.href; const target = (_b = link.target) != null ? _b : attrs.target; if (href) { window.open(href, target); handled = true; } } return handled; } } }); } function pasteHandler(options) { return new Plugin({ key: new PluginKey("handlePasteLink"), props: { handlePaste: (view, _event, slice2) => { const { shouldAutoLink } = options; const { state } = view; const { selection } = state; const { empty: empty2 } = selection; if (empty2) { return false; } let textContent = ""; slice2.content.forEach((node) => { textContent += node.textContent; }); const link = find(textContent, { defaultProtocol: options.defaultProtocol }).find( (item) => item.isLink && item.value === textContent ); if (!textContent || !link || shouldAutoLink !== void 0 && !shouldAutoLink(link.value)) { return false; } return options.editor.commands.setMark(options.type, { href: link.href }); } } }); } function isAllowedUri(uri, protocols) { const allowedProtocols = ["http", "https", "ftp", "ftps", "mailto", "tel", "callto", "sms", "cid", "xmpp"]; if (protocols) { protocols.forEach((protocol) => { const nextProtocol = typeof protocol === "string" ? protocol : protocol.scheme; if (nextProtocol) { allowedProtocols.push(nextProtocol); } }); } return !uri || uri.replace(UNICODE_WHITESPACE_REGEX_GLOBAL, "").match( new RegExp( // eslint-disable-next-line no-useless-escape `^(?:(?:${allowedProtocols.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`, "i" ) ); } var Link = Mark2.create({ name: "link", priority: 1e3, keepOnSplit: false, exitable: true, onCreate() { if (this.options.validate && !this.options.shouldAutoLink) { this.options.shouldAutoLink = this.options.validate; console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead."); } this.options.protocols.forEach((protocol) => { if (typeof protocol === "string") { registerCustomProtocol(protocol); return; } registerCustomProtocol(protocol.scheme, protocol.optionalSlashes); }); }, onDestroy() { reset(); }, inclusive() { return this.options.autolink; }, addOptions() { return { openOnClick: true, enableClickSelection: false, linkOnPaste: true, autolink: true, protocols: [], defaultProtocol: "http", HTMLAttributes: { target: "_blank", rel: "noopener noreferrer nofollow", class: null }, isAllowedUri: (url, ctx) => !!isAllowedUri(url, ctx.protocols), validate: (url) => !!url, shouldAutoLink: (url) => { const hasProtocol = /^[a-z][a-z0-9+.-]*:\/\//i.test(url); const hasMaybeProtocol = /^[a-z][a-z0-9+.-]*:/i.test(url); if (hasProtocol || hasMaybeProtocol && !url.includes("@")) { return true; } const urlWithoutUserinfo = url.includes("@") ? url.split("@").pop() : url; const hostname = urlWithoutUserinfo.split(/[/?#:]/)[0]; if (/^\d{1,3}(\.\d{1,3}){3}$/.test(hostname)) { return false; } if (!/\./.test(hostname)) { return false; } return true; } }; }, addAttributes() { return { href: { default: null, parseHTML(element) { return element.getAttribute("href"); } }, target: { default: this.options.HTMLAttributes.target }, rel: { default: this.options.HTMLAttributes.rel }, class: { default: this.options.HTMLAttributes.class }, title: { default: null } }; }, parseHTML() { return [ { tag: "a[href]", getAttrs: (dom) => { const href = dom.getAttribute("href"); if (!href || !this.options.isAllowedUri(href, { defaultValidate: (url) => !!isAllowedUri(url, this.options.protocols), protocols: this.options.protocols, defaultProtocol: this.options.defaultProtocol })) { return false; } return null; } } ]; }, renderHTML({ HTMLAttributes }) { if (!this.options.isAllowedUri(HTMLAttributes.href, { defaultValidate: (href) => !!isAllowedUri(href, this.options.protocols), protocols: this.options.protocols, defaultProtocol: this.options.defaultProtocol })) { return ["a", mergeAttributes(this.options.HTMLAttributes, { ...HTMLAttributes, href: "" }), 0]; } return ["a", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, markdownTokenName: "link", parseMarkdown: (token, helpers) => { return helpers.applyMark("link", helpers.parseInline(token.tokens || []), { href: token.href, title: token.title || null }); }, renderMarkdown: (node, h2) => { var _a, _b, _c, _d; const href = (_b = (_a = node.attrs) == null ? void 0 : _a.href) != null ? _b : ""; const title = (_d = (_c = node.attrs) == null ? void 0 : _c.title) != null ? _d : ""; const text = h2.renderChildren(node); return title ? `[${text}](${href} "${title}")` : `[${text}](${href})`; }, addCommands() { return { setLink: (attributes) => ({ chain }) => { const { href } = attributes; if (!this.options.isAllowedUri(href, { defaultValidate: (url) => !!isAllowedUri(url, this.options.protocols), protocols: this.options.protocols, defaultProtocol: this.options.defaultProtocol })) { return false; } return chain().setMark(this.name, attributes).setMeta("preventAutolink", true).run(); }, toggleLink: (attributes) => ({ chain }) => { const { href } = attributes || {}; if (href && !this.options.isAllowedUri(href, { defaultValidate: (url) => !!isAllowedUri(url, this.options.protocols), protocols: this.options.protocols, defaultProtocol: this.options.defaultProtocol })) { return false; } return chain().toggleMark(this.name, attributes, { extendEmptyMarkRange: true }).setMeta("preventAutolink", true).run(); }, unsetLink: () => ({ chain }) => { return chain().unsetMark(this.name, { extendEmptyMarkRange: true }).setMeta("preventAutolink", true).run(); } }; }, addPasteRules() { return [ markPasteRule({ find: (text) => { const foundLinks = []; if (text) { const { protocols, defaultProtocol } = this.options; const links = find(text).filter( (item) => item.isLink && this.options.isAllowedUri(item.value, { defaultValidate: (href) => !!isAllowedUri(href, protocols), protocols, defaultProtocol }) ); if (links.length) { links.forEach((link) => { if (!this.options.shouldAutoLink(link.value)) { return; } foundLinks.push({ text: link.value, data: { href: link.href }, index: link.start }); }); } } return foundLinks; }, type: this.type, getAttributes: (match) => { var _a; return { href: (_a = match.data) == null ? void 0 : _a.href }; } }) ]; }, addProseMirrorPlugins() { const plugins = []; const { protocols, defaultProtocol } = this.options; if (this.options.autolink) { plugins.push( autolink({ type: this.type, defaultProtocol: this.options.defaultProtocol, validate: (url) => this.options.isAllowedUri(url, { defaultValidate: (href) => !!isAllowedUri(href, protocols), protocols, defaultProtocol }), shouldAutoLink: this.options.shouldAutoLink }) ); } plugins.push( clickHandler({ type: this.type, editor: this.editor, openOnClick: this.options.openOnClick === "whenNotEditable" ? true : this.options.openOnClick, enableClickSelection: this.options.enableClickSelection }) ); if (this.options.linkOnPaste) { plugins.push( pasteHandler({ editor: this.editor, defaultProtocol: this.options.defaultProtocol, type: this.type, shouldAutoLink: this.options.shouldAutoLink }) ); } return plugins; } }); var index_default$5 = Link; var __defProp = Object.defineProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var ListItemName = "listItem"; var TextStyleName = "textStyle"; var bulletListInputRegex = /^\s*([-+*])\s$/; var BulletList = Node3.create({ name: "bulletList", addOptions() { return { itemTypeName: "listItem", HTMLAttributes: {}, keepMarks: false, keepAttributes: false }; }, group: "block list", content() { return `${this.options.itemTypeName}+`; }, parseHTML() { return [{ tag: "ul" }]; }, renderHTML({ HTMLAttributes }) { return ["ul", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, markdownTokenName: "list", parseMarkdown: (token, helpers) => { if (token.type !== "list" || token.ordered) { return []; } return { type: "bulletList", content: token.items ? helpers.parseChildren(token.items) : [] }; }, renderMarkdown: (node, h2) => { if (!node.content) { return ""; } return h2.renderChildren(node.content, "\n"); }, markdownOptions: { indentsContent: true }, addCommands() { return { toggleBulletList: () => ({ commands, chain }) => { if (this.options.keepAttributes) { return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run(); } return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks); } }; }, addKeyboardShortcuts() { return { "Mod-Shift-8": () => this.editor.commands.toggleBulletList() }; }, addInputRules() { let inputRule = wrappingInputRule({ find: bulletListInputRegex, type: this.type }); if (this.options.keepMarks || this.options.keepAttributes) { inputRule = wrappingInputRule({ find: bulletListInputRegex, type: this.type, keepMarks: this.options.keepMarks, keepAttributes: this.options.keepAttributes, getAttributes: () => { return this.editor.getAttributes(TextStyleName); }, editor: this.editor }); } return [inputRule]; } }); var ListItem = Node3.create({ name: "listItem", addOptions() { return { HTMLAttributes: {}, bulletListTypeName: "bulletList", orderedListTypeName: "orderedList" }; }, content: "paragraph block*", defining: true, parseHTML() { return [ { tag: "li" } ]; }, renderHTML({ HTMLAttributes }) { return ["li", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, markdownTokenName: "list_item", parseMarkdown: (token, helpers) => { var _a; if (token.type !== "list_item") { return []; } const parseBlockChildren = (_a = helpers.parseBlockChildren) != null ? _a : helpers.parseChildren; let content = []; if (token.tokens && token.tokens.length > 0) { const hasParagraphTokens = token.tokens.some((t) => t.type === "paragraph"); if (hasParagraphTokens) { content = parseBlockChildren(token.tokens); } else { const firstToken = token.tokens[0]; if (firstToken && firstToken.type === "text" && firstToken.tokens && firstToken.tokens.length > 0) { const inlineContent = helpers.parseInline(firstToken.tokens); content = [ { type: "paragraph", content: inlineContent } ]; if (token.tokens.length > 1) { const remainingTokens = token.tokens.slice(1); const additionalContent = parseBlockChildren(remainingTokens); content.push(...additionalContent); } } else { content = parseBlockChildren(token.tokens); } } } if (content.length === 0) { content = [ { type: "paragraph", content: [] } ]; } return { type: "listItem", content }; }, renderMarkdown: (node, h2, ctx) => { return renderNestedMarkdownContent( node, h2, (context) => { var _a, _b; if (context.parentType === "bulletList") { return "- "; } if (context.parentType === "orderedList") { const start = ((_b = (_a = context.meta) == null ? void 0 : _a.parentAttrs) == null ? void 0 : _b.start) || 1; return `${start + context.index}. `; } return "- "; }, ctx ); }, addKeyboardShortcuts() { return { Enter: () => this.editor.commands.splitListItem(this.name), Tab: () => this.editor.commands.sinkListItem(this.name), "Shift-Tab": () => this.editor.commands.liftListItem(this.name) }; } }); var listHelpers_exports = {}; __export(listHelpers_exports, { findListItemPos: () => findListItemPos, getNextListDepth: () => getNextListDepth, handleBackspace: () => handleBackspace, handleDelete: () => handleDelete, hasListBefore: () => hasListBefore, hasListItemAfter: () => hasListItemAfter, hasListItemBefore: () => hasListItemBefore, listItemHasSubList: () => listItemHasSubList, nextListIsDeeper: () => nextListIsDeeper, nextListIsHigher: () => nextListIsHigher }); var findListItemPos = (typeOrName, state) => { const { $from } = state.selection; const nodeType = getNodeType(typeOrName, state.schema); let currentNode = null; let currentDepth = $from.depth; let currentPos = $from.pos; let targetDepth = null; while (currentDepth > 0 && targetDepth === null) { currentNode = $from.node(currentDepth); if (currentNode.type === nodeType) { targetDepth = currentDepth; } else { currentDepth -= 1; currentPos -= 1; } } if (targetDepth === null) { return null; } return { $pos: state.doc.resolve(currentPos), depth: targetDepth }; }; var getNextListDepth = (typeOrName, state) => { const listItemPos = findListItemPos(typeOrName, state); if (!listItemPos) { return false; } const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4); return depth; }; var hasListBefore = (editorState, name, parentListTypes) => { const { $anchor } = editorState.selection; const previousNodePos = Math.max(0, $anchor.pos - 2); const previousNode = editorState.doc.resolve(previousNodePos).node(); if (!previousNode || !parentListTypes.includes(previousNode.type.name)) { return false; } return true; }; var hasListItemBefore = (typeOrName, state) => { var _a; const { $anchor } = state.selection; const $targetPos = state.doc.resolve($anchor.pos - 2); if ($targetPos.index() === 0) { return false; } if (((_a = $targetPos.nodeBefore) == null ? void 0 : _a.type.name) !== typeOrName) { return false; } return true; }; var listItemHasSubList = (typeOrName, state, node) => { if (!node) { return false; } const nodeType = getNodeType(typeOrName, state.schema); let hasSubList = false; node.descendants((child) => { if (child.type === nodeType) { hasSubList = true; } }); return hasSubList; }; var handleBackspace = (editor, name, parentListTypes) => { if (editor.commands.undoInputRule()) { return true; } if (editor.state.selection.from !== editor.state.selection.to) { return false; } if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) { const { $anchor } = editor.state.selection; const $listPos = editor.state.doc.resolve($anchor.before() - 1); const listDescendants = []; $listPos.node().descendants((node, pos) => { if (node.type.name === name) { listDescendants.push({ node, pos }); } }); const lastItem = listDescendants.at(-1); if (!lastItem) { return false; } const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1); return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run(); } if (!isNodeActive(editor.state, name)) { return false; } if (!isAtStartOfNode(editor.state)) { return false; } const listItemPos = findListItemPos(name, editor.state); if (!listItemPos) { return false; } const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2); const prevNode = $prev.node(listItemPos.depth); const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode); if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) { return editor.commands.joinItemBackward(); } return editor.chain().liftListItem(name).run(); }; var nextListIsDeeper = (typeOrName, state) => { const listDepth = getNextListDepth(typeOrName, state); const listItemPos = findListItemPos(typeOrName, state); if (!listItemPos || !listDepth) { return false; } if (listDepth > listItemPos.depth) { return true; } return false; }; var nextListIsHigher = (typeOrName, state) => { const listDepth = getNextListDepth(typeOrName, state); const listItemPos = findListItemPos(typeOrName, state); if (!listItemPos || !listDepth) { return false; } if (listDepth < listItemPos.depth) { return true; } return false; }; var handleDelete = (editor, name) => { if (!isNodeActive(editor.state, name)) { return false; } if (!isAtEndOfNode(editor.state, name)) { return false; } const { selection } = editor.state; const { $from, $to } = selection; if (!selection.empty && $from.sameParent($to)) { return false; } if (nextListIsDeeper(name, editor.state)) { return editor.chain().focus(editor.state.selection.from + 4).lift(name).joinBackward().run(); } if (nextListIsHigher(name, editor.state)) { return editor.chain().joinForward().joinBackward().run(); } return editor.commands.joinItemForward(); }; var hasListItemAfter = (typeOrName, state) => { var _a; const { $anchor } = state.selection; const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2); if ($targetPos.index() === $targetPos.parent.childCount - 1) { return false; } if (((_a = $targetPos.nodeAfter) == null ? void 0 : _a.type.name) !== typeOrName) { return false; } return true; }; var ListKeymap = Extension.create({ name: "listKeymap", addOptions() { return { listTypes: [ { itemName: "listItem", wrapperNames: ["bulletList", "orderedList"] }, { itemName: "taskItem", wrapperNames: ["taskList"] } ] }; }, addKeyboardShortcuts() { return { Delete: ({ editor }) => { let handled = false; this.options.listTypes.forEach(({ itemName }) => { if (editor.state.schema.nodes[itemName] === void 0) { return; } if (handleDelete(editor, itemName)) { handled = true; } }); return handled; }, "Mod-Delete": ({ editor }) => { let handled = false; this.options.listTypes.forEach(({ itemName }) => { if (editor.state.schema.nodes[itemName] === void 0) { return; } if (handleDelete(editor, itemName)) { handled = true; } }); return handled; }, Backspace: ({ editor }) => { let handled = false; this.options.listTypes.forEach(({ itemName, wrapperNames }) => { if (editor.state.schema.nodes[itemName] === void 0) { return; } if (handleBackspace(editor, itemName, wrapperNames)) { handled = true; } }); return handled; }, "Mod-Backspace": ({ editor }) => { let handled = false; this.options.listTypes.forEach(({ itemName, wrapperNames }) => { if (editor.state.schema.nodes[itemName] === void 0) { return; } if (handleBackspace(editor, itemName, wrapperNames)) { handled = true; } }); return handled; } }; } }); var ORDERED_LIST_ITEM_REGEX = /^(\s*)(\d+)\.\s+(.*)$/; var INDENTED_LINE_REGEX = /^\s/; function collectOrderedListItems(lines) { const listItems = []; let currentLineIndex = 0; let consumed = 0; while (currentLineIndex < lines.length) { const line = lines[currentLineIndex]; const match = line.match(ORDERED_LIST_ITEM_REGEX); if (!match) { break; } const [, indent, number, content] = match; const indentLevel = indent.length; let itemContent = content; let nextLineIndex = currentLineIndex + 1; const itemLines = [line]; while (nextLineIndex < lines.length) { const nextLine = lines[nextLineIndex]; const nextMatch = nextLine.match(ORDERED_LIST_ITEM_REGEX); if (nextMatch) { break; } if (nextLine.trim() === "") { itemLines.push(nextLine); itemContent += "\n"; nextLineIndex += 1; } else if (nextLine.match(INDENTED_LINE_REGEX)) { itemLines.push(nextLine); itemContent += ` ${nextLine.slice(indentLevel + 2)}`; nextLineIndex += 1; } else { break; } } listItems.push({ indent: indentLevel, number: parseInt(number, 10), content: itemContent.trim(), raw: itemLines.join("\n") }); consumed = nextLineIndex; currentLineIndex = nextLineIndex; } return [listItems, consumed]; } function buildNestedStructure(items, baseIndent, lexer) { var _a; const result = []; let currentIndex = 0; while (currentIndex < items.length) { const item = items[currentIndex]; if (item.indent === baseIndent) { const contentLines = item.content.split("\n"); const mainText = ((_a = contentLines[0]) == null ? void 0 : _a.trim()) || ""; const tokens = []; if (mainText) { tokens.push({ type: "paragraph", raw: mainText, tokens: lexer.inlineTokens(mainText) }); } const additionalContent = contentLines.slice(1).join("\n").trim(); if (additionalContent) { const blockTokens = lexer.blockTokens(additionalContent); tokens.push(...blockTokens); } let lookAheadIndex = currentIndex + 1; const nestedItems = []; while (lookAheadIndex < items.length && items[lookAheadIndex].indent > baseIndent) { nestedItems.push(items[lookAheadIndex]); lookAheadIndex += 1; } if (nestedItems.length > 0) { const nextIndent = Math.min(...nestedItems.map((nestedItem) => nestedItem.indent)); const nestedListItems = buildNestedStructure(nestedItems, nextIndent, lexer); tokens.push({ type: "list", ordered: true, start: nestedItems[0].number, items: nestedListItems, raw: nestedItems.map((nestedItem) => nestedItem.raw).join("\n") }); } result.push({ type: "list_item", raw: item.raw, tokens }); currentIndex = lookAheadIndex; } else { currentIndex += 1; } } return result; } function parseListItems(items, helpers) { return items.map((item) => { if (item.type !== "list_item") { return helpers.parseChildren([item])[0]; } const content = []; if (item.tokens && item.tokens.length > 0) { item.tokens.forEach((itemToken) => { if (itemToken.type === "paragraph" || itemToken.type === "list" || itemToken.type === "blockquote" || itemToken.type === "code") { content.push(...helpers.parseChildren([itemToken])); } else if (itemToken.type === "text" && itemToken.tokens) { const inlineContent = helpers.parseChildren([itemToken]); content.push({ type: "paragraph", content: inlineContent }); } else { const parsed = helpers.parseChildren([itemToken]); if (parsed.length > 0) { content.push(...parsed); } } }); } return { type: "listItem", content }; }); } var ListItemName2 = "listItem"; var TextStyleName2 = "textStyle"; var orderedListInputRegex = /^(\d+)\.\s$/; var OrderedList = Node3.create({ name: "orderedList", addOptions() { return { itemTypeName: "listItem", HTMLAttributes: {}, keepMarks: false, keepAttributes: false }; }, group: "block list", content() { return `${this.options.itemTypeName}+`; }, addAttributes() { return { start: { default: 1, parseHTML: (element) => { return element.hasAttribute("start") ? parseInt(element.getAttribute("start") || "", 10) : 1; } }, type: { default: null, parseHTML: (element) => element.getAttribute("type") } }; }, parseHTML() { return [ { tag: "ol" } ]; }, renderHTML({ HTMLAttributes }) { const { start, ...attributesWithoutStart } = HTMLAttributes; return start === 1 ? ["ol", mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart), 0] : ["ol", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, markdownTokenName: "list", parseMarkdown: (token, helpers) => { if (token.type !== "list" || !token.ordered) { return []; } const startValue = token.start || 1; const content = token.items ? parseListItems(token.items, helpers) : []; if (startValue !== 1) { return { type: "orderedList", attrs: { start: startValue }, content }; } return { type: "orderedList", content }; }, renderMarkdown: (node, h2) => { if (!node.content) { return ""; } return h2.renderChildren(node.content, "\n"); }, markdownTokenizer: { name: "orderedList", level: "block", start: (src) => { const match = src.match(/^(\s*)(\d+)\.\s+/); const index = match == null ? void 0 : match.index; return index !== void 0 ? index : -1; }, tokenize: (src, _tokens, lexer) => { var _a; const lines = src.split("\n"); const [listItems, consumed] = collectOrderedListItems(lines); if (listItems.length === 0) { return void 0; } const items = buildNestedStructure(listItems, 0, lexer); if (items.length === 0) { return void 0; } const startValue = ((_a = listItems[0]) == null ? void 0 : _a.number) || 1; return { type: "list", ordered: true, start: startValue, items, raw: lines.slice(0, consumed).join("\n") }; } }, markdownOptions: { indentsContent: true }, addCommands() { return { toggleOrderedList: () => ({ commands, chain }) => { if (this.options.keepAttributes) { return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName2, this.editor.getAttributes(TextStyleName2)).run(); } return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks); } }; }, addKeyboardShortcuts() { return { "Mod-Shift-7": () => this.editor.commands.toggleOrderedList() }; }, addInputRules() { let inputRule = wrappingInputRule({ find: orderedListInputRegex, type: this.type, getAttributes: (match) => ({ start: +match[1] }), joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1] }); if (this.options.keepMarks || this.options.keepAttributes) { inputRule = wrappingInputRule({ find: orderedListInputRegex, type: this.type, keepMarks: this.options.keepMarks, keepAttributes: this.options.keepAttributes, getAttributes: (match) => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName2) }), joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1], editor: this.editor }); } return [inputRule]; } }); var inputRegex$2 = /^\s*(\[([( |x])?\])\s$/; var TaskItem = Node3.create({ name: "taskItem", addOptions() { return { nested: false, HTMLAttributes: {}, taskListTypeName: "taskList", a11y: void 0 }; }, content() { return this.options.nested ? "paragraph block*" : "paragraph+"; }, defining: true, addAttributes() { return { checked: { default: false, keepOnSplit: false, parseHTML: (element) => { const dataChecked = element.getAttribute("data-checked"); return dataChecked === "" || dataChecked === "true"; }, renderHTML: (attributes) => ({ "data-checked": attributes.checked }) } }; }, parseHTML() { return [ { tag: `li[data-type="${this.name}"]`, priority: 51 } ]; }, renderHTML({ node, HTMLAttributes }) { return [ "li", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { "data-type": this.name }), [ "label", [ "input", { type: "checkbox", checked: node.attrs.checked ? "checked" : null } ], ["span"] ], ["div", 0] ]; }, parseMarkdown: (token, h2) => { const content = []; if (token.tokens && token.tokens.length > 0) { content.push(h2.createNode("paragraph", {}, h2.parseInline(token.tokens))); } else if (token.text) { content.push(h2.createNode("paragraph", {}, [h2.createNode("text", { text: token.text })])); } else { content.push(h2.createNode("paragraph", {}, [])); } if (token.nestedTokens && token.nestedTokens.length > 0) { const nestedContent = h2.parseChildren(token.nestedTokens); content.push(...nestedContent); } return h2.createNode("taskItem", { checked: token.checked || false }, content); }, renderMarkdown: (node, h2) => { var _a; const checkedChar = ((_a = node.attrs) == null ? void 0 : _a.checked) ? "x" : " "; const prefix = `- [${checkedChar}] `; return renderNestedMarkdownContent(node, h2, prefix); }, addKeyboardShortcuts() { const shortcuts = { Enter: () => this.editor.commands.splitListItem(this.name), "Shift-Tab": () => this.editor.commands.liftListItem(this.name) }; if (!this.options.nested) { return shortcuts; } return { ...shortcuts, Tab: () => this.editor.commands.sinkListItem(this.name) }; }, addNodeView() { return ({ node, HTMLAttributes, getPos, editor }) => { const listItem = document.createElement("li"); const checkboxWrapper = document.createElement("label"); const checkboxStyler = document.createElement("span"); const checkbox = document.createElement("input"); const content = document.createElement("div"); const updateA11Y = (currentNode) => { var _a, _b; checkbox.ariaLabel = ((_b = (_a = this.options.a11y) == null ? void 0 : _a.checkboxLabel) == null ? void 0 : _b.call(_a, currentNode, checkbox.checked)) || `Task item checkbox for ${currentNode.textContent || "empty task item"}`; }; updateA11Y(node); checkboxWrapper.contentEditable = "false"; checkbox.type = "checkbox"; checkbox.addEventListener("mousedown", (event) => event.preventDefault()); checkbox.addEventListener("change", (event) => { if (!editor.isEditable && !this.options.onReadOnlyChecked) { checkbox.checked = !checkbox.checked; return; } const { checked } = event.target; if (editor.isEditable && typeof getPos === "function") { editor.chain().focus(void 0, { scrollIntoView: false }).command(({ tr: tr2 }) => { const position = getPos(); if (typeof position !== "number") { return false; } const currentNode = tr2.doc.nodeAt(position); tr2.setNodeMarkup(position, void 0, { ...currentNode == null ? void 0 : currentNode.attrs, checked }); return true; }).run(); } if (!editor.isEditable && this.options.onReadOnlyChecked) { if (!this.options.onReadOnlyChecked(node, checked)) { checkbox.checked = !checkbox.checked; } } }); Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => { listItem.setAttribute(key, value); }); listItem.dataset.checked = node.attrs.checked; checkbox.checked = node.attrs.checked; checkboxWrapper.append(checkbox, checkboxStyler); listItem.append(checkboxWrapper, content); Object.entries(HTMLAttributes).forEach(([key, value]) => { listItem.setAttribute(key, value); }); let prevRenderedAttributeKeys = new Set(Object.keys(HTMLAttributes)); return { dom: listItem, contentDOM: content, update: (updatedNode) => { if (updatedNode.type !== this.type) { return false; } listItem.dataset.checked = updatedNode.attrs.checked; checkbox.checked = updatedNode.attrs.checked; updateA11Y(updatedNode); const extensionAttributes = editor.extensionManager.attributes; const newHTMLAttributes = getRenderedAttributes(updatedNode, extensionAttributes); const newKeys = new Set(Object.keys(newHTMLAttributes)); const staticAttrs = this.options.HTMLAttributes; prevRenderedAttributeKeys.forEach((key) => { if (!newKeys.has(key)) { if (key in staticAttrs) { listItem.setAttribute(key, staticAttrs[key]); } else { listItem.removeAttribute(key); } } }); Object.entries(newHTMLAttributes).forEach(([key, value]) => { if (value === null || value === void 0) { if (key in staticAttrs) { listItem.setAttribute(key, staticAttrs[key]); } else { listItem.removeAttribute(key); } } else { listItem.setAttribute(key, value); } }); prevRenderedAttributeKeys = newKeys; return true; } }; }; }, addInputRules() { return [ wrappingInputRule({ find: inputRegex$2, type: this.type, getAttributes: (match) => ({ checked: match[match.length - 1] === "x" }) }) ]; } }); var TaskList = Node3.create({ name: "taskList", addOptions() { return { itemTypeName: "taskItem", HTMLAttributes: {} }; }, group: "block list", content() { return `${this.options.itemTypeName}+`; }, parseHTML() { return [ { tag: `ul[data-type="${this.name}"]`, priority: 51 } ]; }, renderHTML({ HTMLAttributes }) { return ["ul", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { "data-type": this.name }), 0]; }, parseMarkdown: (token, h2) => { return h2.createNode("taskList", {}, h2.parseChildren(token.items || [])); }, renderMarkdown: (node, h2) => { if (!node.content) { return ""; } return h2.renderChildren(node.content, "\n"); }, markdownTokenizer: { name: "taskList", level: "block", start(src) { var _a; const index = (_a = src.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)) == null ? void 0 : _a.index; return index !== void 0 ? index : -1; }, tokenize(src, tokens, lexer) { const parseTaskListContent = (content) => { const nestedResult = parseIndentedBlocks( content, { itemPattern: /^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/, extractItemData: (match) => ({ indentLevel: match[1].length, mainContent: match[4], checked: match[3].toLowerCase() === "x" }), createToken: (data, nestedTokens) => ({ type: "taskItem", raw: "", mainContent: data.mainContent, indentLevel: data.indentLevel, checked: data.checked, text: data.mainContent, tokens: lexer.inlineTokens(data.mainContent), nestedTokens }), // Allow recursive nesting customNestedParser: parseTaskListContent }, lexer ); if (nestedResult) { return [ { type: "taskList", raw: nestedResult.raw, items: nestedResult.items } ]; } return lexer.blockTokens(content); }; const result = parseIndentedBlocks( src, { itemPattern: /^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/, extractItemData: (match) => ({ indentLevel: match[1].length, mainContent: match[4], checked: match[3].toLowerCase() === "x" }), createToken: (data, nestedTokens) => ({ type: "taskItem", raw: "", mainContent: data.mainContent, indentLevel: data.indentLevel, checked: data.checked, text: data.mainContent, tokens: lexer.inlineTokens(data.mainContent), nestedTokens }), // Use the recursive parser for nested content customNestedParser: parseTaskListContent }, lexer ); if (!result) { return void 0; } return { type: "taskList", raw: result.raw, items: result.items }; } }, markdownOptions: { indentsContent: true }, addCommands() { return { toggleTaskList: () => ({ commands }) => { return commands.toggleList(this.name, this.options.itemTypeName); } }; }, addKeyboardShortcuts() { return { "Mod-Shift-9": () => this.editor.commands.toggleTaskList() }; } }); Extension.create({ name: "listKit", addExtensions() { const extensions = []; if (this.options.bulletList !== false) { extensions.push(BulletList.configure(this.options.bulletList)); } if (this.options.listItem !== false) { extensions.push(ListItem.configure(this.options.listItem)); } if (this.options.listKeymap !== false) { extensions.push(ListKeymap.configure(this.options.listKeymap)); } if (this.options.orderedList !== false) { extensions.push(OrderedList.configure(this.options.orderedList)); } if (this.options.taskItem !== false) { extensions.push(TaskItem.configure(this.options.taskItem)); } if (this.options.taskList !== false) { extensions.push(TaskList.configure(this.options.taskList)); } return extensions; } }); var EMPTY_PARAGRAPH_MARKDOWN = " "; var NBSP_CHAR = " "; var Paragraph = Node3.create({ name: "paragraph", priority: 1e3, addOptions() { return { HTMLAttributes: {} }; }, group: "block", content: "inline*", parseHTML() { return [{ tag: "p" }]; }, renderHTML({ HTMLAttributes }) { return ["p", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, parseMarkdown: (token, helpers) => { const tokens = token.tokens || []; if (tokens.length === 1 && tokens[0].type === "image") { return helpers.parseChildren([tokens[0]]); } const content = helpers.parseInline(tokens); const hasExplicitEmptyParagraphMarker = tokens.length === 1 && tokens[0].type === "text" && (tokens[0].raw === EMPTY_PARAGRAPH_MARKDOWN || tokens[0].text === EMPTY_PARAGRAPH_MARKDOWN || tokens[0].raw === NBSP_CHAR || tokens[0].text === NBSP_CHAR); if (hasExplicitEmptyParagraphMarker && content.length === 1 && content[0].type === "text" && (content[0].text === EMPTY_PARAGRAPH_MARKDOWN || content[0].text === NBSP_CHAR)) { return helpers.createNode("paragraph", void 0, []); } return helpers.createNode("paragraph", void 0, content); }, renderMarkdown: (node, h2, ctx) => { var _a, _b; if (!node) { return ""; } const content = Array.isArray(node.content) ? node.content : []; if (content.length === 0) { const previousContent = Array.isArray((_a = ctx == null ? void 0 : ctx.previousNode) == null ? void 0 : _a.content) ? ctx.previousNode.content : []; const previousNodeIsEmptyParagraph = ((_b = ctx == null ? void 0 : ctx.previousNode) == null ? void 0 : _b.type) === "paragraph" && previousContent.length === 0; return previousNodeIsEmptyParagraph ? EMPTY_PARAGRAPH_MARKDOWN : ""; } return h2.renderChildren(content); }, addCommands() { return { setParagraph: () => ({ commands }) => { return commands.setNode(this.name); } }; }, addKeyboardShortcuts() { return { "Mod-Alt-0": () => this.editor.commands.setParagraph() }; } }); var inputRegex$1 = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/; var pasteRegex = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g; var Strike = Mark2.create({ name: "strike", addOptions() { return { HTMLAttributes: {} }; }, parseHTML() { return [ { tag: "s" }, { tag: "del" }, { tag: "strike" }, { style: "text-decoration", consuming: false, getAttrs: (style2) => style2.includes("line-through") ? {} : false } ]; }, renderHTML({ HTMLAttributes }) { return ["s", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, markdownTokenName: "del", parseMarkdown: (token, helpers) => { return helpers.applyMark("strike", helpers.parseInline(token.tokens || [])); }, renderMarkdown: (node, h2) => { return `~~${h2.renderChildren(node)}~~`; }, addCommands() { return { setStrike: () => ({ commands }) => { return commands.setMark(this.name); }, toggleStrike: () => ({ commands }) => { return commands.toggleMark(this.name); }, unsetStrike: () => ({ commands }) => { return commands.unsetMark(this.name); } }; }, addKeyboardShortcuts() { return { "Mod-Shift-s": () => this.editor.commands.toggleStrike() }; }, addInputRules() { return [ markInputRule({ find: inputRegex$1, type: this.type }) ]; }, addPasteRules() { return [ markPasteRule({ find: pasteRegex, type: this.type }) ]; } }); var Text = Node3.create({ name: "text", group: "inline", parseMarkdown: (token) => { return { type: "text", text: token.text || "" }; }, renderMarkdown: (node) => node.text || "" }); var Underline = Mark2.create({ name: "underline", addOptions() { return { HTMLAttributes: {} }; }, parseHTML() { return [ { tag: "u" }, { style: "text-decoration", consuming: false, getAttrs: (style2) => style2.includes("underline") ? {} : false } ]; }, renderHTML({ HTMLAttributes }) { return ["u", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, parseMarkdown(token, helpers) { return helpers.applyMark(this.name || "underline", helpers.parseInline(token.tokens || [])); }, renderMarkdown(node, helpers) { return `++${helpers.renderChildren(node)}++`; }, markdownTokenizer: { name: "underline", level: "inline", start(src) { return src.indexOf("++"); }, tokenize(src, _tokens, lexer) { const rule = /^(\+\+)([\s\S]+?)(\+\+)/; const match = rule.exec(src); if (!match) { return void 0; } const innerContent = match[2].trim(); return { type: "underline", raw: match[0], text: innerContent, tokens: lexer.inlineTokens(innerContent) }; } }, addCommands() { return { setUnderline: () => ({ commands }) => { return commands.setMark(this.name); }, toggleUnderline: () => ({ commands }) => { return commands.toggleMark(this.name); }, unsetUnderline: () => ({ commands }) => { return commands.unsetMark(this.name); } }; }, addKeyboardShortcuts() { return { "Mod-u": () => this.editor.commands.toggleUnderline(), "Mod-U": () => this.editor.commands.toggleUnderline() }; } }); var index_default$4 = Underline; function dropCursor(options = {}) { return new Plugin({ view(editorView) { return new DropCursorView(editorView, options); } }); } class DropCursorView { constructor(editorView, options) { var _a; this.editorView = editorView; this.cursorPos = null; this.element = null; this.timeout = -1; this.width = (_a = options.width) !== null && _a !== void 0 ? _a : 1; this.color = options.color === false ? void 0 : options.color || "black"; this.class = options.class; this.handlers = ["dragover", "dragend", "drop", "dragleave"].map((name) => { let handler = (e) => { this[name](e); }; editorView.dom.addEventListener(name, handler); return { name, handler }; }); } destroy() { this.handlers.forEach(({ name, handler }) => this.editorView.dom.removeEventListener(name, handler)); } update(editorView, prevState) { if (this.cursorPos != null && prevState.doc != editorView.state.doc) { if (this.cursorPos > editorView.state.doc.content.size) this.setCursor(null); else this.updateOverlay(); } } setCursor(pos) { if (pos == this.cursorPos) return; this.cursorPos = pos; if (pos == null) { this.element.parentNode.removeChild(this.element); this.element = null; } else { this.updateOverlay(); } } updateOverlay() { let $pos = this.editorView.state.doc.resolve(this.cursorPos); let isBlock = !$pos.parent.inlineContent, rect; let editorDOM = this.editorView.dom, editorRect = editorDOM.getBoundingClientRect(); let scaleX = editorRect.width / editorDOM.offsetWidth, scaleY = editorRect.height / editorDOM.offsetHeight; if (isBlock) { let before = $pos.nodeBefore, after = $pos.nodeAfter; if (before || after) { let node = this.editorView.nodeDOM(this.cursorPos - (before ? before.nodeSize : 0)); if (node) { let nodeRect = node.getBoundingClientRect(); let top = before ? nodeRect.bottom : nodeRect.top; if (before && after) top = (top + this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top) / 2; let halfWidth = this.width / 2 * scaleY; rect = { left: nodeRect.left, right: nodeRect.right, top: top - halfWidth, bottom: top + halfWidth }; } } } if (!rect) { let coords = this.editorView.coordsAtPos(this.cursorPos); let halfWidth = this.width / 2 * scaleX; rect = { left: coords.left - halfWidth, right: coords.left + halfWidth, top: coords.top, bottom: coords.bottom }; } let parent = this.editorView.dom.offsetParent; if (!this.element) { this.element = parent.appendChild(document.createElement("div")); if (this.class) this.element.className = this.class; this.element.style.cssText = "position: absolute; z-index: 50; pointer-events: none;"; if (this.color) { this.element.style.backgroundColor = this.color; } } this.element.classList.toggle("prosemirror-dropcursor-block", isBlock); this.element.classList.toggle("prosemirror-dropcursor-inline", !isBlock); let parentLeft, parentTop; if (!parent || parent == document.body && getComputedStyle(parent).position == "static") { parentLeft = -pageXOffset; parentTop = -pageYOffset; } else { let rect2 = parent.getBoundingClientRect(); let parentScaleX = rect2.width / parent.offsetWidth, parentScaleY = rect2.height / parent.offsetHeight; parentLeft = rect2.left - parent.scrollLeft * parentScaleX; parentTop = rect2.top - parent.scrollTop * parentScaleY; } this.element.style.left = (rect.left - parentLeft) / scaleX + "px"; this.element.style.top = (rect.top - parentTop) / scaleY + "px"; this.element.style.width = (rect.right - rect.left) / scaleX + "px"; this.element.style.height = (rect.bottom - rect.top) / scaleY + "px"; } scheduleRemoval(timeout) { clearTimeout(this.timeout); this.timeout = setTimeout(() => this.setCursor(null), timeout); } dragover(event) { if (!this.editorView.editable) return; let pos = this.editorView.posAtCoords({ left: event.clientX, top: event.clientY }); let node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside); let disableDropCursor = node && node.type.spec.disableDropCursor; let disabled = typeof disableDropCursor == "function" ? disableDropCursor(this.editorView, pos, event) : disableDropCursor; if (pos && !disabled) { let target = pos.pos; if (this.editorView.dragging && this.editorView.dragging.slice) { let point = dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice); if (point != null) target = point; } this.setCursor(target); this.scheduleRemoval(5e3); } } dragend() { this.scheduleRemoval(20); } drop() { this.scheduleRemoval(20); } dragleave(event) { if (!this.editorView.dom.contains(event.relatedTarget)) this.setCursor(null); } } class GapCursor extends Selection { /** Create a gap cursor. */ constructor($pos) { super($pos, $pos); } map(doc2, mapping) { let $pos = doc2.resolve(mapping.map(this.head)); return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos); } content() { return Slice.empty; } eq(other) { return other instanceof GapCursor && other.head == this.head; } toJSON() { return { type: "gapcursor", pos: this.head }; } /** @internal */ static fromJSON(doc2, json) { if (typeof json.pos != "number") throw new RangeError("Invalid input for GapCursor.fromJSON"); return new GapCursor(doc2.resolve(json.pos)); } /** @internal */ getBookmark() { return new GapBookmark(this.anchor); } /** @internal */ static valid($pos) { let parent = $pos.parent; if (parent.inlineContent || !closedBefore($pos) || !closedAfter($pos)) return false; let override = parent.type.spec.allowGapCursor; if (override != null) return override; let deflt = parent.contentMatchAt($pos.index()).defaultType; return deflt && deflt.isTextblock; } /** @internal */ static findGapCursorFrom($pos, dir, mustMove = false) { search: for (; ; ) { if (!mustMove && GapCursor.valid($pos)) return $pos; let pos = $pos.pos, next = null; for (let d = $pos.depth; ; d--) { let parent = $pos.node(d); if (dir > 0 ? $pos.indexAfter(d) < parent.childCount : $pos.index(d) > 0) { next = parent.child(dir > 0 ? $pos.indexAfter(d) : $pos.index(d) - 1); break; } else if (d == 0) { return null; } pos += dir; let $cur = $pos.doc.resolve(pos); if (GapCursor.valid($cur)) return $cur; } for (; ; ) { let inside = dir > 0 ? next.firstChild : next.lastChild; if (!inside) { if (next.isAtom && !next.isText && !NodeSelection.isSelectable(next)) { $pos = $pos.doc.resolve(pos + next.nodeSize * dir); mustMove = false; continue search; } break; } next = inside; pos += dir; let $cur = $pos.doc.resolve(pos); if (GapCursor.valid($cur)) return $cur; } return null; } } } GapCursor.prototype.visible = false; GapCursor.findFrom = GapCursor.findGapCursorFrom; Selection.jsonID("gapcursor", GapCursor); class GapBookmark { constructor(pos) { this.pos = pos; } map(mapping) { return new GapBookmark(mapping.map(this.pos)); } resolve(doc2) { let $pos = doc2.resolve(this.pos); return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos); } } function needsGap(type) { return type.isAtom || type.spec.isolating || type.spec.createGapCursor; } function closedBefore($pos) { for (let d = $pos.depth; d >= 0; d--) { let index = $pos.index(d), parent = $pos.node(d); if (index == 0) { if (parent.type.spec.isolating) return true; continue; } for (let before = parent.child(index - 1); ; before = before.lastChild) { if (before.childCount == 0 && !before.inlineContent || needsGap(before.type)) return true; if (before.inlineContent) return false; } } return true; } function closedAfter($pos) { for (let d = $pos.depth; d >= 0; d--) { let index = $pos.indexAfter(d), parent = $pos.node(d); if (index == parent.childCount) { if (parent.type.spec.isolating) return true; continue; } for (let after = parent.child(index); ; after = after.firstChild) { if (after.childCount == 0 && !after.inlineContent || needsGap(after.type)) return true; if (after.inlineContent) return false; } } return true; } function gapCursor() { return new Plugin({ props: { decorations: drawGapCursor, createSelectionBetween(_view, $anchor, $head) { return $anchor.pos == $head.pos && GapCursor.valid($head) ? new GapCursor($head) : null; }, handleClick, handleKeyDown: handleKeyDown$1, handleDOMEvents: { beforeinput } } }); } const handleKeyDown$1 = keydownHandler({ "ArrowLeft": arrow$3("horiz", -1), "ArrowRight": arrow$3("horiz", 1), "ArrowUp": arrow$3("vert", -1), "ArrowDown": arrow$3("vert", 1) }); function arrow$3(axis, dir) { const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left"; return function(state, dispatch, view) { let sel = state.selection; let $start = dir > 0 ? sel.$to : sel.$from, mustMove = sel.empty; if (sel instanceof TextSelection) { if (!view.endOfTextblock(dirStr) || $start.depth == 0) return false; mustMove = false; $start = state.doc.resolve(dir > 0 ? $start.after() : $start.before()); } let $found = GapCursor.findGapCursorFrom($start, dir, mustMove); if (!$found) return false; if (dispatch) dispatch(state.tr.setSelection(new GapCursor($found))); return true; }; } function handleClick(view, pos, event) { if (!view || !view.editable) return false; let $pos = view.state.doc.resolve(pos); if (!GapCursor.valid($pos)) return false; let clickPos = view.posAtCoords({ left: event.clientX, top: event.clientY }); if (clickPos && clickPos.inside > -1 && NodeSelection.isSelectable(view.state.doc.nodeAt(clickPos.inside))) return false; view.dispatch(view.state.tr.setSelection(new GapCursor($pos))); return true; } function beforeinput(view, event) { if (event.inputType != "insertCompositionText" || !(view.state.selection instanceof GapCursor)) return false; let { $from } = view.state.selection; let insert = $from.parent.contentMatchAt($from.index()).findWrapping(view.state.schema.nodes.text); if (!insert) return false; let frag = Fragment.empty; for (let i = insert.length - 1; i >= 0; i--) frag = Fragment.from(insert[i].createAndFill(null, frag)); let tr2 = view.state.tr.replace($from.pos, $from.pos, new Slice(frag, 0, 0)); tr2.setSelection(TextSelection.near(tr2.doc.resolve($from.pos + 1))); view.dispatch(tr2); return false; } function drawGapCursor(state) { if (!(state.selection instanceof GapCursor)) return null; let node = document.createElement("div"); node.className = "ProseMirror-gapcursor"; return DecorationSet.create(state.doc, [Decoration.widget(state.selection.head, node, { key: "gapcursor" })]); } var GOOD_LEAF_SIZE = 200; var RopeSequence = function RopeSequence2() { }; RopeSequence.prototype.append = function append(other) { if (!other.length) { return this; } other = RopeSequence.from(other); return !this.length && other || other.length < GOOD_LEAF_SIZE && this.leafAppend(other) || this.length < GOOD_LEAF_SIZE && other.leafPrepend(this) || this.appendInner(other); }; RopeSequence.prototype.prepend = function prepend(other) { if (!other.length) { return this; } return RopeSequence.from(other).append(this); }; RopeSequence.prototype.appendInner = function appendInner(other) { return new Append(this, other); }; RopeSequence.prototype.slice = function slice(from2, to) { if (from2 === void 0) from2 = 0; if (to === void 0) to = this.length; if (from2 >= to) { return RopeSequence.empty; } return this.sliceInner(Math.max(0, from2), Math.min(this.length, to)); }; RopeSequence.prototype.get = function get(i) { if (i < 0 || i >= this.length) { return void 0; } return this.getInner(i); }; RopeSequence.prototype.forEach = function forEach2(f, from2, to) { if (from2 === void 0) from2 = 0; if (to === void 0) to = this.length; if (from2 <= to) { this.forEachInner(f, from2, to, 0); } else { this.forEachInvertedInner(f, from2, to, 0); } }; RopeSequence.prototype.map = function map(f, from2, to) { if (from2 === void 0) from2 = 0; if (to === void 0) to = this.length; var result = []; this.forEach(function(elt, i) { return result.push(f(elt, i)); }, from2, to); return result; }; RopeSequence.from = function from(values) { if (values instanceof RopeSequence) { return values; } return values && values.length ? new Leaf(values) : RopeSequence.empty; }; var Leaf = /* @__PURE__ */ (function(RopeSequence3) { function Leaf2(values) { RopeSequence3.call(this); this.values = values; } if (RopeSequence3) Leaf2.__proto__ = RopeSequence3; Leaf2.prototype = Object.create(RopeSequence3 && RopeSequence3.prototype); Leaf2.prototype.constructor = Leaf2; var prototypeAccessors = { length: { configurable: true }, depth: { configurable: true } }; Leaf2.prototype.flatten = function flatten() { return this.values; }; Leaf2.prototype.sliceInner = function sliceInner(from2, to) { if (from2 == 0 && to == this.length) { return this; } return new Leaf2(this.values.slice(from2, to)); }; Leaf2.prototype.getInner = function getInner(i) { return this.values[i]; }; Leaf2.prototype.forEachInner = function forEachInner(f, from2, to, start) { for (var i = from2; i < to; i++) { if (f(this.values[i], start + i) === false) { return false; } } }; Leaf2.prototype.forEachInvertedInner = function forEachInvertedInner(f, from2, to, start) { for (var i = from2 - 1; i >= to; i--) { if (f(this.values[i], start + i) === false) { return false; } } }; Leaf2.prototype.leafAppend = function leafAppend(other) { if (this.length + other.length <= GOOD_LEAF_SIZE) { return new Leaf2(this.values.concat(other.flatten())); } }; Leaf2.prototype.leafPrepend = function leafPrepend(other) { if (this.length + other.length <= GOOD_LEAF_SIZE) { return new Leaf2(other.flatten().concat(this.values)); } }; prototypeAccessors.length.get = function() { return this.values.length; }; prototypeAccessors.depth.get = function() { return 0; }; Object.defineProperties(Leaf2.prototype, prototypeAccessors); return Leaf2; })(RopeSequence); RopeSequence.empty = new Leaf([]); var Append = /* @__PURE__ */ (function(RopeSequence3) { function Append2(left, right) { RopeSequence3.call(this); this.left = left; this.right = right; this.length = left.length + right.length; this.depth = Math.max(left.depth, right.depth) + 1; } if (RopeSequence3) Append2.__proto__ = RopeSequence3; Append2.prototype = Object.create(RopeSequence3 && RopeSequence3.prototype); Append2.prototype.constructor = Append2; Append2.prototype.flatten = function flatten() { return this.left.flatten().concat(this.right.flatten()); }; Append2.prototype.getInner = function getInner(i) { return i < this.left.length ? this.left.get(i) : this.right.get(i - this.left.length); }; Append2.prototype.forEachInner = function forEachInner(f, from2, to, start) { var leftLen = this.left.length; if (from2 < leftLen && this.left.forEachInner(f, from2, Math.min(to, leftLen), start) === false) { return false; } if (to > leftLen && this.right.forEachInner(f, Math.max(from2 - leftLen, 0), Math.min(this.length, to) - leftLen, start + leftLen) === false) { return false; } }; Append2.prototype.forEachInvertedInner = function forEachInvertedInner(f, from2, to, start) { var leftLen = this.left.length; if (from2 > leftLen && this.right.forEachInvertedInner(f, from2 - leftLen, Math.max(to, leftLen) - leftLen, start + leftLen) === false) { return false; } if (to < leftLen && this.left.forEachInvertedInner(f, Math.min(from2, leftLen), to, start) === false) { return false; } }; Append2.prototype.sliceInner = function sliceInner(from2, to) { if (from2 == 0 && to == this.length) { return this; } var leftLen = this.left.length; if (to <= leftLen) { return this.left.slice(from2, to); } if (from2 >= leftLen) { return this.right.slice(from2 - leftLen, to - leftLen); } return this.left.slice(from2, leftLen).append(this.right.slice(0, to - leftLen)); }; Append2.prototype.leafAppend = function leafAppend(other) { var inner = this.right.leafAppend(other); if (inner) { return new Append2(this.left, inner); } }; Append2.prototype.leafPrepend = function leafPrepend(other) { var inner = this.left.leafPrepend(other); if (inner) { return new Append2(inner, this.right); } }; Append2.prototype.appendInner = function appendInner2(other) { if (this.left.depth >= Math.max(this.right.depth, other.depth) + 1) { return new Append2(this.left, new Append2(this.right, other)); } return new Append2(this, other); }; return Append2; })(RopeSequence); const max_empty_items = 500; class Branch { constructor(items, eventCount) { this.items = items; this.eventCount = eventCount; } // Pop the latest event off the branch's history and apply it // to a document transform. popEvent(state, preserveItems) { if (this.eventCount == 0) return null; let end = this.items.length; for (; ; end--) { let next = this.items.get(end - 1); if (next.selection) { --end; break; } } let remap, mapFrom; if (preserveItems) { remap = this.remapping(end, this.items.length); mapFrom = remap.maps.length; } let transform = state.tr; let selection, remaining; let addAfter = [], addBefore = []; this.items.forEach((item, i) => { if (!item.step) { if (!remap) { remap = this.remapping(end, i + 1); mapFrom = remap.maps.length; } mapFrom--; addBefore.push(item); return; } if (remap) { addBefore.push(new Item(item.map)); let step = item.step.map(remap.slice(mapFrom)), map2; if (step && transform.maybeStep(step).doc) { map2 = transform.mapping.maps[transform.mapping.maps.length - 1]; addAfter.push(new Item(map2, void 0, void 0, addAfter.length + addBefore.length)); } mapFrom--; if (map2) remap.appendMap(map2, mapFrom); } else { transform.maybeStep(item.step); } if (item.selection) { selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection; remaining = new Branch(this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), this.eventCount - 1); return false; } }, this.items.length, 0); return { remaining, transform, selection }; } // Create a new branch with the given transform added. addTransform(transform, selection, histOptions, preserveItems) { let newItems = [], eventCount = this.eventCount; let oldItems = this.items, lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null; for (let i = 0; i < transform.steps.length; i++) { let step = transform.steps[i].invert(transform.docs[i]); let item = new Item(transform.mapping.maps[i], step, selection), merged; if (merged = lastItem && lastItem.merge(item)) { item = merged; if (i) newItems.pop(); else oldItems = oldItems.slice(0, oldItems.length - 1); } newItems.push(item); if (selection) { eventCount++; selection = void 0; } if (!preserveItems) lastItem = item; } let overflow = eventCount - histOptions.depth; if (overflow > DEPTH_OVERFLOW) { oldItems = cutOffEvents(oldItems, overflow); eventCount -= overflow; } return new Branch(oldItems.append(newItems), eventCount); } remapping(from2, to) { let maps = new Mapping(); this.items.forEach((item, i) => { let mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from2 ? maps.maps.length - item.mirrorOffset : void 0; maps.appendMap(item.map, mirrorPos); }, from2, to); return maps; } addMaps(array) { if (this.eventCount == 0) return this; return new Branch(this.items.append(array.map((map2) => new Item(map2))), this.eventCount); } // When the collab module receives remote changes, the history has // to know about those, so that it can adjust the steps that were // rebased on top of the remote changes, and include the position // maps for the remote changes in its array of items. rebased(rebasedTransform, rebasedCount) { if (!this.eventCount) return this; let rebasedItems = [], start = Math.max(0, this.items.length - rebasedCount); let mapping = rebasedTransform.mapping; let newUntil = rebasedTransform.steps.length; let eventCount = this.eventCount; this.items.forEach((item) => { if (item.selection) eventCount--; }, start); let iRebased = rebasedCount; this.items.forEach((item) => { let pos = mapping.getMirror(--iRebased); if (pos == null) return; newUntil = Math.min(newUntil, pos); let map2 = mapping.maps[pos]; if (item.step) { let step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]); let selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos)); if (selection) eventCount++; rebasedItems.push(new Item(map2, step, selection)); } else { rebasedItems.push(new Item(map2)); } }, start); let newMaps = []; for (let i = rebasedCount; i < newUntil; i++) newMaps.push(new Item(mapping.maps[i])); let items = this.items.slice(0, start).append(newMaps).append(rebasedItems); let branch = new Branch(items, eventCount); if (branch.emptyItemCount() > max_empty_items) branch = branch.compress(this.items.length - rebasedItems.length); return branch; } emptyItemCount() { let count = 0; this.items.forEach((item) => { if (!item.step) count++; }); return count; } // Compressing a branch means rewriting it to push the air (map-only // items) out. During collaboration, these naturally accumulate // because each remote change adds one. The `upto` argument is used // to ensure that only the items below a given level are compressed, // because `rebased` relies on a clean, untouched set of items in // order to associate old items with rebased steps. compress(upto = this.items.length) { let remap = this.remapping(0, upto), mapFrom = remap.maps.length; let items = [], events = 0; this.items.forEach((item, i) => { if (i >= upto) { items.push(item); if (item.selection) events++; } else if (item.step) { let step = item.step.map(remap.slice(mapFrom)), map2 = step && step.getMap(); mapFrom--; if (map2) remap.appendMap(map2, mapFrom); if (step) { let selection = item.selection && item.selection.map(remap.slice(mapFrom)); if (selection) events++; let newItem = new Item(map2.invert(), step, selection), merged, last = items.length - 1; if (merged = items.length && items[last].merge(newItem)) items[last] = merged; else items.push(newItem); } } else if (item.map) { mapFrom--; } }, this.items.length, 0); return new Branch(RopeSequence.from(items.reverse()), events); } } Branch.empty = new Branch(RopeSequence.empty, 0); function cutOffEvents(items, n) { let cutPoint; items.forEach((item, i) => { if (item.selection && n-- == 0) { cutPoint = i; return false; } }); return items.slice(cutPoint); } class Item { constructor(map2, step, selection, mirrorOffset) { this.map = map2; this.step = step; this.selection = selection; this.mirrorOffset = mirrorOffset; } merge(other) { if (this.step && other.step && !other.selection) { let step = other.step.merge(this.step); if (step) return new Item(step.getMap().invert(), step, this.selection); } } } class HistoryState { constructor(done, undone, prevRanges, prevTime, prevComposition) { this.done = done; this.undone = undone; this.prevRanges = prevRanges; this.prevTime = prevTime; this.prevComposition = prevComposition; } } const DEPTH_OVERFLOW = 20; function applyTransaction(history2, state, tr2, options) { let historyTr = tr2.getMeta(historyKey), rebased; if (historyTr) return historyTr.historyState; if (tr2.getMeta(closeHistoryKey)) history2 = new HistoryState(history2.done, history2.undone, null, 0, -1); let appended = tr2.getMeta("appendedTransaction"); if (tr2.steps.length == 0) { return history2; } else if (appended && appended.getMeta(historyKey)) { if (appended.getMeta(historyKey).redo) return new HistoryState(history2.done.addTransform(tr2, void 0, options, mustPreserveItems(state)), history2.undone, rangesFor(tr2.mapping.maps), history2.prevTime, history2.prevComposition); else return new HistoryState(history2.done, history2.undone.addTransform(tr2, void 0, options, mustPreserveItems(state)), null, history2.prevTime, history2.prevComposition); } else if (tr2.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) { let composition = tr2.getMeta("composition"); let newGroup = history2.prevTime == 0 || !appended && history2.prevComposition != composition && (history2.prevTime < (tr2.time || 0) - options.newGroupDelay || !isAdjacentTo(tr2, history2.prevRanges)); let prevRanges = appended ? mapRanges(history2.prevRanges, tr2.mapping) : rangesFor(tr2.mapping.maps); return new HistoryState(history2.done.addTransform(tr2, newGroup ? state.selection.getBookmark() : void 0, options, mustPreserveItems(state)), Branch.empty, prevRanges, tr2.time, composition == null ? history2.prevComposition : composition); } else if (rebased = tr2.getMeta("rebased")) { return new HistoryState(history2.done.rebased(tr2, rebased), history2.undone.rebased(tr2, rebased), mapRanges(history2.prevRanges, tr2.mapping), history2.prevTime, history2.prevComposition); } else { return new HistoryState(history2.done.addMaps(tr2.mapping.maps), history2.undone.addMaps(tr2.mapping.maps), mapRanges(history2.prevRanges, tr2.mapping), history2.prevTime, history2.prevComposition); } } function isAdjacentTo(transform, prevRanges) { if (!prevRanges) return false; if (!transform.docChanged) return true; let adjacent = false; transform.mapping.maps[0].forEach((start, end) => { for (let i = 0; i < prevRanges.length; i += 2) if (start <= prevRanges[i + 1] && end >= prevRanges[i]) adjacent = true; }); return adjacent; } function rangesFor(maps) { let result = []; for (let i = maps.length - 1; i >= 0 && result.length == 0; i--) maps[i].forEach((_from, _to, from2, to) => result.push(from2, to)); return result; } function mapRanges(ranges, mapping) { if (!ranges) return null; let result = []; for (let i = 0; i < ranges.length; i += 2) { let from2 = mapping.map(ranges[i], 1), to = mapping.map(ranges[i + 1], -1); if (from2 <= to) result.push(from2, to); } return result; } function histTransaction(history2, state, redo2) { let preserveItems = mustPreserveItems(state); let histOptions = historyKey.get(state).spec.config; let pop = (redo2 ? history2.undone : history2.done).popEvent(state, preserveItems); if (!pop) return null; let selection = pop.selection.resolve(pop.transform.doc); let added = (redo2 ? history2.done : history2.undone).addTransform(pop.transform, state.selection.getBookmark(), histOptions, preserveItems); let newHist = new HistoryState(redo2 ? added : pop.remaining, redo2 ? pop.remaining : added, null, 0, -1); return pop.transform.setSelection(selection).setMeta(historyKey, { redo: redo2, historyState: newHist }); } let cachedPreserveItems = false, cachedPreserveItemsPlugins = null; function mustPreserveItems(state) { let plugins = state.plugins; if (cachedPreserveItemsPlugins != plugins) { cachedPreserveItems = false; cachedPreserveItemsPlugins = plugins; for (let i = 0; i < plugins.length; i++) if (plugins[i].spec.historyPreserveItems) { cachedPreserveItems = true; break; } } return cachedPreserveItems; } const historyKey = new PluginKey("history"); const closeHistoryKey = new PluginKey("closeHistory"); function history(config = {}) { config = { depth: config.depth || 100, newGroupDelay: config.newGroupDelay || 500 }; return new Plugin({ key: historyKey, state: { init() { return new HistoryState(Branch.empty, Branch.empty, null, 0, -1); }, apply(tr2, hist, state) { return applyTransaction(hist, state, tr2, config); } }, config, props: { handleDOMEvents: { beforeinput(view, e) { let inputType = e.inputType; let command2 = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null; if (!command2 || !view.editable) return false; e.preventDefault(); return command2(view.state, view.dispatch); } } } }); } function buildCommand(redo2, scroll) { return (state, dispatch) => { let hist = historyKey.getState(state); if (!hist || (redo2 ? hist.undone : hist.done).eventCount == 0) return false; if (dispatch) { let tr2 = histTransaction(hist, state, redo2); if (tr2) dispatch(scroll ? tr2.scrollIntoView() : tr2); } return true; }; } const undo = buildCommand(false, true); const redo = buildCommand(true, true); Extension.create({ name: "characterCount", addOptions() { return { limit: null, mode: "textSize", textCounter: (text) => text.length, wordCounter: (text) => text.split(" ").filter((word) => word !== "").length }; }, addStorage() { return { characters: () => 0, words: () => 0 }; }, onBeforeCreate() { this.storage.characters = (options) => { const node = (options == null ? void 0 : options.node) || this.editor.state.doc; const mode = (options == null ? void 0 : options.mode) || this.options.mode; if (mode === "textSize") { const text = node.textBetween(0, node.content.size, void 0, " "); return this.options.textCounter(text); } return node.nodeSize; }; this.storage.words = (options) => { const node = (options == null ? void 0 : options.node) || this.editor.state.doc; const text = node.textBetween(0, node.content.size, " ", " "); return this.options.wordCounter(text); }; }, addProseMirrorPlugins() { let initialEvaluationDone = false; return [ new Plugin({ key: new PluginKey("characterCount"), appendTransaction: (transactions, oldState, newState) => { if (initialEvaluationDone) { return; } const limit = this.options.limit; if (limit === null || limit === void 0 || limit === 0) { initialEvaluationDone = true; return; } const initialContentSize = this.storage.characters({ node: newState.doc }); if (initialContentSize > limit) { const over = initialContentSize - limit; const from2 = 0; const to = over; console.warn( `[CharacterCount] Initial content exceeded limit of ${limit} characters. Content was automatically trimmed.` ); const tr2 = newState.tr.deleteRange(from2, to); initialEvaluationDone = true; return tr2; } initialEvaluationDone = true; }, filterTransaction: (transaction, state) => { const limit = this.options.limit; if (!transaction.docChanged || limit === 0 || limit === null || limit === void 0) { return true; } const oldSize = this.storage.characters({ node: state.doc }); const newSize = this.storage.characters({ node: transaction.doc }); if (newSize <= limit) { return true; } if (oldSize > limit && newSize > limit && newSize <= oldSize) { return true; } if (oldSize > limit && newSize > limit && newSize > oldSize) { return false; } const isPaste = transaction.getMeta("paste"); if (!isPaste) { return false; } const pos = transaction.selection.$head.pos; const over = newSize - limit; const from2 = pos - over; const to = pos; transaction.deleteRange(from2, to); const updatedSize = this.storage.characters({ node: transaction.doc }); if (updatedSize > limit) { return false; } return true; } }) ]; } }); var Dropcursor = Extension.create({ name: "dropCursor", addOptions() { return { color: "currentColor", width: 1, class: void 0 }; }, addProseMirrorPlugins() { return [dropCursor(this.options)]; } }); Extension.create({ name: "focus", addOptions() { return { className: "has-focus", mode: "all" }; }, addProseMirrorPlugins() { return [ new Plugin({ key: new PluginKey("focus"), props: { decorations: ({ doc: doc2, selection }) => { const { isEditable, isFocused } = this.editor; const { anchor } = selection; const decorations = []; if (!isEditable || !isFocused) { return DecorationSet.create(doc2, []); } let maxLevels = 0; if (this.options.mode === "deepest") { doc2.descendants((node, pos) => { if (node.isText) { return; } const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1; if (!isCurrent) { return false; } maxLevels += 1; }); } let currentLevel = 0; doc2.descendants((node, pos) => { if (node.isText) { return false; } const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1; if (!isCurrent) { return false; } currentLevel += 1; const outOfScope = this.options.mode === "deepest" && maxLevels - currentLevel > 0 || this.options.mode === "shallowest" && currentLevel > 1; if (outOfScope) { return this.options.mode === "deepest"; } decorations.push( Decoration.node(pos, pos + node.nodeSize, { class: this.options.className }) ); }); return DecorationSet.create(doc2, decorations); } } }) ]; } }); var Gapcursor = Extension.create({ name: "gapCursor", addProseMirrorPlugins() { return [gapCursor()]; }, extendNodeSchema(extension) { var _a; const context = { name: extension.name, options: extension.options, storage: extension.storage }; return { allowGapCursor: (_a = callOrReturn(getExtensionField(extension, "allowGapCursor", context))) != null ? _a : null }; } }); var DEFAULT_DATA_ATTRIBUTE = "placeholder"; function preparePlaceholderAttribute(attr) { return attr.replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-]/g, "").replace(/^[0-9-]+/, "").replace(/^-+/, "").toLowerCase(); } var Placeholder = Extension.create({ name: "placeholder", addOptions() { return { emptyEditorClass: "is-editor-empty", emptyNodeClass: "is-empty", dataAttribute: DEFAULT_DATA_ATTRIBUTE, placeholder: "Write something …", showOnlyWhenEditable: true, showOnlyCurrent: true, includeChildren: false }; }, addProseMirrorPlugins() { const dataAttribute = this.options.dataAttribute ? `data-${preparePlaceholderAttribute(this.options.dataAttribute)}` : `data-${DEFAULT_DATA_ATTRIBUTE}`; return [ new Plugin({ key: new PluginKey("placeholder"), props: { decorations: ({ doc: doc2, selection }) => { const active = this.editor.isEditable || !this.options.showOnlyWhenEditable; const { anchor } = selection; const decorations = []; if (!active) { return null; } const isEmptyDoc = this.editor.isEmpty; doc2.descendants((node, pos) => { const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize; const isEmpty2 = !node.isLeaf && isNodeEmpty(node); if (!node.type.isTextblock) { return this.options.includeChildren; } if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty2) { const classes = [this.options.emptyNodeClass]; if (isEmptyDoc) { classes.push(this.options.emptyEditorClass); } const decoration = Decoration.node(pos, pos + node.nodeSize, { class: classes.join(" "), [dataAttribute]: typeof this.options.placeholder === "function" ? this.options.placeholder({ editor: this.editor, node, pos, hasAnchor }) : this.options.placeholder }); decorations.push(decoration); } return this.options.includeChildren; }); return DecorationSet.create(doc2, decorations); } } }) ]; } }); Extension.create({ name: "selection", addOptions() { return { className: "selection" }; }, addProseMirrorPlugins() { const { editor, options } = this; return [ new Plugin({ key: new PluginKey("selection"), props: { decorations(state) { if (state.selection.empty || editor.isFocused || !editor.isEditable || isNodeSelection(state.selection) || editor.view.dragging) { return null; } return DecorationSet.create(state.doc, [ Decoration.inline(state.selection.from, state.selection.to, { class: options.className }) ]); } } }) ]; } }); var skipTrailingNodeMeta = "skipTrailingNode"; function nodeEqualsType({ types, node }) { return node && Array.isArray(types) && types.includes(node.type) || (node == null ? void 0 : node.type) === types; } var TrailingNode = Extension.create({ name: "trailingNode", addOptions() { return { node: void 0, notAfter: [] }; }, addProseMirrorPlugins() { var _a; const plugin = new PluginKey(this.name); const defaultNode = this.options.node || ((_a = this.editor.schema.topNodeType.contentMatch.defaultType) == null ? void 0 : _a.name) || "paragraph"; const disabledNodes = Object.entries(this.editor.schema.nodes).map(([, value]) => value).filter((node) => (this.options.notAfter || []).concat(defaultNode).includes(node.name)); return [ new Plugin({ key: plugin, appendTransaction: (transactions, __, state) => { const { doc: doc2, tr: tr2, schema } = state; const shouldInsertNodeAtEnd = plugin.getState(state); const endPosition = doc2.content.size; const type = schema.nodes[defaultNode]; if (transactions.some((transaction) => transaction.getMeta(skipTrailingNodeMeta))) { return; } if (!shouldInsertNodeAtEnd) { return; } return tr2.insert(endPosition, type.create()); }, state: { init: (_, state) => { const lastNode = state.tr.doc.lastChild; return !nodeEqualsType({ node: lastNode, types: disabledNodes }); }, apply: (tr2, value) => { if (!tr2.docChanged) { return value; } if (tr2.getMeta("__uniqueIDTransaction")) { return value; } const lastNode = tr2.doc.lastChild; return !nodeEqualsType({ node: lastNode, types: disabledNodes }); } } }) ]; } }); var UndoRedo = Extension.create({ name: "undoRedo", addOptions() { return { depth: 100, newGroupDelay: 500 }; }, addCommands() { return { undo: () => ({ state, dispatch }) => { return undo(state, dispatch); }, redo: () => ({ state, dispatch }) => { return redo(state, dispatch); } }; }, addProseMirrorPlugins() { return [history(this.options)]; }, addKeyboardShortcuts() { return { "Mod-z": () => this.editor.commands.undo(), "Shift-Mod-z": () => this.editor.commands.redo(), "Mod-y": () => this.editor.commands.redo(), // Russian keyboard layouts "Mod-я": () => this.editor.commands.undo(), "Shift-Mod-я": () => this.editor.commands.redo() }; } }); var StarterKit = Extension.create({ name: "starterKit", addExtensions() { var _a, _b, _c, _d; const extensions = []; if (this.options.bold !== false) { extensions.push(Bold.configure(this.options.bold)); } if (this.options.blockquote !== false) { extensions.push(Blockquote.configure(this.options.blockquote)); } if (this.options.bulletList !== false) { extensions.push(BulletList.configure(this.options.bulletList)); } if (this.options.code !== false) { extensions.push(Code.configure(this.options.code)); } if (this.options.codeBlock !== false) { extensions.push(CodeBlock.configure(this.options.codeBlock)); } if (this.options.document !== false) { extensions.push(Document.configure(this.options.document)); } if (this.options.dropcursor !== false) { extensions.push(Dropcursor.configure(this.options.dropcursor)); } if (this.options.gapcursor !== false) { extensions.push(Gapcursor.configure(this.options.gapcursor)); } if (this.options.hardBreak !== false) { extensions.push(HardBreak.configure(this.options.hardBreak)); } if (this.options.heading !== false) { extensions.push(Heading.configure(this.options.heading)); } if (this.options.undoRedo !== false) { extensions.push(UndoRedo.configure(this.options.undoRedo)); } if (this.options.horizontalRule !== false) { extensions.push(HorizontalRule.configure(this.options.horizontalRule)); } if (this.options.italic !== false) { extensions.push(Italic.configure(this.options.italic)); } if (this.options.listItem !== false) { extensions.push(ListItem.configure(this.options.listItem)); } if (this.options.listKeymap !== false) { extensions.push(ListKeymap.configure((_a = this.options) == null ? void 0 : _a.listKeymap)); } if (this.options.link !== false) { extensions.push(Link.configure((_b = this.options) == null ? void 0 : _b.link)); } if (this.options.orderedList !== false) { extensions.push(OrderedList.configure(this.options.orderedList)); } if (this.options.paragraph !== false) { extensions.push(Paragraph.configure(this.options.paragraph)); } if (this.options.strike !== false) { extensions.push(Strike.configure(this.options.strike)); } if (this.options.text !== false) { extensions.push(Text.configure(this.options.text)); } if (this.options.underline !== false) { extensions.push(Underline.configure((_c = this.options) == null ? void 0 : _c.underline)); } if (this.options.trailingNode !== false) { extensions.push(TrailingNode.configure((_d = this.options) == null ? void 0 : _d.trailingNode)); } return extensions; } }); var index_default$3 = StarterKit; let readFromCache; let addToCache; if (typeof WeakMap != "undefined") { let cache = /* @__PURE__ */ new WeakMap(); readFromCache = (key) => cache.get(key); addToCache = (key, value) => { cache.set(key, value); return value; }; } else { const cache = []; const cacheSize = 10; let cachePos = 0; readFromCache = (key) => { for (let i = 0; i < cache.length; i += 2) if (cache[i] == key) return cache[i + 1]; }; addToCache = (key, value) => { if (cachePos == cacheSize) cachePos = 0; cache[cachePos++] = key; return cache[cachePos++] = value; }; } var TableMap = class { constructor(width, height, map2, problems) { this.width = width; this.height = height; this.map = map2; this.problems = problems; } findCell(pos) { for (let i = 0; i < this.map.length; i++) { const curPos = this.map[i]; if (curPos != pos) continue; const left = i % this.width; const top = i / this.width | 0; let right = left + 1; let bottom = top + 1; for (let j = 1; right < this.width && this.map[i + j] == curPos; j++) right++; for (let j = 1; bottom < this.height && this.map[i + this.width * j] == curPos; j++) bottom++; return { left, top, right, bottom }; } throw new RangeError(`No cell with offset ${pos} found`); } colCount(pos) { for (let i = 0; i < this.map.length; i++) if (this.map[i] == pos) return i % this.width; throw new RangeError(`No cell with offset ${pos} found`); } nextCell(pos, axis, dir) { const { left, right, top, bottom } = this.findCell(pos); if (axis == "horiz") { if (dir < 0 ? left == 0 : right == this.width) return null; return this.map[top * this.width + (dir < 0 ? left - 1 : right)]; } else { if (dir < 0 ? top == 0 : bottom == this.height) return null; return this.map[left + this.width * (dir < 0 ? top - 1 : bottom)]; } } rectBetween(a, b) { const { left: leftA, right: rightA, top: topA, bottom: bottomA } = this.findCell(a); const { left: leftB, right: rightB, top: topB, bottom: bottomB } = this.findCell(b); return { left: Math.min(leftA, leftB), top: Math.min(topA, topB), right: Math.max(rightA, rightB), bottom: Math.max(bottomA, bottomB) }; } cellsInRect(rect) { const result = []; const seen = {}; for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) { const index = row * this.width + col; const pos = this.map[index]; if (seen[pos]) continue; seen[pos] = true; if (col == rect.left && col && this.map[index - 1] == pos || row == rect.top && row && this.map[index - this.width] == pos) continue; result.push(pos); } return result; } positionAt(row, col, table) { for (let i = 0, rowStart = 0; ; i++) { const rowEnd = rowStart + table.child(i).nodeSize; if (i == row) { let index = col + row * this.width; const rowEndIndex = (row + 1) * this.width; while (index < rowEndIndex && this.map[index] < rowStart) index++; return index == rowEndIndex ? rowEnd - 1 : this.map[index]; } rowStart = rowEnd; } } static get(table) { return readFromCache(table) || addToCache(table, computeMap(table)); } }; function computeMap(table) { if (table.type.spec.tableRole != "table") throw new RangeError("Not a table node: " + table.type.name); const width = findWidth(table), height = table.childCount; const map2 = []; let mapPos = 0; let problems = null; const colWidths = []; for (let i = 0, e = width * height; i < e; i++) map2[i] = 0; for (let row = 0, pos = 0; row < height; row++) { const rowNode = table.child(row); pos++; for (let i = 0; ; i++) { while (mapPos < map2.length && map2[mapPos] != 0) mapPos++; if (i == rowNode.childCount) break; const cellNode = rowNode.child(i); const { colspan, rowspan, colwidth } = cellNode.attrs; for (let h2 = 0; h2 < rowspan; h2++) { if (h2 + row >= height) { (problems || (problems = [])).push({ type: "overlong_rowspan", pos, n: rowspan - h2 }); break; } const start = mapPos + h2 * width; for (let w = 0; w < colspan; w++) { if (map2[start + w] == 0) map2[start + w] = pos; else (problems || (problems = [])).push({ type: "collision", row, pos, n: colspan - w }); const colW = colwidth && colwidth[w]; if (colW) { const widthIndex = (start + w) % width * 2, prev = colWidths[widthIndex]; if (prev == null || prev != colW && colWidths[widthIndex + 1] == 1) { colWidths[widthIndex] = colW; colWidths[widthIndex + 1] = 1; } else if (prev == colW) colWidths[widthIndex + 1]++; } } } mapPos += colspan; pos += cellNode.nodeSize; } const expectedPos = (row + 1) * width; let missing = 0; while (mapPos < expectedPos) if (map2[mapPos++] == 0) missing++; if (missing) (problems || (problems = [])).push({ type: "missing", row, n: missing }); pos++; } if (width === 0 || height === 0) (problems || (problems = [])).push({ type: "zero_sized" }); const tableMap = new TableMap(width, height, map2, problems); let badWidths = false; for (let i = 0; !badWidths && i < colWidths.length; i += 2) if (colWidths[i] != null && colWidths[i + 1] < height) badWidths = true; if (badWidths) findBadColWidths(tableMap, colWidths, table); return tableMap; } function findWidth(table) { let width = -1; let hasRowSpan = false; for (let row = 0; row < table.childCount; row++) { const rowNode = table.child(row); let rowWidth = 0; if (hasRowSpan) for (let j = 0; j < row; j++) { const prevRow = table.child(j); for (let i = 0; i < prevRow.childCount; i++) { const cell = prevRow.child(i); if (j + cell.attrs.rowspan > row) rowWidth += cell.attrs.colspan; } } for (let i = 0; i < rowNode.childCount; i++) { const cell = rowNode.child(i); rowWidth += cell.attrs.colspan; if (cell.attrs.rowspan > 1) hasRowSpan = true; } if (width == -1) width = rowWidth; else if (width != rowWidth) width = Math.max(width, rowWidth); } return width; } function findBadColWidths(map2, colWidths, table) { if (!map2.problems) map2.problems = []; const seen = {}; for (let i = 0; i < map2.map.length; i++) { const pos = map2.map[i]; if (seen[pos]) continue; seen[pos] = true; const node = table.nodeAt(pos); if (!node) throw new RangeError(`No cell with offset ${pos} found`); let updated = null; const attrs = node.attrs; for (let j = 0; j < attrs.colspan; j++) { const colWidth = colWidths[(i + j) % map2.width * 2]; if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth)) (updated || (updated = freshColWidth(attrs)))[j] = colWidth; } if (updated) map2.problems.unshift({ type: "colwidth mismatch", pos, colwidth: updated }); } } function freshColWidth(attrs) { if (attrs.colwidth) return attrs.colwidth.slice(); const result = []; for (let i = 0; i < attrs.colspan; i++) result.push(0); return result; } function tableNodeTypes(schema) { let result = schema.cached.tableNodeTypes; if (!result) { result = schema.cached.tableNodeTypes = {}; for (const name in schema.nodes) { const type = schema.nodes[name], role = type.spec.tableRole; if (role) result[role] = type; } } return result; } const tableEditingKey = new PluginKey("selectingCells"); function cellAround($pos) { for (let d = $pos.depth - 1; d > 0; d--) if ($pos.node(d).type.spec.tableRole == "row") return $pos.node(0).resolve($pos.before(d + 1)); return null; } function cellWrapping($pos) { for (let d = $pos.depth; d > 0; d--) { const role = $pos.node(d).type.spec.tableRole; if (role === "cell" || role === "header_cell") return $pos.node(d); } return null; } function isInTable(state) { const $head = state.selection.$head; for (let d = $head.depth; d > 0; d--) if ($head.node(d).type.spec.tableRole == "row") return true; return false; } function selectionCell(state) { const sel = state.selection; if ("$anchorCell" in sel && sel.$anchorCell) return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell; else if ("node" in sel && sel.node && sel.node.type.spec.tableRole == "cell") return sel.$anchor; const $cell = cellAround(sel.$head) || cellNear(sel.$head); if ($cell) return $cell; throw new RangeError(`No cell found around position ${sel.head}`); } function cellNear($pos) { for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) { const role = after.type.spec.tableRole; if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos); } for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) { const role = before.type.spec.tableRole; if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos - before.nodeSize); } } function pointsAtCell($pos) { return $pos.parent.type.spec.tableRole == "row" && !!$pos.nodeAfter; } function moveCellForward($pos) { return $pos.node(0).resolve($pos.pos + $pos.nodeAfter.nodeSize); } function inSameTable($cellA, $cellB) { return $cellA.depth == $cellB.depth && $cellA.pos >= $cellB.start(-1) && $cellA.pos <= $cellB.end(-1); } function nextCell($pos, axis, dir) { const table = $pos.node(-1); const map2 = TableMap.get(table); const tableStart = $pos.start(-1); const moved = map2.nextCell($pos.pos - tableStart, axis, dir); return moved == null ? null : $pos.node(0).resolve(tableStart + moved); } function removeColSpan(attrs, pos, n = 1) { const result = { ...attrs, colspan: attrs.colspan - n }; if (result.colwidth) { result.colwidth = result.colwidth.slice(); result.colwidth.splice(pos, n); if (!result.colwidth.some((w) => w > 0)) result.colwidth = null; } return result; } function addColSpan(attrs, pos, n = 1) { const result = { ...attrs, colspan: attrs.colspan + n }; if (result.colwidth) { result.colwidth = result.colwidth.slice(); for (let i = 0; i < n; i++) result.colwidth.splice(pos, 0, 0); } return result; } function columnIsHeader(map2, table, col) { const headerCell = tableNodeTypes(table.type.schema).header_cell; for (let row = 0; row < map2.height; row++) if (table.nodeAt(map2.map[col + row * map2.width]).type != headerCell) return false; return true; } var CellSelection = class CellSelection2 extends Selection { constructor($anchorCell, $headCell = $anchorCell) { const table = $anchorCell.node(-1); const map2 = TableMap.get(table); const tableStart = $anchorCell.start(-1); const rect = map2.rectBetween($anchorCell.pos - tableStart, $headCell.pos - tableStart); const doc2 = $anchorCell.node(0); const cells = map2.cellsInRect(rect).filter((p) => p != $headCell.pos - tableStart); cells.unshift($headCell.pos - tableStart); const ranges = cells.map((pos) => { const cell = table.nodeAt(pos); if (!cell) throw new RangeError(`No cell with offset ${pos} found`); const from2 = tableStart + pos + 1; return new SelectionRange(doc2.resolve(from2), doc2.resolve(from2 + cell.content.size)); }); super(ranges[0].$from, ranges[0].$to, ranges); this.$anchorCell = $anchorCell; this.$headCell = $headCell; } map(doc2, mapping) { const $anchorCell = doc2.resolve(mapping.map(this.$anchorCell.pos)); const $headCell = doc2.resolve(mapping.map(this.$headCell.pos)); if (pointsAtCell($anchorCell) && pointsAtCell($headCell) && inSameTable($anchorCell, $headCell)) { const tableChanged = this.$anchorCell.node(-1) != $anchorCell.node(-1); if (tableChanged && this.isRowSelection()) return CellSelection2.rowSelection($anchorCell, $headCell); else if (tableChanged && this.isColSelection()) return CellSelection2.colSelection($anchorCell, $headCell); else return new CellSelection2($anchorCell, $headCell); } return TextSelection.between($anchorCell, $headCell); } content() { const table = this.$anchorCell.node(-1); const map2 = TableMap.get(table); const tableStart = this.$anchorCell.start(-1); const rect = map2.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart); const seen = {}; const rows = []; for (let row = rect.top; row < rect.bottom; row++) { const rowContent = []; for (let index = row * map2.width + rect.left, col = rect.left; col < rect.right; col++, index++) { const pos = map2.map[index]; if (seen[pos]) continue; seen[pos] = true; const cellRect = map2.findCell(pos); let cell = table.nodeAt(pos); if (!cell) throw new RangeError(`No cell with offset ${pos} found`); const extraLeft = rect.left - cellRect.left; const extraRight = cellRect.right - rect.right; if (extraLeft > 0 || extraRight > 0) { let attrs = cell.attrs; if (extraLeft > 0) attrs = removeColSpan(attrs, 0, extraLeft); if (extraRight > 0) attrs = removeColSpan(attrs, attrs.colspan - extraRight, extraRight); if (cellRect.left < rect.left) { cell = cell.type.createAndFill(attrs); if (!cell) throw new RangeError(`Could not create cell with attrs ${JSON.stringify(attrs)}`); } else cell = cell.type.create(attrs, cell.content); } if (cellRect.top < rect.top || cellRect.bottom > rect.bottom) { const attrs = { ...cell.attrs, rowspan: Math.min(cellRect.bottom, rect.bottom) - Math.max(cellRect.top, rect.top) }; if (cellRect.top < rect.top) cell = cell.type.createAndFill(attrs); else cell = cell.type.create(attrs, cell.content); } rowContent.push(cell); } rows.push(table.child(row).copy(Fragment.from(rowContent))); } const fragment = this.isColSelection() && this.isRowSelection() ? table : rows; return new Slice(Fragment.from(fragment), 1, 1); } replace(tr2, content = Slice.empty) { const mapFrom = tr2.steps.length, ranges = this.ranges; for (let i = 0; i < ranges.length; i++) { const { $from, $to } = ranges[i], mapping = tr2.mapping.slice(mapFrom); tr2.replace(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content); } const sel = Selection.findFrom(tr2.doc.resolve(tr2.mapping.slice(mapFrom).map(this.to)), -1); if (sel) tr2.setSelection(sel); } replaceWith(tr2, node) { this.replace(tr2, new Slice(Fragment.from(node), 0, 0)); } forEachCell(f) { const table = this.$anchorCell.node(-1); const map2 = TableMap.get(table); const tableStart = this.$anchorCell.start(-1); const cells = map2.cellsInRect(map2.rectBetween(this.$anchorCell.pos - tableStart, this.$headCell.pos - tableStart)); for (let i = 0; i < cells.length; i++) f(table.nodeAt(cells[i]), tableStart + cells[i]); } isColSelection() { const anchorTop = this.$anchorCell.index(-1); const headTop = this.$headCell.index(-1); if (Math.min(anchorTop, headTop) > 0) return false; const anchorBottom = anchorTop + this.$anchorCell.nodeAfter.attrs.rowspan; const headBottom = headTop + this.$headCell.nodeAfter.attrs.rowspan; return Math.max(anchorBottom, headBottom) == this.$headCell.node(-1).childCount; } static colSelection($anchorCell, $headCell = $anchorCell) { const table = $anchorCell.node(-1); const map2 = TableMap.get(table); const tableStart = $anchorCell.start(-1); const anchorRect = map2.findCell($anchorCell.pos - tableStart); const headRect = map2.findCell($headCell.pos - tableStart); const doc2 = $anchorCell.node(0); if (anchorRect.top <= headRect.top) { if (anchorRect.top > 0) $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.left]); if (headRect.bottom < map2.height) $headCell = doc2.resolve(tableStart + map2.map[map2.width * (map2.height - 1) + headRect.right - 1]); } else { if (headRect.top > 0) $headCell = doc2.resolve(tableStart + map2.map[headRect.left]); if (anchorRect.bottom < map2.height) $anchorCell = doc2.resolve(tableStart + map2.map[map2.width * (map2.height - 1) + anchorRect.right - 1]); } return new CellSelection2($anchorCell, $headCell); } isRowSelection() { const table = this.$anchorCell.node(-1); const map2 = TableMap.get(table); const tableStart = this.$anchorCell.start(-1); const anchorLeft = map2.colCount(this.$anchorCell.pos - tableStart); const headLeft = map2.colCount(this.$headCell.pos - tableStart); if (Math.min(anchorLeft, headLeft) > 0) return false; const anchorRight = anchorLeft + this.$anchorCell.nodeAfter.attrs.colspan; const headRight = headLeft + this.$headCell.nodeAfter.attrs.colspan; return Math.max(anchorRight, headRight) == map2.width; } eq(other) { return other instanceof CellSelection2 && other.$anchorCell.pos == this.$anchorCell.pos && other.$headCell.pos == this.$headCell.pos; } static rowSelection($anchorCell, $headCell = $anchorCell) { const table = $anchorCell.node(-1); const map2 = TableMap.get(table); const tableStart = $anchorCell.start(-1); const anchorRect = map2.findCell($anchorCell.pos - tableStart); const headRect = map2.findCell($headCell.pos - tableStart); const doc2 = $anchorCell.node(0); if (anchorRect.left <= headRect.left) { if (anchorRect.left > 0) $anchorCell = doc2.resolve(tableStart + map2.map[anchorRect.top * map2.width]); if (headRect.right < map2.width) $headCell = doc2.resolve(tableStart + map2.map[map2.width * (headRect.top + 1) - 1]); } else { if (headRect.left > 0) $headCell = doc2.resolve(tableStart + map2.map[headRect.top * map2.width]); if (anchorRect.right < map2.width) $anchorCell = doc2.resolve(tableStart + map2.map[map2.width * (anchorRect.top + 1) - 1]); } return new CellSelection2($anchorCell, $headCell); } toJSON() { return { type: "cell", anchor: this.$anchorCell.pos, head: this.$headCell.pos }; } static fromJSON(doc2, json) { return new CellSelection2(doc2.resolve(json.anchor), doc2.resolve(json.head)); } static create(doc2, anchorCell, headCell = anchorCell) { return new CellSelection2(doc2.resolve(anchorCell), doc2.resolve(headCell)); } getBookmark() { return new CellBookmark(this.$anchorCell.pos, this.$headCell.pos); } }; CellSelection.prototype.visible = false; Selection.jsonID("cell", CellSelection); var CellBookmark = class CellBookmark2 { constructor(anchor, head) { this.anchor = anchor; this.head = head; } map(mapping) { return new CellBookmark2(mapping.map(this.anchor), mapping.map(this.head)); } resolve(doc2) { const $anchorCell = doc2.resolve(this.anchor), $headCell = doc2.resolve(this.head); 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)) return new CellSelection($anchorCell, $headCell); else return Selection.near($headCell, 1); } }; function drawCellSelection(state) { if (!(state.selection instanceof CellSelection)) return null; const cells = []; state.selection.forEachCell((node, pos) => { cells.push(Decoration.node(pos, pos + node.nodeSize, { class: "selectedCell" })); }); return DecorationSet.create(state.doc, cells); } function isCellBoundarySelection({ $from, $to }) { if ($from.pos == $to.pos || $from.pos < $to.pos - 6) return false; let afterFrom = $from.pos; let beforeTo = $to.pos; let depth = $from.depth; for (; depth >= 0; depth--, afterFrom++) if ($from.after(depth + 1) < $from.end(depth)) break; for (let d = $to.depth; d >= 0; d--, beforeTo--) if ($to.before(d + 1) > $to.start(d)) break; return afterFrom == beforeTo && /row|table/.test($from.node(depth).type.spec.tableRole); } function isTextSelectionAcrossCells({ $from, $to }) { let fromCellBoundaryNode; let toCellBoundaryNode; for (let i = $from.depth; i > 0; i--) { const node = $from.node(i); if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") { fromCellBoundaryNode = node; break; } } for (let i = $to.depth; i > 0; i--) { const node = $to.node(i); if (node.type.spec.tableRole === "cell" || node.type.spec.tableRole === "header_cell") { toCellBoundaryNode = node; break; } } return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0; } function normalizeSelection(state, tr2, allowTableNodeSelection) { const sel = (tr2 || state).selection; const doc2 = (tr2 || state).doc; let normalize2; let role; if (sel instanceof NodeSelection && (role = sel.node.type.spec.tableRole)) { if (role == "cell" || role == "header_cell") normalize2 = CellSelection.create(doc2, sel.from); else if (role == "row") { const $cell = doc2.resolve(sel.from + 1); normalize2 = CellSelection.rowSelection($cell, $cell); } else if (!allowTableNodeSelection) { const map2 = TableMap.get(sel.node); const start = sel.from + 1; const lastCell = start + map2.map[map2.width * map2.height - 1]; normalize2 = CellSelection.create(doc2, start + 1, lastCell); } } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) normalize2 = TextSelection.create(doc2, sel.from); else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) normalize2 = TextSelection.create(doc2, sel.$from.start(), sel.$from.end()); if (normalize2) (tr2 || (tr2 = state.tr)).setSelection(normalize2); return tr2; } const fixTablesKey = new PluginKey("fix-tables"); function changedDescendants(old, cur, offset2, f) { const oldSize = old.childCount, curSize = cur.childCount; outer: for (let i = 0, j = 0; i < curSize; i++) { const child = cur.child(i); for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) if (old.child(scan) == child) { j = scan + 1; offset2 += child.nodeSize; continue outer; } f(child, offset2); if (j < oldSize && old.child(j).sameMarkup(child)) changedDescendants(old.child(j), child, offset2 + 1, f); else child.nodesBetween(0, child.content.size, f, offset2 + 1); offset2 += child.nodeSize; } } function fixTables(state, oldState) { let tr2; const check = (node, pos) => { if (node.type.spec.tableRole == "table") tr2 = fixTable(state, node, pos, tr2); }; if (!oldState) state.doc.descendants(check); else if (oldState.doc != state.doc) changedDescendants(oldState.doc, state.doc, 0, check); return tr2; } function fixTable(state, table, tablePos, tr2) { const map2 = TableMap.get(table); if (!map2.problems) return tr2; if (!tr2) tr2 = state.tr; const mustAdd = []; for (let i = 0; i < map2.height; i++) mustAdd.push(0); for (let i = 0; i < map2.problems.length; i++) { const prob = map2.problems[i]; if (prob.type == "collision") { const cell = table.nodeAt(prob.pos); if (!cell) continue; const attrs = cell.attrs; for (let j = 0; j < attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n; tr2.setNodeMarkup(tr2.mapping.map(tablePos + 1 + prob.pos), null, removeColSpan(attrs, attrs.colspan - prob.n, prob.n)); } else if (prob.type == "missing") mustAdd[prob.row] += prob.n; else if (prob.type == "overlong_rowspan") { const cell = table.nodeAt(prob.pos); if (!cell) continue; tr2.setNodeMarkup(tr2.mapping.map(tablePos + 1 + prob.pos), null, { ...cell.attrs, rowspan: cell.attrs.rowspan - prob.n }); } else if (prob.type == "colwidth mismatch") { const cell = table.nodeAt(prob.pos); if (!cell) continue; tr2.setNodeMarkup(tr2.mapping.map(tablePos + 1 + prob.pos), null, { ...cell.attrs, colwidth: prob.colwidth }); } else if (prob.type == "zero_sized") { const pos = tr2.mapping.map(tablePos); tr2.delete(pos, pos + table.nodeSize); } } let first2, last; for (let i = 0; i < mustAdd.length; i++) if (mustAdd[i]) { if (first2 == null) first2 = i; last = i; } for (let i = 0, pos = tablePos + 1; i < map2.height; i++) { const row = table.child(i); const end = pos + row.nodeSize; const add = mustAdd[i]; if (add > 0) { let role = "cell"; if (row.firstChild) role = row.firstChild.type.spec.tableRole; const nodes = []; for (let j = 0; j < add; j++) { const node = tableNodeTypes(state.schema)[role].createAndFill(); if (node) nodes.push(node); } const side = (i == 0 || first2 == i - 1) && last == i ? pos + 1 : end - 1; tr2.insert(tr2.mapping.map(side), nodes); } pos = end; } return tr2.setMeta(fixTablesKey, { fixTables: true }); } function selectedRect(state) { const sel = state.selection; const $pos = selectionCell(state); const table = $pos.node(-1); const tableStart = $pos.start(-1); const map2 = TableMap.get(table); return { ...sel instanceof CellSelection ? map2.rectBetween(sel.$anchorCell.pos - tableStart, sel.$headCell.pos - tableStart) : map2.findCell($pos.pos - tableStart), tableStart, map: map2, table }; } function addColumn(tr2, { map: map2, tableStart, table }, col) { let refColumn = col > 0 ? -1 : 0; if (columnIsHeader(map2, table, col + refColumn)) refColumn = col == 0 || col == map2.width ? null : 0; for (let row = 0; row < map2.height; row++) { const index = row * map2.width + col; if (col > 0 && col < map2.width && map2.map[index - 1] == map2.map[index]) { const pos = map2.map[index]; const cell = table.nodeAt(pos); tr2.setNodeMarkup(tr2.mapping.map(tableStart + pos), null, addColSpan(cell.attrs, col - map2.colCount(pos))); row += cell.attrs.rowspan - 1; } else { const type = refColumn == null ? tableNodeTypes(table.type.schema).cell : table.nodeAt(map2.map[index + refColumn]).type; const pos = map2.positionAt(row, col, table); tr2.insert(tr2.mapping.map(tableStart + pos), type.createAndFill()); } } return tr2; } function addColumnBefore(state, dispatch) { if (!isInTable(state)) return false; if (dispatch) { const rect = selectedRect(state); dispatch(addColumn(state.tr, rect, rect.left)); } return true; } function addColumnAfter(state, dispatch) { if (!isInTable(state)) return false; if (dispatch) { const rect = selectedRect(state); dispatch(addColumn(state.tr, rect, rect.right)); } return true; } function removeColumn(tr2, { map: map2, table, tableStart }, col) { const mapStart = tr2.mapping.maps.length; for (let row = 0; row < map2.height; ) { const index = row * map2.width + col; const pos = map2.map[index]; const cell = table.nodeAt(pos); const attrs = cell.attrs; if (col > 0 && map2.map[index - 1] == pos || col < map2.width - 1 && map2.map[index + 1] == pos) tr2.setNodeMarkup(tr2.mapping.slice(mapStart).map(tableStart + pos), null, removeColSpan(attrs, col - map2.colCount(pos))); else { const start = tr2.mapping.slice(mapStart).map(tableStart + pos); tr2.delete(start, start + cell.nodeSize); } row += attrs.rowspan; } } function deleteColumn(state, dispatch) { if (!isInTable(state)) return false; if (dispatch) { const rect = selectedRect(state); const tr2 = state.tr; if (rect.left == 0 && rect.right == rect.map.width) return false; for (let i = rect.right - 1; ; i--) { removeColumn(tr2, rect, i); if (i == rect.left) break; const table = rect.tableStart ? tr2.doc.nodeAt(rect.tableStart - 1) : tr2.doc; if (!table) throw new RangeError("No table found"); rect.table = table; rect.map = TableMap.get(table); } dispatch(tr2); } return true; } function rowIsHeader(map2, table, row) { var _table$nodeAt; const headerCell = tableNodeTypes(table.type.schema).header_cell; for (let col = 0; col < map2.width; col++) if (((_table$nodeAt = table.nodeAt(map2.map[col + row * map2.width])) === null || _table$nodeAt === void 0 ? void 0 : _table$nodeAt.type) != headerCell) return false; return true; } function addRow(tr2, { map: map2, tableStart, table }, row) { let rowPos = tableStart; for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize; const cells = []; let refRow = row > 0 ? -1 : 0; if (rowIsHeader(map2, table, row + refRow)) refRow = row == 0 || row == map2.height ? null : 0; for (let col = 0, index = map2.width * row; col < map2.width; col++, index++) if (row > 0 && row < map2.height && map2.map[index] == map2.map[index - map2.width]) { const pos = map2.map[index]; const attrs = table.nodeAt(pos).attrs; tr2.setNodeMarkup(tableStart + pos, null, { ...attrs, rowspan: attrs.rowspan + 1 }); col += attrs.colspan - 1; } else { var _table$nodeAt2; const type = refRow == null ? tableNodeTypes(table.type.schema).cell : (_table$nodeAt2 = table.nodeAt(map2.map[index + refRow * map2.width])) === null || _table$nodeAt2 === void 0 ? void 0 : _table$nodeAt2.type; const node = type === null || type === void 0 ? void 0 : type.createAndFill(); if (node) cells.push(node); } tr2.insert(rowPos, tableNodeTypes(table.type.schema).row.create(null, cells)); return tr2; } function addRowBefore(state, dispatch) { if (!isInTable(state)) return false; if (dispatch) { const rect = selectedRect(state); dispatch(addRow(state.tr, rect, rect.top)); } return true; } function addRowAfter(state, dispatch) { if (!isInTable(state)) return false; if (dispatch) { const rect = selectedRect(state); dispatch(addRow(state.tr, rect, rect.bottom)); } return true; } function removeRow(tr2, { map: map2, table, tableStart }, row) { let rowPos = 0; for (let i = 0; i < row; i++) rowPos += table.child(i).nodeSize; const nextRow = rowPos + table.child(row).nodeSize; const mapFrom = tr2.mapping.maps.length; tr2.delete(rowPos + tableStart, nextRow + tableStart); const seen = /* @__PURE__ */ new Set(); for (let col = 0, index = row * map2.width; col < map2.width; col++, index++) { const pos = map2.map[index]; if (seen.has(pos)) continue; seen.add(pos); if (row > 0 && pos == map2.map[index - map2.width]) { const attrs = table.nodeAt(pos).attrs; tr2.setNodeMarkup(tr2.mapping.slice(mapFrom).map(pos + tableStart), null, { ...attrs, rowspan: attrs.rowspan - 1 }); col += attrs.colspan - 1; } else if (row < map2.height && pos == map2.map[index + map2.width]) { const cell = table.nodeAt(pos); const attrs = cell.attrs; const copy2 = cell.type.create({ ...attrs, rowspan: cell.attrs.rowspan - 1 }, cell.content); const newPos = map2.positionAt(row + 1, col, table); tr2.insert(tr2.mapping.slice(mapFrom).map(tableStart + newPos), copy2); col += attrs.colspan - 1; } } } function deleteRow(state, dispatch) { if (!isInTable(state)) return false; if (dispatch) { const rect = selectedRect(state), tr2 = state.tr; if (rect.top == 0 && rect.bottom == rect.map.height) return false; for (let i = rect.bottom - 1; ; i--) { removeRow(tr2, rect, i); if (i == rect.top) break; const table = rect.tableStart ? tr2.doc.nodeAt(rect.tableStart - 1) : tr2.doc; if (!table) throw new RangeError("No table found"); rect.table = table; rect.map = TableMap.get(rect.table); } dispatch(tr2); } return true; } function isEmpty(cell) { const c = cell.content; return c.childCount == 1 && c.child(0).isTextblock && c.child(0).childCount == 0; } function cellsOverlapRectangle({ width, height, map: map2 }, rect) { let indexTop = rect.top * width + rect.left, indexLeft = indexTop; let indexBottom = (rect.bottom - 1) * width + rect.left, indexRight = indexTop + (rect.right - rect.left - 1); for (let i = rect.top; i < rect.bottom; i++) { if (rect.left > 0 && map2[indexLeft] == map2[indexLeft - 1] || rect.right < width && map2[indexRight] == map2[indexRight + 1]) return true; indexLeft += width; indexRight += width; } for (let i = rect.left; i < rect.right; i++) { if (rect.top > 0 && map2[indexTop] == map2[indexTop - width] || rect.bottom < height && map2[indexBottom] == map2[indexBottom + width]) return true; indexTop++; indexBottom++; } return false; } function mergeCells(state, dispatch) { const sel = state.selection; if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos) return false; const rect = selectedRect(state), { map: map2 } = rect; if (cellsOverlapRectangle(map2, rect)) return false; if (dispatch) { const tr2 = state.tr; const seen = {}; let content = Fragment.empty; let mergedPos; let mergedCell; for (let row = rect.top; row < rect.bottom; row++) for (let col = rect.left; col < rect.right; col++) { const cellPos = map2.map[row * map2.width + col]; const cell = rect.table.nodeAt(cellPos); if (seen[cellPos] || !cell) continue; seen[cellPos] = true; if (mergedPos == null) { mergedPos = cellPos; mergedCell = cell; } else { if (!isEmpty(cell)) content = content.append(cell.content); const mapped = tr2.mapping.map(cellPos + rect.tableStart); tr2.delete(mapped, mapped + cell.nodeSize); } } if (mergedPos == null || mergedCell == null) return true; tr2.setNodeMarkup(mergedPos + rect.tableStart, null, { ...addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, rect.right - rect.left - mergedCell.attrs.colspan), rowspan: rect.bottom - rect.top }); if (content.size > 0) { const end = mergedPos + 1 + mergedCell.content.size; const start = isEmpty(mergedCell) ? mergedPos + 1 : end; tr2.replaceWith(start + rect.tableStart, end + rect.tableStart, content); } tr2.setSelection(new CellSelection(tr2.doc.resolve(mergedPos + rect.tableStart))); dispatch(tr2); } return true; } function splitCell(state, dispatch) { const nodeTypes = tableNodeTypes(state.schema); return splitCellWithType(({ node }) => { return nodeTypes[node.type.spec.tableRole]; })(state, dispatch); } function splitCellWithType(getCellType) { return (state, dispatch) => { const sel = state.selection; let cellNode; let cellPos; if (!(sel instanceof CellSelection)) { var _cellAround; cellNode = cellWrapping(sel.$from); if (!cellNode) return false; cellPos = (_cellAround = cellAround(sel.$from)) === null || _cellAround === void 0 ? void 0 : _cellAround.pos; } else { if (sel.$anchorCell.pos != sel.$headCell.pos) return false; cellNode = sel.$anchorCell.nodeAfter; cellPos = sel.$anchorCell.pos; } if (cellNode == null || cellPos == null) return false; if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) return false; if (dispatch) { let baseAttrs = cellNode.attrs; const attrs = []; const colwidth = baseAttrs.colwidth; if (baseAttrs.rowspan > 1) baseAttrs = { ...baseAttrs, rowspan: 1 }; if (baseAttrs.colspan > 1) baseAttrs = { ...baseAttrs, colspan: 1 }; const rect = selectedRect(state), tr2 = state.tr; for (let i = 0; i < rect.right - rect.left; i++) attrs.push(colwidth ? { ...baseAttrs, colwidth: colwidth && colwidth[i] ? [colwidth[i]] : null } : baseAttrs); let lastCell; for (let row = rect.top; row < rect.bottom; row++) { let pos = rect.map.positionAt(row, rect.left, rect.table); if (row == rect.top) pos += cellNode.nodeSize; for (let col = rect.left, i = 0; col < rect.right; col++, i++) { if (col == rect.left && row == rect.top) continue; tr2.insert(lastCell = tr2.mapping.map(pos + rect.tableStart, 1), getCellType({ node: cellNode, row, col }).createAndFill(attrs[i])); } } tr2.setNodeMarkup(cellPos, getCellType({ node: cellNode, row: rect.top, col: rect.left }), attrs[0]); if (sel instanceof CellSelection) tr2.setSelection(new CellSelection(tr2.doc.resolve(sel.$anchorCell.pos), lastCell ? tr2.doc.resolve(lastCell) : void 0)); dispatch(tr2); } return true; }; } function setCellAttr(name, value) { return function(state, dispatch) { if (!isInTable(state)) return false; const $cell = selectionCell(state); if ($cell.nodeAfter.attrs[name] === value) return false; if (dispatch) { const tr2 = state.tr; if (state.selection instanceof CellSelection) state.selection.forEachCell((node, pos) => { if (node.attrs[name] !== value) tr2.setNodeMarkup(pos, null, { ...node.attrs, [name]: value }); }); else tr2.setNodeMarkup($cell.pos, null, { ...$cell.nodeAfter.attrs, [name]: value }); dispatch(tr2); } return true; }; } function deprecated_toggleHeader(type) { return function(state, dispatch) { if (!isInTable(state)) return false; if (dispatch) { const types = tableNodeTypes(state.schema); const rect = selectedRect(state), tr2 = state.tr; const cells = rect.map.cellsInRect(type == "column" ? { left: rect.left, top: 0, right: rect.right, bottom: rect.map.height } : type == "row" ? { left: 0, top: rect.top, right: rect.map.width, bottom: rect.bottom } : rect); const nodes = cells.map((pos) => rect.table.nodeAt(pos)); for (let i = 0; i < cells.length; i++) if (nodes[i].type == types.header_cell) tr2.setNodeMarkup(rect.tableStart + cells[i], types.cell, nodes[i].attrs); if (tr2.steps.length === 0) for (let i = 0; i < cells.length; i++) tr2.setNodeMarkup(rect.tableStart + cells[i], types.header_cell, nodes[i].attrs); dispatch(tr2); } return true; }; } function isHeaderEnabledByType(type, rect, types) { const cellPositions = rect.map.cellsInRect({ left: 0, top: 0, right: type == "row" ? rect.map.width : 1, bottom: type == "column" ? rect.map.height : 1 }); for (let i = 0; i < cellPositions.length; i++) { const cell = rect.table.nodeAt(cellPositions[i]); if (cell && cell.type !== types.header_cell) return false; } return true; } function toggleHeader(type, options) { options = options || { useDeprecatedLogic: false }; if (options.useDeprecatedLogic) return deprecated_toggleHeader(type); return function(state, dispatch) { if (!isInTable(state)) return false; if (dispatch) { const types = tableNodeTypes(state.schema); const rect = selectedRect(state), tr2 = state.tr; const isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types); const isHeaderColumnEnabled = isHeaderEnabledByType("column", rect, types); const selectionStartsAt = (type === "column" ? isHeaderRowEnabled : type === "row" ? isHeaderColumnEnabled : false) ? 1 : 0; const cellsRect = type == "column" ? { left: 0, top: selectionStartsAt, right: 1, bottom: rect.map.height } : type == "row" ? { left: selectionStartsAt, top: 0, right: rect.map.width, bottom: 1 } : rect; const newType = type == "column" ? isHeaderColumnEnabled ? types.cell : types.header_cell : type == "row" ? isHeaderRowEnabled ? types.cell : types.header_cell : types.cell; rect.map.cellsInRect(cellsRect).forEach((relativeCellPos) => { const cellPos = relativeCellPos + rect.tableStart; const cell = tr2.doc.nodeAt(cellPos); if (cell) tr2.setNodeMarkup(cellPos, newType, cell.attrs); }); dispatch(tr2); } return true; }; } toggleHeader("row", { useDeprecatedLogic: true }); toggleHeader("column", { useDeprecatedLogic: true }); const toggleHeaderCell = toggleHeader("cell", { useDeprecatedLogic: true }); function findNextCell($cell, dir) { if (dir < 0) { const before = $cell.nodeBefore; if (before) return $cell.pos - before.nodeSize; for (let row = $cell.index(-1) - 1, rowEnd = $cell.before(); row >= 0; row--) { const rowNode = $cell.node(-1).child(row); const lastChild = rowNode.lastChild; if (lastChild) return rowEnd - 1 - lastChild.nodeSize; rowEnd -= rowNode.nodeSize; } } else { if ($cell.index() < $cell.parent.childCount - 1) return $cell.pos + $cell.nodeAfter.nodeSize; const table = $cell.node(-1); for (let row = $cell.indexAfter(-1), rowStart = $cell.after(); row < table.childCount; row++) { const rowNode = table.child(row); if (rowNode.childCount) return rowStart + 1; rowStart += rowNode.nodeSize; } } return null; } function goToNextCell(direction) { return function(state, dispatch) { if (!isInTable(state)) return false; const cell = findNextCell(selectionCell(state), direction); if (cell == null) return false; if (dispatch) { const $cell = state.doc.resolve(cell); dispatch(state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView()); } return true; }; } function deleteTable(state, dispatch) { const $pos = state.selection.$anchor; for (let d = $pos.depth; d > 0; d--) if ($pos.node(d).type.spec.tableRole == "table") { if (dispatch) dispatch(state.tr.delete($pos.before(d), $pos.after(d)).scrollIntoView()); return true; } return false; } function deleteCellSelection(state, dispatch) { const sel = state.selection; if (!(sel instanceof CellSelection)) return false; if (dispatch) { const tr2 = state.tr; const baseContent = tableNodeTypes(state.schema).cell.createAndFill().content; sel.forEachCell((cell, pos) => { if (!cell.content.eq(baseContent)) tr2.replace(tr2.mapping.map(pos + 1), tr2.mapping.map(pos + cell.nodeSize - 1), new Slice(baseContent, 0, 0)); }); if (tr2.docChanged) dispatch(tr2); } return true; } function pastedCells(slice2) { if (slice2.size === 0) return null; let { content, openStart, openEnd } = slice2; while (content.childCount == 1 && (openStart > 0 && openEnd > 0 || content.child(0).type.spec.tableRole == "table")) { openStart--; openEnd--; content = content.child(0).content; } const first2 = content.child(0); const role = first2.type.spec.tableRole; const schema = first2.type.schema, rows = []; if (role == "row") for (let i = 0; i < content.childCount; i++) { let cells = content.child(i).content; const left = i ? 0 : Math.max(0, openStart - 1); const right = i < content.childCount - 1 ? 0 : Math.max(0, openEnd - 1); if (left || right) cells = fitSlice(tableNodeTypes(schema).row, new Slice(cells, left, right)).content; rows.push(cells); } else if (role == "cell" || role == "header_cell") rows.push(openStart || openEnd ? fitSlice(tableNodeTypes(schema).row, new Slice(content, openStart, openEnd)).content : content); else return null; return ensureRectangular(schema, rows); } function ensureRectangular(schema, rows) { const widths = []; for (let i = 0; i < rows.length; i++) { const row = rows[i]; for (let j = row.childCount - 1; j >= 0; j--) { const { rowspan, colspan } = row.child(j).attrs; for (let r = i; r < i + rowspan; r++) widths[r] = (widths[r] || 0) + colspan; } } let width = 0; for (let r = 0; r < widths.length; r++) width = Math.max(width, widths[r]); for (let r = 0; r < widths.length; r++) { if (r >= rows.length) rows.push(Fragment.empty); if (widths[r] < width) { const empty2 = tableNodeTypes(schema).cell.createAndFill(); const cells = []; for (let i = widths[r]; i < width; i++) cells.push(empty2); rows[r] = rows[r].append(Fragment.from(cells)); } } return { height: rows.length, width, rows }; } function fitSlice(nodeType, slice2) { const node = nodeType.createAndFill(); return new Transform(node).replace(0, node.content.size, slice2).doc; } function clipCells({ width, height, rows }, newWidth, newHeight) { if (width != newWidth) { const added = []; const newRows = []; for (let row = 0; row < rows.length; row++) { const frag = rows[row], cells = []; for (let col = added[row] || 0, i = 0; col < newWidth; i++) { let cell = frag.child(i % frag.childCount); if (col + cell.attrs.colspan > newWidth) cell = cell.type.createChecked(removeColSpan(cell.attrs, cell.attrs.colspan, col + cell.attrs.colspan - newWidth), cell.content); cells.push(cell); col += cell.attrs.colspan; for (let j = 1; j < cell.attrs.rowspan; j++) added[row + j] = (added[row + j] || 0) + cell.attrs.colspan; } newRows.push(Fragment.from(cells)); } rows = newRows; width = newWidth; } if (height != newHeight) { const newRows = []; for (let row = 0, i = 0; row < newHeight; row++, i++) { const cells = [], source = rows[i % height]; for (let j = 0; j < source.childCount; j++) { let cell = source.child(j); if (row + cell.attrs.rowspan > newHeight) cell = cell.type.create({ ...cell.attrs, rowspan: Math.max(1, newHeight - cell.attrs.rowspan) }, cell.content); cells.push(cell); } newRows.push(Fragment.from(cells)); } rows = newRows; height = newHeight; } return { width, height, rows }; } function growTable(tr2, map2, table, start, width, height, mapFrom) { const schema = tr2.doc.type.schema; const types = tableNodeTypes(schema); let empty2; let emptyHead; if (width > map2.width) for (let row = 0, rowEnd = 0; row < map2.height; row++) { const rowNode = table.child(row); rowEnd += rowNode.nodeSize; const cells = []; let add; if (rowNode.lastChild == null || rowNode.lastChild.type == types.cell) add = empty2 || (empty2 = types.cell.createAndFill()); else add = emptyHead || (emptyHead = types.header_cell.createAndFill()); for (let i = map2.width; i < width; i++) cells.push(add); tr2.insert(tr2.mapping.slice(mapFrom).map(rowEnd - 1 + start), cells); } if (height > map2.height) { const cells = []; for (let i = 0, start$1 = (map2.height - 1) * map2.width; i < Math.max(map2.width, width); i++) { const header = i >= map2.width ? false : table.nodeAt(map2.map[start$1 + i]).type == types.header_cell; cells.push(header ? emptyHead || (emptyHead = types.header_cell.createAndFill()) : empty2 || (empty2 = types.cell.createAndFill())); } const emptyRow = types.row.create(null, Fragment.from(cells)), rows = []; for (let i = map2.height; i < height; i++) rows.push(emptyRow); tr2.insert(tr2.mapping.slice(mapFrom).map(start + table.nodeSize - 2), rows); } return !!(empty2 || emptyHead); } function isolateHorizontal(tr2, map2, table, start, left, right, top, mapFrom) { if (top == 0 || top == map2.height) return false; let found2 = false; for (let col = left; col < right; col++) { const index = top * map2.width + col, pos = map2.map[index]; if (map2.map[index - map2.width] == pos) { found2 = true; const cell = table.nodeAt(pos); const { top: cellTop, left: cellLeft } = map2.findCell(pos); tr2.setNodeMarkup(tr2.mapping.slice(mapFrom).map(pos + start), null, { ...cell.attrs, rowspan: top - cellTop }); tr2.insert(tr2.mapping.slice(mapFrom).map(map2.positionAt(top, cellLeft, table)), cell.type.createAndFill({ ...cell.attrs, rowspan: cellTop + cell.attrs.rowspan - top })); col += cell.attrs.colspan - 1; } } return found2; } function isolateVertical(tr2, map2, table, start, top, bottom, left, mapFrom) { if (left == 0 || left == map2.width) return false; let found2 = false; for (let row = top; row < bottom; row++) { const index = row * map2.width + left, pos = map2.map[index]; if (map2.map[index - 1] == pos) { found2 = true; const cell = table.nodeAt(pos); const cellLeft = map2.colCount(pos); const updatePos = tr2.mapping.slice(mapFrom).map(pos + start); tr2.setNodeMarkup(updatePos, null, removeColSpan(cell.attrs, left - cellLeft, cell.attrs.colspan - (left - cellLeft))); tr2.insert(updatePos + cell.nodeSize, cell.type.createAndFill(removeColSpan(cell.attrs, 0, left - cellLeft))); row += cell.attrs.rowspan - 1; } } return found2; } function insertCells(state, dispatch, tableStart, rect, cells) { let table = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc; if (!table) throw new Error("No table found"); let map2 = TableMap.get(table); const { top, left } = rect; const right = left + cells.width, bottom = top + cells.height; const tr2 = state.tr; let mapFrom = 0; function recomp() { table = tableStart ? tr2.doc.nodeAt(tableStart - 1) : tr2.doc; if (!table) throw new Error("No table found"); map2 = TableMap.get(table); mapFrom = tr2.mapping.maps.length; } if (growTable(tr2, map2, table, tableStart, right, bottom, mapFrom)) recomp(); if (isolateHorizontal(tr2, map2, table, tableStart, left, right, top, mapFrom)) recomp(); if (isolateHorizontal(tr2, map2, table, tableStart, left, right, bottom, mapFrom)) recomp(); if (isolateVertical(tr2, map2, table, tableStart, top, bottom, left, mapFrom)) recomp(); if (isolateVertical(tr2, map2, table, tableStart, top, bottom, right, mapFrom)) recomp(); for (let row = top; row < bottom; row++) { const from2 = map2.positionAt(row, left, table), to = map2.positionAt(row, right, table); tr2.replace(tr2.mapping.slice(mapFrom).map(from2 + tableStart), tr2.mapping.slice(mapFrom).map(to + tableStart), new Slice(cells.rows[row - top], 0, 0)); } recomp(); tr2.setSelection(new CellSelection(tr2.doc.resolve(tableStart + map2.positionAt(top, left, table)), tr2.doc.resolve(tableStart + map2.positionAt(bottom - 1, right - 1, table)))); dispatch(tr2); } const handleKeyDown = keydownHandler({ ArrowLeft: arrow$2("horiz", -1), ArrowRight: arrow$2("horiz", 1), ArrowUp: arrow$2("vert", -1), ArrowDown: arrow$2("vert", 1), "Shift-ArrowLeft": shiftArrow("horiz", -1), "Shift-ArrowRight": shiftArrow("horiz", 1), "Shift-ArrowUp": shiftArrow("vert", -1), "Shift-ArrowDown": shiftArrow("vert", 1), Backspace: deleteCellSelection, "Mod-Backspace": deleteCellSelection, Delete: deleteCellSelection, "Mod-Delete": deleteCellSelection }); function maybeSetSelection(state, dispatch, selection) { if (selection.eq(state.selection)) return false; if (dispatch) dispatch(state.tr.setSelection(selection).scrollIntoView()); return true; } function arrow$2(axis, dir) { return (state, dispatch, view) => { if (!view) return false; const sel = state.selection; if (sel instanceof CellSelection) return maybeSetSelection(state, dispatch, Selection.near(sel.$headCell, dir)); if (axis != "horiz" && !sel.empty) return false; const end = atEndOfCell(view, axis, dir); if (end == null) return false; if (axis == "horiz") return maybeSetSelection(state, dispatch, Selection.near(state.doc.resolve(sel.head + dir), dir)); else { const $cell = state.doc.resolve(end); const $next = nextCell($cell, axis, dir); let newSel; if ($next) newSel = Selection.near($next, 1); else if (dir < 0) newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1); else newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1); return maybeSetSelection(state, dispatch, newSel); } }; } function shiftArrow(axis, dir) { return (state, dispatch, view) => { if (!view) return false; const sel = state.selection; let cellSel; if (sel instanceof CellSelection) cellSel = sel; else { const end = atEndOfCell(view, axis, dir); if (end == null) return false; cellSel = new CellSelection(state.doc.resolve(end)); } const $head = nextCell(cellSel.$headCell, axis, dir); if (!$head) return false; return maybeSetSelection(state, dispatch, new CellSelection(cellSel.$anchorCell, $head)); }; } function handleTripleClick(view, pos) { const doc2 = view.state.doc, $cell = cellAround(doc2.resolve(pos)); if (!$cell) return false; view.dispatch(view.state.tr.setSelection(new CellSelection($cell))); return true; } function handlePaste(view, _, slice2) { if (!isInTable(view.state)) return false; let cells = pastedCells(slice2); const sel = view.state.selection; if (sel instanceof CellSelection) { if (!cells) cells = { width: 1, height: 1, rows: [Fragment.from(fitSlice(tableNodeTypes(view.state.schema).cell, slice2))] }; const table = sel.$anchorCell.node(-1); const start = sel.$anchorCell.start(-1); const rect = TableMap.get(table).rectBetween(sel.$anchorCell.pos - start, sel.$headCell.pos - start); cells = clipCells(cells, rect.right - rect.left, rect.bottom - rect.top); insertCells(view.state, view.dispatch, start, rect, cells); return true; } else if (cells) { const $cell = selectionCell(view.state); const start = $cell.start(-1); insertCells(view.state, view.dispatch, start, TableMap.get($cell.node(-1)).findCell($cell.pos - start), cells); return true; } else return false; } function handleMouseDown$1(view, startEvent) { var _cellUnderMouse; if (startEvent.button != 0) return; if (startEvent.ctrlKey || startEvent.metaKey) return; const startDOMCell = domInCell(view, startEvent.target); let $anchor; if (startEvent.shiftKey && view.state.selection instanceof CellSelection) { setCellSelection(view.state.selection.$anchorCell, startEvent); startEvent.preventDefault(); } else if (startEvent.shiftKey && startDOMCell && ($anchor = cellAround(view.state.selection.$anchor)) != null && ((_cellUnderMouse = cellUnderMouse(view, startEvent)) === null || _cellUnderMouse === void 0 ? void 0 : _cellUnderMouse.pos) != $anchor.pos) { setCellSelection($anchor, startEvent); startEvent.preventDefault(); } else if (!startDOMCell) return; function setCellSelection($anchor$1, event) { let $head = cellUnderMouse(view, event); const starting = tableEditingKey.getState(view.state) == null; if (!$head || !inSameTable($anchor$1, $head)) if (starting) $head = $anchor$1; else return; const selection = new CellSelection($anchor$1, $head); if (starting || !view.state.selection.eq(selection)) { const tr2 = view.state.tr.setSelection(selection); if (starting) tr2.setMeta(tableEditingKey, $anchor$1.pos); view.dispatch(tr2); } } function stop() { view.root.removeEventListener("mouseup", stop); view.root.removeEventListener("dragstart", stop); view.root.removeEventListener("mousemove", move); if (tableEditingKey.getState(view.state) != null) view.dispatch(view.state.tr.setMeta(tableEditingKey, -1)); } function move(_event) { const event = _event; const anchor = tableEditingKey.getState(view.state); let $anchor$1; if (anchor != null) $anchor$1 = view.state.doc.resolve(anchor); else if (domInCell(view, event.target) != startDOMCell) { $anchor$1 = cellUnderMouse(view, startEvent); if (!$anchor$1) return stop(); } if ($anchor$1) setCellSelection($anchor$1, event); } view.root.addEventListener("mouseup", stop); view.root.addEventListener("dragstart", stop); view.root.addEventListener("mousemove", move); } function atEndOfCell(view, axis, dir) { if (!(view.state.selection instanceof TextSelection)) return null; const { $head } = view.state.selection; for (let d = $head.depth - 1; d >= 0; d--) { const parent = $head.node(d); if ((dir < 0 ? $head.index(d) : $head.indexAfter(d)) != (dir < 0 ? 0 : parent.childCount)) return null; if (parent.type.spec.tableRole == "cell" || parent.type.spec.tableRole == "header_cell") { const cellPos = $head.before(d); const dirStr = axis == "vert" ? dir > 0 ? "down" : "up" : dir > 0 ? "right" : "left"; return view.endOfTextblock(dirStr) ? cellPos : null; } } return null; } function domInCell(view, dom) { for (; dom && dom != view.dom; dom = dom.parentNode) if (dom.nodeName == "TD" || dom.nodeName == "TH") return dom; return null; } function cellUnderMouse(view, event) { const mousePos = view.posAtCoords({ left: event.clientX, top: event.clientY }); if (!mousePos) return null; let { inside, pos } = mousePos; return inside >= 0 && cellAround(view.state.doc.resolve(inside)) || cellAround(view.state.doc.resolve(pos)); } var TableView$1 = class TableView { constructor(node, defaultCellMinWidth) { this.node = node; this.defaultCellMinWidth = defaultCellMinWidth; this.dom = document.createElement("div"); this.dom.className = "tableWrapper"; this.table = this.dom.appendChild(document.createElement("table")); this.table.style.setProperty("--default-cell-min-width", `${defaultCellMinWidth}px`); this.colgroup = this.table.appendChild(document.createElement("colgroup")); updateColumnsOnResize(node, this.colgroup, this.table, defaultCellMinWidth); this.contentDOM = this.table.appendChild(document.createElement("tbody")); } update(node) { if (node.type != this.node.type) return false; this.node = node; updateColumnsOnResize(node, this.colgroup, this.table, this.defaultCellMinWidth); return true; } ignoreMutation(record) { return record.type == "attributes" && (record.target == this.table || this.colgroup.contains(record.target)); } }; function updateColumnsOnResize(node, colgroup, table, defaultCellMinWidth, overrideCol, overrideValue) { let totalWidth = 0; let fixedWidth = true; let nextDOM = colgroup.firstChild; const row = node.firstChild; if (!row) return; for (let i = 0, col = 0; i < row.childCount; i++) { const { colspan, colwidth } = row.child(i).attrs; for (let j = 0; j < colspan; j++, col++) { const hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j]; const cssWidth = hasWidth ? hasWidth + "px" : ""; totalWidth += hasWidth || defaultCellMinWidth; if (!hasWidth) fixedWidth = false; if (!nextDOM) { const col$1 = document.createElement("col"); col$1.style.width = cssWidth; colgroup.appendChild(col$1); } else { if (nextDOM.style.width != cssWidth) nextDOM.style.width = cssWidth; nextDOM = nextDOM.nextSibling; } } } while (nextDOM) { var _nextDOM$parentNode; const after = nextDOM.nextSibling; (_nextDOM$parentNode = nextDOM.parentNode) === null || _nextDOM$parentNode === void 0 || _nextDOM$parentNode.removeChild(nextDOM); nextDOM = after; } if (fixedWidth) { table.style.width = totalWidth + "px"; table.style.minWidth = ""; } else { table.style.width = ""; table.style.minWidth = totalWidth + "px"; } } const columnResizingPluginKey = new PluginKey("tableColumnResizing"); function columnResizing({ handleWidth = 5, cellMinWidth = 25, defaultCellMinWidth = 100, View = TableView$1, lastColumnResizable = true } = {}) { const plugin = new Plugin({ key: columnResizingPluginKey, state: { init(_, state) { var _plugin$spec; const nodeViews = (_plugin$spec = plugin.spec) === null || _plugin$spec === void 0 || (_plugin$spec = _plugin$spec.props) === null || _plugin$spec === void 0 ? void 0 : _plugin$spec.nodeViews; const tableName = tableNodeTypes(state.schema).table.name; if (View && nodeViews) nodeViews[tableName] = (node, view) => { return new View(node, defaultCellMinWidth, view); }; return new ResizeState(-1, false); }, apply(tr2, prev) { return prev.apply(tr2); } }, props: { attributes: (state) => { const pluginState = columnResizingPluginKey.getState(state); return pluginState && pluginState.activeHandle > -1 ? { class: "resize-cursor" } : {}; }, handleDOMEvents: { mousemove: (view, event) => { handleMouseMove(view, event, handleWidth, lastColumnResizable); }, mouseleave: (view) => { handleMouseLeave(view); }, mousedown: (view, event) => { handleMouseDown(view, event, cellMinWidth, defaultCellMinWidth); } }, decorations: (state) => { const pluginState = columnResizingPluginKey.getState(state); if (pluginState && pluginState.activeHandle > -1) return handleDecorations(state, pluginState.activeHandle); }, nodeViews: {} } }); return plugin; } var ResizeState = class ResizeState2 { constructor(activeHandle, dragging) { this.activeHandle = activeHandle; this.dragging = dragging; } apply(tr2) { const state = this; const action = tr2.getMeta(columnResizingPluginKey); if (action && action.setHandle != null) return new ResizeState2(action.setHandle, false); if (action && action.setDragging !== void 0) return new ResizeState2(state.activeHandle, action.setDragging); if (state.activeHandle > -1 && tr2.docChanged) { let handle = tr2.mapping.map(state.activeHandle, -1); if (!pointsAtCell(tr2.doc.resolve(handle))) handle = -1; return new ResizeState2(handle, state.dragging); } return state; } }; function handleMouseMove(view, event, handleWidth, lastColumnResizable) { if (!view.editable) return; const pluginState = columnResizingPluginKey.getState(view.state); if (!pluginState) return; if (!pluginState.dragging) { const target = domCellAround(event.target); let cell = -1; if (target) { const { left, right } = target.getBoundingClientRect(); if (event.clientX - left <= handleWidth) cell = edgeCell(view, event, "left", handleWidth); else if (right - event.clientX <= handleWidth) cell = edgeCell(view, event, "right", handleWidth); } if (cell != pluginState.activeHandle) { if (!lastColumnResizable && cell !== -1) { const $cell = view.state.doc.resolve(cell); const table = $cell.node(-1); const map2 = TableMap.get(table); const tableStart = $cell.start(-1); if (map2.colCount($cell.pos - tableStart) + $cell.nodeAfter.attrs.colspan - 1 == map2.width - 1) return; } updateHandle(view, cell); } } } function handleMouseLeave(view) { if (!view.editable) return; const pluginState = columnResizingPluginKey.getState(view.state); if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging) updateHandle(view, -1); } function handleMouseDown(view, event, cellMinWidth, defaultCellMinWidth) { var _view$dom$ownerDocume; if (!view.editable) return false; const win = (_view$dom$ownerDocume = view.dom.ownerDocument.defaultView) !== null && _view$dom$ownerDocume !== void 0 ? _view$dom$ownerDocume : window; const pluginState = columnResizingPluginKey.getState(view.state); if (!pluginState || pluginState.activeHandle == -1 || pluginState.dragging) return false; const cell = view.state.doc.nodeAt(pluginState.activeHandle); const width = currentColWidth(view, pluginState.activeHandle, cell.attrs); view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: { startX: event.clientX, startWidth: width } })); function finish(event$1) { win.removeEventListener("mouseup", finish); win.removeEventListener("mousemove", move); const pluginState$1 = columnResizingPluginKey.getState(view.state); if (pluginState$1 === null || pluginState$1 === void 0 ? void 0 : pluginState$1.dragging) { updateColumnWidth(view, pluginState$1.activeHandle, draggedWidth(pluginState$1.dragging, event$1, cellMinWidth)); view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setDragging: null })); } } function move(event$1) { if (!event$1.which) return finish(event$1); const pluginState$1 = columnResizingPluginKey.getState(view.state); if (!pluginState$1) return; if (pluginState$1.dragging) { const dragged = draggedWidth(pluginState$1.dragging, event$1, cellMinWidth); displayColumnWidth(view, pluginState$1.activeHandle, dragged, defaultCellMinWidth); } } displayColumnWidth(view, pluginState.activeHandle, width, defaultCellMinWidth); win.addEventListener("mouseup", finish); win.addEventListener("mousemove", move); event.preventDefault(); return true; } function currentColWidth(view, cellPos, { colspan, colwidth }) { const width = colwidth && colwidth[colwidth.length - 1]; if (width) return width; const dom = view.domAtPos(cellPos); let domWidth = dom.node.childNodes[dom.offset].offsetWidth, parts = colspan; if (colwidth) { for (let i = 0; i < colspan; i++) if (colwidth[i]) { domWidth -= colwidth[i]; parts--; } } return domWidth / parts; } function domCellAround(target) { while (target && target.nodeName != "TD" && target.nodeName != "TH") target = target.classList && target.classList.contains("ProseMirror") ? null : target.parentNode; return target; } function edgeCell(view, event, side, handleWidth) { const offset2 = side == "right" ? -handleWidth : handleWidth; const found2 = view.posAtCoords({ left: event.clientX + offset2, top: event.clientY }); if (!found2) return -1; const { pos } = found2; const $cell = cellAround(view.state.doc.resolve(pos)); if (!$cell) return -1; if (side == "right") return $cell.pos; const map2 = TableMap.get($cell.node(-1)), start = $cell.start(-1); const index = map2.map.indexOf($cell.pos - start); return index % map2.width == 0 ? -1 : start + map2.map[index - 1]; } function draggedWidth(dragging, event, resizeMinWidth) { const offset2 = event.clientX - dragging.startX; return Math.max(resizeMinWidth, dragging.startWidth + offset2); } function updateHandle(view, value) { view.dispatch(view.state.tr.setMeta(columnResizingPluginKey, { setHandle: value })); } function updateColumnWidth(view, cell, width) { const $cell = view.state.doc.resolve(cell); const table = $cell.node(-1), map2 = TableMap.get(table), start = $cell.start(-1); const col = map2.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1; const tr2 = view.state.tr; for (let row = 0; row < map2.height; row++) { const mapIndex = row * map2.width + col; if (row && map2.map[mapIndex] == map2.map[mapIndex - map2.width]) continue; const pos = map2.map[mapIndex]; const attrs = table.nodeAt(pos).attrs; const index = attrs.colspan == 1 ? 0 : col - map2.colCount(pos); if (attrs.colwidth && attrs.colwidth[index] == width) continue; const colwidth = attrs.colwidth ? attrs.colwidth.slice() : zeroes(attrs.colspan); colwidth[index] = width; tr2.setNodeMarkup(start + pos, null, { ...attrs, colwidth }); } if (tr2.docChanged) view.dispatch(tr2); } function displayColumnWidth(view, cell, width, defaultCellMinWidth) { const $cell = view.state.doc.resolve(cell); const table = $cell.node(-1), start = $cell.start(-1); const col = TableMap.get(table).colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1; let dom = view.domAtPos($cell.start(-1)).node; while (dom && dom.nodeName != "TABLE") dom = dom.parentNode; if (!dom) return; updateColumnsOnResize(table, dom.firstChild, dom, defaultCellMinWidth, col, width); } function zeroes(n) { return Array(n).fill(0); } function handleDecorations(state, cell) { const decorations = []; const $cell = state.doc.resolve(cell); const table = $cell.node(-1); if (!table) return DecorationSet.empty; const map2 = TableMap.get(table); const start = $cell.start(-1); const col = map2.colCount($cell.pos - start) + $cell.nodeAfter.attrs.colspan - 1; for (let row = 0; row < map2.height; row++) { const index = col + row * map2.width; if ((col == map2.width - 1 || map2.map[index] != map2.map[index + 1]) && (row == 0 || map2.map[index] != map2.map[index - map2.width])) { var _columnResizingPlugin; const cellPos = map2.map[index]; const pos = start + cellPos + table.nodeAt(cellPos).nodeSize - 1; const dom = document.createElement("div"); dom.className = "column-resize-handle"; if ((_columnResizingPlugin = columnResizingPluginKey.getState(state)) === null || _columnResizingPlugin === void 0 ? void 0 : _columnResizingPlugin.dragging) decorations.push(Decoration.node(start + cellPos, start + cellPos + table.nodeAt(cellPos).nodeSize, { class: "column-resize-dragging" })); decorations.push(Decoration.widget(pos, dom)); } } return DecorationSet.create(state.doc, decorations); } function tableEditing({ allowTableNodeSelection = false } = {}) { return new Plugin({ key: tableEditingKey, state: { init() { return null; }, apply(tr2, cur) { const set = tr2.getMeta(tableEditingKey); if (set != null) return set == -1 ? null : set; if (cur == null || !tr2.docChanged) return cur; const { deleted, pos } = tr2.mapping.mapResult(cur); return deleted ? null : pos; } }, props: { decorations: drawCellSelection, handleDOMEvents: { mousedown: handleMouseDown$1 }, createSelectionBetween(view) { return tableEditingKey.getState(view.state) != null ? view.state.selection : null; }, handleTripleClick, handleKeyDown, handlePaste }, appendTransaction(_, oldState, state) { return normalizeSelection(state, fixTables(state, oldState), allowTableNodeSelection); } }); } function normalizeTableCellAlign(value) { if (value === "left" || value === "right" || value === "center") { return value; } return null; } function parseAlign(element) { const styleAlign = (element.style.textAlign || "").trim().toLowerCase(); const attrAlign = (element.getAttribute("align") || "").trim().toLowerCase(); const align = styleAlign || attrAlign; return normalizeTableCellAlign(align); } function normalizeTableCellAlignFromAttributes(attributes) { return normalizeTableCellAlign(attributes == null ? void 0 : attributes.align); } function createAlignAttribute() { return { default: null, parseHTML: (element) => parseAlign(element), renderHTML: (attributes) => { if (!attributes.align) { return {}; } return { style: `text-align: ${attributes.align}` }; } }; } var TableCell = Node3.create({ name: "tableCell", addOptions() { return { HTMLAttributes: {} }; }, content: "block+", addAttributes() { return { colspan: { default: 1 }, rowspan: { default: 1 }, colwidth: { default: null, parseHTML: (element) => { var _a, _b; const colwidth = element.getAttribute("colwidth"); const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null; if (!value) { const cols = (_a = element.closest("table")) == null ? void 0 : _a.querySelectorAll("colgroup > col"); const cellIndex = Array.from(((_b = element.parentElement) == null ? void 0 : _b.children) || []).indexOf(element); if (cellIndex && cellIndex > -1 && cols && cols[cellIndex]) { const colWidth = cols[cellIndex].getAttribute("width"); return colWidth ? [parseInt(colWidth, 10)] : null; } } return value; } }, align: createAlignAttribute() }; }, tableRole: "cell", isolating: true, parseHTML() { return [{ tag: "td" }]; }, renderHTML({ HTMLAttributes }) { return ["td", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; } }); var TableHeader = Node3.create({ name: "tableHeader", addOptions() { return { HTMLAttributes: {} }; }, content: "block+", addAttributes() { return { colspan: { default: 1 }, rowspan: { default: 1 }, colwidth: { default: null, parseHTML: (element) => { const colwidth = element.getAttribute("colwidth"); const value = colwidth ? colwidth.split(",").map((width) => parseInt(width, 10)) : null; return value; } }, align: createAlignAttribute() }; }, tableRole: "header_cell", isolating: true, parseHTML() { return [{ tag: "th" }]; }, renderHTML({ HTMLAttributes }) { return ["th", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; } }); var TableRow = Node3.create({ name: "tableRow", addOptions() { return { HTMLAttributes: {} }; }, content: "(tableCell | tableHeader)*", tableRole: "row", parseHTML() { return [{ tag: "tr" }]; }, renderHTML({ HTMLAttributes }) { return ["tr", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; } }); function getColStyleDeclaration(minWidth, width) { if (width) { return ["width", `${Math.max(width, minWidth)}px`]; } return ["min-width", `${minWidth}px`]; } function updateColumns(node, colgroup, table, cellMinWidth, overrideCol, overrideValue) { var _a; let totalWidth = 0; let fixedWidth = true; let nextDOM = colgroup.firstChild; const row = node.firstChild; if (row !== null) { for (let i = 0, col = 0; i < row.childCount; i += 1) { const { colspan, colwidth } = row.child(i).attrs; for (let j = 0; j < colspan; j += 1, col += 1) { const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]; const cssWidth = hasWidth ? `${hasWidth}px` : ""; totalWidth += hasWidth || cellMinWidth; if (!hasWidth) { fixedWidth = false; } if (!nextDOM) { const colElement = document.createElement("col"); const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth); colElement.style.setProperty(propertyKey, propertyValue); colgroup.appendChild(colElement); } else { if (nextDOM.style.width !== cssWidth) { const [propertyKey, propertyValue] = getColStyleDeclaration(cellMinWidth, hasWidth); nextDOM.style.setProperty(propertyKey, propertyValue); } nextDOM = nextDOM.nextSibling; } } } } while (nextDOM) { const after = nextDOM.nextSibling; (_a = nextDOM.parentNode) == null ? void 0 : _a.removeChild(nextDOM); nextDOM = after; } const hasUserWidth = node.attrs.style && typeof node.attrs.style === "string" && /\bwidth\s*:/i.test(node.attrs.style); if (fixedWidth && !hasUserWidth) { table.style.width = `${totalWidth}px`; table.style.minWidth = ""; } else { table.style.width = ""; table.style.minWidth = `${totalWidth}px`; } } var TableView2 = class { constructor(node, cellMinWidth) { this.node = node; this.cellMinWidth = cellMinWidth; this.dom = document.createElement("div"); this.dom.className = "tableWrapper"; this.table = this.dom.appendChild(document.createElement("table")); if (node.attrs.style) { this.table.style.cssText = node.attrs.style; } this.colgroup = this.table.appendChild(document.createElement("colgroup")); updateColumns(node, this.colgroup, this.table, cellMinWidth); this.contentDOM = this.table.appendChild(document.createElement("tbody")); } update(node) { if (node.type !== this.node.type) { return false; } this.node = node; updateColumns(node, this.colgroup, this.table, this.cellMinWidth); return true; } ignoreMutation(mutation) { const target = mutation.target; const isInsideWrapper = this.dom.contains(target); const isInsideContent = this.contentDOM.contains(target); if (isInsideWrapper && !isInsideContent) { if (mutation.type === "attributes" || mutation.type === "childList" || mutation.type === "characterData") { return true; } } return false; } }; function createColGroup(node, cellMinWidth, overrideCol, overrideValue) { let totalWidth = 0; let fixedWidth = true; const cols = []; const row = node.firstChild; if (!row) { return {}; } for (let i = 0, col = 0; i < row.childCount; i += 1) { const { colspan, colwidth } = row.child(i).attrs; for (let j = 0; j < colspan; j += 1, col += 1) { const hasWidth = overrideCol === col ? overrideValue : colwidth && colwidth[j]; totalWidth += hasWidth || cellMinWidth; if (!hasWidth) { fixedWidth = false; } const [property, value] = getColStyleDeclaration(cellMinWidth, hasWidth); cols.push(["col", { style: `${property}: ${value}` }]); } } const tableWidth = fixedWidth ? `${totalWidth}px` : ""; const tableMinWidth = fixedWidth ? "" : `${totalWidth}px`; const colgroup = ["colgroup", {}, ...cols]; return { colgroup, tableWidth, tableMinWidth }; } function createCell(cellType, cellContent) { return cellType.createAndFill(); } function getTableNodeTypes(schema) { if (schema.cached.tableNodeTypes) { return schema.cached.tableNodeTypes; } const roles = {}; Object.keys(schema.nodes).forEach((type) => { const nodeType = schema.nodes[type]; if (nodeType.spec.tableRole) { roles[nodeType.spec.tableRole] = nodeType; } }); schema.cached.tableNodeTypes = roles; return roles; } function createTable(schema, rowsCount, colsCount, withHeaderRow, cellContent) { const types = getTableNodeTypes(schema); const headerCells = []; const cells = []; for (let index = 0; index < colsCount; index += 1) { const cell = createCell(types.cell); if (cell) { cells.push(cell); } if (withHeaderRow) { const headerCell = createCell(types.header_cell); if (headerCell) { headerCells.push(headerCell); } } } const rows = []; for (let index = 0; index < rowsCount; index += 1) { rows.push(types.row.createChecked(null, withHeaderRow && index === 0 ? headerCells : cells)); } return types.table.createChecked(null, rows); } function isCellSelection(value) { return value instanceof CellSelection; } var deleteTableWhenAllCellsSelected = ({ editor }) => { const { selection } = editor.state; if (!isCellSelection(selection)) { return false; } let cellCount = 0; const table = findParentNodeClosestToPos(selection.ranges[0].$from, (node) => { return node.type.name === "table"; }); table == null ? void 0 : table.node.descendants((node) => { if (node.type.name === "table") { return false; } if (["tableCell", "tableHeader"].includes(node.type.name)) { cellCount += 1; } }); const allCellsSelected = cellCount === selection.ranges.length; if (!allCellsSelected) { return false; } editor.commands.deleteTable(); return true; }; var DEFAULT_CELL_LINE_SEPARATOR = ""; function collapseWhitespace(s) { return (s || "").replace(/\s+/g, " ").trim(); } function renderTableToMarkdown(node, h2, options = {}) { var _a; const cellSep = (_a = options.cellLineSeparator) != null ? _a : DEFAULT_CELL_LINE_SEPARATOR; if (!node || !node.content || node.content.length === 0) { return ""; } const rows = []; node.content.forEach((rowNode) => { const cells = []; if (rowNode.content) { rowNode.content.forEach((cellNode) => { let raw = ""; if (cellNode.content && Array.isArray(cellNode.content) && cellNode.content.length > 1) { const parts = cellNode.content.map((child) => h2.renderChildren(child)); raw = parts.join(cellSep); } else { raw = cellNode.content ? h2.renderChildren(cellNode.content) : ""; } const text = collapseWhitespace(raw); const isHeader = cellNode.type === "tableHeader"; const align = normalizeTableCellAlignFromAttributes(cellNode.attrs); cells.push({ text, isHeader, align }); }); } rows.push(cells); }); const columnCount = rows.reduce((max2, r) => Math.max(max2, r.length), 0); if (columnCount === 0) { return ""; } const colWidths = new Array(columnCount).fill(0); rows.forEach((r) => { var _a2; for (let i = 0; i < columnCount; i += 1) { const cell = ((_a2 = r[i]) == null ? void 0 : _a2.text) || ""; const len = cell.length; if (len > colWidths[i]) { colWidths[i] = len; } if (colWidths[i] < 3) { colWidths[i] = 3; } } }); const pad = (s, width) => s + " ".repeat(Math.max(0, width - s.length)); const headerRow = rows[0]; const hasHeader = headerRow.some((c) => c.isHeader); const colAlignments = new Array(columnCount).fill(null); rows.forEach((r) => { var _a2; for (let i = 0; i < columnCount; i += 1) { if (!colAlignments[i] && ((_a2 = r[i]) == null ? void 0 : _a2.align)) { colAlignments[i] = r[i].align; } } }); let out = "\n"; const headerTexts = new Array(columnCount).fill(0).map((_, i) => hasHeader ? headerRow[i] && headerRow[i].text || "" : ""); out += `| ${headerTexts.map((t, i) => pad(t, colWidths[i])).join(" | ")} | `; out += `| ${colWidths.map((w, index) => { const dashCount = Math.max(3, w); const alignment = colAlignments[index]; if (alignment === "left") { return `:${"-".repeat(dashCount)}`; } if (alignment === "right") { return `${"-".repeat(dashCount)}:`; } if (alignment === "center") { return `:${"-".repeat(dashCount)}:`; } return "-".repeat(dashCount); }).join(" | ")} | `; const body = hasHeader ? rows.slice(1) : rows; body.forEach((r) => { out += `| ${new Array(columnCount).fill(0).map((_, i) => pad(r[i] && r[i].text || "", colWidths[i])).join(" | ")} | `; }); return out; } var markdown_default = renderTableToMarkdown; var Table = Node3.create({ name: "table", // @ts-ignore addOptions() { return { HTMLAttributes: {}, resizable: false, renderWrapper: false, handleWidth: 5, cellMinWidth: 25, // TODO: fix View: TableView2, lastColumnResizable: true, allowTableNodeSelection: false }; }, content: "tableRow+", tableRole: "table", isolating: true, group: "block", parseHTML() { return [{ tag: "table" }]; }, renderHTML({ node, HTMLAttributes }) { const { colgroup, tableWidth, tableMinWidth } = createColGroup(node, this.options.cellMinWidth); const userStyles = HTMLAttributes.style; function getTableStyle() { if (userStyles) { return userStyles; } return tableWidth ? `width: ${tableWidth}` : `min-width: ${tableMinWidth}`; } const table = [ "table", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { style: getTableStyle() }), colgroup, ["tbody", 0] ]; return this.options.renderWrapper ? ["div", { class: "tableWrapper" }, table] : table; }, parseMarkdown: (token, h2) => { const rows = []; const alignments2 = Array.isArray(token.align) ? token.align : []; if (token.header) { const headerCells = []; token.header.forEach((cell, index) => { var _a; const align = normalizeTableCellAlign((_a = alignments2[index]) != null ? _a : cell.align); const attrs = align ? { align } : {}; headerCells.push( h2.createNode("tableHeader", attrs, [{ type: "paragraph", content: h2.parseInline(cell.tokens) }]) ); }); rows.push(h2.createNode("tableRow", {}, headerCells)); } if (token.rows) { token.rows.forEach((row) => { const bodyCells = []; row.forEach((cell, index) => { var _a; const align = normalizeTableCellAlign((_a = alignments2[index]) != null ? _a : cell.align); const attrs = align ? { align } : {}; bodyCells.push(h2.createNode("tableCell", attrs, [{ type: "paragraph", content: h2.parseInline(cell.tokens) }])); }); rows.push(h2.createNode("tableRow", {}, bodyCells)); }); } return h2.createNode("table", void 0, rows); }, renderMarkdown: (node, h2) => { return markdown_default(node, h2); }, addCommands() { return { insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr: tr2, dispatch, editor }) => { const node = createTable(editor.schema, rows, cols, withHeaderRow); if (dispatch) { const offset2 = tr2.selection.from + 1; tr2.replaceSelectionWith(node).scrollIntoView().setSelection(TextSelection.near(tr2.doc.resolve(offset2))); } return true; }, addColumnBefore: () => ({ state, dispatch }) => { return addColumnBefore(state, dispatch); }, addColumnAfter: () => ({ state, dispatch }) => { return addColumnAfter(state, dispatch); }, deleteColumn: () => ({ state, dispatch }) => { return deleteColumn(state, dispatch); }, addRowBefore: () => ({ state, dispatch }) => { return addRowBefore(state, dispatch); }, addRowAfter: () => ({ state, dispatch }) => { return addRowAfter(state, dispatch); }, deleteRow: () => ({ state, dispatch }) => { return deleteRow(state, dispatch); }, deleteTable: () => ({ state, dispatch }) => { return deleteTable(state, dispatch); }, mergeCells: () => ({ state, dispatch }) => { return mergeCells(state, dispatch); }, splitCell: () => ({ state, dispatch }) => { return splitCell(state, dispatch); }, toggleHeaderColumn: () => ({ state, dispatch }) => { return toggleHeader("column")(state, dispatch); }, toggleHeaderRow: () => ({ state, dispatch }) => { return toggleHeader("row")(state, dispatch); }, toggleHeaderCell: () => ({ state, dispatch }) => { return toggleHeaderCell(state, dispatch); }, mergeOrSplit: () => ({ state, dispatch }) => { if (mergeCells(state, dispatch)) { return true; } return splitCell(state, dispatch); }, setCellAttribute: (name, value) => ({ state, dispatch }) => { return setCellAttr(name, value)(state, dispatch); }, goToNextCell: () => ({ state, dispatch }) => { return goToNextCell(1)(state, dispatch); }, goToPreviousCell: () => ({ state, dispatch }) => { return goToNextCell(-1)(state, dispatch); }, fixTables: () => ({ state, dispatch }) => { if (dispatch) { fixTables(state); } return true; }, setCellSelection: (position) => ({ tr: tr2, dispatch }) => { if (dispatch) { const selection = CellSelection.create(tr2.doc, position.anchorCell, position.headCell); tr2.setSelection(selection); } return true; } }; }, addKeyboardShortcuts() { return { Tab: () => { if (this.editor.commands.goToNextCell()) { return true; } if (!this.editor.can().addRowAfter()) { return false; } return this.editor.chain().addRowAfter().goToNextCell().run(); }, "Shift-Tab": () => this.editor.commands.goToPreviousCell(), Backspace: deleteTableWhenAllCellsSelected, "Mod-Backspace": deleteTableWhenAllCellsSelected, Delete: deleteTableWhenAllCellsSelected, "Mod-Delete": deleteTableWhenAllCellsSelected }; }, addProseMirrorPlugins() { const isResizable = this.options.resizable && this.editor.isEditable; return [ ...isResizable ? [ columnResizing({ handleWidth: this.options.handleWidth, cellMinWidth: this.options.cellMinWidth, defaultCellMinWidth: this.options.cellMinWidth, View: this.options.View, lastColumnResizable: this.options.lastColumnResizable }) ] : [], tableEditing({ allowTableNodeSelection: this.options.allowTableNodeSelection }) ]; }, extendNodeSchema(extension) { const context = { name: extension.name, options: extension.options, storage: extension.storage }; return { tableRole: callOrReturn(getExtensionField(extension, "tableRole", context)) }; } }); Extension.create({ name: "tableKit", addExtensions() { const extensions = []; if (this.options.table !== false) { extensions.push(Table.configure(this.options.table)); } if (this.options.tableCell !== false) { extensions.push(TableCell.configure(this.options.tableCell)); } if (this.options.tableHeader !== false) { extensions.push(TableHeader.configure(this.options.tableHeader)); } if (this.options.tableRow !== false) { extensions.push(TableRow.configure(this.options.tableRow)); } return extensions; } }); var index_default$2 = Placeholder; function findSuggestionMatch(config) { var _a; const { char, allowSpaces: allowSpacesOption, allowToIncludeChar, allowedPrefixes, startOfLine, $position } = config; const allowSpaces = allowSpacesOption && !allowToIncludeChar; const escapedChar = escapeForRegEx(char); const suffix = new RegExp(`\\s${escapedChar}$`); const prefix = startOfLine ? "^" : ""; const finalEscapedChar = allowToIncludeChar ? "" : escapedChar; const regexp = allowSpaces ? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${finalEscapedChar}|$)`, "gm") : new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${finalEscapedChar}]*`, "gm"); const text = ((_a = $position.nodeBefore) == null ? void 0 : _a.isText) && $position.nodeBefore.text; if (!text) { return null; } const textFrom = $position.pos - text.length; const match = Array.from(text.matchAll(regexp)).pop(); if (!match || match.input === void 0 || match.index === void 0) { return null; } const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index); const matchPrefixIsAllowed = new RegExp(`^[${allowedPrefixes == null ? void 0 : allowedPrefixes.join("")}\0]?$`).test(matchPrefix); if (allowedPrefixes !== null && !matchPrefixIsAllowed) { return null; } const from2 = textFrom + match.index; let to = from2 + match[0].length; if (allowSpaces && suffix.test(text.slice(to - 1, to + 1))) { match[0] += " "; to += 1; } if (from2 < $position.pos && to >= $position.pos) { return { range: { from: from2, to }, query: match[0].slice(char.length), text: match[0] }; } return null; } function hasInsertedWhitespace(transaction) { if (!transaction.docChanged) { return false; } return transaction.steps.some((step) => { const slice2 = step.slice; if (!(slice2 == null ? void 0 : slice2.content)) { return false; } const inserted = slice2.content.textBetween(0, slice2.content.size, "\n"); return /\s/.test(inserted); }); } var SuggestionPluginKey = new PluginKey("suggestion"); function Suggestion({ pluginKey = SuggestionPluginKey, editor, char = "@", allowSpaces = false, allowToIncludeChar = false, allowedPrefixes = [" "], startOfLine = false, decorationTag = "span", decorationClass = "suggestion", decorationContent = "", decorationEmptyClass = "is-empty", command: command2 = () => null, items = () => [], render = () => ({}), allow = () => true, findSuggestionMatch: findSuggestionMatch2 = findSuggestionMatch, shouldShow, shouldResetDismissed }) { let props; const renderer = render == null ? void 0 : render(); const effectiveAllowSpaces = allowSpaces && !allowToIncludeChar; const getAnchorClientRect = () => { const pos = editor.state.selection.$anchor.pos; const coords = editor.view.coordsAtPos(pos); const { top, right, bottom, left } = coords; try { return new DOMRect(left, top, right - left, bottom - top); } catch { return null; } }; const clientRectFor = (view, decorationNode) => { if (!decorationNode) { return getAnchorClientRect; } return () => { const state = pluginKey.getState(editor.state); const decorationId = state == null ? void 0 : state.decorationId; const currentDecorationNode = view.dom.querySelector(`[data-decoration-id="${decorationId}"]`); return (currentDecorationNode == null ? void 0 : currentDecorationNode.getBoundingClientRect()) || null; }; }; const shouldKeepDismissed = ({ match, dismissedRange, state, transaction }) => { if (shouldResetDismissed == null ? void 0 : shouldResetDismissed({ editor, state, range: dismissedRange, match, transaction, allowSpaces: effectiveAllowSpaces })) { return false; } if (effectiveAllowSpaces) { return match.range.from === dismissedRange.from; } return match.range.from === dismissedRange.from && !hasInsertedWhitespace(transaction); }; function dispatchExit(view, pluginKeyRef) { var _a; try { const state = pluginKey.getState(view.state); const decorationNode = (state == null ? void 0 : state.decorationId) ? view.dom.querySelector(`[data-decoration-id="${state.decorationId}"]`) : null; const exitProps = { // @ts-ignore editor is available in closure editor, range: (state == null ? void 0 : state.range) || { from: 0, to: 0 }, query: (state == null ? void 0 : state.query) || null, text: (state == null ? void 0 : state.text) || null, items: [], command: (commandProps) => { return command2({ editor, range: (state == null ? void 0 : state.range) || { from: 0, to: 0 }, props: commandProps }); }, decorationNode, clientRect: clientRectFor(view, decorationNode) }; (_a = renderer == null ? void 0 : renderer.onExit) == null ? void 0 : _a.call(renderer, exitProps); } catch { } const tr2 = view.state.tr.setMeta(pluginKeyRef, { exit: true }); view.dispatch(tr2); } const plugin = new Plugin({ key: pluginKey, view() { return { update: async (view, prevState) => { var _a, _b, _c, _d, _e, _f, _g; const prev = (_a = this.key) == null ? void 0 : _a.getState(prevState); const next = (_b = this.key) == null ? void 0 : _b.getState(view.state); const moved = prev.active && next.active && prev.range.from !== next.range.from; const started = !prev.active && next.active; const stopped = prev.active && !next.active; const changed = !started && !stopped && prev.query !== next.query; const handleStart = started || moved && changed; const handleChange = changed || moved; const handleExit = stopped || moved && changed; if (!handleStart && !handleChange && !handleExit) { return; } const state = handleExit && !handleStart ? prev : next; const decorationNode = view.dom.querySelector(`[data-decoration-id="${state.decorationId}"]`); props = { editor, range: state.range, query: state.query, text: state.text, items: [], command: (commandProps) => { return command2({ editor, range: state.range, props: commandProps }); }, decorationNode, clientRect: clientRectFor(view, decorationNode) }; if (handleStart) { (_c = renderer == null ? void 0 : renderer.onBeforeStart) == null ? void 0 : _c.call(renderer, props); } if (handleChange) { (_d = renderer == null ? void 0 : renderer.onBeforeUpdate) == null ? void 0 : _d.call(renderer, props); } if (handleChange || handleStart) { props.items = await items({ editor, query: state.query }); } if (handleExit) { (_e = renderer == null ? void 0 : renderer.onExit) == null ? void 0 : _e.call(renderer, props); } if (handleChange) { (_f = renderer == null ? void 0 : renderer.onUpdate) == null ? void 0 : _f.call(renderer, props); } if (handleStart) { (_g = renderer == null ? void 0 : renderer.onStart) == null ? void 0 : _g.call(renderer, props); } }, destroy: () => { var _a; if (!props) { return; } (_a = renderer == null ? void 0 : renderer.onExit) == null ? void 0 : _a.call(renderer, props); } }; }, state: { // Initialize the plugin's internal state. init() { const state = { active: false, range: { from: 0, to: 0 }, query: null, text: null, composing: false, dismissedRange: null }; return state; }, // Apply changes to the plugin state from a view transaction. apply(transaction, prev, _oldState, state) { const { isEditable } = editor; const { composing } = editor.view; const { selection } = transaction; const { empty: empty2, from: from2 } = selection; const next = { ...prev }; const meta = transaction.getMeta(pluginKey); if (meta && meta.exit) { next.active = false; next.decorationId = null; next.range = { from: 0, to: 0 }; next.query = null; next.text = null; next.dismissedRange = prev.active ? { ...prev.range } : prev.dismissedRange; return next; } next.composing = composing; if (transaction.docChanged && next.dismissedRange !== null) { next.dismissedRange = { from: transaction.mapping.map(next.dismissedRange.from), to: transaction.mapping.map(next.dismissedRange.to) }; } if (isEditable && (empty2 || editor.view.composing)) { if ((from2 < prev.range.from || from2 > prev.range.to) && !composing && !prev.composing) { next.active = false; } const match = findSuggestionMatch2({ char, allowSpaces, allowToIncludeChar, allowedPrefixes, startOfLine, $position: selection.$from }); const decorationId = `id_${Math.floor(Math.random() * 4294967295)}`; if (match && allow({ editor, state, range: match.range, isActive: prev.active }) && (!shouldShow || shouldShow({ editor, range: match.range, query: match.query, text: match.text, transaction }))) { if (next.dismissedRange !== null && !shouldKeepDismissed({ match, dismissedRange: next.dismissedRange, state, transaction })) { next.dismissedRange = null; } if (next.dismissedRange === null) { next.active = true; next.decorationId = prev.decorationId ? prev.decorationId : decorationId; next.range = match.range; next.query = match.query; next.text = match.text; } else { next.active = false; } } else { if (!match) { next.dismissedRange = null; } next.active = false; } } else { next.active = false; } if (!next.active) { next.decorationId = null; next.range = { from: 0, to: 0 }; next.query = null; next.text = null; } return next; } }, props: { // Call the keydown hook if suggestion is active. handleKeyDown(view, event) { var _a, _b; const { active, range } = plugin.getState(view.state); if (!active) { return false; } if (event.key === "Escape" || event.key === "Esc") { const state = plugin.getState(view.state); (_a = renderer == null ? void 0 : renderer.onKeyDown) == null ? void 0 : _a.call(renderer, { view, event, range: state.range }); dispatchExit(view, pluginKey); return true; } const handled = ((_b = renderer == null ? void 0 : renderer.onKeyDown) == null ? void 0 : _b.call(renderer, { view, event, range })) || false; return handled; }, // Setup decorator on the currently active suggestion. decorations(state) { const { active, range, decorationId, query } = plugin.getState(state); if (!active) { return null; } const isEmpty2 = !(query == null ? void 0 : query.length); const classNames = [decorationClass]; if (isEmpty2) { classNames.push(decorationEmptyClass); } return DecorationSet.create(state.doc, [ Decoration.inline(range.from, range.to, { nodeName: decorationTag, class: classNames.join(" "), "data-decoration-id": decorationId, "data-decoration-content": decorationContent }) ]); } } }); return plugin; } function getSuggestionOptions({ editor: tiptapEditor, overrideSuggestionOptions, extensionName, char = "@" }) { const pluginKey = new PluginKey(); return { editor: tiptapEditor, char, pluginKey, command: ({ editor, range, props }) => { var _a, _b, _c; const nodeAfter = editor.view.state.selection.$to.nodeAfter; const overrideSpace = (_a = nodeAfter == null ? void 0 : nodeAfter.text) == null ? void 0 : _a.startsWith(" "); if (overrideSpace) { range.to += 1; } editor.chain().focus().insertContentAt(range, [ { type: extensionName, attrs: { ...props, mentionSuggestionChar: char } }, { type: "text", text: " " } ]).run(); (_c = (_b = editor.view.dom.ownerDocument.defaultView) == null ? void 0 : _b.getSelection()) == null ? void 0 : _c.collapseToEnd(); }, allow: ({ state, range }) => { const $from = state.doc.resolve(range.from); const type = state.schema.nodes[extensionName]; const allow = !!$from.parent.type.contentMatch.matchType(type); return allow; }, ...overrideSuggestionOptions }; } function getSuggestions(options) { return (options.options.suggestions.length ? options.options.suggestions : [options.options.suggestion]).map( (suggestion) => getSuggestionOptions({ // @ts-ignore `editor` can be `undefined` when converting the document to HTML with the HTML utility editor: options.editor, overrideSuggestionOptions: suggestion, extensionName: options.name, char: suggestion.char }) ); } function getSuggestionFromChar(options, char) { const suggestions = getSuggestions(options); const suggestion = suggestions.find((s) => s.char === char); if (suggestion) { return suggestion; } if (suggestions.length) { return suggestions[0]; } return null; } var Mention = Node3.create({ name: "mention", priority: 101, addOptions() { return { HTMLAttributes: {}, renderText({ node, suggestion }) { var _a, _b; return `${(_a = suggestion == null ? void 0 : suggestion.char) != null ? _a : "@"}${(_b = node.attrs.label) != null ? _b : node.attrs.id}`; }, deleteTriggerWithBackspace: false, renderHTML({ options, node, suggestion }) { var _a, _b; return [ "span", mergeAttributes(this.HTMLAttributes, options.HTMLAttributes), `${(_a = suggestion == null ? void 0 : suggestion.char) != null ? _a : "@"}${(_b = node.attrs.label) != null ? _b : node.attrs.id}` ]; }, suggestions: [], suggestion: {} }; }, group: "inline", inline: true, selectable: false, atom: true, addAttributes() { return { id: { default: null, parseHTML: (element) => element.getAttribute("data-id"), renderHTML: (attributes) => { if (!attributes.id) { return {}; } return { "data-id": attributes.id }; } }, label: { default: null, parseHTML: (element) => element.getAttribute("data-label"), renderHTML: (attributes) => { if (!attributes.label) { return {}; } return { "data-label": attributes.label }; } }, // When there are multiple types of mentions, this attribute helps distinguish them mentionSuggestionChar: { default: "@", parseHTML: (element) => element.getAttribute("data-mention-suggestion-char"), renderHTML: (attributes) => { return { "data-mention-suggestion-char": attributes.mentionSuggestionChar }; } } }; }, parseHTML() { return [ { tag: `span[data-type="${this.name}"]` } ]; }, renderHTML({ node, HTMLAttributes }) { const suggestion = getSuggestionFromChar(this, node.attrs.mentionSuggestionChar); if (this.options.renderLabel !== void 0) { console.warn("renderLabel is deprecated use renderText and renderHTML instead"); return [ "span", mergeAttributes({ "data-type": this.name }, this.options.HTMLAttributes, HTMLAttributes), this.options.renderLabel({ options: this.options, node, suggestion }) ]; } const mergedOptions = { ...this.options }; mergedOptions.HTMLAttributes = mergeAttributes( { "data-type": this.name }, this.options.HTMLAttributes, HTMLAttributes ); const html = this.options.renderHTML({ options: mergedOptions, node, suggestion }); if (typeof html === "string") { return ["span", mergeAttributes({ "data-type": this.name }, this.options.HTMLAttributes, HTMLAttributes), html]; } return html; }, ...createInlineMarkdownSpec({ nodeName: "mention", name: "@", selfClosing: true, allowedAttributes: ["id", "label", { name: "mentionSuggestionChar", skipIfDefault: "@" }], parseAttributes: (attrString) => { const attrs = {}; const regex = /(\w+)=(?:"([^"]*)"|'([^']*)')/g; let match = regex.exec(attrString); while (match !== null) { const [, key, doubleQuoted, singleQuoted] = match; const value = doubleQuoted != null ? doubleQuoted : singleQuoted; attrs[key === "char" ? "mentionSuggestionChar" : key] = value; match = regex.exec(attrString); } return attrs; }, serializeAttributes: (attrs) => { return Object.entries(attrs).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => { const serializedKey = key === "mentionSuggestionChar" ? "char" : key; return `${serializedKey}="${value}"`; }).join(" "); } }), renderText({ node }) { const args = { options: this.options, node, suggestion: getSuggestionFromChar(this, node.attrs.mentionSuggestionChar) }; if (this.options.renderLabel !== void 0) { console.warn("renderLabel is deprecated use renderText and renderHTML instead"); return this.options.renderLabel(args); } return this.options.renderText(args); }, addKeyboardShortcuts() { return { Backspace: () => this.editor.commands.command(({ tr: tr2, state }) => { let isMention = false; const { selection } = state; const { empty: empty2, anchor } = selection; if (!empty2) { return false; } let mentionNode = new Node$1(); let mentionPos = 0; state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => { if (node.type.name === this.name) { isMention = true; mentionNode = node; mentionPos = pos; return false; } }); if (isMention) { tr2.insertText( this.options.deleteTriggerWithBackspace ? "" : mentionNode.attrs.mentionSuggestionChar, mentionPos, mentionPos + mentionNode.nodeSize ); } return isMention; }) }; }, addProseMirrorPlugins() { return getSuggestions(this).map(Suggestion); } }); var index_default$1 = Mention; var inputRegex = /(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/; var Image = Node3.create({ name: "image", addOptions() { return { inline: false, allowBase64: false, HTMLAttributes: {}, resize: false }; }, inline() { return this.options.inline; }, group() { return this.options.inline ? "inline" : "block"; }, draggable: true, addAttributes() { return { src: { default: null }, alt: { default: null }, title: { default: null }, width: { default: null }, height: { default: null } }; }, parseHTML() { return [ { tag: this.options.allowBase64 ? "img[src]" : 'img[src]:not([src^="data:"])' } ]; }, renderHTML({ HTMLAttributes }) { return ["img", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]; }, parseMarkdown: (token, helpers) => { return helpers.createNode("image", { src: token.href, title: token.title, alt: token.text }); }, renderMarkdown: (node) => { var _a, _b, _c, _d, _e, _f; const src = (_b = (_a = node.attrs) == null ? void 0 : _a.src) != null ? _b : ""; const alt = (_d = (_c = node.attrs) == null ? void 0 : _c.alt) != null ? _d : ""; const title = (_f = (_e = node.attrs) == null ? void 0 : _e.title) != null ? _f : ""; return title ? `![${alt}](${src} "${title}")` : `![${alt}](${src})`; }, addNodeView() { if (!this.options.resize || !this.options.resize.enabled || typeof document === "undefined") { return null; } const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = this.options.resize; return ({ node, getPos, HTMLAttributes, editor }) => { const el = document.createElement("img"); Object.entries(HTMLAttributes).forEach(([key, value]) => { if (value != null) { switch (key) { case "width": case "height": break; default: el.setAttribute(key, value); break; } } }); el.src = HTMLAttributes.src; const nodeView = new ResizableNodeView({ element: el, editor, node, getPos, onResize: (width, height) => { el.style.width = `${width}px`; el.style.height = `${height}px`; }, onCommit: (width, height) => { const pos = getPos(); if (pos === void 0) { return; } this.editor.chain().setNodeSelection(pos).updateAttributes(this.name, { width, height }).run(); }, onUpdate: (updatedNode, _decorations, _innerDecorations) => { if (updatedNode.type !== node.type) { return false; } return true; }, options: { directions, min: { width: minWidth, height: minHeight }, preserveAspectRatio: alwaysPreserveAspectRatio === true } }); const dom = nodeView.dom; dom.style.visibility = "hidden"; dom.style.pointerEvents = "none"; el.onload = () => { dom.style.visibility = ""; dom.style.pointerEvents = ""; }; return nodeView; }; }, addCommands() { return { setImage: (options) => ({ commands }) => { return commands.insertContent({ type: this.name, attrs: options }); } }; }, addInputRules() { return [ nodeInputRule({ find: inputRegex, type: this.type, getAttributes: (match) => { const [, , alt, src, title] = match; return { src, alt, title }; } }) ]; } }); var index_default = Image; const sides = ["top", "right", "bottom", "left"]; const alignments = ["start", "end"]; const placements = /* @__PURE__ */ sides.reduce((acc, side) => acc.concat(side, side + "-" + alignments[0], side + "-" + alignments[1]), []); const min = Math.min; const max = Math.max; const round = Math.round; const createCoords = (v) => ({ x: v, y: v }); const oppositeSideMap = { left: "right", right: "left", bottom: "top", top: "bottom" }; function clamp(start, value, end) { return max(start, min(value, end)); } function evaluate(value, param) { return typeof value === "function" ? value(param) : value; } function getSide(placement) { return placement.split("-")[0]; } function getAlignment(placement) { return placement.split("-")[1]; } function getOppositeAxis(axis) { return axis === "x" ? "y" : "x"; } function getAxisLength(axis) { return axis === "y" ? "height" : "width"; } function getSideAxis(placement) { const firstChar = placement[0]; return firstChar === "t" || firstChar === "b" ? "y" : "x"; } function getAlignmentAxis(placement) { return getOppositeAxis(getSideAxis(placement)); } function getAlignmentSides(placement, rects, rtl) { if (rtl === void 0) { rtl = false; } const alignment = getAlignment(placement); const alignmentAxis = getAlignmentAxis(placement); const length = getAxisLength(alignmentAxis); let mainAlignmentSide = alignmentAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top"; if (rects.reference[length] > rects.floating[length]) { mainAlignmentSide = getOppositePlacement(mainAlignmentSide); } return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)]; } function getExpandedPlacements(placement) { const oppositePlacement = getOppositePlacement(placement); return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)]; } function getOppositeAlignmentPlacement(placement) { return placement.includes("start") ? placement.replace("start", "end") : placement.replace("end", "start"); } const lrPlacement = ["left", "right"]; const rlPlacement = ["right", "left"]; const tbPlacement = ["top", "bottom"]; const btPlacement = ["bottom", "top"]; function getSideList(side, isStart, rtl) { switch (side) { case "top": case "bottom": if (rtl) return isStart ? rlPlacement : lrPlacement; return isStart ? lrPlacement : rlPlacement; case "left": case "right": return isStart ? tbPlacement : btPlacement; default: return []; } } function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) { const alignment = getAlignment(placement); let list = getSideList(getSide(placement), direction === "start", rtl); if (alignment) { list = list.map((side) => side + "-" + alignment); if (flipAlignment) { list = list.concat(list.map(getOppositeAlignmentPlacement)); } } return list; } function getOppositePlacement(placement) { const side = getSide(placement); return oppositeSideMap[side] + placement.slice(side.length); } function expandPaddingObject(padding) { return { top: 0, right: 0, bottom: 0, left: 0, ...padding }; } function getPaddingObject(padding) { return typeof padding !== "number" ? expandPaddingObject(padding) : { top: padding, right: padding, bottom: padding, left: padding }; } function rectToClientRect(rect) { const { x, y, width, height } = rect; return { width, height, top: y, left: x, right: x + width, bottom: y + height, x, y }; } function computeCoordsFromPlacement(_ref, placement, rtl) { let { reference, floating } = _ref; const sideAxis = getSideAxis(placement); const alignmentAxis = getAlignmentAxis(placement); const alignLength = getAxisLength(alignmentAxis); const side = getSide(placement); const isVertical = sideAxis === "y"; const commonX = reference.x + reference.width / 2 - floating.width / 2; const commonY = reference.y + reference.height / 2 - floating.height / 2; const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2; let coords; switch (side) { case "top": coords = { x: commonX, y: reference.y - floating.height }; break; case "bottom": coords = { x: commonX, y: reference.y + reference.height }; break; case "right": coords = { x: reference.x + reference.width, y: commonY }; break; case "left": coords = { x: reference.x - floating.width, y: commonY }; break; default: coords = { x: reference.x, y: reference.y }; } switch (getAlignment(placement)) { case "start": coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1); break; case "end": coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1); break; } return coords; } async function detectOverflow(state, options) { var _await$platform$isEle; if (options === void 0) { options = {}; } const { x, y, platform: platform2, rects, elements, strategy } = state; const { boundary = "clippingAncestors", rootBoundary = "viewport", elementContext = "floating", altBoundary = false, padding = 0 } = evaluate(options, state); const paddingObject = getPaddingObject(padding); const altContext = elementContext === "floating" ? "reference" : "floating"; const element = elements[altBoundary ? altContext : elementContext]; const clippingClientRect = rectToClientRect(await platform2.getClippingRect({ element: ((_await$platform$isEle = await (platform2.isElement == null ? void 0 : platform2.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || await (platform2.getDocumentElement == null ? void 0 : platform2.getDocumentElement(elements.floating)), boundary, rootBoundary, strategy })); const rect = elementContext === "floating" ? { x, y, width: rects.floating.width, height: rects.floating.height } : rects.reference; const offsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating)); const offsetScale = await (platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) ? await (platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || { x: 1, y: 1 } : { x: 1, y: 1 }; const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform2.convertOffsetParentRelativeRectToViewportRelativeRect({ elements, rect, offsetParent, strategy }) : rect); return { top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y, bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y, left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x, right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x }; } const MAX_RESET_COUNT = 50; const computePosition$1 = async (reference, floating, config) => { const { placement = "bottom", strategy = "absolute", middleware = [], platform: platform2 } = config; const platformWithDetectOverflow = platform2.detectOverflow ? platform2 : { ...platform2, detectOverflow }; const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(floating)); let rects = await platform2.getElementRects({ reference, floating, strategy }); let { x, y } = computeCoordsFromPlacement(rects, placement, rtl); let statefulPlacement = placement; let resetCount = 0; const middlewareData = {}; for (let i = 0; i < middleware.length; i++) { const currentMiddleware = middleware[i]; if (!currentMiddleware) { continue; } const { name, fn } = currentMiddleware; const { x: nextX, y: nextY, data, reset: reset2 } = await fn({ x, y, initialPlacement: placement, placement: statefulPlacement, strategy, middlewareData, rects, platform: platformWithDetectOverflow, elements: { reference, floating } }); x = nextX != null ? nextX : x; y = nextY != null ? nextY : y; middlewareData[name] = { ...middlewareData[name], ...data }; if (reset2 && resetCount < MAX_RESET_COUNT) { resetCount++; if (typeof reset2 === "object") { if (reset2.placement) { statefulPlacement = reset2.placement; } if (reset2.rects) { rects = reset2.rects === true ? await platform2.getElementRects({ reference, floating, strategy }) : reset2.rects; } ({ x, y } = computeCoordsFromPlacement(rects, statefulPlacement, rtl)); } i = -1; } } return { x, y, placement: statefulPlacement, strategy, middlewareData }; }; const arrow$1 = (options) => ({ name: "arrow", options, async fn(state) { const { x, y, placement, rects, platform: platform2, elements, middlewareData } = state; const { element, padding = 0 } = evaluate(options, state) || {}; if (element == null) { return {}; } const paddingObject = getPaddingObject(padding); const coords = { x, y }; const axis = getAlignmentAxis(placement); const length = getAxisLength(axis); const arrowDimensions = await platform2.getDimensions(element); const isYAxis = axis === "y"; const minProp = isYAxis ? "top" : "left"; const maxProp = isYAxis ? "bottom" : "right"; const clientProp = isYAxis ? "clientHeight" : "clientWidth"; const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length]; const startDiff = coords[axis] - rects.reference[axis]; const arrowOffsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(element)); let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0; if (!clientSize || !await (platform2.isElement == null ? void 0 : platform2.isElement(arrowOffsetParent))) { clientSize = elements.floating[clientProp] || rects.floating[length]; } const centerToReference = endDiff / 2 - startDiff / 2; const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1; const minPadding = min(paddingObject[minProp], largestPossiblePadding); const maxPadding = min(paddingObject[maxProp], largestPossiblePadding); const min$1 = minPadding; const max2 = clientSize - arrowDimensions[length] - maxPadding; const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference; const offset2 = clamp(min$1, center, max2); const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset2 && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0; const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max2 : 0; return { [axis]: coords[axis] + alignmentOffset, data: { [axis]: offset2, centerOffset: center - offset2 - alignmentOffset, ...shouldAddOffset && { alignmentOffset } }, reset: shouldAddOffset }; } }); function getPlacementList(alignment, autoAlignment, allowedPlacements) { const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter((placement) => getAlignment(placement) === alignment), ...allowedPlacements.filter((placement) => getAlignment(placement) !== alignment)] : allowedPlacements.filter((placement) => getSide(placement) === placement); return allowedPlacementsSortedByAlignment.filter((placement) => { if (alignment) { return getAlignment(placement) === alignment || (autoAlignment ? getOppositeAlignmentPlacement(placement) !== placement : false); } return true; }); } const autoPlacement$1 = function(options) { if (options === void 0) { options = {}; } return { name: "autoPlacement", options, async fn(state) { var _middlewareData$autoP, _middlewareData$autoP2, _placementsThatFitOnE; const { rects, middlewareData, placement, platform: platform2, elements } = state; const { crossAxis = false, alignment, allowedPlacements = placements, autoAlignment = true, ...detectOverflowOptions } = evaluate(options, state); const placements$1 = alignment !== void 0 || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements; const overflow = await platform2.detectOverflow(state, detectOverflowOptions); const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0; const currentPlacement = placements$1[currentIndex]; if (currentPlacement == null) { return {}; } const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating))); if (placement !== currentPlacement) { return { reset: { placement: placements$1[0] } }; } const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]]; const allOverflows = [...((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || [], { placement: currentPlacement, overflows: currentOverflows }]; const nextPlacement = placements$1[currentIndex + 1]; if (nextPlacement) { return { data: { index: currentIndex + 1, overflows: allOverflows }, reset: { placement: nextPlacement } }; } const placementsSortedByMostSpace = allOverflows.map((d) => { const alignment2 = getAlignment(d.placement); return [d.placement, alignment2 && crossAxis ? ( // Check along the mainAxis and main crossAxis side. d.overflows.slice(0, 2).reduce((acc, v) => acc + v, 0) ) : ( // Check only the mainAxis. d.overflows[0] ), d.overflows]; }).sort((a, b) => a[1] - b[1]); const placementsThatFitOnEachSide = placementsSortedByMostSpace.filter((d) => d[2].slice( 0, // Aligned placements should not check their opposite crossAxis // side. getAlignment(d[0]) ? 2 : 3 ).every((v) => v <= 0)); const resetPlacement = ((_placementsThatFitOnE = placementsThatFitOnEachSide[0]) == null ? void 0 : _placementsThatFitOnE[0]) || placementsSortedByMostSpace[0][0]; if (resetPlacement !== placement) { return { data: { index: currentIndex + 1, overflows: allOverflows }, reset: { placement: resetPlacement } }; } return {}; } }; }; const flip$1 = function(options) { if (options === void 0) { options = {}; } return { name: "flip", options, async fn(state) { var _middlewareData$arrow, _middlewareData$flip; const { placement, middlewareData, rects, initialPlacement, platform: platform2, elements } = state; const { mainAxis: checkMainAxis = true, crossAxis: checkCrossAxis = true, fallbackPlacements: specifiedFallbackPlacements, fallbackStrategy = "bestFit", fallbackAxisSideDirection = "none", flipAlignment = true, ...detectOverflowOptions } = evaluate(options, state); if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) { return {}; } const side = getSide(placement); const initialSideAxis = getSideAxis(initialPlacement); const isBasePlacement = getSide(initialPlacement) === initialPlacement; const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating)); const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement)); const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none"; if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) { fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl)); } const placements2 = [initialPlacement, ...fallbackPlacements]; const overflow = await platform2.detectOverflow(state, detectOverflowOptions); const overflows = []; let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || []; if (checkMainAxis) { overflows.push(overflow[side]); } if (checkCrossAxis) { const sides2 = getAlignmentSides(placement, rects, rtl); overflows.push(overflow[sides2[0]], overflow[sides2[1]]); } overflowsData = [...overflowsData, { placement, overflows }]; if (!overflows.every((side2) => side2 <= 0)) { var _middlewareData$flip2, _overflowsData$filter; const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1; const nextPlacement = placements2[nextIndex]; if (nextPlacement) { const ignoreCrossAxisOverflow = checkCrossAxis === "alignment" ? initialSideAxis !== getSideAxis(nextPlacement) : false; if (!ignoreCrossAxisOverflow || // We leave the current main axis only if every placement on that axis // overflows the main axis. overflowsData.every((d) => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) { return { data: { index: nextIndex, overflows: overflowsData }, reset: { placement: nextPlacement } }; } } let resetPlacement = (_overflowsData$filter = overflowsData.filter((d) => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement; if (!resetPlacement) { switch (fallbackStrategy) { case "bestFit": { var _overflowsData$filter2; const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => { if (hasFallbackAxisSideDirection) { const currentSideAxis = getSideAxis(d.placement); return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal // reading directions favoring greater width. currentSideAxis === "y"; } return true; }).map((d) => [d.placement, d.overflows.filter((overflow2) => overflow2 > 0).reduce((acc, overflow2) => acc + overflow2, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0]; if (placement2) { resetPlacement = placement2; } break; } case "initialPlacement": resetPlacement = initialPlacement; break; } } if (placement !== resetPlacement) { return { reset: { placement: resetPlacement } }; } } return {}; } }; }; function getSideOffsets(overflow, rect) { return { top: overflow.top - rect.height, right: overflow.right - rect.width, bottom: overflow.bottom - rect.height, left: overflow.left - rect.width }; } function isAnySideFullyClipped(overflow) { return sides.some((side) => overflow[side] >= 0); } const hide$1 = function(options) { if (options === void 0) { options = {}; } return { name: "hide", options, async fn(state) { const { rects, platform: platform2 } = state; const { strategy = "referenceHidden", ...detectOverflowOptions } = evaluate(options, state); switch (strategy) { case "referenceHidden": { const overflow = await platform2.detectOverflow(state, { ...detectOverflowOptions, elementContext: "reference" }); const offsets = getSideOffsets(overflow, rects.reference); return { data: { referenceHiddenOffsets: offsets, referenceHidden: isAnySideFullyClipped(offsets) } }; } case "escaped": { const overflow = await platform2.detectOverflow(state, { ...detectOverflowOptions, altBoundary: true }); const offsets = getSideOffsets(overflow, rects.floating); return { data: { escapedOffsets: offsets, escaped: isAnySideFullyClipped(offsets) } }; } default: { return {}; } } } }; }; function getBoundingRect(rects) { const minX = min(...rects.map((rect) => rect.left)); const minY = min(...rects.map((rect) => rect.top)); const maxX = max(...rects.map((rect) => rect.right)); const maxY = max(...rects.map((rect) => rect.bottom)); return { x: minX, y: minY, width: maxX - minX, height: maxY - minY }; } function getRectsByLine(rects) { const sortedRects = rects.slice().sort((a, b) => a.y - b.y); const groups = []; let prevRect = null; for (let i = 0; i < sortedRects.length; i++) { const rect = sortedRects[i]; if (!prevRect || rect.y - prevRect.y > prevRect.height / 2) { groups.push([rect]); } else { groups[groups.length - 1].push(rect); } prevRect = rect; } return groups.map((rect) => rectToClientRect(getBoundingRect(rect))); } const inline$1 = function(options) { if (options === void 0) { options = {}; } return { name: "inline", options, async fn(state) { const { placement, elements, rects, platform: platform2, strategy } = state; const { padding = 2, x, y } = evaluate(options, state); const nativeClientRects = Array.from(await (platform2.getClientRects == null ? void 0 : platform2.getClientRects(elements.reference)) || []); const clientRects = getRectsByLine(nativeClientRects); const fallback = rectToClientRect(getBoundingRect(nativeClientRects)); const paddingObject = getPaddingObject(padding); function getBoundingClientRect2() { if (clientRects.length === 2 && clientRects[0].left > clientRects[1].right && x != null && y != null) { return clientRects.find((rect) => x > rect.left - paddingObject.left && x < rect.right + paddingObject.right && y > rect.top - paddingObject.top && y < rect.bottom + paddingObject.bottom) || fallback; } if (clientRects.length >= 2) { if (getSideAxis(placement) === "y") { const firstRect = clientRects[0]; const lastRect = clientRects[clientRects.length - 1]; const isTop = getSide(placement) === "top"; const top2 = firstRect.top; const bottom2 = lastRect.bottom; const left2 = isTop ? firstRect.left : lastRect.left; const right2 = isTop ? firstRect.right : lastRect.right; const width2 = right2 - left2; const height2 = bottom2 - top2; return { top: top2, bottom: bottom2, left: left2, right: right2, width: width2, height: height2, x: left2, y: top2 }; } const isLeftSide = getSide(placement) === "left"; const maxRight = max(...clientRects.map((rect) => rect.right)); const minLeft = min(...clientRects.map((rect) => rect.left)); const measureRects = clientRects.filter((rect) => isLeftSide ? rect.left === minLeft : rect.right === maxRight); const top = measureRects[0].top; const bottom = measureRects[measureRects.length - 1].bottom; const left = minLeft; const right = maxRight; const width = right - left; const height = bottom - top; return { top, bottom, left, right, width, height, x: left, y: top }; } return fallback; } const resetRects = await platform2.getElementRects({ reference: { getBoundingClientRect: getBoundingClientRect2 }, floating: elements.floating, strategy }); if (rects.reference.x !== resetRects.reference.x || rects.reference.y !== resetRects.reference.y || rects.reference.width !== resetRects.reference.width || rects.reference.height !== resetRects.reference.height) { return { reset: { rects: resetRects } }; } return {}; } }; }; const originSides = /* @__PURE__ */ new Set(["left", "top"]); async function convertValueToCoords(state, options) { const { placement, platform: platform2, elements } = state; const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating)); const side = getSide(placement); const alignment = getAlignment(placement); const isVertical = getSideAxis(placement) === "y"; const mainAxisMulti = originSides.has(side) ? -1 : 1; const crossAxisMulti = rtl && isVertical ? -1 : 1; const rawValue = evaluate(options, state); let { mainAxis, crossAxis, alignmentAxis } = typeof rawValue === "number" ? { mainAxis: rawValue, crossAxis: 0, alignmentAxis: null } : { mainAxis: rawValue.mainAxis || 0, crossAxis: rawValue.crossAxis || 0, alignmentAxis: rawValue.alignmentAxis }; if (alignment && typeof alignmentAxis === "number") { crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis; } return isVertical ? { x: crossAxis * crossAxisMulti, y: mainAxis * mainAxisMulti } : { x: mainAxis * mainAxisMulti, y: crossAxis * crossAxisMulti }; } const offset$1 = function(options) { if (options === void 0) { options = 0; } return { name: "offset", options, async fn(state) { var _middlewareData$offse, _middlewareData$arrow; const { x, y, placement, middlewareData } = state; const diffCoords = await convertValueToCoords(state, options); if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) { return {}; } return { x: x + diffCoords.x, y: y + diffCoords.y, data: { ...diffCoords, placement } }; } }; }; const shift$1 = function(options) { if (options === void 0) { options = {}; } return { name: "shift", options, async fn(state) { const { x, y, placement, platform: platform2 } = state; const { mainAxis: checkMainAxis = true, crossAxis: checkCrossAxis = false, limiter = { fn: (_ref) => { let { x: x2, y: y2 } = _ref; return { x: x2, y: y2 }; } }, ...detectOverflowOptions } = evaluate(options, state); const coords = { x, y }; const overflow = await platform2.detectOverflow(state, detectOverflowOptions); const crossAxis = getSideAxis(getSide(placement)); const mainAxis = getOppositeAxis(crossAxis); let mainAxisCoord = coords[mainAxis]; let crossAxisCoord = coords[crossAxis]; if (checkMainAxis) { const minSide = mainAxis === "y" ? "top" : "left"; const maxSide = mainAxis === "y" ? "bottom" : "right"; const min2 = mainAxisCoord + overflow[minSide]; const max2 = mainAxisCoord - overflow[maxSide]; mainAxisCoord = clamp(min2, mainAxisCoord, max2); } if (checkCrossAxis) { const minSide = crossAxis === "y" ? "top" : "left"; const maxSide = crossAxis === "y" ? "bottom" : "right"; const min2 = crossAxisCoord + overflow[minSide]; const max2 = crossAxisCoord - overflow[maxSide]; crossAxisCoord = clamp(min2, crossAxisCoord, max2); } const limitedCoords = limiter.fn({ ...state, [mainAxis]: mainAxisCoord, [crossAxis]: crossAxisCoord }); return { ...limitedCoords, data: { x: limitedCoords.x - x, y: limitedCoords.y - y, enabled: { [mainAxis]: checkMainAxis, [crossAxis]: checkCrossAxis } } }; } }; }; const size$1 = function(options) { if (options === void 0) { options = {}; } return { name: "size", options, async fn(state) { var _state$middlewareData, _state$middlewareData2; const { placement, rects, platform: platform2, elements } = state; const { apply: apply2 = () => { }, ...detectOverflowOptions } = evaluate(options, state); const overflow = await platform2.detectOverflow(state, detectOverflowOptions); const side = getSide(placement); const alignment = getAlignment(placement); const isYAxis = getSideAxis(placement) === "y"; const { width, height } = rects.floating; let heightSide; let widthSide; if (side === "top" || side === "bottom") { heightSide = side; widthSide = alignment === (await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating)) ? "start" : "end") ? "left" : "right"; } else { widthSide = side; heightSide = alignment === "end" ? "top" : "bottom"; } const maximumClippingHeight = height - overflow.top - overflow.bottom; const maximumClippingWidth = width - overflow.left - overflow.right; const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight); const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth); const noShift = !state.middlewareData.shift; let availableHeight = overflowAvailableHeight; let availableWidth = overflowAvailableWidth; if ((_state$middlewareData = state.middlewareData.shift) != null && _state$middlewareData.enabled.x) { availableWidth = maximumClippingWidth; } if ((_state$middlewareData2 = state.middlewareData.shift) != null && _state$middlewareData2.enabled.y) { availableHeight = maximumClippingHeight; } if (noShift && !alignment) { const xMin = max(overflow.left, 0); const xMax = max(overflow.right, 0); const yMin = max(overflow.top, 0); const yMax = max(overflow.bottom, 0); if (isYAxis) { availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right)); } else { availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom)); } } await apply2({ ...state, availableWidth, availableHeight }); const nextDimensions = await platform2.getDimensions(elements.floating); if (width !== nextDimensions.width || height !== nextDimensions.height) { return { reset: { rects: true } }; } return {}; } }; }; function hasWindow() { return typeof window !== "undefined"; } function getNodeName(node) { if (isNode(node)) { return (node.nodeName || "").toLowerCase(); } return "#document"; } function getWindow(node) { var _node$ownerDocument; return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window; } function getDocumentElement(node) { var _ref; return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement; } function isNode(value) { if (!hasWindow()) { return false; } return value instanceof Node || value instanceof getWindow(value).Node; } function isElement(value) { if (!hasWindow()) { return false; } return value instanceof Element || value instanceof getWindow(value).Element; } function isHTMLElement(value) { if (!hasWindow()) { return false; } return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement; } function isShadowRoot(value) { if (!hasWindow() || typeof ShadowRoot === "undefined") { return false; } return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot; } function isOverflowElement(element) { const { overflow, overflowX, overflowY, display } = getComputedStyle$1(element); return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && display !== "inline" && display !== "contents"; } function isTableElement(element) { return /^(table|td|th)$/.test(getNodeName(element)); } function isTopLayer(element) { try { if (element.matches(":popover-open")) { return true; } } catch (_e) { } try { return element.matches(":modal"); } catch (_e) { return false; } } const willChangeRe = /transform|translate|scale|rotate|perspective|filter/; const containRe = /paint|layout|strict|content/; const isNotNone = (value) => !!value && value !== "none"; let isWebKitValue; function isContainingBlock(elementOrCss) { const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss; return isNotNone(css.transform) || isNotNone(css.translate) || isNotNone(css.scale) || isNotNone(css.rotate) || isNotNone(css.perspective) || !isWebKit() && (isNotNone(css.backdropFilter) || isNotNone(css.filter)) || willChangeRe.test(css.willChange || "") || containRe.test(css.contain || ""); } function getContainingBlock(element) { let currentNode = getParentNode(element); while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) { if (isContainingBlock(currentNode)) { return currentNode; } else if (isTopLayer(currentNode)) { return null; } currentNode = getParentNode(currentNode); } return null; } function isWebKit() { if (isWebKitValue == null) { isWebKitValue = typeof CSS !== "undefined" && CSS.supports && CSS.supports("-webkit-backdrop-filter", "none"); } return isWebKitValue; } function isLastTraversableNode(node) { return /^(html|body|#document)$/.test(getNodeName(node)); } function getComputedStyle$1(element) { return getWindow(element).getComputedStyle(element); } function getNodeScroll(element) { if (isElement(element)) { return { scrollLeft: element.scrollLeft, scrollTop: element.scrollTop }; } return { scrollLeft: element.scrollX, scrollTop: element.scrollY }; } function getParentNode(node) { if (getNodeName(node) === "html") { return node; } const result = ( // Step into the shadow DOM of the parent of a slotted node. node.assignedSlot || // DOM Element detected. node.parentNode || // ShadowRoot detected. isShadowRoot(node) && node.host || // Fallback. getDocumentElement(node) ); return isShadowRoot(result) ? result.host : result; } function getNearestOverflowAncestor(node) { const parentNode2 = getParentNode(node); if (isLastTraversableNode(parentNode2)) { return node.ownerDocument ? node.ownerDocument.body : node.body; } if (isHTMLElement(parentNode2) && isOverflowElement(parentNode2)) { return parentNode2; } return getNearestOverflowAncestor(parentNode2); } function getOverflowAncestors(node, list, traverseIframes) { var _node$ownerDocument2; if (list === void 0) { list = []; } const scrollableAncestor = getNearestOverflowAncestor(node); const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body); const win = getWindow(scrollableAncestor); if (isBody) { getFrameElement(win); return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], []); } else { return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [])); } } function getFrameElement(win) { return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null; } function getCssDimensions(element) { const css = getComputedStyle$1(element); let width = parseFloat(css.width) || 0; let height = parseFloat(css.height) || 0; const hasOffset = isHTMLElement(element); const offsetWidth = hasOffset ? element.offsetWidth : width; const offsetHeight = hasOffset ? element.offsetHeight : height; const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight; if (shouldFallback) { width = offsetWidth; height = offsetHeight; } return { width, height, $: shouldFallback }; } function unwrapElement(element) { return !isElement(element) ? element.contextElement : element; } function getScale(element) { const domElement = unwrapElement(element); if (!isHTMLElement(domElement)) { return createCoords(1); } const rect = domElement.getBoundingClientRect(); const { width, height, $ } = getCssDimensions(domElement); let x = ($ ? round(rect.width) : rect.width) / width; let y = ($ ? round(rect.height) : rect.height) / height; if (!x || !Number.isFinite(x)) { x = 1; } if (!y || !Number.isFinite(y)) { y = 1; } return { x, y }; } const noOffsets = /* @__PURE__ */ createCoords(0); function getVisualOffsets(element) { const win = getWindow(element); if (!isWebKit() || !win.visualViewport) { return noOffsets; } return { x: win.visualViewport.offsetLeft, y: win.visualViewport.offsetTop }; } function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) { if (isFixed === void 0) { isFixed = false; } if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) { return false; } return isFixed; } function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) { if (includeScale === void 0) { includeScale = false; } if (isFixedStrategy === void 0) { isFixedStrategy = false; } const clientRect2 = element.getBoundingClientRect(); const domElement = unwrapElement(element); let scale = createCoords(1); if (includeScale) { if (offsetParent) { if (isElement(offsetParent)) { scale = getScale(offsetParent); } } else { scale = getScale(element); } } const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0); let x = (clientRect2.left + visualOffsets.x) / scale.x; let y = (clientRect2.top + visualOffsets.y) / scale.y; let width = clientRect2.width / scale.x; let height = clientRect2.height / scale.y; if (domElement) { const win = getWindow(domElement); const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent; let currentWin = win; let currentIFrame = getFrameElement(currentWin); while (currentIFrame && offsetParent && offsetWin !== currentWin) { const iframeScale = getScale(currentIFrame); const iframeRect = currentIFrame.getBoundingClientRect(); const css = getComputedStyle$1(currentIFrame); const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x; const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y; x *= iframeScale.x; y *= iframeScale.y; width *= iframeScale.x; height *= iframeScale.y; x += left; y += top; currentWin = getWindow(currentIFrame); currentIFrame = getFrameElement(currentWin); } } return rectToClientRect({ width, height, x, y }); } function getWindowScrollBarX(element, rect) { const leftScroll = getNodeScroll(element).scrollLeft; if (!rect) { return getBoundingClientRect(getDocumentElement(element)).left + leftScroll; } return rect.left + leftScroll; } function getHTMLOffset(documentElement, scroll) { const htmlRect = documentElement.getBoundingClientRect(); const x = htmlRect.left + scroll.scrollLeft - getWindowScrollBarX(documentElement, htmlRect); const y = htmlRect.top + scroll.scrollTop; return { x, y }; } function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) { let { elements, rect, offsetParent, strategy } = _ref; const isFixed = strategy === "fixed"; const documentElement = getDocumentElement(offsetParent); const topLayer = elements ? isTopLayer(elements.floating) : false; if (offsetParent === documentElement || topLayer && isFixed) { return rect; } let scroll = { scrollLeft: 0, scrollTop: 0 }; let scale = createCoords(1); const offsets = createCoords(0); const isOffsetParentAnElement = isHTMLElement(offsetParent); if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) { if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) { scroll = getNodeScroll(offsetParent); } if (isOffsetParentAnElement) { const offsetRect = getBoundingClientRect(offsetParent); scale = getScale(offsetParent); offsets.x = offsetRect.x + offsetParent.clientLeft; offsets.y = offsetRect.y + offsetParent.clientTop; } } const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0); return { width: rect.width * scale.x, height: rect.height * scale.y, x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x, y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y }; } function getClientRects(element) { return Array.from(element.getClientRects()); } function getDocumentRect(element) { const html = getDocumentElement(element); const scroll = getNodeScroll(element); const body = element.ownerDocument.body; const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth); const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight); let x = -scroll.scrollLeft + getWindowScrollBarX(element); const y = -scroll.scrollTop; if (getComputedStyle$1(body).direction === "rtl") { x += max(html.clientWidth, body.clientWidth) - width; } return { width, height, x, y }; } const SCROLLBAR_MAX = 25; function getViewportRect(element, strategy) { const win = getWindow(element); const html = getDocumentElement(element); const visualViewport = win.visualViewport; let width = html.clientWidth; let height = html.clientHeight; let x = 0; let y = 0; if (visualViewport) { width = visualViewport.width; height = visualViewport.height; const visualViewportBased = isWebKit(); if (!visualViewportBased || visualViewportBased && strategy === "fixed") { x = visualViewport.offsetLeft; y = visualViewport.offsetTop; } } const windowScrollbarX = getWindowScrollBarX(html); if (windowScrollbarX <= 0) { const doc2 = html.ownerDocument; const body = doc2.body; const bodyStyles = getComputedStyle(body); const bodyMarginInline = doc2.compatMode === "CSS1Compat" ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0; const clippingStableScrollbarWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline); if (clippingStableScrollbarWidth <= SCROLLBAR_MAX) { width -= clippingStableScrollbarWidth; } } else if (windowScrollbarX <= SCROLLBAR_MAX) { width += windowScrollbarX; } return { width, height, x, y }; } function getInnerBoundingClientRect(element, strategy) { const clientRect2 = getBoundingClientRect(element, true, strategy === "fixed"); const top = clientRect2.top + element.clientTop; const left = clientRect2.left + element.clientLeft; const scale = isHTMLElement(element) ? getScale(element) : createCoords(1); const width = element.clientWidth * scale.x; const height = element.clientHeight * scale.y; const x = left * scale.x; const y = top * scale.y; return { width, height, x, y }; } function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) { let rect; if (clippingAncestor === "viewport") { rect = getViewportRect(element, strategy); } else if (clippingAncestor === "document") { rect = getDocumentRect(getDocumentElement(element)); } else if (isElement(clippingAncestor)) { rect = getInnerBoundingClientRect(clippingAncestor, strategy); } else { const visualOffsets = getVisualOffsets(element); rect = { x: clippingAncestor.x - visualOffsets.x, y: clippingAncestor.y - visualOffsets.y, width: clippingAncestor.width, height: clippingAncestor.height }; } return rectToClientRect(rect); } function hasFixedPositionAncestor(element, stopNode) { const parentNode2 = getParentNode(element); if (parentNode2 === stopNode || !isElement(parentNode2) || isLastTraversableNode(parentNode2)) { return false; } return getComputedStyle$1(parentNode2).position === "fixed" || hasFixedPositionAncestor(parentNode2, stopNode); } function getClippingElementAncestors(element, cache) { const cachedResult2 = cache.get(element); if (cachedResult2) { return cachedResult2; } let result = getOverflowAncestors(element, []).filter((el) => isElement(el) && getNodeName(el) !== "body"); let currentContainingBlockComputedStyle = null; const elementIsFixed = getComputedStyle$1(element).position === "fixed"; let currentNode = elementIsFixed ? getParentNode(element) : element; while (isElement(currentNode) && !isLastTraversableNode(currentNode)) { const computedStyle = getComputedStyle$1(currentNode); const currentNodeIsContaining = isContainingBlock(currentNode); if (!currentNodeIsContaining && computedStyle.position === "fixed") { currentContainingBlockComputedStyle = null; } const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && (currentContainingBlockComputedStyle.position === "absolute" || currentContainingBlockComputedStyle.position === "fixed") || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode); if (shouldDropCurrentNode) { result = result.filter((ancestor) => ancestor !== currentNode); } else { currentContainingBlockComputedStyle = computedStyle; } currentNode = getParentNode(currentNode); } cache.set(element, result); return result; } function getClippingRect(_ref) { let { element, boundary, rootBoundary, strategy } = _ref; const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary); const clippingAncestors = [...elementClippingAncestors, rootBoundary]; const firstRect = getClientRectFromClippingAncestor(element, clippingAncestors[0], strategy); let top = firstRect.top; let right = firstRect.right; let bottom = firstRect.bottom; let left = firstRect.left; for (let i = 1; i < clippingAncestors.length; i++) { const rect = getClientRectFromClippingAncestor(element, clippingAncestors[i], strategy); top = max(rect.top, top); right = min(rect.right, right); bottom = min(rect.bottom, bottom); left = max(rect.left, left); } return { width: right - left, height: bottom - top, x: left, y: top }; } function getDimensions(element) { const { width, height } = getCssDimensions(element); return { width, height }; } function getRectRelativeToOffsetParent(element, offsetParent, strategy) { const isOffsetParentAnElement = isHTMLElement(offsetParent); const documentElement = getDocumentElement(offsetParent); const isFixed = strategy === "fixed"; const rect = getBoundingClientRect(element, true, isFixed, offsetParent); let scroll = { scrollLeft: 0, scrollTop: 0 }; const offsets = createCoords(0); function setLeftRTLScrollbarOffset() { offsets.x = getWindowScrollBarX(documentElement); } if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) { if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) { scroll = getNodeScroll(offsetParent); } if (isOffsetParentAnElement) { const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent); offsets.x = offsetRect.x + offsetParent.clientLeft; offsets.y = offsetRect.y + offsetParent.clientTop; } else if (documentElement) { setLeftRTLScrollbarOffset(); } } if (isFixed && !isOffsetParentAnElement && documentElement) { setLeftRTLScrollbarOffset(); } const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0); const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x; const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y; return { x, y, width: rect.width, height: rect.height }; } function isStaticPositioned(element) { return getComputedStyle$1(element).position === "static"; } function getTrueOffsetParent(element, polyfill) { if (!isHTMLElement(element) || getComputedStyle$1(element).position === "fixed") { return null; } if (polyfill) { return polyfill(element); } let rawOffsetParent = element.offsetParent; if (getDocumentElement(element) === rawOffsetParent) { rawOffsetParent = rawOffsetParent.ownerDocument.body; } return rawOffsetParent; } function getOffsetParent(element, polyfill) { const win = getWindow(element); if (isTopLayer(element)) { return win; } if (!isHTMLElement(element)) { let svgOffsetParent = getParentNode(element); while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) { if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) { return svgOffsetParent; } svgOffsetParent = getParentNode(svgOffsetParent); } return win; } let offsetParent = getTrueOffsetParent(element, polyfill); while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) { offsetParent = getTrueOffsetParent(offsetParent, polyfill); } if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) { return win; } return offsetParent || getContainingBlock(element) || win; } const getElementRects = async function(data) { const getOffsetParentFn = this.getOffsetParent || getOffsetParent; const getDimensionsFn = this.getDimensions; const floatingDimensions = await getDimensionsFn(data.floating); return { reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy), floating: { x: 0, y: 0, width: floatingDimensions.width, height: floatingDimensions.height } }; }; function isRTL(element) { return getComputedStyle$1(element).direction === "rtl"; } const platform = { convertOffsetParentRelativeRectToViewportRelativeRect, getDocumentElement, getClippingRect, getOffsetParent, getElementRects, getClientRects, getDimensions, getScale, isElement, isRTL }; const offset = offset$1; const autoPlacement = autoPlacement$1; const shift = shift$1; const flip = flip$1; const size = size$1; const hide = hide$1; const arrow = arrow$1; const inline = inline$1; const computePosition = (reference, floating, options) => { const cache = /* @__PURE__ */ new Map(); const mergedOptions = { platform, ...options }; const platformWithCache = { ...mergedOptions.platform, _c: cache }; return computePosition$1(reference, floating, { ...mergedOptions, platform: platformWithCache }); }; function combineDOMRects(rect1, rect2) { const top = Math.min(rect1.top, rect2.top); const bottom = Math.max(rect1.bottom, rect2.bottom); const left = Math.min(rect1.left, rect2.left); const right = Math.max(rect1.right, rect2.right); const width = right - left; const height = bottom - top; const x = left; const y = top; return new DOMRect(x, y, width, height); } var BubbleMenuView = class { constructor({ editor, element, view, pluginKey = "bubbleMenu", updateDelay = 250, resizeDelay = 60, shouldShow, appendTo, getReferencedVirtualElement, options }) { this.preventHide = false; this.isVisible = false; this.scrollTarget = window; this.floatingUIOptions = { strategy: "absolute", placement: "top", offset: 8, flip: {}, shift: {}, arrow: false, size: false, autoPlacement: false, hide: false, inline: false, onShow: void 0, onHide: void 0, onUpdate: void 0, onDestroy: void 0 }; this.shouldShow = ({ view: view2, state, from: from2, to }) => { const { doc: doc2, selection } = state; const { empty: empty2 } = selection; const isEmptyTextBlock = !doc2.textBetween(from2, to).length && isTextSelection(state.selection); const isChildOfMenu = this.element.contains(document.activeElement); const hasEditorFocus = view2.hasFocus() || isChildOfMenu; if (!hasEditorFocus || empty2 || isEmptyTextBlock || !this.editor.isEditable) { return false; } return true; }; this.mousedownHandler = () => { this.preventHide = true; }; this.dragstartHandler = () => { this.hide(); }; this.resizeHandler = () => { if (this.resizeDebounceTimer) { clearTimeout(this.resizeDebounceTimer); } this.resizeDebounceTimer = window.setTimeout(() => { this.updatePosition(); }, this.resizeDelay); }; this.focusHandler = () => { setTimeout(() => this.update(this.editor.view)); }; this.blurHandler = ({ event }) => { var _a2; if (this.editor.isDestroyed) { this.destroy(); return; } if (this.preventHide) { this.preventHide = false; return; } if ((event == null ? void 0 : event.relatedTarget) && ((_a2 = this.element.parentNode) == null ? void 0 : _a2.contains(event.relatedTarget))) { return; } if ((event == null ? void 0 : event.relatedTarget) === this.editor.view.dom) { return; } this.hide(); }; this.handleDebouncedUpdate = (view2, oldState) => { const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view2.state.selection)); const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view2.state.doc)); if (!selectionChanged && !docChanged) { return; } if (this.updateDebounceTimer) { clearTimeout(this.updateDebounceTimer); } this.updateDebounceTimer = window.setTimeout(() => { this.updateHandler(view2, selectionChanged, docChanged, oldState); }, this.updateDelay); }; this.updateHandler = (view2, selectionChanged, docChanged, oldState) => { const { composing } = view2; const isSame = !selectionChanged && !docChanged; if (composing || isSame) { return; } const shouldShow2 = this.getShouldShow(oldState); if (!shouldShow2) { this.hide(); return; } this.show(); this.updatePosition(); }; this.transactionHandler = ({ transaction: tr2 }) => { const meta = tr2.getMeta(this.pluginKey); if (meta === "updatePosition") { this.updatePosition(); } else if (meta && typeof meta === "object" && meta.type === "updateOptions") { this.updateOptions(meta.options); } }; var _a; this.editor = editor; this.element = element; this.view = view; this.pluginKey = pluginKey; this.updateDelay = updateDelay; this.resizeDelay = resizeDelay; this.appendTo = appendTo; this.scrollTarget = (_a = options == null ? void 0 : options.scrollTarget) != null ? _a : window; this.getReferencedVirtualElement = getReferencedVirtualElement; this.floatingUIOptions = { ...this.floatingUIOptions, ...options }; this.element.tabIndex = 0; if (shouldShow) { this.shouldShow = shouldShow; } this.element.addEventListener("mousedown", this.mousedownHandler, { capture: true }); this.view.dom.addEventListener("dragstart", this.dragstartHandler); this.editor.on("focus", this.focusHandler); this.editor.on("blur", this.blurHandler); this.editor.on("transaction", this.transactionHandler); window.addEventListener("resize", this.resizeHandler); this.scrollTarget.addEventListener("scroll", this.resizeHandler); this.update(view, view.state); if (this.getShouldShow()) { this.show(); this.updatePosition(); } } get middlewares() { const middlewares = []; if (this.floatingUIOptions.flip) { middlewares.push(flip(typeof this.floatingUIOptions.flip !== "boolean" ? this.floatingUIOptions.flip : void 0)); } if (this.floatingUIOptions.shift) { middlewares.push( shift(typeof this.floatingUIOptions.shift !== "boolean" ? this.floatingUIOptions.shift : void 0) ); } if (this.floatingUIOptions.offset) { middlewares.push( offset(typeof this.floatingUIOptions.offset !== "boolean" ? this.floatingUIOptions.offset : void 0) ); } if (this.floatingUIOptions.arrow) { middlewares.push(arrow(this.floatingUIOptions.arrow)); } if (this.floatingUIOptions.size) { middlewares.push(size(typeof this.floatingUIOptions.size !== "boolean" ? this.floatingUIOptions.size : void 0)); } if (this.floatingUIOptions.autoPlacement) { middlewares.push( autoPlacement( typeof this.floatingUIOptions.autoPlacement !== "boolean" ? this.floatingUIOptions.autoPlacement : void 0 ) ); } if (this.floatingUIOptions.hide) { middlewares.push(hide(typeof this.floatingUIOptions.hide !== "boolean" ? this.floatingUIOptions.hide : void 0)); } if (this.floatingUIOptions.inline) { middlewares.push( inline(typeof this.floatingUIOptions.inline !== "boolean" ? this.floatingUIOptions.inline : void 0) ); } return middlewares; } get virtualElement() { var _a, _b, _c; const { selection } = this.editor.state; const referencedVirtualElement = (_a = this.getReferencedVirtualElement) == null ? void 0 : _a.call(this); if (referencedVirtualElement) { return referencedVirtualElement; } if (!((_c = (_b = this.view) == null ? void 0 : _b.dom) == null ? void 0 : _c.parentNode)) { return; } const domRect = posToDOMRect(this.view, selection.from, selection.to); let virtualElement = { getBoundingClientRect: () => domRect, getClientRects: () => [domRect] }; if (selection instanceof NodeSelection) { let node = this.view.nodeDOM(selection.from); const nodeViewWrapper = node.dataset.nodeViewWrapper ? node : node.querySelector("[data-node-view-wrapper]"); if (nodeViewWrapper) { node = nodeViewWrapper; } if (node) { virtualElement = { getBoundingClientRect: () => node.getBoundingClientRect(), getClientRects: () => [node.getBoundingClientRect()] }; } } if (selection instanceof CellSelection) { const { $anchorCell, $headCell } = selection; const from2 = $anchorCell ? $anchorCell.pos : $headCell.pos; const to = $headCell ? $headCell.pos : $anchorCell.pos; const fromDOM = this.view.nodeDOM(from2); const toDOM = this.view.nodeDOM(to); if (!fromDOM || !toDOM) { return; } const clientRect2 = fromDOM === toDOM ? fromDOM.getBoundingClientRect() : combineDOMRects( fromDOM.getBoundingClientRect(), toDOM.getBoundingClientRect() ); virtualElement = { getBoundingClientRect: () => clientRect2, getClientRects: () => [clientRect2] }; } return virtualElement; } updatePosition() { if (!this.isVisible) { return; } const virtualElement = this.virtualElement; if (!virtualElement) { return; } computePosition(virtualElement, this.element, { placement: this.floatingUIOptions.placement, strategy: this.floatingUIOptions.strategy, middleware: this.middlewares }).then(({ x, y, strategy, middlewareData }) => { var _a, _b; if (!this.isVisible || this.editor.isDestroyed || !this.element.isConnected) { return; } if (((_a = middlewareData.hide) == null ? void 0 : _a.referenceHidden) || ((_b = middlewareData.hide) == null ? void 0 : _b.escaped)) { this.element.style.visibility = "hidden"; return; } this.element.style.visibility = "visible"; this.element.style.width = "max-content"; this.element.style.position = strategy; this.element.style.left = `${x}px`; this.element.style.top = `${y}px`; if (this.isVisible && this.floatingUIOptions.onUpdate) { this.floatingUIOptions.onUpdate(); } }); } update(view, oldState) { const { state } = view; const hasValidSelection = state.selection.from !== state.selection.to; if (this.updateDelay > 0 && hasValidSelection) { this.handleDebouncedUpdate(view, oldState); return; } const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view.state.selection)); const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view.state.doc)); this.updateHandler(view, selectionChanged, docChanged, oldState); } getShouldShow(oldState) { var _a; const { state } = this.view; const { selection } = state; const { ranges } = selection; const from2 = Math.min(...ranges.map((range) => range.$from.pos)); const to = Math.max(...ranges.map((range) => range.$to.pos)); const shouldShow = (_a = this.shouldShow) == null ? void 0 : _a.call(this, { editor: this.editor, element: this.element, view: this.view, state, oldState, from: from2, to }); return shouldShow || false; } show() { var _a; if (this.isVisible) { return; } this.element.style.visibility = "visible"; this.element.style.opacity = "1"; const appendToElement = typeof this.appendTo === "function" ? this.appendTo() : this.appendTo; (_a = appendToElement != null ? appendToElement : this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element); if (this.floatingUIOptions.onShow) { this.floatingUIOptions.onShow(); } this.isVisible = true; } hide() { if (!this.isVisible) { return; } this.element.style.visibility = "hidden"; this.element.style.opacity = "0"; this.element.remove(); if (this.floatingUIOptions.onHide) { this.floatingUIOptions.onHide(); } this.isVisible = false; } updateOptions(newProps) { var _a; if (newProps.updateDelay !== void 0) { this.updateDelay = newProps.updateDelay; } if (newProps.resizeDelay !== void 0) { this.resizeDelay = newProps.resizeDelay; } if (newProps.appendTo !== void 0) { this.appendTo = newProps.appendTo; } if (newProps.getReferencedVirtualElement !== void 0) { this.getReferencedVirtualElement = newProps.getReferencedVirtualElement; } if (newProps.shouldShow !== void 0) { if (newProps.shouldShow) { this.shouldShow = newProps.shouldShow; } } if (newProps.options !== void 0) { const newScrollTarget = (_a = newProps.options.scrollTarget) != null ? _a : window; if (newScrollTarget !== this.scrollTarget) { this.scrollTarget.removeEventListener("scroll", this.resizeHandler); this.scrollTarget = newScrollTarget; this.scrollTarget.addEventListener("scroll", this.resizeHandler); } this.floatingUIOptions = { ...this.floatingUIOptions, ...newProps.options }; } } destroy() { this.hide(); this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true }); this.view.dom.removeEventListener("dragstart", this.dragstartHandler); window.removeEventListener("resize", this.resizeHandler); this.scrollTarget.removeEventListener("scroll", this.resizeHandler); this.editor.off("focus", this.focusHandler); this.editor.off("blur", this.blurHandler); this.editor.off("transaction", this.transactionHandler); if (this.floatingUIOptions.onDestroy) { this.floatingUIOptions.onDestroy(); } } }; var BubbleMenuPlugin = (options) => { return new Plugin({ key: typeof options.pluginKey === "string" ? new PluginKey(options.pluginKey) : options.pluginKey, view: (view) => new BubbleMenuView({ view, ...options }) }); }; Extension.create({ name: "bubbleMenu", addOptions() { return { element: null, pluginKey: "bubbleMenu", updateDelay: void 0, appendTo: void 0, shouldShow: null }; }, addProseMirrorPlugins() { if (!this.options.element) { return []; } return [ BubbleMenuPlugin({ pluginKey: this.options.pluginKey, editor: this.editor, element: this.options.element, updateDelay: this.options.updateDelay, options: this.options.options, appendTo: this.options.appendTo, getReferencedVirtualElement: this.options.getReferencedVirtualElement, shouldShow: this.options.shouldShow }) ]; } }); var FloatingMenuView = class { constructor({ editor, element, view, pluginKey = "floatingMenu", updateDelay = 250, resizeDelay = 60, options, appendTo, shouldShow }) { this.preventHide = false; this.isVisible = false; this.scrollTarget = window; this.shouldShow = ({ view: view2, state }) => { const { selection } = state; const { $anchor, empty: empty2 } = selection; const isRootDepth = $anchor.depth === 1; const isEmptyTextBlock = $anchor.parent.isTextblock && !$anchor.parent.type.spec.code && !$anchor.parent.textContent && $anchor.parent.childCount === 0 && !this.getTextContent($anchor.parent); if (!view2.hasFocus() || !empty2 || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) { return false; } return true; }; this.floatingUIOptions = { strategy: "absolute", placement: "right", offset: 8, flip: {}, shift: {}, arrow: false, size: false, autoPlacement: false, hide: false, inline: false }; this.updateHandler = (view2, selectionChanged, docChanged, oldState) => { const { composing } = view2; const isSame = !selectionChanged && !docChanged; if (composing || isSame) { return; } const shouldShow2 = this.getShouldShow(oldState); if (!shouldShow2) { this.hide(); return; } this.updatePosition(); this.show(); }; this.mousedownHandler = () => { this.preventHide = true; }; this.focusHandler = () => { setTimeout(() => this.update(this.editor.view)); }; this.blurHandler = ({ event }) => { var _a2; if (this.preventHide) { this.preventHide = false; return; } if ((event == null ? void 0 : event.relatedTarget) && ((_a2 = this.element.parentNode) == null ? void 0 : _a2.contains(event.relatedTarget))) { return; } if ((event == null ? void 0 : event.relatedTarget) === this.editor.view.dom) { return; } this.hide(); }; this.transactionHandler = ({ transaction: tr2 }) => { const meta = tr2.getMeta(this.pluginKey); if (meta === "updatePosition") { this.updatePosition(); } else if (meta && typeof meta === "object" && meta.type === "updateOptions") { this.updateOptions(meta.options); } }; this.resizeHandler = () => { if (this.resizeDebounceTimer) { clearTimeout(this.resizeDebounceTimer); } this.resizeDebounceTimer = window.setTimeout(() => { this.updatePosition(); }, this.resizeDelay); }; var _a; this.editor = editor; this.element = element; this.view = view; this.pluginKey = pluginKey; this.updateDelay = updateDelay; this.resizeDelay = resizeDelay; this.appendTo = appendTo; this.scrollTarget = (_a = options == null ? void 0 : options.scrollTarget) != null ? _a : window; this.floatingUIOptions = { ...this.floatingUIOptions, ...options }; this.element.tabIndex = 0; if (shouldShow) { this.shouldShow = shouldShow; } this.element.addEventListener("mousedown", this.mousedownHandler, { capture: true }); this.editor.on("focus", this.focusHandler); this.editor.on("blur", this.blurHandler); this.editor.on("transaction", this.transactionHandler); window.addEventListener("resize", this.resizeHandler); this.scrollTarget.addEventListener("scroll", this.resizeHandler); this.update(view, view.state); if (this.getShouldShow()) { this.show(); this.updatePosition(); } } getTextContent(node) { return getText(node, { textSerializers: getTextSerializersFromSchema(this.editor.schema) }); } get middlewares() { const middlewares = []; if (this.floatingUIOptions.flip) { middlewares.push(flip(typeof this.floatingUIOptions.flip !== "boolean" ? this.floatingUIOptions.flip : void 0)); } if (this.floatingUIOptions.shift) { middlewares.push( shift(typeof this.floatingUIOptions.shift !== "boolean" ? this.floatingUIOptions.shift : void 0) ); } if (this.floatingUIOptions.offset) { middlewares.push( offset(typeof this.floatingUIOptions.offset !== "boolean" ? this.floatingUIOptions.offset : void 0) ); } if (this.floatingUIOptions.arrow) { middlewares.push(arrow(this.floatingUIOptions.arrow)); } if (this.floatingUIOptions.size) { middlewares.push(size(typeof this.floatingUIOptions.size !== "boolean" ? this.floatingUIOptions.size : void 0)); } if (this.floatingUIOptions.autoPlacement) { middlewares.push( autoPlacement( typeof this.floatingUIOptions.autoPlacement !== "boolean" ? this.floatingUIOptions.autoPlacement : void 0 ) ); } if (this.floatingUIOptions.hide) { middlewares.push(hide(typeof this.floatingUIOptions.hide !== "boolean" ? this.floatingUIOptions.hide : void 0)); } if (this.floatingUIOptions.inline) { middlewares.push( inline(typeof this.floatingUIOptions.inline !== "boolean" ? this.floatingUIOptions.inline : void 0) ); } return middlewares; } getShouldShow(oldState) { var _a; const { state } = this.view; const { selection } = state; const { ranges } = selection; const from2 = Math.min(...ranges.map((range) => range.$from.pos)); const to = Math.max(...ranges.map((range) => range.$to.pos)); const shouldShow = (_a = this.shouldShow) == null ? void 0 : _a.call(this, { editor: this.editor, view: this.view, state, oldState, from: from2, to }); return shouldShow; } updateOptions(newProps) { var _a; if (newProps.updateDelay !== void 0) { this.updateDelay = newProps.updateDelay; } if (newProps.resizeDelay !== void 0) { this.resizeDelay = newProps.resizeDelay; } if (newProps.appendTo !== void 0) { this.appendTo = newProps.appendTo; } if (newProps.shouldShow !== void 0) { if (newProps.shouldShow) { this.shouldShow = newProps.shouldShow; } } if (newProps.options !== void 0) { const newScrollTarget = (_a = newProps.options.scrollTarget) != null ? _a : window; if (newScrollTarget !== this.scrollTarget) { this.scrollTarget.removeEventListener("scroll", this.resizeHandler); this.scrollTarget = newScrollTarget; this.scrollTarget.addEventListener("scroll", this.resizeHandler); } this.floatingUIOptions = { ...this.floatingUIOptions, ...newProps.options }; } } updatePosition() { const { selection } = this.editor.state; const domRect = posToDOMRect(this.view, selection.from, selection.to); const virtualElement = { getBoundingClientRect: () => domRect, getClientRects: () => [domRect] }; computePosition(virtualElement, this.element, { placement: this.floatingUIOptions.placement, strategy: this.floatingUIOptions.strategy, middleware: this.middlewares }).then(({ x, y, strategy, middlewareData }) => { var _a, _b; if (((_a = middlewareData.hide) == null ? void 0 : _a.referenceHidden) || ((_b = middlewareData.hide) == null ? void 0 : _b.escaped)) { this.element.style.visibility = "hidden"; return; } this.element.style.visibility = "visible"; this.element.style.width = "max-content"; this.element.style.position = strategy; this.element.style.left = `${x}px`; this.element.style.top = `${y}px`; if (this.isVisible && this.floatingUIOptions.onUpdate) { this.floatingUIOptions.onUpdate(); } }); } update(view, oldState) { const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view.state.selection)); const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view.state.doc)); this.updateHandler(view, selectionChanged, docChanged, oldState); } show() { var _a; if (this.isVisible) { return; } this.element.style.visibility = "visible"; this.element.style.opacity = "1"; const appendToElement = typeof this.appendTo === "function" ? this.appendTo() : this.appendTo; (_a = appendToElement != null ? appendToElement : this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element); if (this.floatingUIOptions.onShow) { this.floatingUIOptions.onShow(); } this.isVisible = true; } hide() { if (!this.isVisible) { return; } this.element.style.visibility = "hidden"; this.element.style.opacity = "0"; this.element.remove(); if (this.floatingUIOptions.onHide) { this.floatingUIOptions.onHide(); } this.isVisible = false; } destroy() { this.hide(); this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true }); window.removeEventListener("resize", this.resizeHandler); this.scrollTarget.removeEventListener("scroll", this.resizeHandler); this.editor.off("focus", this.focusHandler); this.editor.off("blur", this.blurHandler); this.editor.off("transaction", this.transactionHandler); if (this.floatingUIOptions.onDestroy) { this.floatingUIOptions.onDestroy(); } } }; var FloatingMenuPlugin = (options) => { return new Plugin({ key: typeof options.pluginKey === "string" ? new PluginKey(options.pluginKey) : options.pluginKey, view: (view) => new FloatingMenuView({ view, ...options }) }); }; Extension.create({ name: "floatingMenu", addOptions() { return { element: null, options: {}, pluginKey: "floatingMenu", updateDelay: void 0, resizeDelay: void 0, appendTo: void 0, shouldShow: null }; }, addCommands() { return { updateFloatingMenuPosition: () => ({ tr: tr2, dispatch }) => { if (dispatch) { tr2.setMeta(this.options.pluginKey, "updatePosition"); } return true; } }; }, addProseMirrorPlugins() { if (!this.options.element) { return []; } return [ FloatingMenuPlugin({ pluginKey: this.options.pluginKey, editor: this.editor, element: this.options.element, updateDelay: this.options.updateDelay, resizeDelay: this.options.resizeDelay, options: this.options.options, appendTo: this.options.appendTo, shouldShow: this.options.shouldShow }) ]; } }); function getAutoPluginKey(pluginKey, defaultName) { return pluginKey != null ? pluginKey : new PluginKey(defaultName); } var useIsomorphicLayoutEffect = typeof window !== "undefined" ? reactExports.useLayoutEffect : reactExports.useEffect; var PLUGIN_MANAGED_STYLE_PROPERTIES = /* @__PURE__ */ new Set(["left", "opacity", "position", "top", "visibility", "width"]); var UNITLESS_STYLE_PROPERTIES = /* @__PURE__ */ new Set([ "animationIterationCount", "aspectRatio", "borderImageOutset", "borderImageSlice", "borderImageWidth", "columnCount", "columns", "fillOpacity", "flex", "flexGrow", "flexShrink", "fontWeight", "gridArea", "gridColumn", "gridColumnEnd", "gridColumnStart", "gridRow", "gridRowEnd", "gridRowStart", "lineClamp", "lineHeight", "opacity", "order", "orphans", "scale", "stopOpacity", "strokeDasharray", "strokeDashoffset", "strokeMiterlimit", "strokeOpacity", "strokeWidth", "tabSize", "widows", "zIndex", "zoom" ]); var ATTRIBUTE_EXCLUSIONS = /* @__PURE__ */ new Set(["children", "className", "style"]); var DIRECT_PROPERTY_KEYS = /* @__PURE__ */ new Set(["tabIndex"]); var FORWARDED_ATTRIBUTE_KEYS = /* @__PURE__ */ new Set([ "accessKey", "autoCapitalize", "contentEditable", "contextMenu", "dir", "draggable", "enterKeyHint", "hidden", "id", "lang", "nonce", "role", "slot", "spellCheck", "tabIndex", "title", "translate" ]); var SPECIAL_EVENT_NAMES = { Blur: "focusout", DoubleClick: "dblclick", Focus: "focusin", MouseEnter: "mouseenter", MouseLeave: "mouseleave" }; function isEventProp(key, value) { return /^on[A-Z]/.test(key) && typeof value === "function"; } function toAttributeName(key) { if (key.startsWith("aria-") || key.startsWith("data-")) { return key; } return key; } function isForwardedAttributeKey(key) { return key.startsWith("aria-") || key.startsWith("data-") || FORWARDED_ATTRIBUTE_KEYS.has(key); } function toStylePropertyName(key) { if (key.startsWith("--")) { return key; } return key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`); } function toEventConfig(key) { var _a; const useCapture = key.endsWith("Capture"); const baseKey = useCapture ? key.slice(0, -7) : key; const reactEventName = baseKey.slice(2); const eventName = (_a = SPECIAL_EVENT_NAMES[reactEventName]) != null ? _a : reactEventName.toLowerCase(); return { eventName, options: useCapture ? { capture: true } : void 0 }; } function createSyntheticEvent(element, nativeEvent) { let defaultPrevented = nativeEvent.defaultPrevented; let propagationStopped = false; const syntheticEvent = Object.create(nativeEvent); Object.defineProperties(syntheticEvent, { nativeEvent: { value: nativeEvent }, currentTarget: { value: element }, target: { value: nativeEvent.target }, persist: { value: () => void 0 }, isDefaultPrevented: { value: () => defaultPrevented }, isPropagationStopped: { value: () => propagationStopped }, preventDefault: { value: () => { defaultPrevented = true; nativeEvent.preventDefault(); } }, stopPropagation: { value: () => { propagationStopped = true; nativeEvent.stopPropagation(); } } }); return syntheticEvent; } function isDirectPropertyKey(key) { return DIRECT_PROPERTY_KEYS.has(key); } function setDirectProperty(element, key, value) { if (key === "tabIndex") { element.tabIndex = Number(value); return; } element[key] = value; } function clearDirectProperty(element, key) { if (key === "tabIndex") { element.removeAttribute("tabindex"); return; } const propertyValue = element[key]; if (typeof propertyValue === "boolean") { element[key] = false; return; } if (typeof propertyValue === "number") { element[key] = 0; return; } element[key] = ""; } function toStyleValue(styleName, value) { if (typeof value !== "number" || value === 0 || styleName.startsWith("--") || UNITLESS_STYLE_PROPERTIES.has(styleName)) { return String(value); } return `${value}px`; } function removeStyleProperty(element, styleName) { if (PLUGIN_MANAGED_STYLE_PROPERTIES.has(styleName)) { return; } element.style.removeProperty(toStylePropertyName(styleName)); } function applyStyleProperty(element, styleName, value) { if (PLUGIN_MANAGED_STYLE_PROPERTIES.has(styleName)) { return; } element.style.setProperty(toStylePropertyName(styleName), toStyleValue(styleName, value)); } function syncAttributes(element, prevProps, nextProps) { const allKeys = /* @__PURE__ */ new Set([...Object.keys(prevProps), ...Object.keys(nextProps)]); allKeys.forEach((key) => { if (ATTRIBUTE_EXCLUSIONS.has(key) || !isForwardedAttributeKey(key) || isEventProp(key, prevProps[key]) || isEventProp(key, nextProps[key])) { return; } const prevValue = prevProps[key]; const nextValue = nextProps[key]; if (prevValue === nextValue) { return; } const attributeName = toAttributeName(key); if (nextValue == null || nextValue === false) { if (isDirectPropertyKey(key)) { clearDirectProperty(element, key); } element.removeAttribute(attributeName); return; } if (nextValue === true) { if (isDirectPropertyKey(key)) { setDirectProperty(element, key, true); } element.setAttribute(attributeName, ""); return; } if (isDirectPropertyKey(key)) { setDirectProperty(element, key, nextValue); return; } element.setAttribute(attributeName, String(nextValue)); }); } function syncClassName(element, prevClassName, nextClassName) { if (prevClassName === nextClassName) { return; } if (nextClassName) { element.className = nextClassName; return; } element.removeAttribute("class"); } function syncStyles(element, prevStyle, nextStyle) { const previousStyle = prevStyle != null ? prevStyle : {}; const currentStyle = nextStyle != null ? nextStyle : {}; const allStyleNames = /* @__PURE__ */ new Set([...Object.keys(previousStyle), ...Object.keys(currentStyle)]); allStyleNames.forEach((styleName) => { const prevValue = previousStyle[styleName]; const nextValue = currentStyle[styleName]; if (prevValue === nextValue) { return; } if (nextValue == null) { removeStyleProperty(element, styleName); return; } applyStyleProperty(element, styleName, nextValue); }); } function syncEventListeners(element, prevListeners, nextProps) { prevListeners.forEach(({ eventName, listener, options }) => { element.removeEventListener(eventName, listener, options); }); const nextListeners = []; Object.entries(nextProps).forEach(([key, value]) => { if (!isEventProp(key, value)) { return; } const { eventName, options } = toEventConfig(key); const listener = (event) => { value(createSyntheticEvent(element, event)); }; element.addEventListener(eventName, listener, options); nextListeners.push({ eventName, listener, options }); }); return nextListeners; } function useMenuElementProps(element, props) { const previousPropsRef = reactExports.useRef({}); const listenersRef = reactExports.useRef([]); useIsomorphicLayoutEffect(() => { const previousProps = previousPropsRef.current; syncClassName(element, previousProps.className, props.className); syncStyles(element, previousProps.style, props.style); syncAttributes(element, previousProps, props); listenersRef.current = syncEventListeners(element, listenersRef.current, props); previousPropsRef.current = props; return () => { listenersRef.current.forEach(({ eventName, listener, options }) => { element.removeEventListener(eventName, listener, options); }); listenersRef.current = []; }; }, [element, props]); } var BubbleMenu = React.forwardRef( ({ pluginKey, editor, updateDelay, resizeDelay, appendTo, shouldShow = null, getReferencedVirtualElement, options, children, ...restProps }, ref) => { const menuEl = reactExports.useRef(document.createElement("div")); const resolvedPluginKey = reactExports.useRef(getAutoPluginKey(pluginKey, "bubbleMenu")).current; useMenuElementProps(menuEl.current, restProps); if (typeof ref === "function") { ref(menuEl.current); } else if (ref) { ref.current = menuEl.current; } const { editor: currentEditor } = useCurrentEditor(); const pluginEditor = editor || currentEditor; const bubbleMenuPluginProps = { updateDelay, resizeDelay, appendTo, pluginKey: resolvedPluginKey, shouldShow, getReferencedVirtualElement, options }; const bubbleMenuPluginPropsRef = reactExports.useRef(bubbleMenuPluginProps); bubbleMenuPluginPropsRef.current = bubbleMenuPluginProps; const [pluginInitialized, setPluginInitialized] = reactExports.useState(false); const skipFirstUpdateRef = reactExports.useRef(true); reactExports.useEffect(() => { if (pluginEditor == null ? void 0 : pluginEditor.isDestroyed) { return; } if (!pluginEditor) { console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop."); return; } const bubbleMenuElement = menuEl.current; bubbleMenuElement.style.visibility = "hidden"; bubbleMenuElement.style.position = "absolute"; const plugin = BubbleMenuPlugin({ ...bubbleMenuPluginPropsRef.current, editor: pluginEditor, element: bubbleMenuElement }); pluginEditor.registerPlugin(plugin); const createdPluginKey = bubbleMenuPluginPropsRef.current.pluginKey; skipFirstUpdateRef.current = true; setPluginInitialized(true); return () => { setPluginInitialized(false); pluginEditor.unregisterPlugin(createdPluginKey); window.requestAnimationFrame(() => { if (bubbleMenuElement.parentNode) { bubbleMenuElement.parentNode.removeChild(bubbleMenuElement); } }); }; }, [pluginEditor]); reactExports.useEffect(() => { if (!pluginInitialized || !pluginEditor || pluginEditor.isDestroyed) { return; } if (skipFirstUpdateRef.current) { skipFirstUpdateRef.current = false; return; } pluginEditor.view.dispatch( pluginEditor.state.tr.setMeta(resolvedPluginKey, { type: "updateOptions", options: bubbleMenuPluginPropsRef.current }) ); }, [ pluginInitialized, pluginEditor, updateDelay, resizeDelay, shouldShow, options, appendTo, getReferencedVirtualElement, resolvedPluginKey ]); return reactDomExports.createPortal(children, menuEl.current); } ); React.forwardRef( ({ pluginKey, editor, updateDelay, resizeDelay, appendTo, shouldShow = null, options, children, ...restProps }, ref) => { const menuEl = reactExports.useRef(document.createElement("div")); const resolvedPluginKey = reactExports.useRef(getAutoPluginKey(pluginKey, "floatingMenu")).current; useMenuElementProps(menuEl.current, restProps); if (typeof ref === "function") { ref(menuEl.current); } else if (ref) { ref.current = menuEl.current; } const { editor: currentEditor } = useCurrentEditor(); const pluginEditor = editor || currentEditor; const floatingMenuPluginProps = { updateDelay, resizeDelay, appendTo, pluginKey: resolvedPluginKey, shouldShow, options }; const floatingMenuPluginPropsRef = reactExports.useRef(floatingMenuPluginProps); floatingMenuPluginPropsRef.current = floatingMenuPluginProps; const [pluginInitialized, setPluginInitialized] = reactExports.useState(false); const skipFirstUpdateRef = reactExports.useRef(true); reactExports.useEffect(() => { if (pluginEditor == null ? void 0 : pluginEditor.isDestroyed) { return; } if (!pluginEditor) { console.warn( "FloatingMenu component is not rendered inside of an editor component or does not have editor prop." ); return; } const floatingMenuElement = menuEl.current; floatingMenuElement.style.visibility = "hidden"; floatingMenuElement.style.position = "absolute"; const plugin = FloatingMenuPlugin({ ...floatingMenuPluginPropsRef.current, editor: pluginEditor, element: floatingMenuElement }); pluginEditor.registerPlugin(plugin); const createdPluginKey = floatingMenuPluginPropsRef.current.pluginKey; skipFirstUpdateRef.current = true; setPluginInitialized(true); return () => { setPluginInitialized(false); pluginEditor.unregisterPlugin(createdPluginKey); window.requestAnimationFrame(() => { if (floatingMenuElement.parentNode) { floatingMenuElement.parentNode.removeChild(floatingMenuElement); } }); }; }, [pluginEditor]); reactExports.useEffect(() => { if (!pluginInitialized || !pluginEditor || pluginEditor.isDestroyed) { return; } if (skipFirstUpdateRef.current) { skipFirstUpdateRef.current = false; return; } pluginEditor.view.dispatch( pluginEditor.state.tr.setMeta(resolvedPluginKey, { type: "updateOptions", options: floatingMenuPluginPropsRef.current }) ); }, [pluginInitialized, pluginEditor, updateDelay, resizeDelay, shouldShow, options, appendTo, resolvedPluginKey]); return reactDomExports.createPortal(children, menuEl.current); } ); export { BubbleMenu as B, EditorContent as E, NodeViewWrapper as N, React as R, TableRow as T, reactDomExports as a, ReactRenderer as b, commonjsGlobal as c, ReactNodeViewRenderer as d, Node3 as e, index_default$4 as f, getDefaultExportFromCjs as g, index_default$3 as h, index_default as i, jsxRuntimeExports as j, index_default$5 as k, Table as l, mergeAttributes as m, TableHeader as n, TableCell as o, index_default$2 as p, index_default$1 as q, reactExports as r, requireReact as s, requireReactDom as t, useEditor as u };