Skip to content

Commit

Permalink
Fix: empty state
Browse files Browse the repository at this point in the history
  • Loading branch information
awcodes committed Dec 23, 2023
1 parent 48ed6cf commit 477ef7f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
2 changes: 1 addition & 1 deletion resources/dist/filament-tiptap-editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/js/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export default function tiptap({
},
onUpdate({editor}) {
_this.updatedAt = Date.now();
_this.state = editor.getJSON();
_this.state = editor.isEmpty ? null : editor.getJSON();
},
onSelectionUpdate() {
_this.updatedAt = Date.now();
Expand Down
9 changes: 2 additions & 7 deletions src/TiptapEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function setUp(): void

$this->afterStateHydrated(function (TiptapEditor $component, string | array | null $state): void {

if (! $state || $this->isStateEmpty($state)) {
if (! $state) {
return;
}

Expand All @@ -93,7 +93,7 @@ protected function setUp(): void

$this->dehydrateStateUsing(function (TiptapEditor $component, string | array | null $state): string | array | null {

if (! $state || $this->isStateEmpty($state)) {
if (! $state) {
return null;
}

Expand Down Expand Up @@ -478,9 +478,4 @@ public function getGridLayouts(): array
{
return $this->gridLayouts;
}

private function isStateEmpty(string|array|null $state): bool
{
return tiptap_converter()->asHtml($state) === '<p></p>';
}
}

0 comments on commit 477ef7f

Please sign in to comment.