
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
ngx-tiptap
Advanced tools
Angular bindings for tiptap v2
demo on stackblitz | edit stackblitz
Find a example on how to use the editor here at project/demo directory.
npm i ngx-tiptap
# or
yarn add ngx-tiptap
[!NOTE] This package just provides the bindings for angular. For configuring/customizing the editor, refer tiptap's official documentation.
For any issues with the editor. You may need to open the issue on tiptap's repository
All components are now standalone. Import the component you need.
Create an instance of the editor
import { Component, OnDestroy } from '@angular/core';
import { Editor } from '@tiptap/core';
import StarterKit from '@tiptap/starter-kit';
import { TiptapEditorDirective } from 'ngx-tiptap';
@Component({
selector: 'app-root',
template: './app.component.html',
imports: [CommonModule, FormsModule, TiptapEditorDirective],
standalone: true,
})
export class AppComponent implements OnDestroy {
editor = new Editor({
extensions: [StarterKit],
});
value = '<p>Hello, Tiptap!</p>'; // can be HTML or JSON, see https://www.tiptap.dev/api/editor#content
ngOnDestroy(): void {
this.editor.destroy();
}
}
and in HTML
<tiptap-editor [editor]="editor" [(ngModel)]="value"></tiptap-editor>
[!NOTE] No styling is provided by default. You are in full control of how your editor looks. Refer tiptaps's styling guide for more information.
[!TIP] Since the editor is dynamically created, You may need to set ViewEncapsulation to
None
or target the class/element via ::ng-deep to apply the styles. See Component Styles docs for more info.
json
or html
] - defaults to html.You can get the json or html format from the editor directly as well.
Refer https://www.tiptap.dev/guide/output#export
Refer: https://www.tiptap.dev/api/extensions
This will make a contextual menu appear near a selection of text. The markup and styling are totally up to you.
Import the TiptapFloatingMenuDirective
to your component and use it. For example:
<tiptap-editor [editor]="editor"></tiptap-editor>
<tiptap-floating-menu [editor]="editor">
<!-- Anything that should be rendered inside floating menu -->
</tiptap-floating-menu>
Refer: https://www.tiptap.dev/api/extensions/floating-menu
This will make a contextual menu appear near a selection of text. Use it to let users apply marks to their text selection. The markup and styling are totally up to you.
Import the TiptapBubbleMenuDirective
to your component and use it. For example:
<tiptap-editor [editor]="editor"></tiptap-editor>
<tiptap-bubble-menu [editor]="editor">
<!-- Anything that should be rendered inside bubble menu -->
</tiptap-bubble-menu>
Refer: https://www.tiptap.dev/api/extensions/bubble-menu
This enables rendering Angular Components as NodeViews.
import { Injector } from '@angular/core';
import { Node, mergeAttributes } from '@tiptap/core';
import { AngularNodeViewRenderer } from 'ngx-tiptap';
import { NodeviewCounterComponent } from './nodeview-counter/nodeview-counter.component';
const CounterComponentExtension = (injector: Injector): Node => {
return Node.create({
// ...other configuration hidden for brevity
parseHTML() {
return [{ tag: 'angular-component-counter' }];
},
renderHTML({ HTMLAttributes }) {
return ['angular-component-counter', mergeAttributes(HTMLAttributes)];
},
addNodeView() {
return AngularNodeViewRenderer(NodeviewCounterComponent, { injector });
},
});
};
export default CounterComponentExtension;
Refer: https://tiptap.dev/guide/custom-extensions
import { Component } from '@angular/core';
import { AngularNodeViewComponent } from 'ngx-tiptap';
@Component({
selector: 'app-nodeview-counter',
})
export class NodeviewCounterComponent extends AngularNodeViewComponent {
increment(): void {
const updateAttributes = this.updateAttributes();
updateAttributes({
count: this.node.attrs.count + 1,
});
}
}
import { Component, Injector, OnInit, OnDestroy } from '@angular/core';
import { Editor } from '@tiptap/core';
import StarterKit from '@tiptap/starter-kit';
import CounterComponentExtension from './CounterComponentExtension';
@Component({
selector: 'app-root',
template: './app.component.html',
})
export class AppComponent implements OnInit, OnDestroy {
editor: Editor;
constructor(private injector: Injector) {}
ngOnInit(): void {
this.editor = new Editor({
content: `
<p>This is still the text editor you’re used to, but enriched with node views.</p>
<angular-component-counter count="0"></angular-component-counter>
`,
extensions: [StarterKit, CounterComponentExtension(this.injector)],
editorProps: {
attributes: {
class: 'p-2 border-black focus:border-blue-700 border-2 rounded-md outline-none',
},
},
});
}
ngOnDestroy(): void {
this.editor.destroy();
}
}
Refer https://www.tiptap.dev/guide/node-views/react/#all-available-props for the list of all available attributes. You can access them by extending the AngularNodeViewComponent
import { AngularNodeViewComponent } from 'ngx-tiptap';
export class NodeviewCounterComponent extends AngularNodeViewComponent {
increment(): void {
const updateAttributes = this.updateAttributes();
updateAttributes({
count: this.node.attrs.count + 1,
});
}
}
There is another directive called tiptapNodeViewContent
which helps you adding editable content to your node view. Make sure to import the TiptapNodeViewContentDirective
to your component.
Here is an example.
<!-- editable.component.html -->
<div class="angular-component-with-content">
<p tiptapNodeViewContent></p>
</div>
Refer: https://www.tiptap.dev/guide/node-views/react/#adding-a-content-editable
To make your node views draggable, import the TiptapDraggableDirective
to your component and set draggable: true
in the tiptap extension. Add tiptapDraggable
directive to the DOM element inside the component that should function as the drag handle.
You can also manually render the angular components using AngularRenderer
.
import { AngularRenderer } from 'ngx-tiptap';
const renderer = new AngularRenderer(Component, injector, props);
renderer.instance; // get the instance of the component, can be used to update `@Input` properties
renderer.dom; // get the HTMLElement for the component
renderer.destroy(); // destroy the component and its instance
All types of contributions are welcome. See CONTRIBUTING.md to get started.
v12.0.0 (2024-11-28)
Everything is now standalone, and NgxTiptapModule
is no longer needed and has been removed.
Manually import the following components wherever required:
AngularNodeViewComponent methods are now signals.
An example of updating attributes in a custom node view:
Before
this.updateAttributes({
count: this.node.attrs['count'] + 1,
});
After
const updateAttributes = this.updateAttributes();
updateAttributes({
count: this.node().attrs['count'] + 1,
});
For more details, refer to the README.
FAQs
Angular bindings for tiptap v2
The npm package ngx-tiptap receives a total of 6,150 weekly downloads. As such, ngx-tiptap popularity was classified as popular.
We found that ngx-tiptap demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.