@tiptap/core 3.0.0-beta.13 → 3.0.0-beta.15
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 +31 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +30 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/NodePos.ts +6 -0
- package/src/utilities/canInsertNode.ts +30 -0
- package/src/utilities/index.ts +1 -0
package/dist/index.d.cts
CHANGED
|
@@ -3265,6 +3265,8 @@ declare class Tracker {
|
|
|
3265
3265
|
*/
|
|
3266
3266
|
declare function callOrReturn<T>(value: T, context?: any, ...props: any[]): MaybeReturnType<T>;
|
|
3267
3267
|
|
|
3268
|
+
declare function canInsertNode(state: EditorState, nodeType: NodeType$1): boolean;
|
|
3269
|
+
|
|
3268
3270
|
declare function createStyleTag(style: string, nonce?: string, suffix?: string): HTMLStyleElement;
|
|
3269
3271
|
|
|
3270
3272
|
/**
|
|
@@ -3332,4 +3334,4 @@ interface Commands<ReturnType = any> {
|
|
|
3332
3334
|
interface Storage {
|
|
3333
3335
|
}
|
|
3334
3336
|
|
|
3335
|
-
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 };
|
|
3337
|
+
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, wrappingInputRule };
|
package/dist/index.d.ts
CHANGED
|
@@ -3265,6 +3265,8 @@ declare class Tracker {
|
|
|
3265
3265
|
*/
|
|
3266
3266
|
declare function callOrReturn<T>(value: T, context?: any, ...props: any[]): MaybeReturnType<T>;
|
|
3267
3267
|
|
|
3268
|
+
declare function canInsertNode(state: EditorState, nodeType: NodeType$1): boolean;
|
|
3269
|
+
|
|
3268
3270
|
declare function createStyleTag(style: string, nonce?: string, suffix?: string): HTMLStyleElement;
|
|
3269
3271
|
|
|
3270
3272
|
/**
|
|
@@ -3332,4 +3334,4 @@ interface Commands<ReturnType = any> {
|
|
|
3332
3334
|
interface Storage {
|
|
3333
3335
|
}
|
|
3334
3336
|
|
|
3335
|
-
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 };
|
|
3337
|
+
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, wrappingInputRule };
|
package/dist/index.js
CHANGED
|
@@ -4086,6 +4086,9 @@ var NodePos = class _NodePos {
|
|
|
4086
4086
|
const isBlock = node.isBlock && !node.isTextblock;
|
|
4087
4087
|
const isNonTextAtom = node.isAtom && !node.isText;
|
|
4088
4088
|
const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1);
|
|
4089
|
+
if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) {
|
|
4090
|
+
return;
|
|
4091
|
+
}
|
|
4089
4092
|
const $pos = this.resolvedPos.doc.resolve(targetPos);
|
|
4090
4093
|
if (!isBlock && $pos.depth <= this.depth) {
|
|
4091
4094
|
return;
|
|
@@ -4943,6 +4946,29 @@ var h = (tag, attributes) => {
|
|
|
4943
4946
|
return [tag, rest, children];
|
|
4944
4947
|
};
|
|
4945
4948
|
|
|
4949
|
+
// src/utilities/canInsertNode.ts
|
|
4950
|
+
import { NodeSelection as NodeSelection4 } from "@tiptap/pm/state";
|
|
4951
|
+
function canInsertNode(state, nodeType) {
|
|
4952
|
+
const { selection } = state;
|
|
4953
|
+
const { $from } = selection;
|
|
4954
|
+
if (selection instanceof NodeSelection4) {
|
|
4955
|
+
const index = $from.index();
|
|
4956
|
+
const parent = $from.parent;
|
|
4957
|
+
return parent.canReplaceWith(index, index + 1, nodeType);
|
|
4958
|
+
}
|
|
4959
|
+
let depth = $from.depth;
|
|
4960
|
+
while (depth >= 0) {
|
|
4961
|
+
const index = $from.index(depth);
|
|
4962
|
+
const parent = $from.node(depth);
|
|
4963
|
+
const match = parent.contentMatchAt(index);
|
|
4964
|
+
if (match.matchType(nodeType)) {
|
|
4965
|
+
return true;
|
|
4966
|
+
}
|
|
4967
|
+
depth -= 1;
|
|
4968
|
+
}
|
|
4969
|
+
return false;
|
|
4970
|
+
}
|
|
4971
|
+
|
|
4946
4972
|
// src/utilities/escapeForRegEx.ts
|
|
4947
4973
|
function escapeForRegEx(string) {
|
|
4948
4974
|
return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
@@ -5012,7 +5038,7 @@ var Node3 = class _Node extends Extendable {
|
|
|
5012
5038
|
};
|
|
5013
5039
|
|
|
5014
5040
|
// src/NodeView.ts
|
|
5015
|
-
import { NodeSelection as
|
|
5041
|
+
import { NodeSelection as NodeSelection5 } from "@tiptap/pm/state";
|
|
5016
5042
|
var NodeView = class {
|
|
5017
5043
|
constructor(component, props, options) {
|
|
5018
5044
|
this.isDragging = false;
|
|
@@ -5065,7 +5091,7 @@ var NodeView = class {
|
|
|
5065
5091
|
if (typeof pos !== "number") {
|
|
5066
5092
|
return;
|
|
5067
5093
|
}
|
|
5068
|
-
const selection =
|
|
5094
|
+
const selection = NodeSelection5.create(view.state.doc, pos);
|
|
5069
5095
|
const transaction = view.state.tr.setSelection(selection);
|
|
5070
5096
|
view.dispatch(transaction);
|
|
5071
5097
|
}
|
|
@@ -5091,7 +5117,7 @@ var NodeView = class {
|
|
|
5091
5117
|
const { isEditable } = this.editor;
|
|
5092
5118
|
const { isDragging } = this;
|
|
5093
5119
|
const isDraggable = !!this.node.type.spec.draggable;
|
|
5094
|
-
const isSelectable =
|
|
5120
|
+
const isSelectable = NodeSelection5.isSelectable(this.node);
|
|
5095
5121
|
const isCopyEvent = event.type === "copy";
|
|
5096
5122
|
const isPasteEvent = event.type === "paste";
|
|
5097
5123
|
const isCutEvent = event.type === "cut";
|
|
@@ -5314,6 +5340,7 @@ export {
|
|
|
5314
5340
|
PasteRule,
|
|
5315
5341
|
Tracker,
|
|
5316
5342
|
callOrReturn,
|
|
5343
|
+
canInsertNode,
|
|
5317
5344
|
combineTransactionSteps,
|
|
5318
5345
|
createChainableState,
|
|
5319
5346
|
createDocument,
|