@tiptap/core 3.11.0 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +44 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -4
- package/dist/index.d.ts +75 -4
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/Editor.ts +10 -0
- package/src/Mark.ts +1 -1
- package/src/Node.ts +1 -1
- package/src/helpers/MappablePosition.ts +66 -0
- package/src/helpers/index.ts +1 -0
- package/src/types.ts +35 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Transaction, EditorState, Plugin, Selection, NodeSelection, TextSelection, PluginKey } from '@tiptap/pm/state';
|
|
2
2
|
import { Node as Node$1, MarkType as MarkType$1, MarkSpec, Mark as Mark$1, DOMOutputSpec, NodeType as NodeType$1, NodeSpec, Slice, ParseOptions, Fragment as Fragment$1, Schema, ContentMatch, ResolvedPos, ParseRule } from '@tiptap/pm/model';
|
|
3
3
|
import { EditorProps, EditorView, Decoration, DecorationAttrs, ViewMutationRecord, NodeViewConstructor, NodeView as NodeView$1, MarkViewConstructor, MarkView as MarkView$1, DecorationSource } from '@tiptap/pm/view';
|
|
4
|
-
import { Transform, Mappable } from '@tiptap/pm/transform';
|
|
4
|
+
import { Transform, Mappable, MapResult } from '@tiptap/pm/transform';
|
|
5
5
|
|
|
6
6
|
type StringKeyOf<T> = Extract<keyof T, string>;
|
|
7
7
|
type CallbackType<T extends Record<string, any>, EventName extends StringKeyOf<T>> = T[EventName] extends any[] ? T[EventName] : [T[EventName]];
|
|
@@ -195,7 +195,7 @@ declare class Mark<Options = any, Storage = any> extends Extendable<Options, Sto
|
|
|
195
195
|
mark: Mark;
|
|
196
196
|
}): boolean;
|
|
197
197
|
configure(options?: Partial<Options>): Mark<Options, Storage>;
|
|
198
|
-
extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = MarkConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: (() => Partial<ExtendedConfig>) | (Partial<ExtendedConfig> & ThisType<{
|
|
198
|
+
extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig extends MarkConfig<ExtendedOptions, ExtendedStorage> = MarkConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: (() => Partial<ExtendedConfig>) | (Partial<ExtendedConfig> & ThisType<{
|
|
199
199
|
name: string;
|
|
200
200
|
options: ExtendedOptions;
|
|
201
201
|
storage: ExtendedStorage;
|
|
@@ -488,7 +488,7 @@ declare class Node<Options = any, Storage = any> extends Extendable<Options, Sto
|
|
|
488
488
|
*/
|
|
489
489
|
static create<O = any, S = any>(config?: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>)): Node<O, S>;
|
|
490
490
|
configure(options?: Partial<Options>): Node<Options, Storage>;
|
|
491
|
-
extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = NodeConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: (() => Partial<ExtendedConfig>) | (Partial<ExtendedConfig> & ThisType<{
|
|
491
|
+
extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig extends NodeConfig<ExtendedOptions, ExtendedStorage> = NodeConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: (() => Partial<ExtendedConfig>) | (Partial<ExtendedConfig> & ThisType<{
|
|
492
492
|
name: string;
|
|
493
493
|
options: ExtendedOptions;
|
|
494
494
|
storage: ExtendedStorage;
|
|
@@ -1761,6 +1761,31 @@ type MarkdownRendererHelpers = {
|
|
|
1761
1761
|
*/
|
|
1762
1762
|
indent: (content: string) => string;
|
|
1763
1763
|
};
|
|
1764
|
+
type Utils = {
|
|
1765
|
+
/**
|
|
1766
|
+
* Returns the new position after applying a transaction.
|
|
1767
|
+
*
|
|
1768
|
+
* @param position The position to update. A MappablePosition instance.
|
|
1769
|
+
* @param transaction The transaction to apply.
|
|
1770
|
+
* @returns The new position after applying the transaction.
|
|
1771
|
+
*
|
|
1772
|
+
* @example
|
|
1773
|
+
* const position = editor.utils.createMappablePosition(10)
|
|
1774
|
+
* const {position, mapResult} = editor.utils.getUpdatedPosition(position, transaction)
|
|
1775
|
+
*/
|
|
1776
|
+
getUpdatedPosition: (position: MappablePosition, transaction: Transaction) => GetUpdatedPositionResult;
|
|
1777
|
+
/**
|
|
1778
|
+
* Creates a MappablePosition from a position number. A mappable position can be used to track the
|
|
1779
|
+
* next position after applying a transaction.
|
|
1780
|
+
*
|
|
1781
|
+
* @param position The position (as a number) where the MappablePosition will be created.
|
|
1782
|
+
* @returns A new MappablePosition instance at the given position.
|
|
1783
|
+
*
|
|
1784
|
+
* @example
|
|
1785
|
+
* const position = editor.utils.createMappablePosition(10)
|
|
1786
|
+
*/
|
|
1787
|
+
createMappablePosition: (position: number) => MappablePosition;
|
|
1788
|
+
};
|
|
1764
1789
|
|
|
1765
1790
|
/**
|
|
1766
1791
|
* Create a new Prosemirror document node from content.
|
|
@@ -2093,6 +2118,48 @@ declare function isNodeSelection(value: unknown): value is NodeSelection;
|
|
|
2093
2118
|
|
|
2094
2119
|
declare function isTextSelection(value: unknown): value is TextSelection;
|
|
2095
2120
|
|
|
2121
|
+
/**
|
|
2122
|
+
* A class that represents a mappable position in the editor. It can be extended
|
|
2123
|
+
* by other extensions to add additional position mapping capabilities.
|
|
2124
|
+
*/
|
|
2125
|
+
declare class MappablePosition {
|
|
2126
|
+
/**
|
|
2127
|
+
* The absolute position in the editor.
|
|
2128
|
+
*/
|
|
2129
|
+
position: number;
|
|
2130
|
+
constructor(position: number);
|
|
2131
|
+
/**
|
|
2132
|
+
* Creates a MappablePosition from a JSON object.
|
|
2133
|
+
*/
|
|
2134
|
+
static fromJSON(json: any): MappablePosition;
|
|
2135
|
+
/**
|
|
2136
|
+
* Converts the MappablePosition to a JSON object.
|
|
2137
|
+
*/
|
|
2138
|
+
toJSON(): any;
|
|
2139
|
+
}
|
|
2140
|
+
/**
|
|
2141
|
+
* The result of the getUpdatedPosition function.
|
|
2142
|
+
*/
|
|
2143
|
+
interface GetUpdatedPositionResult {
|
|
2144
|
+
position: MappablePosition;
|
|
2145
|
+
mapResult: MapResult | null;
|
|
2146
|
+
}
|
|
2147
|
+
/**
|
|
2148
|
+
* Calculates the new position after applying a transaction.
|
|
2149
|
+
*
|
|
2150
|
+
* @returns The new mappable position and the map result.
|
|
2151
|
+
*/
|
|
2152
|
+
declare function getUpdatedPosition(position: MappablePosition, transaction: Transaction): GetUpdatedPositionResult;
|
|
2153
|
+
/**
|
|
2154
|
+
* Creates a MappablePosition from a position number. This is the default
|
|
2155
|
+
* implementation for Tiptap core. It can be overridden by other Tiptap
|
|
2156
|
+
* extensions.
|
|
2157
|
+
*
|
|
2158
|
+
* @param position The position (as a number) where the MappablePosition will be created.
|
|
2159
|
+
* @returns A new MappablePosition instance at the given position.
|
|
2160
|
+
*/
|
|
2161
|
+
declare function createMappablePosition(position: number): MappablePosition;
|
|
2162
|
+
|
|
2096
2163
|
declare function posToDOMRect(view: EditorView, from: number, to: number): DOMRect;
|
|
2097
2164
|
|
|
2098
2165
|
/**
|
|
@@ -3513,6 +3580,10 @@ declare class Editor extends EventEmitter<EditorEvents> {
|
|
|
3513
3580
|
}): NodePos[] | null;
|
|
3514
3581
|
$pos(pos: number): NodePos;
|
|
3515
3582
|
get $doc(): NodePos;
|
|
3583
|
+
/**
|
|
3584
|
+
* Returns a set of utilities for working with positions and ranges.
|
|
3585
|
+
*/
|
|
3586
|
+
utils: Utils;
|
|
3516
3587
|
}
|
|
3517
3588
|
|
|
3518
3589
|
declare class CommandManager {
|
|
@@ -4643,4 +4714,4 @@ interface Commands<ReturnType = any> {
|
|
|
4643
4714
|
interface Storage {
|
|
4644
4715
|
}
|
|
4645
4716
|
|
|
4646
|
-
export { type AnyCommands, type AnyConfig, type AnyExtension, type AtomBlockMarkdownSpecOptions, type Attribute, type Attributes$1 as Attributes, type BlockMarkdownSpecOptions, type BlockParserConfig, type CanCommands, type ChainedCommands, type ChangedRange, type Command, CommandManager, type CommandProps, type CommandSpec, type Commands, type Content, type CreateNodeFromContentOptions, type DOMNode, type DOMOutputSpecArray$1 as DOMOutputSpecArray, type DecorationType, type DecorationWithType, type Diff, type Dispatch, type DocumentType, Editor, type EditorEvents, type EditorOptions, type EnableRules, Extendable, type ExtendableConfig, type ExtendedRegExpMatchArray, Extension, type ExtensionAttribute, type ExtensionConfig, type Extensions, type FocusPosition, Fragment, type FullMarkdownHelpers, type GlobalAttributes, type HTMLContent, type InlineMarkdownSpecOptions, InputRule, type InputRuleFinder, type InputRuleMatch, type InsertContentAtOptions, type InsertContentOptions, type JSONContent, type KeyboardShortcutCommand, type KeysWithTypeOf, Mark, type MarkConfig, type MarkRange, type MarkType, MarkView, type MarkViewProps, type MarkViewRenderer, type MarkViewRendererOptions, type MarkViewRendererProps, type MarkdownExtensionSpec, type MarkdownHelpers, type MarkdownLexerConfiguration, type MarkdownParseHelpers, type MarkdownParseResult, type MarkdownRendererHelpers, type MarkdownToken, type MarkdownTokenizer, type MaybeReturnType, type MaybeThisParameterType, Node, type NodeConfig, NodePos, type NodeRange, type NodeType, NodeView, type NodeViewProps, type NodeViewRenderer, type NodeViewRendererOptions, type NodeViewRendererProps, type NodeWithPos, type Overwrite, type ParentConfig, type ParsedBlock, PasteRule, type PasteRuleFinder, type PasteRuleMatch, type PickValue, type Predicate, type Primitive, type Range, type RawCommands, type RemoveThis, type RenderContext, type ResizableNodeDimensions, ResizableNodeView, type ResizableNodeViewDirection, type ResizableNodeViewOptions, ResizableNodeview, type SetContentOptions, type SingleCommands, type Storage, type TextSerializer, type TextType, type TiptapEditorHTMLElement, Tracker, type TrackerResult, type UnionCommands, type UnionToIntersection, type ValuesOf, blur, callOrReturn, canInsertNode, clearContent, clearNodes, combineTransactionSteps, command, index$2 as commands, createAtomBlockMarkdownSpec, createBlockMarkdownSpec, createChainableState, createDocument, h as createElement, createInlineMarkdownSpec, createNodeFromContent, createParagraphNear, createStyleTag, cut, defaultBlockAt, deleteCurrentNode, deleteNode, deleteProps, deleteRange, deleteSelection, elementFromString, enter, escapeForRegEx, exitCode, extendMarkRange, index$1 as extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, first, flattenExtensions, focus, forEach, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAtPosition, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, h, injectExtensionAttributesToParseRule, inputRulesPlugin, insertContent, insertContentAt, isActive, isAndroid, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, joinBackward, joinDown, joinForward, joinItemBackward, joinItemForward, joinTextblockBackward, joinTextblockForward, joinUp, keyboardShortcut, lift, liftEmptyBlock, liftListItem, markInputRule, markPasteRule, index as markdown, mergeAttributes, mergeDeep, minMax, newlineInCode, nodeInputRule, nodePasteRule, objectIncludes, parseAttributes, parseIndentedBlocks, pasteRulesPlugin, posToDOMRect, removeDuplicates, renderNestedMarkdownContent, resetAttributes, resolveExtensions, resolveFocusPosition, rewriteUnknownContent, scrollIntoView, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, selectTextblockEnd, selectTextblockStart, selectionToInsertionEnd, serializeAttributes, setContent, setMark, setMeta, setNode, setNodeSelection, setTextDirection, setTextSelection, sinkListItem, sortExtensions, splitBlock, splitExtensions, splitListItem, textInputRule, textPasteRule, textblockTypeInputRule, toggleList, toggleMark, toggleNode, toggleWrap, undoInputRule, unsetAllMarks, unsetMark, unsetTextDirection, updateAttributes, updateMarkViewAttributes, wrapIn, wrapInList, wrappingInputRule };
|
|
4717
|
+
export { type AnyCommands, type AnyConfig, type AnyExtension, type AtomBlockMarkdownSpecOptions, type Attribute, type Attributes$1 as Attributes, type BlockMarkdownSpecOptions, type BlockParserConfig, type CanCommands, type ChainedCommands, type ChangedRange, type Command, CommandManager, type CommandProps, type CommandSpec, type Commands, type Content, type CreateNodeFromContentOptions, type DOMNode, type DOMOutputSpecArray$1 as DOMOutputSpecArray, type DecorationType, type DecorationWithType, type Diff, type Dispatch, type DocumentType, Editor, type EditorEvents, type EditorOptions, type EnableRules, Extendable, type ExtendableConfig, type ExtendedRegExpMatchArray, Extension, type ExtensionAttribute, type ExtensionConfig, type Extensions, type FocusPosition, Fragment, type FullMarkdownHelpers, type GetUpdatedPositionResult, type GlobalAttributes, type HTMLContent, type InlineMarkdownSpecOptions, InputRule, type InputRuleFinder, type InputRuleMatch, type InsertContentAtOptions, type InsertContentOptions, type JSONContent, type KeyboardShortcutCommand, type KeysWithTypeOf, MappablePosition, Mark, type MarkConfig, type MarkRange, type MarkType, MarkView, type MarkViewProps, type MarkViewRenderer, type MarkViewRendererOptions, type MarkViewRendererProps, type MarkdownExtensionSpec, type MarkdownHelpers, type MarkdownLexerConfiguration, type MarkdownParseHelpers, type MarkdownParseResult, type MarkdownRendererHelpers, type MarkdownToken, type MarkdownTokenizer, type MaybeReturnType, type MaybeThisParameterType, Node, type NodeConfig, NodePos, type NodeRange, type NodeType, NodeView, type NodeViewProps, type NodeViewRenderer, type NodeViewRendererOptions, type NodeViewRendererProps, type NodeWithPos, type Overwrite, type ParentConfig, type ParsedBlock, PasteRule, type PasteRuleFinder, type PasteRuleMatch, type PickValue, type Predicate, type Primitive, type Range, type RawCommands, type RemoveThis, type RenderContext, type ResizableNodeDimensions, ResizableNodeView, type ResizableNodeViewDirection, type ResizableNodeViewOptions, ResizableNodeview, type SetContentOptions, type SingleCommands, type Storage, type TextSerializer, type TextType, type TiptapEditorHTMLElement, Tracker, type TrackerResult, type UnionCommands, type UnionToIntersection, type Utils, type ValuesOf, blur, callOrReturn, canInsertNode, clearContent, clearNodes, combineTransactionSteps, command, index$2 as commands, createAtomBlockMarkdownSpec, createBlockMarkdownSpec, createChainableState, createDocument, h as createElement, createInlineMarkdownSpec, createMappablePosition, createNodeFromContent, createParagraphNear, createStyleTag, cut, defaultBlockAt, deleteCurrentNode, deleteNode, deleteProps, deleteRange, deleteSelection, elementFromString, enter, escapeForRegEx, exitCode, extendMarkRange, index$1 as extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, first, flattenExtensions, focus, forEach, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAtPosition, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, getUpdatedPosition, h, injectExtensionAttributesToParseRule, inputRulesPlugin, insertContent, insertContentAt, isActive, isAndroid, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, joinBackward, joinDown, joinForward, joinItemBackward, joinItemForward, joinTextblockBackward, joinTextblockForward, joinUp, keyboardShortcut, lift, liftEmptyBlock, liftListItem, markInputRule, markPasteRule, index as markdown, mergeAttributes, mergeDeep, minMax, newlineInCode, nodeInputRule, nodePasteRule, objectIncludes, parseAttributes, parseIndentedBlocks, pasteRulesPlugin, posToDOMRect, removeDuplicates, renderNestedMarkdownContent, resetAttributes, resolveExtensions, resolveFocusPosition, rewriteUnknownContent, scrollIntoView, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, selectTextblockEnd, selectTextblockStart, selectionToInsertionEnd, serializeAttributes, setContent, setMark, setMeta, setNode, setNodeSelection, setTextDirection, setTextSelection, sinkListItem, sortExtensions, splitBlock, splitExtensions, splitListItem, textInputRule, textPasteRule, textblockTypeInputRule, toggleList, toggleMark, toggleNode, toggleWrap, undoInputRule, unsetAllMarks, unsetMark, unsetTextDirection, updateAttributes, updateMarkViewAttributes, wrapIn, wrapInList, wrappingInputRule };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Transaction, EditorState, Plugin, Selection, NodeSelection, TextSelection, PluginKey } from '@tiptap/pm/state';
|
|
2
2
|
import { Node as Node$1, MarkType as MarkType$1, MarkSpec, Mark as Mark$1, DOMOutputSpec, NodeType as NodeType$1, NodeSpec, Slice, ParseOptions, Fragment as Fragment$1, Schema, ContentMatch, ResolvedPos, ParseRule } from '@tiptap/pm/model';
|
|
3
3
|
import { EditorProps, EditorView, Decoration, DecorationAttrs, ViewMutationRecord, NodeViewConstructor, NodeView as NodeView$1, MarkViewConstructor, MarkView as MarkView$1, DecorationSource } from '@tiptap/pm/view';
|
|
4
|
-
import { Transform, Mappable } from '@tiptap/pm/transform';
|
|
4
|
+
import { Transform, Mappable, MapResult } from '@tiptap/pm/transform';
|
|
5
5
|
|
|
6
6
|
type StringKeyOf<T> = Extract<keyof T, string>;
|
|
7
7
|
type CallbackType<T extends Record<string, any>, EventName extends StringKeyOf<T>> = T[EventName] extends any[] ? T[EventName] : [T[EventName]];
|
|
@@ -195,7 +195,7 @@ declare class Mark<Options = any, Storage = any> extends Extendable<Options, Sto
|
|
|
195
195
|
mark: Mark;
|
|
196
196
|
}): boolean;
|
|
197
197
|
configure(options?: Partial<Options>): Mark<Options, Storage>;
|
|
198
|
-
extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = MarkConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: (() => Partial<ExtendedConfig>) | (Partial<ExtendedConfig> & ThisType<{
|
|
198
|
+
extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig extends MarkConfig<ExtendedOptions, ExtendedStorage> = MarkConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: (() => Partial<ExtendedConfig>) | (Partial<ExtendedConfig> & ThisType<{
|
|
199
199
|
name: string;
|
|
200
200
|
options: ExtendedOptions;
|
|
201
201
|
storage: ExtendedStorage;
|
|
@@ -488,7 +488,7 @@ declare class Node<Options = any, Storage = any> extends Extendable<Options, Sto
|
|
|
488
488
|
*/
|
|
489
489
|
static create<O = any, S = any>(config?: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>)): Node<O, S>;
|
|
490
490
|
configure(options?: Partial<Options>): Node<Options, Storage>;
|
|
491
|
-
extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = NodeConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: (() => Partial<ExtendedConfig>) | (Partial<ExtendedConfig> & ThisType<{
|
|
491
|
+
extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig extends NodeConfig<ExtendedOptions, ExtendedStorage> = NodeConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: (() => Partial<ExtendedConfig>) | (Partial<ExtendedConfig> & ThisType<{
|
|
492
492
|
name: string;
|
|
493
493
|
options: ExtendedOptions;
|
|
494
494
|
storage: ExtendedStorage;
|
|
@@ -1761,6 +1761,31 @@ type MarkdownRendererHelpers = {
|
|
|
1761
1761
|
*/
|
|
1762
1762
|
indent: (content: string) => string;
|
|
1763
1763
|
};
|
|
1764
|
+
type Utils = {
|
|
1765
|
+
/**
|
|
1766
|
+
* Returns the new position after applying a transaction.
|
|
1767
|
+
*
|
|
1768
|
+
* @param position The position to update. A MappablePosition instance.
|
|
1769
|
+
* @param transaction The transaction to apply.
|
|
1770
|
+
* @returns The new position after applying the transaction.
|
|
1771
|
+
*
|
|
1772
|
+
* @example
|
|
1773
|
+
* const position = editor.utils.createMappablePosition(10)
|
|
1774
|
+
* const {position, mapResult} = editor.utils.getUpdatedPosition(position, transaction)
|
|
1775
|
+
*/
|
|
1776
|
+
getUpdatedPosition: (position: MappablePosition, transaction: Transaction) => GetUpdatedPositionResult;
|
|
1777
|
+
/**
|
|
1778
|
+
* Creates a MappablePosition from a position number. A mappable position can be used to track the
|
|
1779
|
+
* next position after applying a transaction.
|
|
1780
|
+
*
|
|
1781
|
+
* @param position The position (as a number) where the MappablePosition will be created.
|
|
1782
|
+
* @returns A new MappablePosition instance at the given position.
|
|
1783
|
+
*
|
|
1784
|
+
* @example
|
|
1785
|
+
* const position = editor.utils.createMappablePosition(10)
|
|
1786
|
+
*/
|
|
1787
|
+
createMappablePosition: (position: number) => MappablePosition;
|
|
1788
|
+
};
|
|
1764
1789
|
|
|
1765
1790
|
/**
|
|
1766
1791
|
* Create a new Prosemirror document node from content.
|
|
@@ -2093,6 +2118,48 @@ declare function isNodeSelection(value: unknown): value is NodeSelection;
|
|
|
2093
2118
|
|
|
2094
2119
|
declare function isTextSelection(value: unknown): value is TextSelection;
|
|
2095
2120
|
|
|
2121
|
+
/**
|
|
2122
|
+
* A class that represents a mappable position in the editor. It can be extended
|
|
2123
|
+
* by other extensions to add additional position mapping capabilities.
|
|
2124
|
+
*/
|
|
2125
|
+
declare class MappablePosition {
|
|
2126
|
+
/**
|
|
2127
|
+
* The absolute position in the editor.
|
|
2128
|
+
*/
|
|
2129
|
+
position: number;
|
|
2130
|
+
constructor(position: number);
|
|
2131
|
+
/**
|
|
2132
|
+
* Creates a MappablePosition from a JSON object.
|
|
2133
|
+
*/
|
|
2134
|
+
static fromJSON(json: any): MappablePosition;
|
|
2135
|
+
/**
|
|
2136
|
+
* Converts the MappablePosition to a JSON object.
|
|
2137
|
+
*/
|
|
2138
|
+
toJSON(): any;
|
|
2139
|
+
}
|
|
2140
|
+
/**
|
|
2141
|
+
* The result of the getUpdatedPosition function.
|
|
2142
|
+
*/
|
|
2143
|
+
interface GetUpdatedPositionResult {
|
|
2144
|
+
position: MappablePosition;
|
|
2145
|
+
mapResult: MapResult | null;
|
|
2146
|
+
}
|
|
2147
|
+
/**
|
|
2148
|
+
* Calculates the new position after applying a transaction.
|
|
2149
|
+
*
|
|
2150
|
+
* @returns The new mappable position and the map result.
|
|
2151
|
+
*/
|
|
2152
|
+
declare function getUpdatedPosition(position: MappablePosition, transaction: Transaction): GetUpdatedPositionResult;
|
|
2153
|
+
/**
|
|
2154
|
+
* Creates a MappablePosition from a position number. This is the default
|
|
2155
|
+
* implementation for Tiptap core. It can be overridden by other Tiptap
|
|
2156
|
+
* extensions.
|
|
2157
|
+
*
|
|
2158
|
+
* @param position The position (as a number) where the MappablePosition will be created.
|
|
2159
|
+
* @returns A new MappablePosition instance at the given position.
|
|
2160
|
+
*/
|
|
2161
|
+
declare function createMappablePosition(position: number): MappablePosition;
|
|
2162
|
+
|
|
2096
2163
|
declare function posToDOMRect(view: EditorView, from: number, to: number): DOMRect;
|
|
2097
2164
|
|
|
2098
2165
|
/**
|
|
@@ -3513,6 +3580,10 @@ declare class Editor extends EventEmitter<EditorEvents> {
|
|
|
3513
3580
|
}): NodePos[] | null;
|
|
3514
3581
|
$pos(pos: number): NodePos;
|
|
3515
3582
|
get $doc(): NodePos;
|
|
3583
|
+
/**
|
|
3584
|
+
* Returns a set of utilities for working with positions and ranges.
|
|
3585
|
+
*/
|
|
3586
|
+
utils: Utils;
|
|
3516
3587
|
}
|
|
3517
3588
|
|
|
3518
3589
|
declare class CommandManager {
|
|
@@ -4643,4 +4714,4 @@ interface Commands<ReturnType = any> {
|
|
|
4643
4714
|
interface Storage {
|
|
4644
4715
|
}
|
|
4645
4716
|
|
|
4646
|
-
export { type AnyCommands, type AnyConfig, type AnyExtension, type AtomBlockMarkdownSpecOptions, type Attribute, type Attributes$1 as Attributes, type BlockMarkdownSpecOptions, type BlockParserConfig, type CanCommands, type ChainedCommands, type ChangedRange, type Command, CommandManager, type CommandProps, type CommandSpec, type Commands, type Content, type CreateNodeFromContentOptions, type DOMNode, type DOMOutputSpecArray$1 as DOMOutputSpecArray, type DecorationType, type DecorationWithType, type Diff, type Dispatch, type DocumentType, Editor, type EditorEvents, type EditorOptions, type EnableRules, Extendable, type ExtendableConfig, type ExtendedRegExpMatchArray, Extension, type ExtensionAttribute, type ExtensionConfig, type Extensions, type FocusPosition, Fragment, type FullMarkdownHelpers, type GlobalAttributes, type HTMLContent, type InlineMarkdownSpecOptions, InputRule, type InputRuleFinder, type InputRuleMatch, type InsertContentAtOptions, type InsertContentOptions, type JSONContent, type KeyboardShortcutCommand, type KeysWithTypeOf, Mark, type MarkConfig, type MarkRange, type MarkType, MarkView, type MarkViewProps, type MarkViewRenderer, type MarkViewRendererOptions, type MarkViewRendererProps, type MarkdownExtensionSpec, type MarkdownHelpers, type MarkdownLexerConfiguration, type MarkdownParseHelpers, type MarkdownParseResult, type MarkdownRendererHelpers, type MarkdownToken, type MarkdownTokenizer, type MaybeReturnType, type MaybeThisParameterType, Node, type NodeConfig, NodePos, type NodeRange, type NodeType, NodeView, type NodeViewProps, type NodeViewRenderer, type NodeViewRendererOptions, type NodeViewRendererProps, type NodeWithPos, type Overwrite, type ParentConfig, type ParsedBlock, PasteRule, type PasteRuleFinder, type PasteRuleMatch, type PickValue, type Predicate, type Primitive, type Range, type RawCommands, type RemoveThis, type RenderContext, type ResizableNodeDimensions, ResizableNodeView, type ResizableNodeViewDirection, type ResizableNodeViewOptions, ResizableNodeview, type SetContentOptions, type SingleCommands, type Storage, type TextSerializer, type TextType, type TiptapEditorHTMLElement, Tracker, type TrackerResult, type UnionCommands, type UnionToIntersection, type ValuesOf, blur, callOrReturn, canInsertNode, clearContent, clearNodes, combineTransactionSteps, command, index$2 as commands, createAtomBlockMarkdownSpec, createBlockMarkdownSpec, createChainableState, createDocument, h as createElement, createInlineMarkdownSpec, createNodeFromContent, createParagraphNear, createStyleTag, cut, defaultBlockAt, deleteCurrentNode, deleteNode, deleteProps, deleteRange, deleteSelection, elementFromString, enter, escapeForRegEx, exitCode, extendMarkRange, index$1 as extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, first, flattenExtensions, focus, forEach, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAtPosition, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, h, injectExtensionAttributesToParseRule, inputRulesPlugin, insertContent, insertContentAt, isActive, isAndroid, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, joinBackward, joinDown, joinForward, joinItemBackward, joinItemForward, joinTextblockBackward, joinTextblockForward, joinUp, keyboardShortcut, lift, liftEmptyBlock, liftListItem, markInputRule, markPasteRule, index as markdown, mergeAttributes, mergeDeep, minMax, newlineInCode, nodeInputRule, nodePasteRule, objectIncludes, parseAttributes, parseIndentedBlocks, pasteRulesPlugin, posToDOMRect, removeDuplicates, renderNestedMarkdownContent, resetAttributes, resolveExtensions, resolveFocusPosition, rewriteUnknownContent, scrollIntoView, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, selectTextblockEnd, selectTextblockStart, selectionToInsertionEnd, serializeAttributes, setContent, setMark, setMeta, setNode, setNodeSelection, setTextDirection, setTextSelection, sinkListItem, sortExtensions, splitBlock, splitExtensions, splitListItem, textInputRule, textPasteRule, textblockTypeInputRule, toggleList, toggleMark, toggleNode, toggleWrap, undoInputRule, unsetAllMarks, unsetMark, unsetTextDirection, updateAttributes, updateMarkViewAttributes, wrapIn, wrapInList, wrappingInputRule };
|
|
4717
|
+
export { type AnyCommands, type AnyConfig, type AnyExtension, type AtomBlockMarkdownSpecOptions, type Attribute, type Attributes$1 as Attributes, type BlockMarkdownSpecOptions, type BlockParserConfig, type CanCommands, type ChainedCommands, type ChangedRange, type Command, CommandManager, type CommandProps, type CommandSpec, type Commands, type Content, type CreateNodeFromContentOptions, type DOMNode, type DOMOutputSpecArray$1 as DOMOutputSpecArray, type DecorationType, type DecorationWithType, type Diff, type Dispatch, type DocumentType, Editor, type EditorEvents, type EditorOptions, type EnableRules, Extendable, type ExtendableConfig, type ExtendedRegExpMatchArray, Extension, type ExtensionAttribute, type ExtensionConfig, type Extensions, type FocusPosition, Fragment, type FullMarkdownHelpers, type GetUpdatedPositionResult, type GlobalAttributes, type HTMLContent, type InlineMarkdownSpecOptions, InputRule, type InputRuleFinder, type InputRuleMatch, type InsertContentAtOptions, type InsertContentOptions, type JSONContent, type KeyboardShortcutCommand, type KeysWithTypeOf, MappablePosition, Mark, type MarkConfig, type MarkRange, type MarkType, MarkView, type MarkViewProps, type MarkViewRenderer, type MarkViewRendererOptions, type MarkViewRendererProps, type MarkdownExtensionSpec, type MarkdownHelpers, type MarkdownLexerConfiguration, type MarkdownParseHelpers, type MarkdownParseResult, type MarkdownRendererHelpers, type MarkdownToken, type MarkdownTokenizer, type MaybeReturnType, type MaybeThisParameterType, Node, type NodeConfig, NodePos, type NodeRange, type NodeType, NodeView, type NodeViewProps, type NodeViewRenderer, type NodeViewRendererOptions, type NodeViewRendererProps, type NodeWithPos, type Overwrite, type ParentConfig, type ParsedBlock, PasteRule, type PasteRuleFinder, type PasteRuleMatch, type PickValue, type Predicate, type Primitive, type Range, type RawCommands, type RemoveThis, type RenderContext, type ResizableNodeDimensions, ResizableNodeView, type ResizableNodeViewDirection, type ResizableNodeViewOptions, ResizableNodeview, type SetContentOptions, type SingleCommands, type Storage, type TextSerializer, type TextType, type TiptapEditorHTMLElement, Tracker, type TrackerResult, type UnionCommands, type UnionToIntersection, type Utils, type ValuesOf, blur, callOrReturn, canInsertNode, clearContent, clearNodes, combineTransactionSteps, command, index$2 as commands, createAtomBlockMarkdownSpec, createBlockMarkdownSpec, createChainableState, createDocument, h as createElement, createInlineMarkdownSpec, createMappablePosition, createNodeFromContent, createParagraphNear, createStyleTag, cut, defaultBlockAt, deleteCurrentNode, deleteNode, deleteProps, deleteRange, deleteSelection, elementFromString, enter, escapeForRegEx, exitCode, extendMarkRange, index$1 as extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, first, flattenExtensions, focus, forEach, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAtPosition, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, getUpdatedPosition, h, injectExtensionAttributesToParseRule, inputRulesPlugin, insertContent, insertContentAt, isActive, isAndroid, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, joinBackward, joinDown, joinForward, joinItemBackward, joinItemForward, joinTextblockBackward, joinTextblockForward, joinUp, keyboardShortcut, lift, liftEmptyBlock, liftListItem, markInputRule, markPasteRule, index as markdown, mergeAttributes, mergeDeep, minMax, newlineInCode, nodeInputRule, nodePasteRule, objectIncludes, parseAttributes, parseIndentedBlocks, pasteRulesPlugin, posToDOMRect, removeDuplicates, renderNestedMarkdownContent, resetAttributes, resolveExtensions, resolveFocusPosition, rewriteUnknownContent, scrollIntoView, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, selectTextblockEnd, selectTextblockStart, selectionToInsertionEnd, serializeAttributes, setContent, setMark, setMeta, setNode, setNodeSelection, setTextDirection, setTextSelection, sinkListItem, sortExtensions, splitBlock, splitExtensions, splitListItem, textInputRule, textPasteRule, textblockTypeInputRule, toggleList, toggleMark, toggleNode, toggleWrap, undoInputRule, unsetAllMarks, unsetMark, unsetTextDirection, updateAttributes, updateMarkViewAttributes, wrapIn, wrapInList, wrappingInputRule };
|
package/dist/index.js
CHANGED
|
@@ -2123,6 +2123,37 @@ function isNodeSelection(value) {
|
|
|
2123
2123
|
return value instanceof NodeSelection;
|
|
2124
2124
|
}
|
|
2125
2125
|
|
|
2126
|
+
// src/helpers/MappablePosition.ts
|
|
2127
|
+
var MappablePosition = class _MappablePosition {
|
|
2128
|
+
constructor(position) {
|
|
2129
|
+
this.position = position;
|
|
2130
|
+
}
|
|
2131
|
+
/**
|
|
2132
|
+
* Creates a MappablePosition from a JSON object.
|
|
2133
|
+
*/
|
|
2134
|
+
static fromJSON(json) {
|
|
2135
|
+
return new _MappablePosition(json.position);
|
|
2136
|
+
}
|
|
2137
|
+
/**
|
|
2138
|
+
* Converts the MappablePosition to a JSON object.
|
|
2139
|
+
*/
|
|
2140
|
+
toJSON() {
|
|
2141
|
+
return {
|
|
2142
|
+
position: this.position
|
|
2143
|
+
};
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
function getUpdatedPosition(position, transaction) {
|
|
2147
|
+
const mapResult = transaction.mapping.mapResult(position.position);
|
|
2148
|
+
return {
|
|
2149
|
+
position: new MappablePosition(mapResult.pos),
|
|
2150
|
+
mapResult
|
|
2151
|
+
};
|
|
2152
|
+
}
|
|
2153
|
+
function createMappablePosition(position) {
|
|
2154
|
+
return new MappablePosition(position);
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2126
2157
|
// src/helpers/posToDOMRect.ts
|
|
2127
2158
|
function posToDOMRect(view, from, to) {
|
|
2128
2159
|
const minPos = 0;
|
|
@@ -4475,6 +4506,13 @@ var Editor = class extends EventEmitter {
|
|
|
4475
4506
|
};
|
|
4476
4507
|
this.isCapturingTransaction = false;
|
|
4477
4508
|
this.capturedTransaction = null;
|
|
4509
|
+
/**
|
|
4510
|
+
* Returns a set of utilities for working with positions and ranges.
|
|
4511
|
+
*/
|
|
4512
|
+
this.utils = {
|
|
4513
|
+
getUpdatedPosition,
|
|
4514
|
+
createMappablePosition
|
|
4515
|
+
};
|
|
4478
4516
|
this.setOptions(options);
|
|
4479
4517
|
this.createExtensionManager();
|
|
4480
4518
|
this.createCommandManager();
|
|
@@ -6627,6 +6665,7 @@ export {
|
|
|
6627
6665
|
Extension,
|
|
6628
6666
|
Fragment6 as Fragment,
|
|
6629
6667
|
InputRule,
|
|
6668
|
+
MappablePosition,
|
|
6630
6669
|
Mark,
|
|
6631
6670
|
MarkView,
|
|
6632
6671
|
Node3 as Node,
|
|
@@ -6646,6 +6685,7 @@ export {
|
|
|
6646
6685
|
createDocument,
|
|
6647
6686
|
h as createElement,
|
|
6648
6687
|
createInlineMarkdownSpec,
|
|
6688
|
+
createMappablePosition,
|
|
6649
6689
|
createNodeFromContent,
|
|
6650
6690
|
createStyleTag,
|
|
6651
6691
|
defaultBlockAt,
|
|
@@ -6686,6 +6726,7 @@ export {
|
|
|
6686
6726
|
getTextBetween,
|
|
6687
6727
|
getTextContentFromNodes,
|
|
6688
6728
|
getTextSerializersFromSchema,
|
|
6729
|
+
getUpdatedPosition,
|
|
6689
6730
|
h,
|
|
6690
6731
|
injectExtensionAttributesToParseRule,
|
|
6691
6732
|
inputRulesPlugin,
|