registerComponent(new $component); } foreach (['metric', 'chart', 'table', 'activity', 'calendar'] as $widget) { $this->widgets[$widget] = ['type' => $widget, 'label' => str($widget)->headline()->toString()]; } foreach (['text', 'textarea', 'email', 'number', 'select', 'checkbox', 'date', 'file'] as $field) { $this->fields[$field] = ['type' => $field, 'label' => str($field)->headline()->toString()]; } } public function registerComponent(BuilderComponent $component): void { $this->components[$component->type()] = $component; } public function component(string $type): BuilderComponent { return $this->components[$type] ?? throw new InvalidArgumentException("Unknown builder component [$type]."); } public function components(): array { return array_map(fn (BuilderComponent $c) => ['type' => $c->type(), 'label' => $c->label(), 'category' => $c->category(), 'schema' => $c->schema(), 'defaults' => $c->defaults()], array_values($this->components)); } public function widgets(): array { return array_values($this->widgets); } public function fields(): array { return array_values($this->fields); } }