athphane / filament-editorjs
This is my package filament-editorjs
Fund package maintenance!
athphane
Installs: 2 186
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 1
Forks: 9
Open Issues: 5
pkg:composer/athphane/filament-editorjs
Requires
- php: ^8.3
- filament/filament: ^4.5|^5.0
- filament/spatie-laravel-media-library-plugin: ^v4.0|^5.0
Requires (Dev)
- larastan/larastan: ^2.11
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.1
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- pestphp/pest-plugin-livewire: ^2.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2026-01-31 19:06:49 UTC
README
A premium EditorJS field for Filament with seamless Spatie Media Library integration and a robust rendering system.
Filament EditorJS brings the power of Editor.js to your Filament admin panel, allowing you to create rich, block-based content with ease. It handles image uploads out of the box using Livewire and Spatie's Media Library, and provides a powerful rendering engine to display your content on the frontend with Tailwind CSS support.
โจ Features
- ๐ Zero-Config Uploads: Effortless image uploads using Filament's internal file attachment system.
- ๐ฆ Spatie Media Library: Full integration for managing your content assets.
- ๐ ๏ธ Dynamic Plugin System: Easily add and configure both built-in and custom Editor.js tools.
- ๐จ Tailwind Rendering: Built-in support for rendering content with Tailwind Typography (
prose). - โก Filament v5 Ready: Fully compatible with the latest Filament v4 and v5 features.
- ๐งฉ Extensible Blocks: Create custom renderers for your unique block types in PHP.
- ๐ Automatic Cleanup: Automatically manages and cleans up unused media attachments.
๐ Installation
Install the package via composer:
composer require athphane/filament-editorjs
Publish the configuration file:
php artisan vendor:publish --tag="filament-editorjs-config"
๐ฅ Quick Start
1. Prepare your Model
Your model must implement Spatie's HasMedia interface and use the ModelHasEditorJsComponent trait provided by this package.
use Athphane\FilamentEditorjs\Traits\ModelHasEditorJsComponent; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; class Post extends Model implements HasMedia { use InteractsWithMedia; use ModelHasEditorJsComponent; // By default, it expects a 'content' column (json) // and registers a 'content_images' media collection. }
2. Register the Plugin (Optional but recommended for v4/v5)
Add the plugin to your Filament Panel provider (usually AdminPanelProvider.php):
use Athphane\FilamentEditorjs\FilamentEditorjsPlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ FilamentEditorjsPlugin::make(), ]); }
3. Add to your Filament Resource
Simply use the EditorjsTextField in your form schema:
use Athphane\FilamentEditorjs\Forms\Components\EditorjsTextField; public static function form(Form $form): Form { return $form ->schema([ EditorjsTextField::make('content') ->placeholder('Start writing your masterpiece...') ->columnSpanFull(), ]); }
4. Render on the Frontend
Displaying your content is just as easy:
{{-- In your Blade view --}} {!! \Athphane\FilamentEditorjs\FilamentEditorjs::renderContent($post->content) !!}
Note: For the best experience, ensure you have the @tailwindcss/typography plugin installed.
๐ ๏ธ Dynamic Plugin System
This package allows you to customize the editor tools dynamically.
Adding Custom Tools
You can add any Editor.js compatible tool by registering it in Javascript and then enabling it in PHP.
1. Register in Javascript
Add your custom tool to the global window.filamentEditorJsTools registry:
import LinkTool from '@editorjs/link'; window.filamentEditorJsTools = window.filamentEditorJsTools || {}; window.filamentEditorJsTools.linkTool = LinkTool;
2. Enable in PHP
Use the addPlugin method on your field:
EditorjsTextField::make('content') ->addPlugin('linkTool', [ 'endpoint' => route('editorjs.link-tool-parser'), ])
๐จ Customizing Content Rendering
You can extend the rendering engine by adding custom renderers for specific block types.
Creating a Custom Renderer
use Athphane\FilamentEditorjs\Renderers\BlockRenderer; class CustomBlockRenderer extends BlockRenderer { public function render(array $block): string { return view('renderers.custom-block', [ 'data' => $block['data'], ])->render(); } public function getType(): string { return 'custom-block-type'; } }
Registering your Renderer
Register it in your AppServiceProvider:
use Athphane\FilamentEditorjs\FilamentEditorjs; public function boot() { FilamentEditorjs::addRenderer(new CustomBlockRenderer()); }
โ๏ธ Configuration
The config/filament-editorjs.php file allows you to define different tool profiles:
'profiles' => [ 'default' => [ 'header', 'image', 'delimiter', 'list', 'underline', 'quote', 'table', ], 'pro' => [ 'header', 'image', 'delimiter', 'list', 'underline', 'quote', 'table', 'raw', 'code', 'inline-code', 'style', 'checklist', ], ],
Switch between profiles in your form:
EditorjsTextField::make('content')->tools('pro')
๐ Upgrading
Please refer to the Upgrade Guide when moving between major versions.
๐งช Testing
composer test
๐ค Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
๐ License
The MIT License (MIT). Please see License File for more information.
