Skip to content

Commit 2a19e20

Browse files
authored
[ADVAPP-2131]: Enhance forms and admissions by integrating a series of blocks that are integrated and mapped to information in the student or prospect record (#31)
* [ADVAPP-2131]: Enhance forms and admissions by integrating a series of blocks that are integrated and mapped to information in the student or prospect record Signed-off-by: Dan Harrin <dan.harrin@canyongbs.com> * Update CI Signed-off-by: Dan Harrin <dan.harrin@canyongbs.com> * Add push Signed-off-by: Dan Harrin <dan.harrin@canyongbs.com> * fix tests Signed-off-by: Dan Harrin <dan.harrin@canyongbs.com> * remove push trigger Signed-off-by: Dan Harrin <dan.harrin@canyongbs.com> --------- Signed-off-by: Dan Harrin <dan.harrin@canyongbs.com>
1 parent 4ea237e commit 2a19e20

10 files changed

Lines changed: 171 additions & 50 deletions

File tree

.github/workflows/tests.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@ name: 'Run Tests'
22

33
on:
44
pull_request:
5-
types:
6-
- opened
7-
branches:
8-
- main
9-
paths:
10-
- '**.php'
11-
- '.github/workflows/run-tests.yml'
12-
- 'phpunit.xml.dist'
13-
- 'composer.json'
14-
- 'composer.lock'
155

166
jobs:
177
test:
@@ -21,13 +11,12 @@ jobs:
2111
fail-fast: true
2212
matrix:
2313
os: [ubuntu-latest, windows-latest]
24-
php: [8.2]
25-
laravel: [10.*]
14+
php: [8.4]
15+
laravel: [12.*]
2616
stability: [prefer-lowest, prefer-stable]
2717
include:
28-
- laravel: 10.*
29-
testbench: 8.*
30-
carbon: ^2.67
18+
- laravel: 12.*
19+
testbench: 10.*
3120

3221
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
3322

@@ -49,7 +38,7 @@ jobs:
4938
5039
- name: Install dependencies
5140
run: |
52-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
41+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
5342
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
5443
5544
- name: List Installed Dependencies

resources/views/components/menus/default-bubble-menu.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
@props([
22
'statePath' => null,
33
'tools' => [],
4+
'blocks' => [],
5+
'shouldSupportBlocks' => false,
46
'editor' => null,
57
])
68

resources/views/components/tools/blocks.blade.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,43 @@
22
'blocks' => [],
33
'key' => null,
44
'statePath' => null,
5+
'editor' => null,
56
])
67

8+
@php
9+
$hasGroups = $editor?->hasBlockGroups() ?? false;
10+
$blockGroups = $hasGroups ? ($editor?->getBlockGroups() ?? []) : [];
11+
@endphp
12+
713
<x-filament-tiptap-editor::dropdown-button
814
label="{{ trans('filament-tiptap-editor::editor.blocks.insert') }}"
915
icon="blocks"
1016
:active="true"
1117
>
12-
@foreach ($blocks as $key => $block)
13-
<x-filament-tiptap-editor::dropdown-button-item
14-
action="$wire.mountAction('insertBlock', {
15-
type: '{{ $key }}'
16-
}, { schemaComponent: '{{ $key }}' })"
17-
>
18-
{{ $block->getLabel() }}
19-
</x-filament-tiptap-editor::dropdown-button-item>
20-
@endforeach
18+
@if ($hasGroups && count($blockGroups) > 1)
19+
@foreach ($blockGroups as $groupName => $groupBlocks)
20+
<li class="px-3 py-1.5 text-xs font-semibold text-gray-700 bg-gray-100 dark:text-gray-300 dark:bg-gray-900">
21+
{{ $groupName }}
22+
</li>
23+
@foreach ($groupBlocks as $blockKey => $block)
24+
<x-filament-tiptap-editor::dropdown-button-item
25+
action="$wire.mountAction('insertBlock', {
26+
type: '{{ $blockKey }}'
27+
}, { schemaComponent: '{{ $key }}' })"
28+
>
29+
{{ $block->getLabel() }}
30+
</x-filament-tiptap-editor::dropdown-button-item>
31+
@endforeach
32+
@endforeach
33+
@else
34+
@foreach ($blocks as $key => $block)
35+
<x-filament-tiptap-editor::dropdown-button-item
36+
action="$wire.mountAction('insertBlock', {
37+
type: '{{ $key }}'
38+
}, { schemaComponent: '{{ $key }}' })"
39+
>
40+
{{ $block->getLabel() }}
41+
</x-filament-tiptap-editor::dropdown-button-item>
42+
@endforeach
43+
@endif
2144
</x-filament-tiptap-editor::dropdown-button>

resources/views/components/tools/media.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@props([
2-
'key' => $key,
2+
'key' => null,
33
'statePath' => null,
44
'icon' => 'media',
55
])

