Skip to content

Commit

Permalink
Merge pull request #3 from codebar-ag/feature-folded-code
Browse files Browse the repository at this point in the history
Feature folded code
  • Loading branch information
StanBarrows committed Mar 26, 2024
2 parents e53f387 + 8107b52 commit af13ab7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
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

0 comments on commit af13ab7

Please sign in to comment.