iamgerwin/filament-tinymce
Composer 安装命令:
composer require iamgerwin/filament-tinymce
包简介
TinyMCE editor field for Filament v4 with full customization support
README 文档
README
A powerful and flexible TinyMCE rich text editor field for Filament v3, featuring comprehensive customization options, image uploads, dark mode support, and multiple editor profiles.
Features
- 🎨 Full TinyMCE 6 Integration - Complete access to TinyMCE's powerful editing capabilities
- 🌓 Dark Mode Support - Seamless theme switching that follows Filament's theme
- 📸 Image Upload - Built-in image upload with configurable storage options
- ⚙️ Highly Customizable - Configure plugins, toolbar, and initialization options
- 📱 Responsive Design - Mobile-optimized editor configuration
- 🚀 Multiple Profiles - Pre-configured editor profiles (simple, standard, full)
- 🔒 Secure - Built-in CSRF protection and authentication checks for uploads
- 🎯 PHP 8.3 Optimized - Leveraging modern PHP features for better performance
Requirements
- PHP ^8.3
- Laravel ^11.0
- Filament ^3.2
Installation
You can install the package via composer:
composer require iamgerwin/filament-tinymce
Publish the configuration file:
php artisan vendor:publish --tag="filament-tinymce-config"
Optionally, publish the assets:
php artisan vendor:publish --tag="filament-tinymce-assets"
Configuration
TinyMCE API Key
To use TinyMCE cloud, add your API key to your .env file:
TINYMCE_API_KEY=your-api-key-here TINYMCE_CLOUD_CHANNEL=6
You can get a free API key from TinyMCE.
Configuration File
The configuration file config/filament-tinymce.php provides extensive customization options:
return [ 'api_key' => env('TINYMCE_API_KEY', ''), 'cloud_channel' => env('TINYMCE_CLOUD_CHANNEL', '6'), 'show_menu_bar' => false, 'min_height' => 256, 'max_height' => 0, // 0 = no limit 'plugins' => [ 'advlist', 'anchor', 'autolink', 'autoresize', 'autosave', 'charmap', 'code', 'codesample', 'directionality', 'emoticons', 'fullscreen', 'help', 'image', 'insertdatetime', 'link', 'lists', 'media', 'pagebreak', 'preview', 'quickbars', 'searchreplace', 'table', 'visualblocks', 'visualchars', 'wordcount' ], 'toolbar' => [ 'undo redo restoredraft | styles | bold italic underline strikethrough', 'alignleft aligncenter alignright alignjustify | outdent indent', 'blocks fontfamily fontsize | forecolor backcolor', 'bullist numlist | link image media table | code fullscreen preview' ], 'upload_images' => [ 'enabled' => false, 'disk' => 'public', 'folder' => 'images', 'max_size' => 2048, // in KB ], // Pre-configured profiles 'profiles' => [ 'simple' => [...], 'standard' => [...], 'full' => [...] ] ];
Usage
Basic Usage
use Iamgerwin\FilamentTinymce\Forms\Components\TinymceEditor; TinymceEditor::make('content') ->label('Content') ->required()
Simple Profile
For basic text editing needs:
TinymceEditor::make('description') ->simple()
With Image Uploads
Enable image uploads with custom configuration:
TinymceEditor::make('content') ->uploadImages() ->uploadDisk('s3') ->uploadDirectory('blog/images') ->uploadMaxSize(4096) // 4MB
Custom Toolbar and Plugins
TinymceEditor::make('content') ->plugins(['link', 'image', 'code', 'table']) ->toolbar([ 'undo redo | bold italic underline', 'link image table | code' ]) ->showMenuBar()
Height Configuration
TinymceEditor::make('content') ->minHeight(400) ->maxHeight(800)
Advanced Configuration
TinymceEditor::make('content') ->apiKey('your-custom-api-key') ->cloudChannel('7') ->init([ 'branding' => false, 'promotion' => false, 'browser_spellcheck' => true, 'paste_as_text' => true, 'autosave_interval' => '30s', 'autosave_retention' => '60m', 'content_style' => 'body { font-family: Arial; font-size: 16px; }' ])
Using in Resource Forms
namespace App\Filament\Resources\PostResource\Pages; use App\Filament\Resources\PostResource; use Filament\Resources\Pages\CreateRecord; use Iamgerwin\FilamentTinymce\Forms\Components\TinymceEditor; class CreatePost extends CreateRecord { protected static string $resource = PostResource::class; protected function getFormSchema(): array { return [ Forms\Components\TextInput::make('title') ->required() ->maxLength(255), TinymceEditor::make('content') ->label('Post Content') ->required() ->uploadImages() ->uploadDirectory('posts/' . date('Y/m')) ->minHeight(500), Forms\Components\Toggle::make('is_published') ->label('Publish immediately') ]; } }
Validation
The field works seamlessly with Laravel's validation rules:
TinymceEditor::make('content') ->required() ->minLength(100) ->maxLength(5000) ->rules(['string', 'max:5000'])
Read-only and Disabled States
TinymceEditor::make('content') ->disabled() // or ->readonly() // or conditionally ->disabled(fn () => ! auth()->user()->isAdmin())
Advanced Features
Dark Mode Support
The editor automatically adapts to Filament's dark mode. No additional configuration needed.
Autosave
Configure autosave functionality:
TinymceEditor::make('content') ->init([ 'autosave_interval' => '20s', 'autosave_retention' => '30m', 'autosave_restore_when_empty' => true, ])
Custom CSS Styling
Apply custom styles to the editor content:
TinymceEditor::make('content') ->init([ 'content_style' => ' body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.6; color: #333; } h1 { color: #2563eb; } blockquote { border-left: 4px solid #e5e7eb; padding-left: 1rem; color: #6b7280; } ' ])
Mobile Configuration
Different configuration for mobile devices:
TinymceEditor::make('content') ->init([ 'mobile' => [ 'menubar' => false, 'plugins' => 'autosave lists link image', 'toolbar' => 'undo bold italic styles link image', ] ])
Image Upload Security
When enabling image uploads, the package includes:
- File type validation (images only)
- File size validation
- Automatic file name sanitization
- CSRF protection
- Authentication checks
Configure in your config/filament-tinymce.php:
'upload_images' => [ 'enabled' => true, 'disk' => 's3', // or 'local', 'public' 'folder' => 'uploads/tinymce', 'max_size' => 2048, // KB ],
Testing
Run the test suite:
composer test
Run tests with coverage:
composer test-coverage
Run PHPStan analysis:
./vendor/bin/phpstan analyse
Format code with Pint:
composer format
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
This package is inspired by Nova4-TinymceEditor and uses the Spatie Laravel Package Skeleton.
License
The MIT License (MIT). Please see License File for more information.
iamgerwin/filament-tinymce 适用场景与选型建议
iamgerwin/filament-tinymce 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 09 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wysiwyg」 「tinymce」 「editor」 「laravel」 「filament」 「rich-text」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 iamgerwin/filament-tinymce 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iamgerwin/filament-tinymce 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 iamgerwin/filament-tinymce 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Adds links to data objects in TinyMCE editor
TinyMCE Silverstripe 4 inspired theme
Adds more BBCode
WYSIWYG editor for Yii2 based on Bootstrap 3
UEditor 是一套开源的在线HTML编辑器,主要用于让用户在网站上获得所见即所得编辑效果,开发人员可以用 UEditor 把传统的多行文本输入框(textarea)替换为可视化的富文本输入框。
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-22