Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
266
vendor/filament/schemas/src/Components/Actions.php
vendored
Normal file
266
vendor/filament/schemas/src/Components/Actions.php
vendored
Normal file
|
|
@ -0,0 +1,266 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Schemas\Components\Concerns\HasLabel;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\HasAlignment;
|
||||
use Filament\Support\Concerns\HasVerticalAlignment;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Support\Enums\VerticalAlignment;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class Actions extends Component implements HasEmbeddedView
|
||||
{
|
||||
use HasAlignment;
|
||||
use HasLabel;
|
||||
use HasVerticalAlignment;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.actions';
|
||||
|
||||
protected bool | Closure $isSticky = false;
|
||||
|
||||
protected bool | Closure $isFullWidth = false;
|
||||
|
||||
const BEFORE_LABEL_SCHEMA_KEY = 'before_label';
|
||||
|
||||
const AFTER_LABEL_SCHEMA_KEY = 'after_label';
|
||||
|
||||
const ABOVE_CONTENT_SCHEMA_KEY = 'above_content';
|
||||
|
||||
const BELOW_CONTENT_SCHEMA_KEY = 'below_content';
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup> | Closure $actions
|
||||
*/
|
||||
final public function __construct(array | Closure $actions)
|
||||
{
|
||||
$this->actions($actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup> | Closure $actions
|
||||
*/
|
||||
public static function make(array | Closure $actions): static
|
||||
{
|
||||
$static = app(static::class, ['actions' => $actions]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup> | Closure $actions
|
||||
*/
|
||||
public function actions(array | Closure $actions): static
|
||||
{
|
||||
$this->components($actions);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isHidden(): bool
|
||||
{
|
||||
if (parent::isHidden()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->getChildSchema()->getComponents() as $component) {
|
||||
if ($component->isVisible()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function fullWidth(bool | Closure $isFullWidth = true): static
|
||||
{
|
||||
$this->isFullWidth = $isFullWidth;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isFullWidth(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isFullWidth);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function beforeLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BEFORE_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function afterLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::AFTER_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function aboveContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::ABOVE_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function belowContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BELOW_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function makeChildSchema(string $key): Schema
|
||||
{
|
||||
$schema = parent::makeChildSchema($key);
|
||||
|
||||
if ($key === static::AFTER_LABEL_SCHEMA_KEY) {
|
||||
$schema->alignEnd();
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
protected function configureChildSchema(Schema $schema, string $key): Schema
|
||||
{
|
||||
$schema = parent::configureChildSchema($schema, $key);
|
||||
|
||||
if (in_array($key, [
|
||||
static::BEFORE_LABEL_SCHEMA_KEY,
|
||||
static::AFTER_LABEL_SCHEMA_KEY,
|
||||
static::ABOVE_CONTENT_SCHEMA_KEY,
|
||||
static::BELOW_CONTENT_SCHEMA_KEY,
|
||||
])) {
|
||||
$schema
|
||||
->inline()
|
||||
->embeddedInParentComponent()
|
||||
->modifyActionsUsing(fn (Action $action) => $action
|
||||
->defaultSize(Size::Small)
|
||||
->defaultView(Action::LINK_VIEW))
|
||||
->modifyActionGroupsUsing(fn (ActionGroup $actionGroup) => $actionGroup->defaultSize(Size::Small));
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public function sticky(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isSticky = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isSticky(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isSticky);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$actions = $this->getChildSchema()->getComponents();
|
||||
$alignment = $this->getAlignment();
|
||||
$isFullWidth = $this->isFullWidth();
|
||||
$isSticky = $this->isSticky();
|
||||
$verticalAlignment = $this->getVerticalAlignment();
|
||||
|
||||
if (! $verticalAlignment instanceof VerticalAlignment) {
|
||||
$verticalAlignment = filled($verticalAlignment) ? (VerticalAlignment::tryFrom($verticalAlignment) ?? $verticalAlignment) : null;
|
||||
}
|
||||
|
||||
if (! $alignment instanceof Alignment) {
|
||||
$alignment = filled($alignment) ? (Alignment::tryFrom($alignment) ?? $alignment) : null;
|
||||
}
|
||||
|
||||
// Filter to visible actions
|
||||
$visibleActions = array_filter(
|
||||
$actions,
|
||||
fn ($action): bool => $action->isVisible(),
|
||||
);
|
||||
|
||||
$outerAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'id' => $this->getId(),
|
||||
], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->class([
|
||||
'fi-sc-actions',
|
||||
($verticalAlignment instanceof VerticalAlignment) ? "fi-vertical-align-{$verticalAlignment->value}" : $verticalAlignment,
|
||||
]);
|
||||
|
||||
$label = $this->getLabel();
|
||||
$beforeLabelSchema = $this->getChildSchema(static::BEFORE_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$afterLabelSchema = $this->getChildSchema(static::AFTER_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$aboveContentSchema = $this->getChildSchema(static::ABOVE_CONTENT_SCHEMA_KEY)?->toHtmlString();
|
||||
$belowContentSchema = $this->getChildSchema(static::BELOW_CONTENT_SCHEMA_KEY)?->toHtmlString();
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div
|
||||
<?php if ($isSticky) { ?>
|
||||
x-data="filamentActionsSchemaComponent()"
|
||||
x-intersect:enter.half="disableSticky"
|
||||
x-intersect:leave="enableSticky"
|
||||
x-bind:class="{ 'fi-sticky': isSticky }"
|
||||
<?php } ?>
|
||||
<?= $outerAttributes->toHtml() ?>
|
||||
>
|
||||
<?php if (filled($label)) { ?>
|
||||
<div class="fi-sc-actions-label-ctn">
|
||||
<?= $beforeLabelSchema?->toHtml() ?>
|
||||
|
||||
<div class="fi-sc-actions-label">
|
||||
<?= e($label) ?>
|
||||
</div>
|
||||
|
||||
<?= $afterLabelSchema?->toHtml() ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?= $aboveContentSchema?->toHtml() ?>
|
||||
|
||||
<?php if (filled($visibleActions)) { ?>
|
||||
<div
|
||||
<?= (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'x-bind:style' => $isSticky ? 'isSticky ? `width: ${width}px;` : \'\'' : null,
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-ac',
|
||||
'fi-width-full' => $isFullWidth,
|
||||
(($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : (is_string($alignment) ? $alignment : '')) => ! $isFullWidth,
|
||||
])->toHtml() ?>
|
||||
>
|
||||
<?php foreach ($visibleActions as $action) { ?>
|
||||
<?= $action->toHtml() ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?= $belowContentSchema?->toHtml() ?>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
339
vendor/filament/schemas/src/Components/Callout.php
vendored
Normal file
339
vendor/filament/schemas/src/Components/Callout.php
vendored
Normal file
|
|
@ -0,0 +1,339 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Schemas\Components\Concerns\HasDescription;
|
||||
use Filament\Schemas\Components\Concerns\HasFooterActions;
|
||||
use Filament\Schemas\Components\Concerns\HasHeading;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Schemas\View\SchemaIconAlias;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\HasColor;
|
||||
use Filament\Support\Concerns\HasIcon;
|
||||
use Filament\Support\Concerns\HasIconColor;
|
||||
use Filament\Support\Concerns\HasIconSize;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Support\Facades\FilamentIcon;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Support\View\Components\CalloutComponent;
|
||||
use Filament\Support\View\Components\CalloutComponent\IconComponent;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
use function Filament\Support\generate_icon_html;
|
||||
|
||||
class Callout extends Component implements HasEmbeddedView
|
||||
{
|
||||
use HasColor {
|
||||
color as baseColor;
|
||||
getColor as getBaseColor;
|
||||
}
|
||||
use HasDescription;
|
||||
use HasFooterActions;
|
||||
use HasHeading;
|
||||
use HasIcon {
|
||||
getIcon as getBaseIcon;
|
||||
}
|
||||
use HasIconColor {
|
||||
getIconColor as getBaseIconColor;
|
||||
}
|
||||
use HasIconSize;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.callout';
|
||||
|
||||
public const FOOTER_SCHEMA_KEY = 'footer';
|
||||
|
||||
public const CONTROLS_SCHEMA_KEY = 'controls';
|
||||
|
||||
protected bool $hasColor = false;
|
||||
|
||||
protected string | Closure | null $status = null;
|
||||
|
||||
/**
|
||||
* @var array<Action | Closure>
|
||||
*/
|
||||
protected array $controlActions = [];
|
||||
|
||||
final public function __construct(string | Htmlable | Closure | null $heading = null)
|
||||
{
|
||||
$this->heading($heading);
|
||||
}
|
||||
|
||||
public static function make(string | Htmlable | Closure | null $heading = null): static
|
||||
{
|
||||
$static = app(static::class, ['heading' => $heading]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->footer(function (Callout $component): Schema {
|
||||
return match ($component->getFooterActionsAlignment()) {
|
||||
Alignment::End, Alignment::Right => Schema::end($component->getFooterActions()),
|
||||
Alignment::Center => Schema::center($component->getFooterActions()),
|
||||
Alignment::Between, Alignment::Justify => Schema::between($component->getFooterActions()),
|
||||
default => Schema::start($component->getFooterActions()),
|
||||
};
|
||||
});
|
||||
|
||||
$this->controls(function (Callout $component): Schema {
|
||||
return Schema::start($component->getControlActions());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | Closure> $actions
|
||||
*/
|
||||
public function actions(array $actions): static
|
||||
{
|
||||
$this->footerActions($actions);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function footer(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::FOOTER_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | Closure | null $color
|
||||
*/
|
||||
public function color(string | array | Closure | null $color): static
|
||||
{
|
||||
$this->hasColor = true;
|
||||
|
||||
$this->baseColor($color);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function status(string | Closure | null $status): static
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStatus(): ?string
|
||||
{
|
||||
return $this->evaluate($this->status);
|
||||
}
|
||||
|
||||
public function danger(): static
|
||||
{
|
||||
return $this->status('danger');
|
||||
}
|
||||
|
||||
public function info(): static
|
||||
{
|
||||
return $this->status('info');
|
||||
}
|
||||
|
||||
public function success(): static
|
||||
{
|
||||
return $this->status('success');
|
||||
}
|
||||
|
||||
public function warning(): static
|
||||
{
|
||||
return $this->status('warning');
|
||||
}
|
||||
|
||||
public function getIcon(): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
return $this->getBaseIcon() ?? match ($this->getStatus()) {
|
||||
'danger' => FilamentIcon::resolve(SchemaIconAlias::COMPONENTS_CALLOUT_DANGER) ?? Heroicon::OutlinedXCircle,
|
||||
'info' => FilamentIcon::resolve(SchemaIconAlias::COMPONENTS_CALLOUT_INFO) ?? Heroicon::OutlinedInformationCircle,
|
||||
'success' => FilamentIcon::resolve(SchemaIconAlias::COMPONENTS_CALLOUT_SUCCESS) ?? Heroicon::OutlinedCheckCircle,
|
||||
'warning' => FilamentIcon::resolve(SchemaIconAlias::COMPONENTS_CALLOUT_WARNING) ?? Heroicon::OutlinedExclamationCircle,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string | array<string> | null
|
||||
*/
|
||||
public function getIconColor(): string | array | null
|
||||
{
|
||||
return $this->getBaseIconColor() ?? $this->getStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string | array<string> | null
|
||||
*/
|
||||
public function getColor(): string | array | null
|
||||
{
|
||||
if ($this->hasColor) {
|
||||
return $this->getBaseColor();
|
||||
}
|
||||
|
||||
return $this->getBaseColor() ?? $this->getStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function getDefaultActions(): array
|
||||
{
|
||||
return $this->getFooterActions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | Closure> $actions
|
||||
*/
|
||||
public function controlActions(array $actions): static
|
||||
{
|
||||
$this->controlActions = [
|
||||
...$this->controlActions,
|
||||
...$actions,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function getControlActions(): array
|
||||
{
|
||||
$actions = [];
|
||||
|
||||
foreach ($this->controlActions as $controlAction) {
|
||||
foreach (Arr::wrap($this->evaluate($controlAction)) as $action) {
|
||||
$actions[] = $this->prepareAction($action);
|
||||
}
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function controls(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::CONTROLS_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$controls = $this->getChildSchema(static::CONTROLS_SCHEMA_KEY)?->toHtmlString();
|
||||
$footer = $this->getChildSchema(static::FOOTER_SCHEMA_KEY)?->toHtmlString();
|
||||
$color = $this->getColor() ?? 'gray';
|
||||
$description = $this->getDescription();
|
||||
$heading = $this->getHeading();
|
||||
$icon = $this->getIcon();
|
||||
$iconColor = $this->getIconColor() ?? $color;
|
||||
$iconSize = $this->getIconSize() ?? IconSize::Large;
|
||||
|
||||
if (filled($iconSize) && (! $iconSize instanceof IconSize)) {
|
||||
$iconSize = IconSize::tryFrom($iconSize) ?? $iconSize;
|
||||
}
|
||||
|
||||
$hasDescription = filled((string) $description);
|
||||
$hasHeading = filled($heading);
|
||||
$hasFooter = filled($footer?->toHtml());
|
||||
$hasIcon = filled($icon);
|
||||
$hasControls = filled($controls?->toHtml());
|
||||
|
||||
$status = $this->getStatus();
|
||||
$statusLabel = filled($status)
|
||||
? __("filament-schemas::components.callout.statuses.{$status}")
|
||||
: null;
|
||||
|
||||
// `__()` returns the key itself when there is no translation (e.g. a custom status), so drop it
|
||||
// rather than announcing a raw translation key to screen readers.
|
||||
if (filled($statusLabel) && str_contains($statusLabel, 'filament-schemas::')) {
|
||||
$statusLabel = null;
|
||||
}
|
||||
|
||||
$attributes = $this->getExtraAttributeBag()
|
||||
->color(CalloutComponent::class, $color)
|
||||
->class(['fi-sc-callout', 'fi-callout']);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php if ($hasIcon) { ?>
|
||||
<?= generate_icon_html(
|
||||
$icon,
|
||||
attributes: (new FilamentComponentAttributeBag(['aria-hidden' => 'true']))
|
||||
->color(IconComponent::class, $iconColor)
|
||||
->class(['fi-callout-icon']),
|
||||
size: $iconSize,
|
||||
)?->toHtml() ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasHeading || $hasDescription || $hasFooter) { ?>
|
||||
<div class="fi-callout-main">
|
||||
<?php if ($hasHeading || $hasDescription) { ?>
|
||||
<div class="fi-callout-text">
|
||||
<?php if ($hasHeading) { ?>
|
||||
<h4 class="fi-callout-heading"><?php if (filled($statusLabel)) { ?><span class="fi-sr-only"><?= e($statusLabel) ?> </span><?php } ?><?= e($heading) ?></h4>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasDescription) { ?>
|
||||
<p class="fi-callout-description"><?php if ((! $hasHeading) && filled($statusLabel)) { ?><span class="fi-sr-only"><?= e($statusLabel) ?> </span><?php } ?><?= e($description) ?></p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasFooter) { ?>
|
||||
<div class="fi-callout-footer"><?= $footer ?></div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasControls) { ?>
|
||||
<div class="fi-callout-controls"><?= $controls ?></div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
protected function configureChildSchema(Schema $schema, string $key): Schema
|
||||
{
|
||||
$schema = parent::configureChildSchema($schema, $key);
|
||||
|
||||
if ($key === static::FOOTER_SCHEMA_KEY) {
|
||||
$schema
|
||||
->inline()
|
||||
->embeddedInParentComponent()
|
||||
->modifyActionsUsing(fn (Action $action) => $action
|
||||
->defaultSize(Size::Small)
|
||||
->defaultView(Action::LINK_VIEW))
|
||||
->modifyActionGroupsUsing(fn (ActionGroup $actionGroup) => $actionGroup->defaultSize(Size::Small));
|
||||
}
|
||||
|
||||
if ($key === static::CONTROLS_SCHEMA_KEY) {
|
||||
$schema
|
||||
->inline()
|
||||
->embeddedInParentComponent()
|
||||
->modifyActionsUsing(fn (Action $action) => $action
|
||||
->defaultSize(Size::Small))
|
||||
->modifyActionGroupsUsing(fn (ActionGroup $actionGroup) => $actionGroup->defaultSize(Size::Small));
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
}
|
||||
272
vendor/filament/schemas/src/Components/Component.php
vendored
Normal file
272
vendor/filament/schemas/src/Components/Component.php
vendored
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Filament\Schemas\Components\Concerns\BelongsToContainer;
|
||||
use Filament\Schemas\Components\Concerns\BelongsToModel;
|
||||
use Filament\Schemas\Components\Concerns\CanBeDisabled;
|
||||
use Filament\Schemas\Components\Concerns\CanBeGridContainer;
|
||||
use Filament\Schemas\Components\Concerns\CanBeHidden;
|
||||
use Filament\Schemas\Components\Concerns\CanBeLiberatedFromContainerGrid;
|
||||
use Filament\Schemas\Components\Concerns\CanBeRepeated;
|
||||
use Filament\Schemas\Components\Concerns\CanPartiallyRender;
|
||||
use Filament\Schemas\Components\Concerns\CanPoll;
|
||||
use Filament\Schemas\Components\Concerns\Cloneable;
|
||||
use Filament\Schemas\Components\Concerns\HasActions;
|
||||
use Filament\Schemas\Components\Concerns\HasChildComponents;
|
||||
use Filament\Schemas\Components\Concerns\HasEntryWrapper;
|
||||
use Filament\Schemas\Components\Concerns\HasFieldWrapper;
|
||||
use Filament\Schemas\Components\Concerns\HasHeadings;
|
||||
use Filament\Schemas\Components\Concerns\HasId;
|
||||
use Filament\Schemas\Components\Concerns\HasInlineLabel;
|
||||
use Filament\Schemas\Components\Concerns\HasKey;
|
||||
use Filament\Schemas\Components\Concerns\HasMaxWidth;
|
||||
use Filament\Schemas\Components\Concerns\HasMeta;
|
||||
use Filament\Schemas\Components\Concerns\HasState;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\Utilities\Set;
|
||||
use Filament\Schemas\Concerns\HasColumns;
|
||||
use Filament\Schemas\Concerns\HasGap;
|
||||
use Filament\Schemas\Concerns\HasStateBindingModifiers;
|
||||
use Filament\Support\Components\ViewComponent;
|
||||
use Filament\Support\Concerns\CanGrow;
|
||||
use Filament\Support\Concerns\CanOrderColumns;
|
||||
use Filament\Support\Concerns\CanSpanColumns;
|
||||
use Filament\Support\Concerns\HasExtraAttributes;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
use Illuminate\View\ComponentSlot;
|
||||
|
||||
class Component extends ViewComponent
|
||||
{
|
||||
use BelongsToContainer;
|
||||
use BelongsToModel;
|
||||
use CanBeDisabled;
|
||||
use CanBeGridContainer;
|
||||
use CanBeHidden;
|
||||
use CanBeLiberatedFromContainerGrid;
|
||||
use CanBeRepeated;
|
||||
use CanGrow;
|
||||
use CanOrderColumns;
|
||||
use CanPartiallyRender;
|
||||
use CanPoll;
|
||||
use CanSpanColumns;
|
||||
use Cloneable;
|
||||
use HasActions;
|
||||
use HasChildComponents;
|
||||
use HasColumns;
|
||||
use HasEntryWrapper;
|
||||
use HasExtraAttributes;
|
||||
use HasFieldWrapper;
|
||||
use HasGap;
|
||||
use HasHeadings;
|
||||
use HasId;
|
||||
use HasInlineLabel;
|
||||
use HasKey;
|
||||
use HasMaxWidth;
|
||||
use HasMeta;
|
||||
use HasState;
|
||||
use HasStateBindingModifiers;
|
||||
|
||||
protected string $evaluationIdentifier = 'component';
|
||||
|
||||
protected string $viewIdentifier = 'schemaComponent';
|
||||
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
protected function resolveDefaultClosureDependencyForEvaluationByName(string $parameterName): array
|
||||
{
|
||||
return match ($parameterName) {
|
||||
'context', 'operation' => [$this->getContainer()->getOperation()],
|
||||
'get' => [$this->makeGetUtility()],
|
||||
'livewire' => [$this->getLivewire()],
|
||||
'model' => [$this->getModel()],
|
||||
'parentRepeaterItemIndex' => [$this->getParentRepeaterItemIndex()],
|
||||
'rawState' => [$this->getRawState()],
|
||||
'record' => [$this->getRecord()],
|
||||
'set' => [$this->makeSetUtility()],
|
||||
'state' => [$this->getState()],
|
||||
default => parent::resolveDefaultClosureDependencyForEvaluationByName($parameterName),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
protected function resolveDefaultClosureDependencyForEvaluationByType(string $parameterType): array
|
||||
{
|
||||
$record = is_a($parameterType, Model::class, allow_string: true) ? $this->getRecord() : null;
|
||||
|
||||
if ((! $record) || is_array($record)) {
|
||||
return match ($parameterType) {
|
||||
Get::class => [$this->makeGetUtility()],
|
||||
Set::class => [$this->makeSetUtility()],
|
||||
default => parent::resolveDefaultClosureDependencyForEvaluationByType($parameterType),
|
||||
};
|
||||
}
|
||||
|
||||
return match ($parameterType) {
|
||||
Model::class, $record::class => [$record],
|
||||
default => parent::resolveDefaultClosureDependencyForEvaluationByType($parameterType),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getExtraViewData(): array
|
||||
{
|
||||
return [
|
||||
'get' => $this->makeGetUtility(),
|
||||
'operation' => $this->getContainer()->getOperation(),
|
||||
'record' => $this->getRecord(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Do not use this method outside the internals of Filament. It is subject to breaking changes in minor and patch releases.
|
||||
*/
|
||||
public function toSchemaHtml(?bool $isVisible = null): string
|
||||
{
|
||||
$isVisible ??= $this->isVisible();
|
||||
|
||||
$container = $this->getContainer();
|
||||
|
||||
$isContainerEmbeddedInParentComponent = $container->isEmbeddedInParentComponent();
|
||||
$containerParentComponent = $isContainerEmbeddedInParentComponent
|
||||
? $container->getParentComponent()
|
||||
: null;
|
||||
$containerStatePath = $isContainerEmbeddedInParentComponent
|
||||
? $containerParentComponent->getContainer()->getStatePath()
|
||||
: $container->getStatePath();
|
||||
|
||||
/**
|
||||
* Instead of only rendering the hidden components, we should
|
||||
* render the `<div>` wrappers for all fields, regardless of
|
||||
* if they are hidden or not. This is to solve Livewire DOM
|
||||
* diffing issues.
|
||||
*
|
||||
* Additionally, any `<div>` elements that wrap hidden
|
||||
* components need to have `class="fi-hidden"`, so that they
|
||||
* don't consume grid space.
|
||||
*/
|
||||
$hiddenJs = $this->getHiddenJs();
|
||||
$visibleJs = $this->getVisibleJs();
|
||||
|
||||
$visibilityJs = match ([filled($hiddenJs), filled($visibleJs)]) {
|
||||
[true, true] => "(! ({$hiddenJs})) && ({$visibleJs})",
|
||||
[true, false] => "! ({$hiddenJs})",
|
||||
[false, true] => $visibleJs,
|
||||
default => null,
|
||||
};
|
||||
|
||||
// A component with a client-side visibility condition is wrapped in a `<fieldset>`
|
||||
// that is `disabled` while hidden, which bars its controls from native browser
|
||||
// validation. Otherwise, the browser would silently block form submission over an
|
||||
// invalid control that it cannot focus or anchor a validation bubble to. Unlike
|
||||
// concealing containers such as collapsed sections, these components cannot be
|
||||
// revealed on demand when they contain an invalid control. The `disabled` attribute
|
||||
// is rendered so that the controls are also barred before Alpine.js applies
|
||||
// `x-bind:disabled`.
|
||||
$wrapperTag = ($isVisible && filled($visibilityJs)) ? 'fieldset' : 'div';
|
||||
|
||||
$maxWidth = $this->getMaxWidth();
|
||||
|
||||
$statePath = $isContainerEmbeddedInParentComponent
|
||||
? $containerParentComponent->getStatePath()
|
||||
: $this->getStatePath();
|
||||
|
||||
$key = $this->getKey();
|
||||
|
||||
$attributes = (new FilamentComponentAttributeBag)
|
||||
->when(
|
||||
! $container->isInline(),
|
||||
fn (ComponentAttributeBag $attributes) => $attributes->gridColumn($this->getColumnSpan(), $this->getColumnStart(), $this->getColumnOrder(), ! $isVisible),
|
||||
)
|
||||
->merge([
|
||||
'wire:key' => $this->getLivewireKey(),
|
||||
...(($pollingInterval = $this->getPollingInterval()) ? ["wire:poll.{$pollingInterval}" => "partiallyRenderSchemaComponent('{$this->getKey()}')"] : []),
|
||||
], escape: false)
|
||||
->class([
|
||||
($maxWidth instanceof Width) ? "fi-width-{$maxWidth->value}" : $maxWidth,
|
||||
'fi-growable' => $container->isInline() && $this->canGrow(default: false),
|
||||
'fi-sc-visibility-fieldset' => $wrapperTag === 'fieldset',
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<<?= $wrapperTag ?>
|
||||
<?php if ($wrapperTag === 'fieldset') { ?>
|
||||
disabled
|
||||
role="none"
|
||||
<?php } ?>
|
||||
<?php if (filled($key)) { ?>
|
||||
wire:partial="schema-component::<?= $key ?>"
|
||||
<?php } ?>
|
||||
<?php if ($isVisible) { ?>
|
||||
x-data="filamentSchemaComponent({
|
||||
path: <?= Js::from($statePath) ?>,
|
||||
containerPath: <?= Js::from($containerStatePath) ?>,
|
||||
$wire,
|
||||
})"
|
||||
<?php if ($afterStateUpdatedJs = $this->getAfterStateUpdatedJs()) { ?>
|
||||
x-init="<?= implode(';', array_map(
|
||||
fn (string $js): string => '$wire; $wire.watch(' . Js::from($statePath) . ', ($state, $old) => isStateChanged($state, $old) && eval(' . Js::from($js) . '))',
|
||||
$afterStateUpdatedJs,
|
||||
)) ?>"
|
||||
<?php } ?>
|
||||
<?php if (filled($visibilityJs)) { ?>
|
||||
x-bind:class="{ 'fi-hidden': ! (<?= $visibilityJs ?>) }"
|
||||
x-bind:disabled="! (<?= $visibilityJs ?>)"
|
||||
x-cloak
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<?= $attributes->toHtml() ?>
|
||||
>
|
||||
<?php if ($isVisible) { ?>
|
||||
<div
|
||||
class="<?= Arr::toCssClasses([
|
||||
'fi-sc-component',
|
||||
'fi-grid-ctn' => $this->isGridContainer(),
|
||||
]) ?>"
|
||||
>
|
||||
<?= $this->toHtml() ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</<?= $wrapperTag ?>>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal This method is not part of the public API and should not be used. Its parameters may change at any time without notice.
|
||||
*/
|
||||
protected function renderWrapperBladeComponent(string $component, ComponentSlot $slot, ComponentAttributeBag $attributes): string
|
||||
{
|
||||
// Wrappers were originally rendered using the `<x-dynamic-component>` Blade component,
|
||||
// so `fieldWrapperView()` and `entryWrapperView()` accepted any Blade component name,
|
||||
// which is still supported for backwards compatibility.
|
||||
return Blade::render(
|
||||
'<x-dynamic-component :component="$component" {{ $attributes }}>{{ $slot }}</x-dynamic-component>',
|
||||
[
|
||||
'component' => $component,
|
||||
'attributes' => $attributes,
|
||||
'slot' => $slot,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Fields no longer strip their native validation attributes when concealed. Concealing containers reveal themselves around an invalid control, using the `invalid` event listener in the `filament/schemas` package, and components with a client-side visibility condition are wrapped in a `<fieldset>` that is `disabled` while hidden.
|
||||
*/
|
||||
public function isConcealed(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
101
vendor/filament/schemas/src/Components/Concerns/BelongsToContainer.php
vendored
Normal file
101
vendor/filament/schemas/src/Components/Concerns/BelongsToContainer.php
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Livewire\Component;
|
||||
|
||||
trait BelongsToContainer
|
||||
{
|
||||
protected Schema $container;
|
||||
|
||||
protected Schema $rootContainer;
|
||||
|
||||
public function container(Schema $schema): static
|
||||
{
|
||||
if (! isset($this->container)) {
|
||||
$this->container = $schema;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($this->container === $schema) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->container = $schema;
|
||||
$this->flushCachedHierarchy();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Do not use this method outside the internals of Filament. It is subject to breaking changes in minor and patch releases.
|
||||
*/
|
||||
public function flushCachedHierarchy(): void
|
||||
{
|
||||
$this->flushCachedAbsoluteKey();
|
||||
$this->flushCachedAbsoluteInheritanceKey();
|
||||
$this->flushCachedAbsoluteStatePath();
|
||||
$this->flushCachedParentRepeaterItem();
|
||||
/** @phpstan-ignore unset.possiblyHookedProperty */
|
||||
unset($this->rootContainer);
|
||||
|
||||
$this->flushCachedChildSchemaHierarchies();
|
||||
}
|
||||
|
||||
public function getContainer(): Schema
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Do not use this method outside the internals of Filament. It is subject to breaking changes in minor and patch releases.
|
||||
*/
|
||||
public function hasContainer(): bool
|
||||
{
|
||||
return isset($this->container);
|
||||
}
|
||||
|
||||
public function getRootContainer(): Schema
|
||||
{
|
||||
return $this->rootContainer ??= (function (): Schema {
|
||||
$container = $this->getContainer();
|
||||
|
||||
while (($parentComponent = $container->getParentComponent()) !== null) {
|
||||
$container = $parentComponent->getContainer();
|
||||
}
|
||||
|
||||
return $container;
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Do not use this method outside the internals of Filament. It is subject to breaking changes in minor and patch releases.
|
||||
*/
|
||||
public function getModelRootContainer(): Schema
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
$model = $this->getModel();
|
||||
$record = $this->getRecord();
|
||||
|
||||
while (($parentComponent = $container->getParentComponent()) !== null) {
|
||||
if (
|
||||
($parentComponent->getModel() !== $model) ||
|
||||
($parentComponent->getRecord() !== $record)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
$container = $parentComponent->getContainer();
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
public function getLivewire(): Component & HasSchemas
|
||||
{
|
||||
return $this->getContainer()->getLivewire();
|
||||
}
|
||||
}
|
||||
247
vendor/filament/schemas/src/Components/Concerns/BelongsToModel.php
vendored
Normal file
247
vendor/filament/schemas/src/Components/Concerns/BelongsToModel.php
vendored
Normal file
|
|
@ -0,0 +1,247 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
trait BelongsToModel
|
||||
{
|
||||
/**
|
||||
* @var Model | array<string, mixed> | class-string<Model> | Closure | null
|
||||
*/
|
||||
protected Model | array | string | Closure | null $model = null;
|
||||
|
||||
protected ?Closure $loadStateFromRelationshipsUsing = null;
|
||||
|
||||
protected ?Closure $saveRelationshipsUsing = null;
|
||||
|
||||
protected ?Closure $saveRelationshipsBeforeChildrenUsing = null;
|
||||
|
||||
protected bool | Closure $shouldSaveRelationshipsWhenDisabled = false;
|
||||
|
||||
protected bool | Closure $shouldSaveRelationshipsWhenHidden = false;
|
||||
|
||||
/**
|
||||
* @param Model | array<string, mixed> | class-string<Model> | Closure | null $model
|
||||
*/
|
||||
public function model(Model | array | string | Closure | null $model = null): static
|
||||
{
|
||||
$this->model = $model;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function saveRelationships(): void
|
||||
{
|
||||
$callback = $this->saveRelationshipsUsing;
|
||||
|
||||
if (! $callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
$isDisabled = $this->isDisabled();
|
||||
$isHidden = $this->isHidden();
|
||||
$isSaved = $this->isSaved();
|
||||
|
||||
if ($isDisabled && (! $this->shouldSaveRelationshipsWhenDisabled()) && (! $isSaved)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($isHidden && (! $this->shouldSaveRelationshipsWhenHidden())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((! $isDisabled) && (! $isHidden) && (! $isSaved)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! ($this->getRecord()?->exists)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->evaluate($callback);
|
||||
}
|
||||
|
||||
public function saveRelationshipsBeforeChildren(): void
|
||||
{
|
||||
$callback = $this->saveRelationshipsBeforeChildrenUsing;
|
||||
|
||||
if (! $callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
$isDisabled = $this->isDisabled();
|
||||
$isHidden = $this->isHidden();
|
||||
$isSaved = $this->isSaved();
|
||||
|
||||
if ($isDisabled && (! $this->shouldSaveRelationshipsWhenDisabled()) && (! $isSaved)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($isHidden && (! $this->shouldSaveRelationshipsWhenHidden())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((! $isDisabled) && (! $isHidden) && (! $isSaved)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! ($this->getRecord()?->exists)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->evaluate($callback);
|
||||
}
|
||||
|
||||
public function loadStateFromRelationships(bool $shouldHydrate = false): void
|
||||
{
|
||||
$callback = $this->loadStateFromRelationshipsUsing;
|
||||
|
||||
if (! $callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->getRecord()?->exists) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->evaluate($callback);
|
||||
|
||||
if ($shouldHydrate) {
|
||||
$this->castStateAfterLoadingFromRelationships();
|
||||
|
||||
$this->callAfterStateHydrated();
|
||||
|
||||
foreach ($this->getChildSchemas(withHidden: true) as $childSchema) {
|
||||
$childSchema->callAfterStateHydrated();
|
||||
}
|
||||
|
||||
$this->fillStateWithNull();
|
||||
}
|
||||
}
|
||||
|
||||
public function castStateAfterLoadingFromRelationships(): void
|
||||
{
|
||||
foreach ($this->getChildSchemas(withHidden: true) as $childSchema) {
|
||||
foreach ($childSchema->getComponents(withActions: false, withHidden: true) as $component) {
|
||||
$component->castStateAfterLoadingFromRelationships();
|
||||
}
|
||||
}
|
||||
|
||||
$rawState = $this->getRawState();
|
||||
$originalRawState = $rawState;
|
||||
|
||||
foreach ($this->getStateCasts() as $stateCast) {
|
||||
$rawState = $stateCast->set($rawState);
|
||||
}
|
||||
|
||||
if ($rawState !== $originalRawState) {
|
||||
$this->rawState($rawState);
|
||||
}
|
||||
}
|
||||
|
||||
public function saveRelationshipsUsing(?Closure $callback): static
|
||||
{
|
||||
$this->saveRelationshipsUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function saveRelationshipsBeforeChildrenUsing(?Closure $callback): static
|
||||
{
|
||||
$this->saveRelationshipsBeforeChildrenUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function saveRelationshipsWhenDisabled(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->shouldSaveRelationshipsWhenDisabled = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function shouldSaveRelationshipsWhenDisabled(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->shouldSaveRelationshipsWhenDisabled);
|
||||
}
|
||||
|
||||
public function saveRelationshipsWhenHidden(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->shouldSaveRelationshipsWhenHidden = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function shouldSaveRelationshipsWhenHidden(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->shouldSaveRelationshipsWhenHidden);
|
||||
}
|
||||
|
||||
public function loadStateFromRelationshipsUsing(?Closure $callback): static
|
||||
{
|
||||
$this->loadStateFromRelationshipsUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<Model>|null
|
||||
*/
|
||||
public function getModel(): ?string
|
||||
{
|
||||
$model = $this->evaluate($this->model);
|
||||
|
||||
if ($model instanceof Model) {
|
||||
return $model::class;
|
||||
}
|
||||
|
||||
if (is_array($model)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (filled($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return $this->getContainer()->getModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Model | array<string, mixed> | null
|
||||
*/
|
||||
public function getRecord(bool $withContainerRecord = true): Model | array | null
|
||||
{
|
||||
$model = $this->evaluate($this->model);
|
||||
|
||||
if (($model instanceof Model) || is_array($model)) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
if (is_string($model)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $withContainerRecord) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->getContainer()->getRecord();
|
||||
}
|
||||
|
||||
public function getModelInstance(): ?Model
|
||||
{
|
||||
$model = $this->evaluate($this->model);
|
||||
|
||||
if (($model === null) || is_array($model)) {
|
||||
return $this->getContainer()->getModelInstance();
|
||||
}
|
||||
|
||||
if ($model instanceof Model) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
return app($model);
|
||||
}
|
||||
}
|
||||
55
vendor/filament/schemas/src/Components/Concerns/CanBeCollapsed.php
vendored
Normal file
55
vendor/filament/schemas/src/Components/Concerns/CanBeCollapsed.php
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
trait CanBeCollapsed
|
||||
{
|
||||
protected bool | Closure $isCollapsed = false;
|
||||
|
||||
protected bool | Closure | null $isCollapsible = null;
|
||||
|
||||
protected bool | Closure $shouldPersistCollapsed = false;
|
||||
|
||||
public function collapsed(bool | Closure $condition = true, bool $shouldMakeComponentCollapsible = true): static
|
||||
{
|
||||
$this->isCollapsed = $condition;
|
||||
|
||||
if ($shouldMakeComponentCollapsible && ($this->isCollapsible === null)) {
|
||||
$this->collapsible();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isCollapsed(?Schema $schema = null): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isCollapsed, ['item' => $schema]);
|
||||
}
|
||||
|
||||
public function collapsible(bool | Closure | null $condition = true): static
|
||||
{
|
||||
$this->isCollapsible = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isCollapsible(): bool
|
||||
{
|
||||
return (bool) ($this->evaluate($this->isCollapsible) ?? false);
|
||||
}
|
||||
|
||||
public function persistCollapsed(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->shouldPersistCollapsed = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function shouldPersistCollapsed(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->shouldPersistCollapsed);
|
||||
}
|
||||
}
|
||||
22
vendor/filament/schemas/src/Components/Concerns/CanBeCompact.php
vendored
Normal file
22
vendor/filament/schemas/src/Components/Concerns/CanBeCompact.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanBeCompact
|
||||
{
|
||||
protected bool | Closure $isCompact = false;
|
||||
|
||||
public function compact(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isCompact = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isCompact(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isCompact);
|
||||
}
|
||||
}
|
||||
61
vendor/filament/schemas/src/Components/Concerns/CanBeDisabled.php
vendored
Normal file
61
vendor/filament/schemas/src/Components/Concerns/CanBeDisabled.php
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Support\Enums\Operation;
|
||||
use Illuminate\Support\Arr;
|
||||
use Livewire\Component as LivewireComponent;
|
||||
|
||||
trait CanBeDisabled
|
||||
{
|
||||
protected bool | Closure $isDisabled = false;
|
||||
|
||||
public function disabled(bool | Closure $condition = true): static
|
||||
{
|
||||
// Security: Disabling a field prevents it from being saved, but
|
||||
// skilled users can manipulate Livewire's JavaScript to bypass
|
||||
// the disabled state on the client. Always enforce authorization
|
||||
// on the backend (e.g. in `mutateFormDataBeforeSave()` or
|
||||
// via Model Policies) for sensitive fields.
|
||||
|
||||
$this->isDisabled = $condition;
|
||||
$this->saved(fn (Component $component): bool => ! $component->evaluate($condition));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | Operation | array<string | Operation> $operations
|
||||
*/
|
||||
public function disabledOn(string | Operation | array $operations): static
|
||||
{
|
||||
$this->disabled(static function (LivewireComponent & HasSchemas $livewire, string $operation) use ($operations): bool {
|
||||
foreach (Arr::wrap($operations) as $disabledOperation) {
|
||||
if ($disabledOperation instanceof Operation) {
|
||||
$disabledOperation = $disabledOperation->value;
|
||||
}
|
||||
|
||||
if ($disabledOperation === $operation || $livewire instanceof $disabledOperation) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isDisabled(): bool
|
||||
{
|
||||
return $this->evaluate($this->isDisabled) || $this->getContainer()->isDisabled();
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return ! $this->isDisabled();
|
||||
}
|
||||
}
|
||||
22
vendor/filament/schemas/src/Components/Concerns/CanBeDivided.php
vendored
Normal file
22
vendor/filament/schemas/src/Components/Concerns/CanBeDivided.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanBeDivided
|
||||
{
|
||||
protected bool | Closure $isDivided = false;
|
||||
|
||||
public function divided(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isDivided = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isDivided(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isDivided);
|
||||
}
|
||||
}
|
||||
22
vendor/filament/schemas/src/Components/Concerns/CanBeGridContainer.php
vendored
Normal file
22
vendor/filament/schemas/src/Components/Concerns/CanBeGridContainer.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanBeGridContainer
|
||||
{
|
||||
protected bool | Closure $isGridContainer = false;
|
||||
|
||||
public function gridContainer(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isGridContainer = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isGridContainer(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isGridContainer);
|
||||
}
|
||||
}
|
||||
277
vendor/filament/schemas/src/Components/Concerns/CanBeHidden.php
vendored
Normal file
277
vendor/filament/schemas/src/Components/Concerns/CanBeHidden.php
vendored
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Support\Enums\Operation;
|
||||
use Illuminate\Support\Arr;
|
||||
use Livewire\Component as LivewireComponent;
|
||||
|
||||
trait CanBeHidden
|
||||
{
|
||||
protected bool | Closure $isHidden = false;
|
||||
|
||||
protected bool | Closure $isVisible = true;
|
||||
|
||||
protected string | Closure | null $visibleJs = null;
|
||||
|
||||
protected string | Closure | null $hiddenJs = null;
|
||||
|
||||
protected static bool $isCachingVisibility = false;
|
||||
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected static array $visibilityCache = [];
|
||||
|
||||
public function hidden(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isHidden = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | Operation | array<string | Operation> $operations
|
||||
*/
|
||||
public function hiddenOn(string | Operation | array $operations): static
|
||||
{
|
||||
$this->hidden(static function (LivewireComponent & HasSchemas $livewire, string $operation) use ($operations): bool {
|
||||
foreach (Arr::wrap($operations) as $hiddenOperation) {
|
||||
if ($hiddenOperation instanceof Operation) {
|
||||
$hiddenOperation = $hiddenOperation->value;
|
||||
}
|
||||
|
||||
if ($hiddenOperation === $operation || $livewire instanceof $hiddenOperation) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hiddenWhenAllChildComponentsHidden(): static
|
||||
{
|
||||
$this->hidden(static function (Component $component): bool {
|
||||
foreach ($component->getChildSchemas(withHidden: true) as $childSchema) {
|
||||
foreach ($childSchema->getComponents(withHidden: false) as $childComponent) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> $paths
|
||||
*/
|
||||
public function whenTruthy(string | array $paths): static
|
||||
{
|
||||
$paths = Arr::wrap($paths);
|
||||
|
||||
$this->hidden(static function (Get $get) use ($paths): bool {
|
||||
foreach ($paths as $path) {
|
||||
if (! $get($path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> $paths
|
||||
*/
|
||||
public function whenFalsy(string | array $paths): static
|
||||
{
|
||||
$paths = Arr::wrap($paths);
|
||||
|
||||
$this->hidden(static function (Get $get) use ($paths): bool {
|
||||
foreach ($paths as $path) {
|
||||
if ((bool) $get($path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function visible(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isVisible = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | Operation | array<string | Operation> $operations
|
||||
*/
|
||||
public function visibleOn(string | Operation | array $operations): static
|
||||
{
|
||||
$this->visible(static function (LivewireComponent & HasSchemas $livewire, string $operation) use ($operations): bool {
|
||||
foreach (Arr::wrap($operations) as $visibleOperation) {
|
||||
if ($visibleOperation instanceof Operation) {
|
||||
$visibleOperation = $visibleOperation->value;
|
||||
}
|
||||
|
||||
if ($visibleOperation === $operation || $livewire instanceof $visibleOperation) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isHidden(): bool
|
||||
{
|
||||
if (static::isVisibilityCacheEnabled()) {
|
||||
$componentKey = $this->getKey() ?? spl_object_id($this);
|
||||
|
||||
if ($this->isHidden instanceof Closure) {
|
||||
$hiddenClosureKey = $componentKey . '.hidden.' . spl_object_id($this->isHidden);
|
||||
|
||||
if (! static::hasVisibilityCacheKey($hiddenClosureKey)) {
|
||||
static::setVisibilityCacheValue(
|
||||
$hiddenClosureKey,
|
||||
! $this->evaluate($this->isHidden),
|
||||
);
|
||||
}
|
||||
|
||||
if (! static::getVisibilityCacheValue($hiddenClosureKey)) {
|
||||
return true;
|
||||
}
|
||||
} elseif ($this->isHidden) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->isVisible instanceof Closure) {
|
||||
$visibleClosureKey = $componentKey . '.visible.' . spl_object_id($this->isVisible);
|
||||
|
||||
if (! static::hasVisibilityCacheKey($visibleClosureKey)) {
|
||||
static::setVisibilityCacheValue(
|
||||
$visibleClosureKey,
|
||||
(bool) $this->evaluate($this->isVisible)
|
||||
);
|
||||
}
|
||||
|
||||
return ! static::getVisibilityCacheValue($visibleClosureKey);
|
||||
}
|
||||
|
||||
return ! $this->isVisible;
|
||||
}
|
||||
|
||||
if ($this->evaluate($this->isHidden)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ! $this->evaluate($this->isVisible);
|
||||
}
|
||||
|
||||
public function isVisible(): bool
|
||||
{
|
||||
return ! $this->isHidden();
|
||||
}
|
||||
|
||||
public function visibleJs(string | Closure | null $condition): static
|
||||
{
|
||||
// Security: This JavaScript is evaluated on the client via `eval()`.
|
||||
// Never pass user input — only developer-defined expressions.
|
||||
|
||||
$this->visibleJs = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hiddenJs(string | Closure | null $condition): static
|
||||
{
|
||||
// Security: This JavaScript is evaluated on the client via `eval()`.
|
||||
// Never pass user input — only developer-defined expressions.
|
||||
|
||||
$this->hiddenJs = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVisibleJs(): ?string
|
||||
{
|
||||
return $this->evaluate($this->visibleJs);
|
||||
}
|
||||
|
||||
public function getHiddenJs(): ?string
|
||||
{
|
||||
return $this->evaluate($this->hiddenJs);
|
||||
}
|
||||
|
||||
public static function isVisibilityCacheEnabled(): bool
|
||||
{
|
||||
return static::$isCachingVisibility;
|
||||
}
|
||||
|
||||
public static function getVisibilityCacheValue(string $key): bool
|
||||
{
|
||||
return static::$visibilityCache[$key] ?? false;
|
||||
}
|
||||
|
||||
public static function setVisibilityCacheValue(string $key, bool $value): void
|
||||
{
|
||||
static::$visibilityCache[$key] = $value;
|
||||
}
|
||||
|
||||
public static function hasVisibilityCacheKey(string $key): bool
|
||||
{
|
||||
return array_key_exists($key, static::$visibilityCache);
|
||||
}
|
||||
|
||||
public static function enableVisibilityCache(): void
|
||||
{
|
||||
static::$isCachingVisibility = true;
|
||||
static::$visibilityCache = [];
|
||||
}
|
||||
|
||||
public static function disableVisibilityCache(): void
|
||||
{
|
||||
static::$isCachingVisibility = false;
|
||||
static::$visibilityCache = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
*
|
||||
* @param callable(): T $callback
|
||||
* @return T
|
||||
*/
|
||||
public static function withVisibilityCache(callable $callback): mixed
|
||||
{
|
||||
$wasEnabled = static::isVisibilityCacheEnabled();
|
||||
|
||||
if (! $wasEnabled) {
|
||||
static::enableVisibilityCache();
|
||||
}
|
||||
|
||||
try {
|
||||
return $callback();
|
||||
} finally {
|
||||
if (! $wasEnabled) {
|
||||
static::disableVisibilityCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
vendor/filament/schemas/src/Components/Concerns/CanBeLiberatedFromContainerGrid.php
vendored
Normal file
22
vendor/filament/schemas/src/Components/Concerns/CanBeLiberatedFromContainerGrid.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanBeLiberatedFromContainerGrid
|
||||
{
|
||||
protected bool | Closure $isLiberatedFromContainerGrid = false;
|
||||
|
||||
public function liberatedFromContainerGrid(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isLiberatedFromContainerGrid = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isLiberatedFromContainerGrid(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isLiberatedFromContainerGrid);
|
||||
}
|
||||
}
|
||||
69
vendor/filament/schemas/src/Components/Concerns/CanBeRepeated.php
vendored
Normal file
69
vendor/filament/schemas/src/Components/Concerns/CanBeRepeated.php
vendored
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Filament\Forms\Components\Builder;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
trait CanBeRepeated
|
||||
{
|
||||
protected Schema | bool | null $cachedParentRepeaterItem = null;
|
||||
|
||||
public function getParentRepeater(): Repeater | Builder | null
|
||||
{
|
||||
$repeater = $this->getParentRepeaterItem()?->getParentComponent();
|
||||
|
||||
assert(($repeater instanceof Repeater) || ($repeater instanceof Builder) || (! $repeater));
|
||||
|
||||
return $repeater;
|
||||
}
|
||||
|
||||
public function getParentRepeaterItem(): ?Schema
|
||||
{
|
||||
if (filled($this->cachedParentRepeaterItem)) {
|
||||
return $this->cachedParentRepeaterItem ?: null;
|
||||
}
|
||||
|
||||
$container = $this->getContainer();
|
||||
|
||||
$parentComponent = $container->getParentComponent();
|
||||
|
||||
if (! $parentComponent) {
|
||||
$this->cachedParentRepeaterItem = false;
|
||||
} elseif (($parentComponent instanceof Repeater) || ($parentComponent instanceof Builder)) {
|
||||
$this->cachedParentRepeaterItem = $container;
|
||||
} else {
|
||||
$this->cachedParentRepeaterItem = $parentComponent->getParentRepeaterItem();
|
||||
}
|
||||
|
||||
return $this->cachedParentRepeaterItem ?: null;
|
||||
}
|
||||
|
||||
protected function flushCachedParentRepeaterItem(): void
|
||||
{
|
||||
$this->cachedParentRepeaterItem = null;
|
||||
}
|
||||
|
||||
public function getParentRepeaterItemIndex(): int
|
||||
{
|
||||
$item = $this->getParentRepeaterItem();
|
||||
|
||||
if (! $item) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$keys = array_keys($item->getParentComponent()->getState());
|
||||
|
||||
$index = array_search(
|
||||
$item->getStatePath(isAbsolute: false),
|
||||
$keys,
|
||||
);
|
||||
|
||||
if ($index === false) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $index;
|
||||
}
|
||||
}
|
||||
22
vendor/filament/schemas/src/Components/Concerns/CanBeSecondary.php
vendored
Normal file
22
vendor/filament/schemas/src/Components/Concerns/CanBeSecondary.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanBeSecondary
|
||||
{
|
||||
protected bool | Closure $isSecondary = false;
|
||||
|
||||
public function secondary(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isSecondary = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isSecondary(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isSecondary);
|
||||
}
|
||||
}
|
||||
163
vendor/filament/schemas/src/Components/Concerns/CanGetStateFromRelationships.php
vendored
Normal file
163
vendor/filament/schemas/src/Components/Concerns/CanGetStateFromRelationships.php
vendored
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
trait CanGetStateFromRelationships
|
||||
{
|
||||
protected ?bool $hasMultipleStateRelationshipCache = null;
|
||||
|
||||
protected ?Relation $stateRelationshipCache = null;
|
||||
|
||||
public function hasStateRelationship(Model $record): bool
|
||||
{
|
||||
return $this->getStateRelationship($record) !== null;
|
||||
}
|
||||
|
||||
public function getStateRelationship(Model $record, ?string $statePath = null): ?Relation
|
||||
{
|
||||
if ($this->stateRelationshipCache) {
|
||||
return $this->stateRelationshipCache;
|
||||
}
|
||||
|
||||
if (blank($statePath) && (! str($this->getStateRelationshipPath())->contains('.'))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$relationship = null;
|
||||
|
||||
foreach (explode('.', $statePath ?? $this->getStateRelationshipName()) as $nestedRelationshipName) {
|
||||
if ($record->hasAttribute($nestedRelationshipName)) {
|
||||
$relationship = null;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (! $record->isRelation($nestedRelationshipName)) {
|
||||
$relationship = null;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$relationship = $record->{$nestedRelationshipName}();
|
||||
$record = $relationship->getRelated();
|
||||
}
|
||||
|
||||
return $this->stateRelationshipCache = $relationship;
|
||||
}
|
||||
|
||||
public function hasMultipleStateRelationship(Model $record): bool
|
||||
{
|
||||
if (isset($this->hasMultipleStateRelationshipCache)) {
|
||||
return $this->hasMultipleStateRelationshipCache;
|
||||
}
|
||||
|
||||
$relationships = explode('.', $this->getStateRelationshipName($record));
|
||||
|
||||
while (count($relationships)) {
|
||||
$currentRelationshipName = array_shift($relationships);
|
||||
|
||||
$currentRelationshipValue = $record->getRelationValue($currentRelationshipName);
|
||||
|
||||
if ($currentRelationshipValue instanceof Collection) {
|
||||
return $this->hasMultipleStateRelationshipCache = true;
|
||||
}
|
||||
|
||||
if (! $currentRelationshipValue instanceof Model) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (! count($relationships)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$record = $currentRelationshipValue;
|
||||
}
|
||||
|
||||
return $this->hasMultipleStateRelationshipCache = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> | null $relationships
|
||||
* @return array<Model>
|
||||
*/
|
||||
public function getStateRelationshipResults(Model $record, ?array $relationships = null): array
|
||||
{
|
||||
$results = [];
|
||||
|
||||
$relationships ??= explode('.', $this->getStateRelationshipName());
|
||||
|
||||
while (count($relationships)) {
|
||||
$currentRelationshipName = array_shift($relationships);
|
||||
|
||||
$currentRelationshipValue = $record->getRelationValue($currentRelationshipName);
|
||||
|
||||
if ($currentRelationshipValue instanceof Collection) {
|
||||
if (! count($relationships)) {
|
||||
$results = [
|
||||
...$results,
|
||||
...$currentRelationshipValue->all(),
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($currentRelationshipValue as $valueRecord) {
|
||||
$results = [
|
||||
...$results,
|
||||
...$this->getStateRelationshipResults(
|
||||
$valueRecord,
|
||||
$relationships,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (! $currentRelationshipValue instanceof Model) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (! count($relationships)) {
|
||||
$results[] = $currentRelationshipValue;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$record = $currentRelationshipValue;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getStateRelationshipAttribute(?string $statePath = null): string
|
||||
{
|
||||
$statePath ??= $this->getStateRelationshipPath();
|
||||
|
||||
if (! str($statePath)->contains('.')) {
|
||||
return $statePath;
|
||||
}
|
||||
|
||||
return (string) str($statePath)->afterLast('.');
|
||||
}
|
||||
|
||||
public function getStateRelationshipName(?string $statePath = null): ?string
|
||||
{
|
||||
$statePath ??= $this->getStateRelationshipPath();
|
||||
|
||||
if (! str($statePath)->contains('.')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) str($statePath)->beforeLast('.');
|
||||
}
|
||||
|
||||
public function getStateRelationshipPath(): ?string
|
||||
{
|
||||
return $this->getStatePath(isAbsolute: false);
|
||||
}
|
||||
}
|
||||
61
vendor/filament/schemas/src/Components/Concerns/CanOpenUrl.php
vendored
Normal file
61
vendor/filament/schemas/src/Components/Concerns/CanOpenUrl.php
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanOpenUrl
|
||||
{
|
||||
protected bool | Closure $shouldOpenUrlInNewTab = false;
|
||||
|
||||
protected string | Closure | null $url = null;
|
||||
|
||||
public function openUrlInNewTab(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->shouldOpenUrlInNewTab = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function url(string | Closure | null $url, bool | Closure | null $shouldOpenInNewTab = null): static
|
||||
{
|
||||
// Security: If this URL is derived from user input, validate it
|
||||
// to prevent XSS via `javascript:` protocol URLs rendered
|
||||
// in `href` attributes.
|
||||
|
||||
if ($shouldOpenInNewTab !== null) {
|
||||
$this->openUrlInNewTab($shouldOpenInNewTab);
|
||||
}
|
||||
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUrl(mixed $state = null): ?string
|
||||
{
|
||||
if (func_num_args() === 1) {
|
||||
return $this->hasStateBasedUrls()
|
||||
? $this->evaluate($this->url, [
|
||||
'state' => $state,
|
||||
])
|
||||
: null;
|
||||
}
|
||||
|
||||
if ($this->hasStateBasedUrls()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->evaluate($this->url);
|
||||
}
|
||||
|
||||
public function hasStateBasedUrls(): bool
|
||||
{
|
||||
return $this->evaluationValueIsFunctionAndHasParameter($this->url, parameterName: 'state');
|
||||
}
|
||||
|
||||
public function shouldOpenUrlInNewTab(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->shouldOpenUrlInNewTab);
|
||||
}
|
||||
}
|
||||
81
vendor/filament/schemas/src/Components/Concerns/CanPartiallyRender.php
vendored
Normal file
81
vendor/filament/schemas/src/Components/Concerns/CanPartiallyRender.php
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Livewire\Partials\PartialsComponentHook;
|
||||
use LogicException;
|
||||
|
||||
trait CanPartiallyRender
|
||||
{
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $componentsToPartiallyRenderAfterStateUpdated = [];
|
||||
|
||||
protected bool | Closure $isRenderlessAfterStateUpdated = false;
|
||||
|
||||
protected bool | Closure $isPartiallyRenderedAfterStateUpdated = false;
|
||||
|
||||
/**
|
||||
* @param array<string> $components
|
||||
*/
|
||||
public function partiallyRenderComponentsAfterStateUpdated(array $components): static
|
||||
{
|
||||
$this->componentsToPartiallyRenderAfterStateUpdated = $components;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function skipRenderAfterStateUpdated(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isRenderlessAfterStateUpdated = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function partiallyRenderAfterStateUpdated(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isPartiallyRenderedAfterStateUpdated = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getComponentsToPartiallyRenderAfterStateUpdated(): array
|
||||
{
|
||||
return $this->componentsToPartiallyRenderAfterStateUpdated;
|
||||
}
|
||||
|
||||
public function isRenderlessAfterStateUpdated(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isRenderlessAfterStateUpdated);
|
||||
}
|
||||
|
||||
public function isPartiallyRenderedAfterStateUpdated(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isPartiallyRenderedAfterStateUpdated);
|
||||
}
|
||||
|
||||
public function partiallyRender(): void
|
||||
{
|
||||
app(PartialsComponentHook::class)->renderPartial($this->getLivewire(), function (): array {
|
||||
$key = $this->getKey();
|
||||
|
||||
if (blank($key)) {
|
||||
throw new LogicException('A [key()] or [statePath()] is required to partially render a component.');
|
||||
}
|
||||
|
||||
return [
|
||||
"schema-component::{$key}" => $this->toSchemaHtml(...),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function skipRender(): void
|
||||
{
|
||||
app(PartialsComponentHook::class)->skipPartialRender($this->getLivewire());
|
||||
}
|
||||
}
|
||||
22
vendor/filament/schemas/src/Components/Concerns/CanPersistTab.php
vendored
Normal file
22
vendor/filament/schemas/src/Components/Concerns/CanPersistTab.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanPersistTab
|
||||
{
|
||||
public bool | Closure $isTabPersisted = false;
|
||||
|
||||
public function persistTab(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isTabPersisted = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isTabPersisted(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isTabPersisted);
|
||||
}
|
||||
}
|
||||
22
vendor/filament/schemas/src/Components/Concerns/CanPoll.php
vendored
Normal file
22
vendor/filament/schemas/src/Components/Concerns/CanPoll.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanPoll
|
||||
{
|
||||
protected string | Closure | null $pollingInterval = null;
|
||||
|
||||
public function poll(string | Closure | null $interval = '10s'): static
|
||||
{
|
||||
$this->pollingInterval = $interval;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPollingInterval(): ?string
|
||||
{
|
||||
return $this->evaluate($this->pollingInterval);
|
||||
}
|
||||
}
|
||||
57
vendor/filament/schemas/src/Components/Concerns/CanStripCharactersFromState.php
vendored
Normal file
57
vendor/filament/schemas/src/Components/Concerns/CanStripCharactersFromState.php
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait CanStripCharactersFromState
|
||||
{
|
||||
/**
|
||||
* @var string | array<string> | Closure | null
|
||||
*/
|
||||
protected string | array | Closure | null $stripCharacters = null;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $cachedStripCharacters;
|
||||
|
||||
/**
|
||||
* @param string | array<string> | Closure | null $characters
|
||||
*/
|
||||
public function stripCharacters(string | array | Closure | null $characters): static
|
||||
{
|
||||
$this->stripCharacters = $characters;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getStripCharacters(): array
|
||||
{
|
||||
return $this->cachedStripCharacters ??= Arr::wrap($this->evaluate($this->stripCharacters));
|
||||
}
|
||||
|
||||
public function hasStripCharacters(): bool
|
||||
{
|
||||
return filled($this->getStripCharacters());
|
||||
}
|
||||
|
||||
protected function stripCharactersFromState(mixed $state): mixed
|
||||
{
|
||||
if (! is_string($state)) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
$stripCharacters = $this->getStripCharacters();
|
||||
|
||||
if (empty($stripCharacters)) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
return str_replace($stripCharacters, '', $state);
|
||||
}
|
||||
}
|
||||
38
vendor/filament/schemas/src/Components/Concerns/CanTrimState.php
vendored
Normal file
38
vendor/filament/schemas/src/Components/Concerns/CanTrimState.php
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait CanTrimState
|
||||
{
|
||||
protected bool | Closure $isTrimmed = false;
|
||||
|
||||
protected bool $cachedIsTrimmed;
|
||||
|
||||
public function trim(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isTrimmed = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isTrimmed(): bool
|
||||
{
|
||||
return $this->cachedIsTrimmed ??= (bool) $this->evaluate($this->isTrimmed);
|
||||
}
|
||||
|
||||
protected function trimState(mixed $state): mixed
|
||||
{
|
||||
if (! is_string($state)) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
if (! $this->isTrimmed()) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
return Str::trim($state);
|
||||
}
|
||||
}
|
||||
39
vendor/filament/schemas/src/Components/Concerns/Cloneable.php
vendored
Normal file
39
vendor/filament/schemas/src/Components/Concerns/Cloneable.php
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait Cloneable
|
||||
{
|
||||
/**
|
||||
* @var array<Closure>
|
||||
*/
|
||||
protected array $afterCloned = [];
|
||||
|
||||
public function afterCloned(Closure $callback): static
|
||||
{
|
||||
$this->afterCloned[] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClone(): static
|
||||
{
|
||||
$clone = clone $this;
|
||||
$clone->flushCachedAbsoluteKey();
|
||||
$clone->flushCachedAbsoluteStatePath();
|
||||
$clone->flushCachedAbsoluteInheritanceKey();
|
||||
$clone->flushCachedParentRepeaterItem();
|
||||
$clone->cloneChildComponents();
|
||||
|
||||
foreach ($this->afterCloned as $callback) {
|
||||
$clone->evaluate(
|
||||
value: $callback->bindTo($clone),
|
||||
namedInjections: ['clone' => $clone, 'original' => $this]
|
||||
);
|
||||
}
|
||||
|
||||
return $clone;
|
||||
}
|
||||
}
|
||||
369
vendor/filament/schemas/src/Components/Concerns/EntanglesStateWithSingularRelationship.php
vendored
Normal file
369
vendor/filament/schemas/src/Components/Concerns/EntanglesStateWithSingularRelationship.php
vendored
Normal file
|
|
@ -0,0 +1,369 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Contracts\CanEntangleWithSingularRelationships;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Support\Arr;
|
||||
use Livewire\Component as LivewireComponent;
|
||||
|
||||
trait EntanglesStateWithSingularRelationship
|
||||
{
|
||||
protected ?Model $cachedExistingRecord = null;
|
||||
|
||||
protected ?string $relationship = null;
|
||||
|
||||
protected string | Closure | null $relatedModel = null;
|
||||
|
||||
protected ?Closure $mutateRelationshipDataBeforeCreateUsing = null;
|
||||
|
||||
protected ?Closure $mutateRelationshipDataBeforeFillUsing = null;
|
||||
|
||||
protected ?Closure $mutateRelationshipDataBeforeSaveUsing = null;
|
||||
|
||||
protected bool | Closure $hasRelationship = false;
|
||||
|
||||
public function relationship(string $name, bool | Closure $condition = true, string | Closure | null $relatedModel = null): static
|
||||
{
|
||||
$this->relationship = $name;
|
||||
$this->hasRelationship = $condition;
|
||||
$this->relatedModel = $relatedModel;
|
||||
$this->statePath($name);
|
||||
|
||||
$this->loadStateFromRelationshipsUsing(static function (Component | CanEntangleWithSingularRelationships $component): void {
|
||||
$component->clearCachedExistingRecord();
|
||||
|
||||
$findFirstComponentWithThisRelationship = function (Schema $schema) use ($component, &$findFirstComponentWithThisRelationship): ?CanEntangleWithSingularRelationships {
|
||||
foreach ($schema->getComponents(withActions: false, withHidden: true) as $childComponent) {
|
||||
if (
|
||||
($childComponent->getStatePath() === $component->getStatePath()) &&
|
||||
($childComponent->getModel() === $component->getModel()) &&
|
||||
($childComponent->getRecord() === $component->getRecord()) &&
|
||||
($childComponent instanceof CanEntangleWithSingularRelationships) &&
|
||||
($childComponent->getRelationshipName() === $component->getRelationshipName()) &&
|
||||
($childComponent->hasRelationship())
|
||||
) {
|
||||
return $childComponent;
|
||||
}
|
||||
|
||||
foreach ($childComponent->getChildSchemas() as $schema) {
|
||||
$found = $findFirstComponentWithThisRelationship($schema);
|
||||
|
||||
if ($found) {
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
$firstComponentWithThisRelationship = $findFirstComponentWithThisRelationship($component->getModelRootContainer());
|
||||
|
||||
$isFirstComponent = ($firstComponentWithThisRelationship === null) || ($firstComponentWithThisRelationship === $component);
|
||||
|
||||
if ($isFirstComponent) {
|
||||
$component->fillFromRelationship();
|
||||
}
|
||||
});
|
||||
|
||||
$this->saveRelationshipsBeforeChildrenUsing(static function (Component | CanEntangleWithSingularRelationships $component, LivewireComponent & HasSchemas $livewire): void {
|
||||
// All layout components using this relationship should be saved together in this function.
|
||||
$componentsWithThisRelationship = [];
|
||||
|
||||
$findComponentsWithThisRelationship = function (Schema $schema) use ($component, &$componentsWithThisRelationship, &$findComponentsWithThisRelationship): void {
|
||||
foreach ($schema->getComponents(withActions: false, withHidden: true) as $childComponent) {
|
||||
if ($childComponent->isHidden() && (! $childComponent->shouldSaveRelationshipsWhenHidden())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
($childComponent->getModel() === $component->getModel()) &&
|
||||
($childComponent->getRecord() === $component->getRecord()) &&
|
||||
($childComponent instanceof CanEntangleWithSingularRelationships) &&
|
||||
($childComponent->getRelationshipName() === $component->getRelationshipName()) &&
|
||||
($childComponent->hasRelationship())
|
||||
) {
|
||||
$componentsWithThisRelationship[] = $childComponent;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($childComponent->getChildSchemas() as $schema) {
|
||||
$findComponentsWithThisRelationship($schema);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$findComponentsWithThisRelationship($component->getModelRootContainer());
|
||||
|
||||
// The first layout component using this relationship is the one that will save the relationship for all of them.
|
||||
if (filled($componentsWithThisRelationship) && (Arr::first($componentsWithThisRelationship) !== $component)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$record = $component->getCachedExistingRecord();
|
||||
|
||||
if (! $component->hasRelationship()) {
|
||||
$record?->delete();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($componentsWithThisRelationship as $componentWithThisRelationship) {
|
||||
$data = [
|
||||
...$data,
|
||||
...$componentWithThisRelationship->getChildSchema()->getState(shouldCallHooksBefore: false),
|
||||
];
|
||||
}
|
||||
|
||||
$translatableContentDriver = $livewire->makeFilamentTranslatableContentDriver();
|
||||
|
||||
if ($record) {
|
||||
foreach ($componentsWithThisRelationship as $componentWithThisRelationship) {
|
||||
$data = $componentWithThisRelationship->mutateRelationshipDataBeforeSave($data);
|
||||
}
|
||||
|
||||
$translatableContentDriver ?
|
||||
$translatableContentDriver->updateRecord($record, $data) :
|
||||
$record->fill($data)->save();
|
||||
|
||||
foreach ($componentsWithThisRelationship as $componentWithThisRelationship) {
|
||||
$componentWithThisRelationship->cachedExistingRecord($record);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$relationship = $component->getRelationship();
|
||||
$relatedModel = $component->getRelatedModel();
|
||||
|
||||
foreach ($componentsWithThisRelationship as $componentWithThisRelationship) {
|
||||
$data = $componentWithThisRelationship->mutateRelationshipDataBeforeCreate($data);
|
||||
}
|
||||
|
||||
if ($translatableContentDriver) {
|
||||
$record = $translatableContentDriver->makeRecord($relatedModel, $data);
|
||||
} else {
|
||||
$record = new $relatedModel;
|
||||
$record->fill($data);
|
||||
}
|
||||
|
||||
if ($relationship instanceof BelongsTo) {
|
||||
$record->save();
|
||||
$relationship->associate($record);
|
||||
$relationship->getParent()->save();
|
||||
} else {
|
||||
$relationship->save($record);
|
||||
}
|
||||
|
||||
foreach ($componentsWithThisRelationship as $componentWithThisRelationship) {
|
||||
$componentWithThisRelationship->cachedExistingRecord($record);
|
||||
}
|
||||
});
|
||||
|
||||
$this->dehydrated(false);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function fillFromRelationship(): void
|
||||
{
|
||||
$record = $this->getCachedExistingRecord();
|
||||
|
||||
if (! $record) {
|
||||
// State casts are skipped here; the surrounding `Component::hydrateState()`
|
||||
// recurses into child schemas and applies them exactly once.
|
||||
$this->getChildSchema()->fill(shouldCallHydrationHooks: false, shouldFillStateWithNull: false, shouldApplyStateCasts: false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$data = $this->mutateRelationshipDataBeforeFill(
|
||||
$this->getStateFromRelatedRecord($record),
|
||||
);
|
||||
|
||||
$this->getChildSchema()->fill($data, shouldCallHydrationHooks: false, shouldFillStateWithNull: false, shouldApplyStateCasts: false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function getStateFromRelatedRecord(Model $record): array
|
||||
{
|
||||
if ($translatableContentDriver = $this->getLivewire()->makeFilamentTranslatableContentDriver()) {
|
||||
return $translatableContentDriver->getRecordAttributesToArray($record);
|
||||
}
|
||||
|
||||
return $record->attributesToArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array-key $key
|
||||
*/
|
||||
public function getChildSchema($key = null): ?Schema
|
||||
{
|
||||
$container = parent::getChildSchema($key);
|
||||
|
||||
if (! $container) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$relationship = $this->getRelationship();
|
||||
|
||||
if (! $relationship) {
|
||||
return $container;
|
||||
}
|
||||
|
||||
return $container->model($this->getCachedExistingRecord() ?? $this->getRelatedModel());
|
||||
}
|
||||
|
||||
public function getRelationship(): BelongsTo | HasOne | MorphOne | null
|
||||
{
|
||||
$name = $this->getRelationshipName();
|
||||
|
||||
if (blank($name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->getModelInstance()->{$name}();
|
||||
}
|
||||
|
||||
public function getRelationshipName(): ?string
|
||||
{
|
||||
return $this->relationship;
|
||||
}
|
||||
|
||||
public function hasRelationship(): bool
|
||||
{
|
||||
return $this->evaluate($this->hasRelationship) && filled($this->getRelationshipName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<Model>|null
|
||||
*/
|
||||
public function getRelatedModel(): ?string
|
||||
{
|
||||
return $this->evaluate($this->relatedModel) ?? $this->getRelationship()?->getModel()::class;
|
||||
}
|
||||
|
||||
public function cachedExistingRecord(?Model $record): static
|
||||
{
|
||||
$this->cachedExistingRecord = $record;
|
||||
|
||||
$this->clearCachedChildSchemas();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCachedExistingRecord(): ?Model
|
||||
{
|
||||
if ($this->cachedExistingRecord) {
|
||||
return $this->cachedExistingRecord;
|
||||
}
|
||||
|
||||
$parentRecord = $this->getRecord();
|
||||
|
||||
if (! $parentRecord) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$relationshipName = $this->getRelationshipName();
|
||||
|
||||
if (blank($relationshipName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($parentRecord->relationLoaded($relationshipName)) {
|
||||
$record = $parentRecord->getRelationValue($relationshipName);
|
||||
} else {
|
||||
$record = $this->getRelationship()?->getResults();
|
||||
}
|
||||
|
||||
if (! $record?->exists) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->cachedExistingRecord = $record;
|
||||
}
|
||||
|
||||
public function clearCachedExistingRecord(): void
|
||||
{
|
||||
$this->cachedExistingRecord = null;
|
||||
}
|
||||
|
||||
public function mutateRelationshipDataBeforeCreateUsing(?Closure $callback): static
|
||||
{
|
||||
$this->mutateRelationshipDataBeforeCreateUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function mutateRelationshipDataBeforeCreate(array $data): array
|
||||
{
|
||||
if ($this->mutateRelationshipDataBeforeCreateUsing instanceof Closure) {
|
||||
$data = $this->evaluate($this->mutateRelationshipDataBeforeCreateUsing, [
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function mutateRelationshipDataBeforeSaveUsing(?Closure $callback): static
|
||||
{
|
||||
$this->mutateRelationshipDataBeforeSaveUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function mutateRelationshipDataBeforeFill(array $data): array
|
||||
{
|
||||
if ($this->mutateRelationshipDataBeforeFillUsing instanceof Closure) {
|
||||
$data = $this->evaluate($this->mutateRelationshipDataBeforeFillUsing, [
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function mutateRelationshipDataBeforeFillUsing(?Closure $callback): static
|
||||
{
|
||||
$this->mutateRelationshipDataBeforeFillUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function mutateRelationshipDataBeforeSave(array $data): array
|
||||
{
|
||||
if ($this->mutateRelationshipDataBeforeSaveUsing instanceof Closure) {
|
||||
$data = $this->evaluate($this->mutateRelationshipDataBeforeSaveUsing, [
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
182
vendor/filament/schemas/src/Components/Concerns/HasActions.php
vendored
Normal file
182
vendor/filament/schemas/src/Components/Concerns/HasActions.php
vendored
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Schemas\Components\Contracts\HasAffixActions;
|
||||
use Filament\Schemas\Components\Contracts\HasExtraItemActions;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait HasActions
|
||||
{
|
||||
/**
|
||||
* @var array<Action> | null
|
||||
*/
|
||||
protected ?array $cachedActions = null;
|
||||
|
||||
/**
|
||||
* @var array<string, Action | Closure>
|
||||
*/
|
||||
protected array $actions = [];
|
||||
|
||||
/**
|
||||
* @var Model|class-string<Model>|null
|
||||
*/
|
||||
protected Model | string | Closure | null $actionSchemaModel = null;
|
||||
|
||||
protected ?Action $action = null;
|
||||
|
||||
/**
|
||||
* @param array<Action | Closure> $actions
|
||||
*/
|
||||
public function registerActions(array $actions): static
|
||||
{
|
||||
$this->actions = [
|
||||
...$this->actions,
|
||||
...$actions,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function action(?Action $action): static
|
||||
{
|
||||
$this->action = $action;
|
||||
|
||||
if ($action) {
|
||||
$this->registerActions([$action]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | null $name
|
||||
*/
|
||||
public function getAction(string | array | null $name = null): ?Action
|
||||
{
|
||||
$actions = $this->getActions();
|
||||
|
||||
if (blank($name)) {
|
||||
return $this->action;
|
||||
}
|
||||
|
||||
if (is_string($name) && str($name)->contains('.')) {
|
||||
$name = explode('.', $name);
|
||||
}
|
||||
|
||||
if (is_array($name)) {
|
||||
$firstName = array_shift($name);
|
||||
$modalActionNames = $name;
|
||||
|
||||
$name = $firstName;
|
||||
}
|
||||
|
||||
$action = $actions[$name] ?? null;
|
||||
|
||||
if (! $action) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($modalActionNames ?? [] as $modalActionName) {
|
||||
$action = $action->getModalAction($modalActionName);
|
||||
|
||||
if (! $action) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$name = $modalActionName;
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Action>
|
||||
*/
|
||||
public function getActions(): array
|
||||
{
|
||||
return $this->cachedActions ??= $this->cacheActions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function cacheActions(): array
|
||||
{
|
||||
$this->cachedActions = [];
|
||||
|
||||
foreach ($this->getDefaultActions() as $defaultAction) {
|
||||
foreach (Arr::wrap($this->evaluate($defaultAction)) as $action) {
|
||||
$this->cachedActions[$action->getName()] = $this->prepareAction($action);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this instanceof HasAffixActions) {
|
||||
$this->cachedActions = [
|
||||
...$this->cachedActions,
|
||||
...$this->getPrefixActions(),
|
||||
...$this->getSuffixActions(),
|
||||
];
|
||||
}
|
||||
|
||||
if ($this instanceof HasExtraItemActions) {
|
||||
$this->cachedActions = [
|
||||
...$this->cachedActions,
|
||||
...$this->getExtraItemActions(),
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($this->actions as $registeredAction) {
|
||||
foreach (Arr::wrap($this->evaluate($registeredAction)) as $action) {
|
||||
$this->cachedActions[$action->getName()] = $this->prepareAction($action);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->cachedActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function getDefaultActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function prepareAction(Action $action): Action
|
||||
{
|
||||
return $action->schemaComponent($this);
|
||||
}
|
||||
|
||||
public function prepareActionGroup(ActionGroup $group): ActionGroup
|
||||
{
|
||||
return $group->schemaComponent($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model | class-string<Model> | Closure | null $model
|
||||
*/
|
||||
public function actionSchemaModel(Model | string | Closure | null $model): static
|
||||
{
|
||||
$this->actionSchemaModel = $model;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Model | array<string, mixed> | class-string<Model> | null
|
||||
*/
|
||||
public function getActionSchemaModel(): Model | array | string | null
|
||||
{
|
||||
return $this->evaluate($this->actionSchemaModel) ?? $this->getRecord() ?? $this->getModel();
|
||||
}
|
||||
|
||||
public function hasAction(string $name): bool
|
||||
{
|
||||
return array_key_exists($name, $this->getActions());
|
||||
}
|
||||
}
|
||||
446
vendor/filament/schemas/src/Components/Concerns/HasChildComponents.php
vendored
Normal file
446
vendor/filament/schemas/src/Components/Concerns/HasChildComponents.php
vendored
Normal file
|
|
@ -0,0 +1,446 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
trait HasChildComponents
|
||||
{
|
||||
/**
|
||||
* @var array<string, array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null>
|
||||
*/
|
||||
protected array $childComponents = [];
|
||||
|
||||
/**
|
||||
* @var array<Schema> | null
|
||||
*/
|
||||
protected ?array $cachedDefaultChildSchemas = null;
|
||||
|
||||
/**
|
||||
* @var array<int, array-key>
|
||||
*/
|
||||
protected array $cachedDefaultChildSchemaKeys = [];
|
||||
|
||||
/**
|
||||
* @var array<string, Schema>
|
||||
*/
|
||||
protected array $cachedChildSchemas = [];
|
||||
|
||||
protected bool $isEvaluatingDefaultChildSchemas = false;
|
||||
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $evaluatingChildSchemaKeys = [];
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Closure $components
|
||||
*/
|
||||
public function components(array | Closure $components): static
|
||||
{
|
||||
$this->childComponents($components);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function childComponents(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components, string $key = 'default'): static
|
||||
{
|
||||
$this->childComponents[$key] = $components;
|
||||
unset($this->cachedChildSchemas[$key]);
|
||||
|
||||
if ($key === 'default') {
|
||||
$this->cachedDefaultChildSchemas = null;
|
||||
$this->cachedDefaultChildSchemaKeys = [];
|
||||
}
|
||||
|
||||
$this->clearCachedComponentsByStatePath();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Closure $components
|
||||
*/
|
||||
public function schema(array | Schema | Closure $components): static
|
||||
{
|
||||
$this->childComponents($components);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Component | Action | ActionGroup>
|
||||
*/
|
||||
public function getChildComponents(?string $key = null): array
|
||||
{
|
||||
return $this->getChildSchema($key)->getComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Component | Action | ActionGroup | string | Htmlable> | Schema
|
||||
*/
|
||||
public function getDefaultChildComponents(): array | Schema
|
||||
{
|
||||
$wasEvaluatingDefaultChildSchemas = $this->isEvaluatingDefaultChildSchemas;
|
||||
$this->isEvaluatingDefaultChildSchemas = true;
|
||||
|
||||
try {
|
||||
return $this->evaluate($this->childComponents['default'] ?? []) ?? [];
|
||||
} finally {
|
||||
$this->isEvaluatingDefaultChildSchemas = $wasEvaluatingDefaultChildSchemas;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array-key $key
|
||||
*/
|
||||
public function getChildSchema($key = null): ?Schema
|
||||
{
|
||||
if (filled($key) && ! array_key_exists($key, $this->childComponents)) {
|
||||
return $this->getCachedDefaultChildSchemas()[$key] ?? null;
|
||||
}
|
||||
|
||||
if (filled($key) && array_key_exists($key, $cachedDefaultChildSchemas = $this->getCachedDefaultChildSchemas())) {
|
||||
return $cachedDefaultChildSchemas[$key];
|
||||
}
|
||||
|
||||
$key ??= 'default';
|
||||
|
||||
if (isset($this->evaluatingChildSchemaKeys[$key])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$isCacheable = ($key !== 'default')
|
||||
&& filled($this->childComponents[$key] ?? null)
|
||||
&& ! (($this->childComponents[$key] ?? null) instanceof Closure);
|
||||
|
||||
if ($isCacheable && isset($this->cachedChildSchemas[$key])) {
|
||||
return $this->cachedChildSchemas[$key];
|
||||
}
|
||||
|
||||
if ($key === 'default') {
|
||||
$components = $this->getDefaultChildComponents();
|
||||
} elseif (($this->childComponents[$key] ?? null) instanceof Closure) {
|
||||
$this->evaluatingChildSchemaKeys[$key] = true;
|
||||
|
||||
try {
|
||||
$components = $this->evaluate($this->childComponents[$key]) ?? [];
|
||||
} finally {
|
||||
unset($this->evaluatingChildSchemaKeys[$key]);
|
||||
}
|
||||
} else {
|
||||
$components = $this->evaluate($this->childComponents[$key] ?? []) ?? [];
|
||||
}
|
||||
|
||||
if (blank($components)) {
|
||||
return ($key === 'default')
|
||||
? $this->configureChildSchema(
|
||||
$this->makeChildSchema($key),
|
||||
$key,
|
||||
)
|
||||
: null;
|
||||
}
|
||||
|
||||
if ($components instanceof Schema) {
|
||||
$childSchema = $this->configureChildSchema(
|
||||
$components
|
||||
->livewire($this->getLivewire())
|
||||
->parentComponent($this),
|
||||
$key,
|
||||
);
|
||||
} else {
|
||||
$childSchema = $this->configureChildSchema(
|
||||
$this->makeChildSchema($key)
|
||||
->components($components),
|
||||
$key,
|
||||
);
|
||||
}
|
||||
|
||||
if ($isCacheable) {
|
||||
$this->cachedChildSchemas[$key] = $childSchema;
|
||||
}
|
||||
|
||||
return $childSchema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getChildSchema()` instead.
|
||||
*
|
||||
* @param array-key $key
|
||||
*/
|
||||
public function getChildComponentContainer($key = null): ?Schema
|
||||
{
|
||||
return $this->getChildSchema($key);
|
||||
}
|
||||
|
||||
protected function makeChildSchema(string $key): Schema
|
||||
{
|
||||
return Schema::make($this->getLivewire())
|
||||
->parentComponent($this, shouldFlushCachedHierarchy: false);
|
||||
}
|
||||
|
||||
protected function configureChildSchema(Schema $schema, string $key): Schema
|
||||
{
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Schema>
|
||||
*/
|
||||
public function getChildSchemas(bool $withHidden = false): array
|
||||
{
|
||||
if ((! $withHidden) && $this->isHidden()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
...(array_key_exists('default', $this->childComponents) ? $this->getCachedDefaultChildSchemas() : []),
|
||||
...array_reduce(
|
||||
array_keys($this->childComponents),
|
||||
function (array $carry, string $key): array {
|
||||
if ($key === 'default') {
|
||||
return $carry;
|
||||
}
|
||||
|
||||
if ($container = $this->getChildSchema($key)) {
|
||||
$carry[$key] = $container;
|
||||
}
|
||||
|
||||
return $carry;
|
||||
},
|
||||
initial: [],
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Schema>
|
||||
*
|
||||
* @internal This method is not part of the public API and should not be used. Its parameters may change at any time without notice.
|
||||
*/
|
||||
public function getCachedChildSchemas(bool $withHidden = false): array
|
||||
{
|
||||
if ((! $withHidden) && $this->isHidden()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_filter([
|
||||
...((($this->cachedDefaultChildSchemas !== null) && (! $this->isEvaluatingDefaultChildSchemas) && $this->areCachedDefaultChildSchemasFreshWithoutRecursion()) ? $this->cachedDefaultChildSchemas : []),
|
||||
...$this->cachedChildSchemas,
|
||||
], static fn (Schema $schema): bool => $schema->hasCachedComponents());
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal This method is not part of the public API and should not be used. Its parameters may change at any time without notice.
|
||||
*/
|
||||
public function isChildSchemaCached(Schema $schema, bool $withHidden = false): bool
|
||||
{
|
||||
if (((! $withHidden) && $this->isHidden()) || (! $schema->hasCachedComponents())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$defaultChildSchemaKey = $this->cachedDefaultChildSchemaKeys[spl_object_id($schema)] ?? null;
|
||||
|
||||
if ($defaultChildSchemaKey !== null) {
|
||||
return (! $this->isEvaluatingDefaultChildSchemas)
|
||||
&& (($this->cachedDefaultChildSchemas[$defaultChildSchemaKey] ?? null) === $schema)
|
||||
&& $this->isCachedDefaultChildSchemaFreshWithoutRecursion($defaultChildSchemaKey);
|
||||
}
|
||||
|
||||
return in_array($schema, $this->cachedChildSchemas, strict: true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getChildSchemas()` instead.
|
||||
*
|
||||
* @return array<Schema>
|
||||
*/
|
||||
public function getChildComponentContainers(bool $withHidden = false): array
|
||||
{
|
||||
return $this->getChildSchemas($withHidden);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Schema>
|
||||
*/
|
||||
public function getDefaultChildSchemas(): array
|
||||
{
|
||||
return ['default' => $this->getChildSchema()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Schema>
|
||||
*/
|
||||
protected function getCachedDefaultChildSchemas(): array
|
||||
{
|
||||
if ($this->isEvaluatingDefaultChildSchemas) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($this->cachedDefaultChildSchemas !== null) {
|
||||
if ($this->areCachedDefaultChildSchemasFreshWithoutRecursion()) {
|
||||
return $this->cachedDefaultChildSchemas;
|
||||
}
|
||||
|
||||
$this->clearCachedComponentsByStatePath();
|
||||
$this->cachedDefaultChildSchemas = null;
|
||||
$this->cachedDefaultChildSchemaKeys = [];
|
||||
}
|
||||
|
||||
$this->isEvaluatingDefaultChildSchemas = true;
|
||||
|
||||
try {
|
||||
$this->cachedDefaultChildSchemas = $this->getDefaultChildSchemas();
|
||||
$this->cachedDefaultChildSchemaKeys = [];
|
||||
|
||||
foreach ($this->cachedDefaultChildSchemas as $key => $schema) {
|
||||
$this->cachedDefaultChildSchemaKeys[spl_object_id($schema)] = $key;
|
||||
}
|
||||
|
||||
return $this->cachedDefaultChildSchemas;
|
||||
} finally {
|
||||
$this->isEvaluatingDefaultChildSchemas = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Components whose child schemas are derived from state, such as repeaters,
|
||||
* can override this method to compare the current state against a snapshot
|
||||
* taken when the cache was built, so that the cache invalidates itself when
|
||||
* the state changes, without an explicit `clearCachedChildSchemas()` call.
|
||||
*/
|
||||
protected function areCachedDefaultChildSchemasFresh(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function isCachedDefaultChildSchemaFresh(string | int $key): bool
|
||||
{
|
||||
return $this->areCachedDefaultChildSchemasFresh();
|
||||
}
|
||||
|
||||
protected function isCachedDefaultChildSchemaFreshWithoutRecursion(string | int $key): bool
|
||||
{
|
||||
$this->isEvaluatingDefaultChildSchemas = true;
|
||||
|
||||
try {
|
||||
return $this->isCachedDefaultChildSchemaFresh($key);
|
||||
} finally {
|
||||
$this->isEvaluatingDefaultChildSchemas = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected function areCachedDefaultChildSchemasFreshWithoutRecursion(): bool
|
||||
{
|
||||
$this->isEvaluatingDefaultChildSchemas = true;
|
||||
|
||||
try {
|
||||
return $this->areCachedDefaultChildSchemasFresh();
|
||||
} finally {
|
||||
$this->isEvaluatingDefaultChildSchemas = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function clearCachedChildSchemas(): void
|
||||
{
|
||||
$hasCachedChildComponents = false;
|
||||
|
||||
foreach ([...($this->cachedDefaultChildSchemas ?? []), ...$this->cachedChildSchemas] as $cachedChildSchema) {
|
||||
if ($cachedChildSchema->hasCachedComponents() && ($cachedChildSchema->getComponents(withActions: false, withHidden: true) !== [])) {
|
||||
$hasCachedChildComponents = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->cachedDefaultChildSchemas = null;
|
||||
$this->cachedDefaultChildSchemaKeys = [];
|
||||
$this->cachedChildSchemas = [];
|
||||
|
||||
if ($hasCachedChildComponents) {
|
||||
$this->clearCachedComponentsByStatePath();
|
||||
}
|
||||
}
|
||||
|
||||
protected function clearCachedComponentsByStatePath(): void
|
||||
{
|
||||
if (isset($this->container)) {
|
||||
$this->getContainer()->clearCachedComponentsByStatePath();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal This method is not part of the public API and should not be used. Its parameters may change at any time without notice.
|
||||
*/
|
||||
protected function flushCachedChildSchemaHierarchies(): void
|
||||
{
|
||||
$childSchemas = [
|
||||
...($this->cachedDefaultChildSchemas ?? []),
|
||||
...$this->cachedChildSchemas,
|
||||
];
|
||||
|
||||
foreach ($this->childComponents as $childComponents) {
|
||||
if ($childComponents instanceof Schema) {
|
||||
$childSchemas[] = $childComponents;
|
||||
}
|
||||
}
|
||||
|
||||
$flushedChildSchemas = [];
|
||||
|
||||
foreach ($childSchemas as $childSchema) {
|
||||
$childSchemaId = spl_object_id($childSchema);
|
||||
|
||||
if (isset($flushedChildSchemas[$childSchemaId])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$childSchema->flushCachedHierarchy();
|
||||
$flushedChildSchemas[$childSchemaId] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `clearCachedChildSchemas()` instead.
|
||||
*/
|
||||
public function clearCachedDefaultChildSchemas(): void
|
||||
{
|
||||
$this->clearCachedChildSchemas();
|
||||
}
|
||||
|
||||
protected function cloneChildComponents(): static
|
||||
{
|
||||
$this->cachedDefaultChildSchemas = null;
|
||||
$this->cachedDefaultChildSchemaKeys = [];
|
||||
$this->cachedChildSchemas = [];
|
||||
$this->evaluatingChildSchemaKeys = [];
|
||||
|
||||
foreach ($this->childComponents as $key => $childComponents) {
|
||||
if (is_array($childComponents)) {
|
||||
$this->childComponents[$key] = array_map(
|
||||
fn (Component | Action | ActionGroup | string | Htmlable $component): Component | Action | ActionGroup | string | Htmlable => match (true) {
|
||||
$component instanceof Component, $component instanceof Action, $component instanceof ActionGroup => $component->getClone(),
|
||||
default => $component,
|
||||
},
|
||||
$childComponents,
|
||||
);
|
||||
} elseif (
|
||||
($childComponents instanceof Component) ||
|
||||
($childComponents instanceof Action) ||
|
||||
($childComponents instanceof ActionGroup) ||
|
||||
($childComponents instanceof Schema)
|
||||
) {
|
||||
$this->childComponents[$key] = $childComponents->getClone();
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
90
vendor/filament/schemas/src/Components/Concerns/HasContainerGridLayout.php
vendored
Normal file
90
vendor/filament/schemas/src/Components/Concerns/HasContainerGridLayout.php
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasContainerGridLayout
|
||||
{
|
||||
/**
|
||||
* @var array<string | int, int | Closure | null> | null
|
||||
*/
|
||||
protected ?array $gridColumns = null;
|
||||
|
||||
/**
|
||||
* @param array<string, int | Closure | null> | int | Closure | null $columns
|
||||
*/
|
||||
public function grid(array | int | Closure | null $columns = 2): static
|
||||
{
|
||||
if ($columns instanceof Closure) {
|
||||
$this->gridColumns[] = $columns;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (! is_array($columns)) {
|
||||
$columns = [
|
||||
'lg' => $columns,
|
||||
];
|
||||
}
|
||||
|
||||
$this->gridColumns = [
|
||||
...($this->gridColumns ?? []),
|
||||
...$columns,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, ?int> | int | null
|
||||
*/
|
||||
public function getGridColumns(?string $breakpoint = null): array | int | null
|
||||
{
|
||||
$columns = $this->gridColumns ?? [
|
||||
'default' => 1,
|
||||
'sm' => null,
|
||||
'md' => null,
|
||||
'lg' => null,
|
||||
'xl' => null,
|
||||
'2xl' => null,
|
||||
];
|
||||
|
||||
foreach ($this->gridColumns ?? [] as $gridColumnBreakpoint => $gridColumn) {
|
||||
$gridColumn = $this->evaluate($gridColumn);
|
||||
|
||||
if (is_array($gridColumn)) {
|
||||
$columns = [
|
||||
...$columns,
|
||||
...$gridColumn,
|
||||
];
|
||||
|
||||
unset($columns[$gridColumnBreakpoint]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (blank($gridColumnBreakpoint)) {
|
||||
unset($columns[$gridColumnBreakpoint]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! is_string($gridColumnBreakpoint)) {
|
||||
$columns['lg'] = $gridColumn;
|
||||
|
||||
unset($columns[$gridColumnBreakpoint]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$columns[$gridColumnBreakpoint] = $gridColumn;
|
||||
}
|
||||
|
||||
if ($breakpoint !== null) {
|
||||
return $columns[$breakpoint] ?? null;
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
}
|
||||
23
vendor/filament/schemas/src/Components/Concerns/HasDescription.php
vendored
Normal file
23
vendor/filament/schemas/src/Components/Concerns/HasDescription.php
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
trait HasDescription
|
||||
{
|
||||
protected string | Htmlable | Closure | null $description = null;
|
||||
|
||||
public function description(string | Htmlable | Closure | null $description = null): static
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDescription(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->description);
|
||||
}
|
||||
}
|
||||
40
vendor/filament/schemas/src/Components/Concerns/HasEntryWrapper.php
vendored
Normal file
40
vendor/filament/schemas/src/Components/Concerns/HasEntryWrapper.php
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasEntryWrapper
|
||||
{
|
||||
protected string | Closure | null $entryWrapperView = null;
|
||||
|
||||
public function entryWrapperView(string | Closure | null $view): static
|
||||
{
|
||||
$this->entryWrapperView = $view;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEntryWrapperView(): string
|
||||
{
|
||||
return $this->getCustomEntryWrapperView() ??
|
||||
$this->getContainer()->getCustomEntryWrapperView() ??
|
||||
'filament-infolists::entry-wrapper';
|
||||
}
|
||||
|
||||
public function getEntryWrapperAbsoluteView(): string
|
||||
{
|
||||
$view = $this->getEntryWrapperView();
|
||||
|
||||
if (str($view)->contains('::')) {
|
||||
return str($view)->replaceFirst('::', '::components.');
|
||||
}
|
||||
|
||||
return "components.{$view}";
|
||||
}
|
||||
|
||||
public function getCustomEntryWrapperView(): ?string
|
||||
{
|
||||
return $this->evaluate($this->entryWrapperView);
|
||||
}
|
||||
}
|
||||
29
vendor/filament/schemas/src/Components/Concerns/HasFieldWrapper.php
vendored
Normal file
29
vendor/filament/schemas/src/Components/Concerns/HasFieldWrapper.php
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasFieldWrapper
|
||||
{
|
||||
protected string | Closure | null $fieldWrapperView = null;
|
||||
|
||||
public function fieldWrapperView(string | Closure | null $view): static
|
||||
{
|
||||
$this->fieldWrapperView = $view;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFieldWrapperView(): string
|
||||
{
|
||||
return $this->getCustomFieldWrapperView() ??
|
||||
$this->getContainer()->getCustomFieldWrapperView() ??
|
||||
'filament-forms::field-wrapper';
|
||||
}
|
||||
|
||||
public function getCustomFieldWrapperView(): ?string
|
||||
{
|
||||
return $this->evaluate($this->fieldWrapperView);
|
||||
}
|
||||
}
|
||||
49
vendor/filament/schemas/src/Components/Concerns/HasFooterActions.php
vendored
Normal file
49
vendor/filament/schemas/src/Components/Concerns/HasFooterActions.php
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait HasFooterActions
|
||||
{
|
||||
use HasFooterActionsAlignment;
|
||||
|
||||
/**
|
||||
* @var array<Action | ActionGroup | Closure>
|
||||
*/
|
||||
protected array $footerActions = [];
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup | Closure> $actions
|
||||
*/
|
||||
public function footerActions(array $actions): static
|
||||
{
|
||||
$this->footerActions = [
|
||||
...$this->footerActions,
|
||||
...$actions,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action | ActionGroup>
|
||||
*/
|
||||
public function getFooterActions(): array
|
||||
{
|
||||
$actions = [];
|
||||
|
||||
foreach ($this->footerActions as $footerAction) {
|
||||
foreach (Arr::wrap($this->evaluate($footerAction)) as $action) {
|
||||
$actions[] = ($action instanceof ActionGroup)
|
||||
? $this->prepareActionGroup($action)
|
||||
: $this->prepareAction($action);
|
||||
}
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
}
|
||||
23
vendor/filament/schemas/src/Components/Concerns/HasFooterActionsAlignment.php
vendored
Normal file
23
vendor/filament/schemas/src/Components/Concerns/HasFooterActionsAlignment.php
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
|
||||
trait HasFooterActionsAlignment
|
||||
{
|
||||
protected Alignment | Closure | null $footerActionsAlignment = Alignment::Start;
|
||||
|
||||
public function footerActionsAlignment(Alignment | Closure | null $alignment): static
|
||||
{
|
||||
$this->footerActionsAlignment = $alignment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFooterActionsAlignment(): ?Alignment
|
||||
{
|
||||
return $this->evaluate($this->footerActionsAlignment);
|
||||
}
|
||||
}
|
||||
47
vendor/filament/schemas/src/Components/Concerns/HasHeaderActions.php
vendored
Normal file
47
vendor/filament/schemas/src/Components/Concerns/HasHeaderActions.php
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait HasHeaderActions
|
||||
{
|
||||
/**
|
||||
* @var array<Action | ActionGroup | Closure>
|
||||
*/
|
||||
protected array $headerActions = [];
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup | Closure> $actions
|
||||
*/
|
||||
public function headerActions(array $actions): static
|
||||
{
|
||||
$this->headerActions = [
|
||||
...$this->headerActions,
|
||||
...$actions,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action | ActionGroup>
|
||||
*/
|
||||
public function getHeaderActions(): array
|
||||
{
|
||||
$actions = [];
|
||||
|
||||
foreach ($this->headerActions as $headerAction) {
|
||||
foreach (Arr::wrap($this->evaluate($headerAction)) as $action) {
|
||||
$actions[] = ($action instanceof ActionGroup)
|
||||
? $this->prepareActionGroup($action)
|
||||
: $this->prepareAction($action);
|
||||
}
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
}
|
||||
23
vendor/filament/schemas/src/Components/Concerns/HasHeading.php
vendored
Normal file
23
vendor/filament/schemas/src/Components/Concerns/HasHeading.php
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
trait HasHeading
|
||||
{
|
||||
protected string | Htmlable | Closure | null $heading = null;
|
||||
|
||||
public function heading(string | Htmlable | Closure | null $heading = null): static
|
||||
{
|
||||
$this->heading = $heading;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHeading(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->heading);
|
||||
}
|
||||
}
|
||||
32
vendor/filament/schemas/src/Components/Concerns/HasHeadings.php
vendored
Normal file
32
vendor/filament/schemas/src/Components/Concerns/HasHeadings.php
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
trait HasHeadings
|
||||
{
|
||||
public function getHeadingLevel(int $index = 0): int
|
||||
{
|
||||
return $this->getContainer()->getRootHeadingLevel() + $index;
|
||||
}
|
||||
|
||||
public function getHeadingTag(int $index = 0): string
|
||||
{
|
||||
$level = $this->getHeadingLevel($index);
|
||||
|
||||
if ($level > 6) {
|
||||
return 'p';
|
||||
}
|
||||
|
||||
return "h{$level}";
|
||||
}
|
||||
|
||||
public function getChildSchemaRootHeadingLevel(): int
|
||||
{
|
||||
return $this->getHeadingLevel() + $this->getHeadingsCount();
|
||||
}
|
||||
|
||||
public function getHeadingsCount(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
30
vendor/filament/schemas/src/Components/Concerns/HasId.php
vendored
Normal file
30
vendor/filament/schemas/src/Components/Concerns/HasId.php
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasId
|
||||
{
|
||||
protected string | Closure | null $id = null;
|
||||
|
||||
public function id(string | Closure | null $id): static
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId(): ?string
|
||||
{
|
||||
return $this->getCustomId() ?? $this->getKey();
|
||||
}
|
||||
|
||||
public function getCustomId(): ?string
|
||||
{
|
||||
$id = $this->evaluate($this->id);
|
||||
|
||||
// Security: Strip characters that could break out of a quoted HTML attribute or a JS string, so every downstream sink that embeds this ID raw is safe without per-sink escaping. Legitimate IDs never contain these characters.
|
||||
return ($id === null) ? null : preg_replace('/[<>"\'`\x00-\x1F\x7F]/', '', $id);
|
||||
}
|
||||
}
|
||||
22
vendor/filament/schemas/src/Components/Concerns/HasInlineLabel.php
vendored
Normal file
22
vendor/filament/schemas/src/Components/Concerns/HasInlineLabel.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasInlineLabel
|
||||
{
|
||||
protected bool | Closure | null $hasInlineLabel = null;
|
||||
|
||||
public function inlineLabel(bool | Closure | null $condition = true): static
|
||||
{
|
||||
$this->hasInlineLabel = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasInlineLabel(): ?bool
|
||||
{
|
||||
return $this->evaluate($this->hasInlineLabel) ?? $this->getContainer()->hasInlineLabel();
|
||||
}
|
||||
}
|
||||
139
vendor/filament/schemas/src/Components/Concerns/HasKey.php
vendored
Normal file
139
vendor/filament/schemas/src/Components/Concerns/HasKey.php
vendored
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasKey
|
||||
{
|
||||
protected string | Closure | null $key = null;
|
||||
|
||||
protected bool $isKeyInheritable = true;
|
||||
|
||||
protected ?string $cachedAbsoluteKey = null;
|
||||
|
||||
protected bool $hasCachedAbsoluteKey = false;
|
||||
|
||||
protected ?string $cachedAbsoluteInheritanceKey = null;
|
||||
|
||||
protected bool $hasCachedAbsoluteInheritanceKey = false;
|
||||
|
||||
public function key(string | Closure | null $key, bool $isInheritable = true): static
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->isKeyInheritable = $isInheritable;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getKey(bool $isAbsolute = true): ?string
|
||||
{
|
||||
if ($isAbsolute && $this->hasCachedAbsoluteKey) {
|
||||
return $this->cachedAbsoluteKey;
|
||||
}
|
||||
|
||||
$key = ($this->isKeyInheritable() || (! $this->hasStatePath()))
|
||||
? ($this->evaluate($this->key) ?? $this->getStatePath(isAbsolute: false))
|
||||
: $this->getStatePath(isAbsolute: false);
|
||||
|
||||
// Security: Strip characters that could break out of a quoted HTML attribute or a JS string, so every downstream sink that embeds this key raw (including `getLivewireKey()` and `getId()`) is safe without per-sink escaping. Legitimate keys never contain these characters.
|
||||
if ($key !== null) {
|
||||
$key = preg_replace('/[<>"\'`\x00-\x1F\x7F]/', '', $key);
|
||||
}
|
||||
|
||||
if (! $isAbsolute) {
|
||||
return $key;
|
||||
}
|
||||
|
||||
if (blank($key)) {
|
||||
return $this->cacheAbsoluteKey(null);
|
||||
}
|
||||
|
||||
$keyComponents = [];
|
||||
|
||||
if (filled($containerInheritanceKey = $this->getContainer()->getInheritanceKey())) {
|
||||
$keyComponents[] = $containerInheritanceKey;
|
||||
}
|
||||
|
||||
$keyComponents[] = $key;
|
||||
|
||||
return $this->cacheAbsoluteKey(implode('.', $keyComponents));
|
||||
}
|
||||
|
||||
public function getInheritanceKey(bool $isAbsolute = true): ?string
|
||||
{
|
||||
if ($isAbsolute && $this->hasCachedAbsoluteInheritanceKey) {
|
||||
return $this->cachedAbsoluteInheritanceKey;
|
||||
}
|
||||
|
||||
if (! $isAbsolute) {
|
||||
return $this->isKeyInheritable() ? $this->getKey(isAbsolute: false) : $this->getStatePath(isAbsolute: false);
|
||||
}
|
||||
|
||||
if ($this->isKeyInheritable()) {
|
||||
$key = $this->getKey();
|
||||
|
||||
if (filled($key)) {
|
||||
return $this->cacheAbsoluteInheritanceKey($key);
|
||||
}
|
||||
} elseif ($this->hasStatePath()) {
|
||||
$keyComponents = [];
|
||||
|
||||
if (filled($containerInheritanceKey = $this->getContainer()->getInheritanceKey())) {
|
||||
$keyComponents[] = $containerInheritanceKey;
|
||||
}
|
||||
|
||||
$keyComponents[] = $this->getStatePath(isAbsolute: false);
|
||||
|
||||
return $this->cacheAbsoluteInheritanceKey(implode('.', $keyComponents));
|
||||
}
|
||||
|
||||
return $this->cacheAbsoluteInheritanceKey($this->getContainer()->getInheritanceKey());
|
||||
}
|
||||
|
||||
public function isKeyInheritable(): bool
|
||||
{
|
||||
return $this->isKeyInheritable;
|
||||
}
|
||||
|
||||
protected function cacheAbsoluteKey(?string $key): ?string
|
||||
{
|
||||
try {
|
||||
return $this->cachedAbsoluteKey = $key;
|
||||
} finally {
|
||||
$this->hasCachedAbsoluteKey = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function cacheAbsoluteInheritanceKey(?string $key): ?string
|
||||
{
|
||||
try {
|
||||
return $this->cachedAbsoluteInheritanceKey = $key;
|
||||
} finally {
|
||||
$this->hasCachedAbsoluteInheritanceKey = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function flushCachedAbsoluteKey(): void
|
||||
{
|
||||
$this->cachedAbsoluteKey = null;
|
||||
$this->hasCachedAbsoluteKey = false;
|
||||
}
|
||||
|
||||
protected function flushCachedAbsoluteInheritanceKey(): void
|
||||
{
|
||||
$this->cachedAbsoluteInheritanceKey = null;
|
||||
$this->hasCachedAbsoluteInheritanceKey = false;
|
||||
}
|
||||
|
||||
public function getLivewireKey(): ?string
|
||||
{
|
||||
$key = $this->getKey();
|
||||
|
||||
if (blank($key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return "{$this->getLivewire()->getId()}.{$key}";
|
||||
}
|
||||
}
|
||||
65
vendor/filament/schemas/src/Components/Concerns/HasLabel.php
vendored
Normal file
65
vendor/filament/schemas/src/Components/Concerns/HasLabel.php
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
trait HasLabel
|
||||
{
|
||||
protected bool | Closure $isLabelHidden = false;
|
||||
|
||||
protected string | Htmlable | Closure | null $label = null;
|
||||
|
||||
protected bool $shouldTranslateLabel = false;
|
||||
|
||||
/**
|
||||
* @deprecated Use `hiddenLabel()` instead.
|
||||
*/
|
||||
public function disableLabel(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->hiddenLabel($condition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hiddenLabel(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isLabelHidden = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function label(string | Htmlable | Closure | null $label): static
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function translateLabel(bool $shouldTranslateLabel = true): static
|
||||
{
|
||||
$this->shouldTranslateLabel = $shouldTranslateLabel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLabel(): string | Htmlable | null
|
||||
{
|
||||
$label = $this->evaluate($this->label);
|
||||
|
||||
return (is_string($label) && $this->shouldTranslateLabel) ?
|
||||
__($label) :
|
||||
$label;
|
||||
}
|
||||
|
||||
public function hasCustomLabel(): bool
|
||||
{
|
||||
return $this->label !== null;
|
||||
}
|
||||
|
||||
public function isLabelHidden(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isLabelHidden);
|
||||
}
|
||||
}
|
||||
33
vendor/filament/schemas/src/Components/Concerns/HasMaxWidth.php
vendored
Normal file
33
vendor/filament/schemas/src/Components/Concerns/HasMaxWidth.php
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
trait HasMaxWidth
|
||||
{
|
||||
protected Width | string | Closure | null $maxWidth = null;
|
||||
|
||||
public function maxWidth(Width | string | Closure | null $width): static
|
||||
{
|
||||
$this->maxWidth = $width;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMaxWidth(): Width | string | null
|
||||
{
|
||||
$width = $this->evaluate($this->maxWidth);
|
||||
|
||||
if (blank($width)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_string($width)) {
|
||||
$width = Width::tryFrom($width) ?? $width;
|
||||
}
|
||||
|
||||
return $width;
|
||||
}
|
||||
}
|
||||
44
vendor/filament/schemas/src/Components/Concerns/HasMeta.php
vendored
Normal file
44
vendor/filament/schemas/src/Components/Concerns/HasMeta.php
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait HasMeta
|
||||
{
|
||||
/**
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
protected array $meta = [];
|
||||
|
||||
public function meta(string $key, mixed $value): static
|
||||
{
|
||||
$this->meta[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | null $keys
|
||||
*/
|
||||
public function getMeta(string | array | null $keys = null): mixed
|
||||
{
|
||||
if (is_array($keys)) {
|
||||
return Arr::only($this->meta, $keys);
|
||||
}
|
||||
|
||||
if (is_string($keys)) {
|
||||
return Arr::get($this->meta, $keys);
|
||||
}
|
||||
|
||||
return $this->meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> $keys
|
||||
*/
|
||||
public function hasMeta(string | array $keys): bool
|
||||
{
|
||||
return Arr::has($this->meta, $keys);
|
||||
}
|
||||
}
|
||||
20
vendor/filament/schemas/src/Components/Concerns/HasName.php
vendored
Normal file
20
vendor/filament/schemas/src/Components/Concerns/HasName.php
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Concerns;
|
||||
|
||||
trait HasName
|
||||
{
|
||||
protected string $name;
|
||||
|
||||
public function name(string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
||||
1118
vendor/filament/schemas/src/Components/Concerns/HasState.php
vendored
Normal file
1118
vendor/filament/schemas/src/Components/Concerns/HasState.php
vendored
Normal file
File diff suppressed because it is too large
Load diff
8
vendor/filament/schemas/src/Components/Contracts/CanConcealComponents.php
vendored
Normal file
8
vendor/filament/schemas/src/Components/Contracts/CanConcealComponents.php
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Contracts;
|
||||
|
||||
/**
|
||||
* @deprecated Fields no longer strip their native validation attributes when concealed, so concealing containers no longer need to be identified.
|
||||
*/
|
||||
interface CanConcealComponents {}
|
||||
48
vendor/filament/schemas/src/Components/Contracts/CanEntangleWithSingularRelationships.php
vendored
Normal file
48
vendor/filament/schemas/src/Components/Contracts/CanEntangleWithSingularRelationships.php
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Contracts;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
|
||||
interface CanEntangleWithSingularRelationships
|
||||
{
|
||||
public function cachedExistingRecord(?Model $record): static;
|
||||
|
||||
public function clearCachedExistingRecord(): void;
|
||||
|
||||
public function fillFromRelationship(): void;
|
||||
|
||||
public function getCachedExistingRecord(): ?Model;
|
||||
|
||||
/**
|
||||
* @return class-string<Model>|null
|
||||
*/
|
||||
public function getRelatedModel(): ?string;
|
||||
|
||||
public function getRelationship(): BelongsTo | HasOne | MorphOne | null;
|
||||
|
||||
public function getRelationshipName(): ?string;
|
||||
|
||||
public function hasRelationship(): bool;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function mutateRelationshipDataBeforeFill(array $data): array;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function mutateRelationshipDataBeforeCreate(array $data): array;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function mutateRelationshipDataBeforeSave(array $data): array;
|
||||
}
|
||||
5
vendor/filament/schemas/src/Components/Contracts/ExposesStateToActionData.php
vendored
Normal file
5
vendor/filament/schemas/src/Components/Contracts/ExposesStateToActionData.php
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Contracts;
|
||||
|
||||
interface ExposesStateToActionData {}
|
||||
18
vendor/filament/schemas/src/Components/Contracts/HasAffixActions.php
vendored
Normal file
18
vendor/filament/schemas/src/Components/Contracts/HasAffixActions.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Contracts;
|
||||
|
||||
use Filament\Actions\Action;
|
||||
|
||||
interface HasAffixActions
|
||||
{
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function getPrefixActions(): array;
|
||||
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function getSuffixActions(): array;
|
||||
}
|
||||
18
vendor/filament/schemas/src/Components/Contracts/HasExtraItemActions.php
vendored
Normal file
18
vendor/filament/schemas/src/Components/Contracts/HasExtraItemActions.php
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Contracts;
|
||||
|
||||
use Filament\Actions\Action;
|
||||
|
||||
interface HasExtraItemActions
|
||||
{
|
||||
/**
|
||||
* @return array<Action>
|
||||
*/
|
||||
public function getExtraItemActions(): array;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getItemState(string $key): array;
|
||||
}
|
||||
41
vendor/filament/schemas/src/Components/EmbeddedSchema.php
vendored
Normal file
41
vendor/filament/schemas/src/Components/EmbeddedSchema.php
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
|
||||
class EmbeddedSchema extends Component implements HasEmbeddedView
|
||||
{
|
||||
protected string | Closure $name;
|
||||
|
||||
final public function __construct(string | Closure $name)
|
||||
{
|
||||
$this->name($name);
|
||||
}
|
||||
|
||||
public static function make(string $name): static
|
||||
{
|
||||
$static = app(static::class, ['name' => $name]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function name(string | Closure $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->evaluate($this->name);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
return $this->getLivewire()->getSchema($this->getName())->toHtml();
|
||||
}
|
||||
}
|
||||
37
vendor/filament/schemas/src/Components/EmbeddedTable.php
vendored
Normal file
37
vendor/filament/schemas/src/Components/EmbeddedTable.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use LogicException;
|
||||
|
||||
class EmbeddedTable extends Component
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> | Closure $livewireComponentData
|
||||
*/
|
||||
public static function make(string | Closure | null $livewireComponent = null, array | Closure $livewireComponentData = []): static | Livewire
|
||||
{
|
||||
if (filled($livewireComponent)) {
|
||||
return Livewire::make($livewireComponent, $livewireComponentData);
|
||||
}
|
||||
|
||||
$static = app(static::class);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
$livewire = $this->getLivewire();
|
||||
|
||||
if (! ($livewire instanceof HasTable)) {
|
||||
throw new LogicException('The [' . $livewire::class . '] component must have a table defined.');
|
||||
}
|
||||
|
||||
return $livewire->getTable()->render();
|
||||
}
|
||||
}
|
||||
157
vendor/filament/schemas/src/Components/EmptyState.php
vendored
Normal file
157
vendor/filament/schemas/src/Components/EmptyState.php
vendored
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Schemas\Components\Concerns\CanBeCompact;
|
||||
use Filament\Schemas\Components\Concerns\HasDescription;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\CanBeContained;
|
||||
use Filament\Support\Concerns\HasIcon;
|
||||
use Filament\Support\Concerns\HasIconColor;
|
||||
use Filament\Support\Concerns\HasIconSize;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Support\View\Components\SectionComponent\IconComponent;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
use function Filament\Support\generate_icon_html;
|
||||
|
||||
class EmptyState extends Component implements HasEmbeddedView
|
||||
{
|
||||
use CanBeCompact;
|
||||
use CanBeContained;
|
||||
use HasDescription;
|
||||
use HasIcon;
|
||||
use HasIconColor;
|
||||
use HasIconSize;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.empty-state';
|
||||
|
||||
protected string | Htmlable | Closure $heading;
|
||||
|
||||
const FOOTER_SCHEMA_KEY = 'footer';
|
||||
|
||||
final public function __construct(string | Htmlable | Closure $heading)
|
||||
{
|
||||
$this->heading($heading);
|
||||
}
|
||||
|
||||
public static function make(string | Htmlable | Closure $heading): static
|
||||
{
|
||||
$static = app(static::class, ['heading' => $heading]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function footer(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::FOOTER_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function configureChildSchema(Schema $schema, string $key): Schema
|
||||
{
|
||||
$schema = parent::configureChildSchema($schema, $key);
|
||||
|
||||
if (in_array($key, [
|
||||
static::FOOTER_SCHEMA_KEY,
|
||||
])) {
|
||||
$schema
|
||||
->inline()
|
||||
->embeddedInParentComponent();
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public function heading(string | Htmlable | Closure $heading): static
|
||||
{
|
||||
$this->heading = $heading;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHeading(): string | Htmlable
|
||||
{
|
||||
return $this->evaluate($this->heading);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$description = $this->getDescription();
|
||||
$footer = $this->getChildSchema(static::FOOTER_SCHEMA_KEY)?->toHtmlString();
|
||||
$heading = $this->getHeading();
|
||||
$headingTag = $this->getHeadingTag();
|
||||
$icon = $this->getIcon();
|
||||
$iconColor = $this->getIconColor() ?? 'primary';
|
||||
$iconSize = $this->getIconSize();
|
||||
$isCompact = $this->isCompact();
|
||||
$isContained = $this->isContained();
|
||||
|
||||
if (filled($iconSize) && (! $iconSize instanceof IconSize)) {
|
||||
$iconSize = IconSize::tryFrom($iconSize) ?? $iconSize;
|
||||
}
|
||||
|
||||
$hasDescription = filled((string) $description);
|
||||
$hasFooter = filled((string) $footer);
|
||||
$hasIcon = filled($icon);
|
||||
|
||||
$outerAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->class(['fi-sc-empty-state']);
|
||||
|
||||
$sectionAttributes = (new FilamentComponentAttributeBag)
|
||||
->class([
|
||||
'fi-empty-state',
|
||||
'fi-compact' => $isCompact,
|
||||
'fi-empty-state-not-contained' => ! $isContained,
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $outerAttributes->toHtml() ?>>
|
||||
<section <?= $sectionAttributes->toHtml() ?>>
|
||||
<div class="fi-empty-state-content">
|
||||
<?php if ($hasIcon) { ?>
|
||||
<div
|
||||
<?= (new FilamentComponentAttributeBag)->class([
|
||||
'fi-empty-state-icon-bg',
|
||||
'fi-color ' . ('fi-color-' . $iconColor) => $iconColor !== 'gray',
|
||||
])->toHtml() ?>
|
||||
>
|
||||
<?= generate_icon_html($icon, attributes: (new FilamentComponentAttributeBag)
|
||||
->color(IconComponent::class, $iconColor), size: $iconSize ?? IconSize::Large)?->toHtml() ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="fi-empty-state-text-ctn">
|
||||
<<?= $headingTag ?> class="fi-empty-state-heading">
|
||||
<?= e($heading) ?>
|
||||
</<?= $headingTag ?>>
|
||||
|
||||
<?php if ($hasDescription) { ?>
|
||||
<p class="fi-empty-state-description"><?= e($description) ?></p>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasFooter) { ?>
|
||||
<footer class="fi-empty-state-footer">
|
||||
<?= $footer->toHtml() ?>
|
||||
</footer>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
76
vendor/filament/schemas/src/Components/Fieldset.php
vendored
Normal file
76
vendor/filament/schemas/src/Components/Fieldset.php
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Forms\Components\Concerns\CanBeMarkedAsRequired;
|
||||
use Filament\Schemas\Components\Concerns\EntanglesStateWithSingularRelationship;
|
||||
use Filament\Schemas\Components\Concerns\HasLabel;
|
||||
use Filament\Schemas\Components\Contracts\CanEntangleWithSingularRelationships;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\CanBeContained;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class Fieldset extends Component implements CanEntangleWithSingularRelationships, HasEmbeddedView
|
||||
{
|
||||
use CanBeContained;
|
||||
use CanBeMarkedAsRequired;
|
||||
use EntanglesStateWithSingularRelationship;
|
||||
use HasLabel;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.fieldset';
|
||||
|
||||
final public function __construct(string | Htmlable | Closure | null $label = null)
|
||||
{
|
||||
$this->label($label);
|
||||
}
|
||||
|
||||
public static function make(string | Htmlable | Closure | null $label = null): static
|
||||
{
|
||||
$static = app(static::class, ['label' => $label]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->columns(2);
|
||||
}
|
||||
|
||||
public function isRequired(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$id = $this->getId();
|
||||
$isLabelHidden = $this->isLabelHidden();
|
||||
$label = $this->getLabel();
|
||||
$isContained = $this->isContained();
|
||||
$isRequired = $this->isMarkedAsRequired();
|
||||
|
||||
$attributes = (new FilamentComponentAttributeBag)
|
||||
->merge(['id' => $id], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->class([
|
||||
'fi-sc-fieldset',
|
||||
'fi-fieldset',
|
||||
'fi-fieldset-label-hidden' => $isLabelHidden,
|
||||
'fi-fieldset-not-contained' => ! $isContained,
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
<fieldset <?= $attributes->toHtml() ?>>
|
||||
<?php if (filled($label)) { ?>
|
||||
<legend><?= e($label) ?><?php if ($isRequired) { ?><sup class="fi-fieldset-label-required-mark">*</sup><?php } ?></legend>
|
||||
<?php } ?>
|
||||
<?= $this->getChildSchema()->toHtml() ?>
|
||||
</fieldset>
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
121
vendor/filament/schemas/src/Components/Flex.php
vendored
Normal file
121
vendor/filament/schemas/src/Components/Flex.php
vendored
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Schemas\Components\Concerns\EntanglesStateWithSingularRelationship;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\HasAlignment;
|
||||
use Filament\Support\Concerns\HasFromBreakpoint;
|
||||
use Filament\Support\Concerns\HasVerticalAlignment;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\Enums\VerticalAlignment;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
|
||||
class Flex extends Component implements HasEmbeddedView
|
||||
{
|
||||
use EntanglesStateWithSingularRelationship;
|
||||
use HasAlignment;
|
||||
use HasFromBreakpoint;
|
||||
use HasVerticalAlignment;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.flex';
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Closure $schema
|
||||
*/
|
||||
final public function __construct(array | Closure $schema)
|
||||
{
|
||||
$this->schema($schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Closure $schema
|
||||
*/
|
||||
public static function make(array | Closure $schema): static
|
||||
{
|
||||
$static = app(static::class, ['schema' => $schema]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$statePath = $this->getStatePath();
|
||||
$fromBreakpoint = $this->getFromBreakpoint();
|
||||
$verticalAlignment = $this->getVerticalAlignment();
|
||||
$alignment = $this->getAlignment();
|
||||
|
||||
if (! $verticalAlignment instanceof VerticalAlignment) {
|
||||
$verticalAlignment = filled($verticalAlignment) ? (VerticalAlignment::tryFrom($verticalAlignment) ?? $verticalAlignment) : null;
|
||||
}
|
||||
|
||||
if (! $alignment instanceof Alignment) {
|
||||
$alignment = filled($alignment) ? (Alignment::tryFrom($alignment) ?? $alignment) : null;
|
||||
}
|
||||
|
||||
$attributes = (new FilamentComponentAttributeBag)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->class([
|
||||
'fi-sc-flex',
|
||||
'fi-dense' => $this->isDense(),
|
||||
'fi-from-' . ($fromBreakpoint ?? 'default'),
|
||||
($verticalAlignment instanceof VerticalAlignment) ? "fi-vertical-align-{$verticalAlignment->value}" : $verticalAlignment,
|
||||
($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : $alignment,
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?php foreach ($this->getChildSchema()->getComponents() as $schemaComponent) { ?>
|
||||
<?php if (($schemaComponent instanceof Action) || ($schemaComponent instanceof ActionGroup)) { ?>
|
||||
<div>
|
||||
<?= $schemaComponent->toHtml() ?>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<?php
|
||||
$hiddenJs = $schemaComponent->getHiddenJs();
|
||||
$visibleJs = $schemaComponent->getVisibleJs();
|
||||
$schemaComponentStatePath = $schemaComponent->getStatePath();
|
||||
|
||||
$visibilityJs = match ([filled($hiddenJs), filled($visibleJs)]) {
|
||||
[true, true] => "(! ({$hiddenJs})) && ({$visibleJs})",
|
||||
[true, false] => "! ({$hiddenJs})",
|
||||
[false, true] => $visibleJs,
|
||||
default => null,
|
||||
};
|
||||
?>
|
||||
<div
|
||||
x-data="filamentSchemaComponent({
|
||||
path: <?= Js::from($schemaComponentStatePath) ?>,
|
||||
containerPath: <?= Js::from($statePath) ?>,
|
||||
$wire,
|
||||
})"
|
||||
<?php if ($afterStateUpdatedJs = $schemaComponent->getAfterStateUpdatedJs()) { ?>
|
||||
x-init="<?= implode(';', array_map(
|
||||
fn (string $js): string => '$wire; $wire.watch(' . Js::from($schemaComponentStatePath) . ', ($state, $old) => isStateChanged($state, $old) && eval(' . Js::from($js) . '))',
|
||||
$afterStateUpdatedJs,
|
||||
)) ?>"
|
||||
<?php } ?>
|
||||
<?php if (filled($visibilityJs)) { ?>
|
||||
x-bind:class="{ 'fi-hidden': ! (<?= $visibilityJs ?>) }"
|
||||
x-cloak
|
||||
<?php } ?>
|
||||
<?php if ($schemaComponent->canGrow()) { ?>
|
||||
class="fi-growable"
|
||||
<?php } ?>
|
||||
>
|
||||
<?= $schemaComponent->toHtml() ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
129
vendor/filament/schemas/src/Components/Form.php
vendored
Normal file
129
vendor/filament/schemas/src/Components/Form.php
vendored
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Schemas\Components\Concerns\EntanglesStateWithSingularRelationship;
|
||||
use Filament\Schemas\Components\Contracts\CanEntangleWithSingularRelationships;
|
||||
use Filament\Schemas\Components\Contracts\ExposesStateToActionData;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class Form extends Component implements CanEntangleWithSingularRelationships, ExposesStateToActionData, HasEmbeddedView
|
||||
{
|
||||
use EntanglesStateWithSingularRelationship;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.form';
|
||||
|
||||
protected string | Closure | null $livewireSubmitHandler = null;
|
||||
|
||||
const HEADER_SCHEMA_KEY = 'header';
|
||||
|
||||
const FOOTER_SCHEMA_KEY = 'footer';
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Closure $schema
|
||||
*/
|
||||
final public function __construct(array | Closure $schema = [])
|
||||
{
|
||||
$this->schema($schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Closure $schema
|
||||
*/
|
||||
public static function make(array | Closure $schema = []): static
|
||||
{
|
||||
$static = app(static::class, ['schema' => $schema]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function action(Action | Closure | null $action): static
|
||||
{
|
||||
if ($action instanceof Closure) {
|
||||
$action = Action::make('submit')->action($action);
|
||||
}
|
||||
|
||||
parent::action($action);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function livewireSubmitHandler(string | Closure | null $handler): static
|
||||
{
|
||||
$this->livewireSubmitHandler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLivewireSubmitHandler(): ?string
|
||||
{
|
||||
return $this->evaluate($this->livewireSubmitHandler) ?? $this->action?->getLivewireClickHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function header(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::HEADER_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function footer(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::FOOTER_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$attributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'id' => $this->getId(),
|
||||
'wire:submit' => $this->getLivewireSubmitHandler(),
|
||||
], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->class([
|
||||
'fi-sc-form',
|
||||
'fi-dense' => $this->isDense(),
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<form <?= $attributes->toHtml() ?>>
|
||||
<?= $this->getChildSchema(static::HEADER_SCHEMA_KEY)?->toHtml() ?>
|
||||
|
||||
<?= $this->getChildSchema()?->toHtml() ?>
|
||||
|
||||
<?= $this->getChildSchema(static::FOOTER_SCHEMA_KEY)?->toHtml() ?>
|
||||
</form>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
protected function configureChildSchema(Schema $schema, string $key): Schema
|
||||
{
|
||||
$schema = parent::configureChildSchema($schema, $key);
|
||||
|
||||
if (in_array($key, [
|
||||
static::HEADER_SCHEMA_KEY,
|
||||
static::FOOTER_SCHEMA_KEY,
|
||||
])) {
|
||||
$schema->embeddedInParentComponent();
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
}
|
||||
458
vendor/filament/schemas/src/Components/FusedGroup.php
vendored
Normal file
458
vendor/filament/schemas/src/Components/FusedGroup.php
vendored
Normal file
|
|
@ -0,0 +1,458 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Forms\Components\Concerns\CanBeMarkedAsRequired;
|
||||
use Filament\Forms\Components\Concerns\HasExtraFieldWrapperAttributes;
|
||||
use Filament\Forms\Components\Concerns\HasHelperText;
|
||||
use Filament\Forms\Components\Contracts\HasNestedRecursiveValidationRules;
|
||||
use Filament\Forms\Components\Field;
|
||||
use Filament\Schemas\Components\Concerns\EntanglesStateWithSingularRelationship;
|
||||
use Filament\Schemas\Components\Concerns\HasLabel;
|
||||
use Filament\Schemas\Components\Contracts\CanEntangleWithSingularRelationships;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Components\ViewComponent;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Support\Enums\VerticalAlignment;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\Support\ViewErrorBag;
|
||||
use Illuminate\View\ComponentSlot;
|
||||
|
||||
class FusedGroup extends Component implements CanEntangleWithSingularRelationships, HasEmbeddedView
|
||||
{
|
||||
use CanBeMarkedAsRequired;
|
||||
use EntanglesStateWithSingularRelationship;
|
||||
use HasExtraFieldWrapperAttributes;
|
||||
use HasHelperText;
|
||||
use HasLabel;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.fused-group';
|
||||
|
||||
const ABOVE_LABEL_SCHEMA_KEY = 'above_label';
|
||||
|
||||
const BELOW_LABEL_SCHEMA_KEY = 'below_label';
|
||||
|
||||
const BEFORE_LABEL_SCHEMA_KEY = 'before_label';
|
||||
|
||||
const AFTER_LABEL_SCHEMA_KEY = 'after_label';
|
||||
|
||||
const BEFORE_CONTENT_SCHEMA_KEY = 'before_content';
|
||||
|
||||
const AFTER_CONTENT_SCHEMA_KEY = 'after_content';
|
||||
|
||||
const ABOVE_CONTENT_SCHEMA_KEY = 'above_content';
|
||||
|
||||
const BELOW_CONTENT_SCHEMA_KEY = 'below_content';
|
||||
|
||||
const ABOVE_ERROR_MESSAGE_SCHEMA_KEY = 'above_error_message';
|
||||
|
||||
const BELOW_ERROR_MESSAGE_SCHEMA_KEY = 'below_error_message';
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Closure $schema
|
||||
*/
|
||||
final public function __construct(array | Closure $schema = [])
|
||||
{
|
||||
$this->schema($schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Closure $schema
|
||||
*/
|
||||
public static function make(array | Closure $schema = []): static
|
||||
{
|
||||
$static = app(static::class, ['schema' => $schema]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->gap(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function aboveLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::ABOVE_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function belowLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BELOW_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function beforeLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BEFORE_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function afterLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::AFTER_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function beforeContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BEFORE_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function afterContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::AFTER_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function aboveContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::ABOVE_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function belowContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BELOW_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function aboveErrorMessage(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::ABOVE_ERROR_MESSAGE_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function belowErrorMessage(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BELOW_ERROR_MESSAGE_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function makeChildSchema(string $key): Schema
|
||||
{
|
||||
$schema = parent::makeChildSchema($key);
|
||||
|
||||
if ($key === static::AFTER_LABEL_SCHEMA_KEY) {
|
||||
$schema->alignEnd();
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
protected function configureChildSchema(Schema $schema, string $key): Schema
|
||||
{
|
||||
$schema = parent::configureChildSchema($schema, $key);
|
||||
|
||||
$schema->fieldWrapperView('filament-forms::plain-field-wrapper');
|
||||
|
||||
if (in_array($key, [
|
||||
static::BEFORE_LABEL_SCHEMA_KEY,
|
||||
static::AFTER_LABEL_SCHEMA_KEY,
|
||||
static::ABOVE_CONTENT_SCHEMA_KEY,
|
||||
static::BELOW_CONTENT_SCHEMA_KEY,
|
||||
static::ABOVE_ERROR_MESSAGE_SCHEMA_KEY,
|
||||
static::BELOW_ERROR_MESSAGE_SCHEMA_KEY,
|
||||
])) {
|
||||
$schema
|
||||
->inline()
|
||||
->embeddedInParentComponent()
|
||||
->modifyActionsUsing(fn (Action $action) => $action
|
||||
->defaultSize(Size::Small)
|
||||
->defaultView(Action::LINK_VIEW))
|
||||
->modifyActionGroupsUsing(fn (ActionGroup $actionGroup) => $actionGroup->defaultSize(Size::Small));
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
// Custom error collection from child fields
|
||||
/** @var MessageBag $errors */
|
||||
$errors = view()->shared('errors') instanceof ViewErrorBag
|
||||
? view()->shared('errors')->getBag('default')
|
||||
: new MessageBag;
|
||||
|
||||
$errorMessage = null;
|
||||
$errorMessages = [];
|
||||
$areHtmlErrorMessagesAllowed = false;
|
||||
|
||||
foreach ($this->getChildComponentContainer()->getComponents() as $childComponent) {
|
||||
if (! ($childComponent instanceof Field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$statePath = $childComponent->getStatePath();
|
||||
|
||||
if (blank($statePath)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($errors->has($statePath)) {
|
||||
if ($childComponent->shouldShowAllValidationMessages()) {
|
||||
$errorMessages = $errors->get($statePath);
|
||||
} else {
|
||||
$errorMessage = $errors->first($statePath);
|
||||
}
|
||||
|
||||
$areHtmlErrorMessagesAllowed = $childComponent->areHtmlValidationMessagesAllowed();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (! ($childComponent instanceof HasNestedRecursiveValidationRules)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($errors->has("{$statePath}.*")) {
|
||||
if ($childComponent->shouldShowAllValidationMessages()) {
|
||||
$errorMessages = Arr::flatten($errors->get("{$statePath}.*"));
|
||||
} else {
|
||||
$errorMessage = $errors->first("{$statePath}.*");
|
||||
}
|
||||
|
||||
$areHtmlErrorMessagesAllowed = $childComponent->areHtmlValidationMessagesAllowed();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// A single message renders as `<p>`; only multiple messages render as
|
||||
// `<ul><li>`, so collapse a one-element list into the scalar form.
|
||||
if (count($errorMessages) === 1) {
|
||||
$errorMessage = Arr::first($errorMessages);
|
||||
$errorMessages = [];
|
||||
}
|
||||
|
||||
$hasError = filled($errorMessage) || filled($errorMessages);
|
||||
|
||||
// Inner content
|
||||
$groupId = $this->getId();
|
||||
$groupLabelId = (filled($groupId) && filled($this->getLabel())) ? "{$groupId}-label" : null;
|
||||
$groupErrorId = (filled($groupId) && $hasError) ? "{$groupId}-error" : null;
|
||||
|
||||
$innerAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'id' => $groupId,
|
||||
'role' => 'group',
|
||||
'aria-labelledby' => $groupLabelId,
|
||||
'aria-describedby' => $groupErrorId,
|
||||
'aria-invalid' => $hasError ? 'true' : null,
|
||||
], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->class(['fi-sc-fused-group']);
|
||||
|
||||
$innerHtml = '<div ' . $innerAttributes->toHtml() . '>' . $this->getChildSchema()->toHtml() . '</div>';
|
||||
|
||||
$fieldWrapperView = $this->getFieldWrapperView();
|
||||
$isDefaultFieldWrapperView = $fieldWrapperView === 'filament-forms::field-wrapper';
|
||||
|
||||
if (
|
||||
(! $isDefaultFieldWrapperView)
|
||||
|| ViewComponent::hasPublishedEmbeddedViewOverride('filament-forms::components.field-wrapper')
|
||||
) {
|
||||
$absoluteView = $isDefaultFieldWrapperView
|
||||
? 'filament-forms::components.field-wrapper'
|
||||
: (string) (str($fieldWrapperView)->contains('::')
|
||||
? str($fieldWrapperView)->replaceFirst('::', '::components.')
|
||||
: str("components.{$fieldWrapperView}"));
|
||||
|
||||
if (view()->exists($absoluteView)) {
|
||||
return view($absoluteView, [
|
||||
'field' => $this,
|
||||
'slot' => new ComponentSlot($innerHtml),
|
||||
'errorMessage' => $errorMessage,
|
||||
'errorMessages' => $errorMessages,
|
||||
'areHtmlErrorMessagesAllowed' => $areHtmlErrorMessagesAllowed,
|
||||
'shouldShowAllValidationMessages' => filled($errorMessages),
|
||||
])->toHtml();
|
||||
}
|
||||
|
||||
return $this->renderWrapperBladeComponent(
|
||||
$fieldWrapperView,
|
||||
new ComponentSlot($innerHtml),
|
||||
new FilamentComponentAttributeBag([
|
||||
'field' => $this,
|
||||
'error-message' => $errorMessage,
|
||||
'error-messages' => $errorMessages,
|
||||
'are-html-error-messages-allowed' => $areHtmlErrorMessagesAllowed,
|
||||
'should-show-all-validation-messages' => filled($errorMessages),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
// Field wrapper rendering (inline, same as `Field::wrapEmbeddedHtml()` but with custom errors)
|
||||
$hasInlineLabel = $this->hasInlineLabel();
|
||||
$id = $this->getId();
|
||||
$isDisabled = $this->isDisabled();
|
||||
$label = $this->getLabel();
|
||||
$labelSrOnly = $this->isLabelHidden();
|
||||
$required = $this->isMarkedAsRequired();
|
||||
|
||||
$aboveLabelSchema = $this->getChildSchema(static::ABOVE_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$belowLabelSchema = $this->getChildSchema(static::BELOW_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$beforeLabelSchema = $this->getChildSchema(static::BEFORE_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$afterLabelSchema = $this->getChildSchema(static::AFTER_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$aboveContentSchema = $this->getChildSchema(static::ABOVE_CONTENT_SCHEMA_KEY)?->toHtmlString();
|
||||
$belowContentSchema = $this->getChildSchema(static::BELOW_CONTENT_SCHEMA_KEY)?->toHtmlString();
|
||||
$beforeContentSchema = $this->getChildSchema(static::BEFORE_CONTENT_SCHEMA_KEY)?->toHtmlString();
|
||||
$afterContentSchema = $this->getChildSchema(static::AFTER_CONTENT_SCHEMA_KEY)?->toHtmlString();
|
||||
$aboveErrorMessageSchema = $this->getChildSchema(static::ABOVE_ERROR_MESSAGE_SCHEMA_KEY)?->toHtmlString();
|
||||
$belowErrorMessageSchema = $this->getChildSchema(static::BELOW_ERROR_MESSAGE_SCHEMA_KEY)?->toHtmlString();
|
||||
|
||||
$wrapperAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge($this->getExtraFieldWrapperAttributes(), escape: false)
|
||||
->class([
|
||||
'fi-fo-field',
|
||||
'fi-fo-field-has-inline-label' => $hasInlineLabel,
|
||||
]);
|
||||
|
||||
$inlineLabelVerticalAlignment = VerticalAlignment::Start;
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div data-field-wrapper <?= $wrapperAttributes->toHtml() ?>>
|
||||
<?php if (filled($label) && $labelSrOnly) { ?>
|
||||
<label <?php if (filled($id)) { ?>id="<?= e($id) ?>-label" <?php } ?>class="fi-fo-field-label fi-sr-only"><?= e($label) ?></label>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ((filled($label) && (! $labelSrOnly)) || $hasInlineLabel || $aboveLabelSchema || $belowLabelSchema || $beforeLabelSchema || $afterLabelSchema) { ?>
|
||||
<div
|
||||
<?= (new FilamentComponentAttributeBag)->class([
|
||||
'fi-fo-field-label-col',
|
||||
"fi-vertical-align-{$inlineLabelVerticalAlignment->value}" => $hasInlineLabel,
|
||||
])->toHtml() ?>
|
||||
>
|
||||
<?= $aboveLabelSchema?->toHtml() ?>
|
||||
<div
|
||||
<?= (new FilamentComponentAttributeBag)->class([
|
||||
'fi-fo-field-label-ctn',
|
||||
($label instanceof ComponentSlot) ? $label->attributes->get('class') : null,
|
||||
])->toHtml() ?>
|
||||
>
|
||||
<?= $beforeLabelSchema?->toHtml() ?>
|
||||
<?php if (filled($label) && (! $labelSrOnly)) { ?>
|
||||
<label <?php if (filled($id)) { ?>id="<?= e($id) ?>-label" <?php } ?>class="fi-fo-field-label">
|
||||
<span class="fi-fo-field-label-content">
|
||||
<?= e($label) ?><?php if ($required && (! $isDisabled)) { ?><sup class="fi-fo-field-label-required-mark">*</sup><?php } ?>
|
||||
</span>
|
||||
</label>
|
||||
<?php } ?>
|
||||
<?= $afterLabelSchema?->toHtml() ?>
|
||||
</div>
|
||||
<?= $belowLabelSchema?->toHtml() ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="fi-fo-field-content-col">
|
||||
<?= $aboveContentSchema?->toHtml() ?>
|
||||
|
||||
<?php if ($beforeContentSchema || $afterContentSchema) { ?>
|
||||
<div class="fi-fo-field-content-ctn">
|
||||
<?= $beforeContentSchema?->toHtml() ?>
|
||||
<div class="fi-fo-field-content"><?= $innerHtml ?></div>
|
||||
<?= $afterContentSchema?->toHtml() ?>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<?= $innerHtml ?>
|
||||
<?php } ?>
|
||||
|
||||
<?= $belowContentSchema?->toHtml() ?>
|
||||
|
||||
<?php if ($hasError) { ?>
|
||||
<?= $aboveErrorMessageSchema?->toHtml() ?>
|
||||
|
||||
<?php if (filled($errorMessages)) { ?>
|
||||
<ul data-validation-error <?php if (filled($id)) { ?>id="<?= e($id) ?>-error" <?php } ?>class="fi-fo-field-wrp-error-list">
|
||||
<?php foreach ($errorMessages as $errorMsg) { ?>
|
||||
<li class="fi-fo-field-wrp-error-message">
|
||||
<?php if ($areHtmlErrorMessagesAllowed) { ?>
|
||||
<?= $errorMsg ?>
|
||||
<?php } else { ?>
|
||||
<?= e($errorMsg) ?>
|
||||
<?php } ?>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<?php } elseif ($areHtmlErrorMessagesAllowed) { ?>
|
||||
<div data-validation-error <?php if (filled($id)) { ?>id="<?= e($id) ?>-error" <?php } ?>class="fi-fo-field-wrp-error-message"><?= $errorMessage ?></div>
|
||||
<?php } else { ?>
|
||||
<p data-validation-error <?php if (filled($id)) { ?>id="<?= e($id) ?>-error" <?php } ?>class="fi-fo-field-wrp-error-message"><?= e($errorMessage) ?></p>
|
||||
<?php } ?>
|
||||
|
||||
<?= $belowErrorMessageSchema?->toHtml() ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
public function isRequired(): bool
|
||||
{
|
||||
foreach ($this->getDefaultChildComponents() as $component) {
|
||||
if (! ($component instanceof Field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($component->isMarkedAsRequired()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
51
vendor/filament/schemas/src/Components/Grid.php
vendored
Normal file
51
vendor/filament/schemas/src/Components/Grid.php
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Filament\Schemas\Components\Concerns\EntanglesStateWithSingularRelationship;
|
||||
use Filament\Schemas\Components\Contracts\CanEntangleWithSingularRelationships;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
|
||||
class Grid extends Component implements CanEntangleWithSingularRelationships, HasEmbeddedView
|
||||
{
|
||||
use EntanglesStateWithSingularRelationship;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.grid';
|
||||
|
||||
/**
|
||||
* @param array<string, ?int> | int | null $columns
|
||||
*/
|
||||
final public function __construct(array | int | null $columns)
|
||||
{
|
||||
$this->columns($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, ?int> | int | null $columns
|
||||
*/
|
||||
public static function make(array | int | null $columns = 2): static
|
||||
{
|
||||
$static = app(static::class, ['columns' => $columns]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$attributes = (new FilamentComponentAttributeBag)
|
||||
->merge(['id' => $this->getId()], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false);
|
||||
|
||||
$childSchema = $this->getChildSchema();
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?= $childSchema->toHtml() ?>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
53
vendor/filament/schemas/src/Components/Group.php
vendored
Normal file
53
vendor/filament/schemas/src/Components/Group.php
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Schemas\Components\Concerns\EntanglesStateWithSingularRelationship;
|
||||
use Filament\Schemas\Components\Contracts\CanEntangleWithSingularRelationships;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class Group extends Component implements CanEntangleWithSingularRelationships, HasEmbeddedView
|
||||
{
|
||||
use EntanglesStateWithSingularRelationship;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.grid';
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Closure $schema
|
||||
*/
|
||||
final public function __construct(array | Closure $schema = [])
|
||||
{
|
||||
$this->schema($schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Closure $schema
|
||||
*/
|
||||
public static function make(array | Closure $schema = []): static
|
||||
{
|
||||
$static = app(static::class, ['schema' => $schema]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$attributes = (new FilamentComponentAttributeBag)
|
||||
->merge(['id' => $this->getId()], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->toHtml() ?>>
|
||||
<?= $this->getChildSchema()->toHtml() ?>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
48
vendor/filament/schemas/src/Components/Html.php
vendored
Normal file
48
vendor/filament/schemas/src/Components/Html.php
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class Html extends Component implements HasEmbeddedView
|
||||
{
|
||||
protected string | Htmlable | Closure | null $content = null;
|
||||
|
||||
final public function __construct(string | Htmlable | Closure | null $content)
|
||||
{
|
||||
$this->content($content);
|
||||
}
|
||||
|
||||
public static function make(string | Htmlable | Closure | null $content): static
|
||||
{
|
||||
$static = app(static::class, ['content' => $content]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function content(string | Htmlable | Closure | null $content): static
|
||||
{
|
||||
$this->content = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContent(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->content);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$content = $this->getContent();
|
||||
|
||||
if ($content instanceof Htmlable) {
|
||||
return $content->toHtml();
|
||||
}
|
||||
|
||||
return $content ?? '';
|
||||
}
|
||||
}
|
||||
117
vendor/filament/schemas/src/Components/Icon.php
vendored
Normal file
117
vendor/filament/schemas/src/Components/Icon.php
vendored
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Schemas\View\Components\IconComponent;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\HasColor;
|
||||
use Filament\Support\Concerns\HasTooltip;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
|
||||
use function Filament\Support\generate_icon_html;
|
||||
|
||||
class Icon extends Component implements HasEmbeddedView
|
||||
{
|
||||
use HasColor;
|
||||
use HasTooltip;
|
||||
|
||||
protected string | BackedEnum | Htmlable | Closure $icon;
|
||||
|
||||
protected IconSize | string | Closure | null $size = null;
|
||||
|
||||
final public function __construct(string | BackedEnum | Htmlable | Closure $icon)
|
||||
{
|
||||
$this->icon($icon);
|
||||
}
|
||||
|
||||
public static function make(string | BackedEnum | Htmlable | Closure $icon): static
|
||||
{
|
||||
$static = app(static::class, ['icon' => $icon]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function icon(string | BackedEnum | Htmlable | Closure $icon): static
|
||||
{
|
||||
$this->icon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIcon(): string | BackedEnum
|
||||
{
|
||||
return $this->evaluate($this->icon);
|
||||
}
|
||||
|
||||
public function size(IconSize | string | Closure | null $size): static
|
||||
{
|
||||
$this->size = $size;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSize(): IconSize | string | null
|
||||
{
|
||||
$size = $this->evaluate($this->size);
|
||||
|
||||
if (blank($size)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($size === 'base') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_string($size)) {
|
||||
$size = IconSize::tryFrom($size) ?? $size;
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$size = $this->getSize();
|
||||
|
||||
$tooltip = $this->getTooltip();
|
||||
$hasTooltip = filled($tooltip);
|
||||
|
||||
$extraAttributes = $this->getExtraAttributes();
|
||||
|
||||
// A user-supplied `aria-label` via `extraAttributes()` would land on the icon's `<svg>`, but the
|
||||
// SVG carries a baked-in `aria-hidden="true"` (from the icon source) that removes it — and every
|
||||
// attribute on it, including the label — from the accessibility tree, leaving the icon unnamed.
|
||||
// Pull the label off the SVG and expose it as the icon's visually-hidden text alternative instead.
|
||||
$userLabel = $extraAttributes['aria-label'] ?? null;
|
||||
unset($extraAttributes['aria-label']);
|
||||
|
||||
$iconAttributes = [
|
||||
'x-tooltip' => $hasTooltip ? '{ content: ' . Js::from($tooltip) . ', theme: $store.theme, allowHTML: ' . Js::from($tooltip instanceof Htmlable) . ' }' : null,
|
||||
];
|
||||
|
||||
$html = generate_icon_html($this->getIcon(), attributes: (new FilamentComponentAttributeBag($iconAttributes))->merge($extraAttributes, escape: false)->color(IconComponent::class, $this->getColor() ?? 'primary')->class(['fi-sc-icon']), size: $size instanceof IconSize ? $size : null)?->toHtml() ?? '';
|
||||
|
||||
// Give the decorative icon a visually-hidden text alternative. Priority: an explicit user
|
||||
// `aria-label`, then the tooltip (which is the icon's meaning but is hover-only). Skipped when the
|
||||
// user named the icon through `aria-labelledby` — they've deliberately pointed at another element.
|
||||
if (filled($userLabel)) {
|
||||
$accessibleText = $userLabel instanceof Htmlable ? trim(strip_tags($userLabel->toHtml())) : $userLabel;
|
||||
} elseif ($hasTooltip && blank($extraAttributes['aria-labelledby'] ?? null)) {
|
||||
$accessibleText = $tooltip instanceof Htmlable ? trim(strip_tags($tooltip->toHtml())) : $tooltip;
|
||||
} else {
|
||||
$accessibleText = null;
|
||||
}
|
||||
|
||||
if (filled($accessibleText)) {
|
||||
$html .= '<span class="fi-sr-only">' . e($accessibleText) . '</span>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
156
vendor/filament/schemas/src/Components/Image.php
vendored
Normal file
156
vendor/filament/schemas/src/Components/Image.php
vendored
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\HasAlignment;
|
||||
use Filament\Support\Concerns\HasTooltip;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
|
||||
class Image extends Component implements HasEmbeddedView
|
||||
{
|
||||
use HasAlignment;
|
||||
use HasTooltip;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.image';
|
||||
|
||||
protected string | Closure $url;
|
||||
|
||||
protected string | Closure $alt;
|
||||
|
||||
protected int | string | Closure | null $imageHeight = null;
|
||||
|
||||
protected int | string | Closure | null $imageWidth = null;
|
||||
|
||||
final public function __construct(string | Closure $url, string | Closure $alt)
|
||||
{
|
||||
$this->url($url);
|
||||
$this->alt($alt);
|
||||
}
|
||||
|
||||
public static function make(string | Closure $url, string | Closure $alt): static
|
||||
{
|
||||
$static = app(static::class, ['url' => $url, 'alt' => $alt]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function url(string | Closure $url): static
|
||||
{
|
||||
// Security: If this URL is derived from user input, validate it
|
||||
// to prevent XSS via `javascript:` protocol URLs rendered
|
||||
// in `src` attributes.
|
||||
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUrl(): string
|
||||
{
|
||||
return $this->evaluate($this->url);
|
||||
}
|
||||
|
||||
public function alt(string | Closure $alt): static
|
||||
{
|
||||
$this->alt = $alt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAlt(): string
|
||||
{
|
||||
return $this->evaluate($this->alt);
|
||||
}
|
||||
|
||||
public function imageHeight(int | string | Closure | null $height): static
|
||||
{
|
||||
$this->imageHeight = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function imageSize(int | string | Closure $size): static
|
||||
{
|
||||
$this->imageWidth($size);
|
||||
$this->imageHeight($size);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function imageWidth(int | string | Closure | null $width): static
|
||||
{
|
||||
$this->imageWidth = $width;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getImageHeight(): ?string
|
||||
{
|
||||
$height = $this->evaluate($this->imageHeight);
|
||||
|
||||
if ($height === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_int($height)) {
|
||||
return "{$height}px";
|
||||
}
|
||||
|
||||
return $height;
|
||||
}
|
||||
|
||||
public function getImageWidth(): ?string
|
||||
{
|
||||
$width = $this->evaluate($this->imageWidth);
|
||||
|
||||
if ($width === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_int($width)) {
|
||||
return "{$width}px";
|
||||
}
|
||||
|
||||
return $width;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$alignment = $this->getAlignment();
|
||||
$height = $this->getImageHeight() ?? '8rem';
|
||||
$width = $this->getImageWidth();
|
||||
$tooltip = $this->getTooltip();
|
||||
|
||||
if (! $alignment instanceof Alignment) {
|
||||
$alignment = filled($alignment) ? (Alignment::tryFrom($alignment) ?? $alignment) : null;
|
||||
}
|
||||
|
||||
$attributes = $this->getExtraAttributeBag()
|
||||
->class([
|
||||
'fi-sc-image',
|
||||
($alignment instanceof Alignment) ? "fi-align-{$alignment->value}" : $alignment,
|
||||
])
|
||||
->style([
|
||||
('height: ' . e($height)) => $height,
|
||||
('width: ' . e($width)) => $width,
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<img
|
||||
alt="<?= e($this->getAlt()) ?>"
|
||||
src="<?= e($this->getUrl()) ?>"
|
||||
<?php if (filled($tooltip)) { ?>
|
||||
x-tooltip="{ content: <?= Js::from($tooltip) ?>, theme: $store.theme, allowHTML: <?= Js::from($tooltip instanceof Htmlable) ?> }"
|
||||
<?php } ?>
|
||||
<?= $attributes->toHtml() ?>
|
||||
/>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
134
vendor/filament/schemas/src/Components/Livewire.php
vendored
Normal file
134
vendor/filament/schemas/src/Components/Livewire.php
vendored
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Livewire\Livewire as LivewireFacade;
|
||||
|
||||
class Livewire extends Component implements HasEmbeddedView
|
||||
{
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.livewire';
|
||||
|
||||
protected bool | Closure $isLazy = false;
|
||||
|
||||
/**
|
||||
* @var array<string, mixed> | Closure
|
||||
*/
|
||||
protected array | Closure $data = [];
|
||||
|
||||
protected string | Closure $component;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> | Closure $data
|
||||
*/
|
||||
final public function __construct(string | Closure $component, array | Closure $data = [])
|
||||
{
|
||||
$this->component($component);
|
||||
$this->data($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> | Closure $data
|
||||
*/
|
||||
public static function make(string | Closure $component, array | Closure $data = []): static
|
||||
{
|
||||
$static = app(static::class, [
|
||||
'component' => $component,
|
||||
'data' => $data,
|
||||
]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
public function component(string | Closure $component): static
|
||||
{
|
||||
$this->component = $component;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getComponent(): string
|
||||
{
|
||||
return $this->evaluate($this->component);
|
||||
}
|
||||
|
||||
public function lazy(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isLazy = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isLazy(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isLazy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> | Closure $data
|
||||
*/
|
||||
public function data(array | Closure $data): static
|
||||
{
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->evaluate($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getComponentProperties(): array
|
||||
{
|
||||
$properties = [
|
||||
'record' => $this->getRecord(),
|
||||
];
|
||||
|
||||
if ($this->isLazy()) {
|
||||
$properties['lazy'] = true;
|
||||
}
|
||||
|
||||
return [
|
||||
...$properties,
|
||||
...$this->getData(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getId(): ?string
|
||||
{
|
||||
return $this->getCustomId();
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$extraAttributes = $this->getExtraAttributes();
|
||||
$id = $this->getId();
|
||||
$hasWrapper = filled($id) || filled($extraAttributes);
|
||||
|
||||
$component = $this->getComponent();
|
||||
$properties = $this->getComponentProperties();
|
||||
$key = $this->getLivewireKey() ?? "{$this->getLivewire()->getId()}.{$component}";
|
||||
|
||||
$livewireHtml = LivewireFacade::mount($component, $properties, $key);
|
||||
|
||||
if ($hasWrapper) {
|
||||
$attributes = (new FilamentComponentAttributeBag)
|
||||
->merge(['id' => $id], escape: false)
|
||||
->merge($extraAttributes, escape: false);
|
||||
|
||||
return '<div ' . $attributes->toHtml() . '>' . $livewireHtml . '</div>';
|
||||
}
|
||||
|
||||
return $livewireHtml;
|
||||
}
|
||||
}
|
||||
92
vendor/filament/schemas/src/Components/RenderHook.php
vendored
Normal file
92
vendor/filament/schemas/src/Components/RenderHook.php
vendored
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Schemas\Contracts\HasRenderHookScopes;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Facades\FilamentView;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class RenderHook extends Component implements HasEmbeddedView
|
||||
{
|
||||
protected string | Closure $name;
|
||||
|
||||
/**
|
||||
* @var string | array<string> | Closure | null
|
||||
*/
|
||||
protected string | array | Closure | null $scopes = null;
|
||||
|
||||
/**
|
||||
* @param string | array<string> | Closure | null $scopes
|
||||
*/
|
||||
final public function __construct(string | Closure $name, string | array | Closure | null $scopes = null)
|
||||
{
|
||||
$this->name($name);
|
||||
$this->scopes($scopes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | null $scopes
|
||||
*/
|
||||
public static function make(string $name, string | array | null $scopes = null): static
|
||||
{
|
||||
$static = app(static::class, ['name' => $name, 'scopes' => $scopes]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->liberatedFromContainerGrid();
|
||||
}
|
||||
|
||||
public function name(string | Closure $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->evaluate($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | Closure | null $scopes
|
||||
*/
|
||||
public function scopes(string | array | Closure | null $scopes): static
|
||||
{
|
||||
$this->scopes = $scopes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getScopes(): array
|
||||
{
|
||||
$scopes = Arr::wrap($this->evaluate($this->scopes));
|
||||
|
||||
$livewire = $this->getLivewire();
|
||||
|
||||
if ($livewire instanceof HasRenderHookScopes) {
|
||||
$scopes = [
|
||||
...$scopes,
|
||||
...$livewire->getRenderHookScopes(),
|
||||
];
|
||||
}
|
||||
|
||||
return array_unique($scopes);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
return FilamentView::renderHook($this->getName(), scopes: $this->getScopes())->toHtml();
|
||||
}
|
||||
}
|
||||
490
vendor/filament/schemas/src/Components/Section.php
vendored
Normal file
490
vendor/filament/schemas/src/Components/Section.php
vendored
Normal file
|
|
@ -0,0 +1,490 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Schemas\Components\Concerns\CanBeCollapsed;
|
||||
use Filament\Schemas\Components\Concerns\CanBeCompact;
|
||||
use Filament\Schemas\Components\Concerns\CanBeDivided;
|
||||
use Filament\Schemas\Components\Concerns\CanBeSecondary;
|
||||
use Filament\Schemas\Components\Concerns\EntanglesStateWithSingularRelationship;
|
||||
use Filament\Schemas\Components\Concerns\HasDescription;
|
||||
use Filament\Schemas\Components\Concerns\HasFooterActions;
|
||||
use Filament\Schemas\Components\Concerns\HasHeaderActions;
|
||||
use Filament\Schemas\Components\Concerns\HasHeading;
|
||||
use Filament\Schemas\Components\Concerns\HasLabel;
|
||||
use Filament\Schemas\Components\Contracts\CanEntangleWithSingularRelationships;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\CanBeContained;
|
||||
use Filament\Support\Concerns\HasExtraAlpineAttributes;
|
||||
use Filament\Support\Concerns\HasIcon;
|
||||
use Filament\Support\Concerns\HasIconColor;
|
||||
use Filament\Support\Concerns\HasIconSize;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Support\View\Components\IconButtonComponent;
|
||||
use Filament\Support\View\Components\SectionComponent\IconComponent;
|
||||
use Filament\Support\View\SupportIconAlias;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use function Filament\Support\generate_icon_html;
|
||||
use function Filament\Support\is_slot_empty;
|
||||
|
||||
class Section extends Component implements CanEntangleWithSingularRelationships, HasEmbeddedView
|
||||
{
|
||||
use CanBeCollapsed;
|
||||
use CanBeCompact;
|
||||
use CanBeContained;
|
||||
use CanBeDivided;
|
||||
use CanBeSecondary;
|
||||
use EntanglesStateWithSingularRelationship;
|
||||
use HasDescription;
|
||||
use HasExtraAlpineAttributes;
|
||||
use HasFooterActions;
|
||||
use HasHeaderActions;
|
||||
use HasHeading;
|
||||
use HasIcon;
|
||||
use HasIconColor;
|
||||
use HasIconSize;
|
||||
use HasLabel;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.section';
|
||||
|
||||
protected bool | Closure | null $isAside = null;
|
||||
|
||||
protected bool | Closure $isFormBefore = false;
|
||||
|
||||
protected ?Closure $contentSchemaExtraAttributes = null;
|
||||
|
||||
const AFTER_HEADER_SCHEMA_KEY = 'after_header';
|
||||
|
||||
const FOOTER_SCHEMA_KEY = 'footer';
|
||||
|
||||
const BEFORE_LABEL_SCHEMA_KEY = 'before_label';
|
||||
|
||||
const AFTER_LABEL_SCHEMA_KEY = 'after_label';
|
||||
|
||||
const ABOVE_CONTENT_SCHEMA_KEY = 'above_content';
|
||||
|
||||
const BELOW_CONTENT_SCHEMA_KEY = 'below_content';
|
||||
|
||||
/**
|
||||
* @param string | array<Component | Action | ActionGroup> | Htmlable | Closure | null $heading
|
||||
*/
|
||||
final public function __construct(string | array | Htmlable | Closure | null $heading = null)
|
||||
{
|
||||
is_array($heading)
|
||||
? $this->components($heading)
|
||||
: $this->heading($heading);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<Component | Action | ActionGroup> | Htmlable | Closure | null $heading
|
||||
*/
|
||||
public static function make(string | array | Htmlable | Closure | null $heading = null): static
|
||||
{
|
||||
$static = app(static::class, ['heading' => $heading]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->key(function (Section $component): ?string {
|
||||
$heading = $component->getHeading();
|
||||
|
||||
if (blank($heading)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$statePath = $component->getStatePath();
|
||||
|
||||
return Str::slug(Str::transliterate($heading, strict: true)) . '::' . (filled($statePath) ? "{$statePath}::section" : 'section');
|
||||
}, isInheritable: false);
|
||||
|
||||
$this->afterHeader(fn (Section $component): array => $component->getHeaderActions());
|
||||
$this->footer(function (Section $component): Schema {
|
||||
return match ($component->getFooterActionsAlignment()) {
|
||||
Alignment::End, Alignment::Right => Schema::end($component->getFooterActions()),
|
||||
Alignment::Center, => Schema::center($component->getFooterActions()),
|
||||
Alignment::Between, Alignment::Justify => Schema::between($component->getFooterActions()),
|
||||
default => Schema::start($component->getFooterActions()),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
public function aside(bool | Closure | null $condition = true): static
|
||||
{
|
||||
$this->isAside = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isAside(): bool
|
||||
{
|
||||
return (bool) ($this->evaluate($this->isAside) ?? false);
|
||||
}
|
||||
|
||||
public function formBefore(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isFormBefore = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isFormBefore(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isFormBefore);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function afterHeader(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::AFTER_HEADER_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function footer(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::FOOTER_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function beforeLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BEFORE_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function afterLabel(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::AFTER_LABEL_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function aboveContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::ABOVE_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
|
||||
*/
|
||||
public function belowContent(array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components): static
|
||||
{
|
||||
$this->childComponents($components, static::BELOW_CONTENT_SCHEMA_KEY);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function makeChildSchema(string $key): Schema
|
||||
{
|
||||
$schema = parent::makeChildSchema($key);
|
||||
|
||||
if (in_array($key, [static::AFTER_HEADER_SCHEMA_KEY, static::AFTER_LABEL_SCHEMA_KEY])) {
|
||||
$schema->alignEnd();
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
protected function configureChildSchema(Schema $schema, string $key): Schema
|
||||
{
|
||||
$schema = parent::configureChildSchema($schema, $key);
|
||||
|
||||
if ($key === 'default') {
|
||||
$schema->extraAttributes(
|
||||
$this->contentSchemaExtraAttributes ??= static fn (): array => ['class' => 'fi-section-content'],
|
||||
merge: true,
|
||||
);
|
||||
}
|
||||
|
||||
if (in_array($key, [
|
||||
static::AFTER_HEADER_SCHEMA_KEY,
|
||||
static::FOOTER_SCHEMA_KEY,
|
||||
static::BEFORE_LABEL_SCHEMA_KEY,
|
||||
static::AFTER_LABEL_SCHEMA_KEY,
|
||||
static::ABOVE_CONTENT_SCHEMA_KEY,
|
||||
static::BELOW_CONTENT_SCHEMA_KEY,
|
||||
])) {
|
||||
$schema
|
||||
->inline()
|
||||
->embeddedInParentComponent();
|
||||
}
|
||||
|
||||
if (in_array($key, [
|
||||
static::BEFORE_LABEL_SCHEMA_KEY,
|
||||
static::AFTER_LABEL_SCHEMA_KEY,
|
||||
static::ABOVE_CONTENT_SCHEMA_KEY,
|
||||
static::BELOW_CONTENT_SCHEMA_KEY,
|
||||
])) {
|
||||
$schema
|
||||
->modifyActionsUsing(fn (Action $action) => $action
|
||||
->defaultSize(Size::Small)
|
||||
->defaultView(Action::LINK_VIEW))
|
||||
->modifyActionGroupsUsing(fn (ActionGroup $actionGroup) => $actionGroup->defaultSize(Size::Small));
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$afterHeader = $this->getChildSchema(static::AFTER_HEADER_SCHEMA_KEY)?->toHtmlString();
|
||||
$isAside = $this->isAside();
|
||||
$isCollapsed = $this->isCollapsed();
|
||||
$isCollapsible = $this->isCollapsible();
|
||||
$isCompact = $this->isCompact();
|
||||
$isContained = $this->isContained();
|
||||
$isDivided = $this->isDivided();
|
||||
$isFormBefore = $this->isFormBefore();
|
||||
$description = $this->getDescription();
|
||||
$footer = $this->getChildSchema(static::FOOTER_SCHEMA_KEY)?->toHtmlString();
|
||||
$heading = $this->getHeading();
|
||||
$headingTag = $this->getHeadingTag();
|
||||
$icon = $this->getIcon();
|
||||
$iconColor = $this->getIconColor() ?? 'gray';
|
||||
$iconSize = $this->getIconSize();
|
||||
$shouldPersistCollapsed = $this->shouldPersistCollapsed();
|
||||
$isSecondary = $this->isSecondary();
|
||||
$id = $this->getId();
|
||||
|
||||
if (filled($iconSize) && (! $iconSize instanceof IconSize)) {
|
||||
$iconSize = IconSize::tryFrom($iconSize) ?? $iconSize;
|
||||
}
|
||||
|
||||
$hasDescription = filled((string) $description);
|
||||
$hasHeading = filled($heading);
|
||||
$hasIcon = filled($icon);
|
||||
$hasAfterHeader = ! is_slot_empty($afterHeader);
|
||||
$hasHeader = $hasIcon || $hasHeading || $hasDescription || ($isCollapsible && (! $isAside)) || $hasAfterHeader;
|
||||
|
||||
// Outer wrapper attributes (from schema section view)
|
||||
$outerAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge(['id' => $id], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->merge($this->getExtraAlpineAttributes(), escape: false)
|
||||
->class(['fi-sc-section']);
|
||||
|
||||
// Inner section attributes
|
||||
$sectionAttributes = (new FilamentComponentAttributeBag)
|
||||
->class([
|
||||
'fi-section',
|
||||
'fi-section-not-contained' => ! $isContained,
|
||||
'fi-section-has-content-before' => $isFormBefore,
|
||||
'fi-section-has-header' => $hasHeader,
|
||||
'fi-aside' => $isAside,
|
||||
'fi-compact' => $isCompact,
|
||||
'fi-collapsible' => $isCollapsible && (! $isAside),
|
||||
'fi-divided' => $isDivided,
|
||||
'fi-secondary' => $isSecondary,
|
||||
]);
|
||||
|
||||
$collapsible = $isCollapsible && (! $isAside);
|
||||
$collapseId = $id;
|
||||
|
||||
// Render child schema content
|
||||
$contentHtml = $this->getChildSchema()?->toHtml();
|
||||
$hasContent = ! is_slot_empty(filled($contentHtml) ? new HtmlString($contentHtml) : null);
|
||||
$hasFooter = ! is_slot_empty($footer);
|
||||
|
||||
// The disclosure button uses this to reference the collapsible region via `aria-controls`. Only set
|
||||
// when there is both an `$id` and a content region to point at, so the reference never dangles.
|
||||
$contentId = (filled($id) && ($hasContent || $hasFooter)) ? "{$id}-content" : null;
|
||||
|
||||
// Label schemas
|
||||
$label = $this->getLabel();
|
||||
$beforeLabelSchema = $this->getChildSchema(static::BEFORE_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$afterLabelSchema = $this->getChildSchema(static::AFTER_LABEL_SCHEMA_KEY)?->toHtmlString();
|
||||
$aboveContentSchema = $this->getChildSchema(static::ABOVE_CONTENT_SCHEMA_KEY)?->toHtmlString();
|
||||
$belowContentSchema = $this->getChildSchema(static::BELOW_CONTENT_SCHEMA_KEY)?->toHtmlString();
|
||||
|
||||
// Name the `<section>` as a landmark region by referencing its heading (or, failing that, its `label()`),
|
||||
// and associate its description. An unnamed `<section>` is not exposed as a `region` by assistive tech, so
|
||||
// this promotes it to a navigable landmark. Every id is guarded so a reference is never left dangling. The
|
||||
// `-heading`/`-description`/`-label` suffixes are disjoint from the disclosure `-content` id above.
|
||||
$headingId = (filled($id) && $hasHeading) ? "{$id}-heading" : null;
|
||||
$descriptionId = (filled($id) && $hasDescription) ? "{$id}-description" : null;
|
||||
$labelId = (filled($id) && filled($label) && (! $hasHeading)) ? "{$id}-label" : null;
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $outerAttributes->toHtml() ?>>
|
||||
<?php if (filled($label)) { ?>
|
||||
<div class="fi-sc-section-label-ctn">
|
||||
<?= $beforeLabelSchema?->toHtml() ?>
|
||||
|
||||
<div
|
||||
<?php if (filled($labelId)) { ?>id="<?= e($labelId) ?>"<?php } ?>
|
||||
class="fi-sc-section-label"
|
||||
>
|
||||
<?= e($label) ?>
|
||||
</div>
|
||||
|
||||
<?= $afterLabelSchema?->toHtml() ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?= $aboveContentSchema?->toHtml() ?>
|
||||
|
||||
<section
|
||||
x-data="{
|
||||
isCollapsed: <?php if ($shouldPersistCollapsed) { ?>$persist(<?= Js::from($isCollapsed) ?>).as(`section-${<?= Js::from($collapseId) ?> ?? $el.id}-isCollapsed`)<?php } else { ?><?= Js::from($isCollapsed) ?><?php } ?>,
|
||||
}"
|
||||
<?php if ($collapsible) { ?>
|
||||
x-on:collapse-section.window="if ($event.detail.id == (<?= Js::from($collapseId) ?> ?? $el.id)) isCollapsed = true"
|
||||
x-on:expand="isCollapsed = false"
|
||||
x-on:expand-section.window="if ($event.detail.id == (<?= Js::from($collapseId) ?> ?? $el.id)) isCollapsed = false"
|
||||
x-on:open-section.window="if ($event.detail.id == (<?= Js::from($collapseId) ?> ?? $el.id)) isCollapsed = false"
|
||||
x-on:toggle-section.window="if ($event.detail.id == (<?= Js::from($collapseId) ?> ?? $el.id)) isCollapsed = ! isCollapsed"
|
||||
<?php if (! $shouldPersistCollapsed) { ?>
|
||||
x-on:reset-schema-component-state.window="if (($event.detail.livewireId === <?= Js::from($this->getLivewire()->getId()) ?>) && ($event.detail.schemaKey === <?= Js::from($this->getRootContainer()->getKey()) ?>)) $nextTick(() => isCollapsed = <?= Js::from($isCollapsed) ?>)"
|
||||
<?php } ?>
|
||||
x-bind:class="isCollapsed && 'fi-collapsed'"
|
||||
<?php } ?>
|
||||
<?php if (filled($labelledById = $headingId ?? $labelId)) { ?>
|
||||
aria-labelledby="<?= e($labelledById) ?>"
|
||||
<?php } ?>
|
||||
<?php if (filled($descriptionId)) { ?>
|
||||
aria-describedby="<?= e($descriptionId) ?>"
|
||||
<?php } ?>
|
||||
<?= $sectionAttributes->toHtml() ?>
|
||||
>
|
||||
<?php if ($hasHeader) { ?>
|
||||
<header
|
||||
<?php if ($collapsible) { ?>
|
||||
x-on:click="if (! $event.target.closest('.fi-section-header-after-ctn')) isCollapsed = ! isCollapsed"
|
||||
<?php } ?>
|
||||
class="fi-section-header"
|
||||
>
|
||||
<?= generate_icon_html($icon, attributes: (new FilamentComponentAttributeBag)
|
||||
->color(IconComponent::class, $iconColor), size: $iconSize ?? IconSize::Large)?->toHtml() ?>
|
||||
|
||||
<?php if ($hasHeading || $hasDescription) { ?>
|
||||
<div class="fi-section-header-text-ctn">
|
||||
<?php if ($hasHeading) { ?>
|
||||
<<?= $headingTag ?>
|
||||
<?php if (filled($headingId)) { ?>id="<?= e($headingId) ?>"<?php } ?>
|
||||
class="fi-section-header-heading"
|
||||
>
|
||||
<?= e($heading) ?>
|
||||
</<?= $headingTag ?>>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasDescription) { ?>
|
||||
<p
|
||||
<?php if (filled($descriptionId)) { ?>id="<?= e($descriptionId) ?>"<?php } ?>
|
||||
class="fi-section-header-description"
|
||||
>
|
||||
<?= e($description) ?>
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasAfterHeader) { ?>
|
||||
<div class="fi-section-header-after-ctn">
|
||||
<?= $afterHeader ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($collapsible) { ?>
|
||||
<?php
|
||||
$collapseButtonAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'type' => 'button',
|
||||
'wire:loading.attr' => 'disabled',
|
||||
'x-on:click.stop' => 'isCollapsed = ! isCollapsed',
|
||||
// The button only contains a decorative chevron, so give it an accessible
|
||||
// name. Static values cover the pre-Alpine/no-JS render; `x-bind` keeps the
|
||||
// name and expanded state correct as the section is toggled. `aria-expanded`
|
||||
// belongs on the control, not the region, and `aria-controls` points at it.
|
||||
'aria-label' => __($isCollapsed ? 'filament-schemas::components.section.actions.expand.label' : 'filament-schemas::components.section.actions.collapse.label'),
|
||||
'x-bind:aria-label' => 'isCollapsed ? ' . Js::from(__('filament-schemas::components.section.actions.expand.label')) . ' : ' . Js::from(__('filament-schemas::components.section.actions.collapse.label')),
|
||||
'aria-expanded' => $isCollapsed ? 'false' : 'true',
|
||||
'x-bind:aria-expanded' => '(! isCollapsed).toString()',
|
||||
'aria-controls' => $contentId,
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-icon-btn',
|
||||
'fi-size-md',
|
||||
'fi-section-collapse-btn',
|
||||
])
|
||||
->color(IconButtonComponent::class, 'gray');
|
||||
?>
|
||||
|
||||
<button <?= $collapseButtonAttributes->toHtml() ?>>
|
||||
<?= generate_icon_html(Heroicon::ChevronUp, alias: SupportIconAlias::SECTION_COLLAPSE_BUTTON)?->toHtml() ?>
|
||||
</button>
|
||||
<?php } ?>
|
||||
</header>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($hasContent || $hasFooter) { ?>
|
||||
<div
|
||||
<?php if (filled($contentId)) { ?>
|
||||
id="<?= e($contentId) ?>"
|
||||
<?php } ?>
|
||||
<?php if ($collapsible && ($isCollapsed || $shouldPersistCollapsed)) { ?>
|
||||
x-cloak
|
||||
<?php } ?>
|
||||
class="fi-section-content-ctn"
|
||||
>
|
||||
<?= $contentHtml ?>
|
||||
|
||||
<?php if ($hasFooter) { ?>
|
||||
<footer class="fi-section-footer">
|
||||
<?= $footer ?>
|
||||
</footer>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</section>
|
||||
|
||||
<?= $belowContentSchema?->toHtml() ?>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
public function getHeadingsCount(): int
|
||||
{
|
||||
if (blank($this->getHeading())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
35
vendor/filament/schemas/src/Components/StateCasts/BooleanStateCast.php
vendored
Normal file
35
vendor/filament/schemas/src/Components/StateCasts/BooleanStateCast.php
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts;
|
||||
|
||||
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||
|
||||
class BooleanStateCast implements StateCast
|
||||
{
|
||||
public function __construct(
|
||||
protected bool $isNullable = true,
|
||||
protected bool $isStoredAsInt = false,
|
||||
) {}
|
||||
|
||||
public function get(mixed $state): ?bool
|
||||
{
|
||||
if ($this->isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return boolval($state);
|
||||
}
|
||||
|
||||
public function set(mixed $state): bool | int | null
|
||||
{
|
||||
if ($this->isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->isStoredAsInt) {
|
||||
return $state ? 1 : 0;
|
||||
}
|
||||
|
||||
return boolval($state);
|
||||
}
|
||||
}
|
||||
10
vendor/filament/schemas/src/Components/StateCasts/Contracts/StateCast.php
vendored
Normal file
10
vendor/filament/schemas/src/Components/StateCasts/Contracts/StateCast.php
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts\Contracts;
|
||||
|
||||
interface StateCast
|
||||
{
|
||||
public function get(mixed $state): mixed;
|
||||
|
||||
public function set(mixed $state): mixed;
|
||||
}
|
||||
56
vendor/filament/schemas/src/Components/StateCasts/DateTimeStateCast.php
vendored
Normal file
56
vendor/filament/schemas/src/Components/StateCasts/DateTimeStateCast.php
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use Carbon\Exceptions\InvalidFormatException;
|
||||
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class DateTimeStateCast implements StateCast
|
||||
{
|
||||
public function __construct(
|
||||
protected string $format,
|
||||
protected string $internalFormat,
|
||||
protected string $timezone,
|
||||
) {}
|
||||
|
||||
public function get(mixed $state): ?string
|
||||
{
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $state instanceof CarbonInterface) {
|
||||
$state = Carbon::parse($state);
|
||||
}
|
||||
|
||||
$state->shiftTimezone($this->timezone);
|
||||
$state->setTimezone(config('app.timezone'));
|
||||
|
||||
return $state->format($this->format);
|
||||
}
|
||||
|
||||
public function set(mixed $state): ?string
|
||||
{
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $state instanceof CarbonInterface) {
|
||||
try {
|
||||
$state = Carbon::createFromFormat($this->format, (string) $state, config('app.timezone'));
|
||||
} catch (InvalidFormatException) {
|
||||
try {
|
||||
$state = Carbon::parse($state, config('app.timezone'));
|
||||
} catch (InvalidFormatException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$state = $state->setTimezone($this->timezone);
|
||||
|
||||
return $state->format($this->internalFormat);
|
||||
}
|
||||
}
|
||||
100
vendor/filament/schemas/src/Components/StateCasts/EnumArrayStateCast.php
vendored
Normal file
100
vendor/filament/schemas/src/Components/StateCasts/EnumArrayStateCast.php
vendored
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||
use Illuminate\Support\Arr;
|
||||
use Stringable;
|
||||
|
||||
class EnumArrayStateCast implements StateCast
|
||||
{
|
||||
/**
|
||||
* @param class-string<BackedEnum> $enum
|
||||
*/
|
||||
public function __construct(
|
||||
protected string $enum,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<BackedEnum>
|
||||
*/
|
||||
public function get(mixed $state): array
|
||||
{
|
||||
if (blank($state)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! is_array($state)) {
|
||||
$state = json_decode($state, associative: true);
|
||||
}
|
||||
|
||||
/** @var array<mixed> $state */
|
||||
$state = Arr::wrap($state);
|
||||
|
||||
return array_reduce(
|
||||
$state,
|
||||
function (array $carry, $stateItem): array {
|
||||
if (blank($stateItem)) {
|
||||
return $carry;
|
||||
}
|
||||
|
||||
if ($stateItem instanceof BackedEnum) {
|
||||
$carry[] = $stateItem;
|
||||
|
||||
return $carry;
|
||||
}
|
||||
|
||||
if ($stateItem instanceof Stringable) {
|
||||
$stateItem = (string) $stateItem;
|
||||
}
|
||||
|
||||
if (! is_scalar($stateItem)) {
|
||||
return $carry;
|
||||
}
|
||||
|
||||
$carry[] = $this->enum::tryFrom($stateItem);
|
||||
|
||||
return $carry;
|
||||
},
|
||||
initial: [],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function set(mixed $state): array
|
||||
{
|
||||
if (blank($state)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! is_array($state)) {
|
||||
$state = json_decode($state, associative: true);
|
||||
}
|
||||
|
||||
/** @var array<mixed> $state */
|
||||
$state = Arr::wrap($state);
|
||||
|
||||
return array_reduce(
|
||||
$state,
|
||||
function (array $carry, $stateItem): array {
|
||||
if (blank($stateItem)) {
|
||||
return $carry;
|
||||
}
|
||||
|
||||
if (! ($stateItem instanceof BackedEnum)) {
|
||||
$carry[] = $stateItem;
|
||||
|
||||
return $carry;
|
||||
}
|
||||
|
||||
$carry[] = strval($stateItem->value);
|
||||
|
||||
return $carry;
|
||||
},
|
||||
initial: [],
|
||||
);
|
||||
}
|
||||
}
|
||||
47
vendor/filament/schemas/src/Components/StateCasts/EnumStateCast.php
vendored
Normal file
47
vendor/filament/schemas/src/Components/StateCasts/EnumStateCast.php
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||
use Stringable;
|
||||
|
||||
class EnumStateCast implements StateCast
|
||||
{
|
||||
/**
|
||||
* @param class-string<BackedEnum> $enum
|
||||
*/
|
||||
public function __construct(
|
||||
protected string $enum,
|
||||
) {}
|
||||
|
||||
public function get(mixed $state): ?BackedEnum
|
||||
{
|
||||
if (blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($state instanceof $this->enum) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
if ($state instanceof Stringable) {
|
||||
$state = (string) $state;
|
||||
}
|
||||
|
||||
if (! is_scalar($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->enum::tryFrom($state);
|
||||
}
|
||||
|
||||
public function set(mixed $state): mixed
|
||||
{
|
||||
if (! ($state instanceof BackedEnum)) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
return strval($state->value);
|
||||
}
|
||||
}
|
||||
46
vendor/filament/schemas/src/Components/StateCasts/FileUploadStateCast.php
vendored
Normal file
46
vendor/filament/schemas/src/Components/StateCasts/FileUploadStateCast.php
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts;
|
||||
|
||||
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class FileUploadStateCast implements StateCast
|
||||
{
|
||||
public function __construct(
|
||||
protected bool $isMultiple = false,
|
||||
) {}
|
||||
|
||||
public function get(mixed $state): mixed
|
||||
{
|
||||
if ($this->isMultiple) {
|
||||
return array_values(Arr::wrap($state));
|
||||
}
|
||||
|
||||
if (! is_array($state)) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
return Arr::first($state);
|
||||
}
|
||||
|
||||
public function set(mixed $state): mixed
|
||||
{
|
||||
$newState = [];
|
||||
|
||||
foreach (Arr::wrap($state) as $key => $file) {
|
||||
if (blank($file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_numeric($key)) {
|
||||
$key = (string) Str::uuid();
|
||||
}
|
||||
|
||||
$newState[$key] = $file;
|
||||
}
|
||||
|
||||
return $newState;
|
||||
}
|
||||
}
|
||||
63
vendor/filament/schemas/src/Components/StateCasts/KeyValueStateCast.php
vendored
Normal file
63
vendor/filament/schemas/src/Components/StateCasts/KeyValueStateCast.php
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts;
|
||||
|
||||
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class KeyValueStateCast implements StateCast
|
||||
{
|
||||
/**
|
||||
* @return array<mixed, mixed>
|
||||
*/
|
||||
public function get(mixed $state): array
|
||||
{
|
||||
if (blank($state)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! is_array($state)) {
|
||||
$state = json_decode($state, associative: true);
|
||||
}
|
||||
|
||||
if (! is_array($state[array_key_first($state)])) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
$state = Arr::pluck($state, 'value', 'key');
|
||||
|
||||
if (array_key_exists('', $state)) {
|
||||
unset($state['']);
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array{key: mixed, value: mixed}>
|
||||
*/
|
||||
public function set(mixed $state): array
|
||||
{
|
||||
if (blank($state)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! is_array($state)) {
|
||||
$state = json_decode($state, associative: true);
|
||||
}
|
||||
|
||||
if (is_array($state[array_key_first($state)])) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
if (array_key_exists('', $state)) {
|
||||
unset($state['']);
|
||||
}
|
||||
|
||||
return array_map(
|
||||
fn ($value, $key): array => ['key' => $key, 'value' => $value],
|
||||
$state,
|
||||
array_keys($state),
|
||||
);
|
||||
}
|
||||
}
|
||||
31
vendor/filament/schemas/src/Components/StateCasts/NumberStateCast.php
vendored
Normal file
31
vendor/filament/schemas/src/Components/StateCasts/NumberStateCast.php
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts;
|
||||
|
||||
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||
|
||||
class NumberStateCast implements StateCast
|
||||
{
|
||||
public function __construct(
|
||||
protected bool $isNullable = true,
|
||||
protected bool $isInteger = false,
|
||||
) {}
|
||||
|
||||
public function get(mixed $state): int | float | null
|
||||
{
|
||||
if ($this->isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->isInteger ? intval($state) : floatval($state);
|
||||
}
|
||||
|
||||
public function set(mixed $state): int | float | null
|
||||
{
|
||||
if ($this->isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->isInteger ? intval($state) : floatval($state);
|
||||
}
|
||||
}
|
||||
78
vendor/filament/schemas/src/Components/StateCasts/OptionStateCast.php
vendored
Normal file
78
vendor/filament/schemas/src/Components/StateCasts/OptionStateCast.php
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||
use Stringable;
|
||||
|
||||
class OptionStateCast implements StateCast
|
||||
{
|
||||
public function __construct(
|
||||
protected bool $isNullable = true,
|
||||
) {}
|
||||
|
||||
public function get(mixed $state): string | int | null
|
||||
{
|
||||
if ($this->isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Security: this cast backs single-value option fields, so a legitimate state is
|
||||
// always a scalar or `null`. A tampered request payload can deliver an array (or
|
||||
// other non-scalar), which would throw a `TypeError` at the `strval()` below and
|
||||
// crash the request. Fail closed by treating it as no selection instead.
|
||||
if (! is_scalar($state) && (! $state instanceof BackedEnum) && (! $state instanceof Stringable)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($state instanceof BackedEnum) {
|
||||
$state = $state->value;
|
||||
}
|
||||
|
||||
if ($state instanceof Stringable) {
|
||||
$state = (string) $state;
|
||||
}
|
||||
|
||||
if (
|
||||
is_int($state)
|
||||
|| (
|
||||
is_string($state)
|
||||
&& ctype_digit($state)
|
||||
&& (($state === '0') || (! str($state)->startsWith('0')))
|
||||
)
|
||||
) {
|
||||
$max = (string) PHP_INT_MAX;
|
||||
|
||||
if (
|
||||
(strlen($state) > strlen($max)) ||
|
||||
((strlen($state) === strlen($max)) && (strcmp($state, $max) > 0))
|
||||
) {
|
||||
return strval($state);
|
||||
}
|
||||
|
||||
return intval($state);
|
||||
}
|
||||
|
||||
return strval($state);
|
||||
}
|
||||
|
||||
public function set(mixed $state): ?string
|
||||
{
|
||||
if ($this->isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Security: mirror `get()` and fail closed on a tampered non-scalar value so a
|
||||
// malformed array cannot reach `strval()` and crash the request.
|
||||
if (! is_scalar($state) && (! $state instanceof BackedEnum) && (! $state instanceof Stringable)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($state instanceof BackedEnum) {
|
||||
$state = $state->value;
|
||||
}
|
||||
|
||||
return strval($state);
|
||||
}
|
||||
}
|
||||
119
vendor/filament/schemas/src/Components/StateCasts/OptionsArrayStateCast.php
vendored
Normal file
119
vendor/filament/schemas/src/Components/StateCasts/OptionsArrayStateCast.php
vendored
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts;
|
||||
|
||||
use BackedEnum;
|
||||
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||
use Illuminate\Support\Arr;
|
||||
use Stringable;
|
||||
|
||||
class OptionsArrayStateCast implements StateCast
|
||||
{
|
||||
/**
|
||||
* @return array<string | int>
|
||||
*/
|
||||
public function get(mixed $state): array
|
||||
{
|
||||
if (blank($state)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! is_array($state)) {
|
||||
$state = json_decode($state, associative: true);
|
||||
}
|
||||
|
||||
/** @var array<mixed> $state */
|
||||
$state = Arr::wrap($state);
|
||||
|
||||
return array_reduce(
|
||||
$state,
|
||||
function (array $carry, $stateItem): array {
|
||||
if (blank($stateItem)) {
|
||||
return $carry;
|
||||
}
|
||||
|
||||
// Security: each option must be a scalar or `BackedEnum`, but a tampered
|
||||
// request payload can deliver a nested array, which would throw a `TypeError`
|
||||
// at the `strval()` below and crash the request. Fail closed by skipping it.
|
||||
if ((! is_scalar($stateItem)) && (! $stateItem instanceof BackedEnum) && (! $stateItem instanceof Stringable)) {
|
||||
return $carry;
|
||||
}
|
||||
|
||||
if ($stateItem instanceof BackedEnum) {
|
||||
$stateItem = $stateItem->value;
|
||||
}
|
||||
|
||||
if ($stateItem instanceof Stringable) {
|
||||
$stateItem = (string) $stateItem;
|
||||
}
|
||||
|
||||
if (
|
||||
is_int($stateItem)
|
||||
|| (
|
||||
is_string($stateItem)
|
||||
&& ctype_digit($stateItem)
|
||||
&& (($stateItem === '0') || (! str($stateItem)->startsWith('0')))
|
||||
)
|
||||
) {
|
||||
$max = (string) PHP_INT_MAX;
|
||||
|
||||
if (
|
||||
(strlen($stateItem) > strlen($max)) ||
|
||||
((strlen($stateItem) === strlen($max)) && (strcmp($stateItem, $max) > 0))
|
||||
) {
|
||||
$carry[] = strval($stateItem);
|
||||
} else {
|
||||
$carry[] = intval($stateItem);
|
||||
}
|
||||
} else {
|
||||
$carry[] = strval($stateItem);
|
||||
}
|
||||
|
||||
return $carry;
|
||||
},
|
||||
initial: [],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function set(mixed $state): array
|
||||
{
|
||||
if (blank($state)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! is_array($state)) {
|
||||
$state = json_decode($state, associative: true);
|
||||
}
|
||||
|
||||
/** @var array<mixed> $state */
|
||||
$state = Arr::wrap($state);
|
||||
|
||||
return array_reduce(
|
||||
$state,
|
||||
function (array $carry, $stateItem): array {
|
||||
if (blank($stateItem)) {
|
||||
return $carry;
|
||||
}
|
||||
|
||||
// Security: each option must be a scalar or `BackedEnum`, but a tampered
|
||||
// request payload can deliver a nested array, which would throw a `TypeError`
|
||||
// at the `strval()` below and crash the request. Fail closed by skipping it.
|
||||
if ((! is_scalar($stateItem)) && (! $stateItem instanceof BackedEnum) && (! $stateItem instanceof Stringable)) {
|
||||
return $carry;
|
||||
}
|
||||
|
||||
if ($stateItem instanceof BackedEnum) {
|
||||
$stateItem = $stateItem->value;
|
||||
}
|
||||
|
||||
$carry[] = strval($stateItem);
|
||||
|
||||
return $carry;
|
||||
},
|
||||
initial: [],
|
||||
);
|
||||
}
|
||||
}
|
||||
44
vendor/filament/schemas/src/Components/StateCasts/SliderStateCast.php
vendored
Normal file
44
vendor/filament/schemas/src/Components/StateCasts/SliderStateCast.php
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts;
|
||||
|
||||
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||
|
||||
class SliderStateCast implements StateCast
|
||||
{
|
||||
public function __construct(
|
||||
protected ?int $decimalPlaces = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return float | array<float>
|
||||
*/
|
||||
public function get(mixed $state): float | array
|
||||
{
|
||||
if (is_array($state)) {
|
||||
$state = array_map(floatval(...), $state);
|
||||
|
||||
if (filled($this->decimalPlaces)) {
|
||||
$state = array_map(fn (float $value): float => round($value, $this->decimalPlaces), $state);
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
$state = floatval($state);
|
||||
|
||||
if (filled($this->decimalPlaces)) {
|
||||
$state = round($state, $this->decimalPlaces);
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float | array<float>
|
||||
*/
|
||||
public function set(mixed $state): float | array
|
||||
{
|
||||
return $this->get($state);
|
||||
}
|
||||
}
|
||||
49
vendor/filament/schemas/src/Components/StateCasts/StripCharactersStateCast.php
vendored
Normal file
49
vendor/filament/schemas/src/Components/StateCasts/StripCharactersStateCast.php
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\StateCasts;
|
||||
|
||||
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
||||
|
||||
class StripCharactersStateCast implements StateCast
|
||||
{
|
||||
/**
|
||||
* @param array<string> $characters
|
||||
*/
|
||||
public function __construct(
|
||||
protected array $characters = [],
|
||||
) {}
|
||||
|
||||
public function get(mixed $state): mixed
|
||||
{
|
||||
if (empty($this->characters)) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
if (is_array($state)) {
|
||||
return array_map(fn (mixed $value): mixed => is_string($value) ? str_replace($this->characters, '', $value) : $value, $state);
|
||||
}
|
||||
|
||||
if (! is_string($state)) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
return str_replace($this->characters, '', $state);
|
||||
}
|
||||
|
||||
public function set(mixed $state): mixed
|
||||
{
|
||||
if (empty($this->characters)) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
if (is_array($state)) {
|
||||
return array_map(fn (mixed $value): mixed => is_string($value) ? str_replace($this->characters, '', $value) : $value, $state);
|
||||
}
|
||||
|
||||
if (! is_string($state)) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
return str_replace($this->characters, '', $state);
|
||||
}
|
||||
}
|
||||
961
vendor/filament/schemas/src/Components/Tabs.php
vendored
Normal file
961
vendor/filament/schemas/src/Components/Tabs.php
vendored
Normal file
|
|
@ -0,0 +1,961 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Schemas\Components\Concerns\CanPersistTab;
|
||||
use Filament\Schemas\Components\Concerns\HasLabel;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Schemas\Contracts\HasRenderHookScopes;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Schemas\View\SchemaIconAlias;
|
||||
use Filament\Support\Components\Attributes\ExposedLivewireMethod;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Facades\FilamentAsset;
|
||||
use Filament\Support\Facades\FilamentColor;
|
||||
use Filament\Support\Facades\FilamentView;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Support\View\Components\BadgeComponent;
|
||||
use Filament\Support\View\Components\DropdownComponent\ItemComponent;
|
||||
use Filament\Support\View\Components\DropdownComponent\ItemComponent\IconComponent;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Attributes\Renderless;
|
||||
|
||||
use function Filament\Support\generate_icon_html;
|
||||
use function Filament\Support\generate_loading_indicator_html;
|
||||
|
||||
class Tabs extends Component implements HasEmbeddedView
|
||||
{
|
||||
use CanPersistTab;
|
||||
use Concerns\CanBeContained;
|
||||
use Concerns\HasExtraAlpineAttributes;
|
||||
use HasLabel;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.tabs';
|
||||
|
||||
protected int | Closure $activeTab = 1;
|
||||
|
||||
protected string | Closure | null $tabQueryStringKey = null;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $startRenderHooks = [];
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $endRenderHooks = [];
|
||||
|
||||
protected string | Closure | null $livewireProperty = null;
|
||||
|
||||
protected bool | Closure $isScrollable = true;
|
||||
|
||||
protected bool | Closure $isVertical = false;
|
||||
|
||||
final public function __construct(string | Htmlable | Closure | null $label = null)
|
||||
{
|
||||
$this->label($label);
|
||||
}
|
||||
|
||||
public static function make(string | Htmlable | Closure | null $label = null): static
|
||||
{
|
||||
$static = app(static::class, ['label' => $label]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->key(function (Tabs $component): ?string {
|
||||
$label = $component->getLabel();
|
||||
|
||||
if (blank($label)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$statePath = $component->getStatePath();
|
||||
|
||||
return Str::slug(Str::transliterate($label, strict: true)) . '::' . (filled($statePath) ? "{$statePath}::tabs" : 'tabs');
|
||||
}, isInheritable: false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Tab> | Closure $tabs
|
||||
*/
|
||||
public function tabs(array | Closure $tabs): static
|
||||
{
|
||||
$this->components($tabs);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Component | Action | ActionGroup | string | Htmlable> | Schema
|
||||
*/
|
||||
public function getDefaultChildComponents(): array | Schema
|
||||
{
|
||||
$components = parent::getDefaultChildComponents();
|
||||
|
||||
if (blank($this->getLivewireProperty()) || (! is_array($components))) {
|
||||
return $components;
|
||||
}
|
||||
|
||||
// Each tab's key must match the array key written into the Livewire
|
||||
// property, so `$set(...)` can activate it. This is done here rather than
|
||||
// during rendering so the key is settled before any absolute keys (such
|
||||
// as those of nested actions) are computed and cached.
|
||||
foreach ($components as $tabKey => $tab) {
|
||||
if (! $tab instanceof Tab) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tab->key(strval($tabKey));
|
||||
}
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
public function activeTab(int | Closure $activeTab): static
|
||||
{
|
||||
$this->activeTab = $activeTab;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function persistTabInQueryString(string | Closure | null $key = 'tab'): static
|
||||
{
|
||||
$this->tabQueryStringKey = $key;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getActiveTab(): int
|
||||
{
|
||||
if ($this->isTabPersistedInQueryString()) {
|
||||
$queryStringTab = request()->query($this->getTabQueryStringKey());
|
||||
|
||||
foreach ($this->getChildSchema()->getComponents() as $index => $tab) {
|
||||
if ($tab->getId() !== $queryStringTab) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $index + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->evaluate($this->activeTab);
|
||||
}
|
||||
|
||||
public function getTabQueryStringKey(): ?string
|
||||
{
|
||||
return $this->evaluate($this->tabQueryStringKey);
|
||||
}
|
||||
|
||||
public function isTabPersistedInQueryString(): bool
|
||||
{
|
||||
return filled($this->getTabQueryStringKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $hooks
|
||||
*/
|
||||
public function startRenderHooks(array $hooks): static
|
||||
{
|
||||
$this->startRenderHooks = $hooks;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $hooks
|
||||
*/
|
||||
public function endRenderHooks(array $hooks): static
|
||||
{
|
||||
$this->endRenderHooks = $hooks;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getStartRenderHooks(): array
|
||||
{
|
||||
return $this->startRenderHooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getEndRenderHooks(): array
|
||||
{
|
||||
return $this->endRenderHooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getRenderHookScopes(): array
|
||||
{
|
||||
$livewire = $this->getLivewire();
|
||||
|
||||
if (! ($livewire instanceof HasRenderHookScopes)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $livewire->getRenderHookScopes();
|
||||
}
|
||||
|
||||
public function livewireProperty(string | Closure | null $property): static
|
||||
{
|
||||
$this->livewireProperty = $property;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLivewireProperty(): ?string
|
||||
{
|
||||
return $this->evaluate($this->livewireProperty);
|
||||
}
|
||||
|
||||
public function scrollable(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isScrollable = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isScrollable(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isScrollable);
|
||||
}
|
||||
|
||||
public function vertical(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isVertical = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isVertical(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isVertical);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
if (filled($this->getLivewireProperty())) {
|
||||
return $this->toEmbeddedHtmlForLivewireProperty();
|
||||
}
|
||||
|
||||
$activeTab = $this->getActiveTab();
|
||||
$hasDeferredBadges = $this->hasDeferredBadges();
|
||||
$id = $this->getId();
|
||||
$isContained = $this->isContained();
|
||||
$isScrollable = $this->isScrollable();
|
||||
$isVertical = $this->isVertical();
|
||||
$label = $this->getLabel();
|
||||
$renderHookScopes = $this->getRenderHookScopes();
|
||||
$tabs = array_values(array_filter(
|
||||
$this->getChildSchema()->getComponents(),
|
||||
static fn ($component): bool => $component instanceof Tab,
|
||||
));
|
||||
$tabsKey = $this->getKey();
|
||||
|
||||
$getTabVisibilityJs = static function (Tab $tab, ?int $index = null, ?string $mode = null) use ($isScrollable): ?string {
|
||||
$hiddenJs = $tab->getHiddenJs();
|
||||
$visibleJs = $tab->getVisibleJs();
|
||||
|
||||
$baseJs = match ([filled($hiddenJs), filled($visibleJs)]) {
|
||||
[true, true] => "(! ({$hiddenJs})) && ({$visibleJs})",
|
||||
[true, false] => "! ({$hiddenJs})",
|
||||
[false, true] => $visibleJs,
|
||||
default => null,
|
||||
};
|
||||
|
||||
if ($isScrollable || $index === null || $mode === null) {
|
||||
return $baseJs;
|
||||
}
|
||||
|
||||
$tabKey = $tab->getKey(isAbsolute: false);
|
||||
|
||||
$dropdownJs = match ($mode) {
|
||||
'inline' => "(!withinDropdownMounted || withinDropdownIndex === null || {$index} < withinDropdownIndex)",
|
||||
'trigger' => "(withinDropdownMounted && withinDropdownIndex !== null && {$index} >= withinDropdownIndex && '{$tabKey}' === tab)",
|
||||
default => null,
|
||||
};
|
||||
|
||||
return $baseJs ? "{$baseJs} && {$dropdownJs}" : $dropdownJs;
|
||||
};
|
||||
|
||||
$outerAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'id' => $id,
|
||||
'wire:key' => $this->getLivewireKey() . '.container',
|
||||
], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->merge($this->getExtraAlpineAttributes(), escape: false)
|
||||
->class([
|
||||
'fi-sc-tabs',
|
||||
'fi-contained' => $isContained,
|
||||
'fi-vertical' => $isVertical,
|
||||
]);
|
||||
|
||||
$navAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'aria-label' => $label,
|
||||
'role' => 'tablist',
|
||||
])
|
||||
->class([
|
||||
'fi-tabs',
|
||||
'fi-contained' => $isContained,
|
||||
'fi-vertical' => $isVertical,
|
||||
]);
|
||||
|
||||
if (! $isScrollable) {
|
||||
$navAttributes = $navAttributes->merge([
|
||||
'x-bind:class' => '{ \'fi-invisible\': ! withinDropdownMounted }',
|
||||
], escape: false);
|
||||
}
|
||||
|
||||
$navAttributes = $navAttributes->merge(['x-cloak' => true], escape: false);
|
||||
|
||||
$deferredBadgesXData = '';
|
||||
|
||||
if ($hasDeferredBadges) {
|
||||
$deferredBadgesXData = '{
|
||||
deferredBadges: {},
|
||||
isLoadingDeferredBadges: true,
|
||||
|
||||
async init() {
|
||||
try {
|
||||
const badges = await $wire.callSchemaComponentMethod(' . Js::from($tabsKey) . ', \'getDeferredTabBadges\')
|
||||
this.deferredBadges = badges ?? {}
|
||||
} finally {
|
||||
this.isLoadingDeferredBadges = false
|
||||
}
|
||||
},
|
||||
}';
|
||||
|
||||
$navAttributes = $navAttributes->merge([
|
||||
'x-data' => $deferredBadgesXData,
|
||||
], escape: false);
|
||||
}
|
||||
|
||||
$visibleTabKeysJson = collect($tabs)
|
||||
->filter(static fn (Tab $tab): bool => $tab->isVisible())
|
||||
->map(static fn (Tab $tab) => $tab->getKey(isAbsolute: false))
|
||||
->values()
|
||||
->toJson();
|
||||
|
||||
$alpineComponentSrc = FilamentAsset::getAlpineComponentSrc('tabs', 'filament/schemas');
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div
|
||||
x-data="tabsSchemaComponent({
|
||||
activeTab: <?= Js::from($activeTab) ?>,
|
||||
isScrollable: <?= Js::from($isScrollable) ?>,
|
||||
isTabPersisted: <?= Js::from($this->isTabPersisted()) ?>,
|
||||
isTabPersistedInQueryString: <?= Js::from($this->isTabPersistedInQueryString()) ?>,
|
||||
livewireId: <?= Js::from($this->getLivewire()->getId()) ?>,
|
||||
schemaKey: <?= Js::from($this->getRootContainer()->getKey()) ?>,
|
||||
tab: <?php if ($this->isTabPersisted() && filled($id)) { ?>$persist(null).as(<?= Js::from($id) ?>)<?php } else { ?><?= Js::from(null) ?><?php } ?>,
|
||||
tabQueryStringKey: <?= Js::from($this->getTabQueryStringKey()) ?>,
|
||||
})"
|
||||
x-load
|
||||
x-load-src="<?= e($alpineComponentSrc) ?>"
|
||||
wire:ignore.self
|
||||
<?= $outerAttributes->toHtml() ?>
|
||||
>
|
||||
<input
|
||||
type="hidden"
|
||||
value="<?= e($visibleTabKeysJson) ?>"
|
||||
x-ref="tabsData"
|
||||
/>
|
||||
|
||||
<nav <?= $navAttributes->toHtml() ?>>
|
||||
<?php foreach ($this->getStartRenderHooks() as $startRenderHook) { ?>
|
||||
<?= FilamentView::renderHook($startRenderHook, scopes: $renderHookScopes)->toHtml() ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php foreach ($tabs as $index => $tab) {
|
||||
$isTabBadgeDeferred = $tab->isBadgeDeferred();
|
||||
$tabBadge = $isTabBadgeDeferred ? null : $tab->getBadge();
|
||||
$tabBadgeColor = $isTabBadgeDeferred ? null : $tab->getBadgeColor($tabBadge);
|
||||
$tabBadgeIcon = $isTabBadgeDeferred ? null : $tab->getBadgeIcon($tabBadge);
|
||||
$tabBadgeIconPosition = $isTabBadgeDeferred ? null : $tab->getBadgeIconPosition($tabBadge);
|
||||
$tabBadgeTooltip = $isTabBadgeDeferred ? null : $tab->getBadgeTooltip($tabBadge);
|
||||
$tabExtraAttributeBag = $tab->getExtraAttributeBag();
|
||||
$tabIcon = $tab->getIcon();
|
||||
$tabIconPosition = $tab->getIconPosition();
|
||||
$tabKey = $tab->getKey(isAbsolute: false);
|
||||
$tabLabel = $tab->getLabel();
|
||||
$tabVisibilityJs = $getTabVisibilityJs($tab, $index, 'inline');
|
||||
|
||||
$tabItemAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge($tabExtraAttributeBag->getAttributes(), escape: false)
|
||||
->merge([
|
||||
'role' => 'tab',
|
||||
'aria-selected' => 'false',
|
||||
'data-tab-key' => $tabKey,
|
||||
'x-bind:aria-selected' => "tab === '{$tabKey}'",
|
||||
'x-on:click' => "tab = '{$tabKey}'",
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-tabs-item',
|
||||
]);
|
||||
|
||||
if ($tabVisibilityJs !== null) {
|
||||
$tabItemAttributes = $tabItemAttributes->merge([
|
||||
'x-cloak' => true,
|
||||
'x-show' => $tabVisibilityJs,
|
||||
], escape: false);
|
||||
}
|
||||
?>
|
||||
<button
|
||||
type="button"
|
||||
x-bind:class="{
|
||||
'fi-active': tab === '<?= e($tabKey) ?>',
|
||||
}"
|
||||
<?= $tabItemAttributes->toHtml() ?>
|
||||
>
|
||||
<?php if ($tabIcon && $tabIconPosition === IconPosition::Before) { ?>
|
||||
<?= generate_icon_html($tabIcon)?->toHtml() ?>
|
||||
<?php } ?>
|
||||
|
||||
<span class="fi-tabs-item-label">
|
||||
<?= e($tabLabel) ?>
|
||||
</span>
|
||||
|
||||
<?php if ($tabIcon && $tabIconPosition === IconPosition::After) { ?>
|
||||
<?= generate_icon_html($tabIcon)?->toHtml() ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (filled($tabBadge)) { ?>
|
||||
<?= $this->generateTabBadgeHtml($tabBadge, $tabBadgeColor, $tabBadgeIcon, $tabBadgeIconPosition, $tabBadgeTooltip) ?>
|
||||
<?php } elseif ($isTabBadgeDeferred) { ?>
|
||||
<?= $this->generateDeferredBadgePlaceholderHtml(Js::from($index)) ?>
|
||||
<?php } ?>
|
||||
</button>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (! $isScrollable) { ?>
|
||||
<div x-data="filamentDropdown" class="fi-dropdown">
|
||||
<div
|
||||
x-on:keyup.enter="toggle($event)"
|
||||
x-on:keyup.space="toggle($event)"
|
||||
x-on:mousedown="if ($event.button === 0) toggle($event)"
|
||||
class="fi-dropdown-trigger"
|
||||
>
|
||||
<?php foreach ($tabs as $index => $tab) {
|
||||
$isTabBadgeDeferred = $tab->isBadgeDeferred();
|
||||
$tabBadge = $isTabBadgeDeferred ? null : $tab->getBadge();
|
||||
$tabBadgeColor = $isTabBadgeDeferred ? null : $tab->getBadgeColor($tabBadge);
|
||||
$tabBadgeTooltip = $isTabBadgeDeferred ? null : $tab->getBadgeTooltip($tabBadge);
|
||||
$tabExtraAttributeBag = $tab->getExtraAttributeBag();
|
||||
$tabKey = $tab->getKey(isAbsolute: false);
|
||||
$tabLabel = $tab->getLabel();
|
||||
$tabVisibilityJs = $getTabVisibilityJs($tab, $index, 'trigger');
|
||||
|
||||
$triggerTabAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge($tabExtraAttributeBag->getAttributes(), escape: false)
|
||||
->merge([
|
||||
'role' => 'tab',
|
||||
'aria-selected' => 'false',
|
||||
'x-bind:aria-selected' => "tab === '{$tabKey}'",
|
||||
], escape: false)
|
||||
->class(['fi-tabs-item']);
|
||||
|
||||
if ($tabVisibilityJs !== null) {
|
||||
$triggerTabAttributes = $triggerTabAttributes->merge([
|
||||
'x-cloak' => true,
|
||||
'x-show' => $tabVisibilityJs,
|
||||
], escape: false);
|
||||
}
|
||||
|
||||
$chevronIconHtml = generate_icon_html(Heroicon::ChevronDown, alias: SchemaIconAlias::COMPONENTS_TABS_DROPDOWN_TRIGGER_BUTTON)?->toHtml();
|
||||
?>
|
||||
<button
|
||||
type="button"
|
||||
x-bind:class="{
|
||||
'fi-active': tab === '<?= e($tabKey) ?>',
|
||||
}"
|
||||
<?= $triggerTabAttributes->toHtml() ?>
|
||||
>
|
||||
<?= $chevronIconHtml ?>
|
||||
|
||||
<span class="fi-tabs-item-label">
|
||||
<?= e($tabLabel) ?>
|
||||
</span>
|
||||
|
||||
<?php if (filled($tabBadge)) { ?>
|
||||
<?= $this->generateTabBadgeHtml($tabBadge, $tabBadgeColor, tooltip: $tabBadgeTooltip) ?>
|
||||
<?php } elseif ($isTabBadgeDeferred) { ?>
|
||||
<?= $this->generateDeferredBadgePlaceholderHtml(Js::from($index)) ?>
|
||||
<?php } ?>
|
||||
</button>
|
||||
<?php } ?>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected="false"
|
||||
class="fi-tabs-item"
|
||||
x-show="isDropdownButtonVisible"
|
||||
>
|
||||
<span class="fi-tabs-item-label">
|
||||
<?= generate_icon_html(Heroicon::EllipsisHorizontal, alias: SchemaIconAlias::COMPONENTS_TABS_MORE_TABS_BUTTON)?->toHtml() ?>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
x-cloak
|
||||
x-float.placement.<?= e(__('filament-panels::layout.direction') === 'ltr' ? 'bottom-start' : 'bottom-end') ?>.flip.offset="{ offset: 8 }"
|
||||
x-ref="panel"
|
||||
x-transition:enter-start="fi-opacity-0"
|
||||
x-transition:leave-end="fi-opacity-0"
|
||||
class="fi-dropdown-panel"
|
||||
>
|
||||
<div class="fi-dropdown-list">
|
||||
<?php foreach ($tabs as $index => $tab) {
|
||||
$isTabBadgeDeferred = $tab->isBadgeDeferred();
|
||||
$tabBadge = $isTabBadgeDeferred ? null : $tab->getBadge();
|
||||
$tabBadgeColor = $isTabBadgeDeferred ? null : $tab->getBadgeColor($tabBadge);
|
||||
$tabBadgeTooltip = $isTabBadgeDeferred ? null : $tab->getBadgeTooltip($tabBadge);
|
||||
$tabIcon = $tab->getIcon();
|
||||
$tabKey = $tab->getKey(isAbsolute: false);
|
||||
$tabLabel = $tab->getLabel();
|
||||
|
||||
$dropdownItemAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'type' => 'button',
|
||||
'wire:loading.attr' => 'disabled',
|
||||
'x-bind:class' => "{ 'fi-selected': tab === '" . e($tabKey) . "' }",
|
||||
'x-on:click' => "tab = '{$tabKey}'; close(\$event);",
|
||||
'x-show' => "{$index} >= withinDropdownIndex",
|
||||
], escape: false)
|
||||
->class(['fi-dropdown-list-item'])
|
||||
->color(ItemComponent::class, 'gray');
|
||||
?>
|
||||
<button <?= $dropdownItemAttributes->toHtml() ?>>
|
||||
<?php if ($tabIcon) { ?>
|
||||
<?= generate_icon_html($tabIcon, attributes: (new FilamentComponentAttributeBag)->color(IconComponent::class, 'gray'))?->toHtml() ?>
|
||||
<?php } ?>
|
||||
|
||||
<span class="fi-dropdown-list-item-label">
|
||||
<?= e($tabLabel) ?>
|
||||
</span>
|
||||
|
||||
<?php if (filled($tabBadge)) { ?>
|
||||
<span
|
||||
<?php if ($tabBadgeTooltip) { ?>
|
||||
x-tooltip="{
|
||||
content: <?= Js::from($tabBadgeTooltip) ?>,
|
||||
theme: $store.theme,
|
||||
allowHTML: <?= Js::from($tabBadgeTooltip instanceof Htmlable) ?>,
|
||||
}"
|
||||
<?php } ?>
|
||||
<?= (new FilamentComponentAttributeBag)->color(BadgeComponent::class, $tabBadgeColor ?? 'primary')->class(['fi-badge'])->toHtml() ?>
|
||||
>
|
||||
<?= e($tabBadge) ?>
|
||||
</span>
|
||||
<?php } elseif ($isTabBadgeDeferred) { ?>
|
||||
<span
|
||||
x-show="isLoadingDeferredBadges"
|
||||
x-cloak
|
||||
class="fi-dropdown-list-item-badge-placeholder"
|
||||
>
|
||||
<?= generate_loading_indicator_html(size: IconSize::Small)->toHtml() ?>
|
||||
</span>
|
||||
|
||||
<template
|
||||
x-if="
|
||||
! isLoadingDeferredBadges &&
|
||||
deferredBadges[<?= Js::from($index) ?>]?.badge != null
|
||||
"
|
||||
>
|
||||
<span
|
||||
x-bind:class="'fi-badge ' + (deferredBadges[<?= Js::from($index) ?>]?.badgeColorClasses ?? '')"
|
||||
x-bind:style="deferredBadges[<?= Js::from($index) ?>]?.badgeColorStyles ?? ''"
|
||||
x-init="
|
||||
let tooltip = deferredBadges[<?= Js::from($index) ?>]?.badgeTooltip
|
||||
if (tooltip) {
|
||||
window.tippy?.($el, {
|
||||
content: tooltip,
|
||||
theme: $store.theme,
|
||||
})
|
||||
}
|
||||
"
|
||||
>
|
||||
<span class="fi-badge-label-ctn">
|
||||
<span
|
||||
class="fi-badge-label"
|
||||
x-text="deferredBadges[<?= Js::from($index) ?>]?.badge"
|
||||
></span>
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
<?php } ?>
|
||||
</button>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php foreach ($this->getEndRenderHooks() as $endRenderHook) { ?>
|
||||
<?= FilamentView::renderHook($endRenderHook, scopes: $renderHookScopes)->toHtml() ?>
|
||||
<?php } ?>
|
||||
</nav>
|
||||
|
||||
<?php foreach ($tabs as $tab) {
|
||||
$tabVisibilityJs = $getTabVisibilityJs($tab);
|
||||
|
||||
if ($tabVisibilityJs) { ?>
|
||||
<div x-cloak x-show="<?= $tabVisibilityJs ?>">
|
||||
<?= $tab->toHtml() ?>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<?= $tab->toHtml() ?>
|
||||
<?php }
|
||||
} ?>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
protected function toEmbeddedHtmlForLivewireProperty(): string
|
||||
{
|
||||
$livewireProperty = $this->getLivewireProperty();
|
||||
$hasDeferredBadges = $this->hasDeferredBadges();
|
||||
$id = $this->getId();
|
||||
$isContained = $this->isContained();
|
||||
$isVertical = $this->isVertical();
|
||||
$label = $this->getLabel();
|
||||
$renderHookScopes = $this->getRenderHookScopes();
|
||||
$tabsKey = $this->getKey();
|
||||
|
||||
// Tab keys are overridden with their array keys in
|
||||
// `getDefaultChildComponents()`.
|
||||
/** @var array<array-key, Tab> $tabs */
|
||||
$tabs = array_filter(
|
||||
$this->getChildSchema()->getComponents(withOriginalKeys: true),
|
||||
static fn ($component): bool => $component instanceof Tab,
|
||||
);
|
||||
|
||||
$activeTab = strval($this->getLivewire()->{$livewireProperty});
|
||||
|
||||
$outerAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'id' => $id,
|
||||
'wire:key' => $this->getLivewireKey() . '.container',
|
||||
], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->class([
|
||||
'fi-sc-tabs',
|
||||
'fi-contained' => $isContained,
|
||||
'fi-vertical' => $isVertical,
|
||||
]);
|
||||
|
||||
if ($hasDeferredBadges) {
|
||||
$outerAttributes = $outerAttributes->merge([
|
||||
'x-data' => '{
|
||||
deferredBadges: {},
|
||||
isLoadingDeferredBadges: true,
|
||||
|
||||
async init() {
|
||||
try {
|
||||
const badges = await $wire.callSchemaComponentMethod(' . Js::from($tabsKey) . ', \'getDeferredTabBadges\')
|
||||
this.deferredBadges = badges ?? {}
|
||||
} finally {
|
||||
this.isLoadingDeferredBadges = false
|
||||
}
|
||||
},
|
||||
}',
|
||||
], escape: false);
|
||||
}
|
||||
|
||||
$navAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'aria-label' => $label,
|
||||
'role' => 'tablist',
|
||||
])
|
||||
->class([
|
||||
'fi-tabs',
|
||||
'fi-contained' => $isContained,
|
||||
'fi-vertical' => $isVertical,
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $outerAttributes->toHtml() ?>>
|
||||
<nav <?= $navAttributes->toHtml() ?>>
|
||||
<?php foreach ($this->getStartRenderHooks() as $startRenderHook) { ?>
|
||||
<?= FilamentView::renderHook($startRenderHook, scopes: $renderHookScopes)->toHtml() ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php
|
||||
$livewire = $this->getLivewire();
|
||||
$canGenerateTabLabel = method_exists($livewire, 'generateTabLabel');
|
||||
?>
|
||||
|
||||
<?php foreach ($tabs as $tabKey => $tab) {
|
||||
$tabKey = strval($tabKey);
|
||||
$isTabBadgeDeferred = $tab->isBadgeDeferred();
|
||||
$tabBadge = $isTabBadgeDeferred ? null : $tab->getBadge();
|
||||
$tabBadgeColor = $isTabBadgeDeferred ? null : $tab->getBadgeColor($tabBadge);
|
||||
$tabBadgeIcon = $isTabBadgeDeferred ? null : $tab->getBadgeIcon($tabBadge);
|
||||
$tabBadgeIconPosition = $isTabBadgeDeferred ? null : $tab->getBadgeIconPosition($tabBadge);
|
||||
$tabBadgeTooltip = $isTabBadgeDeferred ? null : $tab->getBadgeTooltip($tabBadge);
|
||||
$tabExtraAttributeBag = $tab->getExtraAttributeBag();
|
||||
$tabIcon = $tab->getIcon();
|
||||
$tabIconPosition = $tab->getIconPosition();
|
||||
$tabLabel = $tab->getLabel() ?? ($canGenerateTabLabel ? $livewire->generateTabLabel($tabKey) : null);
|
||||
$isActive = $activeTab === $tabKey;
|
||||
|
||||
$wireClickValue = filled($tabKey)
|
||||
? "\$set('{$livewireProperty}', '" . addslashes($tabKey) . "')"
|
||||
: "\$set('{$livewireProperty}', null)";
|
||||
|
||||
$tabItemAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge($tabExtraAttributeBag->getAttributes(), escape: false)
|
||||
->merge([
|
||||
'aria-selected' => $isActive ? 'true' : 'false',
|
||||
'role' => 'tab',
|
||||
'type' => 'button',
|
||||
'wire:click' => $wireClickValue,
|
||||
'wire:loading.attr' => 'disabled',
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-tabs-item',
|
||||
'fi-active' => $isActive,
|
||||
]);
|
||||
?>
|
||||
<button <?= $tabItemAttributes->toHtml() ?>>
|
||||
<?php if ($tabIcon && $tabIconPosition === IconPosition::Before) { ?>
|
||||
<?= generate_icon_html($tabIcon)?->toHtml() ?>
|
||||
<?php } ?>
|
||||
|
||||
<span class="fi-tabs-item-label">
|
||||
<?= e($tabLabel) ?>
|
||||
</span>
|
||||
|
||||
<?php if ($tabIcon && $tabIconPosition === IconPosition::After) { ?>
|
||||
<?= generate_icon_html($tabIcon)?->toHtml() ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (filled($tabBadge)) { ?>
|
||||
<?= $this->generateTabBadgeHtml($tabBadge, $tabBadgeColor, $tabBadgeIcon, $tabBadgeIconPosition, $tabBadgeTooltip) ?>
|
||||
<?php } elseif ($isTabBadgeDeferred) { ?>
|
||||
<?= $this->generateDeferredBadgePlaceholderHtml(Js::from($tabKey)) ?>
|
||||
<?php } ?>
|
||||
</button>
|
||||
<?php } ?>
|
||||
|
||||
<?php foreach ($this->getEndRenderHooks() as $endRenderHook) { ?>
|
||||
<?= FilamentView::renderHook($endRenderHook, scopes: $renderHookScopes)->toHtml() ?>
|
||||
<?php } ?>
|
||||
</nav>
|
||||
|
||||
<?php foreach ($tabs as $tab) { ?>
|
||||
<?= $tab->toHtml() ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string | array<string> | null $color
|
||||
*/
|
||||
protected function generateTabBadgeHtml(
|
||||
string | int | float $badge,
|
||||
string | array | null $color = null,
|
||||
string | BackedEnum | Htmlable | null $icon = null,
|
||||
IconPosition | string | null $iconPosition = null,
|
||||
string | Htmlable | null $tooltip = null,
|
||||
): string {
|
||||
if (! $iconPosition instanceof IconPosition) {
|
||||
$iconPosition = filled($iconPosition) ? (IconPosition::tryFrom($iconPosition) ?? $iconPosition) : IconPosition::Before;
|
||||
}
|
||||
|
||||
$badgeAttributes = (new FilamentComponentAttributeBag)
|
||||
->class(['fi-badge', 'fi-size-sm'])
|
||||
->color(BadgeComponent::class, $color ?? 'primary');
|
||||
|
||||
ob_start(); ?>
|
||||
<span
|
||||
<?php if ($tooltip) { ?>
|
||||
x-tooltip="{
|
||||
content: <?= Js::from($tooltip) ?>,
|
||||
theme: $store.theme,
|
||||
allowHTML: <?= Js::from($tooltip instanceof Htmlable) ?>,
|
||||
}"
|
||||
<?php } ?>
|
||||
<?= $badgeAttributes->toHtml() ?>
|
||||
>
|
||||
<?php if ($icon && $iconPosition === IconPosition::Before) { ?>
|
||||
<?= generate_icon_html($icon, size: IconSize::Small)?->toHtml() ?>
|
||||
<?php } ?>
|
||||
|
||||
<span class="fi-badge-label-ctn">
|
||||
<span class="fi-badge-label">
|
||||
<?= e($badge) ?>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<?php if ($icon && $iconPosition === IconPosition::After) { ?>
|
||||
<?= generate_icon_html($icon, size: IconSize::Small)?->toHtml() ?>
|
||||
<?php } ?>
|
||||
</span>
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
protected function generateDeferredBadgePlaceholderHtml(Js $indexJs): string
|
||||
{
|
||||
ob_start(); ?>
|
||||
<span
|
||||
x-show="isLoadingDeferredBadges"
|
||||
x-cloak
|
||||
class="fi-tabs-item-badge-placeholder"
|
||||
>
|
||||
<?= generate_loading_indicator_html(size: IconSize::Small)->toHtml() ?>
|
||||
</span>
|
||||
|
||||
<template
|
||||
x-if="
|
||||
! isLoadingDeferredBadges &&
|
||||
deferredBadges[<?= $indexJs ?>]?.badge != null
|
||||
"
|
||||
>
|
||||
<span
|
||||
x-bind:class="
|
||||
'fi-badge fi-size-sm ' +
|
||||
(deferredBadges[<?= $indexJs ?>]?.badgeColorClasses ?? '')
|
||||
"
|
||||
x-bind:style="deferredBadges[<?= $indexJs ?>]?.badgeColorStyles ?? ''"
|
||||
x-init="
|
||||
let tooltip = deferredBadges[<?= $indexJs ?>]?.badgeTooltip
|
||||
if (tooltip) {
|
||||
window.tippy?.($el, {
|
||||
content: tooltip,
|
||||
theme: $store.theme,
|
||||
})
|
||||
}
|
||||
"
|
||||
>
|
||||
<template
|
||||
x-if="
|
||||
deferredBadges[<?= $indexJs ?>]?.badgeIconHtml &&
|
||||
deferredBadges[<?= $indexJs ?>]?.badgeIconPosition !== 'after'
|
||||
"
|
||||
>
|
||||
<span
|
||||
x-html="deferredBadges[<?= $indexJs ?>].badgeIconHtml"
|
||||
></span>
|
||||
</template>
|
||||
|
||||
<span class="fi-badge-label-ctn">
|
||||
<span
|
||||
class="fi-badge-label"
|
||||
x-text="deferredBadges[<?= $indexJs ?>]?.badge"
|
||||
></span>
|
||||
</span>
|
||||
|
||||
<template
|
||||
x-if="
|
||||
deferredBadges[<?= $indexJs ?>]?.badgeIconHtml &&
|
||||
deferredBadges[<?= $indexJs ?>]?.badgeIconPosition === 'after'
|
||||
"
|
||||
>
|
||||
<span
|
||||
x-html="deferredBadges[<?= $indexJs ?>].badgeIconHtml"
|
||||
></span>
|
||||
</template>
|
||||
</span>
|
||||
</template>
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{badge: ?string, badgeColorClasses: string, badgeColorStyles: string, badgeIconHtml: string | null, badgeIconPosition: string | null, badgeTooltip: string | null}>
|
||||
*/
|
||||
#[ExposedLivewireMethod]
|
||||
#[Renderless]
|
||||
public function getDeferredTabBadges(): array
|
||||
{
|
||||
$badges = [];
|
||||
|
||||
foreach ($this->getChildSchema()->getComponents(withOriginalKeys: true) as $tabKey => $tab) {
|
||||
if (! $tab instanceof Tab) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $tab->isBadgeDeferred()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$badge = $tab->getBadge();
|
||||
$badgeColor = $tab->getBadgeColor($badge);
|
||||
|
||||
$badgeColorClasses = '';
|
||||
$badgeColorStyles = '';
|
||||
|
||||
if (is_array($badgeColor)) {
|
||||
$badgeColorClasses = 'fi-color';
|
||||
$badgeColorStyles = implode('; ', FilamentColor::getComponentCustomStyles(BadgeComponent::class, $badgeColor));
|
||||
} elseif (is_string($badgeColor)) {
|
||||
$badgeColorClasses = implode(' ', FilamentColor::getComponentClasses(BadgeComponent::class, $badgeColor));
|
||||
}
|
||||
|
||||
$badgeIcon = $tab->getBadgeIcon($badge);
|
||||
$badgeIconHtml = $badgeIcon
|
||||
? generate_icon_html($badgeIcon, size: IconSize::Small)?->toHtml()
|
||||
: null;
|
||||
|
||||
$badgeIconPosition = $tab->getBadgeIconPosition($badge);
|
||||
$badgeTooltip = $tab->getBadgeTooltip($badge);
|
||||
|
||||
$badges[strval($tabKey)] = [
|
||||
'badge' => $badge,
|
||||
'badgeColorClasses' => $badgeColorClasses,
|
||||
'badgeColorStyles' => $badgeColorStyles,
|
||||
'badgeIconHtml' => $badgeIconHtml,
|
||||
'badgeIconPosition' => $badgeIconPosition instanceof IconPosition ? $badgeIconPosition->value : $badgeIconPosition,
|
||||
'badgeTooltip' => $badgeTooltip ? strval($badgeTooltip) : null,
|
||||
];
|
||||
}
|
||||
|
||||
return $badges;
|
||||
}
|
||||
|
||||
public function hasDeferredBadges(): bool
|
||||
{
|
||||
foreach ($this->getChildSchema()->getComponents() as $tab) {
|
||||
if (! $tab instanceof Tab) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($tab->isBadgeDeferred()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
216
vendor/filament/schemas/src/Components/Tabs/Tab.php
vendored
Normal file
216
vendor/filament/schemas/src/Components/Tabs/Tab.php
vendored
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Tabs;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Concerns\HasLabel;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\HasBadge;
|
||||
use Filament\Support\Concerns\HasBadgeTooltip;
|
||||
use Filament\Support\Concerns\HasIcon;
|
||||
use Filament\Support\Concerns\HasIconPosition;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Tab extends Component implements HasEmbeddedView
|
||||
{
|
||||
use HasBadge;
|
||||
use HasBadgeTooltip;
|
||||
use HasIcon;
|
||||
use HasIconPosition;
|
||||
use HasLabel;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.tabs.tab';
|
||||
|
||||
protected ?Closure $modifyQueryUsing = null;
|
||||
|
||||
protected bool | Closure $shouldExcludeQueryWhenResolvingRecord = false;
|
||||
|
||||
protected string | BackedEnum | Htmlable | Closure | null $badgeIcon = null;
|
||||
|
||||
protected IconPosition | string | Closure | null $badgeIconPosition = null;
|
||||
|
||||
protected bool | Closure $isBadgeDeferred = false;
|
||||
|
||||
final public function __construct(string | Htmlable | Closure | null $label = null)
|
||||
{
|
||||
$this->label($label);
|
||||
}
|
||||
|
||||
public static function make(string | Htmlable | Closure | null $label = null): static
|
||||
{
|
||||
$static = app(static::class, ['label' => $label]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->key(function (Tab $component): string {
|
||||
$label = $component->getLabel();
|
||||
$statePath = $component->getStatePath();
|
||||
|
||||
return Str::slug(Str::transliterate($label, strict: true)) . '::' . (filled($statePath) ? "{$statePath}::tab" : 'tab');
|
||||
}, isInheritable: false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int | null>
|
||||
*/
|
||||
public function getAllColumns(): array
|
||||
{
|
||||
if ($this->columns === null) {
|
||||
return $this->getContainer()->getAllColumns();
|
||||
}
|
||||
|
||||
return parent::getAllColumns();
|
||||
}
|
||||
|
||||
public function query(?Closure $callback): static
|
||||
{
|
||||
$this->modifyQueryUsing($callback);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function modifyQueryUsing(?Closure $callback): static
|
||||
{
|
||||
$this->modifyQueryUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TModel of Model
|
||||
*
|
||||
* @param Builder<TModel> $query
|
||||
* @return Builder<TModel>
|
||||
*/
|
||||
public function modifyQuery(Builder $query): Builder
|
||||
{
|
||||
return $this->evaluate($this->modifyQueryUsing, [
|
||||
'query' => $query,
|
||||
]) ?? $query;
|
||||
}
|
||||
|
||||
public function badgeIcon(string | BackedEnum | Htmlable | Closure | null $icon): static
|
||||
{
|
||||
$this->badgeIcon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function badgeIconPosition(IconPosition | string | Closure | null $position): static
|
||||
{
|
||||
$this->badgeIconPosition = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBadgeIcon(?string $badge = null): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->badgeIcon, [
|
||||
'badge' => $badge,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getBadgeIconPosition(?string $badge = null): IconPosition | string
|
||||
{
|
||||
return $this->evaluate($this->badgeIconPosition, [
|
||||
'badge' => $badge,
|
||||
]) ?? IconPosition::Before;
|
||||
}
|
||||
|
||||
public function deferBadge(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isBadgeDeferred = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isBadgeDeferred(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isBadgeDeferred);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$id = $this->getId();
|
||||
$key = $this->getKey(isAbsolute: false);
|
||||
/** @var Tabs $tabs */
|
||||
$tabs = $this->getContainer()->getParentComponent();
|
||||
$livewireProperty = $tabs->getLivewireProperty();
|
||||
|
||||
$childSchema = $this->getChildSchema();
|
||||
|
||||
if (empty($childSchema->getComponents())) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$attributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'aria-labelledby' => $id,
|
||||
'id' => $id,
|
||||
'role' => 'tabpanel',
|
||||
'wire:key' => $this->getLivewireKey() . '.container',
|
||||
], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->class(['fi-sc-tabs-tab']);
|
||||
|
||||
if (blank($livewireProperty)) {
|
||||
ob_start(); ?>
|
||||
|
||||
<div
|
||||
x-bind:class="{
|
||||
'fi-active': tab === <?= Js::from($key) ?>,
|
||||
}"
|
||||
x-on:expand="tab = <?= Js::from($key) ?>"
|
||||
<?= $attributes->toHtml() ?>
|
||||
>
|
||||
<?= $childSchema->toHtml() ?>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
if (strval($tabs->getLivewire()->{$livewireProperty}) !== strval($key)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div <?= $attributes->class(['fi-active'])->toHtml() ?>>
|
||||
<?= $childSchema->toHtml() ?>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
public function excludeQueryWhenResolvingRecord(bool | Closure $condition = true): static
|
||||
{
|
||||
// Security: Do NOT use this on tabs that enforce authorization
|
||||
// scopes (e.g. restricting records by tenant or user ownership).
|
||||
// Excluding the query allows direct URL access to records
|
||||
// that the tab's scope would otherwise prevent.
|
||||
|
||||
$this->shouldExcludeQueryWhenResolvingRecord = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function shouldExcludeQueryWhenResolvingRecord(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->shouldExcludeQueryWhenResolvingRecord);
|
||||
}
|
||||
}
|
||||
242
vendor/filament/schemas/src/Components/Text.php
vendored
Normal file
242
vendor/filament/schemas/src/Components/Text.php
vendored
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Schemas\JsContent;
|
||||
use Filament\Schemas\View\Components\TextComponent;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns\CanBeCopied;
|
||||
use Filament\Support\Concerns\HasColor;
|
||||
use Filament\Support\Concerns\HasFontFamily;
|
||||
use Filament\Support\Concerns\HasIcon;
|
||||
use Filament\Support\Concerns\HasIconPosition;
|
||||
use Filament\Support\Concerns\HasIconSize;
|
||||
use Filament\Support\Concerns\HasTooltip;
|
||||
use Filament\Support\Concerns\HasWeight;
|
||||
use Filament\Support\Enums\FontFamily;
|
||||
use Filament\Support\Enums\FontWeight;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Support\Enums\TextSize;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Filament\Support\View\Components\BadgeComponent;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
|
||||
use function Filament\Support\generate_icon_html;
|
||||
|
||||
class Text extends Component implements HasEmbeddedView
|
||||
{
|
||||
use CanBeCopied;
|
||||
use HasColor;
|
||||
use HasFontFamily;
|
||||
use HasIcon;
|
||||
use HasIconPosition;
|
||||
use HasIconSize;
|
||||
use HasTooltip;
|
||||
use HasWeight;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.text';
|
||||
|
||||
protected string | Htmlable | Closure | null $content;
|
||||
|
||||
protected bool | Closure $isBadge = false;
|
||||
|
||||
protected TextSize | Size | string | Closure | null $size = null;
|
||||
|
||||
final public function __construct(string | Htmlable | Closure | null $content)
|
||||
{
|
||||
$this->content($content);
|
||||
}
|
||||
|
||||
public static function make(string | Htmlable | Closure | null $content): static
|
||||
{
|
||||
$static = app(static::class, ['content' => $content]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->defaultColor('gray');
|
||||
}
|
||||
|
||||
public function content(string | Htmlable | Closure | null $content): static
|
||||
{
|
||||
$this->content = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function badge(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isBadge = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isBadge(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isBadge);
|
||||
}
|
||||
|
||||
public function js(): static
|
||||
{
|
||||
$this->content(JsContent::make($this->getContent()));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContent(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->content);
|
||||
}
|
||||
|
||||
public function size(TextSize | Size | string | Closure | null $size): static
|
||||
{
|
||||
$this->size = $size;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSize(): TextSize | Size | string | null
|
||||
{
|
||||
$size = $this->evaluate($this->size);
|
||||
|
||||
if (blank($size)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_string($size)) {
|
||||
$size = TextSize::tryFrom($size) ?? $size;
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$color = $this->getColor();
|
||||
$content = $this->getContent();
|
||||
$icon = $this->getIcon();
|
||||
$iconPosition = $this->getIconPosition();
|
||||
$iconSize = $this->getIconSize();
|
||||
$size = $this->getSize();
|
||||
$tooltip = $this->getTooltip();
|
||||
$weight = $this->getWeight();
|
||||
$fontFamily = $this->getFontFamily();
|
||||
|
||||
$copyableState = $this->getCopyableState($content) ?? $content;
|
||||
$copyMessage = $this->getCopyMessage($copyableState);
|
||||
$copyMessageDuration = $this->getCopyMessageDuration($copyableState);
|
||||
$isCopyable = $this->isCopyable($copyableState);
|
||||
|
||||
$hasTooltip = filled($tooltip);
|
||||
|
||||
if ($this->isBadge()) {
|
||||
if (! $size instanceof Size) {
|
||||
$size = filled($size) ? (is_string($size) ? (Size::tryFrom($size) ?? $size) : $size) : Size::Medium;
|
||||
}
|
||||
|
||||
if (filled($iconSize) && (! $iconSize instanceof IconSize)) {
|
||||
$iconSize = IconSize::tryFrom($iconSize) ?? $iconSize;
|
||||
}
|
||||
|
||||
$badgeAttributes = $this->getExtraAttributeBag()
|
||||
->merge([
|
||||
'type' => $isCopyable ? 'button' : null,
|
||||
'wire:loading.attr' => $isCopyable ? 'disabled' : null,
|
||||
], escape: false)
|
||||
->class([
|
||||
'fi-sc-text',
|
||||
'fi-badge',
|
||||
($size instanceof BackedEnum) ? "fi-size-{$size->value}" : $size,
|
||||
])
|
||||
->color(BadgeComponent::class, $color ?? 'primary');
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<<?= $isCopyable ? 'button' : 'span' ?>
|
||||
<?php if ($isCopyable) { ?>
|
||||
x-on:click="
|
||||
window.navigator.clipboard.writeText(<?= Js::from($copyableState) ?>)
|
||||
$tooltip(<?= Js::from($copyMessage) ?>, {
|
||||
theme: $store.theme,
|
||||
timeout: <?= Js::from($copyMessageDuration) ?>,
|
||||
})
|
||||
"
|
||||
<?php } ?>
|
||||
<?php if ($hasTooltip) { ?>
|
||||
x-tooltip="{
|
||||
content: <?= Js::from($tooltip) ?>,
|
||||
theme: $store.theme,
|
||||
allowHTML: <?= Js::from($tooltip instanceof Htmlable) ?>,
|
||||
}"
|
||||
<?php } ?>
|
||||
<?= $badgeAttributes->toHtml() ?>
|
||||
>
|
||||
<?php if ($iconPosition === IconPosition::Before && filled($icon)) { ?>
|
||||
<?= generate_icon_html($icon, size: $iconSize ?? IconSize::Small)?->toHtml() ?>
|
||||
<?php } ?>
|
||||
|
||||
<span class="fi-badge-label-ctn">
|
||||
<span class="fi-badge-label"><?= e($content) ?></span>
|
||||
</span>
|
||||
|
||||
<?php if ($iconPosition === IconPosition::After && filled($icon)) { ?>
|
||||
<?= generate_icon_html($icon, size: $iconSize ?? IconSize::Small)?->toHtml() ?>
|
||||
<?php } ?>
|
||||
</<?= $isCopyable ? 'button' : 'span' ?>>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
|
||||
// Non-badge mode: simple span
|
||||
$spanAttributes = (new FilamentComponentAttributeBag)
|
||||
->color(TextComponent::class, $color)
|
||||
->class([
|
||||
'fi-sc-text',
|
||||
'fi-copyable' => $isCopyable,
|
||||
($size instanceof BackedEnum) ? "fi-size-{$size->value}" : $size,
|
||||
($weight instanceof FontWeight) ? "fi-font-{$weight->value}" : $weight,
|
||||
($fontFamily instanceof FontFamily) ? "fi-font-{$fontFamily->value}" : $fontFamily,
|
||||
])
|
||||
->merge($this->getExtraAttributes(), escape: false);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<span
|
||||
<?php if ($isCopyable) { ?>
|
||||
role="button"
|
||||
tabindex="0"
|
||||
x-on:click="
|
||||
window.navigator.clipboard.writeText(<?= Js::from($copyableState) ?>)
|
||||
$tooltip(<?= Js::from($copyMessage) ?>, {
|
||||
theme: $store.theme,
|
||||
timeout: <?= Js::from($copyMessageDuration) ?>,
|
||||
})
|
||||
"
|
||||
x-on:keydown.enter.prevent="$el.click()"
|
||||
x-on:keydown.space.prevent="$el.click()"
|
||||
<?php } ?>
|
||||
<?php if ($hasTooltip) { ?>
|
||||
x-tooltip="{
|
||||
content: <?= Js::from($tooltip) ?>,
|
||||
theme: $store.theme,
|
||||
allowHTML: <?= Js::from($tooltip instanceof Htmlable) ?>,
|
||||
}"
|
||||
<?php } ?>
|
||||
<?= $spanAttributes->toHtml() ?>
|
||||
>
|
||||
<?= e($content) ?>
|
||||
</span>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
88
vendor/filament/schemas/src/Components/UnorderedList.php
vendored
Normal file
88
vendor/filament/schemas/src/Components/UnorderedList.php
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Enums\GridDirection;
|
||||
use Filament\Support\Enums\TextSize;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class UnorderedList extends Component implements HasEmbeddedView
|
||||
{
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.unordered-list';
|
||||
|
||||
protected TextSize | string | Closure | null $size = null;
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Closure $schema
|
||||
*/
|
||||
final public function __construct(array | Closure $schema = [])
|
||||
{
|
||||
$this->schema($schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Component | Action | ActionGroup | string | Htmlable> | Closure $schema
|
||||
*/
|
||||
public static function make(array | Closure $schema = []): static
|
||||
{
|
||||
$static = app(static::class, ['schema' => $schema]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->columns(['sm' => 2]);
|
||||
}
|
||||
|
||||
public function size(TextSize | string | Closure | null $size): static
|
||||
{
|
||||
$this->size = $size;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSize(): TextSize | string | null
|
||||
{
|
||||
$size = $this->evaluate($this->size);
|
||||
|
||||
if (blank($size)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_string($size)) {
|
||||
$size = TextSize::tryFrom($size) ?? $size;
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$size = $this->getSize();
|
||||
|
||||
$attributes = $this->getExtraAttributeBag()
|
||||
->grid($this->getColumns(), GridDirection::Column)
|
||||
->class([
|
||||
'fi-sc-unordered-list',
|
||||
($size instanceof TextSize) ? "fi-size-{$size->value}" : $size,
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<ul <?= $attributes->toHtml() ?>>
|
||||
<?php foreach ($this->getChildSchema()->getComponents() as $schemaComponent) { ?>
|
||||
<li><?= $schemaComponent->toHtml() ?></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
192
vendor/filament/schemas/src/Components/Utilities/Get.php
vendored
Normal file
192
vendor/filament/schemas/src/Components/Utilities/Get.php
vendored
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Utilities;
|
||||
|
||||
use BackedEnum;
|
||||
use Carbon\CarbonInterface;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class Get
|
||||
{
|
||||
/**
|
||||
* @var array<Component>
|
||||
*/
|
||||
protected static array $skipComponentsChildContainersWhileSearching = [];
|
||||
|
||||
protected bool $shouldSkipComponentsChildContainersWhileSearching = true;
|
||||
|
||||
public function __construct(
|
||||
protected Component $component,
|
||||
) {}
|
||||
|
||||
public function __invoke(string | Component $path = '', bool $isAbsolute = false): mixed
|
||||
{
|
||||
$livewire = $this->component->getLivewire();
|
||||
|
||||
$path = $this->component->resolveRelativeStatePath($path, $isAbsolute);
|
||||
|
||||
static::$skipComponentsChildContainersWhileSearching[] = $this->component;
|
||||
|
||||
$component = ($this->component->getStatePath() === $path)
|
||||
? $this->component
|
||||
: $this->component->getRootContainer()->getComponentByStatePath(
|
||||
$path,
|
||||
withHidden: true,
|
||||
withAbsoluteStatePath: true,
|
||||
skipComponentsChildContainersWhileSearching: $this->shouldSkipComponentsChildContainersWhileSearching ? static::$skipComponentsChildContainersWhileSearching : [],
|
||||
);
|
||||
|
||||
try {
|
||||
if (! $component) {
|
||||
return data_get($livewire, $path);
|
||||
}
|
||||
|
||||
return $component->getState();
|
||||
} finally {
|
||||
array_pop(static::$skipComponentsChildContainersWhileSearching);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TNullable of bool
|
||||
*
|
||||
* @param TNullable $isNullable
|
||||
* @return (TNullable is true ? ?string : string)
|
||||
*/
|
||||
public function string(string $key, bool $isNullable = false, bool $isAbsolute = false): ?string
|
||||
{
|
||||
$state = $this($key, $isAbsolute);
|
||||
|
||||
if ($isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TNullable of bool
|
||||
*
|
||||
* @param TNullable $isNullable
|
||||
* @return (TNullable is true ? ?int : int)
|
||||
*/
|
||||
public function integer(string $key, bool $isNullable = false, bool $isAbsolute = false): ?int
|
||||
{
|
||||
$state = $this($key, $isAbsolute);
|
||||
|
||||
if ($isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TNullable of bool
|
||||
*
|
||||
* @param TNullable $isNullable
|
||||
* @return (TNullable is true ? ?float : float)
|
||||
*/
|
||||
public function float(string $key, bool $isNullable = false, bool $isAbsolute = false): ?float
|
||||
{
|
||||
$state = $this($key, $isAbsolute);
|
||||
|
||||
if ($isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (float) $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TNullable of bool
|
||||
*
|
||||
* @param TNullable $isNullable
|
||||
* @return (TNullable is true ? ?bool : bool)
|
||||
*/
|
||||
public function boolean(string $key, bool $isNullable = false, bool $isAbsolute = false): ?bool
|
||||
{
|
||||
$state = $this($key, $isAbsolute);
|
||||
|
||||
if ($isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (bool) $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TNullable of bool
|
||||
*
|
||||
* @param TNullable $isNullable
|
||||
* @return (TNullable is true ? ?array<mixed, mixed> : array<mixed, mixed>)
|
||||
*/
|
||||
public function array(string $key, bool $isNullable = false, bool $isAbsolute = false): ?array
|
||||
{
|
||||
$state = $this($key, $isAbsolute);
|
||||
|
||||
if ($isNullable && (! is_array($state))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (array) ($state ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TNullable of bool
|
||||
*
|
||||
* @param TNullable $isNullable
|
||||
* @return (TNullable is true ? ?CarbonInterface : CarbonInterface)
|
||||
*/
|
||||
public function date(string $key, bool $isNullable = false, bool $isAbsolute = false): ?CarbonInterface
|
||||
{
|
||||
$state = $this($key, $isAbsolute);
|
||||
|
||||
if ($isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Carbon::parse($state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T of BackedEnum
|
||||
* @template TNullable of bool
|
||||
*
|
||||
* @param class-string<T> $enumClass
|
||||
* @param TNullable $isNullable
|
||||
* @return (TNullable is true ? T|null : T)
|
||||
*/
|
||||
public function enum(string $key, string $enumClass, bool $isNullable = false, bool $isAbsolute = false): ?BackedEnum
|
||||
{
|
||||
$state = $this($key, $isAbsolute);
|
||||
|
||||
if ($isNullable && blank($state)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($state instanceof BackedEnum) {
|
||||
return $state;
|
||||
}
|
||||
|
||||
return $enumClass::tryFrom($state);
|
||||
}
|
||||
|
||||
public function filled(string $key, bool $isAbsolute = false): bool
|
||||
{
|
||||
return filled($this($key, $isAbsolute));
|
||||
}
|
||||
|
||||
public function blank(string $key, bool $isAbsolute = false): bool
|
||||
{
|
||||
return blank($this($key, $isAbsolute));
|
||||
}
|
||||
|
||||
public function skipComponentsChildContainersWhileSearching(bool $condition = true): static
|
||||
{
|
||||
$this->shouldSkipComponentsChildContainersWhileSearching = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
50
vendor/filament/schemas/src/Components/Utilities/Set.php
vendored
Normal file
50
vendor/filament/schemas/src/Components/Utilities/Set.php
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Utilities;
|
||||
|
||||
use Filament\Schemas\Components\Component;
|
||||
|
||||
class Set
|
||||
{
|
||||
protected bool $shouldSkipComponentsChildContainersWhileSearching = true;
|
||||
|
||||
public function __construct(
|
||||
protected Component $component,
|
||||
) {}
|
||||
|
||||
public function __invoke(string | Component $path, mixed $state, bool $isAbsolute = false, bool $shouldCallUpdatedHooks = false): mixed
|
||||
{
|
||||
$livewire = $this->component->getLivewire();
|
||||
|
||||
$path = $this->component->resolveRelativeStatePath($path, $isAbsolute);
|
||||
|
||||
$component = ($this->component->getStatePath() === $path)
|
||||
? $this->component
|
||||
: $this->component->getRootContainer()->getComponentByStatePath(
|
||||
$path,
|
||||
withHidden: true,
|
||||
withAbsoluteStatePath: true,
|
||||
skipComponentsChildContainersWhileSearching: $this->shouldSkipComponentsChildContainersWhileSearching ? [$this->component] : [],
|
||||
);
|
||||
|
||||
$state = $this->component->evaluate($state);
|
||||
|
||||
if ($component) {
|
||||
$component->state($state);
|
||||
$shouldCallUpdatedHooks && $component->callAfterStateUpdated();
|
||||
} else {
|
||||
data_set($livewire, $path, $state);
|
||||
|
||||
$this->component->getRootContainer()->clearCachedChildSchemas();
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
public function skipComponentsChildContainersWhileSearching(bool $condition = true): static
|
||||
{
|
||||
$this->shouldSkipComponentsChildContainersWhileSearching = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
25
vendor/filament/schemas/src/Components/View.php
vendored
Normal file
25
vendor/filament/schemas/src/Components/View.php
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
class View extends Component
|
||||
{
|
||||
/**
|
||||
* @param view-string $view
|
||||
*/
|
||||
final public function __construct(string $view)
|
||||
{
|
||||
$this->view($view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param view-string $view
|
||||
*/
|
||||
public static function make(string $view): static
|
||||
{
|
||||
$static = app(static::class, ['view' => $view]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
}
|
||||
547
vendor/filament/schemas/src/Components/Wizard.php
vendored
Normal file
547
vendor/filament/schemas/src/Components/Wizard.php
vendored
Normal file
|
|
@ -0,0 +1,547 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Schemas\Components\Concerns\HasLabel;
|
||||
use Filament\Schemas\Components\Wizard\Step;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Schemas\View\SchemaIconAlias;
|
||||
use Filament\Support\Components\Attributes\ExposedLivewireMethod;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\Concerns;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Support\Enums\IconSize;
|
||||
use Filament\Support\Exceptions\Halt;
|
||||
use Filament\Support\Facades\FilamentAsset;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component as LivewireComponent;
|
||||
|
||||
use function Filament\Support\generate_icon_html;
|
||||
|
||||
class Wizard extends Component implements HasEmbeddedView
|
||||
{
|
||||
use Concerns\CanBeContained;
|
||||
use Concerns\HasExtraAlpineAttributes;
|
||||
use HasLabel;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.wizard';
|
||||
|
||||
protected string | Htmlable | null $cancelAction = null;
|
||||
|
||||
protected bool | Closure $isSkippable = false;
|
||||
|
||||
protected string | Closure | null $stepQueryStringKey = null;
|
||||
|
||||
protected string | Htmlable | null $submitAction = null;
|
||||
|
||||
protected ?Closure $modifyNextActionUsing = null;
|
||||
|
||||
protected ?Closure $modifyPreviousActionUsing = null;
|
||||
|
||||
protected int | Closure $startStep = 1;
|
||||
|
||||
protected ?int $currentStepIndex = null;
|
||||
|
||||
protected string | Closure | null $alpineSubmitHandler = null;
|
||||
|
||||
protected bool | Closure $isHeaderHidden = false;
|
||||
|
||||
/**
|
||||
* @param array<Step> | Closure $steps
|
||||
*/
|
||||
final public function __construct(array | Closure $steps = [])
|
||||
{
|
||||
$this->steps($steps);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Step> | Closure $steps
|
||||
*/
|
||||
public static function make(array | Closure $steps = []): static
|
||||
{
|
||||
$static = app(static::class, ['steps' => $steps]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->key(function (Wizard $component): string {
|
||||
$statePath = $component->getStatePath();
|
||||
$label = $component->getLabel();
|
||||
|
||||
if (blank($label)) {
|
||||
return filled($statePath) ? "{$statePath}::wizard" : 'wizard';
|
||||
}
|
||||
|
||||
return Str::slug(Str::transliterate($label, strict: true)) . '::' . (filled($statePath) ? "{$statePath}::wizard" : 'wizard');
|
||||
}, isInheritable: false);
|
||||
|
||||
$this->registerActions([
|
||||
fn (Wizard $component): Action => $component->getNextAction(),
|
||||
fn (Wizard $component): Action => $component->getPreviousAction(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[ExposedLivewireMethod]
|
||||
public function nextStep(int $currentStepIndex): void
|
||||
{
|
||||
if (! $this->isSkippable()) {
|
||||
$steps = array_values(
|
||||
$this
|
||||
->getChildSchema()
|
||||
->getComponents()
|
||||
);
|
||||
|
||||
/** @var Step $currentStep */
|
||||
$currentStep = $steps[$currentStepIndex];
|
||||
|
||||
/** @var ?Step $nextStep */
|
||||
$nextStep = $steps[$currentStepIndex + 1] ?? null;
|
||||
$this->currentStepIndex($currentStepIndex + 1);
|
||||
|
||||
try {
|
||||
$currentStep->callBeforeValidation();
|
||||
$currentStep->getChildSchema()->validate();
|
||||
$currentStep->callAfterValidation();
|
||||
$nextStep?->fillStateWithNull();
|
||||
} catch (Halt $exception) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/** @var HasSchemas&LivewireComponent $livewire */
|
||||
$livewire = $this->getLivewire();
|
||||
$livewire->dispatch('next-wizard-step', key: $this->getKey());
|
||||
}
|
||||
|
||||
#[ExposedLivewireMethod]
|
||||
public function previousStep(int $currentStepIndex): void
|
||||
{
|
||||
if ($currentStepIndex < 1) {
|
||||
$currentStepIndex = 1;
|
||||
}
|
||||
|
||||
$this->currentStepIndex($currentStepIndex - 1);
|
||||
}
|
||||
|
||||
public function goToStep(string $step): void
|
||||
{
|
||||
$steps = array_values(
|
||||
$this->getChildSchema()->getComponents()
|
||||
);
|
||||
|
||||
foreach ($steps as $index => $wizardStep) {
|
||||
if ($wizardStep->getKey() !== $step) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((! $this->isSkippable()) && ($index > $this->getCurrentStepIndex())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->currentStepIndex($index);
|
||||
|
||||
/** @var HasSchemas&LivewireComponent $livewire */
|
||||
$livewire = $this->getLivewire();
|
||||
|
||||
$livewire->dispatch(
|
||||
'go-to-wizard-step',
|
||||
key: $this->getKey(),
|
||||
step: $step,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public function getNextAction(): Action
|
||||
{
|
||||
$action = Action::make($this->getNextActionName())
|
||||
->label(__('filament-schemas::components.wizard.actions.next_step.label'))
|
||||
->iconPosition(IconPosition::After)
|
||||
->livewireClickHandlerEnabled(false)
|
||||
->livewireTarget('callSchemaComponentMethod')
|
||||
->button();
|
||||
|
||||
if ($this->modifyNextActionUsing) {
|
||||
$action = $this->evaluate($this->modifyNextActionUsing, [
|
||||
'action' => $action,
|
||||
]) ?? $action;
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
public function nextAction(?Closure $callback): static
|
||||
{
|
||||
$this->modifyNextActionUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNextActionName(): string
|
||||
{
|
||||
return 'next';
|
||||
}
|
||||
|
||||
public function getPreviousAction(): Action
|
||||
{
|
||||
$action = Action::make($this->getPreviousActionName())
|
||||
->label(__('filament-schemas::components.wizard.actions.previous_step.label'))
|
||||
->color('gray')
|
||||
->livewireClickHandlerEnabled(false)
|
||||
->button();
|
||||
|
||||
if ($this->modifyPreviousActionUsing) {
|
||||
$action = $this->evaluate($this->modifyPreviousActionUsing, [
|
||||
'action' => $action,
|
||||
]) ?? $action;
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
public function previousAction(?Closure $callback): static
|
||||
{
|
||||
$this->modifyPreviousActionUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPreviousActionName(): string
|
||||
{
|
||||
return 'previous';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Step> | Closure $steps
|
||||
*/
|
||||
public function steps(array | Closure $steps): static
|
||||
{
|
||||
$this->components($steps);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function startOnStep(int | Closure $startStep): static
|
||||
{
|
||||
$this->startStep = $startStep;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function cancelAction(string | Htmlable | null $action): static
|
||||
{
|
||||
$this->cancelAction = $action;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function submitAction(string | Htmlable | null $action): static
|
||||
{
|
||||
$this->submitAction = $action;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function skippable(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isSkippable = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function persistStepInQueryString(string | Closure | null $key = 'step'): static
|
||||
{
|
||||
$this->stepQueryStringKey = $key;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCancelAction(): string | Htmlable | null
|
||||
{
|
||||
return $this->cancelAction;
|
||||
}
|
||||
|
||||
public function getSubmitAction(): string | Htmlable | null
|
||||
{
|
||||
return $this->submitAction;
|
||||
}
|
||||
|
||||
public function getStartStep(): int
|
||||
{
|
||||
if ($this->isStepPersistedInQueryString()) {
|
||||
$queryStringStep = request()->query($this->getStepQueryStringKey());
|
||||
|
||||
foreach ($this->getChildSchema()->getComponents() as $index => $step) {
|
||||
if ($step->getId() !== $queryStringStep) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $index + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->evaluate($this->startStep);
|
||||
}
|
||||
|
||||
public function getStepQueryStringKey(): ?string
|
||||
{
|
||||
return $this->evaluate($this->stepQueryStringKey);
|
||||
}
|
||||
|
||||
public function isSkippable(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isSkippable);
|
||||
}
|
||||
|
||||
public function isStepPersistedInQueryString(): bool
|
||||
{
|
||||
return filled($this->getStepQueryStringKey());
|
||||
}
|
||||
|
||||
public function getCurrentStepIndex(): int
|
||||
{
|
||||
return $this->currentStepIndex ??= ($this->getStartStep() - 1);
|
||||
}
|
||||
|
||||
protected function currentStepIndex(int $index): static
|
||||
{
|
||||
$this->currentStepIndex = $index;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function alpineSubmitHandler(string | Closure | null $handler): static
|
||||
{
|
||||
$this->alpineSubmitHandler = $handler;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAlpineSubmitHandler(): ?string
|
||||
{
|
||||
return $this->evaluate($this->alpineSubmitHandler);
|
||||
}
|
||||
|
||||
public function hiddenHeader(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isHeaderHidden = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isHeaderHidden(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isHeaderHidden);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$isContained = $this->isContained();
|
||||
$key = $this->getKey();
|
||||
$previousAction = $this->getAction('previous');
|
||||
$nextAction = $this->getAction('next');
|
||||
$steps = array_filter(
|
||||
$this->getChildSchema()->getComponents(),
|
||||
static fn ($component): bool => $component instanceof Step,
|
||||
);
|
||||
|
||||
if (
|
||||
(count($steps) > 1) &&
|
||||
($nextAction->getLivewireTarget() === 'callSchemaComponentMethod')
|
||||
) {
|
||||
$nextActionLivewireTargetKey = Js::from($key)->toHtml();
|
||||
|
||||
$nextAction->livewireTarget(
|
||||
collect(range(0, count($steps) - 2))
|
||||
->map(static fn (int $stepIndex): string => "callSchemaComponentMethod({$nextActionLivewireTargetKey}, 'nextStep', " . Js::from([
|
||||
'currentStepIndex' => $stepIndex,
|
||||
])->toHtml() . ')')
|
||||
->implode(', '),
|
||||
);
|
||||
}
|
||||
|
||||
$isHeaderHidden = $this->isHeaderHidden();
|
||||
|
||||
$outerAttributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
'id' => $this->getId(),
|
||||
], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->merge($this->getExtraAlpineAttributes(), escape: false)
|
||||
->class([
|
||||
'fi-sc-wizard',
|
||||
'fi-contained' => $isContained,
|
||||
'fi-sc-wizard-header-hidden' => $isHeaderHidden,
|
||||
]);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div
|
||||
x-load
|
||||
x-load-src="<?= e(FilamentAsset::getAlpineComponentSrc('wizard', 'filament/schemas')) ?>"
|
||||
x-data="wizardSchemaComponent({
|
||||
isSkippable: <?= Js::from($this->isSkippable()) ?>,
|
||||
isStepPersistedInQueryString: <?= Js::from($this->isStepPersistedInQueryString()) ?>,
|
||||
key: <?= Js::from($key) ?>,
|
||||
livewireId: <?= Js::from($this->getLivewire()->getId()) ?>,
|
||||
schemaKey: <?= Js::from($this->getRootContainer()->getKey()) ?>,
|
||||
startStep: <?= Js::from($this->getStartStep()) ?>,
|
||||
stepQueryStringKey: <?= Js::from($this->getStepQueryStringKey()) ?>,
|
||||
})"
|
||||
x-on:next-wizard-step.window="if ($event.detail.key === <?= Js::from($key) ?>) goToNextStep()"
|
||||
x-on:go-to-wizard-step.window="$event.detail.key === <?= Js::from($key) ?> && goToStep($event.detail.step)"
|
||||
wire:ignore.self
|
||||
<?= $outerAttributes->toHtml() ?>
|
||||
>
|
||||
<input
|
||||
type="hidden"
|
||||
value="<?= e(collect($steps)
|
||||
->filter(static fn (Step $step): bool => $step->isVisible())
|
||||
->map(static fn (Step $step): ?string => $step->getKey())
|
||||
->values()
|
||||
->toJson()) ?>"
|
||||
x-ref="stepsData"
|
||||
/>
|
||||
|
||||
<?php if (! $isHeaderHidden) { ?>
|
||||
<ol
|
||||
<?php if (filled($label = $this->getLabel())) { ?>
|
||||
aria-label="<?= e($label) ?>"
|
||||
<?php } ?>
|
||||
role="list"
|
||||
x-cloak
|
||||
x-ref="header"
|
||||
class="fi-sc-wizard-header"
|
||||
>
|
||||
<?php $stepIndex = 0; ?>
|
||||
<?php $stepCount = count($steps); ?>
|
||||
<?php foreach ($steps as $step) { ?>
|
||||
<li
|
||||
class="fi-sc-wizard-header-step"
|
||||
x-bind:class="{
|
||||
'fi-active': getStepIndex(step) === <?= $stepIndex ?>,
|
||||
'fi-completed': getStepIndex(step) > <?= $stepIndex ?>,
|
||||
}"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
<?php if (filled($stepId = $step->getId())) { ?>
|
||||
id="<?= e($stepId) ?>-tab"
|
||||
aria-controls="<?= e($stepId) ?>"
|
||||
<?php } ?>
|
||||
x-bind:aria-current="getStepIndex(step) === <?= $stepIndex ?> ? 'step' : null"
|
||||
x-on:click="step = <?= Js::from($step->getKey()) ?>"
|
||||
x-bind:disabled="! isStepAccessible(<?= Js::from($step->getKey()) ?>) || <?= Js::from($previousAction->isDisabled()) ?>"
|
||||
class="fi-sc-wizard-header-step-btn"
|
||||
>
|
||||
<div class="fi-sc-wizard-header-step-icon-ctn">
|
||||
<?php $completedIcon = $step->getCompletedIcon(); ?>
|
||||
|
||||
<?= generate_icon_html(
|
||||
$completedIcon ?? Heroicon::OutlinedCheck,
|
||||
alias: filled($completedIcon) ? null : SchemaIconAlias::COMPONENTS_WIZARD_COMPLETED_STEP,
|
||||
attributes: new FilamentComponentAttributeBag([
|
||||
'x-cloak' => 'x-cloak',
|
||||
'x-show' => "getStepIndex(step) > {$stepIndex}",
|
||||
]),
|
||||
size: IconSize::Large,
|
||||
)?->toHtml() ?>
|
||||
|
||||
<?php if (filled($icon = $step->getIcon())) { ?>
|
||||
<?= generate_icon_html(
|
||||
$icon,
|
||||
attributes: new FilamentComponentAttributeBag([
|
||||
'x-cloak' => 'x-cloak',
|
||||
'x-show' => "getStepIndex(step) <= {$stepIndex}",
|
||||
]),
|
||||
size: IconSize::Large,
|
||||
)?->toHtml() ?>
|
||||
<?php } else { ?>
|
||||
<span
|
||||
x-show="getStepIndex(step) <= <?= $stepIndex ?>"
|
||||
aria-hidden="true"
|
||||
class="fi-sc-wizard-header-step-number"
|
||||
>
|
||||
<?= str_pad((string) ($stepIndex + 1), 2, '0', STR_PAD_LEFT) ?>
|
||||
</span>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<div class="fi-sc-wizard-header-step-text">
|
||||
<?php // Always render the label so the button (and the panel it labels via `aria-labelledby`) keeps an accessible name; visually hide it when `hiddenLabel()` is set.?>
|
||||
<span class="fi-sc-wizard-header-step-label<?= $step->isLabelHidden() ? ' fi-sr-only' : '' ?>"><?= e($step->getLabel()) ?></span>
|
||||
|
||||
<?php if (filled($description = $step->getDescription())) { ?>
|
||||
<span class="fi-sc-wizard-header-step-description"><?= e($description) ?></span>
|
||||
<?php } ?>
|
||||
|
||||
<?php // Announce completed/upcoming state to screen readers. The current step is owned by `aria-current="step"`, so its status text stays empty to avoid a redundant, doubly-announced name.?>
|
||||
<span
|
||||
class="fi-sr-only"
|
||||
x-text="getStepIndex(step) > <?= $stepIndex ?> ? <?= Js::from(__('filament-schemas::components.wizard.header.step.statuses.completed')) ?> : (getStepIndex(step) === <?= $stepIndex ?> ? '' : <?= Js::from(__('filament-schemas::components.wizard.header.step.statuses.upcoming')) ?>)"
|
||||
></span>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<?php if ($stepIndex < $stepCount - 1) { ?>
|
||||
<svg fill="none" preserveAspectRatio="none" viewBox="0 0 22 80" aria-hidden="true" class="fi-sc-wizard-header-step-separator">
|
||||
<path d="M0 -2L20 40L0 82" stroke-linejoin="round" stroke="currentcolor" vector-effect="non-scaling-stroke"></path>
|
||||
</svg>
|
||||
<?php } ?>
|
||||
</li>
|
||||
<?php $stepIndex++; ?>
|
||||
<?php } ?>
|
||||
</ol>
|
||||
<?php } ?>
|
||||
|
||||
<?php foreach ($steps as $step) { ?>
|
||||
<?= $step->toHtml() ?>
|
||||
<?php } ?>
|
||||
|
||||
<div x-cloak class="fi-sc-wizard-footer">
|
||||
<div
|
||||
x-cloak
|
||||
<?php if (! $previousAction->isDisabled()) { ?>
|
||||
x-on:click="goToPreviousStep"
|
||||
<?php } ?>
|
||||
x-show="! isFirstStep()"
|
||||
>
|
||||
<?= $previousAction->toHtml() ?>
|
||||
</div>
|
||||
|
||||
<div x-show="isFirstStep()">
|
||||
<?= e($this->getCancelAction()) ?>
|
||||
</div>
|
||||
|
||||
<div
|
||||
x-cloak
|
||||
<?php if (! $nextAction->isDisabled()) { ?>
|
||||
x-on:click="requestNextStep()"
|
||||
<?php } ?>
|
||||
x-bind:class="{ 'fi-hidden': isLastStep() }"
|
||||
wire:loading.attr="inert"
|
||||
>
|
||||
<?= $nextAction->toHtml() ?>
|
||||
</div>
|
||||
|
||||
<div x-bind:class="{ 'fi-hidden': ! isLastStep() }">
|
||||
<?= e($this->getSubmitAction()) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
215
vendor/filament/schemas/src/Components/Wizard/Step.php
vendored
Normal file
215
vendor/filament/schemas/src/Components/Wizard/Step.php
vendored
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Schemas\Components\Wizard;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Schemas\Components\Component;
|
||||
use Filament\Schemas\Components\Concerns\HasLabel;
|
||||
use Filament\Schemas\Components\Wizard;
|
||||
use Filament\Support\Components\Contracts\HasEmbeddedView;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Js;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Step extends Component implements HasEmbeddedView
|
||||
{
|
||||
use HasLabel;
|
||||
|
||||
protected ?string $publishedViewOverrideCheckPath = 'filament-schemas::components.wizard.step';
|
||||
|
||||
protected ?Closure $afterValidation = null;
|
||||
|
||||
protected ?Closure $beforeValidation = null;
|
||||
|
||||
protected string | Closure | null $description = null;
|
||||
|
||||
protected string | BackedEnum | Htmlable | Closure | null $icon = null;
|
||||
|
||||
protected string | BackedEnum | Htmlable | Closure | null $completedIcon = null;
|
||||
|
||||
protected bool | Closure $hasFormWrapper = true;
|
||||
|
||||
final public function __construct(string $label)
|
||||
{
|
||||
$this->label($label);
|
||||
}
|
||||
|
||||
public static function make(string $label): static
|
||||
{
|
||||
$static = app(static::class, ['label' => $label]);
|
||||
$static->configure();
|
||||
|
||||
return $static;
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->key(function (Step $component): string {
|
||||
$label = $component->getLabel();
|
||||
$statePath = $component->getStatePath();
|
||||
|
||||
return Str::slug(Str::transliterate($label, strict: true)) . '::' . (filled($statePath) ? "{$statePath}::wizard-step" : 'wizard-step');
|
||||
}, isInheritable: false);
|
||||
}
|
||||
|
||||
public function afterValidation(?Closure $callback): static
|
||||
{
|
||||
$this->afterValidation = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `afterValidation()` instead.
|
||||
*/
|
||||
public function afterValidated(?Closure $callback): static
|
||||
{
|
||||
$this->afterValidation($callback);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function beforeValidation(?Closure $callback): static
|
||||
{
|
||||
$this->beforeValidation = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function description(string | Closure | null $description): static
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function icon(string | BackedEnum | Htmlable | Closure | null $icon): static
|
||||
{
|
||||
$this->icon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function completedIcon(string | BackedEnum | Htmlable | Closure | null $icon): static
|
||||
{
|
||||
$this->completedIcon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function callAfterValidation(): void
|
||||
{
|
||||
$this->evaluate($this->afterValidation);
|
||||
}
|
||||
|
||||
public function callBeforeValidation(): void
|
||||
{
|
||||
$this->evaluate($this->beforeValidation);
|
||||
}
|
||||
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->evaluate($this->description);
|
||||
}
|
||||
|
||||
public function getIcon(): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->icon);
|
||||
}
|
||||
|
||||
public function getCompletedIcon(): string | BackedEnum | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->completedIcon);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int | null>
|
||||
*/
|
||||
public function getAllColumns(): array
|
||||
{
|
||||
if ($this->columns === null) {
|
||||
return $this->getContainer()->getAllColumns();
|
||||
}
|
||||
|
||||
return parent::getAllColumns();
|
||||
}
|
||||
|
||||
public function formWrapper(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->hasFormWrapper = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasFormWrapper(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->hasFormWrapper);
|
||||
}
|
||||
|
||||
public function toEmbeddedHtml(): string
|
||||
{
|
||||
$id = $this->getId();
|
||||
$key = $this->getKey();
|
||||
/** @var Wizard $wizard */
|
||||
$wizard = $this->getContainer()->getParentComponent();
|
||||
$alpineSubmitHandler = $this->hasFormWrapper() ? $wizard->getAlpineSubmitHandler() : null;
|
||||
|
||||
$tag = filled($alpineSubmitHandler) ? 'form' : 'div';
|
||||
|
||||
// The header button carrying `id="{$id}-tab"` only renders when the wizard header is shown, so a
|
||||
// `hiddenHeader()` wizard has no such element — reference it only when it exists, otherwise the
|
||||
// `role="group"` panel would point `aria-labelledby` at a nonexistent id and lose its name.
|
||||
$hasHeaderReference = filled($id) && ! $wizard->isHeaderHidden();
|
||||
|
||||
$label = $this->getLabel();
|
||||
$labelText = $label instanceof Htmlable ? strip_tags($label->toHtml()) : $label;
|
||||
|
||||
$attributes = (new FilamentComponentAttributeBag)
|
||||
->merge([
|
||||
// Name the panel by its header button (`{id}-tab`) rather than itself. The header is an `<ol>`
|
||||
// stepper of plain buttons with `aria-current="step"`, not a `tablist` of `role="tab"` controls,
|
||||
// so `role="tabpanel"` (which implies an owning tab) is incoherent — `role="group"` is honest.
|
||||
// When the header is hidden, fall back to the step's own label so the panel keeps a name.
|
||||
'aria-labelledby' => $hasHeaderReference ? "{$id}-tab" : null,
|
||||
'aria-label' => (! $hasHeaderReference && filled($labelText)) ? e($labelText) : null,
|
||||
'id' => $id,
|
||||
'role' => 'group',
|
||||
], escape: false)
|
||||
->merge($this->getExtraAttributes(), escape: false)
|
||||
->class(['fi-sc-wizard-step']);
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<<?= $tag ?>
|
||||
x-bind:tabindex="$el.querySelector('[autofocus]') ? '-1' : '0'"
|
||||
x-bind:class="{
|
||||
'fi-active': step === <?= Js::from($key) ?>,
|
||||
}"
|
||||
x-on:expand="
|
||||
if (! isStepAccessible(<?= Js::from($key) ?>)) {
|
||||
return
|
||||
}
|
||||
|
||||
step = <?= Js::from($key) ?>
|
||||
"
|
||||
<?php if (filled($alpineSubmitHandler)) { ?>
|
||||
x-on:submit.prevent="isLastStep() ? <?= $alpineSubmitHandler ?> : requestNextStep()"
|
||||
<?php } ?>
|
||||
x-cloak
|
||||
x-ref="step-<?= e($key) ?>"
|
||||
<?= $attributes->toHtml() ?>
|
||||
>
|
||||
<?= $this->getChildSchema()->toHtml() ?>
|
||||
|
||||
<?php if (filled($alpineSubmitHandler)) { ?>
|
||||
<input type="submit" hidden />
|
||||
<?php } ?>
|
||||
</<?= $tag ?>>
|
||||
|
||||
<?php return ob_get_clean();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue