react-tiptap-base-editor 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -0
- package/dist/components/tiptap-icons/align-center-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/align-center-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/align-justify-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/align-justify-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/align-left-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/align-left-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/align-right-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/align-right-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/arrow-left-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/arrow-left-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/ban-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/ban-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/blockquote-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/blockquote-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/bold-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/bold-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/chevron-down-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/chevron-down-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/close-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/close-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/code-block-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/code-block-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/code2-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/code2-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/corner-down-left-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/corner-down-left-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/external-link-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/external-link-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/heading-five-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/heading-five-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/heading-four-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/heading-four-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/heading-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/heading-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/heading-one-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/heading-one-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/heading-six-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/heading-six-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/heading-three-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/heading-three-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/heading-two-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/heading-two-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/highlighter-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/highlighter-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/image-plus-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/image-plus-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/italic-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/italic-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/link-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/link-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/list-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/list-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/list-ordered-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/list-ordered-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/list-todo-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/list-todo-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/moon-star-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/moon-star-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/redo2-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/redo2-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/strike-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/strike-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/subscript-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/subscript-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/sun-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/sun-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/superscript-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/superscript-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/trash-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/trash-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/underline-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/underline-icon.d.ts.map +1 -0
- package/dist/components/tiptap-icons/undo2-icon.d.ts +3 -0
- package/dist/components/tiptap-icons/undo2-icon.d.ts.map +1 -0
- package/dist/components/tiptap-node/horizontal-rule-node/horizontal-rule-node-extension.d.ts +3 -0
- package/dist/components/tiptap-node/horizontal-rule-node/horizontal-rule-node-extension.d.ts.map +1 -0
- package/dist/components/tiptap-node/image-upload-node/image-upload-node-extension.d.ts +59 -0
- package/dist/components/tiptap-node/image-upload-node/image-upload-node-extension.d.ts.map +1 -0
- package/dist/components/tiptap-node/image-upload-node/image-upload-node.d.ts +71 -0
- package/dist/components/tiptap-node/image-upload-node/image-upload-node.d.ts.map +1 -0
- package/dist/components/tiptap-node/image-upload-node/index.d.ts +2 -0
- package/dist/components/tiptap-node/image-upload-node/index.d.ts.map +1 -0
- package/dist/components/tiptap-templates/simple/simple-editor.d.ts +10 -0
- package/dist/components/tiptap-templates/simple/simple-editor.d.ts.map +1 -0
- package/dist/components/tiptap-templates/simple/theme-toggle.d.ts +2 -0
- package/dist/components/tiptap-templates/simple/theme-toggle.d.ts.map +1 -0
- package/dist/components/tiptap-ui/blockquote-button/blockquote-button.d.ts +24 -0
- package/dist/components/tiptap-ui/blockquote-button/blockquote-button.d.ts.map +1 -0
- package/dist/components/tiptap-ui/blockquote-button/index.d.ts +3 -0
- package/dist/components/tiptap-ui/blockquote-button/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/blockquote-button/use-blockquote.d.ts +82 -0
- package/dist/components/tiptap-ui/blockquote-button/use-blockquote.d.ts.map +1 -0
- package/dist/components/tiptap-ui/code-block-button/code-block-button.d.ts +24 -0
- package/dist/components/tiptap-ui/code-block-button/code-block-button.d.ts.map +1 -0
- package/dist/components/tiptap-ui/code-block-button/index.d.ts +3 -0
- package/dist/components/tiptap-ui/code-block-button/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/code-block-button/use-code-block.d.ts +89 -0
- package/dist/components/tiptap-ui/code-block-button/use-code-block.d.ts.map +1 -0
- package/dist/components/tiptap-ui/color-highlight-button/color-highlight-button.d.ts +25 -0
- package/dist/components/tiptap-ui/color-highlight-button/color-highlight-button.d.ts.map +1 -0
- package/dist/components/tiptap-ui/color-highlight-button/index.d.ts +3 -0
- package/dist/components/tiptap-ui/color-highlight-button/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/color-highlight-button/use-color-highlight.d.ts +61 -0
- package/dist/components/tiptap-ui/color-highlight-button/use-color-highlight.d.ts.map +1 -0
- package/dist/components/tiptap-ui/color-highlight-popover/color-highlight-popover.d.ts +27 -0
- package/dist/components/tiptap-ui/color-highlight-popover/color-highlight-popover.d.ts.map +1 -0
- package/dist/components/tiptap-ui/color-highlight-popover/index.d.ts +2 -0
- package/dist/components/tiptap-ui/color-highlight-popover/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/heading-button/heading-button.d.ts +25 -0
- package/dist/components/tiptap-ui/heading-button/heading-button.d.ts.map +1 -0
- package/dist/components/tiptap-ui/heading-button/index.d.ts +3 -0
- package/dist/components/tiptap-ui/heading-button/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/heading-button/use-heading.d.ts +110 -0
- package/dist/components/tiptap-ui/heading-button/use-heading.d.ts.map +1 -0
- package/dist/components/tiptap-ui/heading-dropdown-menu/heading-dropdown-menu.d.ts +22 -0
- package/dist/components/tiptap-ui/heading-dropdown-menu/heading-dropdown-menu.d.ts.map +1 -0
- package/dist/components/tiptap-ui/heading-dropdown-menu/index.d.ts +3 -0
- package/dist/components/tiptap-ui/heading-dropdown-menu/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/heading-dropdown-menu/use-heading-dropdown-menu.d.ts +75 -0
- package/dist/components/tiptap-ui/heading-dropdown-menu/use-heading-dropdown-menu.d.ts.map +1 -0
- package/dist/components/tiptap-ui/image-upload-button/image-upload-button.d.ts +24 -0
- package/dist/components/tiptap-ui/image-upload-button/image-upload-button.d.ts.map +1 -0
- package/dist/components/tiptap-ui/image-upload-button/index.d.ts +3 -0
- package/dist/components/tiptap-ui/image-upload-button/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/image-upload-button/use-image-upload.d.ts +86 -0
- package/dist/components/tiptap-ui/image-upload-button/use-image-upload.d.ts.map +1 -0
- package/dist/components/tiptap-ui/link-popover/index.d.ts +3 -0
- package/dist/components/tiptap-ui/link-popover/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/link-popover/link-popover.d.ts +59 -0
- package/dist/components/tiptap-ui/link-popover/link-popover.d.ts.map +1 -0
- package/dist/components/tiptap-ui/link-popover/use-link-popover.d.ts +119 -0
- package/dist/components/tiptap-ui/link-popover/use-link-popover.d.ts.map +1 -0
- package/dist/components/tiptap-ui/list-button/index.d.ts +3 -0
- package/dist/components/tiptap-ui/list-button/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/list-button/list-button.d.ts +25 -0
- package/dist/components/tiptap-ui/list-button/list-button.d.ts.map +1 -0
- package/dist/components/tiptap-ui/list-button/use-list.d.ts +99 -0
- package/dist/components/tiptap-ui/list-button/use-list.d.ts.map +1 -0
- package/dist/components/tiptap-ui/list-dropdown-menu/index.d.ts +2 -0
- package/dist/components/tiptap-ui/list-dropdown-menu/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/list-dropdown-menu/list-dropdown-menu.d.ts +30 -0
- package/dist/components/tiptap-ui/list-dropdown-menu/list-dropdown-menu.d.ts.map +1 -0
- package/dist/components/tiptap-ui/list-dropdown-menu/use-list-dropdown-menu.d.ts +92 -0
- package/dist/components/tiptap-ui/list-dropdown-menu/use-list-dropdown-menu.d.ts.map +1 -0
- package/dist/components/tiptap-ui/mark-button/index.d.ts +3 -0
- package/dist/components/tiptap-ui/mark-button/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/mark-button/mark-button.d.ts +25 -0
- package/dist/components/tiptap-ui/mark-button/mark-button.d.ts.map +1 -0
- package/dist/components/tiptap-ui/mark-button/use-mark.d.ts +106 -0
- package/dist/components/tiptap-ui/mark-button/use-mark.d.ts.map +1 -0
- package/dist/components/tiptap-ui/text-align-button/index.d.ts +3 -0
- package/dist/components/tiptap-ui/text-align-button/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/text-align-button/text-align-button.d.ts +32 -0
- package/dist/components/tiptap-ui/text-align-button/text-align-button.d.ts.map +1 -0
- package/dist/components/tiptap-ui/text-align-button/use-text-align.d.ts +104 -0
- package/dist/components/tiptap-ui/text-align-button/use-text-align.d.ts.map +1 -0
- package/dist/components/tiptap-ui/undo-redo-button/index.d.ts +3 -0
- package/dist/components/tiptap-ui/undo-redo-button/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui/undo-redo-button/undo-redo-button.d.ts +25 -0
- package/dist/components/tiptap-ui/undo-redo-button/undo-redo-button.d.ts.map +1 -0
- package/dist/components/tiptap-ui/undo-redo-button/use-undo-redo.d.ts +92 -0
- package/dist/components/tiptap-ui/undo-redo-button/use-undo-redo.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/badge/badge.d.ts +13 -0
- package/dist/components/tiptap-ui-primitive/badge/badge.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/badge/index.d.ts +2 -0
- package/dist/components/tiptap-ui-primitive/badge/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/button/button.d.ts +19 -0
- package/dist/components/tiptap-ui-primitive/button/button.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/button/index.d.ts +2 -0
- package/dist/components/tiptap-ui-primitive/button/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/card/card.d.ts +12 -0
- package/dist/components/tiptap-ui-primitive/card/card.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/card/index.d.ts +2 -0
- package/dist/components/tiptap-ui-primitive/card/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/dropdown-menu/dropdown-menu.d.ts +19 -0
- package/dist/components/tiptap-ui-primitive/dropdown-menu/dropdown-menu.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/dropdown-menu/index.d.ts +2 -0
- package/dist/components/tiptap-ui-primitive/dropdown-menu/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/input/index.d.ts +2 -0
- package/dist/components/tiptap-ui-primitive/input/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/input/input.d.ts +6 -0
- package/dist/components/tiptap-ui-primitive/input/input.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/popover/index.d.ts +2 -0
- package/dist/components/tiptap-ui-primitive/popover/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/popover/popover.d.ts +8 -0
- package/dist/components/tiptap-ui-primitive/popover/popover.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/separator/index.d.ts +2 -0
- package/dist/components/tiptap-ui-primitive/separator/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/separator/separator.d.ts +9 -0
- package/dist/components/tiptap-ui-primitive/separator/separator.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/spacer/index.d.ts +2 -0
- package/dist/components/tiptap-ui-primitive/spacer/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/spacer/spacer.d.ts +8 -0
- package/dist/components/tiptap-ui-primitive/spacer/spacer.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/toolbar/index.d.ts +2 -0
- package/dist/components/tiptap-ui-primitive/toolbar/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/toolbar/toolbar.d.ts +11 -0
- package/dist/components/tiptap-ui-primitive/toolbar/toolbar.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/tooltip/index.d.ts +2 -0
- package/dist/components/tiptap-ui-primitive/tooltip/index.d.ts.map +1 -0
- package/dist/components/tiptap-ui-primitive/tooltip/tooltip.d.ts +31 -0
- package/dist/components/tiptap-ui-primitive/tooltip/tooltip.d.ts.map +1 -0
- package/dist/hooks/use-composed-ref.d.ts +5 -0
- package/dist/hooks/use-composed-ref.d.ts.map +1 -0
- package/dist/hooks/use-cursor-visibility.d.ts +21 -0
- package/dist/hooks/use-cursor-visibility.d.ts.map +1 -0
- package/dist/hooks/use-element-rect.d.ts +37 -0
- package/dist/hooks/use-element-rect.d.ts.map +1 -0
- package/dist/hooks/use-menu-navigation.d.ts +54 -0
- package/dist/hooks/use-menu-navigation.d.ts.map +1 -0
- package/dist/hooks/use-mobile.d.ts +2 -0
- package/dist/hooks/use-mobile.d.ts.map +1 -0
- package/dist/hooks/use-scrolling.d.ts +9 -0
- package/dist/hooks/use-scrolling.d.ts.map +1 -0
- package/dist/hooks/use-throttled-callback.d.ts +20 -0
- package/dist/hooks/use-throttled-callback.d.ts.map +1 -0
- package/dist/hooks/use-tiptap-editor.d.ts +18 -0
- package/dist/hooks/use-tiptap-editor.d.ts.map +1 -0
- package/dist/hooks/use-unmount.d.ts +8 -0
- package/dist/hooks/use-unmount.d.ts.map +1 -0
- package/dist/hooks/use-window-size.d.ts +36 -0
- package/dist/hooks/use-window-size.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5929 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/tiptap-utils.d.ts +123 -0
- package/dist/lib/tiptap-utils.d.ts.map +1 -0
- package/dist/styles/index.css +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/components/tiptap-ui-primitive/tooltip/tooltip.tsx","../node_modules/prosemirror-model/dist/index.js","../node_modules/prosemirror-transform/dist/index.js","../node_modules/prosemirror-state/dist/index.js","../src/lib/tiptap-utils.ts","../src/components/tiptap-ui-primitive/button/button.tsx","../src/components/tiptap-ui-primitive/spacer/spacer.tsx","../src/components/tiptap-ui-primitive/separator/separator.tsx","../src/hooks/use-menu-navigation.ts","../src/hooks/use-composed-ref.ts","../src/components/tiptap-ui-primitive/toolbar/toolbar.tsx","../src/components/tiptap-icons/close-icon.tsx","../src/components/tiptap-node/image-upload-node/image-upload-node.tsx","../src/components/tiptap-node/image-upload-node/image-upload-node-extension.ts","../src/components/tiptap-node/horizontal-rule-node/horizontal-rule-node-extension.ts","../src/components/tiptap-icons/chevron-down-icon.tsx","../src/hooks/use-tiptap-editor.ts","../src/components/tiptap-ui-primitive/badge/badge.tsx","../src/components/tiptap-ui/heading-button/heading-button.tsx","../src/components/tiptap-icons/heading-one-icon.tsx","../src/components/tiptap-icons/heading-two-icon.tsx","../src/components/tiptap-icons/heading-three-icon.tsx","../src/components/tiptap-icons/heading-four-icon.tsx","../src/components/tiptap-icons/heading-five-icon.tsx","../src/components/tiptap-icons/heading-six-icon.tsx","../src/components/tiptap-ui/heading-button/use-heading.ts","../src/components/tiptap-ui-primitive/dropdown-menu/dropdown-menu.tsx","../src/components/tiptap-ui-primitive/card/card.tsx","../src/components/tiptap-ui/heading-dropdown-menu/heading-dropdown-menu.tsx","../src/components/tiptap-icons/heading-icon.tsx","../src/components/tiptap-ui/heading-dropdown-menu/use-heading-dropdown-menu.ts","../src/components/tiptap-ui/image-upload-button/image-upload-button.tsx","../src/hooks/use-mobile.ts","../src/components/tiptap-icons/image-plus-icon.tsx","../src/components/tiptap-ui/image-upload-button/use-image-upload.ts","../src/components/tiptap-ui/list-button/list-button.tsx","../src/components/tiptap-icons/list-icon.tsx","../src/components/tiptap-icons/list-ordered-icon.tsx","../src/components/tiptap-icons/list-todo-icon.tsx","../src/components/tiptap-ui/list-button/use-list.ts","../src/components/tiptap-ui/list-dropdown-menu/use-list-dropdown-menu.ts","../src/components/tiptap-ui/list-dropdown-menu/list-dropdown-menu.tsx","../src/components/tiptap-ui/blockquote-button/blockquote-button.tsx","../src/components/tiptap-icons/blockquote-icon.tsx","../src/components/tiptap-ui/blockquote-button/use-blockquote.ts","../src/components/tiptap-ui/code-block-button/code-block-button.tsx","../src/components/tiptap-icons/code-block-icon.tsx","../src/components/tiptap-ui/code-block-button/use-code-block.ts","../src/components/tiptap-icons/ban-icon.tsx","../src/components/tiptap-icons/highlighter-icon.tsx","../src/components/tiptap-ui-primitive/popover/popover.tsx","../src/components/tiptap-ui/color-highlight-button/color-highlight-button.tsx","../src/components/tiptap-ui/color-highlight-button/use-color-highlight.ts","../src/components/tiptap-ui/color-highlight-popover/color-highlight-popover.tsx","../src/components/tiptap-icons/corner-down-left-icon.tsx","../src/components/tiptap-icons/external-link-icon.tsx","../src/components/tiptap-icons/link-icon.tsx","../src/components/tiptap-icons/trash-icon.tsx","../src/components/tiptap-ui-primitive/input/input.tsx","../src/components/tiptap-ui/link-popover/link-popover.tsx","../src/components/tiptap-ui/link-popover/use-link-popover.ts","../src/components/tiptap-ui/mark-button/mark-button.tsx","../src/components/tiptap-icons/bold-icon.tsx","../src/components/tiptap-icons/code2-icon.tsx","../src/components/tiptap-icons/italic-icon.tsx","../src/components/tiptap-icons/strike-icon.tsx","../src/components/tiptap-icons/subscript-icon.tsx","../src/components/tiptap-icons/superscript-icon.tsx","../src/components/tiptap-icons/underline-icon.tsx","../src/components/tiptap-ui/mark-button/use-mark.ts","../src/components/tiptap-ui/text-align-button/text-align-button.tsx","../src/components/tiptap-icons/align-center-icon.tsx","../src/components/tiptap-icons/align-justify-icon.tsx","../src/components/tiptap-icons/align-left-icon.tsx","../src/components/tiptap-icons/align-right-icon.tsx","../src/components/tiptap-ui/text-align-button/use-text-align.ts","../src/components/tiptap-ui/undo-redo-button/undo-redo-button.tsx","../src/components/tiptap-icons/redo2-icon.tsx","../src/components/tiptap-icons/undo2-icon.tsx","../src/components/tiptap-ui/undo-redo-button/use-undo-redo.ts","../src/components/tiptap-icons/arrow-left-icon.tsx","../src/hooks/use-unmount.ts","../src/hooks/use-throttled-callback.ts","../src/hooks/use-window-size.ts","../src/hooks/use-element-rect.ts","../src/hooks/use-cursor-visibility.ts","../src/components/tiptap-templates/simple/simple-editor.tsx"],"sourcesContent":["\"use client\"\n\nimport * as React from \"react\"\nimport {\n useFloating,\n autoUpdate,\n offset,\n flip,\n shift,\n useHover,\n useFocus,\n useDismiss,\n useRole,\n useInteractions,\n useMergeRefs,\n FloatingPortal,\n type Placement,\n type UseFloatingReturn,\n type ReferenceType,\n FloatingDelayGroup,\n} from \"@floating-ui/react\"\nimport \"@/components/tiptap-ui-primitive/tooltip/tooltip.scss\"\n\ninterface TooltipProviderProps {\n children: React.ReactNode\n initialOpen?: boolean\n placement?: Placement\n open?: boolean\n onOpenChange?: (open: boolean) => void\n delay?: number\n closeDelay?: number\n timeout?: number\n useDelayGroup?: boolean\n}\n\ninterface TooltipTriggerProps\n extends Omit<React.HTMLProps<HTMLElement>, \"ref\"> {\n asChild?: boolean\n children: React.ReactNode\n}\n\ninterface TooltipContentProps\n extends Omit<React.HTMLProps<HTMLDivElement>, \"ref\"> {\n children?: React.ReactNode\n portal?: boolean\n portalProps?: Omit<React.ComponentProps<typeof FloatingPortal>, \"children\">\n}\n\ninterface TooltipContextValue extends UseFloatingReturn<ReferenceType> {\n open: boolean\n setOpen: (open: boolean) => void\n getReferenceProps: (\n userProps?: React.HTMLProps<HTMLElement>\n ) => Record<string, unknown>\n getFloatingProps: (\n userProps?: React.HTMLProps<HTMLDivElement>\n ) => Record<string, unknown>\n}\n\nfunction useTooltip({\n initialOpen = false,\n placement = \"top\",\n open: controlledOpen,\n onOpenChange: setControlledOpen,\n delay = 600,\n closeDelay = 0,\n}: Omit<TooltipProviderProps, \"children\"> = {}) {\n const [uncontrolledOpen, setUncontrolledOpen] =\n React.useState<boolean>(initialOpen)\n\n const open = controlledOpen ?? uncontrolledOpen\n const setOpen = setControlledOpen ?? setUncontrolledOpen\n\n const data = useFloating({\n placement,\n open,\n onOpenChange: setOpen,\n whileElementsMounted: autoUpdate,\n middleware: [\n offset(4),\n flip({\n crossAxis: placement.includes(\"-\"),\n fallbackAxisSideDirection: \"start\",\n padding: 4,\n }),\n shift({ padding: 4 }),\n ],\n })\n\n const context = data.context\n\n const hover = useHover(context, {\n mouseOnly: true,\n move: false,\n restMs: delay,\n enabled: controlledOpen == null,\n delay: {\n close: closeDelay,\n },\n })\n const focus = useFocus(context, {\n enabled: controlledOpen == null,\n })\n const dismiss = useDismiss(context)\n const role = useRole(context, { role: \"tooltip\" })\n\n const interactions = useInteractions([hover, focus, dismiss, role])\n\n return React.useMemo(\n () => ({\n open,\n setOpen,\n ...interactions,\n ...data,\n }),\n [open, setOpen, interactions, data]\n )\n}\n\nconst TooltipContext = React.createContext<TooltipContextValue | null>(null)\n\nfunction useTooltipContext() {\n const context = React.useContext(TooltipContext)\n\n if (context == null) {\n throw new Error(\"Tooltip components must be wrapped in <TooltipProvider />\")\n }\n\n return context\n}\n\nexport function Tooltip({ children, ...props }: TooltipProviderProps) {\n const tooltip = useTooltip(props)\n\n if (!props.useDelayGroup) {\n return (\n <TooltipContext.Provider value={tooltip}>\n {children}\n </TooltipContext.Provider>\n )\n }\n\n return (\n <FloatingDelayGroup\n delay={{ open: props.delay ?? 0, close: props.closeDelay ?? 0 }}\n timeoutMs={props.timeout}\n >\n <TooltipContext.Provider value={tooltip}>\n {children}\n </TooltipContext.Provider>\n </FloatingDelayGroup>\n )\n}\n\nexport const TooltipTrigger = React.forwardRef<\n HTMLElement,\n TooltipTriggerProps\n>(function TooltipTrigger({ children, asChild = false, ...props }, propRef) {\n const context = useTooltipContext()\n const childrenRef = React.isValidElement(children)\n ? parseInt(React.version, 10) >= 19\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (children as { props: { ref?: React.Ref<any> } }).props.ref\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (children as any).ref\n : undefined\n const ref = useMergeRefs([context.refs.setReference, propRef, childrenRef])\n\n if (asChild && React.isValidElement(children)) {\n const dataAttributes = {\n \"data-tooltip-state\": context.open ? \"open\" : \"closed\",\n }\n\n return React.cloneElement(\n children,\n context.getReferenceProps({\n ref,\n ...props,\n ...(typeof children.props === \"object\" ? children.props : {}),\n ...dataAttributes,\n })\n )\n }\n\n return (\n <button\n ref={ref}\n data-tooltip-state={context.open ? \"open\" : \"closed\"}\n {...context.getReferenceProps(props)}\n >\n {children}\n </button>\n )\n})\n\nexport const TooltipContent = React.forwardRef<\n HTMLDivElement,\n TooltipContentProps\n>(function TooltipContent(\n { style, children, portal = true, portalProps = {}, ...props },\n propRef\n) {\n const context = useTooltipContext()\n const ref = useMergeRefs([context.refs.setFloating, propRef])\n\n if (!context.open) return null\n\n const content = (\n <div\n ref={ref}\n style={{\n ...context.floatingStyles,\n ...style,\n }}\n {...context.getFloatingProps(props)}\n className=\"tiptap-tooltip\"\n >\n {children}\n </div>\n )\n\n if (portal) {\n return <FloatingPortal {...portalProps}>{content}</FloatingPortal>\n }\n\n return content\n})\n\nTooltip.displayName = \"Tooltip\"\nTooltipTrigger.displayName = \"TooltipTrigger\"\nTooltipContent.displayName = \"TooltipContent\"\n","import OrderedMap from 'orderedmap';\n\nfunction findDiffStart(a, b, pos) {\n for (let i = 0;; i++) {\n if (i == a.childCount || i == b.childCount)\n return a.childCount == b.childCount ? null : pos;\n let childA = a.child(i), childB = b.child(i);\n if (childA == childB) {\n pos += childA.nodeSize;\n continue;\n }\n if (!childA.sameMarkup(childB))\n return pos;\n if (childA.isText && childA.text != childB.text) {\n for (let j = 0; childA.text[j] == childB.text[j]; j++)\n pos++;\n return pos;\n }\n if (childA.content.size || childB.content.size) {\n let inner = findDiffStart(childA.content, childB.content, pos + 1);\n if (inner != null)\n return inner;\n }\n pos += childA.nodeSize;\n }\n}\nfunction findDiffEnd(a, b, posA, posB) {\n for (let iA = a.childCount, iB = b.childCount;;) {\n if (iA == 0 || iB == 0)\n return iA == iB ? null : { a: posA, b: posB };\n let childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize;\n if (childA == childB) {\n posA -= size;\n posB -= size;\n continue;\n }\n if (!childA.sameMarkup(childB))\n return { a: posA, b: posB };\n if (childA.isText && childA.text != childB.text) {\n let same = 0, minSize = Math.min(childA.text.length, childB.text.length);\n while (same < minSize && childA.text[childA.text.length - same - 1] == childB.text[childB.text.length - same - 1]) {\n same++;\n posA--;\n posB--;\n }\n return { a: posA, b: posB };\n }\n if (childA.content.size || childB.content.size) {\n let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1);\n if (inner)\n return inner;\n }\n posA -= size;\n posB -= size;\n }\n}\n\n/**\nA fragment represents a node's collection of child nodes.\n\nLike nodes, fragments are persistent data structures, and you\nshould not mutate them or their content. Rather, you create new\ninstances whenever needed. The API tries to make this easy.\n*/\nclass Fragment {\n /**\n @internal\n */\n constructor(\n /**\n The child nodes in this fragment.\n */\n content, size) {\n this.content = content;\n this.size = size || 0;\n if (size == null)\n for (let i = 0; i < content.length; i++)\n this.size += content[i].nodeSize;\n }\n /**\n Invoke a callback for all descendant nodes between the given two\n positions (relative to start of this fragment). Doesn't descend\n into a node when the callback returns `false`.\n */\n nodesBetween(from, to, f, nodeStart = 0, parent) {\n for (let i = 0, pos = 0; pos < to; i++) {\n let child = this.content[i], end = pos + child.nodeSize;\n if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) {\n let start = pos + 1;\n child.nodesBetween(Math.max(0, from - start), Math.min(child.content.size, to - start), f, nodeStart + start);\n }\n pos = end;\n }\n }\n /**\n Call the given callback for every descendant node. `pos` will be\n relative to the start of the fragment. The callback may return\n `false` to prevent traversal of a given node's children.\n */\n descendants(f) {\n this.nodesBetween(0, this.size, f);\n }\n /**\n Extract the text between `from` and `to`. See the same method on\n [`Node`](https://prosemirror.net/docs/ref/#model.Node.textBetween).\n */\n textBetween(from, to, blockSeparator, leafText) {\n let text = \"\", first = true;\n this.nodesBetween(from, to, (node, pos) => {\n let nodeText = node.isText ? node.text.slice(Math.max(from, pos) - pos, to - pos)\n : !node.isLeaf ? \"\"\n : leafText ? (typeof leafText === \"function\" ? leafText(node) : leafText)\n : node.type.spec.leafText ? node.type.spec.leafText(node)\n : \"\";\n if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) {\n if (first)\n first = false;\n else\n text += blockSeparator;\n }\n text += nodeText;\n }, 0);\n return text;\n }\n /**\n Create a new fragment containing the combined content of this\n fragment and the other.\n */\n append(other) {\n if (!other.size)\n return this;\n if (!this.size)\n return other;\n let last = this.lastChild, first = other.firstChild, content = this.content.slice(), i = 0;\n if (last.isText && last.sameMarkup(first)) {\n content[content.length - 1] = last.withText(last.text + first.text);\n i = 1;\n }\n for (; i < other.content.length; i++)\n content.push(other.content[i]);\n return new Fragment(content, this.size + other.size);\n }\n /**\n Cut out the sub-fragment between the two given positions.\n */\n cut(from, to = this.size) {\n if (from == 0 && to == this.size)\n return this;\n let result = [], size = 0;\n if (to > from)\n for (let i = 0, pos = 0; pos < to; i++) {\n let child = this.content[i], end = pos + child.nodeSize;\n if (end > from) {\n if (pos < from || end > to) {\n if (child.isText)\n child = child.cut(Math.max(0, from - pos), Math.min(child.text.length, to - pos));\n else\n child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1));\n }\n result.push(child);\n size += child.nodeSize;\n }\n pos = end;\n }\n return new Fragment(result, size);\n }\n /**\n @internal\n */\n cutByIndex(from, to) {\n if (from == to)\n return Fragment.empty;\n if (from == 0 && to == this.content.length)\n return this;\n return new Fragment(this.content.slice(from, to));\n }\n /**\n Create a new fragment in which the node at the given index is\n replaced by the given node.\n */\n replaceChild(index, node) {\n let current = this.content[index];\n if (current == node)\n return this;\n let copy = this.content.slice();\n let size = this.size + node.nodeSize - current.nodeSize;\n copy[index] = node;\n return new Fragment(copy, size);\n }\n /**\n Create a new fragment by prepending the given node to this\n fragment.\n */\n addToStart(node) {\n return new Fragment([node].concat(this.content), this.size + node.nodeSize);\n }\n /**\n Create a new fragment by appending the given node to this\n fragment.\n */\n addToEnd(node) {\n return new Fragment(this.content.concat(node), this.size + node.nodeSize);\n }\n /**\n Compare this fragment to another one.\n */\n eq(other) {\n if (this.content.length != other.content.length)\n return false;\n for (let i = 0; i < this.content.length; i++)\n if (!this.content[i].eq(other.content[i]))\n return false;\n return true;\n }\n /**\n The first child of the fragment, or `null` if it is empty.\n */\n get firstChild() { return this.content.length ? this.content[0] : null; }\n /**\n The last child of the fragment, or `null` if it is empty.\n */\n get lastChild() { return this.content.length ? this.content[this.content.length - 1] : null; }\n /**\n The number of child nodes in this fragment.\n */\n get childCount() { return this.content.length; }\n /**\n Get the child node at the given index. Raise an error when the\n index is out of range.\n */\n child(index) {\n let found = this.content[index];\n if (!found)\n throw new RangeError(\"Index \" + index + \" out of range for \" + this);\n return found;\n }\n /**\n Get the child node at the given index, if it exists.\n */\n maybeChild(index) {\n return this.content[index] || null;\n }\n /**\n Call `f` for every child node, passing the node, its offset\n into this parent node, and its index.\n */\n forEach(f) {\n for (let i = 0, p = 0; i < this.content.length; i++) {\n let child = this.content[i];\n f(child, p, i);\n p += child.nodeSize;\n }\n }\n /**\n Find the first position at which this fragment and another\n fragment differ, or `null` if they are the same.\n */\n findDiffStart(other, pos = 0) {\n return findDiffStart(this, other, pos);\n }\n /**\n Find the first position, searching from the end, at which this\n fragment and the given fragment differ, or `null` if they are\n the same. Since this position will not be the same in both\n nodes, an object with two separate positions is returned.\n */\n findDiffEnd(other, pos = this.size, otherPos = other.size) {\n return findDiffEnd(this, other, pos, otherPos);\n }\n /**\n Find the index and inner offset corresponding to a given relative\n position in this fragment. The result object will be reused\n (overwritten) the next time the function is called. @internal\n */\n findIndex(pos) {\n if (pos == 0)\n return retIndex(0, pos);\n if (pos == this.size)\n return retIndex(this.content.length, pos);\n if (pos > this.size || pos < 0)\n throw new RangeError(`Position ${pos} outside of fragment (${this})`);\n for (let i = 0, curPos = 0;; i++) {\n let cur = this.child(i), end = curPos + cur.nodeSize;\n if (end >= pos) {\n if (end == pos)\n return retIndex(i + 1, end);\n return retIndex(i, curPos);\n }\n curPos = end;\n }\n }\n /**\n Return a debugging string that describes this fragment.\n */\n toString() { return \"<\" + this.toStringInner() + \">\"; }\n /**\n @internal\n */\n toStringInner() { return this.content.join(\", \"); }\n /**\n Create a JSON-serializeable representation of this fragment.\n */\n toJSON() {\n return this.content.length ? this.content.map(n => n.toJSON()) : null;\n }\n /**\n Deserialize a fragment from its JSON representation.\n */\n static fromJSON(schema, value) {\n if (!value)\n return Fragment.empty;\n if (!Array.isArray(value))\n throw new RangeError(\"Invalid input for Fragment.fromJSON\");\n return new Fragment(value.map(schema.nodeFromJSON));\n }\n /**\n Build a fragment from an array of nodes. Ensures that adjacent\n text nodes with the same marks are joined together.\n */\n static fromArray(array) {\n if (!array.length)\n return Fragment.empty;\n let joined, size = 0;\n for (let i = 0; i < array.length; i++) {\n let node = array[i];\n size += node.nodeSize;\n if (i && node.isText && array[i - 1].sameMarkup(node)) {\n if (!joined)\n joined = array.slice(0, i);\n joined[joined.length - 1] = node\n .withText(joined[joined.length - 1].text + node.text);\n }\n else if (joined) {\n joined.push(node);\n }\n }\n return new Fragment(joined || array, size);\n }\n /**\n Create a fragment from something that can be interpreted as a\n set of nodes. For `null`, it returns the empty fragment. For a\n fragment, the fragment itself. For a node or array of nodes, a\n fragment containing those nodes.\n */\n static from(nodes) {\n if (!nodes)\n return Fragment.empty;\n if (nodes instanceof Fragment)\n return nodes;\n if (Array.isArray(nodes))\n return this.fromArray(nodes);\n if (nodes.attrs)\n return new Fragment([nodes], nodes.nodeSize);\n throw new RangeError(\"Can not convert \" + nodes + \" to a Fragment\" +\n (nodes.nodesBetween ? \" (looks like multiple versions of prosemirror-model were loaded)\" : \"\"));\n }\n}\n/**\nAn empty fragment. Intended to be reused whenever a node doesn't\ncontain anything (rather than allocating a new empty fragment for\neach leaf node).\n*/\nFragment.empty = new Fragment([], 0);\nconst found = { index: 0, offset: 0 };\nfunction retIndex(index, offset) {\n found.index = index;\n found.offset = offset;\n return found;\n}\n\nfunction compareDeep(a, b) {\n if (a === b)\n return true;\n if (!(a && typeof a == \"object\") ||\n !(b && typeof b == \"object\"))\n return false;\n let array = Array.isArray(a);\n if (Array.isArray(b) != array)\n return false;\n if (array) {\n if (a.length != b.length)\n return false;\n for (let i = 0; i < a.length; i++)\n if (!compareDeep(a[i], b[i]))\n return false;\n }\n else {\n for (let p in a)\n if (!(p in b) || !compareDeep(a[p], b[p]))\n return false;\n for (let p in b)\n if (!(p in a))\n return false;\n }\n return true;\n}\n\n/**\nA mark is a piece of information that can be attached to a node,\nsuch as it being emphasized, in code font, or a link. It has a\ntype and optionally a set of attributes that provide further\ninformation (such as the target of the link). Marks are created\nthrough a `Schema`, which controls which types exist and which\nattributes they have.\n*/\nclass Mark {\n /**\n @internal\n */\n constructor(\n /**\n The type of this mark.\n */\n type, \n /**\n The attributes associated with this mark.\n */\n attrs) {\n this.type = type;\n this.attrs = attrs;\n }\n /**\n Given a set of marks, create a new set which contains this one as\n well, in the right position. If this mark is already in the set,\n the set itself is returned. If any marks that are set to be\n [exclusive](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) with this mark are present,\n those are replaced by this one.\n */\n addToSet(set) {\n let copy, placed = false;\n for (let i = 0; i < set.length; i++) {\n let other = set[i];\n if (this.eq(other))\n return set;\n if (this.type.excludes(other.type)) {\n if (!copy)\n copy = set.slice(0, i);\n }\n else if (other.type.excludes(this.type)) {\n return set;\n }\n else {\n if (!placed && other.type.rank > this.type.rank) {\n if (!copy)\n copy = set.slice(0, i);\n copy.push(this);\n placed = true;\n }\n if (copy)\n copy.push(other);\n }\n }\n if (!copy)\n copy = set.slice();\n if (!placed)\n copy.push(this);\n return copy;\n }\n /**\n Remove this mark from the given set, returning a new set. If this\n mark is not in the set, the set itself is returned.\n */\n removeFromSet(set) {\n for (let i = 0; i < set.length; i++)\n if (this.eq(set[i]))\n return set.slice(0, i).concat(set.slice(i + 1));\n return set;\n }\n /**\n Test whether this mark is in the given set of marks.\n */\n isInSet(set) {\n for (let i = 0; i < set.length; i++)\n if (this.eq(set[i]))\n return true;\n return false;\n }\n /**\n Test whether this mark has the same type and attributes as\n another mark.\n */\n eq(other) {\n return this == other ||\n (this.type == other.type && compareDeep(this.attrs, other.attrs));\n }\n /**\n Convert this mark to a JSON-serializeable representation.\n */\n toJSON() {\n let obj = { type: this.type.name };\n for (let _ in this.attrs) {\n obj.attrs = this.attrs;\n break;\n }\n return obj;\n }\n /**\n Deserialize a mark from JSON.\n */\n static fromJSON(schema, json) {\n if (!json)\n throw new RangeError(\"Invalid input for Mark.fromJSON\");\n let type = schema.marks[json.type];\n if (!type)\n throw new RangeError(`There is no mark type ${json.type} in this schema`);\n let mark = type.create(json.attrs);\n type.checkAttrs(mark.attrs);\n return mark;\n }\n /**\n Test whether two sets of marks are identical.\n */\n static sameSet(a, b) {\n if (a == b)\n return true;\n if (a.length != b.length)\n return false;\n for (let i = 0; i < a.length; i++)\n if (!a[i].eq(b[i]))\n return false;\n return true;\n }\n /**\n Create a properly sorted mark set from null, a single mark, or an\n unsorted array of marks.\n */\n static setFrom(marks) {\n if (!marks || Array.isArray(marks) && marks.length == 0)\n return Mark.none;\n if (marks instanceof Mark)\n return [marks];\n let copy = marks.slice();\n copy.sort((a, b) => a.type.rank - b.type.rank);\n return copy;\n }\n}\n/**\nThe empty set of marks.\n*/\nMark.none = [];\n\n/**\nError type raised by [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) when\ngiven an invalid replacement.\n*/\nclass ReplaceError extends Error {\n}\n/*\nReplaceError = function(this: any, message: string) {\n let err = Error.call(this, message)\n ;(err as any).__proto__ = ReplaceError.prototype\n return err\n} as any\n\nReplaceError.prototype = Object.create(Error.prototype)\nReplaceError.prototype.constructor = ReplaceError\nReplaceError.prototype.name = \"ReplaceError\"\n*/\n/**\nA slice represents a piece cut out of a larger document. It\nstores not only a fragment, but also the depth up to which nodes on\nboth side are ‘open’ (cut through).\n*/\nclass Slice {\n /**\n Create a slice. When specifying a non-zero open depth, you must\n make sure that there are nodes of at least that depth at the\n appropriate side of the fragment—i.e. if the fragment is an\n empty paragraph node, `openStart` and `openEnd` can't be greater\n than 1.\n \n It is not necessary for the content of open nodes to conform to\n the schema's content constraints, though it should be a valid\n start/end/middle for such a node, depending on which sides are\n open.\n */\n constructor(\n /**\n The slice's content.\n */\n content, \n /**\n The open depth at the start of the fragment.\n */\n openStart, \n /**\n The open depth at the end.\n */\n openEnd) {\n this.content = content;\n this.openStart = openStart;\n this.openEnd = openEnd;\n }\n /**\n The size this slice would add when inserted into a document.\n */\n get size() {\n return this.content.size - this.openStart - this.openEnd;\n }\n /**\n @internal\n */\n insertAt(pos, fragment) {\n let content = insertInto(this.content, pos + this.openStart, fragment);\n return content && new Slice(content, this.openStart, this.openEnd);\n }\n /**\n @internal\n */\n removeBetween(from, to) {\n return new Slice(removeRange(this.content, from + this.openStart, to + this.openStart), this.openStart, this.openEnd);\n }\n /**\n Tests whether this slice is equal to another slice.\n */\n eq(other) {\n return this.content.eq(other.content) && this.openStart == other.openStart && this.openEnd == other.openEnd;\n }\n /**\n @internal\n */\n toString() {\n return this.content + \"(\" + this.openStart + \",\" + this.openEnd + \")\";\n }\n /**\n Convert a slice to a JSON-serializable representation.\n */\n toJSON() {\n if (!this.content.size)\n return null;\n let json = { content: this.content.toJSON() };\n if (this.openStart > 0)\n json.openStart = this.openStart;\n if (this.openEnd > 0)\n json.openEnd = this.openEnd;\n return json;\n }\n /**\n Deserialize a slice from its JSON representation.\n */\n static fromJSON(schema, json) {\n if (!json)\n return Slice.empty;\n let openStart = json.openStart || 0, openEnd = json.openEnd || 0;\n if (typeof openStart != \"number\" || typeof openEnd != \"number\")\n throw new RangeError(\"Invalid input for Slice.fromJSON\");\n return new Slice(Fragment.fromJSON(schema, json.content), openStart, openEnd);\n }\n /**\n Create a slice from a fragment by taking the maximum possible\n open value on both side of the fragment.\n */\n static maxOpen(fragment, openIsolating = true) {\n let openStart = 0, openEnd = 0;\n for (let n = fragment.firstChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.firstChild)\n openStart++;\n for (let n = fragment.lastChild; n && !n.isLeaf && (openIsolating || !n.type.spec.isolating); n = n.lastChild)\n openEnd++;\n return new Slice(fragment, openStart, openEnd);\n }\n}\n/**\nThe empty slice.\n*/\nSlice.empty = new Slice(Fragment.empty, 0, 0);\nfunction removeRange(content, from, to) {\n let { index, offset } = content.findIndex(from), child = content.maybeChild(index);\n let { index: indexTo, offset: offsetTo } = content.findIndex(to);\n if (offset == from || child.isText) {\n if (offsetTo != to && !content.child(indexTo).isText)\n throw new RangeError(\"Removing non-flat range\");\n return content.cut(0, from).append(content.cut(to));\n }\n if (index != indexTo)\n throw new RangeError(\"Removing non-flat range\");\n return content.replaceChild(index, child.copy(removeRange(child.content, from - offset - 1, to - offset - 1)));\n}\nfunction insertInto(content, dist, insert, parent) {\n let { index, offset } = content.findIndex(dist), child = content.maybeChild(index);\n if (offset == dist || child.isText) {\n if (parent && !parent.canReplace(index, index, insert))\n return null;\n return content.cut(0, dist).append(insert).append(content.cut(dist));\n }\n let inner = insertInto(child.content, dist - offset - 1, insert, child);\n return inner && content.replaceChild(index, child.copy(inner));\n}\nfunction replace($from, $to, slice) {\n if (slice.openStart > $from.depth)\n throw new ReplaceError(\"Inserted content deeper than insertion position\");\n if ($from.depth - slice.openStart != $to.depth - slice.openEnd)\n throw new ReplaceError(\"Inconsistent open depths\");\n return replaceOuter($from, $to, slice, 0);\n}\nfunction replaceOuter($from, $to, slice, depth) {\n let index = $from.index(depth), node = $from.node(depth);\n if (index == $to.index(depth) && depth < $from.depth - slice.openStart) {\n let inner = replaceOuter($from, $to, slice, depth + 1);\n return node.copy(node.content.replaceChild(index, inner));\n }\n else if (!slice.content.size) {\n return close(node, replaceTwoWay($from, $to, depth));\n }\n else if (!slice.openStart && !slice.openEnd && $from.depth == depth && $to.depth == depth) { // Simple, flat case\n let parent = $from.parent, content = parent.content;\n return close(parent, content.cut(0, $from.parentOffset).append(slice.content).append(content.cut($to.parentOffset)));\n }\n else {\n let { start, end } = prepareSliceForReplace(slice, $from);\n return close(node, replaceThreeWay($from, start, end, $to, depth));\n }\n}\nfunction checkJoin(main, sub) {\n if (!sub.type.compatibleContent(main.type))\n throw new ReplaceError(\"Cannot join \" + sub.type.name + \" onto \" + main.type.name);\n}\nfunction joinable($before, $after, depth) {\n let node = $before.node(depth);\n checkJoin(node, $after.node(depth));\n return node;\n}\nfunction addNode(child, target) {\n let last = target.length - 1;\n if (last >= 0 && child.isText && child.sameMarkup(target[last]))\n target[last] = child.withText(target[last].text + child.text);\n else\n target.push(child);\n}\nfunction addRange($start, $end, depth, target) {\n let node = ($end || $start).node(depth);\n let startIndex = 0, endIndex = $end ? $end.index(depth) : node.childCount;\n if ($start) {\n startIndex = $start.index(depth);\n if ($start.depth > depth) {\n startIndex++;\n }\n else if ($start.textOffset) {\n addNode($start.nodeAfter, target);\n startIndex++;\n }\n }\n for (let i = startIndex; i < endIndex; i++)\n addNode(node.child(i), target);\n if ($end && $end.depth == depth && $end.textOffset)\n addNode($end.nodeBefore, target);\n}\nfunction close(node, content) {\n node.type.checkContent(content);\n return node.copy(content);\n}\nfunction replaceThreeWay($from, $start, $end, $to, depth) {\n let openStart = $from.depth > depth && joinable($from, $start, depth + 1);\n let openEnd = $to.depth > depth && joinable($end, $to, depth + 1);\n let content = [];\n addRange(null, $from, depth, content);\n if (openStart && openEnd && $start.index(depth) == $end.index(depth)) {\n checkJoin(openStart, openEnd);\n addNode(close(openStart, replaceThreeWay($from, $start, $end, $to, depth + 1)), content);\n }\n else {\n if (openStart)\n addNode(close(openStart, replaceTwoWay($from, $start, depth + 1)), content);\n addRange($start, $end, depth, content);\n if (openEnd)\n addNode(close(openEnd, replaceTwoWay($end, $to, depth + 1)), content);\n }\n addRange($to, null, depth, content);\n return new Fragment(content);\n}\nfunction replaceTwoWay($from, $to, depth) {\n let content = [];\n addRange(null, $from, depth, content);\n if ($from.depth > depth) {\n let type = joinable($from, $to, depth + 1);\n addNode(close(type, replaceTwoWay($from, $to, depth + 1)), content);\n }\n addRange($to, null, depth, content);\n return new Fragment(content);\n}\nfunction prepareSliceForReplace(slice, $along) {\n let extra = $along.depth - slice.openStart, parent = $along.node(extra);\n let node = parent.copy(slice.content);\n for (let i = extra - 1; i >= 0; i--)\n node = $along.node(i).copy(Fragment.from(node));\n return { start: node.resolveNoCache(slice.openStart + extra),\n end: node.resolveNoCache(node.content.size - slice.openEnd - extra) };\n}\n\n/**\nYou can [_resolve_](https://prosemirror.net/docs/ref/#model.Node.resolve) a position to get more\ninformation about it. Objects of this class represent such a\nresolved position, providing various pieces of context\ninformation, and some helper methods.\n\nThroughout this interface, methods that take an optional `depth`\nparameter will interpret undefined as `this.depth` and negative\nnumbers as `this.depth + value`.\n*/\nclass ResolvedPos {\n /**\n @internal\n */\n constructor(\n /**\n The position that was resolved.\n */\n pos, \n /**\n @internal\n */\n path, \n /**\n The offset this position has into its parent node.\n */\n parentOffset) {\n this.pos = pos;\n this.path = path;\n this.parentOffset = parentOffset;\n this.depth = path.length / 3 - 1;\n }\n /**\n @internal\n */\n resolveDepth(val) {\n if (val == null)\n return this.depth;\n if (val < 0)\n return this.depth + val;\n return val;\n }\n /**\n The parent node that the position points into. Note that even if\n a position points into a text node, that node is not considered\n the parent—text nodes are ‘flat’ in this model, and have no content.\n */\n get parent() { return this.node(this.depth); }\n /**\n The root node in which the position was resolved.\n */\n get doc() { return this.node(0); }\n /**\n The ancestor node at the given level. `p.node(p.depth)` is the\n same as `p.parent`.\n */\n node(depth) { return this.path[this.resolveDepth(depth) * 3]; }\n /**\n The index into the ancestor at the given level. If this points\n at the 3rd node in the 2nd paragraph on the top level, for\n example, `p.index(0)` is 1 and `p.index(1)` is 2.\n */\n index(depth) { return this.path[this.resolveDepth(depth) * 3 + 1]; }\n /**\n The index pointing after this position into the ancestor at the\n given level.\n */\n indexAfter(depth) {\n depth = this.resolveDepth(depth);\n return this.index(depth) + (depth == this.depth && !this.textOffset ? 0 : 1);\n }\n /**\n The (absolute) position at the start of the node at the given\n level.\n */\n start(depth) {\n depth = this.resolveDepth(depth);\n return depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;\n }\n /**\n The (absolute) position at the end of the node at the given\n level.\n */\n end(depth) {\n depth = this.resolveDepth(depth);\n return this.start(depth) + this.node(depth).content.size;\n }\n /**\n The (absolute) position directly before the wrapping node at the\n given level, or, when `depth` is `this.depth + 1`, the original\n position.\n */\n before(depth) {\n depth = this.resolveDepth(depth);\n if (!depth)\n throw new RangeError(\"There is no position before the top-level node\");\n return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1];\n }\n /**\n The (absolute) position directly after the wrapping node at the\n given level, or the original position when `depth` is `this.depth + 1`.\n */\n after(depth) {\n depth = this.resolveDepth(depth);\n if (!depth)\n throw new RangeError(\"There is no position after the top-level node\");\n return depth == this.depth + 1 ? this.pos : this.path[depth * 3 - 1] + this.path[depth * 3].nodeSize;\n }\n /**\n When this position points into a text node, this returns the\n distance between the position and the start of the text node.\n Will be zero for positions that point between nodes.\n */\n get textOffset() { return this.pos - this.path[this.path.length - 1]; }\n /**\n Get the node directly after the position, if any. If the position\n points into a text node, only the part of that node after the\n position is returned.\n */\n get nodeAfter() {\n let parent = this.parent, index = this.index(this.depth);\n if (index == parent.childCount)\n return null;\n let dOff = this.pos - this.path[this.path.length - 1], child = parent.child(index);\n return dOff ? parent.child(index).cut(dOff) : child;\n }\n /**\n Get the node directly before the position, if any. If the\n position points into a text node, only the part of that node\n before the position is returned.\n */\n get nodeBefore() {\n let index = this.index(this.depth);\n let dOff = this.pos - this.path[this.path.length - 1];\n if (dOff)\n return this.parent.child(index).cut(0, dOff);\n return index == 0 ? null : this.parent.child(index - 1);\n }\n /**\n Get the position at the given index in the parent node at the\n given depth (which defaults to `this.depth`).\n */\n posAtIndex(index, depth) {\n depth = this.resolveDepth(depth);\n let node = this.path[depth * 3], pos = depth == 0 ? 0 : this.path[depth * 3 - 1] + 1;\n for (let i = 0; i < index; i++)\n pos += node.child(i).nodeSize;\n return pos;\n }\n /**\n Get the marks at this position, factoring in the surrounding\n marks' [`inclusive`](https://prosemirror.net/docs/ref/#model.MarkSpec.inclusive) property. If the\n position is at the start of a non-empty node, the marks of the\n node after it (if any) are returned.\n */\n marks() {\n let parent = this.parent, index = this.index();\n // In an empty parent, return the empty array\n if (parent.content.size == 0)\n return Mark.none;\n // When inside a text node, just return the text node's marks\n if (this.textOffset)\n return parent.child(index).marks;\n let main = parent.maybeChild(index - 1), other = parent.maybeChild(index);\n // If the `after` flag is true of there is no node before, make\n // the node after this position the main reference.\n if (!main) {\n let tmp = main;\n main = other;\n other = tmp;\n }\n // Use all marks in the main node, except those that have\n // `inclusive` set to false and are not present in the other node.\n let marks = main.marks;\n for (var i = 0; i < marks.length; i++)\n if (marks[i].type.spec.inclusive === false && (!other || !marks[i].isInSet(other.marks)))\n marks = marks[i--].removeFromSet(marks);\n return marks;\n }\n /**\n Get the marks after the current position, if any, except those\n that are non-inclusive and not present at position `$end`. This\n is mostly useful for getting the set of marks to preserve after a\n deletion. Will return `null` if this position is at the end of\n its parent node or its parent node isn't a textblock (in which\n case no marks should be preserved).\n */\n marksAcross($end) {\n let after = this.parent.maybeChild(this.index());\n if (!after || !after.isInline)\n return null;\n let marks = after.marks, next = $end.parent.maybeChild($end.index());\n for (var i = 0; i < marks.length; i++)\n if (marks[i].type.spec.inclusive === false && (!next || !marks[i].isInSet(next.marks)))\n marks = marks[i--].removeFromSet(marks);\n return marks;\n }\n /**\n The depth up to which this position and the given (non-resolved)\n position share the same parent nodes.\n */\n sharedDepth(pos) {\n for (let depth = this.depth; depth > 0; depth--)\n if (this.start(depth) <= pos && this.end(depth) >= pos)\n return depth;\n return 0;\n }\n /**\n Returns a range based on the place where this position and the\n given position diverge around block content. If both point into\n the same textblock, for example, a range around that textblock\n will be returned. If they point into different blocks, the range\n around those blocks in their shared ancestor is returned. You can\n pass in an optional predicate that will be called with a parent\n node to see if a range into that parent is acceptable.\n */\n blockRange(other = this, pred) {\n if (other.pos < this.pos)\n return other.blockRange(this);\n for (let d = this.depth - (this.parent.inlineContent || this.pos == other.pos ? 1 : 0); d >= 0; d--)\n if (other.pos <= this.end(d) && (!pred || pred(this.node(d))))\n return new NodeRange(this, other, d);\n return null;\n }\n /**\n Query whether the given position shares the same parent node.\n */\n sameParent(other) {\n return this.pos - this.parentOffset == other.pos - other.parentOffset;\n }\n /**\n Return the greater of this and the given position.\n */\n max(other) {\n return other.pos > this.pos ? other : this;\n }\n /**\n Return the smaller of this and the given position.\n */\n min(other) {\n return other.pos < this.pos ? other : this;\n }\n /**\n @internal\n */\n toString() {\n let str = \"\";\n for (let i = 1; i <= this.depth; i++)\n str += (str ? \"/\" : \"\") + this.node(i).type.name + \"_\" + this.index(i - 1);\n return str + \":\" + this.parentOffset;\n }\n /**\n @internal\n */\n static resolve(doc, pos) {\n if (!(pos >= 0 && pos <= doc.content.size))\n throw new RangeError(\"Position \" + pos + \" out of range\");\n let path = [];\n let start = 0, parentOffset = pos;\n for (let node = doc;;) {\n let { index, offset } = node.content.findIndex(parentOffset);\n let rem = parentOffset - offset;\n path.push(node, index, start + offset);\n if (!rem)\n break;\n node = node.child(index);\n if (node.isText)\n break;\n parentOffset = rem - 1;\n start += offset + 1;\n }\n return new ResolvedPos(pos, path, parentOffset);\n }\n /**\n @internal\n */\n static resolveCached(doc, pos) {\n let cache = resolveCache.get(doc);\n if (cache) {\n for (let i = 0; i < cache.elts.length; i++) {\n let elt = cache.elts[i];\n if (elt.pos == pos)\n return elt;\n }\n }\n else {\n resolveCache.set(doc, cache = new ResolveCache);\n }\n let result = cache.elts[cache.i] = ResolvedPos.resolve(doc, pos);\n cache.i = (cache.i + 1) % resolveCacheSize;\n return result;\n }\n}\nclass ResolveCache {\n constructor() {\n this.elts = [];\n this.i = 0;\n }\n}\nconst resolveCacheSize = 12, resolveCache = new WeakMap();\n/**\nRepresents a flat range of content, i.e. one that starts and\nends in the same node.\n*/\nclass NodeRange {\n /**\n Construct a node range. `$from` and `$to` should point into the\n same node until at least the given `depth`, since a node range\n denotes an adjacent set of nodes in a single parent node.\n */\n constructor(\n /**\n A resolved position along the start of the content. May have a\n `depth` greater than this object's `depth` property, since\n these are the positions that were used to compute the range,\n not re-resolved positions directly at its boundaries.\n */\n $from, \n /**\n A position along the end of the content. See\n caveat for [`$from`](https://prosemirror.net/docs/ref/#model.NodeRange.$from).\n */\n $to, \n /**\n The depth of the node that this range points into.\n */\n depth) {\n this.$from = $from;\n this.$to = $to;\n this.depth = depth;\n }\n /**\n The position at the start of the range.\n */\n get start() { return this.$from.before(this.depth + 1); }\n /**\n The position at the end of the range.\n */\n get end() { return this.$to.after(this.depth + 1); }\n /**\n The parent node that the range points into.\n */\n get parent() { return this.$from.node(this.depth); }\n /**\n The start index of the range in the parent node.\n */\n get startIndex() { return this.$from.index(this.depth); }\n /**\n The end index of the range in the parent node.\n */\n get endIndex() { return this.$to.indexAfter(this.depth); }\n}\n\nconst emptyAttrs = Object.create(null);\n/**\nThis class represents a node in the tree that makes up a\nProseMirror document. So a document is an instance of `Node`, with\nchildren that are also instances of `Node`.\n\nNodes are persistent data structures. Instead of changing them, you\ncreate new ones with the content you want. Old ones keep pointing\nat the old document shape. This is made cheaper by sharing\nstructure between the old and new data as much as possible, which a\ntree shape like this (without back pointers) makes easy.\n\n**Do not** directly mutate the properties of a `Node` object. See\n[the guide](https://prosemirror.net/docs/guide/#doc) for more information.\n*/\nclass Node {\n /**\n @internal\n */\n constructor(\n /**\n The type of node that this is.\n */\n type, \n /**\n An object mapping attribute names to values. The kind of\n attributes allowed and required are\n [determined](https://prosemirror.net/docs/ref/#model.NodeSpec.attrs) by the node type.\n */\n attrs, \n // A fragment holding the node's children.\n content, \n /**\n The marks (things like whether it is emphasized or part of a\n link) applied to this node.\n */\n marks = Mark.none) {\n this.type = type;\n this.attrs = attrs;\n this.marks = marks;\n this.content = content || Fragment.empty;\n }\n /**\n The array of this node's child nodes.\n */\n get children() { return this.content.content; }\n /**\n The size of this node, as defined by the integer-based [indexing\n scheme](https://prosemirror.net/docs/guide/#doc.indexing). For text nodes, this is the\n amount of characters. For other leaf nodes, it is one. For\n non-leaf nodes, it is the size of the content plus two (the\n start and end token).\n */\n get nodeSize() { return this.isLeaf ? 1 : 2 + this.content.size; }\n /**\n The number of children that the node has.\n */\n get childCount() { return this.content.childCount; }\n /**\n Get the child node at the given index. Raises an error when the\n index is out of range.\n */\n child(index) { return this.content.child(index); }\n /**\n Get the child node at the given index, if it exists.\n */\n maybeChild(index) { return this.content.maybeChild(index); }\n /**\n Call `f` for every child node, passing the node, its offset\n into this parent node, and its index.\n */\n forEach(f) { this.content.forEach(f); }\n /**\n Invoke a callback for all descendant nodes recursively between\n the given two positions that are relative to start of this\n node's content. The callback is invoked with the node, its\n position relative to the original node (method receiver),\n its parent node, and its child index. When the callback returns\n false for a given node, that node's children will not be\n recursed over. The last parameter can be used to specify a\n starting position to count from.\n */\n nodesBetween(from, to, f, startPos = 0) {\n this.content.nodesBetween(from, to, f, startPos, this);\n }\n /**\n Call the given callback for every descendant node. Doesn't\n descend into a node when the callback returns `false`.\n */\n descendants(f) {\n this.nodesBetween(0, this.content.size, f);\n }\n /**\n Concatenates all the text nodes found in this fragment and its\n children.\n */\n get textContent() {\n return (this.isLeaf && this.type.spec.leafText)\n ? this.type.spec.leafText(this)\n : this.textBetween(0, this.content.size, \"\");\n }\n /**\n Get all text between positions `from` and `to`. When\n `blockSeparator` is given, it will be inserted to separate text\n from different block nodes. If `leafText` is given, it'll be\n inserted for every non-text leaf node encountered, otherwise\n [`leafText`](https://prosemirror.net/docs/ref/#model.NodeSpec.leafText) will be used.\n */\n textBetween(from, to, blockSeparator, leafText) {\n return this.content.textBetween(from, to, blockSeparator, leafText);\n }\n /**\n Returns this node's first child, or `null` if there are no\n children.\n */\n get firstChild() { return this.content.firstChild; }\n /**\n Returns this node's last child, or `null` if there are no\n children.\n */\n get lastChild() { return this.content.lastChild; }\n /**\n Test whether two nodes represent the same piece of document.\n */\n eq(other) {\n return this == other || (this.sameMarkup(other) && this.content.eq(other.content));\n }\n /**\n Compare the markup (type, attributes, and marks) of this node to\n those of another. Returns `true` if both have the same markup.\n */\n sameMarkup(other) {\n return this.hasMarkup(other.type, other.attrs, other.marks);\n }\n /**\n Check whether this node's markup correspond to the given type,\n attributes, and marks.\n */\n hasMarkup(type, attrs, marks) {\n return this.type == type &&\n compareDeep(this.attrs, attrs || type.defaultAttrs || emptyAttrs) &&\n Mark.sameSet(this.marks, marks || Mark.none);\n }\n /**\n Create a new node with the same markup as this node, containing\n the given content (or empty, if no content is given).\n */\n copy(content = null) {\n if (content == this.content)\n return this;\n return new Node(this.type, this.attrs, content, this.marks);\n }\n /**\n Create a copy of this node, with the given set of marks instead\n of the node's own marks.\n */\n mark(marks) {\n return marks == this.marks ? this : new Node(this.type, this.attrs, this.content, marks);\n }\n /**\n Create a copy of this node with only the content between the\n given positions. If `to` is not given, it defaults to the end of\n the node.\n */\n cut(from, to = this.content.size) {\n if (from == 0 && to == this.content.size)\n return this;\n return this.copy(this.content.cut(from, to));\n }\n /**\n Cut out the part of the document between the given positions, and\n return it as a `Slice` object.\n */\n slice(from, to = this.content.size, includeParents = false) {\n if (from == to)\n return Slice.empty;\n let $from = this.resolve(from), $to = this.resolve(to);\n let depth = includeParents ? 0 : $from.sharedDepth(to);\n let start = $from.start(depth), node = $from.node(depth);\n let content = node.content.cut($from.pos - start, $to.pos - start);\n return new Slice(content, $from.depth - depth, $to.depth - depth);\n }\n /**\n Replace the part of the document between the given positions with\n the given slice. The slice must 'fit', meaning its open sides\n must be able to connect to the surrounding content, and its\n content nodes must be valid children for the node they are placed\n into. If any of this is violated, an error of type\n [`ReplaceError`](https://prosemirror.net/docs/ref/#model.ReplaceError) is thrown.\n */\n replace(from, to, slice) {\n return replace(this.resolve(from), this.resolve(to), slice);\n }\n /**\n Find the node directly after the given position.\n */\n nodeAt(pos) {\n for (let node = this;;) {\n let { index, offset } = node.content.findIndex(pos);\n node = node.maybeChild(index);\n if (!node)\n return null;\n if (offset == pos || node.isText)\n return node;\n pos -= offset + 1;\n }\n }\n /**\n Find the (direct) child node after the given offset, if any,\n and return it along with its index and offset relative to this\n node.\n */\n childAfter(pos) {\n let { index, offset } = this.content.findIndex(pos);\n return { node: this.content.maybeChild(index), index, offset };\n }\n /**\n Find the (direct) child node before the given offset, if any,\n and return it along with its index and offset relative to this\n node.\n */\n childBefore(pos) {\n if (pos == 0)\n return { node: null, index: 0, offset: 0 };\n let { index, offset } = this.content.findIndex(pos);\n if (offset < pos)\n return { node: this.content.child(index), index, offset };\n let node = this.content.child(index - 1);\n return { node, index: index - 1, offset: offset - node.nodeSize };\n }\n /**\n Resolve the given position in the document, returning an\n [object](https://prosemirror.net/docs/ref/#model.ResolvedPos) with information about its context.\n */\n resolve(pos) { return ResolvedPos.resolveCached(this, pos); }\n /**\n @internal\n */\n resolveNoCache(pos) { return ResolvedPos.resolve(this, pos); }\n /**\n Test whether a given mark or mark type occurs in this document\n between the two given positions.\n */\n rangeHasMark(from, to, type) {\n let found = false;\n if (to > from)\n this.nodesBetween(from, to, node => {\n if (type.isInSet(node.marks))\n found = true;\n return !found;\n });\n return found;\n }\n /**\n True when this is a block (non-inline node)\n */\n get isBlock() { return this.type.isBlock; }\n /**\n True when this is a textblock node, a block node with inline\n content.\n */\n get isTextblock() { return this.type.isTextblock; }\n /**\n True when this node allows inline content.\n */\n get inlineContent() { return this.type.inlineContent; }\n /**\n True when this is an inline node (a text node or a node that can\n appear among text).\n */\n get isInline() { return this.type.isInline; }\n /**\n True when this is a text node.\n */\n get isText() { return this.type.isText; }\n /**\n True when this is a leaf node.\n */\n get isLeaf() { return this.type.isLeaf; }\n /**\n True when this is an atom, i.e. when it does not have directly\n editable content. This is usually the same as `isLeaf`, but can\n be configured with the [`atom` property](https://prosemirror.net/docs/ref/#model.NodeSpec.atom)\n on a node's spec (typically used when the node is displayed as\n an uneditable [node view](https://prosemirror.net/docs/ref/#view.NodeView)).\n */\n get isAtom() { return this.type.isAtom; }\n /**\n Return a string representation of this node for debugging\n purposes.\n */\n toString() {\n if (this.type.spec.toDebugString)\n return this.type.spec.toDebugString(this);\n let name = this.type.name;\n if (this.content.size)\n name += \"(\" + this.content.toStringInner() + \")\";\n return wrapMarks(this.marks, name);\n }\n /**\n Get the content match in this node at the given index.\n */\n contentMatchAt(index) {\n let match = this.type.contentMatch.matchFragment(this.content, 0, index);\n if (!match)\n throw new Error(\"Called contentMatchAt on a node with invalid content\");\n return match;\n }\n /**\n Test whether replacing the range between `from` and `to` (by\n child index) with the given replacement fragment (which defaults\n to the empty fragment) would leave the node's content valid. You\n can optionally pass `start` and `end` indices into the\n replacement fragment.\n */\n canReplace(from, to, replacement = Fragment.empty, start = 0, end = replacement.childCount) {\n let one = this.contentMatchAt(from).matchFragment(replacement, start, end);\n let two = one && one.matchFragment(this.content, to);\n if (!two || !two.validEnd)\n return false;\n for (let i = start; i < end; i++)\n if (!this.type.allowsMarks(replacement.child(i).marks))\n return false;\n return true;\n }\n /**\n Test whether replacing the range `from` to `to` (by index) with\n a node of the given type would leave the node's content valid.\n */\n canReplaceWith(from, to, type, marks) {\n if (marks && !this.type.allowsMarks(marks))\n return false;\n let start = this.contentMatchAt(from).matchType(type);\n let end = start && start.matchFragment(this.content, to);\n return end ? end.validEnd : false;\n }\n /**\n Test whether the given node's content could be appended to this\n node. If that node is empty, this will only return true if there\n is at least one node type that can appear in both nodes (to avoid\n merging completely incompatible nodes).\n */\n canAppend(other) {\n if (other.content.size)\n return this.canReplace(this.childCount, this.childCount, other.content);\n else\n return this.type.compatibleContent(other.type);\n }\n /**\n Check whether this node and its descendants conform to the\n schema, and raise an exception when they do not.\n */\n check() {\n this.type.checkContent(this.content);\n this.type.checkAttrs(this.attrs);\n let copy = Mark.none;\n for (let i = 0; i < this.marks.length; i++) {\n let mark = this.marks[i];\n mark.type.checkAttrs(mark.attrs);\n copy = mark.addToSet(copy);\n }\n if (!Mark.sameSet(copy, this.marks))\n throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(m => m.type.name)}`);\n this.content.forEach(node => node.check());\n }\n /**\n Return a JSON-serializeable representation of this node.\n */\n toJSON() {\n let obj = { type: this.type.name };\n for (let _ in this.attrs) {\n obj.attrs = this.attrs;\n break;\n }\n if (this.content.size)\n obj.content = this.content.toJSON();\n if (this.marks.length)\n obj.marks = this.marks.map(n => n.toJSON());\n return obj;\n }\n /**\n Deserialize a node from its JSON representation.\n */\n static fromJSON(schema, json) {\n if (!json)\n throw new RangeError(\"Invalid input for Node.fromJSON\");\n let marks = undefined;\n if (json.marks) {\n if (!Array.isArray(json.marks))\n throw new RangeError(\"Invalid mark data for Node.fromJSON\");\n marks = json.marks.map(schema.markFromJSON);\n }\n if (json.type == \"text\") {\n if (typeof json.text != \"string\")\n throw new RangeError(\"Invalid text node in JSON\");\n return schema.text(json.text, marks);\n }\n let content = Fragment.fromJSON(schema, json.content);\n let node = schema.nodeType(json.type).create(json.attrs, content, marks);\n node.type.checkAttrs(node.attrs);\n return node;\n }\n}\nNode.prototype.text = undefined;\nclass TextNode extends Node {\n /**\n @internal\n */\n constructor(type, attrs, content, marks) {\n super(type, attrs, null, marks);\n if (!content)\n throw new RangeError(\"Empty text nodes are not allowed\");\n this.text = content;\n }\n toString() {\n if (this.type.spec.toDebugString)\n return this.type.spec.toDebugString(this);\n return wrapMarks(this.marks, JSON.stringify(this.text));\n }\n get textContent() { return this.text; }\n textBetween(from, to) { return this.text.slice(from, to); }\n get nodeSize() { return this.text.length; }\n mark(marks) {\n return marks == this.marks ? this : new TextNode(this.type, this.attrs, this.text, marks);\n }\n withText(text) {\n if (text == this.text)\n return this;\n return new TextNode(this.type, this.attrs, text, this.marks);\n }\n cut(from = 0, to = this.text.length) {\n if (from == 0 && to == this.text.length)\n return this;\n return this.withText(this.text.slice(from, to));\n }\n eq(other) {\n return this.sameMarkup(other) && this.text == other.text;\n }\n toJSON() {\n let base = super.toJSON();\n base.text = this.text;\n return base;\n }\n}\nfunction wrapMarks(marks, str) {\n for (let i = marks.length - 1; i >= 0; i--)\n str = marks[i].type.name + \"(\" + str + \")\";\n return str;\n}\n\n/**\nInstances of this class represent a match state of a node type's\n[content expression](https://prosemirror.net/docs/ref/#model.NodeSpec.content), and can be used to\nfind out whether further content matches here, and whether a given\nposition is a valid end of the node.\n*/\nclass ContentMatch {\n /**\n @internal\n */\n constructor(\n /**\n True when this match state represents a valid end of the node.\n */\n validEnd) {\n this.validEnd = validEnd;\n /**\n @internal\n */\n this.next = [];\n /**\n @internal\n */\n this.wrapCache = [];\n }\n /**\n @internal\n */\n static parse(string, nodeTypes) {\n let stream = new TokenStream(string, nodeTypes);\n if (stream.next == null)\n return ContentMatch.empty;\n let expr = parseExpr(stream);\n if (stream.next)\n stream.err(\"Unexpected trailing text\");\n let match = dfa(nfa(expr));\n checkForDeadEnds(match, stream);\n return match;\n }\n /**\n Match a node type, returning a match after that node if\n successful.\n */\n matchType(type) {\n for (let i = 0; i < this.next.length; i++)\n if (this.next[i].type == type)\n return this.next[i].next;\n return null;\n }\n /**\n Try to match a fragment. Returns the resulting match when\n successful.\n */\n matchFragment(frag, start = 0, end = frag.childCount) {\n let cur = this;\n for (let i = start; cur && i < end; i++)\n cur = cur.matchType(frag.child(i).type);\n return cur;\n }\n /**\n @internal\n */\n get inlineContent() {\n return this.next.length != 0 && this.next[0].type.isInline;\n }\n /**\n Get the first matching node type at this match position that can\n be generated.\n */\n get defaultType() {\n for (let i = 0; i < this.next.length; i++) {\n let { type } = this.next[i];\n if (!(type.isText || type.hasRequiredAttrs()))\n return type;\n }\n return null;\n }\n /**\n @internal\n */\n compatible(other) {\n for (let i = 0; i < this.next.length; i++)\n for (let j = 0; j < other.next.length; j++)\n if (this.next[i].type == other.next[j].type)\n return true;\n return false;\n }\n /**\n Try to match the given fragment, and if that fails, see if it can\n be made to match by inserting nodes in front of it. When\n successful, return a fragment of inserted nodes (which may be\n empty if nothing had to be inserted). When `toEnd` is true, only\n return a fragment if the resulting match goes to the end of the\n content expression.\n */\n fillBefore(after, toEnd = false, startIndex = 0) {\n let seen = [this];\n function search(match, types) {\n let finished = match.matchFragment(after, startIndex);\n if (finished && (!toEnd || finished.validEnd))\n return Fragment.from(types.map(tp => tp.createAndFill()));\n for (let i = 0; i < match.next.length; i++) {\n let { type, next } = match.next[i];\n if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) {\n seen.push(next);\n let found = search(next, types.concat(type));\n if (found)\n return found;\n }\n }\n return null;\n }\n return search(this, []);\n }\n /**\n Find a set of wrapping node types that would allow a node of the\n given type to appear at this position. The result may be empty\n (when it fits directly) and will be null when no such wrapping\n exists.\n */\n findWrapping(target) {\n for (let i = 0; i < this.wrapCache.length; i += 2)\n if (this.wrapCache[i] == target)\n return this.wrapCache[i + 1];\n let computed = this.computeWrapping(target);\n this.wrapCache.push(target, computed);\n return computed;\n }\n /**\n @internal\n */\n computeWrapping(target) {\n let seen = Object.create(null), active = [{ match: this, type: null, via: null }];\n while (active.length) {\n let current = active.shift(), match = current.match;\n if (match.matchType(target)) {\n let result = [];\n for (let obj = current; obj.type; obj = obj.via)\n result.push(obj.type);\n return result.reverse();\n }\n for (let i = 0; i < match.next.length; i++) {\n let { type, next } = match.next[i];\n if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) {\n active.push({ match: type.contentMatch, type, via: current });\n seen[type.name] = true;\n }\n }\n }\n return null;\n }\n /**\n The number of outgoing edges this node has in the finite\n automaton that describes the content expression.\n */\n get edgeCount() {\n return this.next.length;\n }\n /**\n Get the _n_th outgoing edge from this node in the finite\n automaton that describes the content expression.\n */\n edge(n) {\n if (n >= this.next.length)\n throw new RangeError(`There's no ${n}th edge in this content match`);\n return this.next[n];\n }\n /**\n @internal\n */\n toString() {\n let seen = [];\n function scan(m) {\n seen.push(m);\n for (let i = 0; i < m.next.length; i++)\n if (seen.indexOf(m.next[i].next) == -1)\n scan(m.next[i].next);\n }\n scan(this);\n return seen.map((m, i) => {\n let out = i + (m.validEnd ? \"*\" : \" \") + \" \";\n for (let i = 0; i < m.next.length; i++)\n out += (i ? \", \" : \"\") + m.next[i].type.name + \"->\" + seen.indexOf(m.next[i].next);\n return out;\n }).join(\"\\n\");\n }\n}\n/**\n@internal\n*/\nContentMatch.empty = new ContentMatch(true);\nclass TokenStream {\n constructor(string, nodeTypes) {\n this.string = string;\n this.nodeTypes = nodeTypes;\n this.inline = null;\n this.pos = 0;\n this.tokens = string.split(/\\s*(?=\\b|\\W|$)/);\n if (this.tokens[this.tokens.length - 1] == \"\")\n this.tokens.pop();\n if (this.tokens[0] == \"\")\n this.tokens.shift();\n }\n get next() { return this.tokens[this.pos]; }\n eat(tok) { return this.next == tok && (this.pos++ || true); }\n err(str) { throw new SyntaxError(str + \" (in content expression '\" + this.string + \"')\"); }\n}\nfunction parseExpr(stream) {\n let exprs = [];\n do {\n exprs.push(parseExprSeq(stream));\n } while (stream.eat(\"|\"));\n return exprs.length == 1 ? exprs[0] : { type: \"choice\", exprs };\n}\nfunction parseExprSeq(stream) {\n let exprs = [];\n do {\n exprs.push(parseExprSubscript(stream));\n } while (stream.next && stream.next != \")\" && stream.next != \"|\");\n return exprs.length == 1 ? exprs[0] : { type: \"seq\", exprs };\n}\nfunction parseExprSubscript(stream) {\n let expr = parseExprAtom(stream);\n for (;;) {\n if (stream.eat(\"+\"))\n expr = { type: \"plus\", expr };\n else if (stream.eat(\"*\"))\n expr = { type: \"star\", expr };\n else if (stream.eat(\"?\"))\n expr = { type: \"opt\", expr };\n else if (stream.eat(\"{\"))\n expr = parseExprRange(stream, expr);\n else\n break;\n }\n return expr;\n}\nfunction parseNum(stream) {\n if (/\\D/.test(stream.next))\n stream.err(\"Expected number, got '\" + stream.next + \"'\");\n let result = Number(stream.next);\n stream.pos++;\n return result;\n}\nfunction parseExprRange(stream, expr) {\n let min = parseNum(stream), max = min;\n if (stream.eat(\",\")) {\n if (stream.next != \"}\")\n max = parseNum(stream);\n else\n max = -1;\n }\n if (!stream.eat(\"}\"))\n stream.err(\"Unclosed braced range\");\n return { type: \"range\", min, max, expr };\n}\nfunction resolveName(stream, name) {\n let types = stream.nodeTypes, type = types[name];\n if (type)\n return [type];\n let result = [];\n for (let typeName in types) {\n let type = types[typeName];\n if (type.isInGroup(name))\n result.push(type);\n }\n if (result.length == 0)\n stream.err(\"No node type or group '\" + name + \"' found\");\n return result;\n}\nfunction parseExprAtom(stream) {\n if (stream.eat(\"(\")) {\n let expr = parseExpr(stream);\n if (!stream.eat(\")\"))\n stream.err(\"Missing closing paren\");\n return expr;\n }\n else if (!/\\W/.test(stream.next)) {\n let exprs = resolveName(stream, stream.next).map(type => {\n if (stream.inline == null)\n stream.inline = type.isInline;\n else if (stream.inline != type.isInline)\n stream.err(\"Mixing inline and block content\");\n return { type: \"name\", value: type };\n });\n stream.pos++;\n return exprs.length == 1 ? exprs[0] : { type: \"choice\", exprs };\n }\n else {\n stream.err(\"Unexpected token '\" + stream.next + \"'\");\n }\n}\n// Construct an NFA from an expression as returned by the parser. The\n// NFA is represented as an array of states, which are themselves\n// arrays of edges, which are `{term, to}` objects. The first state is\n// the entry state and the last node is the success state.\n//\n// Note that unlike typical NFAs, the edge ordering in this one is\n// significant, in that it is used to contruct filler content when\n// necessary.\nfunction nfa(expr) {\n let nfa = [[]];\n connect(compile(expr, 0), node());\n return nfa;\n function node() { return nfa.push([]) - 1; }\n function edge(from, to, term) {\n let edge = { term, to };\n nfa[from].push(edge);\n return edge;\n }\n function connect(edges, to) {\n edges.forEach(edge => edge.to = to);\n }\n function compile(expr, from) {\n if (expr.type == \"choice\") {\n return expr.exprs.reduce((out, expr) => out.concat(compile(expr, from)), []);\n }\n else if (expr.type == \"seq\") {\n for (let i = 0;; i++) {\n let next = compile(expr.exprs[i], from);\n if (i == expr.exprs.length - 1)\n return next;\n connect(next, from = node());\n }\n }\n else if (expr.type == \"star\") {\n let loop = node();\n edge(from, loop);\n connect(compile(expr.expr, loop), loop);\n return [edge(loop)];\n }\n else if (expr.type == \"plus\") {\n let loop = node();\n connect(compile(expr.expr, from), loop);\n connect(compile(expr.expr, loop), loop);\n return [edge(loop)];\n }\n else if (expr.type == \"opt\") {\n return [edge(from)].concat(compile(expr.expr, from));\n }\n else if (expr.type == \"range\") {\n let cur = from;\n for (let i = 0; i < expr.min; i++) {\n let next = node();\n connect(compile(expr.expr, cur), next);\n cur = next;\n }\n if (expr.max == -1) {\n connect(compile(expr.expr, cur), cur);\n }\n else {\n for (let i = expr.min; i < expr.max; i++) {\n let next = node();\n edge(cur, next);\n connect(compile(expr.expr, cur), next);\n cur = next;\n }\n }\n return [edge(cur)];\n }\n else if (expr.type == \"name\") {\n return [edge(from, undefined, expr.value)];\n }\n else {\n throw new Error(\"Unknown expr type\");\n }\n }\n}\nfunction cmp(a, b) { return b - a; }\n// Get the set of nodes reachable by null edges from `node`. Omit\n// nodes with only a single null-out-edge, since they may lead to\n// needless duplicated nodes.\nfunction nullFrom(nfa, node) {\n let result = [];\n scan(node);\n return result.sort(cmp);\n function scan(node) {\n let edges = nfa[node];\n if (edges.length == 1 && !edges[0].term)\n return scan(edges[0].to);\n result.push(node);\n for (let i = 0; i < edges.length; i++) {\n let { term, to } = edges[i];\n if (!term && result.indexOf(to) == -1)\n scan(to);\n }\n }\n}\n// Compiles an NFA as produced by `nfa` into a DFA, modeled as a set\n// of state objects (`ContentMatch` instances) with transitions\n// between them.\nfunction dfa(nfa) {\n let labeled = Object.create(null);\n return explore(nullFrom(nfa, 0));\n function explore(states) {\n let out = [];\n states.forEach(node => {\n nfa[node].forEach(({ term, to }) => {\n if (!term)\n return;\n let set;\n for (let i = 0; i < out.length; i++)\n if (out[i][0] == term)\n set = out[i][1];\n nullFrom(nfa, to).forEach(node => {\n if (!set)\n out.push([term, set = []]);\n if (set.indexOf(node) == -1)\n set.push(node);\n });\n });\n });\n let state = labeled[states.join(\",\")] = new ContentMatch(states.indexOf(nfa.length - 1) > -1);\n for (let i = 0; i < out.length; i++) {\n let states = out[i][1].sort(cmp);\n state.next.push({ type: out[i][0], next: labeled[states.join(\",\")] || explore(states) });\n }\n return state;\n }\n}\nfunction checkForDeadEnds(match, stream) {\n for (let i = 0, work = [match]; i < work.length; i++) {\n let state = work[i], dead = !state.validEnd, nodes = [];\n for (let j = 0; j < state.next.length; j++) {\n let { type, next } = state.next[j];\n nodes.push(type.name);\n if (dead && !(type.isText || type.hasRequiredAttrs()))\n dead = false;\n if (work.indexOf(next) == -1)\n work.push(next);\n }\n if (dead)\n stream.err(\"Only non-generatable nodes (\" + nodes.join(\", \") + \") in a required position (see https://prosemirror.net/docs/guide/#generatable)\");\n }\n}\n\n// For node types where all attrs have a default value (or which don't\n// have any attributes), build up a single reusable default attribute\n// object, and use it for all nodes that don't specify specific\n// attributes.\nfunction defaultAttrs(attrs) {\n let defaults = Object.create(null);\n for (let attrName in attrs) {\n let attr = attrs[attrName];\n if (!attr.hasDefault)\n return null;\n defaults[attrName] = attr.default;\n }\n return defaults;\n}\nfunction computeAttrs(attrs, value) {\n let built = Object.create(null);\n for (let name in attrs) {\n let given = value && value[name];\n if (given === undefined) {\n let attr = attrs[name];\n if (attr.hasDefault)\n given = attr.default;\n else\n throw new RangeError(\"No value supplied for attribute \" + name);\n }\n built[name] = given;\n }\n return built;\n}\nfunction checkAttrs(attrs, values, type, name) {\n for (let name in values)\n if (!(name in attrs))\n throw new RangeError(`Unsupported attribute ${name} for ${type} of type ${name}`);\n for (let name in attrs) {\n let attr = attrs[name];\n if (attr.validate)\n attr.validate(values[name]);\n }\n}\nfunction initAttrs(typeName, attrs) {\n let result = Object.create(null);\n if (attrs)\n for (let name in attrs)\n result[name] = new Attribute(typeName, name, attrs[name]);\n return result;\n}\n/**\nNode types are objects allocated once per `Schema` and used to\n[tag](https://prosemirror.net/docs/ref/#model.Node.type) `Node` instances. They contain information\nabout the node type, such as its name and what kind of node it\nrepresents.\n*/\nclass NodeType {\n /**\n @internal\n */\n constructor(\n /**\n The name the node type has in this schema.\n */\n name, \n /**\n A link back to the `Schema` the node type belongs to.\n */\n schema, \n /**\n The spec that this type is based on\n */\n spec) {\n this.name = name;\n this.schema = schema;\n this.spec = spec;\n /**\n The set of marks allowed in this node. `null` means all marks\n are allowed.\n */\n this.markSet = null;\n this.groups = spec.group ? spec.group.split(\" \") : [];\n this.attrs = initAttrs(name, spec.attrs);\n this.defaultAttrs = defaultAttrs(this.attrs);\n this.contentMatch = null;\n this.inlineContent = null;\n this.isBlock = !(spec.inline || name == \"text\");\n this.isText = name == \"text\";\n }\n /**\n True if this is an inline type.\n */\n get isInline() { return !this.isBlock; }\n /**\n True if this is a textblock type, a block that contains inline\n content.\n */\n get isTextblock() { return this.isBlock && this.inlineContent; }\n /**\n True for node types that allow no content.\n */\n get isLeaf() { return this.contentMatch == ContentMatch.empty; }\n /**\n True when this node is an atom, i.e. when it does not have\n directly editable content.\n */\n get isAtom() { return this.isLeaf || !!this.spec.atom; }\n /**\n Return true when this node type is part of the given\n [group](https://prosemirror.net/docs/ref/#model.NodeSpec.group).\n */\n isInGroup(group) {\n return this.groups.indexOf(group) > -1;\n }\n /**\n The node type's [whitespace](https://prosemirror.net/docs/ref/#model.NodeSpec.whitespace) option.\n */\n get whitespace() {\n return this.spec.whitespace || (this.spec.code ? \"pre\" : \"normal\");\n }\n /**\n Tells you whether this node type has any required attributes.\n */\n hasRequiredAttrs() {\n for (let n in this.attrs)\n if (this.attrs[n].isRequired)\n return true;\n return false;\n }\n /**\n Indicates whether this node allows some of the same content as\n the given node type.\n */\n compatibleContent(other) {\n return this == other || this.contentMatch.compatible(other.contentMatch);\n }\n /**\n @internal\n */\n computeAttrs(attrs) {\n if (!attrs && this.defaultAttrs)\n return this.defaultAttrs;\n else\n return computeAttrs(this.attrs, attrs);\n }\n /**\n Create a `Node` of this type. The given attributes are\n checked and defaulted (you can pass `null` to use the type's\n defaults entirely, if no required attributes exist). `content`\n may be a `Fragment`, a node, an array of nodes, or\n `null`. Similarly `marks` may be `null` to default to the empty\n set of marks.\n */\n create(attrs = null, content, marks) {\n if (this.isText)\n throw new Error(\"NodeType.create can't construct text nodes\");\n return new Node(this, this.computeAttrs(attrs), Fragment.from(content), Mark.setFrom(marks));\n }\n /**\n Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content\n against the node type's content restrictions, and throw an error\n if it doesn't match.\n */\n createChecked(attrs = null, content, marks) {\n content = Fragment.from(content);\n this.checkContent(content);\n return new Node(this, this.computeAttrs(attrs), content, Mark.setFrom(marks));\n }\n /**\n Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is\n necessary to add nodes to the start or end of the given fragment\n to make it fit the node. If no fitting wrapping can be found,\n return null. Note that, due to the fact that required nodes can\n always be created, this will always succeed if you pass null or\n `Fragment.empty` as content.\n */\n createAndFill(attrs = null, content, marks) {\n attrs = this.computeAttrs(attrs);\n content = Fragment.from(content);\n if (content.size) {\n let before = this.contentMatch.fillBefore(content);\n if (!before)\n return null;\n content = before.append(content);\n }\n let matched = this.contentMatch.matchFragment(content);\n let after = matched && matched.fillBefore(Fragment.empty, true);\n if (!after)\n return null;\n return new Node(this, attrs, content.append(after), Mark.setFrom(marks));\n }\n /**\n Returns true if the given fragment is valid content for this node\n type.\n */\n validContent(content) {\n let result = this.contentMatch.matchFragment(content);\n if (!result || !result.validEnd)\n return false;\n for (let i = 0; i < content.childCount; i++)\n if (!this.allowsMarks(content.child(i).marks))\n return false;\n return true;\n }\n /**\n Throws a RangeError if the given fragment is not valid content for this\n node type.\n @internal\n */\n checkContent(content) {\n if (!this.validContent(content))\n throw new RangeError(`Invalid content for node ${this.name}: ${content.toString().slice(0, 50)}`);\n }\n /**\n @internal\n */\n checkAttrs(attrs) {\n checkAttrs(this.attrs, attrs, \"node\", this.name);\n }\n /**\n Check whether the given mark type is allowed in this node.\n */\n allowsMarkType(markType) {\n return this.markSet == null || this.markSet.indexOf(markType) > -1;\n }\n /**\n Test whether the given set of marks are allowed in this node.\n */\n allowsMarks(marks) {\n if (this.markSet == null)\n return true;\n for (let i = 0; i < marks.length; i++)\n if (!this.allowsMarkType(marks[i].type))\n return false;\n return true;\n }\n /**\n Removes the marks that are not allowed in this node from the given set.\n */\n allowedMarks(marks) {\n if (this.markSet == null)\n return marks;\n let copy;\n for (let i = 0; i < marks.length; i++) {\n if (!this.allowsMarkType(marks[i].type)) {\n if (!copy)\n copy = marks.slice(0, i);\n }\n else if (copy) {\n copy.push(marks[i]);\n }\n }\n return !copy ? marks : copy.length ? copy : Mark.none;\n }\n /**\n @internal\n */\n static compile(nodes, schema) {\n let result = Object.create(null);\n nodes.forEach((name, spec) => result[name] = new NodeType(name, schema, spec));\n let topType = schema.spec.topNode || \"doc\";\n if (!result[topType])\n throw new RangeError(\"Schema is missing its top node type ('\" + topType + \"')\");\n if (!result.text)\n throw new RangeError(\"Every schema needs a 'text' type\");\n for (let _ in result.text.attrs)\n throw new RangeError(\"The text node type should not have attributes\");\n return result;\n }\n}\nfunction validateType(typeName, attrName, type) {\n let types = type.split(\"|\");\n return (value) => {\n let name = value === null ? \"null\" : typeof value;\n if (types.indexOf(name) < 0)\n throw new RangeError(`Expected value of type ${types} for attribute ${attrName} on type ${typeName}, got ${name}`);\n };\n}\n// Attribute descriptors\nclass Attribute {\n constructor(typeName, attrName, options) {\n this.hasDefault = Object.prototype.hasOwnProperty.call(options, \"default\");\n this.default = options.default;\n this.validate = typeof options.validate == \"string\" ? validateType(typeName, attrName, options.validate) : options.validate;\n }\n get isRequired() {\n return !this.hasDefault;\n }\n}\n// Marks\n/**\nLike nodes, marks (which are associated with nodes to signify\nthings like emphasis or being part of a link) are\n[tagged](https://prosemirror.net/docs/ref/#model.Mark.type) with type objects, which are\ninstantiated once per `Schema`.\n*/\nclass MarkType {\n /**\n @internal\n */\n constructor(\n /**\n The name of the mark type.\n */\n name, \n /**\n @internal\n */\n rank, \n /**\n The schema that this mark type instance is part of.\n */\n schema, \n /**\n The spec on which the type is based.\n */\n spec) {\n this.name = name;\n this.rank = rank;\n this.schema = schema;\n this.spec = spec;\n this.attrs = initAttrs(name, spec.attrs);\n this.excluded = null;\n let defaults = defaultAttrs(this.attrs);\n this.instance = defaults ? new Mark(this, defaults) : null;\n }\n /**\n Create a mark of this type. `attrs` may be `null` or an object\n containing only some of the mark's attributes. The others, if\n they have defaults, will be added.\n */\n create(attrs = null) {\n if (!attrs && this.instance)\n return this.instance;\n return new Mark(this, computeAttrs(this.attrs, attrs));\n }\n /**\n @internal\n */\n static compile(marks, schema) {\n let result = Object.create(null), rank = 0;\n marks.forEach((name, spec) => result[name] = new MarkType(name, rank++, schema, spec));\n return result;\n }\n /**\n When there is a mark of this type in the given set, a new set\n without it is returned. Otherwise, the input set is returned.\n */\n removeFromSet(set) {\n for (var i = 0; i < set.length; i++)\n if (set[i].type == this) {\n set = set.slice(0, i).concat(set.slice(i + 1));\n i--;\n }\n return set;\n }\n /**\n Tests whether there is a mark of this type in the given set.\n */\n isInSet(set) {\n for (let i = 0; i < set.length; i++)\n if (set[i].type == this)\n return set[i];\n }\n /**\n @internal\n */\n checkAttrs(attrs) {\n checkAttrs(this.attrs, attrs, \"mark\", this.name);\n }\n /**\n Queries whether a given mark type is\n [excluded](https://prosemirror.net/docs/ref/#model.MarkSpec.excludes) by this one.\n */\n excludes(other) {\n return this.excluded.indexOf(other) > -1;\n }\n}\n/**\nA document schema. Holds [node](https://prosemirror.net/docs/ref/#model.NodeType) and [mark\ntype](https://prosemirror.net/docs/ref/#model.MarkType) objects for the nodes and marks that may\noccur in conforming documents, and provides functionality for\ncreating and deserializing such documents.\n\nWhen given, the type parameters provide the names of the nodes and\nmarks in this schema.\n*/\nclass Schema {\n /**\n Construct a schema from a schema [specification](https://prosemirror.net/docs/ref/#model.SchemaSpec).\n */\n constructor(spec) {\n /**\n The [linebreak\n replacement](https://prosemirror.net/docs/ref/#model.NodeSpec.linebreakReplacement) node defined\n in this schema, if any.\n */\n this.linebreakReplacement = null;\n /**\n An object for storing whatever values modules may want to\n compute and cache per schema. (If you want to store something\n in it, try to use property names unlikely to clash.)\n */\n this.cached = Object.create(null);\n let instanceSpec = this.spec = {};\n for (let prop in spec)\n instanceSpec[prop] = spec[prop];\n instanceSpec.nodes = OrderedMap.from(spec.nodes),\n instanceSpec.marks = OrderedMap.from(spec.marks || {}),\n this.nodes = NodeType.compile(this.spec.nodes, this);\n this.marks = MarkType.compile(this.spec.marks, this);\n let contentExprCache = Object.create(null);\n for (let prop in this.nodes) {\n if (prop in this.marks)\n throw new RangeError(prop + \" can not be both a node and a mark\");\n let type = this.nodes[prop], contentExpr = type.spec.content || \"\", markExpr = type.spec.marks;\n type.contentMatch = contentExprCache[contentExpr] ||\n (contentExprCache[contentExpr] = ContentMatch.parse(contentExpr, this.nodes));\n type.inlineContent = type.contentMatch.inlineContent;\n if (type.spec.linebreakReplacement) {\n if (this.linebreakReplacement)\n throw new RangeError(\"Multiple linebreak nodes defined\");\n if (!type.isInline || !type.isLeaf)\n throw new RangeError(\"Linebreak replacement nodes must be inline leaf nodes\");\n this.linebreakReplacement = type;\n }\n type.markSet = markExpr == \"_\" ? null :\n markExpr ? gatherMarks(this, markExpr.split(\" \")) :\n markExpr == \"\" || !type.inlineContent ? [] : null;\n }\n for (let prop in this.marks) {\n let type = this.marks[prop], excl = type.spec.excludes;\n type.excluded = excl == null ? [type] : excl == \"\" ? [] : gatherMarks(this, excl.split(\" \"));\n }\n this.nodeFromJSON = json => Node.fromJSON(this, json);\n this.markFromJSON = json => Mark.fromJSON(this, json);\n this.topNodeType = this.nodes[this.spec.topNode || \"doc\"];\n this.cached.wrappings = Object.create(null);\n }\n /**\n Create a node in this schema. The `type` may be a string or a\n `NodeType` instance. Attributes will be extended with defaults,\n `content` may be a `Fragment`, `null`, a `Node`, or an array of\n nodes.\n */\n node(type, attrs = null, content, marks) {\n if (typeof type == \"string\")\n type = this.nodeType(type);\n else if (!(type instanceof NodeType))\n throw new RangeError(\"Invalid node type: \" + type);\n else if (type.schema != this)\n throw new RangeError(\"Node type from different schema used (\" + type.name + \")\");\n return type.createChecked(attrs, content, marks);\n }\n /**\n Create a text node in the schema. Empty text nodes are not\n allowed.\n */\n text(text, marks) {\n let type = this.nodes.text;\n return new TextNode(type, type.defaultAttrs, text, Mark.setFrom(marks));\n }\n /**\n Create a mark with the given type and attributes.\n */\n mark(type, attrs) {\n if (typeof type == \"string\")\n type = this.marks[type];\n return type.create(attrs);\n }\n /**\n @internal\n */\n nodeType(name) {\n let found = this.nodes[name];\n if (!found)\n throw new RangeError(\"Unknown node type: \" + name);\n return found;\n }\n}\nfunction gatherMarks(schema, marks) {\n let found = [];\n for (let i = 0; i < marks.length; i++) {\n let name = marks[i], mark = schema.marks[name], ok = mark;\n if (mark) {\n found.push(mark);\n }\n else {\n for (let prop in schema.marks) {\n let mark = schema.marks[prop];\n if (name == \"_\" || (mark.spec.group && mark.spec.group.split(\" \").indexOf(name) > -1))\n found.push(ok = mark);\n }\n }\n if (!ok)\n throw new SyntaxError(\"Unknown mark type: '\" + marks[i] + \"'\");\n }\n return found;\n}\n\nfunction isTagRule(rule) { return rule.tag != null; }\nfunction isStyleRule(rule) { return rule.style != null; }\n/**\nA DOM parser represents a strategy for parsing DOM content into a\nProseMirror document conforming to a given schema. Its behavior is\ndefined by an array of [rules](https://prosemirror.net/docs/ref/#model.ParseRule).\n*/\nclass DOMParser {\n /**\n Create a parser that targets the given schema, using the given\n parsing rules.\n */\n constructor(\n /**\n The schema into which the parser parses.\n */\n schema, \n /**\n The set of [parse rules](https://prosemirror.net/docs/ref/#model.ParseRule) that the parser\n uses, in order of precedence.\n */\n rules) {\n this.schema = schema;\n this.rules = rules;\n /**\n @internal\n */\n this.tags = [];\n /**\n @internal\n */\n this.styles = [];\n let matchedStyles = this.matchedStyles = [];\n rules.forEach(rule => {\n if (isTagRule(rule)) {\n this.tags.push(rule);\n }\n else if (isStyleRule(rule)) {\n let prop = /[^=]*/.exec(rule.style)[0];\n if (matchedStyles.indexOf(prop) < 0)\n matchedStyles.push(prop);\n this.styles.push(rule);\n }\n });\n // Only normalize list elements when lists in the schema can't directly contain themselves\n this.normalizeLists = !this.tags.some(r => {\n if (!/^(ul|ol)\\b/.test(r.tag) || !r.node)\n return false;\n let node = schema.nodes[r.node];\n return node.contentMatch.matchType(node);\n });\n }\n /**\n Parse a document from the content of a DOM node.\n */\n parse(dom, options = {}) {\n let context = new ParseContext(this, options, false);\n context.addAll(dom, Mark.none, options.from, options.to);\n return context.finish();\n }\n /**\n Parses the content of the given DOM node, like\n [`parse`](https://prosemirror.net/docs/ref/#model.DOMParser.parse), and takes the same set of\n options. But unlike that method, which produces a whole node,\n this one returns a slice that is open at the sides, meaning that\n the schema constraints aren't applied to the start of nodes to\n the left of the input and the end of nodes at the end.\n */\n parseSlice(dom, options = {}) {\n let context = new ParseContext(this, options, true);\n context.addAll(dom, Mark.none, options.from, options.to);\n return Slice.maxOpen(context.finish());\n }\n /**\n @internal\n */\n matchTag(dom, context, after) {\n for (let i = after ? this.tags.indexOf(after) + 1 : 0; i < this.tags.length; i++) {\n let rule = this.tags[i];\n if (matches(dom, rule.tag) &&\n (rule.namespace === undefined || dom.namespaceURI == rule.namespace) &&\n (!rule.context || context.matchesContext(rule.context))) {\n if (rule.getAttrs) {\n let result = rule.getAttrs(dom);\n if (result === false)\n continue;\n rule.attrs = result || undefined;\n }\n return rule;\n }\n }\n }\n /**\n @internal\n */\n matchStyle(prop, value, context, after) {\n for (let i = after ? this.styles.indexOf(after) + 1 : 0; i < this.styles.length; i++) {\n let rule = this.styles[i], style = rule.style;\n if (style.indexOf(prop) != 0 ||\n rule.context && !context.matchesContext(rule.context) ||\n // Test that the style string either precisely matches the prop,\n // or has an '=' sign after the prop, followed by the given\n // value.\n style.length > prop.length &&\n (style.charCodeAt(prop.length) != 61 || style.slice(prop.length + 1) != value))\n continue;\n if (rule.getAttrs) {\n let result = rule.getAttrs(value);\n if (result === false)\n continue;\n rule.attrs = result || undefined;\n }\n return rule;\n }\n }\n /**\n @internal\n */\n static schemaRules(schema) {\n let result = [];\n function insert(rule) {\n let priority = rule.priority == null ? 50 : rule.priority, i = 0;\n for (; i < result.length; i++) {\n let next = result[i], nextPriority = next.priority == null ? 50 : next.priority;\n if (nextPriority < priority)\n break;\n }\n result.splice(i, 0, rule);\n }\n for (let name in schema.marks) {\n let rules = schema.marks[name].spec.parseDOM;\n if (rules)\n rules.forEach(rule => {\n insert(rule = copy(rule));\n if (!(rule.mark || rule.ignore || rule.clearMark))\n rule.mark = name;\n });\n }\n for (let name in schema.nodes) {\n let rules = schema.nodes[name].spec.parseDOM;\n if (rules)\n rules.forEach(rule => {\n insert(rule = copy(rule));\n if (!(rule.node || rule.ignore || rule.mark))\n rule.node = name;\n });\n }\n return result;\n }\n /**\n Construct a DOM parser using the parsing rules listed in a\n schema's [node specs](https://prosemirror.net/docs/ref/#model.NodeSpec.parseDOM), reordered by\n [priority](https://prosemirror.net/docs/ref/#model.GenericParseRule.priority).\n */\n static fromSchema(schema) {\n return schema.cached.domParser ||\n (schema.cached.domParser = new DOMParser(schema, DOMParser.schemaRules(schema)));\n }\n}\nconst blockTags = {\n address: true, article: true, aside: true, blockquote: true, canvas: true,\n dd: true, div: true, dl: true, fieldset: true, figcaption: true, figure: true,\n footer: true, form: true, h1: true, h2: true, h3: true, h4: true, h5: true,\n h6: true, header: true, hgroup: true, hr: true, li: true, noscript: true, ol: true,\n output: true, p: true, pre: true, section: true, table: true, tfoot: true, ul: true\n};\nconst ignoreTags = {\n head: true, noscript: true, object: true, script: true, style: true, title: true\n};\nconst listTags = { ol: true, ul: true };\n// Using a bitfield for node context options\nconst OPT_PRESERVE_WS = 1, OPT_PRESERVE_WS_FULL = 2, OPT_OPEN_LEFT = 4;\nfunction wsOptionsFor(type, preserveWhitespace, base) {\n if (preserveWhitespace != null)\n return (preserveWhitespace ? OPT_PRESERVE_WS : 0) |\n (preserveWhitespace === \"full\" ? OPT_PRESERVE_WS_FULL : 0);\n return type && type.whitespace == \"pre\" ? OPT_PRESERVE_WS | OPT_PRESERVE_WS_FULL : base & ~OPT_OPEN_LEFT;\n}\nclass NodeContext {\n constructor(type, attrs, marks, solid, match, options) {\n this.type = type;\n this.attrs = attrs;\n this.marks = marks;\n this.solid = solid;\n this.options = options;\n this.content = [];\n // Marks applied to the node's children\n this.activeMarks = Mark.none;\n this.match = match || (options & OPT_OPEN_LEFT ? null : type.contentMatch);\n }\n findWrapping(node) {\n if (!this.match) {\n if (!this.type)\n return [];\n let fill = this.type.contentMatch.fillBefore(Fragment.from(node));\n if (fill) {\n this.match = this.type.contentMatch.matchFragment(fill);\n }\n else {\n let start = this.type.contentMatch, wrap;\n if (wrap = start.findWrapping(node.type)) {\n this.match = start;\n return wrap;\n }\n else {\n return null;\n }\n }\n }\n return this.match.findWrapping(node.type);\n }\n finish(openEnd) {\n if (!(this.options & OPT_PRESERVE_WS)) { // Strip trailing whitespace\n let last = this.content[this.content.length - 1], m;\n if (last && last.isText && (m = /[ \\t\\r\\n\\u000c]+$/.exec(last.text))) {\n let text = last;\n if (last.text.length == m[0].length)\n this.content.pop();\n else\n this.content[this.content.length - 1] = text.withText(text.text.slice(0, text.text.length - m[0].length));\n }\n }\n let content = Fragment.from(this.content);\n if (!openEnd && this.match)\n content = content.append(this.match.fillBefore(Fragment.empty, true));\n return this.type ? this.type.create(this.attrs, content, this.marks) : content;\n }\n inlineContext(node) {\n if (this.type)\n return this.type.inlineContent;\n if (this.content.length)\n return this.content[0].isInline;\n return node.parentNode && !blockTags.hasOwnProperty(node.parentNode.nodeName.toLowerCase());\n }\n}\nclass ParseContext {\n constructor(\n // The parser we are using.\n parser, \n // The options passed to this parse.\n options, isOpen) {\n this.parser = parser;\n this.options = options;\n this.isOpen = isOpen;\n this.open = 0;\n this.localPreserveWS = false;\n let topNode = options.topNode, topContext;\n let topOptions = wsOptionsFor(null, options.preserveWhitespace, 0) | (isOpen ? OPT_OPEN_LEFT : 0);\n if (topNode)\n topContext = new NodeContext(topNode.type, topNode.attrs, Mark.none, true, options.topMatch || topNode.type.contentMatch, topOptions);\n else if (isOpen)\n topContext = new NodeContext(null, null, Mark.none, true, null, topOptions);\n else\n topContext = new NodeContext(parser.schema.topNodeType, null, Mark.none, true, null, topOptions);\n this.nodes = [topContext];\n this.find = options.findPositions;\n this.needsBlock = false;\n }\n get top() {\n return this.nodes[this.open];\n }\n // Add a DOM node to the content. Text is inserted as text node,\n // otherwise, the node is passed to `addElement` or, if it has a\n // `style` attribute, `addElementWithStyles`.\n addDOM(dom, marks) {\n if (dom.nodeType == 3)\n this.addTextNode(dom, marks);\n else if (dom.nodeType == 1)\n this.addElement(dom, marks);\n }\n addTextNode(dom, marks) {\n let value = dom.nodeValue;\n let top = this.top, preserveWS = (top.options & OPT_PRESERVE_WS_FULL) ? \"full\"\n : this.localPreserveWS || (top.options & OPT_PRESERVE_WS) > 0;\n if (preserveWS === \"full\" ||\n top.inlineContext(dom) ||\n /[^ \\t\\r\\n\\u000c]/.test(value)) {\n if (!preserveWS) {\n value = value.replace(/[ \\t\\r\\n\\u000c]+/g, \" \");\n // If this starts with whitespace, and there is no node before it, or\n // a hard break, or a text node that ends with whitespace, strip the\n // leading space.\n if (/^[ \\t\\r\\n\\u000c]/.test(value) && this.open == this.nodes.length - 1) {\n let nodeBefore = top.content[top.content.length - 1];\n let domNodeBefore = dom.previousSibling;\n if (!nodeBefore ||\n (domNodeBefore && domNodeBefore.nodeName == 'BR') ||\n (nodeBefore.isText && /[ \\t\\r\\n\\u000c]$/.test(nodeBefore.text)))\n value = value.slice(1);\n }\n }\n else if (preserveWS !== \"full\") {\n value = value.replace(/\\r?\\n|\\r/g, \" \");\n }\n else {\n value = value.replace(/\\r\\n?/g, \"\\n\");\n }\n if (value)\n this.insertNode(this.parser.schema.text(value), marks, !/\\S/.test(value));\n this.findInText(dom);\n }\n else {\n this.findInside(dom);\n }\n }\n // Try to find a handler for the given tag and use that to parse. If\n // none is found, the element's content nodes are added directly.\n addElement(dom, marks, matchAfter) {\n let outerWS = this.localPreserveWS, top = this.top;\n if (dom.tagName == \"PRE\" || /pre/.test(dom.style && dom.style.whiteSpace))\n this.localPreserveWS = true;\n let name = dom.nodeName.toLowerCase(), ruleID;\n if (listTags.hasOwnProperty(name) && this.parser.normalizeLists)\n normalizeList(dom);\n let rule = (this.options.ruleFromNode && this.options.ruleFromNode(dom)) ||\n (ruleID = this.parser.matchTag(dom, this, matchAfter));\n out: if (rule ? rule.ignore : ignoreTags.hasOwnProperty(name)) {\n this.findInside(dom);\n this.ignoreFallback(dom, marks);\n }\n else if (!rule || rule.skip || rule.closeParent) {\n if (rule && rule.closeParent)\n this.open = Math.max(0, this.open - 1);\n else if (rule && rule.skip.nodeType)\n dom = rule.skip;\n let sync, oldNeedsBlock = this.needsBlock;\n if (blockTags.hasOwnProperty(name)) {\n if (top.content.length && top.content[0].isInline && this.open) {\n this.open--;\n top = this.top;\n }\n sync = true;\n if (!top.type)\n this.needsBlock = true;\n }\n else if (!dom.firstChild) {\n this.leafFallback(dom, marks);\n break out;\n }\n let innerMarks = rule && rule.skip ? marks : this.readStyles(dom, marks);\n if (innerMarks)\n this.addAll(dom, innerMarks);\n if (sync)\n this.sync(top);\n this.needsBlock = oldNeedsBlock;\n }\n else {\n let innerMarks = this.readStyles(dom, marks);\n if (innerMarks)\n this.addElementByRule(dom, rule, innerMarks, rule.consuming === false ? ruleID : undefined);\n }\n this.localPreserveWS = outerWS;\n }\n // Called for leaf DOM nodes that would otherwise be ignored\n leafFallback(dom, marks) {\n if (dom.nodeName == \"BR\" && this.top.type && this.top.type.inlineContent)\n this.addTextNode(dom.ownerDocument.createTextNode(\"\\n\"), marks);\n }\n // Called for ignored nodes\n ignoreFallback(dom, marks) {\n // Ignored BR nodes should at least create an inline context\n if (dom.nodeName == \"BR\" && (!this.top.type || !this.top.type.inlineContent))\n this.findPlace(this.parser.schema.text(\"-\"), marks, true);\n }\n // Run any style parser associated with the node's styles. Either\n // return an updated array of marks, or null to indicate some of the\n // styles had a rule with `ignore` set.\n readStyles(dom, marks) {\n let styles = dom.style;\n // Because many properties will only show up in 'normalized' form\n // in `style.item` (i.e. text-decoration becomes\n // text-decoration-line, text-decoration-color, etc), we directly\n // query the styles mentioned in our rules instead of iterating\n // over the items.\n if (styles && styles.length)\n for (let i = 0; i < this.parser.matchedStyles.length; i++) {\n let name = this.parser.matchedStyles[i], value = styles.getPropertyValue(name);\n if (value)\n for (let after = undefined;;) {\n let rule = this.parser.matchStyle(name, value, this, after);\n if (!rule)\n break;\n if (rule.ignore)\n return null;\n if (rule.clearMark)\n marks = marks.filter(m => !rule.clearMark(m));\n else\n marks = marks.concat(this.parser.schema.marks[rule.mark].create(rule.attrs));\n if (rule.consuming === false)\n after = rule;\n else\n break;\n }\n }\n return marks;\n }\n // Look up a handler for the given node. If none are found, return\n // false. Otherwise, apply it, use its return value to drive the way\n // the node's content is wrapped, and return true.\n addElementByRule(dom, rule, marks, continueAfter) {\n let sync, nodeType;\n if (rule.node) {\n nodeType = this.parser.schema.nodes[rule.node];\n if (!nodeType.isLeaf) {\n let inner = this.enter(nodeType, rule.attrs || null, marks, rule.preserveWhitespace);\n if (inner) {\n sync = true;\n marks = inner;\n }\n }\n else if (!this.insertNode(nodeType.create(rule.attrs), marks, dom.nodeName == \"BR\")) {\n this.leafFallback(dom, marks);\n }\n }\n else {\n let markType = this.parser.schema.marks[rule.mark];\n marks = marks.concat(markType.create(rule.attrs));\n }\n let startIn = this.top;\n if (nodeType && nodeType.isLeaf) {\n this.findInside(dom);\n }\n else if (continueAfter) {\n this.addElement(dom, marks, continueAfter);\n }\n else if (rule.getContent) {\n this.findInside(dom);\n rule.getContent(dom, this.parser.schema).forEach(node => this.insertNode(node, marks, false));\n }\n else {\n let contentDOM = dom;\n if (typeof rule.contentElement == \"string\")\n contentDOM = dom.querySelector(rule.contentElement);\n else if (typeof rule.contentElement == \"function\")\n contentDOM = rule.contentElement(dom);\n else if (rule.contentElement)\n contentDOM = rule.contentElement;\n this.findAround(dom, contentDOM, true);\n this.addAll(contentDOM, marks);\n this.findAround(dom, contentDOM, false);\n }\n if (sync && this.sync(startIn))\n this.open--;\n }\n // Add all child nodes between `startIndex` and `endIndex` (or the\n // whole node, if not given). If `sync` is passed, use it to\n // synchronize after every block element.\n addAll(parent, marks, startIndex, endIndex) {\n let index = startIndex || 0;\n for (let dom = startIndex ? parent.childNodes[startIndex] : parent.firstChild, end = endIndex == null ? null : parent.childNodes[endIndex]; dom != end; dom = dom.nextSibling, ++index) {\n this.findAtPoint(parent, index);\n this.addDOM(dom, marks);\n }\n this.findAtPoint(parent, index);\n }\n // Try to find a way to fit the given node type into the current\n // context. May add intermediate wrappers and/or leave non-solid\n // nodes that we're in.\n findPlace(node, marks, cautious) {\n let route, sync;\n for (let depth = this.open, penalty = 0; depth >= 0; depth--) {\n let cx = this.nodes[depth];\n let found = cx.findWrapping(node);\n if (found && (!route || route.length > found.length + penalty)) {\n route = found;\n sync = cx;\n if (!found.length)\n break;\n }\n if (cx.solid) {\n if (cautious)\n break;\n penalty += 2;\n }\n }\n if (!route)\n return null;\n this.sync(sync);\n for (let i = 0; i < route.length; i++)\n marks = this.enterInner(route[i], null, marks, false);\n return marks;\n }\n // Try to insert the given node, adjusting the context when needed.\n insertNode(node, marks, cautious) {\n if (node.isInline && this.needsBlock && !this.top.type) {\n let block = this.textblockFromContext();\n if (block)\n marks = this.enterInner(block, null, marks);\n }\n let innerMarks = this.findPlace(node, marks, cautious);\n if (innerMarks) {\n this.closeExtra();\n let top = this.top;\n if (top.match)\n top.match = top.match.matchType(node.type);\n let nodeMarks = Mark.none;\n for (let m of innerMarks.concat(node.marks))\n if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, node.type))\n nodeMarks = m.addToSet(nodeMarks);\n top.content.push(node.mark(nodeMarks));\n return true;\n }\n return false;\n }\n // Try to start a node of the given type, adjusting the context when\n // necessary.\n enter(type, attrs, marks, preserveWS) {\n let innerMarks = this.findPlace(type.create(attrs), marks, false);\n if (innerMarks)\n innerMarks = this.enterInner(type, attrs, marks, true, preserveWS);\n return innerMarks;\n }\n // Open a node of the given type\n enterInner(type, attrs, marks, solid = false, preserveWS) {\n this.closeExtra();\n let top = this.top;\n top.match = top.match && top.match.matchType(type);\n let options = wsOptionsFor(type, preserveWS, top.options);\n if ((top.options & OPT_OPEN_LEFT) && top.content.length == 0)\n options |= OPT_OPEN_LEFT;\n let applyMarks = Mark.none;\n marks = marks.filter(m => {\n if (top.type ? top.type.allowsMarkType(m.type) : markMayApply(m.type, type)) {\n applyMarks = m.addToSet(applyMarks);\n return false;\n }\n return true;\n });\n this.nodes.push(new NodeContext(type, attrs, applyMarks, solid, null, options));\n this.open++;\n return marks;\n }\n // Make sure all nodes above this.open are finished and added to\n // their parents\n closeExtra(openEnd = false) {\n let i = this.nodes.length - 1;\n if (i > this.open) {\n for (; i > this.open; i--)\n this.nodes[i - 1].content.push(this.nodes[i].finish(openEnd));\n this.nodes.length = this.open + 1;\n }\n }\n finish() {\n this.open = 0;\n this.closeExtra(this.isOpen);\n return this.nodes[0].finish(!!(this.isOpen || this.options.topOpen));\n }\n sync(to) {\n for (let i = this.open; i >= 0; i--) {\n if (this.nodes[i] == to) {\n this.open = i;\n return true;\n }\n else if (this.localPreserveWS) {\n this.nodes[i].options |= OPT_PRESERVE_WS;\n }\n }\n return false;\n }\n get currentPos() {\n this.closeExtra();\n let pos = 0;\n for (let i = this.open; i >= 0; i--) {\n let content = this.nodes[i].content;\n for (let j = content.length - 1; j >= 0; j--)\n pos += content[j].nodeSize;\n if (i)\n pos++;\n }\n return pos;\n }\n findAtPoint(parent, offset) {\n if (this.find)\n for (let i = 0; i < this.find.length; i++) {\n if (this.find[i].node == parent && this.find[i].offset == offset)\n this.find[i].pos = this.currentPos;\n }\n }\n findInside(parent) {\n if (this.find)\n for (let i = 0; i < this.find.length; i++) {\n if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node))\n this.find[i].pos = this.currentPos;\n }\n }\n findAround(parent, content, before) {\n if (parent != content && this.find)\n for (let i = 0; i < this.find.length; i++) {\n if (this.find[i].pos == null && parent.nodeType == 1 && parent.contains(this.find[i].node)) {\n let pos = content.compareDocumentPosition(this.find[i].node);\n if (pos & (before ? 2 : 4))\n this.find[i].pos = this.currentPos;\n }\n }\n }\n findInText(textNode) {\n if (this.find)\n for (let i = 0; i < this.find.length; i++) {\n if (this.find[i].node == textNode)\n this.find[i].pos = this.currentPos - (textNode.nodeValue.length - this.find[i].offset);\n }\n }\n // Determines whether the given context string matches this context.\n matchesContext(context) {\n if (context.indexOf(\"|\") > -1)\n return context.split(/\\s*\\|\\s*/).some(this.matchesContext, this);\n let parts = context.split(\"/\");\n let option = this.options.context;\n let useRoot = !this.isOpen && (!option || option.parent.type == this.nodes[0].type);\n let minDepth = -(option ? option.depth + 1 : 0) + (useRoot ? 0 : 1);\n let match = (i, depth) => {\n for (; i >= 0; i--) {\n let part = parts[i];\n if (part == \"\") {\n if (i == parts.length - 1 || i == 0)\n continue;\n for (; depth >= minDepth; depth--)\n if (match(i - 1, depth))\n return true;\n return false;\n }\n else {\n let next = depth > 0 || (depth == 0 && useRoot) ? this.nodes[depth].type\n : option && depth >= minDepth ? option.node(depth - minDepth).type\n : null;\n if (!next || (next.name != part && !next.isInGroup(part)))\n return false;\n depth--;\n }\n }\n return true;\n };\n return match(parts.length - 1, this.open);\n }\n textblockFromContext() {\n let $context = this.options.context;\n if ($context)\n for (let d = $context.depth; d >= 0; d--) {\n let deflt = $context.node(d).contentMatchAt($context.indexAfter(d)).defaultType;\n if (deflt && deflt.isTextblock && deflt.defaultAttrs)\n return deflt;\n }\n for (let name in this.parser.schema.nodes) {\n let type = this.parser.schema.nodes[name];\n if (type.isTextblock && type.defaultAttrs)\n return type;\n }\n }\n}\n// Kludge to work around directly nested list nodes produced by some\n// tools and allowed by browsers to mean that the nested list is\n// actually part of the list item above it.\nfunction normalizeList(dom) {\n for (let child = dom.firstChild, prevItem = null; child; child = child.nextSibling) {\n let name = child.nodeType == 1 ? child.nodeName.toLowerCase() : null;\n if (name && listTags.hasOwnProperty(name) && prevItem) {\n prevItem.appendChild(child);\n child = prevItem;\n }\n else if (name == \"li\") {\n prevItem = child;\n }\n else if (name) {\n prevItem = null;\n }\n }\n}\n// Apply a CSS selector.\nfunction matches(dom, selector) {\n return (dom.matches || dom.msMatchesSelector || dom.webkitMatchesSelector || dom.mozMatchesSelector).call(dom, selector);\n}\nfunction copy(obj) {\n let copy = {};\n for (let prop in obj)\n copy[prop] = obj[prop];\n return copy;\n}\n// Used when finding a mark at the top level of a fragment parse.\n// Checks whether it would be reasonable to apply a given mark type to\n// a given node, by looking at the way the mark occurs in the schema.\nfunction markMayApply(markType, nodeType) {\n let nodes = nodeType.schema.nodes;\n for (let name in nodes) {\n let parent = nodes[name];\n if (!parent.allowsMarkType(markType))\n continue;\n let seen = [], scan = (match) => {\n seen.push(match);\n for (let i = 0; i < match.edgeCount; i++) {\n let { type, next } = match.edge(i);\n if (type == nodeType)\n return true;\n if (seen.indexOf(next) < 0 && scan(next))\n return true;\n }\n };\n if (scan(parent.contentMatch))\n return true;\n }\n}\n\n/**\nA DOM serializer knows how to convert ProseMirror nodes and\nmarks of various types to DOM nodes.\n*/\nclass DOMSerializer {\n /**\n Create a serializer. `nodes` should map node names to functions\n that take a node and return a description of the corresponding\n DOM. `marks` does the same for mark names, but also gets an\n argument that tells it whether the mark's content is block or\n inline content (for typical use, it'll always be inline). A mark\n serializer may be `null` to indicate that marks of that type\n should not be serialized.\n */\n constructor(\n /**\n The node serialization functions.\n */\n nodes, \n /**\n The mark serialization functions.\n */\n marks) {\n this.nodes = nodes;\n this.marks = marks;\n }\n /**\n Serialize the content of this fragment to a DOM fragment. When\n not in the browser, the `document` option, containing a DOM\n document, should be passed so that the serializer can create\n nodes.\n */\n serializeFragment(fragment, options = {}, target) {\n if (!target)\n target = doc(options).createDocumentFragment();\n let top = target, active = [];\n fragment.forEach(node => {\n if (active.length || node.marks.length) {\n let keep = 0, rendered = 0;\n while (keep < active.length && rendered < node.marks.length) {\n let next = node.marks[rendered];\n if (!this.marks[next.type.name]) {\n rendered++;\n continue;\n }\n if (!next.eq(active[keep][0]) || next.type.spec.spanning === false)\n break;\n keep++;\n rendered++;\n }\n while (keep < active.length)\n top = active.pop()[1];\n while (rendered < node.marks.length) {\n let add = node.marks[rendered++];\n let markDOM = this.serializeMark(add, node.isInline, options);\n if (markDOM) {\n active.push([add, top]);\n top.appendChild(markDOM.dom);\n top = markDOM.contentDOM || markDOM.dom;\n }\n }\n }\n top.appendChild(this.serializeNodeInner(node, options));\n });\n return target;\n }\n /**\n @internal\n */\n serializeNodeInner(node, options) {\n let { dom, contentDOM } = renderSpec(doc(options), this.nodes[node.type.name](node), null, node.attrs);\n if (contentDOM) {\n if (node.isLeaf)\n throw new RangeError(\"Content hole not allowed in a leaf node spec\");\n this.serializeFragment(node.content, options, contentDOM);\n }\n return dom;\n }\n /**\n Serialize this node to a DOM node. This can be useful when you\n need to serialize a part of a document, as opposed to the whole\n document. To serialize a whole document, use\n [`serializeFragment`](https://prosemirror.net/docs/ref/#model.DOMSerializer.serializeFragment) on\n its [content](https://prosemirror.net/docs/ref/#model.Node.content).\n */\n serializeNode(node, options = {}) {\n let dom = this.serializeNodeInner(node, options);\n for (let i = node.marks.length - 1; i >= 0; i--) {\n let wrap = this.serializeMark(node.marks[i], node.isInline, options);\n if (wrap) {\n (wrap.contentDOM || wrap.dom).appendChild(dom);\n dom = wrap.dom;\n }\n }\n return dom;\n }\n /**\n @internal\n */\n serializeMark(mark, inline, options = {}) {\n let toDOM = this.marks[mark.type.name];\n return toDOM && renderSpec(doc(options), toDOM(mark, inline), null, mark.attrs);\n }\n static renderSpec(doc, structure, xmlNS = null, blockArraysIn) {\n return renderSpec(doc, structure, xmlNS, blockArraysIn);\n }\n /**\n Build a serializer using the [`toDOM`](https://prosemirror.net/docs/ref/#model.NodeSpec.toDOM)\n properties in a schema's node and mark specs.\n */\n static fromSchema(schema) {\n return schema.cached.domSerializer ||\n (schema.cached.domSerializer = new DOMSerializer(this.nodesFromSchema(schema), this.marksFromSchema(schema)));\n }\n /**\n Gather the serializers in a schema's node specs into an object.\n This can be useful as a base to build a custom serializer from.\n */\n static nodesFromSchema(schema) {\n let result = gatherToDOM(schema.nodes);\n if (!result.text)\n result.text = node => node.text;\n return result;\n }\n /**\n Gather the serializers in a schema's mark specs into an object.\n */\n static marksFromSchema(schema) {\n return gatherToDOM(schema.marks);\n }\n}\nfunction gatherToDOM(obj) {\n let result = {};\n for (let name in obj) {\n let toDOM = obj[name].spec.toDOM;\n if (toDOM)\n result[name] = toDOM;\n }\n return result;\n}\nfunction doc(options) {\n return options.document || window.document;\n}\nconst suspiciousAttributeCache = new WeakMap();\nfunction suspiciousAttributes(attrs) {\n let value = suspiciousAttributeCache.get(attrs);\n if (value === undefined)\n suspiciousAttributeCache.set(attrs, value = suspiciousAttributesInner(attrs));\n return value;\n}\nfunction suspiciousAttributesInner(attrs) {\n let result = null;\n function scan(value) {\n if (value && typeof value == \"object\") {\n if (Array.isArray(value)) {\n if (typeof value[0] == \"string\") {\n if (!result)\n result = [];\n result.push(value);\n }\n else {\n for (let i = 0; i < value.length; i++)\n scan(value[i]);\n }\n }\n else {\n for (let prop in value)\n scan(value[prop]);\n }\n }\n }\n scan(attrs);\n return result;\n}\nfunction renderSpec(doc, structure, xmlNS, blockArraysIn) {\n if (typeof structure == \"string\")\n return { dom: doc.createTextNode(structure) };\n if (structure.nodeType != null)\n return { dom: structure };\n if (structure.dom && structure.dom.nodeType != null)\n return structure;\n let tagName = structure[0], suspicious;\n if (typeof tagName != \"string\")\n throw new RangeError(\"Invalid array passed to renderSpec\");\n if (blockArraysIn && (suspicious = suspiciousAttributes(blockArraysIn)) &&\n suspicious.indexOf(structure) > -1)\n throw new RangeError(\"Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.\");\n let space = tagName.indexOf(\" \");\n if (space > 0) {\n xmlNS = tagName.slice(0, space);\n tagName = tagName.slice(space + 1);\n }\n let contentDOM;\n let dom = (xmlNS ? doc.createElementNS(xmlNS, tagName) : doc.createElement(tagName));\n let attrs = structure[1], start = 1;\n if (attrs && typeof attrs == \"object\" && attrs.nodeType == null && !Array.isArray(attrs)) {\n start = 2;\n for (let name in attrs)\n if (attrs[name] != null) {\n let space = name.indexOf(\" \");\n if (space > 0)\n dom.setAttributeNS(name.slice(0, space), name.slice(space + 1), attrs[name]);\n else if (name == \"style\" && dom.style)\n dom.style.cssText = attrs[name];\n else\n dom.setAttribute(name, attrs[name]);\n }\n }\n for (let i = start; i < structure.length; i++) {\n let child = structure[i];\n if (child === 0) {\n if (i < structure.length - 1 || i > start)\n throw new RangeError(\"Content hole must be the only child of its parent node\");\n return { dom, contentDOM: dom };\n }\n else {\n let { dom: inner, contentDOM: innerContent } = renderSpec(doc, child, xmlNS, blockArraysIn);\n dom.appendChild(inner);\n if (innerContent) {\n if (contentDOM)\n throw new RangeError(\"Multiple content holes\");\n contentDOM = innerContent;\n }\n }\n }\n return { dom, contentDOM };\n}\n\nexport { ContentMatch, DOMParser, DOMSerializer, Fragment, Mark, MarkType, Node, NodeRange, NodeType, ReplaceError, ResolvedPos, Schema, Slice };\n","import { ReplaceError, Slice, Fragment, MarkType, Mark } from 'prosemirror-model';\n\n// Recovery values encode a range index and an offset. They are\n// represented as numbers, because tons of them will be created when\n// mapping, for example, a large number of decorations. The number's\n// lower 16 bits provide the index, the remaining bits the offset.\n//\n// Note: We intentionally don't use bit shift operators to en- and\n// decode these, since those clip to 32 bits, which we might in rare\n// cases want to overflow. A 64-bit float can represent 48-bit\n// integers precisely.\nconst lower16 = 0xffff;\nconst factor16 = Math.pow(2, 16);\nfunction makeRecover(index, offset) { return index + offset * factor16; }\nfunction recoverIndex(value) { return value & lower16; }\nfunction recoverOffset(value) { return (value - (value & lower16)) / factor16; }\nconst DEL_BEFORE = 1, DEL_AFTER = 2, DEL_ACROSS = 4, DEL_SIDE = 8;\n/**\nAn object representing a mapped position with extra\ninformation.\n*/\nclass MapResult {\n /**\n @internal\n */\n constructor(\n /**\n The mapped version of the position.\n */\n pos, \n /**\n @internal\n */\n delInfo, \n /**\n @internal\n */\n recover) {\n this.pos = pos;\n this.delInfo = delInfo;\n this.recover = recover;\n }\n /**\n Tells you whether the position was deleted, that is, whether the\n step removed the token on the side queried (via the `assoc`)\n argument from the document.\n */\n get deleted() { return (this.delInfo & DEL_SIDE) > 0; }\n /**\n Tells you whether the token before the mapped position was deleted.\n */\n get deletedBefore() { return (this.delInfo & (DEL_BEFORE | DEL_ACROSS)) > 0; }\n /**\n True when the token after the mapped position was deleted.\n */\n get deletedAfter() { return (this.delInfo & (DEL_AFTER | DEL_ACROSS)) > 0; }\n /**\n Tells whether any of the steps mapped through deletes across the\n position (including both the token before and after the\n position).\n */\n get deletedAcross() { return (this.delInfo & DEL_ACROSS) > 0; }\n}\n/**\nA map describing the deletions and insertions made by a step, which\ncan be used to find the correspondence between positions in the\npre-step version of a document and the same position in the\npost-step version.\n*/\nclass StepMap {\n /**\n Create a position map. The modifications to the document are\n represented as an array of numbers, in which each group of three\n represents a modified chunk as `[start, oldSize, newSize]`.\n */\n constructor(\n /**\n @internal\n */\n ranges, \n /**\n @internal\n */\n inverted = false) {\n this.ranges = ranges;\n this.inverted = inverted;\n if (!ranges.length && StepMap.empty)\n return StepMap.empty;\n }\n /**\n @internal\n */\n recover(value) {\n let diff = 0, index = recoverIndex(value);\n if (!this.inverted)\n for (let i = 0; i < index; i++)\n diff += this.ranges[i * 3 + 2] - this.ranges[i * 3 + 1];\n return this.ranges[index * 3] + diff + recoverOffset(value);\n }\n mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); }\n map(pos, assoc = 1) { return this._map(pos, assoc, true); }\n /**\n @internal\n */\n _map(pos, assoc, simple) {\n let diff = 0, oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;\n for (let i = 0; i < this.ranges.length; i += 3) {\n let start = this.ranges[i] - (this.inverted ? diff : 0);\n if (start > pos)\n break;\n let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex], end = start + oldSize;\n if (pos <= end) {\n let side = !oldSize ? assoc : pos == start ? -1 : pos == end ? 1 : assoc;\n let result = start + diff + (side < 0 ? 0 : newSize);\n if (simple)\n return result;\n let recover = pos == (assoc < 0 ? start : end) ? null : makeRecover(i / 3, pos - start);\n let del = pos == start ? DEL_AFTER : pos == end ? DEL_BEFORE : DEL_ACROSS;\n if (assoc < 0 ? pos != start : pos != end)\n del |= DEL_SIDE;\n return new MapResult(result, del, recover);\n }\n diff += newSize - oldSize;\n }\n return simple ? pos + diff : new MapResult(pos + diff, 0, null);\n }\n /**\n @internal\n */\n touches(pos, recover) {\n let diff = 0, index = recoverIndex(recover);\n let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;\n for (let i = 0; i < this.ranges.length; i += 3) {\n let start = this.ranges[i] - (this.inverted ? diff : 0);\n if (start > pos)\n break;\n let oldSize = this.ranges[i + oldIndex], end = start + oldSize;\n if (pos <= end && i == index * 3)\n return true;\n diff += this.ranges[i + newIndex] - oldSize;\n }\n return false;\n }\n /**\n Calls the given function on each of the changed ranges included in\n this map.\n */\n forEach(f) {\n let oldIndex = this.inverted ? 2 : 1, newIndex = this.inverted ? 1 : 2;\n for (let i = 0, diff = 0; i < this.ranges.length; i += 3) {\n let start = this.ranges[i], oldStart = start - (this.inverted ? diff : 0), newStart = start + (this.inverted ? 0 : diff);\n let oldSize = this.ranges[i + oldIndex], newSize = this.ranges[i + newIndex];\n f(oldStart, oldStart + oldSize, newStart, newStart + newSize);\n diff += newSize - oldSize;\n }\n }\n /**\n Create an inverted version of this map. The result can be used to\n map positions in the post-step document to the pre-step document.\n */\n invert() {\n return new StepMap(this.ranges, !this.inverted);\n }\n /**\n @internal\n */\n toString() {\n return (this.inverted ? \"-\" : \"\") + JSON.stringify(this.ranges);\n }\n /**\n Create a map that moves all positions by offset `n` (which may be\n negative). This can be useful when applying steps meant for a\n sub-document to a larger document, or vice-versa.\n */\n static offset(n) {\n return n == 0 ? StepMap.empty : new StepMap(n < 0 ? [0, -n, 0] : [0, 0, n]);\n }\n}\n/**\nA StepMap that contains no changed ranges.\n*/\nStepMap.empty = new StepMap([]);\n/**\nA mapping represents a pipeline of zero or more [step\nmaps](https://prosemirror.net/docs/ref/#transform.StepMap). It has special provisions for losslessly\nhandling mapping positions through a series of steps in which some\nsteps are inverted versions of earlier steps. (This comes up when\n‘[rebasing](https://prosemirror.net/docs/guide/#transform.rebasing)’ steps for\ncollaboration or history management.)\n*/\nclass Mapping {\n /**\n Create a new mapping with the given position maps.\n */\n constructor(maps, \n /**\n @internal\n */\n mirror, \n /**\n The starting position in the `maps` array, used when `map` or\n `mapResult` is called.\n */\n from = 0, \n /**\n The end position in the `maps` array.\n */\n to = maps ? maps.length : 0) {\n this.mirror = mirror;\n this.from = from;\n this.to = to;\n this._maps = maps || [];\n this.ownData = !(maps || mirror);\n }\n /**\n The step maps in this mapping.\n */\n get maps() { return this._maps; }\n /**\n Create a mapping that maps only through a part of this one.\n */\n slice(from = 0, to = this.maps.length) {\n return new Mapping(this._maps, this.mirror, from, to);\n }\n /**\n Add a step map to the end of this mapping. If `mirrors` is\n given, it should be the index of the step map that is the mirror\n image of this one.\n */\n appendMap(map, mirrors) {\n if (!this.ownData) {\n this._maps = this._maps.slice();\n this.mirror = this.mirror && this.mirror.slice();\n this.ownData = true;\n }\n this.to = this._maps.push(map);\n if (mirrors != null)\n this.setMirror(this._maps.length - 1, mirrors);\n }\n /**\n Add all the step maps in a given mapping to this one (preserving\n mirroring information).\n */\n appendMapping(mapping) {\n for (let i = 0, startSize = this._maps.length; i < mapping._maps.length; i++) {\n let mirr = mapping.getMirror(i);\n this.appendMap(mapping._maps[i], mirr != null && mirr < i ? startSize + mirr : undefined);\n }\n }\n /**\n Finds the offset of the step map that mirrors the map at the\n given offset, in this mapping (as per the second argument to\n `appendMap`).\n */\n getMirror(n) {\n if (this.mirror)\n for (let i = 0; i < this.mirror.length; i++)\n if (this.mirror[i] == n)\n return this.mirror[i + (i % 2 ? -1 : 1)];\n }\n /**\n @internal\n */\n setMirror(n, m) {\n if (!this.mirror)\n this.mirror = [];\n this.mirror.push(n, m);\n }\n /**\n Append the inverse of the given mapping to this one.\n */\n appendMappingInverted(mapping) {\n for (let i = mapping.maps.length - 1, totalSize = this._maps.length + mapping._maps.length; i >= 0; i--) {\n let mirr = mapping.getMirror(i);\n this.appendMap(mapping._maps[i].invert(), mirr != null && mirr > i ? totalSize - mirr - 1 : undefined);\n }\n }\n /**\n Create an inverted version of this mapping.\n */\n invert() {\n let inverse = new Mapping;\n inverse.appendMappingInverted(this);\n return inverse;\n }\n /**\n Map a position through this mapping.\n */\n map(pos, assoc = 1) {\n if (this.mirror)\n return this._map(pos, assoc, true);\n for (let i = this.from; i < this.to; i++)\n pos = this._maps[i].map(pos, assoc);\n return pos;\n }\n /**\n Map a position through this mapping, returning a mapping\n result.\n */\n mapResult(pos, assoc = 1) { return this._map(pos, assoc, false); }\n /**\n @internal\n */\n _map(pos, assoc, simple) {\n let delInfo = 0;\n for (let i = this.from; i < this.to; i++) {\n let map = this._maps[i], result = map.mapResult(pos, assoc);\n if (result.recover != null) {\n let corr = this.getMirror(i);\n if (corr != null && corr > i && corr < this.to) {\n i = corr;\n pos = this._maps[corr].recover(result.recover);\n continue;\n }\n }\n delInfo |= result.delInfo;\n pos = result.pos;\n }\n return simple ? pos : new MapResult(pos, delInfo, null);\n }\n}\n\nconst stepsByID = Object.create(null);\n/**\nA step object represents an atomic change. It generally applies\nonly to the document it was created for, since the positions\nstored in it will only make sense for that document.\n\nNew steps are defined by creating classes that extend `Step`,\noverriding the `apply`, `invert`, `map`, `getMap` and `fromJSON`\nmethods, and registering your class with a unique\nJSON-serialization identifier using\n[`Step.jsonID`](https://prosemirror.net/docs/ref/#transform.Step^jsonID).\n*/\nclass Step {\n /**\n Get the step map that represents the changes made by this step,\n and which can be used to transform between positions in the old\n and the new document.\n */\n getMap() { return StepMap.empty; }\n /**\n Try to merge this step with another one, to be applied directly\n after it. Returns the merged step when possible, null if the\n steps can't be merged.\n */\n merge(other) { return null; }\n /**\n Deserialize a step from its JSON representation. Will call\n through to the step class' own implementation of this method.\n */\n static fromJSON(schema, json) {\n if (!json || !json.stepType)\n throw new RangeError(\"Invalid input for Step.fromJSON\");\n let type = stepsByID[json.stepType];\n if (!type)\n throw new RangeError(`No step type ${json.stepType} defined`);\n return type.fromJSON(schema, json);\n }\n /**\n To be able to serialize steps to JSON, each step needs a string\n ID to attach to its JSON representation. Use this method to\n register an ID for your step classes. Try to pick something\n that's unlikely to clash with steps from other modules.\n */\n static jsonID(id, stepClass) {\n if (id in stepsByID)\n throw new RangeError(\"Duplicate use of step JSON ID \" + id);\n stepsByID[id] = stepClass;\n stepClass.prototype.jsonID = id;\n return stepClass;\n }\n}\n/**\nThe result of [applying](https://prosemirror.net/docs/ref/#transform.Step.apply) a step. Contains either a\nnew document or a failure value.\n*/\nclass StepResult {\n /**\n @internal\n */\n constructor(\n /**\n The transformed document, if successful.\n */\n doc, \n /**\n The failure message, if unsuccessful.\n */\n failed) {\n this.doc = doc;\n this.failed = failed;\n }\n /**\n Create a successful step result.\n */\n static ok(doc) { return new StepResult(doc, null); }\n /**\n Create a failed step result.\n */\n static fail(message) { return new StepResult(null, message); }\n /**\n Call [`Node.replace`](https://prosemirror.net/docs/ref/#model.Node.replace) with the given\n arguments. Create a successful result if it succeeds, and a\n failed one if it throws a `ReplaceError`.\n */\n static fromReplace(doc, from, to, slice) {\n try {\n return StepResult.ok(doc.replace(from, to, slice));\n }\n catch (e) {\n if (e instanceof ReplaceError)\n return StepResult.fail(e.message);\n throw e;\n }\n }\n}\n\nfunction mapFragment(fragment, f, parent) {\n let mapped = [];\n for (let i = 0; i < fragment.childCount; i++) {\n let child = fragment.child(i);\n if (child.content.size)\n child = child.copy(mapFragment(child.content, f, child));\n if (child.isInline)\n child = f(child, parent, i);\n mapped.push(child);\n }\n return Fragment.fromArray(mapped);\n}\n/**\nAdd a mark to all inline content between two positions.\n*/\nclass AddMarkStep extends Step {\n /**\n Create a mark step.\n */\n constructor(\n /**\n The start of the marked range.\n */\n from, \n /**\n The end of the marked range.\n */\n to, \n /**\n The mark to add.\n */\n mark) {\n super();\n this.from = from;\n this.to = to;\n this.mark = mark;\n }\n apply(doc) {\n let oldSlice = doc.slice(this.from, this.to), $from = doc.resolve(this.from);\n let parent = $from.node($from.sharedDepth(this.to));\n let slice = new Slice(mapFragment(oldSlice.content, (node, parent) => {\n if (!node.isAtom || !parent.type.allowsMarkType(this.mark.type))\n return node;\n return node.mark(this.mark.addToSet(node.marks));\n }, parent), oldSlice.openStart, oldSlice.openEnd);\n return StepResult.fromReplace(doc, this.from, this.to, slice);\n }\n invert() {\n return new RemoveMarkStep(this.from, this.to, this.mark);\n }\n map(mapping) {\n let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);\n if (from.deleted && to.deleted || from.pos >= to.pos)\n return null;\n return new AddMarkStep(from.pos, to.pos, this.mark);\n }\n merge(other) {\n if (other instanceof AddMarkStep &&\n other.mark.eq(this.mark) &&\n this.from <= other.to && this.to >= other.from)\n return new AddMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);\n return null;\n }\n toJSON() {\n return { stepType: \"addMark\", mark: this.mark.toJSON(),\n from: this.from, to: this.to };\n }\n /**\n @internal\n */\n static fromJSON(schema, json) {\n if (typeof json.from != \"number\" || typeof json.to != \"number\")\n throw new RangeError(\"Invalid input for AddMarkStep.fromJSON\");\n return new AddMarkStep(json.from, json.to, schema.markFromJSON(json.mark));\n }\n}\nStep.jsonID(\"addMark\", AddMarkStep);\n/**\nRemove a mark from all inline content between two positions.\n*/\nclass RemoveMarkStep extends Step {\n /**\n Create a mark-removing step.\n */\n constructor(\n /**\n The start of the unmarked range.\n */\n from, \n /**\n The end of the unmarked range.\n */\n to, \n /**\n The mark to remove.\n */\n mark) {\n super();\n this.from = from;\n this.to = to;\n this.mark = mark;\n }\n apply(doc) {\n let oldSlice = doc.slice(this.from, this.to);\n let slice = new Slice(mapFragment(oldSlice.content, node => {\n return node.mark(this.mark.removeFromSet(node.marks));\n }, doc), oldSlice.openStart, oldSlice.openEnd);\n return StepResult.fromReplace(doc, this.from, this.to, slice);\n }\n invert() {\n return new AddMarkStep(this.from, this.to, this.mark);\n }\n map(mapping) {\n let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);\n if (from.deleted && to.deleted || from.pos >= to.pos)\n return null;\n return new RemoveMarkStep(from.pos, to.pos, this.mark);\n }\n merge(other) {\n if (other instanceof RemoveMarkStep &&\n other.mark.eq(this.mark) &&\n this.from <= other.to && this.to >= other.from)\n return new RemoveMarkStep(Math.min(this.from, other.from), Math.max(this.to, other.to), this.mark);\n return null;\n }\n toJSON() {\n return { stepType: \"removeMark\", mark: this.mark.toJSON(),\n from: this.from, to: this.to };\n }\n /**\n @internal\n */\n static fromJSON(schema, json) {\n if (typeof json.from != \"number\" || typeof json.to != \"number\")\n throw new RangeError(\"Invalid input for RemoveMarkStep.fromJSON\");\n return new RemoveMarkStep(json.from, json.to, schema.markFromJSON(json.mark));\n }\n}\nStep.jsonID(\"removeMark\", RemoveMarkStep);\n/**\nAdd a mark to a specific node.\n*/\nclass AddNodeMarkStep extends Step {\n /**\n Create a node mark step.\n */\n constructor(\n /**\n The position of the target node.\n */\n pos, \n /**\n The mark to add.\n */\n mark) {\n super();\n this.pos = pos;\n this.mark = mark;\n }\n apply(doc) {\n let node = doc.nodeAt(this.pos);\n if (!node)\n return StepResult.fail(\"No node at mark step's position\");\n let updated = node.type.create(node.attrs, null, this.mark.addToSet(node.marks));\n return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));\n }\n invert(doc) {\n let node = doc.nodeAt(this.pos);\n if (node) {\n let newSet = this.mark.addToSet(node.marks);\n if (newSet.length == node.marks.length) {\n for (let i = 0; i < node.marks.length; i++)\n if (!node.marks[i].isInSet(newSet))\n return new AddNodeMarkStep(this.pos, node.marks[i]);\n return new AddNodeMarkStep(this.pos, this.mark);\n }\n }\n return new RemoveNodeMarkStep(this.pos, this.mark);\n }\n map(mapping) {\n let pos = mapping.mapResult(this.pos, 1);\n return pos.deletedAfter ? null : new AddNodeMarkStep(pos.pos, this.mark);\n }\n toJSON() {\n return { stepType: \"addNodeMark\", pos: this.pos, mark: this.mark.toJSON() };\n }\n /**\n @internal\n */\n static fromJSON(schema, json) {\n if (typeof json.pos != \"number\")\n throw new RangeError(\"Invalid input for AddNodeMarkStep.fromJSON\");\n return new AddNodeMarkStep(json.pos, schema.markFromJSON(json.mark));\n }\n}\nStep.jsonID(\"addNodeMark\", AddNodeMarkStep);\n/**\nRemove a mark from a specific node.\n*/\nclass RemoveNodeMarkStep extends Step {\n /**\n Create a mark-removing step.\n */\n constructor(\n /**\n The position of the target node.\n */\n pos, \n /**\n The mark to remove.\n */\n mark) {\n super();\n this.pos = pos;\n this.mark = mark;\n }\n apply(doc) {\n let node = doc.nodeAt(this.pos);\n if (!node)\n return StepResult.fail(\"No node at mark step's position\");\n let updated = node.type.create(node.attrs, null, this.mark.removeFromSet(node.marks));\n return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));\n }\n invert(doc) {\n let node = doc.nodeAt(this.pos);\n if (!node || !this.mark.isInSet(node.marks))\n return this;\n return new AddNodeMarkStep(this.pos, this.mark);\n }\n map(mapping) {\n let pos = mapping.mapResult(this.pos, 1);\n return pos.deletedAfter ? null : new RemoveNodeMarkStep(pos.pos, this.mark);\n }\n toJSON() {\n return { stepType: \"removeNodeMark\", pos: this.pos, mark: this.mark.toJSON() };\n }\n /**\n @internal\n */\n static fromJSON(schema, json) {\n if (typeof json.pos != \"number\")\n throw new RangeError(\"Invalid input for RemoveNodeMarkStep.fromJSON\");\n return new RemoveNodeMarkStep(json.pos, schema.markFromJSON(json.mark));\n }\n}\nStep.jsonID(\"removeNodeMark\", RemoveNodeMarkStep);\n\n/**\nReplace a part of the document with a slice of new content.\n*/\nclass ReplaceStep extends Step {\n /**\n The given `slice` should fit the 'gap' between `from` and\n `to`—the depths must line up, and the surrounding nodes must be\n able to be joined with the open sides of the slice. When\n `structure` is true, the step will fail if the content between\n from and to is not just a sequence of closing and then opening\n tokens (this is to guard against rebased replace steps\n overwriting something they weren't supposed to).\n */\n constructor(\n /**\n The start position of the replaced range.\n */\n from, \n /**\n The end position of the replaced range.\n */\n to, \n /**\n The slice to insert.\n */\n slice, \n /**\n @internal\n */\n structure = false) {\n super();\n this.from = from;\n this.to = to;\n this.slice = slice;\n this.structure = structure;\n }\n apply(doc) {\n if (this.structure && contentBetween(doc, this.from, this.to))\n return StepResult.fail(\"Structure replace would overwrite content\");\n return StepResult.fromReplace(doc, this.from, this.to, this.slice);\n }\n getMap() {\n return new StepMap([this.from, this.to - this.from, this.slice.size]);\n }\n invert(doc) {\n return new ReplaceStep(this.from, this.from + this.slice.size, doc.slice(this.from, this.to));\n }\n map(mapping) {\n let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);\n if (from.deletedAcross && to.deletedAcross)\n return null;\n return new ReplaceStep(from.pos, Math.max(from.pos, to.pos), this.slice, this.structure);\n }\n merge(other) {\n if (!(other instanceof ReplaceStep) || other.structure || this.structure)\n return null;\n if (this.from + this.slice.size == other.from && !this.slice.openEnd && !other.slice.openStart) {\n let slice = this.slice.size + other.slice.size == 0 ? Slice.empty\n : new Slice(this.slice.content.append(other.slice.content), this.slice.openStart, other.slice.openEnd);\n return new ReplaceStep(this.from, this.to + (other.to - other.from), slice, this.structure);\n }\n else if (other.to == this.from && !this.slice.openStart && !other.slice.openEnd) {\n let slice = this.slice.size + other.slice.size == 0 ? Slice.empty\n : new Slice(other.slice.content.append(this.slice.content), other.slice.openStart, this.slice.openEnd);\n return new ReplaceStep(other.from, this.to, slice, this.structure);\n }\n else {\n return null;\n }\n }\n toJSON() {\n let json = { stepType: \"replace\", from: this.from, to: this.to };\n if (this.slice.size)\n json.slice = this.slice.toJSON();\n if (this.structure)\n json.structure = true;\n return json;\n }\n /**\n @internal\n */\n static fromJSON(schema, json) {\n if (typeof json.from != \"number\" || typeof json.to != \"number\")\n throw new RangeError(\"Invalid input for ReplaceStep.fromJSON\");\n return new ReplaceStep(json.from, json.to, Slice.fromJSON(schema, json.slice), !!json.structure);\n }\n}\nStep.jsonID(\"replace\", ReplaceStep);\n/**\nReplace a part of the document with a slice of content, but\npreserve a range of the replaced content by moving it into the\nslice.\n*/\nclass ReplaceAroundStep extends Step {\n /**\n Create a replace-around step with the given range and gap.\n `insert` should be the point in the slice into which the content\n of the gap should be moved. `structure` has the same meaning as\n it has in the [`ReplaceStep`](https://prosemirror.net/docs/ref/#transform.ReplaceStep) class.\n */\n constructor(\n /**\n The start position of the replaced range.\n */\n from, \n /**\n The end position of the replaced range.\n */\n to, \n /**\n The start of preserved range.\n */\n gapFrom, \n /**\n The end of preserved range.\n */\n gapTo, \n /**\n The slice to insert.\n */\n slice, \n /**\n The position in the slice where the preserved range should be\n inserted.\n */\n insert, \n /**\n @internal\n */\n structure = false) {\n super();\n this.from = from;\n this.to = to;\n this.gapFrom = gapFrom;\n this.gapTo = gapTo;\n this.slice = slice;\n this.insert = insert;\n this.structure = structure;\n }\n apply(doc) {\n if (this.structure && (contentBetween(doc, this.from, this.gapFrom) ||\n contentBetween(doc, this.gapTo, this.to)))\n return StepResult.fail(\"Structure gap-replace would overwrite content\");\n let gap = doc.slice(this.gapFrom, this.gapTo);\n if (gap.openStart || gap.openEnd)\n return StepResult.fail(\"Gap is not a flat range\");\n let inserted = this.slice.insertAt(this.insert, gap.content);\n if (!inserted)\n return StepResult.fail(\"Content does not fit in gap\");\n return StepResult.fromReplace(doc, this.from, this.to, inserted);\n }\n getMap() {\n return new StepMap([this.from, this.gapFrom - this.from, this.insert,\n this.gapTo, this.to - this.gapTo, this.slice.size - this.insert]);\n }\n invert(doc) {\n let gap = this.gapTo - this.gapFrom;\n return new ReplaceAroundStep(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);\n }\n map(mapping) {\n let from = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);\n let gapFrom = this.from == this.gapFrom ? from.pos : mapping.map(this.gapFrom, -1);\n let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);\n if ((from.deletedAcross && to.deletedAcross) || gapFrom < from.pos || gapTo > to.pos)\n return null;\n return new ReplaceAroundStep(from.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);\n }\n toJSON() {\n let json = { stepType: \"replaceAround\", from: this.from, to: this.to,\n gapFrom: this.gapFrom, gapTo: this.gapTo, insert: this.insert };\n if (this.slice.size)\n json.slice = this.slice.toJSON();\n if (this.structure)\n json.structure = true;\n return json;\n }\n /**\n @internal\n */\n static fromJSON(schema, json) {\n if (typeof json.from != \"number\" || typeof json.to != \"number\" ||\n typeof json.gapFrom != \"number\" || typeof json.gapTo != \"number\" || typeof json.insert != \"number\")\n throw new RangeError(\"Invalid input for ReplaceAroundStep.fromJSON\");\n return new ReplaceAroundStep(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);\n }\n}\nStep.jsonID(\"replaceAround\", ReplaceAroundStep);\nfunction contentBetween(doc, from, to) {\n let $from = doc.resolve(from), dist = to - from, depth = $from.depth;\n while (dist > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {\n depth--;\n dist--;\n }\n if (dist > 0) {\n let next = $from.node(depth).maybeChild($from.indexAfter(depth));\n while (dist > 0) {\n if (!next || next.isLeaf)\n return true;\n next = next.firstChild;\n dist--;\n }\n }\n return false;\n}\n\nfunction addMark(tr, from, to, mark) {\n let removed = [], added = [];\n let removing, adding;\n tr.doc.nodesBetween(from, to, (node, pos, parent) => {\n if (!node.isInline)\n return;\n let marks = node.marks;\n if (!mark.isInSet(marks) && parent.type.allowsMarkType(mark.type)) {\n let start = Math.max(pos, from), end = Math.min(pos + node.nodeSize, to);\n let newSet = mark.addToSet(marks);\n for (let i = 0; i < marks.length; i++) {\n if (!marks[i].isInSet(newSet)) {\n if (removing && removing.to == start && removing.mark.eq(marks[i]))\n removing.to = end;\n else\n removed.push(removing = new RemoveMarkStep(start, end, marks[i]));\n }\n }\n if (adding && adding.to == start)\n adding.to = end;\n else\n added.push(adding = new AddMarkStep(start, end, mark));\n }\n });\n removed.forEach(s => tr.step(s));\n added.forEach(s => tr.step(s));\n}\nfunction removeMark(tr, from, to, mark) {\n let matched = [], step = 0;\n tr.doc.nodesBetween(from, to, (node, pos) => {\n if (!node.isInline)\n return;\n step++;\n let toRemove = null;\n if (mark instanceof MarkType) {\n let set = node.marks, found;\n while (found = mark.isInSet(set)) {\n (toRemove || (toRemove = [])).push(found);\n set = found.removeFromSet(set);\n }\n }\n else if (mark) {\n if (mark.isInSet(node.marks))\n toRemove = [mark];\n }\n else {\n toRemove = node.marks;\n }\n if (toRemove && toRemove.length) {\n let end = Math.min(pos + node.nodeSize, to);\n for (let i = 0; i < toRemove.length; i++) {\n let style = toRemove[i], found;\n for (let j = 0; j < matched.length; j++) {\n let m = matched[j];\n if (m.step == step - 1 && style.eq(matched[j].style))\n found = m;\n }\n if (found) {\n found.to = end;\n found.step = step;\n }\n else {\n matched.push({ style, from: Math.max(pos, from), to: end, step });\n }\n }\n }\n });\n matched.forEach(m => tr.step(new RemoveMarkStep(m.from, m.to, m.style)));\n}\nfunction clearIncompatible(tr, pos, parentType, match = parentType.contentMatch, clearNewlines = true) {\n let node = tr.doc.nodeAt(pos);\n let replSteps = [], cur = pos + 1;\n for (let i = 0; i < node.childCount; i++) {\n let child = node.child(i), end = cur + child.nodeSize;\n let allowed = match.matchType(child.type);\n if (!allowed) {\n replSteps.push(new ReplaceStep(cur, end, Slice.empty));\n }\n else {\n match = allowed;\n for (let j = 0; j < child.marks.length; j++)\n if (!parentType.allowsMarkType(child.marks[j].type))\n tr.step(new RemoveMarkStep(cur, end, child.marks[j]));\n if (clearNewlines && child.isText && parentType.whitespace != \"pre\") {\n let m, newline = /\\r?\\n|\\r/g, slice;\n while (m = newline.exec(child.text)) {\n if (!slice)\n slice = new Slice(Fragment.from(parentType.schema.text(\" \", parentType.allowedMarks(child.marks))), 0, 0);\n replSteps.push(new ReplaceStep(cur + m.index, cur + m.index + m[0].length, slice));\n }\n }\n }\n cur = end;\n }\n if (!match.validEnd) {\n let fill = match.fillBefore(Fragment.empty, true);\n tr.replace(cur, cur, new Slice(fill, 0, 0));\n }\n for (let i = replSteps.length - 1; i >= 0; i--)\n tr.step(replSteps[i]);\n}\n\nfunction canCut(node, start, end) {\n return (start == 0 || node.canReplace(start, node.childCount)) &&\n (end == node.childCount || node.canReplace(0, end));\n}\n/**\nTry to find a target depth to which the content in the given range\ncan be lifted. Will not go across\n[isolating](https://prosemirror.net/docs/ref/#model.NodeSpec.isolating) parent nodes.\n*/\nfunction liftTarget(range) {\n let parent = range.parent;\n let content = parent.content.cutByIndex(range.startIndex, range.endIndex);\n for (let depth = range.depth;; --depth) {\n let node = range.$from.node(depth);\n let index = range.$from.index(depth), endIndex = range.$to.indexAfter(depth);\n if (depth < range.depth && node.canReplace(index, endIndex, content))\n return depth;\n if (depth == 0 || node.type.spec.isolating || !canCut(node, index, endIndex))\n break;\n }\n return null;\n}\nfunction lift(tr, range, target) {\n let { $from, $to, depth } = range;\n let gapStart = $from.before(depth + 1), gapEnd = $to.after(depth + 1);\n let start = gapStart, end = gapEnd;\n let before = Fragment.empty, openStart = 0;\n for (let d = depth, splitting = false; d > target; d--)\n if (splitting || $from.index(d) > 0) {\n splitting = true;\n before = Fragment.from($from.node(d).copy(before));\n openStart++;\n }\n else {\n start--;\n }\n let after = Fragment.empty, openEnd = 0;\n for (let d = depth, splitting = false; d > target; d--)\n if (splitting || $to.after(d + 1) < $to.end(d)) {\n splitting = true;\n after = Fragment.from($to.node(d).copy(after));\n openEnd++;\n }\n else {\n end++;\n }\n tr.step(new ReplaceAroundStep(start, end, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true));\n}\n/**\nTry to find a valid way to wrap the content in the given range in a\nnode of the given type. May introduce extra nodes around and inside\nthe wrapper node, if necessary. Returns null if no valid wrapping\ncould be found. When `innerRange` is given, that range's content is\nused as the content to fit into the wrapping, instead of the\ncontent of `range`.\n*/\nfunction findWrapping(range, nodeType, attrs = null, innerRange = range) {\n let around = findWrappingOutside(range, nodeType);\n let inner = around && findWrappingInside(innerRange, nodeType);\n if (!inner)\n return null;\n return around.map(withAttrs)\n .concat({ type: nodeType, attrs }).concat(inner.map(withAttrs));\n}\nfunction withAttrs(type) { return { type, attrs: null }; }\nfunction findWrappingOutside(range, type) {\n let { parent, startIndex, endIndex } = range;\n let around = parent.contentMatchAt(startIndex).findWrapping(type);\n if (!around)\n return null;\n let outer = around.length ? around[0] : type;\n return parent.canReplaceWith(startIndex, endIndex, outer) ? around : null;\n}\nfunction findWrappingInside(range, type) {\n let { parent, startIndex, endIndex } = range;\n let inner = parent.child(startIndex);\n let inside = type.contentMatch.findWrapping(inner.type);\n if (!inside)\n return null;\n let lastType = inside.length ? inside[inside.length - 1] : type;\n let innerMatch = lastType.contentMatch;\n for (let i = startIndex; innerMatch && i < endIndex; i++)\n innerMatch = innerMatch.matchType(parent.child(i).type);\n if (!innerMatch || !innerMatch.validEnd)\n return null;\n return inside;\n}\nfunction wrap(tr, range, wrappers) {\n let content = Fragment.empty;\n for (let i = wrappers.length - 1; i >= 0; i--) {\n if (content.size) {\n let match = wrappers[i].type.contentMatch.matchFragment(content);\n if (!match || !match.validEnd)\n throw new RangeError(\"Wrapper type given to Transform.wrap does not form valid content of its parent wrapper\");\n }\n content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));\n }\n let start = range.start, end = range.end;\n tr.step(new ReplaceAroundStep(start, end, start, end, new Slice(content, 0, 0), wrappers.length, true));\n}\nfunction setBlockType(tr, from, to, type, attrs) {\n if (!type.isTextblock)\n throw new RangeError(\"Type given to setBlockType should be a textblock\");\n let mapFrom = tr.steps.length;\n tr.doc.nodesBetween(from, to, (node, pos) => {\n let attrsHere = typeof attrs == \"function\" ? attrs(node) : attrs;\n if (node.isTextblock && !node.hasMarkup(type, attrsHere) &&\n canChangeType(tr.doc, tr.mapping.slice(mapFrom).map(pos), type)) {\n let convertNewlines = null;\n if (type.schema.linebreakReplacement) {\n let pre = type.whitespace == \"pre\", supportLinebreak = !!type.contentMatch.matchType(type.schema.linebreakReplacement);\n if (pre && !supportLinebreak)\n convertNewlines = false;\n else if (!pre && supportLinebreak)\n convertNewlines = true;\n }\n // Ensure all markup that isn't allowed in the new node type is cleared\n if (convertNewlines === false)\n replaceLinebreaks(tr, node, pos, mapFrom);\n clearIncompatible(tr, tr.mapping.slice(mapFrom).map(pos, 1), type, undefined, convertNewlines === null);\n let mapping = tr.mapping.slice(mapFrom);\n let startM = mapping.map(pos, 1), endM = mapping.map(pos + node.nodeSize, 1);\n tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type.create(attrsHere, null, node.marks)), 0, 0), 1, true));\n if (convertNewlines === true)\n replaceNewlines(tr, node, pos, mapFrom);\n return false;\n }\n });\n}\nfunction replaceNewlines(tr, node, pos, mapFrom) {\n node.forEach((child, offset) => {\n if (child.isText) {\n let m, newline = /\\r?\\n|\\r/g;\n while (m = newline.exec(child.text)) {\n let start = tr.mapping.slice(mapFrom).map(pos + 1 + offset + m.index);\n tr.replaceWith(start, start + 1, node.type.schema.linebreakReplacement.create());\n }\n }\n });\n}\nfunction replaceLinebreaks(tr, node, pos, mapFrom) {\n node.forEach((child, offset) => {\n if (child.type == child.type.schema.linebreakReplacement) {\n let start = tr.mapping.slice(mapFrom).map(pos + 1 + offset);\n tr.replaceWith(start, start + 1, node.type.schema.text(\"\\n\"));\n }\n });\n}\nfunction canChangeType(doc, pos, type) {\n let $pos = doc.resolve(pos), index = $pos.index();\n return $pos.parent.canReplaceWith(index, index + 1, type);\n}\n/**\nChange the type, attributes, and/or marks of the node at `pos`.\nWhen `type` isn't given, the existing node type is preserved,\n*/\nfunction setNodeMarkup(tr, pos, type, attrs, marks) {\n let node = tr.doc.nodeAt(pos);\n if (!node)\n throw new RangeError(\"No node at given position\");\n if (!type)\n type = node.type;\n let newNode = type.create(attrs, null, marks || node.marks);\n if (node.isLeaf)\n return tr.replaceWith(pos, pos + node.nodeSize, newNode);\n if (!type.validContent(node.content))\n throw new RangeError(\"Invalid content for node type \" + type.name);\n tr.step(new ReplaceAroundStep(pos, pos + node.nodeSize, pos + 1, pos + node.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true));\n}\n/**\nCheck whether splitting at the given position is allowed.\n*/\nfunction canSplit(doc, pos, depth = 1, typesAfter) {\n let $pos = doc.resolve(pos), base = $pos.depth - depth;\n let innerType = (typesAfter && typesAfter[typesAfter.length - 1]) || $pos.parent;\n if (base < 0 || $pos.parent.type.spec.isolating ||\n !$pos.parent.canReplace($pos.index(), $pos.parent.childCount) ||\n !innerType.type.validContent($pos.parent.content.cutByIndex($pos.index(), $pos.parent.childCount)))\n return false;\n for (let d = $pos.depth - 1, i = depth - 2; d > base; d--, i--) {\n let node = $pos.node(d), index = $pos.index(d);\n if (node.type.spec.isolating)\n return false;\n let rest = node.content.cutByIndex(index, node.childCount);\n let overrideChild = typesAfter && typesAfter[i + 1];\n if (overrideChild)\n rest = rest.replaceChild(0, overrideChild.type.create(overrideChild.attrs));\n let after = (typesAfter && typesAfter[i]) || node;\n if (!node.canReplace(index + 1, node.childCount) || !after.type.validContent(rest))\n return false;\n }\n let index = $pos.indexAfter(base);\n let baseType = typesAfter && typesAfter[0];\n return $pos.node(base).canReplaceWith(index, index, baseType ? baseType.type : $pos.node(base + 1).type);\n}\nfunction split(tr, pos, depth = 1, typesAfter) {\n let $pos = tr.doc.resolve(pos), before = Fragment.empty, after = Fragment.empty;\n for (let d = $pos.depth, e = $pos.depth - depth, i = depth - 1; d > e; d--, i--) {\n before = Fragment.from($pos.node(d).copy(before));\n let typeAfter = typesAfter && typesAfter[i];\n after = Fragment.from(typeAfter ? typeAfter.type.create(typeAfter.attrs, after) : $pos.node(d).copy(after));\n }\n tr.step(new ReplaceStep(pos, pos, new Slice(before.append(after), depth, depth), true));\n}\n/**\nTest whether the blocks before and after a given position can be\njoined.\n*/\nfunction canJoin(doc, pos) {\n let $pos = doc.resolve(pos), index = $pos.index();\n return joinable($pos.nodeBefore, $pos.nodeAfter) &&\n $pos.parent.canReplace(index, index + 1);\n}\nfunction canAppendWithSubstitutedLinebreaks(a, b) {\n if (!b.content.size)\n a.type.compatibleContent(b.type);\n let match = a.contentMatchAt(a.childCount);\n let { linebreakReplacement } = a.type.schema;\n for (let i = 0; i < b.childCount; i++) {\n let child = b.child(i);\n let type = child.type == linebreakReplacement ? a.type.schema.nodes.text : child.type;\n match = match.matchType(type);\n if (!match)\n return false;\n if (!a.type.allowsMarks(child.marks))\n return false;\n }\n return match.validEnd;\n}\nfunction joinable(a, b) {\n return !!(a && b && !a.isLeaf && canAppendWithSubstitutedLinebreaks(a, b));\n}\n/**\nFind an ancestor of the given position that can be joined to the\nblock before (or after if `dir` is positive). Returns the joinable\npoint, if any.\n*/\nfunction joinPoint(doc, pos, dir = -1) {\n let $pos = doc.resolve(pos);\n for (let d = $pos.depth;; d--) {\n let before, after, index = $pos.index(d);\n if (d == $pos.depth) {\n before = $pos.nodeBefore;\n after = $pos.nodeAfter;\n }\n else if (dir > 0) {\n before = $pos.node(d + 1);\n index++;\n after = $pos.node(d).maybeChild(index);\n }\n else {\n before = $pos.node(d).maybeChild(index - 1);\n after = $pos.node(d + 1);\n }\n if (before && !before.isTextblock && joinable(before, after) &&\n $pos.node(d).canReplace(index, index + 1))\n return pos;\n if (d == 0)\n break;\n pos = dir < 0 ? $pos.before(d) : $pos.after(d);\n }\n}\nfunction join(tr, pos, depth) {\n let convertNewlines = null;\n let { linebreakReplacement } = tr.doc.type.schema;\n let $before = tr.doc.resolve(pos - depth), beforeType = $before.node().type;\n if (linebreakReplacement && beforeType.inlineContent) {\n let pre = beforeType.whitespace == \"pre\";\n let supportLinebreak = !!beforeType.contentMatch.matchType(linebreakReplacement);\n if (pre && !supportLinebreak)\n convertNewlines = false;\n else if (!pre && supportLinebreak)\n convertNewlines = true;\n }\n let mapFrom = tr.steps.length;\n if (convertNewlines === false) {\n let $after = tr.doc.resolve(pos + depth);\n replaceLinebreaks(tr, $after.node(), $after.before(), mapFrom);\n }\n if (beforeType.inlineContent)\n clearIncompatible(tr, pos + depth - 1, beforeType, $before.node().contentMatchAt($before.index()), convertNewlines == null);\n let mapping = tr.mapping.slice(mapFrom), start = mapping.map(pos - depth);\n tr.step(new ReplaceStep(start, mapping.map(pos + depth, -1), Slice.empty, true));\n if (convertNewlines === true) {\n let $full = tr.doc.resolve(start);\n replaceNewlines(tr, $full.node(), $full.before(), tr.steps.length);\n }\n return tr;\n}\n/**\nTry to find a point where a node of the given type can be inserted\nnear `pos`, by searching up the node hierarchy when `pos` itself\nisn't a valid place but is at the start or end of a node. Return\nnull if no position was found.\n*/\nfunction insertPoint(doc, pos, nodeType) {\n let $pos = doc.resolve(pos);\n if ($pos.parent.canReplaceWith($pos.index(), $pos.index(), nodeType))\n return pos;\n if ($pos.parentOffset == 0)\n for (let d = $pos.depth - 1; d >= 0; d--) {\n let index = $pos.index(d);\n if ($pos.node(d).canReplaceWith(index, index, nodeType))\n return $pos.before(d + 1);\n if (index > 0)\n return null;\n }\n if ($pos.parentOffset == $pos.parent.content.size)\n for (let d = $pos.depth - 1; d >= 0; d--) {\n let index = $pos.indexAfter(d);\n if ($pos.node(d).canReplaceWith(index, index, nodeType))\n return $pos.after(d + 1);\n if (index < $pos.node(d).childCount)\n return null;\n }\n return null;\n}\n/**\nFinds a position at or around the given position where the given\nslice can be inserted. Will look at parent nodes' nearest boundary\nand try there, even if the original position wasn't directly at the\nstart or end of that node. Returns null when no position was found.\n*/\nfunction dropPoint(doc, pos, slice) {\n let $pos = doc.resolve(pos);\n if (!slice.content.size)\n return pos;\n let content = slice.content;\n for (let i = 0; i < slice.openStart; i++)\n content = content.firstChild.content;\n for (let pass = 1; pass <= (slice.openStart == 0 && slice.size ? 2 : 1); pass++) {\n for (let d = $pos.depth; d >= 0; d--) {\n let bias = d == $pos.depth ? 0 : $pos.pos <= ($pos.start(d + 1) + $pos.end(d + 1)) / 2 ? -1 : 1;\n let insertPos = $pos.index(d) + (bias > 0 ? 1 : 0);\n let parent = $pos.node(d), fits = false;\n if (pass == 1) {\n fits = parent.canReplace(insertPos, insertPos, content);\n }\n else {\n let wrapping = parent.contentMatchAt(insertPos).findWrapping(content.firstChild.type);\n fits = wrapping && parent.canReplaceWith(insertPos, insertPos, wrapping[0]);\n }\n if (fits)\n return bias == 0 ? $pos.pos : bias < 0 ? $pos.before(d + 1) : $pos.after(d + 1);\n }\n }\n return null;\n}\n\n/**\n‘Fit’ a slice into a given position in the document, producing a\n[step](https://prosemirror.net/docs/ref/#transform.Step) that inserts it. Will return null if\nthere's no meaningful way to insert the slice here, or inserting it\nwould be a no-op (an empty slice over an empty range).\n*/\nfunction replaceStep(doc, from, to = from, slice = Slice.empty) {\n if (from == to && !slice.size)\n return null;\n let $from = doc.resolve(from), $to = doc.resolve(to);\n // Optimization -- avoid work if it's obvious that it's not needed.\n if (fitsTrivially($from, $to, slice))\n return new ReplaceStep(from, to, slice);\n return new Fitter($from, $to, slice).fit();\n}\nfunction fitsTrivially($from, $to, slice) {\n return !slice.openStart && !slice.openEnd && $from.start() == $to.start() &&\n $from.parent.canReplace($from.index(), $to.index(), slice.content);\n}\n// Algorithm for 'placing' the elements of a slice into a gap:\n//\n// We consider the content of each node that is open to the left to be\n// independently placeable. I.e. in <p(\"foo\"), p(\"bar\")>, when the\n// paragraph on the left is open, \"foo\" can be placed (somewhere on\n// the left side of the replacement gap) independently from p(\"bar\").\n//\n// This class tracks the state of the placement progress in the\n// following properties:\n//\n// - `frontier` holds a stack of `{type, match}` objects that\n// represent the open side of the replacement. It starts at\n// `$from`, then moves forward as content is placed, and is finally\n// reconciled with `$to`.\n//\n// - `unplaced` is a slice that represents the content that hasn't\n// been placed yet.\n//\n// - `placed` is a fragment of placed content. Its open-start value\n// is implicit in `$from`, and its open-end value in `frontier`.\nclass Fitter {\n constructor($from, $to, unplaced) {\n this.$from = $from;\n this.$to = $to;\n this.unplaced = unplaced;\n this.frontier = [];\n this.placed = Fragment.empty;\n for (let i = 0; i <= $from.depth; i++) {\n let node = $from.node(i);\n this.frontier.push({\n type: node.type,\n match: node.contentMatchAt($from.indexAfter(i))\n });\n }\n for (let i = $from.depth; i > 0; i--)\n this.placed = Fragment.from($from.node(i).copy(this.placed));\n }\n get depth() { return this.frontier.length - 1; }\n fit() {\n // As long as there's unplaced content, try to place some of it.\n // If that fails, either increase the open score of the unplaced\n // slice, or drop nodes from it, and then try again.\n while (this.unplaced.size) {\n let fit = this.findFittable();\n if (fit)\n this.placeNodes(fit);\n else\n this.openMore() || this.dropNode();\n }\n // When there's inline content directly after the frontier _and_\n // directly after `this.$to`, we must generate a `ReplaceAround`\n // step that pulls that content into the node after the frontier.\n // That means the fitting must be done to the end of the textblock\n // node after `this.$to`, not `this.$to` itself.\n let moveInline = this.mustMoveInline(), placedSize = this.placed.size - this.depth - this.$from.depth;\n let $from = this.$from, $to = this.close(moveInline < 0 ? this.$to : $from.doc.resolve(moveInline));\n if (!$to)\n return null;\n // If closing to `$to` succeeded, create a step\n let content = this.placed, openStart = $from.depth, openEnd = $to.depth;\n while (openStart && openEnd && content.childCount == 1) { // Normalize by dropping open parent nodes\n content = content.firstChild.content;\n openStart--;\n openEnd--;\n }\n let slice = new Slice(content, openStart, openEnd);\n if (moveInline > -1)\n return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice, placedSize);\n if (slice.size || $from.pos != this.$to.pos) // Don't generate no-op steps\n return new ReplaceStep($from.pos, $to.pos, slice);\n return null;\n }\n // Find a position on the start spine of `this.unplaced` that has\n // content that can be moved somewhere on the frontier. Returns two\n // depths, one for the slice and one for the frontier.\n findFittable() {\n let startDepth = this.unplaced.openStart;\n for (let cur = this.unplaced.content, d = 0, openEnd = this.unplaced.openEnd; d < startDepth; d++) {\n let node = cur.firstChild;\n if (cur.childCount > 1)\n openEnd = 0;\n if (node.type.spec.isolating && openEnd <= d) {\n startDepth = d;\n break;\n }\n cur = node.content;\n }\n // Only try wrapping nodes (pass 2) after finding a place without\n // wrapping failed.\n for (let pass = 1; pass <= 2; pass++) {\n for (let sliceDepth = pass == 1 ? startDepth : this.unplaced.openStart; sliceDepth >= 0; sliceDepth--) {\n let fragment, parent = null;\n if (sliceDepth) {\n parent = contentAt(this.unplaced.content, sliceDepth - 1).firstChild;\n fragment = parent.content;\n }\n else {\n fragment = this.unplaced.content;\n }\n let first = fragment.firstChild;\n for (let frontierDepth = this.depth; frontierDepth >= 0; frontierDepth--) {\n let { type, match } = this.frontier[frontierDepth], wrap, inject = null;\n // In pass 1, if the next node matches, or there is no next\n // node but the parents look compatible, we've found a\n // place.\n if (pass == 1 && (first ? match.matchType(first.type) || (inject = match.fillBefore(Fragment.from(first), false))\n : parent && type.compatibleContent(parent.type)))\n return { sliceDepth, frontierDepth, parent, inject };\n // In pass 2, look for a set of wrapping nodes that make\n // `first` fit here.\n else if (pass == 2 && first && (wrap = match.findWrapping(first.type)))\n return { sliceDepth, frontierDepth, parent, wrap };\n // Don't continue looking further up if the parent node\n // would fit here.\n if (parent && match.matchType(parent.type))\n break;\n }\n }\n }\n }\n openMore() {\n let { content, openStart, openEnd } = this.unplaced;\n let inner = contentAt(content, openStart);\n if (!inner.childCount || inner.firstChild.isLeaf)\n return false;\n this.unplaced = new Slice(content, openStart + 1, Math.max(openEnd, inner.size + openStart >= content.size - openEnd ? openStart + 1 : 0));\n return true;\n }\n dropNode() {\n let { content, openStart, openEnd } = this.unplaced;\n let inner = contentAt(content, openStart);\n if (inner.childCount <= 1 && openStart > 0) {\n let openAtEnd = content.size - openStart <= openStart + inner.size;\n this.unplaced = new Slice(dropFromFragment(content, openStart - 1, 1), openStart - 1, openAtEnd ? openStart - 1 : openEnd);\n }\n else {\n this.unplaced = new Slice(dropFromFragment(content, openStart, 1), openStart, openEnd);\n }\n }\n // Move content from the unplaced slice at `sliceDepth` to the\n // frontier node at `frontierDepth`. Close that frontier node when\n // applicable.\n placeNodes({ sliceDepth, frontierDepth, parent, inject, wrap }) {\n while (this.depth > frontierDepth)\n this.closeFrontierNode();\n if (wrap)\n for (let i = 0; i < wrap.length; i++)\n this.openFrontierNode(wrap[i]);\n let slice = this.unplaced, fragment = parent ? parent.content : slice.content;\n let openStart = slice.openStart - sliceDepth;\n let taken = 0, add = [];\n let { match, type } = this.frontier[frontierDepth];\n if (inject) {\n for (let i = 0; i < inject.childCount; i++)\n add.push(inject.child(i));\n match = match.matchFragment(inject);\n }\n // Computes the amount of (end) open nodes at the end of the\n // fragment. When 0, the parent is open, but no more. When\n // negative, nothing is open.\n let openEndCount = (fragment.size + sliceDepth) - (slice.content.size - slice.openEnd);\n // Scan over the fragment, fitting as many child nodes as\n // possible.\n while (taken < fragment.childCount) {\n let next = fragment.child(taken), matches = match.matchType(next.type);\n if (!matches)\n break;\n taken++;\n if (taken > 1 || openStart == 0 || next.content.size) { // Drop empty open nodes\n match = matches;\n add.push(closeNodeStart(next.mark(type.allowedMarks(next.marks)), taken == 1 ? openStart : 0, taken == fragment.childCount ? openEndCount : -1));\n }\n }\n let toEnd = taken == fragment.childCount;\n if (!toEnd)\n openEndCount = -1;\n this.placed = addToFragment(this.placed, frontierDepth, Fragment.from(add));\n this.frontier[frontierDepth].match = match;\n // If the parent types match, and the entire node was moved, and\n // it's not open, close this frontier node right away.\n if (toEnd && openEndCount < 0 && parent && parent.type == this.frontier[this.depth].type && this.frontier.length > 1)\n this.closeFrontierNode();\n // Add new frontier nodes for any open nodes at the end.\n for (let i = 0, cur = fragment; i < openEndCount; i++) {\n let node = cur.lastChild;\n this.frontier.push({ type: node.type, match: node.contentMatchAt(node.childCount) });\n cur = node.content;\n }\n // Update `this.unplaced`. Drop the entire node from which we\n // placed it we got to its end, otherwise just drop the placed\n // nodes.\n this.unplaced = !toEnd ? new Slice(dropFromFragment(slice.content, sliceDepth, taken), slice.openStart, slice.openEnd)\n : sliceDepth == 0 ? Slice.empty\n : new Slice(dropFromFragment(slice.content, sliceDepth - 1, 1), sliceDepth - 1, openEndCount < 0 ? slice.openEnd : sliceDepth - 1);\n }\n mustMoveInline() {\n if (!this.$to.parent.isTextblock)\n return -1;\n let top = this.frontier[this.depth], level;\n if (!top.type.isTextblock || !contentAfterFits(this.$to, this.$to.depth, top.type, top.match, false) ||\n (this.$to.depth == this.depth && (level = this.findCloseLevel(this.$to)) && level.depth == this.depth))\n return -1;\n let { depth } = this.$to, after = this.$to.after(depth);\n while (depth > 1 && after == this.$to.end(--depth))\n ++after;\n return after;\n }\n findCloseLevel($to) {\n scan: for (let i = Math.min(this.depth, $to.depth); i >= 0; i--) {\n let { match, type } = this.frontier[i];\n let dropInner = i < $to.depth && $to.end(i + 1) == $to.pos + ($to.depth - (i + 1));\n let fit = contentAfterFits($to, i, type, match, dropInner);\n if (!fit)\n continue;\n for (let d = i - 1; d >= 0; d--) {\n let { match, type } = this.frontier[d];\n let matches = contentAfterFits($to, d, type, match, true);\n if (!matches || matches.childCount)\n continue scan;\n }\n return { depth: i, fit, move: dropInner ? $to.doc.resolve($to.after(i + 1)) : $to };\n }\n }\n close($to) {\n let close = this.findCloseLevel($to);\n if (!close)\n return null;\n while (this.depth > close.depth)\n this.closeFrontierNode();\n if (close.fit.childCount)\n this.placed = addToFragment(this.placed, close.depth, close.fit);\n $to = close.move;\n for (let d = close.depth + 1; d <= $to.depth; d++) {\n let node = $to.node(d), add = node.type.contentMatch.fillBefore(node.content, true, $to.index(d));\n this.openFrontierNode(node.type, node.attrs, add);\n }\n return $to;\n }\n openFrontierNode(type, attrs = null, content) {\n let top = this.frontier[this.depth];\n top.match = top.match.matchType(type);\n this.placed = addToFragment(this.placed, this.depth, Fragment.from(type.create(attrs, content)));\n this.frontier.push({ type, match: type.contentMatch });\n }\n closeFrontierNode() {\n let open = this.frontier.pop();\n let add = open.match.fillBefore(Fragment.empty, true);\n if (add.childCount)\n this.placed = addToFragment(this.placed, this.frontier.length, add);\n }\n}\nfunction dropFromFragment(fragment, depth, count) {\n if (depth == 0)\n return fragment.cutByIndex(count, fragment.childCount);\n return fragment.replaceChild(0, fragment.firstChild.copy(dropFromFragment(fragment.firstChild.content, depth - 1, count)));\n}\nfunction addToFragment(fragment, depth, content) {\n if (depth == 0)\n return fragment.append(content);\n return fragment.replaceChild(fragment.childCount - 1, fragment.lastChild.copy(addToFragment(fragment.lastChild.content, depth - 1, content)));\n}\nfunction contentAt(fragment, depth) {\n for (let i = 0; i < depth; i++)\n fragment = fragment.firstChild.content;\n return fragment;\n}\nfunction closeNodeStart(node, openStart, openEnd) {\n if (openStart <= 0)\n return node;\n let frag = node.content;\n if (openStart > 1)\n frag = frag.replaceChild(0, closeNodeStart(frag.firstChild, openStart - 1, frag.childCount == 1 ? openEnd - 1 : 0));\n if (openStart > 0) {\n frag = node.type.contentMatch.fillBefore(frag).append(frag);\n if (openEnd <= 0)\n frag = frag.append(node.type.contentMatch.matchFragment(frag).fillBefore(Fragment.empty, true));\n }\n return node.copy(frag);\n}\nfunction contentAfterFits($to, depth, type, match, open) {\n let node = $to.node(depth), index = open ? $to.indexAfter(depth) : $to.index(depth);\n if (index == node.childCount && !type.compatibleContent(node.type))\n return null;\n let fit = match.fillBefore(node.content, true, index);\n return fit && !invalidMarks(type, node.content, index) ? fit : null;\n}\nfunction invalidMarks(type, fragment, start) {\n for (let i = start; i < fragment.childCount; i++)\n if (!type.allowsMarks(fragment.child(i).marks))\n return true;\n return false;\n}\nfunction definesContent(type) {\n return type.spec.defining || type.spec.definingForContent;\n}\nfunction replaceRange(tr, from, to, slice) {\n if (!slice.size)\n return tr.deleteRange(from, to);\n let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);\n if (fitsTrivially($from, $to, slice))\n return tr.step(new ReplaceStep(from, to, slice));\n let targetDepths = coveredDepths($from, tr.doc.resolve(to));\n // Can't replace the whole document, so remove 0 if it's present\n if (targetDepths[targetDepths.length - 1] == 0)\n targetDepths.pop();\n // Negative numbers represent not expansion over the whole node at\n // that depth, but replacing from $from.before(-D) to $to.pos.\n let preferredTarget = -($from.depth + 1);\n targetDepths.unshift(preferredTarget);\n // This loop picks a preferred target depth, if one of the covering\n // depths is not outside of a defining node, and adds negative\n // depths for any depth that has $from at its start and does not\n // cross a defining node.\n for (let d = $from.depth, pos = $from.pos - 1; d > 0; d--, pos--) {\n let spec = $from.node(d).type.spec;\n if (spec.defining || spec.definingAsContext || spec.isolating)\n break;\n if (targetDepths.indexOf(d) > -1)\n preferredTarget = d;\n else if ($from.before(d) == pos)\n targetDepths.splice(1, 0, -d);\n }\n // Try to fit each possible depth of the slice into each possible\n // target depth, starting with the preferred depths.\n let preferredTargetIndex = targetDepths.indexOf(preferredTarget);\n let leftNodes = [], preferredDepth = slice.openStart;\n for (let content = slice.content, i = 0;; i++) {\n let node = content.firstChild;\n leftNodes.push(node);\n if (i == slice.openStart)\n break;\n content = node.content;\n }\n // Back up preferredDepth to cover defining textblocks directly\n // above it, possibly skipping a non-defining textblock.\n for (let d = preferredDepth - 1; d >= 0; d--) {\n let leftNode = leftNodes[d], def = definesContent(leftNode.type);\n if (def && !leftNode.sameMarkup($from.node(Math.abs(preferredTarget) - 1)))\n preferredDepth = d;\n else if (def || !leftNode.type.isTextblock)\n break;\n }\n for (let j = slice.openStart; j >= 0; j--) {\n let openDepth = (j + preferredDepth + 1) % (slice.openStart + 1);\n let insert = leftNodes[openDepth];\n if (!insert)\n continue;\n for (let i = 0; i < targetDepths.length; i++) {\n // Loop over possible expansion levels, starting with the\n // preferred one\n let targetDepth = targetDepths[(i + preferredTargetIndex) % targetDepths.length], expand = true;\n if (targetDepth < 0) {\n expand = false;\n targetDepth = -targetDepth;\n }\n let parent = $from.node(targetDepth - 1), index = $from.index(targetDepth - 1);\n if (parent.canReplaceWith(index, index, insert.type, insert.marks))\n return tr.replace($from.before(targetDepth), expand ? $to.after(targetDepth) : to, new Slice(closeFragment(slice.content, 0, slice.openStart, openDepth), openDepth, slice.openEnd));\n }\n }\n let startSteps = tr.steps.length;\n for (let i = targetDepths.length - 1; i >= 0; i--) {\n tr.replace(from, to, slice);\n if (tr.steps.length > startSteps)\n break;\n let depth = targetDepths[i];\n if (depth < 0)\n continue;\n from = $from.before(depth);\n to = $to.after(depth);\n }\n}\nfunction closeFragment(fragment, depth, oldOpen, newOpen, parent) {\n if (depth < oldOpen) {\n let first = fragment.firstChild;\n fragment = fragment.replaceChild(0, first.copy(closeFragment(first.content, depth + 1, oldOpen, newOpen, first)));\n }\n if (depth > newOpen) {\n let match = parent.contentMatchAt(0);\n let start = match.fillBefore(fragment).append(fragment);\n fragment = start.append(match.matchFragment(start).fillBefore(Fragment.empty, true));\n }\n return fragment;\n}\nfunction replaceRangeWith(tr, from, to, node) {\n if (!node.isInline && from == to && tr.doc.resolve(from).parent.content.size) {\n let point = insertPoint(tr.doc, from, node.type);\n if (point != null)\n from = to = point;\n }\n tr.replaceRange(from, to, new Slice(Fragment.from(node), 0, 0));\n}\nfunction deleteRange(tr, from, to) {\n let $from = tr.doc.resolve(from), $to = tr.doc.resolve(to);\n let covered = coveredDepths($from, $to);\n for (let i = 0; i < covered.length; i++) {\n let depth = covered[i], last = i == covered.length - 1;\n if ((last && depth == 0) || $from.node(depth).type.contentMatch.validEnd)\n return tr.delete($from.start(depth), $to.end(depth));\n if (depth > 0 && (last || $from.node(depth - 1).canReplace($from.index(depth - 1), $to.indexAfter(depth - 1))))\n return tr.delete($from.before(depth), $to.after(depth));\n }\n for (let d = 1; d <= $from.depth && d <= $to.depth; d++) {\n if (from - $from.start(d) == $from.depth - d && to > $from.end(d) && $to.end(d) - to != $to.depth - d &&\n $from.start(d - 1) == $to.start(d - 1) && $from.node(d - 1).canReplace($from.index(d - 1), $to.index(d - 1)))\n return tr.delete($from.before(d), to);\n }\n tr.delete(from, to);\n}\n// Returns an array of all depths for which $from - $to spans the\n// whole content of the nodes at that depth.\nfunction coveredDepths($from, $to) {\n let result = [], minDepth = Math.min($from.depth, $to.depth);\n for (let d = minDepth; d >= 0; d--) {\n let start = $from.start(d);\n if (start < $from.pos - ($from.depth - d) ||\n $to.end(d) > $to.pos + ($to.depth - d) ||\n $from.node(d).type.spec.isolating ||\n $to.node(d).type.spec.isolating)\n break;\n if (start == $to.start(d) ||\n (d == $from.depth && d == $to.depth && $from.parent.inlineContent && $to.parent.inlineContent &&\n d && $to.start(d - 1) == start - 1))\n result.push(d);\n }\n return result;\n}\n\n/**\nUpdate an attribute in a specific node.\n*/\nclass AttrStep extends Step {\n /**\n Construct an attribute step.\n */\n constructor(\n /**\n The position of the target node.\n */\n pos, \n /**\n The attribute to set.\n */\n attr, \n // The attribute's new value.\n value) {\n super();\n this.pos = pos;\n this.attr = attr;\n this.value = value;\n }\n apply(doc) {\n let node = doc.nodeAt(this.pos);\n if (!node)\n return StepResult.fail(\"No node at attribute step's position\");\n let attrs = Object.create(null);\n for (let name in node.attrs)\n attrs[name] = node.attrs[name];\n attrs[this.attr] = this.value;\n let updated = node.type.create(attrs, null, node.marks);\n return StepResult.fromReplace(doc, this.pos, this.pos + 1, new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1));\n }\n getMap() {\n return StepMap.empty;\n }\n invert(doc) {\n return new AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);\n }\n map(mapping) {\n let pos = mapping.mapResult(this.pos, 1);\n return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value);\n }\n toJSON() {\n return { stepType: \"attr\", pos: this.pos, attr: this.attr, value: this.value };\n }\n static fromJSON(schema, json) {\n if (typeof json.pos != \"number\" || typeof json.attr != \"string\")\n throw new RangeError(\"Invalid input for AttrStep.fromJSON\");\n return new AttrStep(json.pos, json.attr, json.value);\n }\n}\nStep.jsonID(\"attr\", AttrStep);\n/**\nUpdate an attribute in the doc node.\n*/\nclass DocAttrStep extends Step {\n /**\n Construct an attribute step.\n */\n constructor(\n /**\n The attribute to set.\n */\n attr, \n // The attribute's new value.\n value) {\n super();\n this.attr = attr;\n this.value = value;\n }\n apply(doc) {\n let attrs = Object.create(null);\n for (let name in doc.attrs)\n attrs[name] = doc.attrs[name];\n attrs[this.attr] = this.value;\n let updated = doc.type.create(attrs, doc.content, doc.marks);\n return StepResult.ok(updated);\n }\n getMap() {\n return StepMap.empty;\n }\n invert(doc) {\n return new DocAttrStep(this.attr, doc.attrs[this.attr]);\n }\n map(mapping) {\n return this;\n }\n toJSON() {\n return { stepType: \"docAttr\", attr: this.attr, value: this.value };\n }\n static fromJSON(schema, json) {\n if (typeof json.attr != \"string\")\n throw new RangeError(\"Invalid input for DocAttrStep.fromJSON\");\n return new DocAttrStep(json.attr, json.value);\n }\n}\nStep.jsonID(\"docAttr\", DocAttrStep);\n\n/**\n@internal\n*/\nlet TransformError = class extends Error {\n};\nTransformError = function TransformError(message) {\n let err = Error.call(this, message);\n err.__proto__ = TransformError.prototype;\n return err;\n};\nTransformError.prototype = Object.create(Error.prototype);\nTransformError.prototype.constructor = TransformError;\nTransformError.prototype.name = \"TransformError\";\n/**\nAbstraction to build up and track an array of\n[steps](https://prosemirror.net/docs/ref/#transform.Step) representing a document transformation.\n\nMost transforming methods return the `Transform` object itself, so\nthat they can be chained.\n*/\nclass Transform {\n /**\n Create a transform that starts with the given document.\n */\n constructor(\n /**\n The current document (the result of applying the steps in the\n transform).\n */\n doc) {\n this.doc = doc;\n /**\n The steps in this transform.\n */\n this.steps = [];\n /**\n The documents before each of the steps.\n */\n this.docs = [];\n /**\n A mapping with the maps for each of the steps in this transform.\n */\n this.mapping = new Mapping;\n }\n /**\n The starting document.\n */\n get before() { return this.docs.length ? this.docs[0] : this.doc; }\n /**\n Apply a new step in this transform, saving the result. Throws an\n error when the step fails.\n */\n step(step) {\n let result = this.maybeStep(step);\n if (result.failed)\n throw new TransformError(result.failed);\n return this;\n }\n /**\n Try to apply a step in this transformation, ignoring it if it\n fails. Returns the step result.\n */\n maybeStep(step) {\n let result = step.apply(this.doc);\n if (!result.failed)\n this.addStep(step, result.doc);\n return result;\n }\n /**\n True when the document has been changed (when there are any\n steps).\n */\n get docChanged() {\n return this.steps.length > 0;\n }\n /**\n @internal\n */\n addStep(step, doc) {\n this.docs.push(this.doc);\n this.steps.push(step);\n this.mapping.appendMap(step.getMap());\n this.doc = doc;\n }\n /**\n Replace the part of the document between `from` and `to` with the\n given `slice`.\n */\n replace(from, to = from, slice = Slice.empty) {\n let step = replaceStep(this.doc, from, to, slice);\n if (step)\n this.step(step);\n return this;\n }\n /**\n Replace the given range with the given content, which may be a\n fragment, node, or array of nodes.\n */\n replaceWith(from, to, content) {\n return this.replace(from, to, new Slice(Fragment.from(content), 0, 0));\n }\n /**\n Delete the content between the given positions.\n */\n delete(from, to) {\n return this.replace(from, to, Slice.empty);\n }\n /**\n Insert the given content at the given position.\n */\n insert(pos, content) {\n return this.replaceWith(pos, pos, content);\n }\n /**\n Replace a range of the document with a given slice, using\n `from`, `to`, and the slice's\n [`openStart`](https://prosemirror.net/docs/ref/#model.Slice.openStart) property as hints, rather\n than fixed start and end points. This method may grow the\n replaced area or close open nodes in the slice in order to get a\n fit that is more in line with WYSIWYG expectations, by dropping\n fully covered parent nodes of the replaced region when they are\n marked [non-defining as\n context](https://prosemirror.net/docs/ref/#model.NodeSpec.definingAsContext), or including an\n open parent node from the slice that _is_ marked as [defining\n its content](https://prosemirror.net/docs/ref/#model.NodeSpec.definingForContent).\n \n This is the method, for example, to handle paste. The similar\n [`replace`](https://prosemirror.net/docs/ref/#transform.Transform.replace) method is a more\n primitive tool which will _not_ move the start and end of its given\n range, and is useful in situations where you need more precise\n control over what happens.\n */\n replaceRange(from, to, slice) {\n replaceRange(this, from, to, slice);\n return this;\n }\n /**\n Replace the given range with a node, but use `from` and `to` as\n hints, rather than precise positions. When from and to are the same\n and are at the start or end of a parent node in which the given\n node doesn't fit, this method may _move_ them out towards a parent\n that does allow the given node to be placed. When the given range\n completely covers a parent node, this method may completely replace\n that parent node.\n */\n replaceRangeWith(from, to, node) {\n replaceRangeWith(this, from, to, node);\n return this;\n }\n /**\n Delete the given range, expanding it to cover fully covered\n parent nodes until a valid replace is found.\n */\n deleteRange(from, to) {\n deleteRange(this, from, to);\n return this;\n }\n /**\n Split the content in the given range off from its parent, if there\n is sibling content before or after it, and move it up the tree to\n the depth specified by `target`. You'll probably want to use\n [`liftTarget`](https://prosemirror.net/docs/ref/#transform.liftTarget) to compute `target`, to make\n sure the lift is valid.\n */\n lift(range, target) {\n lift(this, range, target);\n return this;\n }\n /**\n Join the blocks around the given position. If depth is 2, their\n last and first siblings are also joined, and so on.\n */\n join(pos, depth = 1) {\n join(this, pos, depth);\n return this;\n }\n /**\n Wrap the given [range](https://prosemirror.net/docs/ref/#model.NodeRange) in the given set of wrappers.\n The wrappers are assumed to be valid in this position, and should\n probably be computed with [`findWrapping`](https://prosemirror.net/docs/ref/#transform.findWrapping).\n */\n wrap(range, wrappers) {\n wrap(this, range, wrappers);\n return this;\n }\n /**\n Set the type of all textblocks (partly) between `from` and `to` to\n the given node type with the given attributes.\n */\n setBlockType(from, to = from, type, attrs = null) {\n setBlockType(this, from, to, type, attrs);\n return this;\n }\n /**\n Change the type, attributes, and/or marks of the node at `pos`.\n When `type` isn't given, the existing node type is preserved,\n */\n setNodeMarkup(pos, type, attrs = null, marks) {\n setNodeMarkup(this, pos, type, attrs, marks);\n return this;\n }\n /**\n Set a single attribute on a given node to a new value.\n The `pos` addresses the document content. Use `setDocAttribute`\n to set attributes on the document itself.\n */\n setNodeAttribute(pos, attr, value) {\n this.step(new AttrStep(pos, attr, value));\n return this;\n }\n /**\n Set a single attribute on the document to a new value.\n */\n setDocAttribute(attr, value) {\n this.step(new DocAttrStep(attr, value));\n return this;\n }\n /**\n Add a mark to the node at position `pos`.\n */\n addNodeMark(pos, mark) {\n this.step(new AddNodeMarkStep(pos, mark));\n return this;\n }\n /**\n Remove a mark (or all marks of the given type) from the node at\n position `pos`.\n */\n removeNodeMark(pos, mark) {\n let node = this.doc.nodeAt(pos);\n if (!node)\n throw new RangeError(\"No node at position \" + pos);\n if (mark instanceof Mark) {\n if (mark.isInSet(node.marks))\n this.step(new RemoveNodeMarkStep(pos, mark));\n }\n else {\n let set = node.marks, found, steps = [];\n while (found = mark.isInSet(set)) {\n steps.push(new RemoveNodeMarkStep(pos, found));\n set = found.removeFromSet(set);\n }\n for (let i = steps.length - 1; i >= 0; i--)\n this.step(steps[i]);\n }\n return this;\n }\n /**\n Split the node at the given position, and optionally, if `depth` is\n greater than one, any number of nodes above that. By default, the\n parts split off will inherit the node type of the original node.\n This can be changed by passing an array of types and attributes to\n use after the split (with the outermost nodes coming first).\n */\n split(pos, depth = 1, typesAfter) {\n split(this, pos, depth, typesAfter);\n return this;\n }\n /**\n Add the given mark to the inline content between `from` and `to`.\n */\n addMark(from, to, mark) {\n addMark(this, from, to, mark);\n return this;\n }\n /**\n Remove marks from inline nodes between `from` and `to`. When\n `mark` is a single mark, remove precisely that mark. When it is\n a mark type, remove all marks of that type. When it is null,\n remove all marks of any type.\n */\n removeMark(from, to, mark) {\n removeMark(this, from, to, mark);\n return this;\n }\n /**\n Removes all marks and nodes from the content of the node at\n `pos` that don't match the given new parent node type. Accepts\n an optional starting [content match](https://prosemirror.net/docs/ref/#model.ContentMatch) as\n third argument.\n */\n clearIncompatible(pos, parentType, match) {\n clearIncompatible(this, pos, parentType, match);\n return this;\n }\n}\n\nexport { AddMarkStep, AddNodeMarkStep, AttrStep, DocAttrStep, MapResult, Mapping, RemoveMarkStep, RemoveNodeMarkStep, ReplaceAroundStep, ReplaceStep, Step, StepMap, StepResult, Transform, TransformError, canJoin, canSplit, dropPoint, findWrapping, insertPoint, joinPoint, liftTarget, replaceStep };\n","import { Slice, Fragment, Mark, Node } from 'prosemirror-model';\nimport { ReplaceStep, ReplaceAroundStep, Transform } from 'prosemirror-transform';\n\nconst classesById = Object.create(null);\n/**\nSuperclass for editor selections. Every selection type should\nextend this. Should not be instantiated directly.\n*/\nclass Selection {\n /**\n Initialize a selection with the head and anchor and ranges. If no\n ranges are given, constructs a single range across `$anchor` and\n `$head`.\n */\n constructor(\n /**\n The resolved anchor of the selection (the side that stays in\n place when the selection is modified).\n */\n $anchor, \n /**\n The resolved head of the selection (the side that moves when\n the selection is modified).\n */\n $head, ranges) {\n this.$anchor = $anchor;\n this.$head = $head;\n this.ranges = ranges || [new SelectionRange($anchor.min($head), $anchor.max($head))];\n }\n /**\n The selection's anchor, as an unresolved position.\n */\n get anchor() { return this.$anchor.pos; }\n /**\n The selection's head.\n */\n get head() { return this.$head.pos; }\n /**\n The lower bound of the selection's main range.\n */\n get from() { return this.$from.pos; }\n /**\n The upper bound of the selection's main range.\n */\n get to() { return this.$to.pos; }\n /**\n The resolved lower bound of the selection's main range.\n */\n get $from() {\n return this.ranges[0].$from;\n }\n /**\n The resolved upper bound of the selection's main range.\n */\n get $to() {\n return this.ranges[0].$to;\n }\n /**\n Indicates whether the selection contains any content.\n */\n get empty() {\n let ranges = this.ranges;\n for (let i = 0; i < ranges.length; i++)\n if (ranges[i].$from.pos != ranges[i].$to.pos)\n return false;\n return true;\n }\n /**\n Get the content of this selection as a slice.\n */\n content() {\n return this.$from.doc.slice(this.from, this.to, true);\n }\n /**\n Replace the selection with a slice or, if no slice is given,\n delete the selection. Will append to the given transaction.\n */\n replace(tr, content = Slice.empty) {\n // Put the new selection at the position after the inserted\n // content. When that ended in an inline node, search backwards,\n // to get the position after that node. If not, search forward.\n let lastNode = content.content.lastChild, lastParent = null;\n for (let i = 0; i < content.openEnd; i++) {\n lastParent = lastNode;\n lastNode = lastNode.lastChild;\n }\n let mapFrom = tr.steps.length, ranges = this.ranges;\n for (let i = 0; i < ranges.length; i++) {\n let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);\n tr.replaceRange(mapping.map($from.pos), mapping.map($to.pos), i ? Slice.empty : content);\n if (i == 0)\n selectionToInsertionEnd(tr, mapFrom, (lastNode ? lastNode.isInline : lastParent && lastParent.isTextblock) ? -1 : 1);\n }\n }\n /**\n Replace the selection with the given node, appending the changes\n to the given transaction.\n */\n replaceWith(tr, node) {\n let mapFrom = tr.steps.length, ranges = this.ranges;\n for (let i = 0; i < ranges.length; i++) {\n let { $from, $to } = ranges[i], mapping = tr.mapping.slice(mapFrom);\n let from = mapping.map($from.pos), to = mapping.map($to.pos);\n if (i) {\n tr.deleteRange(from, to);\n }\n else {\n tr.replaceRangeWith(from, to, node);\n selectionToInsertionEnd(tr, mapFrom, node.isInline ? -1 : 1);\n }\n }\n }\n /**\n Find a valid cursor or leaf node selection starting at the given\n position and searching back if `dir` is negative, and forward if\n positive. When `textOnly` is true, only consider cursor\n selections. Will return null when no valid selection position is\n found.\n */\n static findFrom($pos, dir, textOnly = false) {\n let inner = $pos.parent.inlineContent ? new TextSelection($pos)\n : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly);\n if (inner)\n return inner;\n for (let depth = $pos.depth - 1; depth >= 0; depth--) {\n let found = dir < 0\n ? findSelectionIn($pos.node(0), $pos.node(depth), $pos.before(depth + 1), $pos.index(depth), dir, textOnly)\n : findSelectionIn($pos.node(0), $pos.node(depth), $pos.after(depth + 1), $pos.index(depth) + 1, dir, textOnly);\n if (found)\n return found;\n }\n return null;\n }\n /**\n Find a valid cursor or leaf node selection near the given\n position. Searches forward first by default, but if `bias` is\n negative, it will search backwards first.\n */\n static near($pos, bias = 1) {\n return this.findFrom($pos, bias) || this.findFrom($pos, -bias) || new AllSelection($pos.node(0));\n }\n /**\n Find the cursor or leaf node selection closest to the start of\n the given document. Will return an\n [`AllSelection`](https://prosemirror.net/docs/ref/#state.AllSelection) if no valid position\n exists.\n */\n static atStart(doc) {\n return findSelectionIn(doc, doc, 0, 0, 1) || new AllSelection(doc);\n }\n /**\n Find the cursor or leaf node selection closest to the end of the\n given document.\n */\n static atEnd(doc) {\n return findSelectionIn(doc, doc, doc.content.size, doc.childCount, -1) || new AllSelection(doc);\n }\n /**\n Deserialize the JSON representation of a selection. Must be\n implemented for custom classes (as a static class method).\n */\n static fromJSON(doc, json) {\n if (!json || !json.type)\n throw new RangeError(\"Invalid input for Selection.fromJSON\");\n let cls = classesById[json.type];\n if (!cls)\n throw new RangeError(`No selection type ${json.type} defined`);\n return cls.fromJSON(doc, json);\n }\n /**\n To be able to deserialize selections from JSON, custom selection\n classes must register themselves with an ID string, so that they\n can be disambiguated. Try to pick something that's unlikely to\n clash with classes from other modules.\n */\n static jsonID(id, selectionClass) {\n if (id in classesById)\n throw new RangeError(\"Duplicate use of selection JSON ID \" + id);\n classesById[id] = selectionClass;\n selectionClass.prototype.jsonID = id;\n return selectionClass;\n }\n /**\n Get a [bookmark](https://prosemirror.net/docs/ref/#state.SelectionBookmark) for this selection,\n which is a value that can be mapped without having access to a\n current document, and later resolved to a real selection for a\n given document again. (This is used mostly by the history to\n track and restore old selections.) The default implementation of\n this method just converts the selection to a text selection and\n returns the bookmark for that.\n */\n getBookmark() {\n return TextSelection.between(this.$anchor, this.$head).getBookmark();\n }\n}\nSelection.prototype.visible = true;\n/**\nRepresents a selected range in a document.\n*/\nclass SelectionRange {\n /**\n Create a range.\n */\n constructor(\n /**\n The lower bound of the range.\n */\n $from, \n /**\n The upper bound of the range.\n */\n $to) {\n this.$from = $from;\n this.$to = $to;\n }\n}\nlet warnedAboutTextSelection = false;\nfunction checkTextSelection($pos) {\n if (!warnedAboutTextSelection && !$pos.parent.inlineContent) {\n warnedAboutTextSelection = true;\n console[\"warn\"](\"TextSelection endpoint not pointing into a node with inline content (\" + $pos.parent.type.name + \")\");\n }\n}\n/**\nA text selection represents a classical editor selection, with a\nhead (the moving side) and anchor (immobile side), both of which\npoint into textblock nodes. It can be empty (a regular cursor\nposition).\n*/\nclass TextSelection extends Selection {\n /**\n Construct a text selection between the given points.\n */\n constructor($anchor, $head = $anchor) {\n checkTextSelection($anchor);\n checkTextSelection($head);\n super($anchor, $head);\n }\n /**\n Returns a resolved position if this is a cursor selection (an\n empty text selection), and null otherwise.\n */\n get $cursor() { return this.$anchor.pos == this.$head.pos ? this.$head : null; }\n map(doc, mapping) {\n let $head = doc.resolve(mapping.map(this.head));\n if (!$head.parent.inlineContent)\n return Selection.near($head);\n let $anchor = doc.resolve(mapping.map(this.anchor));\n return new TextSelection($anchor.parent.inlineContent ? $anchor : $head, $head);\n }\n replace(tr, content = Slice.empty) {\n super.replace(tr, content);\n if (content == Slice.empty) {\n let marks = this.$from.marksAcross(this.$to);\n if (marks)\n tr.ensureMarks(marks);\n }\n }\n eq(other) {\n return other instanceof TextSelection && other.anchor == this.anchor && other.head == this.head;\n }\n getBookmark() {\n return new TextBookmark(this.anchor, this.head);\n }\n toJSON() {\n return { type: \"text\", anchor: this.anchor, head: this.head };\n }\n /**\n @internal\n */\n static fromJSON(doc, json) {\n if (typeof json.anchor != \"number\" || typeof json.head != \"number\")\n throw new RangeError(\"Invalid input for TextSelection.fromJSON\");\n return new TextSelection(doc.resolve(json.anchor), doc.resolve(json.head));\n }\n /**\n Create a text selection from non-resolved positions.\n */\n static create(doc, anchor, head = anchor) {\n let $anchor = doc.resolve(anchor);\n return new this($anchor, head == anchor ? $anchor : doc.resolve(head));\n }\n /**\n Return a text selection that spans the given positions or, if\n they aren't text positions, find a text selection near them.\n `bias` determines whether the method searches forward (default)\n or backwards (negative number) first. Will fall back to calling\n [`Selection.near`](https://prosemirror.net/docs/ref/#state.Selection^near) when the document\n doesn't contain a valid text position.\n */\n static between($anchor, $head, bias) {\n let dPos = $anchor.pos - $head.pos;\n if (!bias || dPos)\n bias = dPos >= 0 ? 1 : -1;\n if (!$head.parent.inlineContent) {\n let found = Selection.findFrom($head, bias, true) || Selection.findFrom($head, -bias, true);\n if (found)\n $head = found.$head;\n else\n return Selection.near($head, bias);\n }\n if (!$anchor.parent.inlineContent) {\n if (dPos == 0) {\n $anchor = $head;\n }\n else {\n $anchor = (Selection.findFrom($anchor, -bias, true) || Selection.findFrom($anchor, bias, true)).$anchor;\n if (($anchor.pos < $head.pos) != (dPos < 0))\n $anchor = $head;\n }\n }\n return new TextSelection($anchor, $head);\n }\n}\nSelection.jsonID(\"text\", TextSelection);\nclass TextBookmark {\n constructor(anchor, head) {\n this.anchor = anchor;\n this.head = head;\n }\n map(mapping) {\n return new TextBookmark(mapping.map(this.anchor), mapping.map(this.head));\n }\n resolve(doc) {\n return TextSelection.between(doc.resolve(this.anchor), doc.resolve(this.head));\n }\n}\n/**\nA node selection is a selection that points at a single node. All\nnodes marked [selectable](https://prosemirror.net/docs/ref/#model.NodeSpec.selectable) can be the\ntarget of a node selection. In such a selection, `from` and `to`\npoint directly before and after the selected node, `anchor` equals\n`from`, and `head` equals `to`..\n*/\nclass NodeSelection extends Selection {\n /**\n Create a node selection. Does not verify the validity of its\n argument.\n */\n constructor($pos) {\n let node = $pos.nodeAfter;\n let $end = $pos.node(0).resolve($pos.pos + node.nodeSize);\n super($pos, $end);\n this.node = node;\n }\n map(doc, mapping) {\n let { deleted, pos } = mapping.mapResult(this.anchor);\n let $pos = doc.resolve(pos);\n if (deleted)\n return Selection.near($pos);\n return new NodeSelection($pos);\n }\n content() {\n return new Slice(Fragment.from(this.node), 0, 0);\n }\n eq(other) {\n return other instanceof NodeSelection && other.anchor == this.anchor;\n }\n toJSON() {\n return { type: \"node\", anchor: this.anchor };\n }\n getBookmark() { return new NodeBookmark(this.anchor); }\n /**\n @internal\n */\n static fromJSON(doc, json) {\n if (typeof json.anchor != \"number\")\n throw new RangeError(\"Invalid input for NodeSelection.fromJSON\");\n return new NodeSelection(doc.resolve(json.anchor));\n }\n /**\n Create a node selection from non-resolved positions.\n */\n static create(doc, from) {\n return new NodeSelection(doc.resolve(from));\n }\n /**\n Determines whether the given node may be selected as a node\n selection.\n */\n static isSelectable(node) {\n return !node.isText && node.type.spec.selectable !== false;\n }\n}\nNodeSelection.prototype.visible = false;\nSelection.jsonID(\"node\", NodeSelection);\nclass NodeBookmark {\n constructor(anchor) {\n this.anchor = anchor;\n }\n map(mapping) {\n let { deleted, pos } = mapping.mapResult(this.anchor);\n return deleted ? new TextBookmark(pos, pos) : new NodeBookmark(pos);\n }\n resolve(doc) {\n let $pos = doc.resolve(this.anchor), node = $pos.nodeAfter;\n if (node && NodeSelection.isSelectable(node))\n return new NodeSelection($pos);\n return Selection.near($pos);\n }\n}\n/**\nA selection type that represents selecting the whole document\n(which can not necessarily be expressed with a text selection, when\nthere are for example leaf block nodes at the start or end of the\ndocument).\n*/\nclass AllSelection extends Selection {\n /**\n Create an all-selection over the given document.\n */\n constructor(doc) {\n super(doc.resolve(0), doc.resolve(doc.content.size));\n }\n replace(tr, content = Slice.empty) {\n if (content == Slice.empty) {\n tr.delete(0, tr.doc.content.size);\n let sel = Selection.atStart(tr.doc);\n if (!sel.eq(tr.selection))\n tr.setSelection(sel);\n }\n else {\n super.replace(tr, content);\n }\n }\n toJSON() { return { type: \"all\" }; }\n /**\n @internal\n */\n static fromJSON(doc) { return new AllSelection(doc); }\n map(doc) { return new AllSelection(doc); }\n eq(other) { return other instanceof AllSelection; }\n getBookmark() { return AllBookmark; }\n}\nSelection.jsonID(\"all\", AllSelection);\nconst AllBookmark = {\n map() { return this; },\n resolve(doc) { return new AllSelection(doc); }\n};\n// FIXME we'll need some awareness of text direction when scanning for selections\n// Try to find a selection inside the given node. `pos` points at the\n// position where the search starts. When `text` is true, only return\n// text selections.\nfunction findSelectionIn(doc, node, pos, index, dir, text = false) {\n if (node.inlineContent)\n return TextSelection.create(doc, pos);\n for (let i = index - (dir > 0 ? 0 : 1); dir > 0 ? i < node.childCount : i >= 0; i += dir) {\n let child = node.child(i);\n if (!child.isAtom) {\n let inner = findSelectionIn(doc, child, pos + dir, dir < 0 ? child.childCount : 0, dir, text);\n if (inner)\n return inner;\n }\n else if (!text && NodeSelection.isSelectable(child)) {\n return NodeSelection.create(doc, pos - (dir < 0 ? child.nodeSize : 0));\n }\n pos += child.nodeSize * dir;\n }\n return null;\n}\nfunction selectionToInsertionEnd(tr, startLen, bias) {\n let last = tr.steps.length - 1;\n if (last < startLen)\n return;\n let step = tr.steps[last];\n if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep))\n return;\n let map = tr.mapping.maps[last], end;\n map.forEach((_from, _to, _newFrom, newTo) => { if (end == null)\n end = newTo; });\n tr.setSelection(Selection.near(tr.doc.resolve(end), bias));\n}\n\nconst UPDATED_SEL = 1, UPDATED_MARKS = 2, UPDATED_SCROLL = 4;\n/**\nAn editor state transaction, which can be applied to a state to\ncreate an updated state. Use\n[`EditorState.tr`](https://prosemirror.net/docs/ref/#state.EditorState.tr) to create an instance.\n\nTransactions track changes to the document (they are a subclass of\n[`Transform`](https://prosemirror.net/docs/ref/#transform.Transform)), but also other state changes,\nlike selection updates and adjustments of the set of [stored\nmarks](https://prosemirror.net/docs/ref/#state.EditorState.storedMarks). In addition, you can store\nmetadata properties in a transaction, which are extra pieces of\ninformation that client code or plugins can use to describe what a\ntransaction represents, so that they can update their [own\nstate](https://prosemirror.net/docs/ref/#state.StateField) accordingly.\n\nThe [editor view](https://prosemirror.net/docs/ref/#view.EditorView) uses a few metadata\nproperties: it will attach a property `\"pointer\"` with the value\n`true` to selection transactions directly caused by mouse or touch\ninput, a `\"composition\"` property holding an ID identifying the\ncomposition that caused it to transactions caused by composed DOM\ninput, and a `\"uiEvent\"` property of that may be `\"paste\"`,\n`\"cut\"`, or `\"drop\"`.\n*/\nclass Transaction extends Transform {\n /**\n @internal\n */\n constructor(state) {\n super(state.doc);\n // The step count for which the current selection is valid.\n this.curSelectionFor = 0;\n // Bitfield to track which aspects of the state were updated by\n // this transaction.\n this.updated = 0;\n // Object used to store metadata properties for the transaction.\n this.meta = Object.create(null);\n this.time = Date.now();\n this.curSelection = state.selection;\n this.storedMarks = state.storedMarks;\n }\n /**\n The transaction's current selection. This defaults to the editor\n selection [mapped](https://prosemirror.net/docs/ref/#state.Selection.map) through the steps in the\n transaction, but can be overwritten with\n [`setSelection`](https://prosemirror.net/docs/ref/#state.Transaction.setSelection).\n */\n get selection() {\n if (this.curSelectionFor < this.steps.length) {\n this.curSelection = this.curSelection.map(this.doc, this.mapping.slice(this.curSelectionFor));\n this.curSelectionFor = this.steps.length;\n }\n return this.curSelection;\n }\n /**\n Update the transaction's current selection. Will determine the\n selection that the editor gets when the transaction is applied.\n */\n setSelection(selection) {\n if (selection.$from.doc != this.doc)\n throw new RangeError(\"Selection passed to setSelection must point at the current document\");\n this.curSelection = selection;\n this.curSelectionFor = this.steps.length;\n this.updated = (this.updated | UPDATED_SEL) & ~UPDATED_MARKS;\n this.storedMarks = null;\n return this;\n }\n /**\n Whether the selection was explicitly updated by this transaction.\n */\n get selectionSet() {\n return (this.updated & UPDATED_SEL) > 0;\n }\n /**\n Set the current stored marks.\n */\n setStoredMarks(marks) {\n this.storedMarks = marks;\n this.updated |= UPDATED_MARKS;\n return this;\n }\n /**\n Make sure the current stored marks or, if that is null, the marks\n at the selection, match the given set of marks. Does nothing if\n this is already the case.\n */\n ensureMarks(marks) {\n if (!Mark.sameSet(this.storedMarks || this.selection.$from.marks(), marks))\n this.setStoredMarks(marks);\n return this;\n }\n /**\n Add a mark to the set of stored marks.\n */\n addStoredMark(mark) {\n return this.ensureMarks(mark.addToSet(this.storedMarks || this.selection.$head.marks()));\n }\n /**\n Remove a mark or mark type from the set of stored marks.\n */\n removeStoredMark(mark) {\n return this.ensureMarks(mark.removeFromSet(this.storedMarks || this.selection.$head.marks()));\n }\n /**\n Whether the stored marks were explicitly set for this transaction.\n */\n get storedMarksSet() {\n return (this.updated & UPDATED_MARKS) > 0;\n }\n /**\n @internal\n */\n addStep(step, doc) {\n super.addStep(step, doc);\n this.updated = this.updated & ~UPDATED_MARKS;\n this.storedMarks = null;\n }\n /**\n Update the timestamp for the transaction.\n */\n setTime(time) {\n this.time = time;\n return this;\n }\n /**\n Replace the current selection with the given slice.\n */\n replaceSelection(slice) {\n this.selection.replace(this, slice);\n return this;\n }\n /**\n Replace the selection with the given node. When `inheritMarks` is\n true and the content is inline, it inherits the marks from the\n place where it is inserted.\n */\n replaceSelectionWith(node, inheritMarks = true) {\n let selection = this.selection;\n if (inheritMarks)\n node = node.mark(this.storedMarks || (selection.empty ? selection.$from.marks() : (selection.$from.marksAcross(selection.$to) || Mark.none)));\n selection.replaceWith(this, node);\n return this;\n }\n /**\n Delete the selection.\n */\n deleteSelection() {\n this.selection.replace(this);\n return this;\n }\n /**\n Replace the given range, or the selection if no range is given,\n with a text node containing the given string.\n */\n insertText(text, from, to) {\n let schema = this.doc.type.schema;\n if (from == null) {\n if (!text)\n return this.deleteSelection();\n return this.replaceSelectionWith(schema.text(text), true);\n }\n else {\n if (to == null)\n to = from;\n to = to == null ? from : to;\n if (!text)\n return this.deleteRange(from, to);\n let marks = this.storedMarks;\n if (!marks) {\n let $from = this.doc.resolve(from);\n marks = to == from ? $from.marks() : $from.marksAcross(this.doc.resolve(to));\n }\n this.replaceRangeWith(from, to, schema.text(text, marks));\n if (!this.selection.empty)\n this.setSelection(Selection.near(this.selection.$to));\n return this;\n }\n }\n /**\n Store a metadata property in this transaction, keyed either by\n name or by plugin.\n */\n setMeta(key, value) {\n this.meta[typeof key == \"string\" ? key : key.key] = value;\n return this;\n }\n /**\n Retrieve a metadata property for a given name or plugin.\n */\n getMeta(key) {\n return this.meta[typeof key == \"string\" ? key : key.key];\n }\n /**\n Returns true if this transaction doesn't contain any metadata,\n and can thus safely be extended.\n */\n get isGeneric() {\n for (let _ in this.meta)\n return false;\n return true;\n }\n /**\n Indicate that the editor should scroll the selection into view\n when updated to the state produced by this transaction.\n */\n scrollIntoView() {\n this.updated |= UPDATED_SCROLL;\n return this;\n }\n /**\n True when this transaction has had `scrollIntoView` called on it.\n */\n get scrolledIntoView() {\n return (this.updated & UPDATED_SCROLL) > 0;\n }\n}\n\nfunction bind(f, self) {\n return !self || !f ? f : f.bind(self);\n}\nclass FieldDesc {\n constructor(name, desc, self) {\n this.name = name;\n this.init = bind(desc.init, self);\n this.apply = bind(desc.apply, self);\n }\n}\nconst baseFields = [\n new FieldDesc(\"doc\", {\n init(config) { return config.doc || config.schema.topNodeType.createAndFill(); },\n apply(tr) { return tr.doc; }\n }),\n new FieldDesc(\"selection\", {\n init(config, instance) { return config.selection || Selection.atStart(instance.doc); },\n apply(tr) { return tr.selection; }\n }),\n new FieldDesc(\"storedMarks\", {\n init(config) { return config.storedMarks || null; },\n apply(tr, _marks, _old, state) { return state.selection.$cursor ? tr.storedMarks : null; }\n }),\n new FieldDesc(\"scrollToSelection\", {\n init() { return 0; },\n apply(tr, prev) { return tr.scrolledIntoView ? prev + 1 : prev; }\n })\n];\n// Object wrapping the part of a state object that stays the same\n// across transactions. Stored in the state's `config` property.\nclass Configuration {\n constructor(schema, plugins) {\n this.schema = schema;\n this.plugins = [];\n this.pluginsByKey = Object.create(null);\n this.fields = baseFields.slice();\n if (plugins)\n plugins.forEach(plugin => {\n if (this.pluginsByKey[plugin.key])\n throw new RangeError(\"Adding different instances of a keyed plugin (\" + plugin.key + \")\");\n this.plugins.push(plugin);\n this.pluginsByKey[plugin.key] = plugin;\n if (plugin.spec.state)\n this.fields.push(new FieldDesc(plugin.key, plugin.spec.state, plugin));\n });\n }\n}\n/**\nThe state of a ProseMirror editor is represented by an object of\nthis type. A state is a persistent data structure—it isn't\nupdated, but rather a new state value is computed from an old one\nusing the [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) method.\n\nA state holds a number of built-in fields, and plugins can\n[define](https://prosemirror.net/docs/ref/#state.PluginSpec.state) additional fields.\n*/\nclass EditorState {\n /**\n @internal\n */\n constructor(\n /**\n @internal\n */\n config) {\n this.config = config;\n }\n /**\n The schema of the state's document.\n */\n get schema() {\n return this.config.schema;\n }\n /**\n The plugins that are active in this state.\n */\n get plugins() {\n return this.config.plugins;\n }\n /**\n Apply the given transaction to produce a new state.\n */\n apply(tr) {\n return this.applyTransaction(tr).state;\n }\n /**\n @internal\n */\n filterTransaction(tr, ignore = -1) {\n for (let i = 0; i < this.config.plugins.length; i++)\n if (i != ignore) {\n let plugin = this.config.plugins[i];\n if (plugin.spec.filterTransaction && !plugin.spec.filterTransaction.call(plugin, tr, this))\n return false;\n }\n return true;\n }\n /**\n Verbose variant of [`apply`](https://prosemirror.net/docs/ref/#state.EditorState.apply) that\n returns the precise transactions that were applied (which might\n be influenced by the [transaction\n hooks](https://prosemirror.net/docs/ref/#state.PluginSpec.filterTransaction) of\n plugins) along with the new state.\n */\n applyTransaction(rootTr) {\n if (!this.filterTransaction(rootTr))\n return { state: this, transactions: [] };\n let trs = [rootTr], newState = this.applyInner(rootTr), seen = null;\n // This loop repeatedly gives plugins a chance to respond to\n // transactions as new transactions are added, making sure to only\n // pass the transactions the plugin did not see before.\n for (;;) {\n let haveNew = false;\n for (let i = 0; i < this.config.plugins.length; i++) {\n let plugin = this.config.plugins[i];\n if (plugin.spec.appendTransaction) {\n let n = seen ? seen[i].n : 0, oldState = seen ? seen[i].state : this;\n let tr = n < trs.length &&\n plugin.spec.appendTransaction.call(plugin, n ? trs.slice(n) : trs, oldState, newState);\n if (tr && newState.filterTransaction(tr, i)) {\n tr.setMeta(\"appendedTransaction\", rootTr);\n if (!seen) {\n seen = [];\n for (let j = 0; j < this.config.plugins.length; j++)\n seen.push(j < i ? { state: newState, n: trs.length } : { state: this, n: 0 });\n }\n trs.push(tr);\n newState = newState.applyInner(tr);\n haveNew = true;\n }\n if (seen)\n seen[i] = { state: newState, n: trs.length };\n }\n }\n if (!haveNew)\n return { state: newState, transactions: trs };\n }\n }\n /**\n @internal\n */\n applyInner(tr) {\n if (!tr.before.eq(this.doc))\n throw new RangeError(\"Applying a mismatched transaction\");\n let newInstance = new EditorState(this.config), fields = this.config.fields;\n for (let i = 0; i < fields.length; i++) {\n let field = fields[i];\n newInstance[field.name] = field.apply(tr, this[field.name], this, newInstance);\n }\n return newInstance;\n }\n /**\n Start a [transaction](https://prosemirror.net/docs/ref/#state.Transaction) from this state.\n */\n get tr() { return new Transaction(this); }\n /**\n Create a new state.\n */\n static create(config) {\n let $config = new Configuration(config.doc ? config.doc.type.schema : config.schema, config.plugins);\n let instance = new EditorState($config);\n for (let i = 0; i < $config.fields.length; i++)\n instance[$config.fields[i].name] = $config.fields[i].init(config, instance);\n return instance;\n }\n /**\n Create a new state based on this one, but with an adjusted set\n of active plugins. State fields that exist in both sets of\n plugins are kept unchanged. Those that no longer exist are\n dropped, and those that are new are initialized using their\n [`init`](https://prosemirror.net/docs/ref/#state.StateField.init) method, passing in the new\n configuration object..\n */\n reconfigure(config) {\n let $config = new Configuration(this.schema, config.plugins);\n let fields = $config.fields, instance = new EditorState($config);\n for (let i = 0; i < fields.length; i++) {\n let name = fields[i].name;\n instance[name] = this.hasOwnProperty(name) ? this[name] : fields[i].init(config, instance);\n }\n return instance;\n }\n /**\n Serialize this state to JSON. If you want to serialize the state\n of plugins, pass an object mapping property names to use in the\n resulting JSON object to plugin objects. The argument may also be\n a string or number, in which case it is ignored, to support the\n way `JSON.stringify` calls `toString` methods.\n */\n toJSON(pluginFields) {\n let result = { doc: this.doc.toJSON(), selection: this.selection.toJSON() };\n if (this.storedMarks)\n result.storedMarks = this.storedMarks.map(m => m.toJSON());\n if (pluginFields && typeof pluginFields == 'object')\n for (let prop in pluginFields) {\n if (prop == \"doc\" || prop == \"selection\")\n throw new RangeError(\"The JSON fields `doc` and `selection` are reserved\");\n let plugin = pluginFields[prop], state = plugin.spec.state;\n if (state && state.toJSON)\n result[prop] = state.toJSON.call(plugin, this[plugin.key]);\n }\n return result;\n }\n /**\n Deserialize a JSON representation of a state. `config` should\n have at least a `schema` field, and should contain array of\n plugins to initialize the state with. `pluginFields` can be used\n to deserialize the state of plugins, by associating plugin\n instances with the property names they use in the JSON object.\n */\n static fromJSON(config, json, pluginFields) {\n if (!json)\n throw new RangeError(\"Invalid input for EditorState.fromJSON\");\n if (!config.schema)\n throw new RangeError(\"Required config field 'schema' missing\");\n let $config = new Configuration(config.schema, config.plugins);\n let instance = new EditorState($config);\n $config.fields.forEach(field => {\n if (field.name == \"doc\") {\n instance.doc = Node.fromJSON(config.schema, json.doc);\n }\n else if (field.name == \"selection\") {\n instance.selection = Selection.fromJSON(instance.doc, json.selection);\n }\n else if (field.name == \"storedMarks\") {\n if (json.storedMarks)\n instance.storedMarks = json.storedMarks.map(config.schema.markFromJSON);\n }\n else {\n if (pluginFields)\n for (let prop in pluginFields) {\n let plugin = pluginFields[prop], state = plugin.spec.state;\n if (plugin.key == field.name && state && state.fromJSON &&\n Object.prototype.hasOwnProperty.call(json, prop)) {\n instance[field.name] = state.fromJSON.call(plugin, config, json[prop], instance);\n return;\n }\n }\n instance[field.name] = field.init(config, instance);\n }\n });\n return instance;\n }\n}\n\nfunction bindProps(obj, self, target) {\n for (let prop in obj) {\n let val = obj[prop];\n if (val instanceof Function)\n val = val.bind(self);\n else if (prop == \"handleDOMEvents\")\n val = bindProps(val, self, {});\n target[prop] = val;\n }\n return target;\n}\n/**\nPlugins bundle functionality that can be added to an editor.\nThey are part of the [editor state](https://prosemirror.net/docs/ref/#state.EditorState) and\nmay influence that state and the view that contains it.\n*/\nclass Plugin {\n /**\n Create a plugin.\n */\n constructor(\n /**\n The plugin's [spec object](https://prosemirror.net/docs/ref/#state.PluginSpec).\n */\n spec) {\n this.spec = spec;\n /**\n The [props](https://prosemirror.net/docs/ref/#view.EditorProps) exported by this plugin.\n */\n this.props = {};\n if (spec.props)\n bindProps(spec.props, this, this.props);\n this.key = spec.key ? spec.key.key : createKey(\"plugin\");\n }\n /**\n Extract the plugin's state field from an editor state.\n */\n getState(state) { return state[this.key]; }\n}\nconst keys = Object.create(null);\nfunction createKey(name) {\n if (name in keys)\n return name + \"$\" + ++keys[name];\n keys[name] = 0;\n return name + \"$\";\n}\n/**\nA key is used to [tag](https://prosemirror.net/docs/ref/#state.PluginSpec.key) plugins in a way\nthat makes it possible to find them, given an editor state.\nAssigning a key does mean only one plugin of that type can be\nactive in a state.\n*/\nclass PluginKey {\n /**\n Create a plugin key.\n */\n constructor(name = \"key\") { this.key = createKey(name); }\n /**\n Get the active plugin with this key, if any, from an editor\n state.\n */\n get(state) { return state.config.pluginsByKey[this.key]; }\n /**\n Get the plugin's state from an editor state.\n */\n getState(state) { return state[this.key]; }\n}\n\nexport { AllSelection, EditorState, NodeSelection, Plugin, PluginKey, Selection, SelectionRange, TextSelection, Transaction };\n","import type { Node as TiptapNode } from \"@tiptap/pm/model\"\nimport { NodeSelection, Selection, TextSelection } from \"@tiptap/pm/state\"\nimport type { Editor } from \"@tiptap/react\"\n\nexport const MAX_FILE_SIZE = 5 * 1024 * 1024 // 5MB\n\nexport const MAC_SYMBOLS: Record<string, string> = {\n mod: \"⌘\",\n command: \"⌘\",\n meta: \"⌘\",\n ctrl: \"⌃\",\n control: \"⌃\",\n alt: \"⌥\",\n option: \"⌥\",\n shift: \"⇧\",\n backspace: \"Del\",\n delete: \"⌦\",\n enter: \"⏎\",\n escape: \"⎋\",\n capslock: \"⇪\",\n} as const\n\nexport function cn(\n ...classes: (string | boolean | undefined | null)[]\n): string {\n return classes.filter(Boolean).join(\" \")\n}\n\n/**\n * Determines if the current platform is macOS\n * @returns boolean indicating if the current platform is Mac\n */\nexport function isMac(): boolean {\n return (\n typeof navigator !== \"undefined\" &&\n navigator.platform.toLowerCase().includes(\"mac\")\n )\n}\n\n/**\n * Formats a shortcut key based on the platform (Mac or non-Mac)\n * @param key - The key to format (e.g., \"ctrl\", \"alt\", \"shift\")\n * @param isMac - Boolean indicating if the platform is Mac\n * @param capitalize - Whether to capitalize the key (default: true)\n * @returns Formatted shortcut key symbol\n */\nexport const formatShortcutKey = (\n key: string,\n isMac: boolean,\n capitalize: boolean = true\n) => {\n if (isMac) {\n const lowerKey = key.toLowerCase()\n return MAC_SYMBOLS[lowerKey] || (capitalize ? key.toUpperCase() : key)\n }\n\n return capitalize ? key.charAt(0).toUpperCase() + key.slice(1) : key\n}\n\n/**\n * Parses a shortcut key string into an array of formatted key symbols\n * @param shortcutKeys - The string of shortcut keys (e.g., \"ctrl-alt-shift\")\n * @param delimiter - The delimiter used to split the keys (default: \"-\")\n * @param capitalize - Whether to capitalize the keys (default: true)\n * @returns Array of formatted shortcut key symbols\n */\nexport const parseShortcutKeys = (props: {\n shortcutKeys: string | undefined\n delimiter?: string\n capitalize?: boolean\n}) => {\n const { shortcutKeys, delimiter = \"+\", capitalize = true } = props\n\n if (!shortcutKeys) return []\n\n return shortcutKeys\n .split(delimiter)\n .map((key) => key.trim())\n .map((key) => formatShortcutKey(key, isMac(), capitalize))\n}\n\n/**\n * Checks if a mark exists in the editor schema\n * @param markName - The name of the mark to check\n * @param editor - The editor instance\n * @returns boolean indicating if the mark exists in the schema\n */\nexport const isMarkInSchema = (\n markName: string,\n editor: Editor | null\n): boolean => {\n if (!editor?.schema) return false\n return editor.schema.spec.marks.get(markName) !== undefined\n}\n\n/**\n * Checks if a node exists in the editor schema\n * @param nodeName - The name of the node to check\n * @param editor - The editor instance\n * @returns boolean indicating if the node exists in the schema\n */\nexport const isNodeInSchema = (\n nodeName: string,\n editor: Editor | null\n): boolean => {\n if (!editor?.schema) return false\n return editor.schema.spec.nodes.get(nodeName) !== undefined\n}\n\n/**\n * Moves the focus to the next node in the editor\n * @param editor - The editor instance\n * @returns boolean indicating if the focus was moved\n */\nexport function focusNextNode(editor: Editor) {\n const { state, view } = editor\n const { doc, selection } = state\n\n const nextSel = Selection.findFrom(selection.$to, 1, true)\n if (nextSel) {\n view.dispatch(state.tr.setSelection(nextSel).scrollIntoView())\n return true\n }\n\n const paragraphType = state.schema.nodes.paragraph\n if (!paragraphType) {\n console.warn(\"No paragraph node type found in schema.\")\n return false\n }\n\n const end = doc.content.size\n const para = paragraphType.create()\n let tr = state.tr.insert(end, para)\n\n // Place the selection inside the new paragraph\n const $inside = tr.doc.resolve(end + 1)\n tr = tr.setSelection(TextSelection.near($inside)).scrollIntoView()\n view.dispatch(tr)\n return true\n}\n\n/**\n * Checks if a value is a valid number (not null, undefined, or NaN)\n * @param value - The value to check\n * @returns boolean indicating if the value is a valid number\n */\nexport function isValidPosition(pos: number | null | undefined): pos is number {\n return typeof pos === \"number\" && pos >= 0\n}\n\n/**\n * Checks if one or more extensions are registered in the Tiptap editor.\n * @param editor - The Tiptap editor instance\n * @param extensionNames - A single extension name or an array of names to check\n * @returns True if at least one of the extensions is available, false otherwise\n */\nexport function isExtensionAvailable(\n editor: Editor | null,\n extensionNames: string | string[]\n): boolean {\n if (!editor) return false\n\n const names = Array.isArray(extensionNames)\n ? extensionNames\n : [extensionNames]\n\n const found = names.some((name) =>\n editor.extensionManager.extensions.some((ext) => ext.name === name)\n )\n\n if (!found) {\n console.warn(\n `None of the extensions [${names.join(\", \")}] were found in the editor schema. Ensure they are included in the editor configuration.`\n )\n }\n\n return found\n}\n\n/**\n * Finds a node at the specified position with error handling\n * @param editor The Tiptap editor instance\n * @param position The position in the document to find the node\n * @returns The node at the specified position, or null if not found\n */\nexport function findNodeAtPosition(editor: Editor, position: number) {\n try {\n const node = editor.state.doc.nodeAt(position)\n if (!node) {\n console.warn(`No node found at position ${position}`)\n return null\n }\n return node\n } catch (error) {\n console.error(`Error getting node at position ${position}:`, error)\n return null\n }\n}\n\n/**\n * Finds the position and instance of a node in the document\n * @param props Object containing editor, node (optional), and nodePos (optional)\n * @param props.editor The Tiptap editor instance\n * @param props.node The node to find (optional if nodePos is provided)\n * @param props.nodePos The position of the node to find (optional if node is provided)\n * @returns An object with the position and node, or null if not found\n */\nexport function findNodePosition(props: {\n editor: Editor | null\n node?: TiptapNode | null\n nodePos?: number | null\n}): { pos: number; node: TiptapNode } | null {\n const { editor, node, nodePos } = props\n\n if (!editor || !editor.state?.doc) return null\n\n // Zero is valid position\n const hasValidNode = node !== undefined && node !== null\n const hasValidPos = isValidPosition(nodePos)\n\n if (!hasValidNode && !hasValidPos) {\n return null\n }\n\n // First search for the node in the document if we have a node\n if (hasValidNode) {\n let foundPos = -1\n let foundNode: TiptapNode | null = null\n\n editor.state.doc.descendants((currentNode, pos) => {\n // TODO: Needed?\n // if (currentNode.type && currentNode.type.name === node!.type.name) {\n if (currentNode === node) {\n foundPos = pos\n foundNode = currentNode\n return false\n }\n return true\n })\n\n if (foundPos !== -1 && foundNode !== null) {\n return { pos: foundPos, node: foundNode }\n }\n }\n\n // If we have a valid position, use findNodeAtPosition\n if (hasValidPos) {\n const nodeAtPos = findNodeAtPosition(editor, nodePos!)\n if (nodeAtPos) {\n return { pos: nodePos!, node: nodeAtPos }\n }\n }\n\n return null\n}\n\n/**\n * Checks if the current selection in the editor is a node selection of specified types\n * @param editor The Tiptap editor instance\n * @param types An array of node type names to check against\n * @returns boolean indicating if the selected node matches any of the specified types\n */\nexport function isNodeTypeSelected(\n editor: Editor | null,\n types: string[] = []\n): boolean {\n if (!editor || !editor.state.selection) return false\n\n const { state } = editor\n const { selection } = state\n\n if (selection.empty) return false\n\n if (selection instanceof NodeSelection) {\n const node = selection.node\n return node ? types.includes(node.type.name) : false\n }\n\n return false\n}\n\n/**\n * Handles image upload with progress tracking and abort capability\n * @param file The file to upload\n * @param onProgress Optional callback for tracking upload progress\n * @param abortSignal Optional AbortSignal for cancelling the upload\n * @returns Promise resolving to the URL of the uploaded image\n */\nexport const handleImageUpload = async (\n file: File,\n onProgress?: (event: { progress: number }) => void,\n abortSignal?: AbortSignal\n): Promise<string> => {\n // Validate file\n if (!file) {\n throw new Error(\"No file provided\")\n }\n\n if (file.size > MAX_FILE_SIZE) {\n throw new Error(\n `File size exceeds maximum allowed (${MAX_FILE_SIZE / (1024 * 1024)}MB)`\n )\n }\n\n // For demo/testing: Simulate upload progress. In production, replace the following code\n // with your own upload implementation.\n for (let progress = 0; progress <= 100; progress += 10) {\n if (abortSignal?.aborted) {\n throw new Error(\"Upload cancelled\")\n }\n await new Promise((resolve) => setTimeout(resolve, 500))\n onProgress?.({ progress })\n }\n\n return \"/images/tiptap-ui-placeholder-image.jpg\"\n}\n\ntype ProtocolOptions = {\n /**\n * The protocol scheme to be registered.\n * @default '''\n * @example 'ftp'\n * @example 'git'\n */\n scheme: string\n\n /**\n * If enabled, it allows optional slashes after the protocol.\n * @default false\n * @example true\n */\n optionalSlashes?: boolean\n}\n\ntype ProtocolConfig = Array<ProtocolOptions | string>\n\nconst ATTR_WHITESPACE =\n // eslint-disable-next-line no-control-regex\n /[\\u0000-\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u2029\\u205F\\u3000]/g\n\nexport function isAllowedUri(\n uri: string | undefined,\n protocols?: ProtocolConfig\n) {\n const allowedProtocols: string[] = [\n \"http\",\n \"https\",\n \"ftp\",\n \"ftps\",\n \"mailto\",\n \"tel\",\n \"callto\",\n \"sms\",\n \"cid\",\n \"xmpp\",\n ]\n\n if (protocols) {\n protocols.forEach((protocol) => {\n const nextProtocol =\n typeof protocol === \"string\" ? protocol : protocol.scheme\n\n if (nextProtocol) {\n allowedProtocols.push(nextProtocol)\n }\n })\n }\n\n return (\n !uri ||\n uri.replace(ATTR_WHITESPACE, \"\").match(\n new RegExp(\n // eslint-disable-next-line no-useless-escape\n `^(?:(?:${allowedProtocols.join(\"|\")}):|[^a-z]|[a-z0-9+.\\-]+(?:[^a-z+.\\-:]|$))`,\n \"i\"\n )\n )\n )\n}\n\nexport function sanitizeUrl(\n inputUrl: string,\n baseUrl: string,\n protocols?: ProtocolConfig\n): string {\n try {\n const url = new URL(inputUrl, baseUrl)\n\n if (isAllowedUri(url.href, protocols)) {\n return url.href\n }\n } catch {\n // If URL creation fails, it's considered invalid\n }\n return \"#\"\n}\n","import * as React from \"react\"\n\n// --- Tiptap UI Primitive ---\nimport {\n Tooltip,\n TooltipContent,\n TooltipTrigger,\n} from \"@/components/tiptap-ui-primitive/tooltip\"\n\n// --- Lib ---\nimport { cn, parseShortcutKeys } from \"@/lib/tiptap-utils\"\n\nimport \"@/components/tiptap-ui-primitive/button/button-colors.scss\"\nimport \"@/components/tiptap-ui-primitive/button/button-group.scss\"\nimport \"@/components/tiptap-ui-primitive/button/button.scss\"\n\nexport interface ButtonProps\n extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n className?: string\n showTooltip?: boolean\n tooltip?: React.ReactNode\n shortcutKeys?: string\n}\n\nexport const ShortcutDisplay: React.FC<{ shortcuts: string[] }> = ({\n shortcuts,\n}) => {\n if (shortcuts.length === 0) return null\n\n return (\n <div>\n {shortcuts.map((key, index) => (\n <React.Fragment key={index}>\n {index > 0 && <kbd>+</kbd>}\n <kbd>{key}</kbd>\n </React.Fragment>\n ))}\n </div>\n )\n}\n\nexport const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(\n (\n {\n className,\n children,\n tooltip,\n showTooltip = true,\n shortcutKeys,\n \"aria-label\": ariaLabel,\n ...props\n },\n ref\n ) => {\n const shortcuts = React.useMemo(\n () => parseShortcutKeys({ shortcutKeys }),\n [shortcutKeys]\n )\n\n if (!tooltip || !showTooltip) {\n return (\n <button\n className={cn(\"tiptap-button\", className)}\n ref={ref}\n aria-label={ariaLabel}\n {...props}\n >\n {children}\n </button>\n )\n }\n\n return (\n <Tooltip delay={200}>\n <TooltipTrigger\n className={cn(\"tiptap-button\", className)}\n ref={ref}\n aria-label={ariaLabel}\n {...props}\n >\n {children}\n </TooltipTrigger>\n <TooltipContent>\n {tooltip}\n <ShortcutDisplay shortcuts={shortcuts} />\n </TooltipContent>\n </Tooltip>\n )\n }\n)\n\nButton.displayName = \"Button\"\n\nexport const ButtonGroup = React.forwardRef<\n HTMLDivElement,\n React.ComponentProps<\"div\"> & {\n orientation?: \"horizontal\" | \"vertical\"\n }\n>(({ className, children, orientation = \"vertical\", ...props }, ref) => {\n return (\n <div\n ref={ref}\n className={cn(\"tiptap-button-group\", className)}\n data-orientation={orientation}\n role=\"group\"\n {...props}\n >\n {children}\n </div>\n )\n})\nButtonGroup.displayName = \"ButtonGroup\"\n\nexport default Button\n","\"use client\"\n\nimport * as React from \"react\"\n\nexport type SpacerOrientation = \"horizontal\" | \"vertical\"\n\nexport interface SpacerProps extends React.HTMLAttributes<HTMLDivElement> {\n orientation?: SpacerOrientation\n size?: string | number\n}\n\nexport function Spacer({\n orientation = \"horizontal\",\n size,\n style = {},\n ...props\n}: SpacerProps) {\n const computedStyle = {\n ...style,\n ...(orientation === \"horizontal\" && !size && { flex: 1 }),\n ...(size && {\n width: orientation === \"vertical\" ? \"1px\" : size,\n height: orientation === \"horizontal\" ? \"1px\" : size,\n }),\n }\n\n return <div {...props} style={computedStyle} />\n}\n","import * as React from \"react\"\nimport \"@/components/tiptap-ui-primitive/separator/separator.scss\"\nimport { cn } from \"@/lib/tiptap-utils\"\n\nexport type Orientation = \"horizontal\" | \"vertical\"\n\nexport interface SeparatorProps extends React.HTMLAttributes<HTMLDivElement> {\n orientation?: Orientation\n decorative?: boolean\n}\n\nexport const Separator = React.forwardRef<HTMLDivElement, SeparatorProps>(\n ({ decorative, orientation = \"vertical\", className, ...divProps }, ref) => {\n const ariaOrientation = orientation === \"vertical\" ? orientation : undefined\n const semanticProps = decorative\n ? { role: \"none\" }\n : { \"aria-orientation\": ariaOrientation, role: \"separator\" }\n\n return (\n <div\n className={cn(\"tiptap-separator\", className)}\n data-orientation={orientation}\n {...semanticProps}\n {...divProps}\n ref={ref}\n />\n )\n }\n)\n\nSeparator.displayName = \"Separator\"\n","import * as React from \"react\"\nimport type { Editor } from \"@tiptap/react\"\n\ntype Orientation = \"horizontal\" | \"vertical\" | \"both\"\n\ninterface MenuNavigationOptions<T> {\n /**\n * The Tiptap editor instance, if using with a Tiptap editor.\n */\n editor?: Editor | null\n /**\n * Reference to the container element for handling keyboard events.\n */\n containerRef?: React.RefObject<HTMLElement | null>\n /**\n * Search query that affects the selected item.\n */\n query?: string\n /**\n * Array of items to navigate through.\n */\n items: T[]\n /**\n * Callback fired when an item is selected.\n */\n onSelect?: (item: T) => void\n /**\n * Callback fired when the menu should close.\n */\n onClose?: () => void\n /**\n * The navigation orientation of the menu.\n * @default \"vertical\"\n */\n orientation?: Orientation\n /**\n * Whether to automatically select the first item when the menu opens.\n * @default true\n */\n autoSelectFirstItem?: boolean\n}\n\n/**\n * Hook that implements keyboard navigation for dropdown menus and command palettes.\n *\n * Handles arrow keys, tab, home/end, enter for selection, and escape to close.\n * Works with both Tiptap editors and regular DOM elements.\n *\n * @param options - Configuration options for the menu navigation\n * @returns Object containing the selected index and a setter function\n */\nexport function useMenuNavigation<T>({\n editor,\n containerRef,\n query,\n items,\n onSelect,\n onClose,\n orientation = \"vertical\",\n autoSelectFirstItem = true,\n}: MenuNavigationOptions<T>) {\n const [selectedIndex, setSelectedIndex] = React.useState<number>(\n autoSelectFirstItem ? 0 : -1\n )\n\n React.useEffect(() => {\n const handleKeyboardNavigation = (event: KeyboardEvent) => {\n if (!items.length) return false\n\n const moveNext = () =>\n setSelectedIndex((currentIndex) => {\n if (currentIndex === -1) return 0\n return (currentIndex + 1) % items.length\n })\n\n const movePrev = () =>\n setSelectedIndex((currentIndex) => {\n if (currentIndex === -1) return items.length - 1\n return (currentIndex - 1 + items.length) % items.length\n })\n\n switch (event.key) {\n case \"ArrowUp\": {\n if (orientation === \"horizontal\") return false\n event.preventDefault()\n movePrev()\n return true\n }\n\n case \"ArrowDown\": {\n if (orientation === \"horizontal\") return false\n event.preventDefault()\n moveNext()\n return true\n }\n\n case \"ArrowLeft\": {\n if (orientation === \"vertical\") return false\n event.preventDefault()\n movePrev()\n return true\n }\n\n case \"ArrowRight\": {\n if (orientation === \"vertical\") return false\n event.preventDefault()\n moveNext()\n return true\n }\n\n case \"Tab\": {\n event.preventDefault()\n if (event.shiftKey) {\n movePrev()\n } else {\n moveNext()\n }\n return true\n }\n\n case \"Home\": {\n event.preventDefault()\n setSelectedIndex(0)\n return true\n }\n\n case \"End\": {\n event.preventDefault()\n setSelectedIndex(items.length - 1)\n return true\n }\n\n case \"Enter\": {\n if (event.isComposing) return false\n event.preventDefault()\n if (selectedIndex !== -1 && items[selectedIndex]) {\n onSelect?.(items[selectedIndex])\n }\n return true\n }\n\n case \"Escape\": {\n event.preventDefault()\n onClose?.()\n return true\n }\n\n default:\n return false\n }\n }\n\n let targetElement: HTMLElement | null = null\n\n if (editor) {\n targetElement = editor.view.dom\n } else if (containerRef?.current) {\n targetElement = containerRef.current\n }\n\n if (targetElement) {\n targetElement.addEventListener(\"keydown\", handleKeyboardNavigation, true)\n\n return () => {\n targetElement?.removeEventListener(\n \"keydown\",\n handleKeyboardNavigation,\n true\n )\n }\n }\n\n return undefined\n }, [\n editor,\n containerRef,\n items,\n selectedIndex,\n onSelect,\n onClose,\n orientation,\n ])\n\n React.useEffect(() => {\n if (query) {\n setSelectedIndex(autoSelectFirstItem ? 0 : -1)\n }\n }, [query, autoSelectFirstItem])\n\n return {\n selectedIndex: items.length ? selectedIndex : undefined,\n setSelectedIndex,\n }\n}\n","\"use client\"\n\nimport * as React from \"react\"\n\n// basically Exclude<React.ClassAttributes<T>[\"ref\"], string>\ntype UserRef<T> =\n | ((instance: T | null) => void)\n | React.RefObject<T | null>\n | null\n | undefined\n\nconst updateRef = <T>(ref: NonNullable<UserRef<T>>, value: T | null) => {\n if (typeof ref === \"function\") {\n ref(value)\n } else if (ref && typeof ref === \"object\" && \"current\" in ref) {\n // Safe assignment without MutableRefObject\n ;(ref as { current: T | null }).current = value\n }\n}\n\nexport const useComposedRef = <T extends HTMLElement>(\n libRef: React.RefObject<T | null>,\n userRef: UserRef<T>\n) => {\n const prevUserRef = React.useRef<UserRef<T>>(null)\n\n return React.useCallback(\n (instance: T | null) => {\n if (libRef && \"current\" in libRef) {\n ;(libRef as { current: T | null }).current = instance\n }\n\n if (prevUserRef.current) {\n updateRef(prevUserRef.current, null)\n }\n\n prevUserRef.current = userRef\n\n if (userRef) {\n updateRef(userRef, instance)\n }\n },\n [libRef, userRef]\n )\n}\n\nexport default useComposedRef\n","import * as React from \"react\"\nimport { Separator } from \"@/components/tiptap-ui-primitive/separator\"\nimport \"@/components/tiptap-ui-primitive/toolbar/toolbar.scss\"\nimport { cn } from \"@/lib/tiptap-utils\"\nimport { useMenuNavigation } from \"@/hooks/use-menu-navigation\"\nimport { useComposedRef } from \"@/hooks/use-composed-ref\"\n\ntype BaseProps = React.HTMLAttributes<HTMLDivElement>\n\ninterface ToolbarProps extends BaseProps {\n variant?: \"floating\" | \"fixed\"\n}\n\nconst useToolbarNavigation = (\n toolbarRef: React.RefObject<HTMLDivElement | null>\n) => {\n const [items, setItems] = React.useState<HTMLElement[]>([])\n\n const collectItems = React.useCallback(() => {\n if (!toolbarRef.current) return []\n return Array.from(\n toolbarRef.current.querySelectorAll<HTMLElement>(\n 'button:not([disabled]), [role=\"button\"]:not([disabled]), [tabindex=\"0\"]:not([disabled])'\n )\n )\n }, [toolbarRef])\n\n React.useEffect(() => {\n const toolbar = toolbarRef.current\n if (!toolbar) return\n\n const updateItems = () => setItems(collectItems())\n\n updateItems()\n const observer = new MutationObserver(updateItems)\n observer.observe(toolbar, { childList: true, subtree: true })\n\n return () => observer.disconnect()\n }, [collectItems, toolbarRef])\n\n const { selectedIndex } = useMenuNavigation<HTMLElement>({\n containerRef: toolbarRef,\n items,\n orientation: \"horizontal\",\n onSelect: (el) => el.click(),\n autoSelectFirstItem: false,\n })\n\n React.useEffect(() => {\n const toolbar = toolbarRef.current\n if (!toolbar) return\n\n const handleFocus = (e: FocusEvent) => {\n const target = e.target as HTMLElement\n if (toolbar.contains(target))\n target.setAttribute(\"data-focus-visible\", \"true\")\n }\n\n const handleBlur = (e: FocusEvent) => {\n const target = e.target as HTMLElement\n if (toolbar.contains(target)) target.removeAttribute(\"data-focus-visible\")\n }\n\n toolbar.addEventListener(\"focus\", handleFocus, true)\n toolbar.addEventListener(\"blur\", handleBlur, true)\n\n return () => {\n toolbar.removeEventListener(\"focus\", handleFocus, true)\n toolbar.removeEventListener(\"blur\", handleBlur, true)\n }\n }, [toolbarRef])\n\n React.useEffect(() => {\n if (selectedIndex !== undefined && items[selectedIndex]) {\n items[selectedIndex].focus()\n }\n }, [selectedIndex, items])\n}\n\nexport const Toolbar = React.forwardRef<HTMLDivElement, ToolbarProps>(\n ({ children, className, variant = \"fixed\", ...props }, ref) => {\n const toolbarRef = React.useRef<HTMLDivElement>(null)\n const composedRef = useComposedRef(toolbarRef, ref)\n useToolbarNavigation(toolbarRef)\n\n return (\n <div\n ref={composedRef}\n role=\"toolbar\"\n aria-label=\"toolbar\"\n data-variant={variant}\n className={cn(\"tiptap-toolbar\", className)}\n {...props}\n >\n {children}\n </div>\n )\n }\n)\nToolbar.displayName = \"Toolbar\"\n\nexport const ToolbarGroup = React.forwardRef<HTMLDivElement, BaseProps>(\n ({ children, className, ...props }, ref) => (\n <div\n ref={ref}\n role=\"group\"\n className={cn(\"tiptap-toolbar-group\", className)}\n {...props}\n >\n {children}\n </div>\n )\n)\nToolbarGroup.displayName = \"ToolbarGroup\"\n\nexport const ToolbarSeparator = React.forwardRef<HTMLDivElement, BaseProps>(\n ({ ...props }, ref) => (\n <Separator ref={ref} orientation=\"vertical\" decorative {...props} />\n )\n)\nToolbarSeparator.displayName = \"ToolbarSeparator\"\n","import * as React from \"react\"\n\nexport const CloseIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M18.7071 6.70711C19.0976 6.31658 19.0976 5.68342 18.7071 5.29289C18.3166 4.90237 17.6834 4.90237 17.2929 5.29289L12 10.5858L6.70711 5.29289C6.31658 4.90237 5.68342 4.90237 5.29289 5.29289C4.90237 5.68342 4.90237 6.31658 5.29289 6.70711L10.5858 12L5.29289 17.2929C4.90237 17.6834 4.90237 18.3166 5.29289 18.7071C5.68342 19.0976 6.31658 19.0976 6.70711 18.7071L12 13.4142L17.2929 18.7071C17.6834 19.0976 18.3166 19.0976 18.7071 18.7071C19.0976 18.3166 19.0976 17.6834 18.7071 17.2929L13.4142 12L18.7071 6.70711Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nCloseIcon.displayName = \"CloseIcon\"\n","\"use client\"\n\nimport * as React from \"react\"\nimport type { NodeViewProps } from \"@tiptap/react\"\nimport { NodeViewWrapper } from \"@tiptap/react\"\nimport { Button } from \"@/components/tiptap-ui-primitive/button\"\nimport { CloseIcon } from \"@/components/tiptap-icons/close-icon\"\nimport \"@/components/tiptap-node/image-upload-node/image-upload-node.scss\"\nimport { focusNextNode, isValidPosition } from \"@/lib/tiptap-utils\"\n\nexport interface FileItem {\n /**\n * Unique identifier for the file item\n */\n id: string\n /**\n * The actual File object being uploaded\n */\n file: File\n /**\n * Current upload progress as a percentage (0-100)\n */\n progress: number\n /**\n * Current status of the file upload process\n * @default \"uploading\"\n */\n status: \"uploading\" | \"success\" | \"error\"\n\n /**\n * URL to the uploaded file, available after successful upload\n * @optional\n */\n url?: string\n /**\n * Controller that can be used to abort the upload process\n * @optional\n */\n abortController?: AbortController\n}\n\nexport interface UploadOptions {\n /**\n * Maximum allowed file size in bytes\n */\n maxSize: number\n /**\n * Maximum number of files that can be uploaded\n */\n limit: number\n /**\n * String specifying acceptable file types (MIME types or extensions)\n * @example \".jpg,.png,image/jpeg\" or \"image/*\"\n */\n accept: string\n /**\n * Function that handles the actual file upload process\n * @param {File} file - The file to be uploaded\n * @param {Function} onProgress - Callback function to report upload progress\n * @param {AbortSignal} signal - Signal that can be used to abort the upload\n * @returns {Promise<string>} Promise resolving to the URL of the uploaded file\n */\n upload: (\n file: File,\n onProgress: (event: { progress: number }) => void,\n signal: AbortSignal\n ) => Promise<string>\n /**\n * Callback triggered when a file is uploaded successfully\n * @param {string} url - URL of the successfully uploaded file\n * @optional\n */\n onSuccess?: (url: string) => void\n /**\n * Callback triggered when an error occurs during upload\n * @param {Error} error - The error that occurred\n * @optional\n */\n onError?: (error: Error) => void\n}\n\n/**\n * Custom hook for managing multiple file uploads with progress tracking and cancellation\n */\nfunction useFileUpload(options: UploadOptions) {\n const [fileItems, setFileItems] = React.useState<FileItem[]>([])\n\n const uploadFile = async (file: File): Promise<string | null> => {\n if (file.size > options.maxSize) {\n const error = new Error(\n `File size exceeds maximum allowed (${options.maxSize / 1024 / 1024}MB)`\n )\n options.onError?.(error)\n return null\n }\n\n const abortController = new AbortController()\n const fileId = crypto.randomUUID()\n\n const newFileItem: FileItem = {\n id: fileId,\n file,\n progress: 0,\n status: \"uploading\",\n abortController,\n }\n\n setFileItems((prev) => [...prev, newFileItem])\n\n try {\n if (!options.upload) {\n throw new Error(\"Upload function is not defined\")\n }\n\n const url = await options.upload(\n file,\n (event: { progress: number }) => {\n setFileItems((prev) =>\n prev.map((item) =>\n item.id === fileId ? { ...item, progress: event.progress } : item\n )\n )\n },\n abortController.signal\n )\n\n if (!url) throw new Error(\"Upload failed: No URL returned\")\n\n if (!abortController.signal.aborted) {\n setFileItems((prev) =>\n prev.map((item) =>\n item.id === fileId\n ? { ...item, status: \"success\", url, progress: 100 }\n : item\n )\n )\n options.onSuccess?.(url)\n return url\n }\n\n return null\n } catch (error) {\n if (!abortController.signal.aborted) {\n setFileItems((prev) =>\n prev.map((item) =>\n item.id === fileId\n ? { ...item, status: \"error\", progress: 0 }\n : item\n )\n )\n options.onError?.(\n error instanceof Error ? error : new Error(\"Upload failed\")\n )\n }\n return null\n }\n }\n\n const uploadFiles = async (files: File[]): Promise<string[]> => {\n if (!files || files.length === 0) {\n options.onError?.(new Error(\"No files to upload\"))\n return []\n }\n\n if (options.limit && files.length > options.limit) {\n options.onError?.(\n new Error(\n `Maximum ${options.limit} file${options.limit === 1 ? \"\" : \"s\"} allowed`\n )\n )\n return []\n }\n\n // Upload all files concurrently\n const uploadPromises = files.map((file) => uploadFile(file))\n const results = await Promise.all(uploadPromises)\n\n // Filter out null results (failed uploads)\n return results.filter((url): url is string => url !== null)\n }\n\n const removeFileItem = (fileId: string) => {\n setFileItems((prev) => {\n const fileToRemove = prev.find((item) => item.id === fileId)\n if (fileToRemove?.abortController) {\n fileToRemove.abortController.abort()\n }\n if (fileToRemove?.url) {\n URL.revokeObjectURL(fileToRemove.url)\n }\n return prev.filter((item) => item.id !== fileId)\n })\n }\n\n const clearAllFiles = () => {\n fileItems.forEach((item) => {\n if (item.abortController) {\n item.abortController.abort()\n }\n if (item.url) {\n URL.revokeObjectURL(item.url)\n }\n })\n setFileItems([])\n }\n\n return {\n fileItems,\n uploadFiles,\n removeFileItem,\n clearAllFiles,\n }\n}\n\nconst CloudUploadIcon: React.FC = () => (\n <svg\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n className=\"tiptap-image-upload-icon\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M11.1953 4.41771C10.3478 4.08499 9.43578 3.94949 8.5282 4.02147C7.62062 4.09345 6.74133 4.37102 5.95691 4.83316C5.1725 5.2953 4.50354 5.92989 4.00071 6.68886C3.49788 7.44783 3.17436 8.31128 3.05465 9.2138C2.93495 10.1163 3.0222 11.0343 3.3098 11.8981C3.5974 12.7619 4.07781 13.5489 4.71463 14.1995C5.10094 14.5942 5.09414 15.2274 4.69945 15.6137C4.30476 16 3.67163 15.9932 3.28532 15.5985C2.43622 14.731 1.79568 13.6816 1.41221 12.5299C1.02875 11.3781 0.91241 10.1542 1.07201 8.95084C1.23162 7.74748 1.66298 6.59621 2.33343 5.58425C3.00387 4.57229 3.89581 3.72617 4.9417 3.10998C5.98758 2.4938 7.15998 2.1237 8.37008 2.02773C9.58018 1.93176 10.7963 2.11243 11.9262 2.55605C13.0561 2.99968 14.0703 3.69462 14.8919 4.58825C15.5423 5.29573 16.0585 6.11304 16.4177 7.00002H17.4999C18.6799 6.99991 19.8288 7.37933 20.7766 8.08222C21.7245 8.78515 22.4212 9.7743 22.7637 10.9036C23.1062 12.0328 23.0765 13.2423 22.6788 14.3534C22.2812 15.4644 21.5367 16.4181 20.5554 17.0736C20.0962 17.3803 19.4752 17.2567 19.1684 16.7975C18.8617 16.3382 18.9853 15.7172 19.4445 15.4105C20.069 14.9934 20.5427 14.3865 20.7958 13.6794C21.0488 12.9724 21.0678 12.2027 20.8498 11.4841C20.6318 10.7655 20.1885 10.136 19.5853 9.6887C18.9821 9.24138 18.251 8.99993 17.5001 9.00002H15.71C15.2679 9.00002 14.8783 8.70973 14.7518 8.28611C14.4913 7.41374 14.0357 6.61208 13.4195 5.94186C12.8034 5.27164 12.0427 4.75043 11.1953 4.41771Z\"\n fill=\"currentColor\"\n />\n <path\n d=\"M11 14.4142V21C11 21.5523 11.4477 22 12 22C12.5523 22 13 21.5523 13 21V14.4142L15.2929 16.7071C15.6834 17.0976 16.3166 17.0976 16.7071 16.7071C17.0976 16.3166 17.0976 15.6834 16.7071 15.2929L12.7078 11.2936C12.7054 11.2912 12.703 11.2888 12.7005 11.2864C12.5208 11.1099 12.2746 11.0008 12.003 11L12 11L11.997 11C11.8625 11.0004 11.7343 11.0273 11.6172 11.0759C11.502 11.1236 11.3938 11.1937 11.2995 11.2864C11.297 11.2888 11.2946 11.2912 11.2922 11.2936L7.29289 15.2929C6.90237 15.6834 6.90237 16.3166 7.29289 16.7071C7.68342 17.0976 8.31658 17.0976 8.70711 16.7071L11 14.4142Z\"\n fill=\"currentColor\"\n />\n </svg>\n)\n\nconst FileIcon: React.FC = () => (\n <svg\n width=\"43\"\n height=\"57\"\n viewBox=\"0 0 43 57\"\n fill=\"currentColor\"\n className=\"tiptap-image-upload-dropzone-rect-primary\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M0.75 10.75C0.75 5.64137 4.89137 1.5 10 1.5H32.3431C33.2051 1.5 34.0317 1.84241 34.6412 2.4519L40.2981 8.10876C40.9076 8.71825 41.25 9.5449 41.25 10.4069V46.75C41.25 51.8586 37.1086 56 32 56H10C4.89137 56 0.75 51.8586 0.75 46.75V10.75Z\"\n fill=\"currentColor\"\n fillOpacity=\"0.11\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n />\n </svg>\n)\n\nconst FileCornerIcon: React.FC = () => (\n <svg\n width=\"10\"\n height=\"10\"\n className=\"tiptap-image-upload-dropzone-rect-secondary\"\n viewBox=\"0 0 10 10\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n d=\"M0 0.75H0.343146C1.40401 0.75 2.42143 1.17143 3.17157 1.92157L8.82843 7.57843C9.57857 8.32857 10 9.34599 10 10.4069V10.75H4C1.79086 10.75 0 8.95914 0 6.75V0.75Z\"\n fill=\"currentColor\"\n />\n </svg>\n)\n\ninterface ImageUploadDragAreaProps {\n /**\n * Callback function triggered when files are dropped or selected\n * @param {File[]} files - Array of File objects that were dropped or selected\n */\n onFile: (files: File[]) => void\n /**\n * Optional child elements to render inside the drag area\n * @optional\n * @default undefined\n */\n children?: React.ReactNode\n}\n\n/**\n * A component that creates a drag-and-drop area for image uploads\n */\nconst ImageUploadDragArea: React.FC<ImageUploadDragAreaProps> = ({\n onFile,\n children,\n}) => {\n const [isDragOver, setIsDragOver] = React.useState(false)\n const [isDragActive, setIsDragActive] = React.useState(false)\n\n const handleDragEnter = (e: React.DragEvent) => {\n e.preventDefault()\n e.stopPropagation()\n setIsDragActive(true)\n }\n\n const handleDragLeave = (e: React.DragEvent) => {\n e.preventDefault()\n e.stopPropagation()\n if (!e.currentTarget.contains(e.relatedTarget as Node)) {\n setIsDragActive(false)\n setIsDragOver(false)\n }\n }\n\n const handleDragOver = (e: React.DragEvent) => {\n e.preventDefault()\n e.stopPropagation()\n setIsDragOver(true)\n }\n\n const handleDrop = (e: React.DragEvent) => {\n e.preventDefault()\n e.stopPropagation()\n setIsDragActive(false)\n setIsDragOver(false)\n\n const files = Array.from(e.dataTransfer.files)\n if (files.length > 0) {\n onFile(files)\n }\n }\n\n return (\n <div\n className={`tiptap-image-upload-drag-area ${isDragActive ? \"drag-active\" : \"\"} ${isDragOver ? \"drag-over\" : \"\"}`}\n onDragEnter={handleDragEnter}\n onDragLeave={handleDragLeave}\n onDragOver={handleDragOver}\n onDrop={handleDrop}\n >\n {children}\n </div>\n )\n}\n\ninterface ImageUploadPreviewProps {\n /**\n * The file item to preview\n */\n fileItem: FileItem\n /**\n * Callback to remove this file from upload queue\n */\n onRemove: () => void\n}\n\n/**\n * Component that displays a preview of an uploading file with progress\n */\nconst ImageUploadPreview: React.FC<ImageUploadPreviewProps> = ({\n fileItem,\n onRemove,\n}) => {\n const formatFileSize = (bytes: number) => {\n if (bytes === 0) return \"0 Bytes\"\n const k = 1024\n const sizes = [\"Bytes\", \"KB\", \"MB\", \"GB\"]\n const i = Math.floor(Math.log(bytes) / Math.log(k))\n return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`\n }\n\n return (\n <div className=\"tiptap-image-upload-preview\">\n {fileItem.status === \"uploading\" && (\n <div\n className=\"tiptap-image-upload-progress\"\n style={{ width: `${fileItem.progress}%` }}\n />\n )}\n\n <div className=\"tiptap-image-upload-preview-content\">\n <div className=\"tiptap-image-upload-file-info\">\n <div className=\"tiptap-image-upload-file-icon\">\n <CloudUploadIcon />\n </div>\n <div className=\"tiptap-image-upload-details\">\n <span className=\"tiptap-image-upload-text\">\n {fileItem.file.name}\n </span>\n <span className=\"tiptap-image-upload-subtext\">\n {formatFileSize(fileItem.file.size)}\n </span>\n </div>\n </div>\n <div className=\"tiptap-image-upload-actions\">\n {fileItem.status === \"uploading\" && (\n <span className=\"tiptap-image-upload-progress-text\">\n {fileItem.progress}%\n </span>\n )}\n <Button\n type=\"button\"\n data-style=\"ghost\"\n onClick={(e) => {\n e.stopPropagation()\n onRemove()\n }}\n >\n <CloseIcon className=\"tiptap-button-icon\" />\n </Button>\n </div>\n </div>\n </div>\n )\n}\n\nconst DropZoneContent: React.FC<{ maxSize: number; limit: number }> = ({\n maxSize,\n limit,\n}) => (\n <>\n <div className=\"tiptap-image-upload-dropzone\">\n <FileIcon />\n <FileCornerIcon />\n <div className=\"tiptap-image-upload-icon-container\">\n <CloudUploadIcon />\n </div>\n </div>\n\n <div className=\"tiptap-image-upload-content\">\n <span className=\"tiptap-image-upload-text\">\n <em>Click to upload</em> or drag and drop\n </span>\n <span className=\"tiptap-image-upload-subtext\">\n Maximum {limit} file{limit === 1 ? \"\" : \"s\"}, {maxSize / 1024 / 1024}MB\n each.\n </span>\n </div>\n </>\n)\n\nexport const ImageUploadNode: React.FC<NodeViewProps> = (props) => {\n const { accept, limit, maxSize } = props.node.attrs\n const inputRef = React.useRef<HTMLInputElement>(null)\n const extension = props.extension\n\n const uploadOptions: UploadOptions = {\n maxSize,\n limit,\n accept,\n upload: extension.options.upload,\n onSuccess: extension.options.onSuccess,\n onError: extension.options.onError,\n }\n\n const { fileItems, uploadFiles, removeFileItem, clearAllFiles } =\n useFileUpload(uploadOptions)\n\n const handleUpload = async (files: File[]) => {\n const urls = await uploadFiles(files)\n\n if (urls.length > 0) {\n const pos = props.getPos()\n\n if (isValidPosition(pos)) {\n const imageNodes = urls.map((url, index) => {\n const filename =\n files[index]?.name.replace(/\\.[^/.]+$/, \"\") || \"unknown\"\n return {\n type: extension.options.type,\n attrs: {\n ...extension.options,\n src: url,\n alt: filename,\n title: filename,\n },\n }\n })\n\n props.editor\n .chain()\n .focus()\n .deleteRange({ from: pos, to: pos + props.node.nodeSize })\n .insertContentAt(pos, imageNodes)\n .run()\n\n focusNextNode(props.editor)\n }\n }\n }\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const files = e.target.files\n if (!files || files.length === 0) {\n extension.options.onError?.(new Error(\"No file selected\"))\n return\n }\n handleUpload(Array.from(files))\n }\n\n const handleClick = () => {\n if (inputRef.current && fileItems.length === 0) {\n inputRef.current.value = \"\"\n inputRef.current.click()\n }\n }\n\n const hasFiles = fileItems.length > 0\n\n return (\n <NodeViewWrapper\n className=\"tiptap-image-upload\"\n tabIndex={0}\n onClick={handleClick}\n >\n {!hasFiles && (\n <ImageUploadDragArea onFile={handleUpload}>\n <DropZoneContent maxSize={maxSize} limit={limit} />\n </ImageUploadDragArea>\n )}\n\n {hasFiles && (\n <div className=\"tiptap-image-upload-previews\">\n {fileItems.length > 1 && (\n <div className=\"tiptap-image-upload-header\">\n <span>Uploading {fileItems.length} files</span>\n <Button\n type=\"button\"\n data-style=\"ghost\"\n onClick={(e) => {\n e.stopPropagation()\n clearAllFiles()\n }}\n >\n Clear All\n </Button>\n </div>\n )}\n {fileItems.map((fileItem) => (\n <ImageUploadPreview\n key={fileItem.id}\n fileItem={fileItem}\n onRemove={() => removeFileItem(fileItem.id)}\n />\n ))}\n </div>\n )}\n\n <input\n ref={inputRef}\n name=\"file\"\n accept={accept}\n type=\"file\"\n multiple={limit > 1}\n onChange={handleChange}\n onClick={(e: React.MouseEvent<HTMLInputElement>) => e.stopPropagation()}\n />\n </NodeViewWrapper>\n )\n}\n","import { mergeAttributes, Node } from \"@tiptap/react\"\nimport { ReactNodeViewRenderer } from \"@tiptap/react\"\nimport { ImageUploadNode as ImageUploadNodeComponent } from \"@/components/tiptap-node/image-upload-node/image-upload-node\"\nimport type { NodeType } from \"@tiptap/pm/model\"\n\nexport type UploadFunction = (\n file: File,\n onProgress?: (event: { progress: number }) => void,\n abortSignal?: AbortSignal\n) => Promise<string>\n\nexport interface ImageUploadNodeOptions {\n /**\n * The type of the node.\n * @default 'image'\n */\n type?: string | NodeType | undefined\n /**\n * Acceptable file types for upload.\n * @default 'image/*'\n */\n accept?: string\n /**\n * Maximum number of files that can be uploaded.\n * @default 1\n */\n limit?: number\n /**\n * Maximum file size in bytes (0 for unlimited).\n * @default 0\n */\n maxSize?: number\n /**\n * Function to handle the upload process.\n */\n upload?: UploadFunction\n /**\n * Callback for upload errors.\n */\n onError?: (error: Error) => void\n /**\n * Callback for successful uploads.\n */\n onSuccess?: (url: string) => void\n /**\n * HTML attributes to add to the image element.\n * @default {}\n * @example { class: 'foo' }\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n HTMLAttributes: Record<string, any>\n}\n\ndeclare module \"@tiptap/react\" {\n interface Commands<ReturnType> {\n imageUpload: {\n setImageUploadNode: (options?: ImageUploadNodeOptions) => ReturnType\n }\n }\n}\n\n/**\n * A Tiptap node extension that creates an image upload component.\n * @see registry/tiptap-node/image-upload-node/image-upload-node\n */\nexport const ImageUploadNode = Node.create<ImageUploadNodeOptions>({\n name: \"imageUpload\",\n\n group: \"block\",\n\n draggable: true,\n\n atom: true,\n\n addOptions() {\n return {\n type: \"image\",\n accept: \"image/*\",\n limit: 1,\n maxSize: 0,\n upload: undefined,\n onError: undefined,\n onSuccess: undefined,\n HTMLAttributes: {},\n }\n },\n\n addAttributes() {\n return {\n accept: {\n default: this.options.accept,\n },\n limit: {\n default: this.options.limit,\n },\n maxSize: {\n default: this.options.maxSize,\n },\n }\n },\n\n parseHTML() {\n return [{ tag: 'div[data-type=\"image-upload\"]' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\n \"div\",\n mergeAttributes({ \"data-type\": \"image-upload\" }, HTMLAttributes),\n ]\n },\n\n addNodeView() {\n return ReactNodeViewRenderer(ImageUploadNodeComponent)\n },\n\n addCommands() {\n return {\n setImageUploadNode:\n (options) =>\n ({ commands }) => {\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n /**\n * Adds Enter key handler to trigger the upload component when it's selected.\n */\n addKeyboardShortcuts() {\n return {\n Enter: ({ editor }) => {\n const { selection } = editor.state\n const { nodeAfter } = selection.$from\n\n if (\n nodeAfter &&\n nodeAfter.type.name === \"imageUpload\" &&\n editor.isActive(\"imageUpload\")\n ) {\n const nodeEl = editor.view.nodeDOM(selection.$from.pos)\n if (nodeEl && nodeEl instanceof HTMLElement) {\n // Since NodeViewWrapper is wrapped with a div, we need to click the first child\n const firstChild = nodeEl.firstChild\n if (firstChild && firstChild instanceof HTMLElement) {\n firstChild.click()\n return true\n }\n }\n }\n return false\n },\n }\n },\n})\n\nexport default ImageUploadNode\n","import { mergeAttributes } from \"@tiptap/react\"\nimport TiptapHorizontalRule from \"@tiptap/extension-horizontal-rule\"\n\nexport const HorizontalRule = TiptapHorizontalRule.extend({\n renderHTML() {\n return [\n \"div\",\n mergeAttributes(this.options.HTMLAttributes, { \"data-type\": this.name }),\n [\"hr\"],\n ]\n },\n})\n\nexport default HorizontalRule\n","import * as React from \"react\"\n\nexport const ChevronDownIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M5.29289 8.29289C5.68342 7.90237 6.31658 7.90237 6.70711 8.29289L12 13.5858L17.2929 8.29289C17.6834 7.90237 18.3166 7.90237 18.7071 8.29289C19.0976 8.68342 19.0976 9.31658 18.7071 9.70711L12.7071 15.7071C12.3166 16.0976 11.6834 16.0976 11.2929 15.7071L5.29289 9.70711C4.90237 9.31658 4.90237 8.68342 5.29289 8.29289Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nChevronDownIcon.displayName = \"ChevronDownIcon\"\n","import * as React from \"react\"\nimport type { Editor } from \"@tiptap/react\"\nimport { useCurrentEditor, useEditorState } from \"@tiptap/react\"\n\n/**\n * Hook that provides access to a Tiptap editor instance.\n *\n * Accepts an optional editor instance directly, or falls back to retrieving\n * the editor from the Tiptap context if available. This allows components\n * to work both when given an editor directly and when used within a Tiptap\n * editor context.\n *\n * @param providedEditor - Optional editor instance to use instead of the context editor\n * @returns The provided editor or the editor from context, whichever is available\n */\nexport function useTiptapEditor(providedEditor?: Editor | null): {\n editor: Editor | null\n editorState?: Editor[\"state\"]\n canCommand?: Editor[\"can\"]\n} {\n const { editor: coreEditor } = useCurrentEditor()\n const mainEditor = React.useMemo(\n () => providedEditor || coreEditor,\n [providedEditor, coreEditor]\n )\n\n const editorState = useEditorState({\n editor: mainEditor,\n selector(context) {\n if (!context.editor) {\n return {\n editor: null,\n editorState: undefined,\n canCommand: undefined,\n }\n }\n\n return {\n editor: context.editor,\n editorState: context.editor.state,\n canCommand: context.editor.can,\n }\n },\n })\n\n return editorState || { editor: null }\n}\n","import * as React from \"react\"\nimport \"@/components/tiptap-ui-primitive/badge/badge-colors.scss\"\nimport \"@/components/tiptap-ui-primitive/badge/badge-group.scss\"\nimport \"@/components/tiptap-ui-primitive/badge/badge.scss\"\n\nexport interface BadgeProps extends React.HTMLAttributes<HTMLDivElement> {\n variant?: \"ghost\" | \"white\" | \"gray\" | \"green\" | \"default\"\n size?: \"default\" | \"small\"\n appearance?: \"default\" | \"subdued\" | \"emphasized\"\n trimText?: boolean\n}\n\nexport const Badge = React.forwardRef<HTMLDivElement, BadgeProps>(\n (\n {\n variant,\n size = \"default\",\n appearance = \"default\",\n trimText = false,\n className,\n children,\n ...props\n },\n ref\n ) => {\n return (\n <div\n ref={ref}\n className={`tiptap-badge ${className || \"\"}`}\n data-style={variant}\n data-size={size}\n data-appearance={appearance}\n data-text-trim={trimText ? \"on\" : \"off\"}\n {...props}\n >\n {children}\n </div>\n )\n }\n)\n\nBadge.displayName = \"Badge\"\n\nexport default Badge\n","import * as React from \"react\"\n\n// --- Lib ---\nimport { parseShortcutKeys } from \"@/lib/tiptap-utils\"\n\n// --- Tiptap UI ---\nimport type {\n Level,\n UseHeadingConfig,\n} from \"@/components/tiptap-ui/heading-button\"\nimport {\n HEADING_SHORTCUT_KEYS,\n useHeading,\n} from \"@/components/tiptap-ui/heading-button\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button } from \"@/components/tiptap-ui-primitive/button\"\nimport { Badge } from \"@/components/tiptap-ui-primitive/badge\"\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\nexport interface HeadingButtonProps\n extends Omit<ButtonProps, \"type\">,\n UseHeadingConfig {\n /**\n * Optional text to display alongside the icon.\n */\n text?: string\n /**\n * Optional show shortcut keys in the button.\n * @default false\n */\n showShortcut?: boolean\n}\n\nexport function HeadingShortcutBadge({\n level,\n shortcutKeys = HEADING_SHORTCUT_KEYS[level],\n}: {\n level: Level\n shortcutKeys?: string\n}) {\n return <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge>\n}\n\n/**\n * Button component for toggling heading in a Tiptap editor.\n *\n * For custom button implementations, use the `useHeading` hook instead.\n */\nexport const HeadingButton = React.forwardRef<\n HTMLButtonElement,\n HeadingButtonProps\n>(\n (\n {\n editor: providedEditor,\n level,\n text,\n hideWhenUnavailable = false,\n onToggled,\n showShortcut = false,\n onClick,\n children,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const {\n isVisible,\n canToggle,\n isActive,\n handleToggle,\n label,\n Icon,\n shortcutKeys,\n } = useHeading({\n editor,\n level,\n hideWhenUnavailable,\n onToggled,\n })\n\n const handleClick = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented) return\n handleToggle()\n },\n [handleToggle, onClick]\n )\n\n if (!isVisible) {\n return null\n }\n\n return (\n <Button\n type=\"button\"\n data-style=\"ghost\"\n data-active-state={isActive ? \"on\" : \"off\"}\n role=\"button\"\n tabIndex={-1}\n disabled={!canToggle}\n data-disabled={!canToggle}\n aria-label={label}\n aria-pressed={isActive}\n tooltip={label}\n onClick={handleClick}\n {...buttonProps}\n ref={ref}\n >\n {children ?? (\n <>\n <Icon className=\"tiptap-button-icon\" />\n {text && <span className=\"tiptap-button-text\">{text}</span>}\n {showShortcut && (\n <HeadingShortcutBadge level={level} shortcutKeys={shortcutKeys} />\n )}\n </>\n )}\n </Button>\n )\n }\n)\n\nHeadingButton.displayName = \"HeadingButton\"\n","import * as React from \"react\"\n\nexport const HeadingOneIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M5 6C5 5.44772 4.55228 5 4 5C3.44772 5 3 5.44772 3 6V18C3 18.5523 3.44772 19 4 19C4.55228 19 5 18.5523 5 18V13H11V18C11 18.5523 11.4477 19 12 19C12.5523 19 13 18.5523 13 18V6C13 5.44772 12.5523 5 12 5C11.4477 5 11 5.44772 11 6V11H5V6Z\"\n fill=\"currentColor\"\n />\n <path\n d=\"M21.0001 10C21.0001 9.63121 20.7971 9.29235 20.472 9.11833C20.1468 8.94431 19.7523 8.96338 19.4454 9.16795L16.4454 11.168C15.9859 11.4743 15.8617 12.0952 16.1681 12.5547C16.4744 13.0142 17.0953 13.1384 17.5548 12.8321L19.0001 11.8685V18C19.0001 18.5523 19.4478 19 20.0001 19C20.5524 19 21.0001 18.5523 21.0001 18V10Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nHeadingOneIcon.displayName = \"HeadingOneIcon\"\n","import * as React from \"react\"\n\nexport const HeadingTwoIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M5 6C5 5.44772 4.55228 5 4 5C3.44772 5 3 5.44772 3 6V18C3 18.5523 3.44772 19 4 19C4.55228 19 5 18.5523 5 18V13H11V18C11 18.5523 11.4477 19 12 19C12.5523 19 13 18.5523 13 18V6C13 5.44772 12.5523 5 12 5C11.4477 5 11 5.44772 11 6V11H5V6Z\"\n fill=\"currentColor\"\n />\n <path\n d=\"M22.0001 12C22.0001 10.7611 21.1663 9.79297 20.0663 9.42632C18.9547 9.05578 17.6171 9.28724 16.4001 10.2C15.9582 10.5314 15.8687 11.1582 16.2001 11.6C16.5314 12.0418 17.1582 12.1314 17.6001 11.8C18.383 11.2128 19.0455 11.1942 19.4338 11.3237C19.8339 11.457 20.0001 11.7389 20.0001 12C20.0001 12.4839 19.8554 12.7379 19.6537 12.9481C19.4275 13.1837 19.1378 13.363 18.7055 13.6307C18.6313 13.6767 18.553 13.7252 18.4701 13.777C17.9572 14.0975 17.3128 14.5261 16.8163 15.2087C16.3007 15.9177 16.0001 16.8183 16.0001 18C16.0001 18.5523 16.4478 19 17.0001 19H21.0001C21.5523 19 22.0001 18.5523 22.0001 18C22.0001 17.4477 21.5523 17 21.0001 17H18.131C18.21 16.742 18.3176 16.5448 18.4338 16.385C18.6873 16.0364 19.0429 15.7775 19.5301 15.473C19.5898 15.4357 19.6536 15.3966 19.7205 15.3556C20.139 15.0992 20.6783 14.7687 21.0964 14.3332C21.6447 13.7621 22.0001 13.0161 22.0001 12Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nHeadingTwoIcon.displayName = \"HeadingTwoIcon\"\n","import * as React from \"react\"\n\nexport const HeadingThreeIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M4 5C4.55228 5 5 5.44772 5 6V11H11V6C11 5.44772 11.4477 5 12 5C12.5523 5 13 5.44772 13 6V18C13 18.5523 12.5523 19 12 19C11.4477 19 11 18.5523 11 18V13H5V18C5 18.5523 4.55228 19 4 19C3.44772 19 3 18.5523 3 18V6C3 5.44772 3.44772 5 4 5Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M19.4608 11.2169C19.1135 11.0531 18.5876 11.0204 18.0069 11.3619C17.5309 11.642 16.918 11.4831 16.638 11.007C16.358 10.531 16.5169 9.91809 16.9929 9.63807C18.1123 8.97962 19.3364 8.94691 20.314 9.40808C21.2839 9.86558 21.9999 10.818 21.9999 12C21.9999 12.7957 21.6838 13.5587 21.1212 14.1213C20.5586 14.6839 19.7956 15 18.9999 15C18.4476 15 17.9999 14.5523 17.9999 14C17.9999 13.4477 18.4476 13 18.9999 13C19.2651 13 19.5195 12.8947 19.707 12.7071C19.8946 12.5196 19.9999 12.2652 19.9999 12C19.9999 11.6821 19.8159 11.3844 19.4608 11.2169Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M18.0001 14C18.0001 13.4477 18.4478 13 19.0001 13C19.7957 13 20.5588 13.3161 21.1214 13.8787C21.684 14.4413 22.0001 15.2043 22.0001 16C22.0001 17.2853 21.2767 18.3971 20.1604 18.8994C19.0257 19.41 17.642 19.2315 16.4001 18.3C15.9582 17.9686 15.8687 17.3418 16.2001 16.9C16.5314 16.4582 17.1582 16.3686 17.6001 16.7C18.3581 17.2685 18.9744 17.24 19.3397 17.0756C19.7234 16.9029 20.0001 16.5147 20.0001 16C20.0001 15.7348 19.8947 15.4804 19.7072 15.2929C19.5196 15.1054 19.2653 15 19.0001 15C18.4478 15 18.0001 14.5523 18.0001 14Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nHeadingThreeIcon.displayName = \"HeadingThreeIcon\"\n","import * as React from \"react\"\n\nexport const HeadingFourIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M4 5C4.55228 5 5 5.44772 5 6V11H11V6C11 5.44772 11.4477 5 12 5C12.5523 5 13 5.44772 13 6V18C13 18.5523 12.5523 19 12 19C11.4477 19 11 18.5523 11 18V13H5V18C5 18.5523 4.55228 19 4 19C3.44772 19 3 18.5523 3 18V6C3 5.44772 3.44772 5 4 5Z\"\n fill=\"currentColor\"\n />\n <path\n d=\"M17 9C17.5523 9 18 9.44772 18 10V13H20V10C20 9.44772 20.4477 9 21 9C21.5523 9 22 9.44772 22 10V18C22 18.5523 21.5523 19 21 19C20.4477 19 20 18.5523 20 18V15H17C16.4477 15 16 14.5523 16 14V10C16 9.44772 16.4477 9 17 9Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nHeadingFourIcon.displayName = \"HeadingFourIcon\"\n","import * as React from \"react\"\n\nexport const HeadingFiveIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M5 6C5 5.44772 4.55228 5 4 5C3.44772 5 3 5.44772 3 6V18C3 18.5523 3.44772 19 4 19C4.55228 19 5 18.5523 5 18V13H11V18C11 18.5523 11.4477 19 12 19C12.5523 19 13 18.5523 13 18V6C13 5.44772 12.5523 5 12 5C11.4477 5 11 5.44772 11 6V11H5V6Z\"\n fill=\"currentColor\"\n />\n <path\n d=\"M16 10C16 9.44772 16.4477 9 17 9H21C21.5523 9 22 9.44772 22 10C22 10.5523 21.5523 11 21 11H18V12H18.3C20.2754 12 22 13.4739 22 15.5C22 17.5261 20.2754 19 18.3 19C17.6457 19 17.0925 18.8643 16.5528 18.5944C16.0588 18.3474 15.8586 17.7468 16.1055 17.2528C16.3525 16.7588 16.9532 16.5586 17.4472 16.8056C17.7074 16.9357 17.9542 17 18.3 17C19.3246 17 20 16.2739 20 15.5C20 14.7261 19.3246 14 18.3 14H17C16.4477 14 16 13.5523 16 13L16 12.9928V10Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nHeadingFiveIcon.displayName = \"HeadingFiveIcon\"\n","import * as React from \"react\"\n\nexport const HeadingSixIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M5 6C5 5.44772 4.55228 5 4 5C3.44772 5 3 5.44772 3 6V18C3 18.5523 3.44772 19 4 19C4.55228 19 5 18.5523 5 18V13H11V18C11 18.5523 11.4477 19 12 19C12.5523 19 13 18.5523 13 18V6C13 5.44772 12.5523 5 12 5C11.4477 5 11 5.44772 11 6V11H5V6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M20.7071 9.29289C21.0976 9.68342 21.0976 10.3166 20.7071 10.7071C19.8392 11.575 19.2179 12.2949 18.7889 13.0073C18.8587 13.0025 18.929 13 19 13C20.6569 13 22 14.3431 22 16C22 17.6569 20.6569 19 19 19C17.3431 19 16 17.6569 16 16C16 14.6007 16.2837 13.4368 16.8676 12.3419C17.4384 11.2717 18.2728 10.3129 19.2929 9.29289C19.6834 8.90237 20.3166 8.90237 20.7071 9.29289ZM19 17C18.4477 17 18 16.5523 18 16C18 15.4477 18.4477 15 19 15C19.5523 15 20 15.4477 20 16C20 16.5523 19.5523 17 19 17Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nHeadingSixIcon.displayName = \"HeadingSixIcon\"\n","\"use client\"\n\nimport * as React from \"react\"\nimport { type Editor } from \"@tiptap/react\"\nimport { NodeSelection, TextSelection } from \"@tiptap/pm/state\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Lib ---\nimport {\n findNodePosition,\n isNodeInSchema,\n isNodeTypeSelected,\n isValidPosition,\n} from \"@/lib/tiptap-utils\"\n\n// --- Icons ---\nimport { HeadingOneIcon } from \"@/components/tiptap-icons/heading-one-icon\"\nimport { HeadingTwoIcon } from \"@/components/tiptap-icons/heading-two-icon\"\nimport { HeadingThreeIcon } from \"@/components/tiptap-icons/heading-three-icon\"\nimport { HeadingFourIcon } from \"@/components/tiptap-icons/heading-four-icon\"\nimport { HeadingFiveIcon } from \"@/components/tiptap-icons/heading-five-icon\"\nimport { HeadingSixIcon } from \"@/components/tiptap-icons/heading-six-icon\"\n\nexport type Level = 1 | 2 | 3 | 4 | 5 | 6\n\n/**\n * Configuration for the heading functionality\n */\nexport interface UseHeadingConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * The heading level.\n */\n level: Level\n /**\n * Whether the button should hide when heading is not available.\n * @default false\n */\n hideWhenUnavailable?: boolean\n /**\n * Callback function called after a successful heading toggle.\n */\n onToggled?: () => void\n}\n\nexport const headingIcons = {\n 1: HeadingOneIcon,\n 2: HeadingTwoIcon,\n 3: HeadingThreeIcon,\n 4: HeadingFourIcon,\n 5: HeadingFiveIcon,\n 6: HeadingSixIcon,\n}\n\nexport const HEADING_SHORTCUT_KEYS: Record<Level, string> = {\n 1: \"ctrl+alt+1\",\n 2: \"ctrl+alt+2\",\n 3: \"ctrl+alt+3\",\n 4: \"ctrl+alt+4\",\n 5: \"ctrl+alt+5\",\n 6: \"ctrl+alt+6\",\n}\n\n/**\n * Checks if heading can be toggled in the current editor state\n */\nexport function canToggle(\n editor: Editor | null,\n level?: Level,\n turnInto: boolean = true\n): boolean {\n if (!editor || !editor.isEditable) return false\n if (\n !isNodeInSchema(\"heading\", editor) ||\n isNodeTypeSelected(editor, [\"image\"])\n )\n return false\n\n if (!turnInto) {\n return level\n ? editor.can().setNode(\"heading\", { level })\n : editor.can().setNode(\"heading\")\n }\n\n try {\n const view = editor.view\n const state = view.state\n const selection = state.selection\n\n if (selection.empty || selection instanceof TextSelection) {\n const pos = findNodePosition({\n editor,\n node: state.selection.$anchor.node(1),\n })?.pos\n if (!isValidPosition(pos)) return false\n }\n\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Checks if heading is currently active\n */\nexport function isHeadingActive(\n editor: Editor | null,\n level?: Level | Level[]\n): boolean {\n if (!editor || !editor.isEditable) return false\n\n if (Array.isArray(level)) {\n return level.some((l) => editor.isActive(\"heading\", { level: l }))\n }\n\n return level\n ? editor.isActive(\"heading\", { level })\n : editor.isActive(\"heading\")\n}\n\n/**\n * Toggles heading in the editor\n */\nexport function toggleHeading(\n editor: Editor | null,\n level: Level | Level[]\n): boolean {\n if (!editor || !editor.isEditable) return false\n\n const levels = Array.isArray(level) ? level : [level]\n const toggleLevel = levels.find((l) => canToggle(editor, l))\n\n if (!toggleLevel) return false\n\n try {\n const view = editor.view\n let state = view.state\n let tr = state.tr\n\n // No selection, find the cursor position\n if (state.selection.empty || state.selection instanceof TextSelection) {\n const pos = findNodePosition({\n editor,\n node: state.selection.$anchor.node(1),\n })?.pos\n if (!isValidPosition(pos)) return false\n\n tr = tr.setSelection(NodeSelection.create(state.doc, pos))\n view.dispatch(tr)\n state = view.state\n }\n\n const selection = state.selection\n let chain = editor.chain().focus()\n\n // Handle NodeSelection\n if (selection instanceof NodeSelection) {\n const firstChild = selection.node.firstChild?.firstChild\n const lastChild = selection.node.lastChild?.lastChild\n\n const from = firstChild\n ? selection.from + firstChild.nodeSize\n : selection.from + 1\n\n const to = lastChild\n ? selection.to - lastChild.nodeSize\n : selection.to - 1\n\n chain = chain.setTextSelection({ from, to }).clearNodes()\n }\n\n const isActive = levels.some((l) =>\n editor.isActive(\"heading\", { level: l })\n )\n\n const toggle = isActive\n ? chain.setNode(\"paragraph\")\n : chain.setNode(\"heading\", { level: toggleLevel })\n\n toggle.run()\n\n editor.chain().focus().selectTextblockEnd().run()\n\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Determines if the heading button should be shown\n */\nexport function shouldShowButton(props: {\n editor: Editor | null\n level?: Level | Level[]\n hideWhenUnavailable: boolean\n}): boolean {\n const { editor, level, hideWhenUnavailable } = props\n\n if (!editor || !editor.isEditable) return false\n if (!isNodeInSchema(\"heading\", editor)) return false\n\n if (hideWhenUnavailable && !editor.isActive(\"code\")) {\n if (Array.isArray(level)) {\n return level.some((l) => canToggle(editor, l))\n }\n return canToggle(editor, level)\n }\n\n return true\n}\n\n/**\n * Custom hook that provides heading functionality for Tiptap editor\n *\n * @example\n * ```tsx\n * // Simple usage\n * function MySimpleHeadingButton() {\n * const { isVisible, isActive, handleToggle, Icon } = useHeading({ level: 1 })\n *\n * if (!isVisible) return null\n *\n * return (\n * <button\n * onClick={handleToggle}\n * aria-pressed={isActive}\n * >\n * <Icon />\n * Heading 1\n * </button>\n * )\n * }\n *\n * // Advanced usage with configuration\n * function MyAdvancedHeadingButton() {\n * const { isVisible, isActive, handleToggle, label, Icon } = useHeading({\n * level: 2,\n * editor: myEditor,\n * hideWhenUnavailable: true,\n * onToggled: (isActive) => console.log('Heading toggled:', isActive)\n * })\n *\n * if (!isVisible) return null\n *\n * return (\n * <MyButton\n * onClick={handleToggle}\n * aria-label={label}\n * aria-pressed={isActive}\n * >\n * <Icon />\n * Toggle Heading 2\n * </MyButton>\n * )\n * }\n * ```\n */\nexport function useHeading(config: UseHeadingConfig) {\n const {\n editor: providedEditor,\n level,\n hideWhenUnavailable = false,\n onToggled,\n } = config\n\n const { editor } = useTiptapEditor(providedEditor)\n const [isVisible, setIsVisible] = React.useState<boolean>(true)\n const canToggleState = canToggle(editor, level)\n const isActive = isHeadingActive(editor, level)\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleSelectionUpdate = () => {\n setIsVisible(shouldShowButton({ editor, level, hideWhenUnavailable }))\n }\n\n handleSelectionUpdate()\n\n editor.on(\"selectionUpdate\", handleSelectionUpdate)\n\n return () => {\n editor.off(\"selectionUpdate\", handleSelectionUpdate)\n }\n }, [editor, level, hideWhenUnavailable])\n\n const handleToggle = React.useCallback(() => {\n if (!editor) return false\n\n const success = toggleHeading(editor, level)\n if (success) {\n onToggled?.()\n }\n return success\n }, [editor, level, onToggled])\n\n return {\n isVisible,\n isActive,\n handleToggle,\n canToggle: canToggleState,\n label: `Heading ${level}`,\n shortcutKeys: HEADING_SHORTCUT_KEYS[level],\n Icon: headingIcons[level],\n }\n}\n","import * as React from \"react\"\nimport * as DropdownMenuPrimitive from \"@radix-ui/react-dropdown-menu\"\nimport { cn } from \"@/lib/tiptap-utils\"\nimport \"@/components/tiptap-ui-primitive/dropdown-menu/dropdown-menu.scss\"\n\nfunction DropdownMenu({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {\n return <DropdownMenuPrimitive.Root modal={false} {...props} />\n}\n\nfunction DropdownMenuPortal({\n ...props\n}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {\n return <DropdownMenuPrimitive.Portal {...props} />\n}\n\nconst DropdownMenuTrigger = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Trigger>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Trigger>\n>(({ ...props }, ref) => <DropdownMenuPrimitive.Trigger ref={ref} {...props} />)\nDropdownMenuTrigger.displayName = DropdownMenuPrimitive.Trigger.displayName\n\nconst DropdownMenuGroup = DropdownMenuPrimitive.Group\n\nconst DropdownMenuSub = DropdownMenuPrimitive.Sub\n\nconst DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup\n\nconst DropdownMenuItem = DropdownMenuPrimitive.Item\n\nconst DropdownMenuSubTrigger = DropdownMenuPrimitive.SubTrigger\n\nconst DropdownMenuSubContent = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.SubContent>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent> & {\n portal?: boolean | React.ComponentProps<typeof DropdownMenuPortal>\n }\n>(({ className, portal = true, ...props }, ref) => {\n const content = (\n <DropdownMenuPrimitive.SubContent\n ref={ref}\n className={cn(\"tiptap-dropdown-menu\", className)}\n {...props}\n />\n )\n\n return portal ? (\n <DropdownMenuPortal {...(typeof portal === \"object\" ? portal : {})}>\n {content}\n </DropdownMenuPortal>\n ) : (\n content\n )\n})\nDropdownMenuSubContent.displayName =\n DropdownMenuPrimitive.SubContent.displayName\n\nconst DropdownMenuContent = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Content>,\n React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content> & {\n portal?: boolean\n }\n>(({ className, sideOffset = 4, portal = false, ...props }, ref) => {\n const content = (\n <DropdownMenuPrimitive.Content\n ref={ref}\n sideOffset={sideOffset}\n onCloseAutoFocus={(e) => e.preventDefault()}\n className={cn(\"tiptap-dropdown-menu\", className)}\n {...props}\n />\n )\n\n return portal ? (\n <DropdownMenuPortal {...(typeof portal === \"object\" ? portal : {})}>\n {content}\n </DropdownMenuPortal>\n ) : (\n content\n )\n})\nDropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName\n\nexport {\n DropdownMenu,\n DropdownMenuTrigger,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuGroup,\n DropdownMenuSub,\n DropdownMenuPortal,\n DropdownMenuSubContent,\n DropdownMenuSubTrigger,\n DropdownMenuRadioGroup,\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { cn } from \"@/lib/tiptap-utils\"\nimport \"@/components/tiptap-ui-primitive/card/card.scss\"\n\nconst Card = React.forwardRef<HTMLDivElement, React.ComponentProps<\"div\">>(\n ({ className, ...props }, ref) => {\n return <div ref={ref} className={cn(\"tiptap-card\", className)} {...props} />\n }\n)\nCard.displayName = \"Card\"\n\nconst CardHeader = React.forwardRef<\n HTMLDivElement,\n React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => {\n return (\n <div ref={ref} className={cn(\"tiptap-card-header\", className)} {...props} />\n )\n})\nCardHeader.displayName = \"CardHeader\"\n\nconst CardBody = React.forwardRef<HTMLDivElement, React.ComponentProps<\"div\">>(\n ({ className, ...props }, ref) => {\n return (\n <div ref={ref} className={cn(\"tiptap-card-body\", className)} {...props} />\n )\n }\n)\nCardBody.displayName = \"CardBody\"\n\nconst CardItemGroup = React.forwardRef<\n HTMLDivElement,\n React.ComponentProps<\"div\"> & {\n orientation?: \"horizontal\" | \"vertical\"\n }\n>(({ className, orientation = \"vertical\", ...props }, ref) => {\n return (\n <div\n ref={ref}\n data-orientation={orientation}\n className={cn(\"tiptap-card-item-group\", className)}\n {...props}\n />\n )\n})\nCardItemGroup.displayName = \"CardItemGroup\"\n\nconst CardGroupLabel = React.forwardRef<\n HTMLDivElement,\n React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => {\n return (\n <div\n ref={ref}\n className={cn(\"tiptap-card-group-label\", className)}\n {...props}\n />\n )\n})\nCardGroupLabel.displayName = \"CardGroupLabel\"\n\nconst CardFooter = React.forwardRef<\n HTMLDivElement,\n React.ComponentProps<\"div\">\n>(({ className, ...props }, ref) => {\n return (\n <div ref={ref} className={cn(\"tiptap-card-footer\", className)} {...props} />\n )\n})\nCardFooter.displayName = \"CardFooter\"\n\nexport { Card, CardHeader, CardFooter, CardBody, CardItemGroup, CardGroupLabel }\n","import * as React from \"react\"\n\n// --- Icons ---\nimport { ChevronDownIcon } from \"@/components/tiptap-icons/chevron-down-icon\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Tiptap UI ---\nimport { HeadingButton } from \"@/components/tiptap-ui/heading-button\"\nimport type { UseHeadingDropdownMenuConfig } from \"@/components/tiptap-ui/heading-dropdown-menu\"\nimport { useHeadingDropdownMenu } from \"@/components/tiptap-ui/heading-dropdown-menu\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button, ButtonGroup } from \"@/components/tiptap-ui-primitive/button\"\nimport {\n DropdownMenu,\n DropdownMenuTrigger,\n DropdownMenuContent,\n DropdownMenuItem,\n} from \"@/components/tiptap-ui-primitive/dropdown-menu\"\nimport { Card, CardBody } from \"@/components/tiptap-ui-primitive/card\"\n\nexport interface HeadingDropdownMenuProps\n extends Omit<ButtonProps, \"type\">,\n UseHeadingDropdownMenuConfig {\n /**\n * Whether to render the dropdown menu in a portal\n * @default false\n */\n portal?: boolean\n /**\n * Callback for when the dropdown opens or closes\n */\n onOpenChange?: (isOpen: boolean) => void\n}\n\n/**\n * Dropdown menu component for selecting heading levels in a Tiptap editor.\n *\n * For custom dropdown implementations, use the `useHeadingDropdownMenu` hook instead.\n */\nexport const HeadingDropdownMenu = React.forwardRef<\n HTMLButtonElement,\n HeadingDropdownMenuProps\n>(\n (\n {\n editor: providedEditor,\n levels = [1, 2, 3, 4, 5, 6],\n hideWhenUnavailable = false,\n portal = false,\n onOpenChange,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const [isOpen, setIsOpen] = React.useState(false)\n const { isVisible, isActive, canToggle, Icon } = useHeadingDropdownMenu({\n editor,\n levels,\n hideWhenUnavailable,\n })\n\n const handleOpenChange = React.useCallback(\n (open: boolean) => {\n if (!editor || !canToggle) return\n setIsOpen(open)\n onOpenChange?.(open)\n },\n [canToggle, editor, onOpenChange]\n )\n\n if (!isVisible) {\n return null\n }\n\n return (\n <DropdownMenu modal open={isOpen} onOpenChange={handleOpenChange}>\n <DropdownMenuTrigger asChild>\n <Button\n type=\"button\"\n data-style=\"ghost\"\n data-active-state={isActive ? \"on\" : \"off\"}\n role=\"button\"\n tabIndex={-1}\n disabled={!canToggle}\n data-disabled={!canToggle}\n aria-label=\"Format text as heading\"\n aria-pressed={isActive}\n tooltip=\"Heading\"\n {...buttonProps}\n ref={ref}\n >\n <Icon className=\"tiptap-button-icon\" />\n <ChevronDownIcon className=\"tiptap-button-dropdown-small\" />\n </Button>\n </DropdownMenuTrigger>\n\n <DropdownMenuContent align=\"start\" portal={portal}>\n <Card>\n <CardBody>\n <ButtonGroup>\n {levels.map((level) => (\n <DropdownMenuItem key={`heading-${level}`} asChild>\n <HeadingButton\n editor={editor}\n level={level}\n text={`Heading ${level}`}\n showTooltip={false}\n />\n </DropdownMenuItem>\n ))}\n </ButtonGroup>\n </CardBody>\n </Card>\n </DropdownMenuContent>\n </DropdownMenu>\n )\n }\n)\n\nHeadingDropdownMenu.displayName = \"HeadingDropdownMenu\"\n\nexport default HeadingDropdownMenu\n","import * as React from \"react\"\n\nexport const HeadingIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M6 3C6.55228 3 7 3.44772 7 4V11H17V4C17 3.44772 17.4477 3 18 3C18.5523 3 19 3.44772 19 4V20C19 20.5523 18.5523 21 18 21C17.4477 21 17 20.5523 17 20V13H7V20C7 20.5523 6.55228 21 6 21C5.44772 21 5 20.5523 5 20V4C5 3.44772 5.44772 3 6 3Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nHeadingIcon.displayName = \"HeadingIcon\"\n","\"use client\"\n\nimport * as React from \"react\"\nimport type { Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Icons ---\nimport { HeadingIcon } from \"@/components/tiptap-icons/heading-icon\"\n\n// --- Tiptap UI ---\nimport {\n headingIcons,\n type Level,\n isHeadingActive,\n canToggle,\n shouldShowButton,\n} from \"@/components/tiptap-ui/heading-button\"\n\n/**\n * Configuration for the heading dropdown menu functionality\n */\nexport interface UseHeadingDropdownMenuConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * Available heading levels to show in the dropdown\n * @default [1, 2, 3, 4, 5, 6]\n */\n levels?: Level[]\n /**\n * Whether the dropdown should hide when headings are not available.\n * @default false\n */\n hideWhenUnavailable?: boolean\n}\n\n/**\n * Gets the currently active heading level from the available levels\n */\nexport function getActiveHeadingLevel(\n editor: Editor | null,\n levels: Level[] = [1, 2, 3, 4, 5, 6]\n): Level | undefined {\n if (!editor || !editor.isEditable) return undefined\n return levels.find((level) => isHeadingActive(editor, level))\n}\n\n/**\n * Custom hook that provides heading dropdown menu functionality for Tiptap editor\n *\n * @example\n * ```tsx\n * // Simple usage\n * function MyHeadingDropdown() {\n * const {\n * isVisible,\n * activeLevel,\n * isAnyHeadingActive,\n * canToggle,\n * levels,\n * } = useHeadingDropdownMenu()\n *\n * if (!isVisible) return null\n *\n * return (\n * <DropdownMenu>\n * // dropdown content\n * </DropdownMenu>\n * )\n * }\n *\n * // Advanced usage with configuration\n * function MyAdvancedHeadingDropdown() {\n * const {\n * isVisible,\n * activeLevel,\n * } = useHeadingDropdownMenu({\n * editor: myEditor,\n * levels: [1, 2, 3],\n * hideWhenUnavailable: true,\n * })\n *\n * // component implementation\n * }\n * ```\n */\nexport function useHeadingDropdownMenu(config?: UseHeadingDropdownMenuConfig) {\n const {\n editor: providedEditor,\n levels = [1, 2, 3, 4, 5, 6],\n hideWhenUnavailable = false,\n } = config || {}\n\n const { editor } = useTiptapEditor(providedEditor)\n const [isVisible, setIsVisible] = React.useState(true)\n\n const activeLevel = getActiveHeadingLevel(editor, levels)\n const isActive = isHeadingActive(editor)\n const canToggleState = canToggle(editor)\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleSelectionUpdate = () => {\n setIsVisible(\n shouldShowButton({ editor, hideWhenUnavailable, level: levels })\n )\n }\n\n handleSelectionUpdate()\n\n editor.on(\"selectionUpdate\", handleSelectionUpdate)\n\n return () => {\n editor.off(\"selectionUpdate\", handleSelectionUpdate)\n }\n }, [editor, hideWhenUnavailable, levels])\n\n return {\n isVisible,\n activeLevel,\n isActive,\n canToggle: canToggleState,\n levels,\n label: \"Heading\",\n Icon: activeLevel ? headingIcons[activeLevel] : HeadingIcon,\n }\n}\n","import * as React from \"react\"\n\n// --- Lib ---\nimport { parseShortcutKeys } from \"@/lib/tiptap-utils\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Tiptap UI ---\nimport type { UseImageUploadConfig } from \"@/components/tiptap-ui/image-upload-button\"\nimport {\n IMAGE_UPLOAD_SHORTCUT_KEY,\n useImageUpload,\n} from \"@/components/tiptap-ui/image-upload-button\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button } from \"@/components/tiptap-ui-primitive/button\"\nimport { Badge } from \"@/components/tiptap-ui-primitive/badge\"\n\nexport interface ImageUploadButtonProps\n extends Omit<ButtonProps, \"type\">,\n UseImageUploadConfig {\n /**\n * Optional text to display alongside the icon.\n */\n text?: string\n /**\n * Optional show shortcut keys in the button.\n * @default false\n */\n showShortcut?: boolean\n}\n\nexport function ImageShortcutBadge({\n shortcutKeys = IMAGE_UPLOAD_SHORTCUT_KEY,\n}: {\n shortcutKeys?: string\n}) {\n return <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge>\n}\n\n/**\n * Button component for uploading/inserting images in a Tiptap editor.\n *\n * For custom button implementations, use the `useImage` hook instead.\n */\nexport const ImageUploadButton = React.forwardRef<\n HTMLButtonElement,\n ImageUploadButtonProps\n>(\n (\n {\n editor: providedEditor,\n text,\n hideWhenUnavailable = false,\n onInserted,\n showShortcut = false,\n onClick,\n children,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const {\n isVisible,\n canInsert,\n handleImage,\n label,\n isActive,\n shortcutKeys,\n Icon,\n } = useImageUpload({\n editor,\n hideWhenUnavailable,\n onInserted,\n })\n\n const handleClick = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented) return\n handleImage()\n },\n [handleImage, onClick]\n )\n\n if (!isVisible) {\n return null\n }\n\n return (\n <Button\n type=\"button\"\n data-style=\"ghost\"\n data-active-state={isActive ? \"on\" : \"off\"}\n role=\"button\"\n tabIndex={-1}\n disabled={!canInsert}\n data-disabled={!canInsert}\n aria-label={label}\n aria-pressed={isActive}\n tooltip={label}\n onClick={handleClick}\n {...buttonProps}\n ref={ref}\n >\n {children ?? (\n <>\n <Icon className=\"tiptap-button-icon\" />\n {text && <span className=\"tiptap-button-text\">{text}</span>}\n {showShortcut && <ImageShortcutBadge shortcutKeys={shortcutKeys} />}\n </>\n )}\n </Button>\n )\n }\n)\n\nImageUploadButton.displayName = \"ImageUploadButton\"\n","import * as React from \"react\"\n\nexport function useIsMobile(breakpoint = 768) {\n const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)\n\n React.useEffect(() => {\n const mql = window.matchMedia(`(max-width: ${breakpoint - 1}px)`)\n const onChange = () => {\n setIsMobile(window.innerWidth < breakpoint)\n }\n mql.addEventListener(\"change\", onChange)\n setIsMobile(window.innerWidth < breakpoint)\n return () => mql.removeEventListener(\"change\", onChange)\n }, [breakpoint])\n\n return !!isMobile\n}\n","import * as React from \"react\"\n\nexport const ImagePlusIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M20 2C20 1.44772 19.5523 1 19 1C18.4477 1 18 1.44772 18 2V4H16C15.4477 4 15 4.44772 15 5C15 5.55228 15.4477 6 16 6H18V8C18 8.55228 18.4477 9 19 9C19.5523 9 20 8.55228 20 8V6H22C22.5523 6 23 5.55228 23 5C23 4.44772 22.5523 4 22 4H20V2ZM5 4C4.73478 4 4.48043 4.10536 4.29289 4.29289C4.10536 4.48043 4 4.73478 4 5V19C4 19.2652 4.10536 19.5196 4.29289 19.7071C4.48043 19.8946 4.73478 20 5 20H5.58579L14.379 11.2068C14.9416 10.6444 15.7045 10.3284 16.5 10.3284C17.2955 10.3284 18.0584 10.6444 18.621 11.2068L20 12.5858V12C20 11.4477 20.4477 11 21 11C21.5523 11 22 11.4477 22 12V14.998C22 14.9994 22 15.0007 22 15.002V19C22 19.7957 21.6839 20.5587 21.1213 21.1213C20.5587 21.6839 19.7957 22 19 22H6.00219C6.00073 22 5.99927 22 5.99781 22H5C4.20435 22 3.44129 21.6839 2.87868 21.1213C2.31607 20.5587 2 19.7957 2 19V5C2 4.20435 2.31607 3.44129 2.87868 2.87868C3.44129 2.31607 4.20435 2 5 2H12C12.5523 2 13 2.44772 13 3C13 3.55228 12.5523 4 12 4H5ZM8.41422 20H19C19.2652 20 19.5196 19.8946 19.7071 19.7071C19.8946 19.5196 20 19.2652 20 19V15.4142L17.207 12.6212C17.0195 12.4338 16.7651 12.3284 16.5 12.3284C16.2349 12.3284 15.9806 12.4337 15.7931 12.6211L8.41422 20ZM6.87868 6.87868C7.44129 6.31607 8.20435 6 9 6C9.79565 6 10.5587 6.31607 11.1213 6.87868C11.6839 7.44129 12 8.20435 12 9C12 9.79565 11.6839 10.5587 11.1213 11.1213C10.5587 11.6839 9.79565 12 9 12C8.20435 12 7.44129 11.6839 6.87868 11.1213C6.31607 10.5587 6 9.79565 6 9C6 8.20435 6.31607 7.44129 6.87868 6.87868ZM9 8C8.73478 8 8.48043 8.10536 8.29289 8.29289C8.10536 8.48043 8 8.73478 8 9C8 9.26522 8.10536 9.51957 8.29289 9.70711C8.48043 9.89464 8.73478 10 9 10C9.26522 10 9.51957 9.89464 9.70711 9.70711C9.89464 9.51957 10 9.26522 10 9C10 8.73478 9.89464 8.48043 9.70711 8.29289C9.51957 8.10536 9.26522 8 9 8Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nImagePlusIcon.displayName = \"ImagePlusIcon\"\n","\"use client\"\n\nimport * as React from \"react\"\nimport { useHotkeys } from \"react-hotkeys-hook\"\nimport { type Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\nimport { useIsMobile } from \"@/hooks/use-mobile\"\n\n// --- Lib ---\nimport {\n isExtensionAvailable,\n isNodeTypeSelected,\n} from \"@/lib/tiptap-utils\"\n\n// --- Icons ---\nimport { ImagePlusIcon } from \"@/components/tiptap-icons/image-plus-icon\"\n\nexport const IMAGE_UPLOAD_SHORTCUT_KEY = \"mod+shift+i\"\n\n/**\n * Configuration for the image upload functionality\n */\nexport interface UseImageUploadConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * Whether the button should hide when insertion is not available.\n * @default false\n */\n hideWhenUnavailable?: boolean\n /**\n * Callback function called after a successful image insertion.\n */\n onInserted?: () => void\n}\n\n/**\n * Checks if image can be inserted in the current editor state\n */\nexport function canInsertImage(editor: Editor | null): boolean {\n if (!editor || !editor.isEditable) return false\n if (\n !isExtensionAvailable(editor, \"imageUpload\") ||\n isNodeTypeSelected(editor, [\"image\"])\n )\n return false\n\n return editor.can().insertContent({ type: \"imageUpload\" })\n}\n\n/**\n * Checks if image is currently active\n */\nexport function isImageActive(editor: Editor | null): boolean {\n if (!editor || !editor.isEditable) return false\n return editor.isActive(\"imageUpload\")\n}\n\n/**\n * Inserts an image in the editor\n */\nexport function insertImage(editor: Editor | null): boolean {\n if (!editor || !editor.isEditable) return false\n if (!canInsertImage(editor)) return false\n\n try {\n return editor\n .chain()\n .focus()\n .insertContent({\n type: \"imageUpload\",\n })\n .run()\n } catch {\n return false\n }\n}\n\n/**\n * Determines if the image button should be shown\n */\nexport function shouldShowButton(props: {\n editor: Editor | null\n hideWhenUnavailable: boolean\n}): boolean {\n const { editor, hideWhenUnavailable } = props\n\n if (!editor || !editor.isEditable) return false\n if (!isExtensionAvailable(editor, \"imageUpload\")) return false\n\n if (hideWhenUnavailable && !editor.isActive(\"code\")) {\n return canInsertImage(editor)\n }\n\n return true\n}\n\n/**\n * Custom hook that provides image functionality for Tiptap editor\n *\n * @example\n * ```tsx\n * // Simple usage - no params needed\n * function MySimpleImageButton() {\n * const { isVisible, handleImage } = useImage()\n *\n * if (!isVisible) return null\n *\n * return <button onClick={handleImage}>Add Image</button>\n * }\n *\n * // Advanced usage with configuration\n * function MyAdvancedImageButton() {\n * const { isVisible, handleImage, label, isActive } = useImage({\n * editor: myEditor,\n * hideWhenUnavailable: true,\n * onInserted: () => console.log('Image inserted!')\n * })\n *\n * if (!isVisible) return null\n *\n * return (\n * <MyButton\n * onClick={handleImage}\n * aria-pressed={isActive}\n * aria-label={label}\n * >\n * Add Image\n * </MyButton>\n * )\n * }\n * ```\n */\nexport function useImageUpload(config?: UseImageUploadConfig) {\n const {\n editor: providedEditor,\n hideWhenUnavailable = false,\n onInserted,\n } = config || {}\n\n const { editor } = useTiptapEditor(providedEditor)\n const isMobile = useIsMobile()\n const [isVisible, setIsVisible] = React.useState<boolean>(true)\n const canInsert = canInsertImage(editor)\n const isActive = isImageActive(editor)\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleSelectionUpdate = () => {\n setIsVisible(shouldShowButton({ editor, hideWhenUnavailable }))\n }\n\n handleSelectionUpdate()\n\n editor.on(\"selectionUpdate\", handleSelectionUpdate)\n\n return () => {\n editor.off(\"selectionUpdate\", handleSelectionUpdate)\n }\n }, [editor, hideWhenUnavailable])\n\n const handleImage = React.useCallback(() => {\n if (!editor) return false\n\n const success = insertImage(editor)\n if (success) {\n onInserted?.()\n }\n return success\n }, [editor, onInserted])\n\n useHotkeys(\n IMAGE_UPLOAD_SHORTCUT_KEY,\n (event) => {\n event.preventDefault()\n handleImage()\n },\n {\n enabled: isVisible && canInsert,\n enableOnContentEditable: !isMobile,\n enableOnFormTags: true,\n }\n )\n\n return {\n isVisible,\n isActive,\n handleImage,\n canInsert,\n label: \"Add image\",\n shortcutKeys: IMAGE_UPLOAD_SHORTCUT_KEY,\n Icon: ImagePlusIcon,\n }\n}\n","import * as React from \"react\"\n\n// --- Lib ---\nimport { parseShortcutKeys } from \"@/lib/tiptap-utils\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button } from \"@/components/tiptap-ui-primitive/button\"\nimport { Badge } from \"@/components/tiptap-ui-primitive/badge\"\n\n// --- Tiptap UI ---\nimport type { ListType, UseListConfig } from \"@/components/tiptap-ui/list-button\"\nimport { LIST_SHORTCUT_KEYS, useList } from \"@/components/tiptap-ui/list-button\"\n\nexport interface ListButtonProps\n extends Omit<ButtonProps, \"type\">,\n UseListConfig {\n /**\n * Optional text to display alongside the icon.\n */\n text?: string\n /**\n * Optional show shortcut keys in the button.\n * @default false\n */\n showShortcut?: boolean\n}\n\nexport function ListShortcutBadge({\n type,\n shortcutKeys = LIST_SHORTCUT_KEYS[type],\n}: {\n type: ListType\n shortcutKeys?: string\n}) {\n return <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge>\n}\n\n/**\n * Button component for toggling lists in a Tiptap editor.\n *\n * For custom button implementations, use the `useList` hook instead.\n */\nexport const ListButton = React.forwardRef<HTMLButtonElement, ListButtonProps>(\n (\n {\n editor: providedEditor,\n type,\n text,\n hideWhenUnavailable = false,\n onToggled,\n showShortcut = false,\n onClick,\n children,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const {\n isVisible,\n canToggle,\n isActive,\n handleToggle,\n label,\n shortcutKeys,\n Icon,\n } = useList({\n editor,\n type,\n hideWhenUnavailable,\n onToggled,\n })\n\n const handleClick = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented) return\n handleToggle()\n },\n [handleToggle, onClick]\n )\n\n if (!isVisible) {\n return null\n }\n\n return (\n <Button\n type=\"button\"\n data-style=\"ghost\"\n data-active-state={isActive ? \"on\" : \"off\"}\n role=\"button\"\n tabIndex={-1}\n disabled={!canToggle}\n data-disabled={!canToggle}\n aria-label={label}\n aria-pressed={isActive}\n tooltip={label}\n onClick={handleClick}\n {...buttonProps}\n ref={ref}\n >\n {children ?? (\n <>\n <Icon className=\"tiptap-button-icon\" />\n {text && <span className=\"tiptap-button-text\">{text}</span>}\n {showShortcut && (\n <ListShortcutBadge type={type} shortcutKeys={shortcutKeys} />\n )}\n </>\n )}\n </Button>\n )\n }\n)\n\nListButton.displayName = \"ListButton\"\n","import * as React from \"react\"\n\nexport const ListIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M7 6C7 5.44772 7.44772 5 8 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H8C7.44772 7 7 6.55228 7 6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M7 12C7 11.4477 7.44772 11 8 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H8C7.44772 13 7 12.5523 7 12Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M7 18C7 17.4477 7.44772 17 8 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H8C7.44772 19 7 18.5523 7 18Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 6C2 5.44772 2.44772 5 3 5H3.01C3.56228 5 4.01 5.44772 4.01 6C4.01 6.55228 3.56228 7 3.01 7H3C2.44772 7 2 6.55228 2 6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 12C2 11.4477 2.44772 11 3 11H3.01C3.56228 11 4.01 11.4477 4.01 12C4.01 12.5523 3.56228 13 3.01 13H3C2.44772 13 2 12.5523 2 12Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 18C2 17.4477 2.44772 17 3 17H3.01C3.56228 17 4.01 17.4477 4.01 18C4.01 18.5523 3.56228 19 3.01 19H3C2.44772 19 2 18.5523 2 18Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nListIcon.displayName = \"ListIcon\"\n","import * as React from \"react\"\n\nexport const ListOrderedIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M9 6C9 5.44772 9.44772 5 10 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H10C9.44772 7 9 6.55228 9 6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M9 12C9 11.4477 9.44772 11 10 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H10C9.44772 13 9 12.5523 9 12Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M9 18C9 17.4477 9.44772 17 10 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H10C9.44772 19 9 18.5523 9 18Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M3 6C3 5.44772 3.44772 5 4 5H5C5.55228 5 6 5.44772 6 6V10C6 10.5523 5.55228 11 5 11C4.44772 11 4 10.5523 4 10V7C3.44772 7 3 6.55228 3 6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M3 10C3 9.44772 3.44772 9 4 9H6C6.55228 9 7 9.44772 7 10C7 10.5523 6.55228 11 6 11H4C3.44772 11 3 10.5523 3 10Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M5.82219 13.0431C6.54543 13.4047 6.99997 14.1319 6.99997 15C6.99997 15.5763 6.71806 16.0426 6.48747 16.35C6.31395 16.5814 6.1052 16.8044 5.91309 17H5.99997C6.55226 17 6.99997 17.4477 6.99997 18C6.99997 18.5523 6.55226 19 5.99997 19H3.99997C3.44769 19 2.99997 18.5523 2.99997 18C2.99997 17.4237 3.28189 16.9575 3.51247 16.65C3.74323 16.3424 4.03626 16.0494 4.26965 15.8161C4.27745 15.8083 4.2852 15.8006 4.29287 15.7929C4.55594 15.5298 4.75095 15.3321 4.88748 15.15C4.96287 15.0495 4.99021 14.9922 4.99911 14.9714C4.99535 14.9112 4.9803 14.882 4.9739 14.8715C4.96613 14.8588 4.95382 14.845 4.92776 14.8319C4.87723 14.8067 4.71156 14.7623 4.44719 14.8944C3.95321 15.1414 3.35254 14.9412 3.10555 14.4472C2.85856 13.9533 3.05878 13.3526 3.55276 13.1056C4.28839 12.7378 5.12272 12.6934 5.82219 13.0431Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nListOrderedIcon.displayName = \"ListOrderedIcon\"\n","import * as React from \"react\"\n\nexport const ListTodoIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 6C2 4.89543 2.89543 4 4 4H8C9.10457 4 10 4.89543 10 6V10C10 11.1046 9.10457 12 8 12H4C2.89543 12 2 11.1046 2 10V6ZM8 6H4V10H8V6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M9.70711 14.2929C10.0976 14.6834 10.0976 15.3166 9.70711 15.7071L5.70711 19.7071C5.31658 20.0976 4.68342 20.0976 4.29289 19.7071L2.29289 17.7071C1.90237 17.3166 1.90237 16.6834 2.29289 16.2929C2.68342 15.9024 3.31658 15.9024 3.70711 16.2929L5 17.5858L8.29289 14.2929C8.68342 13.9024 9.31658 13.9024 9.70711 14.2929Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M12 6C12 5.44772 12.4477 5 13 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H13C12.4477 7 12 6.55228 12 6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M12 12C12 11.4477 12.4477 11 13 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H13C12.4477 13 12 12.5523 12 12Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M12 18C12 17.4477 12.4477 17 13 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H13C12.4477 19 12 18.5523 12 18Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nListTodoIcon.displayName = \"ListTodoIcon\"\n","\"use client\"\n\nimport * as React from \"react\"\nimport { type Editor } from \"@tiptap/react\"\nimport { NodeSelection, TextSelection } from \"@tiptap/pm/state\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Icons ---\nimport { ListIcon } from \"@/components/tiptap-icons/list-icon\"\nimport { ListOrderedIcon } from \"@/components/tiptap-icons/list-ordered-icon\"\nimport { ListTodoIcon } from \"@/components/tiptap-icons/list-todo-icon\"\n\n// --- Lib ---\nimport {\n findNodePosition,\n isNodeInSchema,\n isNodeTypeSelected,\n isValidPosition,\n} from \"@/lib/tiptap-utils\"\n\nexport type ListType = \"bulletList\" | \"orderedList\" | \"taskList\"\n\n/**\n * Configuration for the list functionality\n */\nexport interface UseListConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * The type of list to toggle.\n */\n type: ListType\n /**\n * Whether the button should hide when list is not available.\n * @default false\n */\n hideWhenUnavailable?: boolean\n /**\n * Callback function called after a successful toggle.\n */\n onToggled?: () => void\n}\n\nexport const listIcons = {\n bulletList: ListIcon,\n orderedList: ListOrderedIcon,\n taskList: ListTodoIcon,\n}\n\nexport const listLabels: Record<ListType, string> = {\n bulletList: \"Bullet List\",\n orderedList: \"Ordered List\",\n taskList: \"Task List\",\n}\n\nexport const LIST_SHORTCUT_KEYS: Record<ListType, string> = {\n bulletList: \"mod+shift+8\",\n orderedList: \"mod+shift+7\",\n taskList: \"mod+shift+9\",\n}\n\n/**\n * Checks if a list can be toggled in the current editor state\n */\nexport function canToggleList(\n editor: Editor | null,\n type: ListType,\n turnInto: boolean = true\n): boolean {\n if (!editor || !editor.isEditable) return false\n if (!isNodeInSchema(type, editor) || isNodeTypeSelected(editor, [\"image\"]))\n return false\n\n if (!turnInto) {\n switch (type) {\n case \"bulletList\":\n return editor.can().toggleBulletList()\n case \"orderedList\":\n return editor.can().toggleOrderedList()\n case \"taskList\":\n return editor.can().toggleList(\"taskList\", \"taskItem\")\n default:\n return false\n }\n }\n\n try {\n const view = editor.view\n const state = view.state\n const selection = state.selection\n\n if (selection.empty || selection instanceof TextSelection) {\n const pos = findNodePosition({\n editor,\n node: state.selection.$anchor.node(1),\n })?.pos\n if (!isValidPosition(pos)) return false\n }\n\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Checks if list is currently active\n */\nexport function isListActive(editor: Editor | null, type: ListType): boolean {\n if (!editor || !editor.isEditable) return false\n\n switch (type) {\n case \"bulletList\":\n return editor.isActive(\"bulletList\")\n case \"orderedList\":\n return editor.isActive(\"orderedList\")\n case \"taskList\":\n return editor.isActive(\"taskList\")\n default:\n return false\n }\n}\n\n/**\n * Toggles list in the editor\n */\nexport function toggleList(editor: Editor | null, type: ListType): boolean {\n if (!editor || !editor.isEditable) return false\n if (!canToggleList(editor, type)) return false\n\n try {\n const view = editor.view\n let state = view.state\n let tr = state.tr\n\n // No selection, find the the cursor position\n if (state.selection.empty || state.selection instanceof TextSelection) {\n const pos = findNodePosition({\n editor,\n node: state.selection.$anchor.node(1),\n })?.pos\n if (!isValidPosition(pos)) return false\n\n tr = tr.setSelection(NodeSelection.create(state.doc, pos))\n view.dispatch(tr)\n state = view.state\n }\n\n const selection = state.selection\n\n let chain = editor.chain().focus()\n\n // Handle NodeSelection\n if (selection instanceof NodeSelection) {\n const firstChild = selection.node.firstChild?.firstChild\n const lastChild = selection.node.lastChild?.lastChild\n\n const from = firstChild\n ? selection.from + firstChild.nodeSize\n : selection.from + 1\n\n const to = lastChild\n ? selection.to - lastChild.nodeSize\n : selection.to - 1\n\n chain = chain.setTextSelection({ from, to }).clearNodes()\n }\n\n if (editor.isActive(type)) {\n // Unwrap list\n chain\n .liftListItem(\"listItem\")\n .lift(\"bulletList\")\n .lift(\"orderedList\")\n .lift(\"taskList\")\n .run()\n } else {\n // Wrap in specific list type\n const toggleMap: Record<ListType, () => typeof chain> = {\n bulletList: () => chain.toggleBulletList(),\n orderedList: () => chain.toggleOrderedList(),\n taskList: () => chain.toggleList(\"taskList\", \"taskItem\"),\n }\n\n const toggle = toggleMap[type]\n if (!toggle) return false\n\n toggle().run()\n }\n\n editor.chain().focus().selectTextblockEnd().run()\n\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Determines if the list button should be shown\n */\nexport function shouldShowButton(props: {\n editor: Editor | null\n type: ListType\n hideWhenUnavailable: boolean\n}): boolean {\n const { editor, type, hideWhenUnavailable } = props\n\n if (!editor || !editor.isEditable) return false\n if (!isNodeInSchema(type, editor)) return false\n\n if (hideWhenUnavailable && !editor.isActive(\"code\")) {\n return canToggleList(editor, type)\n }\n\n return true\n}\n\n/**\n * Custom hook that provides list functionality for Tiptap editor\n *\n * @example\n * ```tsx\n * // Simple usage\n * function MySimpleListButton() {\n * const { isVisible, handleToggle, isActive } = useList({ type: \"bulletList\" })\n *\n * if (!isVisible) return null\n *\n * return <button onClick={handleToggle}>Bullet List</button>\n * }\n *\n * // Advanced usage with configuration\n * function MyAdvancedListButton() {\n * const { isVisible, handleToggle, label, isActive } = useList({\n * type: \"orderedList\",\n * editor: myEditor,\n * hideWhenUnavailable: true,\n * onToggled: () => console.log('List toggled!')\n * })\n *\n * if (!isVisible) return null\n *\n * return (\n * <MyButton\n * onClick={handleToggle}\n * aria-label={label}\n * aria-pressed={isActive}\n * >\n * Toggle List\n * </MyButton>\n * )\n * }\n * ```\n */\nexport function useList(config: UseListConfig) {\n const {\n editor: providedEditor,\n type,\n hideWhenUnavailable = false,\n onToggled,\n } = config\n\n const { editor } = useTiptapEditor(providedEditor)\n const [isVisible, setIsVisible] = React.useState<boolean>(true)\n const canToggle = canToggleList(editor, type)\n const isActive = isListActive(editor, type)\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleSelectionUpdate = () => {\n setIsVisible(shouldShowButton({ editor, type, hideWhenUnavailable }))\n }\n\n handleSelectionUpdate()\n\n editor.on(\"selectionUpdate\", handleSelectionUpdate)\n\n return () => {\n editor.off(\"selectionUpdate\", handleSelectionUpdate)\n }\n }, [editor, type, hideWhenUnavailable])\n\n const handleToggle = React.useCallback(() => {\n if (!editor) return false\n\n const success = toggleList(editor, type)\n if (success) {\n onToggled?.()\n }\n return success\n }, [editor, type, onToggled])\n\n return {\n isVisible,\n isActive,\n handleToggle,\n canToggle,\n label: listLabels[type],\n shortcutKeys: LIST_SHORTCUT_KEYS[type],\n Icon: listIcons[type],\n }\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport type { Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Icons ---\nimport { ListIcon } from \"@/components/tiptap-icons/list-icon\"\nimport { ListOrderedIcon } from \"@/components/tiptap-icons/list-ordered-icon\"\nimport { ListTodoIcon } from \"@/components/tiptap-icons/list-todo-icon\"\n\n// --- Lib ---\nimport { isNodeInSchema } from \"@/lib/tiptap-utils\"\n\n// --- Tiptap UI ---\nimport {\n canToggleList,\n isListActive,\n listIcons,\n type ListType,\n} from \"@/components/tiptap-ui/list-button\"\n\n/**\n * Configuration for the list dropdown menu functionality\n */\nexport interface UseListDropdownMenuConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * The list types to display in the dropdown.\n * @default [\"bulletList\", \"orderedList\", \"taskList\"]\n */\n types?: ListType[]\n /**\n * Whether the dropdown should be hidden when no list types are available\n * @default false\n */\n hideWhenUnavailable?: boolean\n}\n\nexport interface ListOption {\n label: string\n type: ListType\n icon: React.ElementType\n}\n\nexport const listOptions: ListOption[] = [\n {\n label: \"Bullet List\",\n type: \"bulletList\",\n icon: ListIcon,\n },\n {\n label: \"Ordered List\",\n type: \"orderedList\",\n icon: ListOrderedIcon,\n },\n {\n label: \"Task List\",\n type: \"taskList\",\n icon: ListTodoIcon,\n },\n]\n\nexport function canToggleAnyList(\n editor: Editor | null,\n listTypes: ListType[]\n): boolean {\n if (!editor || !editor.isEditable) return false\n return listTypes.some((type) => canToggleList(editor, type))\n}\n\nexport function isAnyListActive(\n editor: Editor | null,\n listTypes: ListType[]\n): boolean {\n if (!editor || !editor.isEditable) return false\n return listTypes.some((type) => isListActive(editor, type))\n}\n\nexport function getFilteredListOptions(\n availableTypes: ListType[]\n): typeof listOptions {\n return listOptions.filter(\n (option) => !option.type || availableTypes.includes(option.type)\n )\n}\n\nexport function shouldShowListDropdown(params: {\n editor: Editor | null\n listTypes: ListType[]\n hideWhenUnavailable: boolean\n listInSchema: boolean\n canToggleAny: boolean\n}): boolean {\n const { editor, hideWhenUnavailable, listInSchema, canToggleAny } = params\n\n if (!listInSchema || !editor) {\n return false\n }\n\n if (hideWhenUnavailable && !editor.isActive(\"code\")) {\n return canToggleAny\n }\n\n return true\n}\n\n/**\n * Gets the currently active list type from the available types\n */\nexport function getActiveListType(\n editor: Editor | null,\n availableTypes: ListType[]\n): ListType | undefined {\n if (!editor || !editor.isEditable) return undefined\n return availableTypes.find((type) => isListActive(editor, type))\n}\n\n/**\n * Custom hook that provides list dropdown menu functionality for Tiptap editor\n *\n * @example\n * ```tsx\n * // Simple usage\n * function MyListDropdown() {\n * const {\n * isVisible,\n * activeType,\n * isAnyActive,\n * canToggleAny,\n * filteredLists,\n * } = useListDropdownMenu()\n *\n * if (!isVisible) return null\n *\n * return (\n * <DropdownMenu>\n * // dropdown content\n * </DropdownMenu>\n * )\n * }\n *\n * // Advanced usage with configuration\n * function MyAdvancedListDropdown() {\n * const {\n * isVisible,\n * activeType,\n * } = useListDropdownMenu({\n * editor: myEditor,\n * types: [\"bulletList\", \"orderedList\"],\n * hideWhenUnavailable: true,\n * })\n *\n * // component implementation\n * }\n * ```\n */\nexport function useListDropdownMenu(config?: UseListDropdownMenuConfig) {\n const {\n editor: providedEditor,\n types = [\"bulletList\", \"orderedList\", \"taskList\"],\n hideWhenUnavailable = false,\n } = config || {}\n\n const { editor } = useTiptapEditor(providedEditor)\n const [isVisible, setIsVisible] = React.useState(false)\n\n const listInSchema = types.some((type) => isNodeInSchema(type, editor))\n\n const filteredLists = React.useMemo(\n () => getFilteredListOptions(types),\n [types]\n )\n\n const canToggleAny = canToggleAnyList(editor, types)\n const isAnyActive = isAnyListActive(editor, types)\n const activeType = getActiveListType(editor, types)\n const activeList = filteredLists.find((option) => option.type === activeType)\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleSelectionUpdate = () => {\n setIsVisible(\n shouldShowListDropdown({\n editor,\n listTypes: types,\n hideWhenUnavailable,\n listInSchema,\n canToggleAny,\n })\n )\n }\n\n handleSelectionUpdate()\n\n editor.on(\"selectionUpdate\", handleSelectionUpdate)\n\n return () => {\n editor.off(\"selectionUpdate\", handleSelectionUpdate)\n }\n }, [canToggleAny, editor, hideWhenUnavailable, listInSchema, types])\n\n return {\n isVisible,\n activeType,\n isActive: isAnyActive,\n canToggle: canToggleAny,\n types,\n filteredLists,\n label: \"List\",\n Icon: activeList ? listIcons[activeList.type] : ListIcon,\n }\n}\n","import * as React from \"react\"\nimport { type Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Icons ---\nimport { ChevronDownIcon } from \"@/components/tiptap-icons/chevron-down-icon\"\n\n// --- Tiptap UI ---\nimport { ListButton, type ListType } from \"@/components/tiptap-ui/list-button\"\n\nimport { useListDropdownMenu } from \"./use-list-dropdown-menu\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button, ButtonGroup } from \"@/components/tiptap-ui-primitive/button\"\nimport {\n DropdownMenu,\n DropdownMenuTrigger,\n DropdownMenuContent,\n DropdownMenuItem,\n} from \"@/components/tiptap-ui-primitive/dropdown-menu\"\nimport { Card, CardBody } from \"@/components/tiptap-ui-primitive/card\"\n\nexport interface ListDropdownMenuProps extends Omit<ButtonProps, \"type\"> {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor\n /**\n * The list types to display in the dropdown.\n */\n types?: ListType[]\n /**\n * Whether the dropdown should be hidden when no list types are available\n * @default false\n */\n hideWhenUnavailable?: boolean\n /**\n * Callback for when the dropdown opens or closes\n */\n onOpenChange?: (isOpen: boolean) => void\n /**\n * Whether to render the dropdown menu in a portal\n * @default false\n */\n portal?: boolean\n}\n\nexport function ListDropdownMenu({\n editor: providedEditor,\n types = [\"bulletList\", \"orderedList\", \"taskList\"],\n hideWhenUnavailable = false,\n onOpenChange,\n portal = false,\n ...props\n}: ListDropdownMenuProps) {\n const { editor } = useTiptapEditor(providedEditor)\n const [isOpen, setIsOpen] = React.useState(false)\n\n const { filteredLists, canToggle, isActive, isVisible, Icon } =\n useListDropdownMenu({\n editor,\n types,\n hideWhenUnavailable,\n })\n\n const handleOnOpenChange = React.useCallback(\n (open: boolean) => {\n setIsOpen(open)\n onOpenChange?.(open)\n },\n [onOpenChange]\n )\n\n if (!isVisible || !editor || !editor.isEditable) {\n return null\n }\n\n return (\n <DropdownMenu open={isOpen} onOpenChange={handleOnOpenChange}>\n <DropdownMenuTrigger asChild>\n <Button\n type=\"button\"\n data-style=\"ghost\"\n data-active-state={isActive ? \"on\" : \"off\"}\n role=\"button\"\n tabIndex={-1}\n disabled={!canToggle}\n data-disabled={!canToggle}\n aria-label=\"List options\"\n tooltip=\"List\"\n {...props}\n >\n <Icon className=\"tiptap-button-icon\" />\n <ChevronDownIcon className=\"tiptap-button-dropdown-small\" />\n </Button>\n </DropdownMenuTrigger>\n\n <DropdownMenuContent align=\"start\" portal={portal}>\n <Card>\n <CardBody>\n <ButtonGroup>\n {filteredLists.map((option) => (\n <DropdownMenuItem key={option.type} asChild>\n <ListButton\n editor={editor}\n type={option.type}\n text={option.label}\n showTooltip={false}\n />\n </DropdownMenuItem>\n ))}\n </ButtonGroup>\n </CardBody>\n </Card>\n </DropdownMenuContent>\n </DropdownMenu>\n )\n}\n\nexport default ListDropdownMenu\n","import * as React from \"react\"\n\n// --- Tiptap UI ---\nimport type { UseBlockquoteConfig } from \"@/components/tiptap-ui/blockquote-button\"\nimport {\n BLOCKQUOTE_SHORTCUT_KEY,\n useBlockquote,\n} from \"@/components/tiptap-ui/blockquote-button\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Lib ---\nimport { parseShortcutKeys } from \"@/lib/tiptap-utils\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button } from \"@/components/tiptap-ui-primitive/button\"\nimport { Badge } from \"@/components/tiptap-ui-primitive/badge\"\n\nexport interface BlockquoteButtonProps\n extends Omit<ButtonProps, \"type\">,\n UseBlockquoteConfig {\n /**\n * Optional text to display alongside the icon.\n */\n text?: string\n /**\n * Optional show shortcut keys in the button.\n * @default false\n */\n showShortcut?: boolean\n}\n\nexport function BlockquoteShortcutBadge({\n shortcutKeys = BLOCKQUOTE_SHORTCUT_KEY,\n}: {\n shortcutKeys?: string\n}) {\n return <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge>\n}\n\n/**\n * Button component for toggling blockquote in a Tiptap editor.\n *\n * For custom button implementations, use the `useBlockquote` hook instead.\n */\nexport const BlockquoteButton = React.forwardRef<\n HTMLButtonElement,\n BlockquoteButtonProps\n>(\n (\n {\n editor: providedEditor,\n text,\n hideWhenUnavailable = false,\n onToggled,\n showShortcut = false,\n onClick,\n children,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const {\n isVisible,\n canToggle,\n isActive,\n handleToggle,\n label,\n shortcutKeys,\n Icon,\n } = useBlockquote({\n editor,\n hideWhenUnavailable,\n onToggled,\n })\n\n const handleClick = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented) return\n handleToggle()\n },\n [handleToggle, onClick]\n )\n\n if (!isVisible) {\n return null\n }\n\n return (\n <Button\n type=\"button\"\n data-style=\"ghost\"\n data-active-state={isActive ? \"on\" : \"off\"}\n role=\"button\"\n tabIndex={-1}\n disabled={!canToggle}\n data-disabled={!canToggle}\n aria-label={label}\n aria-pressed={isActive}\n tooltip=\"Blockquote\"\n onClick={handleClick}\n {...buttonProps}\n ref={ref}\n >\n {children ?? (\n <>\n <Icon className=\"tiptap-button-icon\" />\n {text && <span className=\"tiptap-button-text\">{text}</span>}\n {showShortcut && (\n <BlockquoteShortcutBadge shortcutKeys={shortcutKeys} />\n )}\n </>\n )}\n </Button>\n )\n }\n)\n\nBlockquoteButton.displayName = \"BlockquoteButton\"\n","import * as React from \"react\"\n\nexport const BlockquoteIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M8 6C8 5.44772 8.44772 5 9 5H16C16.5523 5 17 5.44772 17 6C17 6.55228 16.5523 7 16 7H9C8.44772 7 8 6.55228 8 6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M4 3C4.55228 3 5 3.44772 5 4L5 20C5 20.5523 4.55229 21 4 21C3.44772 21 3 20.5523 3 20L3 4C3 3.44772 3.44772 3 4 3Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M8 12C8 11.4477 8.44772 11 9 11H20C20.5523 11 21 11.4477 21 12C21 12.5523 20.5523 13 20 13H9C8.44772 13 8 12.5523 8 12Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M8 18C8 17.4477 8.44772 17 9 17H16C16.5523 17 17 17.4477 17 18C17 18.5523 16.5523 19 16 19H9C8.44772 19 8 18.5523 8 18Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nBlockquoteIcon.displayName = \"BlockquoteIcon\"\n","\"use client\"\n\nimport * as React from \"react\"\nimport type { Editor } from \"@tiptap/react\"\nimport { NodeSelection, TextSelection } from \"@tiptap/pm/state\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Icons ---\nimport { BlockquoteIcon } from \"@/components/tiptap-icons/blockquote-icon\"\n\n// --- UI Utils ---\nimport {\n findNodePosition,\n isNodeInSchema,\n isNodeTypeSelected,\n isValidPosition,\n} from \"@/lib/tiptap-utils\"\n\nexport const BLOCKQUOTE_SHORTCUT_KEY = \"mod+shift+b\"\n\n/**\n * Configuration for the blockquote functionality\n */\nexport interface UseBlockquoteConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * Whether the button should hide when blockquote is not available.\n * @default false\n */\n hideWhenUnavailable?: boolean\n /**\n * Callback function called after a successful toggle.\n */\n onToggled?: () => void\n}\n\n/**\n * Checks if blockquote can be toggled in the current editor state\n */\nexport function canToggleBlockquote(\n editor: Editor | null,\n turnInto: boolean = true\n): boolean {\n if (!editor || !editor.isEditable) return false\n if (\n !isNodeInSchema(\"blockquote\", editor) ||\n isNodeTypeSelected(editor, [\"image\"])\n )\n return false\n\n if (!turnInto) {\n return editor.can().toggleWrap(\"blockquote\")\n }\n\n try {\n const view = editor.view\n const state = view.state\n const selection = state.selection\n\n if (selection.empty || selection instanceof TextSelection) {\n const pos = findNodePosition({\n editor,\n node: state.selection.$anchor.node(1),\n })?.pos\n if (!isValidPosition(pos)) return false\n }\n\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Toggles blockquote formatting for a specific node or the current selection\n */\nexport function toggleBlockquote(editor: Editor | null): boolean {\n if (!editor || !editor.isEditable) return false\n if (!canToggleBlockquote(editor)) return false\n\n try {\n const view = editor.view\n let state = view.state\n let tr = state.tr\n\n // No selection, find the the cursor position\n if (state.selection.empty || state.selection instanceof TextSelection) {\n const pos = findNodePosition({\n editor,\n node: state.selection.$anchor.node(1),\n })?.pos\n if (!isValidPosition(pos)) return false\n\n tr = tr.setSelection(NodeSelection.create(state.doc, pos))\n view.dispatch(tr)\n state = view.state\n }\n\n const selection = state.selection\n\n let chain = editor.chain().focus()\n\n // Handle NodeSelection\n if (selection instanceof NodeSelection) {\n const firstChild = selection.node.firstChild?.firstChild\n const lastChild = selection.node.lastChild?.lastChild\n\n const from = firstChild\n ? selection.from + firstChild.nodeSize\n : selection.from + 1\n\n const to = lastChild\n ? selection.to - lastChild.nodeSize\n : selection.to - 1\n\n chain = chain.setTextSelection({ from, to }).clearNodes()\n }\n\n const toggle = editor.isActive(\"blockquote\")\n ? chain.lift(\"blockquote\")\n : chain.wrapIn(\"blockquote\")\n\n toggle.run()\n\n editor.chain().focus().selectTextblockEnd().run()\n\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Determines if the blockquote button should be shown\n */\nexport function shouldShowButton(props: {\n editor: Editor | null\n hideWhenUnavailable: boolean\n}): boolean {\n const { editor, hideWhenUnavailable } = props\n\n if (!editor || !editor.isEditable) return false\n if (!isNodeInSchema(\"blockquote\", editor)) return false\n\n if (hideWhenUnavailable && !editor.isActive(\"code\")) {\n return canToggleBlockquote(editor)\n }\n\n return true\n}\n\n/**\n * Custom hook that provides blockquote functionality for Tiptap editor\n *\n * @example\n * ```tsx\n * // Simple usage - no params needed\n * function MySimpleBlockquoteButton() {\n * const { isVisible, handleToggle, isActive } = useBlockquote()\n *\n * if (!isVisible) return null\n *\n * return <button onClick={handleToggle}>Blockquote</button>\n * }\n *\n * // Advanced usage with configuration\n * function MyAdvancedBlockquoteButton() {\n * const { isVisible, handleToggle, label, isActive } = useBlockquote({\n * editor: myEditor,\n * hideWhenUnavailable: true,\n * onToggled: () => console.log('Blockquote toggled!')\n * })\n *\n * if (!isVisible) return null\n *\n * return (\n * <MyButton\n * onClick={handleToggle}\n * aria-label={label}\n * aria-pressed={isActive}\n * >\n * Toggle Blockquote\n * </MyButton>\n * )\n * }\n * ```\n */\nexport function useBlockquote(config?: UseBlockquoteConfig) {\n const {\n editor: providedEditor,\n hideWhenUnavailable = false,\n onToggled,\n } = config || {}\n\n const { editor } = useTiptapEditor(providedEditor)\n const [isVisible, setIsVisible] = React.useState<boolean>(true)\n const canToggle = canToggleBlockquote(editor)\n const isActive = editor?.isActive(\"blockquote\") || false\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleSelectionUpdate = () => {\n setIsVisible(shouldShowButton({ editor, hideWhenUnavailable }))\n }\n\n handleSelectionUpdate()\n\n editor.on(\"selectionUpdate\", handleSelectionUpdate)\n\n return () => {\n editor.off(\"selectionUpdate\", handleSelectionUpdate)\n }\n }, [editor, hideWhenUnavailable])\n\n const handleToggle = React.useCallback(() => {\n if (!editor) return false\n\n const success = toggleBlockquote(editor)\n if (success) {\n onToggled?.()\n }\n return success\n }, [editor, onToggled])\n\n return {\n isVisible,\n isActive,\n handleToggle,\n canToggle,\n label: \"Blockquote\",\n shortcutKeys: BLOCKQUOTE_SHORTCUT_KEY,\n Icon: BlockquoteIcon,\n }\n}\n","import * as React from \"react\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Lib ---\nimport { parseShortcutKeys } from \"@/lib/tiptap-utils\"\n\n// --- Tiptap UI ---\nimport type { UseCodeBlockConfig } from \"@/components/tiptap-ui/code-block-button\"\nimport {\n CODE_BLOCK_SHORTCUT_KEY,\n useCodeBlock,\n} from \"@/components/tiptap-ui/code-block-button\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button } from \"@/components/tiptap-ui-primitive/button\"\nimport { Badge } from \"@/components/tiptap-ui-primitive/badge\"\n\nexport interface CodeBlockButtonProps\n extends Omit<ButtonProps, \"type\">,\n UseCodeBlockConfig {\n /**\n * Optional text to display alongside the icon.\n */\n text?: string\n /**\n * Optional show shortcut keys in the button.\n * @default false\n */\n showShortcut?: boolean\n}\n\nexport function CodeBlockShortcutBadge({\n shortcutKeys = CODE_BLOCK_SHORTCUT_KEY,\n}: {\n shortcutKeys?: string\n}) {\n return <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge>\n}\n\n/**\n * Button component for toggling code block in a Tiptap editor.\n *\n * For custom button implementations, use the `useCodeBlock` hook instead.\n */\nexport const CodeBlockButton = React.forwardRef<\n HTMLButtonElement,\n CodeBlockButtonProps\n>(\n (\n {\n editor: providedEditor,\n text,\n hideWhenUnavailable = false,\n onToggled,\n showShortcut = false,\n onClick,\n children,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const {\n isVisible,\n canToggle,\n isActive,\n handleToggle,\n label,\n shortcutKeys,\n Icon,\n } = useCodeBlock({\n editor,\n hideWhenUnavailable,\n onToggled,\n })\n\n const handleClick = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented) return\n handleToggle()\n },\n [handleToggle, onClick]\n )\n\n if (!isVisible) {\n return null\n }\n\n return (\n <Button\n type=\"button\"\n data-style=\"ghost\"\n data-active-state={isActive ? \"on\" : \"off\"}\n role=\"button\"\n disabled={!canToggle}\n data-disabled={!canToggle}\n tabIndex={-1}\n aria-label={label}\n aria-pressed={isActive}\n tooltip=\"Code Block\"\n onClick={handleClick}\n {...buttonProps}\n ref={ref}\n >\n {children ?? (\n <>\n <Icon className=\"tiptap-button-icon\" />\n {text && <span className=\"tiptap-button-text\">{text}</span>}\n {showShortcut && (\n <CodeBlockShortcutBadge shortcutKeys={shortcutKeys} />\n )}\n </>\n )}\n </Button>\n )\n }\n)\n\nCodeBlockButton.displayName = \"CodeBlockButton\"\n","import * as React from \"react\"\n\nexport const CodeBlockIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M6.70711 2.29289C7.09763 2.68342 7.09763 3.31658 6.70711 3.70711L4.41421 6L6.70711 8.29289C7.09763 8.68342 7.09763 9.31658 6.70711 9.70711C6.31658 10.0976 5.68342 10.0976 5.29289 9.70711L2.29289 6.70711C1.90237 6.31658 1.90237 5.68342 2.29289 5.29289L5.29289 2.29289C5.68342 1.90237 6.31658 1.90237 6.70711 2.29289Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M10.2929 2.29289C10.6834 1.90237 11.3166 1.90237 11.7071 2.29289L14.7071 5.29289C15.0976 5.68342 15.0976 6.31658 14.7071 6.70711L11.7071 9.70711C11.3166 10.0976 10.6834 10.0976 10.2929 9.70711C9.90237 9.31658 9.90237 8.68342 10.2929 8.29289L12.5858 6L10.2929 3.70711C9.90237 3.31658 9.90237 2.68342 10.2929 2.29289Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M17 4C17 3.44772 17.4477 3 18 3H19C20.6569 3 22 4.34315 22 6V18C22 19.6569 20.6569 21 19 21H5C3.34315 21 2 19.6569 2 18V12C2 11.4477 2.44772 11 3 11C3.55228 11 4 11.4477 4 12V18C4 18.5523 4.44772 19 5 19H19C19.5523 19 20 18.5523 20 18V6C20 5.44772 19.5523 5 19 5H18C17.4477 5 17 4.55228 17 4Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nCodeBlockIcon.displayName = \"CodeBlockIcon\"\n","\"use client\"\n\nimport * as React from \"react\"\nimport { type Editor } from \"@tiptap/react\"\nimport { NodeSelection, TextSelection } from \"@tiptap/pm/state\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Lib ---\nimport {\n findNodePosition,\n isNodeInSchema,\n isNodeTypeSelected,\n isValidPosition,\n} from \"@/lib/tiptap-utils\"\n\n// --- Icons ---\nimport { CodeBlockIcon } from \"@/components/tiptap-icons/code-block-icon\"\n\nexport const CODE_BLOCK_SHORTCUT_KEY = \"mod+alt+c\"\n\n/**\n * Configuration for the code block functionality\n */\nexport interface UseCodeBlockConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * Whether the button should hide when code block is not available.\n * @default false\n */\n hideWhenUnavailable?: boolean\n /**\n * Callback function called after a successful code block toggle.\n */\n onToggled?: () => void\n}\n\n/**\n * Checks if code block can be toggled in the current editor state\n */\nexport function canToggle(\n editor: Editor | null,\n turnInto: boolean = true\n): boolean {\n if (!editor || !editor.isEditable) return false\n if (\n !isNodeInSchema(\"codeBlock\", editor) ||\n isNodeTypeSelected(editor, [\"image\"])\n )\n return false\n\n if (!turnInto) {\n return editor.can().toggleNode(\"codeBlock\", \"paragraph\")\n }\n\n try {\n const view = editor.view\n const state = view.state\n const selection = state.selection\n\n if (selection.empty || selection instanceof TextSelection) {\n const pos = findNodePosition({\n editor,\n node: state.selection.$anchor.node(1),\n })?.pos\n if (!isValidPosition(pos)) return false\n }\n\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Toggles code block in the editor\n */\nexport function toggleCodeBlock(editor: Editor | null): boolean {\n if (!editor || !editor.isEditable) return false\n if (!canToggle(editor)) return false\n\n try {\n const view = editor.view\n let state = view.state\n let tr = state.tr\n\n // No selection, find the the cursor position\n if (state.selection.empty || state.selection instanceof TextSelection) {\n const pos = findNodePosition({\n editor,\n node: state.selection.$anchor.node(1),\n })?.pos\n if (!isValidPosition(pos)) return false\n\n tr = tr.setSelection(NodeSelection.create(state.doc, pos))\n view.dispatch(tr)\n state = view.state\n }\n\n const selection = state.selection\n\n let chain = editor.chain().focus()\n\n // Handle NodeSelection\n if (selection instanceof NodeSelection) {\n const firstChild = selection.node.firstChild?.firstChild\n const lastChild = selection.node.lastChild?.lastChild\n\n const from = firstChild\n ? selection.from + firstChild.nodeSize\n : selection.from + 1\n\n const to = lastChild\n ? selection.to - lastChild.nodeSize\n : selection.to - 1\n\n chain = chain.setTextSelection({ from, to }).clearNodes()\n }\n\n const toggle = editor.isActive(\"codeBlock\")\n ? chain.setNode(\"paragraph\")\n : chain.toggleNode(\"codeBlock\", \"paragraph\")\n\n toggle.run()\n\n editor.chain().focus().selectTextblockEnd().run()\n\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Determines if the code block button should be shown\n */\nexport function shouldShowButton(props: {\n editor: Editor | null\n hideWhenUnavailable: boolean\n}): boolean {\n const { editor, hideWhenUnavailable } = props\n\n if (!editor || !editor.isEditable) return false\n if (!isNodeInSchema(\"codeBlock\", editor)) return false\n\n if (hideWhenUnavailable && !editor.isActive(\"code\")) {\n return canToggle(editor)\n }\n\n return true\n}\n\n/**\n * Custom hook that provides code block functionality for Tiptap editor\n *\n * @example\n * ```tsx\n * // Simple usage - no params needed\n * function MySimpleCodeBlockButton() {\n * const { isVisible, isActive, handleToggle } = useCodeBlock()\n *\n * if (!isVisible) return null\n *\n * return (\n * <button\n * onClick={handleToggle}\n * aria-pressed={isActive}\n * >\n * Code Block\n * </button>\n * )\n * }\n *\n * // Advanced usage with configuration\n * function MyAdvancedCodeBlockButton() {\n * const { isVisible, isActive, handleToggle, label } = useCodeBlock({\n * editor: myEditor,\n * hideWhenUnavailable: true,\n * onToggled: (isActive) => console.log('Code block toggled:', isActive)\n * })\n *\n * if (!isVisible) return null\n *\n * return (\n * <MyButton\n * onClick={handleToggle}\n * aria-label={label}\n * aria-pressed={isActive}\n * >\n * Toggle Code Block\n * </MyButton>\n * )\n * }\n * ```\n */\nexport function useCodeBlock(config?: UseCodeBlockConfig) {\n const {\n editor: providedEditor,\n hideWhenUnavailable = false,\n onToggled,\n } = config || {}\n\n const { editor } = useTiptapEditor(providedEditor)\n const [isVisible, setIsVisible] = React.useState<boolean>(true)\n const canToggleState = canToggle(editor)\n const isActive = editor?.isActive(\"codeBlock\") || false\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleSelectionUpdate = () => {\n setIsVisible(shouldShowButton({ editor, hideWhenUnavailable }))\n }\n\n handleSelectionUpdate()\n\n editor.on(\"selectionUpdate\", handleSelectionUpdate)\n\n return () => {\n editor.off(\"selectionUpdate\", handleSelectionUpdate)\n }\n }, [editor, hideWhenUnavailable])\n\n const handleToggle = React.useCallback(() => {\n if (!editor) return false\n\n const success = toggleCodeBlock(editor)\n if (success) {\n onToggled?.()\n }\n return success\n }, [editor, onToggled])\n\n return {\n isVisible,\n isActive,\n handleToggle,\n canToggle: canToggleState,\n label: \"Code Block\",\n shortcutKeys: CODE_BLOCK_SHORTCUT_KEY,\n Icon: CodeBlockIcon,\n }\n}\n","import * as React from \"react\"\n\nexport const BanIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M4.43471 4.01458C4.34773 4.06032 4.26607 4.11977 4.19292 4.19292C4.11977 4.26607 4.06032 4.34773 4.01458 4.43471C2.14611 6.40628 1 9.0693 1 12C1 18.0751 5.92487 23 12 23C14.9306 23 17.5936 21.854 19.5651 19.9856C19.6522 19.9398 19.7339 19.8803 19.8071 19.8071C19.8803 19.7339 19.9398 19.6522 19.9856 19.5651C21.854 17.5936 23 14.9306 23 12C23 5.92487 18.0751 1 12 1C9.0693 1 6.40628 2.14611 4.43471 4.01458ZM6.38231 4.9681C7.92199 3.73647 9.87499 3 12 3C16.9706 3 21 7.02944 21 12C21 14.125 20.2635 16.078 19.0319 17.6177L6.38231 4.9681ZM17.6177 19.0319C16.078 20.2635 14.125 21 12 21C7.02944 21 3 16.9706 3 12C3 9.87499 3.73647 7.92199 4.9681 6.38231L17.6177 19.0319Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nBanIcon.displayName = \"BanIcon\"\n","import * as React from \"react\"\n\nexport const HighlighterIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M14.7072 4.70711C15.0977 4.31658 15.0977 3.68342 14.7072 3.29289C14.3167 2.90237 13.6835 2.90237 13.293 3.29289L8.69294 7.89286L8.68594 7.9C8.13626 8.46079 7.82837 9.21474 7.82837 10C7.82837 10.2306 7.85491 10.4584 7.90631 10.6795L2.29289 16.2929C2.10536 16.4804 2 16.7348 2 17V20C2 20.5523 2.44772 21 3 21H12C12.2652 21 12.5196 20.8946 12.7071 20.7071L15.3205 18.0937C15.5416 18.1452 15.7695 18.1717 16.0001 18.1717C16.7853 18.1717 17.5393 17.8639 18.1001 17.3142L22.7072 12.7071C23.0977 12.3166 23.0977 11.6834 22.7072 11.2929C22.3167 10.9024 21.6835 10.9024 21.293 11.2929L16.6971 15.8887C16.5105 16.0702 16.2605 16.1717 16.0001 16.1717C15.7397 16.1717 15.4897 16.0702 15.303 15.8887L10.1113 10.697C9.92992 10.5104 9.82837 10.2604 9.82837 10C9.82837 9.73963 9.92992 9.48958 10.1113 9.30297L14.7072 4.70711ZM13.5858 17L9.00004 12.4142L4 17.4142V19H11.5858L13.5858 17Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nHighlighterIcon.displayName = \"HighlighterIcon\"\n","import * as React from \"react\"\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\"\nimport { cn } from \"@/lib/tiptap-utils\"\nimport \"@/components/tiptap-ui-primitive/popover/popover.scss\"\n\nfunction Popover({\n ...props\n}: React.ComponentProps<typeof PopoverPrimitive.Root>) {\n return <PopoverPrimitive.Root {...props} />\n}\n\nfunction PopoverTrigger({\n ...props\n}: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {\n return <PopoverPrimitive.Trigger {...props} />\n}\n\nfunction PopoverContent({\n className,\n align = \"center\",\n sideOffset = 4,\n ...props\n}: React.ComponentProps<typeof PopoverPrimitive.Content>) {\n return (\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n align={align}\n sideOffset={sideOffset}\n className={cn(\"tiptap-popover\", className)}\n {...props}\n />\n </PopoverPrimitive.Portal>\n )\n}\n\nexport { Popover, PopoverTrigger, PopoverContent }\n","import * as React from \"react\"\n\n// --- Lib ---\nimport { parseShortcutKeys } from \"@/lib/tiptap-utils\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Tiptap UI ---\nimport type { UseColorHighlightConfig } from \"@/components/tiptap-ui/color-highlight-button\"\nimport {\n COLOR_HIGHLIGHT_SHORTCUT_KEY,\n useColorHighlight,\n} from \"@/components/tiptap-ui/color-highlight-button\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button } from \"@/components/tiptap-ui-primitive/button\"\nimport { Badge } from \"@/components/tiptap-ui-primitive/badge\"\n\n// --- Styles ---\nimport \"@/components/tiptap-ui/color-highlight-button/color-highlight-button.scss\"\n\nexport interface ColorHighlightButtonProps\n extends Omit<ButtonProps, \"type\">,\n UseColorHighlightConfig {\n /**\n * Optional text to display alongside the icon.\n */\n text?: string\n /**\n * Optional show shortcut keys in the button.\n * @default false\n */\n showShortcut?: boolean\n}\n\nexport function ColorHighlightShortcutBadge({\n shortcutKeys = COLOR_HIGHLIGHT_SHORTCUT_KEY,\n}: {\n shortcutKeys?: string\n}) {\n return <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge>\n}\n\n/**\n * Button component for applying color highlights in a Tiptap editor.\n *\n * For custom button implementations, use the `useColorHighlight` hook instead.\n */\nexport const ColorHighlightButton = React.forwardRef<\n HTMLButtonElement,\n ColorHighlightButtonProps\n>(\n (\n {\n editor: providedEditor,\n highlightColor,\n text,\n hideWhenUnavailable = false,\n onApplied,\n showShortcut = false,\n onClick,\n children,\n style,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const {\n isVisible,\n canColorHighlight,\n isActive,\n handleColorHighlight,\n label,\n shortcutKeys,\n } = useColorHighlight({\n editor,\n highlightColor,\n label: text || `Toggle highlight (${highlightColor})`,\n hideWhenUnavailable,\n onApplied,\n })\n\n const handleClick = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented) return\n handleColorHighlight()\n },\n [handleColorHighlight, onClick]\n )\n\n const buttonStyle = React.useMemo(\n () =>\n ({\n ...style,\n \"--highlight-color\": highlightColor,\n }) as React.CSSProperties,\n [highlightColor, style]\n )\n\n if (!isVisible) {\n return null\n }\n\n return (\n <Button\n type=\"button\"\n data-style=\"ghost\"\n data-active-state={isActive ? \"on\" : \"off\"}\n role=\"button\"\n tabIndex={-1}\n disabled={!canColorHighlight}\n data-disabled={!canColorHighlight}\n aria-label={label}\n aria-pressed={isActive}\n tooltip={label}\n onClick={handleClick}\n style={buttonStyle}\n {...buttonProps}\n ref={ref}\n >\n {children ?? (\n <>\n <span\n className=\"tiptap-button-highlight\"\n style={\n { \"--highlight-color\": highlightColor } as React.CSSProperties\n }\n />\n {text && <span className=\"tiptap-button-text\">{text}</span>}\n {showShortcut && (\n <ColorHighlightShortcutBadge shortcutKeys={shortcutKeys} />\n )}\n </>\n )}\n </Button>\n )\n }\n)\n\nColorHighlightButton.displayName = \"ColorHighlightButton\"\n","\"use client\"\n\nimport * as React from \"react\"\nimport { type Editor } from \"@tiptap/react\"\nimport { useHotkeys } from \"react-hotkeys-hook\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\nimport { useIsMobile } from \"@/hooks/use-mobile\"\n\n// --- Lib ---\nimport { isMarkInSchema, isNodeTypeSelected } from \"@/lib/tiptap-utils\"\n\n// --- Icons ---\nimport { HighlighterIcon } from \"@/components/tiptap-icons/highlighter-icon\"\n\nexport const COLOR_HIGHLIGHT_SHORTCUT_KEY = \"mod+shift+h\"\nexport const HIGHLIGHT_COLORS = [\n {\n label: \"Default background\",\n value: \"var(--tt-bg-color)\",\n border: \"var(--tt-bg-color-contrast)\",\n },\n {\n label: \"Gray background\",\n value: \"var(--tt-color-highlight-gray)\",\n border: \"var(--tt-color-highlight-gray-contrast)\",\n },\n {\n label: \"Brown background\",\n value: \"var(--tt-color-highlight-brown)\",\n border: \"var(--tt-color-highlight-brown-contrast)\",\n },\n {\n label: \"Orange background\",\n value: \"var(--tt-color-highlight-orange)\",\n border: \"var(--tt-color-highlight-orange-contrast)\",\n },\n {\n label: \"Yellow background\",\n value: \"var(--tt-color-highlight-yellow)\",\n border: \"var(--tt-color-highlight-yellow-contrast)\",\n },\n {\n label: \"Green background\",\n value: \"var(--tt-color-highlight-green)\",\n border: \"var(--tt-color-highlight-green-contrast)\",\n },\n {\n label: \"Blue background\",\n value: \"var(--tt-color-highlight-blue)\",\n border: \"var(--tt-color-highlight-blue-contrast)\",\n },\n {\n label: \"Purple background\",\n value: \"var(--tt-color-highlight-purple)\",\n border: \"var(--tt-color-highlight-purple-contrast)\",\n },\n {\n label: \"Pink background\",\n value: \"var(--tt-color-highlight-pink)\",\n border: \"var(--tt-color-highlight-pink-contrast)\",\n },\n {\n label: \"Red background\",\n value: \"var(--tt-color-highlight-red)\",\n border: \"var(--tt-color-highlight-red-contrast)\",\n },\n]\nexport type HighlightColor = (typeof HIGHLIGHT_COLORS)[number]\n\n/**\n * Configuration for the color highlight functionality\n */\nexport interface UseColorHighlightConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * The color to apply when toggling the highlight.\n */\n highlightColor?: string\n /**\n * Optional label to display alongside the icon.\n */\n label?: string\n /**\n * Whether the button should hide when the mark is not available.\n * @default false\n */\n hideWhenUnavailable?: boolean\n /**\n * Called when the highlight is applied.\n */\n onApplied?: ({ color, label }: { color: string; label: string }) => void\n}\n\nexport function pickHighlightColorsByValue(values: string[]) {\n const colorMap = new Map(\n HIGHLIGHT_COLORS.map((color) => [color.value, color])\n )\n return values\n .map((value) => colorMap.get(value))\n .filter((color): color is (typeof HIGHLIGHT_COLORS)[number] => !!color)\n}\n\nexport function canColorHighlight(editor: Editor | null): boolean {\n if (!editor || !editor.isEditable) return false\n if (\n !isMarkInSchema(\"highlight\", editor) ||\n isNodeTypeSelected(editor, [\"image\"])\n )\n return false\n\n return editor.can().setMark(\"highlight\")\n}\n\nexport function isColorHighlightActive(\n editor: Editor | null,\n highlightColor?: string\n): boolean {\n if (!editor || !editor.isEditable) return false\n return highlightColor\n ? editor.isActive(\"highlight\", { color: highlightColor })\n : editor.isActive(\"highlight\")\n}\n\nexport function removeHighlight(editor: Editor | null): boolean {\n if (!editor || !editor.isEditable) return false\n if (!canColorHighlight(editor)) return false\n\n return editor.chain().focus().unsetMark(\"highlight\").run()\n}\n\nexport function shouldShowButton(props: {\n editor: Editor | null\n hideWhenUnavailable: boolean\n}): boolean {\n const { editor, hideWhenUnavailable } = props\n\n if (!editor || !editor.isEditable) return false\n if (!isMarkInSchema(\"highlight\", editor)) return false\n\n if (hideWhenUnavailable && !editor.isActive(\"code\")) {\n return canColorHighlight(editor)\n }\n\n return true\n}\n\nexport function useColorHighlight(config: UseColorHighlightConfig) {\n const {\n editor: providedEditor,\n label,\n highlightColor,\n hideWhenUnavailable = false,\n onApplied,\n } = config\n\n const { editor } = useTiptapEditor(providedEditor)\n const isMobile = useIsMobile()\n const [isVisible, setIsVisible] = React.useState<boolean>(true)\n const canColorHighlightState = canColorHighlight(editor)\n const isActive = isColorHighlightActive(editor, highlightColor)\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleSelectionUpdate = () => {\n setIsVisible(shouldShowButton({ editor, hideWhenUnavailable }))\n }\n\n handleSelectionUpdate()\n\n editor.on(\"selectionUpdate\", handleSelectionUpdate)\n\n return () => {\n editor.off(\"selectionUpdate\", handleSelectionUpdate)\n }\n }, [editor, hideWhenUnavailable])\n\n const handleColorHighlight = React.useCallback(() => {\n if (!editor || !canColorHighlightState || !highlightColor || !label)\n return false\n\n if (editor.state.storedMarks) {\n const highlightMarkType = editor.schema.marks.highlight\n if (highlightMarkType) {\n editor.view.dispatch(\n editor.state.tr.removeStoredMark(highlightMarkType)\n )\n }\n }\n\n setTimeout(() => {\n const success = editor\n .chain()\n .focus()\n .toggleMark(\"highlight\", { color: highlightColor })\n .run()\n if (success) {\n onApplied?.({ color: highlightColor, label })\n }\n return success\n }, 0)\n }, [canColorHighlightState, highlightColor, editor, label, onApplied])\n\n const handleRemoveHighlight = React.useCallback(() => {\n const success = removeHighlight(editor)\n if (success) {\n onApplied?.({ color: \"\", label: \"Remove highlight\" })\n }\n return success\n }, [editor, onApplied])\n\n useHotkeys(\n COLOR_HIGHLIGHT_SHORTCUT_KEY,\n (event) => {\n event.preventDefault()\n handleColorHighlight()\n },\n {\n enabled: isVisible && canColorHighlightState,\n enableOnContentEditable: !isMobile,\n enableOnFormTags: true,\n }\n )\n\n return {\n isVisible,\n isActive,\n handleColorHighlight,\n handleRemoveHighlight,\n canColorHighlight: canColorHighlightState,\n label: label || `Highlight`,\n shortcutKeys: COLOR_HIGHLIGHT_SHORTCUT_KEY,\n Icon: HighlighterIcon,\n }\n}\n","import * as React from \"react\"\nimport { type Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useMenuNavigation } from \"@/hooks/use-menu-navigation\"\nimport { useIsMobile } from \"@/hooks/use-mobile\"\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Icons ---\nimport { BanIcon } from \"@/components/tiptap-icons/ban-icon\"\nimport { HighlighterIcon } from \"@/components/tiptap-icons/highlighter-icon\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button, ButtonGroup } from \"@/components/tiptap-ui-primitive/button\"\nimport {\n Popover,\n PopoverTrigger,\n PopoverContent,\n} from \"@/components/tiptap-ui-primitive/popover\"\nimport { Separator } from \"@/components/tiptap-ui-primitive/separator\"\nimport {\n Card,\n CardBody,\n CardItemGroup,\n} from \"@/components/tiptap-ui-primitive/card\"\n\n// --- Tiptap UI ---\nimport type {\n HighlightColor,\n UseColorHighlightConfig,\n} from \"@/components/tiptap-ui/color-highlight-button\"\nimport {\n ColorHighlightButton,\n pickHighlightColorsByValue,\n useColorHighlight,\n} from \"@/components/tiptap-ui/color-highlight-button\"\n\nexport interface ColorHighlightPopoverContentProps {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * Optional colors to use in the highlight popover.\n * If not provided, defaults to a predefined set of colors.\n */\n colors?: HighlightColor[]\n}\n\nexport interface ColorHighlightPopoverProps\n extends Omit<ButtonProps, \"type\">,\n Pick<\n UseColorHighlightConfig,\n \"editor\" | \"hideWhenUnavailable\" | \"onApplied\"\n > {\n /**\n * Optional colors to use in the highlight popover.\n * If not provided, defaults to a predefined set of colors.\n */\n colors?: HighlightColor[]\n}\n\nexport const ColorHighlightPopoverButton = React.forwardRef<\n HTMLButtonElement,\n ButtonProps\n>(({ className, children, ...props }, ref) => (\n <Button\n type=\"button\"\n className={className}\n data-style=\"ghost\"\n data-appearance=\"default\"\n role=\"button\"\n tabIndex={-1}\n aria-label=\"Highlight text\"\n tooltip=\"Highlight\"\n ref={ref}\n {...props}\n >\n {children ?? <HighlighterIcon className=\"tiptap-button-icon\" />}\n </Button>\n))\n\nColorHighlightPopoverButton.displayName = \"ColorHighlightPopoverButton\"\n\nexport function ColorHighlightPopoverContent({\n editor,\n colors = pickHighlightColorsByValue([\n \"var(--tt-color-highlight-green)\",\n \"var(--tt-color-highlight-blue)\",\n \"var(--tt-color-highlight-red)\",\n \"var(--tt-color-highlight-purple)\",\n \"var(--tt-color-highlight-yellow)\",\n ]),\n}: ColorHighlightPopoverContentProps) {\n const { handleRemoveHighlight } = useColorHighlight({ editor })\n const isMobile = useIsMobile()\n const containerRef = React.useRef<HTMLDivElement>(null)\n\n const menuItems = React.useMemo(\n () => [...colors, { label: \"Remove highlight\", value: \"none\" }],\n [colors]\n )\n\n const { selectedIndex } = useMenuNavigation({\n containerRef,\n items: menuItems,\n orientation: \"both\",\n onSelect: (item) => {\n if (!containerRef.current) return false\n const highlightedElement = containerRef.current.querySelector(\n '[data-highlighted=\"true\"]'\n ) as HTMLElement\n if (highlightedElement) highlightedElement.click()\n if (item.value === \"none\") handleRemoveHighlight()\n },\n autoSelectFirstItem: false,\n })\n\n return (\n <Card\n ref={containerRef}\n tabIndex={0}\n style={isMobile ? { boxShadow: \"none\", border: 0 } : {}}\n >\n <CardBody style={isMobile ? { padding: 0 } : {}}>\n <CardItemGroup orientation=\"horizontal\">\n <ButtonGroup orientation=\"horizontal\">\n {colors.map((color, index) => (\n <ColorHighlightButton\n key={color.value}\n editor={editor}\n highlightColor={color.value}\n tooltip={color.label}\n aria-label={`${color.label} highlight color`}\n tabIndex={index === selectedIndex ? 0 : -1}\n data-highlighted={selectedIndex === index}\n />\n ))}\n </ButtonGroup>\n <Separator />\n <ButtonGroup orientation=\"horizontal\">\n <Button\n onClick={handleRemoveHighlight}\n aria-label=\"Remove highlight\"\n tooltip=\"Remove highlight\"\n tabIndex={selectedIndex === colors.length ? 0 : -1}\n type=\"button\"\n role=\"menuitem\"\n data-style=\"ghost\"\n data-highlighted={selectedIndex === colors.length}\n >\n <BanIcon className=\"tiptap-button-icon\" />\n </Button>\n </ButtonGroup>\n </CardItemGroup>\n </CardBody>\n </Card>\n )\n}\n\nexport function ColorHighlightPopover({\n editor: providedEditor,\n colors = pickHighlightColorsByValue([\n \"var(--tt-color-highlight-green)\",\n \"var(--tt-color-highlight-blue)\",\n \"var(--tt-color-highlight-red)\",\n \"var(--tt-color-highlight-purple)\",\n \"var(--tt-color-highlight-yellow)\",\n ]),\n hideWhenUnavailable = false,\n onApplied,\n ...props\n}: ColorHighlightPopoverProps) {\n const { editor } = useTiptapEditor(providedEditor)\n const [isOpen, setIsOpen] = React.useState(false)\n const { isVisible, canColorHighlight, isActive, label, Icon } =\n useColorHighlight({\n editor,\n hideWhenUnavailable,\n onApplied,\n })\n\n if (!isVisible) return null\n\n return (\n <Popover open={isOpen} onOpenChange={setIsOpen}>\n <PopoverTrigger asChild>\n <ColorHighlightPopoverButton\n disabled={!canColorHighlight}\n data-active-state={isActive ? \"on\" : \"off\"}\n data-disabled={!canColorHighlight}\n aria-pressed={isActive}\n aria-label={label}\n tooltip={label}\n {...props}\n >\n <Icon className=\"tiptap-button-icon\" />\n </ColorHighlightPopoverButton>\n </PopoverTrigger>\n <PopoverContent aria-label=\"Highlight colors\">\n <ColorHighlightPopoverContent editor={editor} colors={colors} />\n </PopoverContent>\n </Popover>\n )\n}\n\nexport default ColorHighlightPopover\n","import * as React from \"react\"\n\nexport const CornerDownLeftIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M21 4C21 3.44772 20.5523 3 20 3C19.4477 3 19 3.44772 19 4V11C19 11.7956 18.6839 12.5587 18.1213 13.1213C17.5587 13.6839 16.7956 14 16 14H6.41421L9.70711 10.7071C10.0976 10.3166 10.0976 9.68342 9.70711 9.29289C9.31658 8.90237 8.68342 8.90237 8.29289 9.29289L3.29289 14.2929C2.90237 14.6834 2.90237 15.3166 3.29289 15.7071L8.29289 20.7071C8.68342 21.0976 9.31658 21.0976 9.70711 20.7071C10.0976 20.3166 10.0976 19.6834 9.70711 19.2929L6.41421 16H16C17.3261 16 18.5979 15.4732 19.5355 14.5355C20.4732 13.5979 21 12.3261 21 11V4Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nCornerDownLeftIcon.displayName = \"CornerDownLeftIcon\"\n","import * as React from \"react\"\n\nexport const ExternalLinkIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M14 3C14 2.44772 14.4477 2 15 2H21C21.5523 2 22 2.44772 22 3V9C22 9.55228 21.5523 10 21 10C20.4477 10 20 9.55228 20 9V5.41421L10.7071 14.7071C10.3166 15.0976 9.68342 15.0976 9.29289 14.7071C8.90237 14.3166 8.90237 13.6834 9.29289 13.2929L18.5858 4H15C14.4477 4 14 3.55228 14 3Z\"\n fill=\"currentColor\"\n />\n <path\n d=\"M4.29289 7.29289C4.48043 7.10536 4.73478 7 5 7H11C11.5523 7 12 6.55228 12 6C12 5.44772 11.5523 5 11 5H5C4.20435 5 3.44129 5.31607 2.87868 5.87868C2.31607 6.44129 2 7.20435 2 8V19C2 19.7957 2.31607 20.5587 2.87868 21.1213C3.44129 21.6839 4.20435 22 5 22H16C16.7957 22 17.5587 21.6839 18.1213 21.1213C18.6839 20.5587 19 19.7957 19 19V13C19 12.4477 18.5523 12 18 12C17.4477 12 17 12.4477 17 13V19C17 19.2652 16.8946 19.5196 16.7071 19.7071C16.5196 19.8946 16.2652 20 16 20H5C4.73478 20 4.48043 19.8946 4.29289 19.7071C4.10536 19.5196 4 19.2652 4 19V8C4 7.73478 4.10536 7.48043 4.29289 7.29289Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nExternalLinkIcon.displayName = \"ExternalLinkIcon\"\n","import * as React from \"react\"\n\nexport const LinkIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M16.9958 1.06669C15.4226 1.05302 13.907 1.65779 12.7753 2.75074L12.765 2.76086L11.045 4.47086C10.6534 4.86024 10.6515 5.49341 11.0409 5.88507C11.4303 6.27673 12.0634 6.27858 12.4551 5.88919L14.1697 4.18456C14.9236 3.45893 15.9319 3.05752 16.9784 3.06662C18.0272 3.07573 19.0304 3.49641 19.772 4.23804C20.5137 4.97967 20.9344 5.98292 20.9435 7.03171C20.9526 8.07776 20.5515 9.08563 19.8265 9.83941L16.833 12.8329C16.4274 13.2386 15.9393 13.5524 15.4019 13.7529C14.8645 13.9533 14.2903 14.0359 13.7181 13.9949C13.146 13.9539 12.5894 13.7904 12.0861 13.5154C11.5827 13.2404 11.1444 12.8604 10.8008 12.401C10.47 11.9588 9.84333 11.8685 9.40108 12.1993C8.95883 12.5301 8.86849 13.1568 9.1993 13.599C9.71464 14.288 10.3721 14.858 11.1272 15.2705C11.8822 15.683 12.7171 15.9283 13.5753 15.9898C14.4334 16.0513 15.2948 15.9274 16.1009 15.6267C16.907 15.326 17.639 14.8555 18.2473 14.247L21.2472 11.2471L21.2593 11.2347C22.3523 10.1031 22.9571 8.58751 22.9434 7.01433C22.9297 5.44115 22.2987 3.93628 21.1863 2.82383C20.0738 1.71138 18.5689 1.08036 16.9958 1.06669Z\"\n fill=\"currentColor\"\n />\n <path\n d=\"M10.4247 8.0102C9.56657 7.94874 8.70522 8.07256 7.89911 8.37326C7.09305 8.67395 6.36096 9.14458 5.75272 9.753L2.75285 12.7529L2.74067 12.7653C1.64772 13.8969 1.04295 15.4125 1.05662 16.9857C1.07029 18.5589 1.70131 20.0637 2.81376 21.1762C3.9262 22.2886 5.43108 22.9196 7.00426 22.9333C8.57744 22.947 10.0931 22.3422 11.2247 21.2493L11.2371 21.2371L12.9471 19.5271C13.3376 19.1366 13.3376 18.5034 12.9471 18.1129C12.5565 17.7223 11.9234 17.7223 11.5328 18.1129L9.82932 19.8164C9.07555 20.5414 8.06768 20.9425 7.02164 20.9334C5.97285 20.9243 4.9696 20.5036 4.22797 19.762C3.48634 19.0203 3.06566 18.0171 3.05655 16.9683C3.04746 15.9222 3.44851 14.9144 4.17355 14.1606L7.16719 11.167C7.5727 10.7613 8.06071 10.4476 8.59811 10.2471C9.13552 10.0467 9.70976 9.96412 10.2819 10.0051C10.854 10.0461 11.4106 10.2096 11.9139 10.4846C12.4173 10.7596 12.8556 11.1397 13.1992 11.599C13.53 12.0412 14.1567 12.1316 14.5989 11.8007C15.0412 11.4699 15.1315 10.8433 14.8007 10.401C14.2854 9.71205 13.6279 9.14198 12.8729 8.72948C12.1178 8.31697 11.2829 8.07166 10.4247 8.0102Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nLinkIcon.displayName = \"LinkIcon\"\n","import * as React from \"react\"\n\nexport const TrashIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M7 5V4C7 3.17477 7.40255 2.43324 7.91789 1.91789C8.43324 1.40255 9.17477 1 10 1H14C14.8252 1 15.5668 1.40255 16.0821 1.91789C16.5975 2.43324 17 3.17477 17 4V5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H20V20C20 20.8252 19.5975 21.5668 19.0821 22.0821C18.5668 22.5975 17.8252 23 17 23H7C6.17477 23 5.43324 22.5975 4.91789 22.0821C4.40255 21.5668 4 20.8252 4 20V7H3C2.44772 7 2 6.55228 2 6C2 5.44772 2.44772 5 3 5H7ZM9 4C9 3.82523 9.09745 3.56676 9.33211 3.33211C9.56676 3.09745 9.82523 3 10 3H14C14.1748 3 14.4332 3.09745 14.6679 3.33211C14.9025 3.56676 15 3.82523 15 4V5H9V4ZM6 7V20C6 20.1748 6.09745 20.4332 6.33211 20.6679C6.56676 20.9025 6.82523 21 7 21H17C17.1748 21 17.4332 20.9025 17.6679 20.6679C17.9025 20.4332 18 20.1748 18 20V7H6Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nTrashIcon.displayName = \"TrashIcon\"\n","import * as React from \"react\"\nimport { cn } from \"@/lib/tiptap-utils\"\nimport \"@/components/tiptap-ui-primitive/input/input.scss\"\n\nfunction Input({ className, type, ...props }: React.ComponentProps<\"input\">) {\n return (\n <input type={type} className={cn(\"tiptap-input\", className)} {...props} />\n )\n}\n\nfunction InputGroup({\n className,\n children,\n ...props\n}: React.ComponentProps<\"div\">) {\n return (\n <div className={cn(\"tiptap-input-group\", className)} {...props}>\n {children}\n </div>\n )\n}\n\nexport { Input, InputGroup }\n","\"use client\"\n\nimport * as React from \"react\"\nimport type { Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useIsMobile } from \"@/hooks/use-mobile\"\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Icons ---\nimport { CornerDownLeftIcon } from \"@/components/tiptap-icons/corner-down-left-icon\"\nimport { ExternalLinkIcon } from \"@/components/tiptap-icons/external-link-icon\"\nimport { LinkIcon } from \"@/components/tiptap-icons/link-icon\"\nimport { TrashIcon } from \"@/components/tiptap-icons/trash-icon\"\n\n// --- Tiptap UI ---\nimport type { UseLinkPopoverConfig } from \"@/components/tiptap-ui/link-popover\"\nimport { useLinkPopover } from \"@/components/tiptap-ui/link-popover\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button, ButtonGroup } from \"@/components/tiptap-ui-primitive/button\"\nimport {\n Popover,\n PopoverContent,\n PopoverTrigger,\n} from \"@/components/tiptap-ui-primitive/popover\"\nimport { Separator } from \"@/components/tiptap-ui-primitive/separator\"\nimport {\n Card,\n CardBody,\n CardItemGroup,\n} from \"@/components/tiptap-ui-primitive/card\"\nimport { Input, InputGroup } from \"@/components/tiptap-ui-primitive/input\"\n\nexport interface LinkMainProps {\n /**\n * The URL to set for the link.\n */\n url: string\n /**\n * Function to update the URL state.\n */\n setUrl: React.Dispatch<React.SetStateAction<string | null>>\n /**\n * Function to set the link in the editor.\n */\n setLink: () => void\n /**\n * Function to remove the link from the editor.\n */\n removeLink: () => void\n /**\n * Function to open the link.\n */\n openLink: () => void\n /**\n * Whether the link is currently active in the editor.\n */\n isActive: boolean\n}\n\nexport interface LinkPopoverProps\n extends Omit<ButtonProps, \"type\">,\n UseLinkPopoverConfig {\n /**\n * Callback for when the popover opens or closes.\n */\n onOpenChange?: (isOpen: boolean) => void\n /**\n * Whether to automatically open the popover when a link is active.\n * @default true\n */\n autoOpenOnLinkActive?: boolean\n}\n\n/**\n * Link button component for triggering the link popover\n */\nexport const LinkButton = React.forwardRef<HTMLButtonElement, ButtonProps>(\n ({ className, children, ...props }, ref) => {\n return (\n <Button\n type=\"button\"\n className={className}\n data-style=\"ghost\"\n role=\"button\"\n tabIndex={-1}\n aria-label=\"Link\"\n tooltip=\"Link\"\n ref={ref}\n {...props}\n >\n {children || <LinkIcon className=\"tiptap-button-icon\" />}\n </Button>\n )\n }\n)\n\nLinkButton.displayName = \"LinkButton\"\n\n/**\n * Main content component for the link popover\n */\nconst LinkMain: React.FC<LinkMainProps> = ({\n url,\n setUrl,\n setLink,\n removeLink,\n openLink,\n isActive,\n}) => {\n const isMobile = useIsMobile()\n\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (event.key === \"Enter\") {\n event.preventDefault()\n setLink()\n }\n }\n\n return (\n <Card\n style={{\n ...(isMobile ? { boxShadow: \"none\", border: 0 } : {}),\n }}\n >\n <CardBody\n style={{\n ...(isMobile ? { padding: 0 } : {}),\n }}\n >\n <CardItemGroup orientation=\"horizontal\">\n <InputGroup>\n <Input\n type=\"url\"\n placeholder=\"Paste a link...\"\n value={url}\n onChange={(e) => setUrl(e.target.value)}\n onKeyDown={handleKeyDown}\n autoFocus\n autoComplete=\"off\"\n autoCorrect=\"off\"\n autoCapitalize=\"off\"\n />\n </InputGroup>\n\n <ButtonGroup orientation=\"horizontal\">\n <Button\n type=\"button\"\n onClick={setLink}\n title=\"Apply link\"\n disabled={!url && !isActive}\n data-style=\"ghost\"\n >\n <CornerDownLeftIcon className=\"tiptap-button-icon\" />\n </Button>\n </ButtonGroup>\n\n <Separator />\n\n <ButtonGroup orientation=\"horizontal\">\n <Button\n type=\"button\"\n onClick={openLink}\n title=\"Open in new window\"\n disabled={!url && !isActive}\n data-style=\"ghost\"\n >\n <ExternalLinkIcon className=\"tiptap-button-icon\" />\n </Button>\n\n <Button\n type=\"button\"\n onClick={removeLink}\n title=\"Remove link\"\n disabled={!url && !isActive}\n data-style=\"ghost\"\n >\n <TrashIcon className=\"tiptap-button-icon\" />\n </Button>\n </ButtonGroup>\n </CardItemGroup>\n </CardBody>\n </Card>\n )\n}\n\n/**\n * Link content component for standalone use\n */\nexport const LinkContent: React.FC<{\n editor?: Editor | null\n}> = ({ editor }) => {\n const linkPopover = useLinkPopover({\n editor,\n })\n\n return <LinkMain {...linkPopover} />\n}\n\n/**\n * Link popover component for Tiptap editors.\n *\n * For custom popover implementations, use the `useLinkPopover` hook instead.\n */\nexport const LinkPopover = React.forwardRef<\n HTMLButtonElement,\n LinkPopoverProps\n>(\n (\n {\n editor: providedEditor,\n hideWhenUnavailable = false,\n onSetLink,\n onOpenChange,\n autoOpenOnLinkActive = true,\n onClick,\n children,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const [isOpen, setIsOpen] = React.useState(false)\n\n const {\n isVisible,\n canSet,\n isActive,\n url,\n setUrl,\n setLink,\n removeLink,\n openLink,\n label,\n Icon,\n } = useLinkPopover({\n editor,\n hideWhenUnavailable,\n onSetLink,\n })\n\n const handleOnOpenChange = React.useCallback(\n (nextIsOpen: boolean) => {\n setIsOpen(nextIsOpen)\n onOpenChange?.(nextIsOpen)\n },\n [onOpenChange]\n )\n\n const handleSetLink = React.useCallback(() => {\n setLink()\n setIsOpen(false)\n }, [setLink])\n\n const handleClick = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented) return\n setIsOpen(!isOpen)\n },\n [onClick, isOpen]\n )\n\n React.useEffect(() => {\n if (autoOpenOnLinkActive && isActive) {\n setIsOpen(true)\n }\n }, [autoOpenOnLinkActive, isActive])\n\n if (!isVisible) {\n return null\n }\n\n return (\n <Popover open={isOpen} onOpenChange={handleOnOpenChange}>\n <PopoverTrigger asChild>\n <LinkButton\n disabled={!canSet}\n data-active-state={isActive ? \"on\" : \"off\"}\n data-disabled={!canSet}\n aria-label={label}\n aria-pressed={isActive}\n onClick={handleClick}\n {...buttonProps}\n ref={ref}\n >\n {children ?? <Icon className=\"tiptap-button-icon\" />}\n </LinkButton>\n </PopoverTrigger>\n\n <PopoverContent>\n <LinkMain\n url={url}\n setUrl={setUrl}\n setLink={handleSetLink}\n removeLink={removeLink}\n openLink={openLink}\n isActive={isActive}\n />\n </PopoverContent>\n </Popover>\n )\n }\n)\n\nLinkPopover.displayName = \"LinkPopover\"\n\nexport default LinkPopover\n","import * as React from \"react\"\nimport type { Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Icons ---\nimport { LinkIcon } from \"@/components/tiptap-icons/link-icon\"\n\n// --- Lib ---\nimport { isMarkInSchema, sanitizeUrl } from \"@/lib/tiptap-utils\"\n\n/**\n * Configuration for the link popover functionality\n */\nexport interface UseLinkPopoverConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * Whether to hide the link popover when not available.\n * @default false\n */\n hideWhenUnavailable?: boolean\n /**\n * Callback function called when the link is set.\n */\n onSetLink?: () => void\n}\n\n/**\n * Configuration for the link handler functionality\n */\nexport interface LinkHandlerProps {\n /**\n * The Tiptap editor instance.\n */\n editor: Editor | null\n /**\n * Callback function called when the link is set.\n */\n onSetLink?: () => void\n}\n\n/**\n * Checks if a link can be set in the current editor state\n */\nexport function canSetLink(editor: Editor | null): boolean {\n if (!editor || !editor.isEditable) return false\n return editor.can().setMark(\"link\")\n}\n\n/**\n * Checks if a link is currently active in the editor\n */\nexport function isLinkActive(editor: Editor | null): boolean {\n if (!editor || !editor.isEditable) return false\n return editor.isActive(\"link\")\n}\n\n/**\n * Determines if the link button should be shown\n */\nexport function shouldShowLinkButton(props: {\n editor: Editor | null\n hideWhenUnavailable: boolean\n}): boolean {\n const { editor, hideWhenUnavailable } = props\n\n const linkInSchema = isMarkInSchema(\"link\", editor)\n\n if (!linkInSchema || !editor) {\n return false\n }\n\n if (hideWhenUnavailable && !editor.isActive(\"code\")) {\n return canSetLink(editor)\n }\n\n return true\n}\n\n/**\n * Custom hook for handling link operations in a Tiptap editor\n */\nexport function useLinkHandler(props: LinkHandlerProps) {\n const { editor, onSetLink } = props\n const [url, setUrl] = React.useState<string | null>(null)\n\n React.useEffect(() => {\n if (!editor) return\n\n // Get URL immediately on mount\n const { href } = editor.getAttributes(\"link\")\n\n if (isLinkActive(editor) && url === null) {\n setUrl(href || \"\")\n }\n }, [editor, url])\n\n React.useEffect(() => {\n if (!editor) return\n\n const updateLinkState = () => {\n const { href } = editor.getAttributes(\"link\")\n setUrl(href || \"\")\n }\n\n editor.on(\"selectionUpdate\", updateLinkState)\n return () => {\n editor.off(\"selectionUpdate\", updateLinkState)\n }\n }, [editor])\n\n const setLink = React.useCallback(() => {\n if (!url || !editor) return\n\n const { selection } = editor.state\n const isEmpty = selection.empty\n\n let chain = editor.chain().focus()\n\n chain = chain.extendMarkRange(\"link\").setLink({ href: url })\n\n if (isEmpty) {\n chain = chain.insertContent({ type: \"text\", text: url })\n }\n\n chain.run()\n\n setUrl(null)\n\n onSetLink?.()\n }, [editor, onSetLink, url])\n\n const removeLink = React.useCallback(() => {\n if (!editor) return\n editor\n .chain()\n .focus()\n .extendMarkRange(\"link\")\n .unsetLink()\n .setMeta(\"preventAutolink\", true)\n .run()\n setUrl(\"\")\n }, [editor])\n\n const openLink = React.useCallback(\n (target: string = \"_blank\", features: string = \"noopener,noreferrer\") => {\n if (!url) return\n\n const safeUrl = sanitizeUrl(url, window.location.href)\n if (safeUrl !== \"#\") {\n window.open(safeUrl, target, features)\n }\n },\n [url]\n )\n\n return {\n url: url || \"\",\n setUrl,\n setLink,\n removeLink,\n openLink,\n }\n}\n\n/**\n * Custom hook for link popover state management\n */\nexport function useLinkState(props: {\n editor: Editor | null\n hideWhenUnavailable: boolean\n}) {\n const { editor, hideWhenUnavailable = false } = props\n\n const canSet = canSetLink(editor)\n const isActive = isLinkActive(editor)\n\n const [isVisible, setIsVisible] = React.useState(false)\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleSelectionUpdate = () => {\n setIsVisible(\n shouldShowLinkButton({\n editor,\n hideWhenUnavailable,\n })\n )\n }\n\n handleSelectionUpdate()\n\n editor.on(\"selectionUpdate\", handleSelectionUpdate)\n\n return () => {\n editor.off(\"selectionUpdate\", handleSelectionUpdate)\n }\n }, [editor, hideWhenUnavailable])\n\n return {\n isVisible,\n canSet,\n isActive,\n }\n}\n\n/**\n * Main hook that provides link popover functionality for Tiptap editor\n *\n * @example\n * ```tsx\n * // Simple usage\n * function MyLinkButton() {\n * const { isVisible, canSet, isActive, Icon, label } = useLinkPopover()\n *\n * if (!isVisible) return null\n *\n * return <button disabled={!canSet}>Link</button>\n * }\n *\n * // Advanced usage with configuration\n * function MyAdvancedLinkButton() {\n * const { isVisible, canSet, isActive, Icon, label } = useLinkPopover({\n * editor: myEditor,\n * hideWhenUnavailable: true,\n * onSetLink: () => console.log('Link set!')\n * })\n *\n * if (!isVisible) return null\n *\n * return (\n * <MyButton\n * disabled={!canSet}\n * aria-label={label}\n * aria-pressed={isActive}\n * >\n * <Icon />\n * {label}\n * </MyButton>\n * )\n * }\n * ```\n */\nexport function useLinkPopover(config?: UseLinkPopoverConfig) {\n const {\n editor: providedEditor,\n hideWhenUnavailable = false,\n onSetLink,\n } = config || {}\n\n const { editor } = useTiptapEditor(providedEditor)\n\n const { isVisible, canSet, isActive } = useLinkState({\n editor,\n hideWhenUnavailable,\n })\n\n const linkHandler = useLinkHandler({\n editor,\n onSetLink,\n })\n\n return {\n isVisible,\n canSet,\n isActive,\n label: \"Link\",\n Icon: LinkIcon,\n ...linkHandler,\n }\n}\n","\"use client\"\n\nimport * as React from \"react\"\n\n// --- Lib ---\nimport { parseShortcutKeys } from \"@/lib/tiptap-utils\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Tiptap UI ---\nimport type { Mark, UseMarkConfig } from \"@/components/tiptap-ui/mark-button\"\nimport { MARK_SHORTCUT_KEYS, useMark } from \"@/components/tiptap-ui/mark-button\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button } from \"@/components/tiptap-ui-primitive/button\"\nimport { Badge } from \"@/components/tiptap-ui-primitive/badge\"\n\nexport interface MarkButtonProps\n extends Omit<ButtonProps, \"type\">,\n UseMarkConfig {\n /**\n * Optional text to display alongside the icon.\n */\n text?: string\n /**\n * Optional show shortcut keys in the button.\n * @default false\n */\n showShortcut?: boolean\n}\n\nexport function MarkShortcutBadge({\n type,\n shortcutKeys = MARK_SHORTCUT_KEYS[type],\n}: {\n type: Mark\n shortcutKeys?: string\n}) {\n return <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge>\n}\n\n/**\n * Button component for toggling marks in a Tiptap editor.\n *\n * For custom button implementations, use the `useMark` hook instead.\n */\nexport const MarkButton = React.forwardRef<HTMLButtonElement, MarkButtonProps>(\n (\n {\n editor: providedEditor,\n type,\n text,\n hideWhenUnavailable = false,\n onToggled,\n showShortcut = false,\n onClick,\n children,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const {\n isVisible,\n handleMark,\n label,\n canToggle,\n isActive,\n Icon,\n shortcutKeys,\n } = useMark({\n editor,\n type,\n hideWhenUnavailable,\n onToggled,\n })\n\n const handleClick = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented) return\n handleMark()\n },\n [handleMark, onClick]\n )\n\n if (!isVisible) {\n return null\n }\n\n return (\n <Button\n type=\"button\"\n disabled={!canToggle}\n data-style=\"ghost\"\n data-active-state={isActive ? \"on\" : \"off\"}\n data-disabled={!canToggle}\n role=\"button\"\n tabIndex={-1}\n aria-label={label}\n aria-pressed={isActive}\n tooltip={label}\n onClick={handleClick}\n {...buttonProps}\n ref={ref}\n >\n {children ?? (\n <>\n <Icon className=\"tiptap-button-icon\" />\n {text && <span className=\"tiptap-button-text\">{text}</span>}\n {showShortcut && (\n <MarkShortcutBadge type={type} shortcutKeys={shortcutKeys} />\n )}\n </>\n )}\n </Button>\n )\n }\n)\n\nMarkButton.displayName = \"MarkButton\"\n","import * as React from \"react\"\n\nexport const BoldIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M6 2.5C5.17157 2.5 4.5 3.17157 4.5 4V20C4.5 20.8284 5.17157 21.5 6 21.5H15C16.4587 21.5 17.8576 20.9205 18.8891 19.8891C19.9205 18.8576 20.5 17.4587 20.5 16C20.5 14.5413 19.9205 13.1424 18.8891 12.1109C18.6781 11.9 18.4518 11.7079 18.2128 11.5359C19.041 10.5492 19.5 9.29829 19.5 8C19.5 6.54131 18.9205 5.14236 17.8891 4.11091C16.8576 3.07946 15.4587 2.5 14 2.5H6ZM14 10.5C14.663 10.5 15.2989 10.2366 15.7678 9.76777C16.2366 9.29893 16.5 8.66304 16.5 8C16.5 7.33696 16.2366 6.70107 15.7678 6.23223C15.2989 5.76339 14.663 5.5 14 5.5H7.5V10.5H14ZM7.5 18.5V13.5H15C15.663 13.5 16.2989 13.7634 16.7678 14.2322C17.2366 14.7011 17.5 15.337 17.5 16C17.5 16.663 17.2366 17.2989 16.7678 17.7678C16.2989 18.2366 15.663 18.5 15 18.5H7.5Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nBoldIcon.displayName = \"BoldIcon\"\n","import * as React from \"react\"\n\nexport const Code2Icon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M15.4545 4.2983C15.6192 3.77115 15.3254 3.21028 14.7983 3.04554C14.2712 2.88081 13.7103 3.1746 13.5455 3.70175L8.54554 19.7017C8.38081 20.2289 8.6746 20.7898 9.20175 20.9545C9.72889 21.1192 10.2898 20.8254 10.4545 20.2983L15.4545 4.2983Z\"\n fill=\"currentColor\"\n />\n <path\n d=\"M6.70711 7.29289C7.09763 7.68342 7.09763 8.31658 6.70711 8.70711L3.41421 12L6.70711 15.2929C7.09763 15.6834 7.09763 16.3166 6.70711 16.7071C6.31658 17.0976 5.68342 17.0976 5.29289 16.7071L1.29289 12.7071C0.902369 12.3166 0.902369 11.6834 1.29289 11.2929L5.29289 7.29289C5.68342 6.90237 6.31658 6.90237 6.70711 7.29289Z\"\n fill=\"currentColor\"\n />\n <path\n d=\"M17.2929 7.29289C17.6834 6.90237 18.3166 6.90237 18.7071 7.29289L22.7071 11.2929C23.0976 11.6834 23.0976 12.3166 22.7071 12.7071L18.7071 16.7071C18.3166 17.0976 17.6834 17.0976 17.2929 16.7071C16.9024 16.3166 16.9024 15.6834 17.2929 15.2929L20.5858 12L17.2929 8.70711C16.9024 8.31658 16.9024 7.68342 17.2929 7.29289Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nCode2Icon.displayName = \"Code2Icon\"\n","import * as React from \"react\"\n\nexport const ItalicIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M15.0222 3H19C19.5523 3 20 3.44772 20 4C20 4.55228 19.5523 5 19 5H15.693L10.443 19H14C14.5523 19 15 19.4477 15 20C15 20.5523 14.5523 21 14 21H9.02418C9.00802 21.0004 8.99181 21.0004 8.97557 21H5C4.44772 21 4 20.5523 4 20C4 19.4477 4.44772 19 5 19H8.30704L13.557 5H10C9.44772 5 9 4.55228 9 4C9 3.44772 9.44772 3 10 3H14.9782C14.9928 2.99968 15.0075 2.99967 15.0222 3Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nItalicIcon.displayName = \"ItalicIcon\"\n","import * as React from \"react\"\n\nexport const StrikeIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M9.00039 3H16.0001C16.5524 3 17.0001 3.44772 17.0001 4C17.0001 4.55229 16.5524 5 16.0001 5H9.00011C8.68006 4.99983 8.36412 5.07648 8.07983 5.22349C7.79555 5.37051 7.55069 5.5836 7.36585 5.84487C7.181 6.10614 7.06155 6.40796 7.01754 6.72497C6.97352 7.04198 7.00623 7.36492 7.11292 7.66667C7.29701 8.18737 7.02414 8.75872 6.50344 8.94281C5.98274 9.1269 5.4114 8.85403 5.2273 8.33333C5.01393 7.72984 4.94851 7.08396 5.03654 6.44994C5.12456 5.81592 5.36346 5.21229 5.73316 4.68974C6.10285 4.1672 6.59256 3.74101 7.16113 3.44698C7.72955 3.15303 8.36047 2.99975 9.00039 3Z\"\n fill=\"currentColor\"\n />\n <path\n d=\"M18 13H20C20.5523 13 21 12.5523 21 12C21 11.4477 20.5523 11 20 11H4C3.44772 11 3 11.4477 3 12C3 12.5523 3.44772 13 4 13H14C14.7956 13 15.5587 13.3161 16.1213 13.8787C16.6839 14.4413 17 15.2044 17 16C17 16.7956 16.6839 17.5587 16.1213 18.1213C15.5587 18.6839 14.7956 19 14 19H6C5.44772 19 5 19.4477 5 20C5 20.5523 5.44772 21 6 21H14C15.3261 21 16.5979 20.4732 17.5355 19.5355C18.4732 18.5979 19 17.3261 19 16C19 14.9119 18.6453 13.8604 18 13Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nStrikeIcon.displayName = \"StrikeIcon\"\n","import * as React from \"react\"\n\nexport const SubscriptIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M3.29289 7.29289C3.68342 6.90237 4.31658 6.90237 4.70711 7.29289L12.7071 15.2929C13.0976 15.6834 13.0976 16.3166 12.7071 16.7071C12.3166 17.0976 11.6834 17.0976 11.2929 16.7071L3.29289 8.70711C2.90237 8.31658 2.90237 7.68342 3.29289 7.29289Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M12.7071 7.29289C13.0976 7.68342 13.0976 8.31658 12.7071 8.70711L4.70711 16.7071C4.31658 17.0976 3.68342 17.0976 3.29289 16.7071C2.90237 16.3166 2.90237 15.6834 3.29289 15.2929L11.2929 7.29289C11.6834 6.90237 12.3166 6.90237 12.7071 7.29289Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M17.4079 14.3995C18.0284 14.0487 18.7506 13.9217 19.4536 14.0397C20.1566 14.1578 20.7977 14.5138 21.2696 15.0481L21.2779 15.0574L21.2778 15.0575C21.7439 15.5988 22 16.2903 22 17C22 18.0823 21.3962 18.8401 20.7744 19.3404C20.194 19.8073 19.4858 20.141 18.9828 20.378C18.9638 20.387 18.9451 20.3958 18.9266 20.4045C18.4473 20.6306 18.2804 20.7817 18.1922 20.918C18.1773 20.9412 18.1619 20.9681 18.1467 21H21C21.5523 21 22 21.4477 22 22C22 22.5523 21.5523 23 21 23H17C16.4477 23 16 22.5523 16 22C16 21.1708 16.1176 20.4431 16.5128 19.832C16.9096 19.2184 17.4928 18.8695 18.0734 18.5956C18.6279 18.334 19.138 18.0901 19.5207 17.7821C19.8838 17.49 20 17.2477 20 17C20 16.7718 19.9176 16.5452 19.7663 16.3672C19.5983 16.1792 19.3712 16.0539 19.1224 16.0121C18.8722 15.9701 18.6152 16.015 18.3942 16.1394C18.1794 16.2628 18.0205 16.4549 17.9422 16.675C17.7572 17.1954 17.1854 17.4673 16.665 17.2822C16.1446 17.0972 15.8728 16.5254 16.0578 16.005C16.2993 15.3259 16.7797 14.7584 17.4039 14.4018L17.4079 14.3995L17.4079 14.3995Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nSubscriptIcon.displayName = \"SubscriptIcon\"\n","import * as React from \"react\"\n\nexport const SuperscriptIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M12.7071 7.29289C13.0976 7.68342 13.0976 8.31658 12.7071 8.70711L4.70711 16.7071C4.31658 17.0976 3.68342 17.0976 3.29289 16.7071C2.90237 16.3166 2.90237 15.6834 3.29289 15.2929L11.2929 7.29289C11.6834 6.90237 12.3166 6.90237 12.7071 7.29289Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M3.29289 7.29289C3.68342 6.90237 4.31658 6.90237 4.70711 7.29289L12.7071 15.2929C13.0976 15.6834 13.0976 16.3166 12.7071 16.7071C12.3166 17.0976 11.6834 17.0976 11.2929 16.7071L3.29289 8.70711C2.90237 8.31658 2.90237 7.68342 3.29289 7.29289Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M17.405 1.40657C18.0246 1.05456 18.7463 0.92634 19.4492 1.04344C20.1521 1.16054 20.7933 1.51583 21.2652 2.0497L21.2697 2.05469L21.2696 2.05471C21.7431 2.5975 22 3.28922 22 4.00203C22 5.08579 21.3952 5.84326 20.7727 6.34289C20.1966 6.80531 19.4941 7.13675 18.9941 7.37261C18.9714 7.38332 18.9491 7.39383 18.9273 7.40415C18.4487 7.63034 18.2814 7.78152 18.1927 7.91844C18.1778 7.94155 18.1625 7.96834 18.1473 8.00003H21C21.5523 8.00003 22 8.44774 22 9.00003C22 9.55231 21.5523 10 21 10H17C16.4477 10 16 9.55231 16 9.00003C16 8.17007 16.1183 7.44255 16.5138 6.83161C16.9107 6.21854 17.4934 5.86971 18.0728 5.59591C18.6281 5.33347 19.1376 5.09075 19.5208 4.78316C19.8838 4.49179 20 4.25026 20 4.00203C20 3.77192 19.9178 3.54865 19.7646 3.37182C19.5968 3.18324 19.3696 3.05774 19.1205 3.01625C18.8705 2.97459 18.6137 3.02017 18.3933 3.14533C18.1762 3.26898 18.0191 3.45826 17.9406 3.67557C17.7531 4.19504 17.18 4.46414 16.6605 4.27662C16.141 4.0891 15.8719 3.51596 16.0594 2.99649C16.303 2.3219 16.7817 1.76125 17.4045 1.40689L17.405 1.40657Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nSuperscriptIcon.displayName = \"SuperscriptIcon\"\n","import * as React from \"react\"\n\nexport const UnderlineIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M7 4C7 3.44772 6.55228 3 6 3C5.44772 3 5 3.44772 5 4V10C5 11.8565 5.7375 13.637 7.05025 14.9497C8.36301 16.2625 10.1435 17 12 17C13.8565 17 15.637 16.2625 16.9497 14.9497C18.2625 13.637 19 11.8565 19 10V4C19 3.44772 18.5523 3 18 3C17.4477 3 17 3.44772 17 4V10C17 11.3261 16.4732 12.5979 15.5355 13.5355C14.5979 14.4732 13.3261 15 12 15C10.6739 15 9.40215 14.4732 8.46447 13.5355C7.52678 12.5979 7 11.3261 7 10V4ZM4 19C3.44772 19 3 19.4477 3 20C3 20.5523 3.44772 21 4 21H20C20.5523 21 21 20.5523 21 20C21 19.4477 20.5523 19 20 19H4Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nUnderlineIcon.displayName = \"UnderlineIcon\"\n","import * as React from \"react\"\nimport type { Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Lib ---\nimport { isMarkInSchema, isNodeTypeSelected } from \"@/lib/tiptap-utils\"\n\n// --- Icons ---\nimport { BoldIcon } from \"@/components/tiptap-icons/bold-icon\"\nimport { Code2Icon } from \"@/components/tiptap-icons/code2-icon\"\nimport { ItalicIcon } from \"@/components/tiptap-icons/italic-icon\"\nimport { StrikeIcon } from \"@/components/tiptap-icons/strike-icon\"\nimport { SubscriptIcon } from \"@/components/tiptap-icons/subscript-icon\"\nimport { SuperscriptIcon } from \"@/components/tiptap-icons/superscript-icon\"\nimport { UnderlineIcon } from \"@/components/tiptap-icons/underline-icon\"\n\nexport type Mark =\n | \"bold\"\n | \"italic\"\n | \"strike\"\n | \"code\"\n | \"underline\"\n | \"superscript\"\n | \"subscript\"\n\n/**\n * Configuration for the mark functionality\n */\nexport interface UseMarkConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * The type of mark to toggle\n */\n type: Mark\n /**\n * Whether the button should hide when mark is not available.\n * @default false\n */\n hideWhenUnavailable?: boolean\n /**\n * Callback function called after a successful mark toggle.\n */\n onToggled?: () => void\n}\n\nexport const markIcons = {\n bold: BoldIcon,\n italic: ItalicIcon,\n underline: UnderlineIcon,\n strike: StrikeIcon,\n code: Code2Icon,\n superscript: SuperscriptIcon,\n subscript: SubscriptIcon,\n}\n\nexport const MARK_SHORTCUT_KEYS: Record<Mark, string> = {\n bold: \"mod+b\",\n italic: \"mod+i\",\n underline: \"mod+u\",\n strike: \"mod+shift+s\",\n code: \"mod+e\",\n superscript: \"mod+.\",\n subscript: \"mod+,\",\n}\n\n/**\n * Checks if a mark can be toggled in the current editor state\n */\nexport function canToggleMark(editor: Editor | null, type: Mark): boolean {\n if (!editor || !editor.isEditable) return false\n if (!isMarkInSchema(type, editor) || isNodeTypeSelected(editor, [\"image\"]))\n return false\n\n return editor.can().toggleMark(type)\n}\n\n/**\n * Checks if a mark is currently active\n */\nexport function isMarkActive(editor: Editor | null, type: Mark): boolean {\n if (!editor || !editor.isEditable) return false\n return editor.isActive(type)\n}\n\n/**\n * Toggles a mark in the editor\n */\nexport function toggleMark(editor: Editor | null, type: Mark): boolean {\n if (!editor || !editor.isEditable) return false\n if (!canToggleMark(editor, type)) return false\n\n return editor.chain().focus().toggleMark(type).run()\n}\n\n/**\n * Determines if the mark button should be shown\n */\nexport function shouldShowButton(props: {\n editor: Editor | null\n type: Mark\n hideWhenUnavailable: boolean\n}): boolean {\n const { editor, type, hideWhenUnavailable } = props\n\n if (!editor || !editor.isEditable) return false\n if (!isMarkInSchema(type, editor)) return false\n\n if (hideWhenUnavailable && !editor.isActive(\"code\")) {\n return canToggleMark(editor, type)\n }\n\n return true\n}\n\n/**\n * Gets the formatted mark name\n */\nexport function getFormattedMarkName(type: Mark): string {\n return type.charAt(0).toUpperCase() + type.slice(1)\n}\n\n/**\n * Custom hook that provides mark functionality for Tiptap editor\n *\n * @example\n * ```tsx\n * // Simple usage\n * function MySimpleBoldButton() {\n * const { isVisible, handleMark } = useMark({ type: \"bold\" })\n *\n * if (!isVisible) return null\n *\n * return <button onClick={handleMark}>Bold</button>\n * }\n *\n * // Advanced usage with configuration\n * function MyAdvancedItalicButton() {\n * const { isVisible, handleMark, label, isActive } = useMark({\n * editor: myEditor,\n * type: \"italic\",\n * hideWhenUnavailable: true,\n * onToggled: () => console.log('Mark toggled!')\n * })\n *\n * if (!isVisible) return null\n *\n * return (\n * <MyButton\n * onClick={handleMark}\n * aria-pressed={isActive}\n * aria-label={label}\n * >\n * Italic\n * </MyButton>\n * )\n * }\n * ```\n */\nexport function useMark(config: UseMarkConfig) {\n const {\n editor: providedEditor,\n type,\n hideWhenUnavailable = false,\n onToggled,\n } = config\n\n const { editor } = useTiptapEditor(providedEditor)\n const [isVisible, setIsVisible] = React.useState<boolean>(true)\n const canToggle = canToggleMark(editor, type)\n const isActive = isMarkActive(editor, type)\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleSelectionUpdate = () => {\n setIsVisible(shouldShowButton({ editor, type, hideWhenUnavailable }))\n }\n\n handleSelectionUpdate()\n\n editor.on(\"selectionUpdate\", handleSelectionUpdate)\n\n return () => {\n editor.off(\"selectionUpdate\", handleSelectionUpdate)\n }\n }, [editor, type, hideWhenUnavailable])\n\n const handleMark = React.useCallback(() => {\n if (!editor) return false\n\n const success = toggleMark(editor, type)\n if (success) {\n onToggled?.()\n }\n return success\n }, [editor, type, onToggled])\n\n return {\n isVisible,\n isActive,\n handleMark,\n canToggle,\n label: getFormattedMarkName(type),\n shortcutKeys: MARK_SHORTCUT_KEYS[type],\n Icon: markIcons[type],\n }\n}\n","\"use client\"\n\nimport * as React from \"react\"\n\n// --- Lib ---\nimport { parseShortcutKeys } from \"@/lib/tiptap-utils\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Tiptap UI ---\nimport type {\n TextAlign,\n UseTextAlignConfig,\n} from \"@/components/tiptap-ui/text-align-button\"\nimport {\n TEXT_ALIGN_SHORTCUT_KEYS,\n useTextAlign,\n} from \"@/components/tiptap-ui/text-align-button\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button } from \"@/components/tiptap-ui-primitive/button\"\nimport { Badge } from \"@/components/tiptap-ui-primitive/badge\"\n\ntype IconProps = React.SVGProps<SVGSVGElement>\ntype IconComponent = ({ className, ...props }: IconProps) => React.ReactElement\n\nexport interface TextAlignButtonProps\n extends Omit<ButtonProps, \"type\">,\n UseTextAlignConfig {\n /**\n * Optional text to display alongside the icon.\n */\n text?: string\n /**\n * Optional show shortcut keys in the button.\n * @default false\n */\n showShortcut?: boolean\n /**\n * Optional custom icon component to render instead of the default.\n */\n icon?: React.MemoExoticComponent<IconComponent> | React.FC<IconProps>\n}\n\nexport function TextAlignShortcutBadge({\n align,\n shortcutKeys = TEXT_ALIGN_SHORTCUT_KEYS[align],\n}: {\n align: TextAlign\n shortcutKeys?: string\n}) {\n return <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge>\n}\n\n/**\n * Button component for setting text alignment in a Tiptap editor.\n *\n * For custom button implementations, use the `useTextAlign` hook instead.\n */\nexport const TextAlignButton = React.forwardRef<\n HTMLButtonElement,\n TextAlignButtonProps\n>(\n (\n {\n editor: providedEditor,\n align,\n text,\n hideWhenUnavailable = false,\n onAligned,\n showShortcut = false,\n onClick,\n icon: CustomIcon,\n children,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const {\n isVisible,\n handleTextAlign,\n label,\n canAlign,\n isActive,\n Icon,\n shortcutKeys,\n } = useTextAlign({\n editor,\n align,\n hideWhenUnavailable,\n onAligned,\n })\n\n const handleClick = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented) return\n handleTextAlign()\n },\n [handleTextAlign, onClick]\n )\n\n if (!isVisible) {\n return null\n }\n\n const RenderIcon = CustomIcon ?? Icon\n\n return (\n <Button\n type=\"button\"\n disabled={!canAlign}\n data-style=\"ghost\"\n data-active-state={isActive ? \"on\" : \"off\"}\n data-disabled={!canAlign}\n role=\"button\"\n tabIndex={-1}\n aria-label={label}\n aria-pressed={isActive}\n tooltip={label}\n onClick={handleClick}\n {...buttonProps}\n ref={ref}\n >\n {children ?? (\n <>\n <RenderIcon className=\"tiptap-button-icon\" />\n {text && <span className=\"tiptap-button-text\">{text}</span>}\n {showShortcut && (\n <TextAlignShortcutBadge\n align={align}\n shortcutKeys={shortcutKeys}\n />\n )}\n </>\n )}\n </Button>\n )\n }\n)\n\nTextAlignButton.displayName = \"TextAlignButton\"\n","import * as React from \"react\"\n\nexport const AlignCenterIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M6 12C6 11.4477 6.44772 11 7 11H17C17.5523 11 18 11.4477 18 12C18 12.5523 17.5523 13 17 13H7C6.44772 13 6 12.5523 6 12Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M4 18C4 17.4477 4.44772 17 5 17H19C19.5523 17 20 17.4477 20 18C20 18.5523 19.5523 19 19 19H5C4.44772 19 4 18.5523 4 18Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nAlignCenterIcon.displayName = \"AlignCenterIcon\"\n","import * as React from \"react\"\n\nexport const AlignJustifyIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 12C2 11.4477 2.44772 11 3 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H3C2.44772 13 2 12.5523 2 12Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 18C2 17.4477 2.44772 17 3 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H3C2.44772 19 2 18.5523 2 18Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nAlignJustifyIcon.displayName = \"AlignJustifyIcon\"\n","import * as React from \"react\"\n\nexport const AlignLeftIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 12C2 11.4477 2.44772 11 3 11H15C15.5523 11 16 11.4477 16 12C16 12.5523 15.5523 13 15 13H3C2.44772 13 2 12.5523 2 12Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 18C2 17.4477 2.44772 17 3 17H17C17.5523 17 18 17.4477 18 18C18 18.5523 17.5523 19 17 19H3C2.44772 19 2 18.5523 2 18Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nAlignLeftIcon.displayName = \"AlignLeftIcon\"\n","import * as React from \"react\"\n\nexport const AlignRightIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M8 12C8 11.4477 8.44772 11 9 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H9C8.44772 13 8 12.5523 8 12Z\"\n fill=\"currentColor\"\n />\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M6 18C6 17.4477 6.44772 17 7 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H7C6.44772 19 6 18.5523 6 18Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nAlignRightIcon.displayName = \"AlignRightIcon\"\n","import * as React from \"react\"\nimport type { ChainedCommands } from \"@tiptap/react\"\nimport { type Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Lib ---\nimport {\n isExtensionAvailable,\n isNodeTypeSelected,\n} from \"@/lib/tiptap-utils\"\n\n// --- Icons ---\nimport { AlignCenterIcon } from \"@/components/tiptap-icons/align-center-icon\"\nimport { AlignJustifyIcon } from \"@/components/tiptap-icons/align-justify-icon\"\nimport { AlignLeftIcon } from \"@/components/tiptap-icons/align-left-icon\"\nimport { AlignRightIcon } from \"@/components/tiptap-icons/align-right-icon\"\n\nexport type TextAlign = \"left\" | \"center\" | \"right\" | \"justify\"\n\n/**\n * Configuration for the text align functionality\n */\nexport interface UseTextAlignConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * The text alignment to apply.\n */\n align: TextAlign\n /**\n * Whether the button should hide when alignment is not available.\n * @default false\n */\n hideWhenUnavailable?: boolean\n /**\n * Callback function called after a successful alignment change.\n */\n onAligned?: () => void\n}\n\nexport const TEXT_ALIGN_SHORTCUT_KEYS: Record<TextAlign, string> = {\n left: \"mod+shift+l\",\n center: \"mod+shift+e\",\n right: \"mod+shift+r\",\n justify: \"mod+shift+j\",\n}\n\nexport const textAlignIcons = {\n left: AlignLeftIcon,\n center: AlignCenterIcon,\n right: AlignRightIcon,\n justify: AlignJustifyIcon,\n}\n\nexport const textAlignLabels: Record<TextAlign, string> = {\n left: \"Align left\",\n center: \"Align center\",\n right: \"Align right\",\n justify: \"Align justify\",\n}\n\n/**\n * Checks if text alignment can be performed in the current editor state\n */\nexport function canSetTextAlign(\n editor: Editor | null,\n align: TextAlign\n): boolean {\n if (!editor || !editor.isEditable) return false\n if (\n !isExtensionAvailable(editor, \"textAlign\") ||\n isNodeTypeSelected(editor, [\"image\"])\n )\n return false\n\n return editor.can().setTextAlign(align)\n}\n\nexport function hasSetTextAlign(\n commands: ChainedCommands\n): commands is ChainedCommands & {\n setTextAlign: (align: TextAlign) => ChainedCommands\n} {\n return \"setTextAlign\" in commands\n}\n\n/**\n * Checks if the text alignment is currently active\n */\nexport function isTextAlignActive(\n editor: Editor | null,\n align: TextAlign\n): boolean {\n if (!editor || !editor.isEditable) return false\n return editor.isActive({ textAlign: align })\n}\n\n/**\n * Sets text alignment in the editor\n */\nexport function setTextAlign(editor: Editor | null, align: TextAlign): boolean {\n if (!editor || !editor.isEditable) return false\n if (!canSetTextAlign(editor, align)) return false\n\n const chain = editor.chain().focus()\n if (hasSetTextAlign(chain)) {\n return chain.setTextAlign(align).run()\n }\n\n return false\n}\n\n/**\n * Determines if the text align button should be shown\n */\nexport function shouldShowButton(props: {\n editor: Editor | null\n hideWhenUnavailable: boolean\n align: TextAlign\n}): boolean {\n const { editor, hideWhenUnavailable, align } = props\n\n if (!editor || !editor.isEditable) return false\n if (!isExtensionAvailable(editor, \"textAlign\")) return false\n\n if (hideWhenUnavailable && !editor.isActive(\"code\")) {\n return canSetTextAlign(editor, align)\n }\n\n return true\n}\n\n/**\n * Custom hook that provides text align functionality for Tiptap editor\n *\n * @example\n * ```tsx\n * // Simple usage\n * function MySimpleAlignButton() {\n * const { isVisible, handleTextAlign } = useTextAlign({ align: \"center\" })\n *\n * if (!isVisible) return null\n *\n * return <button onClick={handleTextAlign}>Align Center</button>\n * }\n *\n * // Advanced usage with configuration\n * function MyAdvancedAlignButton() {\n * const { isVisible, handleTextAlign, label, isActive } = useTextAlign({\n * editor: myEditor,\n * align: \"right\",\n * hideWhenUnavailable: true,\n * onAligned: () => console.log('Text aligned!')\n * })\n *\n * if (!isVisible) return null\n *\n * return (\n * <MyButton\n * onClick={handleTextAlign}\n * aria-pressed={isActive}\n * aria-label={label}\n * >\n * Align Right\n * </MyButton>\n * )\n * }\n * ```\n */\nexport function useTextAlign(config: UseTextAlignConfig) {\n const {\n editor: providedEditor,\n align,\n hideWhenUnavailable = false,\n onAligned,\n } = config\n\n const { editor } = useTiptapEditor(providedEditor)\n const [isVisible, setIsVisible] = React.useState<boolean>(true)\n const canAlign = canSetTextAlign(editor, align)\n const isActive = isTextAlignActive(editor, align)\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleSelectionUpdate = () => {\n setIsVisible(shouldShowButton({ editor, align, hideWhenUnavailable }))\n }\n\n handleSelectionUpdate()\n\n editor.on(\"selectionUpdate\", handleSelectionUpdate)\n\n return () => {\n editor.off(\"selectionUpdate\", handleSelectionUpdate)\n }\n }, [editor, hideWhenUnavailable, align])\n\n const handleTextAlign = React.useCallback(() => {\n if (!editor) return false\n\n const success = setTextAlign(editor, align)\n if (success) {\n onAligned?.()\n }\n return success\n }, [editor, align, onAligned])\n\n return {\n isVisible,\n isActive,\n handleTextAlign,\n canAlign,\n label: textAlignLabels[align],\n shortcutKeys: TEXT_ALIGN_SHORTCUT_KEYS[align],\n Icon: textAlignIcons[align],\n }\n}\n","\"use client\"\n\nimport * as React from \"react\"\n\n// --- Lib ---\nimport { parseShortcutKeys } from \"@/lib/tiptap-utils\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Tiptap UI ---\nimport type {\n UndoRedoAction,\n UseUndoRedoConfig,\n} from \"@/components/tiptap-ui/undo-redo-button\"\nimport {\n UNDO_REDO_SHORTCUT_KEYS,\n useUndoRedo,\n} from \"@/components/tiptap-ui/undo-redo-button\"\n\n// --- UI Primitives ---\nimport type { ButtonProps } from \"@/components/tiptap-ui-primitive/button\"\nimport { Button } from \"@/components/tiptap-ui-primitive/button\"\nimport { Badge } from \"@/components/tiptap-ui-primitive/badge\"\n\nexport interface UndoRedoButtonProps\n extends Omit<ButtonProps, \"type\">,\n UseUndoRedoConfig {\n /**\n * Optional text to display alongside the icon.\n */\n text?: string\n /**\n * Optional show shortcut keys in the button.\n * @default false\n */\n showShortcut?: boolean\n}\n\nexport function HistoryShortcutBadge({\n action,\n shortcutKeys = UNDO_REDO_SHORTCUT_KEYS[action],\n}: {\n action: UndoRedoAction\n shortcutKeys?: string\n}) {\n return <Badge>{parseShortcutKeys({ shortcutKeys })}</Badge>\n}\n\n/**\n * Button component for triggering undo/redo actions in a Tiptap editor.\n *\n * For custom button implementations, use the `useHistory` hook instead.\n */\nexport const UndoRedoButton = React.forwardRef<\n HTMLButtonElement,\n UndoRedoButtonProps\n>(\n (\n {\n editor: providedEditor,\n action,\n text,\n hideWhenUnavailable = false,\n onExecuted,\n showShortcut = false,\n onClick,\n children,\n ...buttonProps\n },\n ref\n ) => {\n const { editor } = useTiptapEditor(providedEditor)\n const { isVisible, handleAction, label, canExecute, Icon, shortcutKeys } =\n useUndoRedo({\n editor,\n action,\n hideWhenUnavailable,\n onExecuted,\n })\n\n const handleClick = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(event)\n if (event.defaultPrevented) return\n handleAction()\n },\n [handleAction, onClick]\n )\n\n if (!isVisible) {\n return null\n }\n\n return (\n <Button\n type=\"button\"\n disabled={!canExecute}\n data-style=\"ghost\"\n data-disabled={!canExecute}\n role=\"button\"\n tabIndex={-1}\n aria-label={label}\n tooltip={label}\n onClick={handleClick}\n {...buttonProps}\n ref={ref}\n >\n {children ?? (\n <>\n <Icon className=\"tiptap-button-icon\" />\n {text && <span className=\"tiptap-button-text\">{text}</span>}\n {showShortcut && (\n <HistoryShortcutBadge\n action={action}\n shortcutKeys={shortcutKeys}\n />\n )}\n </>\n )}\n </Button>\n )\n }\n)\n\nUndoRedoButton.displayName = \"UndoRedoButton\"\n","import * as React from \"react\"\n\nexport const Redo2Icon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M15.7071 2.29289C15.3166 1.90237 14.6834 1.90237 14.2929 2.29289C13.9024 2.68342 13.9024 3.31658 14.2929 3.70711L17.5858 7H9.5C7.77609 7 6.12279 7.68482 4.90381 8.90381C3.68482 10.1228 3 11.7761 3 13.5C3 14.3536 3.16813 15.1988 3.49478 15.9874C3.82144 16.7761 4.30023 17.4926 4.90381 18.0962C6.12279 19.3152 7.77609 20 9.5 20H13C13.5523 20 14 19.5523 14 19C14 18.4477 13.5523 18 13 18H9.5C8.30653 18 7.16193 17.5259 6.31802 16.682C5.90016 16.2641 5.56869 15.768 5.34254 15.2221C5.1164 14.6761 5 14.0909 5 13.5C5 12.3065 5.47411 11.1619 6.31802 10.318C7.16193 9.47411 8.30653 9 9.5 9H17.5858L14.2929 12.2929C13.9024 12.6834 13.9024 13.3166 14.2929 13.7071C14.6834 14.0976 15.3166 14.0976 15.7071 13.7071L20.7071 8.70711C21.0976 8.31658 21.0976 7.68342 20.7071 7.29289L15.7071 2.29289Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nRedo2Icon.displayName = \"Redo2Icon\"\n","import * as React from \"react\"\n\nexport const Undo2Icon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M9.70711 3.70711C10.0976 3.31658 10.0976 2.68342 9.70711 2.29289C9.31658 1.90237 8.68342 1.90237 8.29289 2.29289L3.29289 7.29289C2.90237 7.68342 2.90237 8.31658 3.29289 8.70711L8.29289 13.7071C8.68342 14.0976 9.31658 14.0976 9.70711 13.7071C10.0976 13.3166 10.0976 12.6834 9.70711 12.2929L6.41421 9H14.5C15.0909 9 15.6761 9.1164 16.2221 9.34254C16.768 9.56869 17.2641 9.90016 17.682 10.318C18.0998 10.7359 18.4313 11.232 18.6575 11.7779C18.8836 12.3239 19 12.9091 19 13.5C19 14.0909 18.8836 14.6761 18.6575 15.2221C18.4313 15.768 18.0998 16.2641 17.682 16.682C17.2641 17.0998 16.768 17.4313 16.2221 17.6575C15.6761 17.8836 15.0909 18 14.5 18H11C10.4477 18 10 18.4477 10 19C10 19.5523 10.4477 20 11 20H14.5C15.3536 20 16.1988 19.8319 16.9874 19.5052C17.7761 19.1786 18.4926 18.6998 19.0962 18.0962C19.6998 17.4926 20.1786 16.7761 20.5052 15.9874C20.8319 15.1988 21 14.3536 21 13.5C21 12.6464 20.8319 11.8012 20.5052 11.0126C20.1786 10.2239 19.6998 9.50739 19.0962 8.90381C18.4926 8.30022 17.7761 7.82144 16.9874 7.49478C16.1988 7.16813 15.3536 7 14.5 7H6.41421L9.70711 3.70711Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nUndo2Icon.displayName = \"Undo2Icon\"\n","import * as React from \"react\"\nimport { type Editor } from \"@tiptap/react\"\n\n// --- Hooks ---\nimport { useTiptapEditor } from \"@/hooks/use-tiptap-editor\"\n\n// --- Lib ---\nimport { isNodeTypeSelected } from \"@/lib/tiptap-utils\"\n\n// --- Icons ---\nimport { Redo2Icon } from \"@/components/tiptap-icons/redo2-icon\"\nimport { Undo2Icon } from \"@/components/tiptap-icons/undo2-icon\"\n\nexport type UndoRedoAction = \"undo\" | \"redo\"\n\n/**\n * Configuration for the history functionality\n */\nexport interface UseUndoRedoConfig {\n /**\n * The Tiptap editor instance.\n */\n editor?: Editor | null\n /**\n * The history action to perform (undo or redo).\n */\n action: UndoRedoAction\n /**\n * Whether the button should hide when action is not available.\n * @default false\n */\n hideWhenUnavailable?: boolean\n /**\n * Callback function called after a successful action execution.\n */\n onExecuted?: () => void\n}\n\nexport const UNDO_REDO_SHORTCUT_KEYS: Record<UndoRedoAction, string> = {\n undo: \"mod+z\",\n redo: \"mod+shift+z\",\n}\n\nexport const historyActionLabels: Record<UndoRedoAction, string> = {\n undo: \"Undo\",\n redo: \"Redo\",\n}\n\nexport const historyIcons = {\n undo: Undo2Icon,\n redo: Redo2Icon,\n}\n\n/**\n * Checks if a history action can be executed\n */\nexport function canExecuteUndoRedoAction(\n editor: Editor | null,\n action: UndoRedoAction\n): boolean {\n if (!editor || !editor.isEditable) return false\n if (isNodeTypeSelected(editor, [\"image\"])) return false\n\n return action === \"undo\" ? editor.can().undo() : editor.can().redo()\n}\n\n/**\n * Executes a history action on the editor\n */\nexport function executeUndoRedoAction(\n editor: Editor | null,\n action: UndoRedoAction\n): boolean {\n if (!editor || !editor.isEditable) return false\n if (!canExecuteUndoRedoAction(editor, action)) return false\n\n const chain = editor.chain().focus()\n return action === \"undo\" ? chain.undo().run() : chain.redo().run()\n}\n\n/**\n * Determines if the history button should be shown\n */\nexport function shouldShowButton(props: {\n editor: Editor | null\n hideWhenUnavailable: boolean\n action: UndoRedoAction\n}): boolean {\n const { editor, hideWhenUnavailable, action } = props\n\n if (!editor || !editor.isEditable) return false\n\n if (hideWhenUnavailable && !editor.isActive(\"code\")) {\n return canExecuteUndoRedoAction(editor, action)\n }\n\n return true\n}\n\n/**\n * Custom hook that provides history functionality for Tiptap editor\n *\n * @example\n * ```tsx\n * // Simple usage\n * function MySimpleUndoButton() {\n * const { isVisible, handleAction } = useHistory({ action: \"undo\" })\n *\n * if (!isVisible) return null\n *\n * return <button onClick={handleAction}>Undo</button>\n * }\n *\n * // Advanced usage with configuration\n * function MyAdvancedRedoButton() {\n * const { isVisible, handleAction, label } = useHistory({\n * editor: myEditor,\n * action: \"redo\",\n * hideWhenUnavailable: true,\n * onExecuted: () => console.log('Action executed!')\n * })\n *\n * if (!isVisible) return null\n *\n * return (\n * <MyButton\n * onClick={handleAction}\n * aria-label={label}\n * >\n * Redo\n * </MyButton>\n * )\n * }\n * ```\n */\nexport function useUndoRedo(config: UseUndoRedoConfig) {\n const {\n editor: providedEditor,\n action,\n hideWhenUnavailable = false,\n onExecuted,\n } = config\n\n const { editor } = useTiptapEditor(providedEditor)\n const [isVisible, setIsVisible] = React.useState<boolean>(true)\n const canExecute = canExecuteUndoRedoAction(editor, action)\n\n React.useEffect(() => {\n if (!editor) return\n\n const handleUpdate = () => {\n setIsVisible(shouldShowButton({ editor, hideWhenUnavailable, action }))\n }\n\n handleUpdate()\n\n editor.on(\"transaction\", handleUpdate)\n\n return () => {\n editor.off(\"transaction\", handleUpdate)\n }\n }, [editor, hideWhenUnavailable, action])\n\n const handleAction = React.useCallback(() => {\n if (!editor) return false\n\n const success = executeUndoRedoAction(editor, action)\n if (success) {\n onExecuted?.()\n }\n return success\n }, [editor, action, onExecuted])\n\n return {\n isVisible,\n handleAction,\n canExecute,\n label: historyActionLabels[action],\n shortcutKeys: UNDO_REDO_SHORTCUT_KEYS[action],\n Icon: historyIcons[action],\n }\n}\n","import * as React from \"react\"\n\nexport const ArrowLeftIcon = React.memo(\n ({ className, ...props }: React.SVGProps<SVGSVGElement>) => {\n return (\n <svg\n width=\"24\"\n height=\"24\"\n className={className}\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n xmlns=\"http://www.w3.org/2000/svg\"\n {...props}\n >\n <path\n d=\"M12.7071 5.70711C13.0976 5.31658 13.0976 4.68342 12.7071 4.29289C12.3166 3.90237 11.6834 3.90237 11.2929 4.29289L4.29289 11.2929C3.90237 11.6834 3.90237 12.3166 4.29289 12.7071L11.2929 19.7071C11.6834 20.0976 12.3166 20.0976 12.7071 19.7071C13.0976 19.3166 13.0976 18.6834 12.7071 18.2929L7.41421 13L19 13C19.5523 13 20 12.5523 20 12C20 11.4477 19.5523 11 19 11L7.41421 11L12.7071 5.70711Z\"\n fill=\"currentColor\"\n />\n </svg>\n )\n }\n)\n\nArrowLeftIcon.displayName = \"ArrowLeftIcon\"\n","import { useRef, useEffect } from \"react\"\n\n/**\n * Hook that executes a callback when the component unmounts.\n *\n * @param callback Function to be called on component unmount\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useUnmount = (callback: (...args: Array<any>) => any) => {\n const ref = useRef(callback)\n ref.current = callback\n\n useEffect(\n () => () => {\n ref.current()\n },\n []\n )\n}\n\nexport default useUnmount\n","import throttle from \"lodash.throttle\"\nimport * as React from \"react\"\nimport { useUnmount } from \"./use-unmount\"\n\ninterface ThrottleSettings {\n leading?: boolean | undefined\n trailing?: boolean | undefined\n}\n\nconst defaultOptions: ThrottleSettings = {\n leading: false,\n trailing: true,\n}\n\n/**\n * A hook that returns a throttled callback function.\n *\n * @param fn The function to throttle\n * @param wait The time in ms to wait before calling the function\n * @param dependencies The dependencies to watch for changes\n * @param options The throttle options\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useThrottledCallback<T extends (...args: any[]) => any>(\n fn: T,\n wait = 250,\n dependencies: React.DependencyList = [],\n options: ThrottleSettings = defaultOptions\n): {\n (this: ThisParameterType<T>, ...args: Parameters<T>): ReturnType<T>\n cancel: () => void\n flush: () => void\n} {\n const handler = React.useMemo(\n () => throttle<T>(fn, wait, options),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n dependencies\n )\n\n useUnmount(() => {\n handler.cancel()\n })\n\n return handler\n}\n\nexport default useThrottledCallback\n","\"use client\"\n\nimport * as React from \"react\"\nimport { useThrottledCallback } from \"./use-throttled-callback\"\n\nexport interface WindowSizeState {\n /**\n * The width of the window's visual viewport in pixels.\n */\n width: number\n /**\n * The height of the window's visual viewport in pixels.\n */\n height: number\n /**\n * The distance from the top of the visual viewport to the top of the layout viewport.\n * Particularly useful for handling mobile keyboard appearance.\n */\n offsetTop: number\n /**\n * The distance from the left of the visual viewport to the left of the layout viewport.\n */\n offsetLeft: number\n /**\n * The scale factor of the visual viewport.\n * This is useful for scaling elements based on the current zoom level.\n */\n scale: number\n}\n\n/**\n * Hook that tracks the window's visual viewport dimensions, position, and provides\n * a CSS transform for positioning elements.\n *\n * Uses the Visual Viewport API to get accurate measurements, especially important\n * for mobile devices where virtual keyboards can change the visible area.\n * Only updates state when values actually change to optimize performance.\n *\n * @returns An object containing viewport properties and a CSS transform string\n */\nexport function useWindowSize(): WindowSizeState {\n const [windowSize, setWindowSize] = React.useState<WindowSizeState>({\n width: 0,\n height: 0,\n offsetTop: 0,\n offsetLeft: 0,\n scale: 0,\n })\n\n const handleViewportChange = useThrottledCallback(() => {\n if (typeof window === \"undefined\") return\n\n const vp = window.visualViewport\n if (!vp) return\n\n const {\n width = 0,\n height = 0,\n offsetTop = 0,\n offsetLeft = 0,\n scale = 0,\n } = vp\n\n setWindowSize((prevState) => {\n if (\n width === prevState.width &&\n height === prevState.height &&\n offsetTop === prevState.offsetTop &&\n offsetLeft === prevState.offsetLeft &&\n scale === prevState.scale\n ) {\n return prevState\n }\n\n return { width, height, offsetTop, offsetLeft, scale }\n })\n }, 200)\n\n React.useEffect(() => {\n const visualViewport = window.visualViewport\n if (!visualViewport) return\n\n visualViewport.addEventListener(\"resize\", handleViewportChange)\n\n handleViewportChange()\n\n return () => {\n visualViewport.removeEventListener(\"resize\", handleViewportChange)\n }\n }, [handleViewportChange])\n\n return windowSize\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { useThrottledCallback } from \"./use-throttled-callback\"\n\nexport type RectState = Omit<DOMRect, \"toJSON\">\n\nexport interface ElementRectOptions {\n /**\n * The element to track. Can be an Element, ref, or selector string.\n * Defaults to document.body if not provided.\n */\n element?: Element | React.RefObject<Element> | string | null\n /**\n * Whether to enable rect tracking\n */\n enabled?: boolean\n /**\n * Throttle delay in milliseconds for rect updates\n */\n throttleMs?: number\n /**\n * Whether to use ResizeObserver for more accurate tracking\n */\n useResizeObserver?: boolean\n}\n\nconst initialRect: RectState = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n}\n\nconst isSSR = typeof window === \"undefined\"\nconst hasResizeObserver = !isSSR && typeof ResizeObserver !== \"undefined\"\n\n/**\n * Helper function to check if code is running on client side\n */\nconst isClientSide = (): boolean => !isSSR\n\n/**\n * Custom hook that tracks an element's bounding rectangle and updates on resize, scroll, etc.\n *\n * @param options Configuration options for element rect tracking\n * @returns The current bounding rectangle of the element\n */\nexport function useElementRect({\n element,\n enabled = true,\n throttleMs = 100,\n useResizeObserver = true,\n}: ElementRectOptions = {}): RectState {\n const [rect, setRect] = React.useState<RectState>(initialRect)\n\n const getTargetElement = React.useCallback((): Element | null => {\n if (!enabled || !isClientSide()) return null\n\n if (!element) {\n return document.body\n }\n\n if (typeof element === \"string\") {\n return document.querySelector(element)\n }\n\n if (\"current\" in element) {\n return element.current\n }\n\n return element\n }, [element, enabled])\n\n const updateRect = useThrottledCallback(\n () => {\n if (!enabled || !isClientSide()) return\n\n const targetElement = getTargetElement()\n if (!targetElement) {\n setRect(initialRect)\n return\n }\n\n const newRect = targetElement.getBoundingClientRect()\n setRect({\n x: newRect.x,\n y: newRect.y,\n width: newRect.width,\n height: newRect.height,\n top: newRect.top,\n right: newRect.right,\n bottom: newRect.bottom,\n left: newRect.left,\n })\n },\n throttleMs,\n [enabled, getTargetElement],\n { leading: true, trailing: true }\n )\n\n React.useEffect(() => {\n if (!enabled || !isClientSide()) {\n setRect(initialRect)\n return\n }\n\n const targetElement = getTargetElement()\n if (!targetElement) return\n\n updateRect()\n\n const cleanup: (() => void)[] = []\n\n if (useResizeObserver && hasResizeObserver) {\n const resizeObserver = new ResizeObserver(() => {\n window.requestAnimationFrame(updateRect)\n })\n resizeObserver.observe(targetElement)\n cleanup.push(() => resizeObserver.disconnect())\n }\n\n const handleUpdate = () => updateRect()\n\n window.addEventListener(\"scroll\", handleUpdate, { passive: true })\n window.addEventListener(\"resize\", handleUpdate, { passive: true })\n\n cleanup.push(() => {\n window.removeEventListener(\"scroll\", handleUpdate)\n window.removeEventListener(\"resize\", handleUpdate)\n })\n\n return () => {\n cleanup.forEach((fn) => fn())\n setRect(initialRect)\n }\n }, [enabled, getTargetElement, updateRect, useResizeObserver])\n\n return rect\n}\n\n/**\n * Convenience hook for tracking document.body rect\n */\nexport function useBodyRect(\n options: Omit<ElementRectOptions, \"element\"> = {}\n): RectState {\n return useElementRect({\n ...options,\n element: isClientSide() ? document.body : null,\n })\n}\n\n/**\n * Convenience hook for tracking a ref element's rect\n */\nexport function useRefRect<T extends Element>(\n ref: React.RefObject<T>,\n options: Omit<ElementRectOptions, \"element\"> = {}\n): RectState {\n return useElementRect({ ...options, element: ref })\n}\n","import * as React from \"react\"\nimport type { Editor } from \"@tiptap/react\"\nimport { useWindowSize } from \"@/hooks/use-window-size\"\nimport { useBodyRect } from \"./use-element-rect\"\n\nexport interface CursorVisibilityOptions {\n /**\n * The Tiptap editor instance\n */\n editor?: Editor | null\n /**\n * Reference to the toolbar element that may obscure the cursor\n */\n overlayHeight?: number\n}\n\n/**\n * Custom hook that ensures the cursor remains visible when typing in a Tiptap editor.\n * Automatically scrolls the window when the cursor would be hidden by the toolbar.\n *\n * @param options.editor The Tiptap editor instance\n * @param options.overlayHeight Toolbar height to account for\n * @returns The bounding rect of the body\n */\nexport function useCursorVisibility({\n editor,\n overlayHeight = 0,\n}: CursorVisibilityOptions) {\n const { height: windowHeight } = useWindowSize()\n const rect = useBodyRect({\n enabled: true,\n throttleMs: 100,\n useResizeObserver: true,\n })\n\n React.useEffect(() => {\n const ensureCursorVisibility = () => {\n if (!editor) return\n\n const { state, view } = editor\n if (!view.hasFocus()) return\n\n // Get current cursor position coordinates\n const { from } = state.selection\n const cursorCoords = view.coordsAtPos(from)\n\n if (windowHeight < rect.height && cursorCoords) {\n const availableSpace = windowHeight - cursorCoords.top\n\n // If the cursor is hidden behind the overlay or offscreen, scroll it into view\n if (availableSpace < overlayHeight) {\n const targetCursorY = Math.max(windowHeight / 2, overlayHeight)\n const currentScrollY = window.scrollY\n const cursorAbsoluteY = cursorCoords.top + currentScrollY\n const newScrollY = cursorAbsoluteY - targetCursorY\n\n window.scrollTo({\n top: Math.max(0, newScrollY),\n behavior: \"smooth\",\n })\n }\n }\n }\n\n ensureCursorVisibility()\n }, [editor, overlayHeight, windowHeight, rect.height])\n\n return rect\n}\n","'use client'\n\nimport * as React from 'react'\nimport { EditorContent, EditorContext, useEditor } from '@tiptap/react'\n\n// --- Tiptap Core Extensions ---\nimport { StarterKit } from '@tiptap/starter-kit'\nimport { Image } from '@tiptap/extension-image'\nimport { TaskItem, TaskList } from '@tiptap/extension-list'\nimport { TextAlign } from '@tiptap/extension-text-align'\nimport { Typography } from '@tiptap/extension-typography'\nimport { Highlight } from '@tiptap/extension-highlight'\nimport { Subscript } from '@tiptap/extension-subscript'\nimport { Superscript } from '@tiptap/extension-superscript'\nimport { Selection } from '@tiptap/extensions'\n\n// --- UI Primitives ---\nimport { Button } from '@/components/tiptap-ui-primitive/button'\nimport { Spacer } from '@/components/tiptap-ui-primitive/spacer'\nimport {\n Toolbar,\n ToolbarGroup,\n ToolbarSeparator\n} from '@/components/tiptap-ui-primitive/toolbar'\n\n// --- Tiptap Node ---\nimport { ImageUploadNode } from '@/components/tiptap-node/image-upload-node/image-upload-node-extension'\nimport { HorizontalRule } from '@/components/tiptap-node/horizontal-rule-node/horizontal-rule-node-extension'\nimport '@/components/tiptap-node/blockquote-node/blockquote-node.scss'\nimport '@/components/tiptap-node/code-block-node/code-block-node.scss'\nimport '@/components/tiptap-node/horizontal-rule-node/horizontal-rule-node.scss'\nimport '@/components/tiptap-node/list-node/list-node.scss'\nimport '@/components/tiptap-node/image-node/image-node.scss'\nimport '@/components/tiptap-node/heading-node/heading-node.scss'\nimport '@/components/tiptap-node/paragraph-node/paragraph-node.scss'\n\n// --- Tiptap UI ---\nimport { HeadingDropdownMenu } from '@/components/tiptap-ui/heading-dropdown-menu'\nimport { ImageUploadButton } from '@/components/tiptap-ui/image-upload-button'\nimport { ListDropdownMenu } from '@/components/tiptap-ui/list-dropdown-menu'\nimport { BlockquoteButton } from '@/components/tiptap-ui/blockquote-button'\nimport { CodeBlockButton } from '@/components/tiptap-ui/code-block-button'\nimport {\n ColorHighlightPopover,\n ColorHighlightPopoverContent,\n ColorHighlightPopoverButton\n} from '@/components/tiptap-ui/color-highlight-popover'\nimport {\n LinkPopover,\n LinkContent,\n LinkButton\n} from '@/components/tiptap-ui/link-popover'\nimport { MarkButton } from '@/components/tiptap-ui/mark-button'\nimport { TextAlignButton } from '@/components/tiptap-ui/text-align-button'\nimport { UndoRedoButton } from '@/components/tiptap-ui/undo-redo-button'\n\n// --- Icons ---\nimport { ArrowLeftIcon } from '@/components/tiptap-icons/arrow-left-icon'\nimport { HighlighterIcon } from '@/components/tiptap-icons/highlighter-icon'\nimport { LinkIcon } from '@/components/tiptap-icons/link-icon'\n\n// --- Hooks ---\nimport { useIsMobile } from '@/hooks/use-mobile'\nimport { useWindowSize } from '@/hooks/use-window-size'\nimport { useCursorVisibility } from '@/hooks/use-cursor-visibility'\n\n// --- Components ---\n// import { ThemeToggle } from '@/components/tiptap-templates/simple/theme-toggle'\n\n// --- Lib ---\nimport { handleImageUpload, MAX_FILE_SIZE } from '@/lib/tiptap-utils'\n\n// --- Styles ---\nimport '@/components/tiptap-templates/simple/simple-editor.scss'\n\nimport content from '@/components/tiptap-templates/simple/data/content.json'\n\nconst MainToolbarContent = ({\n onHighlighterClick,\n onLinkClick,\n isMobile\n}: {\n onHighlighterClick: () => void\n onLinkClick: () => void\n isMobile: boolean\n}) => {\n return (\n <>\n <Spacer />\n\n <ToolbarGroup>\n <UndoRedoButton action='undo' />\n <UndoRedoButton action='redo' />\n </ToolbarGroup>\n\n <ToolbarSeparator />\n\n <ToolbarGroup>\n <HeadingDropdownMenu levels={[1, 2, 3, 4]} portal={isMobile} />\n <ListDropdownMenu\n types={['bulletList', 'orderedList', 'taskList']}\n portal={isMobile}\n />\n <BlockquoteButton />\n <CodeBlockButton />\n </ToolbarGroup>\n\n <ToolbarSeparator />\n\n <ToolbarGroup>\n <MarkButton type='bold' />\n <MarkButton type='italic' />\n <MarkButton type='strike' />\n <MarkButton type='code' />\n <MarkButton type='underline' />\n {!isMobile ? (\n <ColorHighlightPopover />\n ) : (\n <ColorHighlightPopoverButton onClick={onHighlighterClick} />\n )}\n {!isMobile ? <LinkPopover /> : <LinkButton onClick={onLinkClick} />}\n </ToolbarGroup>\n\n <ToolbarSeparator />\n\n <ToolbarGroup>\n <MarkButton type='superscript' />\n <MarkButton type='subscript' />\n </ToolbarGroup>\n\n <ToolbarSeparator />\n\n <ToolbarGroup>\n <TextAlignButton align='left' />\n <TextAlignButton align='center' />\n <TextAlignButton align='right' />\n <TextAlignButton align='justify' />\n </ToolbarGroup>\n\n <ToolbarSeparator />\n\n <ToolbarGroup>\n <ImageUploadButton text='Add' />\n </ToolbarGroup>\n\n <Spacer />\n\n {isMobile && <ToolbarSeparator />}\n\n {/* <ToolbarGroup>\n <ThemeToggle />\n </ToolbarGroup> */}\n </>\n )\n}\n\nconst MobileToolbarContent = ({\n type,\n onBack\n}: {\n type: 'highlighter' | 'link'\n onBack: () => void\n}) => (\n <>\n <ToolbarGroup>\n <Button data-style='ghost' onClick={onBack}>\n <ArrowLeftIcon className='tiptap-button-icon' />\n {type === 'highlighter' ? (\n <HighlighterIcon className='tiptap-button-icon' />\n ) : (\n <LinkIcon className='tiptap-button-icon' />\n )}\n </Button>\n </ToolbarGroup>\n\n <ToolbarSeparator />\n\n {type === 'highlighter' ? (\n <ColorHighlightPopoverContent />\n ) : (\n <LinkContent />\n )}\n </>\n)\n\nexport function TiptapEditor() {\n const isMobile = useIsMobile()\n const { height } = useWindowSize()\n const [mobileView, setMobileView] = React.useState<\n 'main' | 'highlighter' | 'link'\n >('main')\n const toolbarRef = React.useRef<HTMLDivElement>(null)\n\n const editor = useEditor({\n immediatelyRender: false,\n shouldRerenderOnTransaction: false,\n editorProps: {\n attributes: {\n autocomplete: 'off',\n autocorrect: 'off',\n autocapitalize: 'off',\n 'aria-label': 'Main content area, start typing to enter text.',\n class: 'simple-editor'\n }\n },\n extensions: [\n StarterKit.configure({\n horizontalRule: false,\n link: {\n openOnClick: false,\n enableClickSelection: true\n }\n }),\n HorizontalRule,\n TextAlign.configure({ types: ['heading', 'paragraph'] }),\n TaskList,\n TaskItem.configure({ nested: true }),\n Highlight.configure({ multicolor: true }),\n Image,\n Typography,\n Superscript,\n Subscript,\n Selection,\n ImageUploadNode.configure({\n accept: 'image/*',\n maxSize: MAX_FILE_SIZE,\n limit: 3,\n upload: handleImageUpload,\n onError: (error) => console.error('Upload failed:', error)\n })\n ],\n content\n })\n\n const rect = useCursorVisibility({\n editor,\n overlayHeight: toolbarRef.current?.getBoundingClientRect().height ?? 0\n })\n\n React.useEffect(() => {\n if (!isMobile && mobileView !== 'main') {\n setMobileView('main')\n }\n }, [isMobile, mobileView])\n\n return (\n <div className='simple-editor-wrapper'>\n <EditorContext.Provider value={{ editor }}>\n <Toolbar\n ref={toolbarRef}\n style={{\n ...(isMobile\n ? {\n bottom: `calc(100% - ${height - rect.y}px)`\n }\n : {})\n }}\n >\n {mobileView === 'main' ? (\n <MainToolbarContent\n onHighlighterClick={() => setMobileView('highlighter')}\n onLinkClick={() => setMobileView('link')}\n isMobile={isMobile}\n />\n ) : (\n <MobileToolbarContent\n type={mobileView === 'highlighter' ? 'highlighter' : 'link'}\n onBack={() => setMobileView('main')}\n />\n )}\n </Toolbar>\n\n <EditorContent\n editor={editor}\n // role='presentation'\n className='simple-editor-content'\n />\n </EditorContext.Provider>\n </div>\n )\n}\n"],"names":["useTooltip","initialOpen","placement","controlledOpen","setControlledOpen","delay","closeDelay","uncontrolledOpen","setUncontrolledOpen","React","open","setOpen","data","useFloating","autoUpdate","offset","flip","shift","context","hover","useHover","focus","useFocus","dismiss","useDismiss","role","useRole","interactions","useInteractions","TooltipContext","useTooltipContext","Tooltip","children","props","tooltip","jsx","FloatingDelayGroup","TooltipTrigger","asChild","propRef","childrenRef","ref","useMergeRefs","dataAttributes","TooltipContent","style","portal","portalProps","content","FloatingPortal","findDiffStart","a","b","pos","i","childA","childB","j","inner","findDiffEnd","posA","posB","iA","iB","size","same","minSize","Fragment","from","to","f","nodeStart","parent","child","end","start","blockSeparator","leafText","text","first","node","nodeText","other","last","result","index","current","copy","found","p","otherPos","retIndex","curPos","cur","n","schema","value","array","joined","nodes","ReplaceError","Slice","openStart","openEnd","fragment","insertInto","removeRange","json","openIsolating","indexTo","offsetTo","dist","insert","lower16","factor16","makeRecover","recoverIndex","recoverOffset","DEL_BEFORE","DEL_AFTER","DEL_ACROSS","DEL_SIDE","MapResult","delInfo","recover","StepMap","ranges","inverted","diff","assoc","simple","oldIndex","newIndex","oldSize","newSize","side","del","oldStart","newStart","stepsByID","Step","type","id","stepClass","StepResult","doc","failed","message","slice","e","mapFragment","mapped","AddMarkStep","mark","oldSlice","$from","RemoveMarkStep","mapping","AddNodeMarkStep","updated","newSet","RemoveNodeMarkStep","ReplaceStep","structure","contentBetween","ReplaceAroundStep","gapFrom","gapTo","gap","inserted","depth","next","AttrStep","attr","attrs","name","DocAttrStep","TransformError","err","classesById","Selection","$anchor","$head","SelectionRange","tr","lastNode","lastParent","mapFrom","$to","selectionToInsertionEnd","$pos","dir","textOnly","TextSelection","findSelectionIn","bias","AllSelection","cls","selectionClass","warnedAboutTextSelection","checkTextSelection","marks","TextBookmark","anchor","head","dPos","NodeSelection","$end","deleted","NodeBookmark","sel","AllBookmark","startLen","step","map","_from","_to","_newFrom","newTo","bind","self","FieldDesc","desc","config","instance","_marks","_old","state","prev","MAX_FILE_SIZE","MAC_SYMBOLS","cn","classes","isMac","formatShortcutKey","key","capitalize","lowerKey","parseShortcutKeys","shortcutKeys","delimiter","isMarkInSchema","markName","editor","isNodeInSchema","nodeName","focusNextNode","view","selection","nextSel","paragraphType","para","$inside","isValidPosition","isExtensionAvailable","extensionNames","names","ext","findNodeAtPosition","position","error","findNodePosition","nodePos","hasValidNode","hasValidPos","foundPos","foundNode","currentNode","nodeAtPos","isNodeTypeSelected","types","handleImageUpload","file","onProgress","abortSignal","progress","resolve","ATTR_WHITESPACE","isAllowedUri","uri","protocols","allowedProtocols","sanitizeUrl","inputUrl","baseUrl","url","ShortcutDisplay","shortcuts","jsxs","Button","className","showTooltip","ariaLabel","ButtonGroup","orientation","Spacer","computedStyle","Separator","decorative","divProps","semanticProps","useMenuNavigation","containerRef","query","items","onSelect","onClose","autoSelectFirstItem","selectedIndex","setSelectedIndex","handleKeyboardNavigation","event","moveNext","currentIndex","movePrev","targetElement","updateRef","useComposedRef","libRef","userRef","prevUserRef","useToolbarNavigation","toolbarRef","setItems","collectItems","toolbar","updateItems","observer","el","handleFocus","target","handleBlur","Toolbar","variant","composedRef","ToolbarGroup","ToolbarSeparator","CloseIcon","useFileUpload","options","fileItems","setFileItems","uploadFile","abortController","fileId","newFileItem","item","files","uploadPromises","fileToRemove","CloudUploadIcon","FileIcon","FileCornerIcon","ImageUploadDragArea","onFile","isDragOver","setIsDragOver","isDragActive","setIsDragActive","ImageUploadPreview","fileItem","onRemove","formatFileSize","bytes","k","sizes","DropZoneContent","maxSize","limit","ImageUploadNode","accept","inputRef","extension","uploadOptions","uploadFiles","removeFileItem","clearAllFiles","handleUpload","urls","imageNodes","filename","handleChange","handleClick","hasFiles","NodeViewWrapper","Node","HTMLAttributes","mergeAttributes","ReactNodeViewRenderer","ImageUploadNodeComponent","commands","nodeAfter","nodeEl","firstChild","HorizontalRule","TiptapHorizontalRule","ChevronDownIcon","useTiptapEditor","providedEditor","coreEditor","useCurrentEditor","mainEditor","useEditorState","Badge","appearance","trimText","HeadingShortcutBadge","level","HEADING_SHORTCUT_KEYS","HeadingButton","hideWhenUnavailable","onToggled","showShortcut","onClick","buttonProps","isVisible","canToggle","isActive","handleToggle","label","Icon","useHeading","HeadingOneIcon","HeadingTwoIcon","HeadingThreeIcon","HeadingFourIcon","HeadingFiveIcon","HeadingSixIcon","headingIcons","turnInto","isHeadingActive","l","toggleHeading","levels","toggleLevel","chain","lastChild","shouldShowButton","setIsVisible","canToggleState","handleSelectionUpdate","success","DropdownMenu","DropdownMenuPrimitive","DropdownMenuPortal","DropdownMenuTrigger","DropdownMenuItem","DropdownMenuSubContent","DropdownMenuContent","sideOffset","Card","CardHeader","CardBody","CardItemGroup","CardGroupLabel","CardFooter","HeadingDropdownMenu","onOpenChange","isOpen","setIsOpen","useHeadingDropdownMenu","handleOpenChange","HeadingIcon","getActiveHeadingLevel","activeLevel","ImageShortcutBadge","IMAGE_UPLOAD_SHORTCUT_KEY","ImageUploadButton","onInserted","canInsert","handleImage","useImageUpload","useIsMobile","breakpoint","isMobile","setIsMobile","mql","onChange","ImagePlusIcon","canInsertImage","isImageActive","insertImage","useHotkeys","ListShortcutBadge","LIST_SHORTCUT_KEYS","ListButton","useList","ListIcon","ListOrderedIcon","ListTodoIcon","listIcons","listLabels","canToggleList","isListActive","toggleList","toggle","listOptions","canToggleAnyList","listTypes","isAnyListActive","getFilteredListOptions","availableTypes","option","shouldShowListDropdown","params","listInSchema","canToggleAny","getActiveListType","useListDropdownMenu","filteredLists","isAnyActive","activeType","activeList","ListDropdownMenu","handleOnOpenChange","BlockquoteShortcutBadge","BLOCKQUOTE_SHORTCUT_KEY","BlockquoteButton","useBlockquote","BlockquoteIcon","canToggleBlockquote","toggleBlockquote","CodeBlockShortcutBadge","CODE_BLOCK_SHORTCUT_KEY","CodeBlockButton","useCodeBlock","CodeBlockIcon","toggleCodeBlock","BanIcon","HighlighterIcon","Popover","PopoverPrimitive","PopoverTrigger","PopoverContent","align","ColorHighlightShortcutBadge","COLOR_HIGHLIGHT_SHORTCUT_KEY","ColorHighlightButton","highlightColor","onApplied","canColorHighlight","handleColorHighlight","useColorHighlight","buttonStyle","HIGHLIGHT_COLORS","pickHighlightColorsByValue","values","colorMap","color","isColorHighlightActive","removeHighlight","canColorHighlightState","highlightMarkType","handleRemoveHighlight","ColorHighlightPopoverButton","ColorHighlightPopoverContent","colors","menuItems","highlightedElement","ColorHighlightPopover","CornerDownLeftIcon","ExternalLinkIcon","LinkIcon","TrashIcon","Input","InputGroup","LinkButton","LinkMain","setUrl","setLink","removeLink","openLink","handleKeyDown","LinkContent","linkPopover","useLinkPopover","LinkPopover","onSetLink","autoOpenOnLinkActive","canSet","nextIsOpen","handleSetLink","canSetLink","isLinkActive","shouldShowLinkButton","useLinkHandler","href","updateLinkState","isEmpty","features","safeUrl","useLinkState","linkHandler","MarkShortcutBadge","MARK_SHORTCUT_KEYS","MarkButton","handleMark","useMark","BoldIcon","Code2Icon","ItalicIcon","StrikeIcon","SubscriptIcon","SuperscriptIcon","UnderlineIcon","markIcons","canToggleMark","isMarkActive","toggleMark","getFormattedMarkName","TextAlignShortcutBadge","TEXT_ALIGN_SHORTCUT_KEYS","TextAlignButton","onAligned","CustomIcon","handleTextAlign","canAlign","useTextAlign","AlignCenterIcon","AlignJustifyIcon","AlignLeftIcon","AlignRightIcon","textAlignIcons","textAlignLabels","canSetTextAlign","hasSetTextAlign","isTextAlignActive","setTextAlign","HistoryShortcutBadge","action","UNDO_REDO_SHORTCUT_KEYS","UndoRedoButton","onExecuted","handleAction","canExecute","useUndoRedo","Redo2Icon","Undo2Icon","historyActionLabels","historyIcons","canExecuteUndoRedoAction","executeUndoRedoAction","handleUpdate","ArrowLeftIcon","useUnmount","callback","useRef","useEffect","defaultOptions","useThrottledCallback","fn","wait","dependencies","handler","throttle","useWindowSize","windowSize","setWindowSize","handleViewportChange","vp","width","height","offsetTop","offsetLeft","scale","prevState","visualViewport","initialRect","isSSR","hasResizeObserver","isClientSide","useElementRect","element","enabled","throttleMs","useResizeObserver","rect","setRect","getTargetElement","updateRect","newRect","cleanup","resizeObserver","useBodyRect","useCursorVisibility","overlayHeight","windowHeight","cursorCoords","targetCursorY","currentScrollY","newScrollY","MainToolbarContent","onHighlighterClick","onLinkClick","MobileToolbarContent","onBack","TiptapEditor","mobileView","setMobileView","useEditor","StarterKit","TextAlign","TaskList","TaskItem","Highlight","Image","Typography","Superscript","Subscript","EditorContext","EditorContent"],"mappings":";;;;;;;;;;;;;;;;;;;AA2DA,SAASA,GAAW;AAAA,EAClB,aAAAC,IAAc;AAAA,EACd,WAAAC,IAAY;AAAA,EACZ,MAAMC;AAAA,EACN,cAAcC;AAAA,EACd,OAAAC,IAAQ;AAAA,EACR,YAAAC,IAAa;AACf,IAA4C,IAAI;AAC9C,QAAM,CAACC,GAAkBC,CAAmB,IAC1CC,EAAM,SAAkBR,CAAW,GAE/BS,IAAOP,KAAkBI,GACzBI,IAAUP,KAAqBI,GAE/BI,IAAOC,GAAY;AAAA,IACvB,WAAAX;AAAA,IACA,MAAAQ;AAAA,IACA,cAAcC;AAAA,IACd,sBAAsBG;AAAA,IACtB,YAAY;AAAA,MACVC,GAAO,CAAC;AAAA,MACRC,GAAK;AAAA,QACH,WAAWd,EAAU,SAAS,GAAG;AAAA,QACjC,2BAA2B;AAA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