
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
tiptap-utility
Advanced tools
List of utils functions, helps to build custom extension and help working with tiptap editor
A collection of utility functions to enhance your workflow with the Tiptap editor.
npm install tiptap-utility
isTextSelected
Checks if text is selected in the Tiptap editor.
editor
: Tiptap Editor
instance.boolean
: true
if text is selected and editor is editable, otherwise false
.import { isTextSelected } from 'tiptap-utility';
const isSelected = isTextSelected({ editor });
console.log(isSelected ? "Text is selected" : "No text selected");
getWordCount
Counts the number of words in the Tiptap editor content.
editor
: Tiptap Editor
instance.number
: Total word count.import { getWordCount } from 'tiptap-utility';
const wordCount = getWordCount(editor);
console.log(`Word count: ${wordCount}`);
getFocusedNodeContainer
Finds the focused node container in the Tiptap editor DOM based on the specified nodeType
.
editor
: Tiptap Editor
instance.nodeType
: The target node type to locate.attribute
(optional): Attribute used to identify the node. Default is 'data-type'
.focusClass
(optional): CSS class used to identify focused nodes. Default is 'has-focus'
.HTMLElement | null
: The focused node container or null
if not found.import { getFocusedNodeContainer } from 'tiptap-utility';
const container = getFocusedNodeContainer(editor, 'paragraph');
if (container) {
console.log('Focused node container:', container);
} else {
console.log('No focused container found.');
}
getAllNodesOfType
Retrieves all nodes of a specified type from the Tiptap editor document, including those nested within lists, tables, or other container nodes.
editor
: Tiptap Editor
instance.type
: The target node type to locate (e.g., 'heading'
, 'paragraph'
).Array<{ node: Node, pos: number }>
:
node
: The node instance of the specified type.pos
: The position of the node in the document.import { getAllNodesOfType } from 'tiptap-utility';
const headings = getAllNodesOfType(editor, 'heading');
headings.forEach(({ node, pos }) => {
console.log('Found heading:', node, 'at position:', pos);
});
getAllNodesByTypeAndAttrs
Finds all nodes of a given type and with specific attributes in the Tiptap editor's document.
editor
: Tiptap Editor
instance.type
: A string representing the type of node to search for.attrs
: An object containing the attributes to match against the nodes.Array<{ node: any; pos: number }>
: An array of nodes and their positions that match the given type and attributes.import { getAllNodesByTypeAndAttrs } from 'tiptap-utility';
const nodes = getAllNodesByTypeAndAttrs({ editor }, 'image', { src: 'https://example.com/image.jpg' });
console.log(nodes);
getAllMarksByTypeAndAttrs
Finds all marks of a given type and with specific attributes in the Tiptap editor's document.
editor
: Tiptap Editor
instance.markTypeName
: A string representing the type of mark to search for (e.g., 'bold'
, 'italic'
, 'link'
).attrs
: An object containing the attributes to match against the marks.match
(optional): The matching strategy - 'and'
(default) requires all attributes to match, 'or'
requires at least one attribute to match.Array<{ from: number; to: number; attrs: any }>
: An array of objects where each object contains:
from
: The starting position of the marked text.to
: The ending position of the marked text.attrs
: The attributes of the mark.import { getAllMarksByTypeAndAttrs } from 'tiptap-utility';
// Find all bold marks
const boldMarks = getAllMarksByTypeAndAttrs(editor, 'bold', {});
console.log(boldMarks);
// Find all link marks with specific href
const linkMarks = getAllMarksByTypeAndAttrs(editor, 'link', { href: 'https://example.com' });
console.log(linkMarks);
// Find marks where any of the specified attributes match (using 'or' strategy)
const colorMarks = getAllMarksByTypeAndAttrs(editor, 'textStyle', { color: '#ff0000' }, 'or');
console.log(colorMarks);
findParentNodeOfTypeAtPosition
Finds the parent node of a given type at a specific position in the Tiptap editor.
editor
: Tiptap Editor
instance.position
: The position in the document where the search for the parent node begins.parentNodeTypeName
: The name of the parent node type to search for.{ node: any; depth: number; start: number; end: number } | null
: An object containing the parent node, its depth, and its start and end positions if found, otherwise null
.import { findParentNodeOfTypeAtPosition } from 'tiptap-utility';
const parentNode = findParentNodeOfTypeAtPosition({ editor }, 10, 'paragraph');
if (parentNode) {
console.log('Parent node found:', parentNode);
} else {
console.log('No parent node found at the specified position');
}
getEditorState
Retrieves the current state of the Tiptap editor.
editor
: Tiptap Editor
instance.object
: The current state of the editor, either from editor.state
or editor.view.state
.import { getEditorState } from 'tiptap-utility';
const editorState = getEditorState({ editor });
console.log(editorState);
getNodesInRange
Extracts all nodes within a specified range in the Tiptap editor document. Optionally, it can filter nodes by specified types.
editor
(required): An instance of the Tiptap Editor
.from
(required): The starting position of the range (inclusive).to
(required): The ending position of the range (exclusive).nodeType
(optional): An array of node type names to filter for, or null
to include all node types. Defaults to null
.NodeWithPosition[]
: An array of objects, where each object contains:
node
: The ProseMirror Node
instance.pos
: The starting position of the node within the document.import { getNodesInRange } from 'tiptap-utility';
const from = 0;
const to = 50;
const nodeTypes = ['paragraph', 'heading'];
const nodes = getNodesInRange(editor, from, to, nodeTypes);
nodes.forEach(({ node, pos }) => {
console.log(`Node of type ${node.type.name} found at position ${pos}`);
});
getLastChildNode
Retrieves the last child node of a given node along with its starting position.
node
(required): A ProseMirror Node
from which to find the last child.{ node: Node, pos: number } | null
:
node
: The last child Node
.pos
: The starting position of the last child node.null
if the node has no children.import { getLastChildNode } from 'tiptap-utility';
const parentNode = editor.state.doc.nodeAt(0); // Example parent node
if (parentNode) {
const lastChild = getLastChildNode(parentNode);
if (lastChild) {
console.log(`Last child node type: ${lastChild.node.type.name}`);
console.log(`Position: ${lastChild.pos}`);
} else {
console.log('No child nodes found.');
}
}
getNextSiblingNode
Finds the next sibling node of a given node within its parent.
parent
(required): A ProseMirror Node
representing the parent container.currentNode
(required): The child node whose next sibling needs to be found.{ node: Node } | null
:
node
: The next sibling Node
.null
if there is no next sibling.import { getNextSiblingNode } from 'tiptap-utility';
const parentNode = editor.state.doc.nodeAt(0); // Example parent node
const currentNode = parentNode?.firstChild; // Example current node
if (parentNode && currentNode) {
const nextSibling = getNextSiblingNode(parentNode, currentNode);
if (nextSibling) {
console.log(`Next sibling node type: ${nextSibling.node.type.name}`);
} else {
console.log('No next sibling found.');
}
}
This package is open-source and available under the MIT License.
FAQs
List of utils functions, helps to build custom extension and help working with tiptap editor
The npm package tiptap-utility receives a total of 193 weekly downloads. As such, tiptap-utility popularity was classified as not popular.
We found that tiptap-utility demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.