@tiptap/core 2.1.0-rc.5 → 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.cjs CHANGED
@@ -2267,6 +2267,30 @@ function getMarksBetween(from, to, doc) {
2267
2267
  return marks;
2268
2268
  }
2269
2269
 
2270
+ /**
2271
+ * Finds the first node of a given type or name in the current selection.
2272
+ * @param state The editor state.
2273
+ * @param typeOrName The node type or name.
2274
+ * @param pos The position to start searching from.
2275
+ * @param maxDepth The maximum depth to search.
2276
+ * @returns The node and the depth as an array.
2277
+ */
2278
+ const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
2279
+ const $pos = state.doc.resolve(pos);
2280
+ let currentDepth = maxDepth;
2281
+ let node = null;
2282
+ while (currentDepth > 0 && node === null) {
2283
+ const currentNode = $pos.node(currentDepth);
2284
+ if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
2285
+ node = currentNode;
2286
+ }
2287
+ else {
2288
+ currentDepth -= 1;
2289
+ }
2290
+ }
2291
+ return [node, currentDepth];
2292
+ };
2293
+
2270
2294
  function getSplittedAttributes(extensionAttributes, typeName, attributes) {
2271
2295
  return Object.fromEntries(Object
2272
2296
  .entries(attributes)
@@ -2357,6 +2381,22 @@ function isActive(state, name, attributes = {}) {
2357
2381
  return false;
2358
2382
  }
2359
2383
 
2384
+ const istAtEndOfNode = (state) => {
2385
+ const { $from, $to } = state.selection;
2386
+ if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
2387
+ return false;
2388
+ }
2389
+ return true;
2390
+ };
2391
+
2392
+ const isAtStartOfNode = (state) => {
2393
+ const { $from, $to } = state.selection;
2394
+ if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
2395
+ return false;
2396
+ }
2397
+ return true;
2398
+ };
2399
+
2360
2400
  function isList(name, extensions) {
2361
2401
  const { nodeExtensions } = splitExtensions(extensions);
2362
2402
  const extension = nodeExtensions.find(item => item.name === name);
@@ -4325,6 +4365,7 @@ exports.getMarkAttributes = getMarkAttributes;
4325
4365
  exports.getMarkRange = getMarkRange;
4326
4366
  exports.getMarkType = getMarkType;
4327
4367
  exports.getMarksBetween = getMarksBetween;
4368
+ exports.getNodeAtPosition = getNodeAtPosition;
4328
4369
  exports.getNodeAttributes = getNodeAttributes;
4329
4370
  exports.getNodeType = getNodeType;
4330
4371
  exports.getRenderedAttributes = getRenderedAttributes;
@@ -4340,6 +4381,7 @@ exports.getTextSerializersFromSchema = getTextSerializersFromSchema;
4340
4381
  exports.injectExtensionAttributesToParseRule = injectExtensionAttributesToParseRule;
4341
4382
  exports.inputRulesPlugin = inputRulesPlugin;
4342
4383
  exports.isActive = isActive;
4384
+ exports.isAtStartOfNode = isAtStartOfNode;
4343
4385
  exports.isEmptyObject = isEmptyObject;
4344
4386
  exports.isExtensionRulesEnabled = isExtensionRulesEnabled;
4345
4387
  exports.isFunction = isFunction;
@@ -4355,6 +4397,7 @@ exports.isRegExp = isRegExp;
4355
4397
  exports.isString = isString;
4356
4398
  exports.isTextSelection = isTextSelection;
4357
4399
  exports.isiOS = isiOS;
4400
+ exports.istAtEndOfNode = istAtEndOfNode;
4358
4401
  exports.markInputRule = markInputRule;
4359
4402
  exports.markPasteRule = markPasteRule;
4360
4403
  exports.mergeAttributes = mergeAttributes;