Skip to content

Commit af13ab7

Browse files
authored
Merge pull request #3 from codebar-ag/feature-folded-code
Feature folded code
2 parents e53f387 + 8107b52 commit af13ab7

File tree

6 files changed

+56
-2
lines changed

6 files changed

+56
-2
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public function form(Form $form): Form
4646
->lineWrapping(true)
4747
->autoCloseBrackets(true)
4848
->darkTheme(true)
49-
->foldingCode(true),
49+
->foldingCode(true)
50+
->foldedCode(true), // Folded code will fold the code on form load
5051
]);
5152
}
5253
...
@@ -65,9 +66,11 @@ public function form(Form $form): Form
6566
JsonEntry::make('json')
6667
->label('JSON')
6768
->lineNumbers(true)
69+
->lineWrapping(true)
6870
->autoCloseBrackets(true)
6971
->darkTheme(true)
70-
->foldingCode(true),
72+
->foldingCode(true)
73+
->foldedCode(true), // Folded code will fold the code on form load
7174
]);
7275
}
7376
...

resources/views/forms/components/json-input.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
{{ str_replace('.', '', $getId()) }}.setSize('100%', '100%');
5858
{{ str_replace('.', '', $getId()) }}.setValue({{ json_encode(json_encode($getState(), JSON_PRETTY_PRINT), JSON_UNESCAPED_SLASHES) }} ?? '{}');
5959
60+
@php
61+
if($getHasFoldedCode()) {
62+
echo str_replace('.', '', $getId()) . ".foldCode(CodeMirror.Pos(0, 0));";
63+
}
64+
@endphp
65+
6066
setTimeout(function() {
6167
{{ str_replace('.', '', $getId()) }}.refresh();
6268
}, 1);

resources/views/infolists/components/json-entry.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
{{ str_replace('.', '', $getId()) }}.setSize(null, '100%');
5555
{{ str_replace('.', '', $getId()) }}.setValue({{ json_encode(json_encode($getState(), JSON_PRETTY_PRINT), JSON_UNESCAPED_SLASHES) }} ?? '{}');
5656
57+
@php
58+
if($getHasFoldedCode()) {
59+
echo str_replace('.', '', $getId()) . ".foldCode(CodeMirror.Pos(0, 0));";
60+
}
61+
@endphp
62+
5763
setTimeout(function() {
5864
{{ str_replace('.', '', $getId()) }}.refresh();
5965
}, 1);

src/Concerns/HasFoldingCode.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ trait HasFoldingCode
88
{
99
protected bool|Closure $hasFoldingCode = true;
1010

11+
protected bool|Closure $hasFoldedCode = false;
12+
1113
public function foldingCode(bool|Closure $condition = true): static
1214
{
1315
$this->hasFoldingCode = $condition;
@@ -19,4 +21,17 @@ public function getHasFoldingCode(): bool
1921
{
2022
return (bool) $this->evaluate($this->hasFoldingCode);
2123
}
24+
25+
public function foldedCode(bool|Closure $condition = true): static
26+
{
27+
$this->hasFoldingCode = $condition;
28+
$this->hasFoldedCode = $condition;
29+
30+
return $this;
31+
}
32+
33+
public function getHasFoldedCode(): bool
34+
{
35+
return (bool) $this->evaluate($this->hasFoldedCode);
36+
}
2237
}

tests/JsonEntryFieldTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
expect($field->getHasFoldingCode())->toBe(true);
1515
});
1616

17+
it('can have folded code ', function () {
18+
$field = JsonEntry::make('json');
19+
20+
expect($field->getHasFoldedCode())->toBe(false);
21+
22+
$field->foldedCode(false);
23+
expect($field->getHasFoldedCode())->toBe(false);
24+
25+
$field->foldedCode(true);
26+
expect($field->getHasFoldedCode())->toBe(true);
27+
});
28+
1729
it('can have auto closing brackets code ', function () {
1830
$field = JsonEntry::make('json');
1931

tests/JsonInputFieldTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
expect($field->getHasFoldingCode())->toBe(true);
1515
});
1616

17+
it('can have folded code ', function () {
18+
$field = JsonInput::make('json');
19+
20+
expect($field->getHasFoldedCode())->toBe(false);
21+
22+
$field->foldedCode(false);
23+
expect($field->getHasFoldedCode())->toBe(false);
24+
25+
$field->foldedCode(true);
26+
expect($field->getHasFoldedCode())->toBe(true);
27+
});
28+
1729
it('can have auto closing brackets code ', function () {
1830
$field = JsonInput::make('json');
1931

0 commit comments

Comments
 (0)