@tiptap/core 3.0.0-next.8 → 3.0.1

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.d.cts CHANGED
@@ -183,13 +183,17 @@ interface MarkConfig<Options = any, Storage = any> extends ExtendableConfig<Opti
183
183
  */
184
184
  declare class Mark<Options = any, Storage = any> extends Extendable<Options, Storage, MarkConfig<Options, Storage>> {
185
185
  type: string;
186
- static create<O = any, S = any>(config?: Partial<MarkConfig<O, S>>): Mark<O, S>;
186
+ /**
187
+ * Create a new Mark instance
188
+ * @param config - Mark configuration object or a function that returns a configuration object
189
+ */
190
+ static create<O = any, S = any>(config?: Partial<MarkConfig<O, S>> | (() => Partial<MarkConfig<O, S>>)): Mark<O, S>;
187
191
  static handleExit({ editor, mark }: {
188
192
  editor: Editor;
189
193
  mark: Mark;
190
194
  }): boolean;
191
195
  configure(options?: Partial<Options>): Mark<Options, Storage>;
192
- extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = MarkConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig>): Mark<ExtendedOptions, ExtendedStorage>;
196
+ extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = MarkConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)): Mark<ExtendedOptions, ExtendedStorage>;
193
197
  }
194
198
 
195
199
  interface NodeConfig<Options = any, Storage = any> extends ExtendableConfig<Options, Storage, NodeConfig<Options, Storage>, NodeType$1> {
@@ -470,9 +474,13 @@ interface NodeConfig<Options = any, Storage = any> extends ExtendableConfig<Opti
470
474
  */
471
475
  declare class Node<Options = any, Storage = any> extends Extendable<Options, Storage, NodeConfig<Options, Storage>> {
472
476
  type: string;
473
- static create<O = any, S = any>(config?: Partial<NodeConfig<O, S>>): Node<O, S>;
477
+ /**
478
+ * Create a new Node instance
479
+ * @param config - Node configuration object or a function that returns a configuration object
480
+ */
481
+ static create<O = any, S = any>(config?: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>)): Node<O, S>;
474
482
  configure(options?: Partial<Options>): Node<Options, Storage>;
475
- extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = NodeConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig>): Node<ExtendedOptions, ExtendedStorage>;
483
+ extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = NodeConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)): Node<ExtendedOptions, ExtendedStorage>;
476
484
  }
477
485
 
