|
@@ -12,6 +12,18 @@ class CustomTableRepeater extends TableRepeater
|
12
|
12
|
|
13
|
13
|
protected bool | Closure $reorderAtStart = false;
|
14
|
14
|
|
|
15
|
+ /**
|
|
16
|
+ * @var array<string> | Closure | null
|
|
17
|
+ */
|
|
18
|
+ protected array | Closure | null $excludedAttributesForCloning = [
|
|
19
|
+ 'id',
|
|
20
|
+ 'line_number',
|
|
21
|
+ 'created_by',
|
|
22
|
+ 'updated_by',
|
|
23
|
+ 'created_at',
|
|
24
|
+ 'updated_at',
|
|
25
|
+ ];
|
|
26
|
+
|
15
|
27
|
public function spreadsheet(bool | Closure $condition = true): static
|
16
|
28
|
{
|
17
|
29
|
$this->spreadsheet = $condition;
|
|
@@ -36,6 +48,24 @@ class CustomTableRepeater extends TableRepeater
|
36
|
48
|
return $this->evaluate($this->reorderAtStart) && $this->isReorderable();
|
37
|
49
|
}
|
38
|
50
|
|
|
51
|
+ /**
|
|
52
|
+ * @param array<string> | Closure | null $attributes
|
|
53
|
+ */
|
|
54
|
+ public function excludeAttributesForCloning(array | Closure | null $attributes): static
|
|
55
|
+ {
|
|
56
|
+ $this->excludedAttributesForCloning = $attributes;
|
|
57
|
+
|
|
58
|
+ return $this;
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ /**
|
|
62
|
+ * @return array<string> | null
|
|
63
|
+ */
|
|
64
|
+ public function getExcludedAttributesForCloning(): ?array
|
|
65
|
+ {
|
|
66
|
+ return $this->evaluate($this->excludedAttributesForCloning);
|
|
67
|
+ }
|
|
68
|
+
|
39
|
69
|
protected function setUp(): void
|
40
|
70
|
{
|
41
|
71
|
parent::setUp();
|
|
@@ -59,6 +89,30 @@ class CustomTableRepeater extends TableRepeater
|
59
|
89
|
|
60
|
90
|
return $action;
|
61
|
91
|
});
|
|
92
|
+
|
|
93
|
+ $this->cloneAction(function (Action $action) {
|
|
94
|
+ return $action
|
|
95
|
+ ->action(function (array $arguments, CustomTableRepeater $component): void {
|
|
96
|
+ $newUuid = $component->generateUuid();
|
|
97
|
+ $items = $component->getState();
|
|
98
|
+
|
|
99
|
+ $clone = $items[$arguments['item']];
|
|
100
|
+
|
|
101
|
+ foreach ($component->getExcludedAttributesForCloning() as $attribute) {
|
|
102
|
+ unset($clone[$attribute]);
|
|
103
|
+ }
|
|
104
|
+
|
|
105
|
+ if ($newUuid) {
|
|
106
|
+ $items[$newUuid] = $clone;
|
|
107
|
+ } else {
|
|
108
|
+ $items[] = $clone;
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ $component->state($items);
|
|
112
|
+ $component->collapsed(false, shouldMakeComponentCollapsible: false);
|
|
113
|
+ $component->callAfterStateUpdated();
|
|
114
|
+ });
|
|
115
|
+ });
|
62
|
116
|
}
|
63
|
117
|
|
64
|
118
|
public function getView(): string
|