Add categorized template previews and fix canvas event delegation
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Content;
|
||||
|
||||
final class BlockTemplates
|
||||
{
|
||||
public const GROUPS = [
|
||||
'content' => ['标题与正文', [
|
||||
'headline' => ['标题与简介', '<div class="studio-intro"><h3>填写区块标题</h3><p>用一句话补充背景或说明。</p></div>'],
|
||||
'text' => ['正文', '<p>在这里输入区块内容。</p>'],
|
||||
'list' => ['步骤列表', '<ol><li>填写第一步</li><li>填写第二步</li><li>填写第三步</li></ol>'],
|
||||
]],
|
||||
'cover' => ['封面与横幅', [
|
||||
'cover' => ['图文封面', '<div class="studio-cover"><img src="/assets/original/pagepan-example.webp" alt="" loading="lazy"><div><h3>用一句话介绍你的产品</h3><p>在首段说明访客能获得什么。</p><a class="button button-primary" href="/services">查看服务</a></div></div>'],
|
||||
'banner' => ['横幅', '<div class="studio-banner"><h3>用一句话介绍你的项目</h3><p>简要说明项目能为访客做什么。</p><a class="button button-primary" href="/services">了解更多</a></div>'],
|
||||
]],
|
||||
'layout' => ['图文与布局', [
|
||||
'image' => ['图文', '<div class="studio-split"><img src="/assets/original/home-hero.webp" alt="" loading="lazy"><div><h3>介绍主题</h3><p>在这里说明图片或产品。</p></div></div>'],
|
||||
'grid' => ['双栏网格', '<div class="studio-two-column"><article class="content-card"><h3>第一栏</h3><p>填写主要内容。</p></article><article class="content-card"><h3>第二栏</h3><p>补充相关信息。</p></article></div>'],
|
||||
]],
|
||||
'features' => ['特性与口碑', [
|
||||
'features' => ['特性卡片', '<div class="card-grid feature-grid"><article class="content-card feature-card"><h3>特点一</h3><p>介绍这个特点。</p></article><article class="content-card feature-card"><h3>特点二</h3><p>介绍这个特点。</p></article><article class="content-card feature-card"><h3>特点三</h3><p>介绍这个特点。</p></article></div>'],
|
||||
'quote' => ['引文', '<blockquote><p>在这里填写引用或用户反馈。</p></blockquote>'],
|
||||
]],
|
||||
'details' => ['表格与问答', [
|
||||
'table' => ['对比表格', '<table><thead><tr><th scope="col">项目</th><th scope="col">说明</th></tr></thead><tbody><tr><td>项目一</td><td>填写说明</td></tr><tr><td>项目二</td><td>填写说明</td></tr></tbody></table>'],
|
||||
'faq' => ['常见问题', '<div class="faq"><details><summary>请输入问题</summary><div><p>请输入答案。</p></div></details></div>'],
|
||||
]],
|
||||
'actions' => ['导航与引导', [
|
||||
'navigation' => ['快速导航', '<ul class="studio-quick-nav"><li><a href="/services">产品与服务</a></li><li><a href="/articles">动态与文章</a></li><li><a href="/#contact">联系来笙</a></li></ul>'],
|
||||
'cta' => ['行动按钮', '<p>说明下一步。</p><p><a class="button button-primary" href="#contact">联系来笙</a></p>'],
|
||||
]],
|
||||
];
|
||||
|
||||
public static function find(string $key): ?array
|
||||
{
|
||||
foreach (self::GROUPS as [, $templates]) {
|
||||
if (isset($templates[$key])) {
|
||||
return $templates[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Content\Assets;
|
||||
use App\Content\BlockTemplates;
|
||||
use App\Content\Html;
|
||||
use App\Content\Media;
|
||||
use App\Content\Repository;
|
||||
@@ -16,18 +17,6 @@ use Webman\Http\UploadFile;
|
||||
|
||||
final class StudioController extends AdminController
|
||||
{
|
||||
public const BLOCKS = [
|
||||
'text' => ['正文', '<p>在这里输入区块内容。</p>'],
|
||||
'image' => ['图文', '<div class="studio-split"><img src="/assets/original/home-hero.webp" alt="" loading="lazy"><div><h3>介绍主题</h3><p>在这里说明图片或产品。</p></div></div>'],
|
||||
'banner' => ['横幅', '<div class="studio-banner"><h3>用一句话介绍你的项目</h3><p>简要说明项目能为访客做什么。</p><a class="button button-primary" href="/services">了解更多</a></div>'],
|
||||
'features' => ['特性卡片', '<div class="card-grid feature-grid"><article class="content-card feature-card"><h3>特点一</h3><p>介绍这个特点。</p></article><article class="content-card feature-card"><h3>特点二</h3><p>介绍这个特点。</p></article><article class="content-card feature-card"><h3>特点三</h3><p>介绍这个特点。</p></article></div>'],
|
||||
'quote' => ['引文', '<blockquote><p>在这里填写引用或用户反馈。</p></blockquote>'],
|
||||
'table' => ['对比表格', '<table><thead><tr><th scope="col">项目</th><th scope="col">说明</th></tr></thead><tbody><tr><td>项目一</td><td>填写说明</td></tr><tr><td>项目二</td><td>填写说明</td></tr></tbody></table>'],
|
||||
'list' => ['步骤列表', '<ol><li>填写第一步</li><li>填写第二步</li><li>填写第三步</li></ol>'],
|
||||
'cta' => ['行动按钮', '<p>说明下一步。</p><p><a class="button button-primary" href="#contact">联系来笙</a></p>'],
|
||||
'faq' => ['常见问题', '<div class="faq"><details><summary>请输入问题</summary><div><p>请输入答案。</p></div></details></div>'],
|
||||
];
|
||||
|
||||
public function newPage(Request $request): Response
|
||||
{
|
||||
if ($failure = $this->guard($request)) {
|
||||
@@ -80,7 +69,7 @@ final class StudioController extends AdminController
|
||||
throw new RuntimeException('区块锚点不可用。');
|
||||
}
|
||||
if ($action === 'create') {
|
||||
$preset = self::BLOCKS[$this->input($request, 'preset')] ?? null;
|
||||
$preset = BlockTemplates::find($this->input($request, 'preset'));
|
||||
if ($preset === null) {
|
||||
throw new RuntimeException('请选择区块类型。');
|
||||
}
|
||||
|
||||
+9
-13
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
use App\Content\SiteDesign;
|
||||
use App\Content\View;
|
||||
use App\Controller\StudioController;
|
||||
use App\Content\BlockTemplates;
|
||||
|
||||
$e = View::escape(...);
|
||||
$slug = $page['slug'];
|
||||
@@ -19,16 +19,8 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
|
||||
<?= View::fragment('admin-feedback', compact('error', 'saved')) ?>
|
||||
<div class="studio-layout">
|
||||
<aside class="admin-panel studio-library" aria-labelledby="studio-library-title">
|
||||
<h2 id="studio-library-title">元素模板</h2>
|
||||
<div class="studio-presets" data-canvas-presets>
|
||||
<?php foreach (StudioController::BLOCKS as $preset => [$label, $markup]): ?>
|
||||
<button type="button" disabled data-canvas-template="<?= $e($preset) ?>"><?= $e($label) ?></button>
|
||||
<template data-preset="<?= $e($preset) ?>"><?= $markup ?></template>
|
||||
<?php endforeach ?>
|
||||
<label class="studio-insert-mode"><input type="checkbox" data-template-inline> 插入当前正文</label>
|
||||
<p class="field-note" data-template-status role="status"></p>
|
||||
<ul class="studio-pending" data-template-pending hidden></ul>
|
||||
</div>
|
||||
<h2 id="studio-library-title">区块模板</h2>
|
||||
<?= View::fragment('studio-templates') ?>
|
||||
<details class="studio-layers">
|
||||
<summary>首屏与目录</summary>
|
||||
<button type="button" disabled data-hero-control="image">首屏图片</button>
|
||||
@@ -43,8 +35,12 @@ $previewUrl = '/admin/pages/' . $slug . '/preview';
|
||||
<input type="hidden" name="operation" value="create">
|
||||
<label>锚点<input name="key" pattern="[a-z0-9]+(-[a-z0-9]+)*" maxlength="70" placeholder="overview" required></label>
|
||||
<label>模板<select name="preset">
|
||||
<?php foreach (StudioController::BLOCKS as $preset => [$label]): ?>
|
||||
<option value="<?= $e($preset) ?>"><?= $e($label) ?></option>
|
||||
<?php foreach (BlockTemplates::GROUPS as [$category, $templates]): ?>
|
||||
<optgroup label="<?= $e($category) ?>">
|
||||
<?php foreach ($templates as $preset => [$label]): ?>
|
||||
<option value="<?= $e($preset) ?>"><?= $e($label) ?></option>
|
||||
<?php endforeach ?>
|
||||
</optgroup>
|
||||
<?php endforeach ?>
|
||||
</select></label>
|
||||
<button type="submit" class="button button-outline">新建</button>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
use App\Content\BlockTemplates;
|
||||
use App\Content\View;
|
||||
|
||||
$e = View::escape(...);
|
||||
?>
|
||||
<div class="studio-presets" data-canvas-presets>
|
||||
<label class="studio-template-search">搜索模板<input type="search" data-template-search placeholder="按名称或分类搜索" autocomplete="off"></label>
|
||||
<div class="studio-template-filters" role="group" aria-label="模板分类">
|
||||
<button type="button" data-template-filter="" aria-pressed="true">全部</button>
|
||||
<?php foreach (BlockTemplates::GROUPS as $group => [$category]): ?>
|
||||
<button type="button" data-template-filter="<?= $e($group) ?>" aria-pressed="false"><?= $e($category) ?></button>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<label class="studio-insert-mode"><input type="checkbox" data-template-inline> 插入当前正文</label>
|
||||
<p class="field-note" data-template-status role="status"></p>
|
||||
<ul class="studio-pending" data-template-pending hidden></ul>
|
||||
<p class="field-note" data-template-empty hidden role="status">没有找到匹配的模板。</p>
|
||||
<div class="studio-template-groups">
|
||||
<?php foreach (BlockTemplates::GROUPS as $group => [$category, $templates]): ?>
|
||||
<section class="studio-template-group" data-template-group="<?= $e($group) ?>" aria-labelledby="studio-template-<?= $e($group) ?>">
|
||||
<h3 id="studio-template-<?= $e($group) ?>"><?= $e($category) ?></h3>
|
||||
<div class="studio-template-cards">
|
||||
<?php foreach ($templates as $preset => [$label, $markup]): ?>
|
||||
<article class="studio-template-card" data-template-card data-template-search-text="<?= $e($label . ' ' . $category . ' ' . $preset) ?>">
|
||||
<button type="button" class="studio-template-image" data-template-preview="<?= $e($preset) ?>" data-template-title="<?= $e($label) ?>"
|
||||
aria-label="预览<?= $e($label) ?>模板">
|
||||
<img src="/assets/template-previews/<?= $e($preset) ?>.webp" alt="" width="768" height="480" loading="lazy">
|
||||
</button>
|
||||
<div class="studio-template-meta">
|
||||
<span><?= $e($label) ?></span>
|
||||
<button type="button" class="button button-outline" disabled data-canvas-template="<?= $e($preset) ?>"
|
||||
data-template-title="<?= $e($label) ?>" aria-label="添加<?= $e($label) ?>模板">添加</button>
|
||||
</div>
|
||||
<template data-preset="<?= $e($preset) ?>"><?= $markup ?></template>
|
||||
</article>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
<div class="studio-template-peek" data-template-peek aria-hidden="true" hidden>
|
||||
<img alt="">
|
||||
<p></p>
|
||||
</div>
|
||||
<dialog class="media-picker studio-template-dialog" data-template-dialog aria-labelledby="studio-template-preview-title">
|
||||
<header class="admin-heading compact">
|
||||
<h2 id="studio-template-preview-title"></h2>
|
||||
<button type="button" class="button button-outline" data-template-close>关闭</button>
|
||||
</header>
|
||||
<img alt="" width="768" height="480">
|
||||
<div class="actions"><button type="button" class="button button-primary" data-template-use>添加到画布</button></div>
|
||||
</dialog>
|
||||
</div>
|
||||
Reference in New Issue
Block a user