Skip to content

Commit

Permalink
fix: clone StackFields
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Oct 20, 2024
1 parent 3eb617f commit f7816d1
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/UI/src/Fields/StackFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,6 @@ class StackFields extends Field implements HasFieldsContract, FieldsWrapperContr

protected string $view = 'moonshine::fields.stack';

protected bool $withWrapper = false;

protected bool $withLabels = false;

public function withLabels(): static
{
$this->withLabels = true;

return $this;
}

public function hasLabels(): bool
{
return $this->withLabels;
}

/**
* @throws Throwable
*/
Expand All @@ -62,13 +46,12 @@ protected function resolveFill(
protected function resolvePreview(): Renderable|string
{
return FieldsGroup::make(
$this->getFields()->onlyFields()
$this->getFields()
)
->mapFields(fn (FieldContract $field, int $index): FieldContract => $field
->fillData($this->getData())
->beforeRender(fn (): string => $this->hasLabels() || $index === 0 ? '' : (string) LineBreak::make())
->withoutWrapper($this->hasLabels())
->previewMode())
->previewMode()
)
->render();
}

Expand Down Expand Up @@ -143,4 +126,20 @@ protected function viewData(): array
'fields' => $this->getFields(),
];
}

/**
* @throws Throwable
*/
public function __clone()
{
if(!$this->fields instanceof Closure) {
$fields = [];

foreach ($this->getRawFields() as $index => $field) {
$fields[$index] = clone $field;
}

$this->fields($fields);
}
}
}

0 comments on commit f7816d1

Please sign in to comment.