Skip to content

Commit

Permalink
Merge pull request #131 from lara-zeus/add-tiptap
Browse files Browse the repository at this point in the history
Add tiptap editor
  • Loading branch information
atmonshi authored Aug 16, 2023
2 parents a68fc85 + 4929c82 commit 49730de
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 78 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
"filament/spatie-laravel-media-library-plugin": "^3.0@beta",
"filament/spatie-laravel-tags-plugin": "^3.0@beta",
"spatie/laravel-medialibrary": "^10.0.0",
"awcodes/filament-tiptap-editor": "^3.0",
"spatie/laravel-sluggable": "^3.3",
"spatie/laravel-tags": "^4.4",
"andrewdwallo/filament-selectify": "^2.0",
"lara-zeus/core": "^3.0"
},
"require-dev": {
Expand Down
31 changes: 18 additions & 13 deletions src/Filament/Resources/FaqResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LaraZeus\Sky\Filament\Resources;

use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\SpatieTagsInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Form;
Expand Down Expand Up @@ -46,21 +47,25 @@ public static function form(Form $form): Form
{
return $form
->schema([
Textarea::make('question')
->label(__('Question'))
->required()
->maxLength(65535)
->columnSpan(2),
Section::make(__('Library File'))
->columns(2)
->schema([
Textarea::make('question')
->label(__('Question'))
->required()
->maxLength(65535)
->columnSpan(2),

RichEditor::make('answer')
->label(__('Answer'))
->required()
->maxLength(65535)
->columnSpan(2),
RichEditor::make('answer')
->label(__('Answer'))
->required()
->maxLength(65535)
->columnSpan(2),

SpatieTagsInput::make('category')
->type('faq')
->label(__('FAQ Categories')),
SpatieTagsInput::make('category')
->type('faq')
->label(__('FAQ Categories')),
]),
]);
}

Expand Down
82 changes: 42 additions & 40 deletions src/Filament/Resources/LibraryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LaraZeus\Sky\Filament\Resources;

use Filament\Forms\Components\Radio;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
Expand All @@ -24,6 +23,7 @@
use LaraZeus\Sky\Filament\Resources\LibraryResource\Pages;
use LaraZeus\Sky\Models\Library;
use LaraZeus\Sky\SkyPlugin;
use Wallo\FilamentSelectify\Components\ButtonGroup;

class LibraryResource extends SkyResource
{
Expand All @@ -42,56 +42,59 @@ public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')
->label(__('Library Title'))
->required()
->maxLength(255)
->live(onBlur: true)
->afterStateUpdated(function (Set $set, $state, $context) {
if ($context === 'edit') {
return;
}

$set('slug', Str::slug($state));
}),

TextInput::make('slug')
->unique(ignorable: fn (?Library $record): ?Library => $record)
->required()
->maxLength(255)
->label(__('Library Slug')),

Textarea::make('description')
->maxLength(255)
->label(__('Library Description'))
->columnSpan(2),

SpatieTagsInput::make('category')
->type('library')
->label(__('Library Categories')),

Select::make('type')
->label(__('Library Type'))
->visible(SkyPlugin::get()->getLibraryTypes() !== null)
->options(SkyPlugin::get()->getLibraryTypes()),
Section::make(__('Library File'))
->columns(2)
->schema([
TextInput::make('title')
->label(__('Library Title'))
->required()
->maxLength(255)
->live(onBlur: true)
->afterStateUpdated(function (Set $set, $state, $context) {
if ($context === 'edit') {
return;
}

$set('slug', Str::slug($state));
}),

TextInput::make('slug')
->unique(ignorable: fn (?Library $record): ?Library => $record)
->required()
->maxLength(255)
->label(__('Library Slug')),

Textarea::make('description')
->maxLength(255)
->label(__('Library Description'))
->columnSpan(2),

SpatieTagsInput::make('category')
->type('library')
->label(__('Library Categories')),

Select::make('type')
->label(__('Library Type'))
->visible(SkyPlugin::get()->getLibraryTypes() !== null)
->options(SkyPlugin::get()->getLibraryTypes()),
]),

Section::make(__('Library File'))
->collapsible()
->compact()
->schema([
Radio::make('upload_or_url')
->label('')
ButtonGroup::make('upload_or_url')
->live()
->dehydrated(false)
->afterStateHydrated(function (Set $set, Get $get) {
$setVal = ($get('file_path') === null) ? 'upload' : 'url';
$set('upload_or_url', $setVal);
})
->default('upload')
->options([
'upload' => __('upload'),
'url' => __('url'),
])
->inline(),

->default('upload'),
SpatieMediaLibraryFileUpload::make('file_path_upload')
->collection('library')
->multiple()
Expand All @@ -103,8 +106,7 @@ public static function form(Form $form): Form
->label(__('file url'))
->visible(fn (Get $get) => $get('upload_or_url') === 'url')
->url(),
])
->collapsible(),
]),
]);
}