resources/views/tiptap-editor.blade.php

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class="tiptap-toolbar relative z-[1] flex flex-col divide-x divide-gray-950/10 r
104104
<x-filament-tiptap-editor::tools.blocks
105105
:blocks="$blocks"
106106
:state-path="$statePath"
107+
:editor="$field"
107108
/>
108109
@endif
109110
@else
@@ -139,6 +140,9 @@ class="tiptap-editor-bubble-menu-wrapper"
139140
<x-filament-tiptap-editor::menus.default-bubble-menu
140141
:state-path="$statePath"
141142
:tools="$bubbleMenuTools"
143+
:blocks="$blocks"
144+
:should-support-blocks="$shouldSupportBlocks"
145+
:editor="$field"
142146
/>
143147
<x-filament-tiptap-editor::menus.link-bubble-menu
144148
:state-path="$statePath"
@@ -266,22 +270,51 @@ class="grid-col-1 flex cursor-move items-center gap-2 rounded border border-gray
266270
@endforeach
267271
@endif
268272

269-
@foreach ($blocks as $block)
270-
<div
271-
class="grid-col-1 flex cursor-move items-center gap-2 rounded border border-gray-200 bg-white px-3 py-2 text-xs dark:border-gray-700 dark:bg-gray-800"
272-
draggable="true"
273-
x-on:dragstart="$event?.dataTransfer?.setData('block', @js($block->getIdentifier()))"
274-
>
275-
@if ($block->getIcon())
276-
<x-filament::icon
277-
class="h-5 w-5"
278-
:icon="$block->getIcon()"
279-
/>
273+
@if ($hasBlockGroups())
274+
@foreach ($getBlockGroups() as $groupName => $groupBlocks)
275+
@if (count($getBlockGroups()) > 1)
276+
<div class="sticky top-0 z-10 -mx-2 bg-gray-50 px-2 py-1.5 text-xs font-semibold text-gray-700 backdrop-blur-sm dark:bg-gray-950/20 dark:text-gray-300">
277+
{{ $groupName }}
278+
</div>
280279
@endif
280+
281+
<div class="space-y-1">
282+
@foreach ($groupBlocks as $key => $block)
283+
<div
284+
class="grid-col-1 flex cursor-move items-center gap-2 rounded border border-gray-200 bg-white px-3 py-2 text-xs dark:border-gray-700 dark:bg-gray-800"
285+
draggable="true"
286+
x-on:dragstart="$event?.dataTransfer?.setData('block', @js($block->getIdentifier()))"
287+
>
288+
@if ($block->getIcon())
289+
<x-filament::icon
290+
class="h-5 w-5"
291+
:icon="$block->getIcon()"
292+
/>
293+
@endif
294+
295+
{{ $block->getLabel() }}
296+
</div>
297+
@endforeach
298+
</div>
299+
@endforeach
300+
@else
301+
@foreach ($blocks as $block)
302+
<div
303+
class="grid-col-1 flex cursor-move items-center gap-2 rounded border border-gray-200 bg-white px-3 py-2 text-xs dark:border-gray-700 dark:bg-gray-800"
304+
draggable="true"
305+
x-on:dragstart="$event?.dataTransfer?.setData('block', @js($block->getIdentifier()))"
306+
>
307+
@if ($block->getIcon())
308+
<x-filament::icon
309+
class="h-5 w-5"
310+
:icon="$block->getIcon()"
311+
/>
312+
@endif
281313

282-
{{ $block->getLabel() }}
283-
</div>
284-
@endforeach
314+
{{ $block->getLabel() }}
315+
</div>
316+
@endforeach
317+
@endif
285318
</div>
286319
</div>
287320
@endif

src/Extensions/Nodes/TiptapBlock.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,24 @@ public function getBlocks(): array
5656
$customBlocks = $this->options['blocks'] ?? null;
5757

5858
if (blank($customBlocks)) {
59-
return TiptapEditor::make('get_blocks')->getBlocks();
59+
return TiptapEditor::make('get_blocks')->getFlattenedBlocks();
60+
}
61+
62+
$firstValue = reset($customBlocks);
63+
$firstKey = key($customBlocks);
64+
$isGrouped = is_array($firstValue) && ! is_numeric($firstKey);
65+
66+
if ($isGrouped) {
67+
$flattened = [];
68+
69+
foreach ($customBlocks as $groupBlocks) {
70+
foreach ($groupBlocks as $block) {
71+
$blockInstance = app($block);
72+
$flattened = [...$flattened, $blockInstance->getIdentifier() => $blockInstance];
73+
}
74+
}
75+
76+
return $flattened;
6077
}
6178

6279
return collect($customBlocks)

src/TiptapEditor.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,20 +516,70 @@ public function shouldDisableStylesheet(): bool
516516

517517
public function getBlock(string $identifier): TiptapBlock
518518
{
519-
return $this->getBlocks()[$identifier];
519+
return $this->getFlattenedBlocks()[$identifier];
520520
}
521521

