This commit is contained in:
2023-10-02 23:10:49 +03:00
commit c6cb488379
255 changed files with 18731 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
class Block implements FieldInterface, RequiredInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
public bool $nullable = false,
public bool $required = false,
public string $default = "",
public bool $readonly = false,
public string $group = "",
)
{
$this->info = new FieldInfo("block", "Block editor", FieldType::JSON);
}
public function format(array $input, array $output): array
{
$value = $input[$this->name] ?? null;
if (is_string($value)) {
$value = json_decode($value, true);
}
$output[$this->name] = (new Nullable($this->nullable, $value, []))->value();
return $output;
}
public function failRequired(mixed $value): bool
{
return empty($value);
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
use function is_bool;
class Checkbox implements FieldInterface, RequiredInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
public bool $required = false,
public bool $nullable = false,
public string $default = "",
public bool $readonly = false,
public string $group = "",
)
{
$this->info = new FieldInfo("checkbox", "Block Checkbox", FieldType::BOOLEAN);
}
public function format(array $input, array $output): array
{
$value = $input[$this->name] ?? null;
if (is_bool($value)) {
$newValue = $value;
} else {
$newValue = (new Nullable($this->nullable, $value, false))->value();
}
$output[$this->name] = $newValue;
return $output;
}
public function failRequired(mixed $value): bool
{
return (bool)$value !== true;
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
class Color implements FieldInterface, RequiredInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
public bool $required = false,
public bool $nullable = false,
public string $default = "",
public bool $readonly = false,
public string $optionsFrom = "",
public string $optionsField = "",
public bool $optionsSuggest = false,
public string $group = "",
)
{
$this->info = new FieldInfo("color", "Color", FieldType::STRING);
}
public function format(array $input, array $output): array
{
$value = $input[$this->name] ?? null;
$output[$this->name] = (new Nullable($this->nullable, $value, ""))->value();
return $output;
}
public function failRequired(mixed $value): bool
{
return empty(trim($value));
}
}
+73
View File
@@ -0,0 +1,73 @@
<?php
namespace Lucent\Schema\Ui;
use Carbon\Carbon;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\MinMaxInterface;
use Lucent\Schema\Validator\RequiredInterface;
class Date implements FieldInterface, RequiredInterface, MinMaxInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
public bool $required = false,
public bool $nullable = false,
public ?Carbon $min = null,
public ?Carbon $max = null,
public string $default = "",
public bool $readonly = false,
public string $optionsFrom = "",
public string $optionsField = "",
public bool $optionsSuggest = false,
public string $group = "",
)
{
$this->info = new FieldInfo("date", "Date", FieldType::STRING);
}
public function format(array $input, array $output): array
{
$value = $input[$this->name] ?? null;
if (empty($value)) {
$newValue = (new Nullable($this->nullable, null, ""))->value();
} else {
$date = Carbon::parse($value);
$dateFormatted = $date->format("Y-m-d");
$newValue = (new Nullable($this->nullable, $dateFormatted, ""))->value();
}
$output[$this->name] = $newValue;
return $output;
}
public function failRequired(mixed $value): bool
{
return empty(trim($value));
}
public function failMin(mixed $value): bool
{
if (empty($this->value)) {
return false;
}
return $value->lessThanOrEqualTo($this->min);
}
public function failMax(mixed $value): bool
{
if (empty($this->value)) {
return false;
}
return $value->greaterThan($this->max);
}
}
+73
View File
@@ -0,0 +1,73 @@
<?php
namespace Lucent\Schema\Ui;
use Carbon\Carbon;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\MinMaxInterface;
use Lucent\Schema\Validator\RequiredInterface;
class Datetime implements FieldInterface, RequiredInterface, MinMaxInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
public bool $required = false,
public bool $nullable = false,
public ?Carbon $min = null,
public ?Carbon $max = null,
public string $default = "",
public bool $readonly = false,
public string $optionsFrom = "",
public string $optionsField = "",
public bool $optionsSuggest = false,
public string $group = "",
)
{
$this->info = new FieldInfo("datetime", "Datetime", FieldType::STRING);
}
public function format(array $input, array $output): array
{
$value = $input[$this->name] ?? null;
if (empty($value)) {
$newValue = (new Nullable($this->nullable, null, ""))->value();
} else {
$date = Carbon::parse($value);
$dateFormatted = $date->toJSON();
$newValue = (new Nullable($this->nullable, $dateFormatted, ""))->value();
}
$output[$this->name] = $newValue;
return $output;
}
public function failRequired(mixed $value): bool
{
return empty(trim($value));
}
public function failMin(mixed $value): bool
{
if (empty($this->value)) {
return false;
}
return $value->lessThanOrEqualTo($this->min);
}
public function failMax(mixed $value): bool
{
if (empty($this->value)) {
return false;
}
return $value->greaterThan($this->max);
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Validator\MinMaxInterface;
class File implements FieldInterface, MinMaxInterface
{
public FieldInfo $info;
/**
* @param string[] $collections
*/
public function __construct(
public string $name,
public string $label,
public string $mime = "",
public ?int $min = null,
public ?int $max = null,
public array $collections = [],
public string $group = "",
)
{
$this->info = new FieldInfo("file", "File", FieldType::FILE);
}
public function format(array $input, array $output): array
{
return $output;
}
public function failMin(mixed $value): bool
{
if (is_null($value)) {
return false;
}
return count($value) < $this->min;
}
public function failMax(mixed $value): bool
{
if (is_null($value)) {
return false;
}
return count($value) < $this->min;
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
class Json implements FieldInterface, RequiredInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
public bool $required = false,
public string $default = "",
public bool $readonly = false,
public bool $nullable = false,
public string $group = "",
)
{
$this->info = new FieldInfo("json", "JSON", FieldType::JSON);
}
public function format(array $input, array $output): array
{
$value = $input[$this->name] ?? null;
if (is_string($value)) {
$value = json_decode($value, true);
}
$output[$this->name] = (new Nullable($this->nullable, $value, []))->value();
return $output;
}
public function failRequired(mixed $value): bool
{
return empty($value);
}
}
+77
View File
@@ -0,0 +1,77 @@
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\MinMaxInterface;
use Lucent\Schema\Validator\RequiredInterface;
class Number implements FieldInterface, RequiredInterface, MinMaxInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
public bool $required = false,
public bool $nullable = false,
public int $decimals = 0,
public ?int $min = null,
public ?int $max = null,
public ?float $default = null,
public bool $readonly = false,
public string $optionsFrom = "",
public string $optionsField = "",
public bool $optionsSuggest = false,
public string $group = "",
)
{
$this->info = new FieldInfo("number", "Number", FieldType::NUMBER);
}
public function format(array $input, array $output): array
{
$value = $input[$this->name] ?? null;
if (!is_numeric($value)) {
$newValue = null;
} else {
$newValue = number_format(
$value,
$this->decimals,
".",
""
);
$newValue = $this->decimals === 0 ? (int)$newValue : floatval($newValue);
}
$output[$this->name] = (new Nullable($this->nullable, $newValue, 0))->value();
return $output;
}
public function failRequired(mixed $value): bool
{
return is_null($value);
}
public function failMin(mixed $value): bool
{
if (is_null($value)) {
return false;
}
return $value < $this->min;
}
public function failMax(mixed $value): bool
{
if (is_null($value)) {
return false;
}
return $value > $this->min;
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Validator\MinMaxInterface;
class Reference implements FieldInterface, MinMaxInterface
{
public FieldInfo $info;
/**
* @param string[] $collections
*/
public function __construct(
public string $name,
public string $label,
public string $mime = "",
public ?int $min = null,
public ?int $max = null,
public array $collections = [],
public string $layout = "",
public string $group = "",
)
{
$this->info = new FieldInfo("reference", "Reference", FieldType::REFERENCE);
}
public function format(array $input, array $output): array
{
return $output;
}
public function failMin(mixed $value): bool
{
if (is_null($value)) {
return false;
}
return count($value) < $this->min;
}
public function failMax(mixed $value): bool
{
if (is_null($value)) {
return false;
}
return count($value) < $this->min;
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
class Rich implements FieldInterface, RequiredInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
public bool $required = false,
public bool $nullable = false,
public string $default = "",
public ?int $min = null,
public ?int $max = null,
public bool $readonly = false,
public string $group = "",
)
{
$this->info = new FieldInfo("rich", "Rich editor", FieldType::STRING);
}
public function format(array $input, array $output): array
{
$value = $input[$this->name] ?? null;
$output[$this->name] = (new Nullable($this->nullable, $value, ""))->value();
return $output;
}
public function failRequired(mixed $value): bool
{
return empty(trim($value));
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
class Text implements FieldInterface, RequiredInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
public bool $required = false,
public bool $nullable = false,
public ?int $min = null,
public ?int $max = null,
public string $default = "",
public bool $readonly = false,
public string $optionsFrom = "",
public string $optionsField = "",
public bool $optionsSuggest = false,
public string $group = "",
)
{
$this->info = new FieldInfo("text", "Text", FieldType::STRING);
}
public function format(array $input, array $output): array
{
$value = $input[$this->name] ?? null;
$output[$this->name] = (new Nullable($this->nullable, $value, ""))->value();
return $output;
}
public function failRequired(mixed $value): bool
{
return empty(trim($value));
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
class Textarea implements FieldInterface, RequiredInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
public bool $required = false,
public bool $nullable = false,
public ?int $min = null,
public ?int $max = null,
public string $default = "",
public bool $readonly = false,
public string $group = "",
)
{
$this->info = new FieldInfo("textarea", "Textarea", FieldType::STRING);
}
public function format(array $input, array $output): array
{
$value = $input[$this->name] ?? null;
$output[$this->name] = (new Nullable($this->nullable, $value, ""))->value();
return $output;
}
public function failRequired(mixed $value): bool
{
return empty(trim($value));
}
}
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace Lucent\Schema\Ui;
use Lucent\Schema\FieldInfo;
use Lucent\Schema\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
class Uuid implements FieldInterface, RequiredInterface
{
public FieldInfo $info;
public function __construct(
public string $name,
public string $label,
public bool $required = false,
public bool $nullable = false,
public bool $readonly = false,
public string $group = "",
)
{
$this->info = new FieldInfo("uuid", "FieldType", FieldType::STRING);
}
public function format(array $input, array $output): array
{
$value = $input[$this->name] ?? null;
$output[$this->name] = (new Nullable($this->nullable, $value, ""))->value();
return $output;
}
public function failRequired(mixed $value): bool
{
return empty(trim($value));
}
}