Address canvas review and add paragraph shortcut

This commit is contained in:
2026-11-23 20:13:07 +08:00
parent 3e842aa35c
commit 4e3964a6eb
9 changed files with 87 additions and 28 deletions
+13
View File
@@ -25,6 +25,19 @@ final class CanvasStyle
];
private const PREFIX = 'studio-style-';
public static function encode(array $presentation): string
{
return $presentation === [] ? '{}' : Database::json($presentation);
}
public static function stylesheetUrl(): string
{
static $version;
$version ??= hash_file('xxh64', __FILE__);
return '/canvas-style.css?v=' . $version;
}
public static function normalize(mixed $input, array $roles): array
{
if (!is_array($input) || count($input) > count($roles) + 28) {
+2 -2
View File
@@ -93,7 +93,7 @@ final class Repository
$data['name'], $data['title'], $data['description'], $data['heading'], $data['accent'], $data['lead'],
$data['image'], $data['alt'], $data['image_scale'], Database::json($data['alignments']), Database::json($data['actions']), Database::json($data['quicklinks']),
Database::json($data['visibility']), $data['header_id'], $data['footer_id'], $data['palette_id'], $data['status'], self::now(),
isset($data['presentation']) ? Database::json($data['presentation']) : null, $slug, $version,
isset($data['presentation']) ? CanvasStyle::encode($data['presentation']) : null, $slug, $version,
]);
self::checkVersion($query->rowCount());
if ($replaceDraftSections) {
@@ -166,7 +166,7 @@ final class Repository
}
}
$pdo->prepare('UPDATE pages SET actions = ?, quicklinks = ?, presentation = ? WHERE slug = ?')
->execute([$row['actions'], $row['quicklinks'], Database::json($styles), $page]);
->execute([$row['actions'], $row['quicklinks'], CanvasStyle::encode($styles), $page]);
}
public function arrangeSection(string $page, string $key, string $operation, int $version, int $pageVersion): void
+2 -2
View File
@@ -185,7 +185,7 @@ final class SiteBackup
$row['quicklinks'] = Database::json(Buttons::validate(self::decode($row['quicklinks'] ?? '[]'), 20));
$row['visibility'] = Database::json(array_intersect_key(self::decode($row['visibility'] ?? '{}'), array_flip(['header', 'hero', 'footer'])));
$row['alignments'] = Database::json(self::decode($row['alignments'] ?? '{}'));
$row['presentation'] = Database::json(CanvasStyle::normalize(self::decode($row['presentation'] ?? '{}'), CanvasStyle::PAGE));
$row['presentation'] = CanvasStyle::encode(CanvasStyle::normalize(self::decode($row['presentation'] ?? '{}'), CanvasStyle::PAGE));
if (($row['theme'] ?? '') !== '' && !isset(PageTemplates::groups()[$row['theme']])) {
$row['theme'] = '';
}
@@ -200,7 +200,7 @@ final class SiteBackup
throw new RuntimeException('备份包含未知区块样式。');
}
$row['body'] = Html::sanitize($row['body'] ?? '');
$row['presentation'] = Database::json(CanvasStyle::normalize(self::decode($row['presentation'] ?? '{}'), CanvasStyle::SECTION));
$row['presentation'] = CanvasStyle::encode(CanvasStyle::normalize(self::decode($row['presentation'] ?? '{}'), CanvasStyle::SECTION));
if (isset($row['feed'])) {
$feed = self::decode($row['feed']);
if (!in_array($feed['mode'] ?? '', ['merged', 'tabs', 'network', 'catalog'], true)
+1 -1
View File
@@ -434,7 +434,7 @@ class AdminController
$section['alignments'] = Database::json($this->alignmentMap($alignments, ['title', 'lead']));
}
if ($presentation !== null) {
$section['presentation'] = Database::json(CanvasStyle::normalize($presentation, CanvasStyle::SECTION));
$section['presentation'] = CanvasStyle::encode(CanvasStyle::normalize($presentation, CanvasStyle::SECTION));
}
$this->checkSection($section, $section['style']);
if (isset($fields['body'])) {
+3 -1
View File
@@ -1,5 +1,6 @@
<?php
use App\Content\Buttons;
use App\Content\CanvasStyle;
use App\Content\Database;
use App\Content\SiteDesign;
use App\Content\View;
@@ -41,6 +42,7 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
<div class="editor-toolbar studio-canvas-toolbar" data-canvas-toolbar hidden aria-label="正文工具">
<div>
<button type="button" data-canvas-command="heading">小标题</button>
<button type="button" data-canvas-command="paragraph" title="换段(Ctrl/⌘+Enter)" aria-keyshortcuts="Control+Enter Meta+Enter">换段</button>
<button type="button" data-canvas-command="list">列表</button>
<button type="button" data-canvas-command="link">插入链接</button>
<button type="button" data-canvas-command="media">插入媒体</button>
@@ -140,7 +142,7 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
<input type="hidden" name="version" value="<?= $e($page['version']) ?>">
<input type="hidden" name="canvas_sections" value="">
<input type="hidden" name="canvas_order" value="">
<input type="hidden" name="canvas_presentation" value="<?= $e(Database::json($page['presentation'])) ?>">
<input type="hidden" name="canvas_presentation" value="<?= $e(CanvasStyle::encode($page['presentation'])) ?>">
<input type="hidden" name="alignments" value="<?= $e(Database::json($page['alignments'])) ?>">
<details class="studio-hero-settings">
<summary>首屏与目录</summary>
+2 -1
View File
@@ -1,6 +1,7 @@
<?php
use App\Content\View;
use App\Content\Assets;
use App\Content\CanvasStyle;
use App\Content\DesignLibrary;
$e = View::escape(...);
@@ -43,7 +44,7 @@ $showFooter = $page['visibility']['footer'] ?? true;
<?php endif ?>
<meta name="twitter:card" content="summary_large_image">
<link rel="stylesheet" href="/assets/site.css">
<?php if (!empty($canvas) || str_contains($content, 'studio-style-')): ?><link rel="stylesheet" href="/canvas-style.css"><?php endif ?>
<?php if (!empty($canvas) || str_contains($content, 'studio-style-')): ?><link rel="stylesheet" href="<?= $e(CanvasStyle::stylesheetUrl()) ?>"><?php endif ?>
<?php if ($theme !== ''): ?><link rel="stylesheet" href="/assets/page-themes.css"><?php endif ?>
<?php if ($palette): ?><link rel="stylesheet" data-page-palette href="/palette/<?= $e($palette['id']) ?>.css?v=<?= $e($palette['version']) ?>"><?php endif ?>
<script src="/assets/jquery-4.0.0.min.js" defer></script>
+1 -1
View File
@@ -17,7 +17,7 @@ $field = static fn (string $name): string => $canvas ? ' data-studio-field="' .
?>
<?php if (!$showHero && !$canvas): ?><h1 class="sr-only"><?= $e($page['name']) ?></h1><?php endif ?>
<?php if ($showHero || $canvas || $heroLinks): ?>
<section class="hero hero-<?= $e($page['slug']) ?><?= $style('hero') ?>" id="home" data-enter<?= $styleField('hero') ?>>
<section class="hero hero-<?= $e($page['slug']) ?><?= $style('hero') ?>" id="home" data-enter<?= $canvas ? ' data-studio-hero' : '' ?><?= $styleField('hero') ?>>
<?php if ($showHero || $canvas): ?>
<div class="wrap hero-inner<?= $page['image'] === '' ? ' hero-text-only' : '' ?>"<?= $canvas ? ' data-studio-hero-content' : '' ?><?= $showHero ? '' : ' hidden' ?>>
<div class="hero-copy">