522522
public function getBlocks(): array
523523
{
524524
$blocks = $this->evaluate($this->blocks);
525525

526+
if ($this->hasBlockGroups()) {
527+
return collect($blocks)->map(function ($groupBlocks) {
528+
return collect($groupBlocks)->mapWithKeys(function ($block) {
529+
$b = app($block);
530+
531+
return [$b->getIdentifier() => $b];
532+
})->toArray();
533+
})->toArray();
534+
}
535+
526536
return collect($blocks)->mapWithKeys(function ($block, $key) {
527537
$b = app($block);
528538

529539
return [$b->getIdentifier() => $b];
530540
})->toArray();
531541
}
532542

543+
public function hasBlockGroups(): bool
544+
{
545+
$blocks = $this->evaluate($this->blocks);
546+
547+
if (empty($blocks)) {
548+
return false;
549+
}
550+
551+
$firstValue = reset($blocks);
552+
$firstKey = key($blocks);
553+
554+
return is_array($firstValue) && ! is_numeric($firstKey);
555+
}
556+
557+
public function getBlockGroups(): array
558+
{
559+
if (! $this->hasBlockGroups()) {
560+
return [];
561+
}
562+
563+
return $this->getBlocks();
564+
}
565+
566+
public function getFlattenedBlocks(): array
567+
{
568+
$blocks = $this->getBlocks();
569+
570+
if ($this->hasBlockGroups()) {
571+
$flattened = [];
572+
573+
foreach ($blocks as $groupBlocks) {
574+
$flattened = [...$flattened, ...$groupBlocks];
575+
}
576+
577+
return $flattened;
578+
}
579+
580+
return $blocks;
581+
}
582+
533583
public function getTools(): array
534584
{
535585
$extensions = collect($this->extensions);

tests/src/FormsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use Filament\Forms\Components\TextInput;
4-
use Filament\Forms\Form;
4+
use Filament\Schemas\Schema;
55
use FilamentTiptapEditor\Enums\TiptapOutput;
66
use FilamentTiptapEditor\Tests\Fixtures\Livewire as LivewireFixture;
77
use FilamentTiptapEditor\Tests\Models\Page;
@@ -84,9 +84,9 @@
8484

8585
class TestComponentWithForm extends LivewireFixture
8686
{
87-
public function form(Form $form): Form
87+
public function form(Schema $schema): Schema
8888
{
89-
return $form
89+
return $schema
9090
->statePath('data')
9191
->model(Page::class)
9292
->schema([

tests/src/Resources/PageResource.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace FilamentTiptapEditor\Tests\Resources;
44

5+
use BackedEnum;
56
use Filament\Forms;
6-
use Filament\Forms\Form;
77
use Filament\Resources\Resource;
8+
use Filament\Schemas\Schema;
89
use Filament\Tables;
910
use Filament\Tables\Table;
1011
use FilamentTiptapEditor\Enums\TiptapOutput;
@@ -16,11 +17,11 @@ class PageResource extends Resource
1617
{
1718
protected static ?string $model = Page::class;
1819

19-
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
20+
protected static string | BackedEnum | null $navigationIcon = 'heroicon-o-rectangle-stack';
2021

21-
public static function form(Form $form): Form
22+
public static function form(Schema $schema): Schema
2223
{
23-
return $form
24+
return $schema
2425
->schema([
2526
Forms\Components\TextInput::make('title'),
2627
TiptapEditor::make('json_content')

tests/src/TestCase.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Filament\Forms\FormsServiceProvider;
1010
use Filament\Infolists\InfolistsServiceProvider;
1111
use Filament\Notifications\NotificationsServiceProvider;
12+
use Filament\Schemas\SchemasServiceProvider;
1213
use Filament\Support\SupportServiceProvider;
1314
use Filament\Tables\TablesServiceProvider;
1415
use Filament\Widgets\WidgetsServiceProvider;
@@ -24,13 +25,14 @@ class TestCase extends Orchestra
2425

2526
protected function getPackageProviders($app): array
2627
{
27-
return [
28+
$packages = [
2829
ActionsServiceProvider::class,
2930
BladeCaptureDirectiveServiceProvider::class,
3031
BladeHeroiconsServiceProvider::class,
3132
BladeIconsServiceProvider::class,
3233
FilamentServiceProvider::class,
3334
FormsServiceProvider::class,
35+
SchemasServiceProvider::class,
3436
InfolistsServiceProvider::class,
3537
LivewireServiceProvider::class,
3638
NotificationsServiceProvider::class,
@@ -40,6 +42,10 @@ protected function getPackageProviders($app): array
4042
AdminPanelProvider::class,
4143
FilamentTiptapEditorServiceProvider::class,
4244
];
45+
46+
sort($packages);
47+
48+
return $packages;
4349
}
4450

4551
protected function defineDatabaseMigrations(): void

0 commit comments

Comments
 (0)