forked from laysense/laysite
Improve canvas layers, heading removal and component previews in 1.5.3
This commit is contained in:
@@ -8,7 +8,7 @@ use RuntimeException;
|
||||
|
||||
final class CanvasStyle
|
||||
{
|
||||
public const PAGE = ['hero', 'heading', 'accent', 'lead', 'eyebrow', 'image', 'actions', 'navigation', 'breadcrumbs'];
|
||||
public const PAGE = ['hero', 'hero-content', 'heading', 'accent', 'lead', 'eyebrow', 'image', 'actions', 'navigation', 'breadcrumbs'];
|
||||
public const MIN_MEDIA_SCALE = 1;
|
||||
public const SECTION = ['section', 'title', 'lead', 'body'];
|
||||
|
||||
@@ -55,6 +55,10 @@ final class CanvasStyle
|
||||
}
|
||||
$styles = [];
|
||||
foreach ($input as $role => $style) {
|
||||
if ($roles === self::SECTION && $role === 'template' && is_string($style) && BlockTemplates::find($style)) {
|
||||
$styles[$role] = $style;
|
||||
continue;
|
||||
}
|
||||
if ($roles === self::PAGE && $role === 'breadcrumbLinks') {
|
||||
if (!is_string($style)) {
|
||||
throw new RuntimeException('面包屑无效。');
|
||||
@@ -94,14 +98,41 @@ final class CanvasStyle
|
||||
}
|
||||
$cleanRuns[] = [self::lineBreaks($run[0]), self::classList($run[1], textOnly: true)];
|
||||
}
|
||||
if ($classes !== '' || $cleanRuns !== []) {
|
||||
$styles[$role] = ['classes' => $classes, 'runs' => $cleanRuns];
|
||||
$id = $style['id'] ?? '';
|
||||
if (!is_string($id) || ($id !== '' && !preg_match('/^[A-Za-z][A-Za-z0-9_.:-]{0,79}$/D', $id))) {
|
||||
throw new RuntimeException('元素 ID 须以英文字母开头,最长 80 个字符。');
|
||||
}
|
||||
$hidden = in_array($role, ['heading', 'title'], true) && ($style['hidden'] ?? false) === true;
|
||||
if ($classes !== '' || $cleanRuns !== [] || $id !== '' || $hidden) {
|
||||
$styles[$role] = ['classes' => $classes, 'runs' => $cleanRuns]
|
||||
+ ($id !== '' ? ['id' => $id] : []) + ($hidden ? ['hidden' => true] : []);
|
||||
}
|
||||
}
|
||||
|
||||
return $styles;
|
||||
}
|
||||
|
||||
public static function idAttributes(array $styles, string $role, bool $canvas, string $fallback = ''): string
|
||||
{
|
||||
$custom = $styles[$role]['id'] ?? '';
|
||||
$id = $custom !== '' ? $custom : $fallback;
|
||||
|
||||
return ($id === '' ? '' : ' id="' . View::escape($id) . '"')
|
||||
. ($canvas ? ' data-studio-default-id="' . View::escape($fallback) . '"' : '')
|
||||
. ($canvas && $custom !== '' ? ' data-studio-layer-id="' . View::escape($custom) . '"' : '');
|
||||
}
|
||||
|
||||
public static function originalAnchor(array $styles, string $role, string $original): string
|
||||
{
|
||||
return isset($styles[$role]['id']) && $styles[$role]['id'] !== $original
|
||||
? '<span id="' . View::escape($original) . '" class="studio-anchor" aria-hidden="true"></span>' : '';
|
||||
}
|
||||
|
||||
public static function hiddenTitle(array $styles, string $role, string $text, bool $canvas): string
|
||||
{
|
||||
return $canvas && $text === '' && !empty($styles[$role]['hidden']) ? ' hidden data-studio-layer-hidden' : '';
|
||||
}
|
||||
|
||||
private static function classList(mixed $value, bool $textOnly = false): string
|
||||
{
|
||||
if (!is_string($value) || strlen($value) > 1800) {
|
||||
|
||||
Reference in New Issue
Block a user