478
486
  type PasteRuleMatch = {
@@ -1155,6 +1163,15 @@ interface EditorOptions {
1155
1163
  * @default false
1156
1164
  */
1157
1165
  enableContentCheck: boolean;
1166
+ /**
1167
+ * If `true`, the editor will emit the `contentError` event if invalid content is
1168
+ * encountered but `enableContentCheck` is `false`. This lets you preserve the
1169
+ * invalid editor content while still showing a warning or error message to
1170
+ * the user.
1171
+ *
1172
+ * @default false
1173
+ */
1174
+ emitContentError: boolean;
1158
1175
  /**
1159
1176
  * Called before the editor is constructed.
1160
1177
  */
@@ -1419,8 +1436,9 @@ interface MarkViewRendererProps {
1419
1436
  * The HTML attributes that should be added to the mark's DOM element.
1420
1437
  */
1421
1438
  HTMLAttributes: Record<string, any>;
1439
+ updateAttributes: (attrs: Record<string, any>) => void;
1422
1440
  }
1423
- type MarkViewRenderer = (props: MarkViewRendererProps) => MarkView$1;
1441
+ type MarkViewRenderer<Props = MarkViewRendererProps> = (props: Props) => MarkView$1;
1424
1442
  interface MarkViewRendererOptions {
1425
1443
  ignoreMutation: ((props: {
1426
1444
  mutation: ViewMutationRecord;
@@ -1622,9 +1640,13 @@ interface ExtensionConfig<Options = any, Storage = any> extends ExtendableConfig
1622
1640
  */
1623
1641
  declare class Extension<Options = any, Storage = any> extends Extendable<Options, Storage, ExtensionConfig<Options, Storage>> {
1624
1642
  type: string;
1625
- static create<O = any, S = any>(config?: Partial<ExtensionConfig<O, S>>): Extension<O, S>;
1643
+ /**
1644
+ * Create a new Extension instance
1645
+ * @param config - Extension configuration object or a function that returns a configuration object
1646
+ */
1647
+ static create<O = any, S = any>(config?: Partial<ExtensionConfig<O, S>> | (() => Partial<ExtensionConfig<O, S>>)): Extension<O, S>;
1626
1648
  configure(options?: Partial<Options>): Extension<Options, Storage>;
1627
- extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = ExtensionConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig>): Extension<ExtendedOptions, ExtendedStorage>;
1649
+ extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = ExtensionConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)): Extension<ExtendedOptions, ExtendedStorage>;
1628
1650
  }
1629
1651
 
1630
1652
  /**
@@ -3153,6 +3175,7 @@ declare function Fragment(props: {
3153
3175
  }): JSXRenderer[];
3154
3176
  declare const h: JSXRenderer;
3155
3177
 
3178
+ declare function updateMarkViewAttributes(checkMark: Mark$1, editor: Editor, attrs?: Record<string, any>): void;
3156
3179
  declare class MarkView<Component, Options extends MarkViewRendererOptions = MarkViewRendererOptions> {
3157
3180
  component: Component;
3158
3181
  editor: Editor;
@@ -3162,6 +3185,11 @@ declare class MarkView<Component, Options extends MarkViewRendererOptions = Mark
3162
3185
  constructor(component: Component, props: MarkViewProps, options?: Partial<Options>);
3163
3186
  get dom(): HTMLElement;
3164
3187
  get contentDOM(): HTMLElement | null;
3188
+ /**
3189
+ * Update the attributes of the mark in the document.
3190
+ * @param attrs The attributes to update.
3191
+ */
3192
+ updateAttributes(attrs: Record<string, any>, checkMark?: Mark$1): void;
3165
3193
  ignoreMutation(mutation: ViewMutationRecord): boolean;
3166
3194
  }
3167
3195
 
@@ -3256,6 +3284,8 @@ declare class Tracker {
3256
3284
  */
3257
3285
  declare function callOrReturn<T>(value: T, context?: any, ...props: any[]): MaybeReturnType<T>;
3258
3286
 
3287
+ declare function canInsertNode(state: EditorState, nodeType: NodeType$1): boolean;
3288
+
3259
3289
  declare function createStyleTag(style: string, nonce?: string, suffix?: string): HTMLStyleElement;
3260
3290
 
3261
3291
  /**
@@ -3323,4 +3353,4 @@ interface Commands<ReturnType = any> {
3323
3353
  interface Storage {
3324
3354
  }
3325
3355
 
3326
- export { type AnyCommands, type AnyConfig, type AnyExtension, type Attribute, type Attributes$1 as Attributes, 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, type ExtendedRegExpMatchArray, Extension, type ExtensionAttribute, type ExtensionConfig, type Extensions, type FocusPosition, Fragment, type GlobalAttributes, type HTMLContent, InputRule, type InputRuleFinder, type InputRuleMatch, type JSONContent, type KeyboardShortcutCommand, type KeysWithTypeOf, Mark, type MarkConfig, type MarkRange, type MarkType, MarkView, type MarkViewProps, type MarkViewRenderer, type MarkViewRendererOptions, type MarkViewRendererProps, 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, PasteRule, type PasteRuleFinder, type PasteRuleMatch, type PickValue, type Predicate, type Primitive, type Range, type RawCommands, type RemoveThis, type SingleCommands, type Storage, type TextSerializer, type TextType, type TiptapEditorHTMLElement, Tracker, type TrackerResult, type UnionCommands, type UnionToIntersection, type ValuesOf, callOrReturn, combineTransactionSteps, createChainableState, createDocument, h as createElement, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, index as extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, flattenExtensions, 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, isActive, isAndroid, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, markInputRule, markPasteRule, mergeAttributes, mergeDeep, minMax, nodeInputRule, nodePasteRule, objectIncludes, pasteRulesPlugin, posToDOMRect, removeDuplicates, resolveExtensions, resolveFocusPosition, rewriteUnknownContent, selectionToInsertionEnd, sortExtensions, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
3356
+ export { type AnyCommands, type AnyConfig, type AnyExtension, type Attribute, type Attributes$1 as Attributes, 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, type ExtendedRegExpMatchArray, Extension, type ExtensionAttribute, type ExtensionConfig, type Extensions, type FocusPosition, Fragment, type GlobalAttributes, type HTMLContent, InputRule, type InputRuleFinder, type InputRuleMatch, type JSONContent, type KeyboardShortcutCommand, type KeysWithTypeOf, Mark, type MarkConfig, type MarkRange, type MarkType, MarkView, type MarkViewProps, type MarkViewRenderer, type MarkViewRendererOptions, type MarkViewRendererProps, 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, PasteRule, type PasteRuleFinder, type PasteRuleMatch, type PickValue, type Predicate, type Primitive, type Range, type RawCommands, type RemoveThis, type SingleCommands, type Storage, type TextSerializer, type TextType, type TiptapEditorHTMLElement, Tracker, type TrackerResult, type UnionCommands, type UnionToIntersection, type ValuesOf, callOrReturn, canInsertNode, combineTransactionSteps, createChainableState, createDocument, h as createElement, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, index as extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, flattenExtensions, 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, isActive, isAndroid, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, markInputRule, markPasteRule, mergeAttributes, mergeDeep, minMax, nodeInputRule, nodePasteRule, objectIncludes, pasteRulesPlugin, posToDOMRect, removeDuplicates, resolveExtensions, resolveFocusPosition, rewriteUnknownContent, selectionToInsertionEnd, sortExtensions, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, updateMarkViewAttributes, wrappingInputRule };
package/dist/index.d.ts CHANGED
@@ -183,13 +183,17 @@ interface MarkConfig<Options = any, Storage = any> extends ExtendableConfig<Opti
183
183
  */
184
184
  declare class Mark<Options = any, Storage = any> extends Extendable<Options, Storage, MarkConfig<Options, Storage>> {
185
185
  type: string;
186
- static create<O = any, S = any>(config?: Partial<MarkConfig<O, S>>): Mark<O, S>;
186
+ /**
187
+ * Create a new Mark instance
188
+ * @param config - Mark configuration object or a function that returns a configuration object
189
+ */
190
+ static create<O = any, S = any>(config?: Partial<MarkConfig<O, S>> | (() => Partial<MarkConfig<O, S>>)): Mark<O, S>;
187
191
  static handleExit({ editor, mark }: {
188
192
  editor: Editor;
189
193
  mark: Mark;
190
194
  }): boolean;
191
195
  configure(options?: Partial<Options>): Mark<Options, Storage>;
192
- extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = MarkConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig>): Mark<ExtendedOptions, ExtendedStorage>;
196
+ extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = MarkConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)): Mark<ExtendedOptions, ExtendedStorage>;
193
197
  }
