@tiptap/extensions
Advanced tools
+33
-10
@@ -614,9 +614,15 @@ "use strict"; | ||
| var import_view6 = require("@tiptap/pm/view"); | ||
| var selectionStyle = `.ProseMirror:not(.ProseMirror-focused) *::selection { | ||
| background: transparent; | ||
| function shouldSyncDomSelection(state, editor) { | ||
| return !state.selection.empty && !(0, import_core8.isNodeSelection)(state.selection) && editor.isEditable; | ||
| } | ||
| .ProseMirror:not(.ProseMirror-focused) *::-moz-selection { | ||
| background: transparent; | ||
| }`; | ||
| function shouldPreserveSelection(state, editor) { | ||
| return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging; | ||
| } | ||
| function clearDomSelection() { | ||
| var _a; | ||
| (_a = window.getSelection()) == null ? void 0 : _a.removeAllRanges(); | ||
| } | ||
| function restoreDomSelection(view) { | ||
| view.focus(); | ||
| } | ||
| var Selection = import_core8.Extension.create({ | ||
@@ -631,5 +637,2 @@ name: "selection", | ||
| const { editor, options } = this; | ||
| if (editor.options.injectCSS && typeof document !== "undefined") { | ||
| (0, import_core8.createStyleTag)(selectionStyle, editor.options.injectNonce, "selection"); | ||
| } | ||
| return [ | ||
@@ -640,3 +643,3 @@ new import_state5.Plugin({ | ||
| decorations(state) { | ||
| if (state.selection.empty || editor.isFocused || !editor.isEditable || (0, import_core8.isNodeSelection)(state.selection) || editor.view.dragging) { | ||
| if (!shouldPreserveSelection(state, editor)) { | ||
| return null; | ||
@@ -649,2 +652,22 @@ } | ||
| ]); | ||
| }, | ||
| handleDOMEvents: { | ||
| blur(view) { | ||
| if (!shouldSyncDomSelection(view.state, editor)) { | ||
| return false; | ||
| } | ||
| clearDomSelection(); | ||
| return false; | ||
| }, | ||
| focus(view) { | ||
| if (!shouldSyncDomSelection(view.state, editor)) { | ||
| return false; | ||
| } | ||
| requestAnimationFrame(() => { | ||
| if (!editor.isDestroyed && view.hasFocus()) { | ||
| restoreDomSelection(view); | ||
| } | ||
| }); | ||
| return false; | ||
| } | ||
| } | ||
@@ -651,0 +674,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts","../src/character-count/character-count.ts","../src/drop-cursor/drop-cursor.ts","../src/focus/focus.ts","../src/gap-cursor/gap-cursor.ts","../src/placeholder/constants.ts","../src/placeholder/placeholder.ts","../src/placeholder/plugins/PlaceholderPlugin.ts","../src/placeholder/utils/buildPlaceholderDecorations.ts","../src/placeholder/utils/createPlaceholderDecoration.ts","../src/placeholder/utils/placeholderStateField.ts","../src/placeholder/utils/resolveTopLevelRange.ts","../src/placeholder/utils/preparePlaceholderAttribute.ts","../src/selection/selection.ts","../src/trailing-node/trailing-node.ts","../src/undo-redo/undo-redo.ts"],"sourcesContent":["export * from './character-count/index.js'\nexport * from './drop-cursor/index.js'\nexport * from './focus/index.js'\nexport * from './gap-cursor/index.js'\nexport * from './placeholder/index.js'\nexport * from './selection/index.js'\nexport * from './trailing-node/index.js'\nexport * from './undo-redo/index.js'\n","import { Extension } from '@tiptap/core'\nimport type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport interface CharacterCountOptions {\n /**\n * The maximum number of characters that should be allowed. Defaults to `0`.\n * @default null\n * @example 180\n */\n limit: number | null | undefined\n /**\n * The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n * If set to `nodeSize`, the nodeSize of the document is used.\n * @default 'textSize'\n * @example 'textSize'\n */\n mode: 'textSize' | 'nodeSize'\n /**\n * Sets whether the content will be automatically trimmed when programatically setting content over the limit.\n * If set to false, the user will be able to trim the text manually.\n * @default true\n * @example false\n */\n autoTrim?: boolean\n /**\n * The text counter function to use. Defaults to a simple character count.\n * @default (text) => text.length\n * @example (text) => [...new Intl.Segmenter().segment(text)].length\n */\n textCounter: (text: string) => number\n /**\n * The word counter function to use. Defaults to a simple word count.\n * @default (text) => text.split(' ').filter(word => word !== '').length\n * @example (text) => text.split(/\\s+/).filter(word => word !== '').length\n */\n wordCounter: (text: string) => number\n}\n\nexport interface CharacterCountStorage {\n /**\n * Get the number of characters for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the characters from. Defaults to the current document.\n * @param options.mode The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n */\n characters: (options?: { node?: ProseMirrorNode; mode?: 'textSize' | 'nodeSize' }) => number\n\n /**\n * Get the number of words for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the words from. Defaults to the current document.\n */\n words: (options?: { node?: ProseMirrorNode }) => number\n}\n\ndeclare module '@tiptap/core' {\n interface Storage {\n characterCount: CharacterCountStorage\n }\n}\n\n/**\n * This extension allows you to count the characters and words of your document.\n * @see https://tiptap.dev/api/extensions/character-count\n */\nexport const CharacterCount = Extension.create<CharacterCountOptions, CharacterCountStorage>({\n name: 'characterCount',\n\n addOptions() {\n return {\n limit: null,\n autoTrim: true,\n mode: 'textSize',\n textCounter: text => text.length,\n wordCounter: text => text.split(' ').filter(word => word !== '').length,\n }\n },\n\n addStorage() {\n return {\n characters: () => 0,\n words: () => 0,\n }\n },\n\n onBeforeCreate() {\n this.storage.characters = options => {\n const node = options?.node || this.editor.state.doc\n const mode = options?.mode || this.options.mode\n\n if (mode === 'textSize') {\n const text = node.textBetween(0, node.content.size, undefined, ' ')\n\n return this.options.textCounter(text)\n }\n\n return node.nodeSize\n }\n\n this.storage.words = options => {\n const node = options?.node || this.editor.state.doc\n const text = node.textBetween(0, node.content.size, ' ', ' ')\n\n return this.options.wordCounter(text)\n }\n },\n\n addProseMirrorPlugins() {\n let initialEvaluationDone = false\n\n return [\n new Plugin({\n key: new PluginKey('characterCount'),\n appendTransaction: (transactions, oldState, newState) => {\n if (initialEvaluationDone) {\n return\n }\n\n const limit = this.options.limit\n const autoTrim = this.options.autoTrim\n\n if (limit === null || limit === undefined || limit === 0 || autoTrim === false) {\n initialEvaluationDone = true\n return\n }\n\n const initialContentSize = this.storage.characters({ node: newState.doc })\n\n if (initialContentSize > limit) {\n const over = initialContentSize - limit\n const from = 0\n const to = over\n\n console.warn(\n `[CharacterCount] Initial content exceeded limit of ${limit} characters. Content was automatically trimmed.`,\n )\n const tr = newState.tr.deleteRange(from, to)\n initialEvaluationDone = true\n return tr\n }\n\n initialEvaluationDone = true\n },\n filterTransaction: (transaction, state) => {\n const limit = this.options.limit\n\n // Nothing has changed or no limit is defined. Ignore it.\n if (!transaction.docChanged || limit === 0 || limit === null || limit === undefined) {\n return true\n }\n\n const oldSize = this.storage.characters({ node: state.doc })\n const newSize = this.storage.characters({ node: transaction.doc })\n\n // Everything is in the limit. Good.\n if (newSize <= limit) {\n return true\n }\n\n // The limit has already been exceeded but will be reduced.\n if (oldSize > limit && newSize > limit && newSize <= oldSize) {\n return true\n }\n\n // The limit has already been exceeded and will be increased further.\n if (oldSize > limit && newSize > limit && newSize > oldSize) {\n return false\n }\n\n const isPaste = transaction.getMeta('paste')\n\n // Block all exceeding transactions that were not pasted.\n if (!isPaste) {\n return false\n }\n\n // For pasted content, we try to remove the exceeding content.\n const pos = transaction.selection.$head.pos\n const over = newSize - limit\n const from = pos - over\n const to = pos\n\n // It’s probably a bad idea to mutate transactions within `filterTransaction`\n // but for now this is working fine.\n transaction.deleteRange(from, to)\n\n // In some situations, the limit will continue to be exceeded after trimming.\n // This happens e.g. when truncating within a complex node (e.g. table)\n // and ProseMirror has to close this node again.\n // If this is the case, we prevent the transaction completely.\n const updatedSize = this.storage.characters({ node: transaction.doc })\n\n if (updatedSize > limit) {\n return false\n }\n\n return true\n },\n }),\n ]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { dropCursor } from '@tiptap/pm/dropcursor'\n\nexport interface DropcursorOptions {\n /**\n * The color of the drop cursor. Use `false` to apply no color and rely only on class.\n * @default 'currentColor'\n * @example 'red'\n */\n color?: string | false\n\n /**\n * The width of the drop cursor\n * @default 1\n * @example 2\n */\n width: number | undefined\n\n /**\n * The class of the drop cursor\n * @default undefined\n * @example 'drop-cursor'\n */\n class: string | undefined\n}\n\n/**\n * This extension allows you to add a drop cursor to your editor.\n * A drop cursor is a line that appears when you drag and drop content\n * in-between nodes.\n * @see https://tiptap.dev/api/extensions/dropcursor\n */\nexport const Dropcursor = Extension.create<DropcursorOptions>({\n name: 'dropCursor',\n\n addOptions() {\n return {\n color: 'currentColor',\n width: 1,\n class: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [dropCursor(this.options)]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const Focus = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope =\n (this.options.mode === 'deepest' && maxLevels - currentLevel > 0) ||\n (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n","import type { ParentConfig } from '@tiptap/core'\nimport { callOrReturn, Extension, getExtensionField } from '@tiptap/core'\nimport { gapCursor } from '@tiptap/pm/gapcursor'\n\ndeclare module '@tiptap/core' {\n interface NodeConfig<Options, Storage> {\n /**\n * A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.\n * @default null\n */\n allowGapCursor?:\n | boolean\n | null\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['allowGapCursor']\n }) => boolean | null)\n }\n}\n\n/**\n * This extension allows you to add a gap cursor to your editor.\n * A gap cursor is a cursor that appears when you click on a place\n * where no content is present, for example inbetween nodes.\n * @see https://tiptap.dev/api/extensions/gapcursor\n */\nexport const Gapcursor = Extension.create({\n name: 'gapCursor',\n\n addProseMirrorPlugins() {\n return [gapCursor()]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n allowGapCursor: callOrReturn(getExtensionField(extension, 'allowGapCursor', context)) ?? null,\n }\n },\n})\n","import { PluginKey } from '@tiptap/pm/state'\nimport type { DecorationSet } from '@tiptap/pm/view'\n\n/** The default data attribute label */\nexport const DEFAULT_DATA_ATTRIBUTE = 'placeholder'\n\n/** The plugin key used to store and read the placeholder decoration set */\nexport const PLUGIN_KEY = new PluginKey<DecorationSet>('tiptap__placeholder')\n","import { Extension } from '@tiptap/core'\n\nimport { DEFAULT_DATA_ATTRIBUTE } from './constants.js'\nimport { createPlaceholderPlugin } from './plugins/PlaceholderPlugin.js'\nimport type { PlaceholderOptions } from './types.js'\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\n */\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n dataAttribute: DEFAULT_DATA_ATTRIBUTE,\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n return [createPlaceholderPlugin({ editor: this.editor, options: this.options })]\n },\n})\n","import type { Editor } from '@tiptap/core'\nimport { Plugin } from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport { DEFAULT_DATA_ATTRIBUTE, PLUGIN_KEY } from '../constants.js'\nimport type { PlaceholderOptions } from '../types.js'\nimport { buildPlaceholderDecorations } from '../utils/buildPlaceholderDecorations.js'\nimport { createPlaceholderStateField } from '../utils/placeholderStateField.js'\nimport { preparePlaceholderAttribute } from '../utils/preparePlaceholderAttribute.js'\n\nexport type CreatePluginOptions = {\n editor: Editor\n options: PlaceholderOptions\n}\n\n/**\n * Creates the ProseMirror plugin that renders placeholder decorations.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @returns The configured placeholder plugin.\n */\nexport function createPlaceholderPlugin({ editor, options }: CreatePluginOptions) {\n const dataAttribute = options.dataAttribute\n ? `data-${preparePlaceholderAttribute(options.dataAttribute)}`\n : `data-${DEFAULT_DATA_ATTRIBUTE}`\n\n const useResolvedPath = options.showOnlyCurrent && !options.includeChildren\n\n return new Plugin({\n key: PLUGIN_KEY,\n ...(useResolvedPath\n ? {}\n : {\n state: createPlaceholderStateField({ editor, options, dataAttribute }),\n }),\n props: {\n decorations: useResolvedPath\n ? ({ doc, selection }) =>\n buildPlaceholderDecorations({ editor, options, dataAttribute, doc, selection })\n : state => {\n if (options.showOnlyWhenEditable && !editor.isEditable) {\n return DecorationSet.empty\n }\n\n return PLUGIN_KEY.getState(state) ?? DecorationSet.empty\n },\n },\n })\n}\n","import type { Editor } from '@tiptap/core'\nimport { isNodeEmpty } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Selection } from '@tiptap/pm/state'\nimport type { Decoration } from '@tiptap/pm/view'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\nimport { createPlaceholderDecoration } from './createPlaceholderDecoration.js'\n\nfunction resolveEmptyNodeClass(\n emptyNodeClass: PlaceholderOptions['emptyNodeClass'],\n props: { editor: Editor; node: Node; pos: number; hasAnchor: boolean },\n): string {\n return typeof emptyNodeClass === 'function' ? emptyNodeClass(props) : emptyNodeClass\n}\n\n/**\n * Scans a document range for empty textblocks that should receive placeholder\n * decorations. Used by the slow path and incremental state updates.\n */\nexport function scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from,\n to,\n}: {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n from: number\n to: number\n}): Decoration[] {\n const { anchor } = selection\n const decorations: Decoration[] = []\n const isEmptyDoc = editor.isEmpty\n\n doc.nodesBetween(from, to, (node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && isNodeEmpty(node)\n\n if (!node.type.isTextblock) {\n return options.includeChildren\n }\n\n if ((hasAnchor || !options.showOnlyCurrent) && isEmpty) {\n decorations.push(\n createPlaceholderDecoration({\n editor,\n isEmptyDoc,\n dataAttribute,\n hasAnchor,\n placeholder: options.placeholder,\n classes: {\n emptyEditor: options.emptyEditorClass,\n emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {\n editor,\n node,\n pos,\n hasAnchor,\n }),\n },\n node,\n pos,\n }),\n )\n }\n\n return options.includeChildren\n })\n\n return decorations\n}\n\n/**\n * Builds the placeholder decorations for the current document state.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @param options.dataAttribute - The prepared `data-*` attribute name.\n * @param options.doc - The current document node.\n * @param options.selection - The current selection.\n * @returns A decoration set, or `null` when no placeholders should be shown.\n */\nexport function buildPlaceholderDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n}: {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n}): DecorationSet | null {\n const active = editor.isEditable || !options.showOnlyWhenEditable\n\n if (!active) {\n return null\n }\n\n const { anchor } = selection\n const decorations: Decoration[] = []\n const isEmptyDoc = editor.isEmpty\n\n const useResolvedPath = options.showOnlyCurrent && !options.includeChildren\n\n if (useResolvedPath) {\n const resolved = doc.resolve(anchor)\n\n // When the selection spans the whole document (e.g. an `AllSelection`\n // after Cmd+A), the anchor resolves to the document level (depth 0). In\n // that case the relevant textblock is the node directly after the\n // position rather than an ancestor. otherwise the placeholder would\n // disappear after selecting all and deleting.\n const node = resolved.depth > 0 ? resolved.node(1) : resolved.nodeAfter\n const nodeStart = resolved.depth > 0 ? resolved.before(1) : anchor\n\n if (node && node.type.isTextblock && isNodeEmpty(node)) {\n const hasAnchor = anchor >= nodeStart && anchor <= nodeStart + node.nodeSize\n\n decorations.push(\n createPlaceholderDecoration({\n editor,\n isEmptyDoc,\n dataAttribute,\n hasAnchor,\n placeholder: options.placeholder,\n classes: {\n emptyEditor: options.emptyEditorClass,\n emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {\n editor,\n node,\n pos: nodeStart,\n hasAnchor,\n }),\n },\n node,\n pos: nodeStart,\n }),\n )\n }\n } else {\n decorations.push(\n ...scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from: 0,\n to: doc.content.size,\n }),\n )\n }\n\n return DecorationSet.create(doc, decorations)\n}\n","import type { Editor } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport { Decoration } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\n\n/**\n * Creates a ProseMirror node decoration that applies a placeholder\n * CSS class and data attribute to an empty node.\n * @param options.editor - The editor instance\n * @param options.pos - The position of the node in the document\n * @param options.node - The ProseMirror node\n * @param options.isEmptyDoc - Whether the entire document is empty\n * @param options.hasAnchor - Whether the selection anchor is within the node\n * @param options.dataAttribute - The data attribute name (e.g. `data-placeholder`)\n * @param options.classes - CSS classes for empty nodes and the empty editor\n * @param options.placeholder - The placeholder text or a function that returns it\n * @returns A ProseMirror node decoration with placeholder classes and data attribute\n */\nexport function createPlaceholderDecoration(options: {\n editor: Editor\n pos: number\n node: Node\n isEmptyDoc: boolean\n hasAnchor: boolean\n dataAttribute: string\n classes: {\n emptyEditor: PlaceholderOptions['emptyEditorClass']\n emptyNode: string\n }\n placeholder: PlaceholderOptions['placeholder']\n}) {\n const {\n editor,\n placeholder,\n dataAttribute,\n pos,\n node,\n isEmptyDoc,\n hasAnchor,\n classes: { emptyNode, emptyEditor },\n } = options\n const classes = [emptyNode]\n\n if (isEmptyDoc) {\n classes.push(emptyEditor)\n }\n\n return Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n [dataAttribute]:\n typeof placeholder === 'function'\n ? placeholder({\n editor,\n node,\n pos,\n hasAnchor,\n })\n : placeholder,\n })\n}\n","import type { Editor } from '@tiptap/core'\nimport { getChangedRanges } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport type { EditorState, StateField, Transaction } from '@tiptap/pm/state'\nimport type { Selection } from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\nimport {\n buildPlaceholderDecorations,\n scanRangeForDecorations,\n} from './buildPlaceholderDecorations.js'\nimport {\n getTopLevelBlocksInRange,\n mergeRanges,\n resolveTopLevelRange,\n toContentRelativeRange,\n} from './resolveTopLevelRange.js'\n\n/** Options passed to {@link createPlaceholderStateField}. */\nexport type CreatePlaceholderStateFieldOptions = {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n}\n\n/**\n * Expands a single changed range to the top-level blocks it touches.\n * Also resolves blocks at range boundaries so split/merge edits update\n * adjacent empty nodes (e.g. a new paragraph after Enter).\n */\nfunction collectBlocksForChange(\n doc: Node,\n change: { from: number; to: number },\n): Array<{ from: number; to: number }> {\n const ranges = getTopLevelBlocksInRange(doc, change.from, change.to)\n\n ranges.push(toContentRelativeRange(doc, resolveTopLevelRange(doc, change.from)))\n\n if (change.to > change.from) {\n ranges.push(\n toContentRelativeRange(\n doc,\n resolveTopLevelRange(doc, Math.min(change.to, doc.content.size + 1) - 1),\n ),\n )\n } else if (change.from < doc.content.size + 1) {\n ranges.push(\n toContentRelativeRange(\n doc,\n resolveTopLevelRange(doc, Math.min(change.from + 1, doc.content.size)),\n ),\n )\n }\n\n return ranges\n}\n\n/**\n * Collects content-relative top-level block ranges that need placeholder\n * decorations recomputed after a transaction.\n */\nfunction collectRescanRanges(\n tr: Transaction,\n oldState: EditorState,\n newState: EditorState,\n): Array<{ from: number; to: number }> {\n const ranges: Array<{ from: number; to: number }> = []\n\n if (tr.docChanged) {\n const changes = getChangedRanges(tr)\n\n for (const change of changes) {\n ranges.push(...collectBlocksForChange(newState.doc, change.newRange))\n }\n }\n\n if (tr.selectionSet) {\n ranges.push(\n toContentRelativeRange(\n newState.doc,\n resolveTopLevelRange(newState.doc, tr.mapping.map(oldState.selection.anchor)),\n ),\n )\n ranges.push(\n toContentRelativeRange(\n newState.doc,\n resolveTopLevelRange(newState.doc, newState.selection.anchor),\n ),\n )\n }\n\n return mergeRanges(ranges)\n}\n\n/** Clamps a content-relative range to `[0, doc.content.size]`. */\nfunction clampRange(from: number, to: number, doc: Node): { from: number; to: number } {\n const clampedFrom = Math.max(0, Math.min(from, doc.content.size))\n const clampedTo = Math.max(clampedFrom, Math.min(to, doc.content.size))\n\n return { from: clampedFrom, to: clampedTo }\n}\n\n/**\n * Removes and rebuilds placeholder decorations within the given ranges.\n * Only drops decorations fully contained in a range so mapped decorations\n * on neighbouring blocks (e.g. at a block boundary) are kept intact.\n */\nfunction updateDecorationsInRanges({\n decorations,\n ranges,\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n}: {\n decorations: DecorationSet\n ranges: Array<{ from: number; to: number }>\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n}): DecorationSet {\n let next = decorations\n\n for (const range of ranges) {\n const { from, to } = clampRange(range.from, range.to, doc)\n const existing = next\n .find(from, to)\n .filter(decoration => decoration.from >= from && decoration.to <= to)\n\n if (existing.length) {\n next = next.remove(existing)\n }\n\n const newDecos = scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from,\n to,\n })\n\n if (newDecos.length) {\n next = next.add(doc, newDecos)\n }\n }\n\n return next\n}\n\n/**\n * Creates the incremental `StateField<DecorationSet>` used by the slow path\n * (`showOnlyCurrent: false` or `includeChildren: true`).\n *\n * Decorations are mapped through each transaction and only recomputed for\n * top-level blocks touched by document or selection changes.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @param options.dataAttribute - The prepared `data-*` attribute name.\n * @returns A ProseMirror state field storing the placeholder decoration set.\n */\nexport function createPlaceholderStateField({\n editor,\n options,\n dataAttribute,\n}: CreatePlaceholderStateFieldOptions): StateField<DecorationSet> {\n return {\n init(_config, state: EditorState) {\n const decorations = buildPlaceholderDecorations({\n editor,\n options,\n dataAttribute,\n doc: state.doc,\n selection: state.selection,\n })\n\n return decorations ?? DecorationSet.empty\n },\n\n apply(tr: Transaction, prev: DecorationSet, oldState: EditorState, newState: EditorState) {\n if (!tr.docChanged && !tr.selectionSet) {\n return prev\n }\n\n const mapped = prev.map(tr.mapping, tr.doc)\n const ranges = collectRescanRanges(tr, oldState, newState)\n\n return updateDecorationsInRanges({\n decorations: mapped,\n ranges,\n editor,\n options,\n dataAttribute,\n doc: newState.doc,\n selection: newState.selection,\n })\n },\n }\n}\n","import type { Node } from '@tiptap/pm/model'\n\n/**\n * Resolves a document position to the `[from, to)` range of its containing\n * top-level block node in absolute document positions.\n */\nexport function resolveTopLevelRange(doc: Node, pos: number): { from: number; to: number } {\n const resolved = doc.resolve(pos)\n\n if (resolved.depth === 0) {\n const node = resolved.nodeAfter ?? resolved.nodeBefore\n\n if (!node) {\n return { from: pos, to: pos }\n }\n\n const nodePos = resolved.nodeAfter ? pos : pos - node.nodeSize\n\n return { from: nodePos, to: nodePos + node.nodeSize }\n }\n\n const topLevelPos = resolved.before(1)\n const node = resolved.node(1)\n\n return { from: topLevelPos, to: topLevelPos + node.nodeSize }\n}\n\n/**\n * Converts an absolute document range to content-relative positions used by\n * `Node#nodesBetween` and `Node#forEach` offsets.\n */\nexport function toContentRelativeRange(\n doc: Node,\n range: { from: number; to: number },\n): { from: number; to: number } {\n return {\n from: Math.max(0, range.from - 1),\n to: Math.min(doc.content.size, range.to - 1),\n }\n}\n\n/**\n * Returns the top-level block ranges that intersect a document change range.\n * Input `from`/`to` are absolute positions (e.g. from `getChangedRanges`).\n * Returned ranges are content-relative, matching `Node#forEach` offsets.\n */\nexport function getTopLevelBlocksInRange(\n doc: Node,\n from: number,\n to: number,\n): Array<{ from: number; to: number }> {\n const ranges: Array<{ from: number; to: number }> = []\n\n doc.forEach((node, offset) => {\n const nodeStart = offset\n const nodeEnd = nodeStart + node.nodeSize\n const absNodeStart = nodeStart + 1\n const absNodeEnd = nodeEnd + 1\n\n if (absNodeStart < to && absNodeEnd > from) {\n ranges.push({ from: nodeStart, to: nodeEnd })\n }\n })\n\n return ranges\n}\n\n/**\n * Sorts ranges by start position and merges overlapping or adjacent ranges.\n */\nexport function mergeRanges(\n ranges: Array<{ from: number; to: number }>,\n): Array<{ from: number; to: number }> {\n if (ranges.length === 0) {\n return []\n }\n\n const sorted = [...ranges].sort((a, b) => a.from - b.from)\n const merged: Array<{ from: number; to: number }> = [{ ...sorted[0] }]\n\n for (let i = 1; i < sorted.length; i += 1) {\n const last = merged[merged.length - 1]\n const current = sorted[i]\n\n if (current.from <= last.to) {\n last.to = Math.max(last.to, current.to)\n } else {\n merged.push({ ...current })\n }\n }\n\n return merged\n}\n","/**\n * Prepares the placeholder attribute by ensuring it is properly formatted.\n * @param attr - The placeholder attribute string.\n * @returns The prepared placeholder attribute string.\n */\nexport function preparePlaceholderAttribute(attr: string): string {\n return (\n attr\n // replace whitespace with dashes\n .replace(/\\s+/g, '-')\n // replace non-alphanumeric characters\n // or special chars like $, %, &, etc.\n // but not dashes\n .replace(/[^a-zA-Z0-9-]/g, '')\n // and replace any numeric character at the start\n .replace(/^[0-9-]+/, '')\n // and finally replace any stray, leading dashes\n .replace(/^-+/, '')\n .toLowerCase()\n )\n}\n","import { createStyleTag, Extension, isNodeSelection } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nconst selectionStyle = `.ProseMirror:not(.ProseMirror-focused) *::selection {\n background: transparent;\n}\n\n.ProseMirror:not(.ProseMirror-focused) *::-moz-selection {\n background: transparent;\n}`\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * This extension allows you to add a class to the selected text.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create<SelectionOptions>({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n if (editor.options.injectCSS && typeof document !== 'undefined') {\n createStyleTag(selectionStyle, editor.options.injectNonce, 'selection')\n }\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (\n state.selection.empty ||\n editor.isFocused ||\n !editor.isEditable ||\n isNodeSelection(state.selection) ||\n editor.view.dragging\n ) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n","import { Extension } from '@tiptap/core'\nimport type { Node, NodeType } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport const skipTrailingNodeMeta = 'skipTrailingNode'\n\nfunction nodeEqualsType({\n types,\n node,\n}: {\n types: NodeType | NodeType[]\n node: Node | null | undefined\n}) {\n return (node && Array.isArray(types) && types.includes(node.type)) || node?.type === types\n}\n\n/**\n * Extension based on:\n * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js\n * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts\n */\n\nexport interface TrailingNodeOptions {\n /**\n * The node type that should be inserted at the end of the document.\n * @note the node will always be added to the `notAfter` lists to\n * prevent an infinite loop.\n * @default undefined\n */\n node?: string\n /**\n * The node types after which the trailing node should not be inserted.\n * @default ['paragraph']\n */\n notAfter?: string | string[]\n}\n\n/**\n * This extension allows you to add an extra node at the end of the document.\n * @see https://www.tiptap.dev/api/extensions/trailing-node\n */\nexport const TrailingNode = Extension.create<TrailingNodeOptions>({\n name: 'trailingNode',\n\n addOptions() {\n return {\n node: undefined,\n notAfter: [],\n }\n },\n\n addProseMirrorPlugins() {\n const plugin = new PluginKey(this.name)\n const defaultNode =\n this.options.node ||\n this.editor.schema.topNodeType.contentMatch.defaultType?.name ||\n 'paragraph'\n\n const disabledNodes = Object.entries(this.editor.schema.nodes)\n .map(([, value]) => value)\n .filter(node => (this.options.notAfter || []).concat(defaultNode).includes(node.name))\n\n return [\n new Plugin({\n key: plugin,\n appendTransaction: (transactions, __, state) => {\n const { doc, tr, schema } = state\n const shouldInsertNodeAtEnd = plugin.getState(state)\n const endPosition = doc.content.size\n const type = schema.nodes[defaultNode]\n\n if (transactions.some(transaction => transaction.getMeta(skipTrailingNodeMeta))) {\n return\n }\n\n if (!shouldInsertNodeAtEnd) {\n return\n }\n\n return tr.insert(endPosition, type.create())\n },\n state: {\n init: (_, state) => {\n const lastNode = state.tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n apply: (tr, value) => {\n if (!tr.docChanged) {\n return value\n }\n\n // Ignore transactions from UniqueID extension to prevent infinite loops\n // when UniqueID adds IDs to newly inserted trailing nodes\n if (tr.getMeta('__uniqueIDTransaction')) {\n return value\n }\n\n const lastNode = tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n },\n }),\n ]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { history, redo, undo } from '@tiptap/pm/history'\n\nexport interface UndoRedoOptions {\n /**\n * The amount of history events that are collected before the oldest events are discarded.\n * @default 100\n * @example 50\n */\n depth: number\n\n /**\n * The delay (in milliseconds) between changes after which a new group should be started.\n * @default 500\n * @example 1000\n */\n newGroupDelay: number\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n undoRedo: {\n /**\n * Undo recent changes\n * @example editor.commands.undo()\n */\n undo: () => ReturnType\n /**\n * Reapply reverted changes\n * @example editor.commands.redo()\n */\n redo: () => ReturnType\n }\n }\n}\n\n/**\n * This extension allows you to undo and redo recent changes.\n * @see https://www.tiptap.dev/api/extensions/undo-redo\n *\n * **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove\n * the `undo-redo` extension, as it is not compatible with the `collaboration` extension.\n *\n * `@tiptap/extension-collaboration` uses its own history implementation.\n */\nexport const UndoRedo = Extension.create<UndoRedoOptions>({\n name: 'undoRedo',\n\n addOptions() {\n return {\n depth: 100,\n newGroupDelay: 500,\n }\n },\n\n addCommands() {\n return {\n undo:\n () =>\n ({ state, dispatch }) => {\n return undo(state, dispatch)\n },\n redo:\n () =>\n ({ state, dispatch }) => {\n return redo(state, dispatch)\n },\n }\n },\n\n addProseMirrorPlugins() {\n return [history(this.options)]\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-z': () => this.editor.commands.undo(),\n 'Shift-Mod-z': () => this.editor.commands.redo(),\n 'Mod-y': () => this.editor.commands.redo(),\n\n // Russian keyboard layouts\n 'Mod-я': () => this.editor.commands.undo(),\n 'Shift-Mod-я': () => this.editor.commands.redo(),\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;AAE1B,mBAAkC;AAgE3B,IAAM,iBAAiB,sBAAU,OAAqD;AAAA,EAC3F,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,MACN,aAAa,UAAQ,KAAK;AAAA,MAC1B,aAAa,UAAQ,KAAK,MAAM,GAAG,EAAE,OAAO,UAAQ,SAAS,EAAE,EAAE;AAAA,IACnE;AAAA,EACF;AAAA,EAEA,aAAa;AACX,WAAO;AAAA,MACL,YAAY,MAAM;AAAA,MAClB,OAAO,MAAM;AAAA,IACf;AAAA,EACF;AAAA,EAEA,iBAAiB;AACf,SAAK,QAAQ,aAAa,aAAW;AACnC,YAAM,QAAO,mCAAS,SAAQ,KAAK,OAAO,MAAM;AAChD,YAAM,QAAO,mCAAS,SAAQ,KAAK,QAAQ;AAE3C,UAAI,SAAS,YAAY;AACvB,cAAM,OAAO,KAAK,YAAY,GAAG,KAAK,QAAQ,MAAM,QAAW,GAAG;AAElE,eAAO,KAAK,QAAQ,YAAY,IAAI;AAAA,MACtC;AAEA,aAAO,KAAK;AAAA,IACd;AAEA,SAAK,QAAQ,QAAQ,aAAW;AAC9B,YAAM,QAAO,mCAAS,SAAQ,KAAK,OAAO,MAAM;AAChD,YAAM,OAAO,KAAK,YAAY,GAAG,KAAK,QAAQ,MAAM,KAAK,GAAG;AAE5D,aAAO,KAAK,QAAQ,YAAY,IAAI;AAAA,IACtC;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,QAAI,wBAAwB;AAE5B,WA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M;AACvB,mBAAO,qBAAK,OAAO,QAAQ;AAAA,MAC7B;AAAA,MACF,MACE,MACA,CAAC,EAAE,OAAO,SAAS,MAAM;AACvB,mBAAO,qBAAK,OAAO,QAAQ;AAAA,MAC7B;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO,KAAC,wBAAQ,KAAK,OAAO,CAAC;AAAA,EAC/B;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,eAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MAC/C,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA;AAAA,MAGzC,cAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,oBAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,IACjD;AAAA,EACF;AACF,CAAC;","names":["import_core","import_core","import_state","import_core","import_state","import_core","import_state","import_view","import_core","import_view","import_view","import_core","import_view","node","import_core","import_state","import_view","import_core","import_state","import_core"]} | ||
| {"version":3,"sources":["../src/index.ts","../src/character-count/character-count.ts","../src/drop-cursor/drop-cursor.ts","../src/focus/focus.ts","../src/gap-cursor/gap-cursor.ts","../src/placeholder/constants.ts","../src/placeholder/placeholder.ts","../src/placeholder/plugins/PlaceholderPlugin.ts","../src/placeholder/utils/buildPlaceholderDecorations.ts","../src/placeholder/utils/createPlaceholderDecoration.ts","../src/placeholder/utils/placeholderStateField.ts","../src/placeholder/utils/resolveTopLevelRange.ts","../src/placeholder/utils/preparePlaceholderAttribute.ts","../src/selection/selection.ts","../src/trailing-node/trailing-node.ts","../src/undo-redo/undo-redo.ts"],"sourcesContent":["export * from './character-count/index.js'\nexport * from './drop-cursor/index.js'\nexport * from './focus/index.js'\nexport * from './gap-cursor/index.js'\nexport * from './placeholder/index.js'\nexport * from './selection/index.js'\nexport * from './trailing-node/index.js'\nexport * from './undo-redo/index.js'\n","import { Extension } from '@tiptap/core'\nimport type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport interface CharacterCountOptions {\n /**\n * The maximum number of characters that should be allowed. Defaults to `0`.\n * @default null\n * @example 180\n */\n limit: number | null | undefined\n /**\n * The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n * If set to `nodeSize`, the nodeSize of the document is used.\n * @default 'textSize'\n * @example 'textSize'\n */\n mode: 'textSize' | 'nodeSize'\n /**\n * Sets whether the content will be automatically trimmed when programatically setting content over the limit.\n * If set to false, the user will be able to trim the text manually.\n * @default true\n * @example false\n */\n autoTrim?: boolean\n /**\n * The text counter function to use. Defaults to a simple character count.\n * @default (text) => text.length\n * @example (text) => [...new Intl.Segmenter().segment(text)].length\n */\n textCounter: (text: string) => number\n /**\n * The word counter function to use. Defaults to a simple word count.\n * @default (text) => text.split(' ').filter(word => word !== '').length\n * @example (text) => text.split(/\\s+/).filter(word => word !== '').length\n */\n wordCounter: (text: string) => number\n}\n\nexport interface CharacterCountStorage {\n /**\n * Get the number of characters for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the characters from. Defaults to the current document.\n * @param options.mode The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n */\n characters: (options?: { node?: ProseMirrorNode; mode?: 'textSize' | 'nodeSize' }) => number\n\n /**\n * Get the number of words for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the words from. Defaults to the current document.\n */\n words: (options?: { node?: ProseMirrorNode }) => number\n}\n\ndeclare module '@tiptap/core' {\n interface Storage {\n characterCount: CharacterCountStorage\n }\n}\n\n/**\n * This extension allows you to count the characters and words of your document.\n * @see https://tiptap.dev/api/extensions/character-count\n */\nexport const CharacterCount = Extension.create<CharacterCountOptions, CharacterCountStorage>({\n name: 'characterCount',\n\n addOptions() {\n return {\n limit: null,\n autoTrim: true,\n mode: 'textSize',\n textCounter: text => text.length,\n wordCounter: text => text.split(' ').filter(word => word !== '').length,\n }\n },\n\n addStorage() {\n return {\n characters: () => 0,\n words: () => 0,\n }\n },\n\n onBeforeCreate() {\n this.storage.characters = options => {\n const node = options?.node || this.editor.state.doc\n const mode = options?.mode || this.options.mode\n\n if (mode === 'textSize') {\n const text = node.textBetween(0, node.content.size, undefined, ' ')\n\n return this.options.textCounter(text)\n }\n\n return node.nodeSize\n }\n\n this.storage.words = options => {\n const node = options?.node || this.editor.state.doc\n const text = node.textBetween(0, node.content.size, ' ', ' ')\n\n return this.options.wordCounter(text)\n }\n },\n\n addProseMirrorPlugins() {\n let initialEvaluationDone = false\n\n return [\n new Plugin({\n key: new PluginKey('characterCount'),\n appendTransaction: (transactions, oldState, newState) => {\n if (initialEvaluationDone) {\n return\n }\n\n const limit = this.options.limit\n const autoTrim = this.options.autoTrim\n\n if (limit === null || limit === undefined || limit === 0 || autoTrim === false) {\n initialEvaluationDone = true\n return\n }\n\n const initialContentSize = this.storage.characters({ node: newState.doc })\n\n if (initialContentSize > limit) {\n const over = initialContentSize - limit\n const from = 0\n const to = over\n\n console.warn(\n `[CharacterCount] Initial content exceeded limit of ${limit} characters. Content was automatically trimmed.`,\n )\n const tr = newState.tr.deleteRange(from, to)\n initialEvaluationDone = true\n return tr\n }\n\n initialEvaluationDone = true\n },\n filterTransaction: (transaction, state) => {\n const limit = this.options.limit\n\n // Nothing has changed or no limit is defined. Ignore it.\n if (!transaction.docChanged || limit === 0 || limit === null || limit === undefined) {\n return true\n }\n\n const oldSize = this.storage.characters({ node: state.doc })\n const newSize = this.storage.characters({ node: transaction.doc })\n\n // Everything is in the limit. Good.\n if (newSize <= limit) {\n return true\n }\n\n // The limit has already been exceeded but will be reduced.\n if (oldSize > limit && newSize > limit && newSize <= oldSize) {\n return true\n }\n\n // The limit has already been exceeded and will be increased further.\n if (oldSize > limit && newSize > limit && newSize > oldSize) {\n return false\n }\n\n const isPaste = transaction.getMeta('paste')\n\n // Block all exceeding transactions that were not pasted.\n if (!isPaste) {\n return false\n }\n\n // For pasted content, we try to remove the exceeding content.\n const pos = transaction.selection.$head.pos\n const over = newSize - limit\n const from = pos - over\n const to = pos\n\n // It’s probably a bad idea to mutate transactions within `filterTransaction`\n // but for now this is working fine.\n transaction.deleteRange(from, to)\n\n // In some situations, the limit will continue to be exceeded after trimming.\n // This happens e.g. when truncating within a complex node (e.g. table)\n // and ProseMirror has to close this node again.\n // If this is the case, we prevent the transaction completely.\n const updatedSize = this.storage.characters({ node: transaction.doc })\n\n if (updatedSize > limit) {\n return false\n }\n\n return true\n },\n }),\n ]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { dropCursor } from '@tiptap/pm/dropcursor'\n\nexport interface DropcursorOptions {\n /**\n * The color of the drop cursor. Use `false` to apply no color and rely only on class.\n * @default 'currentColor'\n * @example 'red'\n */\n color?: string | false\n\n /**\n * The width of the drop cursor\n * @default 1\n * @example 2\n */\n width: number | undefined\n\n /**\n * The class of the drop cursor\n * @default undefined\n * @example 'drop-cursor'\n */\n class: string | undefined\n}\n\n/**\n * This extension allows you to add a drop cursor to your editor.\n * A drop cursor is a line that appears when you drag and drop content\n * in-between nodes.\n * @see https://tiptap.dev/api/extensions/dropcursor\n */\nexport const Dropcursor = Extension.create<DropcursorOptions>({\n name: 'dropCursor',\n\n addOptions() {\n return {\n color: 'currentColor',\n width: 1,\n class: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [dropCursor(this.options)]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const Focus = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope =\n (this.options.mode === 'deepest' && maxLevels - currentLevel > 0) ||\n (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n","import type { ParentConfig } from '@tiptap/core'\nimport { callOrReturn, Extension, getExtensionField } from '@tiptap/core'\nimport { gapCursor } from '@tiptap/pm/gapcursor'\n\ndeclare module '@tiptap/core' {\n interface NodeConfig<Options, Storage> {\n /**\n * A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.\n * @default null\n */\n allowGapCursor?:\n | boolean\n | null\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['allowGapCursor']\n }) => boolean | null)\n }\n}\n\n/**\n * This extension allows you to add a gap cursor to your editor.\n * A gap cursor is a cursor that appears when you click on a place\n * where no content is present, for example inbetween nodes.\n * @see https://tiptap.dev/api/extensions/gapcursor\n */\nexport const Gapcursor = Extension.create({\n name: 'gapCursor',\n\n addProseMirrorPlugins() {\n return [gapCursor()]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n allowGapCursor: callOrReturn(getExtensionField(extension, 'allowGapCursor', context)) ?? null,\n }\n },\n})\n","import { PluginKey } from '@tiptap/pm/state'\nimport type { DecorationSet } from '@tiptap/pm/view'\n\n/** The default data attribute label */\nexport const DEFAULT_DATA_ATTRIBUTE = 'placeholder'\n\n/** The plugin key used to store and read the placeholder decoration set */\nexport const PLUGIN_KEY = new PluginKey<DecorationSet>('tiptap__placeholder')\n","import { Extension } from '@tiptap/core'\n\nimport { DEFAULT_DATA_ATTRIBUTE } from './constants.js'\nimport { createPlaceholderPlugin } from './plugins/PlaceholderPlugin.js'\nimport type { PlaceholderOptions } from './types.js'\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\n */\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n dataAttribute: DEFAULT_DATA_ATTRIBUTE,\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n return [createPlaceholderPlugin({ editor: this.editor, options: this.options })]\n },\n})\n","import type { Editor } from '@tiptap/core'\nimport { Plugin } from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport { DEFAULT_DATA_ATTRIBUTE, PLUGIN_KEY } from '../constants.js'\nimport type { PlaceholderOptions } from '../types.js'\nimport { buildPlaceholderDecorations } from '../utils/buildPlaceholderDecorations.js'\nimport { createPlaceholderStateField } from '../utils/placeholderStateField.js'\nimport { preparePlaceholderAttribute } from '../utils/preparePlaceholderAttribute.js'\n\nexport type CreatePluginOptions = {\n editor: Editor\n options: PlaceholderOptions\n}\n\n/**\n * Creates the ProseMirror plugin that renders placeholder decorations.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @returns The configured placeholder plugin.\n */\nexport function createPlaceholderPlugin({ editor, options }: CreatePluginOptions) {\n const dataAttribute = options.dataAttribute\n ? `data-${preparePlaceholderAttribute(options.dataAttribute)}`\n : `data-${DEFAULT_DATA_ATTRIBUTE}`\n\n const useResolvedPath = options.showOnlyCurrent && !options.includeChildren\n\n return new Plugin({\n key: PLUGIN_KEY,\n ...(useResolvedPath\n ? {}\n : {\n state: createPlaceholderStateField({ editor, options, dataAttribute }),\n }),\n props: {\n decorations: useResolvedPath\n ? ({ doc, selection }) =>\n buildPlaceholderDecorations({ editor, options, dataAttribute, doc, selection })\n : state => {\n if (options.showOnlyWhenEditable && !editor.isEditable) {\n return DecorationSet.empty\n }\n\n return PLUGIN_KEY.getState(state) ?? DecorationSet.empty\n },\n },\n })\n}\n","import type { Editor } from '@tiptap/core'\nimport { isNodeEmpty } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Selection } from '@tiptap/pm/state'\nimport type { Decoration } from '@tiptap/pm/view'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\nimport { createPlaceholderDecoration } from './createPlaceholderDecoration.js'\n\nfunction resolveEmptyNodeClass(\n emptyNodeClass: PlaceholderOptions['emptyNodeClass'],\n props: { editor: Editor; node: Node; pos: number; hasAnchor: boolean },\n): string {\n return typeof emptyNodeClass === 'function' ? emptyNodeClass(props) : emptyNodeClass\n}\n\n/**\n * Scans a document range for empty textblocks that should receive placeholder\n * decorations. Used by the slow path and incremental state updates.\n */\nexport function scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from,\n to,\n}: {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n from: number\n to: number\n}): Decoration[] {\n const { anchor } = selection\n const decorations: Decoration[] = []\n const isEmptyDoc = editor.isEmpty\n\n doc.nodesBetween(from, to, (node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && isNodeEmpty(node)\n\n if (!node.type.isTextblock) {\n return options.includeChildren\n }\n\n if ((hasAnchor || !options.showOnlyCurrent) && isEmpty) {\n decorations.push(\n createPlaceholderDecoration({\n editor,\n isEmptyDoc,\n dataAttribute,\n hasAnchor,\n placeholder: options.placeholder,\n classes: {\n emptyEditor: options.emptyEditorClass,\n emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {\n editor,\n node,\n pos,\n hasAnchor,\n }),\n },\n node,\n pos,\n }),\n )\n }\n\n return options.includeChildren\n })\n\n return decorations\n}\n\n/**\n * Builds the placeholder decorations for the current document state.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @param options.dataAttribute - The prepared `data-*` attribute name.\n * @param options.doc - The current document node.\n * @param options.selection - The current selection.\n * @returns A decoration set, or `null` when no placeholders should be shown.\n */\nexport function buildPlaceholderDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n}: {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n}): DecorationSet | null {\n const active = editor.isEditable || !options.showOnlyWhenEditable\n\n if (!active) {\n return null\n }\n\n const { anchor } = selection\n const decorations: Decoration[] = []\n const isEmptyDoc = editor.isEmpty\n\n const useResolvedPath = options.showOnlyCurrent && !options.includeChildren\n\n if (useResolvedPath) {\n const resolved = doc.resolve(anchor)\n\n // When the selection spans the whole document (e.g. an `AllSelection`\n // after Cmd+A), the anchor resolves to the document level (depth 0). In\n // that case the relevant textblock is the node directly after the\n // position rather than an ancestor. otherwise the placeholder would\n // disappear after selecting all and deleting.\n const node = resolved.depth > 0 ? resolved.node(1) : resolved.nodeAfter\n const nodeStart = resolved.depth > 0 ? resolved.before(1) : anchor\n\n if (node && node.type.isTextblock && isNodeEmpty(node)) {\n const hasAnchor = anchor >= nodeStart && anchor <= nodeStart + node.nodeSize\n\n decorations.push(\n createPlaceholderDecoration({\n editor,\n isEmptyDoc,\n dataAttribute,\n hasAnchor,\n placeholder: options.placeholder,\n classes: {\n emptyEditor: options.emptyEditorClass,\n emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {\n editor,\n node,\n pos: nodeStart,\n hasAnchor,\n }),\n },\n node,\n pos: nodeStart,\n }),\n )\n }\n } else {\n decorations.push(\n ...scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from: 0,\n to: doc.content.size,\n }),\n )\n }\n\n return DecorationSet.create(doc, decorations)\n}\n","import type { Editor } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport { Decoration } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\n\n/**\n * Creates a ProseMirror node decoration that applies a placeholder\n * CSS class and data attribute to an empty node.\n * @param options.editor - The editor instance\n * @param options.pos - The position of the node in the document\n * @param options.node - The ProseMirror node\n * @param options.isEmptyDoc - Whether the entire document is empty\n * @param options.hasAnchor - Whether the selection anchor is within the node\n * @param options.dataAttribute - The data attribute name (e.g. `data-placeholder`)\n * @param options.classes - CSS classes for empty nodes and the empty editor\n * @param options.placeholder - The placeholder text or a function that returns it\n * @returns A ProseMirror node decoration with placeholder classes and data attribute\n */\nexport function createPlaceholderDecoration(options: {\n editor: Editor\n pos: number\n node: Node\n isEmptyDoc: boolean\n hasAnchor: boolean\n dataAttribute: string\n classes: {\n emptyEditor: PlaceholderOptions['emptyEditorClass']\n emptyNode: string\n }\n placeholder: PlaceholderOptions['placeholder']\n}) {\n const {\n editor,\n placeholder,\n dataAttribute,\n pos,\n node,\n isEmptyDoc,\n hasAnchor,\n classes: { emptyNode, emptyEditor },\n } = options\n const classes = [emptyNode]\n\n if (isEmptyDoc) {\n classes.push(emptyEditor)\n }\n\n return Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n [dataAttribute]:\n typeof placeholder === 'function'\n ? placeholder({\n editor,\n node,\n pos,\n hasAnchor,\n })\n : placeholder,\n })\n}\n","import type { Editor } from '@tiptap/core'\nimport { getChangedRanges } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport type { EditorState, StateField, Transaction } from '@tiptap/pm/state'\nimport type { Selection } from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\nimport {\n buildPlaceholderDecorations,\n scanRangeForDecorations,\n} from './buildPlaceholderDecorations.js'\nimport {\n getTopLevelBlocksInRange,\n mergeRanges,\n resolveTopLevelRange,\n toContentRelativeRange,\n} from './resolveTopLevelRange.js'\n\n/** Options passed to {@link createPlaceholderStateField}. */\nexport type CreatePlaceholderStateFieldOptions = {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n}\n\n/**\n * Expands a single changed range to the top-level blocks it touches.\n * Also resolves blocks at range boundaries so split/merge edits update\n * adjacent empty nodes (e.g. a new paragraph after Enter).\n */\nfunction collectBlocksForChange(\n doc: Node,\n change: { from: number; to: number },\n): Array<{ from: number; to: number }> {\n const ranges = getTopLevelBlocksInRange(doc, change.from, change.to)\n\n ranges.push(toContentRelativeRange(doc, resolveTopLevelRange(doc, change.from)))\n\n if (change.to > change.from) {\n ranges.push(\n toContentRelativeRange(\n doc,\n resolveTopLevelRange(doc, Math.min(change.to, doc.content.size + 1) - 1),\n ),\n )\n } else if (change.from < doc.content.size + 1) {\n ranges.push(\n toContentRelativeRange(\n doc,\n resolveTopLevelRange(doc, Math.min(change.from + 1, doc.content.size)),\n ),\n )\n }\n\n return ranges\n}\n\n/**\n * Collects content-relative top-level block ranges that need placeholder\n * decorations recomputed after a transaction.\n */\nfunction collectRescanRanges(\n tr: Transaction,\n oldState: EditorState,\n newState: EditorState,\n): Array<{ from: number; to: number }> {\n const ranges: Array<{ from: number; to: number }> = []\n\n if (tr.docChanged) {\n const changes = getChangedRanges(tr)\n\n for (const change of changes) {\n ranges.push(...collectBlocksForChange(newState.doc, change.newRange))\n }\n }\n\n if (tr.selectionSet) {\n ranges.push(\n toContentRelativeRange(\n newState.doc,\n resolveTopLevelRange(newState.doc, tr.mapping.map(oldState.selection.anchor)),\n ),\n )\n ranges.push(\n toContentRelativeRange(\n newState.doc,\n resolveTopLevelRange(newState.doc, newState.selection.anchor),\n ),\n )\n }\n\n return mergeRanges(ranges)\n}\n\n/** Clamps a content-relative range to `[0, doc.content.size]`. */\nfunction clampRange(from: number, to: number, doc: Node): { from: number; to: number } {\n const clampedFrom = Math.max(0, Math.min(from, doc.content.size))\n const clampedTo = Math.max(clampedFrom, Math.min(to, doc.content.size))\n\n return { from: clampedFrom, to: clampedTo }\n}\n\n/**\n * Removes and rebuilds placeholder decorations within the given ranges.\n * Only drops decorations fully contained in a range so mapped decorations\n * on neighbouring blocks (e.g. at a block boundary) are kept intact.\n */\nfunction updateDecorationsInRanges({\n decorations,\n ranges,\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n}: {\n decorations: DecorationSet\n ranges: Array<{ from: number; to: number }>\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n}): DecorationSet {\n let next = decorations\n\n for (const range of ranges) {\n const { from, to } = clampRange(range.from, range.to, doc)\n const existing = next\n .find(from, to)\n .filter(decoration => decoration.from >= from && decoration.to <= to)\n\n if (existing.length) {\n next = next.remove(existing)\n }\n\n const newDecos = scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from,\n to,\n })\n\n if (newDecos.length) {\n next = next.add(doc, newDecos)\n }\n }\n\n return next\n}\n\n/**\n * Creates the incremental `StateField<DecorationSet>` used by the slow path\n * (`showOnlyCurrent: false` or `includeChildren: true`).\n *\n * Decorations are mapped through each transaction and only recomputed for\n * top-level blocks touched by document or selection changes.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @param options.dataAttribute - The prepared `data-*` attribute name.\n * @returns A ProseMirror state field storing the placeholder decoration set.\n */\nexport function createPlaceholderStateField({\n editor,\n options,\n dataAttribute,\n}: CreatePlaceholderStateFieldOptions): StateField<DecorationSet> {\n return {\n init(_config, state: EditorState) {\n const decorations = buildPlaceholderDecorations({\n editor,\n options,\n dataAttribute,\n doc: state.doc,\n selection: state.selection,\n })\n\n return decorations ?? DecorationSet.empty\n },\n\n apply(tr: Transaction, prev: DecorationSet, oldState: EditorState, newState: EditorState) {\n if (!tr.docChanged && !tr.selectionSet) {\n return prev\n }\n\n const mapped = prev.map(tr.mapping, tr.doc)\n const ranges = collectRescanRanges(tr, oldState, newState)\n\n return updateDecorationsInRanges({\n decorations: mapped,\n ranges,\n editor,\n options,\n dataAttribute,\n doc: newState.doc,\n selection: newState.selection,\n })\n },\n }\n}\n","import type { Node } from '@tiptap/pm/model'\n\n/**\n * Resolves a document position to the `[from, to)` range of its containing\n * top-level block node in absolute document positions.\n */\nexport function resolveTopLevelRange(doc: Node, pos: number): { from: number; to: number } {\n const resolved = doc.resolve(pos)\n\n if (resolved.depth === 0) {\n const node = resolved.nodeAfter ?? resolved.nodeBefore\n\n if (!node) {\n return { from: pos, to: pos }\n }\n\n const nodePos = resolved.nodeAfter ? pos : pos - node.nodeSize\n\n return { from: nodePos, to: nodePos + node.nodeSize }\n }\n\n const topLevelPos = resolved.before(1)\n const node = resolved.node(1)\n\n return { from: topLevelPos, to: topLevelPos + node.nodeSize }\n}\n\n/**\n * Converts an absolute document range to content-relative positions used by\n * `Node#nodesBetween` and `Node#forEach` offsets.\n */\nexport function toContentRelativeRange(\n doc: Node,\n range: { from: number; to: number },\n): { from: number; to: number } {\n return {\n from: Math.max(0, range.from - 1),\n to: Math.min(doc.content.size, range.to - 1),\n }\n}\n\n/**\n * Returns the top-level block ranges that intersect a document change range.\n * Input `from`/`to` are absolute positions (e.g. from `getChangedRanges`).\n * Returned ranges are content-relative, matching `Node#forEach` offsets.\n */\nexport function getTopLevelBlocksInRange(\n doc: Node,\n from: number,\n to: number,\n): Array<{ from: number; to: number }> {\n const ranges: Array<{ from: number; to: number }> = []\n\n doc.forEach((node, offset) => {\n const nodeStart = offset\n const nodeEnd = nodeStart + node.nodeSize\n const absNodeStart = nodeStart + 1\n const absNodeEnd = nodeEnd + 1\n\n if (absNodeStart < to && absNodeEnd > from) {\n ranges.push({ from: nodeStart, to: nodeEnd })\n }\n })\n\n return ranges\n}\n\n/**\n * Sorts ranges by start position and merges overlapping or adjacent ranges.\n */\nexport function mergeRanges(\n ranges: Array<{ from: number; to: number }>,\n): Array<{ from: number; to: number }> {\n if (ranges.length === 0) {\n return []\n }\n\n const sorted = [...ranges].sort((a, b) => a.from - b.from)\n const merged: Array<{ from: number; to: number }> = [{ ...sorted[0] }]\n\n for (let i = 1; i < sorted.length; i += 1) {\n const last = merged[merged.length - 1]\n const current = sorted[i]\n\n if (current.from <= last.to) {\n last.to = Math.max(last.to, current.to)\n } else {\n merged.push({ ...current })\n }\n }\n\n return merged\n}\n","/**\n * Prepares the placeholder attribute by ensuring it is properly formatted.\n * @param attr - The placeholder attribute string.\n * @returns The prepared placeholder attribute string.\n */\nexport function preparePlaceholderAttribute(attr: string): string {\n return (\n attr\n // replace whitespace with dashes\n .replace(/\\s+/g, '-')\n // replace non-alphanumeric characters\n // or special chars like $, %, &, etc.\n // but not dashes\n .replace(/[^a-zA-Z0-9-]/g, '')\n // and replace any numeric character at the start\n .replace(/^[0-9-]+/, '')\n // and finally replace any stray, leading dashes\n .replace(/^-+/, '')\n .toLowerCase()\n )\n}\n","import { Extension, isNodeSelection, type Editor } from '@tiptap/core'\nimport { Plugin, PluginKey, type EditorState } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * Whether the native browser selection should be cleared on blur and restored on focus.\n * Only applies to non-empty text selections in an editable editor.\n */\nfunction shouldSyncDomSelection(state: EditorState, editor: Editor): boolean {\n return !state.selection.empty && !isNodeSelection(state.selection) && editor.isEditable\n}\n\n/**\n * Whether the selection decoration should be rendered to keep the selection\n * visible while the editor is blurred (and not dragging).\n */\nfunction shouldPreserveSelection(state: EditorState, editor: Editor): boolean {\n return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging\n}\n\nfunction clearDomSelection() {\n window.getSelection()?.removeAllRanges()\n}\n\n/**\n * Sync the native selection from the editor state.\n * @see https://prosemirror.net/docs/ref/#view.EditorView.focus\n */\nfunction restoreDomSelection(view: EditorView) {\n view.focus()\n}\n\n/**\n * This extension allows you to add a class to the selected text when the editor is blurred.\n * It clears the native browser selection on blur (so `::selection` styles do not overlap the\n * decoration) and restores it when the editor is focused again.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create<SelectionOptions>({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (!shouldPreserveSelection(state, editor)) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n handleDOMEvents: {\n blur(view) {\n if (!shouldSyncDomSelection(view.state, editor)) {\n return false\n }\n\n clearDomSelection()\n\n return false\n },\n focus(view) {\n if (!shouldSyncDomSelection(view.state, editor)) {\n return false\n }\n\n requestAnimationFrame(() => {\n if (!editor.isDestroyed && view.hasFocus()) {\n restoreDomSelection(view)\n }\n })\n\n return false\n },\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n","import { Extension } from '@tiptap/core'\nimport type { Node, NodeType } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport const skipTrailingNodeMeta = 'skipTrailingNode'\n\nfunction nodeEqualsType({\n types,\n node,\n}: {\n types: NodeType | NodeType[]\n node: Node | null | undefined\n}) {\n return (node && Array.isArray(types) && types.includes(node.type)) || node?.type === types\n}\n\n/**\n * Extension based on:\n * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js\n * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts\n */\n\nexport interface TrailingNodeOptions {\n /**\n * The node type that should be inserted at the end of the document.\n * @note the node will always be added to the `notAfter` lists to\n * prevent an infinite loop.\n * @default undefined\n */\n node?: string\n /**\n * The node types after which the trailing node should not be inserted.\n * @default ['paragraph']\n */\n notAfter?: string | string[]\n}\n\n/**\n * This extension allows you to add an extra node at the end of the document.\n * @see https://www.tiptap.dev/api/extensions/trailing-node\n */\nexport const TrailingNode = Extension.create<TrailingNodeOptions>({\n name: 'trailingNode',\n\n addOptions() {\n return {\n node: undefined,\n notAfter: [],\n }\n },\n\n addProseMirrorPlugins() {\n const plugin = new PluginKey(this.name)\n const defaultNode =\n this.options.node ||\n this.editor.schema.topNodeType.contentMatch.defaultType?.name ||\n 'paragraph'\n\n const disabledNodes = Object.entries(this.editor.schema.nodes)\n .map(([, value]) => value)\n .filter(node => (this.options.notAfter || []).concat(defaultNode).includes(node.name))\n\n return [\n new Plugin({\n key: plugin,\n appendTransaction: (transactions, __, state) => {\n const { doc, tr, schema } = state\n const shouldInsertNodeAtEnd = plugin.getState(state)\n const endPosition = doc.content.size\n const type = schema.nodes[defaultNode]\n\n if (transactions.some(transaction => transaction.getMeta(skipTrailingNodeMeta))) {\n return\n }\n\n if (!shouldInsertNodeAtEnd) {\n return\n }\n\n return tr.insert(endPosition, type.create())\n },\n state: {\n init: (_, state) => {\n const lastNode = state.tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n apply: (tr, value) => {\n if (!tr.docChanged) {\n return value\n }\n\n // Ignore transactions from UniqueID extension to prevent infinite loops\n // when UniqueID adds IDs to newly inserted trailing nodes\n if (tr.getMeta('__uniqueIDTransaction')) {\n return value\n }\n\n const lastNode = tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n },\n }),\n ]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { history, redo, undo } from '@tiptap/pm/history'\n\nexport interface UndoRedoOptions {\n /**\n * The amount of history events that are collected before the oldest events are discarded.\n * @default 100\n * @example 50\n */\n depth: number\n\n /**\n * The delay (in milliseconds) between changes after which a new group should be started.\n * @default 500\n * @example 1000\n */\n newGroupDelay: number\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n undoRedo: {\n /**\n * Undo recent changes\n * @example editor.commands.undo()\n */\n undo: () => ReturnType\n /**\n * Reapply reverted changes\n * @example editor.commands.redo()\n */\n redo: () => ReturnType\n }\n }\n}\n\n/**\n * This extension allows you to undo and redo recent changes.\n * @see https://www.tiptap.dev/api/extensions/undo-redo\n *\n * **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove\n * the `undo-redo` extension, as it is not compatible with the `collaboration` extension.\n *\n * `@tiptap/extension-collaboration` uses its own history implementation.\n */\nexport const UndoRedo = Extension.create<UndoRedoOptions>({\n name: 'undoRedo',\n\n addOptions() {\n return {\n depth: 100,\n newGroupDelay: 500,\n }\n },\n\n addCommands() {\n return {\n undo:\n () =>\n ({ state, dispatch }) => {\n return undo(state, dispatch)\n },\n redo:\n () =>\n ({ state, dispatch }) => {\n return redo(state, dispatch)\n },\n }\n },\n\n addProseMirrorPlugins() {\n return [history(this.options)]\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-z': () => this.editor.commands.undo(),\n 'Shift-Mod-z': () => this.editor.commands.redo(),\n 'Mod-y': () => this.editor.commands.redo(),\n\n // Russian keyboard layouts\n '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,YACT;AAIA,gBAAI,GAAG,QAAQ,uBAAuB,GAAG;AACvC,qBAAO;AAAA,YACT;AAEA,kBAAM,WAAW,GAAG,IAAI;AAExB,mBAAO,CAAC,eAAe,EAAE,MAAM,UAAU,OAAO,cAAc,CAAC;AAAA,UACjE;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AC1GD,IAAAC,gBAA0B;AAC1B,qBAAoC;AA4C7B,IAAM,WAAW,wBAAU,OAAwB;AAAA,EACxD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO;AAAA,MACP,eAAe;AAAA,IACjB;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,MACE,MACA,CAAC,EAAE,OAAO,SAAS,MAAM;AACvB,mBAAO,qBAAK,OAAO,QAAQ;AAAA,MAC7B;AAAA,MACF,MACE,MACA,CAAC,EAAE,OAAO,SAAS,MAAM;AACvB,mBAAO,qBAAK,OAAO,QAAQ;AAAA,MAC7B;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO,KAAC,wBAAQ,KAAK,OAAO,CAAC;AAAA,EAC/B;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,eAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MAC/C,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA;AAAA,MAGzC,cAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,oBAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,IACjD;AAAA,EACF;AACF,CAAC;","names":["import_core","import_core","import_state","import_core","import_state","import_core","import_state","import_view","import_core","import_view","import_view","import_core","import_view","node","import_core","import_state","import_view","import_core","import_state","import_core"]} |
+3
-1
@@ -236,3 +236,5 @@ import { Extension, ParentConfig, Editor } from '@tiptap/core'; | ||
| /** | ||
| * This extension allows you to add a class to the selected text. | ||
| * This extension allows you to add a class to the selected text when the editor is blurred. | ||
| * It clears the native browser selection on blur (so `::selection` styles do not overlap the | ||
| * decoration) and restores it when the editor is focused again. | ||
| * @see https://www.tiptap.dev/api/extensions/selection | ||
@@ -239,0 +241,0 @@ */ |
+3
-1
@@ -236,3 +236,5 @@ import { Extension, ParentConfig, Editor } from '@tiptap/core'; | ||
| /** | ||
| * This extension allows you to add a class to the selected text. | ||
| * This extension allows you to add a class to the selected text when the editor is blurred. | ||
| * It clears the native browser selection on blur (so `::selection` styles do not overlap the | ||
| * decoration) and restores it when the editor is focused again. | ||
| * @see https://www.tiptap.dev/api/extensions/selection | ||
@@ -239,0 +241,0 @@ */ |
+34
-11
@@ -574,12 +574,18 @@ // src/character-count/character-count.ts | ||
| // src/selection/selection.ts | ||
| import { createStyleTag, Extension as Extension6, isNodeSelection } from "@tiptap/core"; | ||
| import { Extension as Extension6, isNodeSelection } from "@tiptap/core"; | ||
| import { Plugin as Plugin4, PluginKey as PluginKey4 } from "@tiptap/pm/state"; | ||
| import { Decoration as Decoration3, DecorationSet as DecorationSet5 } from "@tiptap/pm/view"; | ||
| var selectionStyle = `.ProseMirror:not(.ProseMirror-focused) *::selection { | ||
| background: transparent; | ||
| function shouldSyncDomSelection(state, editor) { | ||
| return !state.selection.empty && !isNodeSelection(state.selection) && editor.isEditable; | ||
| } | ||
| .ProseMirror:not(.ProseMirror-focused) *::-moz-selection { | ||
| background: transparent; | ||
| }`; | ||
| function shouldPreserveSelection(state, editor) { | ||
| return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging; | ||
| } | ||
| function clearDomSelection() { | ||
| var _a; | ||
| (_a = window.getSelection()) == null ? void 0 : _a.removeAllRanges(); | ||
| } | ||
| function restoreDomSelection(view) { | ||
| view.focus(); | ||
| } | ||
| var Selection = Extension6.create({ | ||
@@ -594,5 +600,2 @@ name: "selection", | ||
| const { editor, options } = this; | ||
| if (editor.options.injectCSS && typeof document !== "undefined") { | ||
| createStyleTag(selectionStyle, editor.options.injectNonce, "selection"); | ||
| } | ||
| return [ | ||
@@ -603,3 +606,3 @@ new Plugin4({ | ||
| decorations(state) { | ||
| if (state.selection.empty || editor.isFocused || !editor.isEditable || isNodeSelection(state.selection) || editor.view.dragging) { | ||
| if (!shouldPreserveSelection(state, editor)) { | ||
| return null; | ||
@@ -612,2 +615,22 @@ } | ||
| ]); | ||
| }, | ||
| handleDOMEvents: { | ||
| blur(view) { | ||
| if (!shouldSyncDomSelection(view.state, editor)) { | ||
| return false; | ||
| } | ||
| clearDomSelection(); | ||
| return false; | ||
| }, | ||
| focus(view) { | ||
| if (!shouldSyncDomSelection(view.state, editor)) { | ||
| return false; | ||
| } | ||
| requestAnimationFrame(() => { | ||
| if (!editor.isDestroyed && view.hasFocus()) { | ||
| restoreDomSelection(view); | ||
| } | ||
| }); | ||
| return false; | ||
| } | ||
| } | ||
@@ -614,0 +637,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/character-count/character-count.ts","../src/drop-cursor/drop-cursor.ts","../src/focus/focus.ts","../src/gap-cursor/gap-cursor.ts","../src/placeholder/constants.ts","../src/placeholder/placeholder.ts","../src/placeholder/plugins/PlaceholderPlugin.ts","../src/placeholder/utils/buildPlaceholderDecorations.ts","../src/placeholder/utils/createPlaceholderDecoration.ts","../src/placeholder/utils/placeholderStateField.ts","../src/placeholder/utils/resolveTopLevelRange.ts","../src/placeholder/utils/preparePlaceholderAttribute.ts","../src/selection/selection.ts","../src/trailing-node/trailing-node.ts","../src/undo-redo/undo-redo.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport interface CharacterCountOptions {\n /**\n * The maximum number of characters that should be allowed. Defaults to `0`.\n * @default null\n * @example 180\n */\n limit: number | null | undefined\n /**\n * The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n * If set to `nodeSize`, the nodeSize of the document is used.\n * @default 'textSize'\n * @example 'textSize'\n */\n mode: 'textSize' | 'nodeSize'\n /**\n * Sets whether the content will be automatically trimmed when programatically setting content over the limit.\n * If set to false, the user will be able to trim the text manually.\n * @default true\n * @example false\n */\n autoTrim?: boolean\n /**\n * The text counter function to use. Defaults to a simple character count.\n * @default (text) => text.length\n * @example (text) => [...new Intl.Segmenter().segment(text)].length\n */\n textCounter: (text: string) => number\n /**\n * The word counter function to use. Defaults to a simple word count.\n * @default (text) => text.split(' ').filter(word => word !== '').length\n * @example (text) => text.split(/\\s+/).filter(word => word !== '').length\n */\n wordCounter: (text: string) => number\n}\n\nexport interface CharacterCountStorage {\n /**\n * Get the number of characters for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the characters from. Defaults to the current document.\n * @param options.mode The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n */\n characters: (options?: { node?: ProseMirrorNode; mode?: 'textSize' | 'nodeSize' }) => number\n\n /**\n * Get the number of words for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the words from. Defaults to the current document.\n */\n words: (options?: { node?: ProseMirrorNode }) => number\n}\n\ndeclare module '@tiptap/core' {\n interface Storage {\n characterCount: CharacterCountStorage\n }\n}\n\n/**\n * This extension allows you to count the characters and words of your document.\n * @see https://tiptap.dev/api/extensions/character-count\n */\nexport const CharacterCount = Extension.create<CharacterCountOptions, CharacterCountStorage>({\n name: 'characterCount',\n\n addOptions() {\n return {\n limit: null,\n autoTrim: true,\n mode: 'textSize',\n textCounter: text => text.length,\n wordCounter: text => text.split(' ').filter(word => word !== '').length,\n }\n },\n\n addStorage() {\n return {\n characters: () => 0,\n words: () => 0,\n }\n },\n\n onBeforeCreate() {\n this.storage.characters = options => {\n const node = options?.node || this.editor.state.doc\n const mode = options?.mode || this.options.mode\n\n if (mode === 'textSize') {\n const text = node.textBetween(0, node.content.size, undefined, ' ')\n\n return this.options.textCounter(text)\n }\n\n return node.nodeSize\n }\n\n this.storage.words = options => {\n const node = options?.node || this.editor.state.doc\n const text = node.textBetween(0, node.content.size, ' ', ' ')\n\n return this.options.wordCounter(text)\n }\n },\n\n addProseMirrorPlugins() {\n let initialEvaluationDone = false\n\n return [\n new Plugin({\n key: new PluginKey('characterCount'),\n appendTransaction: (transactions, oldState, newState) => {\n if (initialEvaluationDone) {\n return\n }\n\n const limit = this.options.limit\n const autoTrim = this.options.autoTrim\n\n if (limit === null || limit === undefined || limit === 0 || autoTrim === false) {\n initialEvaluationDone = true\n return\n }\n\n const initialContentSize = this.storage.characters({ node: newState.doc })\n\n if (initialContentSize > limit) {\n const over = initialContentSize - limit\n const from = 0\n const to = over\n\n console.warn(\n `[CharacterCount] Initial content exceeded limit of ${limit} characters. Content was automatically trimmed.`,\n )\n const tr = newState.tr.deleteRange(from, to)\n initialEvaluationDone = true\n return tr\n }\n\n initialEvaluationDone = true\n },\n filterTransaction: (transaction, state) => {\n const limit = this.options.limit\n\n // Nothing has changed or no limit is defined. Ignore it.\n if (!transaction.docChanged || limit === 0 || limit === null || limit === undefined) {\n return true\n }\n\n const oldSize = this.storage.characters({ node: state.doc })\n const newSize = this.storage.characters({ node: transaction.doc })\n\n // Everything is in the limit. Good.\n if (newSize <= limit) {\n return true\n }\n\n // The limit has already been exceeded but will be reduced.\n if (oldSize > limit && newSize > limit && newSize <= oldSize) {\n return true\n }\n\n // The limit has already been exceeded and will be increased further.\n if (oldSize > limit && newSize > limit && newSize > oldSize) {\n return false\n }\n\n const isPaste = transaction.getMeta('paste')\n\n // Block all exceeding transactions that were not pasted.\n if (!isPaste) {\n return false\n }\n\n // For pasted content, we try to remove the exceeding content.\n const pos = transaction.selection.$head.pos\n const over = newSize - limit\n const from = pos - over\n const to = pos\n\n // It’s probably a bad idea to mutate transactions within `filterTransaction`\n // but for now this is working fine.\n transaction.deleteRange(from, to)\n\n // In some situations, the limit will continue to be exceeded after trimming.\n // This happens e.g. when truncating within a complex node (e.g. table)\n // and ProseMirror has to close this node again.\n // If this is the case, we prevent the transaction completely.\n const updatedSize = this.storage.characters({ node: transaction.doc })\n\n if (updatedSize > limit) {\n return false\n }\n\n return true\n },\n }),\n ]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { dropCursor } from '@tiptap/pm/dropcursor'\n\nexport interface DropcursorOptions {\n /**\n * The color of the drop cursor. Use `false` to apply no color and rely only on class.\n * @default 'currentColor'\n * @example 'red'\n */\n color?: string | false\n\n /**\n * The width of the drop cursor\n * @default 1\n * @example 2\n */\n width: number | undefined\n\n /**\n * The class of the drop cursor\n * @default undefined\n * @example 'drop-cursor'\n */\n class: string | undefined\n}\n\n/**\n * This extension allows you to add a drop cursor to your editor.\n * A drop cursor is a line that appears when you drag and drop content\n * in-between nodes.\n * @see https://tiptap.dev/api/extensions/dropcursor\n */\nexport const Dropcursor = Extension.create<DropcursorOptions>({\n name: 'dropCursor',\n\n addOptions() {\n return {\n color: 'currentColor',\n width: 1,\n class: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [dropCursor(this.options)]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const Focus = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope =\n (this.options.mode === 'deepest' && maxLevels - currentLevel > 0) ||\n (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n","import type { ParentConfig } from '@tiptap/core'\nimport { callOrReturn, Extension, getExtensionField } from '@tiptap/core'\nimport { gapCursor } from '@tiptap/pm/gapcursor'\n\ndeclare module '@tiptap/core' {\n interface NodeConfig<Options, Storage> {\n /**\n * A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.\n * @default null\n */\n allowGapCursor?:\n | boolean\n | null\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['allowGapCursor']\n }) => boolean | null)\n }\n}\n\n/**\n * This extension allows you to add a gap cursor to your editor.\n * A gap cursor is a cursor that appears when you click on a place\n * where no content is present, for example inbetween nodes.\n * @see https://tiptap.dev/api/extensions/gapcursor\n */\nexport const Gapcursor = Extension.create({\n name: 'gapCursor',\n\n addProseMirrorPlugins() {\n return [gapCursor()]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n allowGapCursor: callOrReturn(getExtensionField(extension, 'allowGapCursor', context)) ?? null,\n }\n },\n})\n","import { PluginKey } from '@tiptap/pm/state'\nimport type { DecorationSet } from '@tiptap/pm/view'\n\n/** The default data attribute label */\nexport const DEFAULT_DATA_ATTRIBUTE = 'placeholder'\n\n/** The plugin key used to store and read the placeholder decoration set */\nexport const PLUGIN_KEY = new PluginKey<DecorationSet>('tiptap__placeholder')\n","import { Extension } from '@tiptap/core'\n\nimport { DEFAULT_DATA_ATTRIBUTE } from './constants.js'\nimport { createPlaceholderPlugin } from './plugins/PlaceholderPlugin.js'\nimport type { PlaceholderOptions } from './types.js'\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\n */\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n dataAttribute: DEFAULT_DATA_ATTRIBUTE,\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n return [createPlaceholderPlugin({ editor: this.editor, options: this.options })]\n },\n})\n","import type { Editor } from '@tiptap/core'\nimport { Plugin } from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport { DEFAULT_DATA_ATTRIBUTE, PLUGIN_KEY } from '../constants.js'\nimport type { PlaceholderOptions } from '../types.js'\nimport { buildPlaceholderDecorations } from '../utils/buildPlaceholderDecorations.js'\nimport { createPlaceholderStateField } from '../utils/placeholderStateField.js'\nimport { preparePlaceholderAttribute } from '../utils/preparePlaceholderAttribute.js'\n\nexport type CreatePluginOptions = {\n editor: Editor\n options: PlaceholderOptions\n}\n\n/**\n * Creates the ProseMirror plugin that renders placeholder decorations.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @returns The configured placeholder plugin.\n */\nexport function createPlaceholderPlugin({ editor, options }: CreatePluginOptions) {\n const dataAttribute = options.dataAttribute\n ? `data-${preparePlaceholderAttribute(options.dataAttribute)}`\n : `data-${DEFAULT_DATA_ATTRIBUTE}`\n\n const useResolvedPath = options.showOnlyCurrent && !options.includeChildren\n\n return new Plugin({\n key: PLUGIN_KEY,\n ...(useResolvedPath\n ? {}\n : {\n state: createPlaceholderStateField({ editor, options, dataAttribute }),\n }),\n props: {\n decorations: useResolvedPath\n ? ({ doc, selection }) =>\n buildPlaceholderDecorations({ editor, options, dataAttribute, doc, selection })\n : state => {\n if (options.showOnlyWhenEditable && !editor.isEditable) {\n return DecorationSet.empty\n }\n\n return PLUGIN_KEY.getState(state) ?? DecorationSet.empty\n },\n },\n })\n}\n","import type { Editor } from '@tiptap/core'\nimport { isNodeEmpty } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Selection } from '@tiptap/pm/state'\nimport type { Decoration } from '@tiptap/pm/view'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\nimport { createPlaceholderDecoration } from './createPlaceholderDecoration.js'\n\nfunction resolveEmptyNodeClass(\n emptyNodeClass: PlaceholderOptions['emptyNodeClass'],\n props: { editor: Editor; node: Node; pos: number; hasAnchor: boolean },\n): string {\n return typeof emptyNodeClass === 'function' ? emptyNodeClass(props) : emptyNodeClass\n}\n\n/**\n * Scans a document range for empty textblocks that should receive placeholder\n * decorations. Used by the slow path and incremental state updates.\n */\nexport function scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from,\n to,\n}: {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n from: number\n to: number\n}): Decoration[] {\n const { anchor } = selection\n const decorations: Decoration[] = []\n const isEmptyDoc = editor.isEmpty\n\n doc.nodesBetween(from, to, (node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && isNodeEmpty(node)\n\n if (!node.type.isTextblock) {\n return options.includeChildren\n }\n\n if ((hasAnchor || !options.showOnlyCurrent) && isEmpty) {\n decorations.push(\n createPlaceholderDecoration({\n editor,\n isEmptyDoc,\n dataAttribute,\n hasAnchor,\n placeholder: options.placeholder,\n classes: {\n emptyEditor: options.emptyEditorClass,\n emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {\n editor,\n node,\n pos,\n hasAnchor,\n }),\n },\n node,\n pos,\n }),\n )\n }\n\n return options.includeChildren\n })\n\n return decorations\n}\n\n/**\n * Builds the placeholder decorations for the current document state.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @param options.dataAttribute - The prepared `data-*` attribute name.\n * @param options.doc - The current document node.\n * @param options.selection - The current selection.\n * @returns A decoration set, or `null` when no placeholders should be shown.\n */\nexport function buildPlaceholderDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n}: {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n}): DecorationSet | null {\n const active = editor.isEditable || !options.showOnlyWhenEditable\n\n if (!active) {\n return null\n }\n\n const { anchor } = selection\n const decorations: Decoration[] = []\n const isEmptyDoc = editor.isEmpty\n\n const useResolvedPath = options.showOnlyCurrent && !options.includeChildren\n\n if (useResolvedPath) {\n const resolved = doc.resolve(anchor)\n\n // When the selection spans the whole document (e.g. an `AllSelection`\n // after Cmd+A), the anchor resolves to the document level (depth 0). In\n // that case the relevant textblock is the node directly after the\n // position rather than an ancestor. otherwise the placeholder would\n // disappear after selecting all and deleting.\n const node = resolved.depth > 0 ? resolved.node(1) : resolved.nodeAfter\n const nodeStart = resolved.depth > 0 ? resolved.before(1) : anchor\n\n if (node && node.type.isTextblock && isNodeEmpty(node)) {\n const hasAnchor = anchor >= nodeStart && anchor <= nodeStart + node.nodeSize\n\n decorations.push(\n createPlaceholderDecoration({\n editor,\n isEmptyDoc,\n dataAttribute,\n hasAnchor,\n placeholder: options.placeholder,\n classes: {\n emptyEditor: options.emptyEditorClass,\n emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {\n editor,\n node,\n pos: nodeStart,\n hasAnchor,\n }),\n },\n node,\n pos: nodeStart,\n }),\n )\n }\n } else {\n decorations.push(\n ...scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from: 0,\n to: doc.content.size,\n }),\n )\n }\n\n return DecorationSet.create(doc, decorations)\n}\n","import type { Editor } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport { Decoration } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\n\n/**\n * Creates a ProseMirror node decoration that applies a placeholder\n * CSS class and data attribute to an empty node.\n * @param options.editor - The editor instance\n * @param options.pos - The position of the node in the document\n * @param options.node - The ProseMirror node\n * @param options.isEmptyDoc - Whether the entire document is empty\n * @param options.hasAnchor - Whether the selection anchor is within the node\n * @param options.dataAttribute - The data attribute name (e.g. `data-placeholder`)\n * @param options.classes - CSS classes for empty nodes and the empty editor\n * @param options.placeholder - The placeholder text or a function that returns it\n * @returns A ProseMirror node decoration with placeholder classes and data attribute\n */\nexport function createPlaceholderDecoration(options: {\n editor: Editor\n pos: number\n node: Node\n isEmptyDoc: boolean\n hasAnchor: boolean\n dataAttribute: string\n classes: {\n emptyEditor: PlaceholderOptions['emptyEditorClass']\n emptyNode: string\n }\n placeholder: PlaceholderOptions['placeholder']\n}) {\n const {\n editor,\n placeholder,\n dataAttribute,\n pos,\n node,\n isEmptyDoc,\n hasAnchor,\n classes: { emptyNode, emptyEditor },\n } = options\n const classes = [emptyNode]\n\n if (isEmptyDoc) {\n classes.push(emptyEditor)\n }\n\n return Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n [dataAttribute]:\n typeof placeholder === 'function'\n ? placeholder({\n editor,\n node,\n pos,\n hasAnchor,\n })\n : placeholder,\n })\n}\n","import type { Editor } from '@tiptap/core'\nimport { getChangedRanges } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport type { EditorState, StateField, Transaction } from '@tiptap/pm/state'\nimport type { Selection } from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\nimport {\n buildPlaceholderDecorations,\n scanRangeForDecorations,\n} from './buildPlaceholderDecorations.js'\nimport {\n getTopLevelBlocksInRange,\n mergeRanges,\n resolveTopLevelRange,\n toContentRelativeRange,\n} from './resolveTopLevelRange.js'\n\n/** Options passed to {@link createPlaceholderStateField}. */\nexport type CreatePlaceholderStateFieldOptions = {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n}\n\n/**\n * Expands a single changed range to the top-level blocks it touches.\n * Also resolves blocks at range boundaries so split/merge edits update\n * adjacent empty nodes (e.g. a new paragraph after Enter).\n */\nfunction collectBlocksForChange(\n doc: Node,\n change: { from: number; to: number },\n): Array<{ from: number; to: number }> {\n const ranges = getTopLevelBlocksInRange(doc, change.from, change.to)\n\n ranges.push(toContentRelativeRange(doc, resolveTopLevelRange(doc, change.from)))\n\n if (change.to > change.from) {\n ranges.push(\n toContentRelativeRange(\n doc,\n resolveTopLevelRange(doc, Math.min(change.to, doc.content.size + 1) - 1),\n ),\n )\n } else if (change.from < doc.content.size + 1) {\n ranges.push(\n toContentRelativeRange(\n doc,\n resolveTopLevelRange(doc, Math.min(change.from + 1, doc.content.size)),\n ),\n )\n }\n\n return ranges\n}\n\n/**\n * Collects content-relative top-level block ranges that need placeholder\n * decorations recomputed after a transaction.\n */\nfunction collectRescanRanges(\n tr: Transaction,\n oldState: EditorState,\n newState: EditorState,\n): Array<{ from: number; to: number }> {\n const ranges: Array<{ from: number; to: number }> = []\n\n if (tr.docChanged) {\n const changes = getChangedRanges(tr)\n\n for (const change of changes) {\n ranges.push(...collectBlocksForChange(newState.doc, change.newRange))\n }\n }\n\n if (tr.selectionSet) {\n ranges.push(\n toContentRelativeRange(\n newState.doc,\n resolveTopLevelRange(newState.doc, tr.mapping.map(oldState.selection.anchor)),\n ),\n )\n ranges.push(\n toContentRelativeRange(\n newState.doc,\n resolveTopLevelRange(newState.doc, newState.selection.anchor),\n ),\n )\n }\n\n return mergeRanges(ranges)\n}\n\n/** Clamps a content-relative range to `[0, doc.content.size]`. */\nfunction clampRange(from: number, to: number, doc: Node): { from: number; to: number } {\n const clampedFrom = Math.max(0, Math.min(from, doc.content.size))\n const clampedTo = Math.max(clampedFrom, Math.min(to, doc.content.size))\n\n return { from: clampedFrom, to: clampedTo }\n}\n\n/**\n * Removes and rebuilds placeholder decorations within the given ranges.\n * Only drops decorations fully contained in a range so mapped decorations\n * on neighbouring blocks (e.g. at a block boundary) are kept intact.\n */\nfunction updateDecorationsInRanges({\n decorations,\n ranges,\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n}: {\n decorations: DecorationSet\n ranges: Array<{ from: number; to: number }>\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n}): DecorationSet {\n let next = decorations\n\n for (const range of ranges) {\n const { from, to } = clampRange(range.from, range.to, doc)\n const existing = next\n .find(from, to)\n .filter(decoration => decoration.from >= from && decoration.to <= to)\n\n if (existing.length) {\n next = next.remove(existing)\n }\n\n const newDecos = scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from,\n to,\n })\n\n if (newDecos.length) {\n next = next.add(doc, newDecos)\n }\n }\n\n return next\n}\n\n/**\n * Creates the incremental `StateField<DecorationSet>` used by the slow path\n * (`showOnlyCurrent: false` or `includeChildren: true`).\n *\n * Decorations are mapped through each transaction and only recomputed for\n * top-level blocks touched by document or selection changes.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @param options.dataAttribute - The prepared `data-*` attribute name.\n * @returns A ProseMirror state field storing the placeholder decoration set.\n */\nexport function createPlaceholderStateField({\n editor,\n options,\n dataAttribute,\n}: CreatePlaceholderStateFieldOptions): StateField<DecorationSet> {\n return {\n init(_config, state: EditorState) {\n const decorations = buildPlaceholderDecorations({\n editor,\n options,\n dataAttribute,\n doc: state.doc,\n selection: state.selection,\n })\n\n return decorations ?? DecorationSet.empty\n },\n\n apply(tr: Transaction, prev: DecorationSet, oldState: EditorState, newState: EditorState) {\n if (!tr.docChanged && !tr.selectionSet) {\n return prev\n }\n\n const mapped = prev.map(tr.mapping, tr.doc)\n const ranges = collectRescanRanges(tr, oldState, newState)\n\n return updateDecorationsInRanges({\n decorations: mapped,\n ranges,\n editor,\n options,\n dataAttribute,\n doc: newState.doc,\n selection: newState.selection,\n })\n },\n }\n}\n","import type { Node } from '@tiptap/pm/model'\n\n/**\n * Resolves a document position to the `[from, to)` range of its containing\n * top-level block node in absolute document positions.\n */\nexport function resolveTopLevelRange(doc: Node, pos: number): { from: number; to: number } {\n const resolved = doc.resolve(pos)\n\n if (resolved.depth === 0) {\n const node = resolved.nodeAfter ?? resolved.nodeBefore\n\n if (!node) {\n return { from: pos, to: pos }\n }\n\n const nodePos = resolved.nodeAfter ? pos : pos - node.nodeSize\n\n return { from: nodePos, to: nodePos + node.nodeSize }\n }\n\n const topLevelPos = resolved.before(1)\n const node = resolved.node(1)\n\n return { from: topLevelPos, to: topLevelPos + node.nodeSize }\n}\n\n/**\n * Converts an absolute document range to content-relative positions used by\n * `Node#nodesBetween` and `Node#forEach` offsets.\n */\nexport function toContentRelativeRange(\n doc: Node,\n range: { from: number; to: number },\n): { from: number; to: number } {\n return {\n from: Math.max(0, range.from - 1),\n to: Math.min(doc.content.size, range.to - 1),\n }\n}\n\n/**\n * Returns the top-level block ranges that intersect a document change range.\n * Input `from`/`to` are absolute positions (e.g. from `getChangedRanges`).\n * Returned ranges are content-relative, matching `Node#forEach` offsets.\n */\nexport function getTopLevelBlocksInRange(\n doc: Node,\n from: number,\n to: number,\n): Array<{ from: number; to: number }> {\n const ranges: Array<{ from: number; to: number }> = []\n\n doc.forEach((node, offset) => {\n const nodeStart = offset\n const nodeEnd = nodeStart + node.nodeSize\n const absNodeStart = nodeStart + 1\n const absNodeEnd = nodeEnd + 1\n\n if (absNodeStart < to && absNodeEnd > from) {\n ranges.push({ from: nodeStart, to: nodeEnd })\n }\n })\n\n return ranges\n}\n\n/**\n * Sorts ranges by start position and merges overlapping or adjacent ranges.\n */\nexport function mergeRanges(\n ranges: Array<{ from: number; to: number }>,\n): Array<{ from: number; to: number }> {\n if (ranges.length === 0) {\n return []\n }\n\n const sorted = [...ranges].sort((a, b) => a.from - b.from)\n const merged: Array<{ from: number; to: number }> = [{ ...sorted[0] }]\n\n for (let i = 1; i < sorted.length; i += 1) {\n const last = merged[merged.length - 1]\n const current = sorted[i]\n\n if (current.from <= last.to) {\n last.to = Math.max(last.to, current.to)\n } else {\n merged.push({ ...current })\n }\n }\n\n return merged\n}\n","/**\n * Prepares the placeholder attribute by ensuring it is properly formatted.\n * @param attr - The placeholder attribute string.\n * @returns The prepared placeholder attribute string.\n */\nexport function preparePlaceholderAttribute(attr: string): string {\n return (\n attr\n // replace whitespace with dashes\n .replace(/\\s+/g, '-')\n // replace non-alphanumeric characters\n // or special chars like $, %, &, etc.\n // but not dashes\n .replace(/[^a-zA-Z0-9-]/g, '')\n // and replace any numeric character at the start\n .replace(/^[0-9-]+/, '')\n // and finally replace any stray, leading dashes\n .replace(/^-+/, '')\n .toLowerCase()\n )\n}\n","import { createStyleTag, Extension, isNodeSelection } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nconst selectionStyle = `.ProseMirror:not(.ProseMirror-focused) *::selection {\n background: transparent;\n}\n\n.ProseMirror:not(.ProseMirror-focused) *::-moz-selection {\n background: transparent;\n}`\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * This extension allows you to add a class to the selected text.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create<SelectionOptions>({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n if (editor.options.injectCSS && typeof document !== 'undefined') {\n createStyleTag(selectionStyle, editor.options.injectNonce, 'selection')\n }\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (\n state.selection.empty ||\n editor.isFocused ||\n !editor.isEditable ||\n isNodeSelection(state.selection) ||\n editor.view.dragging\n ) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n","import { Extension } from '@tiptap/core'\nimport type { Node, NodeType } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport const skipTrailingNodeMeta = 'skipTrailingNode'\n\nfunction nodeEqualsType({\n types,\n node,\n}: {\n types: NodeType | NodeType[]\n node: Node | null | undefined\n}) {\n return (node && Array.isArray(types) && types.includes(node.type)) || node?.type === types\n}\n\n/**\n * Extension based on:\n * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js\n * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts\n */\n\nexport interface TrailingNodeOptions {\n /**\n * The node type that should be inserted at the end of the document.\n * @note the node will always be added to the `notAfter` lists to\n * prevent an infinite loop.\n * @default undefined\n */\n node?: string\n /**\n * The node types after which the trailing node should not be inserted.\n * @default ['paragraph']\n */\n notAfter?: string | string[]\n}\n\n/**\n * This extension allows you to add an extra node at the end of the document.\n * @see https://www.tiptap.dev/api/extensions/trailing-node\n */\nexport const TrailingNode = Extension.create<TrailingNodeOptions>({\n name: 'trailingNode',\n\n addOptions() {\n return {\n node: undefined,\n notAfter: [],\n }\n },\n\n addProseMirrorPlugins() {\n const plugin = new PluginKey(this.name)\n const defaultNode =\n this.options.node ||\n this.editor.schema.topNodeType.contentMatch.defaultType?.name ||\n 'paragraph'\n\n const disabledNodes = Object.entries(this.editor.schema.nodes)\n .map(([, value]) => value)\n .filter(node => (this.options.notAfter || []).concat(defaultNode).includes(node.name))\n\n return [\n new Plugin({\n key: plugin,\n appendTransaction: (transactions, __, state) => {\n const { doc, tr, schema } = state\n const shouldInsertNodeAtEnd = plugin.getState(state)\n const endPosition = doc.content.size\n const type = schema.nodes[defaultNode]\n\n if (transactions.some(transaction => transaction.getMeta(skipTrailingNodeMeta))) {\n return\n }\n\n if (!shouldInsertNodeAtEnd) {\n return\n }\n\n return tr.insert(endPosition, type.create())\n },\n state: {\n init: (_, state) => {\n const lastNode = state.tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n apply: (tr, value) => {\n if (!tr.docChanged) {\n return value\n }\n\n // Ignore transactions from UniqueID extension to prevent infinite loops\n // when UniqueID adds IDs to newly inserted trailing nodes\n if (tr.getMeta('__uniqueIDTransaction')) {\n return value\n }\n\n const lastNode = tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n },\n }),\n ]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { history, redo, undo } from '@tiptap/pm/history'\n\nexport interface UndoRedoOptions {\n /**\n * The amount of history events that are collected before the oldest events are discarded.\n * @default 100\n * @example 50\n */\n depth: number\n\n /**\n * The delay (in milliseconds) between changes after which a new group should be started.\n * @default 500\n * @example 1000\n */\n newGroupDelay: number\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n undoRedo: {\n /**\n * Undo recent changes\n * @example editor.commands.undo()\n */\n undo: () => ReturnType\n /**\n * Reapply reverted changes\n * @example editor.commands.redo()\n */\n redo: () => ReturnType\n }\n }\n}\n\n/**\n * This extension allows you to undo and redo recent changes.\n * @see https://www.tiptap.dev/api/extensions/undo-redo\n *\n * **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove\n * the `undo-redo` extension, as it is not compatible with the `collaboration` extension.\n *\n * `@tiptap/extension-collaboration` uses its own history implementation.\n */\nexport const UndoRedo = Extension.create<UndoRedoOptions>({\n name: 'undoRedo',\n\n addOptions() {\n return {\n depth: 100,\n newGroupDelay: 500,\n }\n },\n\n addCommands() {\n return {\n undo:\n () =>\n ({ state, dispatch }) => {\n return undo(state, dispatch)\n },\n redo:\n () =>\n ({ state, dispatch }) => {\n return redo(state, dispatch)\n },\n }\n },\n\n addProseMirrorPlugins() {\n return [history(this.options)]\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-z': () => this.editor.commands.undo(),\n 'Shift-Mod-z': () => this.editor.commands.redo(),\n 'Mod-y': () => this.editor.commands.redo(),\n\n // Russian keyboard layouts\n 'Mod-я': () => this.editor.commands.undo(),\n 'Shift-Mod-я': () => this.editor.commands.redo(),\n }\n },\n})\n"],"mappings":";AAAA,SAAS,iBAAiB;AAE1B,SAAS,QAAQ,iBAAiB;AAgE3B,IAAM,iBAAiB,UAAU,OAAqD;AAAA,EAC3F,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,MACN,aAAa,UAAQ,KAAK;AAAA,MAC1B,aAAa,UAAQ,KAAK,MAAM,GAAG,EAAE,OAAO,UAAQ,SAAS,EAAE,EAAE;AAAA,IACnE;AAAA,EACF;AAAA,EAEA,aAAa;AACX,WAAO;AAAA,MACL,YAAY,MAAM;AAAA,MAClB,OAAO,MAAM;AAAA,IACf;AAAA,EACF;AAAA,EAEA,iBAAiB;AACf,SAAK,QAAQ,aAAa,aAAW;AACnC,YAAM,QAAO,mCAAS,SAAQ,KAAK,OAAO,MAAM;AAChD,YAAM,QAAO,mCAAS,SAAQ,KAAK,QAAQ;AAE3C,UAAI,SAAS,YAAY;AACvB,cAAM,OAAO,KAAK,YAAY,GAAG,KAAK,QAAQ,MAAM,QAAW,GAAG;AAElE,eAAO,KAAK,QA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C,GAAG,YAAY;AAClB,qBAAO;AAAA,YACT;AAIA,gBAAI,GAAG,QAAQ,uBAAuB,GAAG;AACvC,qBAAO;AAAA,YACT;AAEA,kBAAM,WAAW,GAAG,IAAI;AAExB,mBAAO,CAAC,eAAe,EAAE,MAAM,UAAU,OAAO,cAAc,CAAC;AAAA,UACjE;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AC1GD,SAAS,aAAAE,kBAAiB;AAC1B,SAAS,SAAS,MAAM,YAAY;AA4C7B,IAAM,WAAWA,WAAU,OAAwB;AAAA,EACxD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO;AAAA,MACP,eAAe;AAAA,IACjB;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,MACE,MACA,CAAC,EAAE,OAAO,SAAS,MAAM;AACvB,eAAO,KAAK,OAAO,QAAQ;AAAA,MAC7B;AAAA,MACF,MACE,MACA,CAAC,EAAE,OAAO,SAAS,MAAM;AACvB,eAAO,KAAK,OAAO,QAAQ;AAAA,MAC7B;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AAAA,EAC/B;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,eAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MAC/C,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA;AAAA,MAGzC,cAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,oBAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,IACjD;AAAA,EACF;AACF,CAAC;","names":["Extension","Extension","Plugin","PluginKey","Extension","PluginKey","Extension","Plugin","DecorationSet","DecorationSet","Decoration","DecorationSet","DecorationSet","node","DecorationSet","Plugin","DecorationSet","Extension","Extension","Plugin","PluginKey","Decoration","DecorationSet","Extension","Plugin","PluginKey","Extension"]} | ||
| {"version":3,"sources":["../src/character-count/character-count.ts","../src/drop-cursor/drop-cursor.ts","../src/focus/focus.ts","../src/gap-cursor/gap-cursor.ts","../src/placeholder/constants.ts","../src/placeholder/placeholder.ts","../src/placeholder/plugins/PlaceholderPlugin.ts","../src/placeholder/utils/buildPlaceholderDecorations.ts","../src/placeholder/utils/createPlaceholderDecoration.ts","../src/placeholder/utils/placeholderStateField.ts","../src/placeholder/utils/resolveTopLevelRange.ts","../src/placeholder/utils/preparePlaceholderAttribute.ts","../src/selection/selection.ts","../src/trailing-node/trailing-node.ts","../src/undo-redo/undo-redo.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport interface CharacterCountOptions {\n /**\n * The maximum number of characters that should be allowed. Defaults to `0`.\n * @default null\n * @example 180\n */\n limit: number | null | undefined\n /**\n * The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n * If set to `nodeSize`, the nodeSize of the document is used.\n * @default 'textSize'\n * @example 'textSize'\n */\n mode: 'textSize' | 'nodeSize'\n /**\n * Sets whether the content will be automatically trimmed when programatically setting content over the limit.\n * If set to false, the user will be able to trim the text manually.\n * @default true\n * @example false\n */\n autoTrim?: boolean\n /**\n * The text counter function to use. Defaults to a simple character count.\n * @default (text) => text.length\n * @example (text) => [...new Intl.Segmenter().segment(text)].length\n */\n textCounter: (text: string) => number\n /**\n * The word counter function to use. Defaults to a simple word count.\n * @default (text) => text.split(' ').filter(word => word !== '').length\n * @example (text) => text.split(/\\s+/).filter(word => word !== '').length\n */\n wordCounter: (text: string) => number\n}\n\nexport interface CharacterCountStorage {\n /**\n * Get the number of characters for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the characters from. Defaults to the current document.\n * @param options.mode The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.\n */\n characters: (options?: { node?: ProseMirrorNode; mode?: 'textSize' | 'nodeSize' }) => number\n\n /**\n * Get the number of words for the current document.\n * @param options The options for the character count. (optional)\n * @param options.node The node to get the words from. Defaults to the current document.\n */\n words: (options?: { node?: ProseMirrorNode }) => number\n}\n\ndeclare module '@tiptap/core' {\n interface Storage {\n characterCount: CharacterCountStorage\n }\n}\n\n/**\n * This extension allows you to count the characters and words of your document.\n * @see https://tiptap.dev/api/extensions/character-count\n */\nexport const CharacterCount = Extension.create<CharacterCountOptions, CharacterCountStorage>({\n name: 'characterCount',\n\n addOptions() {\n return {\n limit: null,\n autoTrim: true,\n mode: 'textSize',\n textCounter: text => text.length,\n wordCounter: text => text.split(' ').filter(word => word !== '').length,\n }\n },\n\n addStorage() {\n return {\n characters: () => 0,\n words: () => 0,\n }\n },\n\n onBeforeCreate() {\n this.storage.characters = options => {\n const node = options?.node || this.editor.state.doc\n const mode = options?.mode || this.options.mode\n\n if (mode === 'textSize') {\n const text = node.textBetween(0, node.content.size, undefined, ' ')\n\n return this.options.textCounter(text)\n }\n\n return node.nodeSize\n }\n\n this.storage.words = options => {\n const node = options?.node || this.editor.state.doc\n const text = node.textBetween(0, node.content.size, ' ', ' ')\n\n return this.options.wordCounter(text)\n }\n },\n\n addProseMirrorPlugins() {\n let initialEvaluationDone = false\n\n return [\n new Plugin({\n key: new PluginKey('characterCount'),\n appendTransaction: (transactions, oldState, newState) => {\n if (initialEvaluationDone) {\n return\n }\n\n const limit = this.options.limit\n const autoTrim = this.options.autoTrim\n\n if (limit === null || limit === undefined || limit === 0 || autoTrim === false) {\n initialEvaluationDone = true\n return\n }\n\n const initialContentSize = this.storage.characters({ node: newState.doc })\n\n if (initialContentSize > limit) {\n const over = initialContentSize - limit\n const from = 0\n const to = over\n\n console.warn(\n `[CharacterCount] Initial content exceeded limit of ${limit} characters. Content was automatically trimmed.`,\n )\n const tr = newState.tr.deleteRange(from, to)\n initialEvaluationDone = true\n return tr\n }\n\n initialEvaluationDone = true\n },\n filterTransaction: (transaction, state) => {\n const limit = this.options.limit\n\n // Nothing has changed or no limit is defined. Ignore it.\n if (!transaction.docChanged || limit === 0 || limit === null || limit === undefined) {\n return true\n }\n\n const oldSize = this.storage.characters({ node: state.doc })\n const newSize = this.storage.characters({ node: transaction.doc })\n\n // Everything is in the limit. Good.\n if (newSize <= limit) {\n return true\n }\n\n // The limit has already been exceeded but will be reduced.\n if (oldSize > limit && newSize > limit && newSize <= oldSize) {\n return true\n }\n\n // The limit has already been exceeded and will be increased further.\n if (oldSize > limit && newSize > limit && newSize > oldSize) {\n return false\n }\n\n const isPaste = transaction.getMeta('paste')\n\n // Block all exceeding transactions that were not pasted.\n if (!isPaste) {\n return false\n }\n\n // For pasted content, we try to remove the exceeding content.\n const pos = transaction.selection.$head.pos\n const over = newSize - limit\n const from = pos - over\n const to = pos\n\n // It’s probably a bad idea to mutate transactions within `filterTransaction`\n // but for now this is working fine.\n transaction.deleteRange(from, to)\n\n // In some situations, the limit will continue to be exceeded after trimming.\n // This happens e.g. when truncating within a complex node (e.g. table)\n // and ProseMirror has to close this node again.\n // If this is the case, we prevent the transaction completely.\n const updatedSize = this.storage.characters({ node: transaction.doc })\n\n if (updatedSize > limit) {\n return false\n }\n\n return true\n },\n }),\n ]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { dropCursor } from '@tiptap/pm/dropcursor'\n\nexport interface DropcursorOptions {\n /**\n * The color of the drop cursor. Use `false` to apply no color and rely only on class.\n * @default 'currentColor'\n * @example 'red'\n */\n color?: string | false\n\n /**\n * The width of the drop cursor\n * @default 1\n * @example 2\n */\n width: number | undefined\n\n /**\n * The class of the drop cursor\n * @default undefined\n * @example 'drop-cursor'\n */\n class: string | undefined\n}\n\n/**\n * This extension allows you to add a drop cursor to your editor.\n * A drop cursor is a line that appears when you drag and drop content\n * in-between nodes.\n * @see https://tiptap.dev/api/extensions/dropcursor\n */\nexport const Dropcursor = Extension.create<DropcursorOptions>({\n name: 'dropCursor',\n\n addOptions() {\n return {\n color: 'currentColor',\n width: 1,\n class: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [dropCursor(this.options)]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const Focus = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope =\n (this.options.mode === 'deepest' && maxLevels - currentLevel > 0) ||\n (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n","import type { ParentConfig } from '@tiptap/core'\nimport { callOrReturn, Extension, getExtensionField } from '@tiptap/core'\nimport { gapCursor } from '@tiptap/pm/gapcursor'\n\ndeclare module '@tiptap/core' {\n interface NodeConfig<Options, Storage> {\n /**\n * A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.\n * @default null\n */\n allowGapCursor?:\n | boolean\n | null\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['allowGapCursor']\n }) => boolean | null)\n }\n}\n\n/**\n * This extension allows you to add a gap cursor to your editor.\n * A gap cursor is a cursor that appears when you click on a place\n * where no content is present, for example inbetween nodes.\n * @see https://tiptap.dev/api/extensions/gapcursor\n */\nexport const Gapcursor = Extension.create({\n name: 'gapCursor',\n\n addProseMirrorPlugins() {\n return [gapCursor()]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n allowGapCursor: callOrReturn(getExtensionField(extension, 'allowGapCursor', context)) ?? null,\n }\n },\n})\n","import { PluginKey } from '@tiptap/pm/state'\nimport type { DecorationSet } from '@tiptap/pm/view'\n\n/** The default data attribute label */\nexport const DEFAULT_DATA_ATTRIBUTE = 'placeholder'\n\n/** The plugin key used to store and read the placeholder decoration set */\nexport const PLUGIN_KEY = new PluginKey<DecorationSet>('tiptap__placeholder')\n","import { Extension } from '@tiptap/core'\n\nimport { DEFAULT_DATA_ATTRIBUTE } from './constants.js'\nimport { createPlaceholderPlugin } from './plugins/PlaceholderPlugin.js'\nimport type { PlaceholderOptions } from './types.js'\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\n */\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n dataAttribute: DEFAULT_DATA_ATTRIBUTE,\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n return [createPlaceholderPlugin({ editor: this.editor, options: this.options })]\n },\n})\n","import type { Editor } from '@tiptap/core'\nimport { Plugin } from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport { DEFAULT_DATA_ATTRIBUTE, PLUGIN_KEY } from '../constants.js'\nimport type { PlaceholderOptions } from '../types.js'\nimport { buildPlaceholderDecorations } from '../utils/buildPlaceholderDecorations.js'\nimport { createPlaceholderStateField } from '../utils/placeholderStateField.js'\nimport { preparePlaceholderAttribute } from '../utils/preparePlaceholderAttribute.js'\n\nexport type CreatePluginOptions = {\n editor: Editor\n options: PlaceholderOptions\n}\n\n/**\n * Creates the ProseMirror plugin that renders placeholder decorations.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @returns The configured placeholder plugin.\n */\nexport function createPlaceholderPlugin({ editor, options }: CreatePluginOptions) {\n const dataAttribute = options.dataAttribute\n ? `data-${preparePlaceholderAttribute(options.dataAttribute)}`\n : `data-${DEFAULT_DATA_ATTRIBUTE}`\n\n const useResolvedPath = options.showOnlyCurrent && !options.includeChildren\n\n return new Plugin({\n key: PLUGIN_KEY,\n ...(useResolvedPath\n ? {}\n : {\n state: createPlaceholderStateField({ editor, options, dataAttribute }),\n }),\n props: {\n decorations: useResolvedPath\n ? ({ doc, selection }) =>\n buildPlaceholderDecorations({ editor, options, dataAttribute, doc, selection })\n : state => {\n if (options.showOnlyWhenEditable && !editor.isEditable) {\n return DecorationSet.empty\n }\n\n return PLUGIN_KEY.getState(state) ?? DecorationSet.empty\n },\n },\n })\n}\n","import type { Editor } from '@tiptap/core'\nimport { isNodeEmpty } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport type { Selection } from '@tiptap/pm/state'\nimport type { Decoration } from '@tiptap/pm/view'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\nimport { createPlaceholderDecoration } from './createPlaceholderDecoration.js'\n\nfunction resolveEmptyNodeClass(\n emptyNodeClass: PlaceholderOptions['emptyNodeClass'],\n props: { editor: Editor; node: Node; pos: number; hasAnchor: boolean },\n): string {\n return typeof emptyNodeClass === 'function' ? emptyNodeClass(props) : emptyNodeClass\n}\n\n/**\n * Scans a document range for empty textblocks that should receive placeholder\n * decorations. Used by the slow path and incremental state updates.\n */\nexport function scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from,\n to,\n}: {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n from: number\n to: number\n}): Decoration[] {\n const { anchor } = selection\n const decorations: Decoration[] = []\n const isEmptyDoc = editor.isEmpty\n\n doc.nodesBetween(from, to, (node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && isNodeEmpty(node)\n\n if (!node.type.isTextblock) {\n return options.includeChildren\n }\n\n if ((hasAnchor || !options.showOnlyCurrent) && isEmpty) {\n decorations.push(\n createPlaceholderDecoration({\n editor,\n isEmptyDoc,\n dataAttribute,\n hasAnchor,\n placeholder: options.placeholder,\n classes: {\n emptyEditor: options.emptyEditorClass,\n emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {\n editor,\n node,\n pos,\n hasAnchor,\n }),\n },\n node,\n pos,\n }),\n )\n }\n\n return options.includeChildren\n })\n\n return decorations\n}\n\n/**\n * Builds the placeholder decorations for the current document state.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @param options.dataAttribute - The prepared `data-*` attribute name.\n * @param options.doc - The current document node.\n * @param options.selection - The current selection.\n * @returns A decoration set, or `null` when no placeholders should be shown.\n */\nexport function buildPlaceholderDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n}: {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n}): DecorationSet | null {\n const active = editor.isEditable || !options.showOnlyWhenEditable\n\n if (!active) {\n return null\n }\n\n const { anchor } = selection\n const decorations: Decoration[] = []\n const isEmptyDoc = editor.isEmpty\n\n const useResolvedPath = options.showOnlyCurrent && !options.includeChildren\n\n if (useResolvedPath) {\n const resolved = doc.resolve(anchor)\n\n // When the selection spans the whole document (e.g. an `AllSelection`\n // after Cmd+A), the anchor resolves to the document level (depth 0). In\n // that case the relevant textblock is the node directly after the\n // position rather than an ancestor. otherwise the placeholder would\n // disappear after selecting all and deleting.\n const node = resolved.depth > 0 ? resolved.node(1) : resolved.nodeAfter\n const nodeStart = resolved.depth > 0 ? resolved.before(1) : anchor\n\n if (node && node.type.isTextblock && isNodeEmpty(node)) {\n const hasAnchor = anchor >= nodeStart && anchor <= nodeStart + node.nodeSize\n\n decorations.push(\n createPlaceholderDecoration({\n editor,\n isEmptyDoc,\n dataAttribute,\n hasAnchor,\n placeholder: options.placeholder,\n classes: {\n emptyEditor: options.emptyEditorClass,\n emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {\n editor,\n node,\n pos: nodeStart,\n hasAnchor,\n }),\n },\n node,\n pos: nodeStart,\n }),\n )\n }\n } else {\n decorations.push(\n ...scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from: 0,\n to: doc.content.size,\n }),\n )\n }\n\n return DecorationSet.create(doc, decorations)\n}\n","import type { Editor } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport { Decoration } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\n\n/**\n * Creates a ProseMirror node decoration that applies a placeholder\n * CSS class and data attribute to an empty node.\n * @param options.editor - The editor instance\n * @param options.pos - The position of the node in the document\n * @param options.node - The ProseMirror node\n * @param options.isEmptyDoc - Whether the entire document is empty\n * @param options.hasAnchor - Whether the selection anchor is within the node\n * @param options.dataAttribute - The data attribute name (e.g. `data-placeholder`)\n * @param options.classes - CSS classes for empty nodes and the empty editor\n * @param options.placeholder - The placeholder text or a function that returns it\n * @returns A ProseMirror node decoration with placeholder classes and data attribute\n */\nexport function createPlaceholderDecoration(options: {\n editor: Editor\n pos: number\n node: Node\n isEmptyDoc: boolean\n hasAnchor: boolean\n dataAttribute: string\n classes: {\n emptyEditor: PlaceholderOptions['emptyEditorClass']\n emptyNode: string\n }\n placeholder: PlaceholderOptions['placeholder']\n}) {\n const {\n editor,\n placeholder,\n dataAttribute,\n pos,\n node,\n isEmptyDoc,\n hasAnchor,\n classes: { emptyNode, emptyEditor },\n } = options\n const classes = [emptyNode]\n\n if (isEmptyDoc) {\n classes.push(emptyEditor)\n }\n\n return Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n [dataAttribute]:\n typeof placeholder === 'function'\n ? placeholder({\n editor,\n node,\n pos,\n hasAnchor,\n })\n : placeholder,\n })\n}\n","import type { Editor } from '@tiptap/core'\nimport { getChangedRanges } from '@tiptap/core'\nimport type { Node } from '@tiptap/pm/model'\nimport type { EditorState, StateField, Transaction } from '@tiptap/pm/state'\nimport type { Selection } from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { PlaceholderOptions } from '../types.js'\nimport {\n buildPlaceholderDecorations,\n scanRangeForDecorations,\n} from './buildPlaceholderDecorations.js'\nimport {\n getTopLevelBlocksInRange,\n mergeRanges,\n resolveTopLevelRange,\n toContentRelativeRange,\n} from './resolveTopLevelRange.js'\n\n/** Options passed to {@link createPlaceholderStateField}. */\nexport type CreatePlaceholderStateFieldOptions = {\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n}\n\n/**\n * Expands a single changed range to the top-level blocks it touches.\n * Also resolves blocks at range boundaries so split/merge edits update\n * adjacent empty nodes (e.g. a new paragraph after Enter).\n */\nfunction collectBlocksForChange(\n doc: Node,\n change: { from: number; to: number },\n): Array<{ from: number; to: number }> {\n const ranges = getTopLevelBlocksInRange(doc, change.from, change.to)\n\n ranges.push(toContentRelativeRange(doc, resolveTopLevelRange(doc, change.from)))\n\n if (change.to > change.from) {\n ranges.push(\n toContentRelativeRange(\n doc,\n resolveTopLevelRange(doc, Math.min(change.to, doc.content.size + 1) - 1),\n ),\n )\n } else if (change.from < doc.content.size + 1) {\n ranges.push(\n toContentRelativeRange(\n doc,\n resolveTopLevelRange(doc, Math.min(change.from + 1, doc.content.size)),\n ),\n )\n }\n\n return ranges\n}\n\n/**\n * Collects content-relative top-level block ranges that need placeholder\n * decorations recomputed after a transaction.\n */\nfunction collectRescanRanges(\n tr: Transaction,\n oldState: EditorState,\n newState: EditorState,\n): Array<{ from: number; to: number }> {\n const ranges: Array<{ from: number; to: number }> = []\n\n if (tr.docChanged) {\n const changes = getChangedRanges(tr)\n\n for (const change of changes) {\n ranges.push(...collectBlocksForChange(newState.doc, change.newRange))\n }\n }\n\n if (tr.selectionSet) {\n ranges.push(\n toContentRelativeRange(\n newState.doc,\n resolveTopLevelRange(newState.doc, tr.mapping.map(oldState.selection.anchor)),\n ),\n )\n ranges.push(\n toContentRelativeRange(\n newState.doc,\n resolveTopLevelRange(newState.doc, newState.selection.anchor),\n ),\n )\n }\n\n return mergeRanges(ranges)\n}\n\n/** Clamps a content-relative range to `[0, doc.content.size]`. */\nfunction clampRange(from: number, to: number, doc: Node): { from: number; to: number } {\n const clampedFrom = Math.max(0, Math.min(from, doc.content.size))\n const clampedTo = Math.max(clampedFrom, Math.min(to, doc.content.size))\n\n return { from: clampedFrom, to: clampedTo }\n}\n\n/**\n * Removes and rebuilds placeholder decorations within the given ranges.\n * Only drops decorations fully contained in a range so mapped decorations\n * on neighbouring blocks (e.g. at a block boundary) are kept intact.\n */\nfunction updateDecorationsInRanges({\n decorations,\n ranges,\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n}: {\n decorations: DecorationSet\n ranges: Array<{ from: number; to: number }>\n editor: Editor\n options: PlaceholderOptions\n dataAttribute: string\n doc: Node\n selection: Selection\n}): DecorationSet {\n let next = decorations\n\n for (const range of ranges) {\n const { from, to } = clampRange(range.from, range.to, doc)\n const existing = next\n .find(from, to)\n .filter(decoration => decoration.from >= from && decoration.to <= to)\n\n if (existing.length) {\n next = next.remove(existing)\n }\n\n const newDecos = scanRangeForDecorations({\n editor,\n options,\n dataAttribute,\n doc,\n selection,\n from,\n to,\n })\n\n if (newDecos.length) {\n next = next.add(doc, newDecos)\n }\n }\n\n return next\n}\n\n/**\n * Creates the incremental `StateField<DecorationSet>` used by the slow path\n * (`showOnlyCurrent: false` or `includeChildren: true`).\n *\n * Decorations are mapped through each transaction and only recomputed for\n * top-level blocks touched by document or selection changes.\n * @param options.editor - The editor instance.\n * @param options.options - The resolved placeholder options.\n * @param options.dataAttribute - The prepared `data-*` attribute name.\n * @returns A ProseMirror state field storing the placeholder decoration set.\n */\nexport function createPlaceholderStateField({\n editor,\n options,\n dataAttribute,\n}: CreatePlaceholderStateFieldOptions): StateField<DecorationSet> {\n return {\n init(_config, state: EditorState) {\n const decorations = buildPlaceholderDecorations({\n editor,\n options,\n dataAttribute,\n doc: state.doc,\n selection: state.selection,\n })\n\n return decorations ?? DecorationSet.empty\n },\n\n apply(tr: Transaction, prev: DecorationSet, oldState: EditorState, newState: EditorState) {\n if (!tr.docChanged && !tr.selectionSet) {\n return prev\n }\n\n const mapped = prev.map(tr.mapping, tr.doc)\n const ranges = collectRescanRanges(tr, oldState, newState)\n\n return updateDecorationsInRanges({\n decorations: mapped,\n ranges,\n editor,\n options,\n dataAttribute,\n doc: newState.doc,\n selection: newState.selection,\n })\n },\n }\n}\n","import type { Node } from '@tiptap/pm/model'\n\n/**\n * Resolves a document position to the `[from, to)` range of its containing\n * top-level block node in absolute document positions.\n */\nexport function resolveTopLevelRange(doc: Node, pos: number): { from: number; to: number } {\n const resolved = doc.resolve(pos)\n\n if (resolved.depth === 0) {\n const node = resolved.nodeAfter ?? resolved.nodeBefore\n\n if (!node) {\n return { from: pos, to: pos }\n }\n\n const nodePos = resolved.nodeAfter ? pos : pos - node.nodeSize\n\n return { from: nodePos, to: nodePos + node.nodeSize }\n }\n\n const topLevelPos = resolved.before(1)\n const node = resolved.node(1)\n\n return { from: topLevelPos, to: topLevelPos + node.nodeSize }\n}\n\n/**\n * Converts an absolute document range to content-relative positions used by\n * `Node#nodesBetween` and `Node#forEach` offsets.\n */\nexport function toContentRelativeRange(\n doc: Node,\n range: { from: number; to: number },\n): { from: number; to: number } {\n return {\n from: Math.max(0, range.from - 1),\n to: Math.min(doc.content.size, range.to - 1),\n }\n}\n\n/**\n * Returns the top-level block ranges that intersect a document change range.\n * Input `from`/`to` are absolute positions (e.g. from `getChangedRanges`).\n * Returned ranges are content-relative, matching `Node#forEach` offsets.\n */\nexport function getTopLevelBlocksInRange(\n doc: Node,\n from: number,\n to: number,\n): Array<{ from: number; to: number }> {\n const ranges: Array<{ from: number; to: number }> = []\n\n doc.forEach((node, offset) => {\n const nodeStart = offset\n const nodeEnd = nodeStart + node.nodeSize\n const absNodeStart = nodeStart + 1\n const absNodeEnd = nodeEnd + 1\n\n if (absNodeStart < to && absNodeEnd > from) {\n ranges.push({ from: nodeStart, to: nodeEnd })\n }\n })\n\n return ranges\n}\n\n/**\n * Sorts ranges by start position and merges overlapping or adjacent ranges.\n */\nexport function mergeRanges(\n ranges: Array<{ from: number; to: number }>,\n): Array<{ from: number; to: number }> {\n if (ranges.length === 0) {\n return []\n }\n\n const sorted = [...ranges].sort((a, b) => a.from - b.from)\n const merged: Array<{ from: number; to: number }> = [{ ...sorted[0] }]\n\n for (let i = 1; i < sorted.length; i += 1) {\n const last = merged[merged.length - 1]\n const current = sorted[i]\n\n if (current.from <= last.to) {\n last.to = Math.max(last.to, current.to)\n } else {\n merged.push({ ...current })\n }\n }\n\n return merged\n}\n","/**\n * Prepares the placeholder attribute by ensuring it is properly formatted.\n * @param attr - The placeholder attribute string.\n * @returns The prepared placeholder attribute string.\n */\nexport function preparePlaceholderAttribute(attr: string): string {\n return (\n attr\n // replace whitespace with dashes\n .replace(/\\s+/g, '-')\n // replace non-alphanumeric characters\n // or special chars like $, %, &, etc.\n // but not dashes\n .replace(/[^a-zA-Z0-9-]/g, '')\n // and replace any numeric character at the start\n .replace(/^[0-9-]+/, '')\n // and finally replace any stray, leading dashes\n .replace(/^-+/, '')\n .toLowerCase()\n )\n}\n","import { Extension, isNodeSelection, type Editor } from '@tiptap/core'\nimport { Plugin, PluginKey, type EditorState } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * Whether the native browser selection should be cleared on blur and restored on focus.\n * Only applies to non-empty text selections in an editable editor.\n */\nfunction shouldSyncDomSelection(state: EditorState, editor: Editor): boolean {\n return !state.selection.empty && !isNodeSelection(state.selection) && editor.isEditable\n}\n\n/**\n * Whether the selection decoration should be rendered to keep the selection\n * visible while the editor is blurred (and not dragging).\n */\nfunction shouldPreserveSelection(state: EditorState, editor: Editor): boolean {\n return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging\n}\n\nfunction clearDomSelection() {\n window.getSelection()?.removeAllRanges()\n}\n\n/**\n * Sync the native selection from the editor state.\n * @see https://prosemirror.net/docs/ref/#view.EditorView.focus\n */\nfunction restoreDomSelection(view: EditorView) {\n view.focus()\n}\n\n/**\n * This extension allows you to add a class to the selected text when the editor is blurred.\n * It clears the native browser selection on blur (so `::selection` styles do not overlap the\n * decoration) and restores it when the editor is focused again.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create<SelectionOptions>({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (!shouldPreserveSelection(state, editor)) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n handleDOMEvents: {\n blur(view) {\n if (!shouldSyncDomSelection(view.state, editor)) {\n return false\n }\n\n clearDomSelection()\n\n return false\n },\n focus(view) {\n if (!shouldSyncDomSelection(view.state, editor)) {\n return false\n }\n\n requestAnimationFrame(() => {\n if (!editor.isDestroyed && view.hasFocus()) {\n restoreDomSelection(view)\n }\n })\n\n return false\n },\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n","import { Extension } from '@tiptap/core'\nimport type { Node, NodeType } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nexport const skipTrailingNodeMeta = 'skipTrailingNode'\n\nfunction nodeEqualsType({\n types,\n node,\n}: {\n types: NodeType | NodeType[]\n node: Node | null | undefined\n}) {\n return (node && Array.isArray(types) && types.includes(node.type)) || node?.type === types\n}\n\n/**\n * Extension based on:\n * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js\n * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts\n */\n\nexport interface TrailingNodeOptions {\n /**\n * The node type that should be inserted at the end of the document.\n * @note the node will always be added to the `notAfter` lists to\n * prevent an infinite loop.\n * @default undefined\n */\n node?: string\n /**\n * The node types after which the trailing node should not be inserted.\n * @default ['paragraph']\n */\n notAfter?: string | string[]\n}\n\n/**\n * This extension allows you to add an extra node at the end of the document.\n * @see https://www.tiptap.dev/api/extensions/trailing-node\n */\nexport const TrailingNode = Extension.create<TrailingNodeOptions>({\n name: 'trailingNode',\n\n addOptions() {\n return {\n node: undefined,\n notAfter: [],\n }\n },\n\n addProseMirrorPlugins() {\n const plugin = new PluginKey(this.name)\n const defaultNode =\n this.options.node ||\n this.editor.schema.topNodeType.contentMatch.defaultType?.name ||\n 'paragraph'\n\n const disabledNodes = Object.entries(this.editor.schema.nodes)\n .map(([, value]) => value)\n .filter(node => (this.options.notAfter || []).concat(defaultNode).includes(node.name))\n\n return [\n new Plugin({\n key: plugin,\n appendTransaction: (transactions, __, state) => {\n const { doc, tr, schema } = state\n const shouldInsertNodeAtEnd = plugin.getState(state)\n const endPosition = doc.content.size\n const type = schema.nodes[defaultNode]\n\n if (transactions.some(transaction => transaction.getMeta(skipTrailingNodeMeta))) {\n return\n }\n\n if (!shouldInsertNodeAtEnd) {\n return\n }\n\n return tr.insert(endPosition, type.create())\n },\n state: {\n init: (_, state) => {\n const lastNode = state.tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n apply: (tr, value) => {\n if (!tr.docChanged) {\n return value\n }\n\n // Ignore transactions from UniqueID extension to prevent infinite loops\n // when UniqueID adds IDs to newly inserted trailing nodes\n if (tr.getMeta('__uniqueIDTransaction')) {\n return value\n }\n\n const lastNode = tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n },\n }),\n ]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { history, redo, undo } from '@tiptap/pm/history'\n\nexport interface UndoRedoOptions {\n /**\n * The amount of history events that are collected before the oldest events are discarded.\n * @default 100\n * @example 50\n */\n depth: number\n\n /**\n * The delay (in milliseconds) between changes after which a new group should be started.\n * @default 500\n * @example 1000\n */\n newGroupDelay: number\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n undoRedo: {\n /**\n * Undo recent changes\n * @example editor.commands.undo()\n */\n undo: () => ReturnType\n /**\n * Reapply reverted changes\n * @example editor.commands.redo()\n */\n redo: () => ReturnType\n }\n }\n}\n\n/**\n * This extension allows you to undo and redo recent changes.\n * @see https://www.tiptap.dev/api/extensions/undo-redo\n *\n * **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove\n * the `undo-redo` extension, as it is not compatible with the `collaboration` extension.\n *\n * `@tiptap/extension-collaboration` uses its own history implementation.\n */\nexport const UndoRedo = Extension.create<UndoRedoOptions>({\n name: 'undoRedo',\n\n addOptions() {\n return {\n depth: 100,\n newGroupDelay: 500,\n }\n },\n\n addCommands() {\n return {\n undo:\n () =>\n ({ state, dispatch }) => {\n return undo(state, dispatch)\n },\n redo:\n () =>\n ({ state, dispatch }) => {\n return redo(state, dispatch)\n },\n }\n },\n\n addProseMirrorPlugins() {\n return [history(this.options)]\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-z': () => this.editor.commands.undo(),\n 'Shift-Mod-z': () => this.editor.commands.redo(),\n 'Mod-y': () => this.editor.commands.redo(),\n\n // Russian keyboard layouts\n 'Mod-я': () => this.editor.commands.undo(),\n 'Shift-Mod-я': () => this.editor.commands.redo(),\n }\n },\n})\n"],"mappings":";AAAA,SAAS,iBAAiB;AAE1B,SAAS,QAAQ,iBAAiB;AAgE3B,IAAM,iBAAiB,UAAU,OAAqD;AAAA,EAC3F,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,MACN,aAAa,UAAQ,KAAK;AAAA,MAC1B,aAAa,UAAQ,KAAK,MAAM,GAAG,EAAE,OAAO,UAAQ,SAAS,EAAE,EAAE;AAAA,IACnE;AAAA,EACF;AAAA,EAEA,aAAa;AACX,WAAO;AAAA,MACL,YAAY,MAAM;AAAA,MAClB,OAAO,MAAM;AAAA,IACf;AAAA,EACF;AAAA,EAEA,iBAAiB;AACf,SAAK,QAAQ,aAAa,aAAW;AACnC,YAAM,QAAO,mCAAS,SAAQ,KAAK,OAAO,MAAM;AAChD,YAAM,QAAO,mCAAS,SAAQ,KAAK,QAAQ;AAE3C,UAAI,SAAS,YAAY;AACvB,cAAM,OAAO,KAAK,YAAY,GAAG,KAAK,QAAQ,MAAM,QAAW,GAAG;AAElE,eAAO,KAAK,QAAQ,YAAY,IAAI;AAAA,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,EAEA,wBAAwB;AACtB,WAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AAAA,EAC/B;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,eAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MAC/C,SAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA;AAAA,MAGzC,cAAS,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,MACzC,oBAAe,MAAM,KAAK,OAAO,SAAS,KAAK;AAAA,IACjD;AAAA,EACF;AACF,CAAC;","names":["Extension","Extension","Plugin","PluginKey","Extension","PluginKey","Extension","Plugin","DecorationSet","DecorationSet","Decoration","DecorationSet","DecorationSet","node","DecorationSet","Plugin","DecorationSet","Extension","Extension","Plugin","PluginKey","Decoration","DecorationSet","Extension","Plugin","PluginKey","Extension"]} |
+33
-10
@@ -31,9 +31,15 @@ "use strict"; | ||
| var import_view = require("@tiptap/pm/view"); | ||
| var selectionStyle = `.ProseMirror:not(.ProseMirror-focused) *::selection { | ||
| background: transparent; | ||
| function shouldSyncDomSelection(state, editor) { | ||
| return !state.selection.empty && !(0, import_core.isNodeSelection)(state.selection) && editor.isEditable; | ||
| } | ||
| .ProseMirror:not(.ProseMirror-focused) *::-moz-selection { | ||
| background: transparent; | ||
| }`; | ||
| function shouldPreserveSelection(state, editor) { | ||
| return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging; | ||
| } | ||
| function clearDomSelection() { | ||
| var _a; | ||
| (_a = window.getSelection()) == null ? void 0 : _a.removeAllRanges(); | ||
| } | ||
| function restoreDomSelection(view) { | ||
| view.focus(); | ||
| } | ||
| var Selection = import_core.Extension.create({ | ||
@@ -48,5 +54,2 @@ name: "selection", | ||
| const { editor, options } = this; | ||
| if (editor.options.injectCSS && typeof document !== "undefined") { | ||
| (0, import_core.createStyleTag)(selectionStyle, editor.options.injectNonce, "selection"); | ||
| } | ||
| return [ | ||
@@ -57,3 +60,3 @@ new import_state.Plugin({ | ||
| decorations(state) { | ||
| if (state.selection.empty || editor.isFocused || !editor.isEditable || (0, import_core.isNodeSelection)(state.selection) || editor.view.dragging) { | ||
| if (!shouldPreserveSelection(state, editor)) { | ||
| return null; | ||
@@ -66,2 +69,22 @@ } | ||
| ]); | ||
| }, | ||
| handleDOMEvents: { | ||
| blur(view) { | ||
| if (!shouldSyncDomSelection(view.state, editor)) { | ||
| return false; | ||
| } | ||
| clearDomSelection(); | ||
| return false; | ||
| }, | ||
| focus(view) { | ||
| if (!shouldSyncDomSelection(view.state, editor)) { | ||
| return false; | ||
| } | ||
| requestAnimationFrame(() => { | ||
| if (!editor.isDestroyed && view.hasFocus()) { | ||
| restoreDomSelection(view); | ||
| } | ||
| }); | ||
| return false; | ||
| } | ||
| } | ||
@@ -68,0 +91,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../../src/selection/index.ts","../../src/selection/selection.ts"],"sourcesContent":["export * from './selection.js'\n","import { createStyleTag, Extension, isNodeSelection } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nconst selectionStyle = `.ProseMirror:not(.ProseMirror-focused) *::selection {\n background: transparent;\n}\n\n.ProseMirror:not(.ProseMirror-focused) *::-moz-selection {\n background: transparent;\n}`\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * This extension allows you to add a class to the selected text.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create<SelectionOptions>({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n if (editor.options.injectCSS && typeof document !== 'undefined') {\n createStyleTag(selectionStyle, editor.options.injectNonce, 'selection')\n }\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (\n state.selection.empty ||\n editor.isFocused ||\n !editor.isEditable ||\n isNodeSelection(state.selection) ||\n editor.view.dragging\n ) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA2D;AAC3D,mBAAkC;AAClC,kBAA0C;AAE1C,IAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBhB,IAAM,YAAY,sBAAU,OAAyB;AAAA,EAC1D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,QAAI,OAAO,QAAQ,aAAa,OAAO,aAAa,aAAa;AAC/D,sCAAe,gBAAgB,OAAO,QAAQ,aAAa,WAAW;AAAA,IACxE;AAEA,WAAO;AAAA,MACL,IAAI,oBAAO;AAAA,QACT,KAAK,IAAI,uBAAU,WAAW;AAAA,QAC9B,OAAO;AAAA,UACL,YAAY,OAAO;AACjB,gBACE,MAAM,UAAU,SAChB,OAAO,aACP,CAAC,OAAO,kBACR,6BAAgB,MAAM,SAAS,KAC/B,OAAO,KAAK,UACZ;AACA,qBAAO;AAAA,YACT;AAEA,mBAAO,0BAAc,OAAO,MAAM,KAAK;AAAA,cACrC,uBAAW,OAAO,MAAM,UAAU,MAAM,MAAM,UAAU,IAAI;AAAA,gBAC1D,OAAO,QAAQ;AAAA,cACjB,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]} | ||
| {"version":3,"sources":["../../src/selection/index.ts","../../src/selection/selection.ts"],"sourcesContent":["export * from './selection.js'\n","import { Extension, isNodeSelection, type Editor } from '@tiptap/core'\nimport { Plugin, PluginKey, type EditorState } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * Whether the native browser selection should be cleared on blur and restored on focus.\n * Only applies to non-empty text selections in an editable editor.\n */\nfunction shouldSyncDomSelection(state: EditorState, editor: Editor): boolean {\n return !state.selection.empty && !isNodeSelection(state.selection) && editor.isEditable\n}\n\n/**\n * Whether the selection decoration should be rendered to keep the selection\n * visible while the editor is blurred (and not dragging).\n */\nfunction shouldPreserveSelection(state: EditorState, editor: Editor): boolean {\n return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging\n}\n\nfunction clearDomSelection() {\n window.getSelection()?.removeAllRanges()\n}\n\n/**\n * Sync the native selection from the editor state.\n * @see https://prosemirror.net/docs/ref/#view.EditorView.focus\n */\nfunction restoreDomSelection(view: EditorView) {\n view.focus()\n}\n\n/**\n * This extension allows you to add a class to the selected text when the editor is blurred.\n * It clears the native browser selection on blur (so `::selection` styles do not overlap the\n * decoration) and restores it when the editor is focused again.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create<SelectionOptions>({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (!shouldPreserveSelection(state, editor)) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n handleDOMEvents: {\n blur(view) {\n if (!shouldSyncDomSelection(view.state, editor)) {\n return false\n }\n\n clearDomSelection()\n\n return false\n },\n focus(view) {\n if (!shouldSyncDomSelection(view.state, editor)) {\n return false\n }\n\n requestAnimationFrame(() => {\n if (!editor.isDestroyed && view.hasFocus()) {\n restoreDomSelection(view)\n }\n })\n\n return false\n },\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAwD;AACxD,mBAAoD;AAEpD,kBAA0C;AAe1C,SAAS,uBAAuB,OAAoB,QAAyB;AAC3E,SAAO,CAAC,MAAM,UAAU,SAAS,KAAC,6BAAgB,MAAM,SAAS,KAAK,OAAO;AAC/E;AAMA,SAAS,wBAAwB,OAAoB,QAAyB;AAC5E,SAAO,uBAAuB,OAAO,MAAM,KAAK,CAAC,OAAO,aAAa,CAAC,OAAO,KAAK;AACpF;AAEA,SAAS,oBAAoB;AA9B7B;AA+BE,eAAO,aAAa,MAApB,mBAAuB;AACzB;AAMA,SAAS,oBAAoB,MAAkB;AAC7C,OAAK,MAAM;AACb;AAQO,IAAM,YAAY,sBAAU,OAAyB;AAAA,EAC1D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,WAAO;AAAA,MACL,IAAI,oBAAO;AAAA,QACT,KAAK,IAAI,uBAAU,WAAW;AAAA,QAC9B,OAAO;AAAA,UACL,YAAY,OAAO;AACjB,gBAAI,CAAC,wBAAwB,OAAO,MAAM,GAAG;AAC3C,qBAAO;AAAA,YACT;AAEA,mBAAO,0BAAc,OAAO,MAAM,KAAK;AAAA,cACrC,uBAAW,OAAO,MAAM,UAAU,MAAM,MAAM,UAAU,IAAI;AAAA,gBAC1D,OAAO,QAAQ;AAAA,cACjB,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,UACA,iBAAiB;AAAA,YACf,KAAK,MAAM;AACT,kBAAI,CAAC,uBAAuB,KAAK,OAAO,MAAM,GAAG;AAC/C,uBAAO;AAAA,cACT;AAEA,gCAAkB;AAElB,qBAAO;AAAA,YACT;AAAA,YACA,MAAM,MAAM;AACV,kBAAI,CAAC,uBAAuB,KAAK,OAAO,MAAM,GAAG;AAC/C,uBAAO;AAAA,cACT;AAEA,oCAAsB,MAAM;AAC1B,oBAAI,CAAC,OAAO,eAAe,KAAK,SAAS,GAAG;AAC1C,sCAAoB,IAAI;AAAA,gBAC1B;AAAA,cACF,CAAC;AAED,qBAAO;AAAA,YACT;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]} |
@@ -12,3 +12,5 @@ import { Extension } from '@tiptap/core'; | ||
| /** | ||
| * This extension allows you to add a class to the selected text. | ||
| * This extension allows you to add a class to the selected text when the editor is blurred. | ||
| * It clears the native browser selection on blur (so `::selection` styles do not overlap the | ||
| * decoration) and restores it when the editor is focused again. | ||
| * @see https://www.tiptap.dev/api/extensions/selection | ||
@@ -15,0 +17,0 @@ */ |
@@ -12,3 +12,5 @@ import { Extension } from '@tiptap/core'; | ||
| /** | ||
| * This extension allows you to add a class to the selected text. | ||
| * This extension allows you to add a class to the selected text when the editor is blurred. | ||
| * It clears the native browser selection on blur (so `::selection` styles do not overlap the | ||
| * decoration) and restores it when the editor is focused again. | ||
| * @see https://www.tiptap.dev/api/extensions/selection | ||
@@ -15,0 +17,0 @@ */ |
+34
-11
| // src/selection/selection.ts | ||
| import { createStyleTag, Extension, isNodeSelection } from "@tiptap/core"; | ||
| import { Extension, isNodeSelection } from "@tiptap/core"; | ||
| import { Plugin, PluginKey } from "@tiptap/pm/state"; | ||
| import { Decoration, DecorationSet } from "@tiptap/pm/view"; | ||
| var selectionStyle = `.ProseMirror:not(.ProseMirror-focused) *::selection { | ||
| background: transparent; | ||
| function shouldSyncDomSelection(state, editor) { | ||
| return !state.selection.empty && !isNodeSelection(state.selection) && editor.isEditable; | ||
| } | ||
| .ProseMirror:not(.ProseMirror-focused) *::-moz-selection { | ||
| background: transparent; | ||
| }`; | ||
| function shouldPreserveSelection(state, editor) { | ||
| return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging; | ||
| } | ||
| function clearDomSelection() { | ||
| var _a; | ||
| (_a = window.getSelection()) == null ? void 0 : _a.removeAllRanges(); | ||
| } | ||
| function restoreDomSelection(view) { | ||
| view.focus(); | ||
| } | ||
| var Selection = Extension.create({ | ||
@@ -21,5 +27,2 @@ name: "selection", | ||
| const { editor, options } = this; | ||
| if (editor.options.injectCSS && typeof document !== "undefined") { | ||
| createStyleTag(selectionStyle, editor.options.injectNonce, "selection"); | ||
| } | ||
| return [ | ||
@@ -30,3 +33,3 @@ new Plugin({ | ||
| decorations(state) { | ||
| if (state.selection.empty || editor.isFocused || !editor.isEditable || isNodeSelection(state.selection) || editor.view.dragging) { | ||
| if (!shouldPreserveSelection(state, editor)) { | ||
| return null; | ||
@@ -39,2 +42,22 @@ } | ||
| ]); | ||
| }, | ||
| handleDOMEvents: { | ||
| blur(view) { | ||
| if (!shouldSyncDomSelection(view.state, editor)) { | ||
| return false; | ||
| } | ||
| clearDomSelection(); | ||
| return false; | ||
| }, | ||
| focus(view) { | ||
| if (!shouldSyncDomSelection(view.state, editor)) { | ||
| return false; | ||
| } | ||
| requestAnimationFrame(() => { | ||
| if (!editor.isDestroyed && view.hasFocus()) { | ||
| restoreDomSelection(view); | ||
| } | ||
| }); | ||
| return false; | ||
| } | ||
| } | ||
@@ -41,0 +64,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../../src/selection/selection.ts"],"sourcesContent":["import { createStyleTag, Extension, isNodeSelection } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nconst selectionStyle = `.ProseMirror:not(.ProseMirror-focused) *::selection {\n background: transparent;\n}\n\n.ProseMirror:not(.ProseMirror-focused) *::-moz-selection {\n background: transparent;\n}`\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * This extension allows you to add a class to the selected text.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create<SelectionOptions>({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n if (editor.options.injectCSS && typeof document !== 'undefined') {\n createStyleTag(selectionStyle, editor.options.injectNonce, 'selection')\n }\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (\n state.selection.empty ||\n editor.isFocused ||\n !editor.isEditable ||\n isNodeSelection(state.selection) ||\n editor.view.dragging\n ) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n"],"mappings":";AAAA,SAAS,gBAAgB,WAAW,uBAAuB;AAC3D,SAAS,QAAQ,iBAAiB;AAClC,SAAS,YAAY,qBAAqB;AAE1C,IAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBhB,IAAM,YAAY,UAAU,OAAyB;AAAA,EAC1D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,QAAI,OAAO,QAAQ,aAAa,OAAO,aAAa,aAAa;AAC/D,qBAAe,gBAAgB,OAAO,QAAQ,aAAa,WAAW;AAAA,IACxE;AAEA,WAAO;AAAA,MACL,IAAI,OAAO;AAAA,QACT,KAAK,IAAI,UAAU,WAAW;AAAA,QAC9B,OAAO;AAAA,UACL,YAAY,OAAO;AACjB,gBACE,MAAM,UAAU,SAChB,OAAO,aACP,CAAC,OAAO,cACR,gBAAgB,MAAM,SAAS,KAC/B,OAAO,KAAK,UACZ;AACA,qBAAO;AAAA,YACT;AAEA,mBAAO,cAAc,OAAO,MAAM,KAAK;AAAA,cACrC,WAAW,OAAO,MAAM,UAAU,MAAM,MAAM,UAAU,IAAI;AAAA,gBAC1D,OAAO,QAAQ;AAAA,cACjB,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]} | ||
| {"version":3,"sources":["../../src/selection/selection.ts"],"sourcesContent":["import { Extension, isNodeSelection, type Editor } from '@tiptap/core'\nimport { Plugin, PluginKey, type EditorState } from '@tiptap/pm/state'\nimport type { EditorView } from '@tiptap/pm/view'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * Whether the native browser selection should be cleared on blur and restored on focus.\n * Only applies to non-empty text selections in an editable editor.\n */\nfunction shouldSyncDomSelection(state: EditorState, editor: Editor): boolean {\n return !state.selection.empty && !isNodeSelection(state.selection) && editor.isEditable\n}\n\n/**\n * Whether the selection decoration should be rendered to keep the selection\n * visible while the editor is blurred (and not dragging).\n */\nfunction shouldPreserveSelection(state: EditorState, editor: Editor): boolean {\n return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging\n}\n\nfunction clearDomSelection() {\n window.getSelection()?.removeAllRanges()\n}\n\n/**\n * Sync the native selection from the editor state.\n * @see https://prosemirror.net/docs/ref/#view.EditorView.focus\n */\nfunction restoreDomSelection(view: EditorView) {\n view.focus()\n}\n\n/**\n * This extension allows you to add a class to the selected text when the editor is blurred.\n * It clears the native browser selection on blur (so `::selection` styles do not overlap the\n * decoration) and restores it when the editor is focused again.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create<SelectionOptions>({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (!shouldPreserveSelection(state, editor)) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n handleDOMEvents: {\n blur(view) {\n if (!shouldSyncDomSelection(view.state, editor)) {\n return false\n }\n\n clearDomSelection()\n\n return false\n },\n focus(view) {\n if (!shouldSyncDomSelection(view.state, editor)) {\n return false\n }\n\n requestAnimationFrame(() => {\n if (!editor.isDestroyed && view.hasFocus()) {\n restoreDomSelection(view)\n }\n })\n\n return false\n },\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n"],"mappings":";AAAA,SAAS,WAAW,uBAAoC;AACxD,SAAS,QAAQ,iBAAmC;AAEpD,SAAS,YAAY,qBAAqB;AAe1C,SAAS,uBAAuB,OAAoB,QAAyB;AAC3E,SAAO,CAAC,MAAM,UAAU,SAAS,CAAC,gBAAgB,MAAM,SAAS,KAAK,OAAO;AAC/E;AAMA,SAAS,wBAAwB,OAAoB,QAAyB;AAC5E,SAAO,uBAAuB,OAAO,MAAM,KAAK,CAAC,OAAO,aAAa,CAAC,OAAO,KAAK;AACpF;AAEA,SAAS,oBAAoB;AA9B7B;AA+BE,eAAO,aAAa,MAApB,mBAAuB;AACzB;AAMA,SAAS,oBAAoB,MAAkB;AAC7C,OAAK,MAAM;AACb;AAQO,IAAM,YAAY,UAAU,OAAyB;AAAA,EAC1D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,WAAO;AAAA,MACL,IAAI,OAAO;AAAA,QACT,KAAK,IAAI,UAAU,WAAW;AAAA,QAC9B,OAAO;AAAA,UACL,YAAY,OAAO;AACjB,gBAAI,CAAC,wBAAwB,OAAO,MAAM,GAAG;AAC3C,qBAAO;AAAA,YACT;AAEA,mBAAO,cAAc,OAAO,MAAM,KAAK;AAAA,cACrC,WAAW,OAAO,MAAM,UAAU,MAAM,MAAM,UAAU,IAAI;AAAA,gBAC1D,OAAO,QAAQ;AAAA,cACjB,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,UACA,iBAAiB;AAAA,YACf,KAAK,MAAM;AACT,kBAAI,CAAC,uBAAuB,KAAK,OAAO,MAAM,GAAG;AAC/C,uBAAO;AAAA,cACT;AAEA,gCAAkB;AAElB,qBAAO;AAAA,YACT;AAAA,YACA,MAAM,MAAM;AACV,kBAAI,CAAC,uBAAuB,KAAK,OAAO,MAAM,GAAG;AAC/C,uBAAO;AAAA,cACT;AAEA,oCAAsB,MAAM;AAC1B,oBAAI,CAAC,OAAO,eAAe,KAAK,SAAS,GAAG;AAC1C,sCAAoB,IAAI;AAAA,gBAC1B;AAAA,cACF,CAAC;AAED,qBAAO;AAAA,YACT;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]} |
+5
-5
| { | ||
| "name": "@tiptap/extensions", | ||
| "version": "3.27.3", | ||
| "version": "3.27.4", | ||
| "description": "various extensions for tiptap", | ||
@@ -106,8 +106,8 @@ "keywords": [ | ||
| "devDependencies": { | ||
| "@tiptap/core": "^3.27.3", | ||
| "@tiptap/pm": "^3.27.3" | ||
| "@tiptap/core": "^3.27.4", | ||
| "@tiptap/pm": "^3.27.4" | ||
| }, | ||
| "peerDependencies": { | ||
| "@tiptap/core": "3.27.3", | ||
| "@tiptap/pm": "3.27.3" | ||
| "@tiptap/core": "3.27.4", | ||
| "@tiptap/pm": "3.27.4" | ||
| }, | ||
@@ -114,0 +114,0 @@ "scripts": { |
@@ -1,13 +0,6 @@ | ||
| import { createStyleTag, Extension, isNodeSelection } from '@tiptap/core' | ||
| import { Plugin, PluginKey } from '@tiptap/pm/state' | ||
| import { Extension, isNodeSelection, type Editor } from '@tiptap/core' | ||
| import { Plugin, PluginKey, type EditorState } from '@tiptap/pm/state' | ||
| import type { EditorView } from '@tiptap/pm/view' | ||
| import { Decoration, DecorationSet } from '@tiptap/pm/view' | ||
| const selectionStyle = `.ProseMirror:not(.ProseMirror-focused) *::selection { | ||
| background: transparent; | ||
| } | ||
| .ProseMirror:not(.ProseMirror-focused) *::-moz-selection { | ||
| background: transparent; | ||
| }` | ||
| export type SelectionOptions = { | ||
@@ -23,3 +16,33 @@ /** | ||
| /** | ||
| * This extension allows you to add a class to the selected text. | ||
| * Whether the native browser selection should be cleared on blur and restored on focus. | ||
| * Only applies to non-empty text selections in an editable editor. | ||
| */ | ||
| function shouldSyncDomSelection(state: EditorState, editor: Editor): boolean { | ||
| return !state.selection.empty && !isNodeSelection(state.selection) && editor.isEditable | ||
| } | ||
| /** | ||
| * Whether the selection decoration should be rendered to keep the selection | ||
| * visible while the editor is blurred (and not dragging). | ||
| */ | ||
| function shouldPreserveSelection(state: EditorState, editor: Editor): boolean { | ||
| return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging | ||
| } | ||
| function clearDomSelection() { | ||
| window.getSelection()?.removeAllRanges() | ||
| } | ||
| /** | ||
| * Sync the native selection from the editor state. | ||
| * @see https://prosemirror.net/docs/ref/#view.EditorView.focus | ||
| */ | ||
| function restoreDomSelection(view: EditorView) { | ||
| view.focus() | ||
| } | ||
| /** | ||
| * This extension allows you to add a class to the selected text when the editor is blurred. | ||
| * It clears the native browser selection on blur (so `::selection` styles do not overlap the | ||
| * decoration) and restores it when the editor is focused again. | ||
| * @see https://www.tiptap.dev/api/extensions/selection | ||
@@ -39,6 +62,2 @@ */ | ||
| if (editor.options.injectCSS && typeof document !== 'undefined') { | ||
| createStyleTag(selectionStyle, editor.options.injectNonce, 'selection') | ||
| } | ||
| return [ | ||
@@ -49,9 +68,3 @@ new Plugin({ | ||
| decorations(state) { | ||
| if ( | ||
| state.selection.empty || | ||
| editor.isFocused || | ||
| !editor.isEditable || | ||
| isNodeSelection(state.selection) || | ||
| editor.view.dragging | ||
| ) { | ||
| if (!shouldPreserveSelection(state, editor)) { | ||
| return null | ||
@@ -66,2 +79,26 @@ } | ||
| }, | ||
| handleDOMEvents: { | ||
| blur(view) { | ||
| if (!shouldSyncDomSelection(view.state, editor)) { | ||
| return false | ||
| } | ||
| clearDomSelection() | ||
| return false | ||
| }, | ||
| focus(view) { | ||
| if (!shouldSyncDomSelection(view.state, editor)) { | ||
| return false | ||
| } | ||
| requestAnimationFrame(() => { | ||
| if (!editor.isDestroyed && view.hasFocus()) { | ||
| restoreDomSelection(view) | ||
| } | ||
| }) | ||
| return false | ||
| }, | ||
| }, | ||
| }, | ||
@@ -68,0 +105,0 @@ }), |
414230
2.88%5043
2.69%