@tiptap/core 3.0.0-beta.14 → 3.0.0-beta.16

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,
@@ -1950,8 +1951,13 @@ var Mark = class _Mark extends Extendable {
1950
1951
  super(...arguments);
1951
1952
  this.type = "mark";
1952
1953
  }
1954
+ /**
1955
+ * Create a new Mark instance
1956
+ * @param config - Mark configuration object or a function that returns a configuration object
1957
+ */
1953
1958
  static create(config = {}) {
1954
- return new _Mark(config);
1959
+ const resolvedConfig = typeof config === "function" ? config() : config;
1960
+ return new _Mark(resolvedConfig);
1955
1961
  }
1956
1962
  static handleExit({ editor, mark }) {
1957
1963
  const { tr } = editor.state;
@@ -1977,7 +1983,8 @@ var Mark = class _Mark extends Extendable {
1977
1983
  return super.configure(options);
1978
1984
  }
1979
1985
  extend(extendedConfig) {
1980
- return super.extend(extendedConfig);
1986
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
1987
+ return super.extend(resolvedConfig);
1981
1988
  }
1982
1989
  };
1983
1990
 
@@ -2482,14 +2489,20 @@ var Extension = class _Extension extends Extendable {
2482
2489
  super(...arguments);
2483
2490
  this.type = "extension";
2484
2491
  }
2492
+ /**
2493
+ * Create a new Extension instance
2494
+ * @param config - Extension configuration object or a function that returns a configuration object
2495
+ */
2485
2496
  static create(config = {}) {
2486
- return new _Extension(config);
2497
+ const resolvedConfig = typeof config === "function" ? config() : config;
2498
+ return new _Extension(resolvedConfig);
2487
2499
  }
2488
2500
  configure(options) {
2489
2501
  return super.configure(options);
2490
2502
  }
2491
2503
  extend(extendedConfig) {
2492
- return super.extend(extendedConfig);
2504
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
2505
+ return super.extend(resolvedConfig);
2493
2506
  }
2494
2507
  };
2495
2508
 
@@ -2909,7 +2922,8 @@ var insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) =
2909
2922
  newContent = content;
2910
2923
  const fromSelectionAtStart = selection.$from.parentOffset === 0;
2911
2924
  const isTextSelection2 = selection.$from.node().isText || selection.$from.node().isTextblock;
2912
- if (fromSelectionAtStart && isTextSelection2) {
2925
+ const hasContent = selection.$from.node().content.size > 0;
2926
+ if (fromSelectionAtStart && isTextSelection2 && hasContent) {
2913
2927
  from = Math.max(0, from - 1);
2914
2928
  }
2915
2929
  tr.replaceWith(from, to, newContent);
@@ -5060,6 +5074,29 @@ var h = (tag, attributes) => {
5060
5074
  return [tag, rest, children];
5061
5075
  };
5062
5076
 
5077
+ // src/utilities/canInsertNode.ts
5078
+ var import_state22 = require("@tiptap/pm/state");
5079
+ function canInsertNode(state, nodeType) {
5080
+ const { selection } = state;
5081
+ const { $from } = selection;
5082
+ if (selection instanceof import_state22.NodeSelection) {
5083
+ const index = $from.index();
5084
+ const parent = $from.parent;
5085
+ return parent.canReplaceWith(index, index + 1, nodeType);
5086
+ }
5087
+ let depth = $from.depth;
5088
+ while (depth >= 0) {
5089
+ const index = $from.index(depth);
5090
+ const parent = $from.node(depth);
5091
+ const match = parent.contentMatchAt(index);
5092
+ if (match.matchType(nodeType)) {
5093
+ return true;
5094
+ }
5095
+ depth -= 1;
5096
+ }
5097
+ return false;
5098
+ }
5099
+
5063
5100
  // src/utilities/escapeForRegEx.ts
5064
5101
  function escapeForRegEx(string) {
5065
5102
  return string.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
@@ -5117,19 +5154,25 @@ var Node3 = class _Node extends Extendable {
5117
5154
  super(...arguments);
5118
5155
  this.type = "node";
5119
5156
  }
5157
+ /**
5158
+ * Create a new Node instance
5159
+ * @param config - Node configuration object or a function that returns a configuration object
5160
+ */
5120
5161
  static create(config = {}) {
5121
- return new _Node(config);
5162
+ const resolvedConfig = typeof config === "function" ? config() : config;
5163
+ return new _Node(resolvedConfig);
5122
5164
  }
5123
5165
  configure(options) {
5124
5166
  return super.configure(options);
5125
5167
  }
5126
5168
  extend(extendedConfig) {
5127
- return super.extend(extendedConfig);
5169
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
5170
+ return super.extend(resolvedConfig);
5128
5171
  }
5129
5172
  };
5130
5173
 
5131
5174
  // src/NodeView.ts
5132
- var import_state22 = require("@tiptap/pm/state");
5175
+ var import_state23 = require("@tiptap/pm/state");
5133
5176
  var NodeView = class {
5134
5177
  constructor(component, props, options) {
5135
5178
  this.isDragging = false;
@@ -5182,7 +5225,7 @@ var NodeView = class {
5182
5225
  if (typeof pos !== "number") {
5183
5226
  return;
5184
5227
  }
5185
- const selection = import_state22.NodeSelection.create(view.state.doc, pos);
5228
+ const selection = import_state23.NodeSelection.create(view.state.doc, pos);
5186
5229
  const transaction = view.state.tr.setSelection(selection);
5187
5230
  view.dispatch(transaction);
5188
5231
  }
@@ -5208,7 +5251,7 @@ var NodeView = class {
5208
5251
  const { isEditable } = this.editor;
5209
5252
  const { isDragging } = this;
5210
5253
  const isDraggable = !!this.node.type.spec.draggable;
5211
- const isSelectable = import_state22.NodeSelection.isSelectable(this.node);
5254
+ const isSelectable = import_state23.NodeSelection.isSelectable(this.node);
5212
5255
  const isCopyEvent = event.type === "copy";
5213
5256
  const isPasteEvent = event.type === "paste";
5214
5257
  const isCutEvent = event.type === "cut";
@@ -5432,6 +5475,7 @@ var Tracker = class {
5432
5475
  PasteRule,
5433
5476
  Tracker,
5434
5477
  callOrReturn,
5478
+ canInsertNode,
5435
5479
  combineTransactionSteps,
5436
5480
  createChainableState,
5437
5481
  createDocument,