@tiptap/core 2.1.0-rc.8 → 2.1.0-rc.9

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.umd.js CHANGED
@@ -2261,6 +2261,30 @@
2261
2261
  return marks;
2262
2262
  }
2263
2263
 
2264
+ /**
2265
+ * Finds the first node of a given type or name in the current selection.
2266
+ * @param state The editor state.
2267
+ * @param typeOrName The node type or name.
2268
+ * @param pos The position to start searching from.
2269
+ * @param maxDepth The maximum depth to search.
2270
+ * @returns The node and the depth as an array.
2271
+ */
2272
+ const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
2273
+ const $pos = state.doc.resolve(pos);
2274
+ let currentDepth = maxDepth;
2275
+ let node = null;
2276
+ while (currentDepth > 0 && node === null) {
2277
+ const currentNode = $pos.node(currentDepth);
2278
+ if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
2279
+ node = currentNode;
2280
+ }
2281
+ else {
2282
+ currentDepth -= 1;
2283
+ }
2284
+ }
2285
+ return [node, currentDepth];
2286
+ };
2287
+
2264
2288
  function getSplittedAttributes(extensionAttributes, typeName, attributes) {
2265
2289
  return Object.fromEntries(Object
2266
2290
  .entries(attributes)
@@ -2351,6 +2375,22 @@
2351
2375
  return false;
2352
2376
  }
2353
2377
 
2378
+ const istAtEndOfNode = (state) => {
2379
+ const { $from, $to } = state.selection;
2380
+ if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
2381
+ return false;
2382
+ }
2383
+ return true;
2384
+ };
2385
+
2386
+ const isAtStartOfNode = (state) => {
2387
+ const { $from, $to } = state.selection;
2388
+ if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
2389
+ return false;
2390
+ }
2391
+ return true;
2392
+ };
2393
+
2354
2394
  function isList(name, extensions) {
2355
2395
  const { nodeExtensions } = splitExtensions(extensions);
2356
2396
  const extension = nodeExtensions.find(item => item.name === name);
@@ -4319,6 +4359,7 @@ img.ProseMirror-separator {
4319
4359
  exports.getMarkRange = getMarkRange;
4320
4360
  exports.getMarkType = getMarkType;
4321
4361
  exports.getMarksBetween = getMarksBetween;
4362
+ exports.getNodeAtPosition = getNodeAtPosition;
4322
4363
  exports.getNodeAttributes = getNodeAttributes;
4323
4364
  exports.getNodeType = getNodeType;
4324
4365
  exports.getRenderedAttributes = getRenderedAttributes;
@@ -4334,6 +4375,7 @@ img.ProseMirror-separator {
4334
4375
  exports.injectExtensionAttributesToParseRule = injectExtensionAttributesToParseRule;
4335
4376
  exports.inputRulesPlugin = inputRulesPlugin;
4336
4377
  exports.isActive = isActive;
4378
+ exports.isAtStartOfNode = isAtStartOfNode;
4337
4379
  exports.isEmptyObject = isEmptyObject;
4338
4380
  exports.isExtensionRulesEnabled = isExtensionRulesEnabled;
4339
4381
  exports.isFunction = isFunction;
@@ -4349,6 +4391,7 @@ img.ProseMirror-separator {
4349
4391
  exports.isString = isString;
4350
4392
  exports.isTextSelection = isTextSelection;
4351
4393
  exports.isiOS = isiOS;
4394
+ exports.istAtEndOfNode = istAtEndOfNode;
4352
4395
  exports.markInputRule = markInputRule;
4353
4396
  exports.markPasteRule = markPasteRule;
4354
4397
  exports.mergeAttributes = mergeAttributes;