third party plugins
Tailwind CSS WYSIWYG Editor
Utilize the WYSIWYG text editor to create and modify content, adjusting paragraphs, headings, images, and styling options.
Below are the comprehensively outlined steps you can follow to seamlessly integrate Editor JS into your project. This is official EditorJS site.
This is a basic example of a text editor using EditorJS. With EditorJS, we can create a Notion-like text editor. The text editor below includes basic tools such as heading, nested list, table, inline code, and more. For additional tools, you can refer to the EditorJS repository and check out the Awesome Editor.js list for more tools.
For images, we use the Simple Image plugin, which allows you to drag and drop images or paste the image URL directly, but no UI option will be visible in the toolbar.
<div id="basic" class="bg-base-100 shadow-base-300/20 rounded-box w-full p-4 shadow-sm"></div>
<script>
const editor = new EditorJS({
holder: 'basic', // id of the element
// placeholder
placeholder: 'Type text or paste a link',
// Tools
tools: {
header: {
class: Header,
inlineToolbar: ['marker', 'link'],
config: {
placeholder: 'Header'
},
shortcut: 'CMD+SHIFT+H'
},
raw: RawTool,
image: SimpleImage,
checklist: {
class: Checklist,
inlineToolbar: true
},
list: {
class: NestedList,
inlineToolbar: true,
shortcut: 'CMD+SHIFT+L'
},
embed: Embed,
quote: {
class: Quote,
inlineToolbar: true,
config: {
quotePlaceholder: 'Enter a quote',
captionPlaceholder: "Quote's author"
},
shortcut: 'CMD+SHIFT+O'
},
marker: {
class: Marker,
shortcut: 'CMD+SHIFT+M'
},
table: {
class: Table,
inlineToolbar: true,
shortcut: 'CMD+ALT+T'
},
inlineCode: {
class: InlineCode,
shortcut: 'CMD+SHIFT+I'
},
warning: {
class: Warning,
inlineToolbar: true,
shortcut: 'CMD+SHIFT+W',
config: {
titlePlaceholder: 'Title',
messagePlaceholder: 'Message'
}
}
},
onChange: () => {
editor
.save()
.then(outputData => {
displayJSON(outputData)
})
.catch(error => {
console.error('Saving failed: ', error)
})
}
})
// Function to display JSON data
function displayJSON(data) {
const outputElement = document.getElementById('output')
outputElement.textContent = JSON.stringify(data, null, 2) // Pretty print JSON with indentation
}
</script>
This block displays the data in JSON format.
Example showcasing a text editor in a modal.
<button type="button" class="btn btn-primary" aria-haspopup="dialog" aria-expanded="false" aria-controls="text-editor-modal" data-overlay="#text-editor-modal">Daily tasks</button>
<div id="text-editor-modal" class="overlay modal overlay-open:opacity-100 overlay-open:duration-300 hidden" role="dialog" tabindex="-1">
<div class="modal-dialog overlay-open:opacity-100 overlay-open:duration-300 modal-dialog-lg">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Daily tasks</h3>
<button type="button" class="btn btn-text btn-circle btn-sm absolute end-3 top-3" aria-label="Close" data-overlay="#text-editor-modal">
<span class="icon-[tabler--x] size-4"></span>
</button>
</div>
<div class="modal-body">
<div id="modal-editor" class="border border-base-content/25 rounded-box p-4"></div>
</div>
</div>
</div>
</div>
<script>
const modaleditor = new EditorJS({
holder: 'modal-editor', // id of the element
// placeholder
placeholder: 'Type text or paste a link',
// Tools
tools: {
header: {
class: Header,
inlineToolbar: ['marker', 'link'],
config: {
placeholder: 'Header'
},
shortcut: 'CMD+SHIFT+H'
},
raw: RawTool,
image: SimpleImage,
checklist: {
class: Checklist,
inlineToolbar: true
},
list: {
class: NestedList,
inlineToolbar: true,
shortcut: 'CMD+SHIFT+L'
},
embed: Embed,
quote: {
class: Quote,
inlineToolbar: true,
config: {
quotePlaceholder: 'Enter a quote',
captionPlaceholder: "Quote's author"
},
shortcut: 'CMD+SHIFT+O'
},
marker: {
class: Marker,
shortcut: 'CMD+SHIFT+M'
},
table: {
class: Table,
inlineToolbar: true,
shortcut: 'CMD+ALT+T'
},
inlineCode: {
class: InlineCode,
shortcut: 'CMD+SHIFT+I'
},
warning: {
class: Warning,
inlineToolbar: true,
shortcut: 'CMD+SHIFT+W',
config: {
titlePlaceholder: 'Title',
messagePlaceholder: 'Message'
}
}
}
})
</script>