Tiptap Utility Functions
tiptap-utils is an older, standalone JavaScript package providing a collection of general utility functions designed for the Tiptap editor. Its current stable version is 1.13.1, with its last release approximately five years ago. This package is distinct from the modern `@tiptap/core` (v2/v3) monorepo and its associated extensions, which now integrate many of the functionalities previously offered by `tiptap-utils` directly into the core library or specific extensions. As such, `tiptap-utils` does not adhere to the active and rapid release cadence of the current Tiptap ecosystem. Developers are generally advised to use the utilities provided by `@tiptap/core` for modern Tiptap implementations, as `tiptap-utils` may have compatibility issues with newer editor versions due to significant API changes.
Common errors
-
TypeError: editor.state is undefined
cause Attempting to pass a modern Tiptap v2/v3 `editor` instance or its internal state to a `tiptap-utils` function, which expects the structure of Tiptap v1.x.fixEnsure you are using `tiptap-utils` with a Tiptap v1.x editor. If using Tiptap v2/v3, use the built-in `editor.state` property and the `editor.isActive()` method directly on the editor instance instead of `tiptap-utils` functions. -
Error: Cannot find module 'tiptap-utils' or SyntaxError: Named export 'markIsActive' not found.
cause Incorrect import statement (e.g., using `require` in an ESM project, or bundling issues) or attempting to access a non-existent export.fixVerify that `tiptap-utils` is installed correctly (`npm install tiptap-utils`). For ESM projects, use `import { markIsActive } from 'tiptap-utils';`. Ensure your bundler is configured to handle older CommonJS or UMD packages if necessary, though it's recommended to avoid this package entirely for modern projects.
Warnings
- breaking The `tiptap-utils` package (v1.x) is designed for the original Tiptap v1.x editor. It is generally not compatible with `@tiptap/core` v2 or v3 due to fundamental changes in the editor's architecture, state management, and API surface. Attempting to use `tiptap-utils` with modern Tiptap will likely lead to runtime errors or incorrect behavior.
- deprecated This package has not received updates in approximately five years. Many of its functionalities have been superseded or integrated directly into the core `@tiptap/core` package and its extensions. Continuing to use `tiptap-utils` in new projects is strongly discouraged.
- gotcha The package metadata provided in the prompt (recent releases) pertains to the *modern* `@tiptap` monorepo (v3.x) and not to the `tiptap-utils` package (v1.x) itself. Do not confuse `tiptap-utils`'s versioning and release history with the active development of `@tiptap/core`.
Install
-
npm install tiptap-utils -
yarn add tiptap-utils -
pnpm add tiptap-utils
Imports
- getMarkAttrs
const { getMarkAttrs } = require('tiptap-utils')import { getMarkAttrs } from 'tiptap-utils' - markIsActive
import markIsActive from 'tiptap-utils'
import { markIsActive } from 'tiptap-utils' - nodeIsActive
require('tiptap-utils').nodeIsActiveimport { nodeIsActive } from 'tiptap-utils'
Quickstart
import { Editor } from 'tiptap';
import { markIsActive, nodeIsActive } from 'tiptap-utils';
import { Bold, Paragraph, Document } from 'tiptap-extensions'; // Example extensions for older Tiptap
// This example is for older Tiptap v1.x, which `tiptap-utils` was designed for.
// It is NOT compatible with @tiptap/core v2/v3.
const editor = new Editor({
extensions: [
new Document(),
new Paragraph(),
new Bold(),
],
content: '<p>This is <strong>bold</strong> text.</p>',
onUpdate: ({ editor }) => {
const state = editor.state;
console.log('Is bold mark active?', markIsActive(state, 'bold'));
console.log('Is paragraph node active?', nodeIsActive(state, 'paragraph'));
},
});
// To simulate usage in a non-interactive environment or test:
setTimeout(() => {
const state = editor.state;
console.log('Is bold mark active after timeout?', markIsActive(state, 'bold'));
console.log('Is paragraph node active after timeout?', nodeIsActive(state, 'paragraph'));
editor.destroy();
}, 1000);