Expand Down
9 changes: 4 additions & 5 deletions src/Filament/Resources/PageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\Tabs;
Expand Down Expand Up @@ -34,6 +33,7 @@
use LaraZeus\Sky\Filament\Resources\PageResource\Pages;
use LaraZeus\Sky\Models\Post;
use LaraZeus\Sky\SkyPlugin;
use Wallo\FilamentSelectify\Components\ButtonGroup;

class PageResource extends SkyResource
{
Expand Down Expand Up @@ -124,20 +124,19 @@ public static function form(Form $form): Form
]),
Tabs\Tab::make(__('Image'))->schema([
Placeholder::make(__('Featured Image')),
Radio::make('featured_image_type')
->label('')
ButtonGroup::make('featured_image_type')
->live()
->label('')
->dehydrated(false)
->afterStateHydrated(function (Set $set, Get $get) {
$setVal = ($get('featured_image') === null) ? 'upload' : 'url';
$set('featured_image_type', $setVal);
})
->default('upload')
->options([
'upload' => __('upload'),
'url' => __('url'),
])
->inline(),
->default('upload'),
SpatieMediaLibraryFileUpload::make('featured_image_upload')
->collection('pages')
->visible(fn (Get $get) => $get('featured_image_type') === 'upload')
Expand Down
10 changes: 4 additions & 6 deletions src/Filament/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\SpatieTagsInput;
Expand Down Expand Up @@ -35,6 +34,7 @@
use LaraZeus\Sky\Filament\Resources\PostResource\Pages;
use LaraZeus\Sky\Models\Post;
use LaraZeus\Sky\SkyPlugin;
use Wallo\FilamentSelectify\Components\ButtonGroup;

// @mixin Builder<PostScope>
class PostResource extends SkyResource
Expand Down Expand Up @@ -126,21 +126,19 @@ public static function form(Form $form): Form

Tabs\Tab::make(__('Image'))->schema([
Placeholder::make(__('Featured Image')),
Radio::make('featured_image_type')
->label('')
ButtonGroup::make('featured_image_type')
->live()
->label('')
->dehydrated(false)
->afterStateHydrated(function (Set $set, Get $get) {
$setVal = ($get('featured_image') === null) ? 'upload' : 'url';
$set('featured_image_type', $setVal);
})
->default('upload')
->options([
'upload' => __('upload'),
'url' => __('url'),
])
->inline(),

->default('upload'),
SpatieMediaLibraryFileUpload::make('featured_image_upload')
->collection('posts')
->visible(fn (Get $get) => $get('featured_image_type') === 'upload')
Expand Down
34 changes: 20 additions & 14 deletions src/Filament/Resources/TagResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LaraZeus\Sky\Filament\Resources;

use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
Expand Down Expand Up @@ -34,20 +35,25 @@ public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->required()
->maxLength(255)
->label(__('Tag.Name'))
->live(onBlur: true)
->afterStateUpdated(function (Set $set, $state) {
$set('slug', Str::slug($state));
}),
TextInput::make('slug')
->unique(ignorable: fn (?Model $record): ?Model => $record)
->required()
->maxLength(255),
Select::make('type')
->options(SkyPlugin::get()->getTagTypes()),
Section::make()
->columns(2)
->schema([
TextInput::make('name')
->required()
->maxLength(255)
->label(__('Tag.Name'))
->live(onBlur: true)
->afterStateUpdated(function (Set $set, $state) {
$set('slug', Str::slug($state));
}),
TextInput::make('slug')
->unique(ignorable: fn (?Model $record): ?Model => $record)
->required()
->maxLength(255),
Select::make('type')
->columnSpan(2)
->options(SkyPlugin::get()->getTagTypes()),
]),
]);
}

Expand Down

0 comments on commit 49730de

Please sign in to comment.