refactor: replace custom textarea with Filament RichEditor and built-in mentions
Replace the custom Alpine.js textarea + mention system with Filament v5's built-in RichEditor component and MentionProvider. This fixes Alpine scope errors (showMentions/mentionResults not defined) that occurred during Livewire DOM morphing inside Filament slide-over modals. - Add InteractsWithForms + HasForms to Comments and CommentItem components - Define commentForm(), editForm(), replyForm() with RichEditor + mentions - Add CommentsConfig::makeMentionProvider() shared helper - Update MentionParser to extract mention IDs from RichEditor HTML format - Update Comment::renderBodyWithMentions() to use RichContentRenderer - Remove all custom Alpine.js mention code from blade templates - Backward compatible with existing plain text comments
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Relaticle\Comments;
|
||||
|
||||
use App\Models\User;
|
||||
use Closure;
|
||||
use Filament\Forms\Components\RichEditor\MentionProvider;
|
||||
use Relaticle\Comments\Mentions\DefaultMentionResolver;
|
||||
use Relaticle\Comments\Models\Comment;
|
||||
use Relaticle\Comments\Policies\CommentPolicy;
|
||||
@@ -173,4 +174,19 @@ class CommentsConfig
|
||||
{
|
||||
static::$resolveAuthenticatedUser = $callback;
|
||||
}
|
||||
|
||||
public static function makeMentionProvider(): MentionProvider
|
||||
{
|
||||
return MentionProvider::make('@')
|
||||
->getSearchResultsUsing(fn (string $search): array => static::getCommenterModel()::query()
|
||||
->where('name', 'like', "%{$search}%")
|
||||
->orderBy('name')
|
||||
->limit(static::getMentionMaxResults())
|
||||
->pluck('name', 'id')
|
||||
->all())
|
||||
->getLabelsUsing(fn (array $ids): array => static::getCommenterModel()::query()
|
||||
->whereIn('id', $ids)
|
||||
->pluck('name', 'id')
|
||||
->all());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user