blackpig-creatif/filament-component-picker
Composer 安装命令:
composer require blackpig-creatif/filament-component-picker
包简介
Add a component picker to your filament RichEditor fields
README 文档
README
A powerful FilamentPHP package that provides a component picker for RichEditor fields with shortcode rendering support. Insert Blade components into rich text content using a visual picker, and render them on your frontend using shortcode syntax.
Features
- Visual Component Picker - Add a button to any RichEditor field to insert components
- Auto-discovery - Automatically discovers components from configured directories
- Shortcode Rendering - Parse and render
[component-name attr="value"]shortcodes on the frontend - Smart Type Detection - Automatically detects component prop types (text, URL, KeyValue, nested objects)
- CSS Class Merging - Supports components with
$attributes->merge()for custom styling - Highly Configurable - Customize directories, labels, exclusions, and more
Requirements
- PHP 8.2 or higher
- Laravel 11.x or 12.x
- Filament 4.x
Installation
Install the package via composer:
composer require blackpig-creatif/filament-component-picker
Optionally, you can publish the config file with:
php artisan vendor:publish --tag="blackpig-creatif-component-picker-config"
This is the contents of the published config file:
<?php return [ /* |-------------------------------------------------------------------------- | Default Component Directory |-------------------------------------------------------------------------- | | The default directory where component picker will look for components. | This path is relative to resources/views/components/ | | Default: 'richeditor' | Example: components/richeditor/attribution.blade.php | */ 'default_directory' => env('COMPONENT_PICKER_DEFAULT_DIR', 'richeditor'), /* |-------------------------------------------------------------------------- | Fallback Directory |-------------------------------------------------------------------------- | | If a component is not found in the default directory, the picker will | fall back to this directory. | | Default: null (will search in components root) | Example: 'shared' would search in components/shared/ | */ 'fallback_directory' => env('COMPONENT_PICKER_FALLBACK_DIR', null), /* |-------------------------------------------------------------------------- | Auto-discover Components |-------------------------------------------------------------------------- | | Automatically discover all components in the default directory and | make them available in the picker without explicit configuration. | */ 'auto_discover' => env('COMPONENT_PICKER_AUTO_DISCOVER', true), /* |-------------------------------------------------------------------------- | Default Options |-------------------------------------------------------------------------- | | Components that should always be available in the picker. | These are added to auto-discovered components. | | Use dot notation for nested components: | - 'attribution' will look in: richeditor/, then components/ | - 'shared.attribution' will look in: shared/, then components/ | - 'marketing.cta.button' will look in: marketing/cta/, then components/ | */ 'default_options' => [ // 'shared.cta-button', // 'shared.cta-icon', ], /* |-------------------------------------------------------------------------- | Excluded Components |-------------------------------------------------------------------------- | | Components to exclude from auto-discovery. | Use simple names (without directory prefix). | */ 'excluded_components' => [ // 'internal-component', // 'deprecated-widget', ], /* |-------------------------------------------------------------------------- | Component Labels |-------------------------------------------------------------------------- | | Custom labels for components in the picker dropdown. | If not specified, labels are auto-generated from component names. | | Example: 'cta-button' becomes 'Cta Button' | */ 'component_labels' => [ // 'attribution' => 'Photo Attribution', // 'cta-button' => 'Call to Action Button', ], /* |-------------------------------------------------------------------------- | Shortcode Parser |-------------------------------------------------------------------------- | | Configuration for the shortcode parser that renders components | on the frontend. | */ 'parser' => [ // Cache parsed component configurations 'cache' => env('COMPONENT_PICKER_CACHE', true), // Cache duration in seconds (default: 1 hour) 'cache_duration' => 3600, // Log parsing errors 'log_errors' => env('COMPONENT_PICKER_LOG_ERRORS', true), ], ];
Usage
1. Create Your Components
Create Blade components in resources/views/components/richeditor/:
{{-- resources/views/components/richeditor/attribution.blade.php --}} @props([ 'photographer' => '', 'link' => '' ]) <div {{ $attributes->merge(['class' => 'text-sm text-gray-600 italic']) }}> Photo by <a href="{{ $link }}" target="_blank" class="underline">{{ $photographer }}</a> </div>
{{-- resources/views/components/richeditor/callout.blade.php --}} @props([ 'title' => '', 'content' => '', 'type' => 'info' ]) <div class="callout callout-{{ $type }}"> <h4>{{ $title }}</h4> <p>{{ $content }}</p> </div>
2. Add Component Picker to Your Filament Resource
<?php namespace App\Filament\Resources; use BlackpigCreatif\FilamentComponentPicker\Actions\ComponentPickerAction; use Filament\Forms\Components\RichEditor; use Filament\Resources\Resource; class BlogPostResource extends Resource { public static function form(Form $form): Form { return $form ->schema([ RichEditor::make('content') ->required() ->hintAction( ComponentPickerAction::make('insertComponent') // Auto-discovers components from richeditor/ directory // Optionally add more from other directories: ->addOptions(['shared.cta-button', 'shared.cta-icon']) ), ]); } }
3. Render Shortcodes on the Frontend
{{-- resources/views/blog/show.blade.php --}} @php use BlackpigCreatif\FilamentComponentPicker\Services\ShortcodeParser; @endphp <article> <h1>{{ $post->title }}</h1> <div class="content"> {!! ShortcodeParser::parse($post->content) !!} </div> </article>
Advanced Usage
Exclude Specific Components
ComponentPickerAction::make('insertComponent') ->excludeOptions(['internal-component', 'deprecated-widget'])
Exclude All Auto-discovered Components
ComponentPickerAction::make('insertComponent') ->withoutAutoDiscovery() ->addOptions(['shared.cta-button']) // Only show these
Use Custom Exclusion Logic
ComponentPickerAction::make('insertComponent') ->excludeOptions(function (array $options) { // Remove all components starting with 'admin-' return array_filter($options, fn($key) => !str_starts_with($key, 'admin-'), ARRAY_FILTER_USE_KEY); })
Custom Component Labels
In your config file:
'component_labels' => [ 'attribution' => 'Photo Attribution', 'cta-button' => 'Call to Action Button', ],
Component Folder Structure
The package uses a hierarchical component resolution system:
resources/views/components/
├── richeditor/ # Default directory (auto-discovered)
│ ├── attribution.blade.php
│ ├── callout.blade.php
│ └── quote.blade.php
├── shared/ # Explicitly added components
│ ├── cta-button.blade.php
│ └── cta-icon.blade.php
└── marketing/
└── newsletter.blade.php
Usage in Component Picker:
attribution→ looks inricheditor/, thencomponents/shared.cta-button→ looks inshared/, thencomponents/marketing.newsletter→ looks inmarketing/, thencomponents/
How It Works
In the Admin Panel
- Click the component picker button in any RichEditor field
- Select a component from the dropdown
- Fill in the component's props in the generated form
- The shortcode is inserted:
[component-name prop1="value1" prop2="value2"]
On the Frontend
- ShortcodeParser finds all
[component-name ...]patterns - Validates the component exists and is whitelisted
- Parses attributes (including JSON for complex props)
- Renders the component with the provided attributes
Smart Type Detection
The package automatically detects component prop types:
- KeyValue: Props named
*_data,*_config,*_meta - Nested Objects: Props named
*_settings,*_options,*_params - URLs: Props named
*_url,*_link,link - Text: Everything else (TextInput or Textarea based on name)
Testing
composer test
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
License
The MIT License (MIT). Please see License File for more information.
blackpig-creatif/filament-component-picker 适用场景与选型建议
blackpig-creatif/filament-component-picker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「filament-component-picker」 「blackpig-creatif」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blackpig-creatif/filament-component-picker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blackpig-creatif/filament-component-picker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blackpig-creatif/filament-component-picker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
In-panel documentation for FilamentPHP applications
SEO and social media optimization for FilamentPHP v5
L'art du contenu - Artisanal content blocks for FilamentPHP v5
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-15