dasundev/livewire-quill-text-editor
Installation:
composer require dasundev/livewire-quill-text-editor
Publish the config (optional):
php artisan vendor:publish --provider="DasunDev\LivewireQuillTextEditor\LivewireQuillTextEditorServiceProvider"
First Use Case: Add the component to a Livewire blade view:
<livewire:quill-editor wire:model="content" />
Ensure your Livewire component has a content property:
public $content = '';
Where to Look First:
config/livewire-quill-text-editor.php for default settings (e.g., toolbar modules, theme).resources/views/vendor/livewire-quill-text-editor.Basic Integration:
wire:model to bind to a Livewire property:
<livewire:quill-editor wire:model="post.body" />
<livewire:quill-editor wire:model="user.bio" />
Custom Toolbars: Configure via config or component attributes:
<livewire:quill-editor
wire:model="content"
:toolbar="['bold', 'italic', 'link', 'clean']"
/>
Or in config/livewire-quill-text-editor.php:
'default_toolbar' => [
['bold', 'italic', 'underline'],
['link', 'image'],
['clean'],
],
Storing HTML:
The editor returns sanitized HTML. Store it directly in the database (use html column type or text with proper escaping).
Preview Mode:
Use the preview attribute to render a static preview:
<livewire:quill-editor wire:model="content" preview />
Dynamic Configuration:
Pass dynamic options via options attribute (PHP array):
<livewire:quill-editor
wire:model="content"
:options="['theme': 'snow', 'modules': ['toolbar', 'history']]"
/>
Multi-Editor Forms: Reuse the component for multiple fields:
<livewire:quill-editor wire:model="post.intro" />
<livewire:quill-editor wire:model="post.conclusion" />
Image Uploads: Integrate with Laravel File Uploads or custom endpoints:
// In Livewire component
public function uploadImage($file) {
$path = $file->store('quill-images');
return ['url' => asset("storage/{$path}")];
}
Configure in config/livewire-quill-text-editor.php:
'upload_handler' => 'App\Http\Livewire\QuillUploadHandler',
Custom Modules: Extend Quill’s functionality by registering custom modules:
// In a separate JS file
Quill.register('modules/customModule', CustomModuleClass);
Load it via the options attribute:
:options="['modules': ['customModule']]"
Validation: Validate HTML content in Livewire rules:
use Illuminate\Validation\Rule;
$rules = [
'content' => [
'required',
Rule::html(), // Use a package like `spatie/laravel-html` for validation
],
];
HTML Sanitization:
'sanitize_html' => false,
htmlpurifier if needed.CORS for Uploads: If using custom upload handlers, ensure CORS is configured for the endpoint:
// In your upload route middleware
return response()->json(['url' => $url]);
Livewire Property Binding:
public function setContent($value).wire:model="user->posts" may fail).Quill JS Conflicts:
<livewire:quill-editor wire:model="content" name="editor-1" />
Toolbar Module Names:
'bold' vs 'Bold'). Check the Quill docs for exact names.Console Errors: Check browser console for Quill initialization errors. Common issues:
@livewireScripts and @livewireStyles are included).Livewire Logs: Enable Livewire logging to debug property updates:
'log' => env('APP_DEBUG', false),
in config/livewire.php.
Network Requests: Inspect failed uploads or API calls in the Network tab. Look for:
@csrf is present in forms).Custom Themes: Override Quill’s default theme by extending its CSS:
/* resources/css/quill-custom.css */
.ql-theme-custom {
/* Your custom styles */
}
Load it in your layout:
<link rel="stylesheet" href="{{ asset('css/quill-custom.css') }}">
Event Listeners:
Listen to Quill events (e.g., text-change) via JavaScript:
document.addEventListener('livewire:init', () => {
Livewire.hook('quill-editor-initialized', (component, editor) => {
editor.on('text-change', () => {
console.log('Content changed!');
});
});
});
Server-Side Processing:
Use Livewire’s updatedContent hook to process HTML before saving:
public function updatedContent($value) {
$this->content = Str::limit($value, 1000); // Truncate long content
}
Fallback for JavaScript: Provide a fallback for users without JS:
@if (request()->wantsJson() || !app()->environment('production'))
<livewire:quill-editor wire:model="content" />
@else
<textarea wire:model="content">{{ $content }}</textarea>
@endif
Default Values: The config file merges with component attributes. Component attributes override config:
<livewire:quill-editor :options="['theme': 'bubble']" />
Overrides config['default_theme'].
Lazy Loading: Disable lazy loading if you need the editor to initialize immediately:
'lazy_load' => false,
in config/livewire-quill-text-editor.php.
Module Dependencies:
Some Quill modules require others (e.g., history needs toolbar). Ensure dependencies are included:
'default_modules' => [
'toolbar',
'history',
'clipboard',
],
How can I help you explore Laravel packages today?