A Svelte wrapper for Editor.js with TypeScript support and enhanced configuration options.
- 🎯 Full TypeScript support
- ⚡ Dynamic tool registration
- 🌍 Internationalization (i18n) support
- 📝 Read-only mode
- 🛠 Customizable inline toolbar
- 🎨 Block tunes support
- 📊 Custom event handling
- 📝 Advanced configuration options
# Install the library
npm install svelty-editor
# Install required peer dependencies
npm install @editorjs/editorjs
# Install optional tools as needed
npm install @editorjs/header @editorjs/list @editorjs/paragraph
<script lang="ts">
import { SveltyEditor } from 'svelty-editor';
import type { OutputData } from '@editorjs/editorjs';
const handleChange = (data: OutputData) => {
console.log('Content changed:', data);
};
</script>
<SveltyEditor
onChange={handleChange}
placeholder="Start writing..."
autofocus={true}
/>
<script lang="ts">
import { SveltyEditor } from 'svelty-editor';
import type { OutputData } from '@editorjs/editorjs';
let editor: any;
const editorConfig = {
defaultBlock: 'paragraph',
autofocus: true,
placeholder: 'Start writing an awesome story!',
logLevel: 'ERROR',
inlineToolbar: ['link', 'marker', 'bold', 'italic'],
tools: {
header: {
inlineToolbar: true,
config: {
placeholder: 'Enter a header',
levels: [1, 2, 3],
defaultLevel: 1
}
},
list: {
inlineToolbar: true
}
},
i18n: {
messages: {
ui: {
'blockTunes.deleteTune.delete': 'Delete',
'blockTunes.deleteTune.confirm': 'Confirm'
},
toolNames: {
'header': 'Heading',
'list': 'List'
}
}
},
onChange: (api, event) => {
console.log('Content changed:', event);
},
onReady: () => {
console.log('Editor is ready!');
}
};
</script>
<SveltyEditor
bind:this={editor}
{...editorConfig}
/>
// Registering a custom tool
await editor.registerTool(
'customTool',
() => import('./CustomTool'),
{
inlineToolbar: true,
config: {
// custom tool configuration
}
}
);
// Save editor content
const data = await editor.save();
// Toggle read-only mode
editor.setReadOnly(true);
// Register a new tool
await editor.registerTool(name, toolLoader, config);
// Get editor manager instance for advanced usage
const manager = editor.getManager();
Option | Type | Description |
---|---|---|
data |
OutputData |
Initial editor content |
onChange |
(data: OutputData) => void |
Callback when content changes |
placeholder |
string |
Editor placeholder text |
autofocus |
boolean |
Auto focus editor on load |
readOnly |
boolean |
Enable read-only mode |
defaultBlock |
string |
Default block type |
logLevel |
'VERBOSE' | 'INFO' | 'WARN' | 'ERROR' |
Logging level |
inlineToolbar |
boolean | string[] |
Configure inline toolbar |
tools |
Record<string, EditorTool> |
Configure editor tools |
i18n |
I18nConfig |
Internationalization config |
tunes |
string[] |
Block tunes configuration |
The library includes comprehensive TypeScript definitions. You can import types like this:
import type {
EditorOptions,
EditorTool,
EditorChangeEvent
} from 'svelty-editor';
Contributions are welcome! Please feel free to submit a Pull Request.
MIT
This library is powered by Editor.js.