@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.js CHANGED
@@ -2263,6 +2263,30 @@ function getMarksBetween(from, to, doc) {
2263
2263
  return marks;
2264
2264
  }
2265
2265
 
2266
+ /**
2267
+ * Finds the first node of a given type or name in the current selection.
2268
+ * @param state The editor state.
2269
+ * @param typeOrName The node type or name.
2270
+ * @param pos The position to start searching from.
2271
+ * @param maxDepth The maximum depth to search.
2272
+ * @returns The node and the depth as an array.
2273
+ */
2274
+ const getNodeAtPosition = (state, typeOrName, pos, maxDepth = 20) => {
2275
+ const $pos = state.doc.resolve(pos);
2276
+ let currentDepth = maxDepth;
2277
+ let node = null;
2278
+ while (currentDepth > 0 && node === null) {
2279
+ const currentNode = $pos.node(currentDepth);
2280
+ if ((currentNode === null || currentNode === void 0 ? void 0 : currentNode.type.name) === typeOrName) {
2281
+ node = currentNode;
2282
+ }
2283
+ else {
2284
+ currentDepth -= 1;
2285
+ }
2286
+ }
2287
+ return [node, currentDepth];
2288
+ };
2289
+
2266
2290
  function getSplittedAttributes(extensionAttributes, typeName, attributes) {
2267
2291
  return Object.fromEntries(Object
2268
2292
  .entries(attributes)
@@ -2353,6 +2377,22 @@ function isActive(state, name, attributes = {}) {
2353
2377
  return false;
2354
2378
  }
2355
2379
 
2380
+ const istAtEndOfNode = (state) => {
2381
+ const { $from, $to } = state.selection;
2382
+ if ($to.parentOffset < $to.parent.nodeSize - 2 || $from.pos !== $to.pos) {
2383
+ return false;
2384
+ }
2385
+ return true;
2386
+ };
2387
+
2388
+ const isAtStartOfNode = (state) => {
2389
+ const { $from, $to } = state.selection;
2390
+ if ($from.parentOffset > 0 || $from.pos !== $to.pos) {
2391
+ return false;
2392
+ }
2393
+ return true;
2394
+ };
2395
+
2356
2396
  function isList(name, extensions) {
2357
2397
  const { nodeExtensions } = splitExtensions(extensions);
2358
2398
  const extension = nodeExtensions.find(item => item.name === name);
@@ -4282,5 +4322,5 @@ class Tracker {
4282
4322
  }
4283
4323
  }
4284
4324
 
4285
- export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, createChainableState, createDocument, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, extensions, findChildren, findChildrenInRange, findDuplicates, findParentNode, findParentNodeClosestToPos, fromString, generateHTML, generateJSON, generateText, getAttributes, getAttributesFromExtensions, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarkType, getMarksBetween, getNodeAttributes, getNodeType, getRenderedAttributes, getSchema, getSchemaByResolvedExtensions, getSchemaTypeByName, getSchemaTypeNameByName, getSplittedAttributes, getText, getTextBetween, getTextContentFromNodes, getTextSerializersFromSchema, injectExtensionAttributesToParseRule, inputRulesPlugin, isActive, 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, selectionToInsertionEnd, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
4325
+ export { CommandManager, Editor, Extension, InputRule, Mark, Node, NodeView, PasteRule, Tracker, callOrReturn, combineTransactionSteps, createChainableState, createDocument, createNodeFromContent, createStyleTag, defaultBlockAt, deleteProps, elementFromString, escapeForRegEx, 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, isAtStartOfNode, isEmptyObject, isExtensionRulesEnabled, isFunction, isList, isMacOS, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isNumber, isPlainObject, isRegExp, isString, isTextSelection, isiOS, istAtEndOfNode, markInputRule, markPasteRule, mergeAttributes, mergeDeep, minMax, nodeInputRule, nodePasteRule, objectIncludes, pasteRulesPlugin, posToDOMRect, removeDuplicates, resolveFocusPosition, selectionToInsertionEnd, splitExtensions, textInputRule, textPasteRule, textblockTypeInputRule, wrappingInputRule };
4286
4326
  //# sourceMappingURL=index.js.map