@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 CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  PasteRule: () => PasteRule,
34
34
  Tracker: () => Tracker,
35
35
  callOrReturn: () => callOrReturn,
36
+ canInsertNode: () => canInsertNode,
36
37
  combineTransactionSteps: () => combineTransactionSteps,
37
38
  createChainableState: () => createChainableState,
38
39
  createDocument: () => createDocument,
@@ -4200,6 +4201,9 @@ var NodePos = class _NodePos {
4200
4201
  const isBlock = node.isBlock && !node.isTextblock;
4201
4202
  const isNonTextAtom = node.isAtom && !node.isText;
4202
4203
  const targetPos = this.pos + offset + (isNonTextAtom ? 0 : 1);
4204
+ if (targetPos < 0 || targetPos > this.resolvedPos.doc.nodeSize - 2) {
4205
+ return;
4206
+ }
4203
4207
  const $pos = this.resolvedPos.doc.resolve(targetPos);
4204
4208
  if (!isBlock && $pos.depth <= this.depth) {
4205
4209
  return;
@@ -5057,6 +5061,29 @@ var h = (tag, attributes) => {
5057
5061
  return [tag, rest, children];
5058
5062
  };
5059
5063
 
5064
+ // src/utilities/canInsertNode.ts
5065
+ var import_state22 = require("@tiptap/pm/state");
5066
+ function canInsertNode(state, nodeType) {
5067
+ const { selection } = state;
5068
+ const { $from } = selection;
5069
+ if (selection instanceof import_state22.NodeSelection) {
5070
+ const index = $from.index();
5071
+ const parent = $from.parent;
5072
+ return parent.canReplaceWith(index, index + 1, nodeType);
5073
+ }
5074
+ let depth = $from.depth;
5075
+ while (depth >= 0) {
5076
+ const index = $from.index(depth);
5077
+ const parent = $from.node(depth);
5078
+ const match = parent.contentMatchAt(index);
5079
+ if (match.matchType(nodeType)) {
5080
+ return true;
5081
+ }
5082
+ depth -= 1;
5083
+ }
5084
+ return false;
5085
+ }
5086
+
5060
5087
  // src/utilities/escapeForRegEx.ts
5061
5088
  function escapeForRegEx(string) {
5062
5089
  return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
@@ -5126,7 +5153,7 @@ var Node3 = class _Node extends Extendable {
5126
5153
  };
5127
5154
 
5128
5155
  // src/NodeView.ts
5129
- var import_state22 = require("@tiptap/pm/state");
5156
+ var import_state23 = require("@tiptap/pm/state");
5130
5157
  var NodeView = class {
5131
5158
  constructor(component, props, options) {
5132
5159
  this.isDragging = false;
@@ -5179,7 +5206,7 @@ var NodeView = class {
5179
5206
  if (typeof pos !== "number") {
5180
5207
  return;
5181
5208
  }
5182
- const selection = import_state22.NodeSelection.create(view.state.doc, pos);
5209
+ const selection = import_state23.NodeSelection.create(view.state.doc, pos);
5183
5210
  const transaction = view.state.tr.setSelection(selection);
5184
5211
  view.dispatch(transaction);
5185
5212
  }
@@ -5205,7 +5232,7 @@ var NodeView = class {
5205
5232
  const { isEditable } = this.editor;
5206
5233
  const { isDragging } = this;
5207
5234
  const isDraggable = !!this.node.type.spec.draggable;
5208
- const isSelectable = import_state22.NodeSelection.isSelectable(this.node);
5235
+ const isSelectable = import_state23.NodeSelection.isSelectable(this.node);
5209
5236
  const isCopyEvent = event.type === "copy";
5210
5237
  const isPasteEvent = event.type === "paste";
5211
5238
  const isCutEvent = event.type === "cut";
@@ -5429,6 +5456,7 @@ var Tracker = class {
5429
5456
  PasteRule,
5430
5457
  Tracker,
5431
5458
  callOrReturn,
5459
+ canInsertNode,
5432
5460
  combineTransactionSteps,
5433
5461
  createChainableState,
5434
5462
  createDocument,