UNPKG

alinea

Version:
1,721 lines (1,702 loc) 125 kB
import { FloatingMenu } from "../../chunks/chunk-3DIW62EI.js"; import { Decoration, DecorationSet, Extension, Fragment, Mark, Node, NodeSelection, Plugin, PluginKey, Selection, SelectionRange, Slice, TextSelection, Transform, callOrReturn, dropPoint, findParentNodeClosestToPos, getExtensionField, isNodeSelection, keydownHandler, markInputRule, markPasteRule, mergeAttributes, nodeInputRule, textblockTypeInputRule, wrappingInputRule } from "../../chunks/chunk-FKWEJTSK.js"; import { dist_default } from "../../chunks/chunk-A5O3N2GS.js"; import "../../chunks/chunk-NZLE2WMY.js"; // node_modules/@tiptap/extension-blockquote/dist/index.js var inputRegex = /^\s*>\s$/; var Blockquote = Node.create({ name: "blockquote", addOptions() { return { HTMLAttributes: {} }; }, content: "block+", group: "block", defining: true, parseHTML() { return [ { tag: "blockquote" } ]; }, renderHTML({ HTMLAttributes }) { return ["blockquote", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, 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, type: this.type }) ]; } }); // node_modules/@tiptap/extension-bold/dist/index.js var starInputRegex = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/; var starPasteRegex = /(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g; var underscoreInputRegex = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/; var underscorePasteRegex = /(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g; var Bold = Mark.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 ["strong", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, 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, type: this.type }), markInputRule({ find: underscoreInputRegex, type: this.type }) ]; }, addPasteRules() { return [ markPasteRule({ find: starPasteRegex, type: this.type }), markPasteRule({ find: underscorePasteRegex, type: this.type }) ]; } }); // node_modules/@tiptap/extension-bullet-list/dist/index.js var ListItemName = "listItem"; var TextStyleName = "textStyle"; var inputRegex2 = /^\s*([-+*])\s$/; var BulletList = Node.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]; }, 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: inputRegex2, type: this.type }); if (this.options.keepMarks || this.options.keepAttributes) { inputRule = wrappingInputRule({ find: inputRegex2, type: this.type, keepMarks: this.options.keepMarks, keepAttributes: this.options.keepAttributes, getAttributes: () => { return this.editor.getAttributes(TextStyleName); }, editor: this.editor }); } return [ inputRule ]; } }); // node_modules/@tiptap/extension-document/dist/index.js var Document = Node.create({ name: "doc", topNode: true, content: "block+" }); // node_modules/prosemirror-dropcursor/dist/index.js function dropCursor(options = {}) { return new Plugin({ view(editorView) { return new DropCursorView(editorView, options); } }); } var DropCursorView = class { 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; 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; rect = { left: nodeRect.left, right: nodeRect.right, top: top - this.width / 2, bottom: top + this.width / 2 }; } } } if (!rect) { let coords = this.editorView.coordsAtPos(this.cursorPos); rect = { left: coords.left - this.width / 2, right: coords.left + this.width / 2, 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(); parentLeft = rect2.left - parent.scrollLeft; parentTop = rect2.top - parent.scrollTop; } this.element.style.left = rect.left - parentLeft + "px"; this.element.style.top = rect.top - parentTop + "px"; this.element.style.width = rect.right - rect.left + "px"; this.element.style.height = rect.bottom - rect.top + "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 (event.target == this.editorView.dom || !this.editorView.dom.contains(event.relatedTarget)) this.setCursor(null); } }; // node_modules/@tiptap/extension-dropcursor/dist/index.js var Dropcursor = Extension.create({ name: "dropCursor", addOptions() { return { color: "currentColor", width: 1, class: void 0 }; }, addProseMirrorPlugins() { return [ dropCursor(this.options) ]; } }); // node_modules/prosemirror-gapcursor/dist/index.js var GapCursor = class _GapCursor extends Selection { /** Create a gap cursor. */ constructor($pos) { super($pos, $pos); } map(doc, mapping) { let $pos = doc.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(doc, json) { if (typeof json.pos != "number") throw new RangeError("Invalid input for GapCursor.fromJSON"); return new _GapCursor(doc.resolve(json.pos)); } /** @internal */ getBookmark() { return new GapBookmark(this.anchor); } /** @internal */ static valid($pos) { let parent = $pos.parent; if (parent.isTextblock || !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); var GapBookmark = class _GapBookmark { constructor(pos) { this.pos = pos; } map(mapping) { return new _GapBookmark(mapping.map(this.pos)); } resolve(doc) { let $pos = doc.resolve(this.pos); return GapCursor.valid($pos) ? new GapCursor($pos) : Selection.near($pos); } }; 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 || before.isAtom || before.type.spec.isolating) 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 || after.isAtom || after.type.spec.isolating) 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, handleDOMEvents: { beforeinput } } }); } var handleKeyDown = keydownHandler({ "ArrowLeft": arrow("horiz", -1), "ArrowRight": arrow("horiz", 1), "ArrowUp": arrow("vert", -1), "ArrowDown": arrow("vert", 1) }); function arrow(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 tr = view.state.tr.replace($from.pos, $from.pos, new Slice(frag, 0, 0)); tr.setSelection(TextSelection.near(tr.doc.resolve($from.pos + 1))); view.dispatch(tr); 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" })]); } // node_modules/@tiptap/extension-gapcursor/dist/index.js 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 !== void 0 ? _a : null }; } }); // node_modules/@tiptap/extension-hard-break/dist/index.js var HardBreak = Node.create({ name: "hardBreak", 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"; }, 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, dispatch }) => { if (dispatch && marks && keepMarks) { const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name)); tr.ensureMarks(filteredMarks); } return true; }).run(); }) ]); } }; }, addKeyboardShortcuts() { return { "Mod-Enter": () => this.editor.commands.setHardBreak(), "Shift-Enter": () => this.editor.commands.setHardBreak() }; } }); // node_modules/@tiptap/extension-heading/dist/index.js var Heading = Node.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]; }, 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 } }); }); } }); // node_modules/@tiptap/extension-horizontal-rule/dist/index.js var HorizontalRule = Node.create({ name: "horizontalRule", addOptions() { return { HTMLAttributes: {} }; }, group: "block", parseHTML() { return [{ tag: "hr" }]; }, renderHTML({ HTMLAttributes }) { return ["hr", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)]; }, addCommands() { return { setHorizontalRule: () => ({ chain, state }) => { const { selection } = state; const { $from: $originFrom, $to: $originTo } = selection; const currentChain = chain(); if ($originFrom.parentOffset === 0) { currentChain.insertContentAt({ from: Math.max($originFrom.pos - 1, 0), to: $originTo.pos }, { type: this.name }); } else if (isNodeSelection(selection)) { currentChain.insertContentAt($originTo.pos, { type: this.name }); } else { currentChain.insertContent({ type: this.name }); } return currentChain.command(({ tr, dispatch }) => { var _a; if (dispatch) { const { $to } = tr.selection; const posAfter = $to.end(); if ($to.nodeAfter) { if ($to.nodeAfter.isTextblock) { tr.setSelection(TextSelection.create(tr.doc, $to.pos + 1)); } else if ($to.nodeAfter.isBlock) { tr.setSelection(NodeSelection.create(tr.doc, $to.pos)); } else { tr.setSelection(TextSelection.create(tr.doc, $to.pos)); } } else { const node = (_a = $to.parent.type.contentMatch.defaultType) === null || _a === void 0 ? void 0 : _a.create(); if (node) { tr.insert(posAfter, node); tr.setSelection(TextSelection.create(tr.doc, posAfter + 1)); } } tr.scrollIntoView(); } return true; }).run(); } }; }, addInputRules() { return [ nodeInputRule({ find: /^(?:---|—-|___\s|\*\*\*\s)$/, type: this.type }) ]; } }); // node_modules/@tiptap/extension-italic/dist/index.js var starInputRegex2 = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/; var starPasteRegex2 = /(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g; var underscoreInputRegex2 = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/; var underscorePasteRegex2 = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g; var Italic = Mark.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); } }; }, addKeyboardShortcuts() { return { "Mod-i": () => this.editor.commands.toggleItalic(), "Mod-I": () => this.editor.commands.toggleItalic() }; }, addInputRules() { return [ markInputRule({ find: starInputRegex2, type: this.type }), markInputRule({ find: underscoreInputRegex2, type: this.type }) ]; }, addPasteRules() { return [ markPasteRule({ find: starPasteRegex2, type: this.type }), markPasteRule({ find: underscorePasteRegex2, type: this.type }) ]; } }); // node_modules/@tiptap/extension-list-item/dist/index.js var ListItem = Node.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]; }, addKeyboardShortcuts() { return { Enter: () => this.editor.commands.splitListItem(this.name), Tab: () => this.editor.commands.sinkListItem(this.name), "Shift-Tab": () => this.editor.commands.liftListItem(this.name) }; } }); // node_modules/@tiptap/extension-ordered-list/dist/index.js var ListItemName2 = "listItem"; var TextStyleName2 = "textStyle"; var inputRegex3 = /^(\d+)\.\s$/; var OrderedList = Node.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: void 0, 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]; }, 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: inputRegex3, 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: inputRegex3, 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 ]; } }); // node_modules/@tiptap/extension-paragraph/dist/index.js var Paragraph = Node.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]; }, addCommands() { return { setParagraph: () => ({ commands }) => { return commands.setNode(this.name); } }; }, addKeyboardShortcuts() { return { "Mod-Alt-0": () => this.editor.commands.setParagraph() }; } }); // node_modules/@tiptap/extension-strike/dist/index.js var inputRegex4 = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/; var pasteRegex = /(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g; var Strike = Mark.create({ name: "strike", addOptions() { return { HTMLAttributes: {} }; }, parseHTML() { return [ { tag: "s" }, { tag: "del" }, { tag: "strike" }, { style: "text-decoration", consuming: false, getAttrs: (style) => style.includes("line-through") ? {} : false } ]; }, renderHTML({ HTMLAttributes }) { return ["s", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, 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: inputRegex4, type: this.type }) ]; }, addPasteRules() { return [ markPasteRule({ find: pasteRegex, type: this.type }) ]; } }); // node_modules/@tiptap/extension-subscript/dist/index.js var Subscript = Mark.create({ name: "subscript", addOptions() { return { HTMLAttributes: {} }; }, parseHTML() { return [ { tag: "sub" }, { style: "vertical-align", getAttrs(value) { if (value !== "sub") { return false; } return null; } } ]; }, renderHTML({ HTMLAttributes }) { return ["sub", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, addCommands() { return { setSubscript: () => ({ commands }) => { return commands.setMark(this.name); }, toggleSubscript: () => ({ commands }) => { return commands.toggleMark(this.name); }, unsetSubscript: () => ({ commands }) => { return commands.unsetMark(this.name); } }; }, addKeyboardShortcuts() { return { "Mod-,": () => this.editor.commands.toggleSubscript() }; } }); // node_modules/@tiptap/extension-superscript/dist/index.js var Superscript = Mark.create({ name: "superscript", addOptions() { return { HTMLAttributes: {} }; }, parseHTML() { return [ { tag: "sup" }, { style: "vertical-align", getAttrs(value) { if (value !== "super") { return false; } return null; } } ]; }, renderHTML({ HTMLAttributes }) { return ["sup", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, addCommands() { return { setSuperscript: () => ({ commands }) => { return commands.setMark(this.name); }, toggleSuperscript: () => ({ commands }) => { return commands.toggleMark(this.name); }, unsetSuperscript: () => ({ commands }) => { return commands.unsetMark(this.name); } }; }, addKeyboardShortcuts() { return { "Mod-.": () => this.editor.commands.toggleSuperscript() }; } }); // node_modules/prosemirror-tables/dist/index.js var readFromCache; var 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, map, problems) { this.width = width; this.height = height; this.map = map; this.problems = problems; } // Find the dimensions of the cell at the given position. 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`); } // Find the left side of the cell at the given position. 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`); } // Find the next cell in the given direction, starting from the cell // at `pos`, if any. 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)]; } } // Get the rectangle spanning the two given cells. 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) }; } // Return the position of all cells that have the top left corner in // the given rectangle. 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; } // Return the position at which the cell at the given row and column // starts, or would start, if a cell started there. 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; } } // Find the table map for the given table node. 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 map = []; let mapPos = 0; let problems = null; const colWidths = []; for (let i = 0, e = width * height; i < e; i++) map[i] = 0; for (let row = 0, pos = 0; row < height; row++) { const rowNode = table.child(row); pos++; for (let i = 0; ; i++) { while (mapPos < map.length && map[mapPos] != 0) mapPos++; if (i == rowNode.childCount) break; const cellNode = rowNode.child(i); const { colspan, rowspan, colwidth } = cellNode.attrs; for (let h = 0; h < rowspan; h++) { if (h + row >= height) { (problems || (problems = [])).push({ type: "overlong_rowspan", pos, n: rowspan - h }); break; } const start = mapPos + h * width; for (let w = 0; w < colspan; w++) { if (map[start + w] == 0) map[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 (map[mapPos++] == 0) missing++; if (missing) (problems || (problems = [])).push({ type: "missing", row, n: missing }); pos++; } const tableMap = new TableMap(width, height, map, 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(map, colWidths, table) { if (!map.problems) map.problems = []; const seen = {}; for (let i = 0; i < map.map.length; i++) { const pos = map.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 col = (i + j) % map.width; const colWidth = colWidths[col * 2]; if (colWidth != null && (!attrs.colwidth || attrs.colwidth[j] != colWidth)) (updated || (updated = freshColWidth(attrs)))[j] = colWidth; } if (updated) map.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; } var 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 map = TableMap.get(table); const tableStart = $pos.start(-1); const moved = map.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(map, table, col) { const headerCell = tableNodeTypes(table.type.schema).header_cell; for (let row = 0; row < map.height; row++) if (table.nodeAt(map.map[col + row * map.width]).type != headerCell) return false; return true; } var CellSelection = class _CellSelection extends Selection { // A table selection is identified by its anchor and head cells. The // positions given to this constructor should point _before_ two // cells in the same table. They may be the same, to select a single // cell. constructor($anchorCell, $headCell = $anchorCell) { const table = $anchorCell.node(-1); const map = TableMap.get(table); const tableStart = $anchorCell.start(-1); const rect = map.rectBetween( $anchorCell.pos - tableStart, $headCell.pos - tableStart ); const doc = $anchorCell.node(0); const cells = map.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 RangeError(`No cell with offset ${pos} found`); } const from = tableStart + pos + 1; return new SelectionRange( doc.resolve(from), doc.resolve(from + cell.content.size) ); }); super(ranges[0].$from, ranges[0].$to, ranges); this.$anchorCell = $anchorCell; this.$headCell = $headCell; } map(doc, mapping) { const $anchorCell = doc.resolve(mapping.map(this.$anchorCell.pos)); const $headCell = doc.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 _CellSelection.rowSelection($anchorCell, $headCell); else if (tableChanged && this.isColSelection()) return _CellSelection.colSelection($anchorCell, $headCell); else return new _CellSelection($anchorCell, $headCell); } return TextSelection.between($anchorCell, $headCell); } // Returns a rectangular slice of table rows containing the selected // cells. content() { const table = this.$anchorCell.node(-1); const map = TableMap.get(table); const tableStart = this.$anchorCell.start(-1); const rect = map.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 * map.width + rect.left, col = rect.left; col < rect.right; col++, index++) { const pos = map.map[index]; if (seen[pos]) continue; seen[pos] = true; const cellRect = map.findCell(pos); let cell = table.nodeAt(pos); if (!cell) { throw 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 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(tr, content = Slice.empty) { const mapFrom = tr.steps.length, ranges = this.ranges; for (let i = 0; i < ranges.length; i++) { const { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom); tr.replace( mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content ); } const sel = Selection.findFrom( tr.doc.resolve(tr.mapping.slice(mapFrom).map(this.to)), -1 ); if (sel) tr.setSelection(sel); } replaceWith(tr, node) { this.replace(tr, new Slice(Fragment.from(node), 0, 0)); } forEachCell(f) { const table = this.$anchorCell.node(-1); const map = TableMap.get(table); const tableStart = this.$anchorCell.start(-1); const cells = map.cellsInRect( map.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]); } } // True if this selection goes all the way from the top to the // bottom of the table. isColSelection() { const anchorTop = this.$anchorCell.index(-1); const headTop = this.$headCell.index(-1); if (