194
198
 
195
199
  interface NodeConfig<Options = any, Storage = any> extends ExtendableConfig<Options, Storage, NodeConfig<Options, Storage>, NodeType$1> {
@@ -470,9 +474,13 @@ interface NodeConfig<Options = any, Storage = any> extends ExtendableConfig<Opti
470
474
  */
471
475
  declare class Node<Options = any, Storage = any> extends Extendable<Options, Storage, NodeConfig<Options, Storage>> {
472
476
  type: string;
473
- static create<O = any, S = any>(config?: Partial<NodeConfig<O, S>>): Node<O, S>;
477
+ /**
478
+ * Create a new Node instance
479
+ * @param config - Node configuration object or a function that returns a configuration object
480
+ */
481
+ static create<O = any, S = any>(config?: Partial<NodeConfig<O, S>> | (() => Partial<NodeConfig<O, S>>)): Node<O, S>;
474
482
  configure(options?: Partial<Options>): Node<Options, Storage>;
475
- extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = NodeConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig>): Node<ExtendedOptions, ExtendedStorage>;
483
+ extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = NodeConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)): Node<ExtendedOptions, ExtendedStorage>;
476
484
  }
477
485
 
478
486
  type PasteRuleMatch = {
@@ -1155,6 +1163,15 @@ interface EditorOptions {
1155
1163
  * @default false
1156
1164
  */
1157
1165
  enableContentCheck: boolean;
1166
+ /**
1167
+ * If `true`, the editor will emit the `contentError` event if invalid content is
1168
+ * encountered but `enableContentCheck` is `false`. This lets you preserve the
1169
+ * invalid editor content while still showing a warning or error message to
1170
+ * the user.
1171
+ *
1172
+ * @default false
1173
+ */
1174
+ emitContentError: boolean;
1158
1175
  /**
1159
1176
  * Called before the editor is constructed.
1160
1177
  */
@@ -1419,8 +1436,9 @@ interface MarkViewRendererProps {
1419
1436
  * The HTML attributes that should be added to the mark's DOM element.
1420
1437
  */
1421
1438
  HTMLAttributes: Record<string, any>;
1439
+ updateAttributes: (attrs: Record<string, any>) => void;
1422
1440
  }
1423
- type MarkViewRenderer = (props: MarkViewRendererProps) => MarkView$1;
1441
+ type MarkViewRenderer<Props = MarkViewRendererProps> = (props: Props) => MarkView$1;
1424
1442
  interface MarkViewRendererOptions {
1425
1443
  ignoreMutation: ((props: {
1426
1444
  mutation: ViewMutationRecord;
@@ -1622,9 +1640,13 @@ interface ExtensionConfig<Options = any, Storage = any> extends ExtendableConfig
1622
1640
  */
1623
1641
  declare class Extension<Options = any, Storage = any> extends Extendable<Options, Storage, ExtensionConfig<Options, Storage>> {
1624
1642
  type: string;
1625
- static create<O = any, S = any>(config?: Partial<ExtensionConfig<O, S>>): Extension<O, S>;
1643
+ /**
1644
+ * Create a new Extension instance
1645
+ * @param config - Extension configuration object or a function that returns a configuration object
1646
+ */
1647
+ static create<O = any, S = any>(config?: Partial<ExtensionConfig<O, S>> | (() => Partial<ExtensionConfig<O, S>>)): Extension<O, S>;
1626
1648
  configure(options?: Partial<Options>): Extension<Options, Storage>;
1627
- extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = ExtensionConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig>): Extension<ExtendedOptions, ExtendedStorage>;
1649
+ extend<ExtendedOptions = Options, ExtendedStorage = Storage, ExtendedConfig = ExtensionConfig<ExtendedOptions, ExtendedStorage>>(extendedConfig?: Partial<ExtendedConfig> | (() => Partial<ExtendedConfig>)): Extension<ExtendedOptions, ExtendedStorage>;
1628
1650
  }
1629
1651
 
1630
1652
  /**
@@ -3153,6 +3175,7 @@ declare function Fragment(props: {
3153
3175
  }): JSXRenderer[];
3154
3176
  declare const h: JSXRenderer;
3155
3177
 
3178
+ declare function updateMarkViewAttributes(checkMark: Mark$1, editor: Editor, attrs?: Record<string, any>): void;
3156
3179
  declare class MarkView<Component, Options extends MarkViewRendererOptions = MarkViewRendererOptions> {
3157
3180
  component: Component;
3158
3181
  editor: Editor;
@@ -3162,6 +3185,11 @@ declare class MarkView<Component, Options extends MarkViewRendererOptions = Mark
3162
3185
  constructor(component: Component, props: MarkViewProps, options?: Partial<Options>);
3163
3186
  get dom(): HTMLElement;
3164
3187
  get contentDOM(): HTMLElement | null;
3188
+ /**
3189
+ * Update the attributes of the mark in the document.
3190
+ * @param attrs The attributes to update.
3191
+ */
3192
+ updateAttributes(attrs: Record<string, any>, checkMark?: Mark$1): void;
3165
3193
  ignoreMutation(mutation: ViewMutationRecord): boolean;
3166
3194
  }
3167
3195
 
@@ -3256,6 +3284,8 @@ declare class Tracker {
3256
3284
  */
3257
3285
  declare function callOrReturn<T>(value: T, context?: any, ...props: any[]): MaybeReturnType<T>;
3258
3286
 
3287
+ declare function canInsertNode(state: EditorState, nodeType: NodeType$1): boolean;
3288
+
3259
3289
  declare function createStyleTag(style: string, nonce?: string, suffix?: string): HTMLStyleElement;
3260
3290
 
3261
3291
  /**
@@ -3323,4 +3353,4 @@ interface Commands<ReturnType = any> {
3323
3353
  interface Storage {
3324
3354
  }
3325
3355
 
3326
- export { type AnyCommands, type AnyConfig, type AnyExtension, type Attribute, type Attributes$1 as Attributes, 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, type ExtendedRegExpMatchArray, Extension, type ExtensionAttribute, type ExtensionConfig, type Extensions, type FocusPosition, Fragment, type GlobalAttributes, type HTMLContent, InputRule, type InputRuleFinder, type InputRuleMatch, type JSONContent, type KeyboardShortcutCommand, type KeysWithTypeOf, Mark, type MarkConfig, type MarkRange, type MarkType, MarkView, type MarkViewProps, type MarkViewRenderer, type MarkViewRendererOptions, type MarkViewRendererProps, 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, PasteRule, type PasteRuleFinder, type PasteRuleMatch, type PickValue, type Predicate, type Primitive, type Range, type RawCommands, type RemoveThis, type SingleCommands, type Storage, type TextSerializer, type TextType, type TiptapEditorHTMLElement, Tracker, type TrackerResult, type UnionCommands, type UnionToIntersection, type ValuesOf, callOrReturn, combineTransactionSteps, createChainableState, createDocument, h as createElement, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, index as extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, flattenExtensions, 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, isActive, isAndroid, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, markInputRule, markPasteRule, mergeAttributes, mergeDeep, minMax, nodeInputRule, nodePasteRule, objectIncludes, pasteRulesPlugin, posToDOMRect, removeDuplicates, resolveExtensions, resolveFocusPosition, rewriteUnknownContent, selectionToInsertionEnd, sortExtensions, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
3356
+ export { type AnyCommands, type AnyConfig, type AnyExtension, type Attribute, type Attributes$1 as Attributes, 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, type ExtendedRegExpMatchArray, Extension, type ExtensionAttribute, type ExtensionConfig, type Extensions, type FocusPosition, Fragment, type GlobalAttributes, type HTMLContent, InputRule, type InputRuleFinder, type InputRuleMatch, type JSONContent, type KeyboardShortcutCommand, type KeysWithTypeOf, Mark, type MarkConfig, type MarkRange, type MarkType, MarkView, type MarkViewProps, type MarkViewRenderer, type MarkViewRendererOptions, type MarkViewRendererProps, 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, PasteRule, type PasteRuleFinder, type PasteRuleMatch, type PickValue, type Predicate, type Primitive, type Range, type RawCommands, type RemoveThis, type SingleCommands, type Storage, type TextSerializer, type TextType, type TiptapEditorHTMLElement, Tracker, type TrackerResult, type UnionCommands, type UnionToIntersection, type ValuesOf, callOrReturn, canInsertNode, combineTransactionSteps, createChainableState, createDocument, h as createElement, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, index as extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, flattenExtensions, 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, isActive, isAndroid, isAtEndOfNode, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, markInputRule, markPasteRule, mergeAttributes, mergeDeep, minMax, nodeInputRule, nodePasteRule, objectIncludes, pasteRulesPlugin, posToDOMRect, removeDuplicates, resolveExtensions, resolveFocusPosition, rewriteUnknownContent, selectionToInsertionEnd, sortExtensions, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, updateMarkViewAttributes, wrappingInputRule };
package/dist/index.js CHANGED
@@ -1831,8 +1831,13 @@ var Mark = class _Mark extends Extendable {
1831
1831
  super(...arguments);
1832
1832
  this.type = "mark";
1833
1833
  }
1834
+ /**
1835
+ * Create a new Mark instance
1836
+ * @param config - Mark configuration object or a function that returns a configuration object
1837
+ */
1834
1838
  static create(config = {}) {
1835
- return new _Mark(config);
1839
+ const resolvedConfig = typeof config === "function" ? config() : config;
1840
+ return new _Mark(resolvedConfig);
1836
1841
  }
1837
1842
  static handleExit({ editor, mark }) {
1838
1843
  const { tr } = editor.state;
@@ -1858,7 +1863,8 @@ var Mark = class _Mark extends Extendable {
1858
1863
  return super.configure(options);
1859
1864
  }
1860
1865
  extend(extendedConfig) {
1861
- return super.extend(extendedConfig);
1866
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
1867
+ return super.extend(resolvedConfig);
1862
1868
  }
1863
1869
  };
1864
1870
 
@@ -2026,7 +2032,7 @@ function pasteRulesPlugin(props) {
2026
2032
  dropEvent = event;
2027
2033
  if (!isDroppedFromProseMirror) {
2028
2034
  const dragFromOtherEditor = tiptapDragFromOtherEditor;
2029
- if (dragFromOtherEditor) {
2035
+ if (dragFromOtherEditor == null ? void 0 : dragFromOtherEditor.isEditable) {
2030
2036
  setTimeout(() => {
2031
2037
  const selection = dragFromOtherEditor.state.selection;
2032
2038
  if (selection) {
@@ -2265,7 +2271,10 @@ var ExtensionManager = class {
2265
2271
  // tiptap-specific
2266
2272
  editor,
2267
2273
  extension,
2268
- HTMLAttributes
2274
+ HTMLAttributes,
2275
+ updateAttributes: (attrs) => {
2276
+ updateMarkViewAttributes(mark, editor, attrs);
2277
+ }
2269
2278
  });
2270
2279
  };
2271
2280
  return [extension.name, markView];
@@ -2363,14 +2372,20 @@ var Extension = class _Extension extends Extendable {
2363
2372
  super(...arguments);
2364
2373
  this.type = "extension";
2365
2374
  }
2375
+ /**
2376
+ * Create a new Extension instance
2377
+ * @param config - Extension configuration object or a function that returns a configuration object
2378
+ */
2366
2379
  static create(config = {}) {
2367
- return new _Extension(config);
2380
+ const resolvedConfig = typeof config === "function" ? config() : config;
2381
+ return new _Extension(resolvedConfig);
2368
2382
  }
2369
2383
  configure(options) {
2370
2384
  return super.configure(options);
2371
2385
  }
2372
2386
  extend(extendedConfig) {
2373
- return super.extend(extendedConfig);
2387
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
2388
+ return super.extend(resolvedConfig);
2374
2389
  }
2375
2390
  };
2376
2391
 
@@ -2540,7 +2555,7 @@ var cut = (originRange, targetPos) => ({ editor, tr }) => {
2540
2555
  tr.deleteRange(originRange.from, originRange.to);
2541
2556
  const newPos = tr.mapping.map(targetPos);
2542
2557
  tr.insert(newPos, contentSlice.content);
2543
- tr.setSelection(new TextSelection3(tr.doc.resolve(newPos - 1)));
2558
+ tr.setSelection(new TextSelection3(tr.doc.resolve(Math.max(newPos - 1, 0))));
2544
2559
  return true;
2545
2560
  };
2546
2561
 
@@ -2716,18 +2731,10 @@ var insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) =
2716
2731
  };
2717
2732
  let content;
2718
2733
  const { selection } = editor.state;
2719
- try {
2720
- content = createNodeFromContent(value, editor.schema, {
2721
- parseOptions: {
2722
- preserveWhitespace: "full",
2723
- ...options.parseOptions
2724
- },
2725
- errorOnInvalidContent: (_a = options.errorOnInvalidContent) != null ? _a : editor.options.enableContentCheck
2726
- });
2727
- } catch (e) {
2734
+ const emitContentError = (error) => {
2728
2735
  editor.emit("contentError", {
2729
2736
  editor,
2730
- error: e,
2737
+ error,
2731
2738
  disableCollaboration: () => {
2732
2739
  if ("collaboration" in editor.storage && typeof editor.storage.collaboration === "object" && editor.storage.collaboration) {
2733
2740
  ;
@@ -2735,6 +2742,28 @@ var insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) =
2735
2742
  }
2736
2743
  }
2737
2744
  });
2745
+ };
2746
+ const parseOptions = {
2747
+ preserveWhitespace: "full",
2748
+ ...options.parseOptions
2749
+ };
2750
+ if (!options.errorOnInvalidContent && !editor.options.enableContentCheck && editor.options.emitContentError) {
2751
+ try {
2752
+ createNodeFromContent(value, editor.schema, {
2753
+ parseOptions,
2754
+ errorOnInvalidContent: true
2755
+ });
2756
+ } catch (e) {
2757
+ emitContentError(e);
2758
+ }
2759
+ }
2760
+ try {
2761
+ content = createNodeFromContent(value, editor.schema, {
2762
+ parseOptions,
2763
+ errorOnInvalidContent: (_a = options.errorOnInvalidContent) != null ? _a : editor.options.enableContentCheck
2764
+ });
2765
+ } catch (e) {
2766
+ emitContentError(e);
2738
2767
  return false;
2739
2768
  }
2740
2769
  let { from, to } = typeof position === "number" ? { from: position, to: position } : { from: position.from, to: position.to };
@@ -2776,7 +2805,8 @@ var insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) =
2776
2805
  newContent = content;
2777
2806
  const fromSelectionAtStart = selection.$from.parentOffset === 0;
2778
2807
  const isTextSelection2 = selection.$from.node().isText || selection.$from.node().isTextblock;
2779
- if (fromSelectionAtStart && isTextSelection2) {
2808
+ const hasContent = selection.$from.node().content.size > 0;
2809
+ if (fromSelectionAtStart && isTextSelection2 && hasContent) {
2780
2810
  from = Math.max(0, from - 1);
2781
2811
  }
2782
2812
  tr.replaceWith(from, to, newContent);
@@ -4072,6 +4102,9 @@ var NodePos = class _NodePos {
4072
4102
  const isBlock = node.isBlock && !node.isTextblock;
4073
4103
  const isNonTextAtom = node.isAtom && !node.isText;
4074
4104
  const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1);
4105
+ if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) {
4106
+ return;
4107
+ }
4075
4108
  const $pos = this.resolvedPos.doc.resolve(targetPos);
4076
4109
  if (!isBlock && $pos.depth <= this.depth) {
4077
4110
  return;
@@ -4269,6 +4302,7 @@ var Editor = class extends EventEmitter {
4269
4302
  enablePasteRules: true,
4270
4303
  enableCoreExtensions: true,
4271
4304
  enableContentCheck: false,
4305
+ emitContentError: false,
4272
4306
  onBeforeCreate: () => null,
4273
4307
  onCreate: () => null,
4274
4308
  onUpdate: () => null,
@@ -4434,7 +4468,8 @@ var Editor = class extends EventEmitter {
4434
4468
  // Stub some commonly accessed properties to prevent errors
4435
4469
  composing: false,
4436
4470
  dragging: null,
4437
- editable: true
4471
+ editable: true,
4472
+ isDestroyed: false
4438
4473
  },
4439
4474
  {
4440
4475
  get: (obj, key) => {
@@ -4487,7 +4522,7 @@ var Editor = class extends EventEmitter {
4487
4522
  let plugins = prevPlugins;
4488
4523
  [].concat(nameOrPluginKeyToRemove).forEach((nameOrPluginKey) => {
4489
4524
  const name = typeof nameOrPluginKey === "string" ? `${nameOrPluginKey}$` : nameOrPluginKey.key;
4490
- plugins = prevPlugins.filter((plugin) => !plugin.key.startsWith(name));
4525
+ plugins = plugins.filter((plugin) => !plugin.key.startsWith(name));
4491
4526
  });
4492
4527
  if (prevPlugins.length === plugins.length) {
4493
4528
  return void 0;
@@ -4748,8 +4783,8 @@ var Editor = class extends EventEmitter {
4748
4783
  * Check if the editor is already destroyed.
4749
4784
  */
4750
4785
  get isDestroyed() {
4751
- var _a;
4752
- return !((_a = this.view) == null ? void 0 : _a.docView);
4786
+ var _a, _b;
4787
+ return (_b = (_a = this.editorView) == null ? void 0 : _a.isDestroyed) != null ? _b : true;
4753
4788
  }
4754
4789
  $node(selector, attributes) {
4755
4790
  var _a;
@@ -4927,6 +4962,29 @@ var h = (tag, attributes) => {
4927
4962
  return [tag, rest, children];
4928
4963
  };
4929
4964
 
4965
+ // src/utilities/canInsertNode.ts
4966
+ import { NodeSelection as NodeSelection4 } from "@tiptap/pm/state";
4967
+ function canInsertNode(state, nodeType) {
4968
+ const { selection } = state;
4969
+ const { $from } = selection;
4970
+ if (selection instanceof NodeSelection4) {
4971
+ const index = $from.index();
4972
+ const parent = $from.parent;
4973
+ return parent.canReplaceWith(index, index + 1, nodeType);
4974
+ }
4975
+ let depth = $from.depth;
4976
+ while (depth >= 0) {
4977
+ const index = $from.index(depth);
4978
+ const parent = $from.node(depth);
4979
+ const match = parent.contentMatchAt(index);
4980
+ if (match.matchType(nodeType)) {
4981
+ return true;
4982
+ }
4983
+ depth -= 1;
4984
+ }
4985
+ return false;
4986
+ }
4987
+
4930
4988
  // src/utilities/escapeForRegEx.ts
4931
4989
  function escapeForRegEx(string) {
4932
4990
  return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
@@ -4938,6 +4996,42 @@ function isString(value) {
4938
4996
  }
4939
4997
 
4940
4998
  // src/MarkView.ts
4999
+ function updateMarkViewAttributes(checkMark, editor, attrs = {}) {
5000
+ const { state } = editor;
5001
+ const { doc, tr } = state;
5002
+ const thisMark = checkMark;
5003
+ doc.descendants((node, pos) => {
5004
+ const from = tr.mapping.map(pos);
5005
+ const to = tr.mapping.map(pos) + node.nodeSize;
5006
+ let foundMark = null;
5007
+ node.marks.forEach((mark) => {
5008
+ if (mark !== thisMark) {
5009
+ return false;
5010
+ }
5011
+ foundMark = mark;
5012
+ });
5013
+ if (!foundMark) {
5014
+ return;
5015
+ }
5016
+ let needsUpdate = false;
5017
+ Object.keys(attrs).forEach((k) => {
5018
+ if (attrs[k] !== foundMark.attrs[k]) {
5019
+ needsUpdate = true;
5020
+ }
5021
+ });
5022
+ if (needsUpdate) {
5023
+ const updatedMark = checkMark.type.create({
5024
+ ...checkMark.attrs,
5025
+ ...attrs
5026
+ });
5027
+ tr.removeMark(from, to, checkMark.type);
5028
+ tr.addMark(from, to, updatedMark);
5029
+ }
5030
+ });
5031
+ if (tr.docChanged) {
5032
+ editor.view.dispatch(tr);
5033
+ }
5034
+ }
4941
5035
  var MarkView = class {
4942
5036
  constructor(component, props, options) {
4943
5037
  this.component = component;
@@ -4952,6 +5046,13 @@ var MarkView = class {
4952
5046
  get contentDOM() {
4953
5047
  return null;
4954
5048
  }
5049
+ /**
5050
+ * Update the attributes of the mark in the document.
5051
+ * @param attrs The attributes to update.
5052
+ */
5053
+ updateAttributes(attrs, checkMark) {
5054
+ updateMarkViewAttributes(checkMark || this.mark, this.editor, attrs);
5055
+ }
4955
5056
  ignoreMutation(mutation) {
4956
5057
  if (!this.dom || !this.contentDOM) {
4957
5058
  return true;
@@ -4984,19 +5085,25 @@ var Node3 = class _Node extends Extendable {
4984
5085
  super(...arguments);
4985
5086
  this.type = "node";
4986
5087
  }
5088
+ /**
5089
+ * Create a new Node instance
5090
+ * @param config - Node configuration object or a function that returns a configuration object
5091
+ */
4987
5092
  static create(config = {}) {
4988
- return new _Node(config);
5093
+ const resolvedConfig = typeof config === "function" ? config() : config;
5094
+ return new _Node(resolvedConfig);
4989
5095
  }
4990
5096
  configure(options) {
4991
5097
  return super.configure(options);
4992
5098
  }
4993
5099
  extend(extendedConfig) {
4994
- return super.extend(extendedConfig);
5100
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
5101
+ return super.extend(resolvedConfig);
4995
5102
  }
4996
5103
  };
4997
5104
 
4998
5105
  // src/NodeView.ts
4999
- import { NodeSelection as NodeSelection4 } from "@tiptap/pm/state";
5106
+ import { NodeSelection as NodeSelection5 } from "@tiptap/pm/state";
5000
5107
  var NodeView = class {
5001
5108
  constructor(component, props, options) {
5002
5109
  this.isDragging = false;
@@ -5043,12 +5150,13 @@ var NodeView = class {
5043
5150
  x = handleBox.x - domBox.x + offsetX;
5044
5151
  y = handleBox.y - domBox.y + offsetY;
5045
5152
  }
5046
- (_g = event.dataTransfer) == null ? void 0 : _g.setDragImage(this.dom, x, y);
5153
+ const clonedNode = this.dom.cloneNode(true);
5154
+ (_g = event.dataTransfer) == null ? void 0 : _g.setDragImage(clonedNode, x, y);
5047
5155
  const pos = this.getPos();
5048
5156
  if (typeof pos !== "number") {
5049
5157
  return;
5050
5158
  }
5051
- const selection = NodeSelection4.create(view.state.doc, pos);
5159
+ const selection = NodeSelection5.create(view.state.doc, pos);
5052
5160
  const transaction = view.state.tr.setSelection(selection);
5053
5161
  view.dispatch(transaction);
5054
5162
  }
@@ -5074,7 +5182,7 @@ var NodeView = class {
5074
5182
  const { isEditable } = this.editor;
5075
5183
  const { isDragging } = this;
5076
5184
  const isDraggable = !!this.node.type.spec.draggable;
5077
- const isSelectable = NodeSelection4.isSelectable(this.node);
5185
+ const isSelectable = NodeSelection5.isSelectable(this.node);
5078
5186
  const isCopyEvent = event.type === "copy";
5079
5187
  const isPasteEvent = event.type === "paste";
5080
5188
  const isCutEvent = event.type === "cut";
@@ -5297,6 +5405,7 @@ export {
5297
5405
  PasteRule,
5298
5406
  Tracker,
5299
5407
  callOrReturn,
5408
+ canInsertNode,
5300
5409
  combineTransactionSteps,
5301
5410
  createChainableState,
5302
5411
  createDocument,
@@ -5383,6 +5492,7 @@ export {
5383
5492
  textInputRule,
5384
5493
  textPasteRule,
5385
5494
  textblockTypeInputRule,
5495
+ updateMarkViewAttributes,
5386
5496
  wrappingInputRule
5387
5497
  };
5388
5498
  //# sourceMappingURL=index.js.map