block editor
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema;
|
||||
|
||||
use Lucent\Primitive\Collection;
|
||||
|
||||
class BlockSchema implements Schema
|
||||
{
|
||||
|
||||
public Type $type = Type::BLOCK;
|
||||
|
||||
/**
|
||||
* @param Collection<FieldInterface> $fields
|
||||
*/
|
||||
function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public Collection $fields
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
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 = [],
|
||||
)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
use Lucent\Schema\FieldInfo;
|
||||
use Lucent\Schema\FieldInterface;
|
||||
use Lucent\Schema\FieldType;
|
||||
use Lucent\Schema\Nullable;
|
||||
use Lucent\Schema\Validator\RequiredInterface;
|
||||
|
||||
class Heading implements FieldInterface
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public string $default = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("heading", "Heading", FieldType::STRING);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$output[$this->name] = $input[$this->name] ?? "";
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
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 ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public array $collections = [],
|
||||
public string $searchField = "",
|
||||
public string $layout = "",
|
||||
)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Schema\BlockUi;
|
||||
|
||||
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
|
||||
{
|
||||
public FieldInfo $info;
|
||||
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $label,
|
||||
public ?int $min = null,
|
||||
public ?int $max = null,
|
||||
public string $default = "",
|
||||
)
|
||||
{
|
||||
$this->info = new FieldInfo("textarea", "Textarea", FieldType::STRING);
|
||||
}
|
||||
|
||||
public function format(array $input, array $output): array
|
||||
{
|
||||
$output[$this->name] = $input[$this->name] ?? "";
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,11 @@ class SchemaService
|
||||
isEntry: $schemaArr["isEntry"] ?? false,
|
||||
color: $schemaArr["color"] ?? "",
|
||||
titleTemplate: $schemaArr["titleTemplate"] ?? "",
|
||||
),
|
||||
"block" => new BlockSchema(
|
||||
name: $schemaArr["name"],
|
||||
label: $schemaArr["label"],
|
||||
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapBlockFields'])
|
||||
)
|
||||
};
|
||||
|
||||
@@ -47,6 +52,13 @@ class SchemaService
|
||||
return new $className(...$field);
|
||||
}
|
||||
|
||||
public function mapBlockFields(array $field): FieldInterface
|
||||
{
|
||||
$className = "\\Lucent\Schema\BlockUi\\" . ucfirst($field["ui"]);
|
||||
unset($field["ui"]);
|
||||
return new $className(...$field);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// /**
|
||||
|
||||
@@ -7,4 +7,5 @@ enum Type: string
|
||||
{
|
||||
case COLLECTION = 'collection';
|
||||
case FILES = 'files';
|
||||
case BLOCK = 'block';
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ class Block implements FieldInterface, RequiredInterface
|
||||
public bool $required = false,
|
||||
public string $default = "",
|
||||
public bool $readonly = false,
|
||||
public string $schema = "",
|
||||
public string $group = "",
|
||||
)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />
|
||||
<script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||
|
||||
</head>
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<title>@yield('title') - Lucent Data Platform</title>
|
||||
<!-- if development -->
|
||||
{{-- @php--}}
|
||||
{{-- echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';--}}
|
||||
{{-- @endphp--}}
|
||||
{{-- <script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>--}}
|
||||
@php
|
||||
echo '<script type="module" crossorigin src="http://127.0.0.1:5173/@vite/client"></script>';
|
||||
@endphp
|
||||
<script type="module" crossorigin src="http://127.0.0.1:5173/main.js"></script>
|
||||
<!-- if production -->
|
||||
<link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />
|
||||
<script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>
|
||||
{{-- <link rel="stylesheet" href="/vendor/lucent/dist/{{ $manifest['main.css']["file"] }}" />--}}
|
||||
{{-- <script type="module" src="/vendor/lucent/dist/{{ $manifest['main.js']["file"] }}"></script>--}}
|
||||
|
||||
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico">
|
||||
|
||||
Reference in New Issue
Block a user