Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public function form(Form $form): Form
->lineWrapping(true)
->autoCloseBrackets(true)
->darkTheme(true)
->foldingCode(true),
->foldingCode(true)
->foldedCode(true), // Folded code will fold the code on form load
]);
}
...
Expand All @@ -65,9 +66,11 @@ public function form(Form $form): Form
JsonEntry::make('json')
->label('JSON')
->lineNumbers(true)
->lineWrapping(true)
->autoCloseBrackets(true)
->darkTheme(true)
->foldingCode(true),
->foldingCode(true)
->foldedCode(true), // Folded code will fold the code on form load
]);
}
...
Expand Down
6 changes: 6 additions & 0 deletions resources/views/forms/components/json-input.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
{{ str_replace('.', '', $getId()) }}.setSize('100%', '100%');
{{ str_replace('.', '', $getId()) }}.setValue({{ json_encode(json_encode($getState(), JSON_PRETTY_PRINT), JSON_UNESCAPED_SLASHES) }} ?? '{}');

@php
if($getHasFoldedCode()) {
echo str_replace('.', '', $getId()) . ".foldCode(CodeMirror.Pos(0, 0));";
}
@endphp

setTimeout(function() {
{{ str_replace('.', '', $getId()) }}.refresh();
}, 1);
Expand Down
6 changes: 6 additions & 0 deletions resources/views/infolists/components/json-entry.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
{{ str_replace('.', '', $getId()) }}.setSize(null, '100%');
{{ str_replace('.', '', $getId()) }}.setValue({{ json_encode(json_encode($getState(), JSON_PRETTY_PRINT), JSON_UNESCAPED_SLASHES) }} ?? '{}');

@php
if($getHasFoldedCode()) {
echo str_replace('.', '', $getId()) . ".foldCode(CodeMirror.Pos(0, 0));";
}
@endphp

setTimeout(function() {
{{ str_replace('.', '', $getId()) }}.refresh();
}, 1);
Expand Down
15 changes: 15 additions & 0 deletions src/Concerns/HasFoldingCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ trait HasFoldingCode
{
protected bool|Closure $hasFoldingCode = true;

protected bool|Closure $hasFoldedCode = false;

public function foldingCode(bool|Closure $condition = true): static
{
$this->hasFoldingCode = $condition;
Expand All @@ -19,4 +21,17 @@ public function getHasFoldingCode(): bool
{
return (bool) $this->evaluate($this->hasFoldingCode);
}

public function foldedCode(bool|Closure $condition = true): static
{
$this->hasFoldingCode = $condition;
$this->hasFoldedCode = $condition;

return $this;
}

public function getHasFoldedCode(): bool
{
return (bool) $this->evaluate($this->hasFoldedCode);
}
}
12 changes: 12 additions & 0 deletions tests/JsonEntryFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
expect($field->getHasFoldingCode())->toBe(true);
});

it('can have folded code ', function () {
$field = JsonEntry::make('json');

expect($field->getHasFoldedCode())->toBe(false);

$field->foldedCode(false);
expect($field->getHasFoldedCode())->toBe(false);

$field->foldedCode(true);
expect($field->getHasFoldedCode())->toBe(true);
});

it('can have auto closing brackets code ', function () {
$field = JsonEntry::make('json');

Expand Down
12 changes: 12 additions & 0 deletions tests/JsonInputFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
expect($field->getHasFoldingCode())->toBe(true);
});

it('can have folded code ', function () {
$field = JsonInput::make('json');

expect($field->getHasFoldedCode())->toBe(false);

$field->foldedCode(false);
expect($field->getHasFoldedCode())->toBe(false);

$field->foldedCode(true);
expect($field->getHasFoldedCode())->toBe(true);
});

it('can have auto closing brackets code ', function () {
$field = JsonInput::make('json');

Expand Down