@tiptap/core 2.22.1 → 2.22.3

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.js CHANGED
@@ -4212,6 +4212,10 @@ class NodePos {
4212
4212
  const isBlock = node.isBlock && !node.isTextblock;
4213
4213
  const isNonTextAtom = node.isAtom && !node.isText;
4214
4214
  const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1);
4215
+ // Check if targetPos is within valid document range
4216
+ if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) {
4217
+ return;
4218
+ }
4215
4219
  const $pos = this.resolvedPos.doc.resolve(targetPos);
4216
4220
  if (!isBlock && $pos.depth <= this.depth) {
4217
4221
  return;
@@ -5364,6 +5368,30 @@ function markPasteRule(config) {
5364
5368
  });
5365
5369
  }
5366
5370
 
5371
+ function canInsertNode(state, nodeType) {
5372
+ const { selection } = state;
5373
+ const { $from } = selection;
5374
+ // Special handling for NodeSelection
5375
+ if (selection instanceof NodeSelection) {
5376
+ const index = $from.index();
5377
+ const parent = $from.parent;
5378
+ // Can we replace the selected node with the horizontal rule?
5379
+ return parent.canReplaceWith(index, index + 1, nodeType);
5380
+ }
5381
+ // Default: check if we can insert at the current position
5382
+ let depth = $from.depth;
5383
+ while (depth >= 0) {
5384
+ const index = $from.index(depth);
5385
+ const parent = $from.node(depth);
5386
+ const match = parent.contentMatchAt(index);
5387
+ if (match.matchType(nodeType)) {
5388
+ return true;
5389
+ }
5390
+ depth -= 1;
5391
+ }
5392
+ return false;
5393
+ }
5394
+
5367
5395
  // source: https://stackoverflow.com/a/6969486
5368
5396
  function escapeForRegEx(string) {
5369
5397
  return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
@@ -5448,5 +5476,5 @@ class Tracker {
5448
5476
  }
5449
5477
  }
5450
5478
 
5451
- export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodePos, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, createChainableState, createDocument, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, index as extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, 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, injectExtensionAttributesToParseRule, inputRulesPlugin, isActive, 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, resolveFocusPosition, rewriteUnknownContent, selectionToInsertionEnd, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
5479
+ export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodePos, NodeView, PasteRule, Tracker, callOrReturn, canInsertNode, combineTransactionSteps, createChainableState, createDocument, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, index as extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, 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, injectExtensionAttributesToParseRule, inputRulesPlugin, isActive, 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, resolveFocusPosition, rewriteUnknownContent, selectionToInsertionEnd, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
5452
5480
  //# sourceMappingURL=index.js.map