jeffersongoncalves/filament-ace-editor-field
Filament v5 form field that embeds the Ace code editor. Adds syntax-highlighted editing with configurable language modes, themes, height, and placeholder support for a richer code/text input experience in Laravel admin panels.
composer require jeffersongoncalves/filament-ace-editor-field:^2.0
php artisan vendor:publish --tag=filament-ace-editor-field-config
use JeffersonGoncalves\Filament\AceEditorField\Forms\Components\AceEditorInput;
AceEditorInput::make('code_snippet')
->mode('php') // Defaults to 'text'
->height(200)
->required(),
Edit HTML snippets in a marketing page builder:
AceEditorInput::make('page_html')
->mode('html')
->theme('monokai')
->height(400)
->placeholder('<div>Your HTML here...</div>')
->validationRules(['required', 'max:10000']),
Dynamic Mode Selection:
Use a mode() method to set syntax highlighting for different languages:
AceEditorInput::make('config')
->mode('json') // or 'javascript', 'php', 'css', etc.
Conditional Theming: Tie themes to user preferences or roles:
$theme = auth()->user()->prefers_dark_mode ? 'twilight' : 'chrome';
AceEditorInput::make('script')->theme($theme),
Validation Integration: Combine with Filament’s validation rules:
AceEditorInput::make('api_payload')
->mode('json')
->validationRules(['required', 'json']),
Read-Only Mode: Disable editing for display purposes:
AceEditorInput::make('template')
->mode('handlebars')
->readOnly(),
Custom Ace Editor Options:
Pass additional Ace Editor configurations via extraOptions():
AceEditorInput::make('sql_query')
->mode('sql')
->extraOptions([
'showLineNumbers' => true,
'tabSize' => 4,
'fontSize' => '14px',
]),
Dynamic Height: Use JavaScript to adjust height based on content:
AceEditorInput::make('large_code')
->mode('javascript')
->height(150)
->extraOptions(['autoScrollEditorIntoView' => true]),
Integration with Filament Tables: Use in table actions or inline editing:
Tables\Columns\TextColumn::make('code_preview')
->toggleable(isToggledHiddenByDefault: true)
->copyable()
->extraAttributes(['class' => 'whitespace-pre-wrap']),
Multi-Field Coordination: Sync editor modes across related fields:
// In a form component
$language = $this->data['language'] ?? 'javascript';
AceEditorInput::make('code')
->mode($language)
->reactive(),
Filament Version Mismatch:
Class 'JeffersonGoncalves\Filament\AceEditorField\Forms\Components\AceEditorInput' not found^5.3 is installed (package requires it). Downgrade to ^1.x if using Filament ^4.8.Missing Ace Editor Assets:
npm install && npm run dev (if using Vite) or php artisan filament:assets to compile assets.Syntax Validation Bypass:
html to javascript) to inject malicious code.AceEditorInput::make('html_content')
->mode('html')
->validationRules(['required', 'string']),
Performance with Large Files:
height() to limit visible lines or implement client-side chunking.Check Console for Errors:
Open browser dev tools (F12) to inspect Ace Editor initialization errors (e.g., missing modes).
Verify Config Publishing: If custom themes/modes aren’t working, ensure the config was published:
php artisan vendor:publish --tag=filament-ace-editor-field-config --force
Inspect Extra Options:
Use extraOptions(['behavior' => 'start']) to debug editor behavior.
Fallback for Unsupported Modes:
If a mode (e.g., graphql) fails, fall back to text:
$mode = in_array($this->data['language'], ['graphql', 'yaml']) ? $this->data['language'] : 'text';
AceEditorInput::make('code')->mode($mode),
Custom Themes: Extend the package by publishing custom Ace themes:
// config/filament-ace-editor-field.php
'themes' => [
'custom-theme' => resource_path('assets/ace/themes/custom-theme.css'),
],
Plugin Integration:
Load Ace Editor plugins via extraOptions:
AceEditorInput::make('code')
->extraOptions([
'plugins' => ['textmate', 'wrap'],
'textmate' => {
'mode' => 'javascript',
'theme' => 'monokai',
},
]),
Server-Side Processing: Sanitize input before saving:
// In a Filament Resource
protected static function getValidationRules(): array
{
return [
'code_snippet' => ['required', function ($attribute, $value, $fail) {
if (str_contains($value, '<script>')) {
$fail('Script tags are not allowed.');
}
}],
];
}
Localization: Translate placeholders and labels:
AceEditorInput::make('description')
->placeholder(__('filament-ace-editor::fields.placeholder'))
->label(__('filament-ace-editor::fields.label')),
How can I help you explore Laravel packages today?