Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
RhysLees committed Mar 22, 2024
1 parent c6c8930 commit 6a412b3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
12 changes: 8 additions & 4 deletions resources/views/forms/components/json-input.blade.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"

>
@php
ray($getStatePath())
@endphp
<div
x-data="{ state: $wire.{{ $applyStateBindingModifiers("\$entangle('{$getStatePath()}')") }} }"
class="relative rounded-md"
style="position: relative; border-radius: 0.375rem;"
x-cloak
>
<div
Expand All @@ -13,6 +17,7 @@ class="relative rounded-md"
codeMirrorEditor = CodeMirror($refs.input, {
mode: 'application/json',
lineNumbers: {{ json_encode($getHasLineNumbers()) }},
lineWrapping: {{ json_encode($getHasLineWrapping()) }},
autoCloseBrackets: {{ json_encode($getHasAutoCloseBrackets()) }},
viewportMargin: Infinity,
theme: '{{ $getHasDarkTheme() ? 'darcula' : 'default' }}',
Expand Down Expand Up @@ -52,8 +57,8 @@ class="relative rounded-md"
}
});
codeMirrorEditor.setSize(null, '100%');
codeMirrorEditor.setValue(state);
codeMirrorEditor.setSize('100%', '100%');
codeMirrorEditor.setValue(state ?? '{}');
setTimeout(function() {
codeMirrorEditor.refresh();
Expand All @@ -65,7 +70,6 @@ class="relative rounded-md"
<div
wire:ignore
x-ref="input"
class="w-full"
></div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions resources/views/infolists/components/json-entry.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<x-dynamic-component :component="$getEntryWrapperView()" :entry="$entry">
<div
class="relative rounded-md"
style="position: relative; border-radius: 0.375rem;"
x-cloak
>
<div
Expand All @@ -10,6 +10,7 @@ class="relative rounded-md"
mode: 'application/json',
readOnly: true,
lineNumbers: {{ json_encode($getHasLineNumbers()) }},
lineWrapping: {{ json_encode($getHasLineWrapping()) }},
autoCloseBrackets: {{ json_encode($getHasAutoCloseBrackets()) }},
viewportMargin: Infinity,
theme: '{{ $getHasDarkTheme() ? 'darcula' : 'default' }}',
Expand Down Expand Up @@ -50,7 +51,7 @@ class="relative rounded-md"
});
codeMirrorEditor.setSize(null, '100%');
codeMirrorEditor.setValue({{ json_encode($getState()) }});
codeMirrorEditor.setValue({{ json_encode($getState()) }} ?? '{}');
setTimeout(function() {
codeMirrorEditor.refresh();
Expand All @@ -60,7 +61,6 @@ class="relative rounded-md"
<div
wire:ignore
x-ref="input"
class="w-full"
></div>
</div>
</div>
Expand Down
22 changes: 22 additions & 0 deletions src/Concerns/HasLineWrapping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace CodebarAg\FilamentJsonField\Concerns;

use Closure;

trait HasLineWrapping
{
protected bool|Closure $hasLineWrapping = true;

public function lineWrapping(bool|Closure $condition = true): static
{
$this->hasLineWrapping = $condition;

return $this;
}

public function getHasLineWrapping(): bool
{
return (bool) $this->evaluate($this->hasLineWrapping);
}
}
2 changes: 2 additions & 0 deletions src/Forms/Components/JsonInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use CodebarAg\FilamentJsonField\Concerns\HasDarkTheme;
use CodebarAg\FilamentJsonField\Concerns\HasFoldingCode;
use CodebarAg\FilamentJsonField\Concerns\HasLineNumbers;
use CodebarAg\FilamentJsonField\Concerns\HasLineWrapping;
use Filament\Forms\Components\Concerns;
use Filament\Forms\Components\Field;

Expand All @@ -16,6 +17,7 @@ class JsonInput extends Field
use HasDarkTheme;
use HasFoldingCode;
use HasLineNumbers;
use HasLineWrapping;

protected string $view = 'filament-json-field::forms.components.json-input';
}
2 changes: 2 additions & 0 deletions src/Infolists/Components/JsonEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use CodebarAg\FilamentJsonField\Concerns\HasDarkTheme;
use CodebarAg\FilamentJsonField\Concerns\HasFoldingCode;
use CodebarAg\FilamentJsonField\Concerns\HasLineNumbers;
use CodebarAg\FilamentJsonField\Concerns\HasLineWrapping;
use Filament\Infolists\Components\Entry;

class JsonEntry extends Entry
Expand All @@ -14,6 +15,7 @@ class JsonEntry extends Entry
use HasDarkTheme;
use HasFoldingCode;
use HasLineNumbers;
use HasLineWrapping;

protected string $view = 'filament-json-field::infolists.components.json-entry';
}

0 comments on commit 6a412b3

Please sign in to comment.