PHP code example of awcodes / filament-tiptap-editor
1. Go to this page and download the library: Download awcodes/filament-tiptap-editor library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
awcodes / filament-tiptap-editor example snippets
use FilamentTiptapEditor\TiptapEditor;
use FilamentTiptapEditor\Enums\TiptapOutput;
TiptapEditor::make('content')
->profile('default|simple|minimal|none|custom')
->tools([]) // individual tools to use in the editor, overwrites profile
->disk('string') // optional, defaults to config setting
->directory('string or Closure returning a string') // optional, defaults to config setting
->acceptedFileTypes(['array of file types']) // optional, defaults to config setting
->maxSize('integer in KB') // optional, defaults to config setting
->output(TiptapOutput::Html) // optional, change the format for saved data, default is html
->maxContentWidth('5xl')
->
use FilamentTiptapEditor\Enums\TiptapOutput;
TiptapEditor::make('content')
->output(FilamentTiptapEditor\TiptapOutput::Json);
use FilamentTiptapEditor\TiptapBlock;
class BatmanBlock extends TiptapBlock
{
public string $preview = 'blocks.previews.batman';
public string $rendered = 'blocks.rendered.batman';
public function getFormSchema(): array
{
return [
TextInput::make('name'),
TextInput::make('color'),
Select::make('side')
->options([
'Hero' => 'Hero',
'Villain' => 'Villain',
])
->default('Hero')
];
}
}
use FilamentTiptapEditor\TiptapBlock;
class StaticBlock extends TiptapBlock
{
public string $preview = 'blocks.previews.static';
public string $rendered = 'blocks.rendered.static';
}
class BatmanBlock extends TiptapBlock
{
public string $width = 'xl';
public bool $slideOver = true;
public ?string $icon = 'heroicon-o-film';
}
use App\TiptapBlocks\BatmanBlock;
use App\TiptapBlocks\StaticBlock;
use FilamentTiptapEditor\TiptapEditor;
TiptapEditor::configureUsing(function (TiptapEditor $component) {
$component
->blocks([
BatmanBlock::class,
StaticBlock::class,
]);
});
use App\TiptapBlocks\BatmanBlock;
use App\TiptapBlocks\StaticBlock;
use FilamentTiptapEditor\TiptapEditor;
TiptapEditor::configureUsing(function (TiptapEditor $component) {
$component
->collapseBlocksPanel()
->blocks([...]);
});
TiptapEditor::make('content')
->nodePlaceholders([
'paragraph' => 'Start writing your paragraph...',
'heading' => 'Insert a heading...',
])
TiptapEditor::make('content')
// All nodes will immediately be displayed, instead of only the selected node
->showOnlyCurrentPlaceholder(false)
TiptapEditor::make(name: 'content')
->mentionItems([
// The simplest mention item: a label and a id
new MentionItem(label: 'Banana', id: 1),
// Add a href to make the mention clickable in the final HTML output
new MentionItem(id: 1, label: 'Strawberry', href: 'https://filamentphp.com'),
// Include additional data to be stored in the final JSON output
new MentionItem(id: 1, label: 'Strawberry', data: ['type' => 'fruit_mentions']),
])
TiptapEditor::make(name: 'content')
// You can also use MentionSearchStrategy::Tokenized
->mentionSearchStrategy(MentionSearchStrategy::StartsWith)
use FilamentTiptapEditor\Concerns\HasFormMentions;
class YourClass
{
use HasFormMentions;
TiptapEditor::make(name: 'content')
->getMentionItemsUsing(function (string $query) {
// Get suggestions based of the $query
return User::search($query)->get()->map(fn ($user) => new MentionItem(
id: $user->id,
label: $user->name
))->take(5)->toArray();
})
TiptapEditor::make(name: 'content')
->mentionItems([
new MentionItem(id: 1, label: 'John Doe', image: 'YOUR_IMAGE_URL'),
// Optional: Show rounded image, useful for avatars
new MentionItem(id: 1, label: 'John Doe', image: 'YOUR_IMAGE_URL', roundedImage: true),
])
TiptapEditor::make(name: 'content')
// Customize the "No results found" message
->emptyMentionItemsMessage("No users found")
// Set a custom placeholder message. Note: if you set a placeholder, then it will ONLY show suggestions when the query is not empty.
->mentionItemsPlaceholder("Search for users...")
// Customize how many mention items should be shown at once, 8 by default. Is nullable and only works with static suggestions.
->maxMentionItems()
// Set a custom character trigger for mentioning. This is '@' by default
->mentionTrigger('#')
namespace App\TiptapExtensions;
use Tiptap\Core\Node;
class Hero extends Node
{
public static $name = 'hero';
...
}